Search in sources :

Example 1 with BeanDeploymentArchive

use of org.jboss.weld.bootstrap.spi.BeanDeploymentArchive in project wildfly-camel by wildfly-extras.

the class CDIBeanArchiveProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    DeploymentUnit depUnit = phaseContext.getDeploymentUnit();
    CamelDeploymentSettings depSettings = depUnit.getAttachment(CamelDeploymentSettings.ATTACHMENT_KEY);
    List<DeploymentUnit> subDeployments = depUnit.getAttachmentList(Attachments.SUB_DEPLOYMENTS);
    // Return if camel disabled or not a CDI deployment
    if (!depSettings.isEnabled() || !WeldDeploymentMarker.isPartOfWeldDeployment(depUnit)) {
        return;
    }
    // Return if we're not an EAR deployment with 1 or more sub-deployments
    if (depUnit.getName().endsWith(".ear") && subDeployments.isEmpty()) {
        return;
    }
    // Make sure external bean archives from the camel-cdi module are visible to sub deployments
    List<BeanDeploymentArchiveImpl> deploymentArchives = depUnit.getAttachmentList(WeldAttachments.ADDITIONAL_BEAN_DEPLOYMENT_MODULES);
    BeanDeploymentArchiveImpl rootArchive = depUnit.getAttachment(WeldAttachments.DEPLOYMENT_ROOT_BEAN_DEPLOYMENT_ARCHIVE);
    for (BeanDeploymentArchiveImpl bda : deploymentArchives) {
        if (bda.getBeanArchiveType().equals(BeanDeploymentArchiveImpl.BeanArchiveType.EXTERNAL)) {
            for (BeanDeploymentArchive topLevelBda : rootArchive.getBeanDeploymentArchives()) {
                bda.addBeanDeploymentArchive(topLevelBda);
            }
        }
        for (DeploymentUnit subDepUnit : subDeployments) {
            BeanDeploymentArchive subBda = subDepUnit.getAttachment(WeldAttachments.DEPLOYMENT_ROOT_BEAN_DEPLOYMENT_ARCHIVE);
            bda.addBeanDeploymentArchive(subBda);
        }
    }
}
Also used : CamelDeploymentSettings(org.wildfly.extension.camel.deployment.CamelDeploymentSettings) BeanDeploymentArchiveImpl(org.jboss.as.weld.deployment.BeanDeploymentArchiveImpl) BeanDeploymentArchive(org.jboss.weld.bootstrap.spi.BeanDeploymentArchive) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 2 with BeanDeploymentArchive

use of org.jboss.weld.bootstrap.spi.BeanDeploymentArchive in project core by weld.

the class WeldBeanDeploymentArchive method merge.

/**
 * @param bootstrap
 * @param archives
 * @return the "flat" bean deployment archive
 */
public static <T extends BeanDeploymentArchive> WeldBeanDeploymentArchive merge(CDI11Bootstrap bootstrap, Iterable<T> archives) {
    BeansXml mergedBeansXml = BeansXmlParser.mergeExisting(archives, true);
    Set<String> beanClasses = new HashSet<String>();
    for (BeanDeploymentArchive archive : archives) {
        beanClasses.addAll(archive.getBeanClasses());
    }
    return new WeldBeanDeploymentArchive(ManagerObjectFactory.FLAT_BEAN_DEPLOYMENT_ID, beanClasses, mergedBeansXml);
}
Also used : BeansXml(org.jboss.weld.bootstrap.spi.BeansXml) BeanDeploymentArchive(org.jboss.weld.bootstrap.spi.BeanDeploymentArchive) HashSet(java.util.HashSet)

Example 3 with BeanDeploymentArchive

use of org.jboss.weld.bootstrap.spi.BeanDeploymentArchive in project core by weld.

the class Probe method init.

/**
 * @param beanManager
 */
