From 6a32fb0ca5ad55ca4ea5e0d3fb8eb1d9391083d8 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Wed, 18 Sep 2019 16:29:19 +1000 Subject: [PATCH] Issue #4003 Cleanup quickstart * cleanup from review Signed-off-by: Greg Wilkins --- .../maven/plugin/JettyWebAppContext.java | 29 +++++++++++-------- .../eclipse/jetty/webapp/Configurations.java | 21 ++++++++++++++ .../eclipse/jetty/webapp/WebAppContext.java | 7 +---- 3 files changed, 39 insertions(+), 18 deletions(-) diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyWebAppContext.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyWebAppContext.java index f6a26bbf404..302d267f00d 100644 --- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyWebAppContext.java +++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyWebAppContext.java @@ -42,10 +42,10 @@ import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.URIUtil; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; -import org.eclipse.jetty.util.resource.PathResource; import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.util.resource.ResourceCollection; import org.eclipse.jetty.webapp.Configuration; +import org.eclipse.jetty.webapp.Configurations; import org.eclipse.jetty.webapp.MetaInfConfiguration; import org.eclipse.jetty.webapp.WebAppContext; @@ -310,22 +310,27 @@ public class JettyWebAppContext extends WebAppContext } @Override - protected void loadConfigurations() + protected Configurations newConfigurations() { - super.loadConfigurations(); - try + Configurations configurations = super.newConfigurations(); + if (getJettyEnvXml() != null) { - // inject configurations with config from maven plugin - for (Configuration c : getConfigurations()) + try { - if (c instanceof EnvConfiguration && getJettyEnvXml() != null) - ((EnvConfiguration)c).setJettyEnvResource(new PathResource(new File(getJettyEnvXml()))); + // inject configurations with config from maven plugin + for (Configuration c : configurations) + { + if (c instanceof EnvConfiguration) + ((EnvConfiguration)c).setJettyEnvResource(Resource.newResource(getJettyEnvXml())); + } + } + catch (IOException e) + { + throw new RuntimeException(e); } } - catch (Exception e) - { - throw new RuntimeException(e); - } + + return configurations; } @Override diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/Configurations.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/Configurations.java index 5c2963ca937..2839445e540 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/Configurations.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/Configurations.java @@ -279,6 +279,27 @@ public class Configurations extends AbstractList implements Dumpa } } + public T get(Class configClass) + { + for (Configuration configuration : _configurations) + { + if (configClass.isAssignableFrom(configuration.getClass())) + return (T)configuration; + } + return null; + } + + public List getConfigurations(Class configClass) + { + List list = new ArrayList<>(); + for (Configuration configuration : _configurations) + { + if (configClass.isAssignableFrom(configuration.getClass())) + list.add((T)configuration); + } + return list; + } + public void clear() { _configurations.clear(); diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java index f82f579bb9b..7bdb0e1a387 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java @@ -997,12 +997,7 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL public T getConfiguration(Class configClass) { loadConfigurations(); - for (Configuration configuration : _configurations) - { - if (configClass.isAssignableFrom(configuration.getClass())) - return (T)configuration; - } - return null; + return _configurations.get(configClass); } public void removeConfiguration(Configuration... configurations)