Issue #5264 - making embedded examples more reliable
+ Discovering ${jetty.version} better + Creating ${jetty.base}/logs/ on JettyDemoBase usage Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
This commit is contained in:
parent
5d73b42fb3
commit
0f3c41c3ee
|
@ -153,8 +153,90 @@
|
|||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-home</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>tar.gz</type>
|
||||
<type>zip</type>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.jboss.logging</groupId>
|
||||
<artifactId>jboss-logging</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-spring</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.eclipse.jetty.fcgi</groupId>
|
||||
<artifactId>fcgi-server</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-cdi</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-openid</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>infinispan-embedded</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>infinispan-embedded-query</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>infinispan-remote</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>infinispan-remote-query</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.eclipse.jetty.gcloud</groupId>
|
||||
<artifactId>jetty-gcloud-session-manager</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-jaspi</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-hazelcast</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.eclipse.jetty.memcached</groupId>
|
||||
<artifactId>jetty-memcached-sessions</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-nosql</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.eclipse.jetty.demos</groupId>
|
||||
<artifactId>demo-jetty-webapp</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.eclipse.jetty.demos</groupId>
|
||||
<artifactId>demo-jndi-webapp</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.eclipse.jetty.demos</groupId>
|
||||
<artifactId>demo-jaas-webapp</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.eclipse.jetty.demos</groupId>
|
||||
<artifactId>demo-spec-webapp</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.eclipse.jetty.demos</groupId>
|
||||
<artifactId>demo-proxy-webapp</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.eclipse.jetty.demos</groupId>
|
||||
<artifactId>demo-async-rest-webapp</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
|
|
@ -18,12 +18,14 @@
|
|||
|
||||
package org.eclipse.jetty.embedded;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -62,24 +64,44 @@ public class JettyDemoBase
|
|||
jettyBase = Files.createTempDirectory("jetty-base");
|
||||
|
||||
Path startJar = jettyHome.resolve("start.jar");
|
||||
|
||||
URLClassLoader urlClassLoader = new URLClassLoader(new URL[]{
|
||||
startJar.toUri().toURL()
|
||||
});
|
||||
|
||||
Thread.currentThread().setContextClassLoader(urlClassLoader);
|
||||
|
||||
String pomRef = "META-INF/maven/org.eclipse.jetty/jetty-start/pom.properties";
|
||||
URL urlPom = urlClassLoader.findResource(pomRef);
|
||||
if (urlPom == null)
|
||||
throw new IllegalStateException("Unable to find " + pomRef);
|
||||
|
||||
String jettyVersion = null;
|
||||
|
||||
try (InputStream input = urlPom.openStream())
|
||||
{
|
||||
Properties pomProps = new Properties();
|
||||
pomProps.load(input);
|
||||
jettyVersion = pomProps.getProperty("version");
|
||||
}
|
||||
|
||||
Class<?> mainClass = urlClassLoader.loadClass("org.eclipse.jetty.start.Main");
|
||||
Method mainMethod = mainClass.getMethod("main", String[].class);
|
||||
|
||||
String[] args = new String[]{
|
||||
"jetty.version=" + jettyVersion,
|
||||
"jetty.home=" + jettyHome.toString(),
|
||||
"jetty.base=" + jettyBase.toString(),
|
||||
"--add-modules=demo"
|
||||
"--add-modules=logging-jetty,demo"
|
||||
};
|
||||
|
||||
LOG.info("Creating DemoBase in {}", jettyBase);
|
||||
mainMethod.invoke(mainClass, new Object[]{args});
|
||||
|
||||
Path logsDir = jettyBase.resolve("logs");
|
||||
if (!Files.exists(logsDir))
|
||||
Files.createDirectory(logsDir);
|
||||
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("JettyHome(working.resolve(...)) = {}", jettyBase);
|
||||
}
|
||||
|
|
|
@ -34,7 +34,6 @@ import org.eclipse.jetty.io.ConnectionStatistics;
|
|||
import org.eclipse.jetty.jmx.MBeanContainer;
|
||||
import org.eclipse.jetty.plus.webapp.EnvConfiguration;
|
||||
import org.eclipse.jetty.plus.webapp.PlusConfiguration;
|
||||
import org.eclipse.jetty.rewrite.handler.MsieSslRule;
|
||||
import org.eclipse.jetty.rewrite.handler.RewriteHandler;
|
||||
import org.eclipse.jetty.rewrite.handler.ValidUrlRule;
|
||||
import org.eclipse.jetty.security.HashLoginService;
|
||||
|
@ -169,7 +168,6 @@ public class LikeJettyXml
|
|||
RewriteHandler rewrite = new RewriteHandler();
|
||||
rewrite.setHandler(server.getHandler());
|
||||
server.setHandler(rewrite);
|
||||
rewrite.addRule(new MsieSslRule());
|
||||
rewrite.addRule(new ValidUrlRule());
|
||||
|
||||
// === jetty-requestlog.xml ===
|
||||
|
@ -192,7 +190,7 @@ public class LikeJettyXml
|
|||
// === test-realm.xml ===
|
||||
HashLoginService login = new HashLoginService();
|
||||
login.setName("Test Realm");
|
||||
login.setConfig(jettyBase + "/etc/realm.properties");
|
||||
login.setConfig(jettyBase + "/etc/demo-realm.properties");
|
||||
login.setHotReload(false);
|
||||
server.addBean(login);
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ public class LikeJettyXmlTest extends AbstractEmbeddedTest
|
|||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
assumeTrue(JettyHome.JETTY_HOME != null, "jetty-distribution not found");
|
||||
assumeTrue(JettyHome.JETTY_HOME != null, "jetty-home not found");
|
||||
|
||||
server = LikeJettyXml.createServer(0, 0, false);
|
||||
server.start();
|
||||
|
|
Loading…
Reference in New Issue