diff --git a/src/main/java/edu/hm/hafner/analysis/Report.java b/src/main/java/edu/hm/hafner/analysis/Report.java index 6f7a6581b..2241acfa5 100644 --- a/src/main/java/edu/hm/hafner/analysis/Report.java +++ b/src/main/java/edu/hm/hafner/analysis/Report.java @@ -1184,6 +1184,18 @@ public void setCounter(final String key, final int value) { countersByKey.put(Objects.requireNonNull(key), value); } + /** + * Sets a reference to the execution of the static analysis tool (build ID, timestamp, etc.). This property should + * not be set by parsers as it is overwritten by the {@link IssueDifference differencing engine} while computing new + * and fixed issues. + * + * @param reference + * the reference + */ + public void setReference(final String reference) { + elements.forEach(issue -> issue.setReference(reference)); + } + /** * Returns the specified custom counter of this report. * diff --git a/src/test/java/edu/hm/hafner/analysis/ReportTest.java b/src/test/java/edu/hm/hafner/analysis/ReportTest.java index 4580b5e33..2c3567847 100644 --- a/src/test/java/edu/hm/hafner/analysis/ReportTest.java +++ b/src/test/java/edu/hm/hafner/analysis/ReportTest.java @@ -904,7 +904,7 @@ void shouldCreateReportWithOptions() { } @Test - void shouldSetOrigin() { + void shouldSetOriginAndReference() { try (IssueBuilder builder = new IssueBuilder()) { Report report = new Report(); Issue checkstyleWarning = builder.setFileName("A.java") @@ -920,6 +920,11 @@ void shouldSetOrigin() { assertThat(checkstyleWarning).hasOrigin("origin"); assertThat(checkstyleWarning).hasOriginName("Name"); + assertThat(checkstyleWarning).hasReference(""); + + var reference = "reference"; + report.setReference(reference); + assertThat(checkstyleWarning).hasReference(reference); } }