Skip to content

Commit

Permalink
Migrate from EE 8 to EE 9
Browse files Browse the repository at this point in the history
  • Loading branch information
basil committed Jan 22, 2025
1 parent 0089238 commit 5dc2223
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 22 deletions.
4 changes: 2 additions & 2 deletions plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
<dependencies>
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-2.452.x</artifactId>
<version>3696.vb_b_4e2d1a_0542</version>
<artifactId>bom-${jenkins.baseline}.x</artifactId>
<version>3850.vb_c5319efa_e29</version>
<scope>import</scope>
<type>pom</type>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.AbortException;
import hudson.Extension;
import hudson.Util;
import hudson.model.Action;
import hudson.model.Descriptor;
import hudson.model.Failure;
Expand Down Expand Up @@ -68,6 +69,7 @@
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerRequest2;
import org.kohsuke.stapler.interceptor.RequirePOST;

/**
Expand All @@ -89,7 +91,7 @@ public CpsFlowDefinition(String script) throws Descriptor.FormException {
@DataBoundConstructor
public CpsFlowDefinition(String script, boolean sandbox) throws Descriptor.FormException {
ScriptApproval.validateSandbox(sandbox);
StaplerRequest req = Stapler.getCurrentRequest();
StaplerRequest2 req = Stapler.getCurrentRequest2();
this.script = sandbox ? script : ScriptApproval.get().configuring(script, GroovyLanguage.get(),
ApprovalContext.create().withCurrentUser().withItemAsKey(req != null ? req.findAncestorObject(Item.class) : null), req == null);
this.sandbox = sandbox;
Expand Down Expand Up @@ -146,8 +148,26 @@ public static class DescriptorImpl extends FlowDefinitionDescriptor {
* @DataBoundSetters have been invoked (rather than in the @DataBoundConstructor), which is why we use Descriptor.newInstance.
*/
@Override
public FlowDefinition newInstance(@NonNull StaplerRequest2 req, @NonNull JSONObject formData) throws FormException {
if (Util.isOverridden(FlowDefinitionDescriptor.class, getClass(), "newInstance", StaplerRequest.class, JSONObject.class)) {
return newInstance(StaplerRequest.fromStaplerRequest2(req), formData);
} else {
CpsFlowDefinition cpsFlowDefinition = (CpsFlowDefinition) super.newInstance(req, formData);
return newInstanceImpl(cpsFlowDefinition, req, formData);
}
}

/**
* @deprecated use {@link #newInstance(StaplerRequest2, JSONObject)}
*/
@Deprecated
@Override
public FlowDefinition newInstance(@NonNull StaplerRequest req, @NonNull JSONObject formData) throws FormException {
CpsFlowDefinition cpsFlowDefinition = (CpsFlowDefinition) super.newInstance(req, formData);
return newInstanceImpl(cpsFlowDefinition, StaplerRequest.toStaplerRequest2(req), formData);
}

