Java Code Examples for org.jboss.as.server.deployment.DeploymentPhaseContext#addToAttachmentList()

The following examples show how to use org.jboss.as.server.deployment.DeploymentPhaseContext#addToAttachmentList() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ManifestExtensionNameProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/** {@inheritDoc} */
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();

    // we only want to process top level jar deployments
    if (deploymentUnit.getParent() != null) {
        return;
    }

    final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);

    if (!deploymentRoot.getRoot().getName().endsWith(".jar")) {
        return;
    }
    // we are only interested in the root manifest
    // there should not be any additional resource roots for this type of deployment anyway
    final Manifest manifest = deploymentRoot.getAttachment(Attachments.MANIFEST);
    if (manifest == null) {
        return;
    }
    final Attributes mainAttributes = manifest.getMainAttributes();
    final String extensionName = mainAttributes.getValue(EXTENSION_NAME);
    ServerLogger.DEPLOYMENT_LOGGER.debugf("Found Extension-Name manifest entry %s in %s", extensionName, deploymentRoot.getRoot().getPathName());
    if (extensionName == null) {
        // no entry
        return;
    }
    final String implVersion = mainAttributes.getValue(IMPLEMENTATION_VERSION);
    final String implVendorId = mainAttributes.getValue(IMPLEMENTATION_VENDOR_ID);
    final String specVersion = mainAttributes.getValue(SPECIFICATION_VERSION);
    final ExtensionInfo info = new ExtensionInfo(extensionName, specVersion, implVersion, implVendorId);
    deploymentUnit.putAttachment(Attachments.EXTENSION_INFORMATION, info);

    phaseContext.addToAttachmentList(Attachments.NEXT_PHASE_DEPS, Services.JBOSS_DEPLOYMENT_EXTENSION_INDEX);
}
 
Example 2
Source File: DeploymentDependenciesProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void processDependencies(final DeploymentPhaseContext phaseContext, final DeploymentUnit deploymentUnit) {
    final DeploymentDependencies deps = deploymentUnit.getAttachment(DeploymentDependencies.ATTACHMENT_KEY);
    if (!deps.getDependencies().isEmpty()) {
        for (final String deployment : deps.getDependencies()) {
            final ServiceName name =  DeploymentCompleteServiceProcessor.serviceName(Services.deploymentUnitName(deployment));
            phaseContext.addToAttachmentList(Attachments.NEXT_PHASE_DEPS, name);
        }
    }
}
 
Example 3
Source File: ManifestDependencyProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Process the deployment root for module dependency information.
 *
 * @param phaseContext the deployment unit context
 * @throws org.jboss.as.server.deployment.DeploymentUnitProcessingException
 */
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final ServiceModuleLoader deploymentModuleLoader = deploymentUnit.getAttachment(Attachments.SERVICE_MODULE_LOADER);
    final List<ResourceRoot> allResourceRoots = DeploymentUtils.allResourceRoots(deploymentUnit);
    DeploymentUnit top = deploymentUnit.getParent() == null ? deploymentUnit : deploymentUnit.getParent();

    final Set<ModuleIdentifier> additionalModules = new HashSet<>();
    final List<AdditionalModuleSpecification> additionalModuleList = top.getAttachmentList(Attachments.ADDITIONAL_MODULES);
    // Must synchronize on list as subdeployments executing Phase.STRUCTURE may be concurrently modifying it
    //noinspection SynchronizationOnLocalVariableOrMethodParameter
    synchronized (additionalModuleList) {
        for (AdditionalModuleSpecification i : additionalModuleList) {
            additionalModules.add(i.getModuleIdentifier());
        }
    }
    for (final ResourceRoot resourceRoot : allResourceRoots) {
        final Manifest manifest = resourceRoot.getAttachment(Attachments.MANIFEST);
        if (manifest == null)
            continue;

        final String dependencyString = ManifestHelper.getMainAttributeValue(manifest, DEPENDENCIES_ATTR);
        if (dependencyString == null)
            continue;

        if(deploymentUnit.getParent() == null &&
                SubDeploymentMarker.isSubDeployment(resourceRoot)) {
            //we do not want ears reading sub deployments manifests
            continue;
        }

        final String[] dependencyDefs = dependencyString.split(",");
        for (final String dependencyDef : dependencyDefs) {
            final String trimmed = dependencyDef.trim();
            if(trimmed.isEmpty()) {
                continue;
            }
            final String[] dependencyParts = trimmed.split(" ");

            final ModuleIdentifier dependencyId = ModuleIdentifier.fromString(dependencyParts[0]);
            final boolean export = containsParam(dependencyParts, EXPORT_PARAM);
            final boolean optional = containsParam(dependencyParts, OPTIONAL_PARAM);
            final boolean services = containsParam(dependencyParts, SERVICES_PARAM);
            final boolean annotations = containsParam(dependencyParts, ANNOTATIONS_PARAM);
            final boolean metaInf = containsParam(dependencyParts, META_INF);
            final ModuleLoader dependencyLoader;
            if (dependencyId.getName().startsWith(ServiceModuleLoader.MODULE_PREFIX)) {
                dependencyLoader = deploymentModuleLoader;
            } else {
                dependencyLoader = Module.getBootModuleLoader();
            }
            if(annotations) {
                deploymentUnit.addToAttachmentList(Attachments.ADDITIONAL_ANNOTATION_INDEXES, dependencyId);
                if(dependencyLoader == deploymentModuleLoader && !additionalModules.contains(dependencyId)) {
                    //additional modules will not be created till much later, a dep on them would fail
                    phaseContext.addToAttachmentList(Attachments.NEXT_PHASE_DEPS, ServiceModuleLoader.moduleServiceName(dependencyId));
                }
            }

            final ModuleDependency dependency = new ModuleDependency(dependencyLoader, dependencyId, optional, export, services, true);
            if(metaInf) {
                dependency.addImportFilter(PathFilters.getMetaInfSubdirectoriesFilter(), true);
                dependency.addImportFilter(PathFilters.getMetaInfFilter(), true);
            }
            deploymentUnit.addToAttachmentList(Attachments.MANIFEST_DEPENDENCIES, dependency);
        }
    }

}
 
