diff --git a/src/main/java/edu/hm/hafner/coverage/parser/CoberturaParser.java b/src/main/java/edu/hm/hafner/coverage/parser/CoberturaParser.java index 7f7e06f4..3885ff5e 100644 --- a/src/main/java/edu/hm/hafner/coverage/parser/CoberturaParser.java +++ b/src/main/java/edu/hm/hafner/coverage/parser/CoberturaParser.java @@ -41,6 +41,8 @@ public class CoberturaParser extends CoverageParser { private static final Pattern BRANCH_PATTERN = Pattern.compile(".*\\((?\\d+)/(?\\d+)\\)"); private static final PathUtil PATH_UTIL = new PathUtil(); + private static final String DETERMINISTIC_PATH_PREFIX = "/_/"; + private static final Coverage DEFAULT_BRANCH_COVERAGE = new CoverageBuilder(Metric.BRANCH).withCovered(2).withMissed(0).build(); private static final Coverage LINE_COVERED = new CoverageBuilder(Metric.LINE).withCovered(1).withMissed(0).build(); private static final Coverage LINE_MISSED = new CoverageBuilder(Metric.LINE).withCovered(0).withMissed(1).build(); @@ -141,7 +143,8 @@ else if (event.isEndElement()) { private FileNode createFileNode(final StartElement element, final PackageNode packageNode) { var fileName = getValueOf(element, FILE_NAME); - var path = getTreeStringBuilder().intern(PATH_UTIL.getRelativePath(fileName)); + var relativePath = StringUtils.removeStart(PATH_UTIL.getRelativePath(fileName), DETERMINISTIC_PATH_PREFIX); + var path = getTreeStringBuilder().intern(relativePath); return packageNode.findOrCreateFileNode(getFileName(fileName), path); } diff --git a/src/test/java/edu/hm/hafner/coverage/parser/CoberturaParserTest.java b/src/test/java/edu/hm/hafner/coverage/parser/CoberturaParserTest.java index fc795fa9..0a86a9ba 100644 --- a/src/test/java/edu/hm/hafner/coverage/parser/CoberturaParserTest.java +++ b/src/test/java/edu/hm/hafner/coverage/parser/CoberturaParserTest.java @@ -38,6 +38,24 @@ protected String getFolder() { return "cobertura"; } + @Test + @Issue("JENKINS-73635") + void shouldRemovePrefixOfDeterministicCoverageReport() { + var root = readReport("c#-cobertura.xml"); + + assertThat(root.getAllFileNodes()).hasSize(20).map(FileNode::getRelativePath) + .allSatisfy( + file -> assertThat(file) + .doesNotStartWith("/_/") + .startsWith("Lib.LicenseScanner/")); + + assertThat(root.getAllFileNodes()).hasSize(20) + .first().satisfies( + file -> assertThat(file) + .hasName("IssueKeys.cs") + .hasRelativePath("Lib.LicenseScanner/IssueKeys.cs")); + } + @Test @Issue("JENKINS-73325") void shouldUseFullPathWhenParsingFileNodes() { diff --git a/src/test/resources/edu/hm/hafner/coverage/parser/cobertura/c#-cobertura.xml b/src/test/resources/edu/hm/hafner/coverage/parser/cobertura/c#-cobertura.xml new file mode 100644 index 00000000..692816b2 --- /dev/null +++ b/src/test/resources/edu/hm/hafner/coverage/parser/cobertura/c#-cobertura.xml @@ -0,0 +1,1828 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file