Search in sources :

Example 1 with EarMetaData

use of org.jboss.metadata.ear.spec.EarMetaData in project wildfly by wildfly.

the class WarMetaDataProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (!DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) {
        // Skip non web deployments
        return;
    }
    WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    assert warMetaData != null;
    boolean isComplete = false;
    WebMetaData specMetaData = warMetaData.getWebMetaData();
    if (specMetaData != null) {
        if (specMetaData instanceof Web25MetaData) {
            isComplete |= ((Web25MetaData) specMetaData).isMetadataComplete();
        } else if (specMetaData instanceof Web30MetaData) {
            isComplete |= ((Web30MetaData) specMetaData).isMetadataComplete();
        } else {
            // As per Servlet 3.0 spec, metadata is not completed unless it's set to true in web.xml.
            // Hence, any web.xml 2.4 or earlier deployment is not metadata completed.
            isComplete = false;
        }
    }
    // Find all fragments that have been processed by deployers, and place
    // them in a map keyed by location
    LinkedList<String> order = new LinkedList<String>();
    List<WebOrdering> orderings = new ArrayList<WebOrdering>();
    HashSet<String> jarsSet = new HashSet<String>();
    Set<VirtualFile> overlays = new HashSet<VirtualFile>();
    Map<String, VirtualFile> scis = new HashMap<String, VirtualFile>();
    boolean fragmentFound = false;
    Map<String, WebFragmentMetaData> webFragments = warMetaData.getWebFragmentsMetaData();
    List<ResourceRoot> resourceRoots = deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS);
    for (ResourceRoot resourceRoot : resourceRoots) {
        if (resourceRoot.getRoot().getName().toLowerCase(Locale.ENGLISH).endsWith(".jar")) {
            jarsSet.add(resourceRoot.getRootName());
            // Find overlays
            VirtualFile overlay = resourceRoot.getRoot().getChild("META-INF/resources");
            if (overlay.exists()) {
                overlays.add(overlay);
            }
            // Find ServletContainerInitializer services
            VirtualFile sci = resourceRoot.getRoot().getChild("META-INF/services/javax.servlet.ServletContainerInitializer");
            if (sci.exists()) {
                scis.put(resourceRoot.getRootName(), sci);
            }
        }
    }
    if (!isComplete) {
        HashSet<String> jarsWithoutFragmentsSet = new HashSet<String>();
        jarsWithoutFragmentsSet.addAll(jarsSet);
        for (String jarName : webFragments.keySet()) {
            fragmentFound = true;
            WebFragmentMetaData fragmentMetaData = webFragments.get(jarName);
            webFragments.put(jarName, fragmentMetaData);
            WebOrdering webOrdering = new WebOrdering();
            webOrdering.setName(fragmentMetaData.getName());
            webOrdering.setJar(jarName);
            jarsWithoutFragmentsSet.remove(jarName);
            if (fragmentMetaData.getOrdering() != null) {
                if (fragmentMetaData.getOrdering().getAfter() != null) {
                    for (OrderingElementMetaData orderingElementMetaData : fragmentMetaData.getOrdering().getAfter().getOrdering()) {
                        if (orderingElementMetaData.isOthers()) {
                            webOrdering.setAfterOthers(true);
                        } else {
                            webOrdering.addAfter(orderingElementMetaData.getName());
                        }
                    }
                }
                if (fragmentMetaData.getOrdering().getBefore() != null) {
                    for (OrderingElementMetaData orderingElementMetaData : fragmentMetaData.getOrdering().getBefore().getOrdering()) {
                        if (orderingElementMetaData.isOthers()) {
                            webOrdering.setBeforeOthers(true);
                        } else {
                            webOrdering.addBefore(orderingElementMetaData.getName());
                        }
                    }
                }
            }
            orderings.add(webOrdering);
        }
        // fragment specifying no name and no order
        for (String jarName : jarsWithoutFragmentsSet) {
            WebOrdering ordering = new WebOrdering();
            ordering.setJar(jarName);
            orderings.add(ordering);
        }
    }
    if (!fragmentFound) {
        // Drop the order as there is no fragment in the webapp
        orderings.clear();
    }
    // Generate web fragments parsing order
    AbsoluteOrderingMetaData absoluteOrderingMetaData = null;
    if (!isComplete && specMetaData instanceof Web30MetaData) {
        absoluteOrderingMetaData = ((Web30MetaData) specMetaData).getAbsoluteOrdering();
    }
    if (absoluteOrderingMetaData != null) {
        // Absolute ordering from web.xml, any relative fragment ordering is ignored
        int otherPos = -1;
        int i = 0;
        for (OrderingElementMetaData orderingElementMetaData : absoluteOrderingMetaData.getOrdering()) {
            if (orderingElementMetaData.isOthers()) {
                if (otherPos >= 0) {
                    throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.invalidMultipleOthers());
                }
                otherPos = i;
            } else {
                boolean found = false;
                for (WebOrdering ordering : orderings) {
                    if (orderingElementMetaData.getName().equals(ordering.getName())) {
                        order.add(ordering.getJar());
                        jarsSet.remove(ordering.getJar());
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    UndertowLogger.ROOT_LOGGER.invalidAbsoluteOrdering(orderingElementMetaData.getName());
                } else {
                    i++;
                }
            }
        }
        if (otherPos >= 0) {
            order.addAll(otherPos, jarsSet);
            jarsSet.clear();
        }
    } else if (orderings.size() > 0) {
        // Resolve relative ordering
        try {
            resolveOrder(orderings, order);
        } catch (IllegalStateException e) {
            throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.invalidRelativeOrdering(), e);
        }
        jarsSet.clear();
    } else {
        // No order specified
        order.addAll(jarsSet);
        jarsSet.clear();
        warMetaData.setNoOrder(true);
    }
    if (UndertowLogger.ROOT_LOGGER.isDebugEnabled()) {
        StringBuilder builder = new StringBuilder();
        builder.append("Resolved order: [ ");
        for (String jar : order) {
            builder.append(jar).append(' ');
        }
        builder.append(']');
        UndertowLogger.ROOT_LOGGER.debug(builder.toString());
    }
    warMetaData.setOrder(order);
    warMetaData.setOverlays(overlays);
    warMetaData.setScis(scis);
    Map<String, WebMetaData> annotationsMetaData = warMetaData.getAnnotationsMetaData();
    // The fragments and corresponding annotations will need to be merged in order
    // For each JAR in the order:
    // - Merge the annotation metadata into the fragment meta data (unless the fragment exists and is meta data complete)
    // - Merge the fragment metadata into merged fragment meta data
    WebCommonMetaData mergedFragmentMetaData = new WebCommonMetaData();
    if (specMetaData == null) {
        // If there is no web.xml, it has to be considered to be the latest version
        specMetaData = new Web31MetaData();
        specMetaData.setVersion("3.1");
    }
    // Augment with meta data from annotations in /WEB-INF/classes
    WebMetaData annotatedMetaData = annotationsMetaData.get("classes");
    if (annotatedMetaData == null && deploymentUnit.hasAttachment(Attachments.OSGI_MANIFEST)) {
        annotatedMetaData = annotationsMetaData.get(deploymentUnit.getName());
    }
    if (annotatedMetaData != null) {
        if (isComplete) {
            // Discard @WebFilter, @WebListener and @WebServlet
            annotatedMetaData.setFilters(null);
            annotatedMetaData.setFilterMappings(null);
            annotatedMetaData.setListeners(null);
            annotatedMetaData.setServlets(null);
            annotatedMetaData.setServletMappings(null);
        }
        WebCommonMetaDataMerger.augment(specMetaData, annotatedMetaData, null, true);
    }
    // Augment with meta data from fragments and annotations from the corresponding JAR
    for (String jar : order) {
        WebFragmentMetaData webFragmentMetaData = webFragments.get(jar);
        if (webFragmentMetaData == null || isComplete) {
            webFragmentMetaData = new WebFragmentMetaData();
            // Add non overriding default distributable flag
            webFragmentMetaData.setDistributable(new EmptyMetaData());
        }
        WebMetaData jarAnnotatedMetaData = annotationsMetaData.get(jar);
        if ((isComplete || webFragmentMetaData.isMetadataComplete()) && jarAnnotatedMetaData != null) {
            // Discard @WebFilter, @WebListener and @WebServlet
            jarAnnotatedMetaData.setFilters(null);
            jarAnnotatedMetaData.setFilterMappings(null);
            jarAnnotatedMetaData.setListeners(null);
            jarAnnotatedMetaData.setServlets(null);
            jarAnnotatedMetaData.setServletMappings(null);
        }
        if (jarAnnotatedMetaData != null) {
            // Merge annotations corresponding to the JAR
            WebCommonMetaDataMerger.augment(webFragmentMetaData, jarAnnotatedMetaData, null, true);
        }
        // Merge fragment meta data according to the conflict rules
        try {
            WebCommonMetaDataMerger.augment(mergedFragmentMetaData, webFragmentMetaData, specMetaData, false);
        } catch (Exception e) {
            throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.invalidWebFragment(jar), e);
        }
    }
    // Augment with meta data from annotations from JARs excluded from the order
    for (String jar : jarsSet) {
        WebFragmentMetaData webFragmentMetaData = new WebFragmentMetaData();
        // Add non overriding default distributable flag
        webFragmentMetaData.setDistributable(new EmptyMetaData());
        WebMetaData jarAnnotatedMetaData = annotationsMetaData.get(jar);
        if (jarAnnotatedMetaData != null) {
            // Discard @WebFilter, @WebListener and @WebServlet
            jarAnnotatedMetaData.setFilters(null);
            jarAnnotatedMetaData.setFilterMappings(null);
            jarAnnotatedMetaData.setListeners(null);
            jarAnnotatedMetaData.setServlets(null);
            jarAnnotatedMetaData.setServletMappings(null);
        }
        if (jarAnnotatedMetaData != null) {
            // Merge annotations corresponding to the JAR
            WebCommonMetaDataMerger.augment(webFragmentMetaData, jarAnnotatedMetaData, null, true);
        }
        // Merge fragment meta data according to the conflict rules
        try {
            WebCommonMetaDataMerger.augment(mergedFragmentMetaData, webFragmentMetaData, specMetaData, false);
        } catch (Exception e) {
            throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.invalidWebFragment(jar), e);
        }
    }
    WebCommonMetaDataMerger.augment(specMetaData, mergedFragmentMetaData, null, true);
    List<WebMetaData> additional = warMetaData.getAdditionalModuleAnnotationsMetadata();
    if (additional != null && !isComplete) {
        //augument with annotations from additional modules
        for (WebMetaData annotations : additional) {
            // Merge annotations corresponding to the JAR
            WebCommonMetaDataMerger.augment(specMetaData, annotations, null, true);
        }
    }
    // Override with meta data (JBossWebMetaData) Create a merged view
    JBossWebMetaData mergedMetaData = new JBossWebMetaData();
    JBossWebMetaData metaData = warMetaData.getJBossWebMetaData();
    JBossWebMetaDataMerger.merge(mergedMetaData, metaData, specMetaData);
    // FIXME: Incorporate any ear level overrides
    // Use the OSGi Web-ContextPath if not given otherwise
    String contextRoot = mergedMetaData.getContextRoot();
    Manifest manifest = deploymentUnit.getAttachment(Attachments.OSGI_MANIFEST);
    if (contextRoot == null && manifest != null) {
        contextRoot = manifest.getMainAttributes().getValue("Web-ContextPath");
        mergedMetaData.setContextRoot(contextRoot);
    }
    warMetaData.setMergedJBossWebMetaData(mergedMetaData);
    if (mergedMetaData.isMetadataComplete()) {
        MetadataCompleteMarker.setMetadataComplete(deploymentUnit, true);
    }
    //now attach any JNDI binding related information to the deployment
    if (mergedMetaData.getJndiEnvironmentRefsGroup() != null) {
        final DeploymentDescriptorEnvironment bindings = new DeploymentDescriptorEnvironment("java:module/env/", mergedMetaData.getJndiEnvironmentRefsGroup());
        deploymentUnit.putAttachment(org.jboss.as.ee.component.Attachments.MODULE_DEPLOYMENT_DESCRIPTOR_ENVIRONMENT, bindings);
    }
    //override module name if applicable
    if (mergedMetaData.getModuleName() != null && !mergedMetaData.getModuleName().isEmpty()) {
        final EEModuleDescription description = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
        description.setModuleName(mergedMetaData.getModuleName());
    }
    //WFLY-3102 EJB in WAR should inherit WAR's security domain
    if (mergedMetaData.getSecurityDomain() != null) {
        final EEModuleDescription description = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
        description.setDefaultSecurityDomain(mergedMetaData.getSecurityDomain());
    }
    //merge security roles from the ear
    DeploymentUnit parent = deploymentUnit.getParent();
    if (parent != null) {
        final EarMetaData earMetaData = parent.getAttachment(org.jboss.as.ee.structure.Attachments.EAR_METADATA);
        if (earMetaData != null) {
            SecurityRolesMetaData earSecurityRolesMetaData = earMetaData.getSecurityRoles();
            if (earSecurityRolesMetaData != null) {
                if (mergedMetaData.getSecurityRoles() == null) {
                    mergedMetaData.setSecurityRoles(new SecurityRolesMetaData());
                }
                SecurityRolesMetaDataMerger.merge(mergedMetaData.getSecurityRoles(), mergedMetaData.getSecurityRoles(), earSecurityRolesMetaData);
            }
        }
    }
}
Also used : Web25MetaData(org.jboss.metadata.web.spec.Web25MetaData) VirtualFile(org.jboss.vfs.VirtualFile) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) JBossWebMetaData(org.jboss.metadata.web.jboss.JBossWebMetaData) HashMap(java.util.HashMap) EmptyMetaData(org.jboss.metadata.javaee.spec.EmptyMetaData) WarMetaData(org.jboss.as.web.common.WarMetaData) ArrayList(java.util.ArrayList) SecurityRolesMetaData(org.jboss.metadata.javaee.spec.SecurityRolesMetaData) EarMetaData(org.jboss.metadata.ear.spec.EarMetaData) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) DeploymentDescriptorEnvironment(org.jboss.as.ee.component.DeploymentDescriptorEnvironment) Web30MetaData(org.jboss.metadata.web.spec.Web30MetaData) Web31MetaData(org.jboss.metadata.web.spec.Web31MetaData) HashSet(java.util.HashSet) AbsoluteOrderingMetaData(org.jboss.metadata.web.spec.AbsoluteOrderingMetaData) Manifest(java.util.jar.Manifest) LinkedList(java.util.LinkedList) WebFragmentMetaData(org.jboss.metadata.web.spec.WebFragmentMetaData) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) OrderingElementMetaData(org.jboss.metadata.web.spec.OrderingElementMetaData) WebCommonMetaData(org.jboss.metadata.web.spec.WebCommonMetaData) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) JBossWebMetaData(org.jboss.metadata.web.jboss.JBossWebMetaData) WebMetaData(org.jboss.metadata.web.spec.WebMetaData)

