Skip to content

Commit

Permalink
EE 8 to EE 9
Browse files Browse the repository at this point in the history
  • Loading branch information
basil committed May 28, 2024
1 parent 2e095e7 commit 7ab2633
Show file tree
Hide file tree
Showing 138 changed files with 4,026 additions and 583 deletions.
2 changes: 1 addition & 1 deletion core/example/src/example/Book.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package example;

import jakarta.servlet.ServletException;
import java.io.IOException;
import javax.servlet.ServletException;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;

Expand Down
2 changes: 1 addition & 1 deletion core/example/src/example/BookStore.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package example;

import jakarta.servlet.ServletException;
import java.io.IOException;
import java.util.Hashtable;
import java.util.Map;
import javax.servlet.ServletException;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;

Expand Down
4 changes: 2 additions & 2 deletions core/example/src/example/WebAppMain.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package example;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import jakarta.servlet.ServletContextEvent;
import jakarta.servlet.ServletContextListener;
import org.kohsuke.stapler.Stapler;

/**
Expand Down
18 changes: 9 additions & 9 deletions core/maven-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@
<version>1.253</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>javax.servlet.jsp.jstl-api</artifactId>
<version>1.2.1</version>
<groupId>jakarta.servlet.jsp.jstl</groupId>
<artifactId>jakarta.servlet.jsp.jstl-api</artifactId>
<version>2.0.0</version>
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>5.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.0</version>
<groupId>jakarta.servlet.jsp</groupId>
<artifactId>jakarta.servlet.jsp-api</artifactId>
<version>3.0.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion core/maven-example/src/main/java/example/Book.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package example;

import jakarta.servlet.ServletException;
import java.io.IOException;
import javax.servlet.ServletException;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;

Expand Down
2 changes: 1 addition & 1 deletion core/maven-example/src/main/java/example/BookStore.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package example;

import jakarta.servlet.ServletException;
import java.io.IOException;
import java.util.Hashtable;
import java.util.Map;
import javax.servlet.ServletException;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;

Expand Down
4 changes: 2 additions & 2 deletions core/maven-example/src/main/java/example/WebAppMain.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package example;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import jakarta.servlet.ServletContextEvent;
import jakarta.servlet.ServletContextListener;
import org.kohsuke.stapler.Stapler;

/**
Expand Down
18 changes: 12 additions & 6 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@
<artifactId>commons-io</artifactId>
<version>2.16.1</version>
</dependency>
<dependency>
<groupId>io.jenkins.servlet</groupId>
<artifactId>javax-servlet-api</artifactId>
<!-- TODO https://github.com/jenkinsci/javax-servlet-api/pull/5 -->
<version>4.0.7-rc18.81a_78f068132</version>
</dependency>
<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
Expand All @@ -65,7 +71,7 @@
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-fileupload2-javax</artifactId>
<artifactId>commons-fileupload2-jakarta-servlet5</artifactId>
<version>${commons-fileupload2.version}</version>
</dependency>
<dependency>
Expand Down Expand Up @@ -108,7 +114,7 @@
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>4.0.4</version>
<version>5.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -140,13 +146,13 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.ee8</groupId>
<artifactId>jetty-ee8-servlet</artifactId>
<groupId>org.eclipse.jetty.ee9</groupId>
<artifactId>jetty-ee9-servlet</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.ee8</groupId>
<artifactId>jetty-ee8-webapp</artifactId>
<groupId>org.eclipse.jetty.ee9</groupId>
<artifactId>jetty-ee9-webapp</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/kohsuke/stapler/AcceptHeader.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ of this software and associated documentation files (the "Software"), to deal
package org.kohsuke.stapler;

import edu.umd.cs.findbugs.annotations.Nullable;
import jakarta.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.beanutils.Converter;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/kohsuke/stapler/Ancestor.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

package org.kohsuke.stapler;

import javax.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletRequest;

/**
* Information about ancestor of the "it" node.
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/kohsuke/stapler/AncestorImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public String getRestOfUrl() {
@Override
public String getFullUrl() {
StringBuilder buf = new StringBuilder();
StaplerRequest req = Stapler.getCurrentRequest();
StaplerRequest2 req = Stapler.getCurrentRequest2();
buf.append(req.getScheme());
buf.append("://");
buf.append(req.getServerName());
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/org/kohsuke/stapler/AncestorInPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@

package org.kohsuke.stapler;

import jakarta.servlet.ServletException;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.servlet.ServletException;
import org.kohsuke.stapler.AncestorInPath.HandlerImpl;

/**
* Indicates that this parameter is injected by evaluating
* {@link StaplerRequest#findAncestorObject(Class)} with the parameter type.
* {@link StaplerRequest2#findAncestorObject(Class)} with the parameter type.
*
* @author Kohsuke Kawaguchi
*/
Expand All @@ -44,7 +44,7 @@
public @interface AncestorInPath {
class HandlerImpl extends AnnotationHandler<AncestorInPath> {
@Override
public Object parse(StaplerRequest request, AncestorInPath a, Class type, String parameterName)
public Object parse(StaplerRequest2 request, AncestorInPath a, Class type, String parameterName)
throws ServletException {
return request.findAncestorObject(type);
}
Expand Down
54 changes: 49 additions & 5 deletions core/src/main/java/org/kohsuke/stapler/AnnotationHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

package org.kohsuke.stapler;

import jakarta.servlet.ServletException;
import java.lang.annotation.Annotation;
import javax.servlet.ServletException;
import org.apache.commons.beanutils.Converter;

/**
Expand All @@ -47,10 +47,54 @@ public abstract class AnnotationHandler<T extends Annotation> {
* @param parameterName
* Name of the parameter.
*/
public abstract Object parse(StaplerRequest request, T a, Class type, String parameterName) throws ServletException;
public /* abstract */ Object parse(StaplerRequest2 request, T a, Class type, String parameterName)
throws ServletException {
if (ReflectionUtils.isOverridden(
AnnotationHandler.class,
getClass(),
"parse",
StaplerRequest.class,
Annotation.class,
Class.class,
String.class)) {
try {
return parse(StaplerRequest.fromStaplerRequest2(request), a, type, parameterName);
} catch (javax.servlet.ServletException e) {
throw e.toJakartaServletException();
}
} else {
throw new AbstractMethodError("The class " + getClass().getName() + " must override at least one of the "
+ AnnotationHandler.class.getSimpleName() + ".parse methods");
}
}

/**
* @deprecated use {@link #parse(StaplerRequest2, Annotation, Class, String)}
*/
@Deprecated
public Object parse(StaplerRequest request, T a, Class type, String parameterName)
throws javax.servlet.ServletException {
if (ReflectionUtils.isOverridden(
AnnotationHandler.class,
getClass(),
"parse",
StaplerRequest2.class,
Annotation.class,
Class.class,
String.class)) {
try {
return parse(request.toStaplerRequest2(), a, type, parameterName);
} catch (ServletException e) {
throw javax.servlet.ServletException.fromJakartaServletException(e);
}
} else {
throw new AbstractMethodError("The class " + getClass().getName() + " must override at least one of the "
+ AnnotationHandler.class.getSimpleName() + ".parse methods");
}
}

/**
* Helper method for {@link #parse(StaplerRequest, Annotation, Class, String)} to convert to the right type
* Helper method for {@link #parse(StaplerRequest2, Annotation, Class, String)} to convert to the right type
* from String.
*/
protected final Object convert(Class targetType, String value) {
Expand All @@ -62,7 +106,7 @@ protected final Object convert(Class targetType, String value) {
return converter.convert(targetType, value);
}

static Object handle(StaplerRequest request, Annotation[] annotations, String parameterName, Class targetType)
static Object handle(StaplerRequest2 request, Annotation[] annotations, String parameterName, Class targetType)
throws ServletException {
for (Annotation a : annotations) {
Class<? extends Annotation> at = a.annotationType();
Expand Down Expand Up @@ -94,7 +138,7 @@ protected AnnotationHandler computeValue(Class<?> at) {

private static final AnnotationHandler NOT_HANDLER = new AnnotationHandler() {
@Override
public Object parse(StaplerRequest request, Annotation a, Class type, String parameterName)
public Object parse(StaplerRequest2 request, Annotation a, Class type, String parameterName)
throws ServletException {
return null;
}
Expand Down
14 changes: 7 additions & 7 deletions core/src/main/java/org/kohsuke/stapler/AttributeKey.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.kohsuke.stapler;

import jakarta.servlet.ServletContext;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import java.util.UUID;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
* Type-safe attribute accessor.
Expand Down Expand Up @@ -39,15 +39,15 @@ public AttributeKey(String name) {
public abstract void remove(HttpServletRequest req);

public final T get() {
return get(Stapler.getCurrentRequest());
return get(Stapler.getCurrentRequest2());
}

public final void set(T value) {
set(Stapler.getCurrentRequest(), value);
set(Stapler.getCurrentRequest2(), value);
}

public final void remove() {
remove(Stapler.getCurrentRequest());
remove(Stapler.getCurrentRequest2());
}

/**
Expand Down Expand Up @@ -122,7 +122,7 @@ public void remove(HttpServletRequest req) {
}

private ServletContext getContext(HttpServletRequest req) {
return ((StaplerRequest) req).getServletContext();
return ((StaplerRequest2) req).getServletContext();
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Intercepts (and receives callbacks) about the JSON → object binding process.
*
* @author Kohsuke Kawaguchi
* @see StaplerRequest#setBindInterceptor(BindInterceptor)
* @see StaplerRequest2#setBindInterceptor(BindInterceptor)
* @see WebApp#bindInterceptors
*/
public class BindInterceptor {
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/kohsuke/stapler/ClassDescriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ public int compare(Method m1, Method m2) {
} else if (!m1d && m2d) {
return -1;
} else {
// Sort by string representation, so for example doFoo() is preferred to doFoo(StaplerRequest,
// StaplerResponse).
// Sort by string representation, so for example doFoo() is preferred to doFoo(StaplerRequest2,
// StaplerResponse2).
return m1.toString().compareTo(m2.toString());
}
}
Expand Down
52 changes: 52 additions & 0 deletions core/src/main/java/org/kohsuke/stapler/CompatibleFilter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.kohsuke.stapler;

import jakarta.servlet.Filter;
import jakarta.servlet.FilterChain;
import jakarta.servlet.FilterConfig;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import java.io.IOException;

public interface CompatibleFilter extends Filter {
/**
* @deprecated use {@link #init(FilterConfig)}
*/
@Deprecated
default void init(javax.servlet.FilterConfig filterConfig) throws javax.servlet.ServletException {
try {
init(filterConfig.toJakartaFilterConfig());
} catch (ServletException e) {
throw javax.servlet.ServletException.fromJakartaServletException(e);
}
}

/**
* @deprecated use {@link #doFilter(ServletRequest, ServletResponse, FilterChain)}
*/
@Deprecated
default void doFilter(
javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response,
javax.servlet.FilterChain chain)
throws IOException, javax.servlet.ServletException {
try {
if (request instanceof javax.servlet.http.HttpServletRequest
&& response instanceof javax.servlet.http.HttpServletResponse) {
javax.servlet.http.HttpServletRequest httpRequest = (javax.servlet.http.HttpServletRequest) request;
javax.servlet.http.HttpServletResponse httpResponse = (javax.servlet.http.HttpServletResponse) response;
doFilter(
httpRequest.toJakartaHttpServletRequest(),
httpResponse.toJakartaHttpServletResponse(),
chain.toJakartaFilterChain());
} else {
doFilter(
request.toJakartaServletRequest(),
response.toJakartaServletResponse(),
chain.toJakartaFilterChain());
}
} catch (ServletException e) {
throw javax.servlet.ServletException.fromJakartaServletException(e);
}
}
}
Loading

0 comments on commit 7ab2633

Please sign in to comment.