Skip to content

Commit

Permalink
Store original parser ID and reuse this ID when evaluating the icon.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Jan 1, 2025
1 parent cd9dfae commit 70fbc35
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ public class DeltaReport {
public DeltaReport(final Report report, final int currentBuildNumber) {
allIssues = report;
outstandingIssues = report;
referenceIssues = EMPTY_REPORT;
newIssues = EMPTY_REPORT;
fixedIssues = EMPTY_REPORT;

var empty = report.copyEmptyInstance();
referenceIssues = empty;
newIssues = empty;
fixedIssues = empty;

referenceBuildId = StringUtils.EMPTY;

report.logInfo("No valid reference build found");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,6 @@ public class IconLabelProvider extends StaticAnalysisLabelProvider {
private final String smallIconUrl;
private final String largeIconUrl;

/**
* Creates a new label provider with the specified ID and name.
*
* @param id
* the ID (i.e., URL)
* @param name
* the name of the tool
*/
public IconLabelProvider(final String id, final String name) {
this(id, name, EMPTY_DESCRIPTION, id);
}

/**
* Creates a new label provider with the specified ID and name.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public StaticAnalysisLabelProvider create(final String id) {
* @param name
* the name of the tool (might be empty or null)
*
* @return The label provider of the selected static analysis tool. If the tool is not found then a default label
* @return The label provider of the selected static analysis tool. If the tool is not found, then a default label
* provider is returned.
*/
public StaticAnalysisLabelProvider create(final String id, @CheckForNull final String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@ public abstract class ReportScanningTool extends Tool {

private String pattern = StringUtils.EMPTY;
private String reportEncoding = StringUtils.EMPTY;
// Use negative case to allow defaulting to false and defaulting to existing behaviour.
private boolean skipSymbolicLinks = false;

/**
* Sets the Ant file-set pattern of files to work with. If the pattern is undefined then the console log is
* Sets the Ant file-set pattern of files to work with. If the pattern is undefined, then the console log is
* scanned.
*
* @param pattern
Expand Down Expand Up @@ -95,7 +94,7 @@ public ReportScanningToolDescriptor getDescriptor() {
public abstract IssueParser createParser();

/**
* Specify if file scanning skip traversal of symbolic links.
* Specify if the file scanning step should skip the traversal of symbolic links.
*
* @param skipSymbolicLinks
* if symbolic links should be skipped during directory scanning.
Expand Down Expand Up @@ -180,6 +179,7 @@ private Report scanInWorkspace(final FilePath workspace, final String expandedPa

List<Report> results = report.getResults();
Report aggregation;
// FIXME: properties are not set in the aggregation
if (results.isEmpty()) {
aggregation = new Report();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,15 @@ public String toString() {
* @return the label provider for this tool
*/
public StaticAnalysisLabelProvider getLabelProvider() {
return new LabelProviderFactory().create(id, name);
return new LabelProviderFactory().create(getParserId(), name);
}

private String getParserId() {
var originalReport = getResult().getIssues();
if (originalReport.hasParserId()) {
return originalReport.getParserId();
}
return id;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,12 @@ public StaticAnalysisLabelProvider(final String id, @CheckForNull final String n
}

private String getIcon(final IssueType type) {
switch (type) {
case BUG:
return "symbol-solid/bug plugin-font-awesome-api";
case DUPLICATION:
return "symbol-regular/clone plugin-font-awesome-api";
case VULNERABILITY:
return "symbol-solid/shield-halved plugin-font-awesome-api";
default:
return ANALYSIS_SVG_ICON;
}
return switch (type) {
case BUG -> "symbol-solid/bug plugin-font-awesome-api";
case DUPLICATION -> "symbol-regular/clone plugin-font-awesome-api";
case VULNERABILITY -> "symbol-solid/shield-halved plugin-font-awesome-api";
default -> ANALYSIS_SVG_ICON;
};
}

private void changeName(final String originalName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,6 @@ public class SvgIconLabelProvider extends StaticAnalysisLabelProvider {
private static final String SVG_SUFFIX = ".svg";
private final String iconUrl;

/**
* Creates a new label provider with the specified ID and name.
*
* @param id
* the ID (i.e., URL)
* @param name
* the name of the tool
*/
public SvgIconLabelProvider(final String id, final String name) {
this(id, name, EMPTY_DESCRIPTION, id);
}

/**
* Creates a new label provider with the specified ID and name.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
import io.jenkins.plugins.forensics.miner.RepositoryStatistics;

/**
* A report of issues and the associated blame information, i.e. author and commit information of the SCM.
* A report of issues and the associated blame information, i.e., author and commit information of the SCM.
*
* @author Ullrich Hafner
*/
public class AnnotatedReport implements Serializable {
private static final long serialVersionUID = -4797152016409014028L;

private final String id;
private final Report aggregatedReport = new Report();
private Report aggregatedReport = new Report();
private final Blames aggregatedBlames = new Blames();
private final RepositoryStatistics aggregatedRepositoryStatistics = new RepositoryStatistics();

Expand All @@ -44,14 +44,14 @@ public AnnotatedReport(final String id) {
}

/**
* Creates a new instance of {@link AnnotatedReport}. The blames will be initialized empty.
* Creates a new instance of {@link AnnotatedReport}. The SCM blames will be initialized empty.
*
* @param id
* the ID of the report
* @param report
* report with issues
*/
public AnnotatedReport(@CheckForNull final String id, final Report report) {
public AnnotatedReport(final String id, final Report report) {
this(id, report, new Blames(), new RepositoryStatistics());
}

Expand All @@ -65,7 +65,7 @@ public AnnotatedReport(@CheckForNull final String id, final Report report) {
* @param blames
* author and commit information for affected files
*/
public AnnotatedReport(@CheckForNull final String id, final Report report, final Blames blames) {
public AnnotatedReport(final String id, final Report report, final Blames blames) {
this(id, report, blames, new RepositoryStatistics());
}

Expand All @@ -81,11 +81,13 @@ public AnnotatedReport(@CheckForNull final String id, final Report report, final
* @param statistics
* repository statistics for affected files
*/
public AnnotatedReport(@CheckForNull final String id, final Report report, final Blames blames,
public AnnotatedReport(final String id, final Report report, final Blames blames,
final RepositoryStatistics statistics) {
this(id);

addReport(id, report, blames, statistics);
aggregatedReport = report;

addBlames(id, blames, statistics, report.size());
}

/**
Expand All @@ -99,6 +101,7 @@ public AnnotatedReport(@CheckForNull final String id, final Report report, final
public AnnotatedReport(@CheckForNull final String id, final List<AnnotatedReport> reports) {
this(id);

aggregatedReport = new Report();
addAllReports(reports);
}

Expand All @@ -113,6 +116,7 @@ public AnnotatedReport(@CheckForNull final String id, final List<AnnotatedReport
public AnnotatedReport(@CheckForNull final String id, final Iterable<AnnotatedReport> reports) {
this(id);

aggregatedReport = new Report();
addAllReports(reports);
}

Expand Down Expand Up @@ -248,7 +252,12 @@ public void add(final AnnotatedReport other) {
private void addReport(final String actualId, final Report report, final Blames blames,
final RepositoryStatistics statistics) {
aggregatedReport.addAll(report);
sizeOfOrigin.merge(actualId, report.size(), Integer::sum);
addBlames(actualId, blames, statistics, report.size());
}

private void addBlames(final String actualId, final Blames blames,
final RepositoryStatistics statistics, final int size) {
sizeOfOrigin.merge(actualId, size, Integer::sum);
aggregatedBlames.addAll(blames);
aggregatedRepositoryStatistics.addAll(statistics);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ public void setLowTags(final String lowTags) {
}

/**
* Returns whether case should be ignored during the scanning.
* Returns whether the case of the characters should be ignored during the scanning.
*
* @return {@code true} if case should be ignored during the scanning
* @return {@code true} if the case should be ignored during the scanning
*/
@SuppressWarnings("PMD.BooleanGetMethodName")
public boolean getIgnoreCase() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ void shouldCreateSvgProvider() {
.hasName(NAME)
.hasSmallIconUrl(DEFAULT_SVG)
.hasLargeIconUrl(DEFAULT_SVG);
assertThat(new SvgIconLabelProvider(ID, NAME))
.hasName(NAME)
.hasSmallIconUrl(DEFAULT_SVG)
.hasLargeIconUrl(DEFAULT_SVG);
}

@Test
Expand All @@ -53,9 +49,5 @@ void shouldCreateIconProvider() {
.hasName(NAME)
.hasSmallIconUrl(PATH + ID + "-24x24.png")
.hasLargeIconUrl(PATH + ID + "-48x48.png");
assertThat(new IconLabelProvider(ID, NAME))
.hasName(NAME)
.hasSmallIconUrl(PATH + ID + "-24x24.png")
.hasLargeIconUrl(PATH + ID + "-48x48.png");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ protected IssuesRecorder enableGenericWarnings(final AbstractProject<?, ?> job,
* @param job
* the job to register the recorder for
* @param tool
* the tool tool to use
* the tool to use
* @param additionalTools
* the tool configurations to use
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,37 @@ void shouldCreateResultWithDifferentNameAndId() {
assertThat(action.getDisplayName()).startsWith(name);
}

/**
* Runs the CheckStyle parser and changes name and ID and icon.
*/
@Test
@org.junitpioneer.jupiter.Issue("JENKINS-73636, JENKINS-72777")
void shouldCreateResultWithCorrectIcon() {
var checkstyleImage = "checkstyle.svg";

FreeStyleProject project = createFreestyleJob("checkstyle.xml");
ReportScanningTool configuration = configurePattern(new CheckStyle());
enableGenericWarnings(project, configuration);

ResultAction checkstyle = getResultAction(buildWithResult(project, Result.SUCCESS));
assertThat(checkstyle.getId()).isEqualTo("checkstyle");
assertThat(checkstyle.getDisplayName()).startsWith("CheckStyle");
assertThat(checkstyle.getIconFileName()).endsWith(checkstyleImage);

project.getPublishersList().clear();

String changedId = "new-id";
configuration.setId(changedId);
String changedName = "new-name";
configuration.setName(changedName);
enableGenericWarnings(project, configuration);

ResultAction changedProperties = getResultAction(buildWithResult(project, Result.SUCCESS));
assertThat(changedProperties.getId()).isEqualTo(changedId);
assertThat(changedProperties.getDisplayName()).startsWith(changedName);
assertThat(checkstyle.getIconFileName()).endsWith(checkstyleImage);
}

/**
* Runs the CheckStyle parser without specifying a pattern: the default pattern should be used.
*/
Expand Down

0 comments on commit 70fbc35

Please sign in to comment.