Search in sources :

Example 1 with BeanDeploymentArchiveImpl

use of org.jboss.as.weld.deployment.BeanDeploymentArchiveImpl 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 BeanDeploymentArchiveImpl

use of org.jboss.as.weld.deployment.BeanDeploymentArchiveImpl in project wildfly by wildfly.

the class WeldDeploymentProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final DeploymentUnit parent = Utils.getRootDeploymentUnit(deploymentUnit);
    final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
    final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
    if (!WeldDeploymentMarker.isPartOfWeldDeployment(deploymentUnit)) {
        // if there are CDI annotation present and this is the top level deployment we log a warning
        if (deploymentUnit.getParent() == null && CdiAnnotationMarker.cdiAnnotationsPresent(deploymentUnit)) {
            WeldLogger.DEPLOYMENT_LOGGER.cdiAnnotationsButNotBeanArchive(deploymentUnit.getName());
        }
        return;
    }
    // add a dependency on the weld service to web deployments
    final ServiceName weldBootstrapServiceName = parent.getServiceName().append(WeldBootstrapService.SERVICE_NAME);
    final ServiceName weldBootstrapServiceInternalName = parent.getServiceName().append(WeldBootstrapService.INTERNAL_SERVICE_NAME);
    ServiceName weldStartServiceName = parent.getServiceName().append(WeldStartService.SERVICE_NAME);
    deploymentUnit.addToAttachmentList(Attachments.WEB_DEPENDENCIES, weldStartServiceName);
    final Set<ServiceName> dependencies = new HashSet<ServiceName>();
    // we only start weld on top level deployments
    if (deploymentUnit.getParent() != null) {
        return;
    }
    WeldLogger.DEPLOYMENT_LOGGER.startingServicesForCDIDeployment(phaseContext.getDeploymentUnit().getName());
    final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
    final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
    final Set<BeanDeploymentArchiveImpl> beanDeploymentArchives = new HashSet<BeanDeploymentArchiveImpl>();
    final Map<ModuleIdentifier, BeanDeploymentModule> bdmsByIdentifier = new HashMap<ModuleIdentifier, BeanDeploymentModule>();
    final Map<ModuleIdentifier, ModuleSpecification> moduleSpecByIdentifier = new HashMap<ModuleIdentifier, ModuleSpecification>();
    final Map<ModuleIdentifier, EEModuleDescriptor> eeModuleDescriptors = new HashMap<>();
    // the root module only has access to itself. For most deployments this will be the only module
    // for ear deployments this represents the ear/lib directory.
    // war and jar deployment visibility will depend on the dependencies that
    // exist in the application, and mirror inter module dependencies
    final BeanDeploymentModule rootBeanDeploymentModule = deploymentUnit.getAttachment(WeldAttachments.BEAN_DEPLOYMENT_MODULE);
    putIfValueNotNull(eeModuleDescriptors, module.getIdentifier(), rootBeanDeploymentModule.getModuleDescriptor());
    bdmsByIdentifier.put(module.getIdentifier(), rootBeanDeploymentModule);
    moduleSpecByIdentifier.put(module.getIdentifier(), moduleSpecification);
    beanDeploymentArchives.addAll(rootBeanDeploymentModule.getBeanDeploymentArchives());
    final List<DeploymentUnit> subDeployments = deploymentUnit.getAttachmentList(Attachments.SUB_DEPLOYMENTS);
    final Set<ClassLoader> subDeploymentLoaders = new HashSet<ClassLoader>();
    final ServiceLoader<DeploymentUnitDependenciesProvider> dependenciesProviders = ServiceLoader.load(DeploymentUnitDependenciesProvider.class, WildFlySecurityManager.getClassLoaderPrivileged(WeldDeploymentProcessor.class));
    final ServiceLoader<ModuleServicesProvider> moduleServicesProviders = ServiceLoader.load(ModuleServicesProvider.class, WildFlySecurityManager.getClassLoaderPrivileged(WeldDeploymentProcessor.class));
    getDependencies(deploymentUnit, dependencies, dependenciesProviders);
    for (DeploymentUnit subDeployment : subDeployments) {
        getDependencies(subDeployment, dependencies, dependenciesProviders);
        final Module subDeploymentModule = subDeployment.getAttachment(Attachments.MODULE);
        if (subDeploymentModule == null) {
            continue;
        }
        subDeploymentLoaders.add(subDeploymentModule.getClassLoader());
        final ModuleSpecification subDeploymentModuleSpec = subDeployment.getAttachment(Attachments.MODULE_SPECIFICATION);
        final BeanDeploymentModule bdm = subDeployment.getAttachment(WeldAttachments.BEAN_DEPLOYMENT_MODULE);
        if (bdm == null) {
            continue;
        }
        // add the modules bdas to the global set of bdas
        beanDeploymentArchives.addAll(bdm.getBeanDeploymentArchives());
        bdmsByIdentifier.put(subDeploymentModule.getIdentifier(), bdm);
        moduleSpecByIdentifier.put(subDeploymentModule.getIdentifier(), subDeploymentModuleSpec);
        putIfValueNotNull(eeModuleDescriptors, subDeploymentModule.getIdentifier(), bdm.getModuleDescriptor());
        // we have to do this here as the aggregate components are not available in earlier phases
        final ResourceRoot subDeploymentRoot = subDeployment.getAttachment(Attachments.DEPLOYMENT_ROOT);
        // Add module services to bean deployment module
        for (Entry<Class<? extends Service>, Service> entry : ServiceLoaders.loadModuleServices(moduleServicesProviders, deploymentUnit, subDeployment, subDeploymentModule, subDeploymentRoot).entrySet()) {
            bdm.addService(entry.getKey(), Reflections.cast(entry.getValue()));
        }
    }
    for (Map.Entry<ModuleIdentifier, BeanDeploymentModule> entry : bdmsByIdentifier.entrySet()) {
        final ModuleSpecification bdmSpec = moduleSpecByIdentifier.get(entry.getKey());
        final BeanDeploymentModule bdm = entry.getValue();
        if (bdm == rootBeanDeploymentModule) {
            // the root module only has access to itself
            continue;
        }
        for (ModuleDependency dependency : bdmSpec.getSystemDependencies()) {
            BeanDeploymentModule other = bdmsByIdentifier.get(dependency.getIdentifier());
            if (other != null && other != bdm) {
                bdm.addBeanDeploymentModule(other);
            }
        }
    }
    Map<Class<? extends Service>, Service> rootModuleServices = ServiceLoaders.loadModuleServices(moduleServicesProviders, deploymentUnit, deploymentUnit, module, deploymentRoot);
    // Add root module services to root bean deployment module
    for (Entry<Class<? extends Service>, Service> entry : rootModuleServices.entrySet()) {
        rootBeanDeploymentModule.addService(entry.getKey(), Reflections.cast(entry.getValue()));
    }
    // Add root module services to additional bean deployment archives
    for (final BeanDeploymentArchiveImpl additional : deploymentUnit.getAttachmentList(WeldAttachments.ADDITIONAL_BEAN_DEPLOYMENT_MODULES)) {
        beanDeploymentArchives.add(additional);
        for (Entry<Class<? extends Service>, Service> entry : rootModuleServices.entrySet()) {
            additional.getServices().add(entry.getKey(), Reflections.cast(entry.getValue()));
        }
    }
    final Collection<Metadata<Extension>> extensions = WeldPortableExtensions.getPortableExtensions(deploymentUnit).getExtensions();
    final WeldDeployment deployment = new WeldDeployment(beanDeploymentArchives, extensions, module, subDeploymentLoaders, deploymentUnit, rootBeanDeploymentModule, eeModuleDescriptors);
    installBootstrapConfigurationService(deployment, parent);
    // add the weld service
    final ServiceBuilder<?> weldBootstrapServiceBuilder = serviceTarget.addService(weldBootstrapServiceInternalName);
    final Consumer<WeldBootstrapService> weldBootstrapServiceConsumer = weldBootstrapServiceBuilder.provides(weldBootstrapServiceInternalName);
    weldBootstrapServiceBuilder.requires(TCCLSingletonService.SERVICE_NAME);
    final Supplier<ExecutorServices> executorServicesSupplier = weldBootstrapServiceBuilder.requires(WeldExecutorServices.SERVICE_NAME);
    final Supplier<ExecutorService> serverExecutorSupplier = weldBootstrapServiceBuilder.requires(Services.JBOSS_SERVER_EXECUTOR);
    Supplier<SecurityServices> securityServicesSupplier = null;
    Supplier<TransactionServices> weldTransactionServicesSupplier = null;
    // Install additional services
    final ServiceLoader<BootstrapDependencyInstaller> installers = ServiceLoader.load(BootstrapDependencyInstaller.class, WildFlySecurityManager.getClassLoaderPrivileged(WeldDeploymentProcessor.class));
    for (BootstrapDependencyInstaller installer : installers) {
        ServiceName serviceName = installer.install(serviceTarget, deploymentUnit, jtsEnabled);
        // Add dependency for recognized services
        if (ServiceNames.WELD_SECURITY_SERVICES_SERVICE_NAME.getSimpleName().equals(serviceName.getSimpleName())) {
            securityServicesSupplier = weldBootstrapServiceBuilder.requires(serviceName);
        } else if (ServiceNames.WELD_TRANSACTION_SERVICES_SERVICE_NAME.getSimpleName().equals(serviceName.getSimpleName())) {
            weldTransactionServicesSupplier = weldBootstrapServiceBuilder.requires(serviceName);
        }
    }
    ServiceName deploymentServiceName = Utils.getRootDeploymentUnit(deploymentUnit).getServiceName();
    final WeldBootstrapService weldBootstrapService = new WeldBootstrapService(deployment, WildFlyWeldEnvironment.INSTANCE, deploymentUnit.getName(), weldBootstrapServiceConsumer, executorServicesSupplier, serverExecutorSupplier, securityServicesSupplier, weldTransactionServicesSupplier, deploymentServiceName, weldBootstrapServiceName);
    // Add root module services to WeldDeployment
    for (Entry<Class<? extends Service>, Service> entry : rootModuleServices.entrySet()) {
        weldBootstrapService.addWeldService(entry.getKey(), Reflections.cast(entry.getValue()));
    }
    weldBootstrapServiceBuilder.setInstance(weldBootstrapService);
    weldBootstrapServiceBuilder.install();
    final List<SetupAction> setupActions = getSetupActions(deploymentUnit);
    ServiceBuilder<?> startService = serviceTarget.addService(weldStartServiceName);
    for (final ServiceName dependency : dependencies) {
        startService.requires(dependency);
    }
    // make sure JNDI bindings are up
    startService.requires(JndiNamingDependencyProcessor.serviceName(deploymentUnit));
    final CapabilityServiceSupport capabilities = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);
    boolean tx = capabilities.hasCapability("org.wildfly.transactions");
    // [WFLY-5232]
    for (final ServiceName jndiSubsystemDependency : getJNDISubsytemDependencies(tx)) {
        startService.requires(jndiSubsystemDependency);
    }
    final EarMetaData earConfig = deploymentUnit.getAttachment(org.jboss.as.ee.structure.Attachments.EAR_METADATA);
    if (earConfig == null || !earConfig.getInitializeInOrder()) {
        // in-order install of sub-deployments may result in service dependencies deadlocks if the jndi dependency services of subdeployments are added as dependencies
        for (DeploymentUnit sub : subDeployments) {
            startService.requires(JndiNamingDependencyProcessor.serviceName(sub));
        }
    }
    final Supplier<WeldBootstrapService> bootstrapSupplier = startService.requires(weldBootstrapServiceName);
    startService.setInstance(new WeldStartService(bootstrapSupplier, setupActions, module.getClassLoader(), deploymentServiceName));
    startService.install();
}
Also used : ModuleDependency(org.jboss.as.server.deployment.module.ModuleDependency) HashMap(java.util.HashMap) WeldDeployment(org.jboss.as.weld.deployment.WeldDeployment) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport) WeldStartService(org.jboss.as.weld.WeldStartService) WeldBootstrapService(org.jboss.as.weld.WeldBootstrapService) HashSet(java.util.HashSet) ModuleServicesProvider(org.jboss.as.weld.spi.ModuleServicesProvider) ServiceTarget(org.jboss.msc.service.ServiceTarget) SetupAction(org.jboss.as.server.deployment.SetupAction) ConcurrentContextSetupAction(org.jboss.as.ee.concurrent.ConcurrentContextSetupAction) ServiceName(org.jboss.msc.service.ServiceName) Module(org.jboss.modules.Module) BeanDeploymentModule(org.jboss.as.weld.deployment.BeanDeploymentModule) Map(java.util.Map) HashMap(java.util.HashMap) EEModuleDescriptor(org.jboss.weld.bootstrap.spi.EEModuleDescriptor) SecurityServices(org.jboss.weld.security.spi.SecurityServices) Metadata(org.jboss.weld.bootstrap.spi.Metadata) DeploymentUnitDependenciesProvider(org.jboss.as.weld.spi.DeploymentUnitDependenciesProvider) EarMetaData(org.jboss.metadata.ear.spec.EarMetaData) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) BootstrapDependencyInstaller(org.jboss.as.weld.spi.BootstrapDependencyInstaller) ModuleIdentifier(org.jboss.modules.ModuleIdentifier) BeanDeploymentArchiveImpl(org.jboss.as.weld.deployment.BeanDeploymentArchiveImpl) TCCLSingletonService(org.jboss.as.weld.services.TCCLSingletonService) DefaultNamespaceContextSelectorService(org.jboss.as.naming.service.DefaultNamespaceContextSelectorService) Service(org.jboss.weld.bootstrap.api.Service) WeldBootstrapService(org.jboss.as.weld.WeldBootstrapService) NamingService(org.jboss.as.naming.service.NamingService) WeldStartService(org.jboss.as.weld.WeldStartService) ExecutorService(java.util.concurrent.ExecutorService) TransactionServices(org.jboss.weld.transaction.spi.TransactionServices) ModuleSpecification(org.jboss.as.server.deployment.module.ModuleSpecification) ExecutorServices(org.jboss.weld.manager.api.ExecutorServices) WeldExecutorServices(org.jboss.as.weld.services.bootstrap.WeldExecutorServices) ExecutorService(java.util.concurrent.ExecutorService) BeanDeploymentModule(org.jboss.as.weld.deployment.BeanDeploymentModule) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 3 with BeanDeploymentArchiveImpl

