ModuleRootMarker.mark(deploymentRoot, false);
String libDirName = DEFAULT_LIB_DIR;
//its possible that the ear metadata could come for jboss-app.xml
final boolean appXmlPresent = deploymentRoot.getRoot().getChild("META-INF/application.xml").exists();
final EarMetaData earMetaData = deploymentUnit.getAttachment(org.jboss.as.ee.structure.Attachments.EAR_METADATA);
if (earMetaData != null) {
final String xmlLibDirName = earMetaData.getLibraryDirectory();
if (xmlLibDirName != null) {
if (xmlLibDirName.length() == 1 && xmlLibDirName.charAt(0) == '/') {
throw EeLogger.ROOT_LOGGER.rootAsLibraryDirectory();
}
libDirName = xmlLibDirName;
}
}
// Process all the children
Map<String, MountedDeploymentOverlay> overlays = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_OVERLAY_LOCATIONS);
try {
final VirtualFile libDir;
// process the lib directory
if (!libDirName.isEmpty()) {
libDir = virtualFile.getChild(libDirName);
if (libDir.exists()) {
List<VirtualFile> libArchives = libDir.getChildren(CHILD_ARCHIVE_FILTER);
for (final VirtualFile child : libArchives) {
String relativeName = child.getPathNameRelativeTo(deploymentRoot.getRoot());
MountedDeploymentOverlay overlay = overlays.get(relativeName);
final MountHandle mountHandle;
if(overlay != null) {
overlay.remountAsZip(false);
mountHandle = new MountHandle(null);
} else {
final Closeable closable = child.isFile() ? mount(child, false) : null;
mountHandle = new MountHandle(closable);
}
final ResourceRoot childResource = new ResourceRoot(child, mountHandle);
if (child.getName().toLowerCase(Locale.ENGLISH).endsWith(JAR_EXTENSION)) {
ModuleRootMarker.mark(childResource);
deploymentUnit.addToAttachmentList(Attachments.RESOURCE_ROOTS, childResource);
}
}
}
} else {
libDir = null;
}
// scan the ear looking for wars and jars
final List<VirtualFile> childArchives = new ArrayList<VirtualFile>(virtualFile.getChildren(new SuffixMatchFilter(
CHILD_ARCHIVE_EXTENSIONS, new VisitorAttributes() {
@Override
public boolean isLeavesOnly() {
return false;
}
@Override
public boolean isRecurse(VirtualFile file) {
// don't recurse into /lib
if (file.equals(libDir)) {
return false;
}
for (String suffix : CHILD_ARCHIVE_EXTENSIONS) {
if (file.getName().endsWith(suffix)) {
// don't recurse into sub deployments
return false;
}
}
return true;
}
})));
// if there is no application.xml then look in the ear root for modules
if (!appXmlPresent) {
for (final VirtualFile child : childArchives) {
final boolean isWarFile = child.getName().toLowerCase(Locale.ENGLISH).endsWith(WAR_EXTENSION);
final boolean isRarFile = child.getName().toLowerCase(Locale.ENGLISH).endsWith(RAR_EXTENSION);
this.createResourceRoot(deploymentUnit, child, isWarFile || isRarFile, isWarFile);
}
} else {
final Set<VirtualFile> subDeploymentFiles = new HashSet<VirtualFile>();
// otherwise read from application.xml
for (final ModuleMetaData module : earMetaData.getModules()) {
if(module.getFileName().endsWith(".xml")) {
throw EeLogger.ROOT_LOGGER.unsupportedModuleType(module.getFileName());
}