Commit 1bad209b01c3fa730905e879fa22cc9646a6bd5c

Authored by Carlos Morais
Committed by Paulo Meireles
1 parent 0e272fb7

Replacing old lib directory

Showing 33 changed files with 531 additions and 349 deletions   Show diff stats
plugins/mezuro/lib/kalibro/client/base_tool_client.rb 0 → 100644
... ... @@ -0,0 +1,16 @@
  1 +class Kalibro::Client::BaseToolClient
  2 +
  3 + def initialize
  4 + @port = Kalibro::Client::Port.new('BaseTool')
  5 + end
  6 +
  7 + def base_tool_names
  8 + @port.request(:get_base_tool_names)[:base_tool_name].to_a
  9 + end
  10 +
  11 + def base_tool(name)
  12 + hash = @port.request(:get_base_tool, {:base_tool_name => name})[:base_tool]
  13 + Kalibro::Entities::BaseTool.from_hash(hash)
  14 + end
  15 +
  16 +end
0 17 \ No newline at end of file
... ...
plugins/mezuro/lib/kalibro/client/configuration_client.rb 0 → 100644
... ... @@ -0,0 +1,24 @@
  1 +class Kalibro::Client::ConfigurationClient
  2 +
  3 + def initialize
  4 + @port = Kalibro::Client::Port.new('Configuration')
  5 + end
  6 +
  7 + def save(configuration)
  8 + @port.request(:save_configuration, {:configuration => configuration.to_hash})
  9 + end
  10 +
  11 + def configuration_names
  12 + @port.request(:get_configuration_names)[:configuration_name].to_a
  13 + end
  14 +
  15 + def configuration(name)
  16 + hash = @port.request(:get_configuration, {:configuration_name => name})[:configuration]
  17 + Kalibro::Entities::Configuration.from_hash(hash)
  18 + end
  19 +
  20 + def remove(configuration_name)
  21 + @port.request(:remove_configuration, {:configuration_name => configuration_name})
  22 + end
  23 +
  24 +end
0 25 \ No newline at end of file
... ...
plugins/mezuro/lib/kalibro/client/kalibro_client.rb 0 → 100644
... ... @@ -0,0 +1,15 @@
  1 +class Kalibro::Client::KalibroClient
  2 +
  3 + def initialize
  4 + @port = Kalibro::Client::Port.new('Kalibro')
  5 + end
  6 +
  7 + def supported_repository_types
  8 + @port.request(:get_supported_repository_types)[:repository_type].to_a
  9 + end
  10 +
  11 + def process_project(project_name)
  12 + @port.request(:process_project, {:project_name => project_name})
  13 + end
  14 +
  15 +end
0 16 \ No newline at end of file
... ...
plugins/mezuro/lib/kalibro/client/module_result_client.rb 0 → 100644
... ... @@ -0,0 +1,19 @@
  1 +class Kalibro::Client::ModuleResultClient
  2 +
  3 + def initialize
  4 + @port = Kalibro::Client::Port.new('ModuleResult')
  5 + end
  6 +
  7 + def module_result(project_name, module_name, date)
  8 + hash = @port.request(:get_module_result,
  9 + {:project_name => project_name, :module_name => module_name, :date => date})[:module_result]
  10 + Kalibro::Entities::ModuleResult.from_hash(hash)
  11 + end
  12 +
  13 + def result_history(project_name, module_name)
  14 + value = @port.request(:get_result_history,
  15 + {:project_name => project_name, :module_name => module_name})[:module_result]
  16 + Kalibro::Entities::Entity.new.to_entity_array(value, Kalibro::Entities::ModuleResult)
  17 + end
  18 +
  19 +end
0 20 \ No newline at end of file
... ...
plugins/mezuro/lib/kalibro/client/port.rb 0 → 100644
... ... @@ -0,0 +1,24 @@
  1 +require 'savon'
  2 +
  3 +class Kalibro::Client::Port
  4 +
  5 + @@service_address = 'http://valinhos.ime.usp.br:50688/KalibroService/'
  6 +
  7 + def self.service_address
  8 + @@service_address
  9 + end
  10 +
  11 + def self.service_address=(service_address)
  12 + @@service_address = service_address
  13 + end
  14 +
  15 + def initialize(endpoint)
  16 + @client = Savon::Client.new("#{@@service_address}#{endpoint}Endpoint/?wsdl")
  17 + end
  18 +
  19 + def request(action, request_body = nil)
  20 + response = @client.request(:kalibro, action) { soap.body = request_body }
  21 + response.to_hash["#{action}_response".to_sym]
  22 + end
  23 +
  24 +end