Example 2 with EarMetaData

use of org.jboss.metadata.ear.spec.EarMetaData 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 3 with EarMetaData

use of org.jboss.metadata.ear.spec.EarMetaData in project wildfly by wildfly.

the class EarStructureProcessor method deploy.

public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (!DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit)) {
        return;
    }
    final ResourceRoot deploymentRoot = phaseContext.getDeploymentUnit().getAttachment(Attachments.DEPLOYMENT_ROOT);
    final VirtualFile virtualFile = deploymentRoot.getRoot();
    //  Make sure we don't index or add this as a module root
    deploymentRoot.putAttachment(Attachments.INDEX_RESOURCE_ROOT, false);
    ModuleRootMarker.mark(deploymentRoot, false);
    String libDirName = DEFAULT_LIB_DIR;
    //its possible that the ear metadata could come for jboss-app.xml
    final boolean appXmlPresent = deploymentRoot.getRoot().getChild("META-INF/application.xml").exists();
    final EarMetaData earMetaData = deploymentUnit.getAttachment(org.jboss.as.ee.structure.Attachments.EAR_METADATA);
    if (earMetaData != null) {
        final String xmlLibDirName = earMetaData.getLibraryDirectory();
        if (xmlLibDirName != null) {
            if (xmlLibDirName.length() == 1 && xmlLibDirName.charAt(0) == '/') {
                throw EeLogger.ROOT_LOGGER.rootAsLibraryDirectory();
            }
            libDirName = xmlLibDirName;
        }
    }
    // Process all the children
    Map<String, MountedDeploymentOverlay> overlays = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_OVERLAY_LOCATIONS);
    try {
        final VirtualFile libDir;
        // process the lib directory
        if (!libDirName.isEmpty()) {
            libDir = virtualFile.getChild(libDirName);
            if (libDir.exists()) {
                List<VirtualFile> libArchives = libDir.getChildren(CHILD_ARCHIVE_FILTER);
                for (final VirtualFile child : libArchives) {
                    String relativeName = child.getPathNameRelativeTo(deploymentRoot.getRoot());
                    MountedDeploymentOverlay overlay = overlays.get(relativeName);
                    final MountHandle mountHandle;
                    if (overlay != null) {
                        overlay.remountAsZip(false);
                        mountHandle = new MountHandle(null);
                    } else {
                        final Closeable closable = child.isFile() ? mount(child, false) : null;
                        mountHandle = new MountHandle(closable);
                    }
                    final ResourceRoot childResource = new ResourceRoot(child, mountHandle);
                    if (child.getName().toLowerCase(Locale.ENGLISH).endsWith(JAR_EXTENSION)) {
                        ModuleRootMarker.mark(childResource);
                        deploymentUnit.addToAttachmentList(Attachments.RESOURCE_ROOTS, childResource);
                    }
                }
            }
        } else {
            libDir = null;
        }
        // scan the ear looking for wars and jars
        final List<VirtualFile> childArchives = new ArrayList<VirtualFile>(virtualFile.getChildren(new SuffixMatchFilter(CHILD_ARCHIVE_EXTENSIONS, new VisitorAttributes() {

            @Override
            public boolean isLeavesOnly() {
                return false;
            }

            @Override
            public boolean isRecurse(VirtualFile file) {
                // don't recurse into /lib
                if (file.equals(libDir)) {
                    return false;
                }
                for (String suffix : CHILD_ARCHIVE_EXTENSIONS) {
                    if (file.getName().endsWith(suffix)) {
                        // don't recurse into sub deployments
                        return false;
                    }
                }
                return true;
            }
        })));
        // if there is no application.xml then look in the ear root for modules
        if (!appXmlPresent) {
            for (final VirtualFile child : childArchives) {
                final boolean isWarFile = child.getName().toLowerCase(Locale.ENGLISH).endsWith(WAR_EXTENSION);
                final boolean isRarFile = child.getName().toLowerCase(Locale.ENGLISH).endsWith(RAR_EXTENSION);
                this.createResourceRoot(deploymentUnit, child, isWarFile || isRarFile, isWarFile);
            }
        } else {
            final Set<VirtualFile> subDeploymentFiles = new HashSet<VirtualFile>();
            // otherwise read from application.xml
            for (final ModuleMetaData module : earMetaData.getModules()) {
                if (module.getFileName().endsWith(".xml")) {
                    throw EeLogger.ROOT_LOGGER.unsupportedModuleType(module.getFileName());
                }
                final VirtualFile moduleFile = virtualFile.getChild(module.getFileName());
                if (!moduleFile.exists()) {
                    throw EeLogger.ROOT_LOGGER.cannotProcessEarModule(virtualFile, module.getFileName());
                }
                if (libDir != null) {
                    VirtualFile moduleParentFile = moduleFile.getParent();
                    if (moduleParentFile != null) {
                        if (libDir.equals(moduleParentFile)) {
                            throw EeLogger.ROOT_LOGGER.earModuleChildOfLibraryDirectory(libDirName, module.getFileName());
                        }
                    }
                }
                // maintain this in a collection of subdeployment virtual files, to be used later
                subDeploymentFiles.add(moduleFile);
                final boolean webArchive = module.getType() == ModuleType.Web;
                final ResourceRoot childResource = this.createResourceRoot(deploymentUnit, moduleFile, true, webArchive);
                childResource.putAttachment(org.jboss.as.ee.structure.Attachments.MODULE_META_DATA, module);
                if (!webArchive) {
                    ModuleRootMarker.mark(childResource);
                }
                final String alternativeDD = module.getAlternativeDD();
                if (alternativeDD != null && alternativeDD.trim().length() > 0) {
                    final VirtualFile alternateDeploymentDescriptor = deploymentRoot.getRoot().getChild(alternativeDD);
                    if (!alternateDeploymentDescriptor.exists()) {
                        throw EeLogger.ROOT_LOGGER.alternateDeploymentDescriptor(alternateDeploymentDescriptor, moduleFile);
                    }
                    switch(module.getType()) {
                        case Client:
                            childResource.putAttachment(org.jboss.as.ee.structure.Attachments.ALTERNATE_CLIENT_DEPLOYMENT_DESCRIPTOR, alternateDeploymentDescriptor);
                            break;
                        case Connector:
                            childResource.putAttachment(org.jboss.as.ee.structure.Attachments.ALTERNATE_CONNECTOR_DEPLOYMENT_DESCRIPTOR, alternateDeploymentDescriptor);
                            break;
                        case Ejb:
                            childResource.putAttachment(org.jboss.as.ee.structure.Attachments.ALTERNATE_EJB_DEPLOYMENT_DESCRIPTOR, alternateDeploymentDescriptor);
                            break;
                        case Web:
                            childResource.putAttachment(org.jboss.as.ee.structure.Attachments.ALTERNATE_WEB_DEPLOYMENT_DESCRIPTOR, alternateDeploymentDescriptor);
                            break;
                        case Service:
                            throw EeLogger.ROOT_LOGGER.unsupportedModuleType(module.getFileName());
                    }
                }
            }
            // now check the rest of the archive for any other jar/sar files
            for (final VirtualFile child : childArchives) {
                if (subDeploymentFiles.contains(child)) {
                    continue;
                }
                final String fileName = child.getName().toLowerCase(Locale.ENGLISH);
                if (fileName.endsWith(SAR_EXTENSION) || fileName.endsWith(JAR_EXTENSION)) {
                    this.createResourceRoot(deploymentUnit, child, false, false);
                }
            }
        }
    } catch (IOException e) {
        throw EeLogger.ROOT_LOGGER.failedToProcessChild(e, virtualFile);
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) MountedDeploymentOverlay(org.jboss.as.server.deployment.MountedDeploymentOverlay) MountHandle(org.jboss.as.server.deployment.module.MountHandle) Closeable(java.io.Closeable) ArrayList(java.util.ArrayList) IOException(java.io.IOException) VisitorAttributes(org.jboss.vfs.VisitorAttributes) EarMetaData(org.jboss.metadata.ear.spec.EarMetaData) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) SuffixMatchFilter(org.jboss.vfs.util.SuffixMatchFilter) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) HashSet(java.util.HashSet) ModuleMetaData(org.jboss.metadata.ear.spec.ModuleMetaData)

