Skip to content

Commit

Permalink
Updating version number, more robust testing, spelling errors in read…
Browse files Browse the repository at this point in the history
…me, dates on copyrighting
  • Loading branch information
dingusj1 committed Jan 20, 2012
1 parent c370e29 commit 93ebb72
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 19 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2011 Guy Royse & Alyssa Diaz
Copyright (c) 2012 Guy Royse & Alyssa Diaz

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ The CSV content that BVM generates consists of the following format:

The size metric is self-explanitory. It's the size of the box to be generated. By default is it set to ncloc and this is probably what you will always want. I can be changed using the --size switch and specifing a different Sonar metric.

The color metric defaults to coverage. You will probably want this to be several differnt values, depending on the charts you want to generate. It can be sepcified using the --color switch.
The color metric defaults to coverage. You will probably want this to be several different values, depending on the charts you want to generate. It can be specified using the --color switch.

Microsoft Treemapper expects that negative numbers are red and positive numbers are green but our metrics aren't quite so compliant. The --invert-color swtich will mulitply the specified color metric by -1 to accomodate the charts you are trying to create. Furthermore, the --color-adjust switch can be given a number that will be added to the specified metric before being outputed. This allows us to set threshholds of tolerance for our charts.
Microsoft Treemapper expects that negative numbers are red and positive numbers are green but our metrics aren't quite so compliant. The --invert-color switch will multiply the specified color metric by -1 to accomodate the charts you are trying to create. Furthermore, the --color-adjust switch can be given a number that will be added to the specified metric before being outputed. This allows us to set threshholds of tolerance for our charts.

