rferraz-metric_fu 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. data/HISTORY +237 -0
  2. data/MIT-LICENSE +22 -0
  3. data/README +29 -0
  4. data/Rakefile +18 -0
  5. data/TODO +6 -0
  6. data/lib/base/base_template.rb +172 -0
  7. data/lib/base/churn_analyzer.rb +38 -0
  8. data/lib/base/code_issue.rb +97 -0
  9. data/lib/base/configuration.rb +199 -0
  10. data/lib/base/flay_analyzer.rb +50 -0
  11. data/lib/base/flog_analyzer.rb +43 -0
  12. data/lib/base/generator.rb +166 -0
  13. data/lib/base/graph.rb +44 -0
  14. data/lib/base/line_numbers.rb +74 -0
  15. data/lib/base/location.rb +85 -0
  16. data/lib/base/md5_tracker.rb +52 -0
  17. data/lib/base/metric_analyzer.rb +404 -0
  18. data/lib/base/ranking.rb +34 -0
  19. data/lib/base/rcov_analyzer.rb +43 -0
  20. data/lib/base/reek_analyzer.rb +163 -0
  21. data/lib/base/report.rb +108 -0
  22. data/lib/base/roodi_analyzer.rb +37 -0
  23. data/lib/base/saikuro_analyzer.rb +48 -0
  24. data/lib/base/scoring_strategies.rb +29 -0
  25. data/lib/base/stats_analyzer.rb +37 -0
  26. data/lib/base/table.rb +102 -0
  27. data/lib/generators/churn.rb +28 -0
  28. data/lib/generators/flay.rb +31 -0
  29. data/lib/generators/flog.rb +111 -0
  30. data/lib/generators/hotspots.rb +52 -0
  31. data/lib/generators/rails_best_practices.rb +53 -0
  32. data/lib/generators/rcov.rb +122 -0
  33. data/lib/generators/reek.rb +81 -0
  34. data/lib/generators/roodi.rb +35 -0
  35. data/lib/generators/saikuro.rb +256 -0
  36. data/lib/generators/stats.rb +58 -0
  37. data/lib/graphs/engines/bluff.rb +113 -0
  38. data/lib/graphs/engines/gchart.rb +157 -0
  39. data/lib/graphs/flay_grapher.rb +18 -0
  40. data/lib/graphs/flog_grapher.rb +57 -0
  41. data/lib/graphs/grapher.rb +11 -0
  42. data/lib/graphs/rails_best_practices_grapher.rb +19 -0
  43. data/lib/graphs/rcov_grapher.rb +18 -0
  44. data/lib/graphs/reek_grapher.rb +30 -0
  45. data/lib/graphs/roodi_grapher.rb +18 -0
  46. data/lib/graphs/stats_grapher.rb +20 -0
  47. data/lib/metric_fu.rb +40 -0
  48. data/lib/templates/awesome/awesome_template.rb +73 -0
  49. data/lib/templates/awesome/churn.html.erb +58 -0
  50. data/lib/templates/awesome/css/buttons.css +82 -0
  51. data/lib/templates/awesome/css/default.css +91 -0
  52. data/lib/templates/awesome/css/integrity.css +334 -0
  53. data/lib/templates/awesome/css/reset.css +7 -0
  54. data/lib/templates/awesome/css/syntax.css +19 -0
  55. data/lib/templates/awesome/flay.html.erb +34 -0
  56. data/lib/templates/awesome/flog.html.erb +55 -0
  57. data/lib/templates/awesome/hotspots.html.erb +62 -0
  58. data/lib/templates/awesome/index.html.erb +34 -0
  59. data/lib/templates/awesome/layout.html.erb +30 -0
  60. data/lib/templates/awesome/rails_best_practices.html.erb +27 -0
  61. data/lib/templates/awesome/rcov.html.erb +42 -0
  62. data/lib/templates/awesome/reek.html.erb +40 -0
  63. data/lib/templates/awesome/roodi.html.erb +27 -0
  64. data/lib/templates/awesome/saikuro.html.erb +71 -0
  65. data/lib/templates/awesome/stats.html.erb +51 -0
  66. data/lib/templates/javascripts/bluff-min.js +1 -0
  67. data/lib/templates/javascripts/excanvas.js +35 -0
  68. data/lib/templates/javascripts/js-class.js +1 -0
  69. data/lib/templates/standard/churn.html.erb +31 -0
  70. data/lib/templates/standard/default.css +64 -0
  71. data/lib/templates/standard/flay.html.erb +34 -0
  72. data/lib/templates/standard/flog.html.erb +57 -0
  73. data/lib/templates/standard/hotspots.html.erb +54 -0
  74. data/lib/templates/standard/index.html.erb +41 -0
  75. data/lib/templates/standard/rails_best_practices.html.erb +29 -0
  76. data/lib/templates/standard/rcov.html.erb +43 -0
  77. data/lib/templates/standard/reek.html.erb +42 -0
  78. data/lib/templates/standard/roodi.html.erb +29 -0
  79. data/lib/templates/standard/saikuro.html.erb +84 -0
  80. data/lib/templates/standard/standard_template.rb +26 -0
  81. data/lib/templates/standard/stats.html.erb +55 -0
  82. data/spec/base/base_template_spec.rb +177 -0
  83. data/spec/base/configuration_spec.rb +276 -0
  84. data/spec/base/generator_spec.rb +223 -0
  85. data/spec/base/graph_spec.rb +61 -0
  86. data/spec/base/line_numbers_spec.rb +62 -0
  87. data/spec/base/md5_tracker_spec.rb +57 -0
  88. data/spec/base/report_spec.rb +146 -0
  89. data/spec/generators/churn_spec.rb +41 -0
  90. data/spec/generators/flay_spec.rb +105 -0
  91. data/spec/generators/flog_spec.rb +70 -0
  92. data/spec/generators/rails_best_practices_spec.rb +52 -0
  93. data/spec/generators/rcov_spec.rb +180 -0
  94. data/spec/generators/reek_spec.rb +134 -0
  95. data/spec/generators/roodi_spec.rb +24 -0
  96. data/spec/generators/saikuro_spec.rb +74 -0
  97. data/spec/generators/stats_spec.rb +74 -0
  98. data/spec/graphs/engines/bluff_spec.rb +19 -0
  99. data/spec/graphs/engines/gchart_spec.rb +156 -0
  100. data/spec/graphs/flay_grapher_spec.rb +56 -0
  101. data/spec/graphs/flog_grapher_spec.rb +108 -0
  102. data/spec/graphs/rails_best_practices_grapher_spec.rb +61 -0
  103. data/spec/graphs/rcov_grapher_spec.rb +56 -0
  104. data/spec/graphs/reek_grapher_spec.rb +65 -0
  105. data/spec/graphs/roodi_grapher_spec.rb +56 -0
  106. data/spec/graphs/stats_grapher_spec.rb +68 -0
  107. data/spec/resources/line_numbers/foo.rb +33 -0
  108. data/spec/resources/line_numbers/module.rb +11 -0
  109. data/spec/resources/line_numbers/module_surrounds_class.rb +15 -0
  110. data/spec/resources/line_numbers/two_classes.rb +11 -0
  111. data/spec/resources/saikuro/app/controllers/sessions_controller.rb_cyclo.html +10 -0
  112. data/spec/resources/saikuro/app/controllers/users_controller.rb_cyclo.html +16 -0
  113. data/spec/resources/saikuro/index_cyclo.html +155 -0
  114. data/spec/resources/saikuro_sfiles/thing.rb_cyclo.html +11 -0
  115. data/spec/resources/yml/20090630.yml +7922 -0
  116. data/spec/resources/yml/metric_missing.yml +1 -0
  117. data/spec/spec.opts +6 -0
  118. data/spec/spec_helper.rb +7 -0
  119. data/tasks/metric_fu.rake +22 -0
  120. metadata +448 -0