use of org.jboss.as.weld.deployment.BeanDeploymentArchiveImpl in project wildfly by wildfly.

the class BeanArchiveProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (!WeldDeploymentMarker.isPartOfWeldDeployment(deploymentUnit)) {
        return;
    }
    WeldLogger.DEPLOYMENT_LOGGER.processingWeldDeployment(deploymentUnit.getName());
    final Map<ResourceRoot, Index> indexes = AnnotationIndexUtils.getAnnotationIndexes(deploymentUnit);
    final Map<ResourceRoot, BeanDeploymentArchiveImpl> bdaMap = new HashMap<ResourceRoot, BeanDeploymentArchiveImpl>();
    final Components components = new Components(deploymentUnit, indexes);
    final ResourceRootHandler handler = new ResourceRootHandler(deploymentUnit, components, indexes);
    for (ResourceRoot resourceRoot : deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS)) {
        if (ModuleRootMarker.isModuleRoot(resourceRoot) && !SubDeploymentMarker.isSubDeployment(resourceRoot)) {
            if (isClassesRoot(resourceRoot)) {
                // this is handled below
                continue;
            }
            handler.handleResourceRoot(bdaMap, resourceRoot);
        }
    }
    if (!DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit)) {
        handler.handleResourceRoot(bdaMap, handler.deploymentResourceRoot);
    }
    if (!bdaMap.containsKey(handler.deploymentResourceRoot)) {
        // there is not root bda, let's create one
        BeanDeploymentArchiveImpl bda = new BeanDeploymentArchiveImpl(Collections.<String>emptySet(), Collections.<String>emptySet(), BeansXml.EMPTY_BEANS_XML, handler.module, getDeploymentUnitId(deploymentUnit), BeanArchiveType.SYNTHETIC, true);
        WeldLogger.DEPLOYMENT_LOGGER.beanArchiveDiscovered(bda);
        bdaMap.put(handler.deploymentResourceRoot, bda);
    }
    deploymentUnit.putAttachment(WeldAttachments.DEPLOYMENT_ROOT_BEAN_DEPLOYMENT_ARCHIVE, bdaMap.get(handler.deploymentResourceRoot));
    /*
         * Finish EE component processing
         */
    for (Entry<ResourceRoot, Collection<ComponentDescription>> entry : components.componentDescriptions.entrySet()) {
        BeanDeploymentArchiveImpl bda = bdaMap.get(entry.getKey());
        String id = null;
        if (bda != null) {
            id = bda.getId();
        } else {
            id = deploymentUnit.getAttachment(WeldAttachments.DEPLOYMENT_ROOT_BEAN_DEPLOYMENT_ARCHIVE).getId();
        }
        for (ComponentDescription componentDescription : entry.getValue()) {
            componentDescription.setBeanDeploymentArchiveId(id);
        }
    }
    final BeanDeploymentModule bdm = new BeanDeploymentModule(handler.module.getIdentifier().toString(), deploymentUnit, bdaMap.values());
    deploymentUnit.putAttachment(WeldAttachments.BEAN_DEPLOYMENT_MODULE, bdm);
}
Also used : ComponentDescription(org.jboss.as.ee.component.ComponentDescription) BeanDeploymentArchiveImpl(org.jboss.as.weld.deployment.BeanDeploymentArchiveImpl) HashMap(java.util.HashMap) DeploymentReflectionIndex(org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex) Index(org.jboss.jandex.Index) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) Collection(java.util.Collection) BeanDeploymentModule(org.jboss.as.weld.deployment.BeanDeploymentModule) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) Utils.getRootDeploymentUnit(org.jboss.as.weld.util.Utils.getRootDeploymentUnit)

