Skip to content

Commit e8c7d56

Browse files
committed
handle findbugs, spotbugs, maven console, java, javadoc, open tasks, pmd, cpd and checkstyle and add configuration
1 parent 2632ef7 commit e8c7d56

File tree

10 files changed

+372
-79
lines changed

10 files changed

+372
-79
lines changed

pipeline-maven/src/main/java/org/jenkinsci/plugins/pipeline/maven/WithMavenStep.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,11 @@ public ListBoxModel doFillPublisherStrategyItems(@AncestorInPath Item item, @Anc
329329
public DescriptorExtensionList<MavenPublisher, MavenPublisher.DescriptorImpl> getOptionsDescriptors() {
330330
DescriptorExtensionList<MavenPublisher, MavenPublisher.DescriptorImpl> result =
331331
Jenkins.get().getDescriptorList(MavenPublisher.class);
332-
result.removeIf(d -> d.ordinal() < 0);
332+
for (MavenPublisher.DescriptorImpl d : result) {
333+
if (d.ordinal() < 0) {
334+
result.remove(d);
335+
}
336+
}
333337
return result;
334338
}
335339
}

pipeline-maven/src/main/java/org/jenkinsci/plugins/pipeline/maven/publishers/CoveragePublisher.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,16 @@ public void process(StepContext context, Element mavenSpyLogsElt) throws IOExcep
147147
if (method != null) {
148148
makeAccessible(method);
149149
invokeMethod(method, stepExecution);
150+
} else {
151+
listener.error(
152+
"[withMaven] coveragePublisher - error archiving coverage results: CoverageStep.Execution.run() method not found");
153+
LOGGER.log(
154+
Level.WARNING,
155+
"Error processing coverage results: CoverageStep.Execution.run() method not found");
156+
throw new MavenPipelinePublisherException(
157+
"coveragePublisher",
158+
"archiving coverage results",
159+
new RuntimeException("CoverageStep.Execution.run() method not found"));
150160
}
151161
} catch (Exception e) {
152162
listener.error("[withMaven] coveragePublisher - exception archiving coverage results: " + e);
@@ -250,6 +260,7 @@ private SourceCodeDirectory toSourceDirectory(Element e) {
250260
@Symbol("coveragePublisher")
251261
@OptionalExtension(requirePlugins = "coverage")
252262
public static class DescriptorImpl extends MavenPublisher.DescriptorImpl {
263+
253264
@NonNull
254265
@Override
255266
public String getDisplayName() {

pipeline-maven/src/main/java/org/jenkinsci/plugins/pipeline/maven/publishers/WarningsPublisher.java

Lines changed: 229 additions & 75 deletions
Large diffs are not rendered by default.

pipeline-maven/src/main/resources/org/jenkinsci/plugins/pipeline/maven/publishers/WarningsPublisher/config.jelly

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,30 @@ THE SOFTWARE.
2323
-->
2424

2525
<?jelly escape-by-default='true'?>
26-
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler"
27-
>
26+
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:f="/lib/form">
2827

29-
<st:include page="maven-publisher" class="${descriptor.clazz}"/>
28+
<st:include page="maven-publisher" class="${descriptor.clazz}"/>
29+
30+
<f:entry title="${%title.sourceCodeEncoding}" field="sourceCodeEncoding">
31+
<f:combobox/>
32+
</f:entry>
33+
34+
<f:entry field="enabledForFailure">
35+
<f:checkbox title="${%title.enabledForFailure}"/>
36+
</f:entry>
37+
38+
<f:entry field="skipBlames">
39+
<f:checkbox title="${%title.blameDisabled}" />
40+
</f:entry>
41+
42+
<f:entry title="${%title.trendChartType}" field="trendChartType">
43+
<f:select default="TOOLS_ONLY"/>
44+
</f:entry>
45+
46+
<!--
47+
private int qualityGateThreshold = 1;
48+
private QualityGateType qualityGateType = QualityGateType.NEW;
49+
private QualityGateCriticality qualityGateCriticality = QualityGateCriticality.UNSTABLE;
50+
-->
3051

3152
</j:jelly>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
title.sourceCodeEncoding=Source Code Encoding
2+
description.sourceCodeEncoding=Encoding of your source code.
3+
4+
title.enabledForFailure=Enable recording for failed builds
5+
6+
title.blameDisabled=Disable retrieval of blame information (author and commit) from SCM
7+
8+
title.trendChartType=Trend Chart Type and Position
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<div>
2+
By default, static analysis results are only recorded for stable or unstable builds, but not for failed builds:
3+
analysis results might be inaccurate if the build failed. If recording should be enabled for failed builds as well
4+
then activate this check box.
5+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<div>
2+
If this option is unchecked, then the plugin automatically shows what revision and author (name and email)
3+
last modified the lines of the affected files that contain issues. If this operation slows down your build,
4+
or you don't want to publish sensitive user data, you can use this option to deactivate this feature.
5+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<div>
2+
In order to correctly show all your affected source code files in the detail views,
3+
the plugin must open these files with the correct character encoding (UTF-8, ISO-8859-1, etc.).
4+
If you leave this field empty then the default encoding of the platform will be used. This might work but
5+
is not recommended.
6+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<div>
2+
If there is more than one static analysis result available then an aggregation trend chart will be shown
3+
on the project page that shows the analysis results in a single trend chart. You can choose the position of
4+
this aggregation trend:
5+
<dl>
6+
<dt>AGGREGATION_TOOLS</dt>
7+
<dd>The aggregation trend is shown <b>before</b> all other analysis tool trend charts.</dd>
8+
<dt>TOOLS_AGGREGATION</dt>
9+
<dd>The aggregation trend is shown <b>after</b> all other analysis tool trend charts.</dd>
10+
<dt>TOOLS_ONLY</dt>
11+
<dd>The aggregation trend is not shown, only the analysis tool trend charts are shown.</dd>
12+
<dt>AGGREGATION_ONLY</dt>
13+
<dd>The aggregation trend is only shown, no other analysis tool trend charts are shown.</dd>
14+
<dt>NONE</dt>
15+
<dd>Neither the aggregation trend nor analysis tool trend charts are shown.</dd>
16+
</dl>
17+
</div>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package org.jenkinsci.plugins.pipeline.maven.publishers;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import hudson.model.Result;
6+
import hudson.tasks.junit.TestResultAction;
7+
import io.jenkins.plugins.coverage.metrics.steps.CoverageBuildAction;
8+
import java.util.Collection;
9+
import java.util.List;
10+
import org.jenkinsci.plugins.pipeline.maven.AbstractIntegrationTest;
11+
import org.jenkinsci.plugins.pipeline.maven.TestUtils;
12+
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
13+
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
14+
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
15+
import org.junit.jupiter.api.Test;
16+
17+
public class WarningsPublisherTest extends AbstractIntegrationTest {
18+
19+
@Test
20+
public void maven_build_jar_with_findbugs_succeeds() throws Exception {
21+
loadSourceCodeInGitRepository(
22+
this.gitRepoRule,
23+
"/org/jenkinsci/plugins/pipeline/maven/test/test_maven_projects/maven_jar_with_jacoco_project/");
24+
25+
// @formatter:off
26+
String pipelineScript = "node() {\n" +
27+
" git($/" + gitRepoRule.toString() + "/$)\n" +
28+
" withMaven() {\n" +
29+
" if (isUnix()) {\n" +
30+
" sh 'mvn package verify'\n" +
31+
" } else {\n" +
32+
" bat 'mvn package verify'\n" +
33+
" }\n" +
34+
" }\n" +
35+
"}";
36+
// @formatter:on
37+
38+
WorkflowJob pipeline = jenkinsRule.createProject(WorkflowJob.class, "jar-with-jacoco");
39+
pipeline.setDefinition(new CpsFlowDefinition(pipelineScript, true));
40+
WorkflowRun build = jenkinsRule.assertBuildStatus(Result.SUCCESS, pipeline.scheduleBuild2(0));
41+
42+
Collection<String> artifactsFileNames = TestUtils.artifactsToArtifactsFileNames(build.getArtifacts());
43+
assertThat(artifactsFileNames).contains("jar-with-jacoco-0.1-SNAPSHOT.pom", "jar-with-jacoco-0.1-SNAPSHOT.jar");
44+
45+
verifyFileIsFingerPrinted(
46+
pipeline, build, "jenkins/mvn/test/jar-with-jacoco/0.1-SNAPSHOT/jar-with-jacoco-0.1-SNAPSHOT.jar");
47+
verifyFileIsFingerPrinted(
48+
pipeline, build, "jenkins/mvn/test/jar-with-jacoco/0.1-SNAPSHOT/jar-with-jacoco-0.1-SNAPSHOT.pom");
49+
50+
List<TestResultAction> testResultActions = build.getActions(TestResultAction.class);
51+
assertThat(testResultActions).hasSize(1);
52+
TestResultAction testResultAction = testResultActions.get(0);
53+
assertThat(testResultAction.getTotalCount()).isEqualTo(2);
54+
assertThat(testResultAction.getFailCount()).isEqualTo(0);
55+
56+
List<CoverageBuildAction> coverageActions = build.getActions(CoverageBuildAction.class);
57+
assertThat(coverageActions).hasSize(1);
58+
CoverageBuildAction coverageAction = coverageActions.get(0);
59+
assertThat(coverageAction.getProjectActions()).hasSize(1);
60+
assertThat(coverageAction.getQualityGateResult()).isNotNull();
61+
}
62+
}

0 commit comments

Comments
 (0)