Skip to content

Commit

Permalink
Merge pull request #147 from jenkinsci/deterministic-JENKINS-73635
Browse files Browse the repository at this point in the history
[JENKINS-73635] Add support for deterministic Cobertura reports
  • Loading branch information
uhafner authored Jan 15, 2025
2 parents 4343610 + 935ac1f commit c703c3b
Show file tree
Hide file tree
Showing 3 changed files with 1,850 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public class CoberturaParser extends CoverageParser {
private static final Pattern BRANCH_PATTERN = Pattern.compile(".*\\((?<covered>\\d+)/(?<total>\\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();
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Loading

0 comments on commit c703c3b

Please sign in to comment.