sortedEnvXmlPaths = appAttributes.getAttributeNameSet()
.stream()
.filter(k -> k.startsWith(Deployable.ENVIRONMENT_XML))
- .map(k -> Path.of((String)appAttributes.getAttribute(k)))
+ .map(k ->
+ {
+ Path envXmlPath = Paths.get((String)appAttributes.getAttribute(k));
+ if (!envXmlPath.isAbsolute())
+ envXmlPath = getMonitoredDirResource().getPath().getParent().resolve(envXmlPath);
+ return envXmlPath;
+ })
+ .filter(Files::isRegularFile)
.sorted()
.toList();
@@ -227,8 +236,8 @@ else if (!Files.isDirectory(path) && !FileID.isWebArchive(path))
* do not declare the {@link Environment} that they belong to.
*
*
- * Falls back to {@link Environment#getAll()} list, and returns
- * the first name returned after sorting with {@link Deployable#ENVIRONMENT_COMPARATOR}
+ * Falls back to {@link Environment#getAll()} list, and returns
+ * the first name returned after sorting with {@link Deployable#ENVIRONMENT_COMPARATOR}
*
*
* @return the default environment name.
@@ -277,6 +286,46 @@ public void loadPropertiesFromString(Environment environment, String path) throw
loadProperties(environment, Path.of(path));
}
+ /**
+ * Configure the Environment specific Deploy settings.
+ *
+ * @param name the name of the environment.
+ * @return the deployment configuration for the {@link Environment}.
+ */
+ public EnvironmentConfig configureEnvironment(String name)
+ {
+ return new EnvironmentConfig(Environment.ensure(name));
+ }
+
+ /**
+ * To enable support for an {@link Environment}, just ensure it exists.
+ *
+ *
+ * Eg: {@code Environment.ensure("ee11");}
+ *
+ *
+ *
+ * To configure Environment specific deployment {@link Attributes},
+ * either set the appropriate {@link Deployable} attribute via {@link Attributes#setAttribute(String, Object)},
+ * or use the convenience class {@link EnvironmentConfig}.
+ *
+ *
+ * {@code
+ * ContextProvider provider = new ContextProvider();
+ * ContextProvider.EnvironmentConfig envbuilder = provider.configureEnvironment("ee10");
+ * envbuilder.setExtractWars(true);
+ * envbuilder.setParentLoaderPriority(false);
+ * }
+ *
+ * @see #configureEnvironment(String) instead
+ * @deprecated not used anymore.
+ */
+ @Deprecated(since = "12.1.0", forRemoval = true)
+ public void setEnvironmentName(String name)
+ {
+ Environment.ensure(name);
+ }
+
protected Object applyXml(Object context, Path xml, Environment environment, Attributes attributes) throws Exception
{
if (!FileID.isXml(xml))
@@ -511,6 +560,7 @@ protected void pathChanged(Path path) throws Exception
/**
* Get the ClassLoader appropriate for applying Jetty XML.
+ *
* @param environment the environment to use
* @param xml the path to the XML
* @return the appropriate ClassLoader.
@@ -562,8 +612,8 @@ private Attributes initAttributes(Environment environment, App app) throws IOExc
* found in the directory provided.
*
*
- * All found properties files are first sorted by filename, then loaded one by one into
- * a single {@link Properties} instance.
+ * All found properties files are first sorted by filename, then loaded one by one into
+ * a single {@link Properties} instance.
*
*
* @param directory the directory to load environment properties from.
@@ -625,12 +675,12 @@ private void loadProperties(Environment environment, InputStream inputStream) th
* Builder of a deployment configuration for a specific {@link Environment}.
*
*
- * Results in {@link Attributes} for {@link Environment} containing the
- * deployment configuration (as {@link Deployable} keys) that is applied to all deployable
- * apps belonging to that {@link Environment}.
+ * Results in {@link Attributes} for {@link Environment} containing the
+ * deployment configuration (as {@link Deployable} keys) that is applied to all deployable
+ * apps belonging to that {@link Environment}.
*
*/
- public static class EnvBuilder
+ public static class EnvironmentConfig
{
// Using setters in this class to allow jetty-xml
// syntax to skip setting of an environment attribute if property is unset,
@@ -638,9 +688,9 @@ public static class EnvBuilder
private final Environment environment;
- public EnvBuilder(String name)
+ private EnvironmentConfig(Environment environment)
{
- environment = Environment.ensure(name);
+ this.environment = environment;
}
/**
diff --git a/jetty-core/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/DeploymentManagerTest.java b/jetty-core/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/DeploymentManagerTest.java
index 2bd5d43f3646..432501a67e62 100644
--- a/jetty-core/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/DeploymentManagerTest.java
+++ b/jetty-core/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/DeploymentManagerTest.java
@@ -165,7 +165,7 @@ public void testXmlConfigured(WorkDir workDir) throws Exception
jetty = new XmlConfiguredJetty(testdir);
jetty.addConfiguration("jetty.xml");
jetty.addConfiguration("jetty-http.xml");
- jetty.addConfiguration("jetty-deploymgr-contexts.xml");
+ jetty.addConfiguration("jetty-core-deploy-custom.xml");
// Should not throw an Exception
jetty.load();
diff --git a/jetty-core/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/ContextProviderDeferredStartupTest.java b/jetty-core/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/ContextProviderDeferredStartupTest.java
index cda077a79211..c85948ce1788 100644
--- a/jetty-core/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/ContextProviderDeferredStartupTest.java
+++ b/jetty-core/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/ContextProviderDeferredStartupTest.java
@@ -27,14 +27,13 @@
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.toolchain.test.FS;
+import org.eclipse.jetty.toolchain.test.MavenPaths;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
import org.eclipse.jetty.util.Scanner;
import org.eclipse.jetty.util.component.Container;
import org.eclipse.jetty.util.component.LifeCycle;
-import org.eclipse.jetty.util.resource.Resource;
import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -68,7 +67,9 @@ public void testDelayedDeploy() throws Exception
jetty = new XmlConfiguredJetty(realBase);
jetty.addConfiguration("jetty.xml");
jetty.addConfiguration("jetty-http.xml");
- jetty.addConfiguration("jetty-deploymgr-contexts.xml");
+ jetty.addConfiguration(MavenPaths.projectBase().resolve("src/main/config/etc/jetty-deployment-manager.xml"));
+ jetty.addConfiguration(MavenPaths.projectBase().resolve("src/main/config/etc/jetty-deploy.xml"));
+ jetty.addConfiguration("jetty-core-deploy-custom.xml");
// Put a context into the base
jetty.copyWebapp("bar-core-context.xml", "bar.xml");
diff --git a/jetty-core/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/ContextProviderRuntimeUpdatesTest.java b/jetty-core/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/ContextProviderRuntimeUpdatesTest.java
index 977db71608ea..a600972b985c 100644
--- a/jetty-core/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/ContextProviderRuntimeUpdatesTest.java
+++ b/jetty-core/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/ContextProviderRuntimeUpdatesTest.java
@@ -25,6 +25,7 @@
import org.eclipse.jetty.deploy.test.XmlConfiguredJetty;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.toolchain.test.FS;
+import org.eclipse.jetty.toolchain.test.MavenPaths;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
import org.eclipse.jetty.util.Scanner;
@@ -80,7 +81,9 @@ public void startJetty() throws Exception
{
jetty.addConfiguration("jetty.xml");
jetty.addConfiguration("jetty-http.xml");
- jetty.addConfiguration("jetty-deploymgr-contexts.xml");
+ jetty.addConfiguration(MavenPaths.projectBase().resolve("src/main/config/etc/jetty-deployment-manager.xml"));
+ jetty.addConfiguration(MavenPaths.projectBase().resolve("src/main/config/etc/jetty-deploy.xml"));
+ jetty.addConfiguration("jetty-core-deploy-custom.xml");
// Should not throw an Exception
jetty.load();
diff --git a/jetty-core/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/ContextProviderStartupTest.java b/jetty-core/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/ContextProviderStartupTest.java
index a68db97d0e66..9fc7c0a25e0b 100644
--- a/jetty-core/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/ContextProviderStartupTest.java
+++ b/jetty-core/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/ContextProviderStartupTest.java
@@ -37,7 +37,6 @@
import static org.hamcrest.Matchers.equalTo;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
@@ -63,7 +62,9 @@ public void setupEnvironment() throws Exception
jetty.addConfiguration("jetty.xml");
jetty.addConfiguration("jetty-http.xml");
- jetty.addConfiguration("jetty-deploymgr-contexts.xml");
+ jetty.addConfiguration(MavenPaths.projectBase().resolve("src/main/config/etc/jetty-deployment-manager.xml"));
+ jetty.addConfiguration(MavenPaths.projectBase().resolve("src/main/config/etc/jetty-deploy.xml"));
+ jetty.addConfiguration("jetty-core-deploy-custom.xml");
// Setup initial context
jetty.copyWebapp("bar-core-context.xml", "bar.xml");
@@ -167,7 +168,6 @@ public void testNonEnvironmentPropertyFileNotApplied() throws Exception
/**
* Test that properties of the same name will be overridden, in the order of the name of the .properties file
- * @throws Exception
*/
@Test
public void testPropertyOverriding() throws Exception
diff --git a/jetty-core/jetty-deploy/src/test/resources/jetty-core-deploy-custom.xml b/jetty-core/jetty-deploy/src/test/resources/jetty-core-deploy-custom.xml
new file mode 100644
index 000000000000..748ab6ecbda8
--- /dev/null
+++ b/jetty-core/jetty-deploy/src/test/resources/jetty-core-deploy-custom.xml
@@ -0,0 +1,21 @@
+
+
+
+
+ core
+
+
+
+
+
+ core
+
+
+
+
+
+
+
+
+
+
diff --git a/jetty-core/jetty-deploy/src/test/resources/jetty-deploymgr-contexts.xml b/jetty-core/jetty-deploy/src/test/resources/jetty-deploymgr-contexts.xml
deleted file mode 100644
index 0b3431bd2225..000000000000
--- a/jetty-core/jetty-deploy/src/test/resources/jetty-deploymgr-contexts.xml
+++ /dev/null
@@ -1,40 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- core
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-integration/src/test/java/org/eclipse/jetty/ee10/test/DeploymentErrorTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-integration/src/test/java/org/eclipse/jetty/ee10/test/DeploymentErrorTest.java
index 89877be22cba..b7daf2bb4952 100644
--- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-integration/src/test/java/org/eclipse/jetty/ee10/test/DeploymentErrorTest.java
+++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-integration/src/test/java/org/eclipse/jetty/ee10/test/DeploymentErrorTest.java
@@ -107,7 +107,7 @@ public Path startServer(Consumer docrootSetupConsumer) throws Exception
System.setProperty("test.docroots", docroots.toAbsolutePath().toString());
ContextProvider appProvider = new ContextProvider();
- appProvider.setEnvironmentName("ee10");
+ appProvider.configureEnvironment("ee10");
appProvider.setScanInterval(1);
appProvider.setMonitoredDirResource(resourceFactory.newResource(docroots));
diff --git a/jetty-ee10/jetty-ee10-webapp/src/main/config/etc/jetty-ee10-deploy.xml b/jetty-ee10/jetty-ee10-webapp/src/main/config/etc/jetty-ee10-deploy.xml
index 3f5a24819b34..019157c06ce5 100644
--- a/jetty-ee10/jetty-ee10-webapp/src/main/config/etc/jetty-ee10-deploy.xml
+++ b/jetty-ee10/jetty-ee10-webapp/src/main/config/etc/jetty-ee10-deploy.xml
@@ -3,29 +3,31 @@
-
- ee10
-
-
-
-
-
- jetty.deploy.defaultsDescriptor
- jetty.deploy.defaultsDescriptorPath
-
- /etc/webdefault-ee10.xml
-
-
-
-
-
-
-
-
- .*/jakarta.servlet-api-[^/]*\.jar$|.*jakarta.servlet.jsp.jstl-.*\.jar$
-
-
-
-
-
+
+
+ ee10
+
+
+
+
+
+ jetty.deploy.defaultsDescriptorPath
+ jetty.deploy.defaultsDescriptor
+
+ /etc/webdefault-ee10.xml
+
+
+
+
+
+
+
+
+ .*/jakarta.servlet-api-[^/]*\.jar$|.*jakarta.servlet.jsp.jstl-.*\.jar$
+
+
+
+
+
+
diff --git a/jetty-ee10/jetty-ee10-webapp/src/main/config/modules/ee10-deploy.mod b/jetty-ee10/jetty-ee10-webapp/src/main/config/modules/ee10-deploy.mod
index a3e44ecc5c78..30f04501fb69 100644
--- a/jetty-ee10/jetty-ee10-webapp/src/main/config/modules/ee10-deploy.mod
+++ b/jetty-ee10/jetty-ee10-webapp/src/main/config/modules/ee10-deploy.mod
@@ -15,15 +15,6 @@ etc/jetty-ee10-deploy.xml
[ini-template]
# tag::ini-template[]
-## Monitored directory name (relative to $jetty.base)
-# jetty.deploy.monitoredDir=webapps
-
-## Defaults Descriptor for all deployed webapps
-# jetty.deploy.defaultsDescriptorPath=${jetty.base}/etc/webdefault-ee10.xml
-
-## Monitored directory scan period (seconds)
-# jetty.deploy.scanInterval=0
-
## Whether to extract *.war files
# jetty.deploy.extractWars=true
diff --git a/jetty-ee11/jetty-ee11-webapp/src/main/config/etc/jetty-ee11-deploy.xml b/jetty-ee11/jetty-ee11-webapp/src/main/config/etc/jetty-ee11-deploy.xml
index 415591463449..eeccefecff4a 100644
--- a/jetty-ee11/jetty-ee11-webapp/src/main/config/etc/jetty-ee11-deploy.xml
+++ b/jetty-ee11/jetty-ee11-webapp/src/main/config/etc/jetty-ee11-deploy.xml
@@ -3,29 +3,31 @@
-
- ee11
-
-
-
-
-
- jetty.deploy.defaultsDescriptor
- jetty.deploy.defaultsDescriptorPath
-
- /etc/webdefault-ee11.xml
-
-
-
-
-
-
-
-
- .*/jakarta.servlet-api-[^/]*\.jar$|.*jakarta.servlet.jsp.jstl-.*\.jar$
-
-
-
-
-
+
+
+ ee11
+
+
+
+
+
+ jetty.deploy.defaultsDescriptorPath
+ jetty.deploy.defaultsDescriptor
+
+ /etc/webdefault-ee11.xml
+
+
+
+
+
+
+
+
+ .*/jakarta.servlet-api-[^/]*\.jar$|.*jakarta.servlet.jsp.jstl-.*\.jar$
+
+
+
+
+
+
diff --git a/jetty-ee11/jetty-ee11-webapp/src/main/config/modules/ee11-deploy.mod b/jetty-ee11/jetty-ee11-webapp/src/main/config/modules/ee11-deploy.mod
index f36f320f7992..27a2ed0974c6 100644
--- a/jetty-ee11/jetty-ee11-webapp/src/main/config/modules/ee11-deploy.mod
+++ b/jetty-ee11/jetty-ee11-webapp/src/main/config/modules/ee11-deploy.mod
@@ -15,15 +15,9 @@ etc/jetty-ee11-deploy.xml
[ini-template]
# tag::ini-template[]
-## Monitored directory name (relative to $jetty.base)
-# jetty.deploy.monitoredDir=webapps
-
## Defaults Descriptor for all deployed webapps
# jetty.deploy.defaultsDescriptorPath=${jetty.base}/etc/webdefault-ee11.xml
-## Monitored directory scan period (seconds)
-# jetty.deploy.scanInterval=0
-
## Whether to extract *.war files
# jetty.deploy.extractWars=true
diff --git a/jetty-ee8/jetty-ee8-webapp/src/main/config/etc/jetty-ee8-deploy.xml b/jetty-ee8/jetty-ee8-webapp/src/main/config/etc/jetty-ee8-deploy.xml
index f75a07217839..fdb720ccb634 100644
--- a/jetty-ee8/jetty-ee8-webapp/src/main/config/etc/jetty-ee8-deploy.xml
+++ b/jetty-ee8/jetty-ee8-webapp/src/main/config/etc/jetty-ee8-deploy.xml
@@ -3,29 +3,31 @@
-
- ee8
-
-
-
-
-
- jetty.deploy.defaultsDescriptor
- jetty.deploy.defaultsDescriptorPath
-
- /etc/webdefault-ee8.xml
-
-
-
-
-
-
-
-
- .*/jakarta.servlet-api-[^/]*\.jar$|.*jakarta.servlet.jsp.jstl-.*\.jar$
-
-
-
-
-
+
+
+ ee8
+
+
+
+
+
+ jetty.deploy.defaultsDescriptorPath
+ jetty.deploy.defaultsDescriptor
+
+ /etc/webdefault-ee8.xml
+
+
+
+
+
+
+
+
+ .*/jakarta.servlet-api-[^/]*\.jar$|.*jakarta.servlet.jsp.jstl-.*\.jar$
+
+
+
+
+
+
diff --git a/jetty-ee8/jetty-ee8-webapp/src/main/config/modules/ee8-deploy.mod b/jetty-ee8/jetty-ee8-webapp/src/main/config/modules/ee8-deploy.mod
index 3d44d7d5bedd..6897cd9484a2 100644
--- a/jetty-ee8/jetty-ee8-webapp/src/main/config/modules/ee8-deploy.mod
+++ b/jetty-ee8/jetty-ee8-webapp/src/main/config/modules/ee8-deploy.mod
@@ -15,15 +15,9 @@ etc/jetty-ee8-deploy.xml
[ini-template]
# tag::ini-template[]
-## Monitored directory name (relative to $jetty.base)
-# jetty.deploy.monitoredDir=webapps
-
## Defaults Descriptor for all deployed webapps
# jetty.deploy.defaultsDescriptorPath=${jetty.base}/etc/webdefault-ee8.xml
-## Monitored directory scan period (seconds)
-# jetty.deploy.scanInterval=0
-
## Whether to extract *.war files
# jetty.deploy.extractWars=true
diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-integration/src/test/java/org/eclipse/jetty/ee9/test/DeploymentErrorTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-integration/src/test/java/org/eclipse/jetty/ee9/test/DeploymentErrorTest.java
index d9e73b607cbb..34fb6841dfe9 100644
--- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-integration/src/test/java/org/eclipse/jetty/ee9/test/DeploymentErrorTest.java
+++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-integration/src/test/java/org/eclipse/jetty/ee9/test/DeploymentErrorTest.java
@@ -102,7 +102,7 @@ public Path startServer(Consumer docrootSetupConsumer, Path docroots) thro
System.setProperty("test.docroots", docroots.toAbsolutePath().toString());
ContextProvider appProvider = new ContextProvider();
- appProvider.setEnvironmentName("ee9");
+ Environment.ensure("ee9");
appProvider.setMonitoredDirResource(resourceFactory.newResource(docroots));
appProvider.setScanInterval(1);
deploymentManager.addAppProvider(appProvider);
diff --git a/jetty-ee9/jetty-ee9-webapp/src/main/config/etc/jetty-ee9-deploy.xml b/jetty-ee9/jetty-ee9-webapp/src/main/config/etc/jetty-ee9-deploy.xml
index 9c7fc4abdb4d..4ff9703d3569 100644
--- a/jetty-ee9/jetty-ee9-webapp/src/main/config/etc/jetty-ee9-deploy.xml
+++ b/jetty-ee9/jetty-ee9-webapp/src/main/config/etc/jetty-ee9-deploy.xml
@@ -3,29 +3,31 @@
-
- ee9
-
-
-
-
-
- jetty.deploy.defaultsDescriptor
- jetty.deploy.defaultsDescriptorPath
-
- /etc/webdefault-ee9.xml
-
-
-
-
-
-
-
-
- .*/jakarta.servlet-api-[^/]*\.jar$|.*jakarta.servlet.jsp.jstl-.*\.jar$
-
-
-
-
-
+
+
+ ee9
+
+
+
+
+
+ jetty.deploy.defaultsDescriptorPath
+ jetty.deploy.defaultsDescriptor
+
+ /etc/webdefault-ee9.xml
+
+
+
+
+
+
+
+
+ .*/jakarta.servlet-api-[^/]*\.jar$|.*jakarta.servlet.jsp.jstl-.*\.jar$
+
+
+
+
+
+
diff --git a/jetty-ee9/jetty-ee9-webapp/src/main/config/modules/ee9-deploy.mod b/jetty-ee9/jetty-ee9-webapp/src/main/config/modules/ee9-deploy.mod
index 742f44c76019..75b121460f2d 100644
--- a/jetty-ee9/jetty-ee9-webapp/src/main/config/modules/ee9-deploy.mod
+++ b/jetty-ee9/jetty-ee9-webapp/src/main/config/modules/ee9-deploy.mod
@@ -15,15 +15,9 @@ etc/jetty-ee9-deploy.xml
[ini-template]
# tag::ini-template[]
-## Monitored directory name (relative to $jetty.base)
-# jetty.deploy.monitoredDir=webapps
-
## Defaults Descriptor for all deployed webapps
# jetty.deploy.defaultsDescriptorPath=${jetty.base}/etc/webdefault-ee9.xml
-## Monitored directory scan period (seconds)
-# jetty.deploy.scanInterval=0
-
## Whether to extract *.war files
# jetty.deploy.extractWars=true
From 42015b3fbd76242d59f72050b158a106cacf30fc Mon Sep 17 00:00:00 2001
From: Joakim Erdfelt
Date: Tue, 26 Nov 2024 15:22:19 -0600
Subject: [PATCH 06/22] Fixing [-zzz].properties sorting
---
.../jetty/deploy/providers/ContextProvider.java | 14 +++++++++++---
.../providers/ContextProviderStartupTest.java | 13 +++++++------
2 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/jetty-core/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/ContextProvider.java b/jetty-core/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/ContextProvider.java
index ee46a83037ec..7028e45ad550 100644
--- a/jetty-core/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/ContextProvider.java
+++ b/jetty-core/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/ContextProvider.java
@@ -45,6 +45,7 @@
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.annotation.ManagedObject;
import org.eclipse.jetty.util.component.Environment;
+import org.eclipse.jetty.util.resource.PathCollators;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.resource.ResourceFactory;
import org.eclipse.jetty.xml.XmlConfiguration;
@@ -167,11 +168,18 @@ public ContextHandler createContextHandler(final App app) throws Exception
{
Path envXmlPath = Paths.get((String)appAttributes.getAttribute(k));
if (!envXmlPath.isAbsolute())
- envXmlPath = getMonitoredDirResource().getPath().getParent().resolve(envXmlPath);
+ {
+ Path monitoredPath = getMonitoredDirResource().getPath();
+ // not all Resource implementations support java.nio.file.Path.
+ if (monitoredPath != null)
+ {
+ envXmlPath = monitoredPath.getParent().resolve(envXmlPath);
+ }
+ }
return envXmlPath;
})
.filter(Files::isRegularFile)
- .sorted()
+ .sorted(PathCollators.byName(true))
.toList();
// apply each environment context xml file
@@ -211,7 +219,7 @@ else if (!Files.isDirectory(path) && !FileID.isWebArchive(path))
// Build the web application if necessary
if (context == null)
{
- contextHandlerClassName = (String)environment.getAttribute(Deployable.CONTEXT_HANDLER_CLASS);
+ contextHandlerClassName = (String)appAttributes.getAttribute(Deployable.CONTEXT_HANDLER_CLASS);
if (StringUtil.isBlank(contextHandlerClassName))
throw new IllegalStateException("No ContextHandler classname for " + app);
Class> contextHandlerClass = Loader.loadClass(contextHandlerClassName);
diff --git a/jetty-core/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/ContextProviderStartupTest.java b/jetty-core/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/ContextProviderStartupTest.java
index 9fc7c0a25e0b..563c50b87f9a 100644
--- a/jetty-core/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/ContextProviderStartupTest.java
+++ b/jetty-core/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/ContextProviderStartupTest.java
@@ -123,17 +123,18 @@ public void testStartupWithRelativeEnvironmentContext() throws Exception
public void testStartupWithAbsoluteEnvironmentContext() throws Exception
{
Path jettyBase = jetty.getJettyBasePath();
- Path propsFile = Files.writeString(jettyBase.resolve("webapps/core.properties"), Deployable.ENVIRONMENT_XML + " = " +
- MavenPaths.findTestResourceFile("etc/core-context.xml"), StandardOpenOption.CREATE_NEW);
+ Path propsFile = Files.writeString(jettyBase.resolve("webapps/core.properties"),
+ String.format("%s = %s%n", Deployable.ENVIRONMENT_XML, MavenPaths.findTestResourceFile("etc/core-context.xml")),
+ StandardOpenOption.CREATE_NEW);
assertTrue(Files.exists(propsFile));
- Path props2File = Files.writeString(jettyBase.resolve("webapps/core-other.properties"), Deployable.ENVIRONMENT_XML + ".other = " + MavenPaths.findTestResourceFile("etc/core-context-other.xml"), StandardOpenOption.CREATE_NEW);
+ Path props2File = Files.writeString(jettyBase.resolve("webapps/core-other.properties"),
+ String.format("%s = %s%n", (Deployable.ENVIRONMENT_XML + ".other"), MavenPaths.findTestResourceFile("etc/core-context-other.xml")),
+ StandardOpenOption.CREATE_NEW);
assertTrue(Files.exists(props2File));
- Files.copy(MavenPaths.findTestResourceFile("etc/core-context.xml"), jettyBase.resolve("etc/core-context.xml"), StandardCopyOption.REPLACE_EXISTING);
- Files.copy(MavenPaths.findTestResourceFile("etc/core-context-other.xml"), jettyBase.resolve("etc/core-context-other.xml"), StandardCopyOption.REPLACE_EXISTING);
jetty.copyWebapp("bar-core-context.properties", "bar.properties");
startJetty();
- //check core environment context xml was applied to the produced context
+ // check core environment context xml was applied to the produced context
ContextHandler context = jetty.getContextHandler("/bar");
assertNotNull(context);
assertThat(context.getAttribute("core-context-0"), equalTo("core-context-0"));
From f9c90cec7d662497a015f6456c33cb42aecd8707 Mon Sep 17 00:00:00 2001
From: Joakim Erdfelt
Date: Tue, 26 Nov 2024 15:45:01 -0600
Subject: [PATCH 07/22] Allow an Environment to be removed (needed for testing
with Environment)
---
.../java/org/eclipse/jetty/util/component/Environment.java | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/component/Environment.java b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/component/Environment.java
index b2d7cca0bdcd..4338c07b9471 100644
--- a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/component/Environment.java
+++ b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/component/Environment.java
@@ -50,6 +50,11 @@ static Environment set(Environment environment)
return Named.__environments.put(environment.getName(), environment);
}
+ static Environment remove(String name)
+ {
+ return Named.__environments.remove(name);
+ }
+
/**
* @return The case-insensitive name of the environment.
*/
From 83fc5f101143ecc8b17bf3010d02517b409faa2b Mon Sep 17 00:00:00 2001
From: Joakim Erdfelt
Date: Tue, 26 Nov 2024 15:45:17 -0600
Subject: [PATCH 08/22] Fixing test cases
---
.../jetty/deploy/DeploymentManagerTest.java | 62 ++++++++++++-------
.../ContextProviderDeferredStartupTest.java | 2 +-
.../ContextProviderRuntimeUpdatesTest.java | 3 +-
.../providers/ContextProviderStartupTest.java | 3 +-
.../jetty/deploy/test/XmlConfiguredJetty.java | 61 ++----------------
5 files changed, 47 insertions(+), 84 deletions(-)
diff --git a/jetty-core/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/DeploymentManagerTest.java b/jetty-core/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/DeploymentManagerTest.java
index 432501a67e62..f3e8b85d4a12 100644
--- a/jetty-core/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/DeploymentManagerTest.java
+++ b/jetty-core/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/DeploymentManagerTest.java
@@ -15,6 +15,7 @@
import java.nio.file.Path;
import java.util.Collection;
+import java.util.List;
import java.util.Set;
import org.eclipse.jetty.deploy.test.XmlConfiguredJetty;
@@ -23,7 +24,9 @@
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
import org.eclipse.jetty.util.component.Environment;
+import org.eclipse.jetty.util.component.LifeCycle;
import org.hamcrest.Matchers;
+import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -37,6 +40,21 @@
@ExtendWith(WorkDirExtension.class)
public class DeploymentManagerTest
{
+ /**
+ * Cleanup after any tests that modify the Environments singleton
+ */
+ @AfterEach
+ public void clearEnvironments()
+ {
+ List envnames = Environment.getAll().stream()
+ .map(Environment::getName)
+ .toList();
+ for (String envname : envnames)
+ {
+ Environment.remove(envname);
+ }
+ assertEquals(0, Environment.getAll().size());
+ }
@Test
public void testReceiveApp() throws Exception
@@ -53,20 +71,27 @@ public void testReceiveApp() throws Exception
// Start DepMan
depman.start();
- // Trigger new App
- mockProvider.createWebapp("foo-webapp-1.war");
-
- // Test app tracking
- Collection apps = depman.getApps();
- assertNotNull(apps, "Should never be null");
- assertEquals(1, apps.size(), "Expected App Count");
-
- // Test app get
- App app = apps.stream().findFirst().orElse(null);
- assertNotNull(app);
- App actual = depman.getApp(app.getPath());
- assertNotNull(actual, "Should have gotten app (by id)");
- assertThat(actual.getPath().toString(), endsWith("mock-foo-webapp-1.war"));
+ try
+ {
+ // Trigger new App
+ mockProvider.createWebapp("foo-webapp-1.war");
+
+ // Test app tracking
+ Collection apps = depman.getApps();
+ assertNotNull(apps, "Should never be null");
+ assertEquals(1, apps.size(), "Expected App Count");
+
+ // Test app get
+ App app = apps.stream().findFirst().orElse(null);
+ assertNotNull(app);
+ App actual = depman.getApp(app.getPath());
+ assertNotNull(actual, "Should have gotten app (by id)");
+ assertThat(actual.getPath().toString(), endsWith("mock-foo-webapp-1.war"));
+ }
+ finally
+ {
+ LifeCycle.stop(depman);
+ }
}
@Test
@@ -177,14 +202,7 @@ public void testXmlConfigured(WorkDir workDir) throws Exception
{
if (jetty != null)
{
- try
- {
- jetty.stop();
- }
- catch (Exception ignore)
- {
- // ignore
- }
+ jetty.stop();
}
}
}
diff --git a/jetty-core/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/ContextProviderDeferredStartupTest.java b/jetty-core/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/ContextProviderDeferredStartupTest.java
index c85948ce1788..620223a1e319 100644
--- a/jetty-core/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/ContextProviderDeferredStartupTest.java
+++ b/jetty-core/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/ContextProviderDeferredStartupTest.java
@@ -55,7 +55,7 @@ public class ContextProviderDeferredStartupTest
@AfterEach
public void teardownEnvironment() throws Exception
{
- LifeCycle.stop(jetty);
+ jetty.stop();
}
@Test
diff --git a/jetty-core/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/ContextProviderRuntimeUpdatesTest.java b/jetty-core/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/ContextProviderRuntimeUpdatesTest.java
index a600972b985c..653c1a5a12a3 100644
--- a/jetty-core/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/ContextProviderRuntimeUpdatesTest.java
+++ b/jetty-core/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/ContextProviderRuntimeUpdatesTest.java
@@ -29,7 +29,6 @@
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
import org.eclipse.jetty.util.Scanner;
-import org.eclipse.jetty.util.component.LifeCycle;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -115,7 +114,7 @@ public void scanEnded(int cycle)
@AfterEach
public void teardownEnvironment() throws Exception
{
- LifeCycle.stop(jetty);
+ jetty.stop();
}
public void waitForDirectoryScan()
diff --git a/jetty-core/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/ContextProviderStartupTest.java b/jetty-core/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/ContextProviderStartupTest.java
index 563c50b87f9a..dceaeb90eea5 100644
--- a/jetty-core/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/ContextProviderStartupTest.java
+++ b/jetty-core/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/ContextProviderStartupTest.java
@@ -27,7 +27,6 @@
import org.eclipse.jetty.toolchain.test.MavenPaths;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
-import org.eclipse.jetty.util.component.LifeCycle;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -82,7 +81,7 @@ public void startJetty() throws Exception
@AfterEach
public void teardownEnvironment() throws Exception
{
- LifeCycle.stop(jetty);
+ jetty.stop();
}
@Test
diff --git a/jetty-core/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/test/XmlConfiguredJetty.java b/jetty-core/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/test/XmlConfiguredJetty.java
index 2ee6ce882eda..9822961c6657 100644
--- a/jetty-core/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/test/XmlConfiguredJetty.java
+++ b/jetty-core/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/test/XmlConfiguredJetty.java
@@ -36,9 +36,7 @@
import org.eclipse.jetty.http.HttpScheme;
import org.eclipse.jetty.http.HttpURI;
-import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Handler;
-import org.eclipse.jetty.server.NetworkConnector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
@@ -47,6 +45,7 @@
import org.eclipse.jetty.toolchain.test.PathMatchers;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.URIUtil;
+import org.eclipse.jetty.util.component.LifeCycle;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.resource.ResourceFactory;
import org.eclipse.jetty.xml.XmlConfiguration;
@@ -290,47 +289,6 @@ public Server load() throws Exception
return this._server;
}
- /*
- Path testConfig = _jettyBase.resolve("xml-configured-jetty.properties");
- setProperty("jetty.deploy.common.properties", testConfig.toString());
-
- // Write out configuration for use by ConfigurationManager.
- Properties properties = new Properties();
- properties.putAll(_properties);
- try (OutputStream out = Files.newOutputStream(testConfig))
- {
- properties.store(out, "Generated by " + XmlConfiguredJetty.class.getName());
- }
-
- XmlConfiguration last = null;
- Object[] obj = new Object[_xmlConfigurations.size()];
-
- // Configure everything
- for (int i = 0; i < _xmlConfigurations.size(); i++)
- {
- Resource config = _xmlConfigurations.get(i);
- XmlConfiguration configuration = new XmlConfiguration(config);
- if (last != null)
- configuration.getIdMap().putAll(last.getIdMap());
- configuration.getProperties().putAll(_properties);
- obj[i] = configuration.configure();
- last = configuration;
- }
-
- Map ids = last.getIdMap();
-
- // Test for Server Instance.
- Server server = (Server)ids.get("Server");
- if (server == null)
- {
- throw new Exception("Load failed to configure a " + Server.class.getName());
- }
-
- this._server = server;
- this._server.setStopTimeout(10000);
- this._contexts = (ContextHandlerCollection)ids.get("Contexts");
- } */
-
public void removeWebapp(String name) throws IOException
{
Path webappFile = _jettyBase.resolve("webapps/" + name);
@@ -358,19 +316,7 @@ public void start() throws Exception
_server.start();
// Find the active server port.
- _serverPort = -1;
- Connector[] connectors = _server.getConnectors();
- for (int i = 0; _serverPort < 0 && i < connectors.length; i++)
- {
- if (connectors[i] instanceof NetworkConnector)
- {
- int port = ((NetworkConnector)connectors[i]).getLocalPort();
- if (port > 0)
- _serverPort = port;
- }
- }
-
- assertTrue((1 <= this._serverPort) && (this._serverPort <= 65535), "Server Port is between 1 and 65535. Was actually <" + _serverPort + ">");
+ _serverPort = _server.getURI().getPort();
// Uncomment to have server start and continue to run (without exiting)
// System.err.printf("Listening to port %d%n",this.serverPort);
@@ -379,6 +325,7 @@ public void start() throws Exception
public void stop() throws Exception
{
- _server.stop();
+ LifeCycle.stop(_server);
+ _properties.clear();
}
}
From 249679f9b5bb6247bc722d5ab862b29cd778dc6d Mon Sep 17 00:00:00 2001
From: Joakim Erdfelt
Date: Wed, 27 Nov 2024 08:55:16 -0600
Subject: [PATCH 09/22] Fix javadoc
---
.../deploy/providers/ContextProvider.java | 68 +++++++++----------
1 file changed, 34 insertions(+), 34 deletions(-)
diff --git a/jetty-core/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/ContextProvider.java b/jetty-core/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/ContextProvider.java
index 7028e45ad550..34140a910165 100644
--- a/jetty-core/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/ContextProvider.java
+++ b/jetty-core/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/ContextProvider.java
@@ -52,40 +52,40 @@
import org.slf4j.LoggerFactory;
/**
- * The webapps directory scanning provider.
- * * This provider scans one or more directories (typically "webapps") for contexts to
- * * deploy, which may be:
- * *
- * *
- * * - A standard WAR file (must end in ".war")
- * * - A directory containing an expanded WAR file
- * * - A directory containing static content
- * * - An XML descriptor in {@link XmlConfiguration} format that configures a {@link ContextHandler} instance
- * *
- * * To avoid double deployments and allow flexibility of the content of the scanned directories, the provider
- * * implements some heuristics to ignore some files found in the scans:
- * *
- * *
- * * - Hidden files (starting with {@code "."}) are ignored
- * * - Directories with names ending in {@code ".d"} are ignored
- * * - Property files with names ending in {@code ".properties"} are not deployed.
- * * - If a directory and a WAR file exist (eg: {@code foo/} and {@code foo.war}) then the directory is assumed to be
- * * the unpacked WAR and only the WAR is deployed (which may reused the unpacked directory)
- * * - If a directory and a matching XML file exist (eg: {@code foo/} and {@code foo.xml}) then the directory is assumed to be
- * * an unpacked WAR and only the XML is deployed (which may used the directory in its configuration)
- * * - If a WAR file and a matching XML exist (eg: {@code foo.war} and {@code foo.xml}) then the WAR is assumed to
- * * be configured by the XML and only the XML is deployed.
- * *
- * * For XML configured contexts, the ID map will contain a reference to the {@link Server} instance called "Server" and
- * * properties for the webapp file such as "jetty.webapp" and directory as "jetty.webapps".
- * * The properties will be initialized with:
- * *
- * *
- * * - The properties set on the application via {@link App#getProperties()}
- * * - The app specific properties file {@code webapps/.properties}
- * * - The environment specific properties file {@code webapps/[-zzz].properties}
- * * - The {@link Attributes} from the {@link Environment}
- * *
+ * Jetty Environment WebApp Hot Deployment Provider.
+ *
+ * This provider scans one or more directories (typically "webapps") for contexts to
+ * deploy, which may be:
+ *
+ * - A standard WAR file (must end in ".war")
+ * - A directory containing an expanded WAR file
+ * - A directory containing static content
+ * - An XML descriptor in {@link XmlConfiguration} format that configures a {@link ContextHandler} instance
+ *
+ * To avoid double deployments and allow flexibility of the content of the scanned directories, the provider
+ * implements some heuristics to ignore some files found in the scans:
+ *
+ *
+ * - Hidden files (starting with {@code "."}) are ignored
+ * - Directories with names ending in {@code ".d"} are ignored
+ * - Property files with names ending in {@code ".properties"} are not deployed.
+ * - If a directory and a WAR file exist (eg: {@code foo/} and {@code foo.war}) then the directory is assumed to be
+ * the unpacked WAR and only the WAR is deployed (which may reused the unpacked directory)
+ * - If a directory and a matching XML file exist (eg: {@code foo/} and {@code foo.xml}) then the directory is assumed to be
+ * an unpacked WAR and only the XML is deployed (which may used the directory in its configuration)
+ * - If a WAR file and a matching XML exist (eg: {@code foo.war} and {@code foo.xml}) then the WAR is assumed to
+ * be configured by the XML and only the XML is deployed.
+ *
+ * For XML configured contexts, the ID map will contain a reference to the {@link Server} instance called "Server" and
+ * properties for the webapp file such as "jetty.webapp" and directory as "jetty.webapps".
+ * The properties will be initialized with:
+ *
+ *
+ * - The properties set on the application via {@link App#getProperties()}
+ * - The app specific properties file {@code webapps/.properties}
+ * - The environment specific properties file {@code webapps/[-zzz].properties}
+ * - The {@link Attributes} from the {@link Environment}
+ *
*/
@ManagedObject("Provider for start-up deployment of webapps based on presence in directory")
public class ContextProvider extends ScanningAppProvider
From bef04d9888b0fd7ea72a5a49bd5566196d769d42 Mon Sep 17 00:00:00 2001
From: Joakim Erdfelt
Date: Wed, 27 Nov 2024 08:55:25 -0600
Subject: [PATCH 10/22] Fix method names
---
.../src/main/config/etc/jetty-ee10-deploy.xml | 6 +++---
.../src/main/config/etc/jetty-ee11-deploy.xml | 6 +++---
.../src/main/config/etc/jetty-ee8-deploy.xml | 6 +++---
.../src/main/config/etc/jetty-ee9-deploy.xml | 6 +++---
4 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/jetty-ee10/jetty-ee10-webapp/src/main/config/etc/jetty-ee10-deploy.xml b/jetty-ee10/jetty-ee10-webapp/src/main/config/etc/jetty-ee10-deploy.xml
index 019157c06ce5..19c0107e843a 100644
--- a/jetty-ee10/jetty-ee10-webapp/src/main/config/etc/jetty-ee10-deploy.xml
+++ b/jetty-ee10/jetty-ee10-webapp/src/main/config/etc/jetty-ee10-deploy.xml
@@ -26,8 +26,8 @@
.*/jakarta.servlet-api-[^/]*\.jar$|.*jakarta.servlet.jsp.jstl-.*\.jar$
-
-
-
+
+
+