Search in sources :

Example 21 with ResourceRoot

use of org.jboss.as.server.deployment.module.ResourceRoot 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);
    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);
    final WeldBootstrapService weldBootstrapService = new WeldBootstrapService(deployment, WildFlyWeldEnvironment.INSTANCE, deploymentUnit.getName());
    installBootstrapConfigurationService(deployment, parent);
    // Add root module services to WeldDeployment
    for (Entry<Class<? extends Service>, Service> entry : rootModuleServices.entrySet()) {
        weldBootstrapService.addWeldService(entry.getKey(), Reflections.cast(entry.getValue()));
    }
    // add the weld service
    final ServiceBuilder<WeldBootstrapService> weldBootstrapServiceBuilder = serviceTarget.addService(weldBootstrapServiceName, weldBootstrapService);
    weldBootstrapServiceBuilder.addDependencies(TCCLSingletonService.SERVICE_NAME);
    weldBootstrapServiceBuilder.addDependency(WeldExecutorServices.SERVICE_NAME, ExecutorServices.class, weldBootstrapService.getExecutorServices());
    weldBootstrapServiceBuilder.addDependency(Services.JBOSS_SERVER_EXECUTOR, ExecutorService.class, weldBootstrapService.getServerExecutor());
    // 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())) {
            weldBootstrapServiceBuilder.addDependency(serviceName, SecurityServices.class, weldBootstrapService.getSecurityServices());
        } else if (ServiceNames.WELD_TRANSACTION_SERVICES_SERVICE_NAME.getSimpleName().equals(serviceName.getSimpleName())) {
            weldBootstrapServiceBuilder.addDependency(serviceName, TransactionServices.class, weldBootstrapService.getWeldTransactionServices());
        }
    }
    weldBootstrapServiceBuilder.install();
    final List<SetupAction> setupActions = new ArrayList<SetupAction>();
    JavaNamespaceSetup naming = deploymentUnit.getAttachment(org.jboss.as.ee.naming.Attachments.JAVA_NAMESPACE_SETUP_ACTION);
    if (naming != null) {
        setupActions.add(naming);
    }
    final WeldStartService weldStartService = new WeldStartService(setupActions, module.getClassLoader(), Utils.getRootDeploymentUnit(deploymentUnit).getServiceName());
    ServiceBuilder<WeldStartService> startService = serviceTarget.addService(weldStartServiceName, weldStartService).addDependency(weldBootstrapServiceName, WeldBootstrapService.class, weldStartService.getBootstrap()).addDependencies(dependencies);
    // make sure JNDI bindings are up
    startService.addDependency(JndiNamingDependencyProcessor.serviceName(deploymentUnit));
    // [WFLY-5232]
    startService.addDependencies(getJNDISubsytemDependencies());
    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.addDependency(JndiNamingDependencyProcessor.serviceName(sub));
        }
    }
    startService.install();
}
Also used : ModuleDependency(org.jboss.as.server.deployment.module.ModuleDependency) HashMap(java.util.HashMap) Metadata(org.jboss.weld.bootstrap.spi.Metadata) ArrayList(java.util.ArrayList) DeploymentUnitDependenciesProvider(org.jboss.as.weld.spi.DeploymentUnitDependenciesProvider) WeldDeployment(org.jboss.as.weld.deployment.WeldDeployment) EarMetaData(org.jboss.metadata.ear.spec.EarMetaData) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) BootstrapDependencyInstaller(org.jboss.as.weld.spi.BootstrapDependencyInstaller) WeldStartService(org.jboss.as.weld.WeldStartService) ModuleIdentifier(org.jboss.modules.ModuleIdentifier) WeldBootstrapService(org.jboss.as.weld.WeldBootstrapService) HashSet(java.util.HashSet) ModuleServicesProvider(org.jboss.as.weld.spi.ModuleServicesProvider) BeanDeploymentArchiveImpl(org.jboss.as.weld.deployment.BeanDeploymentArchiveImpl) JavaNamespaceSetup(org.jboss.as.ee.naming.JavaNamespaceSetup) ServiceTarget(org.jboss.msc.service.ServiceTarget) 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) SetupAction(org.jboss.as.server.deployment.SetupAction) ServiceName(org.jboss.msc.service.ServiceName) TransactionServices(org.jboss.weld.transaction.spi.TransactionServices) ModuleSpecification(org.jboss.as.server.deployment.module.ModuleSpecification) Module(org.jboss.modules.Module) BeanDeploymentModule(org.jboss.as.weld.deployment.BeanDeploymentModule) BeanDeploymentModule(org.jboss.as.weld.deployment.BeanDeploymentModule) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) Map(java.util.Map) HashMap(java.util.HashMap) EEModuleDescriptor(org.jboss.weld.bootstrap.spi.EEModuleDescriptor)

Example 22 with ResourceRoot

use of org.jboss.as.server.deployment.module.ResourceRoot 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)

Example 23 with ResourceRoot

use of org.jboss.as.server.deployment.module.ResourceRoot 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(), 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) HashMap(java.util.HashMap) BeanDeploymentArchiveImpl(org.jboss.as.weld.deployment.BeanDeploymentArchiveImpl) 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 24 with ResourceRoot

