goldstar-metric_fu 1.5.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. data/HISTORY +208 -0
  2. data/MIT-LICENSE +22 -0
  3. data/README +28 -0
  4. data/Rakefile +16 -0
  5. data/TODO +9 -0
  6. data/lib/base/base_template.rb +151 -0
  7. data/lib/base/configuration.rb +190 -0
  8. data/lib/base/generator.rb +162 -0
  9. data/lib/base/graph.rb +39 -0
  10. data/lib/base/md5_tracker.rb +52 -0
  11. data/lib/base/report.rb +100 -0
  12. data/lib/generators/churn.rb +28 -0
  13. data/lib/generators/flay.rb +31 -0
  14. data/lib/generators/flog.rb +98 -0
  15. data/lib/generators/rails_best_practices.rb +25 -0
  16. data/lib/generators/rcov.rb +85 -0
  17. data/lib/generators/reek.rb +60 -0
  18. data/lib/generators/roodi.rb +27 -0
  19. data/lib/generators/saikuro.rb +224 -0
  20. data/lib/generators/stats.rb +59 -0
  21. data/lib/graphs/engines/bluff.rb +113 -0
  22. data/lib/graphs/engines/gchart.rb +157 -0
  23. data/lib/graphs/flay_grapher.rb +18 -0
  24. data/lib/graphs/flog_grapher.rb +57 -0
  25. data/lib/graphs/grapher.rb +11 -0
  26. data/lib/graphs/rails_best_practices_grapher.rb +19 -0
  27. data/lib/graphs/rcov_grapher.rb +18 -0
  28. data/lib/graphs/reek_grapher.rb +30 -0
  29. data/lib/graphs/roodi_grapher.rb +18 -0
  30. data/lib/graphs/stats_grapher.rb +20 -0
  31. data/lib/metric_fu.rb +37 -0
  32. data/lib/templates/awesome/awesome_template.rb +37 -0
  33. data/lib/templates/awesome/churn.html.erb +58 -0
  34. data/lib/templates/awesome/css/buttons.css +82 -0
  35. data/lib/templates/awesome/css/default.css +91 -0
  36. data/lib/templates/awesome/css/integrity.css +335 -0
  37. data/lib/templates/awesome/css/reset.css +7 -0
  38. data/lib/templates/awesome/flay.html.erb +34 -0
  39. data/lib/templates/awesome/flog.html.erb +55 -0
  40. data/lib/templates/awesome/index.html.erb +31 -0
  41. data/lib/templates/awesome/layout.html.erb +30 -0
  42. data/lib/templates/awesome/rails_best_practices.html.erb +27 -0
  43. data/lib/templates/awesome/rcov.html.erb +42 -0
  44. data/lib/templates/awesome/reek.html.erb +40 -0
  45. data/lib/templates/awesome/roodi.html.erb +27 -0
  46. data/lib/templates/awesome/saikuro.html.erb +71 -0
  47. data/lib/templates/awesome/stats.html.erb +51 -0
  48. data/lib/templates/javascripts/bluff-min.js +1 -0
  49. data/lib/templates/javascripts/excanvas.js +35 -0
  50. data/lib/templates/javascripts/js-class.js +1 -0
  51. data/lib/templates/standard/churn.html.erb +31 -0
  52. data/lib/templates/standard/default.css +64 -0
  53. data/lib/templates/standard/flay.html.erb +34 -0
  54. data/lib/templates/standard/flog.html.erb +57 -0
  55. data/lib/templates/standard/index.html.erb +41 -0
  56. data/lib/templates/standard/rails_best_practices.html.erb +29 -0
  57. data/lib/templates/standard/rcov.html.erb +43 -0
  58. data/lib/templates/standard/reek.html.erb +42 -0
  59. data/lib/templates/standard/roodi.html.erb +29 -0
  60. data/lib/templates/standard/saikuro.html.erb +84 -0
  61. data/lib/templates/standard/standard_template.rb +26 -0
  62. data/lib/templates/standard/stats.html.erb +55 -0
  63. data/spec/base/base_template_spec.rb +161 -0
  64. data/spec/base/configuration_spec.rb +276 -0
  65. data/spec/base/generator_spec.rb +223 -0
  66. data/spec/base/graph_spec.rb +24 -0
  67. data/spec/base/md5_tracker_spec.rb +57 -0
  68. data/spec/base/report_spec.rb +139 -0
  69. data/spec/generators/churn_spec.rb +41 -0
  70. data/spec/generators/flay_spec.rb +105 -0
  71. data/spec/generators/flog_spec.rb +70 -0
  72. data/spec/generators/reek_spec.rb +134 -0
  73. data/spec/generators/saikuro_spec.rb +58 -0
  74. data/spec/generators/stats_spec.rb +74 -0
  75. data/spec/graphs/engines/bluff_spec.rb +19 -0
  76. data/spec/graphs/engines/gchart_spec.rb +156 -0
  77. data/spec/graphs/flay_grapher_spec.rb +56 -0
  78. data/spec/graphs/flog_grapher_spec.rb +108 -0
  79. data/spec/graphs/rcov_grapher_spec.rb +56 -0
  80. data/spec/graphs/reek_grapher_spec.rb +65 -0
  81. data/spec/graphs/roodi_grapher_spec.rb +56 -0
  82. data/spec/resources/saikuro/app/controllers/sessions_controller.rb_cyclo.html +10 -0
  83. data/spec/resources/saikuro/app/controllers/users_controller.rb_cyclo.html +16 -0
  84. data/spec/resources/saikuro/index_cyclo.html +155 -0
  85. data/spec/resources/saikuro_sfiles/thing.rb_cyclo.html +11 -0
  86. data/spec/resources/yml/20090630.yml +7922 -0
  87. data/spec/spec.opts +6 -0
  88. data/spec/spec_helper.rb +7 -0
  89. data/tasks/metric_fu.rake +22 -0
  90. metadata +396 -0