0 25 \ No newline at end of file
... ...
plugins/mezuro/lib/kalibro/client/project_client.rb 0 → 100644
... ... @@ -0,0 +1,24 @@
  1 +class Kalibro::Client::ProjectClient
  2 +
  3 + def initialize
  4 + @port = Kalibro::Client::Port.new('Project')
  5 + end
  6 +
  7 + def save(project)
  8 + @port.request(:save_project, {:project => project.to_hash})
  9 + end
  10 +
  11 + def project_names
  12 + @port.request(:get_project_names)[:project_name].to_a
  13 + end
  14 +
  15 + def project(name)
  16 + hash = @port.request(:get_project, {:project_name => name})[:project]
  17 + Kalibro::Entities::Project.from_hash(hash)
  18 + end
  19 +
  20 + def remove(project_name)
  21 + @port.request(:remove_project, {:project_name => project_name})
  22 + end
  23 +
  24 +end
0 25 \ No newline at end of file
... ...
plugins/mezuro/lib/kalibro/client/project_result_client.rb 0 → 100644
... ... @@ -0,0 +1,41 @@
  1 +class Kalibro::Client::ProjectResultClient
  2 +
  3 + def initialize
  4 + @port = Kalibro::Client::Port.new('ProjectResult')
  5 + end
  6 +
  7 + def has_results_for(project_name)
  8 + @port.request(:has_results_for, {:project_name => project_name})[:has_results]
  9 + end
  10 +
  11 + def has_results_before(project_name, date)
  12 + @port.request(:has_results_before, {:project_name => project_name, :date => date})[:has_results]
  13 + end
  14 +
  15 + def has_results_after(project_name, date)
  16 + @port.request(:has_results_after, {:project_name => project_name, :date => date})[:has_results]
  17 + end
  18 +
  19 + def first_result(project_name)
  20 + hash = @port.request(:get_first_result_of, {:project_name => project_name})[:project_result]
  21 + Kalibro::Entities::ProjectResult.from_hash(hash)
  22 + end
  23 +
  24 + def last_result(project_name)
  25 + hash = @port.request(:get_last_result_of, {:project_name => project_name})[:project_result]
  26 + Kalibro::Entities::ProjectResult.from_hash(hash)
  27 + end
  28 +
  29 + def first_result_after(project_name, date)
  30 + request_body = {:project_name => project_name, :date => date}
  31 + hash = @port.request(:get_first_result_after, request_body)[:project_result]
  32 + Kalibro::Entities::ProjectResult.from_hash(hash)
  33 + end
  34 +
  35 + def last_result_before(project_name, date)
  36 + request_body = {:project_name => project_name, :date => date}
  37 + hash = @port.request(:get_last_result_before, request_body)[:project_result]
  38 + Kalibro::Entities::ProjectResult.from_hash(hash)
  39 + end
  40 +
  41 +end
0 42 \ No newline at end of file
... ...
plugins/mezuro/lib/kalibro/entities/base_tool.rb 0 → 100644
... ... @@ -0,0 +1,17 @@
  1 +class Kalibro::Entities::BaseTool < Kalibro::Entities::Entity
  2 +
  3 + attr_accessor :name, :description, :supported_metric
  4 +
  5 + def supported_metric=(value)
  6 + @supported_metric = to_entity_array(value, Kalibro::Entities::NativeMetric)
  7 + end
  8 +
  9 + def supported_metrics
  10 + @supported_metric
  11 + end
  12 +
  13 + def supported_metrics=(supported_metrics)
  14 + @supported_metric = supported_metrics
  15 + end
  16 +
  17 +end
0 18 \ No newline at end of file
... ...
plugins/mezuro/lib/kalibro/entities/compound_metric.rb 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +class Kalibro::Entities::CompoundMetric < Kalibro::Entities::Metric
  2 +
  3 + attr_accessor :script
  4 +
  5 +end
0 6 \ No newline at end of file
... ...
plugins/mezuro/lib/kalibro/entities/compound_metric_with_error.rb 0 → 100644
... ... @@ -0,0 +1,13 @@
  1 +class Kalibro::Entities::CompoundMetricWithError < Kalibro::Entities::Entity
  2 +
  3 + attr_accessor :metric, :error
  4 +
  5 + def metric=(value)
  6 + @metric = to_entity(value, Kalibro::Entities::CompoundMetric)
  7 + end
  8 +
  9 + def error=(value)
  10 + @error = to_entity(value, Kalibro::Entities::Error)
  11 + end
  12 +
  13 +end
0 14 \ No newline at end of file
... ...
plugins/mezuro/lib/kalibro/entities/configuration.rb 0 → 100644
... ... @@ -0,0 +1,17 @@
  1 +class Kalibro::Entities::Configuration < Kalibro::Entities::Entity
  2 +
  3 + attr_accessor :name, :description, :metric_configuration
  4 +
  5 + def metric_configuration=(value)
  6 + @metric_configuration = to_entity_array(value, Kalibro::Entities::MetricConfiguration)
  7 + end
  8 +
  9 + def metric_configurations
  10 + @metric_configuration
  11 + end
  12 +
  13 + def metric_configurations=(metric_configurations)
  14 + @metric_configuration = metric_configurations
  15 + end
  16 +
  17 +end