void init(BeanManagerImpl beanManager) {
    ContextualStore contextualStore = beanManager.getServices().get(ContextualStore.class);
    bdaToManager.putAll(Container.instance(beanManager).beanDeploymentArchives());
    for (Entry<BeanDeploymentArchive, BeanManagerImpl> entry : bdaToManager.entrySet()) {
        ProbeLogger.LOG.processingBeanDeploymentArchive(entry.getKey().getId());
        BeanManagerImpl manager = entry.getValue();
        // Beans
        for (Bean<?> bean : manager.getBeans()) {
            // there's only one Instance bean though
            if (bean instanceof ExtensionBean) {
                // ExtensionBean does not include BeanManager in its BeanIdentifier
                ExtensionBean<?> extensionBean = (ExtensionBean<?>) bean;
                if (!idToBean.containsValue(extensionBean)) {
                    putBean(Components.getId(extensionBean.getIdentifier()), manager, extensionBean);
                }
            } else if (bean instanceof AbstractBuiltInBean<?>) {
                // Built-in beans are identified by the set of types
                String id = Components.getBuiltinBeanId((AbstractBuiltInBean<?>) bean);
                if (!idToBean.containsKey(id)) {
                    putBean(id, bean);
                }
            } else {
                if (manager.isBeanEnabled(bean)) {
                    // Make sure the bean is truly enabled
                    putBean(contextualStore, manager, bean);
                }
            }
        }
        // Interceptors
        for (Interceptor<?> interceptor : manager.getInterceptors()) {
            putBean(contextualStore, manager, interceptor);
        }
        // Decorators
        for (Decorator<?> decorator : manager.getDecorators()) {
            putBean(contextualStore, manager, decorator);
        }
        // Observers
        int customObservers = 0;
        for (ObserverMethod<?> observerMethod : manager.getObservers()) {
            if (observerMethod instanceof ObserverMethodImpl) {
                ObserverMethodImpl<?, ?> observerMethodImpl = (ObserverMethodImpl<?, ?>) observerMethod;
                putObserver(Components.getId(observerMethodImpl.getId()), observerMethodImpl);
            } else {
                // Custom observer methods
                putObserver(Components.getId("" + customObservers++), observerMethod);
            }
        }
    }
    // Find declared producers
    for (Bean<?> candidate : idToBean.values()) {
        BeanKind kind = BeanKind.from(candidate);
        if ((BeanKind.PRODUCER_FIELD.equals(kind) || BeanKind.PRODUCER_METHOD.equals(kind) || BeanKind.RESOURCE.equals(kind)) && candidate instanceof AbstractProducerBean) {
            AbstractProducerBean<?, ?, ?> producerBean = (AbstractProducerBean<?, ?, ?>) candidate;
            beanToDeclaredProducers.put(producerBean.getDeclaringBean(), producerBean);
        }
    }
    findUnusedBeans();
    initTs.set(System.currentTimeMillis());
}
Also used : AbstractBuiltInBean(org.jboss.weld.bean.builtin.AbstractBuiltInBean) ExtensionBean(org.jboss.weld.bean.builtin.ExtensionBean) AbstractProducerBean(org.jboss.weld.bean.AbstractProducerBean) InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) BeanManagerImpl(org.jboss.weld.manager.BeanManagerImpl) ContextualStore(org.jboss.weld.serialization.spi.ContextualStore) ObserverMethodImpl(org.jboss.weld.event.ObserverMethodImpl) BeanDeploymentArchive(org.jboss.weld.bootstrap.spi.BeanDeploymentArchive) BeanKind(org.jboss.weld.probe.Components.BeanKind)

Example 4 with BeanDeploymentArchive

use of org.jboss.weld.bootstrap.spi.BeanDeploymentArchive in project core by weld.

the class Reports method addBeanArchives.

