Skip to content

Commit

Permalink
Merge pull request #1 from bric3/fixes_multiple_source_element
Browse files Browse the repository at this point in the history
Fixes NPE when coverage.xml has multiple <source> element
  • Loading branch information
kt3k committed Oct 26, 2013
2 parents 5bd222c + 899ba2a commit a242d6d
Show file tree
Hide file tree
Showing 4 changed files with 476 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ build

# gradle local dir
.gradle
.gradletasknamecache

# eclipse files
.settings
Expand Down
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 a242d6d

Please sign in to comment.