0 18 \ No newline at end of file
... ...
plugins/mezuro/lib/kalibro/entities/entity.rb 0 → 100644
... ... @@ -0,0 +1,53 @@
  1 +class Kalibro::Entities::Entity
  2 +
  3 + def self.from_hash(hash)
  4 + entity = self.new
  5 + hash.each { |field, value| entity.set(field, value) }
  6 + entity
  7 + end
  8 +
  9 + def set(field, value)
  10 + send("#{field}=", value)
  11 + end
  12 +
  13 + def to_entity_array(value, entity_class = nil)
  14 + array = value.kind_of?(Array) ? value : [value]
  15 + array.each.collect { |element| to_entity(element, entity_class) }
  16 + end
  17 +
  18 + def to_entity(value, entity_class)
  19 + value.kind_of?(Hash) ? entity_class.from_hash(value) : value
  20 + end
  21 +
  22 + def to_hash
  23 + hash = Hash.new
  24 + fields.each do |field|
  25 + field_value = self.get(field)
  26 + hash[field] = convert_to_hash(field_value) if ! field_value.nil?
  27 + end
  28 + hash
  29 + end
  30 +
  31 + def convert_to_hash(value)
  32 + return value.collect { |element| convert_to_hash(element) } if value.kind_of?(Array)
  33 + return value.to_hash if value.kind_of?(Kalibro::Entities::Entity)
  34 + value
  35 + end
  36 +
  37 + def ==(other)
  38 + begin
  39 + fields.each.inject(true) { |equal, field| equal && (self.get(field) == other.get(field)) }
  40 + rescue NoMethodError
  41 + false
  42 + end
  43 + end
  44 +
  45 + def fields
  46 + instance_variable_names.each.collect { |variable| variable.to_s.sub(/@/, '').to_sym }
  47 + end
  48 +
  49 + def get(field)
  50 + send("#{field}")
  51 + end
  52 +
  53 +end
0 54 \ No newline at end of file
... ...
plugins/mezuro/lib/kalibro/entities/error.rb 0 → 100644
... ... @@ -0,0 +1,17 @@
  1 +class Kalibro::Entities::Error < Kalibro::Entities::Entity
  2 +
  3 + attr_accessor :message, :stack_trace_element
  4 +
  5 + def stack_trace_element=(value)
  6 + @stack_trace_element = to_entity_array(value, Kalibro::Entities::StackTraceElement)
  7 + end
  8 +
  9 + def stack_trace
  10 + @stack_trace_element
  11 + end
  12 +
  13 + def stack_trace=(stack_trace)
  14 + @stack_trace_element = stack_trace
  15 + end
  16 +
  17 +end
0 18 \ No newline at end of file
... ...
plugins/mezuro/lib/kalibro/entities/metric.rb 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +class Kalibro::Entities::Metric < Kalibro::Entities::Entity
  2 +
  3 + attr_accessor :name, :scope, :description
  4 +
  5 +end
0 6 \ No newline at end of file
... ...
plugins/mezuro/lib/kalibro/entities/metric_configuration.rb 0 → 100644
... ... @@ -0,0 +1,26 @@
  1 +class Kalibro::Entities::MetricConfiguration < Kalibro::Entities::Entity
  2 +
  3 + attr_accessor :metric, :code, :weight, :aggregation_form, :range
  4 +
  5 + def metric=(value)
  6 + if value.kind_of?(Hash)
  7 + @metric = to_entity(value, Kalibro::Entities::CompoundMetric) if value.has_key?(:script)
  8 + @metric = to_entity(value, Kalibro::Entities::NativeMetric) if value.has_key?(:origin)
  9 + else
  10 + @metric = value
  11 + end
  12 + end
  13 +
  14 + def range=(value)
  15 + @range = to_entity_array(value, Kalibro::Entities::Range)
  16 + end
  17 +
  18 + def ranges
  19 + @range
  20 + end
  21 +
  22 + def ranges=(ranges)
  23 + @range = ranges
  24 + end
  25 +
  26 +end