Example 4 with EarMetaData

use of org.jboss.metadata.ear.spec.EarMetaData in project wildfly by wildfly.

the class EarMessageDestinationProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit)) {
        final EarMetaData metadata = deploymentUnit.getAttachment(Attachments.EAR_METADATA);
        final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
        if (metadata != null) {
            if (metadata.getEarEnvironmentRefsGroup() != null) {
                if (metadata.getEarEnvironmentRefsGroup().getMessageDestinations() != null) {
                    for (final MessageDestinationMetaData destination : metadata.getEarEnvironmentRefsGroup().getMessageDestinations()) {
                        //TODO: should these be two separate metadata attributes?
                        if (destination.getJndiName() != null) {
                            eeModuleDescription.addMessageDestination(destination.getName(), destination.getJndiName());
                        } else if (destination.getLookupName() != null) {
                            eeModuleDescription.addMessageDestination(destination.getName(), destination.getLookupName());
                        }
                    }
                }
            }
        }
    }
}
Also used : MessageDestinationMetaData(org.jboss.metadata.javaee.spec.MessageDestinationMetaData) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) EarMetaData(org.jboss.metadata.ear.spec.EarMetaData)

Example 5 with EarMetaData

use of org.jboss.metadata.ear.spec.EarMetaData in project wildfly by wildfly.