private FlowDefinition newInstanceImpl(CpsFlowDefinition cpsFlowDefinition, @NonNull StaplerRequest2 req, @NonNull JSONObject formData) {
if (!cpsFlowDefinition.sandbox && formData.get("oldScript") != null) {
String oldScript = formData.getString("oldScript");
boolean approveIfAdmin = !StringUtils.equals(oldScript, cpsFlowDefinition.script);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerRequest2;

@PersistIn(JOB)
public class CpsScmFlowDefinition extends FlowDefinition {
Expand Down Expand Up @@ -218,7 +218,7 @@ private String getFilePathSuffix() {
}

public Collection<? extends SCMDescriptor<?>> getApplicableDescriptors() {
StaplerRequest req = Stapler.getCurrentRequest();
StaplerRequest2 req = Stapler.getCurrentRequest2();
Job<?,?> job = req != null ? req.findAncestorObject(Job.class) : null;
return SCM._for(job).stream().filter(d -> !"org.jenkinsci.plugins.multiplescms.MultiSCM".equals(d.getId())).collect(Collectors.toList());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
import org.jenkinsci.plugins.workflow.flow.FlowExecution;
import org.jenkinsci.plugins.workflow.flow.FlowExecutionList;
import org.kohsuke.stapler.HttpResponses;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.StaplerRequest2;
import org.kohsuke.stapler.StaplerResponse2;
import org.kohsuke.stapler.WebMethod;

/**
Expand Down Expand Up @@ -73,7 +73,7 @@ public CpsThreadDump getThreadDump() {
return execution.getThreadDump();
}

@WebMethod(name = "program.xml") public void doProgramDotXml(StaplerRequest req, StaplerResponse rsp) throws Exception {
@WebMethod(name = "program.xml") public void doProgramDotXml(StaplerRequest2 req, StaplerResponse2 rsp) throws Exception {
Jenkins.get().checkPermission(Jenkins.ADMINISTER);
CompletableFuture<String> f = new CompletableFuture<>();
execution.runInCpsVmThread(new FutureCallback<>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
import org.kohsuke.stapler.HttpResponses;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerRequest2;

/**
* Takes a {@link Step} as configured through the UI and tries to produce equivalent Groovy code.
Expand Down Expand Up @@ -476,15 +476,15 @@ public String getSymbol() {
@Restricted(DoNotUse.class) // for stapler
public Iterable<GlobalVariable> getGlobalVariables() {
// TODO order TBD. Alphabetical? Extension.ordinal?
StaplerRequest req = Stapler.getCurrentRequest();
StaplerRequest2 req = Stapler.getCurrentRequest2();
return GlobalVariable.forJob(req != null ? req.findAncestorObject(Job.class) : null);
}

@Restricted(NoExternalUse.class)
public static final String GENERATE_URL = ACTION_URL + "/generateSnippet";

@Restricted(DoNotUse.class) // accessed via REST API
public HttpResponse doGenerateSnippet(StaplerRequest req, @QueryParameter String json) throws Exception {
public HttpResponse doGenerateSnippet(StaplerRequest2 req, @QueryParameter String json) throws Exception {
// TODO is there not an easier way to do this? Maybe Descriptor.newInstancesFromHeteroList on a one-element JSONArray?
JSONObject jsonO = JSONObject.fromObject(json);
Jenkins j = Jenkins.get();
Expand Down Expand Up @@ -532,7 +532,7 @@ public HttpResponse doGenerateSnippet(StaplerRequest req, @QueryParameter String
}

@Restricted(DoNotUse.class) // for stapler
public @CheckForNull Item getItem(StaplerRequest req) {
public @CheckForNull Item getItem(StaplerRequest2 req) {
return req.findAncestorObject(Item.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import hudson.model.Item;
import hudson.model.Job;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerRequest2;

import edu.umd.cs.findbugs.annotations.NonNull;

Expand Down Expand Up @@ -73,7 +73,7 @@ public final String getDisplayUrl() {
return "";
}

StaplerRequest req = Stapler.getCurrentRequest();
StaplerRequest2 req = Stapler.getCurrentRequest2();
if (req == null) {
return u;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
import java.util.logging.Logger;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import javax.servlet.ServletException;
import jakarta.servlet.ServletException;

import hudson.util.HttpResponses;
import jenkins.model.Jenkins;
Expand All @@ -81,11 +81,11 @@
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.AncestorInPath;
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;
import org.kohsuke.stapler.interceptor.RequirePOST;

import static javax.servlet.http.HttpServletResponse.SC_CONFLICT;
import static jakarta.servlet.http.HttpServletResponse.SC_CONFLICT;

/**
* Attached to a {@link Run} when it could be replayed with script edits.
Expand Down Expand Up @@ -215,7 +215,7 @@ private boolean isSandboxed() {

@Restricted(DoNotUse.class)
@RequirePOST
public void doRun(StaplerRequest req, StaplerResponse rsp) throws ServletException, IOException {
public void doRun(StaplerRequest2 req, StaplerResponse2 rsp) throws ServletException, IOException {
if (!isEnabled() || !(isReplayableSandboxTest())) {
throw new AccessDeniedException("not allowed to replay"); // AccessDeniedException2 requires us to look up the specific Permission
}
Expand All @@ -235,7 +235,7 @@ public void doRun(StaplerRequest req, StaplerResponse rsp) throws ServletExcepti

@Restricted(DoNotUse.class)
@RequirePOST
public void doRebuild(StaplerRequest req, StaplerResponse rsp) throws ServletException, IOException {
public void doRebuild(StaplerRequest2 req, StaplerResponse2 rsp) throws ServletException, IOException {
if (!isRebuildEnabled()) {
throw new AccessDeniedException("not allowed to replay"); // AccessDeniedException2 requires us to look up the specific Permission
}
Expand Down
6 changes: 4 additions & 2 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.5</version>
<relativePath/>
</parent>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
Expand Down Expand Up @@ -41,7 +41,9 @@
<properties>
<changelist>999999-SNAPSHOT</changelist>
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>
<jenkins.version>2.452.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>
<groovy.version>2.4.21</groovy.version> <!-- TODO: Add org.codehaus.groovy:groovy and org.codehaus.groovy:groovy:sources to Jenkins core BOM so this can be deleted? (currently it only specifies groovy-all) -->
</properties>
<modules>
Expand Down

0 comments on commit 5dc2223

Please sign in to comment.