Skip to content

Commit

Permalink
Use the parser category to assign different action icons.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Oct 5, 2024
1 parent d1350aa commit dab14c5
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 20 deletions.
6 changes: 3 additions & 3 deletions plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<scm>
<connection>scm:git:https://github.com/jenkinsci/${project.artifactId}-plugin.git</connection>
<developerConnection>scm:git:git@github.com:jenkinsci/${project.artifactId}-plugin.git</developerConnection>
<tag>v11.3.0</tag>
<tag>${scmTag}</tag>
<url>https://github.com/jenkinsci/${project.artifactId}-plugin</url>
</scm>

Expand All @@ -47,8 +47,8 @@
<changelist>-SNAPSHOT</changelist>
<module.name>${project.groupId}.warnings.ng</module.name>

<analysis-model-api.version>12.7.0</analysis-model-api.version>
<analysis-model-tests.version>12.5.0</analysis-model-tests.version>
<analysis-model-api.version>12.9.0</analysis-model-api.version>
<analysis-model-tests.version>${analysis-model-api.version}</analysis-model-tests.version>
<pull-request-monitoring.version>335.v525cd64ec76b_</pull-request-monitoring.version>

<eclipse-collections.version>9.2.0</eclipse-collections.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import edu.hm.hafner.analysis.Issue;
import edu.hm.hafner.analysis.Report;
import edu.hm.hafner.analysis.registry.ParserDescriptor;
import edu.hm.hafner.analysis.registry.ParserDescriptor.Type;
import edu.hm.hafner.util.Generated;
import edu.hm.hafner.util.VisibleForTesting;
import edu.umd.cs.findbugs.annotations.CheckForNull;
Expand All @@ -33,6 +35,7 @@ public class StaticAnalysisLabelProvider implements DescriptionProvider {
protected static final DescriptionProvider EMPTY_DESCRIPTION = Issue::getDescription;

private final String id;
private final String icon;
@CheckForNull
private String name;
private final DescriptionProvider descriptionProvider;
Expand Down Expand Up @@ -72,14 +75,45 @@ public StaticAnalysisLabelProvider(final String id, @CheckForNull final String n
*/
public StaticAnalysisLabelProvider(final String id, @CheckForNull final String name,
final DescriptionProvider descriptionProvider) {
this(id, name, descriptionProvider, Type.WARNING);
}

/**
* Creates a new {@link StaticAnalysisLabelProvider} with the specified ID.
*
* @param id
* the ID
* @param name
* the name of the static analysis tool
* @param descriptionProvider
* provides additional descriptions for an issue
* @param type
* the type of the parser
*/
public StaticAnalysisLabelProvider(final String id, @CheckForNull final String name,
final DescriptionProvider descriptionProvider, final ParserDescriptor.Type type) {
this.id = id;
this.descriptionProvider = descriptionProvider;
this.icon = getIcon(type);

changeName(name);
}

private String getIcon(final ParserDescriptor.Type type) {
switch (type) {
case BUG:
return "symbol-solid/bug plugin-font-awesome-api";

Check warning on line 105 in plugin/src/main/java/io/jenkins/plugins/analysis/core/model/StaticAnalysisLabelProvider.java

View check run for this annotation

Codecov / codecov/patch

plugin/src/main/java/io/jenkins/plugins/analysis/core/model/StaticAnalysisLabelProvider.java#L105

Added line #L105 was not covered by tests
case DUPLICATION:
return "symbol-regular/clone plugin-font-awesome-api";

Check warning on line 107 in plugin/src/main/java/io/jenkins/plugins/analysis/core/model/StaticAnalysisLabelProvider.java

View check run for this annotation

Codecov / codecov/patch

plugin/src/main/java/io/jenkins/plugins/analysis/core/model/StaticAnalysisLabelProvider.java#L107

Added line #L107 was not covered by tests
case VULNERABILITY:
return "symbol-solid/shield-halved plugin-font-awesome-api";

Check warning on line 109 in plugin/src/main/java/io/jenkins/plugins/analysis/core/model/StaticAnalysisLabelProvider.java

View check run for this annotation

Codecov / codecov/patch

plugin/src/main/java/io/jenkins/plugins/analysis/core/model/StaticAnalysisLabelProvider.java#L109

Added line #L109 was not covered by tests
default:
return ANALYSIS_SVG_ICON;
}
}

private void changeName(final String originalName) {
if (StringUtils.isNotBlank(originalName) && !"-".equals(originalName)) { // don't overwrite with empty or -
if (StringUtils.isNotBlank(originalName) && !"-".equals(originalName)) { // don't overwrite with empty or "-"
name = originalName;
}
}
Expand Down Expand Up @@ -199,7 +233,7 @@ public String getTrendName() {
* @return absolute URL
*/
public String getSmallIconUrl() {
return ANALYSIS_SVG_ICON;
return icon;
}

/**
Expand All @@ -208,7 +242,7 @@ public String getSmallIconUrl() {
* @return absolute URL
*/
public String getLargeIconUrl() {
return ANALYSIS_SVG_ICON;
return icon;

Check warning on line 245 in plugin/src/main/java/io/jenkins/plugins/analysis/core/model/StaticAnalysisLabelProvider.java

View check run for this annotation

Codecov / codecov/patch

plugin/src/main/java/io/jenkins/plugins/analysis/core/model/StaticAnalysisLabelProvider.java#L245

Added line #L245 was not covered by tests
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import hudson.Extension;

import io.jenkins.plugins.analysis.core.model.AnalysisModelParser;
import io.jenkins.plugins.analysis.core.model.StaticAnalysisLabelProvider;
import io.jenkins.plugins.analysis.core.model.SymbolIconLabelProvider;

/**
* Provides a parser and customized messages for Error Prone.
Expand All @@ -32,10 +30,5 @@ public static class Descriptor extends AnalysisModelParserDescriptor {
public Descriptor() {
super(ID);
}

@Override
public StaticAnalysisLabelProvider getLabelProvider() {
return new SymbolIconLabelProvider(getId(), getDisplayName(), getDescriptionProvider(), "symbol-solid/bug plugin-font-awesome-api");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,15 @@ public static class Descriptor extends AnalysisModelParserDescriptor {
public Descriptor() {
super(ID);
}

@Override
public boolean canScanConsoleLog() {
return false;
}

@Override
public boolean isPostProcessingEnabled() {
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import hudson.Extension;

import io.jenkins.plugins.analysis.core.model.AnalysisModelParser;
import io.jenkins.plugins.analysis.core.model.StaticAnalysisLabelProvider;
import io.jenkins.plugins.analysis.core.model.SymbolIconLabelProvider;

/**
* Provides a parser and customized messages for Yocto Scanner CLI (scannercli) reports.
Expand Down Expand Up @@ -44,10 +42,5 @@ public boolean canScanConsoleLog() {
public boolean isPostProcessingEnabled() {
return false;
}

@Override
public StaticAnalysisLabelProvider getLabelProvider() {
return new SymbolIconLabelProvider(getId(), getDisplayName(), getDescriptionProvider(), "symbol-solid/shield-halved plugin-font-awesome-api");
}
}
}

0 comments on commit dab14c5

Please sign in to comment.