final Node appXml = ear.get(ParseUtils.APPLICATION_XML);
if (appXml != null) {
InputStream stream = appXml.getAsset().openStream();
try {
ApplicationDescriptor ad = Descriptors.importAs(ApplicationDescriptor.class).fromStream(stream);
List<JavaArchive> libs = new ArrayList<JavaArchive>();
String libDir = ad.getLibraryDirectory();
if (libDir != null) {
libDir = "lib"; // default?
}
Node lib = ear.get(libDir);
if (lib != null) {
// defensive copy
final Set<Node> children = new HashSet<Node>(lib.getChildren());
for (Node child : children) {
if (child.getPath().get().endsWith(".jar")) {
JavaArchive jar = ear.getAsType(JavaArchive.class, child.getPath());
libs.add(jar);
}
}
}
List<ModuleType<ApplicationDescriptor>> allModules = ad.getAllModule();
for (ModuleType<ApplicationDescriptor> mt : allModules) {
String uri = mt.getOrCreateWeb().getWebUri();
if (uri != null) {
WebArchive war = ear.getAsType(WebArchive.class, uri);
handleWar(root, libs, war, uri);