Example 4 with BeanDeploymentArchiveImpl

use of org.jboss.as.weld.deployment.BeanDeploymentArchiveImpl in project wildfly by wildfly.

the class ExternalBeanArchiveProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (!WeldDeploymentMarker.isPartOfWeldDeployment(deploymentUnit)) {
        return;
    }
    if (deploymentUnit.getParent() != null) {
        return;
    }
    final Set<String> componentClassNames = new HashSet<>();
    final ServiceLoader<ComponentSupport> supportServices = ServiceLoader.load(ComponentSupport.class, WildFlySecurityManager.getClassLoaderPrivileged(ExternalBeanArchiveProcessor.class));
    final String beanArchiveIdPrefix = deploymentUnit.getName() + ".external.";
    // This set is used for external bean archives with annotated discovery mode
    final Set<AnnotationType> beanDefiningAnnotations = new HashSet<>(deploymentUnit.getAttachment(WeldAttachments.BEAN_DEFINING_ANNOTATIONS));
    final List<DeploymentUnit> deploymentUnits = new ArrayList<DeploymentUnit>();
    deploymentUnits.add(deploymentUnit);
    deploymentUnits.addAll(deploymentUnit.getAttachmentList(Attachments.SUB_DEPLOYMENTS));
    BeansXmlParser parser = BeansXmlParserFactory.getPropertyReplacingParser(deploymentUnit, Utils.getRootDeploymentUnit(deploymentUnit).getAttachment(WeldConfiguration.ATTACHMENT_KEY).isLegacyEmptyBeansXmlTreatment());
    final HashSet<URL> existing = new HashSet<URL>();
    // build a set of all deployment unit names, used later on to skip processing of some dependencies
    final Set<String> depUnitNames = new HashSet<>();
    final String prefix = "deployment.";
    for (DeploymentUnit deployment : deploymentUnits) {
        depUnitNames.add(prefix + deployment.getName());
        try {
            final ExplicitBeanArchiveMetadataContainer weldDeploymentMetadata = deployment.getAttachment(ExplicitBeanArchiveMetadataContainer.ATTACHMENT_KEY);
            if (weldDeploymentMetadata != null) {
                for (ExplicitBeanArchiveMetadata md : weldDeploymentMetadata.getBeanArchiveMetadata().values()) {
                    existing.add(md.getBeansXmlFile().toURL());
                    if (md.getAdditionalBeansXmlFile() != null) {
                        existing.add(md.getAdditionalBeansXmlFile().toURL());
                    }
                }
            }
        } catch (MalformedURLException e) {
            throw new DeploymentUnitProcessingException(e);
        }
        EEModuleDescription moduleDesc = deployment.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
        if (moduleDesc != null) {
            for (ComponentDescription component : moduleDesc.getComponentDescriptions()) {
                for (ComponentSupport support : supportServices) {
                    if (!support.isDiscoveredExternalType(component)) {
                        componentClassNames.add(component.getComponentClassName());
                        break;
                    }
                }
            }
        }
    }
    final ServiceLoader<ModuleServicesProvider> moduleServicesProviders = ServiceLoader.load(ModuleServicesProvider.class, WildFlySecurityManager.getClassLoaderPrivileged(WeldDeploymentProcessor.class));
    Set<String> skipPrecalculatedJandexModules = getSkipPrecalculatedJandexModules(deploymentUnit);
    // This map is a cache that allows us to avoid repeated introspection of Module's exported resources
    // it is of little importance for small deployment, but makes a difference in massive ones, see WFLY-14055
    Map<String, Map<URL, URL>> exportedResourcesCache = new HashMap<>();
    for (DeploymentUnit deployment : deploymentUnits) {
        final Module module = deployment.getAttachment(Attachments.MODULE);
        if (module == null) {
            return;
        }
        for (DependencySpec dep : module.getDependencies()) {
            if (!(dep instanceof ModuleDependencySpec)) {
                continue;
            }
            if (depUnitNames.contains(((ModuleDependencySpec) dep).getName())) {
                // we want to skip processing this as it will be (or already was) processed as another dep. unit
                continue;
            }
            final Module dependency = loadModuleDependency(dep);
            if (dependency == null) {
                continue;
            }
            Map<URL, URL> resourcesMap = findExportedResources(dependency, exportedResourcesCache);
            if (!resourcesMap.isEmpty()) {
                List<BeanDeploymentArchiveImpl> moduleBdas = new ArrayList<>();
                for (Entry<URL, URL> entry : resourcesMap.entrySet()) {
                    URL beansXmlUrl = entry.getKey();
                    if (existing.contains(beansXmlUrl)) {
                        continue;
                    }
                    /*
                         * Workaround for http://java.net/jira/browse/JAVASERVERFACES-2837
                         */
                    if (beansXmlUrl.toString().contains("jsf-impl-2.2")) {
                        continue;
                    }
                    /*
                         * Workaround for resteasy-cdi bundling beans.xml
                         */
                    if (beansXmlUrl.toString().contains("resteasy-cdi")) {
                        continue;
                    }
                    /*
                         * check if the dependency processes META-INF, if it doesn't we don't want to pick up beans
                         * See https://docs.wildfly.org/17/Developer_Guide.html#CDI_Reference
                         */
                    if (!dep.getImportFilter().accept("META-INF")) {
                        continue;
                    }
                    WeldLogger.DEPLOYMENT_LOGGER.debugf("Found external beans.xml: %s", beansXmlUrl.toString());
                    final BeansXml beansXml = parseBeansXml(beansXmlUrl, parser, deploymentUnit);
                    if (BeanDiscoveryMode.NONE.equals(beansXml.getBeanDiscoveryMode())) {
                        // Scanning suppressed per spec
                        continue;
                    }
                    final boolean skipPrecalculatedJandex = skipPrecalculatedJandexModules.contains(dependency.getName());
                    Map<String, List<String>> allAndBeanClasses = discover(beansXml.getBeanDiscoveryMode(), beansXmlUrl, entry.getValue(), beanDefiningAnnotations, skipPrecalculatedJandex);
                    Collection<String> discoveredBeanClasses = allAndBeanClasses.get(BEAN_CLASSES);
                    Collection<String> allKnownClasses = allAndBeanClasses.get(ALL_KNOWN_CLASSES);
                    if (discoveredBeanClasses == null) {
                        // URL scanner probably does not understand the protocol
                        continue;
                    }
                    discoveredBeanClasses.removeAll(componentClassNames);
                    final BeanDeploymentArchiveImpl bda = new BeanDeploymentArchiveImpl(new HashSet<String>(discoveredBeanClasses), new HashSet<String>(allKnownClasses), beansXml, dependency, beanArchiveIdPrefix + beansXmlUrl.toExternalForm(), BeanArchiveType.EXTERNAL);
                    WeldLogger.DEPLOYMENT_LOGGER.beanArchiveDiscovered(bda);
                    // Add module services to external bean deployment archive
                    for (Entry<Class<? extends Service>, Service> moduleService : ServiceLoaders.loadModuleServices(moduleServicesProviders, deploymentUnit, deployment, module, null).entrySet()) {
                        bda.getServices().add(moduleService.getKey(), Reflections.cast(moduleService.getValue()));
                    }
                    deploymentUnit.addToAttachmentList(WeldAttachments.ADDITIONAL_BEAN_DEPLOYMENT_MODULES, bda);
                    moduleBdas.add(bda);
                    // make sure that if this beans.xml is seen by some other module, it is not processed twice
                    existing.add(beansXmlUrl);
                }
                // BDA's from inside the same module have visibility on each other
                for (BeanDeploymentArchiveImpl i : moduleBdas) {
                    for (BeanDeploymentArchiveImpl j : moduleBdas) {
                        if (i != j) {
                            i.addBeanDeploymentArchive(j);
                        }
                    }
                }
            }
        }
    }
}
Also used : ComponentSupport(org.jboss.as.weld.spi.ComponentSupport) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) MalformedURLException(java.net.MalformedURLException) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AnnotationType(org.jboss.as.weld.discovery.AnnotationType) URL(java.net.URL) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) BeansXml(org.jboss.weld.bootstrap.spi.BeansXml) DependencySpec(org.jboss.modules.DependencySpec) ModuleDependencySpec(org.jboss.modules.ModuleDependencySpec) List(java.util.List) ArrayList(java.util.ArrayList) ExplicitBeanArchiveMetadataContainer(org.jboss.as.weld.deployment.ExplicitBeanArchiveMetadataContainer) HashSet(java.util.HashSet) ModuleServicesProvider(org.jboss.as.weld.spi.ModuleServicesProvider) ExplicitBeanArchiveMetadata(org.jboss.as.weld.deployment.ExplicitBeanArchiveMetadata) BeanDeploymentArchiveImpl(org.jboss.as.weld.deployment.BeanDeploymentArchiveImpl) Service(org.jboss.weld.bootstrap.api.Service) ModuleDependencySpec(org.jboss.modules.ModuleDependencySpec) BeansXmlParser(org.jboss.weld.xml.BeansXmlParser) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) Utils.getRootDeploymentUnit(org.jboss.as.weld.util.Utils.getRootDeploymentUnit) Map(java.util.Map) HashMap(java.util.HashMap)

