return applicationInfo;
}
private ApplicationInfo getEarPlan(File planFile, JarFile earFile, ModuleIDBuilder idBuilder) throws DeploymentException {
String specDD;
Application application = null;
if (earFile != null) {
URL applicationXmlUrl = null;
try {
applicationXmlUrl = JarUtils.createJarURL(earFile, "META-INF/application.xml");
specDD = JarUtils.readAll(applicationXmlUrl);
//we found something called application.xml in the right place, if we can't parse it it's an error
InputStream in = applicationXmlUrl.openStream();
try {
application = (Application) JaxbJavaee.unmarshalJavaee(Application.class, in);
} finally {
IOUtils.close(in);
}
} catch (ParserConfigurationException e) {
throw new DeploymentException("Could not parse application.xml", e);
} catch (SAXException e) {
throw new DeploymentException("Could not parse application.xml", e);
} catch (JAXBException e) {
throw new DeploymentException("Could not parse application.xml", e);
} catch (Exception e) {
//ee5 spec allows optional application.xml, continue with application == null
if (!earFile.getName().endsWith(".ear")) {
return null;
}
application = new Application();
}
}
GerApplicationType gerApplication = null;
try {
// load the geronimo-application.xml from either the supplied plan or from the earFile
XmlObject rawPlan;
try {
if (planFile != null) {
rawPlan = XmlBeansUtil.parse(planFile.toURI().toURL(), getClass().getClassLoader());
gerApplication = (GerApplicationType) SchemaConversionUtils.fixGeronimoSchema(rawPlan, APPLICATION_QNAME, GerApplicationType.type);
if (gerApplication == null) {
return null;
}
} else {
URL path = JarUtils.createJarURL(earFile, "META-INF/geronimo-application.xml");
rawPlan = XmlBeansUtil.parse(path, getClass().getClassLoader());
gerApplication = (GerApplicationType) SchemaConversionUtils.fixGeronimoSchema(rawPlan, APPLICATION_QNAME, GerApplicationType.type);
}
} catch (IOException e) {
//TODO isn't this an error?
}
// if we got one extract the validate it otherwise create a default one
if (gerApplication == null) {
gerApplication = createDefaultPlan(application, earFile);
}
} catch (XmlException e) {
throw new DeploymentException(e);
}
EnvironmentType environmentType = gerApplication.getEnvironment();
Environment environment = EnvironmentBuilder.buildEnvironment(environmentType, defaultEnvironment);
idBuilder.resolve(environment, earFile == null ? planFile.getName() : new File(earFile.getName()).getName(), "ear");
// Make this EAR's settings the default for child modules
idBuilder.setDefaultGroup(environment.getConfigId().getGroupId());
idBuilder.setDefaultVersion(environment.getConfigId().getVersion());
Artifact artifact = environment.getConfigId();
AbstractName earName = naming.createRootName(artifact, artifact.toString(), NameFactory.J2EE_APPLICATION);
namingBuilders.buildEnvironment(application, gerApplication, environment);
// get the modules either the application plan or for a stand alone module from the specific deployer
// todo change module so you can extract the real module path back out.. then we can eliminate
// the moduleLocations and have addModules return the modules
String applicationName = null;
if (application!=null && application.getApplicationName() != null) {
applicationName = application.getApplicationName().trim();
} else if (earFile != null) {
applicationName = FileUtils.removeExtension(new File(earFile.getName()).getName(), ".ear");
} else {
applicationName = artifact.toString();
}
ApplicationInfo applicationInfo = new ApplicationInfo(ConfigurationModuleType.EAR,
environment,
earName,
applicationName,
earFile,
application,
gerApplication,
application==null ? null : application.toString()
);
try {
addModules(earFile, application, gerApplication, environment, applicationInfo, idBuilder);
if (applicationInfo.getModules().isEmpty()) {
//if no application.xml and no modules detected, return null for stand-alone module processing