p8-metric_fu 0.9.0.2 → 0.9.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -1
- data/lib/metric_fu/base.rb +111 -87
- data/lib/metric_fu/churn.rb +3 -4
- data/lib/tasks/flog.rake +1 -1
- data/lib/tasks/metric_fu.rake +1 -1
- data/lib/tasks/saikuro.rake +1 -1
- data/spec/config_spec.rb +41 -1
- metadata +1 -1
data/README
CHANGED
@@ -154,4 +154,4 @@ You can also change the minimum churn count like so:
|
|
154
154
|
|
155
155
|
****Thanks****
|
156
156
|
|
157
|
-
I'd like to thank the authors of Saikuro, Flog, Rcov, CruiseControl.rb, Flay, Reek, Roodi and Rails for creating such excellent open source products. Also Andre Arko, Petrik de Heus, Sean Soper, Erik St Martin, Andy Gregorowicz, Bastien, Michael Schubert, Kurtis Seebaldt, Toby Tripp, Paul Gross, and Chirdeep Shetty for their help and advice.
|
157
|
+
I'd like to thank the authors of Saikuro, Flog, Rcov, CruiseControl.rb, Flay, Reek, Roodi and Rails for creating such excellent open source products. Also Andre Arko, Petrik de Heus, Sean Soper, Erik St Martin, Andy Gregorowicz, Bastien, Michael Schubert, Kurtis Seebaldt, Jacob Kjeldahl, Toby Tripp, Paul Gross, and Chirdeep Shetty for their help and advice.
|
data/lib/metric_fu/base.rb
CHANGED
@@ -3,15 +3,118 @@ module MetricFu
|
|
3
3
|
|
4
4
|
TEMPLATE_DIR = File.join(File.dirname(__FILE__), '..', 'templates')
|
5
5
|
BASE_DIRECTORY = ENV['CC_BUILD_ARTIFACTS'] || 'tmp/metric_fu'
|
6
|
-
RAILS = File.exist?("config/environment.rb")
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
7
|
+
class << self
|
8
|
+
# The Configuration instance used to configure the Rails environment
|
9
|
+
def configuration
|
10
|
+
@@configuration ||= Configuration.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def churn
|
14
|
+
configuration.churn
|
15
|
+
end
|
16
|
+
|
17
|
+
def coverage
|
18
|
+
configuration.coverage
|
19
|
+
end
|
20
|
+
|
21
|
+
def flay
|
22
|
+
configuration.flay
|
23
|
+
end
|
24
|
+
|
25
|
+
def flog
|
26
|
+
configuration.flog
|
27
|
+
end
|
28
|
+
|
29
|
+
def metrics
|
30
|
+
configuration.metrics
|
31
|
+
end
|
32
|
+
|
33
|
+
def open_in_browser?
|
34
|
+
configuration.general[:open_in_browser] && PLATFORM['darwin'] && !run_by_cruise_control?
|
35
|
+
end
|
36
|
+
|
37
|
+
def saikuro
|
38
|
+
configuration.saikuro
|
39
|
+
end
|
40
|
+
|
41
|
+
def reek
|
42
|
+
configuration.reek
|
43
|
+
end
|
44
|
+
|
45
|
+
def roodi
|
46
|
+
configuration.roodi
|
47
|
+
end
|
48
|
+
|
49
|
+
def run_by_cruise_control?
|
50
|
+
!!ENV['CC_BUILD_ARTIFACTS']
|
51
|
+
end
|
52
|
+
|
53
|
+
def uses_git?
|
54
|
+
File.exist?(".git")
|
55
|
+
end
|
56
|
+
|
57
|
+
def uses_svn?
|
58
|
+
File.exist?(".svn")
|
59
|
+
end
|
60
|
+
|
61
|
+
def can_churn?
|
62
|
+
uses_git? || uses_svn?
|
63
|
+
end
|
64
|
+
|
65
|
+
def is_rails?
|
66
|
+
File.exist?("config/environment.rb")
|
67
|
+
end
|
68
|
+
|
69
|
+
def code_dirs
|
70
|
+
dirs = ['lib']
|
71
|
+
dirs << 'app' if is_rails?
|
72
|
+
dirs.sort{|v1, v2| v1.to_s <=> v2.to_s}
|
73
|
+
end
|
74
|
+
|
75
|
+
def default_metrics
|
76
|
+
metrics = [:coverage, :flog, :flay, :reek, :roodi, :saikuro ]
|
77
|
+
metrics << :stats if is_rails?
|
78
|
+
# Churning requires a subversion or git repo
|
79
|
+
metrics << :churn if can_churn?
|
80
|
+
metrics.sort{|v1, v2| v1.to_s <=> v2.to_s}
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
class Configuration
|
86
|
+
attr_accessor :churn, :coverage, :flay, :flog, :metrics, :reek, :roodi, :saikuro, :general
|
87
|
+
def initialize
|
88
|
+
raise "Use config.churn instead of MetricFu::CHURN_OPTIONS" if defined? ::MetricFu::CHURN_OPTIONS
|
89
|
+
raise "Use config.flog[:dirs_to_flog] instead of MetricFu::DIRECTORIES_TO_FLOG" if defined? ::MetricFu::DIRECTORIES_TO_FLOG
|
90
|
+
raise "Use config.saikuro instead of MetricFu::SAIKURO_OPTIONS" if defined? ::MetricFu::SAIKURO_OPTIONS
|
91
|
+
reset
|
92
|
+
end
|
93
|
+
|
94
|
+
def self.run()
|
95
|
+
yield MetricFu.configuration
|
96
|
+
end
|
97
|
+
|
98
|
+
def reset
|
99
|
+
@general = { :open_in_browser => true }
|
100
|
+
@churn = {}
|
101
|
+
rcov_opts = ["--sort coverage", "--html", "--exclude /gems/,/Library/,spec"]
|
102
|
+
rcov_opts << "--rails" if MetricFu.is_rails?
|
103
|
+
@coverage = { :test_files => ['test/**/*_test.rb', 'spec/**/*_spec.rb'],
|
104
|
+
:rcov_opts => rcov_opts }
|
105
|
+
@flay = { :dirs_to_flay => MetricFu.code_dirs}
|
106
|
+
@flog = { :dirs_to_flog => MetricFu.code_dirs}
|
107
|
+
@reek = { :dirs_to_reek => MetricFu.code_dirs}
|
108
|
+
@roodi = { :dirs_to_roodi => MetricFu.code_dirs}
|
109
|
+
@metrics = MetricFu.default_metrics
|
110
|
+
@saikuro = {}
|
111
|
+
end
|
112
|
+
|
113
|
+
def saikuro=(options)
|
114
|
+
raise "saikuro need to be a Hash" unless options.is_a?(Hash)
|
115
|
+
@saikuro = options
|
116
|
+
end
|
117
|
+
end
|
15
118
|
|
16
119
|
module Base
|
17
120
|
|
@@ -101,83 +204,4 @@ module MetricFu
|
|
101
204
|
end
|
102
205
|
end
|
103
206
|
|
104
|
-
class << self
|
105
|
-
# The Configuration instance used to configure the Rails environment
|
106
|
-
def configuration
|
107
|
-
@@configuration ||= Configuration.new
|
108
|
-
end
|
109
|
-
|
110
|
-
def churn
|
111
|
-
configuration.churn
|
112
|
-
end
|
113
|
-
|
114
|
-
def coverage
|
115
|
-
configuration.coverage
|
116
|
-
end
|
117
|
-
|
118
|
-
def flay
|
119
|
-
configuration.flay
|
120
|
-
end
|
121
|
-
|
122
|
-
def flog
|
123
|
-
configuration.flog
|
124
|
-
end
|
125
|
-
|
126
|
-
def metrics
|
127
|
-
configuration.metrics
|
128
|
-
end
|
129
|
-
|
130
|
-
def open_in_browser?
|
131
|
-
configuration.general[:open_in_browser] && PLATFORM['darwin'] && !run_by_cruise_control?
|
132
|
-
end
|
133
|
-
|
134
|
-
def saikuro
|
135
|
-
configuration.saikuro
|
136
|
-
end
|
137
|
-
|
138
|
-
def reek
|
139
|
-
configuration.reek
|
140
|
-
end
|
141
|
-
|
142
|
-
def roodi
|
143
|
-
configuration.roodi
|
144
|
-
end
|
145
|
-
|
146
|
-
def run_by_cruise_control?
|
147
|
-
!!ENV['CC_BUILD_ARTIFACTS']
|
148
|
-
end
|
149
|
-
|
150
|
-
end
|
151
|
-
|
152
|
-
class Configuration
|
153
|
-
attr_accessor :churn, :coverage, :flay, :flog, :metrics, :reek, :roodi, :saikuro, :general
|
154
|
-
def initialize
|
155
|
-
raise "Use config.churn instead of MetricFu::CHURN_OPTIONS" if defined? ::MetricFu::CHURN_OPTIONS
|
156
|
-
raise "Use config.flog[:dirs_to_flog] instead of MetricFu::DIRECTORIES_TO_FLOG" if defined? ::MetricFu::DIRECTORIES_TO_FLOG
|
157
|
-
raise "Use config.saikuro instead of MetricFu::SAIKURO_OPTIONS" if defined? ::MetricFu::SAIKURO_OPTIONS
|
158
|
-
reset
|
159
|
-
end
|
160
|
-
|
161
|
-
def self.run()
|
162
|
-
yield MetricFu.configuration
|
163
|
-
end
|
164
|
-
|
165
|
-
def reset
|
166
|
-
@general = { :open_in_browser => true }
|
167
|
-
@churn = {}
|
168
|
-
@coverage = { :test_files => ['test/**/*_test.rb', 'spec/**/*_spec.rb'],
|
169
|
-
:rcov_opts => ["--sort coverage", "--html", "--rails", "--exclude /gems/,/Library/,spec"] }
|
170
|
-
@flay = { :dirs_to_flay => CODE_DIRS}
|
171
|
-
@flog = { :dirs_to_flog => CODE_DIRS}
|
172
|
-
@reek = { :dirs_to_reek => CODE_DIRS}
|
173
|
-
@roodi = { :dirs_to_roodi => CODE_DIRS}
|
174
|
-
@metrics = DEFAULT_METRICS
|
175
|
-
@saikuro = {}
|
176
|
-
end
|
177
|
-
|
178
|
-
def saikuro=(options)
|
179
|
-
raise "saikuro need to be a Hash" unless options.is_a?(Hash)
|
180
|
-
@saikuro = options
|
181
|
-
end
|
182
|
-
end
|
183
207
|
end
|
data/lib/metric_fu/churn.rb
CHANGED
@@ -9,9 +9,9 @@ module MetricFu
|
|
9
9
|
|
10
10
|
def initialize(options={})
|
11
11
|
@base_dir = File.join(MetricFu::BASE_DIRECTORY, template_name)
|
12
|
-
if
|
12
|
+
if MetricFu.uses_git?
|
13
13
|
@source_control = Git.new(options[:start_date])
|
14
|
-
elsif
|
14
|
+
elsif MetricFu.uses_svn?
|
15
15
|
@source_control = Svn.new(options[:start_date])
|
16
16
|
else
|
17
17
|
raise "Churning requires a subversion or git repo"
|
@@ -35,8 +35,7 @@ module MetricFu
|
|
35
35
|
end
|
36
36
|
changes
|
37
37
|
end
|
38
|
-
|
39
|
-
|
38
|
+
|
40
39
|
class SourceControl
|
41
40
|
def initialize(start_date=nil)
|
42
41
|
@start_date = start_date
|
data/lib/tasks/flog.rake
CHANGED
data/lib/tasks/metric_fu.rake
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
MetricFu.metrics.each { |task| import "#{File.dirname(__FILE__)}/#{task}.rake" }
|
3
3
|
|
4
4
|
namespace :metrics do
|
5
|
-
if MetricFu
|
5
|
+
if MetricFu.is_rails?
|
6
6
|
|
7
7
|
desc "Generate coverage, cyclomatic complexity, flog, flay, railroad, reek, roodi, stats and churn reports"
|
8
8
|
task :all => MetricFu.metrics
|
data/lib/tasks/saikuro.rake
CHANGED
@@ -9,7 +9,7 @@ namespace :metrics do
|
|
9
9
|
|
10
10
|
raise "SAIKURO_OPTIONS is now MetricFu::SAIKURO_OPTIONS" if defined?(SAIKURO_OPTIONS)
|
11
11
|
options = { :output_directory => SAIKURO_DIR,
|
12
|
-
:input_directory => MetricFu
|
12
|
+
:input_directory => MetricFu.code_dirs,
|
13
13
|
:cyclo => "",
|
14
14
|
:filter_cyclo => "0",
|
15
15
|
:warn_cyclo => "5",
|
data/spec/config_spec.rb
CHANGED
@@ -19,12 +19,38 @@ describe MetricFu::Configuration do
|
|
19
19
|
|
20
20
|
describe "metrics" do
|
21
21
|
it "should be configurable" do
|
22
|
-
MetricFu.metrics.should == [:
|
22
|
+
MetricFu.metrics.should == [:churn, :coverage, :flay, :flog, :reek, :roodi, :saikuro]
|
23
23
|
MetricFu::Configuration.run do |config|
|
24
24
|
config.metrics = [:coverage, :flog]
|
25
25
|
end
|
26
26
|
MetricFu.metrics.should == [:coverage, :flog]
|
27
27
|
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "default metrics" do
|
31
|
+
it "should have :stats for rails projects" do
|
32
|
+
MetricFu.should_receive(:is_rails?).and_return(true)
|
33
|
+
MetricFu.should_receive(:can_churn?).and_return(false)
|
34
|
+
MetricFu.default_metrics.should == [:coverage, :flay, :flog, :reek, :roodi, :saikuro, :stats]
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should have exclude :churn for projects whcih can churn" do
|
38
|
+
MetricFu.should_receive(:is_rails?).and_return(false)
|
39
|
+
MetricFu.should_receive(:can_churn?).and_return(true)
|
40
|
+
MetricFu.default_metrics.should == [:churn, :coverage, :flay, :flog, :reek, :roodi, :saikuro]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "code dirs" do
|
45
|
+
it "should return code dirs" do
|
46
|
+
MetricFu.should_receive(:is_rails?).and_return(false)
|
47
|
+
MetricFu.code_dirs.should == ['lib']
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should have 'app' for rails projects" do
|
51
|
+
MetricFu.should_receive(:is_rails?).and_return(true)
|
52
|
+
MetricFu.code_dirs.should == ['app', 'lib']
|
53
|
+
end
|
28
54
|
end
|
29
55
|
|
30
56
|
describe "churn" do
|
@@ -46,6 +72,20 @@ describe MetricFu::Configuration do
|
|
46
72
|
end
|
47
73
|
MetricFu.coverage[:test_files].should == ['test/**/test_*.rb']
|
48
74
|
end
|
75
|
+
|
76
|
+
it "should have configurable rcov_opts" do
|
77
|
+
MetricFu.coverage[:rcov_opts].should == ["--sort coverage", "--html", "--exclude /gems/,/Library/,spec"]
|
78
|
+
MetricFu::Configuration.run do |config|
|
79
|
+
config.coverage[:rcov_opts] = ["--sort coverage", "--html"]
|
80
|
+
end
|
81
|
+
MetricFu.coverage[:rcov_opts].should == ["--sort coverage", "--html"]
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should have --rails in rcov_opts if it's a rails project" do
|
85
|
+
MetricFu.should_receive(:is_rails?).at_least(1).and_return(true)
|
86
|
+
MetricFu.configuration.reset
|
87
|
+
MetricFu.coverage[:rcov_opts].should == ["--sort coverage", "--html", "--exclude /gems/,/Library/,spec", "--rails"]
|
88
|
+
end
|
49
89
|
end
|
50
90
|
|
51
91
|
describe "flay" do
|