Issue #877
This commit is contained in:
parent
47fd7e1bd2
commit
ce6054391c
|
@ -77,6 +77,7 @@ public class QuickStartDescriptorGenerator
|
||||||
{
|
{
|
||||||
private static final Logger LOG = Log.getLogger(QuickStartDescriptorGenerator.class);
|
private static final Logger LOG = Log.getLogger(QuickStartDescriptorGenerator.class);
|
||||||
|
|
||||||
|
public static final String ORIGIN = "org.eclipse.jetty.originAttribute";
|
||||||
public static final String DEFAULT_QUICKSTART_DESCRIPTOR_NAME = "quickstart-web.xml";
|
public static final String DEFAULT_QUICKSTART_DESCRIPTOR_NAME = "quickstart-web.xml";
|
||||||
public static final String DEFAULT_ORIGIN_ATTRIBUTE_NAME = "origin";
|
public static final String DEFAULT_ORIGIN_ATTRIBUTE_NAME = "origin";
|
||||||
|
|
||||||
|
@ -152,6 +153,16 @@ public class QuickStartDescriptorGenerator
|
||||||
addContextParamFromAttribute(out,MetaInfConfiguration.METAINF_RESOURCES,normalizer);
|
addContextParamFromAttribute(out,MetaInfConfiguration.METAINF_RESOURCES,normalizer);
|
||||||
|
|
||||||
|
|
||||||
|
//add the name of the origin attribute, if it is being used
|
||||||
|
if (_generateOrigin)
|
||||||
|
{
|
||||||
|
out.openTag("context-param")
|
||||||
|
.tag("param-name", ORIGIN)
|
||||||
|
.tag("param-value", _originAttribute)
|
||||||
|
.closeTag();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// init params
|
// init params
|
||||||
for (String p : _webApp.getInitParams().keySet())
|
for (String p : _webApp.getInitParams().keySet())
|
||||||
out.openTag("context-param",origin(md,"context-param." + p))
|
out.openTag("context-param",origin(md,"context-param." + p))
|
||||||
|
|
|
@ -28,9 +28,12 @@ import javax.servlet.ServletContext;
|
||||||
import org.eclipse.jetty.annotations.AnnotationConfiguration;
|
import org.eclipse.jetty.annotations.AnnotationConfiguration;
|
||||||
import org.eclipse.jetty.annotations.ServletContainerInitializersStarter;
|
import org.eclipse.jetty.annotations.ServletContainerInitializersStarter;
|
||||||
import org.eclipse.jetty.plus.annotation.ContainerInitializer;
|
import org.eclipse.jetty.plus.annotation.ContainerInitializer;
|
||||||
|
import org.eclipse.jetty.servlet.ServletMapping;
|
||||||
import org.eclipse.jetty.util.QuotedStringTokenizer;
|
import org.eclipse.jetty.util.QuotedStringTokenizer;
|
||||||
|
import org.eclipse.jetty.util.StringUtil;
|
||||||
import org.eclipse.jetty.util.resource.Resource;
|
import org.eclipse.jetty.util.resource.Resource;
|
||||||
import org.eclipse.jetty.util.resource.ResourceCollection;
|
import org.eclipse.jetty.util.resource.ResourceCollection;
|
||||||
|
import org.eclipse.jetty.webapp.DefaultsDescriptor;
|
||||||
import org.eclipse.jetty.webapp.Descriptor;
|
import org.eclipse.jetty.webapp.Descriptor;
|
||||||
import org.eclipse.jetty.webapp.IterativeDescriptorProcessor;
|
import org.eclipse.jetty.webapp.IterativeDescriptorProcessor;
|
||||||
import org.eclipse.jetty.webapp.MetaInfConfiguration;
|
import org.eclipse.jetty.webapp.MetaInfConfiguration;
|
||||||
|
@ -44,11 +47,18 @@ import org.eclipse.jetty.xml.XmlParser;
|
||||||
*/
|
*/
|
||||||
public class QuickStartDescriptorProcessor extends IterativeDescriptorProcessor
|
public class QuickStartDescriptorProcessor extends IterativeDescriptorProcessor
|
||||||
{
|
{
|
||||||
|
|
||||||
|
private String _originAttributeName = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
public QuickStartDescriptorProcessor()
|
public QuickStartDescriptorProcessor()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
registerVisitor("context-param", this.getClass().getMethod("visitContextParam", __signature));
|
registerVisitor("context-param", this.getClass().getMethod("visitContextParam", __signature));
|
||||||
|
registerVisitor("servlet-mapping", this.getClass().getMethod("visitServletMapping", __signature));
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -62,6 +72,7 @@ public class QuickStartDescriptorProcessor extends IterativeDescriptorProcessor
|
||||||
@Override
|
@Override
|
||||||
public void start(WebAppContext context, Descriptor descriptor)
|
public void start(WebAppContext context, Descriptor descriptor)
|
||||||
{
|
{
|
||||||
|
_originAttributeName = context.getInitParameter(QuickStartDescriptorGenerator.ORIGIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -70,8 +81,50 @@ public class QuickStartDescriptorProcessor extends IterativeDescriptorProcessor
|
||||||
@Override
|
@Override
|
||||||
public void end(WebAppContext context, Descriptor descriptor)
|
public void end(WebAppContext context, Descriptor descriptor)
|
||||||
{
|
{
|
||||||
|
_originAttributeName = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process a servlet-mapping element
|
||||||
|
*
|
||||||
|
* @param context the webapp
|
||||||
|
* @param descriptor the xml file to process
|
||||||
|
* @param node the servlet-mapping element in the xml file to process
|
||||||
|
*/
|
||||||
|
public void visitServletMapping(WebAppContext context, Descriptor descriptor, XmlParser.Node node)
|
||||||
|
{
|
||||||
|
String servletName = node.getString("servlet-name", false, true);
|
||||||
|
ServletMapping mapping = null;
|
||||||
|
ServletMapping[] mappings = context.getServletHandler().getServletMappings();
|
||||||
|
|
||||||
|
if (mappings != null)
|
||||||
|
{
|
||||||
|
for (ServletMapping m:mappings)
|
||||||
|
{
|
||||||
|
if (servletName.equals(m.getServletName()))
|
||||||
|
{
|
||||||
|
mapping = m;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mapping != null && _originAttributeName != null)
|
||||||
|
{
|
||||||
|
String origin = node.getAttribute(_originAttributeName);
|
||||||
|
if (!StringUtil.isBlank(origin) && origin.startsWith(DefaultsDescriptor.class.getSimpleName()))
|
||||||
|
mapping.setDefault(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process a context-param element
|
||||||
|
* @param context the webapp
|
||||||
|
* @param descriptor the xml file to process
|
||||||
|
* @param node the context-param node in the xml file
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
public void visitContextParam (WebAppContext context, Descriptor descriptor, XmlParser.Node node)
|
public void visitContextParam (WebAppContext context, Descriptor descriptor, XmlParser.Node node)
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
@ -82,11 +135,16 @@ public class QuickStartDescriptorProcessor extends IterativeDescriptorProcessor
|
||||||
// extract values
|
// extract values
|
||||||
switch(name)
|
switch(name)
|
||||||
{
|
{
|
||||||
|
case QuickStartDescriptorGenerator.ORIGIN:
|
||||||
|
{
|
||||||
|
//value already contains what we need
|
||||||
|
break;
|
||||||
|
}
|
||||||
case ServletContext.ORDERED_LIBS:
|
case ServletContext.ORDERED_LIBS:
|
||||||
case AnnotationConfiguration.CONTAINER_INITIALIZERS:
|
case AnnotationConfiguration.CONTAINER_INITIALIZERS:
|
||||||
case MetaInfConfiguration.METAINF_TLDS:
|
case MetaInfConfiguration.METAINF_TLDS:
|
||||||
case MetaInfConfiguration.METAINF_RESOURCES:
|
case MetaInfConfiguration.METAINF_RESOURCES:
|
||||||
|
{
|
||||||
context.removeAttribute(name);
|
context.removeAttribute(name);
|
||||||
|
|
||||||
QuotedStringTokenizer tok = new QuotedStringTokenizer(value,",");
|
QuotedStringTokenizer tok = new QuotedStringTokenizer(value,",");
|
||||||
|
@ -94,7 +152,7 @@ public class QuickStartDescriptorProcessor extends IterativeDescriptorProcessor
|
||||||
values.add(tok.nextToken().trim());
|
values.add(tok.nextToken().trim());
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
values.add(value);
|
values.add(value);
|
||||||
}
|
}
|
||||||
|
@ -103,6 +161,11 @@ public class QuickStartDescriptorProcessor extends IterativeDescriptorProcessor
|
||||||
// handle values
|
// handle values
|
||||||
switch(name)
|
switch(name)
|
||||||
{
|
{
|
||||||
|
case QuickStartDescriptorGenerator.ORIGIN:
|
||||||
|
{
|
||||||
|
context.setAttribute(QuickStartDescriptorGenerator.ORIGIN, value);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case ServletContext.ORDERED_LIBS:
|
case ServletContext.ORDERED_LIBS:
|
||||||
{
|
{
|
||||||
List<Object> libs = new ArrayList<>();
|
List<Object> libs = new ArrayList<>();
|
||||||
|
|
Loading…
Reference in New Issue