Java Code Examples for org.jboss.as.server.deployment.DeploymentUnit#putAttachment()

The following examples show how to use org.jboss.as.server.deployment.DeploymentUnit#putAttachment() . 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: AbstractLoggingDeploymentProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void registerLogContext(final DeploymentUnit deploymentUnit, final AttachmentKey<LogContext> attachmentKey, final Module module, final LogContext logContext) {
    LoggingLogger.ROOT_LOGGER.tracef("Registering LogContext %s for deployment %s", logContext, deploymentUnit.getName());
    if (WildFlySecurityManager.isChecking()) {
        WildFlySecurityManager.doUnchecked(new PrivilegedAction<Object>() {
            @Override
            public Object run() {
                logContextSelector.registerLogContext(module.getClassLoader(), logContext);
                return null;
            }
        });
    } else {
        logContextSelector.registerLogContext(module.getClassLoader(), logContext);
    }
    // Add the log context to the sub-deployment unit for later removal
    deploymentUnit.putAttachment(attachmentKey, logContext);
}
 
Example 2
Source File: KeycloakProviderDeploymentProcessor.java    From keycloak with Apache License 2.0 6 votes vote down vote up
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    KeycloakAdapterConfigService config = KeycloakAdapterConfigService.INSTANCE;
    String deploymentName = deploymentUnit.getName();

    if (config.isKeycloakServerDeployment(deploymentName)) {
        return;
    }

    KeycloakDeploymentInfo info = KeycloakProviderDependencyProcessor.getKeycloakProviderDeploymentInfo(deploymentUnit);
    
    ScriptProviderDeploymentProcessor.deploy(deploymentUnit, info);
    
    if (info.isProvider()) {
        logger.infov("Deploying Keycloak provider: {0}", deploymentUnit.getName());
        final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
        ProviderManager pm = new ProviderManager(info, module.getClassLoader());
        ProviderManagerRegistry.SINGLETON.deploy(pm);
        deploymentUnit.putAttachment(ATTACHMENT_KEY, pm);
    }
}
 
Example 3
Source File: CamelDeploymentSettingsProcessor.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {

        final DeploymentUnit depUnit = phaseContext.getDeploymentUnit();

        CamelDeploymentSettings.Builder depSettingsBuilder = depUnit
                .removeAttachment(CamelDeploymentSettings.BUILDER_ATTACHMENT_KEY);
        if (depSettingsBuilder != null && depUnit.getParent() == null) {
            /*
             * We do this only for parentless deployments because for ones that have a parent the build and attachment
             * is done by CamelDeploymentSettings.Builder.build() if the parent
             */
            final CamelDeploymentSettings depSettings = depSettingsBuilder.build();
            depUnit.putAttachment(CamelDeploymentSettings.ATTACHMENT_KEY, depSettings);
        }

    }
 
Example 4
Source File: CamelDeploymentSettingsBuilderProcessor.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {

        final DeploymentUnit depUnit = phaseContext.getDeploymentUnit();

        CamelDeploymentSettings.Builder depSettingsBuilder = depUnit.getAttachment(CamelDeploymentSettings.BUILDER_ATTACHMENT_KEY);
        if (depSettingsBuilder == null) {
            depSettingsBuilder = new CamelDeploymentSettings.Builder();
            depUnit.putAttachment(CamelDeploymentSettings.BUILDER_ATTACHMENT_KEY, depSettingsBuilder);
        } else if (depSettingsBuilder.isDisabledByJbossAll()) {
            // Camel is explicitly disabled in jboss-all.xml
            return;
        }

        depSettingsBuilder.deploymentName(getDeploymentName(depUnit));
        depSettingsBuilder.deploymentValid(isDeploymentValid(depUnit));
        depSettingsBuilder.camelActivationAnnotationPresent(hasCamelActivationAnnotations(depUnit));

        final DeploymentUnit parentDepUnit = depUnit.getParent();
        if (parentDepUnit != null) {
            final CamelDeploymentSettings.Builder parentDepSettingsBuilder = parentDepUnit.getAttachment(CamelDeploymentSettings.BUILDER_ATTACHMENT_KEY);
            if (parentDepSettingsBuilder != null) {
                // This consumer is called by CamelDeploymentSettings.Builder.build() right after the child settings are built
                Consumer<CamelDeploymentSettings> consumer = (CamelDeploymentSettings ds) -> {
                    depUnit.removeAttachment(CamelDeploymentSettings.BUILDER_ATTACHMENT_KEY);
                    depUnit.putAttachment(CamelDeploymentSettings.ATTACHMENT_KEY, ds);
                };
                parentDepSettingsBuilder.child(depSettingsBuilder, consumer);
            }
        }
    }
 
