Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-73260] Forward compatibility with EE 9 cores #770

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ THE SOFTWARE.
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.ee9</groupId>
<artifactId>jetty-ee9-bom</artifactId>
<version>${jetty.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci</groupId>
<artifactId>annotation-indexer</artifactId>
Expand Down Expand Up @@ -110,6 +117,11 @@ THE SOFTWARE.
<artifactId>support-log-formatter</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>io.jenkins.servlet</groupId>
<artifactId>javax-servlet-api</artifactId>
<version>4.0.7</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand All @@ -129,6 +141,11 @@ THE SOFTWARE.
<groupId>org.eclipse.jetty.ee8</groupId>
<artifactId>jetty-ee8-webapp</artifactId>
<exclusions>
<!-- Provided by io.jenkins.servlet:javax-servlet-api -->
<exclusion>
<groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-servlet-api</artifactId>
</exclusion>
<!-- Provided by Jenkins core -->
<exclusion>
<groupId>org.slf4j</groupId>
Expand All @@ -140,6 +157,39 @@ THE SOFTWARE.
<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 io.jenkins.servlet:javax-servlet-api -->
<exclusion>
<groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-servlet-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>
<exclusions>
<!-- Provided by Jenkins core -->
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.ee9.websocket</groupId>
<artifactId>jetty-ee9-websocket-jetty-server</artifactId>
<!-- or jetty-ee9-websocket-javax-server -->
<exclusions>
<!-- Provided by Jenkins core -->
<exclusion>
Expand Down
72 changes: 59 additions & 13 deletions src/main/java/jenkins/benchmark/jmh/JmhBenchmarkState.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
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;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletContext;
import jenkins.model.Jenkins;
import jenkins.model.JenkinsLocationConfiguration;
import org.eclipse.jetty.ee8.webapp.WebAppContext;
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;
import org.jvnet.hudson.test.TestPluginManager;
Expand Down Expand Up @@ -79,7 +84,11 @@ public final void terminateJenkins() {
} finally {
JenkinsRule._stopJenkins(server, null, jenkins);
try {
JavaNetReverseProxy.getInstance().stop();
if (_isEE9Plus()) {
JavaNetReverseProxy2.getInstance().stop();
} else {
JavaNetReverseProxy.getInstance().stop();
}
} catch (Exception e) {
LOGGER.log(Level.WARNING, "Unable to stop JavaNetReverseProxy server", e);
}
Expand All @@ -93,17 +102,45 @@ public final void terminateJenkins() {
}

private void launchInstance() throws Exception {
WebAppContext context = JenkinsRule._createWebAppContext(
contextPath,
localPort::set,
getClass().getClassLoader(),
localPort.get(),
JenkinsRule::_configureUserRealm);
server = context.getServer();

ServletContext webServer = context.getServletContext();
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);
}

jenkins = new Hudson(temporaryDirectoryAllocator.allocate(), webServer, TestPluginManager.INSTANCE);
JenkinsRule._configureJenkinsForTest(jenkins);
JenkinsRule._configureUpdateCenter(jenkins);
jenkins.getActions().add(this);
Expand All @@ -113,6 +150,15 @@ 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
14 changes: 10 additions & 4 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,8 @@
import hudson.model.Descriptor;
import hudson.slaves.ComputerConnector;
import hudson.slaves.ComputerConnectorDescriptor;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.StaplerRequest;

/**
Expand All @@ -47,8 +46,15 @@
this.testCase = testCase;
}

public void doConfigSubmit(StaplerRequest req) throws IOException, ServletException {
connector = req.bindJSON(ComputerConnector.class, req.getSubmittedForm().getJSONObject("connector"));
public void doConfigSubmit(StaplerRequest req) {
JSONObject form;
try {
form = req.getSubmittedForm();
} catch (Exception e) {
// TODO stop wrapping once we drop support for EE 8

Check warning on line 54 in src/main/java/org/jvnet/hudson/test/ComputerConnectorTester.java

View check run for this annotation

ci.jenkins.io / Open Tasks Scanner

TODO

NORMAL: stop wrapping once we drop support for EE 8
throw new RuntimeException(e);
}
connector = req.bindJSON(ComputerConnector.class, form.getJSONObject("connector"));
}

public List<ComputerConnectorDescriptor> getConnectorDescriptors() {
Expand Down
Loading
Loading