use of org.jboss.as.server.deployment.module.ResourceRoot in project wildfly by wildfly.

the class BeansXmlProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    Map<ResourceRoot, ExplicitBeanArchiveMetadata> beanArchiveMetadata = new HashMap<ResourceRoot, ExplicitBeanArchiveMetadata>();
    ResourceRoot deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
    if (deploymentRoot == null) {
        return;
    }
    PropertyReplacingBeansXmlParser parser = new PropertyReplacingBeansXmlParser(deploymentUnit);
    ResourceRoot classesRoot = null;
    List<ResourceRoot> structure = deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS);
    for (ResourceRoot resourceRoot : structure) {
        if (ModuleRootMarker.isModuleRoot(resourceRoot) && !SubDeploymentMarker.isSubDeployment(resourceRoot)) {
            if (resourceRoot.getRootName().equals("classes")) {
                // hack for dealing with war modules
                classesRoot = resourceRoot;
                deploymentUnit.putAttachment(WeldAttachments.CLASSES_RESOURCE_ROOT, resourceRoot);
            } else {
                VirtualFile beansXml = resourceRoot.getRoot().getChild(META_INF_BEANS_XML);
                if (beansXml.exists() && beansXml.isFile()) {
                    WeldLogger.DEPLOYMENT_LOGGER.debugf("Found beans.xml: %s", beansXml.toString());
                    beanArchiveMetadata.put(resourceRoot, new ExplicitBeanArchiveMetadata(beansXml, resourceRoot, parseBeansXml(beansXml, parser, deploymentUnit), false));
                }
            }
        }
    }
    if (DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) {
        final VirtualFile rootBeansXml = deploymentRoot.getRoot().getChild(WEB_INF_BEANS_XML);
        final boolean rootBeansXmlPresent = rootBeansXml.exists() && rootBeansXml.isFile();
        VirtualFile beansXml = null;
        if (classesRoot != null) {
            beansXml = classesRoot.getRoot().getChild(META_INF_BEANS_XML);
        }
        final boolean beansXmlPresent = beansXml != null && beansXml.exists() && beansXml.isFile();
        if (rootBeansXmlPresent) {
            if (beansXmlPresent) {
                // warn that it is not portable to use both locations at the same time
                WeldLogger.DEPLOYMENT_LOGGER.duplicateBeansXml();
                beanArchiveMetadata.put(deploymentRoot, new ExplicitBeanArchiveMetadata(rootBeansXml, beansXml, classesRoot, parseBeansXml(rootBeansXml, parser, deploymentUnit), true));
            } else {
                WeldLogger.DEPLOYMENT_LOGGER.debugf("Found beans.xml: %s", rootBeansXml);
                beanArchiveMetadata.put(deploymentRoot, new ExplicitBeanArchiveMetadata(rootBeansXml, classesRoot, parseBeansXml(rootBeansXml, parser, deploymentUnit), true));
            }
        } else if (beansXmlPresent) {
            WeldLogger.DEPLOYMENT_LOGGER.debugf("Found beans.xml: %s", beansXml);
            beanArchiveMetadata.put(deploymentRoot, new ExplicitBeanArchiveMetadata(beansXml, classesRoot, parseBeansXml(beansXml, parser, deploymentUnit), true));
        }
    } else if (!DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit)) {
        final VirtualFile rootBeansXml = deploymentRoot.getRoot().getChild(META_INF_BEANS_XML);
        if (rootBeansXml.exists() && rootBeansXml.isFile()) {
            WeldLogger.DEPLOYMENT_LOGGER.debugf("Found beans.xml: %s", rootBeansXml.toString());
            beanArchiveMetadata.put(deploymentRoot, new ExplicitBeanArchiveMetadata(rootBeansXml, deploymentRoot, parseBeansXml(rootBeansXml, parser, deploymentUnit), true));
        }
    }
    if (!beanArchiveMetadata.isEmpty()) {
        ExplicitBeanArchiveMetadataContainer deploymentMetadata = new ExplicitBeanArchiveMetadataContainer(beanArchiveMetadata);
        deploymentUnit.putAttachment(ExplicitBeanArchiveMetadataContainer.ATTACHMENT_KEY, deploymentMetadata);
        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;
            }
        }
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) Entry(java.util.Map.Entry) HashMap(java.util.HashMap) ExplicitBeanArchiveMetadata(org.jboss.as.weld.deployment.ExplicitBeanArchiveMetadata) PropertyReplacingBeansXmlParser(org.jboss.as.weld.deployment.PropertyReplacingBeansXmlParser) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) ExplicitBeanArchiveMetadataContainer(org.jboss.as.weld.deployment.ExplicitBeanArchiveMetadataContainer)

Example 25 with ResourceRoot

use of org.jboss.as.server.deployment.module.ResourceRoot in project wildfly by wildfly.

the class WildFlyJobXmlResolver method forDeployment.