Example 5
Source File: PackageScanResolverProcessor.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
public final void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    DeploymentUnit depUnit = phaseContext.getDeploymentUnit();
    CamelDeploymentSettings depSettings = depUnit.getAttachment(CamelDeploymentSettings.ATTACHMENT_KEY);

    // Camel disabled
    if (!depSettings.isEnabled()) {
        return;
    }

    ContextCreateHandlerRegistry createHandlerRegistry = depUnit.getAttachment(CamelConstants.CONTEXT_CREATE_HANDLER_REGISTRY_KEY);
    ModuleClassLoader moduleClassLoader = depUnit.getAttachment(Attachments.MODULE).getClassLoader();
    PackageScanClassResolverAssociationHandler contextCreateHandler = new PackageScanClassResolverAssociationHandler(moduleClassLoader);
    depUnit.putAttachment(PACKAGE_SCAN_ASSOCIATION_HANDLER_ATTACHMENT_KEY, contextCreateHandler);
    createHandlerRegistry.addContextCreateHandler(moduleClassLoader, contextCreateHandler);
}
 
Example 6
Source File: JBossAllXMLParsingProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final ResourceRoot root = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);

    VirtualFile descriptor = null;
    for (final String loc : DEPLOYMENT_STRUCTURE_DESCRIPTOR_LOCATIONS) {
        final VirtualFile file = root.getRoot().getChild(loc);
        if (file.exists()) {
            descriptor = file;
            break;
        }
    }
    if(descriptor == null) {
        return;
    }
    final XMLMapper mapper = XMLMapper.Factory.create();
    final Map<QName, AttachmentKey<?>> namespaceAttachments = new HashMap<QName, AttachmentKey<?>>();
    for(final JBossAllXMLParserDescription<?> parser : deploymentUnit.getAttachmentList(JBossAllXMLParserDescription.ATTACHMENT_KEY)) {
        namespaceAttachments.put(parser.getRootElement(), parser.getAttachmentKey());
        mapper.registerRootElement(parser.getRootElement(), new JBossAllXMLElementReader(parser));
    }
    mapper.registerRootElement(new QName(Namespace.JBOSS_1_0.getUriString(), JBOSS), Parser.INSTANCE);
    mapper.registerRootElement(new QName(Namespace.NONE.getUriString(), JBOSS), Parser.INSTANCE);

    final JBossAllXmlParseContext context = new JBossAllXmlParseContext(deploymentUnit);
    parse(descriptor, mapper, context);

    //we use this map to detect the presence of two different but functionally equivalent namespaces
    final Map<AttachmentKey<?>, QName> usedNamespaces = new HashMap<AttachmentKey<?>, QName>();
    for(Map.Entry<QName, Object> entry : context.getParseResults().entrySet()) {
        final AttachmentKey attachmentKey = namespaceAttachments.get(entry.getKey());
        if(usedNamespaces.containsKey(attachmentKey)) {
            throw ServerLogger.ROOT_LOGGER.equivalentNamespacesInJBossXml(entry.getKey(), usedNamespaces.get(attachmentKey));
        }
        usedNamespaces.put(attachmentKey, entry.getKey());
        deploymentUnit.putAttachment(attachmentKey, entry.getValue());
    }
}
 
Example 7
Source File: ModuleIdentifierProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
    final DeploymentUnit parent = deploymentUnit.getParent();
    final DeploymentUnit topLevelDeployment = parent == null ? deploymentUnit : parent;
    final VirtualFile toplevelRoot = topLevelDeployment.getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot();
    final ModuleIdentifier moduleIdentifier = createModuleIdentifier(deploymentUnit.getName(), deploymentRoot, topLevelDeployment, toplevelRoot, deploymentUnit.getParent() == null);
    deploymentUnit.putAttachment(Attachments.MODULE_IDENTIFIER, moduleIdentifier);
}
 
