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);
}
}
}
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);
}
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());
}
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"));
}
}
}
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()));
}
}
}
Aggregations