0 27 \ No newline at end of file
... ...
plugins/mezuro/lib/kalibro/entities/metric_result.rb 0 → 100644
... ... @@ -0,0 +1,30 @@
  1 +class Kalibro::Entities::MetricResult < Kalibro::Entities::Entity
  2 +
  3 + attr_accessor :metric, :value, :range, :descendent_result
  4 +
  5 + def metric=(value)
  6 + if value.kind_of?(Hash)
  7 + @metric = to_entity(value, Kalibro::Entities::CompoundMetric) if value.has_key?(:script)
  8 + @metric = to_entity(value, Kalibro::Entities::NativeMetric) if value.has_key?(:origin)
  9 + else
  10 + @metric = value
  11 + end
  12 + end
  13 +
  14 + def range=(value)
  15 + @range = to_entity(value, Kalibro::Entities::Range)
  16 + end
  17 +
  18 + def descendent_result=(value)
  19 + @descendent_result = to_entity_array(value)
  20 + end
  21 +
  22 + def descendent_results
  23 + @descendent_result
  24 + end
  25 +
  26 + def descendent_results=(descendent_results)
  27 + @descendent_result = descendent_results
  28 + end
  29 +
  30 +end
0 31 \ No newline at end of file
... ...
plugins/mezuro/lib/kalibro/entities/module.rb 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +class Kalibro::Entities::Module < Kalibro::Entities::Entity
  2 +
  3 + attr_accessor :name, :granularity
  4 +
  5 +end
0 6 \ No newline at end of file
... ...
plugins/mezuro/lib/kalibro/entities/module_node.rb 0 → 100644
... ... @@ -0,0 +1,21 @@
  1 +class Kalibro::Entities::ModuleNode < Kalibro::Entities::Entity
  2 +
  3 + attr_accessor :module, :child
  4 +
  5 + def module=(value)
  6 + @module = to_entity(value, Kalibro::Entities::Module)
  7 + end
  8 +
  9 + def child=(value)
  10 + @child = to_entity_array(value, Kalibro::Entities::ModuleNode)
  11 + end
  12 +
  13 + def children
  14 + @child
  15 + end
  16 +
  17 + def children=(children)
  18 + @child = children
  19 + end
  20 +
  21 +end
0 22 \ No newline at end of file
... ...
plugins/mezuro/lib/kalibro/entities/module_result.rb 0 → 100644
... ... @@ -0,0 +1,33 @@
  1 +class Kalibro::Entities::ModuleResult < Kalibro::Entities::Entity
  2 +
  3 + attr_accessor :module, :date, :grade, :metric_result, :compound_metric_with_error
  4 +
  5 + def module=(value)
  6 + @module = to_entity(value, Kalibro::Entities::Module)
  7 + end
  8 +
  9 + def metric_result=(value)
  10 + @metric_result = to_entity_array(value, Kalibro::Entities::MetricResult)
  11 + end
  12 +
  13 + def metric_results
  14 + @metric_result
  15 + end
  16 +
  17 + def metric_results=(metric_results)
  18 + @metric_result = metric_results
  19 + end
  20 +
  21 + def compound_metric_with_error=(value)
  22 + @compound_metric_with_error = to_entity_array(value, Kalibro::Entities::CompoundMetricWithError)
  23 + end
  24 +
  25 + def compound_metrics_with_error
  26 + @compound_metric_with_error
  27 + end
  28 +
  29 + def compound_metrics_with_error=(compound_metrics_with_error)
  30 + @compound_metric_with_error = compound_metrics_with_error
  31 + end
  32 +
  33 +end
0 34 \ No newline at end of file
... ...
plugins/mezuro/lib/kalibro/entities/native_metric.rb 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +class Kalibro::Entities::NativeMetric < Kalibro::Entities::Metric
  2 +
  3 + attr_accessor :origin, :language
  4 +
  5 +end
0 6 \ No newline at end of file
... ...
plugins/mezuro/lib/kalibro/entities/project.rb 0 → 100644
... ... @@ -0,0 +1,13 @@
  1 +class Kalibro::Entities::Project < Kalibro::Entities::Entity
  2 +
  3 + attr_accessor :name, :license, :description, :repository, :configuration_name, :state, :error
  4 +
  5 + def repository=(value)
  6 + @repository = to_entity(value, Kalibro::Entities::Repository)
  7 + end
  8 +
  9 + def error=(value)
  10 + @error = to_entity(value, Kalibro::Entities::Error)
  11 + end
  12 +
  13 +end