Example 8
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 9
Source File: ModuleSpecProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private ServiceName createModuleService(final DeploymentPhaseContext phaseContext, final DeploymentUnit deploymentUnit,
                                        final List<ResourceRoot> resourceRoots, final List<ResourceRoot> parentResourceRoots,
                                        final ModuleSpecification moduleSpecification, final ModuleIdentifier moduleIdentifier) throws DeploymentUnitProcessingException {
    logger.debugf("Creating module: %s", moduleIdentifier);
    final ModuleSpec.Builder specBuilder = ModuleSpec.build(moduleIdentifier);
    for (final DependencySpec dep : moduleSpecification.getModuleSystemDependencies()) {
        specBuilder.addDependency(dep);
    }
    final List<ModuleDependency> dependencies = moduleSpecification.getSystemDependencies();
    final List<ModuleDependency> localDependencies = moduleSpecification.getLocalDependencies();
    final List<ModuleDependency> userDependencies = moduleSpecification.getUserDependencies();

    final List<PermissionFactory> permFactories = moduleSpecification.getPermissionFactories();

    installAliases(moduleSpecification, moduleIdentifier, deploymentUnit, phaseContext);

    // add additional resource loaders first
    for (final ResourceLoaderSpec resourceLoaderSpec : moduleSpecification.getResourceLoaders()) {
        logger.debugf("Adding resource loader %s to module %s", resourceLoaderSpec, moduleIdentifier);
        specBuilder.addResourceRoot(resourceLoaderSpec);
    }

    for (final ResourceRoot resourceRoot : resourceRoots) {
        logger.debugf("Adding resource %s to module %s", resourceRoot.getRoot(), moduleIdentifier);
        addResourceRoot(specBuilder, resourceRoot, permFactories);
    }

    createDependencies(specBuilder, dependencies, false);
    createDependencies(specBuilder, userDependencies, false);

    if (moduleSpecification.isLocalLast()) {
        createDependencies(specBuilder, localDependencies, moduleSpecification.isLocalDependenciesTransitive());
        specBuilder.addDependency(DependencySpec.createLocalDependencySpec());
    } else {
        specBuilder.addDependency(DependencySpec.createLocalDependencySpec());
        createDependencies(specBuilder, localDependencies, moduleSpecification.isLocalDependenciesTransitive());
    }

    final Enumeration<Permission> e = DEFAULT_PERMISSIONS.elements();
    while (e.hasMoreElements()) {
        permFactories.add(new ImmediatePermissionFactory(e.nextElement()));
    }
    // TODO: servlet context temp dir FilePermission

    // add file permissions for parent roots
    for (ResourceRoot additionalParentRoot : parentResourceRoots) {
        final VirtualFile root = additionalParentRoot.getRoot();
        // start with the root
        permFactories.add(new ImmediatePermissionFactory(
                new VirtualFilePermission(root.getPathName(), VirtualFilePermission.FLAG_READ)));
        // also include all children, recursively
        permFactories.add(new ImmediatePermissionFactory(
                new VirtualFilePermission(root.getChild("-").getPathName(), VirtualFilePermission.FLAG_READ)));
    }

    FactoryPermissionCollection permissionCollection = new FactoryPermissionCollection(permFactories.toArray(new PermissionFactory[permFactories.size()]));

    specBuilder.setPermissionCollection(permissionCollection);
    deploymentUnit.putAttachment(Attachments.MODULE_PERMISSIONS, permissionCollection);

    final DelegatingClassFileTransformer delegatingClassFileTransformer = new DelegatingClassFileTransformer();
    specBuilder.setClassFileTransformer(delegatingClassFileTransformer);
    deploymentUnit.putAttachment(DelegatingClassFileTransformer.ATTACHMENT_KEY, delegatingClassFileTransformer);
    final ModuleSpec moduleSpec = specBuilder.create();
    final ServiceName moduleSpecServiceName = ServiceModuleLoader.moduleSpecServiceName(moduleIdentifier);

    ModuleDefinition moduleDefinition = new ModuleDefinition(moduleIdentifier, new HashSet<>(moduleSpecification.getAllDependencies()), moduleSpec);

    final ValueService<ModuleDefinition> moduleSpecService = new ValueService<>(new ImmediateValue<>(moduleDefinition));
    final ServiceBuilder sb = phaseContext.getServiceTarget().addService(moduleSpecServiceName, moduleSpecService);
    sb.requires(deploymentUnit.getServiceName());
    sb.requires(phaseContext.getPhaseServiceName());
    sb.setInitialMode(Mode.ON_DEMAND);
    sb.install();

    ModuleResolvePhaseService.installService(phaseContext.getServiceTarget(), moduleDefinition);

    return ModuleLoadService.install(phaseContext.getServiceTarget(), moduleIdentifier, dependencies, localDependencies, userDependencies);
}
 
Example 10
Source File: VirtualDomainMarkerUtility.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static void virtualDomainRequired(final DeploymentUnit deploymentUnit) {
    DeploymentUnit rootUnit = toRoot(deploymentUnit);
    rootUnit.putAttachment(REQUIRED, Boolean.TRUE);
}
 
Example 11
Source File: RequestControllerActivationMarker.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
static void mark(DeploymentUnit du) {
    du.putAttachment(MARKER, true);
}
 
