Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the parser category to assign different action icons #1851

Merged
merged 11 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ jobs:
BROWSER: chrome-container
run: |
cd plugin
mvn -V --color always -ntp clean verify '-Djenkins.test.timeout=5000' '-Dgpg.skip'
mvn -V --color always -ntp clean verify -Dquite '-Djenkins.test.timeout=5000' '-Dgpg.skip'
4 changes: 2 additions & 2 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:[email protected]: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 @@ -48,7 +48,7 @@
<module.name>${project.groupId}.warnings.ng</module.name>

<analysis-model-api.version>12.9.0</analysis-model-api.version>
<analysis-model-tests.version>12.5.0</analysis-model-tests.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 @@ -76,7 +76,8 @@ protected AnalysisModelParserDescriptor(final String id, final String descriptio
*/
@Override
public StaticAnalysisLabelProvider getLabelProvider() {
return new StaticAnalysisLabelProvider(getId(), getDisplayName(), descriptionProvider);
return new StaticAnalysisLabelProvider(getId(), getDisplayName(), descriptionProvider,
analysisModelDescriptor.getType());
}

/**
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 @@
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 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";
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";
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 @@
* @return absolute URL
*/
public String getSmallIconUrl() {
return ANALYSIS_SVG_ICON;
return icon;
}

/**
Expand All @@ -208,7 +242,7 @@
* @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 @@ -80,7 +80,8 @@ public IssueParser createParser() {
public StaticAnalysisLabelProvider getLabelProvider() {
ParserDescriptor descriptor = getParserDescriptor();

return new StaticAnalysisLabelProvider(descriptor.getId(), getName(), descriptor::getDescription);
return new StaticAnalysisLabelProvider(descriptor.getId(), getName(), descriptor::getDescription,
descriptor.getType());
}

@Override
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 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");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,13 @@ void shouldReportOnlyNewIssuesInTitleWhenAllIssuesAreNew() {
@Test
void shouldIgnoreColumnsWhenBuildMultipleLineAnnotation() {
FreeStyleProject project = getFreeStyleJob();
enableWarnings(project, new Pmd());
var pmd = new Pmd();
pmd.setPattern("**/pmd-report.xml");
enableWarnings(project, pmd);

buildSuccessfully(project);

copySingleFileToWorkspace(project, "pmd.xml");
copySingleFileToWorkspace(project, "pmd-report.xml");
Run<?, ?> run = buildSuccessfully(project);

WarningChecksPublisher publisher = new WarningChecksPublisher(getResultAction(run), TaskListener.NULL, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void shouldFilterPmdIssuesByModule() {
FreeStyleProject project = createFreeStyleProject();
copyDirectoryToWorkspace(project, MODULE_FILTER);
enableWarnings(project, recorder -> recorder.setFilters(toFilter(entry)),
createTool(new Pmd(), "**/pmd.xml"));
createTool(new Pmd(), "**/pmd-report.xml"));

buildAndVerifyResults(project, entry.getValue());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.jenkins.plugins.analysis.warnings.steps;

import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -159,14 +160,16 @@
* Runs the CheckStyle parser without specifying a pattern: the default pattern should be used.
*/
@Test
void shouldUseDefaultFileNamePattern() {
FreeStyleProject project = createFreeStyleProject();
copySingleFileToWorkspace(project, "checkstyle.xml", "checkstyle-result.xml");
void shouldUseDefaultFileNamePattern() throws IOException, InterruptedException {
var project = createFreeStyleProject();
var report = "checkstyle-result.xml";
copySingleFileToWorkspace(project, "checkstyle.xml", report);
enableWarnings(project, createTool(new CheckStyle(), StringUtils.EMPTY));

AnalysisResult result = scheduleBuildAndAssertStatus(project, Result.SUCCESS);
var result = scheduleBuildAndAssertStatus(project, Result.SUCCESS);

assertThat(result).hasTotalSize(6);
getWorkspace(project).child(report).delete();
}

/**
Expand Down Expand Up @@ -362,14 +365,14 @@

String successfulModel = portlet.getWarningsModel();
assertThatJson(successfulModel).node("fixed").isEqualTo(3);
assertThatJson(successfulModel).node("outstanding").isEqualTo(5);
assertThatJson(successfulModel).node("new").node("total").isEqualTo(0);
assertThatJson(successfulModel).node("new").node("low").isEqualTo(0);
assertThatJson(successfulModel).node("new").node("normal").isEqualTo(0);
assertThatJson(successfulModel).node("new").node("high").isEqualTo(0);
assertThatJson(successfulModel).node("new").node("error").isEqualTo(0);

verifyNoNewWarningsPortletModel(portlet, 5, 3);

Check warning on line 375 in plugin/src/test/java/io/jenkins/plugins/analysis/warnings/steps/MiscIssuesRecorderITest.java

View check run for this annotation

ci.jenkins.io / CPD

CPD

LOW: Found duplicated code.
Raw output
<pre><code>assertThatJson(successfulModel).node(&#34;outstanding&#34;).isEqualTo(5); assertThatJson(successfulModel).node(&#34;new&#34;).node(&#34;total&#34;).isEqualTo(0); assertThatJson(successfulModel).node(&#34;new&#34;).node(&#34;low&#34;).isEqualTo(0); assertThatJson(successfulModel).node(&#34;new&#34;).node(&#34;normal&#34;).isEqualTo(0); assertThatJson(successfulModel).node(&#34;new&#34;).node(&#34;high&#34;).isEqualTo(0); assertThatJson(successfulModel).node(&#34;new&#34;).node(&#34;error&#34;).isEqualTo(0); verifyNoNewWarningsPortletModel(portlet, 5, 3);</code></pre>
}

private FreeStyleProject createFreestyleJob(final String... strings) {
Expand Down Expand Up @@ -467,14 +470,14 @@

String successfulModel = portlet.getWarningsModel();
assertThatJson(successfulModel).node("fixed").isEqualTo(0);
assertThatJson(successfulModel).node("outstanding").isEqualTo(8);
assertThatJson(successfulModel).node("new").node("total").isEqualTo(0);
assertThatJson(successfulModel).node("new").node("low").isEqualTo(0);
assertThatJson(successfulModel).node("new").node("normal").isEqualTo(0);
assertThatJson(successfulModel).node("new").node("high").isEqualTo(0);
assertThatJson(successfulModel).node("new").node("error").isEqualTo(0);

verifyNoNewWarningsPortletModel(portlet, 8, 0);

Check warning on line 480 in plugin/src/test/java/io/jenkins/plugins/analysis/warnings/steps/MiscIssuesRecorderITest.java

View check run for this annotation

ci.jenkins.io / CPD

CPD

LOW: Found duplicated code.
Raw output
<pre><code>assertThatJson(successfulModel).node(&#34;outstanding&#34;).isEqualTo(5); assertThatJson(successfulModel).node(&#34;new&#34;).node(&#34;total&#34;).isEqualTo(0); assertThatJson(successfulModel).node(&#34;new&#34;).node(&#34;low&#34;).isEqualTo(0); assertThatJson(successfulModel).node(&#34;new&#34;).node(&#34;normal&#34;).isEqualTo(0); assertThatJson(successfulModel).node(&#34;new&#34;).node(&#34;high&#34;).isEqualTo(0); assertThatJson(successfulModel).node(&#34;new&#34;).node(&#34;error&#34;).isEqualTo(0); verifyNoNewWarningsPortletModel(portlet, 5, 3);</code></pre>
}

/**
Expand Down
Loading
Loading