fastruby-metric_fu 5.0.0
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.
- checksums.yaml +7 -0
- data/.gitignore +28 -0
- data/.metrics +3 -0
- data/.rspec +2 -0
- data/.rubocop.yml +15 -0
- data/.rubocop_todo.yml +69 -0
- data/.simplecov +74 -0
- data/.travis.yml +18 -0
- data/.yardopts +4 -0
- data/AUTHORS +12 -0
- data/CONTRIBUTING.md +47 -0
- data/CONTRIBUTORS +76 -0
- data/DEV.md +76 -0
- data/Gemfile +58 -0
- data/Guardfile +30 -0
- data/HISTORY.md +705 -0
- data/MIT-LICENSE +22 -0
- data/README.md +299 -0
- data/Rakefile +27 -0
- data/TODO.md +118 -0
- data/appveyor.yml +29 -0
- data/bin/metric_fu +9 -0
- data/bin/mf-cane +10 -0
- data/bin/mf-churn +10 -0
- data/bin/mf-flay +10 -0
- data/bin/mf-reek +10 -0
- data/bin/mf-roodi +10 -0
- data/bin/mf-saikuro +10 -0
- data/certs/bf4.pem +22 -0
- data/checksum/.gitkeep +0 -0
- data/checksum/metric_fu-4.10.0.gem.sha512 +1 -0
- data/checksum/metric_fu-4.11.0.gem.sha512 +1 -0
- data/checksum/metric_fu-4.11.1.gem.sha512 +1 -0
- data/checksum/metric_fu-4.11.2.gem.sha512 +1 -0
- data/checksum/metric_fu-4.11.3.gem.sha512 +1 -0
- data/checksum/metric_fu-4.11.4.gem.sha512 +1 -0
- data/checksum/metric_fu-4.12.0.gem.sha512 +1 -0
- data/checksum/metric_fu-4.2.0.gem.sha512 +1 -0
- data/checksum/metric_fu-4.2.1.gem.sha512 +1 -0
- data/checksum/metric_fu-4.3.0.gem.sha512 +1 -0
- data/checksum/metric_fu-4.3.1.gem.sha512 +1 -0
- data/checksum/metric_fu-4.4.0.gem.sha512 +1 -0
- data/checksum/metric_fu-4.4.1.gem.sha512 +1 -0
- data/checksum/metric_fu-4.4.2.gem.sha512 +1 -0
- data/checksum/metric_fu-4.4.3.gem.sha512 +1 -0
- data/checksum/metric_fu-4.4.4.gem.sha512 +1 -0
- data/checksum/metric_fu-4.5.0.gem.sha512 +1 -0
- data/checksum/metric_fu-4.5.1.gem.sha512 +1 -0
- data/checksum/metric_fu-4.5.2.gem.sha512 +1 -0
- data/checksum/metric_fu-4.6.0.gem.sha512 +1 -0
- data/checksum/metric_fu-4.7.0.gem.sha512 +1 -0
- data/checksum/metric_fu-4.7.1.gem.sha512 +1 -0
- data/checksum/metric_fu-4.7.2.gem.sha512 +1 -0
- data/checksum/metric_fu-4.7.3.gem.sha512 +1 -0
- data/checksum/metric_fu-4.7.4.gem.sha512 +1 -0
- data/checksum/metric_fu-4.8.0.gem.sha512 +1 -0
- data/checksum/metric_fu-4.9.0.gem.sha512 +1 -0
- data/config/roodi_config.yml +22 -0
- data/config/rubocop.yml +269 -0
- data/gem_tasks/build.rake +197 -0
- data/gem_tasks/rubocop.rake +10 -0
- data/gem_tasks/usage_test.rake +19 -0
- data/gem_tasks/yard.rake +24 -0
- data/lib/metric_fu.rb +151 -0
- data/lib/metric_fu/calculate.rb +10 -0
- data/lib/metric_fu/cli/client.rb +26 -0
- data/lib/metric_fu/cli/helper.rb +80 -0
- data/lib/metric_fu/cli/parser.rb +138 -0
- data/lib/metric_fu/configuration.rb +150 -0
- data/lib/metric_fu/constantize.rb +57 -0
- data/lib/metric_fu/data_structures/line_numbers.rb +112 -0
- data/lib/metric_fu/data_structures/location.rb +110 -0
- data/lib/metric_fu/data_structures/sexp_node.rb +107 -0
- data/lib/metric_fu/environment.rb +129 -0
- data/lib/metric_fu/errors/analysis_error.rb +4 -0
- data/lib/metric_fu/formatter.rb +40 -0
- data/lib/metric_fu/formatter/html.rb +96 -0
- data/lib/metric_fu/formatter/syntax.rb +45 -0
- data/lib/metric_fu/formatter/yaml.rb +18 -0
- data/lib/metric_fu/gem_run.rb +70 -0
- data/lib/metric_fu/gem_version.rb +92 -0
- data/lib/metric_fu/generator.rb +135 -0
- data/lib/metric_fu/io.rb +132 -0
- data/lib/metric_fu/loader.rb +105 -0
- data/lib/metric_fu/logger.rb +62 -0
- data/lib/metric_fu/logging/mf_debugger.rb +23 -0
- data/lib/metric_fu/metric.rb +143 -0
- data/lib/metric_fu/metrics/cane/generator.rb +95 -0
- data/lib/metric_fu/metrics/cane/grapher.rb +37 -0
- data/lib/metric_fu/metrics/cane/metric.rb +34 -0
- data/lib/metric_fu/metrics/cane/report.html.erb +87 -0
- data/lib/metric_fu/metrics/cane/violations.rb +46 -0
- data/lib/metric_fu/metrics/churn/generator.rb +37 -0
- data/lib/metric_fu/metrics/churn/hotspot.rb +43 -0
- data/lib/metric_fu/metrics/churn/metric.rb +29 -0
- data/lib/metric_fu/metrics/churn/report.html.erb +58 -0
- data/lib/metric_fu/metrics/flay/generator.rb +51 -0
- data/lib/metric_fu/metrics/flay/grapher.rb +37 -0
- data/lib/metric_fu/metrics/flay/hotspot.rb +52 -0
- data/lib/metric_fu/metrics/flay/metric.rb +28 -0
- data/lib/metric_fu/metrics/flay/report.html.erb +29 -0
- data/lib/metric_fu/metrics/flog/generator.rb +113 -0
- data/lib/metric_fu/metrics/flog/grapher.rb +77 -0
- data/lib/metric_fu/metrics/flog/hotspot.rb +46 -0
- data/lib/metric_fu/metrics/flog/metric.rb +29 -0
- data/lib/metric_fu/metrics/flog/report.html.erb +50 -0
- data/lib/metric_fu/metrics/hotspots/analysis/analyzed_problems.rb +34 -0
- data/lib/metric_fu/metrics/hotspots/analysis/analyzer_tables.rb +114 -0
- data/lib/metric_fu/metrics/hotspots/analysis/grouping.rb +23 -0
- data/lib/metric_fu/metrics/hotspots/analysis/groupings.rb +12 -0
- data/lib/metric_fu/metrics/hotspots/analysis/problems.rb +20 -0
- data/lib/metric_fu/metrics/hotspots/analysis/ranked_problem_location.rb +70 -0
- data/lib/metric_fu/metrics/hotspots/analysis/ranking.rb +29 -0
- data/lib/metric_fu/metrics/hotspots/analysis/rankings.rb +91 -0
- data/lib/metric_fu/metrics/hotspots/analysis/record.rb +32 -0
- data/lib/metric_fu/metrics/hotspots/analysis/scoring_strategies.rb +24 -0
- data/lib/metric_fu/metrics/hotspots/analysis/table.rb +67 -0
- data/lib/metric_fu/metrics/hotspots/generator.rb +40 -0
- data/lib/metric_fu/metrics/hotspots/hotspot.rb +87 -0
- data/lib/metric_fu/metrics/hotspots/hotspot_analyzer.rb +61 -0
- data/lib/metric_fu/metrics/hotspots/metric.rb +20 -0
- data/lib/metric_fu/metrics/hotspots/report.html.erb +60 -0
- data/lib/metric_fu/metrics/rails_best_practices/generator.rb +47 -0
- data/lib/metric_fu/metrics/rails_best_practices/grapher.rb +38 -0
- data/lib/metric_fu/metrics/rails_best_practices/metric.rb +31 -0
- data/lib/metric_fu/metrics/rails_best_practices/report.html.erb +22 -0
- data/lib/metric_fu/metrics/rcov/external_client.rb +22 -0
- data/lib/metric_fu/metrics/rcov/generator.rb +75 -0
- data/lib/metric_fu/metrics/rcov/grapher.rb +37 -0
- data/lib/metric_fu/metrics/rcov/hotspot.rb +46 -0
- data/lib/metric_fu/metrics/rcov/metric.rb +61 -0
- data/lib/metric_fu/metrics/rcov/rcov_format_coverage.rb +149 -0
- data/lib/metric_fu/metrics/rcov/rcov_line.rb +48 -0
- data/lib/metric_fu/metrics/rcov/report.html.erb +40 -0
- data/lib/metric_fu/metrics/rcov/simplecov_formatter.rb +74 -0
- data/lib/metric_fu/metrics/reek/generator.rb +94 -0
- data/lib/metric_fu/metrics/reek/grapher.rb +55 -0
- data/lib/metric_fu/metrics/reek/hotspot.rb +95 -0
- data/lib/metric_fu/metrics/reek/metric.rb +26 -0
- data/lib/metric_fu/metrics/reek/report.html.erb +35 -0
- data/lib/metric_fu/metrics/roodi/generator.rb +40 -0
- data/lib/metric_fu/metrics/roodi/grapher.rb +37 -0
- data/lib/metric_fu/metrics/roodi/hotspot.rb +39 -0
- data/lib/metric_fu/metrics/roodi/metric.rb +24 -0
- data/lib/metric_fu/metrics/roodi/report.html.erb +22 -0
- data/lib/metric_fu/metrics/saikuro/generator.rb +145 -0
- data/lib/metric_fu/metrics/saikuro/hotspot.rb +51 -0
- data/lib/metric_fu/metrics/saikuro/metric.rb +31 -0
- data/lib/metric_fu/metrics/saikuro/parsing_element.rb +37 -0
- data/lib/metric_fu/metrics/saikuro/report.html.erb +71 -0
- data/lib/metric_fu/metrics/saikuro/scratch_file.rb +108 -0
- data/lib/metric_fu/metrics/stats/generator.rb +82 -0
- data/lib/metric_fu/metrics/stats/grapher.rb +40 -0
- data/lib/metric_fu/metrics/stats/hotspot.rb +35 -0
- data/lib/metric_fu/metrics/stats/metric.rb +28 -0
- data/lib/metric_fu/metrics/stats/report.html.erb +44 -0
- data/lib/metric_fu/reporter.rb +37 -0
- data/lib/metric_fu/reporting/graphs/graph.rb +69 -0
- data/lib/metric_fu/reporting/graphs/grapher.rb +66 -0
- data/lib/metric_fu/reporting/result.rb +59 -0
- data/lib/metric_fu/run.rb +82 -0
- data/lib/metric_fu/tasks/metric_fu.rake +54 -0
- data/lib/metric_fu/templates/_graph.html.erb +2 -0
- data/lib/metric_fu/templates/_report_footer.html.erb +1 -0
- data/lib/metric_fu/templates/configuration.rb +25 -0
- data/lib/metric_fu/templates/css/bluff.css +15 -0
- data/lib/metric_fu/templates/css/buttons.css +82 -0
- data/lib/metric_fu/templates/css/default.css +43 -0
- data/lib/metric_fu/templates/css/integrity.css +337 -0
- data/lib/metric_fu/templates/css/rcov.css +32 -0
- data/lib/metric_fu/templates/css/reset.css +7 -0
- data/lib/metric_fu/templates/css/syntax.css +19 -0
- data/lib/metric_fu/templates/index.html.erb +10 -0
- data/lib/metric_fu/templates/javascripts/bluff-min.js +1 -0
- data/lib/metric_fu/templates/javascripts/bluff_graph.js +15 -0
- data/lib/metric_fu/templates/javascripts/excanvas.js +35 -0
- data/lib/metric_fu/templates/javascripts/highcharts.js +294 -0
- data/lib/metric_fu/templates/javascripts/highcharts_graph.js +38 -0
- data/lib/metric_fu/templates/javascripts/js-class.js +1 -0
- data/lib/metric_fu/templates/javascripts/standalone-framework.js +17 -0
- data/lib/metric_fu/templates/javascripts/utils.js +9 -0
- data/lib/metric_fu/templates/layout.html.erb +37 -0
- data/lib/metric_fu/templates/metrics_template.rb +80 -0
- data/lib/metric_fu/templates/report.html.erb +31 -0
- data/lib/metric_fu/templates/report.rb +41 -0
- data/lib/metric_fu/templates/template.rb +244 -0
- data/lib/metric_fu/utility.rb +79 -0
- data/lib/metric_fu/version.rb +9 -0
- data/metric_fu.gemspec +71 -0
- data/spec/capture_warnings.rb +55 -0
- data/spec/cli/helper_spec.rb +165 -0
- data/spec/dummy/.gitignore +1 -0
- data/spec/dummy/.gitkeep +0 -0
- data/spec/dummy/lib/.gitkeep +0 -0
- data/spec/dummy/lib/bad_encoding.rb +6 -0
- data/spec/dummy/spec/.gitkeep +0 -0
- data/spec/fixtures/20090630.yml +7922 -0
- data/spec/fixtures/coverage-153.rb +11 -0
- data/spec/fixtures/coverage.rb +13 -0
- data/spec/fixtures/exit0.sh +3 -0
- data/spec/fixtures/exit1.sh +3 -0
- data/spec/fixtures/hotspots/flog.yml +86 -0
- data/spec/fixtures/hotspots/generator.yml +47 -0
- data/spec/fixtures/hotspots/generator_analysis.yml +53 -0
- data/spec/fixtures/hotspots/reek.yml +14 -0
- data/spec/fixtures/hotspots/roodi.yml +13 -0
- data/spec/fixtures/hotspots/saikuro.yml +27 -0
- data/spec/fixtures/hotspots/several_metrics.yml +47 -0
- data/spec/fixtures/hotspots/stats.yml +4 -0
- data/spec/fixtures/hotspots/three_metrics_on_same_file.yml +36 -0
- data/spec/fixtures/line_numbers/foo.rb +33 -0
- data/spec/fixtures/line_numbers/module.rb +11 -0
- data/spec/fixtures/line_numbers/module_surrounds_class.rb +15 -0
- data/spec/fixtures/line_numbers/two_classes.rb +11 -0
- data/spec/fixtures/metric_missing.yml +1 -0
- data/spec/fixtures/rcov_output.txt +135 -0
- data/spec/fixtures/saikuro/app/controllers/sessions_controller.rb_cyclo.html +10 -0
- data/spec/fixtures/saikuro/app/controllers/users_controller.rb_cyclo.html +16 -0
- data/spec/fixtures/saikuro/index_cyclo.html +155 -0
- data/spec/fixtures/saikuro_sfiles/thing.rb_cyclo.html +11 -0
- data/spec/metric_fu/calculate_spec.rb +21 -0
- data/spec/metric_fu/configuration_spec.rb +90 -0
- data/spec/metric_fu/data_structures/line_numbers_spec.rb +63 -0
- data/spec/metric_fu/data_structures/location_spec.rb +110 -0
- data/spec/metric_fu/formatter/configuration_spec.rb +44 -0
- data/spec/metric_fu/formatter/html_spec.rb +138 -0
- data/spec/metric_fu/formatter/yaml_spec.rb +61 -0
- data/spec/metric_fu/formatter_spec.rb +49 -0
- data/spec/metric_fu/gem_version_spec.rb +12 -0
- data/spec/metric_fu/generator_spec.rb +130 -0
- data/spec/metric_fu/loader_spec.rb +13 -0
- data/spec/metric_fu/metric_spec.rb +46 -0
- data/spec/metric_fu/metrics/cane/configuration_spec.rb +22 -0
- data/spec/metric_fu/metrics/cane/generator_spec.rb +184 -0
- data/spec/metric_fu/metrics/churn/configuration_spec.rb +13 -0
- data/spec/metric_fu/metrics/churn/generator_spec.rb +64 -0
- data/spec/metric_fu/metrics/flay/configuration_spec.rb +13 -0
- data/spec/metric_fu/metrics/flay/generator_spec.rb +105 -0
- data/spec/metric_fu/metrics/flay/grapher_spec.rb +57 -0
- data/spec/metric_fu/metrics/flog/configuration_spec.rb +18 -0
- data/spec/metric_fu/metrics/flog/generator_spec.rb +77 -0
- data/spec/metric_fu/metrics/flog/grapher_spec.rb +107 -0
- data/spec/metric_fu/metrics/hotspots/analysis/analyzed_problems_spec.rb +104 -0
- data/spec/metric_fu/metrics/hotspots/analysis/analyzer_tables_spec.rb +71 -0
- data/spec/metric_fu/metrics/hotspots/analysis/ranking_spec.rb +30 -0
- data/spec/metric_fu/metrics/hotspots/analysis/rankings_spec.rb +97 -0
- data/spec/metric_fu/metrics/hotspots/analysis/table_spec.rb +6 -0
- data/spec/metric_fu/metrics/hotspots/generator_spec.rb +46 -0
- data/spec/metric_fu/metrics/hotspots/hotspot_analyzer_spec.rb +10 -0
- data/spec/metric_fu/metrics/hotspots/hotspot_spec.rb +16 -0
- data/spec/metric_fu/metrics/rails_best_practices/configuration_spec.rb +55 -0
- data/spec/metric_fu/metrics/rails_best_practices/generator_spec.rb +33 -0
- data/spec/metric_fu/metrics/rails_best_practices/grapher_spec.rb +62 -0
- data/spec/metric_fu/metrics/rcov/configuration_spec.rb +28 -0
- data/spec/metric_fu/metrics/rcov/generator_spec.rb +22 -0
- data/spec/metric_fu/metrics/rcov/grapher_spec.rb +57 -0
- data/spec/metric_fu/metrics/rcov/hotspot_spec.rb +20 -0
- data/spec/metric_fu/metrics/rcov/rcov_line_spec.rb +89 -0
- data/spec/metric_fu/metrics/rcov/simplecov_formatter_spec.rb +67 -0
- data/spec/metric_fu/metrics/reek/configuration_spec.rb +13 -0
- data/spec/metric_fu/metrics/reek/generator_spec.rb +203 -0
- data/spec/metric_fu/metrics/reek/grapher_spec.rb +66 -0
- data/spec/metric_fu/metrics/roodi/configuration_spec.rb +14 -0
- data/spec/metric_fu/metrics/roodi/generator_spec.rb +82 -0
- data/spec/metric_fu/metrics/roodi/grapher_spec.rb +57 -0
- data/spec/metric_fu/metrics/saikuro/configuration_spec.rb +25 -0
- data/spec/metric_fu/metrics/saikuro/generator_spec.rb +71 -0
- data/spec/metric_fu/metrics/stats/generator_spec.rb +96 -0
- data/spec/metric_fu/metrics/stats/grapher_spec.rb +69 -0
- data/spec/metric_fu/reporter_spec.rb +41 -0
- data/spec/metric_fu/reporting/graphs/graph_spec.rb +44 -0
- data/spec/metric_fu/reporting/graphs/grapher_spec.rb +24 -0
- data/spec/metric_fu/reporting/result_spec.rb +50 -0
- data/spec/metric_fu/run_spec.rb +197 -0
- data/spec/metric_fu/templates/configuration_spec.rb +51 -0
- data/spec/metric_fu/templates/metrics_template_spec.rb +11 -0
- data/spec/metric_fu/templates/report_spec.rb +15 -0
- data/spec/metric_fu/templates/template_spec.rb +233 -0
- data/spec/metric_fu/utility_spec.rb +12 -0
- data/spec/metric_fu_spec.rb +52 -0
- data/spec/quality_spec.rb +114 -0
- data/spec/shared/configured.rb +45 -0
- data/spec/shared/test_coverage.rb +95 -0
- data/spec/spec_helper.rb +46 -0
- data/spec/support/.metrics +4 -0
- data/spec/support/deferred_garbaged_collection.rb +33 -0
- data/spec/support/helper_methods.rb +32 -0
- data/spec/support/matcher_create_file.rb +37 -0
- data/spec/support/matcher_create_files.rb +43 -0
- data/spec/support/samples/reek/alfa.rb +1 -0
- data/spec/support/suite.rb +26 -0
- data/spec/support/test_fixtures.rb +37 -0
- data/spec/support/timeout.rb +7 -0
- data/spec/support/usage_test.rb +150 -0
- data/spec/usage_test_spec.rb +93 -0
- metadata +735 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require "coderay"
|
|
2
|
+
MetricFu.lib_require { "utility" }
|
|
3
|
+
# CodeRay options
|
|
4
|
+
# used to analyze source code, because object Tokens is a list of tokens with specified types.
|
|
5
|
+
# :tab_width – tabulation width in spaces. Default: 8
|
|
6
|
+
# :css – how to include the styles (:class и :style). Default: :class)
|
|
7
|
+
#
|
|
8
|
+
# :wrap – wrap result in html tag :page, :div, :span or not to wrap (nil)
|
|
9
|
+
#
|
|
10
|
+
# :line_numbers – how render line numbers (:table, :inline, :list or nil)
|
|
11
|
+
#
|
|
12
|
+
# :line_number_start – first line number
|
|
13
|
+
#
|
|
14
|
+
# :bold_every – make every n-th line number bold. Default: 10
|
|
15
|
+
module MetricFu
|
|
16
|
+
module Formatter
|
|
17
|
+
class Syntax
|
|
18
|
+
def initialize
|
|
19
|
+
@options = { css: :class, style: :alpha }
|
|
20
|
+
@line_number_options = { line_numbers: :inline, line_number_start: 0 }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def highlight(ruby_text, line_number)
|
|
24
|
+
tokens = tokenize(ruby_text)
|
|
25
|
+
tokens.div(highlight_options(line_number))
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def highlight_options(line_number)
|
|
29
|
+
line_number = line_number.to_i
|
|
30
|
+
if line_number > 0
|
|
31
|
+
@options.merge(@line_number_options.merge(line_number_start: line_number))
|
|
32
|
+
else
|
|
33
|
+
@options
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
private
|
|
38
|
+
|
|
39
|
+
def tokenize(ruby_text)
|
|
40
|
+
ascii_text = MetricFu::Utility.clean_ascii_text(ruby_text)
|
|
41
|
+
tokens = CodeRay.scan(ascii_text, :ruby)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module MetricFu
|
|
2
|
+
module Formatter
|
|
3
|
+
class YAML
|
|
4
|
+
include MetricFu::Io
|
|
5
|
+
|
|
6
|
+
DEFAULT_PATH = "report.yml"
|
|
7
|
+
|
|
8
|
+
def initialize(opts = {})
|
|
9
|
+
@options = opts
|
|
10
|
+
@path_or_io = @options[:output] || DEFAULT_PATH
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def finish
|
|
14
|
+
write_output(MetricFu.result.as_yaml, @path_or_io)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
require "open3"
|
|
3
|
+
require "shellwords"
|
|
4
|
+
require "metric_fu"
|
|
5
|
+
MetricFu.lib_require { "logger" }
|
|
6
|
+
MetricFu.lib_require { "gem_version" }
|
|
7
|
+
module MetricFu
|
|
8
|
+
class GemRun
|
|
9
|
+
attr_reader :output, :gem_name, :library_name, :version, :arguments
|
|
10
|
+
def initialize(arguments = {})
|
|
11
|
+
@gem_name = arguments.fetch(:gem_name)
|
|
12
|
+
@library_name = arguments.fetch(:metric_name)
|
|
13
|
+
@version = arguments.fetch(:version) { MetricFu::GemVersion.for(library_name) }
|
|
14
|
+
args = arguments.fetch(:args)
|
|
15
|
+
@arguments = args.respond_to?(:scan) ? Shellwords.shellwords(args) : args
|
|
16
|
+
@output = ""
|
|
17
|
+
@errors = []
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def summary
|
|
21
|
+
"RubyGem #{gem_name}, library #{library_name}, version #{version}, arguments #{arguments}"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def run
|
|
25
|
+
@output = execute
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def execute
|
|
29
|
+
mf_debug "Running #{summary}"
|
|
30
|
+
captured_output = ""
|
|
31
|
+
captured_errors = ""
|
|
32
|
+
thread = ""
|
|
33
|
+
Open3.popen3("#{library_name}", *arguments) do |_stdin, stdout, stderr, wait_thr|
|
|
34
|
+
captured_output << stdout.read.chomp
|
|
35
|
+
captured_errors << stderr.read.chomp
|
|
36
|
+
thread = wait_thr
|
|
37
|
+
end
|
|
38
|
+
rescue StandardError => run_error
|
|
39
|
+
handle_run_error(run_error)
|
|
40
|
+
rescue SystemExit => system_exit
|
|
41
|
+
handle_system_exit(system_exit)
|
|
42
|
+
ensure
|
|
43
|
+
print_errors
|
|
44
|
+
return captured_output, captured_errors, thread.value
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def handle_run_error(run_error)
|
|
48
|
+
@errors << "ERROR: #{run_error.inspect}"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def handle_system_exit(system_exit)
|
|
52
|
+
status = system_exit.success? ? "SUCCESS" : "FAILURE"
|
|
53
|
+
message = "#{status} with code #{system_exit.status}: " <<
|
|
54
|
+
"#{system_exit.message}: #{system_exit.backtrace.inspect}"
|
|
55
|
+
if status == "SUCCESS"
|
|
56
|
+
mf_debug message
|
|
57
|
+
else
|
|
58
|
+
@errors << message
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def print_errors
|
|
63
|
+
return if @errors.empty?
|
|
64
|
+
STDERR.puts "ERRORS running #{summary}"
|
|
65
|
+
@errors.each do |error|
|
|
66
|
+
STDERR.puts "\t" << error
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
require "rubygems"
|
|
3
|
+
module MetricFu
|
|
4
|
+
class GemVersion
|
|
5
|
+
# regexp from https://github.com/gemnasium/gemnasium-parser/blob/807d7ccc/lib/gemnasium/parser/patterns.rb#L11
|
|
6
|
+
# under MIT License
|
|
7
|
+
GEM_NAME = /[a-zA-Z0-9\-_\.]+/
|
|
8
|
+
QUOTED_GEM_NAME = /(?:(?<gq>["'])(?<name>#{GEM_NAME})\k<gq>|%q<(?<name>#{GEM_NAME})>)/
|
|
9
|
+
MATCHER = /(?:=|!=|>|<|>=|<=|~>)/
|
|
10
|
+
VERSION = /[0-9]+(?:\.[a-zA-Z0-9]+)*/
|
|
11
|
+
REQUIREMENT = /[ \t]*(?:#{MATCHER}[ \t]*)?#{VERSION}[ \t]*/
|
|
12
|
+
REQUIREMENT_LIST = /(?<qr1>["'])(?<req1>#{REQUIREMENT})\k<qr1>(?:[ \t]*,[ \t]*(?<qr2>["'])(?<req2>#{REQUIREMENT})\k<qr2>)?/
|
|
13
|
+
REQUIREMENTS = /(?:#{REQUIREMENT_LIST}|\[[ \t]*#{REQUIREMENT_LIST}[ \t]*\])/
|
|
14
|
+
COMMENT = /(#[^\n]*)?/
|
|
15
|
+
ADD_DEPENDENCY_CALL = /^[ \t]*\w+\.add(?<type>_runtime|_development)?_dependency\(?[ \t]*#{QUOTED_GEM_NAME}(.freeze)?(?:[ \t]*,[ \t]*#{REQUIREMENTS})?[ \t]*\)?[ \t]*#{COMMENT}$/
|
|
16
|
+
|
|
17
|
+
def initialize
|
|
18
|
+
@gem_spec = File.open(gemspec, "rb") { |f| f.readlines }
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def gemspec
|
|
22
|
+
File.join(MetricFu.root_dir, "metric_fu.gemspec")
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def new_dependency(name, version)
|
|
26
|
+
Gem::Dependency.new(name, version, :runtime)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def gem_runtime_dependencies
|
|
30
|
+
@gem_runtime_dependencies ||=
|
|
31
|
+
begin
|
|
32
|
+
@gem_spec.grep(/add_dependency|add_runtime/).map do |line|
|
|
33
|
+
match = line.match(ADD_DEPENDENCY_CALL)
|
|
34
|
+
name = match["name"].downcase.sub("metric_fu-", "")
|
|
35
|
+
version = [match["req1"], match["req2"]].compact
|
|
36
|
+
new_dependency(name, version)
|
|
37
|
+
end.compact << new_dependency("rcov", ["~> 0.8"])
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def for(name)
|
|
42
|
+
name.downcase!
|
|
43
|
+
dep = gem_runtime_dependencies.find(unknown_dependency(name)) do |gem_dep|
|
|
44
|
+
gem_dep.name == name
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
dep.requirements_list
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def unknown_dependency(name)
|
|
51
|
+
-> { new_dependency(name, [">= 0"]) }
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
RESOLVER = new
|
|
55
|
+
def self.for(name)
|
|
56
|
+
RESOLVER.for(name).dup
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def self.dependencies
|
|
60
|
+
RESOLVER.gem_runtime_dependencies.dup
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def self.activated_gems
|
|
64
|
+
if Gem::Specification.respond_to?(:stubs)
|
|
65
|
+
Gem::Specification.stubs
|
|
66
|
+
else
|
|
67
|
+
Gem.loaded_specs.values
|
|
68
|
+
end.select(&:activated?)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def self.activated_version(name)
|
|
72
|
+
activated_gems.find do |gem|
|
|
73
|
+
return gem.version.version if gem.name == name
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def self.dependency_summary(gem_dep)
|
|
78
|
+
name = gem_dep.name
|
|
79
|
+
version = activated_version(gem_dep.name) || gem_dep.requirements_list
|
|
80
|
+
{
|
|
81
|
+
"name" => name,
|
|
82
|
+
"version" => version,
|
|
83
|
+
}
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def self.dependencies_summary
|
|
87
|
+
dependencies.map do |gem_dep|
|
|
88
|
+
dependency_summary(gem_dep)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
MetricFu.lib_require { "utility" }
|
|
2
|
+
module MetricFu
|
|
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_result(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 metric under the scratch_directory, where
|
|
27
|
+
# any output from the #emit method should go.
|
|
28
|
+
#
|
|
29
|
+
# It will also create the output_directory if neccessary, and
|
|
30
|
+
# in general setup the directory structure that the MetricFu system
|
|
31
|
+
# expects.
|
|
32
|
+
class Generator
|
|
33
|
+
attr_reader :result, :template, :options
|
|
34
|
+
|
|
35
|
+
def initialize(options = {})
|
|
36
|
+
@options = options
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def self.metric
|
|
40
|
+
not_implemented
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def metric
|
|
44
|
+
self.class.metric
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
@generators = []
|
|
48
|
+
# @return all subclassed generators [Array<MetricFu::Generator>]
|
|
49
|
+
def self.generators
|
|
50
|
+
@generators
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def self.get_generator(metric)
|
|
54
|
+
generators.find { |generator|generator.metric.to_s == metric.to_s.downcase }
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def self.inherited(subclass)
|
|
58
|
+
@generators << subclass
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Returns the directory where the Generator will write any output
|
|
62
|
+
def self.metric_directory
|
|
63
|
+
@metric_directory ||=
|
|
64
|
+
MetricFu::Metric.get_metric(metric).run_options[:output_directory] ||
|
|
65
|
+
begin
|
|
66
|
+
metric_directory = MetricFu::Io::FileSystem.scratch_directory(metric)
|
|
67
|
+
MetricFu::Utility.mkdir_p(metric_directory, verbose: false)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# @return [String]
|
|
72
|
+
# The path of the metric directory this class is using.
|
|
73
|
+
def metric_directory
|
|
74
|
+
self.class.metric_directory
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def remove_excluded_files(paths, globs_to_remove = MetricFu::Io::FileSystem.file_globs_to_ignore)
|
|
78
|
+
files_to_remove = []
|
|
79
|
+
globs_to_remove.each do |glob|
|
|
80
|
+
files_to_remove.concat(Dir[glob])
|
|
81
|
+
end
|
|
82
|
+
paths - files_to_remove
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def metric_config
|
|
86
|
+
MetricFu::Metric.get_metric(metric)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def run!(args)
|
|
90
|
+
metric_config.run_external(args)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# Provides a template method to drive the production of a metric
|
|
94
|
+
# from a concrete implementation of this class. Each concrete
|
|
95
|
+
# class must implement the three methods that this template method
|
|
96
|
+
# calls: #emit, #analyze and #to_h. For more details, see the
|
|
97
|
+
# class documentation.
|
|
98
|
+
#
|
|
99
|
+
# This template method also calls before_emit, after_emit... etc.
|
|
100
|
+
# methods to allow extra hooks into the processing methods, and help
|
|
101
|
+
# to keep the logic of your Generators clean.
|
|
102
|
+
def generate_result
|
|
103
|
+
mf_debug "Executing #{metric}"
|
|
104
|
+
emit
|
|
105
|
+
analyze
|
|
106
|
+
to_h
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def round_to_tenths(decimal)
|
|
110
|
+
decimal = 0.0 if decimal.to_s.eql?("NaN")
|
|
111
|
+
(decimal * 10).round / 10.0
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def emit #:nodoc:
|
|
115
|
+
self.class.not_implemented
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def analyze #:nodoc:
|
|
119
|
+
self.class.not_implemented
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def to_h #:nodoc:
|
|
123
|
+
self.class.not_implemented
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def self.not_implemented
|
|
127
|
+
raise NotImplementedError.new <<-EOF
|
|
128
|
+
Required method #{caller[0]} not implemented in #{__FILE__}.
|
|
129
|
+
This method must be implemented by a concrete class descending
|
|
130
|
+
from Generator. See generator class documentation for more
|
|
131
|
+
information.
|
|
132
|
+
EOF
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
end
|
data/lib/metric_fu/io.rb
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
MetricFu.lib_require { "utility" }
|
|
2
|
+
module MetricFu
|
|
3
|
+
module Io
|
|
4
|
+
# TODO: Move this module / functionality elsewhere and make less verbose
|
|
5
|
+
module FileSystem
|
|
6
|
+
# TODO: Use a better environmental variable name for the output / artiface dir. Set to a different default in tests.
|
|
7
|
+
@default_artifact_dir = "tmp/metric_fu"
|
|
8
|
+
def self.default_artifact_dir
|
|
9
|
+
@default_artifact_dir
|
|
10
|
+
end
|
|
11
|
+
def self.artifact_dir
|
|
12
|
+
(ENV["CC_BUILD_ARTIFACTS"] || @artifact_dir)
|
|
13
|
+
end
|
|
14
|
+
def self.artifact_dir=(artifact_dir)
|
|
15
|
+
@artifact_dir = artifact_dir
|
|
16
|
+
end
|
|
17
|
+
self.artifact_dir = default_artifact_dir
|
|
18
|
+
|
|
19
|
+
module_function
|
|
20
|
+
|
|
21
|
+
def directories
|
|
22
|
+
@directories ||= {}
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def directory(name)
|
|
26
|
+
directories.fetch(name) { raise "No such directory configured: #{name}" }
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def scratch_directory(name)
|
|
30
|
+
File.join(directory("scratch_directory"), name.to_s)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def file_globs_to_ignore
|
|
34
|
+
@file_globs_to_ignore ||= []
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def set_directories
|
|
38
|
+
@directories = {}
|
|
39
|
+
@directories["base_directory"] = MetricFu.artifact_dir
|
|
40
|
+
@directories["scratch_directory"] = MetricFu.scratch_dir
|
|
41
|
+
@directories["output_directory"] = MetricFu.output_dir
|
|
42
|
+
@directories["data_directory"] = MetricFu.data_dir
|
|
43
|
+
create_directories @directories.values
|
|
44
|
+
|
|
45
|
+
@directories["root_directory"] = MetricFu.root_dir
|
|
46
|
+
# TODO Though this is true of the general AwesomeTemplate, it is not necessarily true of templates within each Metric. Each metric should probably know how to use AwesomeTemplate (or whatever)
|
|
47
|
+
@directories["template_directory"] = File.join(@directories.fetch("root_directory"), "lib", "templates")
|
|
48
|
+
@file_globs_to_ignore = []
|
|
49
|
+
set_code_dirs
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def create_directories(*dirs)
|
|
53
|
+
# due to behavior differences between ruby 1.8.7 and 1.9.3
|
|
54
|
+
# this is good enough for now
|
|
55
|
+
Array(*dirs).each do |dir|
|
|
56
|
+
MetricFu::Utility.mkdir_p dir
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Add the 'app' directory if we're running within rails.
|
|
61
|
+
def set_code_dirs
|
|
62
|
+
@directories["code_dirs"] = %w(app lib).select { |dir| Dir.exist?(dir) }
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Writes the output to a file or io stream.
|
|
67
|
+
# @param output [String, #to_s] the content to write.
|
|
68
|
+
# @param path_or_io [String, #to_s, IO, #write] a file path
|
|
69
|
+
# or an io stream that responds to write.
|
|
70
|
+
# @return [nil]
|
|
71
|
+
def write_output(output, path_or_io)
|
|
72
|
+
io_for(path_or_io) do |io|
|
|
73
|
+
io.write(output)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Yields an io object for writing output.
|
|
78
|
+
# @example
|
|
79
|
+
# io_for('path/to/file') do |io|
|
|
80
|
+
# io.write(output)
|
|
81
|
+
# end
|
|
82
|
+
#
|
|
83
|
+
# io_for(STDOUT) do |io|
|
|
84
|
+
# io.write(output)
|
|
85
|
+
# end
|
|
86
|
+
#
|
|
87
|
+
# stream = StringIO.new
|
|
88
|
+
# io_for(stream) do |io|
|
|
89
|
+
# io.write(output)
|
|
90
|
+
# end
|
|
91
|
+
#
|
|
92
|
+
# @param path_or_io [String, #to_s, IO, #write] a file path
|
|
93
|
+
# or an io stream that responds to write.
|
|
94
|
+
#
|
|
95
|
+
# @yield [IO] an open stream for writing.
|
|
96
|
+
#
|
|
97
|
+
# @note Given a path to a file, an open file will
|
|
98
|
+
# be yielded and closed after the block completes.
|
|
99
|
+
# Given an existing io stream, the stream will not
|
|
100
|
+
# be automatically closed. Cleanup, if necessary, is
|
|
101
|
+
# the responsibility of the caller.
|
|
102
|
+
def io_for(path_or_io, &block)
|
|
103
|
+
raise ArgumentError, "No path or io provided." if path_or_io.nil?
|
|
104
|
+
raise ArgumentError, "No block given. Cannot yield io stream." unless block_given?
|
|
105
|
+
|
|
106
|
+
if path_or_io.respond_to?(:write)
|
|
107
|
+
# We have an existing open stream...
|
|
108
|
+
block.call(path_or_io)
|
|
109
|
+
else # Otherwise, we assume its a file path...
|
|
110
|
+
file_for(path_or_io, &block)
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def file_for(path, &block)
|
|
115
|
+
File.open(path_relative_to_base(path), "w") do |file|
|
|
116
|
+
block.call(file)
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def dir_for(path)
|
|
121
|
+
return nil if path.nil?
|
|
122
|
+
pathname = path_relative_to_base(path)
|
|
123
|
+
MetricFu::Utility.mkdir_p(pathname) unless File.directory?(pathname)
|
|
124
|
+
pathname
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def path_relative_to_base(path)
|
|
128
|
+
pathname = MetricFu.run_path.join(MetricFu::Io::FileSystem.directory("base_directory")) # make full path relative to base directory
|
|
129
|
+
pathname.join(path)
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
end
|