The JAR name is really just the project name. If you have multiple JARs in your project (and who doesn't) then the --jar switch will allow you to group them all into one file and generate one enourmous view of your entire codebase. It defaults to "jar" and you probably always want to override it.
The JAR name is really just the project name. If you have multiple JARs in your project (and who doesn't) then the --jar switch will allow you to group them all into one file and generate one enormous view of your entire codebase. It defaults to "jar" and you probably always want to override it.

If your command line savy you probably noticed that BVM does not actually operate on files. It reads STDIN and writes STDOUT.
If you are command line savvy you probably noticed that BVM does not actually operate on files. It reads STDIN and writes STDOUT.

Copyright
---------

Copyright (c) 2011 Guy Royse & Alyssa Diaz. See LICENSE for further details.
Copyright (c) 2012 Guy Royse & Alyssa Diaz & Jacob Dingus. See LICENSE for further details.
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ task :build do
end

task :install do
sh "gem install bvm-0.3.2.gem"
sh "gem install bvm-0.3.3.gem"
end

task :uninstall do
sh "gem uninstall bvm"
end

task :push do
sh "gem push bvm-0.3.2.gem"
sh "gem push bvm-0.3.3.gem"
end
6 changes: 3 additions & 3 deletions bvm.gemspec
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
Gem::Specification.new do |s|

s.name = "bvm"
s.version = '0.3.2'
s.version = '0.3.3'
s.platform = Gem::Platform::RUBY
s.authors = ['Guy Royse', 'Alyssa Diaz']
s.authors = ['Guy Royse', 'Alyssa Diaz', 'Jacob Dingus']
s.email = ['guy@guyroyse.com']
s.homepage = "http://github.com/guyroyse/big-visible-metrics"
s.license = "MIT"
s.summary = "Generates CSV files from SONAR metrics"
s.description = "Generates CSV files that can be consumed by Microsoft Treemapper from the Sonar API. Reads stin and stdout."
s.description = "Generates CSV files that can be consumed by Microsoft Treemapper from the Sonar API. Reads stdin and stdout."

s.required_rubygems_version = ">=1.3.6"

Expand Down
24 changes: 16 additions & 8 deletions lib/bvm/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ def initialize
def convert(input)
output = ""
metrics = parse_xml input
metrics[:resource].each do |resource|
output << build_output(resource, @jar, @size_metric, @color_metric, @color_adjustment)
unless metrics[:resource].nil?
metrics[:resource].each do |resource|
output << build_output(resource, @jar, @size_metric, @color_metric, @color_adjustment)
end
end
output
end
Expand All @@ -29,13 +31,19 @@ def parse_xml(input)
end

def build_output(resource, jar, size, color, adjust)
name = resource[:name][0]
size_metric = find_metric resource[:msr], size
color_metric = find_metric resource[:msr], color
color_metric *= -1 unless not @invert_color_metric
color_metric += adjust
package = parse_package resource[:key][0]
%Q/#{size_metric},#{color_metric},"#{jar}","#{package}","#{name}"\n/
name = resource[:name][0]

unless resource[:msr].nil?
size_metric = find_metric resource[:msr], size
color_metric = find_metric resource[:msr], color
color_metric *= -1 unless not @invert_color_metric
color_metric += adjust
%Q/#{size_metric},#{color_metric},"#{jar}","#{package}","#{name}"\n/
else
%Q/1,#{adjust},"NotFound","#{package}","#{name}"\n/
end

end

def find_metric(metrics, key)
Expand Down
68 changes: 68 additions & 0 deletions spec/multipleNodes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
require 'bvm'

describe "BVM" do

describe Converter do

before(:each) do
@input = File.read('spec/multiple.xml')
@converter = Converter.new
end

it "converts XML to CSV for given metrics" do
output = @converter.convert @input
output.should == %Q/100.0,0.8,\"jar\",\"package\",\"Class\"\n200.0,0.6,\"jar\",\"other.package\",\"OtherClass\"\n300.0,0.2,\"jar\",\"other.package\",\"ThirdClass\"\n/
end

it "changes the jar in the output when specified" do
@converter.jar = 'foo'
output = @converter.convert @input
output.should == %Q/100.0,0.8,\"foo\",\"package\",\"Class\"\n200.0,0.6,\"foo\",\"other.package\",\"OtherClass\"\n300.0,0.2,\"foo\",\"other.package\",\"ThirdClass\"\n/
end

it "changes the size metric in the output when specified" do
@converter.size_metric = 'coverage'
output = @converter.convert @input
output.should == %Q/0.8,0.8,\"jar\",\"package\",\"Class\"\n0.6,0.6,\"jar\",\"other.package\",\"OtherClass\"\n0.2,0.2,\"jar\",\"other.package\",\"ThirdClass\"\n/
end

it "changes the color metric in the output when specified" do
@converter.color_metric = 'ncloc'
output = @converter.convert @input
output.should == %Q/100.0,100.0,\"jar\",\"package\",\"Class\"\n200.0,200.0,\"jar\",\"other.package\",\"OtherClass\"\n300.0,300.0,\"jar\",\"other.package\",\"ThirdClass\"\n/
end

it "adjusts the color metric based on color adjustment" do
@converter.color_adjustment = -2.0
output = @converter.convert @input
output.should == %Q/100.0,-1.2,"jar","package","Class"\n200.0,-1.4,"jar","other.package","OtherClass"\n300.0,-1.8,"jar","other.package","ThirdClass"\n/
end

it 'inverts and adjusts by inverting first' do
@converter.color_adjustment = 2.0
@converter.invert_color_metric = true;
output = @converter.convert @input
output.should == %Q/100.0,1.2,"jar","package","Class"\n200.0,1.4,"jar","other.package","OtherClass"\n300.0,1.8,"jar","other.package","ThirdClass"\n/
end

it "inverts the color metric" do
@converter.invert_color_metric = true;
output = @converter.convert @input
output.should == %Q/100.0,-0.8,"jar","package","Class"\n200.0,-0.6,"jar","other.package","OtherClass"\n300.0,-0.2,"jar","other.package","ThirdClass"\n/
end

it 'returns 0 for not found metrics' do
@converter.size_metric = 'foo'
@converter.color_metric = 'bar'
output = @converter.convert @input
output.should == %Q/0.0,0.0,"jar","package","Class"\n0.0,0.0,"jar","other.package","OtherClass"\n0.0,0.0,"jar","other.package","ThirdClass"\n/
end

it 'converts input with multiple lines' do
output = @converter.convert @input
output.should == %Q/100.0,0.8,"jar","package","Class"\n200.0,0.6,"jar","other.package","OtherClass"\n300.0,0.2,"jar","other.package","ThirdClass"\n/
end

end

end
71 changes: 71 additions & 0 deletions spec/singleNode.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
require 'bvm'

describe "BVM" do

describe Converter do

before(:each) do
@input = File.read('spec/single.xml')
@converter = Converter.new
end

it "defaults parameters correctly" do
@converter.jar.should == 'jar'
@converter.size_metric.should == 'ncloc'
@converter.color_metric.should == 'coverage'
@converter.color_adjustment.should == 0.0
@converter.invert_color_metric.should == false
end

it "converts XML to CSV for given metrics" do
output = @converter.convert @input
output.should == %Q/100.0,0.8,"jar","package","Class"\n/
end

it "changes the jar in the output when specified" do
@converter.jar = 'foo'
output = @converter.convert @input
output.should == %Q/100.0,0.8,"foo","package","Class"\n/
end

it "changes the size metric in the output when specified" do
@converter.size_metric = 'coverage'
output = @converter.convert @input
output.should == %Q/0.8,0.8,"jar","package","Class"\n/
end

it "changes the color metric in the output when specified" do
@converter.color_metric = 'ncloc'
output = @converter.convert @input
output.should == %Q/100.0,100.0,"jar","package","Class"\n/
end

it "adjusts the color metric based on color adjustment" do
@converter.color_adjustment = -0.8
output = @converter.convert @input
output.should == %Q/100.0,0.0,"jar","package","Class"\n/
end

it "inverts the color metric" do
@converter.invert_color_metric = true;
output = @converter.convert @input
output.should == %Q/100.0,-0.8,"jar","package","Class"\n/
end

it 'inverts and adjusts by inverting first' do
@converter.color_adjustment = 0.4
@converter.invert_color_metric = true;
output = @converter.convert @input
output.should == %Q/100.0,-0.4,"jar","package","Class"\n/
end

it 'returns 0 for not found metrics' do
@converter.size_metric = 'foo'
@converter.color_metric = 'bar'
output = @converter.convert @input
output.should == %Q/0.0,0.0,"jar","package","Class"\n/
end

end

end

0 comments on commit 93ebb72

Please sign in to comment.