edouard-metric_fu 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. data/README +1 -1
  2. data/Rakefile +4 -4
  3. data/spec/base/configuration_spec.rb +1 -1
  4. data/spec/base/generator_spec.rb +0 -22
  5. data/spec/generators/churn_spec.rb +7 -7
  6. data/spec/generators/flay_spec.rb +0 -3
  7. data/spec/generators/flog_spec.rb +1 -9
  8. data/spec/generators/reek_spec.rb +0 -1
  9. data/spec/generators/saikuro_spec.rb +11 -21
  10. metadata +18 -56
  11. data/lib/base/base_template.rb +0 -134
  12. data/lib/base/configuration.rb +0 -207
  13. data/lib/base/generator.rb +0 -160
  14. data/lib/base/graph.rb +0 -37
  15. data/lib/base/md5_tracker.rb +0 -52
  16. data/lib/base/report.rb +0 -100
  17. data/lib/generators/churn.rb +0 -91
  18. data/lib/generators/flay.rb +0 -34
  19. data/lib/generators/flog.rb +0 -133
  20. data/lib/generators/rcov.rb +0 -87
  21. data/lib/generators/reek.rb +0 -37
  22. data/lib/generators/roodi.rb +0 -31
  23. data/lib/generators/saikuro.rb +0 -209
  24. data/lib/generators/stats.rb +0 -43
  25. data/lib/graphs/flay_grapher.rb +0 -34
  26. data/lib/graphs/flog_grapher.rb +0 -37
  27. data/lib/graphs/rcov_grapher.rb +0 -34
  28. data/lib/graphs/reek_grapher.rb +0 -44
  29. data/lib/graphs/roodi_grapher.rb +0 -34
  30. data/lib/metric_fu.rb +0 -24
  31. data/lib/templates/awesome/awesome_template.rb +0 -30
  32. data/lib/templates/awesome/churn.html.erb +0 -19
  33. data/lib/templates/awesome/default.css +0 -66
  34. data/lib/templates/awesome/flay.html.erb +0 -27
  35. data/lib/templates/awesome/flog.html.erb +0 -46
  36. data/lib/templates/awesome/index.html.erb +0 -28
  37. data/lib/templates/awesome/layout.html.erb +0 -27
  38. data/lib/templates/awesome/rcov.html.erb +0 -36
  39. data/lib/templates/awesome/reek.html.erb +0 -34
  40. data/lib/templates/awesome/roodi.html.erb +0 -21
  41. data/lib/templates/awesome/saikuro.html.erb +0 -71
  42. data/lib/templates/awesome/stats.html.erb +0 -41
  43. data/lib/templates/standard/churn.html.erb +0 -31
  44. data/lib/templates/standard/default.css +0 -64
  45. data/lib/templates/standard/flay.html.erb +0 -34
  46. data/lib/templates/standard/flog.html.erb +0 -53
  47. data/lib/templates/standard/index.html.erb +0 -38
  48. data/lib/templates/standard/rcov.html.erb +0 -43
  49. data/lib/templates/standard/reek.html.erb +0 -42
  50. data/lib/templates/standard/roodi.html.erb +0 -29
  51. data/lib/templates/standard/saikuro.html.erb +0 -84
  52. data/lib/templates/standard/standard_template.rb +0 -26
  53. data/lib/templates/standard/stats.html.erb +0 -55
  54. data/tasks/metric_fu.rake +0 -19
  55. data/tasks/railroad.rake +0 -39
  56. data/vendor/_fonts/monaco.ttf +0 -0
  57. data/vendor/saikuro/saikuro.rb +0 -1214
