Issue #1117
This commit is contained in:
parent
deac849325
commit
40d9e56d92
|
@ -49,13 +49,14 @@ public class JettyEffectiveWebXml extends JettyRunMojo
|
|||
protected File target;
|
||||
|
||||
/**
|
||||
* The target directory
|
||||
* The name of the file to generate into
|
||||
*
|
||||
* @parameter
|
||||
*/
|
||||
protected File effectiveWebXml;
|
||||
|
||||
|
||||
|
||||
protected boolean deleteOnExit = true;
|
||||
|
||||
|
||||
|
@ -91,12 +92,12 @@ public class JettyEffectiveWebXml extends JettyRunMojo
|
|||
//ensure config of the webapp based on settings in plugin
|
||||
configureWebApplication();
|
||||
|
||||
|
||||
//set the webapp up to do very little other than generate the quickstart-web.xml
|
||||
webApp.setCopyWebDir(false);
|
||||
webApp.setCopyWebInf(false);
|
||||
webApp.setGenerateQuickStart(true);
|
||||
|
||||
|
||||
//if the user didn't nominate a file to generate into, pick the name and
|
||||
//make sure that it is deleted on exit
|
||||
if (webApp.getQuickStartWebDescriptor() == null)
|
||||
|
|
|
@ -102,6 +102,8 @@ public class JettyWebAppContext extends WebAppContext
|
|||
private String _jettyEnvXml;
|
||||
private List<Overlay> _overlays;
|
||||
private Resource _quickStartWebXml;
|
||||
private String _originAttribute;
|
||||
private boolean _generateOrigin;
|
||||
|
||||
|
||||
|
||||
|
@ -227,6 +229,38 @@ public class JettyWebAppContext extends WebAppContext
|
|||
_overlays = overlays;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the originAttribute
|
||||
*/
|
||||
public String getOriginAttribute()
|
||||
{
|
||||
return _originAttribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param originAttribute the originAttribute to set
|
||||
*/
|
||||
public void setOriginAttribute(String originAttribute)
|
||||
{
|
||||
_originAttribute = originAttribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the generateOrigin
|
||||
*/
|
||||
public boolean isGenerateOrigin()
|
||||
{
|
||||
return _generateOrigin;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param generateOrigin the generateOrigin to set
|
||||
*/
|
||||
public void setGenerateOrigin(boolean generateOrigin)
|
||||
{
|
||||
_generateOrigin = generateOrigin;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public List<Overlay> getOverlays()
|
||||
{
|
||||
|
@ -311,7 +345,7 @@ public class JettyWebAppContext extends WebAppContext
|
|||
if (getQuickStartWebDescriptor() == null)
|
||||
throw new IllegalStateException ("No location to generate quickstart descriptor");
|
||||
|
||||
QuickStartDescriptorGenerator generator = new QuickStartDescriptorGenerator(this, _preconfigProcessor.getXML());
|
||||
QuickStartDescriptorGenerator generator = new QuickStartDescriptorGenerator(this, _preconfigProcessor.getXML(), _originAttribute, _generateOrigin);
|
||||
try (FileOutputStream fos = new FileOutputStream(getQuickStartWebDescriptor().getFile()))
|
||||
{
|
||||
generator.generateQuickStartWebXml(fos);
|
||||
|
|
|
@ -56,6 +56,7 @@ import org.eclipse.jetty.servlet.ServletHandler;
|
|||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
import org.eclipse.jetty.servlet.ServletMapping;
|
||||
import org.eclipse.jetty.util.QuotedStringTokenizer;
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
|
@ -77,9 +78,13 @@ public class QuickStartDescriptorGenerator
|
|||
private static final Logger LOG = Log.getLogger(QuickStartDescriptorGenerator.class);
|
||||
|
||||
public static final String DEFAULT_QUICKSTART_DESCRIPTOR_NAME = "quickstart-web.xml";
|
||||
public static final String DEFAULT_ORIGIN_ATTRIBUTE_NAME = "origin";
|
||||
|
||||
protected WebAppContext _webApp;
|
||||
protected String _extraXML;
|
||||
protected String _originAttribute;
|
||||
protected boolean _generateOrigin;
|
||||
protected int _count;
|
||||
|
||||
|
||||
|
||||
|
@ -87,10 +92,13 @@ public class QuickStartDescriptorGenerator
|
|||
* @param w the source WebAppContext
|
||||
* @param extraXML any extra xml snippet to append
|
||||
*/
|
||||
public QuickStartDescriptorGenerator (WebAppContext w, String extraXML)
|
||||
public QuickStartDescriptorGenerator (WebAppContext w, String extraXML, String originAttribute, boolean generateOrigin)
|
||||
{
|
||||
_webApp = w;
|
||||
_extraXML = extraXML;
|
||||
_originAttribute = (StringUtil.isBlank(originAttribute)?DEFAULT_ORIGIN_ATTRIBUTE_NAME:originAttribute);
|
||||
_generateOrigin = generateOrigin || LOG.isDebugEnabled();
|
||||
_count = 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -694,7 +702,7 @@ public class QuickStartDescriptorGenerator
|
|||
*/
|
||||
public Map<String, String> origin(MetaData md, String name)
|
||||
{
|
||||
if (!LOG.isDebugEnabled())
|
||||
if (!_generateOrigin)
|
||||
return Collections.emptyMap();
|
||||
if (name == null)
|
||||
return Collections.emptyMap();
|
||||
|
@ -702,7 +710,7 @@ public class QuickStartDescriptorGenerator
|
|||
if (LOG.isDebugEnabled()) LOG.debug("origin of "+name+" is "+origin);
|
||||
if (origin == null)
|
||||
return Collections.emptyMap();
|
||||
return Collections.singletonMap("origin",origin.toString());
|
||||
return Collections.singletonMap(_originAttribute,origin.toString()+":"+(_count++));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -46,6 +46,9 @@ public class QuickStartWebApp extends WebAppContext
|
|||
private boolean _autoPreconfigure=false;
|
||||
private boolean _startWebapp=false;
|
||||
private PreconfigureDescriptorProcessor _preconfigProcessor;
|
||||
private String _originAttribute;
|
||||
private boolean _generateOrigin;
|
||||
|
||||
|
||||
public static final String[] __preconfigurationClasses = new String[]
|
||||
{
|
||||
|
@ -89,6 +92,35 @@ public class QuickStartWebApp extends WebAppContext
|
|||
_autoPreconfigure = autoPrecompile;
|
||||
}
|
||||
|
||||
public void setOriginAttribute (String name)
|
||||
{
|
||||
_originAttribute = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the originAttribute
|
||||
*/
|
||||
public String getOriginAttribute()
|
||||
{
|
||||
return _originAttribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the generateOrigin
|
||||
*/
|
||||
public boolean getGenerateOrigin()
|
||||
{
|
||||
return _generateOrigin;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param generateOrigin the generateOrigin to set
|
||||
*/
|
||||
public void setGenerateOrigin(boolean generateOrigin)
|
||||
{
|
||||
_generateOrigin = generateOrigin;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void startWebapp() throws Exception
|
||||
{
|
||||
|
@ -174,7 +206,7 @@ public class QuickStartWebApp extends WebAppContext
|
|||
Resource descriptor = getWebInf().addPath(QuickStartDescriptorGenerator.DEFAULT_QUICKSTART_DESCRIPTOR_NAME);
|
||||
if (!descriptor.exists())
|
||||
descriptor.getFile().createNewFile();
|
||||
QuickStartDescriptorGenerator generator = new QuickStartDescriptorGenerator(this, extraXML);
|
||||
QuickStartDescriptorGenerator generator = new QuickStartDescriptorGenerator(this, extraXML, _originAttribute, _generateOrigin);
|
||||
try (FileOutputStream fos = new FileOutputStream(descriptor.getFile()))
|
||||
{
|
||||
generator.generateQuickStartWebXml(fos);
|
||||
|
|
|
@ -125,7 +125,7 @@ public class MetaData
|
|||
if (descriptor!=null)
|
||||
return descriptor.toString();
|
||||
if (annotation!=null)
|
||||
return "@"+annotation.annotationType().getSimpleName()+" on "+annotated.getName();
|
||||
return "@"+annotation.annotationType().getSimpleName()+"("+annotated.getName()+")";
|
||||
return origin.toString();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue