Java Code Examples for org.jboss.modules.Module#getBootModuleLoader()

The following examples show how to use org.jboss.modules.Module#getBootModuleLoader() . 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: DriverDependenciesProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
    final ModuleLoader moduleLoader = Module.getBootModuleLoader();
    if (deploymentUnit.hasAttachment(Attachments.RESOURCE_ROOTS)) {
        final List<ResourceRoot> resourceRoots = deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS);
        for (ResourceRoot root : resourceRoots) {
            VirtualFile child = root.getRoot().getChild(SERVICE_FILE_NAME);
            if (child.exists()) {
                moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, JTA, false, false, false, false));
                break;
            }
        }
    }
}
 
Example 2
Source File: KeycloakProviderDependencyProcessor.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 = getKeycloakProviderDeploymentInfo(deploymentUnit);
    if (info.hasServices()) {
        final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
        final ModuleLoader moduleLoader = Module.getBootModuleLoader();
        moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, KEYCLOAK_COMMON, false, false, false, false));
        moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, KEYCLOAK_CORE, false, false, false, false));
        moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, KEYCLOAK_SERVER_SPI, false, false, false, false));
        moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, KEYCLOAK_SERVER_SPI_PRIVATE, false, false, false, false));
        moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, JAXRS, false, false, false, false));
        moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, RESTEASY, false, false, false, false));
        moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, APACHE, false, false, false, false));
        moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, KEYCLOAK_JPA, false, false, false, false));
    }
}
 
Example 3
Source File: KeycloakDependencyProcessor.java    From keycloak with Apache License 2.0 6 votes vote down vote up
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();

    if (Configuration.INSTANCE.getSecureDeployment(deploymentUnit) == null) {
        WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
        if (warMetaData == null) {
            return;
        }
        JBossWebMetaData webMetaData = warMetaData.getMergedJBossWebMetaData();
        if (webMetaData == null) {
            return;
        }
        LoginConfigMetaData loginConfig = webMetaData.getLoginConfig();
        if (loginConfig == null) return;
        if (loginConfig.getAuthMethod() == null) return;
        if (!loginConfig.getAuthMethod().equals("KEYCLOAK-SAML")) return;
    }

     // Next phase, need to detect if this is a Keycloak deployment.  If not, don't add the modules.

    final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
    final ModuleLoader moduleLoader = Module.getBootModuleLoader();
    addCommonModules(moduleSpecification, moduleLoader);
    addPlatformSpecificModules(phaseContext, moduleSpecification, moduleLoader);
}
 
Example 4
Source File: KeycloakDependencyProcessor.java    From keycloak with Apache License 2.0 6 votes vote down vote up
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();

    if (Configuration.INSTANCE.getSecureDeployment(deploymentUnit) == null) {
        WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
        if (warMetaData == null) {
            return;
        }
        JBossWebMetaData webMetaData = warMetaData.getMergedJBossWebMetaData();
        if (webMetaData == null) {
            return;
        }
        LoginConfigMetaData loginConfig = webMetaData.getLoginConfig();
        if (loginConfig == null) return;
        if (loginConfig.getAuthMethod() == null) return;
        if (!loginConfig.getAuthMethod().equals("KEYCLOAK-SAML")) return;
    }

    final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
    final ModuleLoader moduleLoader = Module.getBootModuleLoader();
    addCommonModules(moduleSpecification, moduleLoader);
    addPlatformSpecificModules(moduleSpecification, moduleLoader);
}
 
