use of org.apache.xbean.finder.archive.ClassesArchive in project tomee by apache.
the class ConfigurableClasspathArchive method archive.
public static Archive archive(final Module module, final URL location, final boolean forceDescriptor) {
final ClassLoader loader = module.getClassLoader();
final String name = "META-INF/" + name();
try {
final URL scanXml = new URLClassLoader(new URL[] { location }, new EmptyResourcesClassLoader()).getResource(name);
if (scanXml == null && !forceDescriptor) {
return ClasspathArchive.archive(loader, location);
} else if (scanXml == null) {
return new ClassesArchive();
}
// read descriptors
final ScanUtil.ScanHandler scan = ScanUtil.read(scanXml);
final Archive packageArchive = packageArchive(scan.getPackages(), loader, location);
final Archive classesArchive = classesArchive(scan.getPackages(), scan.getClasses(), loader);
if (packageArchive != null && classesArchive != null) {
return new CompositeArchive(classesArchive, packageArchive);
} else if (packageArchive != null) {
return packageArchive;
}
return classesArchive;
} catch (final IOException e) {
if (forceDescriptor) {
return new ClassesArchive();
}
return ClasspathArchive.archive(loader, location);
}
}
use of org.apache.xbean.finder.archive.ClassesArchive in project tomee by apache.
the class OpenEJBArchiveProcessor method finderArchive.
private static org.apache.xbean.finder.archive.Archive finderArchive(final Node beansXml, final Archive<?> archive, final ClassLoader cl, final CompositeArchive libs, final Map<URL, List<String>> webAppClassesByUrl, final CompositeBeans compositeBeans) {
final List<Class<?>> classes = new ArrayList<>();
final Map<ArchivePath, Node> content = archive.getContent(new IncludeRegExpPaths(".*.class"));
for (final Map.Entry<ArchivePath, Node> node : content.entrySet()) {
final String classname = name(node.getKey().get());
try {
classes.add(cl.loadClass(classname));
} catch (final ClassNotFoundException e) {
LOGGER.fine("Can't load class " + classname);
if (LOGGER.isLoggable(Level.FINEST)) {
e.printStackTrace(System.err);
}
} catch (final NoClassDefFoundError ncdfe) {
// no-op
}
}
final List<org.apache.xbean.finder.archive.Archive> archives = new ArrayList<>();
archives.add(new ClassesArchive(classes));
if (beansXml != null) {
try {
// no host avoid host resolution in hashcode()
final URL key = new URL("jar:file://!/WEB-INF/beans.xml");
try {
DeploymentLoader.doMerge(key, compositeBeans, ReadDescriptors.readBeans(beansXml.getAsset().openStream()));
} catch (final OpenEJBException e) {
throw new IllegalArgumentException(e);
}
final List<String> mainClasses = new ArrayList<>();
for (final Class<?> clazz : classes) {
mainClasses.add(clazz.getName());
}
webAppClassesByUrl.put(key, mainClasses);
} catch (final MalformedURLException mue) {
// no-op
}
}
if (libs != null) {
archives.add(libs);
}
return new SimpleWebappAggregatedArchive(cl, new CompositeArchive(archives), webAppClassesByUrl);
}
use of org.apache.xbean.finder.archive.ClassesArchive 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.ClassesArchive in project tomee by apache.
the class DeploymentLoader method addWebModule.
public static EjbModule addWebModule(final WebModule webModule, final AppModule appModule) throws OpenEJBException {
// create and add the WebModule
appModule.getWebModules().add(webModule);
if (appModule.isStandaloneModule()) {
appModule.getAdditionalLibraries().addAll(webModule.getUrls());
}
{
final Object pXml = appModule.getAltDDs().get("persistence.xml");
List<URL> persistenceXmls = pXml == null ? null : (List.class.isInstance(pXml) ? (List<URL>) pXml : new ArrayList<>(Collections.singletonList(URL.class.cast(pXml))));
if (persistenceXmls == null) {
persistenceXmls = new ArrayList<>();
appModule.getAltDDs().put("persistence.xml", persistenceXmls);
}
final Object o = webModule.getAltDDs().get("persistence.xml");
if (o instanceof URL) {
final URL url = (URL) o;
persistenceXmls.add(url);
}
if (o instanceof List) {
final List<URL> urls = (List<URL>) o;
persistenceXmls.addAll(urls);
}
}
// Per the Spec version of the Collapsed EAR there
// aren't individual EjbModules inside a war.
// The war itself is one big EjbModule if certain
// conditions are met. These conditions are different
// than an ear file, so the ear-style code we were previously
// using doesn't exactly work anymore.
final EjbModule webEjbModule = new EjbModule(webModule.getClassLoader(), webModule.getModuleId(), webModule.getJarLocation(), null, null);
webEjbModule.setWebapp(true);
webEjbModule.getAltDDs().putAll(webModule.getAltDDs());
appModule.getEjbModules().add(webEjbModule);
try {
// TODO: Put our scanning ehnancements back, here
fillEjbJar(webModule, webEjbModule);
if (webModule.getFinder() == null) {
if (isMetadataComplete(webModule, webEjbModule)) {
final IAnnotationFinder finder = new org.apache.xbean.finder.AnnotationFinder(new ClassesArchive());
webModule.setFinder(finder);
webEjbModule.setFinder(finder);
} else {
final IAnnotationFinder finder = FinderFactory.createFinder(webModule);
webModule.setFinder(finder);
webEjbModule.setFinder(finder);
}
} else if (webEjbModule.getFinder() == null) {
webEjbModule.setFinder(webModule.getFinder());
}
} catch (final Exception e) {
throw new OpenEJBException("Unable to create annotation scanner for web module " + webModule.getModuleId(), e);
}
addWebservices(webEjbModule);
return webEjbModule;
}
use of org.apache.xbean.finder.archive.ClassesArchive in project tomee by apache.
the class CheckAnnotationTest method testWebServiceWithStateful.
@Keys({ @Key(value = "annotation.invalid.stateful.webservice", type = KeyType.WARNING) })
public AppModule testWebServiceWithStateful() {
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new StatefulBean(Green.class));
final EjbModule ejbModule = new EjbModule(ejbJar);
ejbModule.setFinder(new AnnotationFinder(new ClassesArchive(Green.class)).link());
final AppModule appModule = new AppModule(ejbModule);
return appModule;
}
Aggregations