Skip to content

Commit

Permalink
Migrate from EE 8 to EE 9 (#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
basil authored Jan 20, 2025
1 parent ae46145 commit bae458a
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 50 deletions.
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.87</version>
<version>5.5</version>
<relativePath />
</parent>

Expand All @@ -31,8 +31,8 @@
<changelist>999999-SNAPSHOT</changelist>
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>
<!-- https://www.jenkins.io/doc/developer/plugin-development/choosing-jenkins-baseline/ -->
<jenkins.baseline>2.414</jenkins.baseline>
<jenkins.version>${jenkins.baseline}.3</jenkins.version>
<jenkins.baseline>2.479</jenkins.baseline>
<jenkins.version>${jenkins.baseline}.1</jenkins.version>
<hpi.compatibleSinceVersion>2.15</hpi.compatibleSinceVersion>
<!-- Needed to use Jenkins.MANAGE -->
<useBeta>true</useBeta>
Expand Down Expand Up @@ -60,7 +60,7 @@
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-${jenkins.baseline}.x</artifactId>
<version>2982.vdce2153031a_0</version>
<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 @@ -9,10 +9,10 @@
import org.kohsuke.stapler.HttpResponses;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerProxy;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.StaplerRequest2;
import org.kohsuke.stapler.StaplerResponse2;

import javax.servlet.ServletException;
import jakarta.servlet.ServletException;
import java.io.IOException;

/**
Expand Down Expand Up @@ -47,7 +47,7 @@ public Object getTarget() {
return this;
}

public void doShow(StaplerRequest req, StaplerResponse rsp, @QueryParameter("id") String fileId, @AncestorInPath ItemGroup group) throws IOException, ServletException {
public void doShow(StaplerRequest2 req, StaplerResponse2 rsp, @QueryParameter("id") String fileId, @AncestorInPath ItemGroup group) throws IOException, ServletException {
Config config = ConfigFiles.getByIdOrNull(group, fileId);
if (config != null) {
req.setAttribute("contentType", config.getProvider().getContentType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ of this software and associated documentation files (the "Software"), to deal
import java.io.IOException;
import java.util.*;

import javax.servlet.ServletException;
import jakarta.servlet.ServletException;

import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
Expand All @@ -46,8 +46,8 @@ of this software and associated documentation files (the "Software"), to deal
import org.kohsuke.stapler.HttpResponse;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerProxy;
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 org.kohsuke.stapler.verb.POST;

Expand Down Expand Up @@ -155,7 +155,7 @@ public Collection<Config> getConfigs() {
* @return
*/
@POST
public HttpResponse doSaveConfig(StaplerRequest req) {
public HttpResponse doSaveConfig(StaplerRequest2 req) {
// permission handled in getTarget
try {
JSONObject json = req.getSubmittedForm().getJSONObject("config");
Expand All @@ -174,7 +174,7 @@ public HttpResponse doSaveConfig(StaplerRequest req) {
return new HttpRedirect("index");
}

public void doShow(StaplerRequest req, StaplerResponse rsp, @QueryParameter("id") String configId) throws IOException, ServletException {
public void doShow(StaplerRequest2 req, StaplerResponse2 rsp, @QueryParameter("id") String configId) throws IOException, ServletException {
// permission handled in getTarget

Config config = store.getById(configId);
Expand All @@ -192,7 +192,7 @@ public void doShow(StaplerRequest req, StaplerResponse rsp, @QueryParameter("id"
* @throws IOException
* @throws ServletException
*/
public void doEditConfig(StaplerRequest req, StaplerResponse rsp, @QueryParameter("id") String configId) throws IOException, ServletException {
public void doEditConfig(StaplerRequest2 req, StaplerResponse2 rsp, @QueryParameter("id") String configId) throws IOException, ServletException {
// permission handled in getTarget

Config config = store.getById(configId);
Expand All @@ -212,7 +212,7 @@ public void doEditConfig(StaplerRequest req, StaplerResponse rsp, @QueryParamete
* @throws ServletException
*/
@POST
public void doAddConfig(StaplerRequest req, StaplerResponse rsp, @QueryParameter("providerId") String providerId, @QueryParameter("configId") String configId) throws IOException, ServletException {
public void doAddConfig(StaplerRequest2 req, StaplerResponse2 rsp, @QueryParameter("providerId") String providerId, @QueryParameter("configId") String configId) throws IOException, ServletException {
// permission handled in getTarget

FormValidation error = null;
Expand Down Expand Up @@ -254,7 +254,7 @@ public void doAddConfig(StaplerRequest req, StaplerResponse rsp, @QueryParameter
req.getView(this, JELLY_RESOURCES_PATH + "edit.jelly").forward(req, rsp);
}

public void doSelectProvider(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
public void doSelectProvider(StaplerRequest2 req, StaplerResponse2 rsp) throws IOException, ServletException {
// permission handled in getTarget
req.setAttribute("providers", ConfigProvider.all());
req.setAttribute("configId", UUID.randomUUID().toString());
Expand All @@ -275,7 +275,7 @@ private void checkPermission(Permission permission) {
* @throws IOException
*/
@RequirePOST
public HttpResponse doRemoveConfig(StaplerRequest res, StaplerResponse rsp, @QueryParameter("id") String configId) throws IOException {
public HttpResponse doRemoveConfig(StaplerRequest2 res, StaplerResponse2 rsp, @QueryParameter("id") String configId) throws IOException {
// permission handled in getTarget

store.remove(configId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ of this software and associated documentation files (the "Software"), to deal
import org.jenkinsci.lib.configprovider.model.ContentType;
import org.kohsuke.stapler.*;

import javax.servlet.ServletException;
import jakarta.servlet.ServletException;
import java.io.IOException;
import java.util.*;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -60,9 +60,9 @@ public interface ConfigFilesUIContract {
* @param req request
* @return
*/
public HttpResponse doSaveConfig(StaplerRequest req) throws IOException, ServletException ;
public HttpResponse doSaveConfig(StaplerRequest2 req) throws IOException, ServletException ;

public void doShow(StaplerRequest req, StaplerResponse rsp, @QueryParameter("id") String configId) throws IOException, ServletException;
public void doShow(StaplerRequest2 req, StaplerResponse2 rsp, @QueryParameter("id") String configId) throws IOException, ServletException;

/**
* Loads the config by its id and forwards the request to "edit.jelly".
Expand All @@ -76,7 +76,7 @@ public interface ConfigFilesUIContract {
* @throws IOException
* @throws ServletException
*/
public void doEditConfig(StaplerRequest req, StaplerResponse rsp, @QueryParameter("id") String configId) throws IOException, ServletException;
public void doEditConfig(StaplerRequest2 req, StaplerResponse2 rsp, @QueryParameter("id") String configId) throws IOException, ServletException;

/**
* Requests a new config object from provider (defined by the given id) and forwards the request to "edit.jelly".
Expand All @@ -92,9 +92,9 @@ public interface ConfigFilesUIContract {
* @throws IOException
* @throws ServletException
*/
public void doAddConfig(StaplerRequest req, StaplerResponse rsp, @QueryParameter("providerId") String providerId, @QueryParameter("configId") String configId) throws IOException, ServletException;
public void doAddConfig(StaplerRequest2 req, StaplerResponse2 rsp, @QueryParameter("providerId") String providerId, @QueryParameter("configId") String configId) throws IOException, ServletException;

public void doSelectProvider(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException;
public void doSelectProvider(StaplerRequest2 req, StaplerResponse2 rsp) throws IOException, ServletException;

/**
* Removes a script from the config and filesystem.
Expand All @@ -108,7 +108,7 @@ public interface ConfigFilesUIContract {
* @return forward to 'index'
* @throws IOException
*/
public HttpResponse doRemoveConfig(StaplerRequest res, StaplerResponse rsp, @QueryParameter("id") String configId) throws IOException;
public HttpResponse doRemoveConfig(StaplerRequest2 res, StaplerResponse2 rsp, @QueryParameter("id") String configId) throws IOException;

public FormValidation doCheckConfigId(@QueryParameter("configId") String configId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public ListBoxModel doFillFileIdItems(@AncestorInPath ItemGroup context, @Ancest
* @param fileId the id of the config file
* @return a validation result / description
*/
public HttpResponse doCheckFileId(StaplerRequest req, @AncestorInPath Item context, @AncestorInPath AccessControlled ac, @QueryParameter String fileId) {
public HttpResponse doCheckFileId(StaplerRequest2 req, @AncestorInPath Item context, @AncestorInPath AccessControlled ac, @QueryParameter String fileId) {
// You should have permission to configure your project in order to check whether the selected file id is
// allowed to you
if (context != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.util.Map;
import java.util.UUID;

import javax.servlet.ServletException;
import jakarta.servlet.ServletException;

import org.jenkinsci.lib.configprovider.ConfigProvider;
import org.jenkinsci.lib.configprovider.model.Config;
Expand All @@ -23,8 +23,8 @@
import org.kohsuke.stapler.HttpResponse;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerProxy;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.StaplerRequest2;
import org.kohsuke.stapler.StaplerResponse2;

import hudson.Extension;
import hudson.Util;
Expand Down Expand Up @@ -116,7 +116,7 @@ public List<ConfigProvider> getProviders() {

@Override
@POST
public HttpResponse doSaveConfig(StaplerRequest req) throws IOException, ServletException {
public HttpResponse doSaveConfig(StaplerRequest2 req) throws IOException, ServletException {
checkPermission(Item.CONFIGURE);
try {
JSONObject json = req.getSubmittedForm().getJSONObject("config");
Expand Down Expand Up @@ -155,7 +155,7 @@ ConfigFileStore getStore() {
}

@Override
public void doShow(StaplerRequest req, StaplerResponse rsp, @QueryParameter("id") String configId) throws IOException, ServletException {
public void doShow(StaplerRequest2 req, StaplerResponse2 rsp, @QueryParameter("id") String configId) throws IOException, ServletException {
folder.checkPermission(Item.EXTENDED_READ);
Config config = getStore().getById(configId);
req.setAttribute("contentType", config.getProvider().getContentType());
Expand All @@ -164,7 +164,7 @@ public void doShow(StaplerRequest req, StaplerResponse rsp, @QueryParameter("id"
}

@Override
public void doEditConfig(StaplerRequest req, StaplerResponse rsp, @QueryParameter("id") String configId) throws IOException, ServletException {
public void doEditConfig(StaplerRequest2 req, StaplerResponse2 rsp, @QueryParameter("id") String configId) throws IOException, ServletException {
checkPermission(Job.CONFIGURE);
Config config = getStore().getById(configId);
req.setAttribute("contentType", config.getProvider().getContentType());
Expand All @@ -176,7 +176,7 @@ public void doEditConfig(StaplerRequest req, StaplerResponse rsp, @QueryParamete

@Override
@POST
public void doAddConfig(StaplerRequest req, StaplerResponse rsp, @QueryParameter("providerId") String providerId, @QueryParameter("configId") String configId) throws IOException, ServletException {
public void doAddConfig(StaplerRequest2 req, StaplerResponse2 rsp, @QueryParameter("providerId") String providerId, @QueryParameter("configId") String configId) throws IOException, ServletException {
checkPermission(Item.CONFIGURE);

FormValidation error = null;
Expand Down Expand Up @@ -219,7 +219,7 @@ public void doAddConfig(StaplerRequest req, StaplerResponse rsp, @QueryParameter
}

@Override
public void doSelectProvider(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
public void doSelectProvider(StaplerRequest2 req, StaplerResponse2 rsp) throws IOException, ServletException {
checkPermission(Job.CONFIGURE);
req.setAttribute("providers", getProviders());
req.setAttribute("configId", UUID.randomUUID().toString());
Expand All @@ -228,7 +228,7 @@ public void doSelectProvider(StaplerRequest req, StaplerResponse rsp) throws IOE

@RequirePOST
@Override
public HttpResponse doRemoveConfig(StaplerRequest res, StaplerResponse rsp, @QueryParameter("id") String configId) throws IOException {
public HttpResponse doRemoveConfig(StaplerRequest2 res, StaplerResponse2 rsp, @QueryParameter("id") String configId) throws IOException {
checkPermission(Job.CONFIGURE);

getStore().remove(configId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.jenkinsci.plugins.configfiles.ConfigFileStore;
import org.jenkinsci.plugins.configfiles.ConfigProviderComparator;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerRequest2;

import java.io.IOException;
import java.util.*;
Expand Down Expand Up @@ -123,7 +123,7 @@ private Object readResolve() {
return this;
}

public FolderConfigFileProperty reconfigure(StaplerRequest req, JSONObject form) throws Descriptor.FormException {
public FolderConfigFileProperty reconfigure(StaplerRequest2 req, JSONObject form) throws Descriptor.FormException {
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
import hudson.model.Item;
import jenkins.model.Jenkins;
import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerRequest2;

public class ConfigFileDetailLinkDescription extends DescriptionResponse {
private ConfigFileDetailLinkDescription(String linkHtml) {
super(linkHtml);
}

public static ConfigFileDetailLinkDescription getDescription(StaplerRequest req, Item context, String fileId) {
public static ConfigFileDetailLinkDescription getDescription(StaplerRequest2 req, Item context, String fileId) {
return new ConfigFileDetailLinkDescription(getDetailsLink(req, context, fileId));
}

private static String getDetailsLink(StaplerRequest req, Item context, String fileId) {
private static String getDetailsLink(StaplerRequest2 req, Item context, String fileId) {
String link = req.getContextPath();
link = StringUtils.isNotBlank(context.getUrl()) ? link + "/" + context.getUrl() : link;
link = link + "configfiles/show?id=" + fileId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import hudson.util.FormValidation;
import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.HttpResponse;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.StaplerRequest2;
import org.kohsuke.stapler.StaplerResponse2;

import javax.servlet.ServletException;
import jakarta.servlet.ServletException;
import java.io.IOException;

/**
Expand All @@ -24,7 +24,7 @@ public DescriptionResponse(String html) {
}

@Override
public void generateResponse(StaplerRequest req, StaplerResponse rsp, Object node) throws IOException, ServletException {
public void generateResponse(StaplerRequest2 req, StaplerResponse2 rsp, Object node) throws IOException, ServletException {
rsp.setContentType("text/html;charset=UTF-8");
rsp.getWriter().print(html);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.MockAuthorizationStrategy;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerRequest2;

import jakarta.inject.Inject;
import java.io.IOException;
Expand Down Expand Up @@ -85,7 +85,7 @@ public void managedFileDoFillFiledIdItemsProtected() {
}

/**
* The {@link ManagedFile.DescriptorImpl#doCheckFileId(StaplerRequest, Item, AccessControlled, String)} is only accessible by people
* The {@link ManagedFile.DescriptorImpl#doCheckFileId(StaplerRequest2, Item, AccessControlled, String)} is only accessible by people
* able to configure the job.
*/
@Issue("SECURITY-2203")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.htmlunit.html.HtmlAnchor;
import org.htmlunit.html.HtmlElement;
import org.htmlunit.html.HtmlPage;
import hudson.model.Descriptor;
import hudson.model.Item;
import hudson.util.VersionNumber;
import jenkins.model.Jenkins;
Expand Down Expand Up @@ -298,7 +299,7 @@ public void folderCheckConfigIdProtected() throws Exception {
MatcherAssert.assertThat(page, notNullValue());
}

private CpsFlowDefinition getNewJobDefinition() {
private CpsFlowDefinition getNewJobDefinition() throws Descriptor.FormException {
return new CpsFlowDefinition("" +
"node {\n" +
" configFileProvider([configFile(fileId: 'my-file-id', variable: 'MY_FILE')]) {\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import hudson.Launcher;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
import hudson.model.Descriptor;
import hudson.model.Computer;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
Expand Down Expand Up @@ -79,14 +80,14 @@ public void assertNoSecretPatternOnControllerLog(Computer computer) throws IOExc
assertThat(computer.getLog(), not(containsString("An agent attempted to look up secret patterns from the controller")));
}

private UsernamePasswordCredentialsImpl createCredential(String id, String username, String password) {
private UsernamePasswordCredentialsImpl createCredential(String id, String username, String password) throws Descriptor.FormException {
UsernamePasswordCredentialsImpl credentials = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, id, "", username, password);
credentials.setUsernameSecret(true);
SystemCredentialsProvider.getInstance().getCredentials().add(credentials);
return credentials;
}
@Before
public void before() {
public void before() throws Exception {
GlobalConfigFiles.get().save(new MavenSettingsConfig("m2settings", "m2settings", "", "<settings/>", true,
Collections.singletonList(new ServerCredentialMapping("myserver", createCredential("creds", "bot-user-name", "bot-user-s3cr3t").getId()))));
GlobalConfigFiles.get().save(new GlobalMavenSettingsConfig("m2GlobalSettings", "m2GlobalSettings", "", "<settings/>", true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.MockAuthorizationStrategy;

import java.io.IOException;
import java.util.function.Supplier;

import static org.hamcrest.MatcherAssert.assertThat;
Expand All @@ -45,7 +44,7 @@ public class Security2254Test {
private Folder folder;

@Before
public void setUpAuthorizationAndProject() throws IOException {
public void setUpAuthorizationAndProject() throws Exception {
// A folder and a project inside
folder = r.jenkins.createProject(Folder.class, "f");
project = folder.createProject(WorkflowJob.class, "p");
Expand Down

0 comments on commit bae458a

Please sign in to comment.