Example 5
Source File: KeycloakDependencyProcessor.java    From keycloak with Apache License 2.0 6 votes vote down vote up
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (!KeycloakAdapterConfigService.getInstance().isSecureDeployment(deploymentUnit)) {
        WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
        if (warMetaData == null) {
            return;
        }
        JBossWebMetaData webMetaData = warMetaData.getMergedJBossWebMetaData();
        if (webMetaData == null) {
            return;
        }
        LoginConfigMetaData loginConfig = webMetaData.getLoginConfig();
        if (loginConfig == null) return;
        if (loginConfig.getAuthMethod() == null) return;
        if (!loginConfig.getAuthMethod().equals("KEYCLOAK")) return;
    }

    final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
    final ModuleLoader moduleLoader = Module.getBootModuleLoader();
    addCommonModules(moduleSpecification, moduleLoader);
    addPlatformSpecificModules(phaseContext, moduleSpecification, moduleLoader);
}
 
Example 6
Source File: KeycloakDependencyProcessor.java    From keycloak with Apache License 2.0 6 votes vote down vote up
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();

    if (!KeycloakAdapterConfigService.getInstance().isSecureDeployment(deploymentUnit)) {
        WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
        if (warMetaData == null) {
            return;
        }
        JBossWebMetaData webMetaData = warMetaData.getMergedJBossWebMetaData();
        if (webMetaData == null) {
            return;
        }
        LoginConfigMetaData loginConfig = webMetaData.getLoginConfig();
        if (loginConfig == null) return;
        if (loginConfig.getAuthMethod() == null) return;
        if (!loginConfig.getAuthMethod().equals("KEYCLOAK")) return;
    }

    final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
    final ModuleLoader moduleLoader = Module.getBootModuleLoader();
    addCommonModules(moduleSpecification, moduleLoader);
    addPlatformSpecificModules(moduleSpecification, moduleLoader);
}
 
Example 7
Source File: ModuleInfoHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    ModelNode model = new ModelNode();
    populateModel(operation, model);
    String moduleName = MODULE_NAME.resolveModelAttribute(context, model).asString();
    String slot = MODULE_SLOT.resolveModelAttribute(context, model).asString();
    ModuleIdentifier id = ModuleIdentifier.create(moduleName, slot);
    ModuleLoader loader = Module.getBootModuleLoader();
    try {
        ModuleLoaderMXBean mxBean = getMxBean(loader);
        ModuleInfo moduleInfo = mxBean.getModuleDescription(id.toString());
        context.getResult().set(populateModuleInfo(moduleInfo));
    } catch (Exception e) {
        throw ServerLogger.ROOT_LOGGER.couldNotGetModuleInfo(id.toString(), e);
    }
}
 
Example 8
Source File: BootstrapPersister.java    From thorntail with Apache License 2.0 6 votes vote down vote up
private XmlConfigurationPersister createDelegate(File configFile) {

        QName rootElement = new QName(Namespace.CURRENT.getUriString(), "server");
        ExtensionRegistry extensionRegistry = new ExtensionRegistry(
                ProcessType.SELF_CONTAINED,
                new RunningModeControl(RunningMode.NORMAL),
                null,
                null,
                null,
                RuntimeHostControllerInfoAccessor.SERVER
        );
        StandaloneXml parser = new StandaloneXml(Module.getBootModuleLoader(), Executors.newSingleThreadExecutor(), extensionRegistry);

        XmlConfigurationPersister persister = new XmlConfigurationPersister(
                configFile, rootElement, parser, parser, false
        );

        return persister;

    }
 