Example 5 with BeanDeploymentArchiveImpl

use of org.jboss.as.weld.deployment.BeanDeploymentArchiveImpl in project wildfly by wildfly.

the class WeldBeanManagerServiceProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final DeploymentUnit topLevelDeployment = Utils.getRootDeploymentUnit(deploymentUnit);
    final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
    if (!WeldDeploymentMarker.isPartOfWeldDeployment(topLevelDeployment)) {
        return;
    }
    BeanDeploymentArchiveImpl rootBda = deploymentUnit.getAttachment(WeldAttachments.DEPLOYMENT_ROOT_BEAN_DEPLOYMENT_ARCHIVE);
    if (rootBda == null) {
        // this archive is not actually a bean archive.
        // then use the top level root bda
        rootBda = topLevelDeployment.getAttachment(WeldAttachments.DEPLOYMENT_ROOT_BEAN_DEPLOYMENT_ARCHIVE);
    }
    if (rootBda == null) {
        WeldLogger.DEPLOYMENT_LOGGER.couldNotFindBeanManagerForDeployment(deploymentUnit.getName());
        return;
    }
    final ServiceName weldServiceName = topLevelDeployment.getServiceName().append(WeldBootstrapService.SERVICE_NAME);
    // add the BeanManager service
    final ServiceName beanManagerServiceName = BeanManagerService.serviceName(deploymentUnit);
    final ServiceBuilder<?> builder = serviceTarget.addService(beanManagerServiceName);
    final Consumer<BeanManager> beanManagerConsumer = builder.provides(beanManagerServiceName);
    final Supplier<WeldBootstrapService> weldContainerSupplier = builder.requires(weldServiceName);
    builder.setInstance(new BeanManagerService(rootBda.getId(), beanManagerConsumer, weldContainerSupplier));
    builder.install();
    final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
    if (moduleDescription == null) {
        return;
    }
    // hack to set up a java:comp binding for jar deployments as well as wars
    if (DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit) || deploymentUnit.getName().endsWith(".jar")) {
        // bind the bean manager to JNDI
        final ServiceName moduleContextServiceName = ContextNames.contextServiceNameOfModule(moduleDescription.getApplicationName(), moduleDescription.getModuleName());
        bindBeanManager(deploymentUnit, serviceTarget, beanManagerServiceName, moduleContextServiceName);
    }
    // bind the bm into java:comp for all components that require it
    for (ComponentDescription component : moduleDescription.getComponentDescriptions()) {
        if (component.getNamingMode() == ComponentNamingMode.CREATE) {
            final ServiceName compContextServiceName = ContextNames.contextServiceNameOfComponent(moduleDescription.getApplicationName(), moduleDescription.getModuleName(), component.getComponentName());
            bindBeanManager(deploymentUnit, serviceTarget, beanManagerServiceName, compContextServiceName);
        }
    }
    SetupAction action = new WeldContextSetup();
    deploymentUnit.putAttachment(ATTACHMENT_KEY, action);
    deploymentUnit.addToAttachmentList(Attachments.SETUP_ACTIONS, action);
}
Also used : ComponentDescription(org.jboss.as.ee.component.ComponentDescription) BeanDeploymentArchiveImpl(org.jboss.as.weld.deployment.BeanDeploymentArchiveImpl) WeldContextSetup(org.jboss.as.weld.arquillian.WeldContextSetup) ServiceTarget(org.jboss.msc.service.ServiceTarget) SetupAction(org.jboss.as.server.deployment.SetupAction) BeanManagerService(org.jboss.as.weld.services.BeanManagerService) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) ServiceName(org.jboss.msc.service.ServiceName) WeldBootstrapService(org.jboss.as.weld.WeldBootstrapService) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) BeanManager(javax.enterprise.inject.spi.BeanManager)

Aggregations

DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)5 BeanDeploymentArchiveImpl (org.jboss.as.weld.deployment.BeanDeploymentArchiveImpl)5 HashMap (java.util.HashMap)3 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)3 HashSet (java.util.HashSet)2 Map (java.util.Map)2 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)2 SetupAction (org.jboss.as.server.deployment.SetupAction)2 ResourceRoot (org.jboss.as.server.deployment.module.ResourceRoot)2 WeldBootstrapService (org.jboss.as.weld.WeldBootstrapService)2 BeanDeploymentModule (org.jboss.as.weld.deployment.BeanDeploymentModule)2 ModuleServicesProvider (org.jboss.as.weld.spi.ModuleServicesProvider)2 Utils.getRootDeploymentUnit (org.jboss.as.weld.util.Utils.getRootDeploymentUnit)2 Module (org.jboss.modules.Module)2 ServiceName (org.jboss.msc.service.ServiceName)2 ServiceTarget (org.jboss.msc.service.ServiceTarget)2 Service (org.jboss.weld.bootstrap.api.Service)2 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1