Skip to content

Commit

Permalink
Avoid usage of Server#getChildHandlerByClass (#767)
Browse files Browse the repository at this point in the history
  • Loading branch information
basil authored May 9, 2024
1 parent 4c06633 commit b580989
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/main/java/jenkins/benchmark/jmh/JmhBenchmarkState.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import jenkins.model.Jenkins;
import jenkins.model.JenkinsLocationConfiguration;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.webapp.WebAppContext;
import org.jvnet.hudson.test.JavaNetReverseProxy;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.TemporaryDirectoryAllocator;
Expand Down Expand Up @@ -93,15 +93,15 @@ public final void terminateJenkins() {
}

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

ServletContext webServer =
server.getChildHandlerByClass(ContextHandler.class).getServletContext();
ServletContext webServer = context.getServletContext();

jenkins = new Hudson(temporaryDirectoryAllocator.allocate(), webServer, TestPluginManager.INSTANCE);
JenkinsRule._configureJenkinsForTest(jenkins);
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/org/jvnet/hudson/test/JenkinsRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@
import org.eclipse.jetty.server.HttpConnectionFactory;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.util.security.Password;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.eclipse.jetty.webapp.Configuration;
Expand Down Expand Up @@ -800,15 +799,16 @@ protected ServletContext createWebServer() throws Exception {
*/
protected ServletContext createWebServer(@CheckForNull BiConsumer<WebAppContext, Server> contextAndServerConsumer)
throws Exception {
server = _createWebServer(
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 server.getChildHandlerByClass(ContextHandler.class).getServletContext();
return context.getServletContext();
}

/**
Expand All @@ -822,14 +822,14 @@ protected ServletContext createWebServer(@CheckForNull BiConsumer<WebAppContext,
* @return the {@link Server}
* @since 2.50
*/
public static Server _createWebServer(
public static WebAppContext _createWebAppContext(
String contextPath,
Consumer<Integer> portSetter,
ClassLoader classLoader,
int localPort,
Supplier<LoginService> loginServiceSupplier)
throws Exception {
return _createWebServer(contextPath, portSetter, classLoader, localPort, loginServiceSupplier, null);
return _createWebAppContext(contextPath, portSetter, classLoader, localPort, loginServiceSupplier, null);
}
/**
* Creates a web server on which Jenkins can run
Expand All @@ -843,7 +843,7 @@ public static Server _createWebServer(
* @return the {@link Server}
* @since 2.50
*/
public static Server _createWebServer(
public static WebAppContext _createWebAppContext(
String contextPath,
Consumer<Integer> portSetter,
ClassLoader classLoader,
Expand Down Expand Up @@ -886,7 +886,7 @@ public static Server _createWebServer(

portSetter.accept(connector.getLocalPort());

return server;
return context;
}

/**
Expand Down

0 comments on commit b580989

Please sign in to comment.