leh-metric_fu 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +98 -0
- data/MIT-LICENSE +22 -0
- data/Manifest.txt +25 -0
- data/README +154 -0
- data/Rakefile +11 -0
- data/TODO +13 -0
- data/lib/metric_fu/base.rb +160 -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 +52 -0
- data/lib/metric_fu/reek.rb +17 -0
- data/lib/metric_fu/roodi.rb +17 -0
- data/lib/metric_fu/saikuro/saikuro.rb +1214 -0
- data/lib/metric_fu.rb +3 -0
- data/lib/tasks/churn.rake +9 -0
- data/lib/tasks/coverage.rake +54 -0
- data/lib/tasks/flay.rake +6 -0
- data/lib/tasks/flog.rake +69 -0
- data/lib/tasks/metric_fu.rake +24 -0
- data/lib/tasks/metric_fu.rb +6 -0
- data/lib/tasks/railroad.rake +39 -0
- data/lib/tasks/reek.rake +6 -0
- data/lib/tasks/roodi.rake +7 -0
- data/lib/tasks/saikuro.rake +35 -0
- data/lib/tasks/stats.rake +14 -0
- 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 +38 -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 +167 -0
@@ -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
|
@@ -0,0 +1,52 @@
|
|
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
|
@@ -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
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module MetricFu
|
2
|
+
|
3
|
+
def self.generate_roodi_report
|
4
|
+
MetricFu::Roodi.generate_report
|
5
|
+
system("open #{Roodi.metric_dir}/index.html") if open_in_browser?
|
6
|
+
end
|
7
|
+
|
8
|
+
class Roodi < Base::Generator
|
9
|
+
|
10
|
+
def analyze
|
11
|
+
files_to_analyze = MetricFu.roodi[:dirs_to_roodi].map{|dir| Dir[File.join(dir, "**/*.rb")] }
|
12
|
+
output = `roodi #{files_to_analyze.join(" ")}`
|
13
|
+
@matches = output.chomp.split("\n").map{|m| m.split(" - ") }
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|