From 48b338d214fd3cf617cc7acf8040d61ebd7bb2b8 Mon Sep 17 00:00:00 2001 From: Basil Crow Date: Wed, 13 Nov 2024 13:19:22 -0800 Subject: [PATCH] Migrate to Jakarta EE 9 (#49) --- pom.xml | 5 +++-- .../plugins/nested_view/NestedView.java | 20 +++++++++---------- .../nested_view/NestedViewColumns.java | 4 ++-- .../nested_view/NestedViewGlobalConfig.java | 4 ++-- .../nested_view/NestedViewsSearch.java | 12 +++++------ .../nested_view/NestedViewsSearchFactory.java | 8 ++++---- .../plugins/nested_view/NestedViewTest.java | 3 ++- 7 files changed, 29 insertions(+), 27 deletions(-) diff --git a/pom.xml b/pom.xml index 935514f..3e0ac7c 100644 --- a/pom.xml +++ b/pom.xml @@ -3,13 +3,14 @@ org.jenkins-ci.plugins plugin - 4.86 + 5.2 1.36 -SNAPSHOT - 2.440.3 + 2.479 + ${jenkins.baseline}.1 jenkinsci/${project.artifactId}-plugin diff --git a/src/main/java/hudson/plugins/nested_view/NestedView.java b/src/main/java/hudson/plugins/nested_view/NestedView.java index aa233f1..809d858 100644 --- a/src/main/java/hudson/plugins/nested_view/NestedView.java +++ b/src/main/java/hudson/plugins/nested_view/NestedView.java @@ -60,7 +60,7 @@ import org.kohsuke.stapler.export.Exported; import hudson.security.Permission; -import javax.servlet.ServletException; +import jakarta.servlet.ServletException; import java.io.IOException; import java.util.*; import java.util.concurrent.CopyOnWriteArrayList; @@ -126,12 +126,12 @@ public boolean contains(TopLevelItem item) { } @Override - public ContextMenu doContextMenu(StaplerRequest request, StaplerResponse response) throws IOException, JellyException { + public ContextMenu doContextMenu(StaplerRequest2 request, StaplerResponse2 response) throws IOException, JellyException { return new ContextMenu().from(this, request, response); } @Override - public ContextMenu doChildrenContextMenu(StaplerRequest request, StaplerResponse response) throws Exception { + public ContextMenu doChildrenContextMenu(StaplerRequest2 request, StaplerResponse2 response) throws Exception { ContextMenu menu = new ContextMenu(); for (View view : getViews()) { menu.add(new MenuItem().withContextRelativeUrl(view.getUrl()).withDisplayName(view.getDisplayName())); @@ -160,7 +160,7 @@ public List getViewActions() { } @Override - public Item doCreateItem(StaplerRequest req, StaplerResponse rsp) + public Item doCreateItem(StaplerRequest2 req, StaplerResponse2 rsp) throws IOException, ServletException { ItemGroup itemGroup = getItemGroup(); if (itemGroup instanceof ModifiableItemGroup) { @@ -212,7 +212,7 @@ public synchronized void onJobRenamed(Item item, String oldName, String newName) v.onJobRenamed(item, oldName, newName); } - protected synchronized void submit(StaplerRequest req) throws IOException, ServletException, FormException { + protected synchronized void submit(StaplerRequest2 req) throws IOException, ServletException, FormException { defaultView = Util.fixEmpty(req.getParameter("defaultView")); if (columns == null) { columns = new NestedViewColumns(); @@ -275,7 +275,7 @@ public void save() throws IOException { } } - public void doCreateView(StaplerRequest req, StaplerResponse rsp) + public void doCreateView(StaplerRequest2 req, StaplerResponse2 rsp) throws IOException, ServletException, FormException { checkPermission(View.CREATE); addView(View.create(req, rsp, this)); @@ -470,11 +470,11 @@ public HealthReportContainer getHealth() { @Override @WebMethod(name = "config.xml") - public HttpResponse doConfigDotXml(StaplerRequest req) throws IOException { + public HttpResponse doConfigDotXml(StaplerRequest2 req) throws IOException { if (req.getMethod().equals("GET")) { checkPermission(READ); return new HttpResponse() { - 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("application/xml"); XStream2 xStream2 = new XStream2(); @@ -596,12 +596,12 @@ public List getBuildHealthReports() { public Object getTarget() { // Proxy to handle redirect when a default subview is configured return (getDefaultView() != null && - "".equals(Stapler.getCurrentRequest().getRestOfPath())) + "".equals(Stapler.getCurrentRequest2().getRestOfPath())) ? new DefaultViewProxy() : this; } public class DefaultViewProxy { - public void doIndex(StaplerRequest req, StaplerResponse rsp) + public void doIndex(StaplerRequest2 req, StaplerResponse2 rsp) throws IOException, ServletException { if (getDefaultView() != null) rsp.sendRedirect2("view/" + defaultView); diff --git a/src/main/java/hudson/plugins/nested_view/NestedViewColumns.java b/src/main/java/hudson/plugins/nested_view/NestedViewColumns.java index 34c926f..a9249a3 100644 --- a/src/main/java/hudson/plugins/nested_view/NestedViewColumns.java +++ b/src/main/java/hudson/plugins/nested_view/NestedViewColumns.java @@ -10,7 +10,7 @@ import hudson.views.WeatherColumn; import jenkins.model.Jenkins; import net.sf.json.JSONObject; -import org.kohsuke.stapler.StaplerRequest; +import org.kohsuke.stapler.StaplerRequest2; import java.io.IOException; import java.util.List; @@ -23,7 +23,7 @@ public class NestedViewColumns { private DescribableList> columns; - public void updateFromForm(StaplerRequest req, JSONObject formData, String key) throws IOException, Descriptor.FormException { + public void updateFromForm(StaplerRequest2 req, JSONObject formData, String key) throws IOException, Descriptor.FormException { columns.rebuildHetero(req, formData, getPossibleColumns(), key); } diff --git a/src/main/java/hudson/plugins/nested_view/NestedViewGlobalConfig.java b/src/main/java/hudson/plugins/nested_view/NestedViewGlobalConfig.java index 027ec66..62ef51c 100644 --- a/src/main/java/hudson/plugins/nested_view/NestedViewGlobalConfig.java +++ b/src/main/java/hudson/plugins/nested_view/NestedViewGlobalConfig.java @@ -4,7 +4,7 @@ import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.DataBoundSetter; -import org.kohsuke.stapler.StaplerRequest; +import org.kohsuke.stapler.StaplerRequest2; import java.util.logging.Logger; @@ -69,7 +69,7 @@ public NestedViewGlobalConfig() { @Override - public boolean configure(StaplerRequest req, JSONObject json) throws FormException { + public boolean configure(StaplerRequest2 req, JSONObject json) throws FormException { req.bindJSON(this, json); save(); return super.configure(req, json); diff --git a/src/main/java/hudson/plugins/nested_view/NestedViewsSearch.java b/src/main/java/hudson/plugins/nested_view/NestedViewsSearch.java index 23bd8d0..7c4680a 100644 --- a/src/main/java/hudson/plugins/nested_view/NestedViewsSearch.java +++ b/src/main/java/hudson/plugins/nested_view/NestedViewsSearch.java @@ -15,11 +15,11 @@ import jenkins.model.Jenkins; 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 javax.servlet.RequestDispatcher; -import javax.servlet.ServletException; +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletException; import java.io.IOException; import java.util.ArrayList; @@ -75,7 +75,7 @@ private void addViewsRecursively(Collection views, String s, List(); if (query != null) { @@ -129,7 +129,7 @@ public List getHistory() { } @Override - public SearchResult getSuggestions(final StaplerRequest req, @QueryParameter final String query) { + public SearchResult getSuggestions(final StaplerRequest2 req, @QueryParameter final String query) { SearchResult suggestedItems = super.getSuggestions(req, query); this.query = new Query(false, query); final Set matched = new HashSet<>(); //unusuded for suggestions diff --git a/src/main/java/hudson/plugins/nested_view/NestedViewsSearchFactory.java b/src/main/java/hudson/plugins/nested_view/NestedViewsSearchFactory.java index 61a4735..7c6c9db 100644 --- a/src/main/java/hudson/plugins/nested_view/NestedViewsSearchFactory.java +++ b/src/main/java/hudson/plugins/nested_view/NestedViewsSearchFactory.java @@ -5,10 +5,10 @@ import hudson.search.Search; import hudson.search.SearchFactory; import hudson.search.SearchableModelObject; -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; @@ -36,7 +36,7 @@ public Search createFor(final SearchableModelObject owner) { if (isTmpSkip()) { return new Search(){ @Override - public void doIndex(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { + public void doIndex(StaplerRequest2 req, StaplerResponse2 rsp) throws IOException, ServletException { //we have to reset it only in search, not during suggestions super.doIndex(req, rsp); resetTmpSkip(); diff --git a/src/test/java/hudson/plugins/nested_view/NestedViewTest.java b/src/test/java/hudson/plugins/nested_view/NestedViewTest.java index 70855bd..401c74c 100644 --- a/src/test/java/hudson/plugins/nested_view/NestedViewTest.java +++ b/src/test/java/hudson/plugins/nested_view/NestedViewTest.java @@ -44,6 +44,7 @@ import static hudson.util.FormValidation.Kind.*; +import jakarta.servlet.ServletRequest; import java.io.IOException; import java.net.URL; import java.util.List; @@ -176,7 +177,7 @@ public void testUploadXml() throws Exception { // First try creating a clone of this view (Jenkins.doCreateView → View.create → View.createViewFromXML): // TODO wc.createCrumbedUrl does not work when you are specifying your own query parameters CrumbIssuer issuer = rule.jenkins.getCrumbIssuer(); - WebRequest req = new WebRequest(new URL(rule.getURL(), "/createView?name=clone&" + issuer.getDescriptor().getCrumbRequestField() + "=" + issuer.getCrumb(null)), HttpMethod.POST); + WebRequest req = new WebRequest(new URL(rule.getURL(), "/createView?name=clone&" + issuer.getDescriptor().getCrumbRequestField() + "=" + issuer.getCrumb((ServletRequest) null)), HttpMethod.POST); req.setAdditionalHeader("Content-Type", "application/xml"); req.setRequestBody(xml); wc.getPage(req);