cdd-metric_fu 1.3.1

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 (112) hide show
  1. data/.document +7 -0
  2. data/.gitignore +24 -0
  3. data/HISTORY +182 -0
  4. data/MIT-LICENSE +22 -0
  5. data/Manifest.txt +25 -0
  6. data/README.rdoc +20 -0
  7. data/Rakefile +59 -0
  8. data/TODO +9 -0
  9. data/VERSION +1 -0
  10. data/cdd-metric_fu.gemspec +200 -0
  11. data/home_page/back_all.jpg +0 -0
  12. data/home_page/churn.gif +0 -0
  13. data/home_page/flay.gif +0 -0
  14. data/home_page/flog.gif +0 -0
  15. data/home_page/footer.gif +0 -0
  16. data/home_page/header.jpg +0 -0
  17. data/home_page/img09.gif +0 -0
  18. data/home_page/index.html +277 -0
  19. data/home_page/rcov.gif +0 -0
  20. data/home_page/reek.gif +0 -0
  21. data/home_page/roodi.gif +0 -0
  22. data/home_page/saikuro.gif +0 -0
  23. data/home_page/stats.gif +0 -0
  24. data/home_page/styles.css +245 -0
  25. data/home_page/title.gif +0 -0
  26. data/home_page/title_back.gif +0 -0
  27. data/lib/base/base_template.rb +145 -0
  28. data/lib/base/configuration.rb +188 -0
  29. data/lib/base/generator.rb +167 -0
  30. data/lib/base/graph.rb +47 -0
  31. data/lib/base/md5_tracker.rb +52 -0
  32. data/lib/base/report.rb +100 -0
  33. data/lib/generators/churn.rb +34 -0
  34. data/lib/generators/flay.rb +35 -0
  35. data/lib/generators/flog.rb +172 -0
  36. data/lib/generators/rcov.rb +82 -0
  37. data/lib/generators/reek.rb +64 -0
  38. data/lib/generators/roodi.rb +33 -0
  39. data/lib/generators/saikuro.rb +221 -0
  40. data/lib/generators/stats.rb +59 -0
  41. data/lib/graphs/engines/bluff.rb +101 -0
  42. data/lib/graphs/engines/gchart.rb +120 -0
  43. data/lib/graphs/flay_grapher.rb +19 -0
  44. data/lib/graphs/flog_grapher.rb +39 -0
  45. data/lib/graphs/grapher.rb +18 -0
  46. data/lib/graphs/rails_best_practices_grapher.rb +24 -0
  47. data/lib/graphs/rcov_grapher.rb +19 -0
  48. data/lib/graphs/reek_grapher.rb +31 -0
  49. data/lib/graphs/roodi_grapher.rb +19 -0
  50. data/lib/graphs/stats_grapher.rb +22 -0
  51. data/lib/metric_fu.rb +32 -0
  52. data/lib/metric_fu/railtie.rb +10 -0
  53. data/lib/tasks/metric_fu.rake +22 -0
  54. data/lib/templates/awesome/awesome_template.rb +37 -0
  55. data/lib/templates/awesome/churn.html.erb +58 -0
  56. data/lib/templates/awesome/css/buttons.css +82 -0
  57. data/lib/templates/awesome/css/default.css +91 -0
  58. data/lib/templates/awesome/css/integrity.css +335 -0
  59. data/lib/templates/awesome/css/reset.css +7 -0
  60. data/lib/templates/awesome/flay.html.erb +34 -0
  61. data/lib/templates/awesome/flog.html.erb +53 -0
  62. data/lib/templates/awesome/index.html.erb +31 -0
  63. data/lib/templates/awesome/layout.html.erb +30 -0
  64. data/lib/templates/awesome/rcov.html.erb +42 -0
  65. data/lib/templates/awesome/reek.html.erb +40 -0
  66. data/lib/templates/awesome/roodi.html.erb +27 -0
  67. data/lib/templates/awesome/saikuro.html.erb +71 -0
  68. data/lib/templates/awesome/stats.html.erb +51 -0
  69. data/lib/templates/javascripts/bluff-min.js +1 -0
  70. data/lib/templates/javascripts/excanvas.js +35 -0
  71. data/lib/templates/javascripts/js-class.js +1 -0
  72. data/lib/templates/standard/churn.html.erb +31 -0
  73. data/lib/templates/standard/default.css +64 -0
  74. data/lib/templates/standard/flay.html.erb +34 -0
  75. data/lib/templates/standard/flog.html.erb +53 -0
  76. data/lib/templates/standard/index.html.erb +38 -0
  77. data/lib/templates/standard/rcov.html.erb +43 -0
  78. data/lib/templates/standard/reek.html.erb +42 -0
  79. data/lib/templates/standard/roodi.html.erb +29 -0
  80. data/lib/templates/standard/saikuro.html.erb +84 -0
  81. data/lib/templates/standard/standard_template.rb +26 -0
  82. data/lib/templates/standard/stats.html.erb +55 -0
  83. data/spec/base/base_template_spec.rb +161 -0
  84. data/spec/base/configuration_spec.rb +274 -0
  85. data/spec/base/generator_spec.rb +244 -0
  86. data/spec/base/graph_spec.rb +32 -0
  87. data/spec/base/md5_tracker_spec.rb +57 -0
  88. data/spec/base/report_spec.rb +139 -0
  89. data/spec/generators/churn_spec.rb +43 -0
  90. data/spec/generators/flay_spec.rb +110 -0
  91. data/spec/generators/flog_spec.rb +262 -0
  92. data/spec/generators/rcov_spec.rb +159 -0
  93. data/spec/generators/reek_spec.rb +125 -0
  94. data/spec/generators/saikuro_spec.rb +58 -0
  95. data/spec/generators/stats_spec.rb +74 -0
  96. data/spec/graphs/engines/bluff_spec.rb +17 -0
  97. data/spec/graphs/engines/gchart_spec.rb +109 -0
  98. data/spec/graphs/flay_grapher_spec.rb +37 -0
  99. data/spec/graphs/flog_grapher_spec.rb +45 -0
  100. data/spec/graphs/grapher_spec.rb +29 -0
  101. data/spec/graphs/rcov_grapher_spec.rb +37 -0
  102. data/spec/graphs/reek_grapher_spec.rb +47 -0
  103. data/spec/graphs/roodi_grapher_spec.rb +37 -0
  104. data/spec/graphs/stats_grapher_spec.rb +44 -0
  105. data/spec/resources/saikuro/app/controllers/sessions_controller.rb_cyclo.html +10 -0
  106. data/spec/resources/saikuro/app/controllers/users_controller.rb_cyclo.html +16 -0
  107. data/spec/resources/saikuro/index_cyclo.html +155 -0
  108. data/spec/resources/saikuro_sfiles/thing.rb_cyclo.html +11 -0
  109. data/spec/resources/yml/20090630.yml +7913 -0
  110. data/spec/spec.opts +6 -0
  111. data/spec/spec_helper.rb +7 -0
  112. metadata +285 -0