0 14 \ No newline at end of file
... ...
plugins/mezuro/lib/kalibro/entities/project_result.rb 0 → 100644
... ... @@ -0,0 +1,34 @@
  1 +class Kalibro::Entities::ProjectResult < Kalibro::Entities::Entity
  2 +
  3 + attr_accessor :project, :date, :load_time, :analysis_time, :source_tree
  4 +
  5 + def project=(value)
  6 + @project = to_entity(value, Kalibro::Entities::Project)
  7 + end
  8 +
  9 + def source_tree=(value)
  10 + @source_tree = to_entity(value, Kalibro::Entities::ModuleNode)
  11 + end
  12 +
  13 + def formatted_load_time
  14 + format_milliseconds(@load_time)
  15 + end
  16 +
  17 + def formatted_analysis_time
  18 + format_milliseconds(@analysis_time)
  19 + end
  20 +
  21 + def format_milliseconds(value)
  22 + seconds = value/1000
  23 + hours = seconds/3600
  24 + seconds -= hours * 3600
  25 + minutes = seconds/60
  26 + seconds -= minutes * 60
  27 + "#{format(hours)}:#{format(minutes)}:#{format(seconds)}"
  28 + end
  29 +
  30 + def format(amount)
  31 + ('%2d' % amount).sub(/\s/, '0')
  32 + end
  33 +
  34 +end
0 35 \ No newline at end of file
... ...
plugins/mezuro/lib/kalibro/entities/range.rb 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +class Kalibro::Entities::Range < Kalibro::Entities::Entity
  2 +
  3 + attr_accessor :beginning, :end, :label, :grade, :color, :comments
  4 +
  5 +end
0 6 \ No newline at end of file
... ...
plugins/mezuro/lib/kalibro/entities/repository.rb 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +class Kalibro::Entities::Repository < Kalibro::Entities::Entity
  2 +
  3 + attr_accessor :type, :address, :username, :password
  4 +
  5 +end
0 6 \ No newline at end of file
... ...
plugins/mezuro/lib/kalibro/entities/stack_trace_element.rb 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +class Kalibro::Entities::StackTraceElement < Kalibro::Entities::Entity
  2 +
  3 + attr_accessor :declaring_class, :method_name, :file_name, :line_number
  4 +
  5 +end
0 6 \ No newline at end of file
... ...
plugins/mezuro/lib/mezuro_plugin.rb
... ... @@ -8,20 +8,20 @@ class MezuroPlugin &lt; Noosfero::Plugin
8 8 _("A metric analizer plugin.")
9 9 end
10 10  
11   - def control_panel_buttons
12   - if context.profile.community?
13   - { :title => 'Mezuro projects', :icon => 'mezuro', :url => {:controller => 'mezuro_plugin_myprofile', :action => 'index'} }
14   - end
  11 + def content_types
  12 + MezuroPlugin::ProjectContent
15 13 end
16 14  
17   - def profile_tabs
18   - if context.profile.community? && !MezuroPlugin::Project.by_profile(context.profile).blank?
19   - MezuroPlugin::Project.by_profile(context.profile).with_tab.map do |project|
20   - { :title => 'Mezuro ' + project.name,
21   - :id => 'mezuro-project-'+project.identifier,
22   - :content => lambda { render :partial => 'project_tab', :locals => {:current_project => project} } }
23   - end
24   - end
  15 + def view_path
  16 + File.join(RAILS_ROOT, "plugins", "mezuro", "views")
25 17 end
26 18  
27   -end
  19 + def stylesheet?
  20 + true
  21 + end
  22 +
  23 + def js_files
  24 + 'javascripts/collapsable.js'
  25 + end
  26 +
  27 +end
