Skip to content

Commit

Permalink
Fixes bug with NPE when coverage report have multiple source folders …
Browse files Browse the repository at this point in the history
…(even wrong ones)
  • Loading branch information
bric3 committed Oct 25, 2013
1 parent c87265a commit 899ba2a
Show file tree
Hide file tree
Showing 3 changed files with 475 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class SourceReportFactory {

public static List<SourceReport> createFromCoberturaXML(File file) {
Node coverage = new XmlParser().parse(file)
String sourceDir = coverage.sources.source.text() + '/'
List<String> sourceDirectories = coverage.sources.source*.text()

Map a = [:]

Expand All @@ -19,8 +19,8 @@ class SourceReportFactory {

List<SourceReport> reports = new ArrayList<SourceReport>()

a.each { String filename, Map cov ->
String source = new File(sourceDir + filename).text
a.each { String filename, Map<Integer, Integer> cov ->
String source = actualSourceFile(sourceDirectories, filename).text

List r = [null] * source.readLines().size()
cov.each { Integer line, Integer hits ->
Expand All @@ -33,4 +33,8 @@ class SourceReportFactory {
return reports

}

private static File actualSourceFile(List<String> sourceDirs, String filename) {
sourceDirs.collect { new File(it + '/' + filename) }.find { it.exists() }
}
}
Loading

0 comments on commit 899ba2a

Please sign in to comment.