Search in sources :

Example 1 with BeanDiscoveryMode

use of org.jboss.weld.bootstrap.spi.BeanDiscoveryMode in project Payara by payara.

the class BeanDeploymentArchiveImpl method populate.

private void populate(Collection<com.sun.enterprise.deployment.EjbDescriptor> ejbs, Application app) {
    try {
        boolean webinfbda = false;
        boolean hasBeansXml = false;
        String beansXMLURL = null;
        if (archive.exists(WEB_INF_BEANS_XML)) {
            beansXMLURL = WEB_INF_BEANS_XML;
        }
        if (beansXMLURL == null && archive.exists(WEB_INF_CLASSES_META_INF_BEANS_XML)) {
            beansXMLURL = WEB_INF_CLASSES_META_INF_BEANS_XML;
        }
        if (beansXMLURL != null) {
            // Parse the descriptor to determine if CDI is disabled
            BeansXml beansXML = parseBeansXML(archive, beansXMLURL);
            BeanDiscoveryMode bdMode = beansXML.getBeanDiscoveryMode();
            if (!bdMode.equals(BeanDiscoveryMode.NONE)) {
                webinfbda = true;
                // If the mode is explicitly set to "annotated", then pretend there is no beans.xml
                // to force the implicit behavior
                hasBeansXml = !bdMode.equals(BeanDiscoveryMode.ANNOTATED);
                if (logger.isLoggable(FINE)) {
                    logger.log(FINE, CDILoggerInfo.PROCESSING_BEANS_XML, new Object[] { archive.getURI(), WEB_INF_BEANS_XML, WEB_INF_CLASSES_META_INF_BEANS_XML });
                }
            } else {
                addBeansXMLURL(archive, beansXMLURL);
            }
        } else if (archive.exists(WEB_INF_CLASSES)) {
            // If WEB-INF/classes exists, check for CDI beans there
            // Check WEB-INF/classes for CDI-enabling annotations
            URI webinfclasses = new File(context.getSourceDir().getAbsolutePath(), WEB_INF_CLASSES).toURI();
            if (WeldUtils.isImplicitBeanArchive(context, webinfclasses)) {
                webinfbda = true;
                if (logger.isLoggable(FINE)) {
                    logger.log(FINE, CDILoggerInfo.PROCESSING_CDI_ENABLED_ARCHIVE, new Object[] { archive.getURI() });
                }
            }
        }
        if (webinfbda) {
            bdaType = BDAType.WAR;
            Enumeration<String> entries = archive.entries();
            while (entries.hasMoreElements()) {
                String entry = entries.nextElement();
                if (legalClassName(entry)) {
                    if (entry.contains(WEB_INF_CLASSES)) {
                        // Workaround for incorrect WARs that bundle classes above WEB-INF/classes
                        // [See. GLASSFISH-16706]
                        entry = entry.substring(WEB_INF_CLASSES.length() + 1);
                    }
                    String className = filenameToClassname(entry);
                    try {
                        if (hasBeansXml || isCDIAnnotatedClass(className)) {
                            beanClassNames.add(className);
                            beanClasses.add(getClassLoader().loadClass(className));
                        }
                        moduleClassNames.add(className);
                    } catch (Throwable t) {
                        if (logger.isLoggable(Level.WARNING)) {
                            logger.log(Level.WARNING, CDILoggerInfo.ERROR_LOADING_BEAN_CLASS, new Object[] { className, t.toString() });
                        }
                    }
                } else if (entry.endsWith(BEANS_XML_FILENAME)) {
                    addBeansXMLURL(archive, entry);
                }
            }
            archive.close();
        }
        if (archive.exists(WEB_INF_LIB)) {
            if (logger.isLoggable(FINE)) {
                logger.log(FINE, CDILoggerInfo.PROCESSING_WEB_INF_LIB, new Object[] { archive.getURI() });
            }
            bdaType = BDAType.WAR;
            Enumeration<String> entries = archive.entries(WEB_INF_LIB);
            List<ReadableArchive> weblibJarsThatAreBeanArchives = new ArrayList<ReadableArchive>();
            while (entries.hasMoreElements()) {
                String entry = (String) entries.nextElement();
                // if directly under WEB-INF/lib
                if (entry.endsWith(JAR_SUFFIX) && entry.indexOf(SEPARATOR_CHAR, WEB_INF_LIB.length() + 1) == -1 && (app == null || DOLUtils.isScanningAllowed(app, entry))) {
                    ReadableArchive weblibJarArchive = archive.getSubArchive(entry);
                    if (weblibJarArchive.exists(META_INF_BEANS_XML)) {
                        // Parse the descriptor to determine if CDI is disabled
                        BeansXml beansXML = parseBeansXML(weblibJarArchive, META_INF_BEANS_XML);
                        BeanDiscoveryMode bdMode = beansXML.getBeanDiscoveryMode();
                        if (!bdMode.equals(BeanDiscoveryMode.NONE)) {
                            if (logger.isLoggable(FINE)) {
                                logger.log(FINE, CDILoggerInfo.WEB_INF_LIB_CONSIDERING_BEAN_ARCHIVE, new Object[] { entry });
                            }
                            weblibJarsThatAreBeanArchives.add(weblibJarArchive);
                        }
                    } else {
                        // Check for classes annotated with qualified annotations
                        if (WeldUtils.isImplicitBeanArchive(context, weblibJarArchive)) {
                            if (logger.isLoggable(FINE)) {
                                logger.log(FINE, CDILoggerInfo.WEB_INF_LIB_CONSIDERING_BEAN_ARCHIVE, new Object[] { entry });
                            }
                            weblibJarsThatAreBeanArchives.add(weblibJarArchive);
                        } else {
                            if (logger.isLoggable(FINE)) {
                                logger.log(FINE, CDILoggerInfo.WEB_INF_LIB_SKIPPING_BEAN_ARCHIVE, new Object[] { archive.getName() });
                            }
                        }
                    }
                }
            }
            // process all web-inf lib JARs and create BDAs for them
            List<BeanDeploymentArchiveImpl> webLibBDAs = new ArrayList<BeanDeploymentArchiveImpl>();
            if (weblibJarsThatAreBeanArchives.size() > 0) {
                ListIterator<ReadableArchive> libJarIterator = weblibJarsThatAreBeanArchives.listIterator();
                while (libJarIterator.hasNext()) {
                    ReadableArchive libJarArchive = (ReadableArchive) libJarIterator.next();
                    BeanDeploymentArchiveImpl wlbda = new BeanDeploymentArchiveImpl(libJarArchive, ejbs, context, makeBdaId(friendlyId, bdaType, libJarArchive.getName()));
                    // add to list of BDAs for this WAR
                    this.beanDeploymentArchives.add(wlbda);
                    webLibBDAs.add(wlbda);
                }
            }
            ensureWebLibJarVisibility(webLibBDAs);
        } else if (archive.getName().endsWith(RAR_SUFFIX) || archive.getName().endsWith(EXPANDED_RAR_SUFFIX)) {
            // Handle RARs. RARs are packaged differently from EJB-JARs or WARs.
            // see 20.2 of Connectors 1.6 specification
            // The resource adapter classes are in a jar file within the
            // RAR archive
            bdaType = BDAType.RAR;
            collectRarInfo(archive);
        } else if (archive.exists(META_INF_BEANS_XML)) {
            // Parse the descriptor to determine if CDI is disabled
            BeansXml beansXML = parseBeansXML(archive, META_INF_BEANS_XML);
            BeanDiscoveryMode bdMode = beansXML.getBeanDiscoveryMode();
            if (!bdMode.equals(BeanDiscoveryMode.NONE)) {
                if (logger.isLoggable(FINE)) {
                    logger.log(FINE, CDILoggerInfo.PROCESSING_BDA_JAR, new Object[] { archive.getURI() });
                }
                bdaType = BDAType.JAR;
                collectJarInfo(archive, true, !bdMode.equals(BeanDiscoveryMode.ANNOTATED));
            } else {
                addBeansXMLURL(archive, META_INF_BEANS_XML);
            }
        } else if (WeldUtils.isImplicitBeanArchive(context, archive)) {
            if (logger.isLoggable(FINE)) {
                logger.log(FINE, CDILoggerInfo.PROCESSING_BECAUSE_SCOPE_ANNOTATION, new Object[] { archive.getURI() });
            }
            bdaType = BDAType.JAR;
            collectJarInfo(archive, true, false);
        }
    // This is causing tck failures, specifically
    // MultiModuleProcessingTest.testProcessedModulesCount
    // creating a bda for an extionsion that does not include a beans.xml is handled later
    // when annotated types are created by that extension.  This is done in
    // DeploymentImpl.loadBeanDeploymentArchive(Class<?> beanClass)
    // if (archive.exists(META_INF_SERVICES_EXTENSION)){
    // if ( logger.isLoggable( FINE ) ) {
    // logger.log(FINE, "-JAR processing: " + archive.getURI()
    // + " as an extensions jar since it has META-INF/services extension");
    // }
    // bdaType = BDAType.UNKNOWN;
    // collectJarInfo(archive, false);
    // }
    } catch (IOException e) {
        logger.log(SEVERE, e.getLocalizedMessage(), e);
    } catch (ClassNotFoundException cne) {
        logger.log(SEVERE, cne.getLocalizedMessage(), cne);
    }
}
Also used : ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) IOException(java.io.IOException) URI(java.net.URI) BeanDiscoveryMode(org.jboss.weld.bootstrap.spi.BeanDiscoveryMode) BeansXml(org.jboss.weld.bootstrap.spi.BeansXml) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) JarFile(java.util.jar.JarFile) File(java.io.File)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 JarFile (java.util.jar.JarFile)1 ReadableArchive (org.glassfish.api.deployment.archive.ReadableArchive)1 BeanDiscoveryMode (org.jboss.weld.bootstrap.spi.BeanDiscoveryMode)1 BeansXml (org.jboss.weld.bootstrap.spi.BeansXml)1