Skip to content

Commit

Permalink
[JENKINS-73261] Drop support for Jetty 12 EE 8 in the test harness (#631
Browse files Browse the repository at this point in the history
)
  • Loading branch information
basil authored Sep 17, 2024
1 parent b13735c commit 5db817b
Show file tree
Hide file tree
Showing 27 changed files with 113 additions and 709 deletions.
37 changes: 1 addition & 36 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ THE SOFTWARE.

<properties>
<changelist>999999-SNAPSHOT</changelist>
<jenkins.version>2.463</jenkins.version>
<jenkins.version>2.476</jenkins.version>
<jmh.version>1.37</jmh.version>
<gitHubRepo>jenkinsci/${project.artifactId}</gitHubRepo>
<!-- Normally filled in by "maven-hpi-plugin" with the path to "org-netbeans-insane-hook.jar" extracted from this repository -->
Expand All @@ -73,13 +73,6 @@ THE SOFTWARE.
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.ee8</groupId>
<artifactId>jetty-ee8-bom</artifactId>
<version>${jetty.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.ee9</groupId>
<artifactId>jetty-ee9-bom</artifactId>
Expand Down Expand Up @@ -132,34 +125,6 @@ THE SOFTWARE.
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.ee8</groupId>
<artifactId>jetty-ee8-webapp</artifactId>
<exclusions>
<!-- Provided by Jenkins core -->
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.ee8.websocket</groupId>
<artifactId>jetty-ee8-websocket-jetty-server</artifactId>
<!-- or jetty-ee8-websocket-javax-server -->
<exclusions>
<!-- Provided by Jenkins core -->
<exclusion>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
</exclusion>
<!-- Provided by Jenkins core -->
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.ee9</groupId>
<artifactId>jetty-ee9-webapp</artifactId>
Expand Down
68 changes: 11 additions & 57 deletions src/main/java/jenkins/benchmark/jmh/JmhBenchmarkState.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
Expand All @@ -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 + "/");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -57,7 +57,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
@Extension
public static final class DescriptorImpl extends Descriptor<Builder> {
@Override
public Builder newInstance(StaplerRequest req, @NonNull JSONObject data) {
public Builder newInstance(StaplerRequest2 req, @NonNull JSONObject data) {
throw new UnsupportedOperationException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)}.
Expand All @@ -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();
Expand Down
16 changes: 5 additions & 11 deletions src/main/java/org/jvnet/hudson/test/ComputerConnectorTester.java
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand All @@ -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<ComputerConnectorDescriptor> getConnectorDescriptors() {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jvnet/hudson/test/CreateFileBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -85,7 +85,7 @@ public Descriptor<Builder> getDescriptor() {
public static final class DescriptorImpl extends Descriptor<Builder> {

@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");
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jvnet/hudson/test/FailureBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -44,7 +44,7 @@ public FailureBuilder() {
@Extension
public static final class DescriptorImpl extends Descriptor<Builder> {
@Override
public FailureBuilder newInstance(StaplerRequest req, @NonNull JSONObject data) {
public FailureBuilder newInstance(StaplerRequest2 req, @NonNull JSONObject data) {
return new FailureBuilder();
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/jvnet/hudson/test/GroovyHudsonTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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}.
* <p>
* The closure will get the request and response as parameters.
*/
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/jvnet/hudson/test/GroovyJenkinsRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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}.
* <p>
* The closure will get the request and response as parameters.
*/
Expand Down
Loading

0 comments on commit 5db817b

Please sign in to comment.