parent = javaClass.getClassLoader();
}
final List<URL> additionalPaths = new ArrayList<URL>();
final List<AssetSource> beansXmlMerged = new ArrayList<>();
CompositeArchive earArchive = null;
Map<URL, List<String>> earMap = null;
final String prefix;
final boolean isEar = EnterpriseArchive.class.isInstance(archive);
if (WebArchive.class.isInstance(archive)) {
prefix = WEB_INF;
final Map<ArchivePath, Node> content = archive.getContent(new IncludeRegExpPaths("/WEB-INF/lib/.*"));
for (final Map.Entry<ArchivePath, Node> node : content.entrySet()) {
final Asset asset = node.getValue().getAsset();
if (UrlAsset.class.isInstance(asset)) {
additionalPaths.add(get(URL.class, "url", asset));
} else if (FileAsset.class.isInstance(asset)) {
try {
additionalPaths.add(get(File.class, "file", asset).toURI().toURL());
} catch (final MalformedURLException e) {
LOGGER.log(Level.SEVERE, "can't add a library to the deployment", e);
}
} else if (ArchiveAsset.class.isInstance(asset)) {
final Archive<?> nestedArchive = ArchiveAsset.class.cast(asset).getArchive();
if (!isExcluded(nestedArchive.getName())) {
final Node bXmlNode = nestedArchive.get(META_INF + BEANS_XML);
if (bXmlNode != null) {
try {
beansXmlMerged.add(new AssetSource(bXmlNode.getAsset(), new URL("jar:file://!/WEB-INF/lib/" + nestedArchive.getName() + "!/META-INF/beans.xml")));
} catch (final MalformedURLException e) {
// shouldn't occur
}
}
archive.merge(nestedArchive);
}
}
}
} else {
if (isEar) { // mainly for CDi TCKs
earMap = new HashMap<>();
final Map<ArchivePath, Node> jars = archive.getContent(new IncludeRegExpPaths("/.*\\.jar"));
final List<org.apache.xbean.finder.archive.Archive> archives = new ArrayList<>(jars.size());
for (final Map.Entry<ArchivePath, Node> node : jars.entrySet()) {
final Asset asset = node.getValue().getAsset();
if (ArchiveAsset.class.isInstance(asset)) {
final Archive<?> libArchive = ArchiveAsset.class.cast(asset).getArchive();
if (!isExcluded(libArchive.getName())) {
final List<Class<?>> earClasses = new ArrayList<>();
final List<String> earClassNames = new ArrayList<>();
final Map<ArchivePath, Node> content = libArchive.getContent(new IncludeRegExpPaths(".*.class"));
for (final Map.Entry<ArchivePath, Node> classNode : content.entrySet()) {
final String classname = name(classNode.getKey().get());
try {
earClasses.add(parent.loadClass(classname));
earClassNames.add(classname);
} catch (final ClassNotFoundException e) {
LOGGER.fine("Can't load class " + classname);
} catch (final NoClassDefFoundError ncdfe) {
// no-op
}
}
try { // ends with !/META-INF/beans.xml to force it to be used as a cdi module
earMap.put(new URL("jar:file://!/lib/" + archive.getName() + (libArchive.get(META_INF + BEANS_XML) != null ? "!/META-INF/beans.xml" : "")), earClassNames);
} catch (final MalformedURLException e) {
// no-op
}
archives.add(new ClassesArchive(earClasses));
}
} // else TODO
}
earArchive = new CompositeArchive(archives);
}
prefix = META_INF;
}