From 0f3c41c3ee5b3e5c8e3d58c593ef97edab284805 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Wed, 23 Sep 2020 17:43:36 -0500 Subject: [PATCH] Issue #5264 - making embedded examples more reliable + Discovering ${jetty.version} better + Creating ${jetty.base}/logs/ on JettyDemoBase usage Signed-off-by: Joakim Erdfelt --- examples/embedded/pom.xml | 84 ++++++++++++++++++- .../eclipse/jetty/embedded/JettyDemoBase.java | 24 +++++- .../eclipse/jetty/embedded/LikeJettyXml.java | 4 +- .../jetty/embedded/LikeJettyXmlTest.java | 2 +- 4 files changed, 108 insertions(+), 6 deletions(-) diff --git a/examples/embedded/pom.xml b/examples/embedded/pom.xml index daf8fa359bf..355b0b1aa63 100644 --- a/examples/embedded/pom.xml +++ b/examples/embedded/pom.xml @@ -153,8 +153,90 @@ org.eclipse.jetty jetty-home ${project.version} - tar.gz + zip test + + + org.jboss.logging + jboss-logging + + + org.eclipse.jetty + jetty-spring + + + org.eclipse.jetty.fcgi + fcgi-server + + + org.eclipse.jetty + jetty-cdi + + + org.eclipse.jetty + jetty-openid + + + org.eclipse.jetty + infinispan-embedded + + + org.eclipse.jetty + infinispan-embedded-query + + + org.eclipse.jetty + infinispan-remote + + + org.eclipse.jetty + infinispan-remote-query + + + org.eclipse.jetty.gcloud + jetty-gcloud-session-manager + + + org.eclipse.jetty + jetty-jaspi + + + org.eclipse.jetty + jetty-hazelcast + + + org.eclipse.jetty.memcached + jetty-memcached-sessions + + + org.eclipse.jetty + jetty-nosql + + + org.eclipse.jetty.demos + demo-jetty-webapp + + + org.eclipse.jetty.demos + demo-jndi-webapp + + + org.eclipse.jetty.demos + demo-jaas-webapp + + + org.eclipse.jetty.demos + demo-spec-webapp + + + org.eclipse.jetty.demos + demo-proxy-webapp + + + org.eclipse.jetty.demos + demo-async-rest-webapp + + diff --git a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/JettyDemoBase.java b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/JettyDemoBase.java index c87ee3afc9f..bb7f8f9e530 100644 --- a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/JettyDemoBase.java +++ b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/JettyDemoBase.java @@ -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); } diff --git a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/LikeJettyXml.java b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/LikeJettyXml.java index d5171cdd1a8..630ae031a88 100644 --- a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/LikeJettyXml.java +++ b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/LikeJettyXml.java @@ -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); diff --git a/examples/embedded/src/test/java/org/eclipse/jetty/embedded/LikeJettyXmlTest.java b/examples/embedded/src/test/java/org/eclipse/jetty/embedded/LikeJettyXmlTest.java index 0ff6f029570..dead1f52d84 100644 --- a/examples/embedded/src/test/java/org/eclipse/jetty/embedded/LikeJettyXmlTest.java +++ b/examples/embedded/src/test/java/org/eclipse/jetty/embedded/LikeJettyXmlTest.java @@ -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();