saikuro 1.1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,98 @@
1
+ module Saikuro
2
+ class CLI
3
+
4
+ require 'stringio'
5
+ require 'getoptlong'
6
+ require 'fileutils'
7
+ require 'find'
8
+ require 'rdoc/usage'
9
+
10
+ include ResultIndexGenerator
11
+
12
+
13
+ def run
14
+
15
+ files = Array.new
16
+ output_dir = "./"
17
+ formater = "html"
18
+ state_filter = Filter.new(5)
19
+ token_filter = Filter.new(10, 25, 50)
20
+ comp_state = comp_token = false
21
+ begin
22
+ opt = GetoptLong.new(
23
+ ["-o","--output_directory", GetoptLong::REQUIRED_ARGUMENT],
24
+ ["-h","--help", GetoptLong::NO_ARGUMENT],
25
+ ["-f","--formater", GetoptLong::REQUIRED_ARGUMENT],
26
+ ["-c","--cyclo", GetoptLong::NO_ARGUMENT],
27
+ ["-t","--token", GetoptLong::NO_ARGUMENT],
28
+ ["-y","--filter_cyclo", GetoptLong::REQUIRED_ARGUMENT],
29
+ ["-k","--filter_token", GetoptLong::REQUIRED_ARGUMENT],
30
+ ["-w","--warn_cyclo", GetoptLong::REQUIRED_ARGUMENT],
31
+ ["-s","--warn_token", GetoptLong::REQUIRED_ARGUMENT],
32
+ ["-e","--error_cyclo", GetoptLong::REQUIRED_ARGUMENT],
33
+ ["-d","--error_token", GetoptLong::REQUIRED_ARGUMENT],
34
+ ["-p","--parse_file", GetoptLong::REQUIRED_ARGUMENT],
35
+ ["-i","--input_directory", GetoptLong::REQUIRED_ARGUMENT],
36
+ ["-v","--verbose", GetoptLong::NO_ARGUMENT]
37
+ )
38
+
39
+ opt.each do |arg,val|
40
+ case arg
41
+ when "-o"
42
+ output_dir = val
43
+ when "-h"
44
+ RDoc.usage('help')
45
+ when "-f"
46
+ formater = val
47
+ when "-c"
48
+ comp_state = true
49
+ when "-t"
50
+ comp_token = true
51
+ when "-k"
52
+ token_filter.limit = val.to_i
53
+ when "-s"
54
+ token_filter.warn = val.to_i
55
+ when "-d"
56
+ token_filter.error = val.to_i
57
+ when "-y"
58
+ state_filter.limit = val.to_i
59
+ when "-w"
60
+ state_filter.warn = val.to_i
61
+ when "-e"
62
+ state_filter.error = val.to_i
63
+ when "-p"
64
+ files<< val
65
+ when "-i"
66
+ files.concat(get_ruby_files(val))
67
+ when "-v"
68
+ STDOUT.puts "Verbose mode on"
69
+ $VERBOSE = true
70
+ end
71
+
72
+ end
73
+ RDoc.usage if !comp_state && !comp_token
74
+ rescue => err
75
+ RDoc.usage
76
+ end
77
+
78
+ if formater =~ /html/i
79
+ state_formater = StateHTMLComplexityFormater.new(STDOUT,state_filter)
80
+ token_count_formater = HTMLTokenCounterFormater.new(STDOUT,token_filter)
81
+ else
82
+ state_formater = ParseStateFormater.new(STDOUT,state_filter)
83
+ token_count_formater = TokenCounterFormater.new(STDOUT,token_filter)
84
+ end
85
+
86
+ state_formater = nil if !comp_state
87
+ token_count_formater = nil if !comp_token
88
+
89
+ idx_states, idx_tokens = Saikuro.analyze(files,
90
+ state_formater,
91
+ token_count_formater,
92
+ output_dir)
93
+
94
+ write_cyclo_index(idx_states, output_dir)
95
+ write_token_index(idx_tokens, output_dir)
96
+ end #end run
97
+ end #class CLI
98
+ end
@@ -0,0 +1,88 @@
1
+ module ResultIndexGenerator
2
+ def summarize_errors_and_warnings(enw, header)
3
+ return "" if enw.empty?
4
+ f = StringIO.new
5
+ erval = Hash.new { |h,k| h[k] = Array.new }
6
+ wval = Hash.new { |h,k| h[k] = Array.new }
7
+
8
+ enw.each do |fname, warnings, errors|
9
+ errors.each do |c,m,v|
10
+ erval[v] << [fname, c, m]
11
+ end
12
+ warnings.each do |c,m,v|
13
+ wval[v] << [fname, c, m]
14
+ end
15
+ end
16
+
17
+ f.puts "<h2 class=\"class_name\">Errors and Warnings</h2>"
18
+ f.puts "<table width=\"100%\" border=\"1\">"
19
+ f.puts header
20
+
21
+ f.puts print_summary_table_rows(erval, "error")
22
+ f.puts print_summary_table_rows(wval, "warning")
23
+ f.puts "</table>"
24
+
25
+ f.string
26
+ end
27
+
28
+ def print_summary_table_rows(ewvals, klass_type)
29
+ f = StringIO.new
30
+ ewvals.sort { |a,b| b <=> a}.each do |v, vals|
31
+ vals.sort.each do |fname, c, m|
32
+ f.puts "<tr><td><a href=\"./#{fname}\">#{c}</a></td><td>#{m}</td>"
33
+ f.puts "<td class=\"#{klass_type}\">#{v}</td></tr>"
34
+ end
35
+ end
36
+ f.string
37
+ end
38
+
39
+ def list_analyzed_files(files)
40
+ f = StringIO.new
41
+ f.puts "<h2 class=\"class_name\">Analyzed Files</h2>"
42
+ f.puts "<ul>"
43
+ files.each do |fname, warnings, errors|
44
+ readname = fname.split("_")[0...-1].join("_")
45
+ f.puts "<li>"
46
+ f.puts "<p class=\"file_name\"><a href=\"./#{fname}\">#{readname}</a>"
47
+ f.puts "</li>"
48
+ end
49
+ f.puts "</ul>"
50
+ f.string
51
+ end
52
+
53
+ def write_index(files, filename, title, header)
54
+ return if files.empty?
55
+
56
+ File.open(filename,"w") do |f|
57
+ f.puts "<html><head><title>#{title}</title></head>"
58
+ f.puts "#{HTMLStyleSheet.style_sheet}\n<body>"
59
+ f.puts "<h1>#{title}</h1>"
60
+
61
+ enw = files.find_all { |fn,w,e| (!w.empty? || !e.empty?) }
62
+
63
+ f.puts summarize_errors_and_warnings(enw, header)
64
+
65
+ f.puts "<hr/>"
66
+ f.puts list_analyzed_files(files)
67
+ f.puts "</body></html>"
68
+ end
69
+ end
70
+
71
+ def write_cyclo_index(files, output_dir)
72
+ header = "<tr><th>Class</th><th>Method</th><th>Complexity</th></tr>"
73
+ write_index(files,
74
+ "#{output_dir}/index_cyclo.html",
75
+ "Index for cyclomatic complexity",
76
+ header)
77
+ end
78
+
79
+ def write_token_index(files, output_dir)
80
+ header = "<tr><th>File</th><th>Line #</th><th>Tokens</th></tr>"
81
+ write_index(files,
82
+ "#{output_dir}/index_token.html",
83
+ "Index for tokens per line",
84
+ header)
85
+ end
86
+
87
+ end
88
+
@@ -1,3 +1,3 @@
1
1
  module Saikuro
2
- VERSION = "1.1.1.1"
2
+ VERSION = "1.2.0"
3
3
  end