Skip to content

Commit

Permalink
Use Java 17 language features
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkEWaite committed Dec 16, 2024
1 parent 738fd51 commit 298a446
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,6 +38,7 @@
public class LabelParameterDefinition extends SimpleParameterDefinition
implements MultipleNodeDescribingParameterDefinition {

@Serial
private static final long serialVersionUID = 1L;

public final String defaultValue;
Expand Down Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ public BuildWrapper createBuildWrapper(AbstractBuild<?, ?> build) {
if (property != null) {
final List<ParameterDefinition> parameterDefinitions = property.getParameterDefinitions();
for (ParameterDefinition paramDef : parameterDefinitions) {
if (paramDef instanceof MultipleNodeDescribingParameterDefinition) {
return ((MultipleNodeDescribingParameterDefinition) paramDef).createBuildWrapper();
if (paramDef instanceof MultipleNodeDescribingParameterDefinition definition) {

Check warning on line 217 in src/main/java/org/jvnet/jenkins/plugins/nodelabelparameter/LabelParameterValue.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 217 is only partially covered, one branch is missing
return definition.createBuildWrapper();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,6 +34,7 @@
public class NodeParameterDefinition extends SimpleParameterDefinition
implements MultipleNodeDescribingParameterDefinition {

@Serial
private static final long serialVersionUID = 1L;

public final List<String> allowedSlaves;
Expand Down Expand Up @@ -261,10 +263,9 @@ public ParameterValue createValue(StaplerRequest2 req, JSONObject jo) {
: jo.get("value");

List<String> 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) {

Check warning on line 266 in src/main/java/org/jvnet/jenkins/plugins/nodelabelparameter/NodeParameterDefinition.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 266 is only partially covered, one branch is missing
nodes.add(string);

Check warning on line 267 in src/main/java/org/jvnet/jenkins/plugins/nodelabelparameter/NodeParameterDefinition.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 267 is not covered by tests
} else if (joValue instanceof JSONArray ja) {

Check warning on line 268 in src/main/java/org/jvnet/jenkins/plugins/nodelabelparameter/NodeParameterDefinition.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 268 is only partially covered, one branch is missing
for (Object strObj : ja) {
nodes.add((String) strObj);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,6 +13,7 @@
*/
public class NodeParameterValue extends LabelParameterValue {

@Serial
private static final long serialVersionUID = 1L;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ private void triggerAllBuildsConcurrent(AbstractBuild<?, ?> build, BuildListener
final List<ParameterValue> origParams = origParamsAction.getParameters();
final List<ParameterValue> newPrams = new ArrayList<>();
for (ParameterValue parameterValue : origParams) {
if (parameterValue instanceof LabelParameterValue) {
LabelParameterValue origNodeParam = (LabelParameterValue) parameterValue;
if (parameterValue instanceof LabelParameterValue origNodeParam) {

Check warning on line 79 in src/main/java/org/jvnet/jenkins/plugins/nodelabelparameter/wrapper/TriggerNextBuildWrapper.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 79 is only partially covered, one branch is missing
parmaName = origNodeParam.getName();
List<String> nextNodes = origNodeParam.getNextLabels();
newBuildNodes.addAll(nextNodes);
Expand Down Expand Up @@ -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) {

Check warning on line 122 in src/main/java/org/jvnet/jenkins/plugins/nodelabelparameter/wrapper/TriggerNextBuildWrapper.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 122 is only partially covered, one branch is missing
List<String> nextNodes = new ArrayList<>(origNodePram.getNextLabels());
nextNodes.remove(initialBuildNode);
if (!nextNodes.isEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 298a446

Please sign in to comment.