data/HISTORY ADDED
@@ -0,0 +1,237 @@
1
+ === MetricFu 2.1.1 / 2011-03-2
2
+
3
+ * Making syntax highlighting optional (config.syntax_highlighting = false) so Ruby 1.9.2 users don't get "invalid byte sequence in UTF-8" errors.
4
+
5
+ === MetricFu 2.1.0 / 2011-03-1
6
+
7
+ * Flog gemspec version was >= 2.2.0, which was too early and didn't work. Changed to >= 2.3.0 - Chris Griego
8
+ * RCov generator now uses a regex with begin and end line anchor to avoid splitting on comments with equal signs in source files - Andrew Selder
9
+ * RCov generator now always strips the 3 leading characters from the lines when reconstruction source files so that heredocs and block comments parse successfully - Andrew Selder
10
+ * Dan Mayer ported some specs for the Hotspots code into MetricFu from Caliper's code.
11
+ * Stefan Huber fixed some problems with churn pretending not to support Svn.
12
+ * Kakutani Shintaro added the ability to opt out of opening files with TextMate (config.darwin_txmt_protocol_no_thanks = true).
13
+ * Joel Nimety and Andrew Selder fixed a problem where Saikuro was parsing a dir twice.
14
+ * Dan Sinclair added some awesome 'annotate' functionality to the Hotspots page. Click on it so see the file with problems in-line.
15
+ * Dan Sinclair added a verbose mode (config.verbose = true).
16
+
17
+ === MetricFu 2.0.1 / 2010-11-13
18
+
19
+ * Delete trailing whitespaces - Delwyn de Villiers
20
+ * Stop Ubuntu choking on invalid multibyte char (US-ASCII) - Delwyn de Villiers
21
+ * Fix invalid next in lib/base/metric_analyzer.rb - Delwyn de Villiers
22
+ * Don't load Saikuro for Ruby 1.9.2 - Delwyn de Villiers
23
+ * Fixed a bug reported by Andrew Davis on the mailing list where configuring the data directory causes dates to be 0/0 - Joshua Cronemeyer
24
+
25
+ === MetricFu 2.0.0 / 2010-11-10
26
+
27
+ * Hotspots - Dan Mayer, Ben Brinckerhoff, Jake Scruggs
28
+ * Rcov integration with Hotspots - Jake Scruggs, Tony Castiglione, Rob Meyer
29
+
30
+ === MetricFu 1.5.1 / 2010-7-28
31
+
32
+ * Patch that allows graphers to skip dates that didn't generate metrics for that graph (GitHub Issue #20). - Chris Griego
33
+ * 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
34
+ * Fixed 'If coverage is 0% metric_fu will explode' bug (GitHub Issue #6). - Stew Welbourne
35
+
36
+ === MetricFu 1.5.0 / 2010-7-27
37
+
38
+ * 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).
39
+ * 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.
40
+ * Added support for using config files in Reek and Roodi (roodi support was already there but undocumented).
41
+ * 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.
42
+ * Deal with Rails 3 activesupport vs active_support problems. - jinzhu
43
+
44
+ === MetricFu 1.4.0 / 2010-06-19
45
+
46
+ * Added support for rails_best_practices gem - Richard Huang
47
+ * Added rails stats graphing -- Josh Cronemeyer
48
+ * Parameterize the filetypes for flay. By default flay supports haml as well as rb and has a plugin ability for other filetypes. - bfabry
49
+ * Support for Flog 2.4.0 line numbers - Dan Mayer
50
+ * Saikuro multi input directory patch - Spencer Dillard and Dan Mayer
51
+ * Can now parse rcov analysis file coming from multiple sources with an rcov :external option in the config. - Tarsoly András
52
+ * Fixed open file handles problem in the Saikuro analyzer - aselder, erebor
53
+ * Fix some problems with the google charts - Chris Griego
54
+ * Stop showing the googlecharts warning if you are not using google charts.
55
+
56
+ === MetricFu 1.3.0 / 2010-01-26
57
+
58
+ * Flay can be configured to ignore scores below a threshold (by default it ignores scores less than 100)
59
+ * When running Rcov you can configure the RAILS_ENV (defaults to 'test') so running metric_fu doesn't interfere with other environments
60
+ * Changed devver-construct (a gem hosted by GitHub) development dependency to test-construct dependency (on Gemcutter) - Dan Mayer
61
+ * Upgrade Bluff to 0.3.6 and added tooltips to graphs - Édouard Brière
62
+ * Removed Saikuro from vendor and added it as a gem dependency - Édouard Brière
63
+ * Churn has moved outside metric_fu and is now a gem and a dependency - Dan Mayer
64
+ * Fix 'activesupport' deprecation (it should be 'active_support') - Bryan Helmkamp
65
+ * Declared development dependencies
66
+ * Cleaned and sped up specs
67
+
68
+ === MetricFu 1.2.0 / 2010-01-09
69
+
70
+ * ftools isn't supported by 1.9 so moved to fileutils.
71
+ * Overhauled the graphing to use Gruff or Google Charts so we no longer depend on ImageMagick/rmagick -- thanks to Carl Youngblood.
72
+ * Stopped relying on Github gems as they will be going away.
73
+
74
+ === MetricFu 1.1.6 / 2009-12-14
75
+
76
+ * Now compatible with Reek 1.2x thanks to Kevin Rutherford
77
+ * Fixed problem with deleted files still showing up in Flog reports thanks to Dan Mayer
78
+
79
+ === MetricFu 1.1.5 / 2009-8-13
80
+
81
+ * Previous Ruby 1.9 fix was not quite fix-y enough
82
+
83
+ === MetricFu 1.1.4 / 2009-7-13
84
+
85
+ * Fixed another Ruby 1.9x bug
86
+
87
+ === MetricFu 1.1.3 / 2009-7-10
88
+
89
+ * MetricFu is now Ruby 1.9x compatible
90
+ * 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.
91
+ * 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.
92
+ * Sort Flog by highest score in the class which I feel is more important than the total flog flog score.
93
+
94
+ === MetricFu 1.1.2 / 2009-7-09
95
+
96
+ * Removed dependency on gruff and rmagick (unless the user wants graphs, of course).
97
+ * New look for styling -- Edouard Brière
98
+ * Extra param in rcov call was causing problems -- Stewart Welbourne
99
+ * Preventing rake task from being run multiple times when other rake tasks switch the environment -- Matthew Van Horn
100
+ * Typo in Rcov dependency verification and fixing parsing Saikuro nested information -- Mark Wilden
101
+
102
+ === MetricFu 1.1.1 / 2009-6-29
103
+
104
+ * Fix for empty flog files
105
+
106
+ === MetricFu 1.1.0 / 2009-6-22
107
+
108
+ * Flog, flay, reek, roodi, and rcov reports now graph progress over time. Well done Nick Quaranto and Edouard Brière.
109
+ * 'Awesome' template has been brought in so that reports look 90% less 'ghetto.' Also done by Nick Quaranto and Edouard Brière.
110
+ * Added links to TextMate (which keep getting removed. Probably by me. Sorry.) -- David Chelimsky
111
+ * Fixed a bug for scratch files which have a size of 0 -- Kevin Hall
112
+ * 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
113
+ * Empty Flog file fix -- Adam Bair
114
+ * Added a simple fix for cases where Saikuro results with nested information -- Randy Souza
115
+ * Fixed rcov configuration so it ignores library files on Linux -- Diego Carrion
116
+ * Changing churn so that it still works deeper than the git root directory -- Andrew Timberlake
117
+ * Andrew Timberlake also made some nice changes to the base template which kinda of got overshadowed by the 'awesome' template. Sorry about that Andrew.
118
+
119
+ === MetricFu 1.0.2 / 2009-5-11
120
+
121
+ * Fixing problems with Reek new line character (thanks to all who pointed this out)
122
+ * Flog now recognizes namespaces in method names thanks to Daniel Guettler
123
+ * Saikuro now looks at multiple directories, again.
124
+
125
+ === MetricFu 1.0.1 / 2009-5-3
126
+
127
+ * metrics:all task no longer requires a MetricFu::Configuration.run {} if you want to accept the defaults
128
+ * rcov task now reports total coverage percent
129
+
130
+ === MetricFu 1.0.0 / 2009-4-30
131
+
132
+ * Merged in Grant McInnes' work on creating yaml output for all metrics to aid harvesting by other tools
133
+ * Supporting Flog 2.1.0
134
+ * Supporting Reek 1.0.0
135
+ * Removed dependency on Rails Env for 3.months.ago (for churn report), now using chronic gem ("3 months ago").
136
+ * Almost all code is out of Rakefiles now and so is more easily testable
137
+ * 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.
138
+ * 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.
139
+
140
+ === MetricFu 0.9.0 / 2009-1-25
141
+
142
+ * Adding line numbers to the views so that people viewing it on cc.rb can figure out where the problems are
143
+ * 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)
144
+ * Added totals to Flog results
145
+ * Moved rcov options to configuration
146
+
147
+ === MetricFu 0.8.9 / 2009-1-20
148
+
149
+ * Thanks to Andre Arko and Petrik de Heus for adding the following features:
150
+ * The source control type is auto-detected for Churn
151
+ * Moved all presentation to templates
152
+ * Wrote specs for all classes
153
+ * Added flay, Reek and Roodi metrics
154
+ * There's now a configuration class (see README for details)
155
+ * Unification of metrics reports
156
+ * Metrics can be generated using one command
157
+ * Adding new metrics reports has been standardized
158
+
159
+ === MetricFu 0.8.0 / 2008-10-06
160
+
161
+ * Source Control Churn now supports git (thanks to Erik St Martin)
162
+ * Flog Results are sorted by Highest Flog Score
163
+ * Fix for a bunch of 'already initialized constant' warnings that metric_fu caused
164
+ * Fixing bug so the flog reporter can handle methods with digits in the name (thanks to Andy Gregorowicz)
165
+ * Internal Rake task now allows metric_fu to flog/churn itself
166
+
167
+ === MetricFu 0.7.6 / 2008-09-15
168
+
169
+ * CHURN_OPTIONS has become MetricFu::CHURN_OPTIONS
170
+ * SAIKURO_OPTIONS has become MetricFu::SAIKURO_OPTIONS
171
+ * Rcov now looks at test and specs
172
+ * Exclude gems and Library ruby code from rcov
173
+ * Fixed bug with churn start_date functionality (bad path)
174
+
175
+ === MetricFu 0.7.5 / 2008-09-12
176
+
177
+ * Flog can now flog any set of directories you like (see README).
178
+ * Saikuro can now look at any set of directories you like (see README).
179
+
180
+ === MetricFu 0.7.1 / 2008-09-12
181
+
182
+ * Fixed filename bugs pointed out by Bastien
183
+
184
+ === MetricFu 0.7.0 / 2008-09-11
185
+
186
+ * Merged in Sean Soper's changes to metric_fu.
187
+ * Metric_fu is now a gem.
188
+ * Flogging now uses a MD5 hash to figure out if it should re-flog a file (if it's changed)
189
+ * Flogging also has a cool new output screen(s)
190
+ * Thanks Sean!
191
+
192
+ === Metricks 0.4.2 / 2008-07-01
193
+
194
+ * Changed rcov output directory so that it is no longer 'coverage/unit' but just 'coverage' for better integration with CC.rb
195
+
196
+ === Metricks 0.4.1 / 2008-06-13
197
+
198
+ * Rcov tests now extend beyond one level depth directory by using RcovTask instead of the shell
199
+
200
+ === Metricks 0.4.0 / 2008-06-13
201
+
202
+ * Implementing functionality for use as a gem
203
+ * Added Rakefile to facilitate testing
204
+
205
+ === Metricks 0.3.0 / 2008-06-11
206
+
207
+ * Generated reports now open on darwin automatically
208
+ * Generated reports reside under tmp/metricks unless otherwise specified by ENV['CC_BUILD_ARTIFACTS']
209
+ * MD5Tracker works with Flog reports for speed optimization
210
+
211
+ === Metricks 0.2.0 / 2008-06-11
212
+
213
+ * Integrated use of base directory constant
214
+ * Have all reports automatically open in a browser if platform is darwin
215
+ * Namespaced under Metricks
216
+ * Dropped use of shell md5 command in favor of Ruby's Digest::MD5 libraries
217
+
218
+ === Metricks 0.1.0 / 2008-06-10
219
+
220
+ * Initial integration of metric_fu and my enhancements to flog
221
+ * Metrics are generated but are all over the place
222
+
223
+ === MetricFu 0.6.0 / 2008-05-11
224
+
225
+ * Add source control churn report
226
+
227
+ === MetricFu 0.5.1 / 2008-04-25
228
+
229
+ * Fixed bug with Saikuro report generation - thanks Toby Tripp
230
+
231
+ === MetricFu 0.5.0 / 2008-04-25
232
+
233
+ * create MetricFu as a Rails Plugin
234
+ * Add Flog Report
235
+ * Add Coverage Report
236
+ * Add Saikuro Report
237
+ * Add Stats Report
data/MIT-LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2008,2009,2010,2011 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,29 @@
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' #to get gem dependencies
7
+ 3. Install the gems RSpec 1.3.0, test-construct, and googlecharts
8
+ 4. Run the tests ('rake')
9
+ 5. Run metric_fu on itself ('rake metrics:all')
10
+ 6. Make the changes you want and back them up with tests.
11
+ 7. Make sure two important rake tests still run ('rake' and 'rake metrics:all')
12
+ 8. Commit and send me a pull request with details as to what has been changed.
13
+
14
+ Extra Credit:
15
+ 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)
16
+ 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).
17
+ 3. Update the documentation (web page inside the 'home_page' folder)
18
+ 4. Update the History and give yourself credit.
19
+
20
+
21
+ 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.
22
+ 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.
23
+
24
+ Resources:
25
+ Homepage: http://metric-fu.rubyforge.org/
26
+ Github: http://github.com/jscruggs/metric_fu
27
+ Google Group: http://groups.google.com/group/metric_fu
28
+ Issue Tracker: http://github.com/jscruggs/metric_fu/issues
29
+ My Blog: http://jakescruggs.blogspot.com/
data/Rakefile ADDED
@@ -0,0 +1,18 @@
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
+ config.churn = { :start_date => "1 year ago", :minimum_churn_count => 10}
15
+ config.hotspots = { :start_date => "1 year ago", :minimum_churn_count => 10}
16
+ end
17
+
18
+ task :default => :spec
data/TODO ADDED
@@ -0,0 +1,6 @@
1
+ == TODO list
2
+
3
+ * Color code flog results with scale from: http://jakescruggs.blogspot.com/2008/08/whats-good-flog-score.html
4
+ * Make running metric_fu on metric_fu less embarrassing
5
+ * Load all gems at config time so you fail fast if one is missing
6
+
@@ -0,0 +1,172 @@
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, :per_file_data
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 display_location(location, stat)
122
+ file_path, class_name, method_name = location.file_path, location.class_name, location.method_name
123
+ str = ""
124
+ str += link_to_filename(file_path)
125
+ str += " : " if method_name || class_name
126
+ if(method_name)
127
+ str += "#{method_name}"
128
+ else
129
+ #TODO HOTSPOTS BUG ONLY exists on move over to metric_fu
130
+ if class_name.is_a?(String)
131
+ str+= "#{class_name}"
132
+ end
133
+ end
134
+ str
135
+ end
136
+
137
+ def file_url(name, line) # :nodoc:
138
+ return '' unless name
139
+ filename = File.expand_path(name.gsub(/^\//, ''))
140
+ if render_as_txmt_protocol?
141
+ "txmt://open/?url=file://#{filename}" << (line ? "&line=#{line}" : "")
142
+ else
143
+ "file://#{filename}"
144
+ end
145
+ end
146
+
147
+ def render_as_txmt_protocol? # :nodoc:
148
+ config = MetricFu.configuration
149
+ return false unless config.platform.include?('darwin')
150
+ return !config.darwin_txmt_protocol_no_thanks
151
+ end
152
+
153
+ # Provides a brain dead way to cycle between two values during
154
+ # an iteration of some sort. Pass in the first_value, the second_value,
155
+ # and the cardinality of the iteration.
156
+ #
157
+ # @param first_value Object
158
+ #
159
+ # @param second_value Object
160
+ #
161
+ # @param iteration Integer
162
+ # The number of times through the iteration.
163
+ #
164
+ # @return Object
165
+ # The first_value if iteration is even. The second_value if
166
+ # iteration is odd.
167
+ def cycle(first_value, second_value, iteration)
168
+ return first_value if iteration % 2 == 0
169
+ return second_value
170
+ end
171
+ end
172
+ end
@@ -0,0 +1,38 @@
1
+ class ChurnAnalyzer
2
+ include ScoringStrategies
3
+
4
+ COLUMNS = %w{times_changed}
5
+
6
+ def columns
7
+ COLUMNS
8
+ end
9
+
10
+ def name
11
+ :churn
12
+ end
13
+
14
+ def map(row)
15
+ ScoringStrategies.present(row)
16
+ end
17
+
18
+ def reduce(scores)
19
+ ScoringStrategies.sum(scores)
20
+ end
21
+
22
+ def score(metric_ranking, item)
23
+ flat_churn_score = 0.50
24
+ metric_ranking.scored?(item) ? flat_churn_score : 0
25
+ end
26
+
27
+ def generate_records(data, table)
28
+ return if data==nil
29
+ Array(data[:changes]).each do |change|
30
+ table << {
31
+ "metric" => :churn,
32
+ "times_changed" => change[:times_changed],
33
+ "file_path" => change[:file_path]
34
+ }
35
+ end
36
+ end
37
+
38
+ end
@@ -0,0 +1,97 @@
1
+ require 'delegate'
2
+ require MetricFu::LIB_ROOT + '/base/metric_analyzer'
3
+ require MetricFu::LIB_ROOT + '/base/flog_analyzer'
4
+ require MetricFu::LIB_ROOT + '/base/saikuro_analyzer'
5
+ require MetricFu::LIB_ROOT + '/base/churn_analyzer'
6
+ require MetricFu::LIB_ROOT + '/base/reek_analyzer'
7
+ require MetricFu::LIB_ROOT + '/base/flay_analyzer'
8
+
9
+ module CarefulArray
10
+
11
+ def carefully_remove(elements)
12
+ missing_elements = elements - self
13
+ raise "Cannot delete missing elements: #{missing_elements.inspect}" unless missing_elements.empty?
14
+ (self - elements).extend(CarefulArray)
15
+ end
16
+
17
+ end
18
+
19
+ class CodeIssue < DelegateClass(Record) #DelegateClass(Ruport::Data::Record)
20
+ include Comparable
21
+
22
+ # TODO: Yuck! 'stat_value' is a column for StatAnalyzer
23
+ EXCLUDED_COLUMNS = FlogAnalyzer::COLUMNS + SaikuroAnalyzer::COLUMNS + ['stat_value'] + ChurnAnalyzer::COLUMNS + ReekAnalyzer.new.columns.extend(CarefulArray).carefully_remove(['reek__type_name', 'reek__comparable_message']) + FlayAnalyzer.new.columns.extend(CarefulArray).carefully_remove(['flay_matching_reason'])
24
+
25
+ def <=>(other)
26
+ spaceship_for_columns(self.attributes, other)
27
+ end
28
+
29
+ def ===(other)
30
+ self.hash_for(included_columns_hash, included_columns) == other.hash_for(included_columns_hash, included_columns)
31
+ end
32
+
33
+ def spaceship_for_columns(columns, other)
34
+ columns.each do |column|
35
+ equality = self[column].to_s <=> other[column].to_s
36
+ return equality if equality!=0
37
+ end
38
+ return 0
39
+ end
40
+
41
+ def hash_for(column_hash, columns)
42
+ @hashes ||= {}
43
+ # fetch would be cleaner, but slower
44
+ if @hashes.has_key?(column_hash)
45
+ @hashes[column_hash]
46
+ else
47
+ values = columns.map {|column| self[column]}
48
+ hash_for_columns = values.join('').hash
49
+ @hashes[column_hash]=hash_for_columns
50
+ hash_for_columns
51
+ end
52
+ end
53
+
54
+ def included_columns_hash
55
+ @included_columns_hash ||= included_columns.hash
56
+ end
57
+
58
+ def included_columns
59
+ @included_columns ||= self.attributes.extend(CarefulArray).carefully_remove(EXCLUDED_COLUMNS)
60
+ end
61
+
62
+ def find_counterpart_index_in(collection)
63
+ # each_with_index is cleaner, but it is slower and we
64
+ # spend a lot of time in this loop
65
+ index = 0
66
+ collection.each do |issue|
67
+ return index if self === issue
68
+ index += 1
69
+ end
70
+ return nil
71
+ end
72
+
73
+ def modifies?(other)
74
+ case self.metric
75
+ when :reek
76
+ #return false unless ["Large Class", "Long Method", "Long Parameter List"].include?(self.reek__type_name)
77
+ return false if self.reek__type_name != other.reek__type_name
78
+ self.reek__value != other.reek__value
79
+ when :flog
80
+ self.score != other.score
81
+ when :saikuro
82
+ self.complexity != other.complexity
83
+ when :stats
84
+ self.stat_value != other.stat_value
85
+ when :churn
86
+ self.times_changed != other.times_changed
87
+ when :flay
88
+ #self.flay_reason != other.flay_reason
89
+ # do nothing for now
90
+ when :roodi, :stats
91
+ # do nothing
92
+ else
93
+ raise ArgumentError, "Invalid metric type #{self.metric}"
94
+ end
95
+ end
96
+
97
+ end