use of org.apache.xbean.finder.archive.JarArchive in project tomee by apache.
the class OpenEJBArchiveProcessor method analyzeLibs.
private static CompositeArchive analyzeLibs(final ClassLoader parent, final List<URL> additionalPaths, final Map<URL, List<String>> earMap, final List<Archive> earLibsArchives, final CompositeBeans earBeans, final Map<ArchivePath, Node> jars, final Map<String, Object> altDD) {
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())) {
earLibsArchives.add(libArchive);
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 *with bda*
final Node beansNode = libArchive.get(META_INF + BEANS_XML);
final URL arUrl = new URL("jar:file://!/lib/" + libArchive.getName() + (beansNode != null ? "!/META-INF/beans.xml" : ""));
if (beansNode != null) {
try {
DeploymentLoader.doMerge(arUrl, earBeans, ReadDescriptors.readBeans(beansNode.getAsset().openStream()));
} catch (final OpenEJBException e) {
throw new IllegalArgumentException(e);
}
}
earMap.put(arUrl, earClassNames);
} catch (final MalformedURLException e) {
// no-op
}
archives.add(new ClassesArchive(earClasses));
}
final Node ejbJarXml = libArchive.get(META_INF + EJB_JAR_XML);
if (ejbJarXml != null) {
// not super, we should merge them surely but ok for use cases we met until today
altDD.put("ejb-jar.xml", new AssetSource(ejbJarXml.getAsset(), null));
}
}
if (UrlAsset.class.isInstance(asset) || FileAsset.class.isInstance(asset)) {
try {
final URL url = UrlAsset.class.isInstance(asset) ? get(URL.class, "url", asset) : get(File.class, "file", asset).toURI().toURL();
final List<String> classes = new ArrayList<String>();
archives.add(new FilteredArchive(new JarArchive(parent, url), new WebappAggregatedArchive.ScanXmlSaverFilter(false, null, classes, null)));
additionalPaths.add(url);
final URLClassLoader loader = new URLClassLoader(new URL[] { url }, EMPTY_LOADER);
for (final String beans : asList("META-INF/beans.xml", "/META-INF/beans.xml")) {
final URL u = loader.getResource(beans);
if (u != null) {
try {
DeploymentLoader.doMerge(u, earBeans, ReadDescriptors.readBeans(u.openStream()));
} catch (final OpenEJBException e) {
throw new IllegalArgumentException(e);
} catch (final IOException e) {
// no-op
}
earMap.put(u, classes);
}
}
try {
loader.close();
} catch (final IOException e) {
// no-op
}
} catch (final MalformedURLException e) {
throw new IllegalArgumentException(e);
}
}
}
return new CompositeArchive(archives);
}
use of org.apache.xbean.finder.archive.JarArchive in project component-runtime by Talend.
the class Generator method generatedJUnitEnvironment.
private static void generatedJUnitEnvironment(final File generatedDir) throws MalformedURLException {
final File file = new File(generatedDir, "generated_junit-environments.adoc");
try (final PrintStream stream = new PrintStream(new WriteIfDifferentStream(file))) {
stream.println("");
stream.println("NOTE: the configuration is read from system properties, environment variables, ....");
stream.println("");
stream.println("[role=\"table-striped table-hover table-ordered\",options=\"header,autowidth\"]");
stream.println("|====");
stream.println("|Class|Name|Description");
final File api = jarLocation(BaseEnvironmentProvider.class);
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
final AnnotationFinder finder = new AnnotationFinder(api.isDirectory() ? new FileArchive(loader, api) : new JarArchive(loader, api.toURI().toURL()));
finder.link().findSubclasses(BaseEnvironmentProvider.class).stream().filter(c -> !Modifier.isAbstract(c.getModifiers())).sorted(Comparator.comparing(Class::getName)).forEach(type -> {
final BaseEnvironmentProvider environment;
try {
environment = BaseEnvironmentProvider.class.cast(type.getConstructor().newInstance());
} catch (final InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
throw new IllegalStateException(e);
}
stream.println("|" + type.getSimpleName() + "|" + environment.getName() + "|" + environment.getName() + " runner");
});
stream.println("|====");
stream.println();
}
}
Aggregations