jscruggs-metric_fu 0.8.0 → 0.8.9
Sign up to get free protection for your applications and to get access to all the features.
- data/{History.txt → HISTORY} +12 -0
- data/MIT-LICENSE +1 -1
- data/Manifest.txt +3 -6
- data/README +66 -16
- data/Rakefile +11 -0
- data/TODO +13 -0
- data/lib/metric_fu/base.rb +159 -0
- data/lib/metric_fu/churn.rb +88 -0
- data/lib/metric_fu/flay.rb +17 -0
- data/lib/metric_fu/flog.rb +129 -0
- data/lib/metric_fu/md5_tracker.rb +6 -6
- data/lib/metric_fu/reek.rb +17 -0
- data/lib/metric_fu/roodi.rb +17 -0
- data/lib/metric_fu.rb +3 -7
- data/lib/tasks/churn.rake +4 -106
- data/lib/tasks/coverage.rake +25 -9
- data/lib/tasks/flay.rake +6 -0
- data/lib/tasks/flog.rake +28 -21
- data/lib/tasks/metric_fu.rake +21 -8
- data/lib/tasks/metric_fu.rb +1 -1
- data/lib/tasks/railroad.rake +36 -0
- data/lib/tasks/reek.rake +6 -0
- data/lib/tasks/roodi.rake +7 -0
- data/lib/tasks/saikuro.rake +20 -19
- data/lib/tasks/stats.rake +3 -3
- data/lib/templates/churn.html.erb +22 -0
- data/lib/templates/default.css +45 -0
- data/lib/templates/flay.html.erb +30 -0
- data/lib/templates/flog.html.erb +31 -0
- data/lib/templates/flog_page.html.erb +25 -0
- data/lib/templates/reek.html.erb +30 -0
- data/lib/templates/roodi.html.erb +26 -0
- data/spec/base_spec.rb +57 -0
- data/spec/churn_spec.rb +117 -0
- data/spec/config_spec.rb +110 -0
- data/spec/flay_spec.rb +19 -0
- data/spec/flog_spec.rb +208 -0
- data/spec/md5_tracker_spec.rb +57 -0
- data/spec/reek_spec.rb +26 -0
- data/spec/spec_helper.rb +11 -0
- metadata +76 -27
- data/TODO.txt +0 -9
- data/lib/metric_fu/flog_reporter/base.rb +0 -58
- data/lib/metric_fu/flog_reporter/flog_reporter.css +0 -39
- data/lib/metric_fu/flog_reporter/generator.rb +0 -71
- data/lib/metric_fu/flog_reporter/operator.rb +0 -10
- data/lib/metric_fu/flog_reporter/page.rb +0 -36
- data/lib/metric_fu/flog_reporter/scanned_method.rb +0 -28
- data/lib/metric_fu/flog_reporter.rb +0 -5
- data/lib/metric_fu/saikuro/SAIKURO_README +0 -142
- data/metric_fu.gemspec +0 -16
- data/test/test_helper.rb +0 -4
- data/test/test_md5_tracker.rb +0 -59
data/{History.txt → HISTORY}
RENAMED
@@ -1,3 +1,15 @@
|
|
1
|
+
=== MetricFu 0.8.9 / 2009-1-20
|
2
|
+
|
3
|
+
* Thanks to Andre Arko and Petrik de Heus for adding the following features:
|
4
|
+
* The source control type is auto-detected for Churn
|
5
|
+
* Moved all presentation to templates
|
6
|
+
* Wrote specs for all classes
|
7
|
+
* Added flay, Reek and Roodi metrics
|
8
|
+
* There's now a configuration class (see README for details)
|
9
|
+
* Unification of metrics reports
|
10
|
+
* Metrics can be generated using one command
|
11
|
+
* Adding new metrics reports has been standardized
|
12
|
+
|
1
13
|
=== MetricFu 0.8.0 / 2008-10-06
|
2
14
|
|
3
15
|
* Source Control Churn now supports git (thanks to Erik St Martin)
|
data/MIT-LICENSE
CHANGED
data/Manifest.txt
CHANGED
@@ -7,14 +7,11 @@ Rakefile
|
|
7
7
|
README
|
8
8
|
TODO.txt
|
9
9
|
lib/metric_fu.rb
|
10
|
+
lib/metric_fu/base.rb
|
11
|
+
lib/metric_fu/churn.rb
|
12
|
+
lib/metric_fu/flay_reporter.rb
|
10
13
|
lib/metric_fu/flog_reporter.rb
|
11
14
|
lib/metric_fu/md5_tracker.rb
|
12
|
-
lib/metric_fu/flog_reporter/base.rb
|
13
|
-
lib/metric_fu/flog_reporter/flog_reporter.css
|
14
|
-
lib/metric_fu/flog_reporter/generator.rb
|
15
|
-
lib/metric_fu/flog_reporter/operator.rb
|
16
|
-
lib/metric_fu/flog_reporter/page.rb
|
17
|
-
lib/metric_fu/flog_reporter/scanned_method.rb
|
18
15
|
lib/metric_fu/saikuro/saikuro.rb
|
19
16
|
lib/metric_fu/saikuro/SAIKURO_README
|
20
17
|
lib/tasks/churn.rake
|
data/README
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Version 0.
|
1
|
+
Version 0.8.9
|
2
2
|
http://github.com/jscruggs/metric_fu
|
3
3
|
|
4
4
|
Metric_fu began its life as a plugin for Rails that generated code metrics reports. As of version 0.7.0, metric_fu is a gem owing to the excellent work done by Sean Soper.
|
@@ -12,7 +12,7 @@ Then in your Rakefile:
|
|
12
12
|
require 'metric_fu'
|
13
13
|
|
14
14
|
If you like to vendor gems, you can unpack metric_fu into vendor/gems and require it like so:
|
15
|
-
require 'vendor/gems/jscruggs-metric_fu-0.
|
15
|
+
require 'vendor/gems/jscruggs-metric_fu-0.8.9/lib/metric_fu'
|
16
16
|
|
17
17
|
then you don't have to install it on every box you run it on.
|
18
18
|
|
@@ -23,13 +23,13 @@ You must have Rcov and Flog installed to get coverage and flog reports. Metric_
|
|
23
23
|
****Usage****
|
24
24
|
|
25
25
|
Out of the box metrics provides these tasks:
|
26
|
-
rake metrics:all
|
27
|
-
rake metrics:all_with_migrate # Useful for continuous integration
|
26
|
+
rake metrics:all # Generate coverage, cyclomatic complexity, flog, flay, railroad and churn reports
|
28
27
|
rake metrics:churn # Which files change the most
|
29
28
|
rake metrics:coverage # Generate and open coverage report
|
30
29
|
rake metrics:coverage:clean # Delete aggregate coverage data.
|
31
30
|
rake metrics:coverage:clobber_do # Remove rcov products for do
|
32
31
|
rake metrics:coverage:do # RCov task to generate report
|
32
|
+
rake metrics:flay # Generate code duplication report with flay
|
33
33
|
rake metrics:flog:all # Generate and open flog report
|
34
34
|
rake metrics:flog:clean # Delete aggregate flog data.
|
35
35
|
rake metrics:flog:controllers # Flog code in app/controllers
|
@@ -37,8 +37,12 @@ rake metrics:flog:custom # Generate a flog report from specified direct
|
|
37
37
|
rake metrics:flog:helpers # Flog code in app/helpers
|
38
38
|
rake metrics:flog:lib # Flog code in lib
|
39
39
|
rake metrics:flog:models # Flog code in app/models
|
40
|
+
rake metrics:reek # A code smell report using Reek
|
40
41
|
rake metrics:saikuro # A cyclomatic complexity report using Saikuro
|
41
|
-
|
42
|
+
|
43
|
+
Rails projects also have the following tasks:
|
44
|
+
|
45
|
+
rake metrics:stats # A stats report
|
42
46
|
|
43
47
|
See below for more detail on the individual tasks. It's recommended to use CruiseControl.rb to set up a metrics build. See the CruiseControl.rb online docs for more info on how to set up cc.rb and, once you've got that figured out, change the cruise_config.rb file inside your project to have these lines:
|
44
48
|
|
@@ -48,31 +52,77 @@ project.scheduler.polling_interval = 24.hours
|
|
48
52
|
Which will check for updates every 24 hours and run all the metrics rake tasks (migrating your test db first). The output will be visible from an individual build's detail page.
|
49
53
|
|
50
54
|
|
55
|
+
****Notes on configuration****
|
56
|
+
|
57
|
+
Metric_fu can be customized to your liking by adding the following to your Rakefile
|
58
|
+
|
59
|
+
MetricFu::Configuration.run do |config|
|
60
|
+
#define which metrics you want to use
|
61
|
+
config.metrics = [:coverage, :flog]
|
62
|
+
config.churn = { :start_date => lambda{ 3.months.ago } }
|
63
|
+
config.coverage = { :test_files => ['test/**/test_*.rb'] }
|
64
|
+
config.flog = { :dirs_to_flog => ['cms/app', 'cms/lib'] }
|
65
|
+
config.flay = { :dirs_to_flay => ['cms/app', 'cms/lib'] }
|
66
|
+
config.saikuro = { "--warn_cyclo" => "3", "--error_cyclo" => "4" }
|
67
|
+
end
|
68
|
+
|
69
|
+
|
51
70
|
****Notes on metrics:coverage****
|
52
71
|
|
53
72
|
When creating a coverage report, metric_fu runs all the tests in the test folder and specs in spec folder using Rcov.
|
73
|
+
You can configure the coverage test files pattern:
|
74
|
+
config.coverage[:test_files] = ['test/**/test_*.rb']
|
75
|
+
|
76
|
+
The default value is ['test/**/*_test.rb', 'spec/**/*_spec.rb']
|
54
77
|
|
55
78
|
|
56
79
|
****Notes on metrics:saikuro****
|
57
80
|
|
58
|
-
Saikuro is bundled with metric_fu so you don't have to install it. Look at the SAIKURO_README (or the internet) for more documentation on Saikuro. If you wish to change the options Saikuro is run with, then set this constant in your
|
59
|
-
|
60
|
-
|
81
|
+
Saikuro is bundled with metric_fu so you don't have to install it. Look at the SAIKURO_README (or the internet) for more documentation on Saikuro. If you wish to change the options Saikuro is run with, then set this constant in your configuration:
|
82
|
+
|
83
|
+
config.saikuro = { "--warn_cyclo" => "3", "--error_cyclo" => "4" }
|
84
|
+
|
85
|
+
config.saikuro is a hash that gets merged with the default options hash. The above example will set the warn_cyclo to 3 and the error_cyclo to 4 (which is way too low -- it's just an example) instructing Saikuro to flag methods with a higher cyclomatic complexity in it's report.
|
86
|
+
|
87
|
+
If you want to have Saikuro look at multiple folders you can put something like this in your configuration:
|
61
88
|
|
62
|
-
|
89
|
+
config.saikuro = {"--input_directory" => '"cms/app | cms/lib"'}
|
63
90
|
|
64
|
-
|
65
|
-
|
91
|
+
|
92
|
+
****Notes on metrics:flay****
|
93
|
+
|
94
|
+
Flay analyzes ruby code for structural similarities.
|
95
|
+
You can configure which directories need to be flayed.
|
96
|
+
The defaults are 'lib' for non Rails projects and ['app', 'lib'] for Rails projects.
|
97
|
+
|
98
|
+
config.flay[:dirs_to_flay] = ['cms/app', 'cms/lib']
|
66
99
|
|
67
100
|
|
68
101
|
****Notes on metrics:flog****
|
69
102
|
|
70
103
|
Flog is another way of measuring complexity (or tortured code as the Flog authors like to put it). You should check out the awesome, and a little scary, Flog website for more info.
|
104
|
+
'rake metrics:flog:custom' allows you to specify a custom set of directories to Flog (in your configuration).
|
105
|
+
The defaults are 'lib' for non Rails projects and ['app', 'lib'] for Rails projects.
|
106
|
+
|
107
|
+
config.flog[:dirs_to_flog] = ['cms/app', 'cms/lib']
|
108
|
+
|
109
|
+
|
110
|
+
****Notes on metrics:reek****
|
111
|
+
|
112
|
+
Reek detects common code smells in ruby code.
|
113
|
+
You can configure which directories need to be checked.
|
114
|
+
The defaults are 'lib' for non Rails projects and ['app', 'lib'] for Rails projects.
|
115
|
+
|
116
|
+
config.reek[:dirs_to_reek] = ['cms/app', 'cms/lib']
|
117
|
+
|
71
118
|
|
72
|
-
|
119
|
+
****Notes on metrics:roodi****
|
73
120
|
|
74
|
-
|
121
|
+
Roodi parses your Ruby code and warns you about design issues you have based on the checks that is has configured.
|
122
|
+
You can configure which directories need to be checked.
|
123
|
+
The defaults are 'lib' for non Rails projects and ['app', 'lib'] for Rails projects.
|
75
124
|
|
125
|
+
config.roodi[:dirs_to_roodi] = ['cms/app', 'cms/lib']
|
76
126
|
|
77
127
|
****Notes on metrics:stats****
|
78
128
|
|
@@ -83,15 +133,15 @@ This is just 'rake stats' for Rails put into a file. On my projects I like to b
|
|
83
133
|
|
84
134
|
Files that change a lot in your project may be bad a sign. This task uses "svn log" to identify those files and put them in a report. The default is to start counting changes from the beginning of your project, which might be too far back so you can change like so:
|
85
135
|
|
86
|
-
|
136
|
+
config.churn = { :start_date => lambda{ 3.months.ago } }
|
87
137
|
|
88
138
|
The Proc is there because '3.months.ago' only works when after the Rails Environment is loaded (and Rails extends Fixnum) which I didn't want to do every time you run a rake task.
|
89
139
|
|
90
140
|
You can also change the minimum churn count like so:
|
91
141
|
|
92
|
-
|
142
|
+
config.churn = { :minimum_churn_count => 3 }
|
93
143
|
|
94
144
|
|
95
145
|
****Thanks****
|
96
146
|
|
97
|
-
I'd like to thank the authors of Saikuro, Flog, Rcov, CruiseControl.rb, and Rails for creating such excellent open source products. Also Sean Soper, Michael Schubert, Kurtis Seebaldt, Toby Tripp, Paul Gross, and Chirdeep Shetty for their help and advice.
|
147
|
+
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.
|
data/Rakefile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/rdoctask'
|
3
|
+
require 'spec/rake/spectask'
|
4
|
+
require File.join(File.dirname(__FILE__), 'lib', 'metric_fu')
|
5
|
+
|
6
|
+
desc "Run all specs in spec directory"
|
7
|
+
Spec::Rake::SpecTask.new(:spec) do |t|
|
8
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
9
|
+
end
|
10
|
+
|
11
|
+
task :default => [:"metrics:all"]
|
data/TODO
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
== TODO list
|
2
|
+
|
3
|
+
* Color code flog results with scale from: http://jakescruggs.blogspot.com/2008/08/whats-good-flog-score.html
|
4
|
+
* Extract functionality from rake files and put under test
|
5
|
+
* Integrate Flog, Saikuro, and Coverage into one report so you can see methods that have high complexity and low coverage (this is a big one)
|
6
|
+
* Integrate MD5 hashing with remainder of reports
|
7
|
+
* Move HTML out of code and into templates/
|
8
|
+
* Replace #generate_report with #new on each metric class
|
9
|
+
* Make each class descend from MetricFu::CodeMetric
|
10
|
+
* Generate metrics:* rake tasks for each of CodeMetric's descendants
|
11
|
+
* Update flog specs so that they actually run flog
|
12
|
+
* Add flay specs that run flay
|
13
|
+
* Convert readme to markdown and rename to README.mkdn so github will render it
|
@@ -0,0 +1,159 @@
|
|
1
|
+
require 'erb'
|
2
|
+
module MetricFu
|
3
|
+
|
4
|
+
TEMPLATE_DIR = File.join(File.dirname(__FILE__), '..', 'templates')
|
5
|
+
BASE_DIRECTORY = ENV['CC_BUILD_ARTIFACTS'] || 'tmp/metric_fu'
|
6
|
+
RAILS = File.exist?("config/environment.rb")
|
7
|
+
|
8
|
+
if RAILS
|
9
|
+
CODE_DIRS = ['app', 'lib']
|
10
|
+
DEFAULT_METRICS = [:coverage, :churn, :flog, :flay, :reek, :roodi, :stats, :saikuro ]
|
11
|
+
else
|
12
|
+
CODE_DIRS = ['lib']
|
13
|
+
DEFAULT_METRICS = [:coverage, :churn, :flog, :flay, :reek, :roodi, :saikuro ]
|
14
|
+
end
|
15
|
+
|
16
|
+
module Base
|
17
|
+
|
18
|
+
######################################################################
|
19
|
+
# Base class for report Generators
|
20
|
+
#
|
21
|
+
class Generator
|
22
|
+
|
23
|
+
def initialize(options={})
|
24
|
+
@base_dir = self.class.metric_dir
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.metric_dir
|
28
|
+
File.join(BASE_DIRECTORY, template_name)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.template_name
|
32
|
+
self.to_s.split('::').last.downcase
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.generate_report(options={})
|
36
|
+
FileUtils.mkdir_p(metric_dir, :verbose => false) unless File.directory?(metric_dir)
|
37
|
+
self.new(options).generate_report
|
38
|
+
end
|
39
|
+
|
40
|
+
def save_html(content, file='index.html')
|
41
|
+
open("#{@base_dir}/#{file}", "w") do |f|
|
42
|
+
f.puts content
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def generate_report
|
47
|
+
save_html(generate_html)
|
48
|
+
end
|
49
|
+
|
50
|
+
def generate_html
|
51
|
+
analyze
|
52
|
+
html = ERB.new(File.read(template_file)).result(binding)
|
53
|
+
end
|
54
|
+
|
55
|
+
def template_name
|
56
|
+
self.class.template_name
|
57
|
+
end
|
58
|
+
|
59
|
+
def template_file
|
60
|
+
File.join(MetricFu::TEMPLATE_DIR, "#{template_name}.html.erb")
|
61
|
+
end
|
62
|
+
|
63
|
+
########################
|
64
|
+
# Template methods
|
65
|
+
|
66
|
+
def inline_css(css)
|
67
|
+
open(File.join(MetricFu::TEMPLATE_DIR, css)) { |f| f.read }
|
68
|
+
end
|
69
|
+
|
70
|
+
def link_to_filename(name, line = nil)
|
71
|
+
filename = File.expand_path(name)
|
72
|
+
if PLATFORM['darwin']
|
73
|
+
%{<a href="txmt://open/?url=file://#{filename}&line=#{line}">#{name}</a>}
|
74
|
+
else
|
75
|
+
%{<a href="file://#{filename}">#{name}</a>}
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def cycle(first_value, second_value, iteration)
|
80
|
+
return first_value if iteration % 2 == 0
|
81
|
+
return second_value
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
class << self
|
87
|
+
# The Configuration instance used to configure the Rails environment
|
88
|
+
def configuration
|
89
|
+
@@configuration ||= Configuration.new
|
90
|
+
end
|
91
|
+
|
92
|
+
def churn
|
93
|
+
configuration.churn
|
94
|
+
end
|
95
|
+
|
96
|
+
def coverage
|
97
|
+
configuration.coverage
|
98
|
+
end
|
99
|
+
|
100
|
+
def flay
|
101
|
+
configuration.flay
|
102
|
+
end
|
103
|
+
|
104
|
+
def flog
|
105
|
+
configuration.flog
|
106
|
+
end
|
107
|
+
|
108
|
+
def metrics
|
109
|
+
configuration.metrics
|
110
|
+
end
|
111
|
+
|
112
|
+
def open_in_browser?
|
113
|
+
PLATFORM['darwin'] && !ENV['CC_BUILD_ARTIFACTS']
|
114
|
+
end
|
115
|
+
|
116
|
+
def saikuro
|
117
|
+
configuration.saikuro
|
118
|
+
end
|
119
|
+
|
120
|
+
def reek
|
121
|
+
configuration.reek
|
122
|
+
end
|
123
|
+
|
124
|
+
def roodi
|
125
|
+
configuration.roodi
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
class Configuration
|
131
|
+
attr_accessor :churn, :coverage, :flay, :flog, :metrics, :reek, :roodi, :saikuro
|
132
|
+
def initialize
|
133
|
+
raise "Use config.churn instead of MetricFu::CHURN_OPTIONS" if defined? ::MetricFu::CHURN_OPTIONS
|
134
|
+
raise "Use config.flog[:dirs_to_flog] instead of MetricFu::DIRECTORIES_TO_FLOG" if defined? ::MetricFu::DIRECTORIES_TO_FLOG
|
135
|
+
raise "Use config.saikuro instead of MetricFu::SAIKURO_OPTIONS" if defined? ::MetricFu::SAIKURO_OPTIONS
|
136
|
+
reset
|
137
|
+
end
|
138
|
+
|
139
|
+
def self.run()
|
140
|
+
yield MetricFu.configuration
|
141
|
+
end
|
142
|
+
|
143
|
+
def reset
|
144
|
+
@churn = {}
|
145
|
+
@coverage = { :test_files => ['test/**/*_test.rb', 'spec/**/*_spec.rb'] }
|
146
|
+
@flay = { :dirs_to_flay => CODE_DIRS}
|
147
|
+
@flog = { :dirs_to_flog => CODE_DIRS}
|
148
|
+
@reek = { :dirs_to_reek => CODE_DIRS}
|
149
|
+
@roodi = { :dirs_to_roodi => CODE_DIRS}
|
150
|
+
@metrics = DEFAULT_METRICS
|
151
|
+
@saikuro = {}
|
152
|
+
end
|
153
|
+
|
154
|
+
def saikuro=(options)
|
155
|
+
raise "saikuro need to be a Hash" unless options.is_a?(Hash)
|
156
|
+
@saikuro = options
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module MetricFu
|
2
|
+
|
3
|
+
def self.generate_churn_report
|
4
|
+
Churn.generate_report(MetricFu.churn)
|
5
|
+
system("open #{Churn.metric_dir}/index.html") if open_in_browser?
|
6
|
+
end
|
7
|
+
|
8
|
+
class Churn < Base::Generator
|
9
|
+
|
10
|
+
def initialize(options={})
|
11
|
+
@base_dir = File.join(MetricFu::BASE_DIRECTORY, template_name)
|
12
|
+
if File.exist?(".git")
|
13
|
+
@source_control = Git.new(options[:start_date])
|
14
|
+
elsif File.exist?(".svn")
|
15
|
+
@source_control = Svn.new(options[:start_date])
|
16
|
+
else
|
17
|
+
raise "Churning requires a subversion or git repo"
|
18
|
+
end
|
19
|
+
|
20
|
+
@minimum_churn_count = options[:minimum_churn_count] || 5
|
21
|
+
end
|
22
|
+
|
23
|
+
def analyze
|
24
|
+
@changes = parse_log_for_changes.reject! {|file, change_count| change_count < @minimum_churn_count}
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def parse_log_for_changes
|
30
|
+
changes = {}
|
31
|
+
|
32
|
+
logs = @source_control.get_logs
|
33
|
+
logs.each do |line|
|
34
|
+
changes[line] ? changes[line] += 1 : changes[line] = 1
|
35
|
+
end
|
36
|
+
changes
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
class SourceControl
|
41
|
+
def initialize(start_date=nil)
|
42
|
+
@start_date = start_date
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
def require_rails_env
|
47
|
+
# not sure if the following works because active_support might only be in vendor/rails
|
48
|
+
# require 'activesupport'
|
49
|
+
require RAILS_ROOT + '/config/environment'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class Git < SourceControl
|
54
|
+
def get_logs
|
55
|
+
`git log #{date_range} --name-only --pretty=format:`.split(/\n/).reject{|line| line == ""}
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
def date_range
|
60
|
+
if @start_date
|
61
|
+
require_rails_env
|
62
|
+
"--after=#{@start_date.call.strftime('%Y-%m-%d')}"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
class Svn < SourceControl
|
69
|
+
def get_logs
|
70
|
+
`svn log #{date_range} --verbose`.split(/\n/).map { |line| clean_up_svn_line(line) }.compact
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
def date_range
|
75
|
+
if @start_date
|
76
|
+
require_rails_env
|
77
|
+
"--revision {#{@start_date.call.strftime('%Y-%m-%d')}}:{#{Time.now.strftime('%Y-%m-%d')}}"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def clean_up_svn_line(line)
|
82
|
+
m = line.match(/\W*[A,M]\W+(\/.*)\b/)
|
83
|
+
m ? m[1] : nil
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module MetricFu
|
2
|
+
|
3
|
+
def self.generate_flay_report
|
4
|
+
Flay.generate_report
|
5
|
+
system("open #{Flay.metric_dir}/index.html") if open_in_browser?
|
6
|
+
end
|
7
|
+
|
8
|
+
class Flay < Base::Generator
|
9
|
+
|
10
|
+
def analyze
|
11
|
+
files_to_flay = MetricFu.flay[:dirs_to_flay].map{|dir| Dir[File.join(dir, "**/*.rb")] }
|
12
|
+
output = `flay #{files_to_flay.join(" ")}`
|
13
|
+
@matches = output.chomp.split("\n\n").map{|m| m.split("\n ") }
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
module MetricFu
|
2
|
+
|
3
|
+
def self.generate_flog_report
|
4
|
+
Flog::Generator.generate_report
|
5
|
+
system("open #{Flog::Generator.metric_dir}/index.html") if open_in_browser?
|
6
|
+
end
|
7
|
+
|
8
|
+
module Flog
|
9
|
+
class Generator < Base::Generator
|
10
|
+
def generate_report
|
11
|
+
@base_dir = self.class.metric_dir
|
12
|
+
pages = []
|
13
|
+
flog_results.each do |filename|
|
14
|
+
page = Base.parse(open(filename, "r") { |f| f.read })
|
15
|
+
if page
|
16
|
+
page.filename = filename
|
17
|
+
pages << page
|
18
|
+
end
|
19
|
+
end
|
20
|
+
generate_pages(pages)
|
21
|
+
end
|
22
|
+
|
23
|
+
def generate_pages(pages)
|
24
|
+
pages.each do |page|
|
25
|
+
unless MetricFu::MD5Tracker.file_already_counted?(page.filename)
|
26
|
+
generate_page(page)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
save_html(ERB.new(File.read(template_file)).result(binding))
|
30
|
+
end
|
31
|
+
|
32
|
+
def generate_page(page)
|
33
|
+
save_html(page.to_html, page.path)
|
34
|
+
end
|
35
|
+
|
36
|
+
def flog_results
|
37
|
+
Dir.glob("#{@base_dir}/**/*.txt")
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.template_name
|
41
|
+
"flog"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
SCORE_FORMAT = "%0.2f"
|
46
|
+
|
47
|
+
class Base
|
48
|
+
METHOD_LINE_REGEX = /([A-Za-z]+#.*):\s\((\d+\.\d+)\)/
|
49
|
+
OPERATOR_LINE_REGEX = /\s+(\d+\.\d+):\s(.*)$/
|
50
|
+
|
51
|
+
class << self
|
52
|
+
|
53
|
+
def parse(text)
|
54
|
+
score = text[/\w+ = (\d+\.\d+)/, 1]
|
55
|
+
return nil unless score
|
56
|
+
page = Page.new(score)
|
57
|
+
|
58
|
+
text.each_line do |method_line|
|
59
|
+
if match = method_line.match(METHOD_LINE_REGEX)
|
60
|
+
page.scanned_methods << ScannedMethod.new(match[1], match[2])
|
61
|
+
end
|
62
|
+
|
63
|
+
if match = method_line.match(OPERATOR_LINE_REGEX)
|
64
|
+
return if page.scanned_methods.empty?
|
65
|
+
page.scanned_methods.last.operators << Operator.new(match[1], match[2])
|
66
|
+
end
|
67
|
+
end
|
68
|
+
page
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
class Page < MetricFu::Base::Generator
|
75
|
+
attr_accessor :filename, :score, :scanned_methods
|
76
|
+
|
77
|
+
def initialize(score, scanned_methods = [])
|
78
|
+
@score = score.to_f
|
79
|
+
@scanned_methods = scanned_methods
|
80
|
+
end
|
81
|
+
|
82
|
+
def path
|
83
|
+
@path ||= File.basename(filename, ".txt") + '.html'
|
84
|
+
end
|
85
|
+
|
86
|
+
def to_html
|
87
|
+
ERB.new(File.read(template_file)).result(binding)
|
88
|
+
end
|
89
|
+
|
90
|
+
def average_score
|
91
|
+
return 0 if scanned_methods.length == 0
|
92
|
+
sum = 0
|
93
|
+
scanned_methods.each do |m|
|
94
|
+
sum += m.score
|
95
|
+
end
|
96
|
+
sum / scanned_methods.length
|
97
|
+
end
|
98
|
+
|
99
|
+
def highest_score
|
100
|
+
scanned_methods.inject(0) do |highest, m|
|
101
|
+
m.score > highest ? m.score : highest
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def template_name
|
106
|
+
'flog_page'
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
class Operator
|
111
|
+
attr_accessor :score, :operator
|
112
|
+
|
113
|
+
def initialize(score, operator)
|
114
|
+
@score = score.to_f
|
115
|
+
@operator = operator
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
class ScannedMethod
|
120
|
+
attr_accessor :name, :score, :operators
|
121
|
+
|
122
|
+
def initialize(name, score, operators = [])
|
123
|
+
@name = name
|
124
|
+
@score = score.to_f
|
125
|
+
@operators = operators
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
@@ -9,11 +9,11 @@ module MetricFu
|
|
9
9
|
class << self
|
10
10
|
def md5_dir(path_to_file, base_dir)
|
11
11
|
File.join(base_dir,
|
12
|
-
path_to_file.split('/')[0..-2].join('/'))
|
12
|
+
path_to_file.split('/')[0..-2].join('/'))
|
13
13
|
end
|
14
14
|
|
15
15
|
def md5_file(path_to_file, base_dir)
|
16
|
-
File.join(md5_dir(path_to_file, base_dir),
|
16
|
+
File.join(md5_dir(path_to_file, base_dir),
|
17
17
|
path_to_file.split('/').last.sub(/\.[a-z]+/, '.md5'))
|
18
18
|
end
|
19
19
|
|
@@ -25,17 +25,17 @@ module MetricFu
|
|
25
25
|
f.close
|
26
26
|
md5
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
def file_changed?(path_to_file, base_dir)
|
30
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)
|
31
|
+
return !!track(path_to_file, base_dir) unless File.exist?(orig_md5_file)
|
32
32
|
|
33
33
|
current_md5 = ""
|
34
34
|
file = File.open(orig_md5_file, 'r')
|
35
35
|
file.each_line { |line| current_md5 << line }
|
36
36
|
file.close
|
37
37
|
current_md5.chomp!
|
38
|
-
|
38
|
+
|
39
39
|
new_md5 = Digest::MD5.hexdigest(File.read(path_to_file))
|
40
40
|
new_md5.chomp!
|
41
41
|
|
@@ -43,7 +43,7 @@ module MetricFu
|
|
43
43
|
|
44
44
|
return new_md5 != current_md5
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
def file_already_counted?(path_to_file)
|
48
48
|
return @@unchanged_md5s.include?(path_to_file)
|
49
49
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module MetricFu
|
2
|
+
|
3
|
+
def self.generate_reek_report
|
4
|
+
Reek.generate_report
|
5
|
+
system("open #{Reek.metric_dir}/index.html") if open_in_browser?
|
6
|
+
end
|
7
|
+
|
8
|
+
class Reek < Base::Generator
|
9
|
+
|
10
|
+
def analyze
|
11
|
+
files_to_reek = MetricFu.reek[:dirs_to_reek].map{|dir| Dir[File.join(dir, "**/*.rb")] }
|
12
|
+
output = `reek #{files_to_reek.join(" ")}`
|
13
|
+
@matches = output.chomp.split("\n\n").map{|m| m.split("\n") }
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|