assert targetPath != null : "targetPath is null";
assert !targetPath.endsWith("/") : "targetPath must not end with a '/'";
// parse the spec dd
String specDD = null;
WebAppType webApp = null;
try {
if (specDDUrl == null) {
specDDUrl = JarUtils.createJarURL(moduleFile, "WEB-INF/web.xml");
}
// read in the entire specDD as a string, we need this for getDeploymentDescriptor
// on the J2ee management object
specDD = JarUtils.readAll(specDDUrl);
// we found web.xml, if it won't parse that's an error.
XmlObject parsed = XmlBeansUtil.parse(specDD);
WebAppDocument webAppDoc = SchemaConversionUtils.convertToServletSchema(parsed);
webApp = webAppDoc.getWebApp();
WebDeploymentValidationUtils.validateWebApp(webApp);
} catch (XmlException e) {
// Output the target path in the error to make it clearer to the user which webapp
// has the problem. The targetPath is used, as moduleFile may have an unhelpful
// value such as C:\geronimo-1.1\var\temp\geronimo-deploymentUtil22826.tmpdir
throw new DeploymentException("Error parsing web.xml for " + targetPath, e);
} catch (Exception e) {
if (!moduleFile.getName().endsWith(".war")) {
//not for us
return null;
}
//else ignore as jee5 allows optional spec dd for .war's
}
if (webApp == null) {
webApp = WebAppType.Factory.newInstance();
}
Deployable deployable = new DeployableJarFile(moduleFile);
// parse vendor dd
boolean standAlone = earEnvironment == null;
TomcatWebAppType tomcatWebApp = getTomcatWebApp(plan, deployable, standAlone, targetPath, webApp);
contextRoot = getContextRoot(tomcatWebApp, contextRoot, webApp, standAlone, moduleFile, targetPath);
EnvironmentType environmentType = tomcatWebApp.getEnvironment();
Environment environment = EnvironmentBuilder.buildEnvironment(environmentType, defaultEnvironment);
if (webApp.getDistributableArray().length == 1) {
clusteringBuilders.buildEnvironment(tomcatWebApp, environment);
}
if (!standAlone && COMBINED_BUNDLE) {
EnvironmentBuilder.mergeEnvironments(earEnvironment, environment);