data/HISTORY ADDED
@@ -0,0 +1,208 @@
1
+ === MetricFu 1.5.1 / 2010-7-28
2
+
3
+ * Patch that allows graphers to skip dates that didn't generate metrics for that graph (GitHub Issue #20). - Chris Griego
4
+ * Fixed bug where if you try and use the gchart grapher with the rails_best_practices metric, it blows up (GitHub Issue #23). - Chris Griego
5
+ * Fixed 'If coverage is 0% metric_fu will explode' bug (GitHub Issue #6). - Stew Welbourne
6
+
7
+ === MetricFu 1.5.0 / 2010-7-27
8
+
9
+ * Fixed bug where Flay results were not being reported. Had to remove the ability to remove selected files from flay processing (undocumented feature that may go away soon if it keeps causing problems).
10
+ * Rewrote Flog parsing/processing to use Flog programmatically. Note: the yaml output for Flog has changed significantly - Pages have now become MethodContainers. This probably doesn't matter to you if you are not consuming the metric_fu yaml output.
11
+ * Added support for using config files in Reek and Roodi (roodi support was already there but undocumented).
12
+ * Removed verify_dependencies! as it caused too much confusion to justify the limited set of problems it solved. In the post Bundler world it just didn't seem necessary to limit metric_fu dependencies.
13
+ * Deal with Rails 3 activesupport vs active_support problems. - jinzhu
14
+
15
+ === MetricFu 1.4.0 / 2010-06-19
16
+
17
+ * Added support for rails_best_practices gem - Richard Huang
18
+ * Added rails stats graphing -- Josh Cronemeyer
19
+ * Parameterize the filetypes for flay. By default flay supports haml as well as rb and has a plugin ability for other filetypes. - bfabry
20
+ * Support for Flog 2.4.0 line numbers - Dan Mayer
21
+ * Saikuro multi input directory patch - Spencer Dillard and Dan Mayer
22
+ * Can now parse rcov analysis file coming from multiple sources with an rcov :external option in the config. - Tarsoly András
23
+ * Fixed open file handles problem in the Saikuro analyzer - aselder, erebor
24
+ * Fix some problems with the google charts - Chris Griego
25
+ * Stop showing the googlecharts warning if you are not using google charts.
26
+
27
+ === MetricFu 1.3.0 / 2010-01-26
28
+
29
+ * Flay can be configured to ignore scores below a threshold (by default it ignores scores less than 100)
30
+ * When running Rcov you can configure the RAILS_ENV (defaults to 'test') so running metric_fu doesn't interfere with other environments
31
+ * Changed devver-construct (a gem hosted by GitHub) development dependency to test-construct dependency (on Gemcutter) - Dan Mayer
32
+ * Upgrade Bluff to 0.3.6 and added tooltips to graphs - Édouard Brière
33
+ * Removed Saikuro from vendor and added it as a gem dependency - Édouard Brière
34
+ * Churn has moved outside metric_fu and is now a gem and a dependency - Dan Mayer
35
+ * Fix 'activesupport' deprecation (it should be 'active_support') - Bryan Helmkamp
36
+ * Declared development dependencies
37
+ * Cleaned and sped up specs
38
+
39
+ === MetricFu 1.2.0 / 2010-01-09
40
+
41
+ * ftools isn't supported by 1.9 so moved to fileutils.
42
+ * Overhauled the graphing to use Gruff or Google Charts so we no longer depend on ImageMagick/rmagick -- thanks to Carl Youngblood.
43
+ * Stopped relying on Github gems as they will be going away.
44
+
45
+ === MetricFu 1.1.6 / 2009-12-14
46
+
47
+ * Now compatible with Reek 1.2x thanks to Kevin Rutherford
48
+ * Fixed problem with deleted files still showing up in Flog reports thanks to Dan Mayer
49
+
50
+ === MetricFu 1.1.5 / 2009-8-13
51
+
52
+ * Previous Ruby 1.9 fix was not quite fix-y enough
53
+
54
+ === MetricFu 1.1.4 / 2009-7-13
55
+
56
+ * Fixed another Ruby 1.9x bug
57
+
58
+ === MetricFu 1.1.3 / 2009-7-10
59
+
60
+ * MetricFu is now Ruby 1.9x compatible
61
+ * Removed the check for deprecated ways of configuring metric_fu as the tests were causing Ruby 1.9x problems and it's been forever since they were supported.
62
+ * Removed total flog score from graph (which will always go up and so doesn't mean much) and replacing it with top_five_percent_average which is an average of the worst 5 percent of your methods.
63
+ * Sort Flog by highest score in the class which I feel is more important than the total flog flog score.
64
+
65
+ === MetricFu 1.1.2 / 2009-7-09
66
+
67
+ * Removed dependency on gruff and rmagick (unless the user wants graphs, of course).
68
+ * New look for styling -- Edouard Brière
69
+ * Extra param in rcov call was causing problems -- Stewart Welbourne
70
+ * Preventing rake task from being run multiple times when other rake tasks switch the environment -- Matthew Van Horn
71
+ * Typo in Rcov dependency verification and fixing parsing Saikuro nested information -- Mark Wilden
72
+
73
+ === MetricFu 1.1.1 / 2009-6-29
74
+
75
+ * Fix for empty flog files
76
+
77
+ === MetricFu 1.1.0 / 2009-6-22
78
+
79
+ * Flog, flay, reek, roodi, and rcov reports now graph progress over time. Well done Nick Quaranto and Edouard Brière.
80
+ * 'Awesome' template has been brought in so that reports look 90% less 'ghetto.' Also done by Nick Quaranto and Edouard Brière.
81
+ * Added links to TextMate (which keep getting removed. Probably by me. Sorry.) -- David Chelimsky
82
+ * Fixed a bug for scratch files which have a size of 0 -- Kevin Hall
83
+ * Changed gem dependencies from install-time in gemspec to runtime when each of the generators is loaded. This allows use of github gems (i.e. relevance-rcov instead of rcov) and also allows you to install only the gems for the metrics you plan on using. -- Alex Rothenberg
84
+ * Empty Flog file fix -- Adam Bair
85
+ * Added a simple fix for cases where Saikuro results with nested information -- Randy Souza
86
+ * Fixed rcov configuration so it ignores library files on Linux -- Diego Carrion
87
+ * Changing churn so that it still works deeper than the git root directory -- Andrew Timberlake
88
+ * Andrew Timberlake also made some nice changes to the base template which kinda of got overshadowed by the 'awesome' template. Sorry about that Andrew.
89
+
90
+ === MetricFu 1.0.2 / 2009-5-11
91
+
92
+ * Fixing problems with Reek new line character (thanks to all who pointed this out)
93
+ * Flog now recognizes namespaces in method names thanks to Daniel Guettler
94
+ * Saikuro now looks at multiple directories, again.
95
+
96
+ === MetricFu 1.0.1 / 2009-5-3
97
+
98
+ * metrics:all task no longer requires a MetricFu::Configuration.run {} if you want to accept the defaults
99
+ * rcov task now reports total coverage percent
100
+
101
+ === MetricFu 1.0.0 / 2009-4-30
102
+
103
+ * Merged in Grant McInnes' work on creating yaml output for all metrics to aid harvesting by other tools
104
+ * Supporting Flog 2.1.0
105
+ * Supporting Reek 1.0.0
106
+ * Removed dependency on Rails Env for 3.months.ago (for churn report), now using chronic gem ("3 months ago").
107
+ * Almost all code is out of Rakefiles now and so is more easily testable
108
+ * Metrics inherit from a refactored Generator now. New metrics generators just have to implement "emit", "analyze", "to_h" and inherit from Generator. They also must have a template. See the flay generator and template for a simple implementation.
109
+ * You now define the metrics you wish to run in the configuration and then run "metrics:all". No other metrics task is exposed by default.
110
+
111
+ === MetricFu 0.9.0 / 2009-1-25
112
+
113
+ * Adding line numbers to the views so that people viewing it on cc.rb can figure out where the problems are
114
+ * Merging in changes from Jay Zeschin having to do with the railroad task -- I still have no idea how to use it (lemme know if you figure it out)
115
+ * Added totals to Flog results
116
+ * Moved rcov options to configuration
117
+
118
+ === MetricFu 0.8.9 / 2009-1-20
119
+
120
+ * Thanks to Andre Arko and Petrik de Heus for adding the following features:
121
+ * The source control type is auto-detected for Churn
122
+ * Moved all presentation to templates
123
+ * Wrote specs for all classes
124
+ * Added flay, Reek and Roodi metrics
125
+ * There's now a configuration class (see README for details)
126
+ * Unification of metrics reports
127
+ * Metrics can be generated using one command
128
+ * Adding new metrics reports has been standardized
129
+
130
+ === MetricFu 0.8.0 / 2008-10-06
131
+
132
+ * Source Control Churn now supports git (thanks to Erik St Martin)
133
+ * Flog Results are sorted by Highest Flog Score
134
+ * Fix for a bunch of 'already initialized constant' warnings that metric_fu caused
135
+ * Fixing bug so the flog reporter can handle methods with digits in the name (thanks to Andy Gregorowicz)
136
+ * Internal Rake task now allows metric_fu to flog/churn itself
137
+
138
+ === MetricFu 0.7.6 / 2008-09-15
139
+
140
+ * CHURN_OPTIONS has become MetricFu::CHURN_OPTIONS
141
+ * SAIKURO_OPTIONS has become MetricFu::SAIKURO_OPTIONS
142
+ * Rcov now looks at test and specs
143
+ * Exclude gems and Library ruby code from rcov
144
+ * Fixed bug with churn start_date functionality (bad path)
145
+
146
+ === MetricFu 0.7.5 / 2008-09-12
147
+
148
+ * Flog can now flog any set of directories you like (see README).
149
+ * Saikuro can now look at any set of directories you like (see README).
150
+
151
+ === MetricFu 0.7.1 / 2008-09-12
152
+
153
+ * Fixed filename bugs pointed out by Bastien
154
+
155
+ === MetricFu 0.7.0 / 2008-09-11
156
+
157
+ * Merged in Sean Soper's changes to metric_fu.
158
+ * Metric_fu is now a gem.
159
+ * Flogging now uses a MD5 hash to figure out if it should re-flog a file (if it's changed)
160
+ * Flogging also has a cool new output screen(s)
161
+ * Thanks Sean!
162
+
163
+ === Metricks 0.4.2 / 2008-07-01
164
+
165
+ * Changed rcov output directory so that it is no longer 'coverage/unit' but just 'coverage' for better integration with CC.rb
166
+
167
+ === Metricks 0.4.1 / 2008-06-13
168
+
169
+ * Rcov tests now extend beyond one level depth directory by using RcovTask instead of the shell
170
+
171
+ === Metricks 0.4.0 / 2008-06-13
172
+
173
+ * Implementing functionality for use as a gem
174
+ * Added Rakefile to facilitate testing
175
+
176
+ === Metricks 0.3.0 / 2008-06-11
177
+
178
+ * Generated reports now open on darwin automatically
179
+ * Generated reports reside under tmp/metricks unless otherwise specified by ENV['CC_BUILD_ARTIFACTS']
180
+ * MD5Tracker works with Flog reports for speed optimization
181
+
182
+ === Metricks 0.2.0 / 2008-06-11
183
+
184
+ * Integrated use of base directory constant
185
+ * Have all reports automatically open in a browser if platform is darwin
186
+ * Namespaced under Metricks
187
+ * Dropped use of shell md5 command in favor of Ruby's Digest::MD5 libraries
188
+
189
+ === Metricks 0.1.0 / 2008-06-10
190
+
191
+ * Initial integration of metric_fu and my enhancements to flog
192
+ * Metrics are generated but are all over the place
193
+
194
+ === MetricFu 0.6.0 / 2008-05-11
195
+
196
+ * Add source control churn report
197
+
198
+ === MetricFu 0.5.1 / 2008-04-25
199
+
200
+ * Fixed bug with Saikuro report generation - thanks Toby Tripp
201
+
202
+ === MetricFu 0.5.0 / 2008-04-25
203
+
204
+ * create MetricFu as a Rails Plugin
205
+ * Add Flog Report
206
+ * Add Coverage Report
207
+ * Add Saikuro Report
208
+ * Add Stats Report
data/MIT-LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2008,2009 Jake Scruggs
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,28 @@
1
+ See http://metric-fu.rubyforge.org/ for documentation, or the HISTORY file for a change log.
2
+
3
+ How to contribute:
4
+
5
+ 1. Fork metric_fu on github.
6
+ 2. 'gem install metric_fu --development' #to get development dependencies
7
+ 3. Run the tests ('rake')
8
+ 4. Run metric_fu on itself ('rake metrics:all')
9
+ 5. Make the changes you want and back them up with tests.
10
+ 6. Make sure two important rake tests still run ('rake' and 'rake metrics:all')
11
+ 7. Commit and send me a pull request with details as to what has been changed.
12
+
13
+ Extra Credit:
14
+ 1. Make sure your changes work in 1.8.7, Ruby Enterprise Edition, and 1.9.1 (Hint use 'rvm' to help install multiple rubies)
15
+ 2. Post to the Google group explaining what you did and why you did it (I don't merge things in immediately so others might want to use what you've done).
16
+ 3. Update the documentation (web page inside the 'home_page' folder)
17
+ 4. Update the History and give yourself credit.
18
+
19
+
20
+ The more of the above steps you do the easier it will be for me to merge in which will greatly increase you chances of getting your changes accepted.
21
+ If you want to do something really radical (which will touch over %30 of all the files) you might what to ask the Google group first to see if anyone is interested in your change before you spend a lot of time on it.
22
+
23
+ Resources:
24
+ Homepage: http://metric-fu.rubyforge.org/
25
+ Github: http://github.com/jscruggs/metric_fu
26
+ Google Group: http://groups.google.com/group/metric_fu
27
+ Issue Tracker: http://github.com/jscruggs/metric_fu/issues
28
+ My Blog: http://jakescruggs.blogspot.com/
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ $LOAD_PATH << '.'
2
+ require 'rake'
3
+ require 'rake/rdoctask'
4
+ require 'spec/rake/spectask'
5
+ require 'lib/metric_fu'
6
+
7
+ desc "Run all specs in spec directory"
8
+ Spec::Rake::SpecTask.new(:spec) do |t|
9
+ t.spec_files = FileList['spec/**/*_spec.rb']
10
+ end
11
+
12
+ MetricFu::Configuration.run do |config|
13
+ config.roodi = config.roodi.merge(:roodi_config => 'config/roodi_config.yml')
14
+ end
15
+
16
+ task :default => :spec
data/TODO ADDED
@@ -0,0 +1,9 @@
1
+ == TODO list
2
+
3
+ * Color code flog results with scale from: http://jakescruggs.blogspot.com/2008/08/whats-good-flog-score.html
4
+ * 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)
5
+ * Update flog specs so that they actually run flog
6
+ * Add flay specs that run flay
7
+ * Convert readme to markdown and rename to README.mkdn so github will render it
8
+ * Saikuro.rb falls over if tries to parse an empty file. Fair enough. We shouldn't feed it empty files
9
+ * Make running metric_fu on metric_fu less embarrassing
@@ -0,0 +1,151 @@
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 round_to_tenths(decimal)
107
+ decimal = 0.0 if decimal.to_s.eql?('NaN')
108
+ (decimal * 10).round / 10.0
109
+ end
110
+
111
+ def link_content(name, line=nil, link_content=nil) # :nodoc:
112
+ if link_content
113
+ link_content
114
+ elsif line
115
+ "#{name}:#{line}"
116
+ else
117
+ name
118
+ end
119
+ end
120
+
121
+ def file_url(name, line) # :nodoc:
122
+ return '' unless name
123
+ filename = File.expand_path(name.gsub(/^\//, ''))
124
+ if MetricFu.configuration.platform.include?('darwin')
125
+ "txmt://open/?url=file://#{filename}" << (line ? "&line=#{line}" : "")
126
+ else
127
+ "file://#{filename}"
128
+ end
129
+ end
130
+
131
+ # Provides a brain dead way to cycle between two values during
132
+ # an iteration of some sort. Pass in the first_value, the second_value,
133
+ # and the cardinality of the iteration.
134
+ #
135
+ # @param first_value Object
136
+ #
137
+ # @param second_value Object
138
+ #
139
+ # @param iteration Integer
140
+ # The number of times through the iteration.
141
+ #
142
+ # @return Object
143
+ # The first_value if iteration is even. The second_value if
144
+ # iteration is odd.
145
+ def cycle(first_value, second_value, iteration)
146
+ return first_value if iteration % 2 == 0
147
+ return second_value
148
+ end
149
+
150
+ end
151
+ end
@@ -0,0 +1,190 @@
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, :rails_best_practices]
12
+ AVAILABLE_GRAPH_ENGINES = [:gchart, :bluff]
13
+
14
+ # The @@configuration class variable holds a global type configuration
15
+ # object for any parts of the system to use.
16
+ def self.configuration
17
+ @@configuration ||= Configuration.new
18
+ end
19
+
20
+ # = Configuration
21
+ #
22
+ # The Configuration class, as it sounds, provides methods for
23
+ # configuring the behaviour of MetricFu.
24
+ #
25
+ # == Customization for Rails
26
+ #
27
+ # The Configuration class checks for the presence of a
28
+ # 'config/environment.rb' file. If the file is present, it assumes
29
+ # it is running in a Rails project. If it is, it will:
30
+ #
31
+ # * Add 'app' to the @code_dirs directory to include the
32
+ # code in the app directory in the processing
33
+ # * Add :stats to the list of metrics to run to get the Rails stats
34
+ # task
35
+ #
36
+ # == Customization for CruiseControl.rb
37
+ #
38
+ # The Configuration class checks for the presence of a
39
+ # 'CC_BUILD_ARTIFACTS' environment variable. If it's found
40
+ # it will change the default output directory from the default
41
+ # "tmp/metric_fu to the directory represented by 'CC_BUILD_ARTIFACTS'
42
+ #
43
+ # == Deprications
44
+ #
45
+ # The Configuration class checks for several deprecated constants
46
+ # that were previously used to configure MetricFu. These include
47
+ # CHURN_OPTIONS, DIRECTORIES_TO_FLOG, SAIKURO_OPTIONS,
48
+ # and MetricFu::SAIKURO_OPTIONS.
49
+ #
50
+ # These have been replaced by config.churn, config.flog and
51
+ # config.saikuro respectively.
52
+ class Configuration
53
+
54
+ def initialize #:nodoc:#
55
+ reset
56
+ add_attr_accessors_to_self
57
+ add_class_methods_to_metric_fu
58
+ end
59
+
60
+ # Searches through the instance variables of the class and
61
+ # creates a class method on the MetricFu module to read the value
62
+ # of the instance variable from the Configuration class.
63
+ def add_class_methods_to_metric_fu
64
+ instance_variables.each do |name|
65
+ method_name = name[1..-1].to_sym
66
+ method = <<-EOF
67
+ def self.#{method_name}
68
+ configuration.send(:#{method_name})
69
+ end
70
+ EOF
71
+ MetricFu.module_eval(method)
72
+ end
73
+ end
74
+
75
+ # Searches through the instance variables of the class and creates
76
+ # an attribute accessor on this instance of the Configuration
77
+ # class for each instance variable.
78
+ def add_attr_accessors_to_self
79
+ instance_variables.each do |name|
80
+ method_name = name[1..-1].to_sym
81
+ MetricFu::Configuration.send(:attr_accessor, method_name)
82
+ end
83
+ end
84
+
85
+ # This allows us to have a nice syntax like:
86
+ #
87
+ # MetricFu.run do |config|
88
+ # config.base_directory = 'tmp/metric_fu'
89
+ # end
90
+ #
91
+ # See the README for more information on configuration options.
92
+ def self.run
93
+ yield MetricFu.configuration
94
+ end
95
+
96
+ # This does the real work of the Configuration class, by setting
97
+ # up a bunch of instance variables to represent the configuration
98
+ # of the MetricFu app.
99
+ def reset
100
+ @base_directory = ENV['CC_BUILD_ARTIFACTS'] || 'tmp/metric_fu'
101
+ @scratch_directory = File.join(@base_directory, 'scratch')
102
+ @output_directory = File.join(@base_directory, 'output')
103
+ @data_directory = File.join('tmp/metric_fu', '_data')
104
+ @metric_fu_root_directory = File.join(File.dirname(__FILE__),
105
+ '..', '..')
106
+ @template_directory = File.join(@metric_fu_root_directory,
107
+ 'lib', 'templates')
108
+ @template_class = AwesomeTemplate
109
+ set_metrics
110
+ set_graphs
111
+ set_code_dirs
112
+ @flay = { :dirs_to_flay => @code_dirs,
113
+ :minimum_score => 100,
114
+ :filetypes => ['rb'] }
115
+ @flog = { :dirs_to_flog => @code_dirs }
116
+ @reek = { :dirs_to_reek => @code_dirs,
117
+ :config_file_pattern => nil}
118
+ @roodi = { :dirs_to_roodi => @code_dirs,
119
+ :roodi_config => nil}
120
+ @saikuro = { :output_directory => @scratch_directory + '/saikuro',
121
+ :input_directory => @code_dirs,
122
+ :cyclo => "",
123
+ :filter_cyclo => "0",
124
+ :warn_cyclo => "5",
125
+ :error_cyclo => "7",
126
+ :formater => "text"}
127
+ @churn = {}
128
+ @stats = {}
129
+ @rcov = { :environment => 'test',
130
+ :test_files => ['test/**/*_test.rb',
131
+ 'spec/**/*_spec.rb'],
132
+ :rcov_opts => ["--sort coverage",
133
+ "--no-html",
134
+ "--text-coverage",
135
+ "--no-color",
136
+ "--profile",
137
+ "--rails",
138
+ "--exclude /gems/,/Library/,/usr/,spec"],
139
+ :external => nil
140
+ }
141
+ @rails_best_practices = {}
142
+ @file_globs_to_ignore = []
143
+
144
+ @graph_engine = :bluff # can be :bluff or :gchart
145
+ end
146
+
147
+ # Perform a simple check to try and guess if we're running
148
+ # against a rails app.
149
+ #
150
+ # @todo This should probably be made a bit more robust.
151
+ def rails?
152
+ @rails = File.exist?("config/environment.rb")
153
+ end
154
+
155
+ # Add the :stats task to the AVAILABLE_METRICS constant if we're
156
+ # running within rails.
157
+ def set_metrics
158
+ if rails?
159
+ @metrics = MetricFu::AVAILABLE_METRICS + [:stats, :rails_best_practices]
160
+ else
161
+ @metrics = MetricFu::AVAILABLE_METRICS
162
+ end
163
+ end
164
+
165
+ def set_graphs
166
+ if rails?
167
+ @graphs = MetricFu::AVAILABLE_GRAPHS + [:stats]
168
+ else
169
+ @graphs = MetricFu::AVAILABLE_GRAPHS
170
+ end
171
+ end
172
+
173
+ # Add the 'app' directory if we're running within rails.
174
+ def set_code_dirs
175
+ if rails?
176
+ @code_dirs = ['app', 'lib']
177
+ else
178
+ @code_dirs = ['lib']
179
+ end
180
+ end
181
+
182
+ def platform #:nodoc:
183
+ return RUBY_PLATFORM
184
+ end
185
+
186
+ def is_cruise_control_rb?
187
+ !!ENV['CC_BUILD_ARTIFACTS']
188
+ end
189
+ end
190
+ end