Fixing JPMS testing issues.

+ Removing jetty-cdi module-info.java
+ Adding requires java.xml to jetty-http-spi

Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
This commit is contained in:
Joakim Erdfelt 2020-09-24 15:41:39 -05:00
parent 7622dec391
commit 4288fd863d
No known key found for this signature in database
GPG Key ID: 2D0E1FB8FE4B68B4
6 changed files with 76 additions and 39 deletions

View File

@ -41,6 +41,11 @@
<artifactId>jetty-slf4j-impl</artifactId> <artifactId>jetty-slf4j-impl</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.jboss.weld.servlet</groupId> <groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-servlet-core</artifactId> <artifactId>weld-servlet-core</artifactId>
@ -50,6 +55,17 @@
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<!--<argLine>
@{argLine} ${jetty.surefire.argLine} &#45;&#45;add-opens=org.eclipse.jetty.cdi/org.eclipse.jetty.cdi=ALL-UNNAMED
</argLine>-->
<additionalClasspathElements />
</configuration>
</plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId> <artifactId>maven-assembly-plugin</artifactId>

View File

@ -1,25 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
module org.eclipse.jetty.cdi
{
requires org.eclipse.jetty.annotations;
requires transitive org.eclipse.jetty.webapp;
exports org.eclipse.jetty.cdi;
}

View File

