465202 Forked Mojo does not extract war overlays/dependencies
This commit is contained in:
parent
2c65b66f9c
commit
d7de34af76
|
@ -71,8 +71,7 @@ public class JettyEffectiveWebXml extends JettyRunMojo
|
|||
@Override
|
||||
public void startJetty() throws MojoExecutionException
|
||||
{
|
||||
//Only do enough setup to be able to produce a quickstart-web.xml file to
|
||||
//pass onto the forked process to run
|
||||
//Only do enough setup to be able to produce a quickstart-web.xml file
|
||||
|
||||
//if the user didn't nominate a file to generate into, pick the name and
|
||||
//make sure that it is deleted on exit
|
||||
|
|
|
@ -162,6 +162,7 @@ public class JettyRunForkedMojo extends JettyRunMojo
|
|||
|
||||
|
||||
private Resource originalBaseResource;
|
||||
private boolean originalPersistTemp;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -267,6 +268,9 @@ public class JettyRunForkedMojo extends JettyRunMojo
|
|||
//copy the base resource as configured by the plugin
|
||||
originalBaseResource = webApp.getBaseResource();
|
||||
|
||||
//get the original persistance setting
|
||||
originalPersistTemp = webApp.isPersistTempDirectory();
|
||||
|
||||
//set the webapp up to do very little other than generate the quickstart-web.xml
|
||||
webApp.setCopyWebDir(false);
|
||||
webApp.setCopyWebInf(false);
|
||||
|
@ -289,8 +293,11 @@ public class JettyRunForkedMojo extends JettyRunMojo
|
|||
tpool.start();
|
||||
else
|
||||
webApp.setAttribute(AnnotationConfiguration.MULTI_THREADED, Boolean.FALSE.toString());
|
||||
|
||||
//leave everything unpacked for the forked process to use
|
||||
webApp.setPersistTempDirectory(true);
|
||||
|
||||
webApp.start(); //just enough to generate the quickstart
|
||||
webApp.start(); //just enough to generate the quickstart
|
||||
|
||||
//save config of the webapp BEFORE we stop
|
||||
File props = prepareConfiguration();
|
||||
|
@ -498,31 +505,23 @@ public class JettyRunForkedMojo extends JettyRunMojo
|
|||
|
||||
//tmp dir
|
||||
props.put("tmp.dir", webApp.getTempDirectory().getAbsolutePath());
|
||||
props.put("tmp.dir.persist", Boolean.toString(webApp.isPersistTempDirectory()));
|
||||
props.put("tmp.dir.persist", Boolean.toString(originalPersistTemp));
|
||||
|
||||
//send over the original base resources before any overlays were added
|
||||
if (originalBaseResource instanceof ResourceCollection)
|
||||
props.put("base.dirs.orig", toCSV(((ResourceCollection)originalBaseResource).getResources()));
|
||||
else
|
||||
props.put("base.dirs.orig", originalBaseResource.toString());
|
||||
|
||||
//send over the calculated resource bases that includes unpacked overlays, but none of the
|
||||
//meta-inf resources
|
||||
Resource postOverlayResources = (Resource)webApp.getAttribute(MavenWebInfConfiguration.RESOURCE_BASES_POST_OVERLAY);
|
||||
if (postOverlayResources instanceof ResourceCollection)
|
||||
props.put("base.dirs", toCSV(((ResourceCollection)postOverlayResources).getResources()));
|
||||
else
|
||||
props.put("base.dirs", postOverlayResources.toString());
|
||||
|
||||
|
||||
//resource bases - these are what has been configured BEFORE the webapp started and
|
||||
//potentially reordered them and included any resources from META-INF
|
||||
if (originalBaseResource != null)
|
||||
{
|
||||
StringBuffer rb = new StringBuffer();
|
||||
if (originalBaseResource instanceof ResourceCollection)
|
||||
{
|
||||
ResourceCollection resources = ((ResourceCollection)originalBaseResource);
|
||||
for (Resource r:resources.getResources())
|
||||
{
|
||||
if (rb.length() > 0) rb.append(",");
|
||||
rb.append(r.toString());
|
||||
}
|
||||
}
|
||||
else
|
||||
rb.append(originalBaseResource.toString());
|
||||
|
||||
props.put("base.dirs", rb.toString());
|
||||
}
|
||||
|
||||
//sort out the resource base directories of the webapp
|
||||
props.put("base.first", Boolean.toString(webApp.getBaseAppFirst()));
|
||||
|
||||
//web-inf classes
|
||||
if (webApp.getClasses() != null)
|
||||
{
|
||||
|
@ -838,4 +837,17 @@ public class JettyRunForkedMojo extends JettyRunMojo
|
|||
}
|
||||
return strbuff.toString();
|
||||
}
|
||||
|
||||
private String toCSV (Resource[] resources)
|
||||
{
|
||||
StringBuffer rb = new StringBuffer();
|
||||
|
||||
for (Resource r:resources)
|
||||
{
|
||||
if (rb.length() > 0) rb.append(",");
|
||||
rb.append(r.toString());
|
||||
}
|
||||
|
||||
return rb.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,9 +23,11 @@ import java.io.File;
|
|||
import java.util.Iterator;
|
||||
|
||||
import org.eclipse.jetty.quickstart.QuickStartConfiguration;
|
||||
import org.eclipse.jetty.util.IO;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
import org.eclipse.jetty.util.resource.ResourceCollection;
|
||||
import org.eclipse.jetty.webapp.WebAppClassLoader;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
|
||||
|
@ -54,6 +56,20 @@ public class MavenQuickStartConfiguration extends QuickStartConfiguration
|
|||
return _quickStartWebXml;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preConfigure(WebAppContext context) throws Exception
|
||||
{
|
||||
//check that webapp is suitable for quick start
|
||||
if (context.getBaseResource() == null)
|
||||
throw new IllegalStateException ("No location for webapp");
|
||||
|
||||
|
||||
//look for quickstart-web.xml in WEB-INF of webapp
|
||||
Resource quickStartWebXml = getQuickStartWebXml(context);
|
||||
LOG.debug("quickStartWebXml={}",quickStartWebXml);
|
||||
|
||||
context.getMetaData().setWebXml(quickStartWebXml);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
|
@ -89,4 +105,28 @@ public class MavenQuickStartConfiguration extends QuickStartConfiguration
|
|||
context.setServerClasses( newServerClasses );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deconfigure(WebAppContext context) throws Exception
|
||||
{
|
||||
//if we're not persisting the temp dir, get rid of any overlays
|
||||
if (!context.isPersistTempDirectory())
|
||||
{
|
||||
Resource originalBases = (Resource)context.getAttribute("org.eclipse.jetty.resources.originalBases");
|
||||
String originalBaseStr = originalBases.toString();
|
||||
|
||||
//Iterate over all of the resource bases and ignore any that were original bases, just
|
||||
//deleting the overlays
|
||||
Resource res = context.getBaseResource();
|
||||
if (res instanceof ResourceCollection)
|
||||
{
|
||||
for (Resource r:((ResourceCollection)res).getResources())
|
||||
{
|
||||
if (originalBaseStr.contains(r.toString()))
|
||||
continue;
|
||||
IO.delete(r.getFile());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.eclipse.jetty.util.IO;
|
||||
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
|
@ -47,7 +47,7 @@ public class MavenWebInfConfiguration extends WebInfConfiguration
|
|||
{
|
||||
private static final Logger LOG = Log.getLogger(MavenWebInfConfiguration.class);
|
||||
|
||||
|
||||
public static final String RESOURCE_BASES_POST_OVERLAY = "org.eclipse.jetty.resource.postOverlay";
|
||||
protected static int COUNTER = 0;
|
||||
protected Resource _originalResourceBase;
|
||||
protected List<Resource> _unpackedOverlayResources;
|
||||
|
@ -119,24 +119,11 @@ public class MavenWebInfConfiguration extends WebInfConfiguration
|
|||
*/
|
||||
public void deconfigure(WebAppContext context) throws Exception
|
||||
{
|
||||
//remove the unpacked wars
|
||||
if (_unpackedOverlayResources != null && !_unpackedOverlayResources.isEmpty())
|
||||
{
|
||||
try
|
||||
{
|
||||
for (Resource r:_unpackedOverlayResources)
|
||||
{
|
||||
IO.delete(r.getFile());
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
LOG.ignore(e);
|
||||
}
|
||||
}
|
||||
super.deconfigure(context);
|
||||
//restore whatever the base resource was before we might have included overlaid wars
|
||||
context.setBaseResource(_originalResourceBase);
|
||||
//undo the setting of the overlayed resources
|
||||
context.removeAttribute(RESOURCE_BASES_POST_OVERLAY);
|
||||
}
|
||||
|
||||
|
||||
|
@ -194,9 +181,10 @@ public class MavenWebInfConfiguration extends WebInfConfiguration
|
|||
resourceBaseCollection.add(_originalResourceBase);
|
||||
}
|
||||
}
|
||||
|
||||
jwac.setBaseResource(new ResourceCollection(resourceBaseCollection.toArray(new Resource[resourceBaseCollection.size()])));
|
||||
}
|
||||
|
||||
jwac.setAttribute(RESOURCE_BASES_POST_OVERLAY, jwac.getBaseResource());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -221,21 +221,23 @@ public class Starter
|
|||
str = (String)props.getProperty("tmp.dir.persist");
|
||||
if (str != null)
|
||||
webApp.setPersistTempDirectory(Boolean.valueOf(str));
|
||||
|
||||
// - the base directories
|
||||
|
||||
//Get the calculated base dirs which includes the overlays
|
||||
str = (String)props.getProperty("base.dirs");
|
||||
if (str != null && !"".equals(str.trim()))
|
||||
{
|
||||
ResourceCollection bases = new ResourceCollection(str.split(","));
|
||||
webApp.setWar(bases.getResources()[0].toString());
|
||||
webApp.setWar(null);
|
||||
webApp.setBaseResource(bases);
|
||||
}
|
||||
|
||||
// - put virtual webapp base resource first on resource path or not
|
||||
str = (String)props.getProperty("base.first");
|
||||
|
||||
//Get the original base dirs without the overlays
|
||||
str = (String)props.get("base.dirs.orig");
|
||||
if (str != null && !"".equals(str.trim()))
|
||||
webApp.setBaseAppFirst(Boolean.valueOf(str));
|
||||
|
||||
{
|
||||
ResourceCollection bases = new ResourceCollection(str.split(","));
|
||||
webApp.setAttribute ("org.eclipse.jetty.resources.originalBases", bases);
|
||||
}
|
||||
|
||||
//For overlays
|
||||
str = (String)props.getProperty("maven.war.includes");
|
||||
|
|
Loading…
Reference in New Issue