Example 9
Source File: ConfigurationPersisterFactory.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static ExtensibleConfigurationPersister createDomainXmlConfigurationPersister(final ConfigurationFile file, ExecutorService executorService, ExtensionRegistry extensionRegistry, final HostControllerEnvironment environment) {
    DomainXml domainXml = new DomainXml(Module.getBootModuleLoader(), executorService, extensionRegistry);

    boolean suppressLoad = false;
    ConfigurationFile.InteractionPolicy policy = file.getInteractionPolicy();
    final boolean isReloaded = environment.getRunningModeControl().isReloaded();

    if (!isReloaded && (policy == ConfigurationFile.InteractionPolicy.NEW && (file.getBootFile().exists() && file.getBootFile().length() != 0))) {
        throw HostControllerLogger.ROOT_LOGGER.cannotOverwriteDomainXmlWithEmpty(file.getBootFile().getName());
    }

    if (!isReloaded && (policy == ConfigurationFile.InteractionPolicy.NEW || policy == ConfigurationFile.InteractionPolicy.DISCARD)) {
        suppressLoad = true;
    }

    BackupXmlConfigurationPersister persister = new BackupXmlConfigurationPersister(file, new QName(Namespace.CURRENT.getUriString(), "domain"), domainXml, domainXml, suppressLoad);
    for (Namespace namespace : Namespace.domainValues()) {
        if (!namespace.equals(Namespace.CURRENT)) {
            persister.registerAdditionalRootElement(new QName(namespace.getUriString(), "domain"), domainXml);
        }
    }
    extensionRegistry.setWriterRegistry(persister);
    return persister;
}
 
Example 10
Source File: ConfigurationPersisterFactory.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static ExtensibleConfigurationPersister createHostXmlConfigurationPersister(final ConfigurationFile file, final HostControllerEnvironment environment,
                                                                                   final ExecutorService executorService, final ExtensionRegistry hostExtensionRegistry,
                                                                                   final LocalHostControllerInfo localHostControllerInfo) {
    String defaultHostname = localHostControllerInfo.getLocalHostName();
    if (environment.getRunningModeControl().isReloaded()) {
        if (environment.getRunningModeControl().getReloadHostName() != null) {
            defaultHostname = environment.getRunningModeControl().getReloadHostName();
        }
    }
    HostXml hostXml = new HostXml(defaultHostname, environment.getRunningModeControl().getRunningMode(),
            environment.isUseCachedDc(), Module.getBootModuleLoader(), executorService, hostExtensionRegistry);
    BackupXmlConfigurationPersister persister = new BackupXmlConfigurationPersister(file, new QName(Namespace.CURRENT.getUriString(), "host"), hostXml, hostXml, false);
    for (Namespace namespace : Namespace.domainValues()) {
        if (!namespace.equals(Namespace.CURRENT)) {
            persister.registerAdditionalRootElement(new QName(namespace.getUriString(), "host"), hostXml);
        }
    }
    hostExtensionRegistry.setWriterRegistry(persister);
    return persister;
}
 
Example 11
Source File: LoggingDependencyDeploymentProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void deploy(final DeploymentPhaseContext phaseContext) {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
    final ModuleLoader moduleLoader = Module.getBootModuleLoader();
    // Add the logging modules
    for (String moduleId : DUP_INJECTED_LOGGING_MODULES) {
        try {
            LoggingLogger.ROOT_LOGGER.tracef("Adding module '%s' to deployment '%s'", moduleId, deploymentUnit.getName());
            moduleLoader.loadModule(moduleId);
            moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, moduleId, false, false, false, false));
        } catch (ModuleLoadException ex) {
            LoggingLogger.ROOT_LOGGER.debugf("Module not found: %s", moduleId);
        }
    }
}
 
Example 12
Source File: Seam2Processor.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Lookup Seam integration resource loader.
 * @return the Seam integration resource loader
 * @throws DeploymentUnitProcessingException for any error
 */
