Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require Jenkins 2.479.1 or newer #396

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.88</version>
<version>5.4</version>
<relativePath />
</parent>

Expand Down Expand Up @@ -33,8 +33,9 @@
<revision>5.2.1</revision>
<changelist>-SNAPSHOT</changelist>
<gitHubRepo>jenkinsci/priority-sorter-plugin</gitHubRepo>
<jenkins.baseline>2.452</jenkins.baseline>
<jenkins.version>${jenkins.baseline}.4</jenkins.version>
<!-- https://www.jenkins.io/doc/developer/plugin-development/choosing-jenkins-baseline/ -->
<jenkins.baseline>2.479</jenkins.baseline>
<jenkins.version>${jenkins.baseline}.1</jenkins.version>
<spotbugs.effort>Max</spotbugs.effort>
<spotbugs.threshold>Low</spotbugs.threshold>
<spotless.check.skip>false</spotless.check.skip>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/jenkins/advancedqueue/JobGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@
@Deprecated
@CheckForNull
public String getView() {
if (jobGroupStrategy instanceof ViewBasedJobInclusionStrategy) {
return ((ViewBasedJobInclusionStrategy) jobGroupStrategy).getViewName();
if (jobGroupStrategy instanceof ViewBasedJobInclusionStrategy strategy) {
return strategy.getViewName();

Check warning on line 171 in src/main/java/jenkins/advancedqueue/JobGroup.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 170-171 are not covered by tests
}
return null;
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/jenkins/advancedqueue/PriorityConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import hudson.security.ACL;
import hudson.util.FormValidation;
import hudson.util.ListBoxModel;
import jakarta.servlet.ServletException;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -50,7 +51,6 @@
import java.util.logging.Logger;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import javax.servlet.ServletException;
import jenkins.advancedqueue.jobinclusion.JobInclusionStrategy;
import jenkins.advancedqueue.priority.PriorityStrategy;
import jenkins.model.GlobalConfiguration;
Expand All @@ -62,8 +62,8 @@
import org.jenkins.ui.icon.IconSpec;
import org.jenkinsci.plugins.workflow.support.steps.ExecutorStepExecution;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.StaplerRequest2;
import org.kohsuke.stapler.StaplerResponse2;

/**
* @author Magnus Sandberg
Expand Down Expand Up @@ -165,7 +165,7 @@
return items;
}

public void doPriorityConfigSubmit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
public void doPriorityConfigSubmit(StaplerRequest2 req, StaplerResponse2 rsp) throws IOException, ServletException {
jobGroups = new LinkedList<JobGroup>();
id2jobGroup = new HashMap<Integer, JobGroup>();
//
Expand Down Expand Up @@ -271,8 +271,8 @@
}

private boolean isJobInView(Job<?, ?> job, View view) {
if (view instanceof ViewGroup) {
return isJobInViewGroup(job, (ViewGroup) view);
if (view instanceof ViewGroup group) {
return isJobInViewGroup(job, group);

Check warning on line 275 in src/main/java/jenkins/advancedqueue/PriorityConfiguration.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 274-275 are not covered by tests
} else {
return view.contains((TopLevelItem) job);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
@NonNull ExecutorStepExecution.PlaceholderTask task,
@NonNull PriorityConfigurationCallback priorityCallback) {
Queue.Task ownerTask = task.getOwnerTask();
if (ownerTask instanceof Job<?, ?>) {
Job<?, ?> job = (Job<?, ?>) ownerTask;
if (ownerTask instanceof Job<?, ?> job) {

Check warning on line 28 in src/main/java/jenkins/advancedqueue/PriorityConfigurationPlaceholderTaskHelper.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 28 is not covered by tests
ItemInfo itemInfo = QueueItemCache.get().getItem(job.getName());
if (itemInfo != null) {
priorityCallback.setPrioritySelection(itemInfo.getPriority());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,12 @@
ItemGroup<?> parent = job.getParent();
decisionLogger.addDecisionLog(2, "Checking for Cloudbees Folder inclusion ...");
while (parent != null) {
if (parent instanceof AbstractFolder) {
AbstractFolder folder = (AbstractFolder) parent;
if (parent instanceof AbstractFolder<?> folder) {
decisionLogger.addDecisionLog(3, "Evaluating Folder [" + folder.getFullName() + "] ...");
DescribableList<AbstractFolderProperty<?>, AbstractFolderPropertyDescriptor> properties =
folder.getProperties();
for (AbstractFolderProperty<?> property : properties) {
if (property instanceof JobInclusionFolderProperty) {
JobInclusionFolderProperty incProperty = (JobInclusionFolderProperty) property;
if (property instanceof JobInclusionFolderProperty incProperty) {

Check warning on line 52 in src/main/java/jenkins/advancedqueue/jobinclusion/strategy/FolderPropertyLoader.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 52 is only partially covered, one branch is missing
if (incProperty.isUseJobGroup()) {
String name = incProperty.getJobGroupName();
decisionLogger.addDecisionLog(4, "JobGroup is enabled, with JobGroup [" + name + "] ...");
Expand All @@ -60,8 +58,8 @@
}
}
}
if (parent instanceof TopLevelItem) {
parent = ((TopLevelItem) parent).getParent();
if (parent instanceof TopLevelItem item) {
parent = item.getParent();
} else {
parent = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@
ListBoxModel strategies = new ListBoxModel();
for (JobGroup jobGroup : jobGroups) {
JobInclusionStrategy inclusionStrategy = jobGroup.getJobGroupStrategy();
if (inclusionStrategy instanceof PropertyBasedJobInclusionStrategy) {
strategies.add(((PropertyBasedJobInclusionStrategy) inclusionStrategy).getName());
if (inclusionStrategy instanceof PropertyBasedJobInclusionStrategy strategy) {

Check warning on line 128 in src/main/java/jenkins/advancedqueue/jobinclusion/strategy/PropertyBasedJobInclusionStrategy.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 128 is only partially covered, one branch is missing
strategies.add(strategy.getName());
}
}
return strategies;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@
private void addViews(String parent, ListBoxModel items, Collection<View> views) {
for (View view : views) {
items.add(parent + view.getDisplayName(), parent + view.getViewName());
if (view instanceof ViewGroup) {
addViews(parent + view.getDisplayName() + "/", items, ((ViewGroup) view).getViews());
if (view instanceof ViewGroup group) {
addViews(parent + view.getDisplayName() + "/", items, group.getViews());

Check warning on line 72 in src/main/java/jenkins/advancedqueue/jobinclusion/strategy/ViewBasedJobInclusionStrategy.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 71-72 are not covered by tests
}
}
}
Expand Down Expand Up @@ -203,8 +203,8 @@
return true;
}
// Then try to iterate over the ViewGroup (Nested View)
if (view instanceof ViewGroup) {
return isJobInViewGroup(job, (ViewGroup) view);
if (view instanceof ViewGroup group) {
return isJobInViewGroup(job, group);
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@

@CheckForNull
private Integer getPriorityInternal(Queue.Item item) {
if (item != null && item.task instanceof Job<?, ?>) {
Job<?, ?> job = (Job<?, ?>) item.task;
if (item != null && item.task instanceof Job<?, ?> job) {

Check warning on line 54 in src/main/java/jenkins/advancedqueue/priority/strategy/JobPropertyStrategy.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 54 is only partially covered, one branch is missing
PriorityJobProperty priorityProperty = job.getProperty(PriorityJobProperty.class);
if (priorityProperty != null && priorityProperty.getUseJobPriority()) {
return priorityProperty.priority;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import jenkins.advancedqueue.priority.PriorityStrategy;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerRequest2;

/**
* @author Magnus Sandberg
Expand All @@ -55,7 +55,7 @@ public class PriorityJobProperty extends JobProperty<Job<?, ?>> {
public final int priority;

@Override
public JobProperty<?> reconfigure(StaplerRequest req, JSONObject form) throws FormException {
public JobProperty<?> reconfigure(StaplerRequest2 req, JSONObject form) throws FormException {
return super.reconfigure(req, form);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,21 @@
//
if (items.size() > 0 && LOGGER.isLoggable(Level.FINER)) {
StringBuilder queueStr = new StringBuilder(items.get(0).getClass().getName());
queueStr.append(" Queue:\n"
+ "+----------------------------------------------------------------------+\n"
+ "| Item Id | Job Name | Priority | Weight |\n"
+ "+----------------------------------------------------------------------+\n");
queueStr.append(
"""
Queue:
+----------------------------------------------------------------------+
| Item Id | Job Name | Priority | Weight |
+----------------------------------------------------------------------+
""");
for (Queue.NotWaitingItem item : items) {
ItemInfo itemInfo = QueueItemCache.get().getItem(item.getId());
String jobName = itemInfo.getJobName();
if (jobName.length() > 21) {
jobName = jobName.substring(0, 9) + "..." + jobName.substring(jobName.length() - 9);
}
queueStr.append(String.format(
"| %10d | %20s | %8d | %20.5f |%n",
item.getId(), jobName, itemInfo.getPriority(), itemInfo.getWeight()));
queueStr.append("| %10d | %20s | %8d | %20.5f |%n"
.formatted(item.getId(), jobName, itemInfo.getPriority(), itemInfo.getWeight()));

Check warning on line 109 in src/main/java/jenkins/advancedqueue/sorter/AdvancedQueueSorter.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 95-109 are not covered by tests
}
queueStr.append("+----------------------------------------------------------------------+");
LOGGER.log(Level.FINER, queueStr.toString());
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/jenkins/advancedqueue/sorter/ItemInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
}

public PriorityConfigurationCallback addDecisionLog(int indent, String log) {
this.decisionLog.add(String.format("%" + ((indent + 1) * 2) + "s%s", "", log));
this.decisionLog.add(("%" + ((indent + 1) * 2) + "s%s").formatted("", log));
return this;
}

Expand Down Expand Up @@ -162,8 +162,7 @@

@Override
public boolean equals(Object obj) {
if (obj instanceof ItemInfo) {
ItemInfo itemInfo = (ItemInfo) obj;
if (obj instanceof ItemInfo itemInfo) {

Check warning on line 165 in src/main/java/jenkins/advancedqueue/sorter/ItemInfo.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 165 is not covered by tests
return compareTo(itemInfo) == 0;
}
return false;
Expand All @@ -190,9 +189,8 @@
if (priorityStrategy != null) {
reason = priorityStrategy.getDescriptor().getDisplayName();
}
return String.format(
"Id: %s, JobName: %s, jobGroupId: %s, reason: %s, priority: %s, weight: %s, status: %s",
itemId, jobName, jobGroupId, reason, priority, weight, itemStatus);
return "Id: %s, JobName: %s, jobGroupId: %s, reason: %s, priority: %s, weight: %s, status: %s"
.formatted(itemId, jobName, jobGroupId, reason, priority, weight, itemStatus);
}

public String getDescisionLog() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ private void maintainCache() {
final PendingItem pi = it.next();
final Executable e = pi.workUnit.getExecutable();

if (e instanceof Run) {
startedItems.put(new StartedItem(pi.itemInfo.getJobName(), ((Run<?, ?>) e).getNumber()), pi.itemInfo);
if (e instanceof Run<?, ?> run) {
startedItems.put(new StartedItem(pi.itemInfo.getJobName(), run.getNumber()), pi.itemInfo);
it.remove();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

import edu.umd.cs.findbugs.annotations.CheckForNull;
import hudson.util.ListBoxModel;
import jakarta.servlet.ServletException;
import java.io.IOException;
import javax.servlet.ServletException;
import jenkins.advancedqueue.PrioritySorterConfiguration;
import jenkins.advancedqueue.sorter.SorterStrategy;
import jenkins.advancedqueue.sorter.SorterStrategyDescriptor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private void assertIncreasingWeight(float initialWeight) {
for (int i = 0; i < 10; ++i) {
float newWeight = new FQStrategy().getWeightToUse(1, previousWeight);
Assert.assertTrue(
String.format("New weight %s should be greater than previous weight %s", newWeight, previousWeight),
"New weight %s should be greater than previous weight %s".formatted(newWeight, previousWeight),
newWeight > previousWeight);
previousWeight = newWeight;
}
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/jenkins/advancedqueue/test/SubmitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import static org.mockito.Mockito.when;

import com.google.common.base.Charsets;
import jakarta.servlet.ServletException;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import javax.servlet.ServletException;
import jenkins.advancedqueue.JobGroup;
import jenkins.advancedqueue.PriorityConfiguration;
import jenkins.advancedqueue.jobinclusion.strategy.ViewBasedJobInclusionStrategy;
Expand All @@ -20,8 +20,8 @@
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.recipes.LocalData;
import org.kohsuke.stapler.MockStaplerRequest;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.StaplerRequest2;
import org.kohsuke.stapler.StaplerResponse2;

public class SubmitTest {

Expand All @@ -33,8 +33,8 @@ public class SubmitTest {
public void shouldGeneratePriorityConfigurationUsingDataBoundConstructor() throws IOException, ServletException {
PriorityConfiguration priorityConfiguration =
(PriorityConfiguration) j.jenkins.getDescriptor(PriorityConfiguration.class);
StaplerResponse staplerResponse = mock(StaplerResponse.class);
StaplerRequest staplerRequest = new MockStaplerRequest.MockStaplerRequestBuilder(
StaplerResponse2 staplerResponse = mock(StaplerResponse2.class);
StaplerRequest2 staplerRequest = new MockStaplerRequest.MockStaplerRequestBuilder(
j, "advanced-build-queue/priorityConfigSubmit")
.build();

Expand Down
6 changes: 3 additions & 3 deletions src/test/java/org/kohsuke/stapler/MockStaplerRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
import static org.mockito.Mockito.mock;

import edu.umd.cs.findbugs.annotations.NonNull;
import jakarta.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.jvnet.hudson.test.JenkinsRule;

public class MockStaplerRequest {
Expand Down Expand Up @@ -63,14 +63,14 @@ public MockStaplerRequestBuilder withAncestor(AncestorImpl ancestor) {
return this;
}

public StaplerRequest build() throws AssertionError {
public StaplerRequest2 build() throws AssertionError {
HttpServletRequest rawRequest = mock(HttpServletRequest.class);
return new RequestImpl(stapler != null ? stapler : getStapler(), rawRequest, ancestors, tokens);
}

private Stapler getStapler() {
final Stapler stapler = new Stapler();
stapler.setWebApp(new WebApp(r.jenkins.servletContext));
stapler.setWebApp(new WebApp(r.jenkins.getServletContext()));
return stapler;
}
}
Expand Down
Loading