the class SecurityDomainMergingProcessor method getJBossAppSecurityDomain.

/**
     * Try to obtain the security domain configured in jboss-app.xml at the ear level if available
     *
     * @param deploymentUnit
     * @return
     */
private String getJBossAppSecurityDomain(final DeploymentUnit deploymentUnit) {
    String securityDomain = null;
    DeploymentUnit parent = deploymentUnit.getParent();
    if (parent != null) {
        final EarMetaData jbossAppMetaData = parent.getAttachment(Attachments.EAR_METADATA);
        if (jbossAppMetaData instanceof JBossAppMetaData) {
            securityDomain = ((JBossAppMetaData) jbossAppMetaData).getSecurityDomain();
        }
    }
    return securityDomain;
}
Also used : JBossAppMetaData(org.jboss.metadata.ear.jboss.JBossAppMetaData) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) EarMetaData(org.jboss.metadata.ear.spec.EarMetaData)

Aggregations

DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)12 EarMetaData (org.jboss.metadata.ear.spec.EarMetaData)12 ResourceRoot (org.jboss.as.server.deployment.module.ResourceRoot)6 JBossAppMetaData (org.jboss.metadata.ear.jboss.JBossAppMetaData)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 ModuleMetaData (org.jboss.metadata.ear.spec.ModuleMetaData)3 SecurityRolesMetaData (org.jboss.metadata.javaee.spec.SecurityRolesMetaData)3 VirtualFile (org.jboss.vfs.VirtualFile)3 DeploymentDescriptorEnvironment (org.jboss.as.ee.component.DeploymentDescriptorEnvironment)2 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)2 WarMetaData (org.jboss.as.web.common.WarMetaData)2 JBossWebMetaData (org.jboss.metadata.web.jboss.JBossWebMetaData)2 Closeable (java.io.Closeable)1 IOException (java.io.IOException)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 ExecutorService (java.util.concurrent.ExecutorService)1 Manifest (java.util.jar.Manifest)1