diff --git a/src/main/java/org/jvnet/jenkins/plugins/nodelabelparameter/LabelParameterDefinition.java b/src/main/java/org/jvnet/jenkins/plugins/nodelabelparameter/LabelParameterDefinition.java index d9eab64..4d49cdb 100644 --- a/src/main/java/org/jvnet/jenkins/plugins/nodelabelparameter/LabelParameterDefinition.java +++ b/src/main/java/org/jvnet/jenkins/plugins/nodelabelparameter/LabelParameterDefinition.java @@ -13,6 +13,7 @@ import hudson.model.labels.LabelExpression; import hudson.util.FormValidation; import jakarta.servlet.ServletException; +import java.io.Serial; import java.util.List; import java.util.Set; import java.util.function.Function; @@ -37,6 +38,7 @@ public class LabelParameterDefinition extends SimpleParameterDefinition implements MultipleNodeDescribingParameterDefinition { + @Serial private static final long serialVersionUID = 1L; public final String defaultValue; @@ -90,8 +92,7 @@ public LabelParameterDefinition(String name, String description, String defaultV @Override public SimpleParameterDefinition copyWithDefaultValue(ParameterValue defaultValueObj) { - if (defaultValueObj instanceof LabelParameterValue) { - LabelParameterValue value = (LabelParameterValue) defaultValueObj; + if (defaultValueObj instanceof LabelParameterValue value) { return new LabelParameterDefinition( getName(), getDescription(), diff --git a/src/main/java/org/jvnet/jenkins/plugins/nodelabelparameter/LabelParameterValue.java b/src/main/java/org/jvnet/jenkins/plugins/nodelabelparameter/LabelParameterValue.java index 9cd3b03..08783e8 100644 --- a/src/main/java/org/jvnet/jenkins/plugins/nodelabelparameter/LabelParameterValue.java +++ b/src/main/java/org/jvnet/jenkins/plugins/nodelabelparameter/LabelParameterValue.java @@ -214,8 +214,8 @@ public BuildWrapper createBuildWrapper(AbstractBuild build) { if (property != null) { final List parameterDefinitions = property.getParameterDefinitions(); for (ParameterDefinition paramDef : parameterDefinitions) { - if (paramDef instanceof MultipleNodeDescribingParameterDefinition) { - return ((MultipleNodeDescribingParameterDefinition) paramDef).createBuildWrapper(); + if (paramDef instanceof MultipleNodeDescribingParameterDefinition definition) { + return definition.createBuildWrapper(); } } } diff --git a/src/main/java/org/jvnet/jenkins/plugins/nodelabelparameter/NodeParameterDefinition.java b/src/main/java/org/jvnet/jenkins/plugins/nodelabelparameter/NodeParameterDefinition.java index f2b519d..1d9e7d3 100644 --- a/src/main/java/org/jvnet/jenkins/plugins/nodelabelparameter/NodeParameterDefinition.java +++ b/src/main/java/org/jvnet/jenkins/plugins/nodelabelparameter/NodeParameterDefinition.java @@ -8,6 +8,7 @@ import hudson.model.ParameterDefinition; import hudson.model.ParameterValue; import hudson.model.SimpleParameterDefinition; +import java.io.Serial; import java.util.ArrayList; import java.util.Comparator; import java.util.List; @@ -33,6 +34,7 @@ public class NodeParameterDefinition extends SimpleParameterDefinition implements MultipleNodeDescribingParameterDefinition { + @Serial private static final long serialVersionUID = 1L; public final List allowedSlaves; @@ -261,10 +263,9 @@ public ParameterValue createValue(StaplerRequest2 req, JSONObject jo) { : jo.get("value"); List nodes = new ArrayList<>(); - if (joValue instanceof String) { - nodes.add((String) joValue); - } else if (joValue instanceof JSONArray) { - JSONArray ja = (JSONArray) joValue; + if (joValue instanceof String string) { + nodes.add(string); + } else if (joValue instanceof JSONArray ja) { for (Object strObj : ja) { nodes.add((String) strObj); } diff --git a/src/main/java/org/jvnet/jenkins/plugins/nodelabelparameter/NodeParameterValue.java b/src/main/java/org/jvnet/jenkins/plugins/nodelabelparameter/NodeParameterValue.java index 41c6f23..2bf210a 100644 --- a/src/main/java/org/jvnet/jenkins/plugins/nodelabelparameter/NodeParameterValue.java +++ b/src/main/java/org/jvnet/jenkins/plugins/nodelabelparameter/NodeParameterValue.java @@ -1,6 +1,7 @@ /** */ package org.jvnet.jenkins.plugins.nodelabelparameter; +import java.io.Serial; import java.util.List; import java.util.Objects; import org.apache.commons.lang.StringUtils; @@ -12,6 +13,7 @@ */ public class NodeParameterValue extends LabelParameterValue { + @Serial private static final long serialVersionUID = 1L; /** diff --git a/src/main/java/org/jvnet/jenkins/plugins/nodelabelparameter/wrapper/TriggerNextBuildWrapper.java b/src/main/java/org/jvnet/jenkins/plugins/nodelabelparameter/wrapper/TriggerNextBuildWrapper.java index 037fd5a..9c8dd7e 100644 --- a/src/main/java/org/jvnet/jenkins/plugins/nodelabelparameter/wrapper/TriggerNextBuildWrapper.java +++ b/src/main/java/org/jvnet/jenkins/plugins/nodelabelparameter/wrapper/TriggerNextBuildWrapper.java @@ -76,8 +76,7 @@ private void triggerAllBuildsConcurrent(AbstractBuild build, BuildListener final List origParams = origParamsAction.getParameters(); final List newPrams = new ArrayList<>(); for (ParameterValue parameterValue : origParams) { - if (parameterValue instanceof LabelParameterValue) { - LabelParameterValue origNodeParam = (LabelParameterValue) parameterValue; + if (parameterValue instanceof LabelParameterValue origNodeParam) { parmaName = origNodeParam.getName(); List nextNodes = origNodeParam.getNextLabels(); newBuildNodes.addAll(nextNodes); @@ -120,8 +119,7 @@ private void triggerBuilds(AbstractBuild build, BuildListener listener) { boolean triggerNewBuild = false; NextLabelCause nextLabelCause = null; for (ParameterValue parameterValue : origParams) { - if (parameterValue instanceof LabelParameterValue) { - LabelParameterValue origNodePram = (LabelParameterValue) parameterValue; + if (parameterValue instanceof LabelParameterValue origNodePram) { List nextNodes = new ArrayList<>(origNodePram.getNextLabels()); nextNodes.remove(initialBuildNode); if (!nextNodes.isEmpty() diff --git a/src/test/java/org/jvnet/jenkins/plugins/nodelabelparameter/TriggerJobsTest.java b/src/test/java/org/jvnet/jenkins/plugins/nodelabelparameter/TriggerJobsTest.java index cec9124..6bac1e3 100644 --- a/src/test/java/org/jvnet/jenkins/plugins/nodelabelparameter/TriggerJobsTest.java +++ b/src/test/java/org/jvnet/jenkins/plugins/nodelabelparameter/TriggerJobsTest.java @@ -334,7 +334,7 @@ void runTestViaCurl( ParametersDefinitionProperty pdp = new ParametersDefinitionProperty(parameterDefinition); project.addProperty(pdp); // URL triggered, see the plugin documentation for more information - String triggerUrl = String.format("%s%sbuild", j.getURL(), project.getUrl()); + String triggerUrl = "%s%sbuild".formatted(j.getURL(), project.getUrl()); JenkinsRule.WebClient wc = j.createWebClient(); URL url = new URL(triggerUrl);