Skip to content

Commit

Permalink
Merge pull request #1009 from jenkinsci/set-reference
Browse files Browse the repository at this point in the history
Add a setter for the reference
  • Loading branch information
uhafner authored Jan 24, 2024
2 parents ede03ac + 71e62fd commit eda93a7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/main/java/edu/hm/hafner/analysis/Report.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
7 changes: 6 additions & 1 deletion src/test/java/edu/hm/hafner/analysis/ReportTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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);
}
}

Expand Down

0 comments on commit eda93a7

Please sign in to comment.