Skip to content
Permalink
Browse files

Trying to fix [JENKINS-26722] with the solution described at http://s…

  • Loading branch information...
madmuffin1 committed Aug 20, 2015
1 parent 167fcea commit c05137bd582507b126c3b7d541e28f0444ddd7c5
@@ -6,3 +6,4 @@ target
*.ipr
*.iws
work
.idea/
@@ -69,21 +69,7 @@ public static ProjectCoverage parse(InputStream in) throws IOException {
if (in == null) {
throw new NullPointerException();
}
Digester digester = new Digester();
digester.setClassLoader(CloverCoverageParser.class.getClassLoader());
digester.addObjectCreate("coverage/project", ProjectCoverage.class);
digester.addSetProperties("coverage/project");
digester.addSetProperties("coverage/project/metrics");

digester.addObjectCreate("coverage/project/file", FileCoverage.class);
digester.addSetProperties("coverage/project/file");
digester.addSetProperties("coverage/project/file/metrics");
digester.addSetNext("coverage/project/file", "addFileCoverage", FileCoverage.class.getName());

digester.addObjectCreate("coverage/project/file/class", ClassCoverage.class);
digester.addSetProperties("coverage/project/file/class");
digester.addSetProperties("coverage/project/file/class/metrics");
digester.addSetNext("coverage/project/file/class", "addClassCoverage", ClassCoverage.class.getName());
Digester digester = buildDigester();

try {
ProjectCoverage coverage = (ProjectCoverage) digester.parse(in);
@@ -95,4 +81,31 @@ public static ProjectCoverage parse(InputStream in) throws IOException {
throw new IOException2("Cannot parse coverage results", e);
}
}

protected static Digester buildDigester() {
Digester digester = new Digester();
digester.setClassLoader(CloverCoverageParser.class.getClassLoader());

addDigester(digester, "coverage/project", ProjectCoverage.class);
addDigester(digester, "coverage/project/package", ProjectCoverage.class);
addDigester(digester, "coverage/project/file", FileCoverage.class, "addFileCoverage");
addDigester(digester, "coverage/project/package/file", FileCoverage.class, "addFileCoverage");
addDigester(digester, "coverage/project/file/class", ClassCoverage.class, "addClassCoverage");
addDigester(digester, "coverage/project/package/file/class", ClassCoverage.class, "addClassCoverage");

return digester;
}

private static void addDigester(Digester digester, String path, Class _class) {
addDigester(digester, path, _class, null);
}

private static void addDigester(Digester digester, String path, Class _class, String next) {
digester.addObjectCreate(path, _class);
digester.addSetProperties(path);
digester.addSetProperties(path + "/metrics");
if(next != null) {
digester.addSetNext(path, next, _class.getName());
}
}
}
@@ -120,4 +120,18 @@ public void testParse() throws Exception {
assertEquals(2, classResult.getCoveredelements());
}

@Test
public void testParseNamespaces() throws Exception {
// GIVEN an clover report with files inside namespaces

// WHEN parsing the file
ProjectCoverage result = CloverCoverageParser.parse(getClass().getResourceAsStream("clover-namespaces.xml"));

// it should produce a valid ProjectCoverage class with 6 files in it
assertNotNull(result);
assertEquals(ProjectCoverage.class, result.getClass());
assertEquals(6, result.getFiles());

}

}

0 comments on commit c05137b

Please sign in to comment.
You can’t perform that action at this time.