Skip to content

Commit

Permalink
Add a pie chart that shows the issues in modified code.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Jan 26, 2024
1 parent 9320d92 commit a30f12e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ public PieChartModel create(final Report issues) {
PieChartModel model = new PieChartModel(Messages.NewVersusFixed_Name());

var totals = issues.size();
model.add(new PieData(Messages.Modified_Code_Warnings_Short(), totals), JenkinsPalette.RED.normal());
model.add(new PieData(Messages.Unchanged_Code_Warnings_Short(), totals), JenkinsPalette.YELLOW.normal());
var modified = issues.getInModifiedCode().size();
model.add(new PieData(Messages.Modified_Code_Warnings_Short(), modified), JenkinsPalette.RED.normal());
model.add(new PieData(Messages.Unchanged_Code_Warnings_Short(), totals - modified), JenkinsPalette.YELLOW.normal());

return model;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private Marker asMarker(final Issue issue, final String description, final Strin
.withColumnEnd(issue.getColumnEnd()).build();
}

@SuppressWarnings({"checkstyle:ParameterNumber", "PMD.CyclomaticComplexity"})
@SuppressWarnings({"checkstyle:ParameterNumber", "PMD.CyclomaticComplexity", "PMD.NPathComplexity"})
@SuppressFBWarnings("IMPROPER_UNICODE")
private Object createNewDetailView(final String link, final Run<?, ?> owner, final AnalysisResult result,
final Report allIssues, final Report newIssues, final Report outstandingIssues, final Report fixedIssues,
Expand All @@ -167,6 +167,11 @@ private Object createNewDetailView(final String link, final Run<?, ?> owner, fin
filterModified(outstandingIssues), EMPTY,
Messages.Modified_Warnings_Header(), url, labelProvider, sourceEncoding);
}
if ("unchanged".equalsIgnoreCase(link)) {
return new IssuesDetail(owner, result, filterUnchanged(allIssues), filterUnchanged(newIssues),
filterUnchanged(outstandingIssues), EMPTY,
Messages.Modified_Warnings_Header(), url, labelProvider, sourceEncoding);
}
if ("fixed".equalsIgnoreCase(link)) {
return new FixedWarningsDetail(owner, result, fixedIssues, url, labelProvider, sourceEncoding);
}
Expand Down Expand Up @@ -200,6 +205,10 @@ private Report filterModified(final Report report) {
return report.filter(Issue::isPartOfModifiedCode);
}

private Report filterUnchanged(final Report report) {
return report.filter(Predicate.not(Issue::isPartOfModifiedCode));
}

private Predicate<Issue> createPropertyFilter(final String plainLink, final String property) {
return issue -> plainLink.equals(String.valueOf(
Issue.getPropertyValueAsString(issue, property).hashCode()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,15 @@ private AnalysisHistory createHistory() {
return new AnalysisHistory(owner, new ByIdResultSelector(result.getId()));
}

/**
* Returns whether there are any issues in the associated static analysis run that are part of modified code.
*
* @return {@code true} if there are issues in modified code, {@code false} otherwise
*/
public boolean hasIssuesInModifiedCode() {
return result.getTotals().getTotalModifiedSize() > 0;
}

/**
* Returns all issues of the associated static analysis run.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
<div class="carousel-item" data-bs-interval="false">
<c:pie-chart id="trend" model="${it.trendModel}" height="256" enableLinks="true"/>
</div>
<j:if test="${it.hasIssuesInModifiedCode()}">
<div class="carousel-item" data-bs-interval="false">
<c:pie-chart id="modified" model="${it.modifiedModel}" height="256" enableLinks="true"/>
</div>
</j:if>
</bs:carousel>
</bs:card>

Expand Down

0 comments on commit a30f12e

Please sign in to comment.