lib/jacoco/plugin.rb in danger-jacoco-0.0.2 vs lib/jacoco/plugin.rb in danger-jacoco-0.0.3
- old
+ new
@@ -30,24 +30,28 @@
# that is your path to java source files is something like
#
# blah/blah/java/slashed_package/Source.java
#
def report(path, delimiter = '/java/')
- classes = @dangerfile.git
- .modified_files
- .select { |file| file.end_with? '.java' }
- .map { |file| extract_class(file, delimiter) }
+ classes = classes(delimiter)
parser = Jacoco::SAXParser.new(classes)
Nokogiri::XML::SAX::Parser.new(parser).parse(File.open(path))
parser.classes.each do |jacoco_class|
# Check which metrics are available
report_class(jacoco_class)
end
end
+ def classes(delimiter)
+ git = @dangerfile.git
+ affected_files = git.modified_files + git.added_files
+ affected_files.select { |file| file.end_with? '.java' }
+ .map { |file| extract_class(file, delimiter) }
+ end
+
def report_class(jacoco_class)
counters = jacoco_class.counters
branch_counter = counters.detect { |e| e.type.eql? 'BRANCH' }
line_counter = counters.detect { |e| e.type.eql? 'LINE' }
counter = branch_counter.nil? ? line_counter : branch_counter
@@ -60,11 +64,11 @@
missed = counter.missed
coverage = (covered.fdiv(covered + missed) * 100).floor
return unless coverage < minimum_coverage_percentage
- fail "#{jacoco_class.name} has coverage of #{coverage}%. " \
- "Improve this to at least #{minimum_coverage_percentage}%"
+ fail("#{jacoco_class.name} has coverage of #{coverage}%. " \
+ "Improve this to at least #{minimum_coverage_percentage}%")
end
def extract_class(file, java_path_delimiter)
file[0, file.length - 5].split(java_path_delimiter)[1]
end