Skip to content

Commit

Permalink
Require Java 17 or newer; migrate to EE 9 (#282)
Browse files Browse the repository at this point in the history
  • Loading branch information
basil authored Oct 9, 2024
1 parent 739d8d3 commit 8e3bc78
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 21 deletions.
2 changes: 1 addition & 1 deletion docs/implementation.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.88</version>
<version>5.1</version>
<relativePath/>
</parent>

Expand All @@ -56,7 +56,7 @@

<properties>
<changelist>999999-SNAPSHOT</changelist>
<jenkins.version>2.426.3</jenkins.version>
<jenkins.version>2.479</jenkins.version>
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>
<no-test-jar>false</no-test-jar>
<hpi.compatibleSinceVersion>2.0.0</hpi.compatibleSinceVersion>
Expand All @@ -79,8 +79,8 @@
<dependencies>
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-2.426.x</artifactId>
<version>2839.v003b_4d9d24fd</version>
<artifactId>bom-2.462.x</artifactId>
<version>3435.v238d66a_043fb_</version>
<scope>import</scope>
<type>pom</type>
</dependency>
Expand Down
19 changes: 15 additions & 4 deletions src/main/java/jenkins/scm/api/SCMEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -151,7 +152,7 @@ public abstract class SCMEvent<P> {
*/
@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()));
}

/**
Expand Down Expand Up @@ -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

Check warning on line 404 in src/main/java/jenkins/scm/api/SCMEvent.java

View check run for this annotation

ci.jenkins.io / Open Tasks Scanner

TODO

NORMAL:
*/
@CheckForNull
public static String originOf(@CheckForNull HttpServletRequest req) {
Expand Down Expand Up @@ -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;

Check warning on line 471 in src/main/java/jenkins/scm/api/SCMEvent.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 471 is not covered by tests
}

/**
* The type of event.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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();

Check warning on line 136 in src/main/java/jenkins/scm/api/metadata/AvatarMetadataAction.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 136 is not covered by tests
if (currentRequest == null) {
throw new IllegalStateException(
"cannot call avatarIconClassNameImageOf from outside a request handling thread"
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/jenkins/scm/impl/avatars/AvatarCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions src/test/java/jenkins/scm/api/SCMEventTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8e3bc78

Please sign in to comment.