From 2bca96dfbbb38fc1308a522da966443c24aae922 Mon Sep 17 00:00:00 2001
From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com>
Date: Fri, 10 May 2024 21:21:37 +0000
Subject: [PATCH 1/4] Update dependency org.jvnet.hudson.plugins:analysis-pom
to v8
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 3d6153af..4683fc41 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
org.jvnet.hudson.plugins
analysis-pom
- 7.4.0
+ 8.1.2
From a2ef3eb930d9268d3af9aa29861eecf4550997b4 Mon Sep 17 00:00:00 2001
From: Ulli Hafner
Date: Fri, 17 May 2024 12:42:54 +0200
Subject: [PATCH 2/4] Fix several CheckStyle and PMD warnings.
The new 8.x release of analysis-pom contains an upgrade to PMD 7
with modified rules and some additional CheckStyle rules.
Maven will now correctly break the build locally if there are warnings.
Fixes https://github.com/jenkinsci/checks-api-plugin/issues/99
---
pom.xml | 30 +--------
.../plugins/checks/api/TruncatedString.java | 3 -
.../status/BuildStatusChecksPublisher.java | 2 +-
.../checks/status/FlowExecutionAnalyzer.java | 11 ++--
.../checks/steps/PublishChecksStep.java | 61 ++++++-------------
.../plugins/checks/steps/WithChecksStep.java | 4 +-
.../plugins/checks/utils/FlowNodeUtils.java | 4 ++
.../checks/api/TruncatedStringTest.java | 8 +--
.../checks/steps/PublishChecksStepITest.java | 1 -
.../checks/steps/WithChecksStepITest.java | 1 -
.../checks/steps/WithChecksStepTest.java | 2 +-
.../checks/util/CapturingChecksPublisher.java | 1 -
12 files changed, 37 insertions(+), 91 deletions(-)
diff --git a/pom.xml b/pom.xml
index 4683fc41..72b81bdd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -156,35 +156,7 @@
org.revapi
revapi-maven-plugin
- \d+\.\d+\.\d+
- false
-
-
- -
-
java.field.serialVersionUIDUnchanged
- field io.jenkins.plugins.checks.steps.PublishChecksStep.serialVersionUID
- 1
- Adding actions list with an initial empty value should not break the compatibility.
-
- -
-
java.field.serialVersionUIDUnchanged
- field io.jenkins.plugins.checks.steps.WithChecksStep.serialVersionUID
- 1
- Boolean value added, will have no impact on backwards compat.
-
- -
- true
-
java.annotation.*
- @edu.umd.cs.findbugs.annotations.*
- Annotation should be safe to change.
-
- -
- true
-
java.missing.*
- Dependencies are not being checked, so they are reported as missing
-
-
-
+ true
diff --git a/src/main/java/io/jenkins/plugins/checks/api/TruncatedString.java b/src/main/java/io/jenkins/plugins/checks/api/TruncatedString.java
index 4e257893..03fa2b06 100644
--- a/src/main/java/io/jenkins/plugins/checks/api/TruncatedString.java
+++ b/src/main/java/io/jenkins/plugins/checks/api/TruncatedString.java
@@ -25,10 +25,7 @@
*
*/
public class TruncatedString {
-
- @NonNull
private final List chunks;
- @NonNull
private final String truncationText;
private final boolean truncateStart;
private final boolean chunkOnNewlines;
diff --git a/src/main/java/io/jenkins/plugins/checks/status/BuildStatusChecksPublisher.java b/src/main/java/io/jenkins/plugins/checks/status/BuildStatusChecksPublisher.java
index e82d78a6..b29c5644 100644
--- a/src/main/java/io/jenkins/plugins/checks/status/BuildStatusChecksPublisher.java
+++ b/src/main/java/io/jenkins/plugins/checks/status/BuildStatusChecksPublisher.java
@@ -41,6 +41,7 @@
* A publisher which publishes different statuses through the checks API based on the stage of the {@link Queue.Item}
* or {@link Run}.
*/
+@SuppressWarnings("PMD.CouplingBetweenObjects")
public final class BuildStatusChecksPublisher {
private static final Logger LOGGER = Logger.getLogger(BuildStatusChecksPublisher.class.getName());
@@ -244,7 +245,6 @@ public void onNewHead(final FlowNode node) {
getChecksName(run).ifPresent(checksName -> publish(ChecksPublisherFactory.fromRun(run, TaskListener.NULL),
ChecksStatus.IN_PROGRESS, ChecksConclusion.NONE, checksName, getOutput(run, node.getExecution())));
}
-
}
}
}
diff --git a/src/main/java/io/jenkins/plugins/checks/status/FlowExecutionAnalyzer.java b/src/main/java/io/jenkins/plugins/checks/status/FlowExecutionAnalyzer.java
index 2f7a09fe..aec20c32 100644
--- a/src/main/java/io/jenkins/plugins/checks/status/FlowExecutionAnalyzer.java
+++ b/src/main/java/io/jenkins/plugins/checks/status/FlowExecutionAnalyzer.java
@@ -39,7 +39,7 @@ class FlowExecutionAnalyzer {
private final Run, ?> run;
private final FlowExecution execution;
- private final Stack indentationStack = new Stack<>();
+ private final Stack indentationStack = new Stack<>(); // NOPMD TODO: replace with DeQueue
private final boolean suppressLogs;
FlowExecutionAnalyzer(final Run, ?> run, final FlowExecution execution, final boolean suppressLogs) {
@@ -128,8 +128,9 @@ private Pair processErrorOrWarningRow(final FlowGraphTable.Row r
nodeTextBuilder.append(String.join("", Collections.nCopies(indentationStack.size() + 1, " ")));
if (warningAction == null) {
- nodeTextBuilder.append(String.format("**Error**: *%s*", errorAction.getDisplayName()));
- nodeSummaryBuilder.append(String.format("```%n%s%n```%n", errorAction.getDisplayName()));
+ var displayName = errorAction == null ? "[no error action]" : errorAction.getDisplayName();
+ nodeTextBuilder.append(String.format("**Error**: *%s*", displayName));
+ nodeSummaryBuilder.append(String.format("```%n%s%n```%n", displayName));
if (!suppressLogs) {
String log = getLog(flowNode);
if (StringUtils.isNotBlank(log)) {
@@ -169,7 +170,7 @@ ChecksOutput extractOutput() {
.orElseGet(() -> processErrorOrWarningRow(row, errorAction, warningAction));
// the last title will be used in the ChecksOutput (if any are found)
- if (!stageOrBranchName.isPresent()) {
+ if (stageOrBranchName.isEmpty()) {
title = getPotentialTitle(flowNode, errorAction);
}
@@ -206,7 +207,7 @@ private static String getLog(final FlowNode flowNode) {
return null;
}
- String outputString = out.toString(StandardCharsets.UTF_8.toString());
+ String outputString = out.toString(StandardCharsets.UTF_8);
// strip ansi color codes
return outputString.replaceAll("\u001B\\[[;\\d]*m", "");
}
diff --git a/src/main/java/io/jenkins/plugins/checks/steps/PublishChecksStep.java b/src/main/java/io/jenkins/plugins/checks/steps/PublishChecksStep.java
index 64e65cd9..ccc5fd19 100644
--- a/src/main/java/io/jenkins/plugins/checks/steps/PublishChecksStep.java
+++ b/src/main/java/io/jenkins/plugins/checks/steps/PublishChecksStep.java
@@ -1,42 +1,24 @@
package io.jenkins.plugins.checks.steps;
-import java.io.IOException;
-import java.io.Serializable;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Optional;
-import java.util.Set;
-import java.util.stream.Collectors;
-
-import org.apache.commons.lang3.StringUtils;
-
import edu.hm.hafner.util.VisibleForTesting;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
-
-import org.kohsuke.stapler.DataBoundConstructor;
-import org.kohsuke.stapler.DataBoundSetter;
-import org.jenkinsci.plugins.workflow.steps.Step;
-import org.jenkinsci.plugins.workflow.steps.StepContext;
-import org.jenkinsci.plugins.workflow.steps.StepDescriptor;
-import org.jenkinsci.plugins.workflow.steps.StepExecution;
-import org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution;
import hudson.Extension;
import hudson.model.AbstractDescribableImpl;
import hudson.model.Descriptor;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.util.ListBoxModel;
+import io.jenkins.plugins.checks.api.*;
+import org.apache.commons.lang3.StringUtils;
+import org.jenkinsci.plugins.workflow.steps.*;
+import org.kohsuke.stapler.DataBoundConstructor;
+import org.kohsuke.stapler.DataBoundSetter;
-import io.jenkins.plugins.checks.api.ChecksAction;
-import io.jenkins.plugins.checks.api.ChecksAnnotation;
-import io.jenkins.plugins.checks.api.ChecksConclusion;
-import io.jenkins.plugins.checks.api.ChecksDetails;
-import io.jenkins.plugins.checks.api.ChecksOutput;
-import io.jenkins.plugins.checks.api.ChecksPublisherFactory;
-import io.jenkins.plugins.checks.api.ChecksStatus;
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.*;
+import java.util.stream.Collectors;
/**
* Pipeline step to publish customized checks.
@@ -93,8 +75,7 @@ public void setDetailsURL(final String detailsURL) {
* When the {@code status} is {@link ChecksStatus#QUEUED} or {@link ChecksStatus#IN_PROGRESS},
* the conclusion will be reset to {@link ChecksConclusion#NONE}
*
- * @param status
- * the status to be set
+ * @param status the status to be set
*/
@DataBoundSetter
public void setStatus(final ChecksStatus status) {
@@ -216,7 +197,9 @@ static class PublishChecksStepExecution extends SynchronousNonBlockingStepExecut
@Override
protected Void run() throws IOException, InterruptedException {
- ChecksPublisherFactory.fromRun(getContext().get(Run.class), getContext().get(TaskListener.class))
+ ChecksPublisherFactory.fromRun(
+ Objects.requireNonNull(getContext().get(Run.class)),
+ Objects.requireNonNull(getContext().get(TaskListener.class)))
.publish(extractChecksDetails());
return null;
@@ -277,14 +260,10 @@ public static class StepChecksAnnotation extends AbstractDescribableImpl parameters() {
Arguments.of(true, true));
}
- private TruncatedString.Builder builder;
+ private TruncatedString.Builder builder = makeBuilder();
- @BeforeEach
- public void makeBuilder() {
+ private TruncatedString.Builder makeBuilder() {
this.builder = new TruncatedString.Builder().withTruncationText(MESSAGE);
+
+ return builder;
}
private String build(final boolean chunkOnChars, final int maxSize) {
diff --git a/src/test/java/io/jenkins/plugins/checks/steps/PublishChecksStepITest.java b/src/test/java/io/jenkins/plugins/checks/steps/PublishChecksStepITest.java
index 8d05dd79..56a5076a 100644
--- a/src/test/java/io/jenkins/plugins/checks/steps/PublishChecksStepITest.java
+++ b/src/test/java/io/jenkins/plugins/checks/steps/PublishChecksStepITest.java
@@ -22,7 +22,6 @@
* Tests the pipeline step to publish checks.
*/
class PublishChecksStepITest extends IntegrationTestWithJenkinsPerTest {
-
private CapturingChecksPublisher.Factory getFactory() {
return getJenkins().getInstance().getExtensionList(ChecksPublisherFactory.class)
.stream()
diff --git a/src/test/java/io/jenkins/plugins/checks/steps/WithChecksStepITest.java b/src/test/java/io/jenkins/plugins/checks/steps/WithChecksStepITest.java
index dd3fad92..1a5075d3 100644
--- a/src/test/java/io/jenkins/plugins/checks/steps/WithChecksStepITest.java
+++ b/src/test/java/io/jenkins/plugins/checks/steps/WithChecksStepITest.java
@@ -30,7 +30,6 @@
* Tests the "withChecks" step.
*/
class WithChecksStepITest extends IntegrationTestWithJenkinsPerTest {
-
/**
* Tests that the step can inject the {@link ChecksInfo} into the closure.
*/
diff --git a/src/test/java/io/jenkins/plugins/checks/steps/WithChecksStepTest.java b/src/test/java/io/jenkins/plugins/checks/steps/WithChecksStepTest.java
index 86d9941f..1b508773 100644
--- a/src/test/java/io/jenkins/plugins/checks/steps/WithChecksStepTest.java
+++ b/src/test/java/io/jenkins/plugins/checks/steps/WithChecksStepTest.java
@@ -19,7 +19,7 @@ void shouldStartWithCorrectExecution() throws IOException, InterruptedException
when(context.get(Run.class)).thenReturn(mock(Run.class));
when(context.get(TaskListener.class)).thenReturn(TaskListener.NULL);
- assertThat(((WithChecksStep.WithChecksStepExecution) (new WithChecksStep("test").start(context)))
+ assertThat(((WithChecksStep.WithChecksStepExecution) new WithChecksStep("test").start(context))
.extractChecksInfo())
.hasFieldOrPropertyWithValue("name", "test");
}
diff --git a/src/test/java/io/jenkins/plugins/checks/util/CapturingChecksPublisher.java b/src/test/java/io/jenkins/plugins/checks/util/CapturingChecksPublisher.java
index be2ff354..70cd46c9 100644
--- a/src/test/java/io/jenkins/plugins/checks/util/CapturingChecksPublisher.java
+++ b/src/test/java/io/jenkins/plugins/checks/util/CapturingChecksPublisher.java
@@ -45,7 +45,6 @@
*
*/
public class CapturingChecksPublisher extends ChecksPublisher {
-
private final List publishedChecks = new ArrayList<>();
@Override
From 03acfe1e9ac1cb4ad66d538411d23e1f33d93494 Mon Sep 17 00:00:00 2001
From: Ulli Hafner
Date: Mon, 20 May 2024 12:39:55 +0200
Subject: [PATCH 3/4] Fix SpotBugs build in CI.
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 72b81bdd..c56833d7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
org.jvnet.hudson.plugins
analysis-pom
- 8.1.2
+ 8.3.0
From 6be47ad6a0609c991ebc06f10510545cbf3c4907 Mon Sep 17 00:00:00 2001
From: Ulli Hafner
Date: Mon, 20 May 2024 15:55:49 +0200
Subject: [PATCH 4/4] Revert skipping of maven flattening.
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index c56833d7..60b17214 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
org.jvnet.hudson.plugins
analysis-pom
- 8.3.0
+ 8.4.0