edouard-metric_fu 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -1
- data/Rakefile +4 -4
- data/spec/base/configuration_spec.rb +1 -1
- data/spec/base/generator_spec.rb +0 -22
- data/spec/generators/churn_spec.rb +7 -7
- data/spec/generators/flay_spec.rb +0 -3
- data/spec/generators/flog_spec.rb +1 -9
- data/spec/generators/reek_spec.rb +0 -1
- data/spec/generators/saikuro_spec.rb +11 -21
- metadata +18 -56
- data/lib/base/base_template.rb +0 -134
- data/lib/base/configuration.rb +0 -207
- data/lib/base/generator.rb +0 -160
- data/lib/base/graph.rb +0 -37
- data/lib/base/md5_tracker.rb +0 -52
- data/lib/base/report.rb +0 -100
- data/lib/generators/churn.rb +0 -91
- data/lib/generators/flay.rb +0 -34
- data/lib/generators/flog.rb +0 -133
- data/lib/generators/rcov.rb +0 -87
- data/lib/generators/reek.rb +0 -37
- data/lib/generators/roodi.rb +0 -31
- data/lib/generators/saikuro.rb +0 -209
- data/lib/generators/stats.rb +0 -43
- data/lib/graphs/flay_grapher.rb +0 -34
- data/lib/graphs/flog_grapher.rb +0 -37
- data/lib/graphs/rcov_grapher.rb +0 -34
- data/lib/graphs/reek_grapher.rb +0 -44
- data/lib/graphs/roodi_grapher.rb +0 -34
- data/lib/metric_fu.rb +0 -24
- data/lib/templates/awesome/awesome_template.rb +0 -30
- data/lib/templates/awesome/churn.html.erb +0 -19
- data/lib/templates/awesome/default.css +0 -66
- data/lib/templates/awesome/flay.html.erb +0 -27
- data/lib/templates/awesome/flog.html.erb +0 -46
- data/lib/templates/awesome/index.html.erb +0 -28
- data/lib/templates/awesome/layout.html.erb +0 -27
- data/lib/templates/awesome/rcov.html.erb +0 -36
- data/lib/templates/awesome/reek.html.erb +0 -34
- data/lib/templates/awesome/roodi.html.erb +0 -21
- data/lib/templates/awesome/saikuro.html.erb +0 -71
- data/lib/templates/awesome/stats.html.erb +0 -41
- data/lib/templates/standard/churn.html.erb +0 -31
- data/lib/templates/standard/default.css +0 -64
- data/lib/templates/standard/flay.html.erb +0 -34
- data/lib/templates/standard/flog.html.erb +0 -53
- data/lib/templates/standard/index.html.erb +0 -38
- data/lib/templates/standard/rcov.html.erb +0 -43
- data/lib/templates/standard/reek.html.erb +0 -42
- data/lib/templates/standard/roodi.html.erb +0 -29
- data/lib/templates/standard/saikuro.html.erb +0 -84
- data/lib/templates/standard/standard_template.rb +0 -26
- data/lib/templates/standard/stats.html.erb +0 -55
- data/tasks/metric_fu.rake +0 -19
- data/tasks/railroad.rake +0 -39
- data/vendor/_fonts/monaco.ttf +0 -0
- data/vendor/saikuro/saikuro.rb +0 -1214
data/lib/base/configuration.rb
DELETED
@@ -1,207 +0,0 @@
|
|
1
|
-
module MetricFu
|
2
|
-
|
3
|
-
# A list of metrics which are available in the MetricFu system.
|
4
|
-
#
|
5
|
-
# These are metrics which have been developed for the system. Of
|
6
|
-
# course, in order to use these metrics, their respective gems must
|
7
|
-
# be installed on the system.
|
8
|
-
AVAILABLE_METRICS = [:churn, :flog, :flay, :reek,
|
9
|
-
:roodi, :saikuro, :rcov]
|
10
|
-
|
11
|
-
AVAILABLE_GRAPHS = [:flog, :flay, :reek, :roodi, :rcov]
|
12
|
-
|
13
|
-
# The @@configuration class variable holds a global type configuration
|
14
|
-
# object for any parts of the system to use.
|
15
|
-
def self.configuration
|
16
|
-
@@configuration ||= Configuration.new
|
17
|
-
end
|
18
|
-
|
19
|
-
# = Configuration
|
20
|
-
#
|
21
|
-
# The Configuration class, as it sounds, provides methods for
|
22
|
-
# configuring the behaviour of MetricFu.
|
23
|
-
#
|
24
|
-
# == Customization for Rails
|
25
|
-
#
|
26
|
-
# The Configuration class checks for the presence of a
|
27
|
-
# 'config/environment.rb' file. If the file is present, it assumes
|
28
|
-
# it is running in a Rails project. If it is, it will:
|
29
|
-
#
|
30
|
-
# * Add 'app' to the @code_dirs directory to include the
|
31
|
-
# code in the app directory in the processing
|
32
|
-
# * Add :stats to the list of metrics to run to get the Rails stats
|
33
|
-
# task
|
34
|
-
#
|
35
|
-
# == Customization for CruiseControl.rb
|
36
|
-
#
|
37
|
-
# The Configuration class checks for the presence of a
|
38
|
-
# 'CC_BUILD_ARTIFACTS' environment variable. If it's found
|
39
|
-
# it will change the default output directory from the default
|
40
|
-
# "tmp/metric_fu to the directory represented by 'CC_BUILD_ARTIFACTS'
|
41
|
-
#
|
42
|
-
# == Deprications
|
43
|
-
#
|
44
|
-
# The Configuration class checks for several deprecated constants
|
45
|
-
# that were previously used to configure MetricFu. These include
|
46
|
-
# CHURN_OPTIONS, DIRECTORIES_TO_FLOG, SAIKURO_OPTIONS,
|
47
|
-
# and MetricFu::SAIKURO_OPTIONS.
|
48
|
-
#
|
49
|
-
# These have been replaced by config.churn, config.flog and
|
50
|
-
# config.saikuro respectively.
|
51
|
-
class Configuration
|
52
|
-
|
53
|
-
def initialize #:nodoc:#
|
54
|
-
warn_about_deprecated_config_options
|
55
|
-
reset
|
56
|
-
add_attr_accessors_to_self
|
57
|
-
add_class_methods_to_metric_fu
|
58
|
-
end
|
59
|
-
|
60
|
-
# Searches through the instance variables of the class and
|
61
|
-
# creates a class method on the MetricFu module to read the value
|
62
|
-
# of the instance variable from the Configuration class.
|
63
|
-
def add_class_methods_to_metric_fu
|
64
|
-
instance_variables.each do |name|
|
65
|
-
method_name = name[1..-1].to_sym
|
66
|
-
method = <<-EOF
|
67
|
-
def self.#{method_name}
|
68
|
-
configuration.send(:#{method_name})
|
69
|
-
end
|
70
|
-
EOF
|
71
|
-
MetricFu.module_eval(method)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
# Searches through the instance variables of the class and creates
|
76
|
-
# an attribute accessor on this instance of the Configuration
|
77
|
-
# class for each instance variable.
|
78
|
-
def add_attr_accessors_to_self
|
79
|
-
instance_variables.each do |name|
|
80
|
-
method_name = name[1..-1].to_sym
|
81
|
-
MetricFu::Configuration.send(:attr_accessor, method_name)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
# Check if certain constants that are deprecated have been
|
86
|
-
# assigned. If so, warn the user about them, and the
|
87
|
-
# fact that they will have no effect.
|
88
|
-
def warn_about_deprecated_config_options
|
89
|
-
if defined?(::MetricFu::CHURN_OPTIONS)
|
90
|
-
raise("Use config.churn instead of MetricFu::CHURN_OPTIONS")
|
91
|
-
end
|
92
|
-
if defined?(::MetricFu::DIRECTORIES_TO_FLOG)
|
93
|
-
raise("Use config.flog[:dirs_to_flog] "+
|
94
|
-
"instead of MetricFu::DIRECTORIES_TO_FLOG")
|
95
|
-
end
|
96
|
-
if defined?(::MetricFu::SAIKURO_OPTIONS)
|
97
|
-
raise("Use config.saikuro instead of MetricFu::SAIKURO_OPTIONS")
|
98
|
-
end
|
99
|
-
if defined?(SAIKURO_OPTIONS)
|
100
|
-
raise("Use config.saikuro instead of SAIKURO_OPTIONS")
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
# This allows us to have a nice syntax like:
|
105
|
-
#
|
106
|
-
# MetricFu.run do |config|
|
107
|
-
# config.base_directory = 'tmp/metric_fu'
|
108
|
-
# end
|
109
|
-
#
|
110
|
-
# See the README for more information on configuration options.
|
111
|
-
def self.run
|
112
|
-
yield MetricFu.configuration
|
113
|
-
end
|
114
|
-
|
115
|
-
# This does the real work of the Configuration class, by setting
|
116
|
-
# up a bunch of instance variables to represent the configuration
|
117
|
-
# of the MetricFu app.
|
118
|
-
def reset
|
119
|
-
@base_directory = ENV['CC_BUILD_ARTIFACTS'] || 'tmp/metric_fu'
|
120
|
-
@scratch_directory = File.join(@base_directory, 'scratch')
|
121
|
-
@output_directory = File.join(@base_directory, 'output')
|
122
|
-
@data_directory = File.join(@base_directory, '_data')
|
123
|
-
@metric_fu_root_directory = File.join(File.dirname(__FILE__),
|
124
|
-
'..', '..')
|
125
|
-
@template_directory = File.join(@metric_fu_root_directory,
|
126
|
-
'lib', 'templates')
|
127
|
-
@template_class = AwesomeTemplate
|
128
|
-
set_metrics
|
129
|
-
set_graphs
|
130
|
-
set_code_dirs
|
131
|
-
@flay = { :dirs_to_flay => @code_dirs }
|
132
|
-
@flog = { :dirs_to_flog => @code_dirs }
|
133
|
-
@reek = { :dirs_to_reek => @code_dirs }
|
134
|
-
@roodi = { :dirs_to_roodi => @code_dirs }
|
135
|
-
@saikuro = { :output_directory => @scratch_directory + '/saikuro',
|
136
|
-
:input_directory => @code_dirs,
|
137
|
-
:cyclo => "",
|
138
|
-
:filter_cyclo => "0",
|
139
|
-
:warn_cyclo => "5",
|
140
|
-
:error_cyclo => "7",
|
141
|
-
:formater => "text"}
|
142
|
-
@churn = {}
|
143
|
-
@stats = {}
|
144
|
-
@rcov = { :test_files => ['test/**/*_test.rb',
|
145
|
-
'spec/**/*_spec.rb'],
|
146
|
-
:rcov_opts => ["--sort coverage",
|
147
|
-
"--no-html",
|
148
|
-
"--text-coverage",
|
149
|
-
"--no-color",
|
150
|
-
"--profile",
|
151
|
-
"--rails",
|
152
|
-
"--exclude /gems/,/Library/,/usr/,spec"]}
|
153
|
-
|
154
|
-
@graph_theme = { :colors => %w(orange purple green white red blue pink yellow),
|
155
|
-
:marker_color => 'blue',
|
156
|
-
:background_colors => %w(white white)}
|
157
|
-
|
158
|
-
relative_font_path = [File.dirname(__FILE__), '..', '..', 'vendor', '_fonts', 'monaco.ttf']
|
159
|
-
@graph_font = File.expand_path(File.join(relative_font_path))
|
160
|
-
@graph_size = "1000x400"
|
161
|
-
@graph_title_font_size = 12
|
162
|
-
@graph_legend_box_size = 12
|
163
|
-
@graph_legend_font_size = 10
|
164
|
-
@graph_marker_font_size = 10
|
165
|
-
|
166
|
-
end
|
167
|
-
|
168
|
-
# Perform a simple check to try and guess if we're running
|
169
|
-
# against a rails app.
|
170
|
-
#
|
171
|
-
# @todo This should probably be made a bit more robust.
|
172
|
-
def rails?
|
173
|
-
@rails = File.exist?("config/environment.rb")
|
174
|
-
end
|
175
|
-
|
176
|
-
# Add the :stats task to the AVAILABLE_METRICS constant if we're
|
177
|
-
# running within rails.
|
178
|
-
def set_metrics
|
179
|
-
if rails?
|
180
|
-
@metrics = MetricFu::AVAILABLE_METRICS + [:stats]
|
181
|
-
else
|
182
|
-
@metrics = MetricFu::AVAILABLE_METRICS
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
def set_graphs
|
187
|
-
@graphs = MetricFu::AVAILABLE_GRAPHS
|
188
|
-
end
|
189
|
-
|
190
|
-
# Add the 'app' directory if we're running within rails.
|
191
|
-
def set_code_dirs
|
192
|
-
if rails?
|
193
|
-
@code_dirs = ['app', 'lib']
|
194
|
-
else
|
195
|
-
@code_dirs = ['lib']
|
196
|
-
end
|
197
|
-
end
|
198
|
-
|
199
|
-
def platform #:nodoc:
|
200
|
-
return PLATFORM
|
201
|
-
end
|
202
|
-
|
203
|
-
def is_cruise_control_rb?
|
204
|
-
!!ENV['CC_BUILD_ARTIFACTS']
|
205
|
-
end
|
206
|
-
end
|
207
|
-
end
|
data/lib/base/generator.rb
DELETED
@@ -1,160 +0,0 @@
|
|
1
|
-
module MetricFu
|
2
|
-
|
3
|
-
# = Generator
|
4
|
-
#
|
5
|
-
# The Generator class is an abstract class that provides the
|
6
|
-
# skeleton for producing different types of metrics.
|
7
|
-
#
|
8
|
-
# It drives the production of the metrics through a template
|
9
|
-
# method - #generate_report(options={}). This method calls
|
10
|
-
# #emit, #analyze and #to_h in order to produce the metrics.
|
11
|
-
#
|
12
|
-
# To implement a concrete class to generate a metric, therefore,
|
13
|
-
# the class must implement those three methods.
|
14
|
-
#
|
15
|
-
# * #emit should take care of running the metric tool and
|
16
|
-
# gathering its output.
|
17
|
-
# * #analyze should take care of manipulating the output from
|
18
|
-
# #emit and making it possible to store it in a programmatic way.
|
19
|
-
# * #to_h should provide a hash representation of the output from
|
20
|
-
# #analyze ready to be serialized into yaml at some point.
|
21
|
-
#
|
22
|
-
# == Pre-conditions
|
23
|
-
#
|
24
|
-
# Based on the class name of the concrete class implementing a
|
25
|
-
# Generator, the Generator class will create a 'metric_directory'
|
26
|
-
# named after the class under the MetricFu.scratch_directory, where
|
27
|
-
# any output from the #emit method should go.
|
28
|
-
#
|
29
|
-
# It will also create the MetricFu.output_directory if neccessary, and
|
30
|
-
# in general setup the directory structure that the MetricFu system
|
31
|
-
# expects.
|
32
|
-
class Generator
|
33
|
-
attr_reader :report, :template
|
34
|
-
|
35
|
-
def initialize(options={})
|
36
|
-
self.class.verify_dependencies!
|
37
|
-
create_metric_dir_if_missing
|
38
|
-
create_output_dir_if_missing
|
39
|
-
create_data_dir_if_missing
|
40
|
-
end
|
41
|
-
|
42
|
-
# Creates a new generator and returns the output of the
|
43
|
-
# #generate_report method. This is the typical way to
|
44
|
-
# generate a new MetricFu report. For more information see
|
45
|
-
# the #generate_report instance method.
|
46
|
-
#
|
47
|
-
# @params options Hash
|
48
|
-
# A currently unused hash to configure the Generator
|
49
|
-
#
|
50
|
-
# @see generate_report
|
51
|
-
def self.generate_report(options={})
|
52
|
-
generator = self.new(options)
|
53
|
-
generator.generate_report
|
54
|
-
end
|
55
|
-
|
56
|
-
# Provides the unqualified class name of an implemented concrete
|
57
|
-
# class, as a string. For example:
|
58
|
-
#
|
59
|
-
# class Flay < Generator; end
|
60
|
-
# klass = Flay.new
|
61
|
-
# klass.class_name
|
62
|
-
# > "flay"
|
63
|
-
#
|
64
|
-
# @return String
|
65
|
-
# The unqualified class name of this concrete class, returned
|
66
|
-
# as a string.
|
67
|
-
def self.class_name
|
68
|
-
self.to_s.split('::').last.downcase
|
69
|
-
end
|
70
|
-
|
71
|
-
# Returns the directory where the Generator will write any output
|
72
|
-
def self.metric_directory
|
73
|
-
File.join(MetricFu.scratch_directory, class_name)
|
74
|
-
end
|
75
|
-
|
76
|
-
def create_metric_dir_if_missing #:nodoc:
|
77
|
-
unless File.directory?(metric_directory)
|
78
|
-
FileUtils.mkdir_p(metric_directory, :verbose => false)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def create_output_dir_if_missing #:nodoc:
|
83
|
-
unless File.directory?(MetricFu.output_directory)
|
84
|
-
FileUtils.mkdir_p(MetricFu.output_directory, :verbose => false)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
def create_data_dir_if_missing #:nodoc:
|
89
|
-
unless File.directory?(MetricFu.data_directory)
|
90
|
-
FileUtils.mkdir_p(MetricFu.data_directory, :verbose => false)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
# @return String
|
95
|
-
# The path of the metric directory this class is using.
|
96
|
-
def metric_directory
|
97
|
-
self.class.metric_directory
|
98
|
-
end
|
99
|
-
|
100
|
-
|
101
|
-
# Defines some hook methods for the concrete classes to hook into.
|
102
|
-
%w[emit analyze].each do |meth|
|
103
|
-
define_method("before_#{meth}".to_sym) {}
|
104
|
-
define_method("after_#{meth}".to_sym) {}
|
105
|
-
end
|
106
|
-
define_method("before_to_h".to_sym) {}
|
107
|
-
|
108
|
-
# Provides a template method to drive the production of a metric
|
109
|
-
# from a concrete implementation of this class. Each concrete
|
110
|
-
# class must implement the three methods that this template method
|
111
|
-
# calls: #emit, #analyze and #to_h. For more details, see the
|
112
|
-
# class documentation.
|
113
|
-
#
|
114
|
-
# This template method also calls before_emit, after_emit... etc.
|
115
|
-
# methods to allow extra hooks into the processing methods, and help
|
116
|
-
# to keep the logic of your Generators clean.
|
117
|
-
def generate_report
|
118
|
-
%w[emit analyze].each do |meth|
|
119
|
-
send("before_#{meth}".to_sym)
|
120
|
-
send("#{meth}".to_sym)
|
121
|
-
send("after_#{meth}".to_sym)
|
122
|
-
end
|
123
|
-
before_to_h()
|
124
|
-
to_h()
|
125
|
-
end
|
126
|
-
|
127
|
-
def round_to_tenths(decimal)
|
128
|
-
(decimal * 10).round / 10.0
|
129
|
-
end
|
130
|
-
|
131
|
-
# Allows subclasses to check for required gems
|
132
|
-
def self.verify_dependencies!
|
133
|
-
true
|
134
|
-
end
|
135
|
-
|
136
|
-
def emit #:nodoc:
|
137
|
-
raise <<-EOF
|
138
|
-
This method must be implemented by a concrete class descending
|
139
|
-
from Generator. See generator class documentation for more
|
140
|
-
information.
|
141
|
-
EOF
|
142
|
-
end
|
143
|
-
|
144
|
-
def analyze #:nodoc:
|
145
|
-
raise <<-EOF
|
146
|
-
This method must be implemented by a concrete class descending
|
147
|
-
from Generator. See generator class documentation for more
|
148
|
-
information.
|
149
|
-
EOF
|
150
|
-
end
|
151
|
-
|
152
|
-
def to_graph #:nodoc:
|
153
|
-
raise <<-EOF
|
154
|
-
This method must be implemented by a concrete class descending
|
155
|
-
from Generator. See generator class documentation for more
|
156
|
-
information.
|
157
|
-
EOF
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|
data/lib/base/graph.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
module MetricFu
|
2
|
-
|
3
|
-
def self.graph
|
4
|
-
@graph ||= Graph.new
|
5
|
-
end
|
6
|
-
|
7
|
-
class Graph
|
8
|
-
|
9
|
-
attr_accessor :clazz
|
10
|
-
|
11
|
-
def initialize
|
12
|
-
self.clazz = []
|
13
|
-
end
|
14
|
-
|
15
|
-
def add(graph_type)
|
16
|
-
grapher_name = graph_type.to_s.capitalize + "Grapher"
|
17
|
-
self.clazz.push MetricFu.const_get(grapher_name).new
|
18
|
-
end
|
19
|
-
|
20
|
-
|
21
|
-
def generate
|
22
|
-
puts "Generating graphs"
|
23
|
-
Dir[File.join(MetricFu.data_directory, '*.yml')].sort.each do |metric_file|
|
24
|
-
puts "Generating graphs for #{metric_file}"
|
25
|
-
date = metric_file.split('/')[3].split('.')[0]
|
26
|
-
metrics = YAML::load(File.open(metric_file))
|
27
|
-
|
28
|
-
self.clazz.each do |grapher|
|
29
|
-
grapher.get_metrics(metrics, date)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
self.clazz.each do |grapher|
|
33
|
-
grapher.graph!
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
data/lib/base/md5_tracker.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
require 'digest/md5'
|
2
|
-
require 'fileutils'
|
3
|
-
|
4
|
-
module MetricFu
|
5
|
-
class MD5Tracker
|
6
|
-
|
7
|
-
@@unchanged_md5s = []
|
8
|
-
|
9
|
-
class << self
|
10
|
-
def md5_dir(path_to_file, base_dir)
|
11
|
-
File.join(base_dir,
|
12
|
-
path_to_file.split('/')[0..-2].join('/'))
|
13
|
-
end
|
14
|
-
|
15
|
-
def md5_file(path_to_file, base_dir)
|
16
|
-
File.join(md5_dir(path_to_file, base_dir),
|
17
|
-
path_to_file.split('/').last.sub(/\.[a-z]+/, '.md5'))
|
18
|
-
end
|
19
|
-
|
20
|
-
def track(path_to_file, base_dir)
|
21
|
-
md5 = Digest::MD5.hexdigest(File.read(path_to_file))
|
22
|
-
FileUtils.mkdir_p(md5_dir(path_to_file, base_dir), :verbose => false)
|
23
|
-
f = File.new(md5_file(path_to_file, base_dir), "w")
|
24
|
-
f.puts(md5)
|
25
|
-
f.close
|
26
|
-
md5
|
27
|
-
end
|
28
|
-
|
29
|
-
def file_changed?(path_to_file, base_dir)
|
30
|
-
orig_md5_file = md5_file(path_to_file, base_dir)
|
31
|
-
return !!track(path_to_file, base_dir) unless File.exist?(orig_md5_file)
|
32
|
-
|
33
|
-
current_md5 = ""
|
34
|
-
file = File.open(orig_md5_file, 'r')
|
35
|
-
file.each_line { |line| current_md5 << line }
|
36
|
-
file.close
|
37
|
-
current_md5.chomp!
|
38
|
-
|
39
|
-
new_md5 = Digest::MD5.hexdigest(File.read(path_to_file))
|
40
|
-
new_md5.chomp!
|
41
|
-
|
42
|
-
@@unchanged_md5s << path_to_file if new_md5 == current_md5
|
43
|
-
|
44
|
-
return new_md5 != current_md5
|
45
|
-
end
|
46
|
-
|
47
|
-
def file_already_counted?(path_to_file)
|
48
|
-
return @@unchanged_md5s.include?(path_to_file)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|