return name.toLowerCase().endsWith(".ear");
}
public boolean doDetermineStructure(StructureContext structureContext) throws DeploymentException
{
ContextInfo context;
boolean valid;
boolean trace = log.isTraceEnabled();
VirtualFile file = structureContext.getFile();
try
{
if (hasValidName(file) == false)
return false;
context = createContext(structureContext, "META-INF");
context.setComparatorClassName(comparatorClassName);
VirtualFile applicationXml = getMetaDataFile(file, "META-INF/application.xml");
VirtualFile jbossAppXml = getMetaDataFile(file, "META-INF/jboss-app.xml");
VirtualFile lib;
boolean scan = true;
Unmarshaller unmarshaller = unmarshallerFactory.newUnmarshaller();
unmarshaller.setValidation(useValidation);
EarMetaData specMetaData = null;
JBossAppMetaData appMetaData = null;
if (applicationXml != null)
{
InputStream in = applicationXml.openStream();
try
{
specMetaData = (EarMetaData) unmarshaller.unmarshal(in, resolver);
}
finally
{
in.close();
}
scan = false;
}
if (jbossAppXml != null)
{
InputStream in = jbossAppXml.openStream();
try
{
appMetaData = (JBossAppMetaData) unmarshaller.unmarshal(in, resolver);
}
finally
{
in.close();
}
}
// Need a metadata instance and there will not be one if there are no descriptors
if (appMetaData == null)
{
appMetaData = new JBossAppMetaData();
}
// Create the merged view
appMetaData.merge(appMetaData, specMetaData);
String libDir = appMetaData.getLibraryDirectory();
if (libDir == null || libDir.length() > 0)
{
if (libDir == null)
libDir = "lib";
// Add the ear lib contents to the classpath
if(trace)
log.trace("Checking for ear lib directory: "+libDir);
try
{
lib = file.getChild(libDir);
if (lib.exists())
{
if(trace)
log.trace("Found ear lib directory: "+lib);
List<VirtualFile> archives = lib.getChildren(earLibFilter);
for (VirtualFile archive : archives)
{
Automounter.mount(file, archive);
addClassPath(structureContext, archive, true, true, context);
// add any jars with persistence.xml as a deployment
if (archive.getChild("META-INF/persistence.xml").exists())
{
log.trace(archive.getName() + " in ear lib directory has persistence units");
if (structureContext.determineChildStructure(archive) == false)
{
throw new RuntimeException(archive.getName()
+ " in lib directory has persistence.xml but is not a recognized deployment, .ear: "
+ file.getName());
}
}
else if (trace)
log.trace(archive.getPathName() + " does not contain META-INF/persistence.xml");
}
}
else if (trace)
log.trace("No lib directory in ear archive.");
}
catch (IOException e)
{
// TODO - should we throw this fwd?
log.warn("Exception while searching for lib dir: " + e);
}
}
else if (trace)
{
log.trace("Ignoring library directory, got empty library-directory element.");
}
// Add the ear manifest locations?
addClassPath(structureContext, file, includeEarRootInClasspath, true, context);
// TODO: need to scan for annotationss
if( scan )
{
scanEar(file, appMetaData);
}
// Create subdeployments for the ear modules
ModulesMetaData modules = appMetaData.getModules();
if(modules != null)
{
for (ModuleMetaData mod : modules)
{
String fileName = mod.getFileName();
if (fileName != null && (fileName = fileName.trim()).length() > 0)
{
if (log.isTraceEnabled())
log.trace("Checking application.xml module: " + fileName);
VirtualFile module = file.getChild(fileName);
if (module.exists() == false)
{
throw new RuntimeException(fileName + " module listed in application.xml does not exist within .ear " + file.toURI());
}
// Ask the deployers to analyze this
if(structureContext.determineChildStructure(module) == false)
{
throw new RuntimeException(fileName
+ " module listed in application.xml is not a recognized deployment, .ear: "
+ file.getName());
}
}
}
if (appMetaData.getModuleOrderEnum() == ModuleOrder.STRICT)
{
context.setComparatorClassName(RelativeDeploymentContextComparator.class.getName());
int i = 0;
for (ContextInfo ctx : structureContext.getMetaData().getContexts())
{
ctx.setRelativeOrder(i++);
}