Merge branch 'jetty-9.1' of ssh://git.eclipse.org/gitroot/jetty/org.eclipse.jetty.project into jetty-9.1

This commit is contained in:
Greg Wilkins 2013-09-09 18:28:35 +10:00
commit f7bde55038
1 changed files with 55 additions and 40 deletions

View File

@ -37,7 +37,7 @@ import org.eclipse.jetty.xml.XmlConfiguration;
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
/** The webapps directory scanning provider. /** The webapps directory scanning provider.
* <p> * <p>
* This provider scans one or more directories (typically "webapps") for contexts to * This provider scans one or more directories (typically "webapps") for contexts to
* deploy, which may be:<ul> * deploy, which may be:<ul>
* <li>A standard WAR file (must end in ".war")</li> * <li>A standard WAR file (must end in ".war")</li>
* <li>A directory containing an expanded WAR file</li> * <li>A directory containing an expanded WAR file</li>
@ -56,7 +56,7 @@ import org.eclipse.jetty.xml.XmlConfiguration;
* <li>If a WAR file and a matching XML exist (eg foo.war and foo.xml) then the WAR is assumed to * <li>If a WAR file and a matching XML exist (eg foo.war and foo.xml) then the WAR is assumed to
* be configured by the XML and only the XML is deployed. * be configured by the XML and only the XML is deployed.
* </ul> * </ul>
* <p>For XML configured contexts, the ID map will contain a reference to the {@link Server} instance called "Server" and * <p>For XML configured contexts, the ID map will contain a reference to the {@link Server} instance called "Server" and
* properties for the webapp file as "jetty.webapp" and directory as "jetty.webapps". * properties for the webapp file as "jetty.webapp" and directory as "jetty.webapps".
*/ */
@ManagedObject("Provider for start-up deployement of webapps based on presence in directory") @ManagedObject("Provider for start-up deployement of webapps based on presence in directory")
@ -79,36 +79,36 @@ public class WebAppProvider extends ScanningAppProvider
return false; return false;
} }
String lowername = name.toLowerCase(Locale.ENGLISH); String lowername = name.toLowerCase(Locale.ENGLISH);
File file = new File(dir,name); File file = new File(dir,name);
// ignore hidden files // ignore hidden files
if (lowername.startsWith(".")) if (lowername.startsWith("."))
return false; return false;
// Ignore some directories // Ignore some directories
if (file.isDirectory()) if (file.isDirectory())
{ {
// is it a nominated config directory // is it a nominated config directory
if (lowername.endsWith(".d")) if (lowername.endsWith(".d"))
return false; return false;
// is it an unpacked directory for an existing war file? // is it an unpacked directory for an existing war file?
if (exists(name+".war")||exists(name+".WAR")) if (exists(name+".war")||exists(name+".WAR"))
return false; return false;
// is it a directory for an existing xml file? // is it a directory for an existing xml file?
if (exists(name+".xml")||exists(name+".XML")) if (exists(name+".xml")||exists(name+".XML"))
return false; return false;
//is it a sccs dir? //is it a sccs dir?
if ("cvs".equals(lowername) || "cvsroot".equals(lowername)) if ("cvs".equals(lowername) || "cvsroot".equals(lowername))
return false; return false;
// OK to deploy it then // OK to deploy it then
return true; return true;
} }
// else is it a war file // else is it a war file
if (lowername.endsWith(".war")) if (lowername.endsWith(".war"))
{ {
@ -120,15 +120,15 @@ public class WebAppProvider extends ScanningAppProvider
// OK to deploy it then // OK to deploy it then
return true; return true;
} }
// else is it a context XML file // else is it a context XML file
if (lowername.endsWith(".xml")) if (lowername.endsWith(".xml"))
return true; return true;
return false; return false;
} }
} }
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
public WebAppProvider() public WebAppProvider()
{ {
@ -220,29 +220,29 @@ public class WebAppProvider extends ScanningAppProvider
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
/** /**
* *
*/ */
@ManagedAttribute("configuration classes for webapps to be processed through") @ManagedAttribute("configuration classes for webapps to be processed through")
public String[] getConfigurationClasses() public String[] getConfigurationClasses()
{ {
return _configurationClasses; return _configurationClasses;
} }
/** /**
* Set the Work directory where unpacked WAR files are managed from. * Set the Work directory where unpacked WAR files are managed from.
* <p> * <p>
* Default is the same as the <code>java.io.tmpdir</code> System Property. * Default is the same as the <code>java.io.tmpdir</code> System Property.
* *
* @param directory the new work directory * @param directory the new work directory
*/ */
public void setTempDir(File directory) public void setTempDir(File directory)
{ {
_tempDirectory = directory; _tempDirectory = directory;
} }
/** /**
* Get the user supplied Work Directory. * Get the user supplied Work Directory.
* *
* @return the user supplied work directory (null if user has not set Temp Directory yet) * @return the user supplied work directory (null if user has not set Temp Directory yet)
*/ */
@ManagedAttribute("temp directory for use, null if no user set temp directory") @ManagedAttribute("temp directory for use, null if no user set temp directory")
@ -250,7 +250,7 @@ public class WebAppProvider extends ScanningAppProvider
{ {
return _tempDirectory; return _tempDirectory;
} }
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
@Override @Override
public ContextHandler createContextHandler(final App app) throws Exception public ContextHandler createContextHandler(final App app) throws Exception
@ -264,14 +264,29 @@ public class WebAppProvider extends ScanningAppProvider
if (resource.exists() && FileID.isXmlFile(file)) if (resource.exists() && FileID.isXmlFile(file))
{ {
XmlConfiguration xmlc = new XmlConfiguration(resource.getURL()); XmlConfiguration xmlc = new XmlConfiguration(resource.getURL())
{
@Override
public void initializeDefaults(Object context)
{
super.initializeDefaults(context);
if (context instanceof WebAppContext)
{
WebAppContext webapp = (WebAppContext)context;
webapp.setParentLoaderPriority(_parentLoaderPriority);
if (_defaultsDescriptor != null)
webapp.setDefaultsDescriptor(_defaultsDescriptor);
}
}
};
xmlc.getIdMap().put("Server",getDeploymentManager().getServer()); xmlc.getIdMap().put("Server",getDeploymentManager().getServer());
xmlc.getProperties().put("jetty.home",System.getProperty("jetty.home",".")); xmlc.getProperties().put("jetty.home",System.getProperty("jetty.home","."));
xmlc.getProperties().put("jetty.base",System.getProperty("jetty.base",".")); xmlc.getProperties().put("jetty.base",System.getProperty("jetty.base","."));
xmlc.getProperties().put("jetty.webapp",file.getCanonicalPath()); xmlc.getProperties().put("jetty.webapp",file.getCanonicalPath());
xmlc.getProperties().put("jetty.webapps",file.getParentFile().getCanonicalPath()); xmlc.getProperties().put("jetty.webapps",file.getParentFile().getCanonicalPath());
if (getConfigurationManager() != null) if (getConfigurationManager() != null)
xmlc.getProperties().putAll(getConfigurationManager().getProperties()); xmlc.getProperties().putAll(getConfigurationManager().getProperties());
return (ContextHandler)xmlc.configure(); return (ContextHandler)xmlc.configure();
@ -285,21 +300,21 @@ public class WebAppProvider extends ScanningAppProvider
// Context Path is the same as the archive. // Context Path is the same as the archive.
context = context.substring(0,context.length() - 4); context = context.substring(0,context.length() - 4);
} }
else else
{ {
throw new IllegalStateException("unable to create ContextHandler for "+app); throw new IllegalStateException("unable to create ContextHandler for "+app);
} }
// Ensure "/" is Not Trailing in context paths. // Ensure "/" is Not Trailing in context paths.
if (context.endsWith("/") && context.length() > 0) if (context.endsWith("/") && context.length() > 0)
{ {
context = context.substring(0,context.length() - 1); context = context.substring(0,context.length() - 1);
} }
// Start building the webapplication // Start building the webapplication
WebAppContext wah = new WebAppContext(); WebAppContext webAppContext = new WebAppContext();
wah.setDisplayName(context); webAppContext.setDisplayName(context);
// special case of archive (or dir) named "root" is / context // special case of archive (or dir) named "root" is / context
if (context.equalsIgnoreCase("root")) if (context.equalsIgnoreCase("root"))
{ {
@ -309,28 +324,28 @@ public class WebAppProvider extends ScanningAppProvider
{ {
int dash=context.toLowerCase(Locale.ENGLISH).indexOf('-'); int dash=context.toLowerCase(Locale.ENGLISH).indexOf('-');
String virtual = context.substring(dash+1); String virtual = context.substring(dash+1);
wah.setVirtualHosts(new String[]{virtual}); webAppContext.setVirtualHosts(new String[]{virtual});
context = URIUtil.SLASH; context = URIUtil.SLASH;
} }
// Ensure "/" is Prepended to all context paths. // Ensure "/" is Prepended to all context paths.
if (context.charAt(0) != '/') if (context.charAt(0) != '/')
{ {
context = "/" + context; context = "/" + context;
} }
wah.setContextPath(context); webAppContext.setContextPath(context);
wah.setWar(file.getAbsolutePath()); webAppContext.setWar(file.getAbsolutePath());
if (_defaultsDescriptor != null) if (_defaultsDescriptor != null)
{ {
wah.setDefaultsDescriptor(_defaultsDescriptor); webAppContext.setDefaultsDescriptor(_defaultsDescriptor);
} }
wah.setExtractWAR(_extractWars); webAppContext.setExtractWAR(_extractWars);
wah.setParentLoaderPriority(_parentLoaderPriority); webAppContext.setParentLoaderPriority(_parentLoaderPriority);
if (_configurationClasses != null) if (_configurationClasses != null)
{ {
wah.setConfigurationClasses(_configurationClasses); webAppContext.setConfigurationClasses(_configurationClasses);
} }
if (_tempDirectory != null) if (_tempDirectory != null)
@ -342,9 +357,9 @@ public class WebAppProvider extends ScanningAppProvider
* If we used .setTempDirectory(File) all webapps will wind up in the * If we used .setTempDirectory(File) all webapps will wind up in the
* same temp / work directory, overwriting each others work. * same temp / work directory, overwriting each others work.
*/ */
wah.setAttribute(WebAppContext.BASETEMPDIR,_tempDirectory); webAppContext.setAttribute(WebAppContext.BASETEMPDIR, _tempDirectory);
} }
return wah; return webAppContext;
} }
} }