app.setName(appName);
List<AbstractArchive> unknowns = new ArrayList();
File[] files = getEligibleEntries(new File(appRoot), directory);
for (File subModule : files) {
AbstractArchive subArchive = null;
try {
try {
if (!directory) {
subArchive = new InputJarArchive();
((InputJarArchive)subArchive).open(subModule.getAbsolutePath());
} else {
subArchive = new FileArchive();
((FileArchive)subArchive).open(subModule.getAbsolutePath());
}
} catch (IOException ex) {
_logger.log(Level.WARNING, ex.getMessage());
}
//for archive deployment, we check the sub archives by its
//file extension; for directory deployment, we check the sub
//directories by its name. We are now supporting directory
//names with both "_suffix" and ".suffix".
//Section EE.8.4.2.1.a
String name = subModule.getName();
String uri = deriveArchiveUri(appRoot, subModule, directory);
if ( (!directory && name.endsWith(".war"))
|| (directory &&
(name.endsWith("_war") ||
name.endsWith(".war"))) ) {
String contextRoot =
uri.substring(uri.lastIndexOf('/')+1, uri.lastIndexOf('.'));
ModuleDescriptor md = new ModuleDescriptor();
md.setArchiveUri(uri);
md.setModuleType(ModuleType.WAR);
md.setContextRoot(contextRoot);
app.addModule(md);
}
//Section EE.8.4.2.1.b
else if ( (!directory && name.endsWith(".rar"))
|| (directory &&
(name.endsWith("_rar") ||
name.endsWith(".rar"))) ) {
ModuleDescriptor md = new ModuleDescriptor();
md.setArchiveUri(uri);
md.setModuleType(ModuleType.RAR);
app.addModule(md);
}
else if ( (!directory && name.endsWith(".jar"))
|| (directory &&
(name.endsWith("_jar") ||
name.endsWith(".jar"))) ) {
try {
//Section EE.8.4.2.1.d.i
AppClientArchivist acArchivist = new AppClientArchivist();
if (acArchivist.hasStandardDeploymentDescriptor(subArchive)
|| acArchivist.hasRuntimeDeploymentDescriptor(subArchive)
|| acArchivist.getMainClassName(subArchive.getManifest()) != null) {
ModuleDescriptor md = new ModuleDescriptor();
md.setArchiveUri(uri);
md.setModuleType(ModuleType.CAR);
md.setManifest(subArchive.getManifest());
app.addModule(md);
continue;
}
//Section EE.8.4.2.1.d.ii
EjbArchivist ejbArchivist = new EjbArchivist();
if (ejbArchivist.hasStandardDeploymentDescriptor(subArchive)
|| ejbArchivist.hasRuntimeDeploymentDescriptor(subArchive)) {
ModuleDescriptor md = new ModuleDescriptor();
md.setArchiveUri(uri);
md.setModuleType(ModuleType.EJB);
app.addModule(md);
continue;
}
} catch (IOException ex) {
_logger.log(Level.WARNING, ex.getMessage());
}
//Still could not decide between an ejb and a library
unknowns.add(subArchive);
} else {
//ignored
}
} finally {
if (subArchive != null) {
try {
subArchive.close();
} catch (IOException ioe) {
_logger.log(Level.WARNING, localStrings.getLocalString("enterprise.deployment.errorClosingSubArch", "Error closing subarchive {0}", new Object[] {subModule.getAbsolutePath()}), ioe);
}
}
}