private static void addBeanArchives(HtmlTag body, List<BeanDeploymentArchive> bdas) {
    body.add(HtmlTag.aname(BDAS));
    body.add(HtmlTag.h2(TITLE_BDAS));
    HtmlTag table = HtmlTag.stripedTable().appendTo(HtmlTag.div(BDAS).appendTo(body));
    HtmlTag.tr().add(HtmlTag.th(""), HtmlTag.th("Identifier"), HtmlTag.th("Bean Discovery Mode"), HtmlTag.th("beans.xml")).appendTo(table);
    int idx = 0;
    for (BeanDeploymentArchive bda : bdas) {
        HtmlTag tr = HtmlTag.tr().add(HtmlTag.td(++idx + "."), HtmlTag.td(bda.getId())).appendTo(table);
        BeansXml beansXml = bda.getBeansXml();
        tr.add(HtmlTag.td(beansXml != null ? beansXml.getBeanDiscoveryMode().toString() : BeanDiscoveryMode.ANNOTATED.toString()));
        if (beansXml != null && !beansXml.equals(BeansXml.EMPTY_BEANS_XML)) {
            HtmlTag.div().attr(HtmlTag.TITLE, beansXml.getUrl() != null ? beansXml.getUrl().toString() : "URL not available").add(beansXml.getVersion() != null ? beansXml.getVersion() : "Version not defined").appendTo(HtmlTag.td().appendTo(tr));
        } else {
            tr.add(HtmlTag.td("No beans.xml"));
        }
    }
}
Also used : BeansXml(org.jboss.weld.bootstrap.spi.BeansXml) BeanDeploymentArchive(org.jboss.weld.bootstrap.spi.BeanDeploymentArchive) InjectionPoint(javax.enterprise.inject.spi.InjectionPoint)

Example 5 with BeanDeploymentArchive

use of org.jboss.weld.bootstrap.spi.BeanDeploymentArchive in project core by weld.

the class BeanDiscoveryInjectionTest method testAnnotatedBeanDiscovery.

@Test
public void testAnnotatedBeanDiscovery(BeanManagerImpl manager) {
    assertEquals(1, manager.getBeans(Tree.class).size());
    assertEquals(1, manager.getBeans(Plant.class).size());
    assertEquals(0, manager.getBeans(Stone.class).size());
    for (BeanDeploymentArchive beanDeploymentArchive : Container.instance(manager).beanDeploymentArchives().keySet()) {
        if (beanDeploymentArchive.getBeanClasses().contains(Plant.class.getName())) {
            assertFalse(beanDeploymentArchive.getBeanClasses().contains(Stone.class.getName()));
            assertTrue(beanDeploymentArchive.getKnownClasses().contains(Stone.class.getName()));
        }
    }
}
Also used : BeanDeploymentArchive(org.jboss.weld.bootstrap.spi.BeanDeploymentArchive) Test(org.junit.Test)

Aggregations

BeanDeploymentArchive (org.jboss.weld.bootstrap.spi.BeanDeploymentArchive)47 WeldBootstrap (org.jboss.weld.bootstrap.WeldBootstrap)11 BundleDescriptor (com.sun.enterprise.deployment.BundleDescriptor)7 HashSet (java.util.HashSet)7 Deployment (org.jboss.weld.bootstrap.spi.Deployment)7 BeanDeploymentArchiveImpl (org.jboss.arquillian.container.weld.embedded.mock.BeanDeploymentArchiveImpl)6 FlatDeployment (org.jboss.arquillian.container.weld.embedded.mock.FlatDeployment)6 TestContainer (org.jboss.arquillian.container.weld.embedded.mock.TestContainer)6 BeansXml (org.jboss.weld.bootstrap.spi.BeansXml)6 BeanManagerImpl (org.jboss.weld.manager.BeanManagerImpl)6 Test (org.testng.annotations.Test)6 BeanManager (javax.enterprise.inject.spi.BeanManager)5 EjbDescriptor (com.sun.enterprise.deployment.EjbDescriptor)4 WeldBeanDeploymentArchive (org.jboss.weld.environment.deployment.WeldBeanDeploymentArchive)4 Test (org.junit.Test)4 WebBundleDescriptor (com.sun.enterprise.deployment.WebBundleDescriptor)3 ComponentInvocation (org.glassfish.api.invocation.ComponentInvocation)3 Metadata (org.jboss.weld.bootstrap.spi.Metadata)3 JndiNameEnvironment (com.sun.enterprise.deployment.JndiNameEnvironment)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2