Skip to content

Commit

Permalink
[FIXED JENKINS-16252] filename in xml should be relative
Browse files Browse the repository at this point in the history
  • Loading branch information
ssogabe committed Apr 26, 2013
1 parent 73f8a41 commit a024c98
Show file tree
Hide file tree
Showing 3 changed files with 424 additions and 2 deletions.
Expand Up @@ -173,7 +173,12 @@ public void startElement(String uri, String localName, String qName, Attributes
} else if ("class".equals(qName)) {
assert rootCoverage.getElement() == CoverageElement.JAVA_PACKAGE;
// cobertura combines file and class
final String filename = attributes.getValue("filename").replace('\\', '/');
String filename = attributes.getValue("filename").replace('\\', '/');
// filename should be a relative path.
// See https://issues.jenkins-ci.org/browse/JENKINS-16252
if (filename.startsWith("\\") || filename.startsWith("/")) {
filename = filename.substring(1);
}
String relativeFilename = filename;

final String packageName = rootCoverage.getName();
Expand Down Expand Up @@ -307,7 +312,7 @@ public void endElement(String uri, String localName, String qName) throws SAXExc
} else if ("source".equals(qName)) {
if (inSources && inSource) {
sourcePaths.add(sourceDir.toString().trim());
}
}
inSource = false;
} else if ("coverage".equals(qName)) {
} else if ("package".equals(qName)) {
Expand Down
Expand Up @@ -10,6 +10,9 @@
import java.util.Map;
import java.util.Set;
import java.util.HashSet;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import org.jvnet.hudson.test.Bug;
import org.netbeans.insane.scanner.CountingVisitor;
import org.netbeans.insane.scanner.ScannerUtils;

Expand Down Expand Up @@ -91,6 +94,26 @@ public void testParse2() throws Exception {
assertEquals(Ratio.create(4, 4), subResult.getCoverage(CoverageMetric.METHOD));
}

@Bug(16252)
public void testParse_NotRelativeSourcePath() throws Exception {
Set<String> paths = new HashSet<String>();
CoverageResult result = CoberturaCoverageParser.parse(getClass().getResourceAsStream("coverage_16252.xml"), null, paths);
result.setOwner(null);
print(result, 0);
assertNotNull(result);
assertEquals(CoverageResult.class, result.getClass());
assertEquals(Messages.CoberturaCoverageParser_name(), result.getName());

assertEquals(4, result.getChildren().size());
CoverageResult subResult = result.getChild("Common");
assertEquals("Common", subResult.getName());

CoverageResult sub2Result = subResult.getChild("CommonLibrary/ProfilerTest.cpp");
assertNotNull(sub2Result);
assertEquals("CommonLibrary/ProfilerTest.cpp", sub2Result.getRelativeSourcePath());

}

public void testParseMultiPackage() throws Exception {
// ProjectCoverage result = CoberturaCoverageParser.parse(getClass().getResourceAsStream("coverage-two-packages.xml"));
// result = CoberturaCoverageParser.trimPaths(result, "C:\\local\\maven\\helpers\\hudson\\cobertura\\");
Expand Down

0 comments on commit a024c98

Please sign in to comment.