protected synchronized ResourceRoot getSeamIntResourceRoot() throws DeploymentUnitProcessingException {
    try {
        if (seamIntResourceRoot == null) {
            final ModuleLoader moduleLoader = Module.getBootModuleLoader();
            Module extModule = moduleLoader.loadModule(EXT_CONTENT_MODULE);
            URL url = extModule.getExportedResource(SEAM_INT_JAR);
            if (url == null)
                throw ServerLogger.ROOT_LOGGER.noSeamIntegrationJarPresent(extModule);

            File file = new File(url.toURI());
            VirtualFile vf = VFS.getChild(file.toURI());
            final Closeable mountHandle = VFS.mountZip(file, vf, TempFileProviderService.provider());
            Service<Closeable> mountHandleService = new Service<Closeable>() {
                public void start(StartContext startContext) throws StartException {
                }

                public void stop(StopContext stopContext) {
                    VFSUtils.safeClose(mountHandle);
                }

                public Closeable getValue() throws IllegalStateException, IllegalArgumentException {
                    return mountHandle;
                }
            };
            ServiceBuilder<Closeable> builder = serviceTarget.addService(ServiceName.JBOSS.append(SEAM_INT_JAR),
                    mountHandleService);
            builder.setInitialMode(ServiceController.Mode.ACTIVE).install();
            serviceTarget = null; // our cleanup service install work is done

            MountHandle dummy = MountHandle.create(null); // actual close is done by the MSC service above
            seamIntResourceRoot = new ResourceRoot(vf, dummy);
        }
        return seamIntResourceRoot;
    } catch (Exception e) {
        throw new DeploymentUnitProcessingException(e);
    }
}
 
Example 13
Source File: Seam2Processor.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (deploymentUnit.getParent() != null) {
        return;
    }

    final List<DeploymentUnit> deploymentUnits = new ArrayList<DeploymentUnit>();
    deploymentUnits.add(deploymentUnit);
    deploymentUnits.addAll(deploymentUnit.getAttachmentList(Attachments.SUB_DEPLOYMENTS));

    for (DeploymentUnit unit : deploymentUnits) {

        final ResourceRoot mainRoot = unit.getAttachment(Attachments.DEPLOYMENT_ROOT);
        if (mainRoot == null)
            continue;

        VirtualFile root = mainRoot.getRoot();
        for (String path : SEAM_FILES) {
            if (root.getChild(path).exists()) {
                final ModuleSpecification moduleSpecification = deploymentUnit
                        .getAttachment(Attachments.MODULE_SPECIFICATION);
                final ModuleLoader moduleLoader = Module.getBootModuleLoader();
                moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, VFS_MODULE, false, false, false,
                        false)); // for VFS scanner

                try {
                    ResourceLoader resourceLoader = ResourceLoaders.createJarResourceLoader(SEAM_INT_JAR, new JarFile(
                            getSeamIntResourceRoot().getRoot().getPathName()));
                    moduleSpecification.addResourceLoader(ResourceLoaderSpec.createResourceLoaderSpec(resourceLoader));
                } catch (Exception e) {
                    throw new DeploymentUnitProcessingException(e);
                }

                unit.addToAttachmentList(Attachments.RESOURCE_ROOTS, getSeamIntResourceRoot());
                return;
            }
        }
    }
}
 
Example 14
Source File: ConfigurationPersisterFactory.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static ExtensibleConfigurationPersister createRemoteBackupDomainXmlConfigurationPersister(final File configDir, ExecutorService executorService, ExtensionRegistry extensionRegistry) {
    DomainXml domainXml = new DomainXml(Module.getBootModuleLoader(), executorService, extensionRegistry);
    File bootFile = new File(configDir, CACHED_DOMAIN_XML_BOOTFILE);
    File file = new File(configDir, CACHED_DOMAIN_XML);
    BackupRemoteDomainXmlPersister persister = new BackupRemoteDomainXmlPersister(file, bootFile, new QName(Namespace.CURRENT.getUriString(), "domain"), domainXml, domainXml);
    for (Namespace namespace : Namespace.domainValues()) {
        if (!namespace.equals(Namespace.CURRENT)) {
            persister.registerAdditionalRootElement(new QName(namespace.getUriString(), "domain"), domainXml);
        }
    }
    extensionRegistry.setWriterRegistry(persister);
    return persister;
}
 