28 28 \ No newline at end of file
... ...
plugins/mezuro/lib/mezuro_plugin/analizo_extractor.rb
... ... @@ -1,43 +0,0 @@
1   -class MezuroPlugin::AnalizoExtractor < Noosfero::Plugin::ActiveRecord
2   - attr_reader :string_output, :hash_output
3   -
4   - def initialize project
5   - @project = project
6   - end
7   -
8   - def perform
9   - run_analizo
10   - create_hash
11   - save_metrics
12   - end
13   -
14   - def run_analizo
15   - project_path = "#{RAILS_ROOT}/tmp/#{@project.identifier}"
16   - @string_output = `analizo metrics #{project_path}`
17   - end
18   -
19   - def create_hash
20   - @hash_output = {}
21   - first_line = true
22   -
23   - @string_output.lines.each do |line|
24   - if line =~ /---/
25   - if first_line
26   - first_line = false
27   - else
28   - break
29   - end
30   - end
31   -
32   - if line =~ /(\S+): (~|(\d+)(\.\d+)?).*/
33   - @hash_output[$1.to_sym] = $2
34   - end
35   - end
36   - end
37   -
38   - def save_metrics
39   - @hash_output.each do | key, value |
40   - MezuroPlugin::Metric.create(:name => key.to_s, :value => value.to_f, :metricable => @project)
41   - end
42   - end
43   -end
plugins/mezuro/lib/mezuro_plugin/calculate_metrics_job.rb
... ... @@ -1,7 +0,0 @@
1   -class MezuroPlugin::CalculateMetricsJob < Struct.new(:project_id)
2   - def perform
3   - project = MezuroPlugin::Project.find project_id
4   - project.calculate_metrics
5   - end
6   -end
7   -
plugins/mezuro/lib/mezuro_plugin/metric.rb
... ... @@ -1,19 +0,0 @@
1   -class MezuroPlugin::Metric < Noosfero::Plugin::ActiveRecord
2   - validates_presence_of :name, :metricable_id, :metricable_type
3   -
4   - belongs_to :metricable, :polymorphic => true
5   - before_save :round_value
6   -
7   - def initialize params
8   - params[:value] = nil if params[:value] == '~'
9   - super params
10   - end
11   -
12   - def round_value
13   - if self.value
14   - multiplied = self.value * 100
15   - rounded = multiplied.round
16   - self.value = rounded / 100.0
17   - end
18   - end
19   -end
plugins/mezuro/lib/mezuro_plugin/project.rb
... ... @@ -1,76 +0,0 @@
1   -require 'svn/client'
2   -
3   -class MezuroPlugin::Project < Noosfero::Plugin::ActiveRecord
4   - has_many :metrics, :as => :metricable
5   -
6   - validates_presence_of :name, :repository_url, :identifier
7   - validates_format_of :identifier, :with => /^[a-z0-9|\-|\.]*$/, :message => "Identifier can only have a combination of lower case, number, hyphen and dot!"
8   - validates_uniqueness_of :identifier
9   -
10   - named_scope :with_tab, :conditions => {:with_tab => true}
11   - named_scope :by_profile, lambda {|profile| {:conditions => {:profile_id => profile.id}}}
12   -
13   -
14   - after_create :asynchronous_calculate_metrics
15   -
16   - def calculate_metrics
17   - begin
18   - download_source_code
19   - extractor = MezuroPlugin::AnalizoExtractor.new self
20   - extractor.perform
21   - rescue Svn::Error => error
22   - update_attribute :svn_error, error.error_message
23   - end
24   - end
25   -
26   - def asynchronous_calculate_metrics
27   - Delayed::Job.enqueue MezuroPlugin::CalculateMetricsJob.new(id)
28   - end
29   -
30   - def download_source_code
31   - download_prepare
32   - Svn::Client::Context.new.checkout(repository_url, "#{RAILS_ROOT}/tmp/#{identifier}")
33   - end
34   -
35   - def download_prepare
36   - project_path = "#{RAILS_ROOT}/tmp/#{identifier}"
37   - FileUtils.rm_r project_path if (File.exists? project_path)
38   - end
39   -
40   - def metrics_calculated?
41   - return !metrics.empty?
42   - end
43   -
44   - def total_metrics
45   - total_metrics = metrics.select do |metric|
46   - metric.name.start_with?("total")
47   - end
48   - return total_metrics.sort_by {|metric| metric.name}
49   - end
50   -
51   - def statistical_metrics
52   - statistical_metrics = collect_statistical_metrics
53   -
54   - hash = {}
55   - statistical_metrics.each do |metric|
56   - insert_metric_in_hash metric, hash
57   - end
58   - hash
59   - end
60   -
61   - def collect_statistical_metrics
62   - statistical_metrics = metrics.select do |metric|
63   - not metric.name.start_with?("total")
64   - end
65   - statistical_metrics.sort_by {|metric| metric.name}
66   - end
67   -
68   - def insert_metric_in_hash metric, hash
69   - metric_name, metric_statistic = metric.name.split("_")
70   - unless hash.key?(metric_name)
71   - hash[metric_name] = {metric_statistic => metric.value}
72   - else
73   - hash[metric_name][metric_statistic] = metric.value
74   - end
75   - end
76   -end
plugins/mezuro/lib/mezuro_plugin/project_content.rb 0 → 100644
... ... @@ -0,0 +1,46 @@
  1 +class MezuroPlugin::ProjectContent < Article
  2 +
  3 + def self.short_description
  4 + 'Kalibro project'
  5 + end
  6 +
  7 + def self.description
  8 + 'Software project tracked by Kalibro'
  9 + end
  10 +
  11 + settings_items :license, :description, :repository_type, :repository_url, :configuration_name
  12 +
  13 + include ActionView::Helpers::TagHelper
  14 + def to_html(options = {})
  15 + lambda do
  16 + render :file => 'content_viewer/show_project.rhtml'
  17 + end
  18 + end
  19 +
  20 + after_save :send_project_to_service
  21 +
  22 + private
  23 +
  24 + def send_project_to_service
  25 + Kalibro::Client::ProjectClient.new.save(project)
  26 + end
  27 +
  28 + def project
  29 + project = Kalibro::Entities::Project.new
  30 + project.name = title
  31 + project.license = license
  32 + project.description = description
  33 + project.repository = repository
  34 + project.configuration_name = configuration_name
  35 + project
  36 + end
  37 +
  38 + def repository
  39 + repository = Kalibro::Entities::Repository.new
  40 + repository.type = repository_type
  41 + repository.address = repository_url
  42 + repository
  43 + end
  44 +
  45 +end
  46 +
