From 5db817ba6f0d84c5de5d1b09c925190a7d9aa4d7 Mon Sep 17 00:00:00 2001 From: Basil Crow Date: Tue, 17 Sep 2024 13:13:28 -0700 Subject: [PATCH] [JENKINS-73261] Drop support for Jetty 12 EE 8 in the test harness (#631) --- pom.xml | 37 +-- .../benchmark/jmh/JmhBenchmarkState.java | 68 +---- .../test/CaptureEnvironmentBuilder.java | 4 +- .../hudson/test/ClosureExecuterAction.java | 4 +- .../hudson/test/ComputerConnectorTester.java | 16 +- .../jvnet/hudson/test/CreateFileBuilder.java | 4 +- .../org/jvnet/hudson/test/FailureBuilder.java | 4 +- .../hudson/test/GroovyHudsonTestCase.java | 6 +- .../jvnet/hudson/test/GroovyJenkinsRule.java | 6 +- .../org/jvnet/hudson/test/HudsonTestCase.java | 163 ++--------- .../hudson/test/JavaNetReverseProxy.java | 100 ------- .../test/JenkinsComputerConnectorTester.java | 16 +- .../org/jvnet/hudson/test/JenkinsRecipe.java | 2 +- .../org/jvnet/hudson/test/JenkinsRule.java | 261 ++---------------- .../org/jvnet/hudson/test/MockBuilder.java | 4 +- .../org/jvnet/hudson/test/MockFolder.java | 16 +- .../test/MockQueueItemAuthenticator.java | 2 +- .../hudson/test/NoListenerConfiguration.java | 58 ---- .../jvnet/hudson/test/RealJenkinsRule.java | 16 +- .../jvnet/hudson/test/TestCrumbIssuer.java | 6 +- .../test/UnitTestSupportingPluginManager.java | 2 +- .../jvnet/hudson/test/UnstableBuilder.java | 4 +- .../hudson/test/WorkspaceCopyFileBuilder.java | 4 +- .../org/jvnet/hudson/test/recipes/Recipe.java | 2 +- src/spotbugs/excludesFilter.xml | 3 - .../main/UseRecipesWithJenkinsRuleTest.java | 2 +- .../hudson/test/RealJenkinsRuleTest.java | 12 +- 27 files changed, 113 insertions(+), 709 deletions(-) delete mode 100644 src/main/java/org/jvnet/hudson/test/JavaNetReverseProxy.java delete mode 100644 src/main/java/org/jvnet/hudson/test/NoListenerConfiguration.java diff --git a/pom.xml b/pom.xml index 44d3c369d..9e51afd64 100644 --- a/pom.xml +++ b/pom.xml @@ -56,7 +56,7 @@ THE SOFTWARE. 999999-SNAPSHOT - 2.463 + 2.476 1.37 jenkinsci/${project.artifactId} @@ -73,13 +73,6 @@ THE SOFTWARE. pom import - - org.eclipse.jetty.ee8 - jetty-ee8-bom - ${jetty.version} - pom - import - org.eclipse.jetty.ee9 jetty-ee9-bom @@ -132,34 +125,6 @@ THE SOFTWARE. - - org.eclipse.jetty.ee8 - jetty-ee8-webapp - - - - org.slf4j - slf4j-api - - - - - org.eclipse.jetty.ee8.websocket - jetty-ee8-websocket-jetty-server - - - - - jakarta.annotation - jakarta.annotation-api - - - - org.slf4j - slf4j-api - - - org.eclipse.jetty.ee9 jetty-ee9-webapp diff --git a/src/main/java/jenkins/benchmark/jmh/JmhBenchmarkState.java b/src/main/java/jenkins/benchmark/jmh/JmhBenchmarkState.java index 08b1690a3..1f1ffb65b 100644 --- a/src/main/java/jenkins/benchmark/jmh/JmhBenchmarkState.java +++ b/src/main/java/jenkins/benchmark/jmh/JmhBenchmarkState.java @@ -1,14 +1,11 @@ package jenkins.benchmark.jmh; import edu.umd.cs.findbugs.annotations.CheckForNull; -import hudson.PluginManager; import hudson.model.Hudson; import hudson.model.RootAction; import hudson.security.ACL; import jakarta.servlet.ServletContext; -import java.io.File; import java.io.IOException; -import java.lang.reflect.InvocationTargetException; import java.net.MalformedURLException; import java.net.URL; import java.util.Objects; @@ -19,8 +16,6 @@ import jenkins.model.JenkinsLocationConfiguration; import org.eclipse.jetty.ee9.webapp.WebAppContext; import org.eclipse.jetty.server.Server; -import org.junit.internal.AssumptionViolatedException; -import org.jvnet.hudson.test.JavaNetReverseProxy; import org.jvnet.hudson.test.JavaNetReverseProxy2; import org.jvnet.hudson.test.JenkinsRule; import org.jvnet.hudson.test.TemporaryDirectoryAllocator; @@ -84,11 +79,7 @@ public final void terminateJenkins() { } finally { JenkinsRule._stopJenkins(server, null, jenkins); try { - if (_isEE9Plus()) { - JavaNetReverseProxy2.getInstance().stop(); - } else { - JavaNetReverseProxy.getInstance().stop(); - } + JavaNetReverseProxy2.getInstance().stop(); } catch (Exception e) { LOGGER.log(Level.WARNING, "Unable to stop JavaNetReverseProxy server", e); } @@ -102,45 +93,17 @@ public final void terminateJenkins() { } private void launchInstance() throws Exception { - if (_isEE9Plus()) { - WebAppContext context = JenkinsRule._createWebAppContext2( - contextPath, - localPort::set, - getClass().getClassLoader(), - localPort.get(), - JenkinsRule::_configureUserRealm); - server = context.getServer(); - ServletContext webServer = context.getServletContext(); - try { - jenkins = Hudson.class - .getDeclaredConstructor(File.class, ServletContext.class, PluginManager.class) - .newInstance(temporaryDirectoryAllocator.allocate(), webServer, TestPluginManager.INSTANCE); - } catch (NoSuchMethodException e) { - throw new AssertionError(e); - } catch (InvocationTargetException e) { - Throwable t = e.getCause(); - if (t instanceof InterruptedException) { - throw new AssumptionViolatedException("Jenkins startup interrupted", t); - } else if (t instanceof Exception) { - throw (Exception) t; - } else if (t instanceof Error) { - throw (Error) t; - } else { - throw e; - } - } - } else { - org.eclipse.jetty.ee8.webapp.WebAppContext context = JenkinsRule._createWebAppContext( - contextPath, - localPort::set, - getClass().getClassLoader(), - localPort.get(), - JenkinsRule::_configureUserRealm); - server = context.getServer(); - javax.servlet.ServletContext webServer = context.getServletContext(); - jenkins = new Hudson(temporaryDirectoryAllocator.allocate(), webServer, TestPluginManager.INSTANCE); - } + WebAppContext context = JenkinsRule._createWebAppContext2( + contextPath, + localPort::set, + getClass().getClassLoader(), + localPort.get(), + JenkinsRule::_configureUserRealm); + server = context.getServer(); + + ServletContext webServer = context.getServletContext(); + jenkins = new Hudson(temporaryDirectoryAllocator.allocate(), webServer, TestPluginManager.INSTANCE); JenkinsRule._configureJenkinsForTest(jenkins); JenkinsRule._configureUpdateCenter(jenkins); jenkins.getActions().add(this); @@ -150,15 +113,6 @@ private void launchInstance() throws Exception { LOGGER.log(Level.INFO, "Running on {0}", url); } - private static boolean _isEE9Plus() { - try { - Jenkins.class.getDeclaredMethod("getServletContext"); - return true; - } catch (NoSuchMethodException e) { - return false; - } - } - private URL getJenkinsURL() throws MalformedURLException { return new URL("http://localhost:" + localPort.get() + contextPath + "/"); } diff --git a/src/main/java/org/jvnet/hudson/test/CaptureEnvironmentBuilder.java b/src/main/java/org/jvnet/hudson/test/CaptureEnvironmentBuilder.java index d368cd866..0a63d6b57 100644 --- a/src/main/java/org/jvnet/hudson/test/CaptureEnvironmentBuilder.java +++ b/src/main/java/org/jvnet/hudson/test/CaptureEnvironmentBuilder.java @@ -33,7 +33,7 @@ import hudson.tasks.Builder; import java.io.IOException; import net.sf.json.JSONObject; -import org.kohsuke.stapler.StaplerRequest; +import org.kohsuke.stapler.StaplerRequest2; /** * {@link Builder} that captures the environment variables used during a build. @@ -57,7 +57,7 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListen @Extension public static final class DescriptorImpl extends Descriptor { @Override - public Builder newInstance(StaplerRequest req, @NonNull JSONObject data) { + public Builder newInstance(StaplerRequest2 req, @NonNull JSONObject data) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/org/jvnet/hudson/test/ClosureExecuterAction.java b/src/main/java/org/jvnet/hudson/test/ClosureExecuterAction.java index 0017b9264..4162ba628 100644 --- a/src/main/java/org/jvnet/hudson/test/ClosureExecuterAction.java +++ b/src/main/java/org/jvnet/hudson/test/ClosureExecuterAction.java @@ -31,7 +31,7 @@ import java.util.Map; import java.util.UUID; import org.kohsuke.stapler.QueryParameter; -import org.kohsuke.stapler.StaplerResponse; +import org.kohsuke.stapler.StaplerResponse2; /** * Server-side logic that implements {@link HudsonTestCase#executeOnServer(java.util.concurrent.Callable)}. @@ -46,7 +46,7 @@ public void add(UUID uuid, Runnable r) { runnables.put(uuid,r); } - public void doIndex(StaplerResponse rsp, @QueryParameter("uuid") String uuid) throws IOException { + public void doIndex(StaplerResponse2 rsp, @QueryParameter("uuid") String uuid) throws IOException { Runnable r = runnables.remove(UUID.fromString(uuid)); if (r!=null) { r.run(); diff --git a/src/main/java/org/jvnet/hudson/test/ComputerConnectorTester.java b/src/main/java/org/jvnet/hudson/test/ComputerConnectorTester.java index d0e6453f3..7c5f03779 100644 --- a/src/main/java/org/jvnet/hudson/test/ComputerConnectorTester.java +++ b/src/main/java/org/jvnet/hudson/test/ComputerConnectorTester.java @@ -28,9 +28,10 @@ import hudson.model.Descriptor; import hudson.slaves.ComputerConnector; import hudson.slaves.ComputerConnectorDescriptor; +import jakarta.servlet.ServletException; +import java.io.IOException; import java.util.List; -import net.sf.json.JSONObject; -import org.kohsuke.stapler.StaplerRequest; +import org.kohsuke.stapler.StaplerRequest2; /** * Test bed to verify the configuration roundtripness of the {@link ComputerConnector}. @@ -46,15 +47,8 @@ public ComputerConnectorTester(HudsonTestCase testCase) { this.testCase = testCase; } - public void doConfigSubmit(StaplerRequest req) { - JSONObject form; - try { - form = req.getSubmittedForm(); - } catch (Exception e) { - // TODO stop wrapping once we drop support for EE 8 - throw new RuntimeException(e); - } - connector = req.bindJSON(ComputerConnector.class, form.getJSONObject("connector")); + public void doConfigSubmit(StaplerRequest2 req) throws IOException, ServletException { + connector = req.bindJSON(ComputerConnector.class, req.getSubmittedForm().getJSONObject("connector")); } public List getConnectorDescriptors() { diff --git a/src/main/java/org/jvnet/hudson/test/CreateFileBuilder.java b/src/main/java/org/jvnet/hudson/test/CreateFileBuilder.java index 04d0e2b09..fd24f031c 100644 --- a/src/main/java/org/jvnet/hudson/test/CreateFileBuilder.java +++ b/src/main/java/org/jvnet/hudson/test/CreateFileBuilder.java @@ -34,7 +34,7 @@ import hudson.tasks.Builder; import java.io.IOException; import net.sf.json.JSONObject; -import org.kohsuke.stapler.StaplerRequest; +import org.kohsuke.stapler.StaplerRequest2; /** * Creates a test builder, which creates a file in the workspace. @@ -85,7 +85,7 @@ public Descriptor getDescriptor() { public static final class DescriptorImpl extends Descriptor { @Override - public Builder newInstance(StaplerRequest req, @NonNull JSONObject data) { + public Builder newInstance(StaplerRequest2 req, @NonNull JSONObject data) { throw new UnsupportedOperationException("This is a temporary test class, " + "which should not be configured from UI"); } diff --git a/src/main/java/org/jvnet/hudson/test/FailureBuilder.java b/src/main/java/org/jvnet/hudson/test/FailureBuilder.java index e94981bdd..4e644b837 100644 --- a/src/main/java/org/jvnet/hudson/test/FailureBuilder.java +++ b/src/main/java/org/jvnet/hudson/test/FailureBuilder.java @@ -29,7 +29,7 @@ import hudson.model.Result; import hudson.tasks.Builder; import net.sf.json.JSONObject; -import org.kohsuke.stapler.StaplerRequest; +import org.kohsuke.stapler.StaplerRequest2; /** * Mock {@link Builder} that always cause a build to fail. @@ -44,7 +44,7 @@ public FailureBuilder() { @Extension public static final class DescriptorImpl extends Descriptor { @Override - public FailureBuilder newInstance(StaplerRequest req, @NonNull JSONObject data) { + public FailureBuilder newInstance(StaplerRequest2 req, @NonNull JSONObject data) { return new FailureBuilder(); } } diff --git a/src/main/java/org/jvnet/hudson/test/GroovyHudsonTestCase.java b/src/main/java/org/jvnet/hudson/test/GroovyHudsonTestCase.java index fe75840f5..4432c8f16 100644 --- a/src/main/java/org/jvnet/hudson/test/GroovyHudsonTestCase.java +++ b/src/main/java/org/jvnet/hudson/test/GroovyHudsonTestCase.java @@ -6,8 +6,8 @@ import hudson.model.BuildListener; import hudson.tasks.Builder; import java.io.IOException; -import org.kohsuke.stapler.StaplerRequest; -import org.kohsuke.stapler.StaplerResponse; +import org.kohsuke.stapler.StaplerRequest2; +import org.kohsuke.stapler.StaplerResponse2; /** * {@link HudsonTestCase} with more convenience methods for Groovy. @@ -19,7 +19,7 @@ public abstract class GroovyHudsonTestCase extends HudsonTestCase { /** * Executes the given closure on the server, in the context of an HTTP request. - * This is useful for testing some methods that require {@link StaplerRequest} and {@link StaplerResponse}. + * This is useful for testing some methods that require {@link StaplerRequest2} and {@link StaplerResponse2}. *

* The closure will get the request and response as parameters. */ diff --git a/src/main/java/org/jvnet/hudson/test/GroovyJenkinsRule.java b/src/main/java/org/jvnet/hudson/test/GroovyJenkinsRule.java index 1d87dccfd..50ebc8ad8 100644 --- a/src/main/java/org/jvnet/hudson/test/GroovyJenkinsRule.java +++ b/src/main/java/org/jvnet/hudson/test/GroovyJenkinsRule.java @@ -30,8 +30,8 @@ import hudson.model.BuildListener; import hudson.tasks.Builder; import java.io.IOException; -import org.kohsuke.stapler.StaplerRequest; -import org.kohsuke.stapler.StaplerResponse; +import org.kohsuke.stapler.StaplerRequest2; +import org.kohsuke.stapler.StaplerResponse2; /** * {@link JenkinsRule} variant with special options for tests written in Groovy. @@ -41,7 +41,7 @@ public class GroovyJenkinsRule extends JenkinsRule { /** * Executes the given closure on the server, in the context of an HTTP request. - * This is useful for testing some methods that require {@link StaplerRequest} and {@link StaplerResponse}. + * This is useful for testing some methods that require {@link StaplerRequest2} and {@link StaplerResponse2}. *

* The closure will get the request and response as parameters. */ diff --git a/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java b/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java index 37a642486..2c44128ad 100644 --- a/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java +++ b/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java @@ -92,6 +92,7 @@ import hudson.util.jna.GNUCLibrary; import jakarta.servlet.ServletContext; import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletRequest; import java.beans.PropertyDescriptor; import java.io.BufferedReader; import java.io.File; @@ -102,7 +103,6 @@ import java.lang.reflect.Array; import java.lang.reflect.Constructor; import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.HttpURLConnection; import java.net.MalformedURLException; @@ -196,8 +196,8 @@ import org.kohsuke.stapler.MetaClass; import org.kohsuke.stapler.MetaClassLoader; import org.kohsuke.stapler.Stapler; -import org.kohsuke.stapler.StaplerRequest; -import org.kohsuke.stapler.StaplerResponse; +import org.kohsuke.stapler.StaplerRequest2; +import org.kohsuke.stapler.StaplerResponse2; import org.springframework.dao.DataAccessException; import org.xml.sax.SAXException; @@ -356,47 +356,9 @@ protected void setUp() throws Exception { jenkins.setCrumbIssuer(new TestCrumbIssuer()); - if (_isEE9Plus()) { - ServletContext servletContext; - try { - servletContext = (ServletContext) - Jenkins.class.getDeclaredMethod("getServletContext").invoke(jenkins); - } catch (NoSuchMethodException e) { - throw new AssertionError(e); - } catch (InvocationTargetException e) { - Throwable t = e.getCause(); - if (t instanceof Exception) { - throw (Exception) t; - } else if (t instanceof Error) { - throw (Error) t; - } else { - throw e; - } - } - servletContext.setAttribute("app", jenkins); - servletContext.setAttribute("version", "?"); - try { - WebAppMain.class - .getDeclaredMethod("installExpressionFactory", ServletContextEvent.class) - .invoke(null, new ServletContextEvent(servletContext)); - } catch (NoSuchMethodException e) { - throw new AssertionError(e); - } catch (InvocationTargetException e) { - Throwable t = e.getCause(); - if (t instanceof Exception) { - throw (Exception) t; - } else if (t instanceof Error) { - throw (Error) t; - } else { - throw e; - } - } - } else { - javax.servlet.ServletContext servletContext = jenkins.servletContext; - servletContext.setAttribute("app", jenkins); - servletContext.setAttribute("version", "?"); - WebAppMain.installExpressionFactory(new javax.servlet.ServletContextEvent(servletContext)); - } + jenkins.getServletContext().setAttribute("app", jenkins); + jenkins.getServletContext().setAttribute("version", "?"); + WebAppMain.installExpressionFactory(new ServletContextEvent(jenkins.getServletContext())); JenkinsLocationConfiguration.get().setUrl(getURL().toString()); // set a default JDK to be the one that the harness is using. @@ -420,15 +382,6 @@ protected void setUp() throws Exception { setUpTimeout(); } - private static boolean _isEE9Plus() { - try { - Jenkins.class.getDeclaredMethod("getServletContext"); - return true; - } catch (NoSuchMethodException e) { - return false; - } - } - protected void setUpTimeout() { if (timeout <= 0) { // no timeout @@ -454,10 +407,8 @@ public void run() { * By default, we load updates from local proxy to avoid network traffic as much as possible. */ protected void configureUpdateCenter() throws Exception { - int localPort = _isEE9Plus() - ? JavaNetReverseProxy2.getInstance().localPort - : JavaNetReverseProxy.getInstance().localPort; - final String updateCenterUrl = "http://localhost:" + localPort + "/update-center.json"; + final String updateCenterUrl = + "http://localhost:" + JavaNetReverseProxy2.getInstance().localPort + "/update-center.json"; // don't waste bandwidth talking to the update center DownloadService.neverUpdate = true; @@ -571,34 +522,11 @@ public String getUrlName() { * you can override it. */ protected Hudson newHudson() throws Exception { - if (_isEE9Plus()) { - File home = homeLoader.allocate(); - for (Runner r : recipes) { - r.decorateHome(this,home); - } - try { - return Hudson.class - .getDeclaredConstructor(File.class, ServletContext.class, PluginManager.class) - .newInstance(home, createWebServer2(), useLocalPluginManager ? null : pluginManager); - } catch (NoSuchMethodException e) { - throw new AssertionError(e); - } catch (InvocationTargetException e) { - Throwable t = e.getCause(); - if (t instanceof Exception) { - throw (Exception) t; - } else if (t instanceof Error) { - throw (Error) t; - } else { - throw e; - } - } - } else { - File home = homeLoader.allocate(); - for (Runner r : recipes) { - r.decorateHome(this,home); - } - return new Hudson(home, createWebServer(), useLocalPluginManager ? null : pluginManager); + File home = homeLoader.allocate(); + for (Runner r : recipes) { + r.decorateHome(this, home); } + return new Hudson(home, createWebServer2(), useLocalPluginManager ? null : pluginManager); } /** @@ -667,61 +595,6 @@ protected ClassLoader configureClassLoader(ClassLoader loader) { return context.getServletContext(); } - /** - * Prepares a webapp hosting environment to get {@link javax.servlet.ServletContext} implementation - * that we need for testing. - * - * @deprecated use {@link #createWebServer2()} - */ - @Deprecated - protected javax.servlet.ServletContext createWebServer() throws Exception { - QueuedThreadPool qtp = new QueuedThreadPool(); - qtp.setName("Jetty (HudsonTestCase)"); - server = new Server(qtp); - - explodedWarDir = WarExploder.getExplodedDir(); - org.eclipse.jetty.ee8.webapp.WebAppContext context = new org.eclipse.jetty.ee8.webapp.WebAppContext(explodedWarDir.getPath(), contextPath) { - @Override - protected ClassLoader configureClassLoader(ClassLoader loader) { - // Use flat classpath in tests - return loader; - } - }; - context.setResourceBase(explodedWarDir.getPath()); - context.setClassLoader(getClass().getClassLoader()); - context.setConfigurations(new org.eclipse.jetty.ee8.webapp.Configuration[]{new org.eclipse.jetty.ee8.webapp.WebXmlConfiguration()}); - context.addBean(new NoListenerConfiguration(context)); - context.setServer(server); - String compression = System.getProperty("jth.compression", "gzip"); - if (compression.equals("gzip")) { - GzipHandler gzipHandler = new GzipHandler(); - gzipHandler.setHandler(context); - server.setHandler(gzipHandler); - } else if (compression.equals("none")) { - server.setHandler(context); - } else { - throw new IllegalArgumentException("Unexpected compression scheme: " + compression); - } - org.eclipse.jetty.ee8.websocket.server.config.JettyWebSocketServletContainerInitializer.configure(context, null); - context.getSecurityHandler().setLoginService(configureUserRealm()); - - ServerConnector connector = new ServerConnector(server); - - HttpConfiguration config = connector.getConnectionFactory(HttpConnectionFactory.class).getHttpConfiguration(); - // use a bigger buffer as Stapler traces can get pretty large on deeply nested URL - config.setRequestHeaderSize(12 * 1024); - config.setHttpCompliance(HttpCompliance.RFC7230); - config.setUriCompliance(UriCompliance.LEGACY); - connector.setHost("localhost"); - - server.addConnector(connector); - server.start(); - - localPort = connector.getLocalPort(); - - return context.getServletContext(); - } - /** * Configures a security realm for a test. */ @@ -1555,7 +1428,7 @@ public HudsonTestCase with(HudsonHomeLoader homeLoader) { * *

* This method allows you to do just that. It is useful for testing some methods that - * require {@link StaplerRequest} and {@link StaplerResponse}, or getting the credential + * require {@link StaplerRequest2} and {@link StaplerResponse2}, or getting the credential * of the current user (via {@link jenkins.model.Jenkins#getAuthentication()}, and so on. * * @param c @@ -1702,7 +1575,7 @@ public WebClient login(String username) throws Exception { * *

* This method allows you to do just that. It is useful for testing some methods that - * require {@link StaplerRequest} and {@link StaplerResponse}, or getting the credential + * require {@link StaplerRequest2} and {@link StaplerResponse2}, or getting the credential * of the current user (via {@link jenkins.model.Jenkins#getAuthentication()}, and so on. * * @param c @@ -1722,7 +1595,7 @@ public V executeOnServer(final Callable c) throws Exception { @Override public void run() { try { - StaplerResponse rsp = Stapler.getCurrentResponse(); + StaplerResponse2 rsp = Stapler.getCurrentResponse2(); rsp.setStatus(200); rsp.setContentType("text/html"); r.add(c.call()); @@ -1902,7 +1775,7 @@ public String getContextPath() throws IOException { public WebRequest addCrumb(WebRequest req) { NameValuePair crumb = new NameValuePair( jenkins.getCrumbIssuer().getDescriptor().getCrumbRequestField(), - jenkins.getCrumbIssuer().getCrumb((javax.servlet.ServletRequest) null)); + jenkins.getCrumbIssuer().getCrumb((ServletRequest) null)); req.setRequestParameters(List.of(crumb)); return req; } @@ -1913,7 +1786,7 @@ public WebRequest addCrumb(WebRequest req) { public URL createCrumbedUrl(String relativePath) throws IOException { CrumbIssuer issuer = jenkins.getCrumbIssuer(); String crumbName = issuer.getDescriptor().getCrumbRequestField(); - String crumb = issuer.getCrumb((javax.servlet.ServletRequest) null); + String crumb = issuer.getCrumb((ServletRequest) null); return new URL(getContextPath()+relativePath+"?"+crumbName+"="+crumb); } @@ -2014,7 +1887,7 @@ public boolean isApplicable(AbstractProject project) { } @Override - public BuildWrapper newInstance(StaplerRequest req, @NonNull JSONObject formData) { + public BuildWrapper newInstance(StaplerRequest2 req, @NonNull JSONObject formData) { throw new UnsupportedOperationException(); } } diff --git a/src/main/java/org/jvnet/hudson/test/JavaNetReverseProxy.java b/src/main/java/org/jvnet/hudson/test/JavaNetReverseProxy.java deleted file mode 100644 index 34b18f353..000000000 --- a/src/main/java/org/jvnet/hudson/test/JavaNetReverseProxy.java +++ /dev/null @@ -1,100 +0,0 @@ -package org.jvnet.hudson.test; - -import hudson.Util; -import java.io.File; -import java.io.IOException; -import java.net.URL; -import java.nio.file.Files; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import org.apache.commons.io.FileUtils; -import org.eclipse.jetty.ee8.servlet.ServletContextHandler; -import org.eclipse.jetty.ee8.servlet.ServletHolder; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.server.ServerConnector; -import org.eclipse.jetty.server.handler.ContextHandlerCollection; -import org.eclipse.jetty.util.thread.QueuedThreadPool; - -/** - * Acts as a reverse proxy, so that during a test we can avoid hitting updates.jenkins.io. - * - *

- * The contents are cached locally. - * - * @author Kohsuke Kawaguchi - * @deprecated use {@link JavaNetReverseProxy2} - */ -@Deprecated -public class JavaNetReverseProxy extends HttpServlet { - private final Server server; - public final int localPort; - - private final File cacheFolder; - - public JavaNetReverseProxy(File cacheFolder) throws Exception { - this.cacheFolder = cacheFolder; - cacheFolder.mkdirs(); - QueuedThreadPool qtp = new QueuedThreadPool(); - qtp.setName("Jetty (JavaNetReverseProxy)"); - server = new Server(qtp); - - ContextHandlerCollection contexts = new ContextHandlerCollection(); - server.setHandler(contexts); - - ServletContextHandler root = new ServletContextHandler(contexts, "/", ServletContextHandler.SESSIONS); - root.addServlet(new ServletHolder(this), "/"); - - ServerConnector connector = new ServerConnector(server); - server.addConnector(connector); - server.start(); - - localPort = connector.getLocalPort(); - } - - public void stop() throws Exception { - server.stop(); - } - - @Override - protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - String path = req.getServletPath(); - String d = Util.getDigestOf(path); - - File cache = new File(cacheFolder, d); - synchronized(this) { - if (!cache.exists()) { - URL url = new URL("https://updates.jenkins.io/" + path); - FileUtils.copyURLToFile(url,cache); - } - } - - resp.setContentType(getMimeType(path)); - Files.copy(cache.toPath(), resp.getOutputStream()); - } - - private String getMimeType(String path) { - int idx = path.indexOf('?'); - if (idx >= 0) { - path = path.substring(0,idx); - } - if (path.endsWith(".json")) { - return "text/javascript"; - } - return getServletContext().getMimeType(path); - } - - private static volatile JavaNetReverseProxy INSTANCE; - - /** - * Gets the default instance. - */ - public static synchronized JavaNetReverseProxy getInstance() throws Exception { - if (INSTANCE == null) { - // TODO: think of a better location --- ideally inside the target/ dir so that clean would wipe them out - INSTANCE = new JavaNetReverseProxy(new File(new File(System.getProperty("java.io.tmpdir")),"jenkins.io-cache2")); - } - return INSTANCE; - } -} diff --git a/src/main/java/org/jvnet/hudson/test/JenkinsComputerConnectorTester.java b/src/main/java/org/jvnet/hudson/test/JenkinsComputerConnectorTester.java index 5f4e36b12..160b0071e 100644 --- a/src/main/java/org/jvnet/hudson/test/JenkinsComputerConnectorTester.java +++ b/src/main/java/org/jvnet/hudson/test/JenkinsComputerConnectorTester.java @@ -28,9 +28,10 @@ import hudson.model.Descriptor; import hudson.slaves.ComputerConnector; import hudson.slaves.ComputerConnectorDescriptor; +import jakarta.servlet.ServletException; +import java.io.IOException; import java.util.List; -import net.sf.json.JSONObject; -import org.kohsuke.stapler.StaplerRequest; +import org.kohsuke.stapler.StaplerRequest2; /** * Test bed to verify the configuration roundtripness of the {@link ComputerConnector}. @@ -47,15 +48,8 @@ public JenkinsComputerConnectorTester(JenkinsRule testCase) { this.jenkinsRule = testCase; } - public void doConfigSubmit(StaplerRequest req) { - JSONObject form; - try { - form = req.getSubmittedForm(); - } catch (Exception e) { - // TODO stop wrapping once we drop support for EE 8 - throw new RuntimeException(e); - } - connector = req.bindJSON(ComputerConnector.class, form.getJSONObject("connector")); + public void doConfigSubmit(StaplerRequest2 req) throws IOException, ServletException { + connector = req.bindJSON(ComputerConnector.class, req.getSubmittedForm().getJSONObject("connector")); } public List getConnectorDescriptors() { diff --git a/src/main/java/org/jvnet/hudson/test/JenkinsRecipe.java b/src/main/java/org/jvnet/hudson/test/JenkinsRecipe.java index 33405f373..20d1bc4d9 100644 --- a/src/main/java/org/jvnet/hudson/test/JenkinsRecipe.java +++ b/src/main/java/org/jvnet/hudson/test/JenkinsRecipe.java @@ -44,7 +44,7 @@ abstract class Runner { public void setup(JenkinsRule jenkinsRule, T recipe) throws Exception {} /** - * Called right before {@code jenkins.model.Jenkins#Jenkins(java.io.File, javax.servlet.ServletContext)} is invoked + * Called right before {@link jenkins.model.Jenkins#Jenkins(java.io.File, jakarta.servlet.ServletContext)} is invoked * to decorate the hudson home directory. */ public void decorateHome(JenkinsRule jenkinsRule, File home) throws Exception {} diff --git a/src/main/java/org/jvnet/hudson/test/JenkinsRule.java b/src/main/java/org/jvnet/hudson/test/JenkinsRule.java index 75f2f4138..549eee05f 100644 --- a/src/main/java/org/jvnet/hudson/test/JenkinsRule.java +++ b/src/main/java/org/jvnet/hudson/test/JenkinsRule.java @@ -102,6 +102,7 @@ import hudson.util.jna.GNUCLibrary; import jakarta.servlet.ServletContext; import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletRequest; import java.beans.Introspector; import java.beans.PropertyDescriptor; import java.io.BufferedReader; @@ -246,8 +247,8 @@ import org.kohsuke.stapler.MetaClass; import org.kohsuke.stapler.MetaClassLoader; import org.kohsuke.stapler.Stapler; -import org.kohsuke.stapler.StaplerRequest; -import org.kohsuke.stapler.StaplerResponse; +import org.kohsuke.stapler.StaplerRequest2; +import org.kohsuke.stapler.StaplerResponse2; import org.springframework.security.authentication.BadCredentialsException; import org.springframework.security.core.AuthenticationException; import org.springframework.security.core.GrantedAuthority; @@ -289,7 +290,7 @@ public class JenkinsRule implements TestRule, MethodRule, RootAction { /** * Where in the {@link Server} is Jenkins deployed? *

- * Just like {@link javax.servlet.ServletContext#getContextPath()}, starts with '/' but doesn't end with '/'. + * Just like {@link jakarta.servlet.ServletContext#getContextPath()}, starts with '/' but doesn't end with '/'. * Unlike {@link WebClient#getContextPath} this is not a complete URL. */ public String contextPath = "/jenkins"; @@ -433,15 +434,6 @@ public void before() throws Throwable { JenkinsLocationConfiguration.get().setUrl(getURL().toString()); } - private static boolean _isEE9Plus() { - try { - Jenkins.class.getDeclaredMethod("getServletContext"); - return true; - } catch (NoSuchMethodException e) { - return false; - } - } - /** * Configures a Jenkins instance for test. * @@ -451,47 +443,9 @@ private static boolean _isEE9Plus() { */ public static void _configureJenkinsForTest(Jenkins jenkins) throws Exception { jenkins.setNoUsageStatistics(true); // collecting usage stats from tests is pointless. - if (_isEE9Plus()) { - ServletContext servletContext; - try { - servletContext = (ServletContext) - Jenkins.class.getDeclaredMethod("getServletContext").invoke(jenkins); - } catch (NoSuchMethodException e) { - throw new AssertionError(e); - } catch (InvocationTargetException e) { - Throwable t = e.getCause(); - if (t instanceof Exception) { - throw (Exception) t; - } else if (t instanceof Error) { - throw (Error) t; - } else { - throw e; - } - } - servletContext.setAttribute("app", jenkins); - servletContext.setAttribute("version", "?"); - try { - WebAppMain.class - .getDeclaredMethod("installExpressionFactory", ServletContextEvent.class) - .invoke(null, new ServletContextEvent(servletContext)); - } catch (NoSuchMethodException e) { - throw new AssertionError(e); - } catch (InvocationTargetException e) { - Throwable t = e.getCause(); - if (t instanceof Exception) { - throw (Exception) t; - } else if (t instanceof Error) { - throw (Error) t; - } else { - throw e; - } - } - } else { - javax.servlet.ServletContext servletContext = jenkins.servletContext; - servletContext.setAttribute("app", jenkins); - servletContext.setAttribute("version", "?"); - WebAppMain.installExpressionFactory(new javax.servlet.ServletContextEvent(servletContext)); - } + jenkins.getServletContext().setAttribute("app", jenkins); + jenkins.getServletContext().setAttribute("version", "?"); + WebAppMain.installExpressionFactory(new ServletContextEvent(jenkins.getServletContext())); // set a default JDK to be the one that the harness is using. jenkins.getJDKs().add(new JDK("default", System.getProperty("java.home"))); @@ -522,10 +476,8 @@ public static void _configureUpdateCenter(Jenkins jenkins) throws Exception { final String updateCenterUrl; jettyLevel(Level.WARNING); try { - int localPort = _isEE9Plus() - ? JavaNetReverseProxy2.getInstance().localPort - : JavaNetReverseProxy.getInstance().localPort; - updateCenterUrl = "http://localhost:" + localPort + "/update-center.json"; + updateCenterUrl = + "http://localhost:" + JavaNetReverseProxy2.getInstance().localPort + "/update-center.json"; } finally { jettyLevel(Level.INFO); } @@ -788,45 +740,17 @@ public String getUrlName() { */ protected Hudson newHudson() throws Exception { jettyLevel(Level.WARNING); - if (_isEE9Plus()) { - ServletContext webServer = createWebServer2(); - File home = homeLoader.allocate(); - for (JenkinsRecipe.Runner r : recipes) { - r.decorateHome(this, home); - } - try { - return Hudson.class - .getDeclaredConstructor(File.class, ServletContext.class, PluginManager.class) - .newInstance(home, webServer, getPluginManager()); - } catch (NoSuchMethodException e) { - throw new AssertionError(e); - } catch (InvocationTargetException e) { - Throwable t = e.getCause(); - if (t instanceof InterruptedException) { - throw new AssumptionViolatedException("Jenkins startup interrupted", t); - } else if (t instanceof Exception) { - throw (Exception) t; - } else if (t instanceof Error) { - throw (Error) t; - } else { - throw e; - } - } finally { - jettyLevel(Level.INFO); - } - } else { - javax.servlet.ServletContext webServer = createWebServer(); - File home = homeLoader.allocate(); - for (JenkinsRecipe.Runner r : recipes) { - r.decorateHome(this, home); - } - try { - return new Hudson(home, webServer, getPluginManager()); - } catch (InterruptedException e) { - throw new AssumptionViolatedException("Jenkins startup interrupted", e); - } finally { - jettyLevel(Level.INFO); - } + ServletContext webServer = createWebServer2(); + File home = homeLoader.allocate(); + for (JenkinsRecipe.Runner r : recipes) { + r.decorateHome(this, home); + } + try { + return new Hudson(home, webServer, getPluginManager()); + } catch (InterruptedException e) { + throw new AssumptionViolatedException("Jenkins startup interrupted", e); + } finally { + jettyLevel(Level.INFO); } } @@ -983,139 +907,6 @@ protected ClassLoader configureClassLoader(ClassLoader loader) { return context; } - /** - * Prepares a webapp hosting environment to get {@link javax.servlet.ServletContext} implementation - * that we need for testing. - * - * @deprecated {use {@link #createWebServer2()}} - */ - @Deprecated - protected javax.servlet.ServletContext createWebServer() throws Exception { - return createWebServer(null); - } - - /** - * Prepares a webapp hosting environment to get {@link javax.servlet.ServletContext} implementation - * that we need for testing. - * - * @deprecated use {@link #createWebServer2(BiConsumer)} - * @param contextAndServerConsumer configures the {@link org.eclipse.jetty.ee8.webapp.WebAppContext} and the {@link Server} for the instance, before they are started - * @since 2.63 - */ - @Deprecated - protected javax.servlet.ServletContext createWebServer( - @CheckForNull BiConsumer contextAndServerConsumer) - throws Exception { - org.eclipse.jetty.ee8.webapp.WebAppContext context = _createWebAppContext( - contextPath, - (x) -> localPort = x, - getClass().getClassLoader(), - localPort, - this::configureUserRealm, - contextAndServerConsumer); - server = context.getServer(); - LOGGER.log(Level.INFO, "Running on {0}", getURL()); - return context.getServletContext(); - } - - /** - * Creates a web server on which Jenkins can run - * - * @param contextPath the context path at which to put Jenkins - * @param portSetter the port on which the server runs will be set using this function - * @param classLoader the class loader for the {@link org.eclipse.jetty.ee8.webapp.WebAppContext} - * @param localPort port on which the server runs - * @param loginServiceSupplier configures the {@link LoginService} for the instance - * @return the {@link Server} - * @deprecated use {@link #_createWebAppContext2(String, Consumer, ClassLoader, int, Supplier)} - * @since 2.50 - */ - @Deprecated - public static org.eclipse.jetty.ee8.webapp.WebAppContext _createWebAppContext( - String contextPath, - Consumer portSetter, - ClassLoader classLoader, - int localPort, - Supplier loginServiceSupplier) - throws Exception { - return _createWebAppContext(contextPath, portSetter, classLoader, localPort, loginServiceSupplier, null); - } - - /** - * Creates a web server on which Jenkins can run - * - * @param contextPath the context path at which to put Jenkins - * @param portSetter the port on which the server runs will be set using this function - * @param classLoader the class loader for the {@link org.eclipse.jetty.ee8.webapp.WebAppContext} - * @param localPort port on which the server runs - * @param loginServiceSupplier configures the {@link LoginService} for the instance - * @param contextAndServerConsumer configures the {@link org.eclipse.jetty.ee8.webapp.WebAppContext} and the {@link Server} for the instance, before they are started - * @return the {@link Server} - * @deprecated use {@link #_createWebAppContext2(String, Consumer, ClassLoader, int, Supplier, BiConsumer)} - * @since 2.50 - */ - @Deprecated - public static org.eclipse.jetty.ee8.webapp.WebAppContext _createWebAppContext( - String contextPath, - Consumer portSetter, - ClassLoader classLoader, - int localPort, - Supplier loginServiceSupplier, - @CheckForNull BiConsumer contextAndServerConsumer) - throws Exception { - QueuedThreadPool qtp = new QueuedThreadPool(); - qtp.setName("Jetty (JenkinsRule)"); - Server server = new Server(qtp); - - org.eclipse.jetty.ee8.webapp.WebAppContext context = new org.eclipse.jetty.ee8.webapp.WebAppContext(WarExploder.getExplodedDir().getPath(), contextPath) { - @Override - protected ClassLoader configureClassLoader(ClassLoader loader) { - // Use flat classpath in tests - return loader; - } - }; - context.setClassLoader(classLoader); - context.setConfigurations(new org.eclipse.jetty.ee8.webapp.Configuration[]{new org.eclipse.jetty.ee8.webapp.WebXmlConfiguration()}); - context.addBean(new NoListenerConfiguration(context)); - context.setServer(server); - String compression = System.getProperty("jth.compression", "gzip"); - if (compression.equals("gzip")) { - GzipHandler gzipHandler = new GzipHandler(); - gzipHandler.setHandler(context); - server.setHandler(gzipHandler); - } else if (compression.equals("none")) { - server.setHandler(context); - } else { - throw new IllegalArgumentException("Unexpected compression scheme: " + compression); - } - org.eclipse.jetty.ee8.websocket.server.config.JettyWebSocketServletContainerInitializer.configure(context, null); - context.getSecurityHandler().setLoginService(loginServiceSupplier.get()); - context.setResourceBase(WarExploder.getExplodedDir().getPath()); - - ServerConnector connector = new ServerConnector(server); - HttpConfiguration config = connector.getConnectionFactory(HttpConnectionFactory.class).getHttpConfiguration(); - // use a bigger buffer as Stapler traces can get pretty large on deeply nested URL - config.setRequestHeaderSize(12 * 1024); - config.setHttpCompliance(HttpCompliance.RFC7230); - config.setUriCompliance(UriCompliance.LEGACY); - connector.setHost("localhost"); - if (System.getProperty("port") != null) { - connector.setPort(Integer.parseInt(System.getProperty("port"))); - } else if (localPort != 0) { - connector.setPort(localPort); - } - - server.addConnector(connector); - if (contextAndServerConsumer != null) { - contextAndServerConsumer.accept(context, server); - } - server.start(); - - portSetter.accept(connector.getLocalPort()); - - return context; - } - /** * Configures a security realm for a test. */ @@ -2527,7 +2318,7 @@ public JenkinsRule with(HudsonHomeLoader homeLoader) { * *

* This method allows you to do just that. It is useful for testing some methods that - * require {@link org.kohsuke.stapler.StaplerRequest} and {@link org.kohsuke.stapler.StaplerResponse}, or getting the credential + * require {@link org.kohsuke.stapler.StaplerRequest2} and {@link org.kohsuke.stapler.StaplerResponse2}, or getting the credential * of the current user (via {@link jenkins.model.Jenkins#getAuthentication()}, and so on. * * @param c @@ -2815,7 +2606,7 @@ public WebClient login(String username) throws Exception { * *

* This method allows you to do just that. It is useful for testing some methods that - * require {@link org.kohsuke.stapler.StaplerRequest} and {@link org.kohsuke.stapler.StaplerResponse}, or getting the credential + * require {@link org.kohsuke.stapler.StaplerRequest2} and {@link org.kohsuke.stapler.StaplerResponse2}, or getting the credential * of the current user (via {@link jenkins.model.Jenkins#getAuthentication()}, and so on. * * @param c @@ -2835,7 +2626,7 @@ public V executeOnServer(final Callable c) throws Exception { @Override public void run() { try { - StaplerResponse rsp = Stapler.getCurrentResponse(); + StaplerResponse2 rsp = Stapler.getCurrentResponse2(); rsp.setStatus(200); rsp.setContentType("text/html"); r.set(c.call()); @@ -3048,7 +2839,7 @@ public WebRequest addCrumb(WebRequest req) { public URL createCrumbedUrl(String relativePath) throws IOException { CrumbIssuer issuer = jenkins.getCrumbIssuer(); String crumbName = issuer.getDescriptor().getCrumbRequestField(); - String crumb = issuer.getCrumb((javax.servlet.ServletRequest) null); + String crumb = issuer.getCrumb((ServletRequest) null); if (relativePath.indexOf('?') == -1) { return new URL(getContextPath()+relativePath+"?"+crumbName+"="+crumb); } @@ -3265,7 +3056,7 @@ public boolean isApplicable(AbstractProject project) { } @Override - public BuildWrapper newInstance(StaplerRequest req, @NonNull JSONObject formData) { + public BuildWrapper newInstance(StaplerRequest2 req, @NonNull JSONObject formData) { throw new UnsupportedOperationException(); } @@ -3283,6 +3074,6 @@ public Description getTestDescription() { private NameValuePair getCrumbHeaderNVP() { return new NameValuePair(jenkins.getCrumbIssuer().getDescriptor().getCrumbRequestField(), - jenkins.getCrumbIssuer().getCrumb((javax.servlet.ServletRequest) null)); + jenkins.getCrumbIssuer().getCrumb((ServletRequest) null)); } } diff --git a/src/main/java/org/jvnet/hudson/test/MockBuilder.java b/src/main/java/org/jvnet/hudson/test/MockBuilder.java index 7ebe859e3..36e7c3b23 100644 --- a/src/main/java/org/jvnet/hudson/test/MockBuilder.java +++ b/src/main/java/org/jvnet/hudson/test/MockBuilder.java @@ -10,7 +10,7 @@ import hudson.tasks.Builder; import java.io.IOException; import net.sf.json.JSONObject; -import org.kohsuke.stapler.StaplerRequest; +import org.kohsuke.stapler.StaplerRequest2; /** * Forces the build result to be some pre-configured value. @@ -39,7 +39,7 @@ public Descriptor getDescriptor() { @Extension public static final class DescriptorImpl extends Descriptor { @Override - public Builder newInstance(StaplerRequest req, @NonNull JSONObject data) { + public Builder newInstance(StaplerRequest2 req, @NonNull JSONObject data) { throw new UnsupportedOperationException(); } } diff --git a/src/main/java/org/jvnet/hudson/test/MockFolder.java b/src/main/java/org/jvnet/hudson/test/MockFolder.java index 05001bd79..7977f6957 100644 --- a/src/main/java/org/jvnet/hudson/test/MockFolder.java +++ b/src/main/java/org/jvnet/hudson/test/MockFolder.java @@ -43,6 +43,7 @@ import hudson.model.listeners.ItemListener; import hudson.views.DefaultViewsTabBar; import hudson.views.ViewsTabBar; +import jakarta.servlet.ServletException; import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -56,8 +57,8 @@ import jenkins.model.DirectlyModifiableTopLevelItemGroup; import jenkins.model.Jenkins; import org.kohsuke.stapler.StaplerFallback; -import org.kohsuke.stapler.StaplerRequest; -import org.kohsuke.stapler.StaplerResponse; +import org.kohsuke.stapler.StaplerRequest2; +import org.kohsuke.stapler.StaplerResponse2; import org.kohsuke.stapler.WebMethod; /** @@ -161,15 +162,8 @@ public T createProject(@NonNull Class type, @NonNull return type.cast(createProject((TopLevelItemDescriptor) Jenkins.get().getDescriptorOrDie(type), name, true)); } - @Override public TopLevelItem doCreateItem(StaplerRequest req, StaplerResponse rsp) throws IOException { - try { - return mixin().createTopLevelItem(req, rsp); - } catch (IOException e) { - throw e; - } catch (Exception e) { - // TODO stop wrapping once we drop support for EE 8 - throw new RuntimeException(e); - } + @Override public TopLevelItem doCreateItem(StaplerRequest2 req, StaplerResponse2 rsp) throws IOException, ServletException { + return mixin().createTopLevelItem(req, rsp); } @Override public String getUrlChildPrefix() { diff --git a/src/main/java/org/jvnet/hudson/test/MockQueueItemAuthenticator.java b/src/main/java/org/jvnet/hudson/test/MockQueueItemAuthenticator.java index a7e46593a..5598a71e9 100644 --- a/src/main/java/org/jvnet/hudson/test/MockQueueItemAuthenticator.java +++ b/src/main/java/org/jvnet/hudson/test/MockQueueItemAuthenticator.java @@ -28,10 +28,10 @@ import hudson.model.Item; import hudson.model.Queue; import hudson.model.User; +import jakarta.inject.Inject; import java.util.HashMap; import java.util.Map; import java.util.stream.Collectors; -import javax.inject.Inject; import jenkins.security.QueueItemAuthenticator; import jenkins.security.QueueItemAuthenticatorConfiguration; import jenkins.security.QueueItemAuthenticatorDescriptor; diff --git a/src/main/java/org/jvnet/hudson/test/NoListenerConfiguration.java b/src/main/java/org/jvnet/hudson/test/NoListenerConfiguration.java deleted file mode 100644 index 0a58b21f2..000000000 --- a/src/main/java/org/jvnet/hudson/test/NoListenerConfiguration.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package org.jvnet.hudson.test; - -import hudson.WebAppMain; -import java.util.EventListener; -import javax.servlet.ServletContextListener; -import org.eclipse.jetty.ee8.webapp.WebAppContext; -import org.eclipse.jetty.util.component.AbstractLifeCycle; - -/** - * Kills off the {@link WebAppMain} {@link ServletContextListener}. - * - *

- * This is so that the harness can create the {@link jenkins.model.Jenkins} object. - * with the home directory of our choice. - * - * @author Kohsuke Kawaguchi - * @deprecated use {@link NoListenerConfiguration2} - */ -@Deprecated -public class NoListenerConfiguration extends AbstractLifeCycle { - private final WebAppContext context; - - public NoListenerConfiguration(WebAppContext context) { - this.context = context; - } - - @Override - protected void doStart() { - for (EventListener eventListener : context.getEventListeners()) { - if (eventListener instanceof WebAppMain) { - context.removeEventListener(eventListener); - } - } - } -} diff --git a/src/main/java/org/jvnet/hudson/test/RealJenkinsRule.java b/src/main/java/org/jvnet/hudson/test/RealJenkinsRule.java index ea784989b..224fc8dd7 100644 --- a/src/main/java/org/jvnet/hudson/test/RealJenkinsRule.java +++ b/src/main/java/org/jvnet/hudson/test/RealJenkinsRule.java @@ -33,6 +33,10 @@ import hudson.security.csrf.CrumbExclusion; import hudson.util.NamingThreadFactory; import hudson.util.StreamCopyThread; +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; @@ -87,10 +91,6 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; -import javax.servlet.FilterChain; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import io.jenkins.test.fips.FIPSTestBundleProvider; import jenkins.model.Jenkins; @@ -108,8 +108,8 @@ import org.kohsuke.stapler.HttpResponses; import org.kohsuke.stapler.QueryParameter; import org.kohsuke.stapler.Stapler; -import org.kohsuke.stapler.StaplerRequest; -import org.kohsuke.stapler.StaplerResponse; +import org.kohsuke.stapler.StaplerRequest2; +import org.kohsuke.stapler.StaplerResponse2; import org.kohsuke.stapler.verb.POST; /** @@ -1295,7 +1295,7 @@ public void doStatus(@QueryParameter String token) { private static final ExecutorService STEP_RUNNER = Executors.newSingleThreadExecutor( new NamingThreadFactory(Executors.defaultThreadFactory(), RealJenkinsRule.class.getName() + ".STEP_RUNNER")); @POST - public void doStep(StaplerRequest req, StaplerResponse rsp) throws Throwable { + public void doStep(StaplerRequest2 req, StaplerResponse2 rsp) throws Throwable { InputPayload input = (InputPayload) Init2.readSer(req.getInputStream(), Endpoint.class.getClassLoader()); checkToken(input.token); Step2 s = input.step; @@ -1322,7 +1322,7 @@ public void doStep(StaplerRequest req, StaplerResponse rsp) throws Throwable { public HttpResponse doExit(@QueryParameter String token) throws IOException { checkToken(token); try (ACLContext ctx = ACL.as2(ACL.SYSTEM2)) { - return Jenkins.get().doSafeExit((StaplerRequest) null); + return Jenkins.get().doSafeExit((StaplerRequest2) null); } } public void doTimeout(@QueryParameter String token) { diff --git a/src/main/java/org/jvnet/hudson/test/TestCrumbIssuer.java b/src/main/java/org/jvnet/hudson/test/TestCrumbIssuer.java index bd4199ae9..946f62002 100644 --- a/src/main/java/org/jvnet/hudson/test/TestCrumbIssuer.java +++ b/src/main/java/org/jvnet/hudson/test/TestCrumbIssuer.java @@ -10,10 +10,10 @@ import hudson.model.ModelObject; import hudson.security.csrf.CrumbIssuer; import hudson.security.csrf.CrumbIssuerDescriptor; -import javax.servlet.ServletRequest; +import jakarta.servlet.ServletRequest; import net.sf.json.JSONObject; import org.kohsuke.stapler.DataBoundConstructor; -import org.kohsuke.stapler.StaplerRequest; +import org.kohsuke.stapler.StaplerRequest2; /** * A crumb issuer that issues a constant crumb value. Used for unit testing. @@ -44,7 +44,7 @@ public DescriptorImpl() { } @Override - public TestCrumbIssuer newInstance(StaplerRequest req, @NonNull JSONObject formData) throws FormException { + public TestCrumbIssuer newInstance(StaplerRequest2 req, @NonNull JSONObject formData) throws FormException { return new TestCrumbIssuer(); } } diff --git a/src/main/java/org/jvnet/hudson/test/UnitTestSupportingPluginManager.java b/src/main/java/org/jvnet/hudson/test/UnitTestSupportingPluginManager.java index 78fbec888..55a66b96c 100644 --- a/src/main/java/org/jvnet/hudson/test/UnitTestSupportingPluginManager.java +++ b/src/main/java/org/jvnet/hudson/test/UnitTestSupportingPluginManager.java @@ -27,6 +27,7 @@ import hudson.LocalPluginManager; import hudson.Plugin; import hudson.PluginManager; +import jakarta.servlet.ServletContext; import java.io.BufferedReader; import java.io.File; import java.io.IOException; @@ -42,7 +43,6 @@ import java.util.jar.Manifest; import java.util.logging.Level; import java.util.logging.Logger; -import javax.servlet.ServletContext; import org.apache.commons.io.FileUtils; import org.junit.Assert; diff --git a/src/main/java/org/jvnet/hudson/test/UnstableBuilder.java b/src/main/java/org/jvnet/hudson/test/UnstableBuilder.java index 0ee59f1b1..447109635 100644 --- a/src/main/java/org/jvnet/hudson/test/UnstableBuilder.java +++ b/src/main/java/org/jvnet/hudson/test/UnstableBuilder.java @@ -29,7 +29,7 @@ import hudson.model.Result; import hudson.tasks.Builder; import net.sf.json.JSONObject; -import org.kohsuke.stapler.StaplerRequest; +import org.kohsuke.stapler.StaplerRequest2; /** * Mock {@link Builder} that always cause a build to fail. @@ -44,7 +44,7 @@ public UnstableBuilder() { @Extension public static final class DescriptorImpl extends Descriptor { @Override - public UnstableBuilder newInstance(StaplerRequest req, @NonNull JSONObject data) { + public UnstableBuilder newInstance(StaplerRequest2 req, @NonNull JSONObject data) { return new UnstableBuilder(); } } diff --git a/src/main/java/org/jvnet/hudson/test/WorkspaceCopyFileBuilder.java b/src/main/java/org/jvnet/hudson/test/WorkspaceCopyFileBuilder.java index 17b0dbcab..e97e022f8 100644 --- a/src/main/java/org/jvnet/hudson/test/WorkspaceCopyFileBuilder.java +++ b/src/main/java/org/jvnet/hudson/test/WorkspaceCopyFileBuilder.java @@ -36,7 +36,7 @@ import java.io.IOException; import jenkins.model.Jenkins; import net.sf.json.JSONObject; -import org.kohsuke.stapler.StaplerRequest; +import org.kohsuke.stapler.StaplerRequest2; /** * Test Builder, which copies a file from a workspace of another job. @@ -105,7 +105,7 @@ public Descriptor getDescriptor() { public static final class DescriptorImpl extends Descriptor { @Override - public Builder newInstance(StaplerRequest req, @NonNull JSONObject data) { + public Builder newInstance(StaplerRequest2 req, @NonNull JSONObject data) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/org/jvnet/hudson/test/recipes/Recipe.java b/src/main/java/org/jvnet/hudson/test/recipes/Recipe.java index 1a26060a2..2963966d2 100644 --- a/src/main/java/org/jvnet/hudson/test/recipes/Recipe.java +++ b/src/main/java/org/jvnet/hudson/test/recipes/Recipe.java @@ -67,7 +67,7 @@ abstract class Runner { public void setup(HudsonTestCase testCase, T recipe) throws Exception {} /** - * Called right before {@code jenkins.model.Jenkins#Jenkins(File, javax.servlet.ServletContext)} is invoked + * Called right before {@link jenkins.model.Jenkins#Jenkins(File, jakarta.servlet.ServletContext)} is invoked * to decorate the hudson home directory. */ public void decorateHome(HudsonTestCase testCase, File home) throws Exception {} diff --git a/src/spotbugs/excludesFilter.xml b/src/spotbugs/excludesFilter.xml index 831b3e6d4..6ae1a118f 100644 --- a/src/spotbugs/excludesFilter.xml +++ b/src/spotbugs/excludesFilter.xml @@ -182,7 +182,6 @@ - @@ -213,7 +212,6 @@ - @@ -232,7 +230,6 @@ - diff --git a/src/test/java/org/jvnet/hudson/main/UseRecipesWithJenkinsRuleTest.java b/src/test/java/org/jvnet/hudson/main/UseRecipesWithJenkinsRuleTest.java index f497c8b7e..fb5a4df85 100644 --- a/src/test/java/org/jvnet/hudson/main/UseRecipesWithJenkinsRuleTest.java +++ b/src/test/java/org/jvnet/hudson/main/UseRecipesWithJenkinsRuleTest.java @@ -7,10 +7,10 @@ import static org.junit.Assert.assertNotNull; import hudson.LocalPluginManager; +import jakarta.servlet.http.HttpServletResponse; import java.io.File; import java.io.IOException; import java.net.URL; -import javax.servlet.http.HttpServletResponse; import jenkins.model.JenkinsLocationConfiguration; import org.htmlunit.html.HtmlPage; import org.junit.Rule; diff --git a/src/test/java/org/jvnet/hudson/test/RealJenkinsRuleTest.java b/src/test/java/org/jvnet/hudson/test/RealJenkinsRuleTest.java index d4ee20649..ee6767bc0 100644 --- a/src/test/java/org/jvnet/hudson/test/RealJenkinsRuleTest.java +++ b/src/test/java/org/jvnet/hudson/test/RealJenkinsRuleTest.java @@ -51,6 +51,12 @@ import hudson.model.Item; import hudson.model.listeners.ItemListener; import hudson.util.PluginServletFilter; +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.ByteArrayInputStream; import java.io.File; import java.io.IOException; @@ -63,12 +69,6 @@ import java.util.List; import java.util.concurrent.atomic.AtomicReference; import java.util.logging.Level; -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; import jenkins.model.Jenkins; import jenkins.model.JenkinsLocationConfiguration; import static org.junit.Assume.assumeThat;