data/lib/base/report.rb DELETED
@@ -1,100 +0,0 @@
1
- module MetricFu
2
-
3
- # MetricFu.report memoizes access to a Report object, that will be
4
- # used throughout the lifecycle of the MetricFu app.
5
- def self.report
6
- @report ||= Report.new
7
- end
8
-
9
- # = Report
10
- #
11
- # The Report class is responsible two things:
12
- #
13
- # It adds information to the yaml report, produced by the system
14
- # as a whole, for each of the generators used in this test run.
15
- #
16
- # It also handles passing the information from each generator used
17
- # in this test run out to the template class set in
18
- # MetricFu::Configuration.
19
- class Report
20
-
21
- # Renders the result of the report_hash into a yaml serialization
22
- # ready for writing out to a file.
23
- #
24
- # @return YAML
25
- # A YAML object containing the results of the report generation
26
- # process
27
- def to_yaml
28
- report_hash.to_yaml
29
- end
30
-
31
-
32
- def report_hash #:nodoc:
33
- @report_hash ||= {}
34
- end
35
-
36
- # Instantiates a new template class based on the configuration set
37
- # in MetricFu::Configuration, or through the MetricFu.config block
38
- # in your rake file (defaults to the included StandardTemplate) and
39
- # assigns the report_hash to the report_hash to the template and
40
- # asks itself to write itself out.
41
- def save_templatized_report
42
- @template = MetricFu.template_class.new
43
- @template.report = report_hash
44
- @template.write
45
- end
46
-
47
- # Adds a hash from a passed report, produced by one of the Generator
48
- # classes to the aggregate report_hash managed by this hash.
49
- #
50
- # @param report_type Hash
51
- # The hash to add to the aggregate report_hash
52
- def add(report_type)
53
- clazz = MetricFu.const_get(report_type.to_s.capitalize)
54
- report_hash.merge!(clazz.generate_report)
55
- end
56
-
57
- # Saves the passed in content to the passed in directory. If
58
- # a filename is passed in it will be used as the name of the
59
- # file, otherwise it will default to 'index.html'
60
- #
61
- # @param content String
62
- # A string containing the content (usually html) to be written
63
- # to the file.
64
- #
65
- # @param dir String
66
- # A dir containing the path to the directory to write the file in.
67
- #
68
- # @param file String
69
- # A filename to save the path as. Defaults to 'index.html'.
70
- #
71
- def save_output(content, dir, file='index.html')
72
- open("#{dir}/#{file}", "w") do |f|
73
- f.puts content
74
- end
75
- end
76
-
77
- # Checks to discover whether we should try and open the results
78
- # of the report in the browser on this system. We only try and open
79
- # in the browser if we're on OS X and we're not running in a
80
- # CruiseControl.rb environment. See MetricFu.configuration for more
81
- # details about how we make those guesses.
82
- #
83
- # @return Boolean
84
- # Should we open in the browser or not?
85
- def open_in_browser?
86
- MetricFu.configuration.platform.include?('darwin') &&
87
- ! MetricFu.configuration.is_cruise_control_rb?
88
- end
89
-
90
- # Shows 'index.html' from the passed directory in the browser
91
- # if we're able to open the browser on this platform.
92
- #
93
- # @param dir String
94
- # The directory path where the 'index.html' we want to open is
95
- # stored
96
- def show_in_browser(dir)
97
- system("open #{dir}/index.html") if open_in_browser?
98
- end
99
- end
100
- end
@@ -1,91 +0,0 @@
1
- require 'chronic'
2
- require 'generator'
3
- module MetricFu
4
-
5
- class Churn < Generator
6
-
7
-
8
- def initialize(options={})
9
- super
10
- if self.class.git?
11
- @source_control = Git.new(MetricFu.churn[:start_date])
12
- elsif File.exist?(".svn")
13
- @source_control = Svn.new(MetricFu.churn[:start_date])
14
- else
15
- raise "Churning requires a subversion or git repo"
16
- end
17
- @minimum_churn_count = MetricFu.churn[:minimum_churn_count] || 5
18
- end
19
-
20
- def self.git?
21
- system("git branch")
22
- end
23
-
24
- def emit
25
- @changes = parse_log_for_changes.reject {|file, change_count| change_count < @minimum_churn_count}
26
- end
27
-
28
- def analyze
29
- @changes = @changes.to_a.sort {|x,y| y[1] <=> x[1]}
30
- @changes = @changes.map {|change| {:file_path => change[0], :times_changed => change[1] }}
31
- end
32
-
33
- def to_h
34
- {:churn => {:changes => @changes}}
35
- end
36
-
37
- private
38
-
39
- def parse_log_for_changes
40
- changes = {}
41
-
42
- logs = @source_control.get_logs
43
- logs.each do |line|
44
- changes[line] ? changes[line] += 1 : changes[line] = 1
45
- end
46
- changes
47
- end
48
-
49
-
50
- class SourceControl
51
- def initialize(start_date=nil)
52
- @start_date = start_date
53
- end
54
- end
55
-
56
- class Git < SourceControl
57
- def get_logs
58
- `git log #{date_range} --name-only --pretty=format:`.split(/\n/).reject{|line| line == ""}
59
- end
60
-
61
- private
62
- def date_range
63
- if @start_date
64
- date = Chronic.parse(@start_date)
65
- "--after=#{date.strftime('%Y-%m-%d')}"
66
- end
67
- end
68
-
69
- end
70
-
71
- class Svn < SourceControl
72
- def get_logs
73
- `svn log #{date_range} --verbose`.split(/\n/).map { |line| clean_up_svn_line(line) }.compact
74
- end
75
-
76
- private
77
- def date_range
78
- if @start_date
79
- date = Chronic.parse(@start_date)
80
- "--revision {#{date.strftime('%Y-%m-%d')}}:{#{Time.now.strftime('%Y-%m-%d')}}"
81
- end
82
- end
83
-
84
- def clean_up_svn_line(line)
85
- m = line.match(/\W*[A,M]\W+(\/.*)\b/)
86
- m ? m[1] : nil
87
- end
88
- end
89
-
90
- end
91
- end
@@ -1,34 +0,0 @@
1
- require 'generator'
2
- module MetricFu
3
-
4
- class Flay < Generator
5
-
6
- def self.verify_dependencies!
7
- `flay --help`
8
- raise 'sudo gem install flay # if you want the flay tasks' unless $?.success?
9
- end
10
-
11
- def emit
12
- files_to_flay = MetricFu.flay[:dirs_to_flay].map{|dir| Dir[File.join(dir, "**/*.rb")] }
13
- @output = `flay #{files_to_flay.join(" ")}`
14
- end
15
-
16
- def analyze
17
- @matches = @output.chomp.split("\n\n").map{|m| m.split("\n ") }
18
- end
19
-
20
- def to_h
21
- target = []
22
- total_score = @matches.shift.first.split('=').last.strip
23
- @matches.each do |problem|
24
- reason = problem.shift.strip
25
- lines_info = problem.map do |full_line|
26
- name, line = full_line.split(":")
27
- {:name => name.strip, :line => line.strip}
28
- end
29
- target << [:reason => reason, :matches => lines_info]
30
- end
31
- {:flay => {:total_score => total_score, :matches => target.flatten}}
32
- end
33
- end
34
- end
@@ -1,133 +0,0 @@
1
- module MetricFu
2
-
3
- class Flog < Generator
4
- attr_reader :pages
5
-
6
- def self.verify_dependencies!
7
- `flog --help`
8
- raise 'sudo gem install flog # if you want the flog tasks' unless $?.success?
9
- end
10
-
11
- SCORE_FORMAT = "%0.2f"
12
- METHOD_LINE_REGEX = /(\d+\.\d+):\s+([A-Za-z:]+#.*)/
13
- OPERATOR_LINE_REGEX = /\s*(\d+\.\d+):\s(.*)$/
14
-
15
- def emit
16
- metric_dir = MetricFu::Flog.metric_directory
17
- MetricFu.flog[:dirs_to_flog].each do |directory|
18
- Dir.glob("#{directory}/**/*.rb").each do |filename|
19
- output_dir = "#{metric_dir}/#{filename.split("/")[0..-2].join("/")}"
20
- mkdir_p(output_dir, :verbose => false) unless File.directory?(output_dir)
21
- if MetricFu::MD5Tracker.file_changed?(filename, metric_dir)
22
- `flog -ad #{filename} > #{metric_dir}/#{filename.split('.')[0]}.txt`
23
- end
24
- end
25
- end
26
- rescue LoadError
27
- if RUBY_PLATFORM =~ /java/
28
- puts 'running in jruby - flog tasks not available'
29
- else
30
- puts 'sudo gem install flog # if you want the flog tasks'
31
- end
32
- end
33
-
34
- def parse(text)
35
- summary, methods_summary = text.split "\n\n"
36
- return unless summary
37
- score, average = summary.split("\n").map {|line| line[OPERATOR_LINE_REGEX, 1]}
38
- return nil unless score && methods_summary
39
- page = Flog::Page.new(score, average)
40
- methods_summary.each_line do |method_line|
41
- if match = method_line.match(METHOD_LINE_REGEX)
42
- page.scanned_methods << ScannedMethod.new(match[2], match[1])
43
- elsif match = method_line.match(OPERATOR_LINE_REGEX)
44
- return if page.scanned_methods.empty?
45
- page.scanned_methods.last.operators << Operator.new(match[1], match[2])
46
- end
47
- end
48
- page
49
- end
50
-
51
- def analyze
52
- @pages = []
53
- flog_results.each do |path|
54
- page = parse(open(path, "r") { |f| f.read })
55
- if page
56
- page.path = path.sub(metric_directory, "").sub(".txt", ".rb")
57
- @pages << page
58
- end
59
- end
60
- end
61
-
62
- def to_h
63
- number_of_methods = @pages.inject(0) {|count, page| count += page.scanned_methods.size}
64
- total_flog_score = @pages.inject(0) {|total, page| total += page.score}
65
- sorted_pages = @pages.sort_by {|page| page.score }.reverse
66
- {:flog => { :total => total_flog_score,
67
- :average => round_to_tenths(total_flog_score/number_of_methods),
68
- :pages => sorted_pages.map {|page| page.to_h}}}
69
- end
70
-
71
- def flog_results
72
- Dir.glob("#{metric_directory}/**/*.txt")
73
- end
74
-
75
- class Operator
76
- attr_accessor :score, :operator
77
-
78
- def initialize(score, operator)
79
- @score = score.to_f
80
- @operator = operator
81
- end
82
-
83
- def to_h
84
- {:score => @score, :operator => @operator}
85
- end
86
- end
87
-
88
- class ScannedMethod
89
- attr_accessor :name, :score, :operators
90
-
91
- def initialize(name, score, operators = [])
92
- @name = name
93
- @score = score.to_f
94
- @operators = operators
95
- end
96
-
97
- def to_h
98
- {:name => @name,
99
- :score => @score,
100
- :operators => @operators.map {|o| o.to_h}}
101
- end
102
- end
103
-
104
- end
105
-
106
- class Flog::Page < MetricFu::Generator
107
- attr_accessor :path, :score, :scanned_methods, :average_score
108
-
109
- def initialize(score, average_score, scanned_methods = [])
110
- @score = score.to_f
111
- @scanned_methods = scanned_methods
112
- @average_score = average_score.to_f
113
- end
114
-
115
- def filename
116
- File.basename(path, ".txt")
117
- end
118
-
119
- def to_h
120
- {:score => @score,
121
- :scanned_methods => @scanned_methods.map {|sm| sm.to_h},
122
- :highest_score => highest_score,
123
- :average_score => average_score,
124
- :path => path}
125
- end
126
-
127
- def highest_score
128
- scanned_methods.inject(0) do |highest, m|
129
- m.score > highest ? m.score : highest
130
- end
131
- end
132
- end
133
- end
@@ -1,87 +0,0 @@
1
- require 'enumerator'
2
-
3
- module MetricFu
4
-
5
- class Rcov < Generator
6
- NEW_FILE_MARKER = ("=" * 80) + "\n"
7
-
8
- def self.verify_dependencies!
9
- `flay --help`
10
- unless $?.success?
11
- if RUBY_PLATFORM =~ /java/
12
- raise 'running in jruby - rcov tasks not available'
13
- else
14
- raise 'sudo gem install rcov # if you want the rcov tasks'
15
- end
16
- end
17
- end
18
-
19
- class Line
20
- attr_accessor :content, :was_run
21
-
22
- def initialize(content, was_run)
23
- @content = content
24
- @was_run = was_run
25
- end
26
-
27
- def to_h
28
- {:content => @content, :was_run => @was_run}
29
- end
30
- end
31
-
32
- def emit
33
- begin
34
- FileUtils.rm_rf(MetricFu::Rcov.metric_directory, :verbose => false)
35
- Dir.mkdir(MetricFu::Rcov.metric_directory)
36
- test_files = FileList[*MetricFu.rcov[:test_files]].join(' ')
37
- rcov_opts = MetricFu.rcov[:rcov_opts].join(' ')
38
- output = ">> #{MetricFu::Rcov.metric_directory}/rcov.txt"
39
- `rcov --include-file #{test_files} #{rcov_opts} #{output}`
40
- rescue LoadError
41
- if RUBY_PLATFORM =~ /java/
42
- puts 'running in jruby - rcov tasks not available'
43
- else
44
- puts 'sudo gem install rcov # if you want the rcov tasks'
45
- end
46
- end
47
- end
48
-
49
-
50
- def analyze
51
- output = File.open(MetricFu::Rcov.metric_directory + '/rcov.txt').read
52
- output = output.split(NEW_FILE_MARKER)
53
- # Throw away the first entry - it's the execution time etc.
54
- output.shift
55
- files = {}
56
- output.each_slice(2) {|out| files[out.first.strip] = out.last}
57
- files.each_pair {|fname, content| files[fname] = content.split("\n") }
58
- files.each_pair do |fname, content|
59
- content.map! do |raw_line|
60
- if raw_line.match(/^!!/)
61
- line = Line.new(raw_line.gsub('!!', ' '), false).to_h
62
- else
63
- line = Line.new(raw_line, true).to_h
64
- end
65
- end
66
- files[fname] = {:lines => content}
67
- end
68
-
69
- # Calculate the percentage of lines run in each file
70
- @global_total_lines = 0
71
- @global_total_lines_run = 0
72
- files.each_pair do |fname, content|
73
- lines = content[:lines]
74
- @global_total_lines_run += lines_run = lines.find_all {|line| line[:was_run] == true }.length
75
- @global_total_lines += total_lines = lines.length
76
- percent_run = ((lines_run.to_f / total_lines.to_f) * 100).round
77
- files[fname][:percent_run] = percent_run
78
- end
79
- @rcov = files
80
- end
81
-
82
- def to_h
83
- global_percent_run = ((@global_total_lines_run.to_f / @global_total_lines.to_f) * 100)
84
- {:rcov => @rcov.merge({:global_percent_run => round_to_tenths(global_percent_run) })}
85
- end
86
- end
87
- end