@ -16,8 +16,9 @@
// ======================================================================== // ========================================================================
// //
package org.eclipse.jetty.embedded; package org.eclipse.jetty.cdi;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.EnumSet; import java.util.EnumSet;
import javax.enterprise.inject.Produces; import javax.enterprise.inject.Produces;
@ -39,7 +40,6 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.annotations.AnnotationConfiguration; import org.eclipse.jetty.annotations.AnnotationConfiguration;
import org.eclipse.jetty.cdi.CdiConfiguration;
import org.eclipse.jetty.server.LocalConnector; import org.eclipse.jetty.server.LocalConnector;
import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ListenerHolder; import org.eclipse.jetty.servlet.ListenerHolder;
@ -54,13 +54,38 @@ import static org.hamcrest.Matchers.containsString;
public class EmbeddedWeldTest public class EmbeddedWeldTest
{ {
static
{
// Wire up java.util.logging (used by weld) to slf4j.
org.slf4j.bridge.SLF4JBridgeHandler.removeHandlersForRootLogger();
org.slf4j.bridge.SLF4JBridgeHandler.install();
}
// @BeforeEach
public void dumpClassLoaderState()
{
String[] cpEntries = System.getProperty("java.class.path").split(File.pathSeparator);
for (int i = 0; i < cpEntries.length; i++)
{
String entry = cpEntries[i];
if (entry.contains(".m2/repo"))
System.out.print(" maven");
else if (entry.contains("/idea"))
System.out.print(" idea ");
else if (entry.contains("/target/"))
System.out.print("*JETTY");
System.out.printf(" [%2d] %s%n", i, entry);
}
}
public static Server createServerWithServletContext(String mode) public static Server createServerWithServletContext(String mode)
{ {
Server server = new Server(); Server server = new Server();
server.addConnector(new LocalConnector(server)); server.addConnector(new LocalConnector(server));
ServletContextHandler context = new ServletContextHandler(); ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/"); context.setContextPath("/");
context.setResourceBase("src/test/resources/weldtest"); context.setResourceBase("src/test/weldtest");
server.setHandler(context); server.setHandler(context);
// Setup context // Setup context
@ -71,7 +96,7 @@ public class EmbeddedWeldTest
// Setup Jetty weld integration // Setup Jetty weld integration
switch (mode) switch (mode)
{ {
case "none" : // Do nothing, let weld work it out. case "none": // Do nothing, let weld work it out.
// Expect:INFO: WELD-ENV-001201: Jetty 7.2+ detected, CDI injection will be available in Servlets and Filters. Injection into Listeners is not supported. // Expect:INFO: WELD-ENV-001201: Jetty 7.2+ detected, CDI injection will be available in Servlets and Filters. Injection into Listeners is not supported.
context.getServletHandler().addListener(new ListenerHolder(org.jboss.weld.environment.servlet.Listener.class)); context.getServletHandler().addListener(new ListenerHolder(org.jboss.weld.environment.servlet.Listener.class));
break; break;
@ -162,22 +187,39 @@ public class EmbeddedWeldTest
server.stop(); server.stop();
} }
@Test
public void testServletContextSimone() throws Exception
{
Server server = createServerWithServletContext("none");
server.start();
LocalConnector connector = server.getBean(LocalConnector.class);
String response = connector.getResponse("GET / HTTP/1.0\r\n\r\n");
assertThat(response, containsString("HTTP/1.1 200 OK"));
assertThat(response, containsString("Hello GreetingsServlet filtered by Weld BeanManager "));
assertThat(response, containsString("Beans from Weld BeanManager "));
assertThat(response, containsString("Listener saw null"));
assertThat(response, containsString("Beans from Weld BeanManager for "));
server.stop();
}
@Test @Test
public void testWebappContext() throws Exception public void testWebappContext() throws Exception
{ {
Server server = new Server(8080); Server server = new Server();
server.addConnector(new LocalConnector(server)); server.addConnector(new LocalConnector(server));
WebAppContext webapp = new WebAppContext(); WebAppContext webapp = new WebAppContext();
webapp.setContextPath("/"); webapp.setContextPath("/");
webapp.setResourceBase("src/test/resources/weldtest"); webapp.setResourceBase("src/test/weldtest");
server.setHandler(webapp); server.setHandler(webapp);
webapp.setInitParameter(org.eclipse.jetty.cdi.CdiServletContainerInitializer.CDI_INTEGRATION_ATTRIBUTE, org.eclipse.jetty.cdi.CdiDecoratingListener.MODE); webapp.setInitParameter(org.eclipse.jetty.cdi.CdiServletContainerInitializer.CDI_INTEGRATION_ATTRIBUTE, org.eclipse.jetty.cdi.CdiDecoratingListener.MODE);
webapp.addBean(new ServletContextHandler.Initializer(webapp, new org.eclipse.jetty.cdi.CdiServletContainerInitializer())); webapp.addBean(new ServletContextHandler.Initializer(webapp, new org.eclipse.jetty.cdi.CdiServletContainerInitializer()));
webapp.addBean(new ServletContextHandler.Initializer(webapp, new org.jboss.weld.environment.servlet.EnhancedListener())); webapp.addBean(new ServletContextHandler.Initializer(webapp, new org.jboss.weld.environment.servlet.EnhancedListener()));
webapp.getServerClassMatcher().add("-org.eclipse.jetty.embedded."); String pkg = EmbeddedWeldTest.class.getPackage().getName();
webapp.getSystemClassMatcher().add("org.eclipse.jetty.embedded."); webapp.getServerClassMatcher().add("-" + pkg + ".");
webapp.getSystemClassMatcher().add(pkg + ".");
webapp.addServlet(GreetingsServlet.class, "/"); webapp.addServlet(GreetingsServlet.class, "/");
webapp.addFilter(MyFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST)); webapp.addFilter(MyFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
@ -197,11 +239,11 @@ public class EmbeddedWeldTest
@Test @Test
public void testWebappContextDiscovered() throws Exception public void testWebappContextDiscovered() throws Exception
{ {
Server server = new Server(8080); Server server = new Server();
server.addConnector(new LocalConnector(server)); server.addConnector(new LocalConnector(server));
WebAppContext webapp = new WebAppContext(); WebAppContext webapp = new WebAppContext();
webapp.setContextPath("/"); webapp.setContextPath("/");
webapp.setResourceBase("src/test/resources/weldtest"); webapp.setResourceBase("src/test/weldtest");
server.setHandler(webapp); server.setHandler(webapp);
// Need the AnnotationConfiguration to detect SCIs // Need the AnnotationConfiguration to detect SCIs
@ -211,8 +253,9 @@ public class EmbeddedWeldTest
webapp.addConfiguration(new CdiConfiguration()); webapp.addConfiguration(new CdiConfiguration());
// This is ugly but needed for maven for testing in a overlaid war pom // This is ugly but needed for maven for testing in a overlaid war pom
webapp.getServerClassMatcher().add("-org.eclipse.jetty.embedded."); String pkg = EmbeddedWeldTest.class.getPackage().getName();
webapp.getSystemClassMatcher().add("org.eclipse.jetty.embedded."); webapp.getServerClassMatcher().add("-" + pkg + ".");
webapp.getSystemClassMatcher().add(pkg + ".");
webapp.getServletHandler().addListener(new ListenerHolder(MyContextListener.class)); webapp.getServletHandler().addListener(new ListenerHolder(MyContextListener.class));
webapp.addFilter(MyFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST)); webapp.addFilter(MyFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
@ -228,7 +271,6 @@ public class EmbeddedWeldTest
assertThat(response, containsString("Beans from Weld BeanManager ")); assertThat(response, containsString("Beans from Weld BeanManager "));
assertThat(response, containsString("Listener saw Weld BeanManager")); assertThat(response, containsString("Listener saw Weld BeanManager"));
server.stop(); server.stop();
} }
public static class MyContextListener implements ServletContextListener public static class MyContextListener implements ServletContextListener
@ -324,5 +366,4 @@ public class EmbeddedWeldTest
return () -> "Salutations!"; return () -> "Salutations!";
} }
} }
} }

View File

@ -0,0 +1,4 @@
# Jetty Logging using jetty-slf4j-impl
org.eclipse.jetty.LEVEL=INFO
org.eclipse.jetty.cdi.LEVEL=DEBUG
org.jboss.LEVEL=DEBUG

View File

View File

@ -19,6 +19,7 @@
module org.eclipse.jetty.http.spi module org.eclipse.jetty.http.spi
{ {
requires transitive jdk.httpserver; requires transitive jdk.httpserver;
requires transitive java.xml;
requires transitive org.eclipse.jetty.server; requires transitive org.eclipse.jetty.server;
requires transitive org.eclipse.jetty.util; requires transitive org.eclipse.jetty.util;