Example 4
Source File: ModuleSpecProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void deployModuleSpec(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {

        final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
        final DeploymentUnit parentDeployment = deploymentUnit.getParent();

        final ResourceRoot mainRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
        if (mainRoot == null)
            return;

        // Add internal resource roots
        final ModuleSpecification moduleSpec = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
        final List<ResourceRoot> resourceRoots = new ArrayList<ResourceRoot>();
        if (ModuleRootMarker.isModuleRoot(mainRoot)) {
            resourceRoots.add(mainRoot);
        }
        final List<ResourceRoot> additionalRoots = deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS);
        for (final ResourceRoot additionalRoot : additionalRoots) {
            if (ModuleRootMarker.isModuleRoot(additionalRoot) && !SubDeploymentMarker.isSubDeployment(additionalRoot)) {
                resourceRoots.add(additionalRoot);
            }
        }

        final List<ResourceRoot> parentResourceRoots = new ArrayList<>();
        if (parentDeployment != null) {
            final List<ResourceRoot> additionalParentRoots = parentDeployment.getAttachmentList(Attachments.RESOURCE_ROOTS);
            for (final ResourceRoot additionalParentRoot : additionalParentRoots) {
                if (ModuleRootMarker.isModuleRoot(additionalParentRoot) && !SubDeploymentMarker.isSubDeployment(additionalParentRoot)) {
                    parentResourceRoots.add(additionalParentRoot);
                }
            }
        }

        final ModuleIdentifier moduleIdentifier = deploymentUnit.getAttachment(Attachments.MODULE_IDENTIFIER);
        if (moduleIdentifier == null) {
            throw ServerLogger.ROOT_LOGGER.noModuleIdentifier(deploymentUnit.getName());
        }

        // create the module service and set it to attach to the deployment in the next phase
        final ServiceName moduleServiceName = createModuleService(phaseContext, deploymentUnit, resourceRoots, parentResourceRoots, moduleSpec, moduleIdentifier);
        phaseContext.addDeploymentDependency(moduleServiceName, Attachments.MODULE);

        for (final DeploymentUnit subDeployment : deploymentUnit.getAttachmentList(Attachments.SUB_DEPLOYMENTS)) {
            ModuleIdentifier moduleId = subDeployment.getAttachment(Attachments.MODULE_IDENTIFIER);
            if (moduleId != null) {
                phaseContext.addToAttachmentList(Attachments.NEXT_PHASE_DEPS, ServiceModuleLoader.moduleSpecServiceName(moduleId));
            }
        }

        if (parentDeployment == null) {
            //only top level deployment adds additional modules
            final List<AdditionalModuleSpecification> additionalModules = deploymentUnit.getAttachmentList(Attachments.ADDITIONAL_MODULES);
            for (final AdditionalModuleSpecification module : additionalModules) {
                addAllDependenciesAndPermissions(moduleSpec, module);
                List<ResourceRoot> roots = module.getResourceRoots();
                ServiceName serviceName = createModuleService(phaseContext, deploymentUnit, roots, parentResourceRoots, module, module.getModuleIdentifier());
                phaseContext.addToAttachmentList(Attachments.NEXT_PHASE_DEPS, serviceName);
            }
        }
    }