Example 12
Source File: DeploymentRootMountProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if(deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT) != null) {
        return;
    }
    final DeploymentMountProvider deploymentMountProvider = deploymentUnit.getAttachment(Attachments.SERVER_DEPLOYMENT_REPOSITORY);
    if(deploymentMountProvider == null) {
        throw ServerLogger.ROOT_LOGGER.noDeploymentRepositoryAvailable();
    }

    final String deploymentName = deploymentUnit.getName();
    final VirtualFile deploymentContents = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_CONTENTS);

    // internal deployments do not have any contents, so there is nothing to mount
    if (deploymentContents == null)
        return;

    final VirtualFile deploymentRoot;
    final MountHandle mountHandle;
    if (deploymentContents.isDirectory()) {
        // use the contents directly
        deploymentRoot = deploymentContents;
        // nothing was mounted
        mountHandle = null;
        ExplodedDeploymentMarker.markAsExplodedDeployment(deploymentUnit);

    } else {
        // The mount point we will use for the repository file
        deploymentRoot = VFS.getChild("content/" + deploymentName);

        boolean failed = false;
        Closeable handle = null;
        try {
            final boolean mountExploded = MountExplodedMarker.isMountExploded(deploymentUnit);
            final MountType type;
            if(mountExploded) {
                type = MountType.EXPANDED;
            } else if (deploymentName.endsWith(".xml")) {
                type = MountType.REAL;
            } else {
                type = MountType.ZIP;
            }
            handle = deploymentMountProvider.mountDeploymentContent(deploymentContents, deploymentRoot, type);
            mountHandle = MountHandle.create(handle);
        } catch (IOException e) {
            failed = true;
            throw ServerLogger.ROOT_LOGGER.deploymentMountFailed(e);
        } finally {
            if(failed) {
                VFSUtils.safeClose(handle);
            }
        }
    }
    final ResourceRoot resourceRoot = new ResourceRoot(deploymentRoot, mountHandle);
    ModuleRootMarker.mark(resourceRoot);
    deploymentUnit.putAttachment(Attachments.DEPLOYMENT_ROOT, resourceRoot);
    deploymentUnit.putAttachment(Attachments.MODULE_SPECIFICATION, new ModuleSpecification());
}
 
Example 13
Source File: ProcessApplicationAttachments.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
/** 
 * marks a a {@link DeploymentUnit} as a process application 
 */
public static void mark(DeploymentUnit unit) {
  unit.putAttachment(MARKER, Boolean.TRUE);    
}
 
Example 14
Source File: ProcessApplicationAttachments.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
/**
 * Attach the {@link ComponentDescription} for the {@link AbstractProcessApplication} component   
 */
public static void attachProcessApplicationComponent(DeploymentUnit deploymentUnit, ComponentDescription componentDescription){
  deploymentUnit.putAttachment(PA_COMPONENT, componentDescription);
}
 
Example 15
Source File: ProcessApplicationAttachments.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
/**
 * Attach the {@link AnnotationInstance}s for the PostDeploy methods
 */
public static void attachPostDeployDescription(DeploymentUnit deploymentUnit, AnnotationInstance annotation){
  deploymentUnit.putAttachment(POST_DEPLOY_METHOD, annotation);      
}
 
Example 16
Source File: ProcessApplicationAttachments.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
/**
 * Attach the {@link AnnotationInstance}s for the PreUndeploy methods
 */
public static void attachPreUndeployDescription(DeploymentUnit deploymentUnit, AnnotationInstance annotation){
  deploymentUnit.putAttachment(PRE_UNDEPLOY_METHOD, annotation);      
}
 
Example 17
Source File: ProcessApplicationAttachments.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
/** 
 * marks a a {@link DeploymentUnit} as a process application 
 */
public static void mark(DeploymentUnit unit) {
  unit.putAttachment(MARKER, Boolean.TRUE);    
}
 
Example 18
Source File: ProcessApplicationAttachments.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
/**
 * Attach the {@link ComponentDescription} for the {@link AbstractProcessApplication} component   
 */
public static void attachProcessApplicationComponent(DeploymentUnit deploymentUnit, ComponentDescription componentDescription){
  deploymentUnit.putAttachment(PA_COMPONENT, componentDescription);
}
 
Example 19
Source File: ProcessApplicationAttachments.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
/**
 * Attach the {@link AnnotationInstance}s for the PostDeploy methods
 */
public static void attachPostDeployDescription(DeploymentUnit deploymentUnit, AnnotationInstance annotation){
  deploymentUnit.putAttachment(POST_DEPLOY_METHOD, annotation);      
}
 
Example 20
Source File: ProcessApplicationAttachments.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
/**
 * Attach the {@link AnnotationInstance}s for the PreUndeploy methods
 */
public static void attachPreUndeployDescription(DeploymentUnit deploymentUnit, AnnotationInstance annotation){
  deploymentUnit.putAttachment(PRE_UNDEPLOY_METHOD, annotation);      
}