... ...
plugins/mezuro/lib/tasks/cucumber.rake
... ... @@ -1,47 +0,0 @@
1   -# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
2   -# It is recommended to regenerate this file in the future when you upgrade to a
3   -# newer version of cucumber-rails. Consider adding your own code to a new file
4   -# instead of editing this one. Cucumber will automatically load all features/**/*.rb
5   -# files.
6   -
7   -
8   -unless ARGV.any? {|a| a =~ /^gems/} # Don't load anything when running the gems:* tasks
9   -
10   -vendored_cucumber_bin = Dir["#{Rails.root}/vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
11   -$LOAD_PATH.unshift(File.dirname(vendored_cucumber_bin) + '/../lib') unless vendored_cucumber_bin.nil?
12   -
13   -begin
14   - require 'cucumber/rake/task'
15   -
16   - namespace :cucumber do
17   - Cucumber::Rake::Task.new({:ok => 'db:test:prepare'}, 'Run features that should pass') do |t|
18   - t.binary = vendored_cucumber_bin # If nil, the gem's binary is used.
19   - t.fork = true # You may get faster startup if you set this to false
20   - t.profile = 'default'
21   - end
22   -
23   - Cucumber::Rake::Task.new({:wip => 'db:test:prepare'}, 'Run features that are being worked on') do |t|
24   - t.binary = vendored_cucumber_bin
25   - t.fork = true # You may get faster startup if you set this to false
26   - t.profile = 'wip'
27   - end
28   -
29   - desc 'Run all features'
30   - task :all => [:ok, :wip]
31   - end
32   - desc 'Alias for cucumber:ok'
33   - task :cucumber => 'cucumber:ok'
34   -
35   - task :default => :cucumber
36   -
37   - task :features => :cucumber do
38   - STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***"
39   - end
40   -rescue LoadError
41   - desc 'cucumber rake task not available (cucumber not installed)'
42   - task :cucumber do
43   - abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
44   - end
45   -end
46   -
47   -end
plugins/mezuro/lib/tasks/rspec.rake
... ... @@ -1,144 +0,0 @@
1   -gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9
2   -rspec_gem_dir = nil
3   -Dir["#{RAILS_ROOT}/vendor/gems/*"].each do |subdir|
4   - rspec_gem_dir = subdir if subdir.gsub("#{RAILS_ROOT}/vendor/gems/","") =~ /^(\w+-)?rspec-(\d+)/ && File.exist?("#{subdir}/lib/spec/rake/spectask.rb")
5   -end
6   -rspec_plugin_dir = File.expand_path(File.dirname(__FILE__) + '/../../vendor/plugins/rspec')
7   -
8   -if rspec_gem_dir && (test ?d, rspec_plugin_dir)
9   - 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"
10   -end
11   -
12   -if rspec_gem_dir
13   - $LOAD_PATH.unshift("#{rspec_gem_dir}/lib")
14   -elsif File.exist?(rspec_plugin_dir)
15   - $LOAD_PATH.unshift("#{rspec_plugin_dir}/lib")
16   -end
17   -
18   -# Don't load rspec if running "rake gems:*"
19   -unless ARGV.any? {|a| a =~ /^gems/}
20   -
21   -begin
22   - require 'spec/rake/spectask'
23   -rescue MissingSourceFile
24   - module Spec
25   - module Rake
26   - class SpecTask
27   - def initialize(name)
28   - task name do
29   - # if rspec-rails is a configured gem, this will output helpful material and exit ...
30   - require File.expand_path(File.join(File.dirname(__FILE__),"..","..","config","environment"))
31   -
32   - # ... otherwise, do this:
33   - raise <<-MSG
34   -
35   -#{"*" * 80}
36   -* You are trying to run an rspec rake task defined in
37   -* #{__FILE__},
38   -* but rspec can not be found in vendor/gems, vendor/plugins or system gems.
39   -#{"*" * 80}
40   -MSG
41   - end
42   - end
43   - end
44   - end
45   - end
46   -end
47   -
48   -Rake.application.instance_variable_get('@tasks').delete('default')
49   -
50   -spec_prereq = File.exist?(File.join(RAILS_ROOT, 'config', 'database.yml')) ? "db:test:prepare" : :noop
51   -task :noop do
52   -end
53   -
54   -task :default => :spec
55   -task :stats => "spec:statsetup"
56   -
57   -desc "Run all specs in spec directory (excluding plugin specs)"
58   -Spec::Rake::SpecTask.new(:spec => spec_prereq) do |t|
59   - t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
60   - t.spec_files = FileList['spec/**/*_spec.rb']
61   -end
62   -
63   -namespace :spec do
64   - desc "Run all specs in spec directory with RCov (excluding plugin specs)"
65   - Spec::Rake::SpecTask.new(:rcov) do |t|
66   - t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
67   - t.spec_files = FileList['spec/**/*_spec.rb']
68   - t.rcov = true
69   - t.rcov_opts = lambda do
70   - IO.readlines("#{RAILS_ROOT}/spec/rcov.opts").map {|l| l.chomp.split " "}.flatten
71   - end
72   - end
73   -
74   - desc "Print Specdoc for all specs (excluding plugin specs)"
75   - Spec::Rake::SpecTask.new(:doc) do |t|
76   - t.spec_opts = ["--format", "specdoc", "--dry-run"]
77   - t.spec_files = FileList['spec/**/*_spec.rb']
78   - end
79   -
80   - desc "Print Specdoc for all plugin examples"
81   - Spec::Rake::SpecTask.new(:plugin_doc) do |t|
82   - t.spec_opts = ["--format", "specdoc", "--dry-run"]
83   - t.spec_files = FileList['vendor/plugins/**/spec/**/*_spec.rb'].exclude('vendor/plugins/rspec/*')
84   - end
85   -
86   - [:models, :controllers, :views, :helpers, :lib, :integration].each do |sub|
87   - desc "Run the code examples in spec/#{sub}"
88   - Spec::Rake::SpecTask.new(sub => spec_prereq) do |t|
89   - t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
90   - t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
91   - end
92   - end
93   -
94   - desc "Run the code examples in vendor/plugins (except RSpec's own)"
95   - Spec::Rake::SpecTask.new(:plugins => spec_prereq) do |t|
96   - t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
97   - t.spec_files = FileList['vendor/plugins/**/spec/**/*_spec.rb'].exclude('vendor/plugins/rspec/*').exclude("vendor/plugins/rspec-rails/*")
98   - end
99   -
100   - namespace :plugins do
101   - desc "Runs the examples for rspec_on_rails"
102   - Spec::Rake::SpecTask.new(:rspec_on_rails) do |t|
103   - t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
104   - t.spec_files = FileList['vendor/plugins/rspec-rails/spec/**/*_spec.rb']
105   - end
106   - end
107   -
108   - # Setup specs for stats
109   - task :statsetup do
110   - require 'code_statistics'
111   - ::STATS_DIRECTORIES << %w(Model\ specs spec/models) if File.exist?('spec/models')
112   - ::STATS_DIRECTORIES << %w(View\ specs spec/views) if File.exist?('spec/views')
113   - ::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers) if File.exist?('spec/controllers')
114   - ::STATS_DIRECTORIES << %w(Helper\ specs spec/helpers) if File.exist?('spec/helpers')
115   - ::STATS_DIRECTORIES << %w(Library\ specs spec/lib) if File.exist?('spec/lib')
116   - ::STATS_DIRECTORIES << %w(Routing\ specs spec/routing) if File.exist?('spec/routing')
117   - ::STATS_DIRECTORIES << %w(Integration\ specs spec/integration) if File.exist?('spec/integration')
118   - ::CodeStatistics::TEST_TYPES << "Model specs" if File.exist?('spec/models')
119   - ::CodeStatistics::TEST_TYPES << "View specs" if File.exist?('spec/views')
120   - ::CodeStatistics::TEST_TYPES << "Controller specs" if File.exist?('spec/controllers')
121   - ::CodeStatistics::TEST_TYPES << "Helper specs" if File.exist?('spec/helpers')
122   - ::CodeStatistics::TEST_TYPES << "Library specs" if File.exist?('spec/lib')
123   - ::CodeStatistics::TEST_TYPES << "Routing specs" if File.exist?('spec/routing')
124   - ::CodeStatistics::TEST_TYPES << "Integration specs" if File.exist?('spec/integration')
125   - end
126   -
127   - namespace :db do
128   - namespace :fixtures do
129   - 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."
130   - task :load => :environment do
131   - ActiveRecord::Base.establish_connection(Rails.env)
132   - base_dir = File.join(Rails.root, 'spec', 'fixtures')
133   - fixtures_dir = ENV['FIXTURES_DIR'] ? File.join(base_dir, ENV['FIXTURES_DIR']) : base_dir
134   -
135   - require 'active_record/fixtures'
136   - (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/).map {|f| File.join(fixtures_dir, f) } : Dir.glob(File.join(fixtures_dir, '*.{yml,csv}'))).each do |fixture_file|
137   - Fixtures.create_fixtures(File.dirname(fixture_file), File.basename(fixture_file, '.*'))
138   - end
139   - end
140   - end
141   - end
142   -end
143   -
144   -end