diff --git a/Jenkinsfile b/Jenkinsfile index 7ff12947..5e9546e3 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,9 +1,8 @@ -/* - See the documentation for more options: - https://github.com/jenkins-infra/pipeline-library/ -*/ def configurations = [ - [ platform: "linux", jdk: "8", jenkins: null ], - [ platform: "linux", jdk: "11", jenkins: null, javaLevel: "8" ] + [ platform: "linux", jdk: "11" ], + [ platform: "windows", jdk: "11" ] ] -buildPlugin(configurations: configurations, useAci: true) + +buildPlugin(failFast: false, configurations: configurations, + checkstyle: [qualityGates: [[threshold: 1, type: 'NEW', unstable: true]]], + pmd: [qualityGates: [[threshold: 1, type: 'NEW', unstable: true]]] ) diff --git a/pom.xml b/pom.xml index 40fdf1b6..a77d937a 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.jvnet.hudson.plugins analysis-pom - 5.9.0 + 5.17.0 @@ -23,7 +23,7 @@ -SNAPSHOT - 2.4.0 + 2.6.0 2.5 diff --git a/spotbugs-exclusion-filter.xml b/spotbugs-exclusion-filter.xml deleted file mode 100644 index 25368055..00000000 --- a/spotbugs-exclusion-filter.xml +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/src/main/java/io/jenkins/plugins/checks/api/ChecksDetails.java b/src/main/java/io/jenkins/plugins/checks/api/ChecksDetails.java index 0060b0d7..8df237f2 100644 --- a/src/main/java/io/jenkins/plugins/checks/api/ChecksDetails.java +++ b/src/main/java/io/jenkins/plugins/checks/api/ChecksDetails.java @@ -1,14 +1,14 @@ package io.jenkins.plugins.checks.api; -import edu.umd.cs.findbugs.annotations.CheckForNull; - import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Optional; -import static java.util.Objects.requireNonNull; +import edu.umd.cs.findbugs.annotations.CheckForNull; + +import static java.util.Objects.*; /** * Details of a check. This class is a top class which contains all parameters needed for a check. @@ -134,6 +134,7 @@ public String toString() { /** * Builder for {@link ChecksDetails}. */ + @SuppressWarnings("ParameterHidesMemberVariable") public static class ChecksDetailsBuilder { @CheckForNull private String name; @@ -165,7 +166,7 @@ public ChecksDetailsBuilder() { *

* Note that for GitHub check runs, the name shown on GitHub UI will be the same as this attribute and * GitHub uses this attribute to identify a check run, so make sure this name is unique, e.g. "Coverage". - *

+ *

* * @param name * the check's name diff --git a/src/main/java/io/jenkins/plugins/checks/api/ChecksOutput.java b/src/main/java/io/jenkins/plugins/checks/api/ChecksOutput.java index 1f9b4416..ae09bb10 100644 --- a/src/main/java/io/jenkins/plugins/checks/api/ChecksOutput.java +++ b/src/main/java/io/jenkins/plugins/checks/api/ChecksOutput.java @@ -1,13 +1,13 @@ package io.jenkins.plugins.checks.api; -import edu.umd.cs.findbugs.annotations.CheckForNull; - import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Optional; -import static java.util.Objects.requireNonNull; +import edu.umd.cs.findbugs.annotations.CheckForNull; + +import static java.util.Objects.*; /** * An output of a check. The output usually contains the most useful information like summary, description, @@ -101,6 +101,7 @@ public String toString() { /** * Builder for {@link ChecksOutput}. */ + @SuppressWarnings("ParameterHidesMemberVariable") public static class ChecksOutputBuilder { @CheckForNull private String title; @@ -139,7 +140,7 @@ public ChecksOutputBuilder withTitle(final String title) { * *

* Note that for the GitHub check runs, the {@code summary} supports Markdown. - *

+ *

* * @param summary * the summary of the check run @@ -155,7 +156,7 @@ public ChecksOutputBuilder withSummary(final String summary) { * *

* Note that for the GitHub check runs, the {@code summary} supports Markdown. - *

+ *

* * @param summary * the summary of the check run as a {@link TruncatedString} @@ -172,7 +173,7 @@ public ChecksOutputBuilder withSummary(final TruncatedString summary) { * *

* Note that for a GitHub check run, the {@code text} supports Markdown. - *

+ *

* * @param text * the details description in Markdown @@ -188,7 +189,7 @@ public ChecksOutputBuilder withText(final String text) { * *

* Note that for a GitHub check run, the {@code text} supports Markdown. - *

+ *

* * @param text * the details description in Markdown as a {@link TruncatedString} 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 035eca8b..4e257893 100644 --- a/src/main/java/io/jenkins/plugins/checks/api/TruncatedString.java +++ b/src/main/java/io/jenkins/plugins/checks/api/TruncatedString.java @@ -1,15 +1,20 @@ package io.jenkins.plugins.checks.api; -import edu.umd.cs.findbugs.annotations.NonNull; - import java.nio.charset.StandardCharsets; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Set; import java.util.function.BiConsumer; import java.util.function.BinaryOperator; import java.util.function.Function; import java.util.function.Supplier; import java.util.stream.Collector; +import edu.umd.cs.findbugs.annotations.NonNull; + /** * Utility wrapper that silently truncates output with a message at a certain size. *

@@ -17,6 +22,7 @@ * truncate to the required length as this could lead to unterminated syntax. The use of this class allows for adding * chunks of complete markdown until an overflow is detected, at which point a message will be added and all future * additions will be silently discarded. + *

*/ public class TruncatedString { @@ -27,7 +33,6 @@ public class TruncatedString { private final boolean truncateStart; private final boolean chunkOnNewlines; - private TruncatedString(@NonNull final List chunks, @NonNull final String truncationText, final boolean truncateStart, final boolean chunkOnNewlines) { this.chunks = Collections.unmodifiableList(Objects.requireNonNull(chunks)); this.truncationText = Objects.requireNonNull(truncationText); @@ -109,10 +114,10 @@ private String build(final int maxSize, final boolean chunkOnChars) { return String.join("", truncatedParts); } - /** * Builder for {@link TruncatedString}. */ + @SuppressWarnings({"ParameterHidesMemberVariable", "UnusedReturnValue"}) public static class Builder { private String truncationText = "Output truncated."; private boolean truncateStart = false; @@ -170,11 +175,9 @@ public Builder setChunkOnNewlines() { this.chunkOnNewlines = true; return this; } - } private static class Joiner implements Collector> { - private final int maxLength; private final String truncationText; private final boolean chunkOnChars; @@ -250,5 +253,4 @@ List truncate() { } } } - } diff --git a/src/main/java/io/jenkins/plugins/checks/status/AbstractStatusChecksProperties.java b/src/main/java/io/jenkins/plugins/checks/status/AbstractStatusChecksProperties.java index eeadb366..b96d2163 100644 --- a/src/main/java/io/jenkins/plugins/checks/status/AbstractStatusChecksProperties.java +++ b/src/main/java/io/jenkins/plugins/checks/status/AbstractStatusChecksProperties.java @@ -4,9 +4,8 @@ import hudson.model.Job; /** - * Extension points for implementations to provide status checks properties. - * - * When no implementations is provided for a job, a {@link DefaultStatusCheckProperties} will be used. + * Extension points for implementations to provide status checks properties. When no implementations is provided for a + * job, a {@link DefaultStatusCheckProperties} will be used. */ public abstract class AbstractStatusChecksProperties implements ExtensionPoint { /** @@ -14,6 +13,7 @@ public abstract class AbstractStatusChecksProperties implements ExtensionPoint { * * @param job * A jenkins job. + * * @return true if applicable */ public abstract boolean isApplicable(Job job); @@ -23,6 +23,7 @@ public abstract class AbstractStatusChecksProperties implements ExtensionPoint { * * @param job * A jenkins job. + * * @return the name of the status check */ public abstract String getName(Job job); @@ -32,17 +33,18 @@ public abstract class AbstractStatusChecksProperties implements ExtensionPoint { * * @param job * A jenkins job. + * * @return true if skip */ public abstract boolean isSkipped(Job job); /** - * Whether to conclude an unstable build as {@link io.jenkins.plugins.checks.api.ChecksConclusion#NEUTRAL}, - * else it would be concluded as {@link io.jenkins.plugins.checks.api.ChecksConclusion#FAILURE}; - * the default is false. + * Whether to conclude an unstable build as {@link io.jenkins.plugins.checks.api.ChecksConclusion#NEUTRAL}, else it + * would be concluded as {@link io.jenkins.plugins.checks.api.ChecksConclusion#FAILURE}; the default is false. * * @param job * A jenkins job. + * * @return false to treat a unstable build as failure. */ public boolean isUnstableBuildNeutral(final Job job) { @@ -54,6 +56,7 @@ public boolean isUnstableBuildNeutral(final Job job) { * * @param job * A jenkins job. + * * @return true if logs should be suppressed from checks output. */ public boolean isSuppressLogs(final Job job) { @@ -66,6 +69,7 @@ public boolean isSuppressLogs(final Job job) { * * @param job * A jenkins job. + * * @return true if progress updates should be skipped. */ public boolean isSkipProgressUpdates(final Job job) { 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 657951e2..e82d78a6 100644 --- a/src/main/java/io/jenkins/plugins/checks/status/BuildStatusChecksPublisher.java +++ b/src/main/java/io/jenkins/plugins/checks/status/BuildStatusChecksPublisher.java @@ -1,7 +1,20 @@ package io.jenkins.plugins.checks.status; +import java.io.File; +import java.io.IOException; +import java.util.Optional; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.stream.Stream; + import edu.umd.cs.findbugs.annotations.CheckForNull; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + +import org.jenkinsci.plugins.workflow.actions.LabelAction; +import org.jenkinsci.plugins.workflow.flow.FlowExecution; +import org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner; +import org.jenkinsci.plugins.workflow.flow.GraphListener; +import org.jenkinsci.plugins.workflow.graph.FlowNode; import hudson.Extension; import hudson.FilePath; import hudson.model.Computer; @@ -15,6 +28,7 @@ import hudson.model.queue.QueueListener; import hudson.scm.SCM; import hudson.scm.SCMRevisionState; + import io.jenkins.plugins.checks.api.ChecksConclusion; import io.jenkins.plugins.checks.api.ChecksDetails.ChecksDetailsBuilder; import io.jenkins.plugins.checks.api.ChecksOutput; @@ -22,25 +36,12 @@ import io.jenkins.plugins.checks.api.ChecksPublisherFactory; import io.jenkins.plugins.checks.api.ChecksStatus; import io.jenkins.plugins.util.JenkinsFacade; -import org.jenkinsci.plugins.workflow.actions.LabelAction; -import org.jenkinsci.plugins.workflow.flow.FlowExecution; -import org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner; -import org.jenkinsci.plugins.workflow.flow.GraphListener; -import org.jenkinsci.plugins.workflow.graph.FlowNode; - -import java.io.File; -import java.io.IOException; -import java.util.Optional; -import java.util.logging.Level; -import java.util.logging.Logger; -import java.util.stream.Stream; /** * A publisher which publishes different statuses through the checks API based on the stage of the {@link Queue.Item} * or {@link Run}. */ public final class BuildStatusChecksPublisher { - private static final Logger LOGGER = Logger.getLogger(BuildStatusChecksPublisher.class.getName()); private BuildStatusChecksPublisher() { @@ -118,11 +119,7 @@ static ChecksOutput getOutput(final Run run, final FlowExecution execution } /** - * {@inheritDoc} - * - *

* Listens to the queue and publishes checks in "queued" state for entering items. - *

*/ @Extension public static class JobScheduledListener extends QueueListener { @@ -147,17 +144,14 @@ public void onEnterWaiting(final Queue.WaitingItem wi) { } @SuppressFBWarnings("RV_RETURN_VALUE_IGNORED_BAD_PRACTICE") - private void runAsync(Runnable run) { + @SuppressWarnings("PMD.DoNotUseThreads") + private void runAsync(final Runnable run) { Computer.threadPoolForRemoting.submit(run); } } /** - * {@inheritDoc} - * - *

* Listens to the SCM checkout and publishes checks. - *

*/ @Extension public static class JobCheckoutListener extends SCMListener { @@ -178,11 +172,7 @@ public void onCheckout(final Run run, final SCM scm, final FilePath worksp /** - * {@inheritDoc} - * - *

* Listens to the run and publishes checks. - *

*/ @Extension public static class JobCompletedListener extends RunListener> { @@ -199,6 +189,7 @@ public void onCompleted(final Run run, @CheckForNull final TaskListener listener ChecksStatus.COMPLETED, extractConclusion(run), checksName, getOutput(run))); } + @SuppressWarnings("PMD.CyclomaticComplexity") private ChecksConclusion extractConclusion(final Run run) { Result result = run.getResult(); if (result == null) { @@ -228,11 +219,7 @@ else if (result.isBetterOrEqualTo(Result.ABORTED)) { } /** - * {@inheritDoc} - * - *

* As a job progresses, record a representation of the flow graph. - *

*/ @Extension public static class ChecksGraphListener implements GraphListener { 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 4ed9298a..9d5bbe97 100644 --- a/src/main/java/io/jenkins/plugins/checks/status/FlowExecutionAnalyzer.java +++ b/src/main/java/io/jenkins/plugins/checks/status/FlowExecutionAnalyzer.java @@ -1,21 +1,5 @@ package io.jenkins.plugins.checks.status; -import edu.umd.cs.findbugs.annotations.CheckForNull; -import edu.umd.cs.findbugs.annotations.NonNull; -import hudson.model.Result; -import hudson.model.Run; -import io.jenkins.plugins.checks.api.ChecksOutput; -import io.jenkins.plugins.checks.api.TruncatedString; -import org.apache.commons.collections.iterators.ReverseListIterator; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.tuple.Pair; -import org.jenkinsci.plugins.workflow.actions.*; -import org.jenkinsci.plugins.workflow.flow.FlowExecution; -import org.jenkinsci.plugins.workflow.graph.FlowNode; -import org.jenkinsci.plugins.workflow.graph.StepNode; -import org.jenkinsci.plugins.workflow.steps.StepDescriptor; -import org.jenkinsci.plugins.workflow.support.visualization.table.FlowGraphTable; - import java.io.ByteArrayOutputStream; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -28,6 +12,31 @@ import java.util.logging.Logger; import java.util.stream.Collectors; +import org.apache.commons.collections.iterators.ReverseListIterator; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.tuple.Pair; + +import edu.umd.cs.findbugs.annotations.CheckForNull; +import edu.umd.cs.findbugs.annotations.NonNull; + +import org.jenkinsci.plugins.workflow.actions.ArgumentsAction; +import org.jenkinsci.plugins.workflow.actions.ErrorAction; +import org.jenkinsci.plugins.workflow.actions.LabelAction; +import org.jenkinsci.plugins.workflow.actions.LogAction; +import org.jenkinsci.plugins.workflow.actions.ThreadNameAction; +import org.jenkinsci.plugins.workflow.actions.WarningAction; +import org.jenkinsci.plugins.workflow.flow.FlowExecution; +import org.jenkinsci.plugins.workflow.graph.FlowNode; +import org.jenkinsci.plugins.workflow.graph.StepNode; +import org.jenkinsci.plugins.workflow.steps.StepDescriptor; +import org.jenkinsci.plugins.workflow.support.visualization.table.FlowGraphTable; +import hudson.model.Result; +import hudson.model.Run; + +import io.jenkins.plugins.checks.api.ChecksOutput; +import io.jenkins.plugins.checks.api.TruncatedString; + +@SuppressWarnings("PMD.GodClass") class FlowExecutionAnalyzer { private static final Logger LOGGER = Logger.getLogger(FlowExecutionAnalyzer.class.getName()); private static final String TRUNCATED_MESSAGE = "\n\nOutput truncated."; diff --git a/src/main/java/io/jenkins/plugins/checks/status/StatusChecksProperties.java b/src/main/java/io/jenkins/plugins/checks/status/StatusChecksProperties.java index c6f789db..433f6f13 100644 --- a/src/main/java/io/jenkins/plugins/checks/status/StatusChecksProperties.java +++ b/src/main/java/io/jenkins/plugins/checks/status/StatusChecksProperties.java @@ -4,9 +4,8 @@ import hudson.model.Job; /** - * Properties that controls status checks. - * - * When no implementations is provided for a job, a {@link DefaultStatusCheckProperties} will be used. + * Properties that controls status checks. When no implementations is provided for a job, a {@link + * DefaultStatusCheckProperties} will be used. * * @deprecated The interface is incompatible for future changes, use {@link AbstractStatusChecksProperties} instead */ @@ -17,6 +16,7 @@ public interface StatusChecksProperties extends ExtensionPoint { * * @param job * A jenkins job. + * * @return true if applicable */ boolean isApplicable(Job job); @@ -26,6 +26,7 @@ public interface StatusChecksProperties extends ExtensionPoint { * * @param job * A jenkins job. + * * @return the name of the status check */ String getName(Job job); @@ -35,6 +36,7 @@ public interface StatusChecksProperties extends ExtensionPoint { * * @param job * A jenkins job. + * * @return true if skip */ boolean isSkip(Job job); 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 f8e26a4f..64e65cd9 100644 --- a/src/main/java/io/jenkins/plugins/checks/steps/PublishChecksStep.java +++ b/src/main/java/io/jenkins/plugins/checks/steps/PublishChecksStep.java @@ -1,14 +1,35 @@ 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.ChecksAction; import io.jenkins.plugins.checks.api.ChecksAnnotation; import io.jenkins.plugins.checks.api.ChecksConclusion; @@ -16,20 +37,11 @@ import io.jenkins.plugins.checks.api.ChecksOutput; import io.jenkins.plugins.checks.api.ChecksPublisherFactory; import io.jenkins.plugins.checks.api.ChecksStatus; -import org.apache.commons.lang3.StringUtils; -import org.jenkinsci.plugins.workflow.steps.*; -import org.kohsuke.stapler.DataBoundConstructor; -import org.kohsuke.stapler.DataBoundSetter; - -import java.io.IOException; -import java.io.Serializable; -import java.util.*; -import java.util.stream.Collectors; /** * Pipeline step to publish customized checks. */ -@SuppressWarnings("PMD.DataClass") +@SuppressWarnings({"PMD.DataClass", "PMD.ExcessivePublicCount"}) public class PublishChecksStep extends Step implements Serializable { private static final long serialVersionUID = 1L; diff --git a/src/test/java/io/jenkins/plugins/checks/status/BuildStatusChecksPublisherITest.java b/src/test/java/io/jenkins/plugins/checks/status/BuildStatusChecksPublisherITest.java index 6f8609f3..282ecdb8 100644 --- a/src/test/java/io/jenkins/plugins/checks/status/BuildStatusChecksPublisherITest.java +++ b/src/test/java/io/jenkins/plugins/checks/status/BuildStatusChecksPublisherITest.java @@ -1,32 +1,34 @@ package io.jenkins.plugins.checks.status; +import java.util.List; +import java.util.regex.Pattern; + +import org.apache.commons.lang3.StringUtils; +import org.junit.After; +import org.junit.Test; +import org.jvnet.hudson.test.TestExtension; + import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + +import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition; +import org.jenkinsci.plugins.workflow.job.WorkflowJob; import hudson.model.Job; import hudson.model.Result; import hudson.model.Run; + import io.jenkins.plugins.checks.api.ChecksConclusion; import io.jenkins.plugins.checks.api.ChecksDetails; import io.jenkins.plugins.checks.api.ChecksStatus; import io.jenkins.plugins.checks.util.CapturingChecksPublisher; import io.jenkins.plugins.util.IntegrationTestWithJenkinsPerTest; -import org.apache.commons.lang3.StringUtils; -import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition; -import org.jenkinsci.plugins.workflow.job.WorkflowJob; -import org.junit.After; -import org.junit.Test; -import org.junit.internal.Checks; -import org.jvnet.hudson.test.TestExtension; - -import java.util.List; -import java.util.regex.Pattern; -import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.*; /** * Tests that the {@link BuildStatusChecksPublisher} listens to the status of a {@link Run} and publishes status * accordingly. */ -@SuppressWarnings("PMD.AddEmptyString") +@SuppressWarnings({"PMD.AddEmptyString", "checkstyle:LambdaBodyLength"}) @SuppressFBWarnings("NP_NONNULL_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR") public class BuildStatusChecksPublisherITest extends IntegrationTestWithJenkinsPerTest { @@ -291,7 +293,7 @@ public void shouldPublishStageDetailsWithoutLogsIfRequested() { } /** - * Validates the a simple successful pipeline works. + * Validates that a simple successful pipeline works. */ @Test public void shouldPublishSimplePipeline() { diff --git a/src/test/java/io/jenkins/plugins/checks/steps/PublishChecksStepTest.java b/src/test/java/io/jenkins/plugins/checks/steps/PublishChecksStepTest.java index 5f3f4dea..6e182efd 100644 --- a/src/test/java/io/jenkins/plugins/checks/steps/PublishChecksStepTest.java +++ b/src/test/java/io/jenkins/plugins/checks/steps/PublishChecksStepTest.java @@ -1,27 +1,28 @@ package io.jenkins.plugins.checks.steps; +import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +import org.apache.commons.lang3.StringUtils; +import org.junit.jupiter.api.Test; + +import org.jenkinsci.plugins.workflow.steps.StepContext; +import org.jenkinsci.plugins.workflow.steps.StepExecution; import hudson.model.Run; import hudson.model.TaskListener; -import hudson.util.ListBoxModel; + 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.ChecksStatus; -import org.apache.commons.lang3.StringUtils; -import org.jenkinsci.plugins.workflow.steps.StepContext; -import org.jenkinsci.plugins.workflow.steps.StepExecution; -import org.junit.jupiter.api.Test; - -import java.io.IOException; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; -import static org.assertj.core.api.Assertions.assertThat; import static io.jenkins.plugins.checks.assertions.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.*; class PublishChecksStepTest { 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 d2674ff3..be2ff354 100644 --- a/src/test/java/io/jenkins/plugins/checks/util/CapturingChecksPublisher.java +++ b/src/test/java/io/jenkins/plugins/checks/util/CapturingChecksPublisher.java @@ -1,22 +1,23 @@ package io.jenkins.plugins.checks.util; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + import hudson.ExtensionList; import hudson.model.Job; import hudson.model.Run; import hudson.model.TaskListener; + import io.jenkins.plugins.checks.api.ChecksDetails; import io.jenkins.plugins.checks.api.ChecksPublisher; import io.jenkins.plugins.checks.api.ChecksPublisherFactory; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - /** * Implementation of {@link ChecksPublisher} for use in testing, that records each captured checks in a simple list. - * + *

* For example: - * + *

*
  * public class ChecksPublishingTest extends IntegrationTestWithJenkinsPerTest {
  *
@@ -39,8 +40,9 @@
  *     }
  * }
  * 
- * + *

* An example of this can be found in {@link io.jenkins.plugins.checks.steps.PublishChecksStepITest} + *

*/ public class CapturingChecksPublisher extends ChecksPublisher { @@ -55,7 +57,6 @@ public void publish(final ChecksDetails details) { * Implementation of {@link ChecksPublisherFactory} that returns a {@link CapturingChecksPublisher}. */ public static class Factory extends ChecksPublisherFactory { - private final CapturingChecksPublisher publisher = new CapturingChecksPublisher(); @Override diff --git a/src/test/java/io/jenkins/plugins/checks/util/LoggingChecksPublisher.java b/src/test/java/io/jenkins/plugins/checks/util/LoggingChecksPublisher.java index 6e7f280b..7fcb82a7 100644 --- a/src/test/java/io/jenkins/plugins/checks/util/LoggingChecksPublisher.java +++ b/src/test/java/io/jenkins/plugins/checks/util/LoggingChecksPublisher.java @@ -1,18 +1,20 @@ package io.jenkins.plugins.checks.util; +import java.util.Optional; + import hudson.model.Job; import hudson.model.Run; import hudson.model.TaskListener; + import io.jenkins.plugins.checks.api.ChecksDetails; import io.jenkins.plugins.checks.api.ChecksPublisher; import io.jenkins.plugins.checks.api.ChecksPublisherFactory; -import java.util.Optional; - /** * Implementation of {@link ChecksPublisher} for use in testing, that logs the checks details in user specified format. - * + *

* For example: + *

* *
  * public class ChecksPublishingTest extends IntegrationTestWithJenkinsPerTest {
@@ -37,8 +39,9 @@
  *     }
  * }
  * 
- * + *

* An example of this can be found in {@link io.jenkins.plugins.checks.status.BuildStatusChecksPublisherITest} + *

*/ public class LoggingChecksPublisher extends ChecksPublisher { private Formatter formatter = ChecksDetails::toString;