Search in sources :

Example 1 with ImplicitBeanArchiveDetector

use of org.jboss.as.weld.spi.ImplicitBeanArchiveDetector in project wildfly by wildfly.

the class WeldImplicitDeploymentProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (WeldDeploymentMarker.isWeldDeployment(deploymentUnit)) {
        return;
    }
    if (Utils.getRootDeploymentUnit(deploymentUnit).getAttachment(WeldConfiguration.ATTACHMENT_KEY).isRequireBeanDescriptor()) {
        // if running in the require-bean-descriptor mode then bean archives are found by BeansXmlProcessor
        return;
    }
    /*
         * look for classes with bean defining annotations
         */
    final Set<AnnotationType> beanDefiningAnnotations = new HashSet<>(getRootDeploymentUnit(deploymentUnit).getAttachment(WeldAttachments.BEAN_DEFINING_ANNOTATIONS));
    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
         */
    final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
    final Iterable<ImplicitBeanArchiveDetector> detectors = ServiceLoader.load(ImplicitBeanArchiveDetector.class, WildFlySecurityManager.getClassLoaderPrivileged(WeldImplicitDeploymentProcessor.class));
    for (ComponentDescription component : eeModuleDescription.getComponentDescriptions()) {
        for (ImplicitBeanArchiveDetector detector : detectors) {
            if (detector.isImplicitBeanArchiveRequired(component)) {
                WeldDeploymentMarker.mark(deploymentUnit);
                return;
            }
        }
    }
}
Also used : ComponentDescription(org.jboss.as.ee.component.ComponentDescription) Index(org.jboss.jandex.Index) AnnotationType(org.jboss.as.weld.discovery.AnnotationType) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) ImplicitBeanArchiveDetector(org.jboss.as.weld.spi.ImplicitBeanArchiveDetector) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) Utils.getRootDeploymentUnit(org.jboss.as.weld.util.Utils.getRootDeploymentUnit) ExplicitBeanArchiveMetadataContainer(org.jboss.as.weld.deployment.ExplicitBeanArchiveMetadataContainer) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)1 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)1 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)1 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)1 ResourceRoot (org.jboss.as.server.deployment.module.ResourceRoot)1 ExplicitBeanArchiveMetadataContainer (org.jboss.as.weld.deployment.ExplicitBeanArchiveMetadataContainer)1 AnnotationType (org.jboss.as.weld.discovery.AnnotationType)1 ImplicitBeanArchiveDetector (org.jboss.as.weld.spi.ImplicitBeanArchiveDetector)1 Utils.getRootDeploymentUnit (org.jboss.as.weld.util.Utils.getRootDeploymentUnit)1 Index (org.jboss.jandex.Index)1