From ac416d21e81b2f8512f9c162154f18305ec52a81 Mon Sep 17 00:00:00 2001 From: Jan Bartel Date: Mon, 2 Nov 2015 12:35:02 +1100 Subject: [PATCH] 481203 Add ability to set configurations to apply to WebAppContext for jetty-maven-plugin --- .../jetty/maven/plugin/AbstractJettyMojo.java | 3 + .../maven/plugin/JettyRunForkedMojo.java | 2 + .../maven/plugin/JettyWebAppContext.java | 65 +++++++++++-------- .../jetty/maven/plugin/ServerSupport.java | 8 +++ .../eclipse/jetty/maven/plugin/Starter.java | 5 +- 5 files changed, 55 insertions(+), 28 deletions(-) diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/AbstractJettyMojo.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/AbstractJettyMojo.java index 402ad482435..caa79c57a9a 100644 --- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/AbstractJettyMojo.java +++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/AbstractJettyMojo.java @@ -443,6 +443,9 @@ public abstract class AbstractJettyMojo extends AbstractMojo //set up a RequestLog if one is provided and the handle structure ServerSupport.configureHandlers(server, this.requestLog); + + //Set up list of default Configurations to apply to a webapp + ServerSupport.configureDefaultConfigurationClasses(server); configureWebApplication(); ServerSupport.addWebApplication(server, webApp); diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunForkedMojo.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunForkedMojo.java index d4ac65e2ac1..22cf2f21dc7 100644 --- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunForkedMojo.java +++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunForkedMojo.java @@ -244,6 +244,8 @@ public class JettyRunForkedMojo extends JettyRunMojo //ensure handler structure enabled ServerSupport.configureHandlers(server, null); + + ServerSupport.configureDefaultConfigurationClasses(server); //ensure config of the webapp based on settings in plugin configureWebApplication(); 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 8f1f3435846..0a2dd8cc3b9 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 @@ -72,23 +72,25 @@ public class JettyWebAppContext extends WebAppContext private static final String DEFAULT_CONTAINER_INCLUDE_JAR_PATTERN = ".*/javax.servlet-[^/]*\\.jar$|.*/servlet-api-[^/]*\\.jar$|.*javax.servlet.jsp.jstl-[^/]*\\.jar|.*taglibs-standard-impl-.*\\.jar"; private static final String WEB_INF_CLASSES_PREFIX = "/WEB-INF/classes"; private static final String WEB_INF_LIB_PREFIX = "/WEB-INF/lib"; + + + public static final String[] DEFAULT_CONFIGURATION_CLASSES = { + "org.eclipse.jetty.maven.plugin.MavenWebInfConfiguration", + "org.eclipse.jetty.webapp.WebXmlConfiguration", + "org.eclipse.jetty.webapp.MetaInfConfiguration", + "org.eclipse.jetty.webapp.FragmentConfiguration", + "org.eclipse.jetty.plus.webapp.EnvConfiguration", + "org.eclipse.jetty.plus.webapp.PlusConfiguration", + "org.eclipse.jetty.annotations.AnnotationConfiguration", + "org.eclipse.jetty.webapp.JettyWebXmlConfiguration" + }; - private final Configuration[] _defaultConfigurations = { - new MavenWebInfConfiguration(), - new WebXmlConfiguration(), - new MetaInfConfiguration(), - new FragmentConfiguration(), - new EnvConfiguration(), - new PlusConfiguration(), - new AnnotationConfiguration(), - new JettyWebXmlConfiguration() - }; - private final Configuration[] _quickStartConfigurations = { - new MavenQuickStartConfiguration(), - new EnvConfiguration(), - new PlusConfiguration(), - new JettyWebXmlConfiguration() + private final String[] QUICKSTART_CONFIGURATION_CLASSES = { + "org.eclipse.jetty.maven.plugin.MavenQuickStartConfiguration", + "org.eclipse.jetty.plus.webapp.EnvConfiguration", + "org.eclipse.jetty.plus.webapp.PlusConfiguration", + "org.eclipse.jetty.webapp.JettyWebXmlConfiguration" }; private File _classes = null; @@ -100,6 +102,7 @@ public class JettyWebAppContext extends WebAppContext private String _jettyEnvXml; private List _overlays; private Resource _quickStartWebXml; + @@ -338,25 +341,17 @@ public class JettyWebAppContext extends WebAppContext { //choose if this will be a quickstart or normal start if (!isGenerateQuickStart() && getQuickStartWebDescriptor() != null) - setConfigurations(_quickStartConfigurations); - else { - setConfigurations(_defaultConfigurations); + setConfigurationClasses(QUICKSTART_CONFIGURATION_CLASSES); + } + else + { if (isGenerateQuickStart()) { _preconfigProcessor = new PreconfigureDescriptorProcessor(); getMetaData().addDescriptorProcessor(_preconfigProcessor); } } - - //inject configurations with config from maven plugin - for (Configuration c:getConfigurations()) - { - if (c instanceof EnvConfiguration && getJettyEnvXml() != null) - ((EnvConfiguration)c).setJettyEnvXml(Resource.toURL(new File(getJettyEnvXml()))); - else if (c instanceof MavenQuickStartConfiguration && getQuickStartWebDescriptor() != null) - ((MavenQuickStartConfiguration)c).setQuickStartWebXml(getQuickStartWebDescriptor()); - } //Set up the pattern that tells us where the jars are that need scanning @@ -404,6 +399,22 @@ public class JettyWebAppContext extends WebAppContext } + @Override + protected void loadConfigurations() throws Exception + { + super.loadConfigurations(); + + //inject configurations with config from maven plugin + for (Configuration c:getConfigurations()) + { + if (c instanceof EnvConfiguration && getJettyEnvXml() != null) + ((EnvConfiguration)c).setJettyEnvXml(Resource.toURL(new File(getJettyEnvXml()))); + else if (c instanceof MavenQuickStartConfiguration && getQuickStartWebDescriptor() != null) + ((MavenQuickStartConfiguration)c).setQuickStartWebXml(getQuickStartWebDescriptor()); + } + } + + /* ------------------------------------------------------------ */ public void doStop () throws Exception { diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/ServerSupport.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/ServerSupport.java index babfe6830a3..407a17f2a95 100644 --- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/ServerSupport.java +++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/ServerSupport.java @@ -35,6 +35,7 @@ import org.eclipse.jetty.server.handler.DefaultHandler; import org.eclipse.jetty.server.handler.HandlerCollection; import org.eclipse.jetty.server.handler.RequestLogHandler; import org.eclipse.jetty.util.resource.Resource; +import org.eclipse.jetty.webapp.Configuration; import org.eclipse.jetty.webapp.WebAppContext; import org.eclipse.jetty.xml.XmlConfiguration; @@ -46,6 +47,13 @@ import org.eclipse.jetty.xml.XmlConfiguration; */ public class ServerSupport { + + public static void configureDefaultConfigurationClasses (Server server) + { + server.setAttribute(Configuration.ATTR, JettyWebAppContext.DEFAULT_CONFIGURATION_CLASSES); + } + + /** * Set up the handler structure to receive a webapp. * Also put in a DefaultHandler so we get a nice page diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/Starter.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/Starter.java index 0f9e361cbd1..a5b94536ad1 100644 --- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/Starter.java +++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/Starter.java @@ -125,7 +125,10 @@ public class Starter //check if contexts already configured, create if not ServerSupport.configureHandlers(server, null); - + + //Set up list of default Configurations to apply to a webapp + ServerSupport.configureDefaultConfigurationClasses(server); + webApp = new JettyWebAppContext(); //configure webapp from properties file describing unassembled webapp