Binary file
Binary file
@@ -0,0 +1,145 @@
1
+ module MetricFu
2
+
3
+ # The Template class is intended as an abstract class for concrete
4
+ # template classes to subclass. It provides a variety of utility
5
+ # methods to make templating a bit easier. However, classes do not
6
+ # have to inherit from here in order to provide a template. The only
7
+ # requirement for a template class is that it provides a #write method
8
+ # to actually write out the template. See StandardTemplate for an
9
+ # example.
10
+ class Template
11
+ attr_accessor :report
12
+
13
+ private
14
+ # Creates a new erb evaluated result from the passed in section.
15
+ #
16
+ # @param section String
17
+ # The section name of
18
+ #
19
+ # @return String
20
+ # The erb evaluated string
21
+ def erbify(section)
22
+ require 'erb'
23
+ erb_doc = File.read(template(section))
24
+ ERB.new(erb_doc).result(binding)
25
+ end
26
+
27
+ # Determines whether a template file exists for a given section
28
+ # of the full template.
29
+ #
30
+ # @param section String
31
+ # The section of the template to check against
32
+ #
33
+ # @return Boolean
34
+ # Does a template file exist for this section or not?
35
+ def template_exists?(section)
36
+ File.exist?(template(section))
37
+ end
38
+
39
+ # Copies an instance variable mimicing the name of the section
40
+ # we are trying to render, with a value equal to the passed in
41
+ # constant. Allows the concrete template classes to refer to
42
+ # that instance variable from their ERB rendering
43
+ #
44
+ # @param section String
45
+ # The name of the instance variable to create
46
+ #
47
+ # @param contents Object
48
+ # The value to set as the value of the created instance
49
+ # variable
50
+ def create_instance_var(section, contents)
51
+ instance_variable_set("@#{section}", contents)
52
+ end
53
+
54
+ # Generates the filename of the template file to load and
55
+ # evaluate. In this case, the path to the template directory +
56
+ # the section name + .html.erb
57
+ #
58
+ # @param section String
59
+ # A section of the template to render
60
+ #
61
+ # @return String
62
+ # A file path
63
+ def template(section)
64
+ File.join(this_directory, section.to_s + ".html.erb")
65
+ end
66
+
67
+ # Returns the filename that the template will render into for
68
+ # a given section. In this case, the section name + '.html'
69
+ #
70
+ # @param section String
71
+ # A section of the template to render
72
+ #
73
+ # @return String
74
+ # The output filename
75
+ def output_filename(section)
76
+ section.to_s + ".html"
77
+ end
78
+
79
+ # Returns the contents of a given css file in order to
80
+ # render it inline into a template.
81
+ #
82
+ # @param css String
83
+ # The name of a css file to open
84
+ #
85
+ # @return String
86
+ # The contents of the css file
87
+ def inline_css(css)
88
+ open(File.join(this_directory, css)) { |f| f.read }
89
+ end
90
+
91
+ # Provides a link to open a file through the textmate protocol
92
+ # on Darwin, or otherwise, a simple file link.
93
+ #
94
+ # @param name String
95
+ #
96
+ # @param line Integer
97
+ # The line number to link to, if textmate is available. Defaults
98
+ # to nil
99
+ #
100
+ # @return String
101
+ # An anchor link to a textmate reference or a file reference
102
+ def link_to_filename(name, line = nil, link_content = nil)
103
+ "<a href='#{file_url(name, line)}'>#{link_content(name, line, link_content)}</a>"
104
+ end
105
+
106
+ def link_content(name, line=nil, link_content=nil) # :nodoc:
107
+ if link_content
108
+ link_content
109
+ elsif line
110
+ "#{name}:#{line}"
111
+ else
112
+ name
113
+ end
114
+ end
115
+
116
+ def file_url(name, line) # :nodoc:
117
+ filename = File.expand_path(name.gsub(/^\//, ''))
118
+ if MetricFu.configuration.platform.include?('darwin')
119
+ "txmt://open/?url=file://#{filename}" << (line ? "&line=#{line}" : "")
120
+ else
121
+ "file://#{filename}"
122
+ end
123
+ end
124
+
125
+ # Provides a brain dead way to cycle between two values during
126
+ # an iteration of some sort. Pass in the first_value, the second_value,
127
+ # and the cardinality of the iteration.
128
+ #
129
+ # @param first_value Object
130
+ #
131
+ # @param second_value Object
132
+ #
133
+ # @param iteration Integer
134
+ # The number of times through the iteration.
135
+ #
136
+ # @return Object
137
+ # The first_value if iteration is even. The second_value if
138
+ # iteration is odd.
139
+ def cycle(first_value, second_value, iteration)
140
+ return first_value if iteration % 2 == 0
141
+ return second_value
142
+ end
143
+
144
+ end
145
+ end
@@ -0,0 +1,188 @@
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
+ AVAILABLE_GRAPH_ENGINES = [:gchart, :bluff]
13
+
14
+ GRAPH_PERIOD = 30 # Only graph 30 days worth of data by default
15
+
16
+ # The @@configuration class variable holds a global type configuration
17
+ # object for any parts of the system to use.
18
+ def self.configuration
19
+ @@configuration ||= Configuration.new
20
+ end
21
+
22
+ # = Configuration
23
+ #
24
+ # The Configuration class, as it sounds, provides methods for
25
+ # configuring the behaviour of MetricFu.
26
+ #
27
+ # == Customization for Rails
28
+ #
29
+ # The Configuration class checks for the presence of a
30
+ # 'config/environment.rb' file. If the file is present, it assumes
31
+ # it is running in a Rails project. If it is, it will:
32
+ #
33
+ # * Add 'app' to the @code_dirs directory to include the
34
+ # code in the app directory in the processing
35
+ # * Add :stats to the list of metrics to run to get the Rails stats
36
+ # task
37
+ #
38
+ # == Customization for CruiseControl.rb
39
+ #
40
+ # The Configuration class checks for the presence of a
41
+ # 'CC_BUILD_ARTIFACTS' environment variable. If it's found
42
+ # it will change the default output directory from the default
43
+ # "tmp/metric_fu to the directory represented by 'CC_BUILD_ARTIFACTS'
44
+ #
45
+ # == Deprications
46
+ #
47
+ # The Configuration class checks for several deprecated constants
48
+ # that were previously used to configure MetricFu. These include
49
+ # CHURN_OPTIONS, DIRECTORIES_TO_FLOG, SAIKURO_OPTIONS,
50
+ # and MetricFu::SAIKURO_OPTIONS.
51
+ #
52
+ # These have been replaced by config.churn, config.flog and
53
+ # config.saikuro respectively.
54
+ class Configuration
55
+
56
+ def initialize #:nodoc:#
57
+ reset
58
+ add_attr_accessors_to_self
59
+ add_class_methods_to_metric_fu
60
+ end
61
+
62
+ # Searches through the instance variables of the class and
63
+ # creates a class method on the MetricFu module to read the value
64
+ # of the instance variable from the Configuration class.
65
+ def add_class_methods_to_metric_fu
66
+ instance_variables.each do |name|
67
+ method_name = name[1..-1].to_sym
68
+ method = <<-EOF
69
+ def self.#{method_name}
70
+ configuration.send(:#{method_name})
71
+ end
72
+ EOF
73
+ MetricFu.module_eval(method)
74
+ end
75
+ end
76
+
77
+ # Searches through the instance variables of the class and creates
78
+ # an attribute accessor on this instance of the Configuration
79
+ # class for each instance variable.
80
+ def add_attr_accessors_to_self
81
+ instance_variables.each do |name|
82
+ method_name = name[1..-1].to_sym
83
+ MetricFu::Configuration.send(:attr_accessor, method_name)
84
+ end
85
+ end
86
+
87
+ # This allows us to have a nice syntax like:
88
+ #
89
+ # MetricFu.run do |config|
90
+ # config.base_directory = 'tmp/metric_fu'
91
+ # end
92
+ #
93
+ # See the README for more information on configuration options.
94
+ def self.run
95
+ yield MetricFu.configuration
96
+ end
97
+
98
+ # This does the real work of the Configuration class, by setting
99
+ # up a bunch of instance variables to represent the configuration
100
+ # of the MetricFu app.
101
+ def reset
102
+ @base_directory = ENV['CC_BUILD_ARTIFACTS'] || 'tmp/metric_fu'
103
+ @scratch_directory = File.join(@base_directory, 'scratch')
104
+ @output_directory = File.join(@base_directory, 'output')
105
+ @data_directory = File.join('tmp/metric_fu', '_data')
106
+ @metric_fu_root_directory = File.join(File.dirname(__FILE__),
107
+ '..', '..')
108
+ @template_directory = File.join(@metric_fu_root_directory,
109
+ 'lib', 'templates')
110
+ @template_class = AwesomeTemplate
111
+ set_metrics
112
+ set_graphs
113
+ set_code_dirs
114
+ @flay = { :dirs_to_flay => @code_dirs,
115
+ :minimum_score => 100 }
116
+ @flog = { :dirs_to_flog => @code_dirs }
117
+ @reek = { :dirs_to_reek => @code_dirs }
118
+ @roodi = { :dirs_to_roodi => @code_dirs }
119
+ @saikuro = { :output_directory => @scratch_directory + '/saikuro',
120
+ :input_directory => @code_dirs,
121
+ :cyclo => "",
122
+ :filter_cyclo => "0",
123
+ :warn_cyclo => "5",
124
+ :error_cyclo => "7",
125
+ :formater => "text"}
126
+ @churn = {}
127
+ @stats = {}
128
+ @rcov = { :environment => 'test',
129
+ :test_files => ['test/**/*_test.rb',
130
+ 'spec/**/*_spec.rb'],
131
+ :rcov_opts => ["--sort coverage",
132
+ "--no-html",
133
+ "--text-coverage",
134
+ "--no-color",
135
+ "--profile",
136
+ "--rails",
137
+ "--exclude /gems/,/Library/,/usr/,spec"]}
138
+
139
+ @file_globs_to_ignore = []
140
+
141
+ @graph_engine = :bluff # can be :bluff or :gchart
142
+ @graph_period = MetricFu::GRAPH_PERIOD
143
+ end
144
+
145
+ # Perform a simple check to try and guess if we're running
146
+ # against a rails app.
147
+ #
148
+ # @todo This should probably be made a bit more robust.
149
+ def rails?
150
+ @rails = File.exist?("config/environment.rb")
151
+ end
152
+
153
+ # Add the :stats task to the AVAILABLE_METRICS constant if we're
154
+ # running within rails.
155
+ def set_metrics
156
+ if rails?
157
+ @metrics = MetricFu::AVAILABLE_METRICS + [:stats]
158
+ else
159
+ @metrics = MetricFu::AVAILABLE_METRICS
160
+ end
161
+ end
162
+
163
+ def set_graphs
164
+ if rails?
165
+ @graphs = MetricFu::AVAILABLE_GRAPHS + [:stats]
166
+ else
167
+ @graphs = MetricFu::AVAILABLE_GRAPHS
168
+ end
169
+ end
170
+
171
+ # Add the 'app' directory if we're running within rails.
172
+ def set_code_dirs
173
+ if rails?
174
+ @code_dirs = ['app', 'lib']
175
+ else
176
+ @code_dirs = ['lib']
177
+ end
178
+ end
179
+
180
+ def platform #:nodoc:
181
+ return RUBY_PLATFORM
182
+ end
183
+
184
+ def is_cruise_control_rb?
185
+ !!ENV['CC_BUILD_ARTIFACTS']
186
+ end
187
+ end
188
+ end
@@ -0,0 +1,167 @@
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
+ def remove_excluded_files(paths, globs_to_remove = MetricFu.file_globs_to_ignore)
101
+ files_to_remove = []
102
+ globs_to_remove.each do |glob|
103
+ files_to_remove.concat(Dir[glob])
104
+ end
105
+ paths - files_to_remove
106
+ end
107
+
108
+ # Defines some hook methods for the concrete classes to hook into.
109
+ %w[emit analyze].each do |meth|
110
+ define_method("before_#{meth}".to_sym) {}
111
+ define_method("after_#{meth}".to_sym) {}
112
+ end
113
+ define_method("before_to_h".to_sym) {}
114
+
115
+ # Provides a template method to drive the production of a metric
116
+ # from a concrete implementation of this class. Each concrete
117
+ # class must implement the three methods that this template method
118
+ # calls: #emit, #analyze and #to_h. For more details, see the
119
+ # class documentation.
120
+ #
121
+ # This template method also calls before_emit, after_emit... etc.
122
+ # methods to allow extra hooks into the processing methods, and help
123
+ # to keep the logic of your Generators clean.
124
+ def generate_report
125
+ %w[emit analyze].each do |meth|
126
+ send("before_#{meth}".to_sym)
127
+ send("#{meth}".to_sym)
128
+ send("after_#{meth}".to_sym)
129
+ end
130
+ before_to_h()
131
+ to_h()
132
+ end
133
+
134
+ def round_to_tenths(decimal)
135
+ (decimal * 10).round / 10.0
136
+ end
137
+
138
+ # Allows subclasses to check for required gems
139
+ def self.verify_dependencies!
140
+ true
141
+ end
142
+
143
+ def emit #:nodoc:
144
+ raise <<-EOF
145
+ This method must be implemented by a concrete class descending
146
+ from Generator. See generator class documentation for more
147
+ information.
148
+ EOF
149
+ end
150
+
151
+ def analyze #:nodoc:
152
+ raise <<-EOF
153
+ This method must be implemented by a concrete class descending
154
+ from Generator. See generator class documentation for more
155
+ information.
156
+ EOF
157
+ end
158
+
159
+ def to_graph #:nodoc:
160
+ raise <<-EOF
161
+ This method must be implemented by a concrete class descending
162
+ from Generator. See generator class documentation for more
163
+ information.
164
+ EOF
165
+ end
166
+ end
167
+ end