Skip to content

Commit

Permalink
WFLY-4388 Weld starts for deployments with bean-discovery-mode="none"
Browse files Browse the repository at this point in the history
  • Loading branch information
jharting committed Mar 5, 2015
1 parent ac18593 commit 781041e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
Expand Up @@ -23,8 +23,10 @@

import java.net.MalformedURLException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.jboss.as.ee.structure.DeploymentType;
import org.jboss.as.ee.structure.DeploymentTypeMarker;
Expand All @@ -37,12 +39,13 @@
import org.jboss.as.server.deployment.SubDeploymentMarker;
import org.jboss.as.server.deployment.module.ModuleRootMarker;
import org.jboss.as.server.deployment.module.ResourceRoot;
import org.jboss.as.weld.logging.WeldLogger;
import org.jboss.as.weld.deployment.ExplicitBeanArchiveMetadata;
import org.jboss.as.weld.deployment.ExplicitBeanArchiveMetadataContainer;
import org.jboss.as.weld.deployment.PropertyReplacingBeansXmlParser;
import org.jboss.as.weld.deployment.WeldAttachments;
import org.jboss.as.weld.logging.WeldLogger;
import org.jboss.vfs.VirtualFile;
import org.jboss.weld.bootstrap.spi.BeanDiscoveryMode;
import org.jboss.weld.bootstrap.spi.BeansXml;

/**
Expand Down Expand Up @@ -120,8 +123,14 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro
if (!beanArchiveMetadata.isEmpty()) {
ExplicitBeanArchiveMetadataContainer deploymentMetadata = new ExplicitBeanArchiveMetadataContainer(beanArchiveMetadata);
deploymentUnit.putAttachment(ExplicitBeanArchiveMetadataContainer.ATTACHMENT_KEY, deploymentMetadata);
// mark the deployment as requiring CDI integration
WeldDeploymentMarker.mark(deploymentUnit);

for (Iterator<Entry<ResourceRoot, ExplicitBeanArchiveMetadata>> iterator = beanArchiveMetadata.entrySet().iterator(); iterator.hasNext(); ) {
if (BeanDiscoveryMode.NONE != iterator.next().getValue().getBeansXml().getBeanDiscoveryMode()) {
// mark the deployment as requiring CDI integration as long as it contains at least one bean archive with bean-discovery-mode other than "none"
WeldDeploymentMarker.mark(deploymentUnit);
break;
}
}
}
}

Expand Down
Expand Up @@ -3,6 +3,8 @@
import static org.jboss.as.weld.util.Utils.getRootDeploymentUnit;

import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import org.jboss.as.ee.component.ComponentDescription;
Expand All @@ -15,10 +17,13 @@
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.as.server.deployment.annotation.CompositeIndex;
import org.jboss.as.server.deployment.annotation.AnnotationIndexUtils;
import org.jboss.as.server.deployment.module.ResourceRoot;
import org.jboss.as.weld.deployment.ExplicitBeanArchiveMetadataContainer;
import org.jboss.as.weld.deployment.WeldAttachments;
import org.jboss.as.weld.discovery.AnnotationType;
import org.jboss.as.weld.util.Utils;
import org.jboss.jandex.Index;

/**
* Deployment processor that finds implicit bean archives (as defined by the CDI spec). If the deployment unit contains any such
Expand All @@ -44,16 +49,35 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro
/*
* look for classes with bean defining annotations
*/
final CompositeIndex index = deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
final Set<AnnotationType> beanDefiningAnnotations = new HashSet<>(getRootDeploymentUnit(deploymentUnit).getAttachment(WeldAttachments.BEAN_DEFINING_ANNOTATIONS));

for (final AnnotationType annotation : beanDefiningAnnotations) {
if (!index.getAnnotations(annotation.getName()).isEmpty()) {
WeldDeploymentMarker.mark(deploymentUnit);
return;
final Map<ResourceRoot, Index> indexes = AnnotationIndexUtils.getAnnotationIndexes(deploymentUnit);
final ExplicitBeanArchiveMetadataContainer explicitBeanArchiveMetadata = deploymentUnit.getAttachment(ExplicitBeanArchiveMetadataContainer.ATTACHMENT_KEY);
final ResourceRoot classesRoot = deploymentUnit.getAttachment(WeldAttachments.CLASSES_RESOURCE_ROOT);
final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);

for (Entry<ResourceRoot, Index> entry : indexes.entrySet()) {
ResourceRoot resourceRoot = entry.getKey();
if (resourceRoot == classesRoot) {
// BDA for WEB-INF/classes is keyed under deploymentRoot in explicitBeanArchiveMetadata
resourceRoot = deploymentRoot;
}
/*
* Make sure bean defining annotations used in archives with bean-discovery-mode="none" are not considered here
* WFLY-4388
*/
if (explicitBeanArchiveMetadata != null && explicitBeanArchiveMetadata.getBeanArchiveMetadata().containsKey(resourceRoot)) {
continue;
}
for (final AnnotationType annotation : beanDefiningAnnotations) {
if (!entry.getValue().getAnnotations(annotation.getName()).isEmpty()) {
WeldDeploymentMarker.mark(deploymentUnit);
return;
}
}
}


/*
* look for session beans and managed beans
*/
Expand Down

0 comments on commit 781041e

Please sign in to comment.