Search in sources :

Example 1 with EmptyResourcesClassLoader

use of org.apache.openejb.core.EmptyResourcesClassLoader 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);
    }
}
Also used : ClasspathArchive(org.apache.xbean.finder.archive.ClasspathArchive) ClassesArchive(org.apache.xbean.finder.archive.ClassesArchive) FilteredArchive(org.apache.xbean.finder.archive.FilteredArchive) CompositeArchive(org.apache.xbean.finder.archive.CompositeArchive) Archive(org.apache.xbean.finder.archive.Archive) CompositeArchive(org.apache.xbean.finder.archive.CompositeArchive) URLClassLoader(java.net.URLClassLoader) EmptyResourcesClassLoader(org.apache.openejb.core.EmptyResourcesClassLoader) ClassesArchive(org.apache.xbean.finder.archive.ClassesArchive) EmptyResourcesClassLoader(org.apache.openejb.core.EmptyResourcesClassLoader) URLClassLoader(java.net.URLClassLoader) IOException(java.io.IOException) URL(java.net.URL)

Example 2 with EmptyResourcesClassLoader

use of org.apache.openejb.core.EmptyResourcesClassLoader in project tomee by apache.

the class DeploymentLoader method addBeansXmls.

public static void addBeansXmls(final WebModule webModule) {
    final List<URL> urls = webModule.getScannableUrls();
    // parent returns nothing when calling getresources because we don't want here to be fooled by maven classloader
    final URLClassLoader loader = new URLClassLoader(urls.toArray(new URL[urls.size()]), new EmptyResourcesClassLoader());
    final List<URL> xmls = new LinkedList<>();
    try {
        final URL e = (URL) webModule.getAltDDs().get("beans.xml");
        if (e != null) {
            // first!
            xmls.add(e);
        }
        xmls.addAll(Collections.list(loader.getResources("META-INF/beans.xml")));
    } catch (final IOException e) {
        return;
    }
    final CompositeBeans complete = new CompositeBeans();
    for (final URL url : xmls) {
        if (url == null) {
            continue;
        }
        mergeBeansXml(complete, url);
    }
    if (!complete.getDiscoveryByUrl().isEmpty()) {
        complete.removeDuplicates();
    }
    webModule.getAltDDs().put("beans.xml", complete);
}
Also used : CompositeBeans(org.apache.openejb.cdi.CompositeBeans) URLClassLoader(java.net.URLClassLoader) EmptyResourcesClassLoader(org.apache.openejb.core.EmptyResourcesClassLoader) IOException(java.io.IOException) URL(java.net.URL) LinkedList(java.util.LinkedList)

Aggregations

IOException (java.io.IOException)2 URL (java.net.URL)2 URLClassLoader (java.net.URLClassLoader)2 EmptyResourcesClassLoader (org.apache.openejb.core.EmptyResourcesClassLoader)2 LinkedList (java.util.LinkedList)1 CompositeBeans (org.apache.openejb.cdi.CompositeBeans)1 Archive (org.apache.xbean.finder.archive.Archive)1 ClassesArchive (org.apache.xbean.finder.archive.ClassesArchive)1 ClasspathArchive (org.apache.xbean.finder.archive.ClasspathArchive)1 CompositeArchive (org.apache.xbean.finder.archive.CompositeArchive)1 FilteredArchive (org.apache.xbean.finder.archive.FilteredArchive)1