/**
     * Creates the {@linkplain JobXmlResolver resolver} for the deployment inheriting any visible resolvers and job XML
     * files from dependencies.
     *
     * @param deploymentUnit the deployment to process
     *
     * @return the resolve
     *
     * @throws DeploymentUnitProcessingException if an error occurs processing the deployment
     */
public static WildFlyJobXmlResolver forDeployment(final DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException {
    // If this deployment unit already has a resolver, just use it
    if (deploymentUnit.hasAttachment(BatchAttachments.JOB_XML_RESOLVER)) {
        return deploymentUnit.getAttachment(BatchAttachments.JOB_XML_RESOLVER);
    }
    // Get the module for it's class loader
    final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
    final ClassLoader classLoader = module.getClassLoader();
    WildFlyJobXmlResolver resolver;
    // access to the EAR/lib directory so those resources need to be processed
    if (DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit)) {
        // Create a new WildFlyJobXmlResolver without jobs from sub-deployments as they'll be processed later
        final List<ResourceRoot> resources = deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS).stream().filter(r -> !SubDeploymentMarker.isSubDeployment(r)).collect(Collectors.toList());
        resolver = create(classLoader, resources);
        deploymentUnit.putAttachment(BatchAttachments.JOB_XML_RESOLVER, resolver);
    } else {
        // Create a new resolver for this deployment
        if (deploymentUnit.hasAttachment(Attachments.RESOURCE_ROOTS)) {
            resolver = create(classLoader, deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS));
        } else {
            resolver = create(classLoader, Collections.singletonList(deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT)));
        }
        deploymentUnit.putAttachment(BatchAttachments.JOB_XML_RESOLVER, resolver);
        // Process all accessible sub-deployments
        final List<DeploymentUnit> accessibleDeployments = deploymentUnit.getAttachmentList(Attachments.ACCESSIBLE_SUB_DEPLOYMENTS);
        for (DeploymentUnit subDeployment : accessibleDeployments) {
            // Skip our self
            if (deploymentUnit.equals(subDeployment)) {
                continue;
            }
            if (subDeployment.hasAttachment(BatchAttachments.JOB_XML_RESOLVER)) {
                final WildFlyJobXmlResolver toCopy = subDeployment.getAttachment(BatchAttachments.JOB_XML_RESOLVER);
                WildFlyJobXmlResolver.merge(resolver, toCopy);
            } else {
                // We need to create a resolver for the sub-deployment and merge the two
                final WildFlyJobXmlResolver toCopy = forDeployment(subDeployment);
                subDeployment.putAttachment(BatchAttachments.JOB_XML_RESOLVER, toCopy);
                WildFlyJobXmlResolver.merge(resolver, toCopy);
            }
        }
    }
    return resolver;
}
Also used : JobXmlResolver(org.jberet.spi.JobXmlResolver) BatchLogger(org.wildfly.extension.batch.jberet._private.BatchLogger) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) DeploymentTypeMarker(org.jboss.as.ee.structure.DeploymentTypeMarker) SubDeploymentMarker(org.jboss.as.server.deployment.SubDeploymentMarker) ArrayList(java.util.ArrayList) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) XMLStreamException(javax.xml.stream.XMLStreamException) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) VirtualFile(org.jboss.vfs.VirtualFile) XMLResolver(javax.xml.stream.XMLResolver) LinkedHashSet(java.util.LinkedHashSet) Collection(java.util.Collection) Set(java.util.Set) IOException(java.io.IOException) ServiceLoader(java.util.ServiceLoader) PrivilegedAction(java.security.PrivilegedAction) Collectors(java.util.stream.Collectors) List(java.util.List) WildFlySecurityManager(org.wildfly.security.manager.WildFlySecurityManager) Module(org.jboss.modules.Module) DeploymentType(org.jboss.as.ee.structure.DeploymentType) JobParser(org.jberet.job.model.JobParser) Attachments(org.jboss.as.server.deployment.Attachments) VirtualFileFilter(org.jboss.vfs.VirtualFileFilter) Job(org.jberet.job.model.Job) AccessController(java.security.AccessController) Collections(java.util.Collections) InputStream(java.io.InputStream) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Aggregations

ResourceRoot (org.jboss.as.server.deployment.module.ResourceRoot)71 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)49 VirtualFile (org.jboss.vfs.VirtualFile)37 IOException (java.io.IOException)16 ArrayList (java.util.ArrayList)16 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)12 HashMap (java.util.HashMap)10 PersistenceUnitMetadataHolder (org.jboss.as.jpa.config.PersistenceUnitMetadataHolder)10 WarMetaData (org.jboss.as.web.common.WarMetaData)10 MountHandle (org.jboss.as.server.deployment.module.MountHandle)9 Index (org.jboss.jandex.Index)8 Closeable (java.io.Closeable)7 URL (java.net.URL)7 HashSet (java.util.HashSet)7 Module (org.jboss.modules.Module)7 InputStream (java.io.InputStream)6 EarMetaData (org.jboss.metadata.ear.spec.EarMetaData)6 ServiceName (org.jboss.msc.service.ServiceName)6 XMLStreamException (javax.xml.stream.XMLStreamException)5 EEApplicationDescription (org.jboss.as.ee.component.EEApplicationDescription)5