ModuleRootMarker.mark(resourceRoot, false);
String libDirName = DEFAULT_LIB_DIR;
final JBossAppMetaData appMetaData = deploymentUnit.getAttachment(org.jboss.as.ee.structure.Attachments.JBOSS_APP_METADATA);
final EarMetaData earMetaData = deploymentUnit.getAttachment(org.jboss.as.ee.structure.Attachments.EAR_METADATA);
if (appMetaData != null) {
final String xmlLibDirName = appMetaData.getLibraryDirectory();
if (xmlLibDirName != null) {
libDirName = xmlLibDirName;
}
} else {
if (earMetaData != null) {
if (earMetaData instanceof Ear5xMetaData) {
final String xmlLibDirName = Ear5xMetaData.class.cast(earMetaData).getLibraryDirectory();
if (xmlLibDirName != null) {
libDirName = xmlLibDirName;
}
}
}
}
// Process all the children
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) {
final Closeable closable = child.isFile() ? mount(child, false) : null;
final MountHandle mountHandle = new MountHandle(closable);
final ResourceRoot childResource = new ResourceRoot(child, mountHandle);
if (child.getName().toLowerCase().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 (earMetaData == null) {
for (final VirtualFile child : childArchives) {
final boolean war = child.getName().toLowerCase().endsWith(WAR_EXTENSION);
final Closeable closable = child.isFile() ? mount(child, war)
: null;
final MountHandle mountHandle = new MountHandle(closable);
final ResourceRoot childResource = new ResourceRoot(child, mountHandle);
deploymentUnit.addToAttachmentList(Attachments.RESOURCE_ROOTS, childResource);
if (war) {
SubDeploymentMarker.mark(childResource);
childResource.putAttachment(Attachments.INDEX_RESOURCE_ROOT, false);
}
}
} else {
Set<VirtualFile> subDeploymentFiles = new HashSet<VirtualFile>();
// otherwise read from application.xml
for (ModuleMetaData module : earMetaData.getModules()) {
VirtualFile moduleFile = virtualFile.getChild(module.getFileName());
if (!moduleFile.exists()) {
throw new DeploymentUnitProcessingException("Unable to process modules in application.xml for EAR ["
+ virtualFile + "], module file " + module.getFileName() + " not found");