From 1bad209b01c3fa730905e879fa22cc9646a6bd5c Mon Sep 17 00:00:00 2001 From: Carlos Morais Date: Mon, 5 Dec 2011 17:05:42 -0200 Subject: [PATCH] Replacing old lib directory --- plugins/mezuro/lib/kalibro/client/base_tool_client.rb | 16 ++++++++++++++++ plugins/mezuro/lib/kalibro/client/configuration_client.rb | 24 ++++++++++++++++++++++++ plugins/mezuro/lib/kalibro/client/kalibro_client.rb | 15 +++++++++++++++ plugins/mezuro/lib/kalibro/client/module_result_client.rb | 19 +++++++++++++++++++ plugins/mezuro/lib/kalibro/client/port.rb | 24 ++++++++++++++++++++++++ plugins/mezuro/lib/kalibro/client/project_client.rb | 24 ++++++++++++++++++++++++ plugins/mezuro/lib/kalibro/client/project_result_client.rb | 41 +++++++++++++++++++++++++++++++++++++++++ plugins/mezuro/lib/kalibro/entities/base_tool.rb | 17 +++++++++++++++++ plugins/mezuro/lib/kalibro/entities/compound_metric.rb | 5 +++++ plugins/mezuro/lib/kalibro/entities/compound_metric_with_error.rb | 13 +++++++++++++ plugins/mezuro/lib/kalibro/entities/configuration.rb | 17 +++++++++++++++++ plugins/mezuro/lib/kalibro/entities/entity.rb | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/mezuro/lib/kalibro/entities/error.rb | 17 +++++++++++++++++ plugins/mezuro/lib/kalibro/entities/metric.rb | 5 +++++ plugins/mezuro/lib/kalibro/entities/metric_configuration.rb | 26 ++++++++++++++++++++++++++ plugins/mezuro/lib/kalibro/entities/metric_result.rb | 30 ++++++++++++++++++++++++++++++ plugins/mezuro/lib/kalibro/entities/module.rb | 5 +++++ plugins/mezuro/lib/kalibro/entities/module_node.rb | 21 +++++++++++++++++++++ plugins/mezuro/lib/kalibro/entities/module_result.rb | 33 +++++++++++++++++++++++++++++++++ plugins/mezuro/lib/kalibro/entities/native_metric.rb | 5 +++++ plugins/mezuro/lib/kalibro/entities/project.rb | 13 +++++++++++++ plugins/mezuro/lib/kalibro/entities/project_result.rb | 34 ++++++++++++++++++++++++++++++++++ plugins/mezuro/lib/kalibro/entities/range.rb | 5 +++++ plugins/mezuro/lib/kalibro/entities/repository.rb | 5 +++++ plugins/mezuro/lib/kalibro/entities/stack_trace_element.rb | 5 +++++ plugins/mezuro/lib/mezuro_plugin.rb | 26 +++++++++++++------------- plugins/mezuro/lib/mezuro_plugin/analizo_extractor.rb | 43 ------------------------------------------- plugins/mezuro/lib/mezuro_plugin/calculate_metrics_job.rb | 7 ------- plugins/mezuro/lib/mezuro_plugin/metric.rb | 19 ------------------- plugins/mezuro/lib/mezuro_plugin/project.rb | 76 ---------------------------------------------------------------------------- plugins/mezuro/lib/mezuro_plugin/project_content.rb | 46 ++++++++++++++++++++++++++++++++++++++++++++++ plugins/mezuro/lib/tasks/cucumber.rake | 47 ----------------------------------------------- plugins/mezuro/lib/tasks/rspec.rake | 144 ------------------------------------------------------------------------------------------------------------------------------------------------ 33 files changed, 531 insertions(+), 349 deletions(-) create mode 100644 plugins/mezuro/lib/kalibro/client/base_tool_client.rb create mode 100644 plugins/mezuro/lib/kalibro/client/configuration_client.rb create mode 100644 plugins/mezuro/lib/kalibro/client/kalibro_client.rb create mode 100644 plugins/mezuro/lib/kalibro/client/module_result_client.rb create mode 100644 plugins/mezuro/lib/kalibro/client/port.rb create mode 100644 plugins/mezuro/lib/kalibro/client/project_client.rb create mode 100644 plugins/mezuro/lib/kalibro/client/project_result_client.rb create mode 100644 plugins/mezuro/lib/kalibro/entities/base_tool.rb create mode 100644 plugins/mezuro/lib/kalibro/entities/compound_metric.rb create mode 100644 plugins/mezuro/lib/kalibro/entities/compound_metric_with_error.rb create mode 100644 plugins/mezuro/lib/kalibro/entities/configuration.rb create mode 100644 plugins/mezuro/lib/kalibro/entities/entity.rb create mode 100644 plugins/mezuro/lib/kalibro/entities/error.rb create mode 100644 plugins/mezuro/lib/kalibro/entities/metric.rb create mode 100644 plugins/mezuro/lib/kalibro/entities/metric_configuration.rb create mode 100644 plugins/mezuro/lib/kalibro/entities/metric_result.rb create mode 100644 plugins/mezuro/lib/kalibro/entities/module.rb create mode 100644 plugins/mezuro/lib/kalibro/entities/module_node.rb create mode 100644 plugins/mezuro/lib/kalibro/entities/module_result.rb create mode 100644 plugins/mezuro/lib/kalibro/entities/native_metric.rb create mode 100644 plugins/mezuro/lib/kalibro/entities/project.rb create mode 100644 plugins/mezuro/lib/kalibro/entities/project_result.rb create mode 100644 plugins/mezuro/lib/kalibro/entities/range.rb create mode 100644 plugins/mezuro/lib/kalibro/entities/repository.rb create mode 100644 plugins/mezuro/lib/kalibro/entities/stack_trace_element.rb delete mode 100644 plugins/mezuro/lib/mezuro_plugin/analizo_extractor.rb delete mode 100644 plugins/mezuro/lib/mezuro_plugin/calculate_metrics_job.rb delete mode 100644 plugins/mezuro/lib/mezuro_plugin/metric.rb delete mode 100644 plugins/mezuro/lib/mezuro_plugin/project.rb create mode 100644 plugins/mezuro/lib/mezuro_plugin/project_content.rb delete mode 100644 plugins/mezuro/lib/tasks/cucumber.rake delete mode 100644 plugins/mezuro/lib/tasks/rspec.rake diff --git a/plugins/mezuro/lib/kalibro/client/base_tool_client.rb b/plugins/mezuro/lib/kalibro/client/base_tool_client.rb new file mode 100644 index 0000000..eb58162 --- /dev/null +++ b/plugins/mezuro/lib/kalibro/client/base_tool_client.rb @@ -0,0 +1,16 @@ +class Kalibro::Client::BaseToolClient + + def initialize + @port = Kalibro::Client::Port.new('BaseTool') + end + + def base_tool_names + @port.request(:get_base_tool_names)[:base_tool_name].to_a + end + + def base_tool(name) + hash = @port.request(:get_base_tool, {:base_tool_name => name})[:base_tool] + Kalibro::Entities::BaseTool.from_hash(hash) + end + +end \ No newline at end of file diff --git a/plugins/mezuro/lib/kalibro/client/configuration_client.rb b/plugins/mezuro/lib/kalibro/client/configuration_client.rb new file mode 100644 index 0000000..f372146 --- /dev/null +++ b/plugins/mezuro/lib/kalibro/client/configuration_client.rb @@ -0,0 +1,24 @@ +class Kalibro::Client::ConfigurationClient + + def initialize + @port = Kalibro::Client::Port.new('Configuration') + end + + def save(configuration) + @port.request(:save_configuration, {:configuration => configuration.to_hash}) + end + + def configuration_names + @port.request(:get_configuration_names)[:configuration_name].to_a + end + + def configuration(name) + hash = @port.request(:get_configuration, {:configuration_name => name})[:configuration] + Kalibro::Entities::Configuration.from_hash(hash) + end + + def remove(configuration_name) + @port.request(:remove_configuration, {:configuration_name => configuration_name}) + end + +end \ No newline at end of file diff --git a/plugins/mezuro/lib/kalibro/client/kalibro_client.rb b/plugins/mezuro/lib/kalibro/client/kalibro_client.rb new file mode 100644 index 0000000..c38a3aa --- /dev/null +++ b/plugins/mezuro/lib/kalibro/client/kalibro_client.rb @@ -0,0 +1,15 @@ +class Kalibro::Client::KalibroClient + + def initialize + @port = Kalibro::Client::Port.new('Kalibro') + end + + def supported_repository_types + @port.request(:get_supported_repository_types)[:repository_type].to_a + end + + def process_project(project_name) + @port.request(:process_project, {:project_name => project_name}) + end + +end \ No newline at end of file diff --git a/plugins/mezuro/lib/kalibro/client/module_result_client.rb b/plugins/mezuro/lib/kalibro/client/module_result_client.rb new file mode 100644 index 0000000..d6934bf --- /dev/null +++ b/plugins/mezuro/lib/kalibro/client/module_result_client.rb @@ -0,0 +1,19 @@ +class Kalibro::Client::ModuleResultClient + + def initialize + @port = Kalibro::Client::Port.new('ModuleResult') + end + + def module_result(project_name, module_name, date) + hash = @port.request(:get_module_result, + {:project_name => project_name, :module_name => module_name, :date => date})[:module_result] + Kalibro::Entities::ModuleResult.from_hash(hash) + end + + def result_history(project_name, module_name) + value = @port.request(:get_result_history, + {:project_name => project_name, :module_name => module_name})[:module_result] + Kalibro::Entities::Entity.new.to_entity_array(value, Kalibro::Entities::ModuleResult) + end + +end \ No newline at end of file diff --git a/plugins/mezuro/lib/kalibro/client/port.rb b/plugins/mezuro/lib/kalibro/client/port.rb new file mode 100644 index 0000000..9054c73 --- /dev/null +++ b/plugins/mezuro/lib/kalibro/client/port.rb @@ -0,0 +1,24 @@ +require 'savon' + +class Kalibro::Client::Port + + @@service_address = 'http://valinhos.ime.usp.br:50688/KalibroService/' + + def self.service_address + @@service_address + end + + def self.service_address=(service_address) + @@service_address = service_address + end + + def initialize(endpoint) + @client = Savon::Client.new("#{@@service_address}#{endpoint}Endpoint/?wsdl") + end + + def request(action, request_body = nil) + response = @client.request(:kalibro, action) { soap.body = request_body } + response.to_hash["#{action}_response".to_sym] + end + +end \ No newline at end of file diff --git a/plugins/mezuro/lib/kalibro/client/project_client.rb b/plugins/mezuro/lib/kalibro/client/project_client.rb new file mode 100644 index 0000000..2945ec7 --- /dev/null +++ b/plugins/mezuro/lib/kalibro/client/project_client.rb @@ -0,0 +1,24 @@ +class Kalibro::Client::ProjectClient + + def initialize + @port = Kalibro::Client::Port.new('Project') + end + + def save(project) + @port.request(:save_project, {:project => project.to_hash}) + end + + def project_names + @port.request(:get_project_names)[:project_name].to_a + end + + def project(name) + hash = @port.request(:get_project, {:project_name => name})[:project] + Kalibro::Entities::Project.from_hash(hash) + end + + def remove(project_name) + @port.request(:remove_project, {:project_name => project_name}) + end + +end \ No newline at end of file diff --git a/plugins/mezuro/lib/kalibro/client/project_result_client.rb b/plugins/mezuro/lib/kalibro/client/project_result_client.rb new file mode 100644 index 0000000..f885caa --- /dev/null +++ b/plugins/mezuro/lib/kalibro/client/project_result_client.rb @@ -0,0 +1,41 @@ +class Kalibro::Client::ProjectResultClient + + def initialize + @port = Kalibro::Client::Port.new('ProjectResult') + end + + def has_results_for(project_name) + @port.request(:has_results_for, {:project_name => project_name})[:has_results] + end + + def has_results_before(project_name, date) + @port.request(:has_results_before, {:project_name => project_name, :date => date})[:has_results] + end + + def has_results_after(project_name, date) + @port.request(:has_results_after, {:project_name => project_name, :date => date})[:has_results] + end + + def first_result(project_name) + hash = @port.request(:get_first_result_of, {:project_name => project_name})[:project_result] + Kalibro::Entities::ProjectResult.from_hash(hash) + end + + def last_result(project_name) + hash = @port.request(:get_last_result_of, {:project_name => project_name})[:project_result] + Kalibro::Entities::ProjectResult.from_hash(hash) + end + + def first_result_after(project_name, date) + request_body = {:project_name => project_name, :date => date} + hash = @port.request(:get_first_result_after, request_body)[:project_result] + Kalibro::Entities::ProjectResult.from_hash(hash) + end + + def last_result_before(project_name, date) + request_body = {:project_name => project_name, :date => date} + hash = @port.request(:get_last_result_before, request_body)[:project_result] + Kalibro::Entities::ProjectResult.from_hash(hash) + end + +end \ No newline at end of file diff --git a/plugins/mezuro/lib/kalibro/entities/base_tool.rb b/plugins/mezuro/lib/kalibro/entities/base_tool.rb new file mode 100644 index 0000000..334e651 --- /dev/null +++ b/plugins/mezuro/lib/kalibro/entities/base_tool.rb @@ -0,0 +1,17 @@ +class Kalibro::Entities::BaseTool < Kalibro::Entities::Entity + + attr_accessor :name, :description, :supported_metric + + def supported_metric=(value) + @supported_metric = to_entity_array(value, Kalibro::Entities::NativeMetric) + end + + def supported_metrics + @supported_metric + end + + def supported_metrics=(supported_metrics) + @supported_metric = supported_metrics + end + +end \ No newline at end of file diff --git a/plugins/mezuro/lib/kalibro/entities/compound_metric.rb b/plugins/mezuro/lib/kalibro/entities/compound_metric.rb new file mode 100644 index 0000000..6e56463 --- /dev/null +++ b/plugins/mezuro/lib/kalibro/entities/compound_metric.rb @@ -0,0 +1,5 @@ +class Kalibro::Entities::CompoundMetric < Kalibro::Entities::Metric + + attr_accessor :script + +end \ No newline at end of file diff --git a/plugins/mezuro/lib/kalibro/entities/compound_metric_with_error.rb b/plugins/mezuro/lib/kalibro/entities/compound_metric_with_error.rb new file mode 100644 index 0000000..ce234ac --- /dev/null +++ b/plugins/mezuro/lib/kalibro/entities/compound_metric_with_error.rb @@ -0,0 +1,13 @@ +class Kalibro::Entities::CompoundMetricWithError < Kalibro::Entities::Entity + + attr_accessor :metric, :error + + def metric=(value) + @metric = to_entity(value, Kalibro::Entities::CompoundMetric) + end + + def error=(value) + @error = to_entity(value, Kalibro::Entities::Error) + end + +end \ No newline at end of file diff --git a/plugins/mezuro/lib/kalibro/entities/configuration.rb b/plugins/mezuro/lib/kalibro/entities/configuration.rb new file mode 100644 index 0000000..ceaf77f --- /dev/null +++ b/plugins/mezuro/lib/kalibro/entities/configuration.rb @@ -0,0 +1,17 @@ +class Kalibro::Entities::Configuration < Kalibro::Entities::Entity + + attr_accessor :name, :description, :metric_configuration + + def metric_configuration=(value) + @metric_configuration = to_entity_array(value, Kalibro::Entities::MetricConfiguration) + end + + def metric_configurations + @metric_configuration + end + + def metric_configurations=(metric_configurations) + @metric_configuration = metric_configurations + end + +end \ No newline at end of file diff --git a/plugins/mezuro/lib/kalibro/entities/entity.rb b/plugins/mezuro/lib/kalibro/entities/entity.rb new file mode 100644 index 0000000..9763f91 --- /dev/null +++ b/plugins/mezuro/lib/kalibro/entities/entity.rb @@ -0,0 +1,53 @@ +class Kalibro::Entities::Entity + + def self.from_hash(hash) + entity = self.new + hash.each { |field, value| entity.set(field, value) } + entity + end + + def set(field, value) + send("#{field}=", value) + end + + def to_entity_array(value, entity_class = nil) + array = value.kind_of?(Array) ? value : [value] + array.each.collect { |element| to_entity(element, entity_class) } + end + + def to_entity(value, entity_class) + value.kind_of?(Hash) ? entity_class.from_hash(value) : value + end + + def to_hash + hash = Hash.new + fields.each do |field| + field_value = self.get(field) + hash[field] = convert_to_hash(field_value) if ! field_value.nil? + end + hash + end + + def convert_to_hash(value) + return value.collect { |element| convert_to_hash(element) } if value.kind_of?(Array) + return value.to_hash if value.kind_of?(Kalibro::Entities::Entity) + value + end + + def ==(other) + begin + fields.each.inject(true) { |equal, field| equal && (self.get(field) == other.get(field)) } + rescue NoMethodError + false + end + end + + def fields + instance_variable_names.each.collect { |variable| variable.to_s.sub(/@/, '').to_sym } + end + + def get(field) + send("#{field}") + end + +end \ No newline at end of file diff --git a/plugins/mezuro/lib/kalibro/entities/error.rb b/plugins/mezuro/lib/kalibro/entities/error.rb new file mode 100644 index 0000000..8a4a879 --- /dev/null +++ b/plugins/mezuro/lib/kalibro/entities/error.rb @@ -0,0 +1,17 @@ +class Kalibro::Entities::Error < Kalibro::Entities::Entity + + attr_accessor :message, :stack_trace_element + + def stack_trace_element=(value) + @stack_trace_element = to_entity_array(value, Kalibro::Entities::StackTraceElement) + end + + def stack_trace + @stack_trace_element + end + + def stack_trace=(stack_trace) + @stack_trace_element = stack_trace + end + +end \ No newline at end of file diff --git a/plugins/mezuro/lib/kalibro/entities/metric.rb b/plugins/mezuro/lib/kalibro/entities/metric.rb new file mode 100644 index 0000000..c8efbbc --- /dev/null +++ b/plugins/mezuro/lib/kalibro/entities/metric.rb @@ -0,0 +1,5 @@ +class Kalibro::Entities::Metric < Kalibro::Entities::Entity + + attr_accessor :name, :scope, :description + +end \ No newline at end of file diff --git a/plugins/mezuro/lib/kalibro/entities/metric_configuration.rb b/plugins/mezuro/lib/kalibro/entities/metric_configuration.rb new file mode 100644 index 0000000..944e101 --- /dev/null +++ b/plugins/mezuro/lib/kalibro/entities/metric_configuration.rb @@ -0,0 +1,26 @@ +class Kalibro::Entities::MetricConfiguration < Kalibro::Entities::Entity + + attr_accessor :metric, :code, :weight, :aggregation_form, :range + + def metric=(value) + if value.kind_of?(Hash) + @metric = to_entity(value, Kalibro::Entities::CompoundMetric) if value.has_key?(:script) + @metric = to_entity(value, Kalibro::Entities::NativeMetric) if value.has_key?(:origin) + else + @metric = value + end + end + + def range=(value) + @range = to_entity_array(value, Kalibro::Entities::Range) + end + + def ranges + @range + end + + def ranges=(ranges) + @range = ranges + end + +end \ No newline at end of file diff --git a/plugins/mezuro/lib/kalibro/entities/metric_result.rb b/plugins/mezuro/lib/kalibro/entities/metric_result.rb new file mode 100644 index 0000000..73ba670 --- /dev/null +++ b/plugins/mezuro/lib/kalibro/entities/metric_result.rb @@ -0,0 +1,30 @@ +class Kalibro::Entities::MetricResult < Kalibro::Entities::Entity + + attr_accessor :metric, :value, :range, :descendent_result + + def metric=(value) + if value.kind_of?(Hash) + @metric = to_entity(value, Kalibro::Entities::CompoundMetric) if value.has_key?(:script) + @metric = to_entity(value, Kalibro::Entities::NativeMetric) if value.has_key?(:origin) + else + @metric = value + end + end + + def range=(value) + @range = to_entity(value, Kalibro::Entities::Range) + end + + def descendent_result=(value) + @descendent_result = to_entity_array(value) + end + + def descendent_results + @descendent_result + end + + def descendent_results=(descendent_results) + @descendent_result = descendent_results + end + +end \ No newline at end of file diff --git a/plugins/mezuro/lib/kalibro/entities/module.rb b/plugins/mezuro/lib/kalibro/entities/module.rb new file mode 100644 index 0000000..ce814c6 --- /dev/null +++ b/plugins/mezuro/lib/kalibro/entities/module.rb @@ -0,0 +1,5 @@ +class Kalibro::Entities::Module < Kalibro::Entities::Entity + + attr_accessor :name, :granularity + +end \ No newline at end of file diff --git a/plugins/mezuro/lib/kalibro/entities/module_node.rb b/plugins/mezuro/lib/kalibro/entities/module_node.rb new file mode 100644 index 0000000..447a231 --- /dev/null +++ b/plugins/mezuro/lib/kalibro/entities/module_node.rb @@ -0,0 +1,21 @@ +class Kalibro::Entities::ModuleNode < Kalibro::Entities::Entity + + attr_accessor :module, :child + + def module=(value) + @module = to_entity(value, Kalibro::Entities::Module) + end + + def child=(value) + @child = to_entity_array(value, Kalibro::Entities::ModuleNode) + end + + def children + @child + end + + def children=(children) + @child = children + end + +end \ No newline at end of file diff --git a/plugins/mezuro/lib/kalibro/entities/module_result.rb b/plugins/mezuro/lib/kalibro/entities/module_result.rb new file mode 100644 index 0000000..39d07dd --- /dev/null +++ b/plugins/mezuro/lib/kalibro/entities/module_result.rb @@ -0,0 +1,33 @@ +class Kalibro::Entities::ModuleResult < Kalibro::Entities::Entity + + attr_accessor :module, :date, :grade, :metric_result, :compound_metric_with_error + + def module=(value) + @module = to_entity(value, Kalibro::Entities::Module) + end + + def metric_result=(value) + @metric_result = to_entity_array(value, Kalibro::Entities::MetricResult) + end + + def metric_results + @metric_result + end + + def metric_results=(metric_results) + @metric_result = metric_results + end + + def compound_metric_with_error=(value) + @compound_metric_with_error = to_entity_array(value, Kalibro::Entities::CompoundMetricWithError) + end + + def compound_metrics_with_error + @compound_metric_with_error + end + + def compound_metrics_with_error=(compound_metrics_with_error) + @compound_metric_with_error = compound_metrics_with_error + end + +end \ No newline at end of file diff --git a/plugins/mezuro/lib/kalibro/entities/native_metric.rb b/plugins/mezuro/lib/kalibro/entities/native_metric.rb new file mode 100644 index 0000000..f7e7822 --- /dev/null +++ b/plugins/mezuro/lib/kalibro/entities/native_metric.rb @@ -0,0 +1,5 @@ +class Kalibro::Entities::NativeMetric < Kalibro::Entities::Metric + + attr_accessor :origin, :language + +end \ No newline at end of file diff --git a/plugins/mezuro/lib/kalibro/entities/project.rb b/plugins/mezuro/lib/kalibro/entities/project.rb new file mode 100644 index 0000000..d35fd47 --- /dev/null +++ b/plugins/mezuro/lib/kalibro/entities/project.rb @@ -0,0 +1,13 @@ +class Kalibro::Entities::Project < Kalibro::Entities::Entity + + attr_accessor :name, :license, :description, :repository, :configuration_name, :state, :error + + def repository=(value) + @repository = to_entity(value, Kalibro::Entities::Repository) + end + + def error=(value) + @error = to_entity(value, Kalibro::Entities::Error) + end + +end \ No newline at end of file diff --git a/plugins/mezuro/lib/kalibro/entities/project_result.rb b/plugins/mezuro/lib/kalibro/entities/project_result.rb new file mode 100644 index 0000000..88f6437 --- /dev/null +++ b/plugins/mezuro/lib/kalibro/entities/project_result.rb @@ -0,0 +1,34 @@ +class Kalibro::Entities::ProjectResult < Kalibro::Entities::Entity + + attr_accessor :project, :date, :load_time, :analysis_time, :source_tree + + def project=(value) + @project = to_entity(value, Kalibro::Entities::Project) + end + + def source_tree=(value) + @source_tree = to_entity(value, Kalibro::Entities::ModuleNode) + end + + def formatted_load_time + format_milliseconds(@load_time) + end + + def formatted_analysis_time + format_milliseconds(@analysis_time) + end + + def format_milliseconds(value) + seconds = value/1000 + hours = seconds/3600 + seconds -= hours * 3600 + minutes = seconds/60 + seconds -= minutes * 60 + "#{format(hours)}:#{format(minutes)}:#{format(seconds)}" + end + + def format(amount) + ('%2d' % amount).sub(/\s/, '0') + end + +end \ No newline at end of file diff --git a/plugins/mezuro/lib/kalibro/entities/range.rb b/plugins/mezuro/lib/kalibro/entities/range.rb new file mode 100644 index 0000000..06a4f51 --- /dev/null +++ b/plugins/mezuro/lib/kalibro/entities/range.rb @@ -0,0 +1,5 @@ +class Kalibro::Entities::Range < Kalibro::Entities::Entity + + attr_accessor :beginning, :end, :label, :grade, :color, :comments + +end \ No newline at end of file diff --git a/plugins/mezuro/lib/kalibro/entities/repository.rb b/plugins/mezuro/lib/kalibro/entities/repository.rb new file mode 100644 index 0000000..22ee062 --- /dev/null +++ b/plugins/mezuro/lib/kalibro/entities/repository.rb @@ -0,0 +1,5 @@ +class Kalibro::Entities::Repository < Kalibro::Entities::Entity + + attr_accessor :type, :address, :username, :password + +end \ No newline at end of file diff --git a/plugins/mezuro/lib/kalibro/entities/stack_trace_element.rb b/plugins/mezuro/lib/kalibro/entities/stack_trace_element.rb new file mode 100644 index 0000000..1b68471 --- /dev/null +++ b/plugins/mezuro/lib/kalibro/entities/stack_trace_element.rb @@ -0,0 +1,5 @@ +class Kalibro::Entities::StackTraceElement < Kalibro::Entities::Entity + + attr_accessor :declaring_class, :method_name, :file_name, :line_number + +end \ No newline at end of file diff --git a/plugins/mezuro/lib/mezuro_plugin.rb b/plugins/mezuro/lib/mezuro_plugin.rb index 225adf9..2a683e2 100644 --- a/plugins/mezuro/lib/mezuro_plugin.rb +++ b/plugins/mezuro/lib/mezuro_plugin.rb @@ -8,20 +8,20 @@ class MezuroPlugin < Noosfero::Plugin _("A metric analizer plugin.") end - def control_panel_buttons - if context.profile.community? - { :title => 'Mezuro projects', :icon => 'mezuro', :url => {:controller => 'mezuro_plugin_myprofile', :action => 'index'} } - end + def content_types + MezuroPlugin::ProjectContent end - def profile_tabs - if context.profile.community? && !MezuroPlugin::Project.by_profile(context.profile).blank? - MezuroPlugin::Project.by_profile(context.profile).with_tab.map do |project| - { :title => 'Mezuro ' + project.name, - :id => 'mezuro-project-'+project.identifier, - :content => lambda { render :partial => 'project_tab', :locals => {:current_project => project} } } - end - end + def view_path + File.join(RAILS_ROOT, "plugins", "mezuro", "views") end -end + def stylesheet? + true + end + + def js_files + 'javascripts/collapsable.js' + end + +end \ No newline at end of file diff --git a/plugins/mezuro/lib/mezuro_plugin/analizo_extractor.rb b/plugins/mezuro/lib/mezuro_plugin/analizo_extractor.rb deleted file mode 100644 index 43f1248..0000000 --- a/plugins/mezuro/lib/mezuro_plugin/analizo_extractor.rb +++ /dev/null @@ -1,43 +0,0 @@ -class MezuroPlugin::AnalizoExtractor < Noosfero::Plugin::ActiveRecord - attr_reader :string_output, :hash_output - - def initialize project - @project = project - end - - def perform - run_analizo - create_hash - save_metrics - end - - def run_analizo - project_path = "#{RAILS_ROOT}/tmp/#{@project.identifier}" - @string_output = `analizo metrics #{project_path}` - end - - def create_hash - @hash_output = {} - first_line = true - - @string_output.lines.each do |line| - if line =~ /---/ - if first_line - first_line = false - else - break - end - end - - if line =~ /(\S+): (~|(\d+)(\.\d+)?).*/ - @hash_output[$1.to_sym] = $2 - end - end - end - - def save_metrics - @hash_output.each do | key, value | - MezuroPlugin::Metric.create(:name => key.to_s, :value => value.to_f, :metricable => @project) - end - end -end diff --git a/plugins/mezuro/lib/mezuro_plugin/calculate_metrics_job.rb b/plugins/mezuro/lib/mezuro_plugin/calculate_metrics_job.rb deleted file mode 100644 index cb671b3..0000000 --- a/plugins/mezuro/lib/mezuro_plugin/calculate_metrics_job.rb +++ /dev/null @@ -1,7 +0,0 @@ -class MezuroPlugin::CalculateMetricsJob < Struct.new(:project_id) - def perform - project = MezuroPlugin::Project.find project_id - project.calculate_metrics - end -end - diff --git a/plugins/mezuro/lib/mezuro_plugin/metric.rb b/plugins/mezuro/lib/mezuro_plugin/metric.rb deleted file mode 100644 index f80f877..0000000 --- a/plugins/mezuro/lib/mezuro_plugin/metric.rb +++ /dev/null @@ -1,19 +0,0 @@ -class MezuroPlugin::Metric < Noosfero::Plugin::ActiveRecord - validates_presence_of :name, :metricable_id, :metricable_type - - belongs_to :metricable, :polymorphic => true - before_save :round_value - - def initialize params - params[:value] = nil if params[:value] == '~' - super params - end - - def round_value - if self.value - multiplied = self.value * 100 - rounded = multiplied.round - self.value = rounded / 100.0 - end - end -end diff --git a/plugins/mezuro/lib/mezuro_plugin/project.rb b/plugins/mezuro/lib/mezuro_plugin/project.rb deleted file mode 100644 index 7d2cd53..0000000 --- a/plugins/mezuro/lib/mezuro_plugin/project.rb +++ /dev/null @@ -1,76 +0,0 @@ -require 'svn/client' - -class MezuroPlugin::Project < Noosfero::Plugin::ActiveRecord - has_many :metrics, :as => :metricable - - validates_presence_of :name, :repository_url, :identifier - validates_format_of :identifier, :with => /^[a-z0-9|\-|\.]*$/, :message => "Identifier can only have a combination of lower case, number, hyphen and dot!" - validates_uniqueness_of :identifier - - named_scope :with_tab, :conditions => {:with_tab => true} - named_scope :by_profile, lambda {|profile| {:conditions => {:profile_id => profile.id}}} - - - after_create :asynchronous_calculate_metrics - - def calculate_metrics - begin - download_source_code - extractor = MezuroPlugin::AnalizoExtractor.new self - extractor.perform - rescue Svn::Error => error - update_attribute :svn_error, error.error_message - end - end - - def asynchronous_calculate_metrics - Delayed::Job.enqueue MezuroPlugin::CalculateMetricsJob.new(id) - end - - def download_source_code - download_prepare - Svn::Client::Context.new.checkout(repository_url, "#{RAILS_ROOT}/tmp/#{identifier}") - end - - def download_prepare - project_path = "#{RAILS_ROOT}/tmp/#{identifier}" - FileUtils.rm_r project_path if (File.exists? project_path) - end - - def metrics_calculated? - return !metrics.empty? - end - - def total_metrics - total_metrics = metrics.select do |metric| - metric.name.start_with?("total") - end - return total_metrics.sort_by {|metric| metric.name} - end - - def statistical_metrics - statistical_metrics = collect_statistical_metrics - - hash = {} - statistical_metrics.each do |metric| - insert_metric_in_hash metric, hash - end - hash - end - - def collect_statistical_metrics - statistical_metrics = metrics.select do |metric| - not metric.name.start_with?("total") - end - statistical_metrics.sort_by {|metric| metric.name} - end - - def insert_metric_in_hash metric, hash - metric_name, metric_statistic = metric.name.split("_") - unless hash.key?(metric_name) - hash[metric_name] = {metric_statistic => metric.value} - else - hash[metric_name][metric_statistic] = metric.value - end - end -end diff --git a/plugins/mezuro/lib/mezuro_plugin/project_content.rb b/plugins/mezuro/lib/mezuro_plugin/project_content.rb new file mode 100644 index 0000000..40d3d20 --- /dev/null +++ b/plugins/mezuro/lib/mezuro_plugin/project_content.rb @@ -0,0 +1,46 @@ +class MezuroPlugin::ProjectContent < Article + + def self.short_description + 'Kalibro project' + end + + def self.description + 'Software project tracked by Kalibro' + end + + settings_items :license, :description, :repository_type, :repository_url, :configuration_name + + include ActionView::Helpers::TagHelper + def to_html(options = {}) + lambda do + render :file => 'content_viewer/show_project.rhtml' + end + end + + after_save :send_project_to_service + + private + + def send_project_to_service + Kalibro::Client::ProjectClient.new.save(project) + end + + def project + project = Kalibro::Entities::Project.new + project.name = title + project.license = license + project.description = description + project.repository = repository + project.configuration_name = configuration_name + project + end + + def repository + repository = Kalibro::Entities::Repository.new + repository.type = repository_type + repository.address = repository_url + repository + end + +end + diff --git a/plugins/mezuro/lib/tasks/cucumber.rake b/plugins/mezuro/lib/tasks/cucumber.rake deleted file mode 100644 index e0bc4ab..0000000 --- a/plugins/mezuro/lib/tasks/cucumber.rake +++ /dev/null @@ -1,47 +0,0 @@ -# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril. -# It is recommended to regenerate this file in the future when you upgrade to a -# newer version of cucumber-rails. Consider adding your own code to a new file -# instead of editing this one. Cucumber will automatically load all features/**/*.rb -# files. - - -unless ARGV.any? {|a| a =~ /^gems/} # Don't load anything when running the gems:* tasks - -vendored_cucumber_bin = Dir["#{Rails.root}/vendor/{gems,plugins}/cucumber*/bin/cucumber"].first -$LOAD_PATH.unshift(File.dirname(vendored_cucumber_bin) + '/../lib') unless vendored_cucumber_bin.nil? - -begin - require 'cucumber/rake/task' - - namespace :cucumber do - Cucumber::Rake::Task.new({:ok => 'db:test:prepare'}, 'Run features that should pass') do |t| - t.binary = vendored_cucumber_bin # If nil, the gem's binary is used. - t.fork = true # You may get faster startup if you set this to false - t.profile = 'default' - end - - Cucumber::Rake::Task.new({:wip => 'db:test:prepare'}, 'Run features that are being worked on') do |t| - t.binary = vendored_cucumber_bin - t.fork = true # You may get faster startup if you set this to false - t.profile = 'wip' - end - - desc 'Run all features' - task :all => [:ok, :wip] - end - desc 'Alias for cucumber:ok' - task :cucumber => 'cucumber:ok' - - task :default => :cucumber - - task :features => :cucumber do - STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***" - end -rescue LoadError - desc 'cucumber rake task not available (cucumber not installed)' - task :cucumber do - abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin' - end -end - -end diff --git a/plugins/mezuro/lib/tasks/rspec.rake b/plugins/mezuro/lib/tasks/rspec.rake deleted file mode 100644 index dba3ffc..0000000 --- a/plugins/mezuro/lib/tasks/rspec.rake +++ /dev/null @@ -1,144 +0,0 @@ -gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9 -rspec_gem_dir = nil -Dir["#{RAILS_ROOT}/vendor/gems/*"].each do |subdir| - rspec_gem_dir = subdir if subdir.gsub("#{RAILS_ROOT}/vendor/gems/","") =~ /^(\w+-)?rspec-(\d+)/ && File.exist?("#{subdir}/lib/spec/rake/spectask.rb") -end -rspec_plugin_dir = File.expand_path(File.dirname(__FILE__) + '/../../vendor/plugins/rspec') - -if rspec_gem_dir && (test ?d, rspec_plugin_dir) - raise "\n#{'*'*50}\nYou have rspec installed in both vendor/gems and vendor/plugins\nPlease pick one and dispose of the other.\n#{'*'*50}\n\n" -end - -if rspec_gem_dir - $LOAD_PATH.unshift("#{rspec_gem_dir}/lib") -elsif File.exist?(rspec_plugin_dir) - $LOAD_PATH.unshift("#{rspec_plugin_dir}/lib") -end - -# Don't load rspec if running "rake gems:*" -unless ARGV.any? {|a| a =~ /^gems/} - -begin - require 'spec/rake/spectask' -rescue MissingSourceFile - module Spec - module Rake - class SpecTask - def initialize(name) - task name do - # if rspec-rails is a configured gem, this will output helpful material and exit ... - require File.expand_path(File.join(File.dirname(__FILE__),"..","..","config","environment")) - - # ... otherwise, do this: - raise <<-MSG - -#{"*" * 80} -* You are trying to run an rspec rake task defined in -* #{__FILE__}, -* but rspec can not be found in vendor/gems, vendor/plugins or system gems. -#{"*" * 80} -MSG - end - end - end - end - end -end - -Rake.application.instance_variable_get('@tasks').delete('default') - -spec_prereq = File.exist?(File.join(RAILS_ROOT, 'config', 'database.yml')) ? "db:test:prepare" : :noop -task :noop do -end - -task :default => :spec -task :stats => "spec:statsetup" - -desc "Run all specs in spec directory (excluding plugin specs)" -Spec::Rake::SpecTask.new(:spec => spec_prereq) do |t| - t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""] - t.spec_files = FileList['spec/**/*_spec.rb'] -end - -namespace :spec do - desc "Run all specs in spec directory with RCov (excluding plugin specs)" - Spec::Rake::SpecTask.new(:rcov) do |t| - t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""] - t.spec_files = FileList['spec/**/*_spec.rb'] - t.rcov = true - t.rcov_opts = lambda do - IO.readlines("#{RAILS_ROOT}/spec/rcov.opts").map {|l| l.chomp.split " "}.flatten - end - end - - desc "Print Specdoc for all specs (excluding plugin specs)" - Spec::Rake::SpecTask.new(:doc) do |t| - t.spec_opts = ["--format", "specdoc", "--dry-run"] - t.spec_files = FileList['spec/**/*_spec.rb'] - end - - desc "Print Specdoc for all plugin examples" - Spec::Rake::SpecTask.new(:plugin_doc) do |t| - t.spec_opts = ["--format", "specdoc", "--dry-run"] - t.spec_files = FileList['vendor/plugins/**/spec/**/*_spec.rb'].exclude('vendor/plugins/rspec/*') - end - - [:models, :controllers, :views, :helpers, :lib, :integration].each do |sub| - desc "Run the code examples in spec/#{sub}" - Spec::Rake::SpecTask.new(sub => spec_prereq) do |t| - t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""] - t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"] - end - end - - desc "Run the code examples in vendor/plugins (except RSpec's own)" - Spec::Rake::SpecTask.new(:plugins => spec_prereq) do |t| - t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""] - t.spec_files = FileList['vendor/plugins/**/spec/**/*_spec.rb'].exclude('vendor/plugins/rspec/*').exclude("vendor/plugins/rspec-rails/*") - end - - namespace :plugins do - desc "Runs the examples for rspec_on_rails" - Spec::Rake::SpecTask.new(:rspec_on_rails) do |t| - t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""] - t.spec_files = FileList['vendor/plugins/rspec-rails/spec/**/*_spec.rb'] - end - end - - # Setup specs for stats - task :statsetup do - require 'code_statistics' - ::STATS_DIRECTORIES << %w(Model\ specs spec/models) if File.exist?('spec/models') - ::STATS_DIRECTORIES << %w(View\ specs spec/views) if File.exist?('spec/views') - ::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers) if File.exist?('spec/controllers') - ::STATS_DIRECTORIES << %w(Helper\ specs spec/helpers) if File.exist?('spec/helpers') - ::STATS_DIRECTORIES << %w(Library\ specs spec/lib) if File.exist?('spec/lib') - ::STATS_DIRECTORIES << %w(Routing\ specs spec/routing) if File.exist?('spec/routing') - ::STATS_DIRECTORIES << %w(Integration\ specs spec/integration) if File.exist?('spec/integration') - ::CodeStatistics::TEST_TYPES << "Model specs" if File.exist?('spec/models') - ::CodeStatistics::TEST_TYPES << "View specs" if File.exist?('spec/views') - ::CodeStatistics::TEST_TYPES << "Controller specs" if File.exist?('spec/controllers') - ::CodeStatistics::TEST_TYPES << "Helper specs" if File.exist?('spec/helpers') - ::CodeStatistics::TEST_TYPES << "Library specs" if File.exist?('spec/lib') - ::CodeStatistics::TEST_TYPES << "Routing specs" if File.exist?('spec/routing') - ::CodeStatistics::TEST_TYPES << "Integration specs" if File.exist?('spec/integration') - end - - namespace :db do - namespace :fixtures do - desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y. Load from subdirectory in test/fixtures using FIXTURES_DIR=z." - task :load => :environment do - ActiveRecord::Base.establish_connection(Rails.env) - base_dir = File.join(Rails.root, 'spec', 'fixtures') - fixtures_dir = ENV['FIXTURES_DIR'] ? File.join(base_dir, ENV['FIXTURES_DIR']) : base_dir - - require 'active_record/fixtures' - (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/).map {|f| File.join(fixtures_dir, f) } : Dir.glob(File.join(fixtures_dir, '*.{yml,csv}'))).each do |fixture_file| - Fixtures.create_fixtures(File.dirname(fixture_file), File.basename(fixture_file, '.*')) - end - end - end - end -end - -end -- libgit2 0.21.2