atoulme-Saikuro 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/{README → README.rdoc} +23 -8
- data/lib/saikuro.rb +143 -90
- metadata +6 -6
data/{README → README.rdoc}
RENAMED
@@ -1,4 +1,4 @@
|
|
1
|
-
Version
|
1
|
+
Version 1.1.2
|
2
2
|
|
3
3
|
Saikuro:
|
4
4
|
Saikuro is a Ruby cyclomatic complexity analyzer. When given Ruby
|
@@ -26,8 +26,8 @@ running. If you are using 1.8.5 please apply this patch :
|
|
26
26
|
http://www.ruby-lang.org/cgi-bin/cvsweb.cgi/ruby/lib/rdoc/ri/ri_options.rb.diff?r1=1.2.2.13;r2=1.2.2.14
|
27
27
|
|
28
28
|
|
29
|
-
Usage:
|
30
|
-
Saikuro is a command line program.
|
29
|
+
=Usage:
|
30
|
+
==Saikuro is a command line program.
|
31
31
|
Running "saikuro -h" will output a usage statement describing all
|
32
32
|
the various arguments you can pass to it.
|
33
33
|
|
@@ -50,8 +50,23 @@ will mark all methods with a complexity of 11 or higher with a
|
|
50
50
|
warning. Finally, "-e 16" will flag all methods with a complexity of
|
51
51
|
16 or higher with an error.
|
52
52
|
|
53
|
+
==Saikuro is also a Ruby library.
|
53
54
|
|
54
|
-
|
55
|
+
You can call it from your application to run metrics.
|
56
|
+
It's perfectly suited for a Rake task, right in the middle of your build.
|
57
|
+
An example from Buildr:
|
58
|
+
gem 'atoulme-Saikuro'
|
59
|
+
require 'saikuro'
|
60
|
+
output_dir = File.expand_path(File.join(File.dirname(__FILE__), "..", "_reports", "saikuro"))
|
61
|
+
base_dir = Pathname.new(File.expand_path(File.join(File.dirname(__FILE__), "..")))
|
62
|
+
rb_files = ["lib", "addon"].collect { |folder|
|
63
|
+
FileList[File.expand_path(File.join(File.dirname(__FILE__), "..", folder, "**", "*.rb"))]
|
64
|
+
}.flatten.collect {|path|
|
65
|
+
Pathname.new(path).relative_path_from(base_dir).to_s
|
66
|
+
}
|
67
|
+
SaikuroRunner.new.run(rb_files, output_dir)
|
68
|
+
|
69
|
+
=About Cyclomatic Complexity:
|
55
70
|
|
56
71
|
The following document provides a very good and detailed description
|
57
72
|
by the author of cyclomatic complexity.
|
@@ -121,20 +136,20 @@ Mainly, because we have not gotten around to it. We are wondering if
|
|
121
136
|
this would increase the noise more than it should.
|
122
137
|
|
123
138
|
|
124
|
-
Tests:
|
139
|
+
=Tests:
|
125
140
|
In the test directory is a sample file that has examples of the
|
126
141
|
various possible cases that we examined and documented the expected
|
127
142
|
cyclomatic complexity result. If you find mistakes or missing tests
|
128
143
|
please report them.
|
129
144
|
|
130
|
-
Contact:
|
145
|
+
=Contact:
|
131
146
|
Saikuro is written by
|
132
147
|
Zev Blut (zb at ubit dot com)
|
133
148
|
|
134
|
-
Acknowledgments:
|
149
|
+
=Acknowledgments:
|
135
150
|
Thanks to Elbert Corpuz for writing the CSS for the HTML output!
|
136
151
|
|
137
|
-
Other metric tools for Ruby:
|
152
|
+
=Other metric tools for Ruby:
|
138
153
|
Ryan Davis has an abc metric program as an example in his ParseTree
|
139
154
|
product: http://www.zenspider.com/ZSS/Products/ParseTree/
|
140
155
|
|
data/lib/saikuro.rb
CHANGED
@@ -730,80 +730,66 @@ end
|
|
730
730
|
|
731
731
|
module HTMLStyleSheet
|
732
732
|
def HTMLStyleSheet.style_sheet
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
out.puts '.start_token_count, .file_count {'
|
794
|
-
out.puts ' color: #333;'
|
795
|
-
out.puts '}'
|
796
|
-
out.puts ''
|
797
|
-
out.puts '.warning {'
|
798
|
-
out.puts ' background-color: yellow;'
|
799
|
-
out.puts '}'
|
800
|
-
out.puts ''
|
801
|
-
out.puts '.error {'
|
802
|
-
out.puts ' background-color: #f00;'
|
803
|
-
out.puts '}'
|
804
|
-
out.puts "</style>"
|
805
|
-
|
806
|
-
out.string
|
733
|
+
<<-CSS
|
734
|
+
<style>
|
735
|
+
body {
|
736
|
+
margin: 20px;
|
737
|
+
padding: 0;
|
738
|
+
font-size: 12px;
|
739
|
+
font-family: bitstream vera sans, verdana, arial, sans serif;
|
740
|
+
background-color: #efefef;
|
741
|
+
}
|
742
|
+
table {
|
743
|
+
border-collapse: collapse;
|
744
|
+
/*border-spacing: 0;*/
|
745
|
+
border: 1px solid #666;
|
746
|
+
background-color: #fff;
|
747
|
+
margin-bottom: 20px;
|
748
|
+
}
|
749
|
+
table, th, th+th, td, td+td {
|
750
|
+
border: 1px solid #ccc;
|
751
|
+
}
|
752
|
+
table th {
|
753
|
+
font-size: 12px;
|
754
|
+
color: #fc0;
|
755
|
+
padding: 4px 0;
|
756
|
+
background-color: #336;
|
757
|
+
}
|
758
|
+
th, td {
|
759
|
+
padding: 4px 10px;
|
760
|
+
}
|
761
|
+
td {
|
762
|
+
font-size: 13px;
|
763
|
+
}
|
764
|
+
.class_name {
|
765
|
+
font-size: 17px;
|
766
|
+
margin: 20px 0 0;
|
767
|
+
}
|
768
|
+
.class_complexity {
|
769
|
+
margin: 0 auto;
|
770
|
+
}
|
771
|
+
.class_complexity>.class_complexity {
|
772
|
+
margin: 0;
|
773
|
+
}
|
774
|
+
.class_total_complexity, .class_total_lines, .start_token_count, .file_count {
|
775
|
+
font-size: 13px;
|
776
|
+
font-weight: bold;
|
777
|
+
}
|
778
|
+
.class_total_complexity, .class_total_lines {
|
779
|
+
color: #c00;
|
780
|
+
}
|
781
|
+
.start_token_count, .file_count {
|
782
|
+
color: #333;
|
783
|
+
}
|
784
|
+
.warning {
|
785
|
+
background-color: yellow;
|
786
|
+
}
|
787
|
+
.error {
|
788
|
+
background-color: #f00;
|
789
|
+
}
|
790
|
+
</style>
|
791
|
+
|
792
|
+
CSS
|
807
793
|
end
|
808
794
|
|
809
795
|
def style_sheet
|
@@ -818,9 +804,7 @@ class HTMLTokenCounterFormater < TokenCounterFormater
|
|
818
804
|
def start(new_out=nil)
|
819
805
|
reset_data
|
820
806
|
@out = new_out if new_out
|
821
|
-
@out.puts "<html>"
|
822
|
-
@out.puts style_sheet
|
823
|
-
@out.puts "<body>"
|
807
|
+
@out.puts "<html>#{style_sheet}<body>"
|
824
808
|
end
|
825
809
|
|
826
810
|
def start_count(number_of_files)
|
@@ -853,8 +837,7 @@ class HTMLTokenCounterFormater < TokenCounterFormater
|
|
853
837
|
end
|
854
838
|
|
855
839
|
def end
|
856
|
-
@out.puts "</body>"
|
857
|
-
@out.puts "</html>"
|
840
|
+
@out.puts "</body>\n</html>"
|
858
841
|
end
|
859
842
|
end
|
860
843
|
|
@@ -1226,21 +1209,91 @@ class SaikuroCMDLineRunner
|
|
1226
1209
|
|
1227
1210
|
end
|
1228
1211
|
|
1212
|
+
#
|
1213
|
+
# A runner to call from Ruby code
|
1214
|
+
# Perfect for the inpromptue Rake task.
|
1215
|
+
#
|
1216
|
+
#
|
1229
1217
|
class SaikuroRunner
|
1230
1218
|
include ResultIndexGenerator
|
1231
1219
|
|
1232
|
-
|
1233
|
-
|
1234
|
-
|
1235
|
-
|
1236
|
-
|
1237
|
-
|
1220
|
+
# :call-seq:
|
1221
|
+
# run(*args)
|
1222
|
+
# Either runs the Saikuro analyzer over a configuration hash (see run_with_config)
|
1223
|
+
# Or runs with standard options (in which case you need to pass files and output_dir, see run_with_standard_options)
|
1224
|
+
def run(*args)
|
1225
|
+
if args.size == 1
|
1226
|
+
run_with_config(*args)
|
1238
1227
|
else
|
1239
|
-
|
1240
|
-
token_count_formater = TokenCounterFormater.new(STDOUT,token_filter)
|
1228
|
+
run_with_standard_options(*args)
|
1241
1229
|
end
|
1242
|
-
idx_states, idx_tokens = Saikuro.analyze(files, state_formater, token_count_formater, output_dir)
|
1243
|
-
write_cyclo_index(idx_states, output_dir)
|
1244
|
-
write_token_index(idx_tokens, output_dir)
|
1245
1230
|
end
|
1231
|
+
|
1232
|
+
# :call-seq:
|
1233
|
+
# run(files, output_dir, formater)
|
1234
|
+
# Runs the Saikuro analyzer over the files, and persists the information
|
1235
|
+
# in output_dir
|
1236
|
+
#
|
1237
|
+
def run_with_standard_options(files, output_dir, formater = "html")
|
1238
|
+
run({:formater => formater, :output_directory => output_dir, :code_dirs => files})
|
1239
|
+
end
|
1240
|
+
|
1241
|
+
# :call-seq:
|
1242
|
+
# run(options)
|
1243
|
+
# Runs the Saikuro analyzer over a configuration hash, which takes those arguments:
|
1244
|
+
# - output_directory
|
1245
|
+
# Where the analysis will be written out
|
1246
|
+
# - filter_cyclo
|
1247
|
+
# - warn_cyclo
|
1248
|
+
# - error_cyclo
|
1249
|
+
#
|
1250
|
+
# - filter_token
|
1251
|
+
# - warn_token
|
1252
|
+
# - error_token
|
1253
|
+
#
|
1254
|
+
# - formater
|
1255
|
+
# text or html. By default html.
|
1256
|
+
#
|
1257
|
+
# - code_dirs
|
1258
|
+
# The directories containing code to look into.
|
1259
|
+
#
|
1260
|
+
def run_with_config(options)
|
1261
|
+
|
1262
|
+
rm_rf options[:output_directory]
|
1263
|
+
|
1264
|
+
state_filter = Filter.new(5)
|
1265
|
+
token_filter = Filter.new(10, 25, 50)
|
1266
|
+
|
1267
|
+
state_filter.limit = options[:filter_cyclo] if options[:filter_cyclo]
|
1268
|
+
state_filter.warn = options[:warn_cyclo] if options[:warn_cyclo]
|
1269
|
+
state_filter.error = options[:error_cyclo] if options[:error_cyclo]
|
1270
|
+
|
1271
|
+
token_filter.limit = options[:filter_token] if options[:filter_token]
|
1272
|
+
token_filter.warn = options[:warn_token] if options[:warn_token]
|
1273
|
+
token_filter.error = options[:error_token] if options[:error_token]
|
1274
|
+
|
1275
|
+
formater = options[:formater] || "html"
|
1276
|
+
if formater =~ /html/i
|
1277
|
+
state_formater = StateHTMLComplexityFormater.new(STDOUT,state_filter)
|
1278
|
+
token_count_formater = HTMLTokenCounterFormater.new(STDOUT,token_filter)
|
1279
|
+
else
|
1280
|
+
state_formater = ParseStateFormater.new(STDOUT,state_filter)
|
1281
|
+
token_count_formater = TokenCounterFormater.new(STDOUT,token_filter)
|
1282
|
+
end
|
1283
|
+
|
1284
|
+
idx_states, idx_tokens = Saikuro.analyze(
|
1285
|
+
files_in_dirs(options[:code_dirs]),
|
1286
|
+
state_formater,
|
1287
|
+
token_count_formater,
|
1288
|
+
options[:output_directory]
|
1289
|
+
)
|
1290
|
+
|
1291
|
+
write_cyclo_index(idx_states, options[:output_directory])
|
1292
|
+
write_token_index(idx_tokens, options[:output_directory])
|
1293
|
+
end
|
1294
|
+
|
1295
|
+
def files_in_dirs(code_dirs)
|
1296
|
+
code_dirs = [code_dirs].flatten
|
1297
|
+
code_dirs.collect {|dir| File.directory?(dir) ? Dir["#{dir}/**/*.rb"] : dir}.flatten
|
1298
|
+
end
|
1246
1299
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: atoulme-Saikuro
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 1.1.
|
9
|
+
- 2
|
10
|
+
version: 1.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Zev Blut, Antoine Toulme
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-07-
|
18
|
+
date: 2010-07-23 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -26,14 +26,14 @@ executables:
|
|
26
26
|
extensions: []
|
27
27
|
|
28
28
|
extra_rdoc_files:
|
29
|
-
- README
|
29
|
+
- README.rdoc
|
30
30
|
files:
|
31
31
|
- bin/saikuro
|
32
32
|
- lib/saikuro/usage.rb
|
33
33
|
- lib/saikuro.rb
|
34
34
|
- tests/large_example.rb
|
35
35
|
- tests/samples.rb
|
36
|
-
- README
|
36
|
+
- README.rdoc
|
37
37
|
has_rdoc: true
|
38
38
|
homepage: http://saikuro.rubyforge.org/
|
39
39
|
licenses: []
|