Example 15
Source File: ModuleLoadingResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void storeRepoRoots(final ModelNode list) throws NoSuchFieldException, IllegalAccessException {
    // TODO get a formal API from jboss-modules to replace this reflection
    ModuleLoader loader = Module.getBootModuleLoader();
    if (loader instanceof LocalModuleLoader) {
        LocalModuleLoader lml = (LocalModuleLoader) loader;
        Field findersField = ModuleLoader.class.getDeclaredField("finders");
        Field repoRootsField = null;
        findersField.setAccessible(true);
        try {
            Object[] finders = (Object[]) findersField.get(lml);
            if (finders.length > 0 && finders[0] instanceof LocalModuleFinder) {
                LocalModuleFinder lmf = (LocalModuleFinder) finders[0];
                repoRootsField = LocalModuleFinder.class.getDeclaredField("repoRoots") ;
                repoRootsField.setAccessible(true);
                File[] repoRoots = (File[]) repoRootsField.get(lmf);
                for (File file : repoRoots) {
                    list.add(file.getAbsolutePath());
                }
            }
        } finally {
            findersField.setAccessible(false);
            if (repoRootsField != null) {
                repoRootsField.setAccessible(false);
            }
        }
    }

}
 
Example 16
Source File: Bootstrap.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Get the factory for the configuration persister to use.
 *
 * @return the configuration persister factory
 */
public synchronized ConfigurationPersisterFactory getConfigurationPersisterFactory() {
    if (configurationPersisterFactory == null) {
        configurationPersisterFactory = new ConfigurationPersisterFactory() {
            @Override
            public ExtensibleConfigurationPersister createConfigurationPersister(ServerEnvironment serverEnvironment, ExecutorService executorService) {
                ConfigurationFile configurationFile = serverEnvironment.getServerConfigurationFile();
                if (runningModeControl.isReloaded()) {
                    configurationFile.resetBootFile(runningModeControl.isUseCurrentConfig(), runningModeControl.getAndClearNewBootFileName());
                }
                QName rootElement = new QName(Namespace.CURRENT.getUriString(), "server");
                StandaloneXml parser = new StandaloneXml(Module.getBootModuleLoader(), executorService, extensionRegistry);
                XmlConfigurationPersister persister;
                if (configurationFile.useGit()) {
                    persister = new GitConfigurationPersister(serverEnvironment.getGitRepository(), configurationFile, rootElement, parser, parser,
                            runningModeControl.isReloaded());
                } else {
                    persister = new BackupXmlConfigurationPersister(configurationFile, rootElement, parser, parser,
                            runningModeControl.isReloaded(), serverEnvironment.getLaunchType() == ServerEnvironment.LaunchType.EMBEDDED);
                }
                for (Namespace namespace : Namespace.domainValues()) {
                    if (!namespace.equals(Namespace.CURRENT)) {
                        persister.registerAdditionalRootElement(new QName(namespace.getUriString(), "server"), parser);
                    }
                }
                extensionRegistry.setWriterRegistry(persister);
                return persister;
            }
        };
    }
    return configurationPersisterFactory;
}
 
Example 17
Source File: EESecurityDependencyProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void deploy(DeploymentPhaseContext phaseContext) {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final ModuleLoader moduleLoader = Module.getBootModuleLoader();
    final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);

    moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, JACC_API, false, false, true, false));
    moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, AUTH_MESSAGE_API, false, false, true, false));
}
 
Example 18
Source File: DependencyProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void deploy(DeploymentPhaseContext context) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = context.getDeploymentUnit();
    final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
    final ModuleLoader moduleLoader = Module.getBootModuleLoader();

    moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, elytronIdentifier, false, false, true, false));
}
 
Example 19
Source File: ConfigurationPersisterFactory.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static ExtensibleConfigurationPersister createTransientDomainXmlConfigurationPersister(ExecutorService executorService, ExtensionRegistry extensionRegistry) {
    DomainXml domainXml = new DomainXml(Module.getBootModuleLoader(), executorService, extensionRegistry);
    ExtensibleConfigurationPersister persister = new NullConfigurationPersister(domainXml);
    extensionRegistry.setWriterRegistry(persister);
    return persister;
}
 
Example 20
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);
        }
    }

}