From 8e3bc788f0a6f1f0a1d966de9635a2aabaa99ad8 Mon Sep 17 00:00:00 2001 From: Basil Crow Date: Wed, 9 Oct 2024 16:59:16 -0700 Subject: [PATCH] Require Java 17 or newer; migrate to EE 9 (#282) --- docs/implementation.adoc | 2 +- pom.xml | 8 ++++---- src/main/java/jenkins/scm/api/SCMEvent.java | 19 +++++++++++++++---- .../api/metadata/AvatarMetadataAction.java | 4 ++-- .../jenkins/scm/impl/avatars/AvatarCache.java | 16 ++++++++-------- .../java/jenkins/scm/api/SCMEventTest.java | 5 +++-- 6 files changed, 33 insertions(+), 21 deletions(-) diff --git a/docs/implementation.adoc b/docs/implementation.adoc index 78e44c70..23d5a434 100644 --- a/docs/implementation.adoc +++ b/docs/implementation.adoc @@ -1393,7 +1393,7 @@ public class MySCMWebHook implements UnprotectedRootAction { } @RequirePOST - public HttpResponse doNotify(StaplerRequest req) { + public HttpResponse doNotify(StaplerRequest2 req) { // check if the event payload at least provides some proof of origin // this may be a query parameter or a HTTP header // if the proof of origin is missing, drop the event on the floor and return diff --git a/pom.xml b/pom.xml index e9577463..a1c863a9 100644 --- a/pom.xml +++ b/pom.xml @@ -29,7 +29,7 @@ org.jenkins-ci.plugins plugin - 4.88 + 5.1 @@ -56,7 +56,7 @@ 999999-SNAPSHOT - 2.426.3 + 2.479 jenkinsci/${project.artifactId}-plugin false 2.0.0 @@ -79,8 +79,8 @@ io.jenkins.tools.bom - bom-2.426.x - 2839.v003b_4d9d24fd + bom-2.462.x + 3435.v238d66a_043fb_ import pom diff --git a/src/main/java/jenkins/scm/api/SCMEvent.java b/src/main/java/jenkins/scm/api/SCMEvent.java index 4bd70509..26795082 100644 --- a/src/main/java/jenkins/scm/api/SCMEvent.java +++ b/src/main/java/jenkins/scm/api/SCMEvent.java @@ -45,7 +45,8 @@ import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; -import javax.servlet.http.HttpServletRequest; +import io.jenkins.servlet.http.HttpServletRequestWrapper; +import jakarta.servlet.http.HttpServletRequest; import jenkins.security.ImpersonatingScheduledExecutorService; import jenkins.util.SystemProperties; import org.apache.commons.lang.StringUtils; @@ -151,7 +152,7 @@ public abstract class SCMEvent

{ */ @Deprecated public SCMEvent(@NonNull Type type, long timestamp, @NonNull P payload) { - this(type, timestamp, payload, originOf(Stapler.getCurrentRequest())); + this(type, timestamp, payload, originOf(Stapler.getCurrentRequest2())); } /** @@ -398,9 +399,9 @@ public String toString() { * {@code →} followed by a {@code ⇒} and finally the requested URL (omitting the query portion of the URL). * * @param req the {@link HttpServletRequest} or {@code null} (this is to allow passing - * {@link Stapler#getCurrentRequest()} without having to check for {@code null}) + * {@link Stapler#getCurrentRequest2()} without having to check for {@code null}) * @return the origin of the event or {@code null} if the {@link HttpServletRequest} is null. - * @since 2.0.3 + * @since TODO */ @CheckForNull public static String originOf(@CheckForNull HttpServletRequest req) { @@ -460,6 +461,16 @@ public static String originOf(@CheckForNull HttpServletRequest req) { return result.toString(); } + /** + * @deprecated use {@link #originOf(HttpServletRequest)} + * @since 2.0.3 + */ + @CheckForNull + @Deprecated + public static String originOf(@CheckForNull javax.servlet.http.HttpServletRequest req) { + return req != null ? originOf(HttpServletRequestWrapper.toJakartaHttpServletRequest(req)) : null; + } + /** * The type of event. */ diff --git a/src/main/java/jenkins/scm/api/metadata/AvatarMetadataAction.java b/src/main/java/jenkins/scm/api/metadata/AvatarMetadataAction.java index 0650da60..0a501423 100644 --- a/src/main/java/jenkins/scm/api/metadata/AvatarMetadataAction.java +++ b/src/main/java/jenkins/scm/api/metadata/AvatarMetadataAction.java @@ -40,7 +40,7 @@ import org.jenkins.ui.icon.IconSet; import org.jenkins.ui.icon.IconSpec; import org.kohsuke.stapler.Stapler; -import org.kohsuke.stapler.StaplerRequest; +import org.kohsuke.stapler.StaplerRequest2; import org.kohsuke.stapler.export.ExportedBean; /** @@ -133,7 +133,7 @@ protected final String avatarIconClassNameImageOf(@CheckForNull String iconClass Icon icon = IconSet.icons.getIconByClassSpec(iconClassName + " " + spec); if (icon != null) { JellyContext ctx = new JellyContext(); - StaplerRequest currentRequest = Stapler.getCurrentRequest(); + StaplerRequest2 currentRequest = Stapler.getCurrentRequest2(); if (currentRequest == null) { throw new IllegalStateException( "cannot call avatarIconClassNameImageOf from outside a request handling thread" diff --git a/src/main/java/jenkins/scm/impl/avatars/AvatarCache.java b/src/main/java/jenkins/scm/impl/avatars/AvatarCache.java index 65296827..66586c49 100644 --- a/src/main/java/jenkins/scm/impl/avatars/AvatarCache.java +++ b/src/main/java/jenkins/scm/impl/avatars/AvatarCache.java @@ -56,15 +56,15 @@ import java.util.concurrent.TimeUnit; import java.util.logging.Logger; import javax.imageio.ImageIO; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletResponse; import jenkins.model.Jenkins; import org.apache.commons.lang.StringUtils; import org.kohsuke.stapler.HttpResponse; 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 static java.awt.RenderingHints.KEY_ALPHA_INTERPOLATION; import static java.awt.RenderingHints.KEY_INTERPOLATION; @@ -305,7 +305,7 @@ public String getUrlName() { * @param size the requested size (defaults to {@code 48x48} if unspecified). * @return the response. */ - public HttpResponse doDynamic(StaplerRequest req, @QueryParameter String size) { + public HttpResponse doDynamic(StaplerRequest2 req, @QueryParameter String size) { if (StringUtils.isBlank(req.getRestOfPath())) { return HttpResponses.notFound(); } @@ -337,7 +337,7 @@ public HttpResponse doDynamic(StaplerRequest req, @QueryParameter String size) { if (startedTime <= since) { return new HttpResponse() { @Override - public void generateResponse(StaplerRequest req, StaplerResponse rsp, Object node) + public void generateResponse(StaplerRequest2 req, StaplerResponse2 rsp, Object node) throws IOException, ServletException { rsp.addDateHeader("Last-Modified", startedTime); rsp.addHeader("Cache-control", "max-age=365000000, immutable, public"); @@ -368,7 +368,7 @@ public void generateResponse(StaplerRequest req, StaplerResponse rsp, Object nod if (avatar.lastModified <= since) { return new HttpResponse() { @Override - public void generateResponse(StaplerRequest req, StaplerResponse rsp, Object node) + public void generateResponse(StaplerRequest2 req, StaplerResponse2 rsp, Object node) throws IOException, ServletException { rsp.addDateHeader("Last-Modified", avatar.lastModified); rsp.addHeader("Cache-control", "max-age=3600, public"); @@ -570,7 +570,7 @@ private ImageResponse(BufferedImage image, boolean flushImage, long lastModified * {@inheritDoc} */ @Override - public void generateResponse(StaplerRequest req, StaplerResponse rsp, Object node) + public void generateResponse(StaplerRequest2 req, StaplerResponse2 rsp, Object node) throws IOException, ServletException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { diff --git a/src/test/java/jenkins/scm/api/SCMEventTest.java b/src/test/java/jenkins/scm/api/SCMEventTest.java index b6c513f0..ae26a72d 100644 --- a/src/test/java/jenkins/scm/api/SCMEventTest.java +++ b/src/test/java/jenkins/scm/api/SCMEventTest.java @@ -28,12 +28,13 @@ import edu.umd.cs.findbugs.annotations.NonNull; import java.util.concurrent.BlockingQueue; import java.util.concurrent.ThreadPoolExecutor; -import javax.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletRequest; import org.junit.Test; import org.junit.experimental.theories.DataPoints; import org.junit.experimental.theories.Theories; import org.junit.experimental.theories.Theory; import org.junit.runner.RunWith; +import org.kohsuke.stapler.StaplerRequest2; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.allOf; @@ -170,7 +171,7 @@ public void usefulToString() throws Exception { @Test public void originOfNull() throws Exception { - assertThat(SCMEvent.originOf(null), is(nullValue())); + assertThat(SCMEvent.originOf((StaplerRequest2) null), is(nullValue())); } @Test