481203 Add ability to set configurations to apply to WebAppContext for jetty-maven-plugin

This commit is contained in:
Jan Bartel 2015-11-02 12:35:02 +11:00
parent 303f98e38c
commit a022c77dab
5 changed files with 55 additions and 28 deletions

View File

@ -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);

View File

@ -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();

View File

@ -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<Overlay> _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
{

View File

@ -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

View File

@ -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