Java Code Examples for org.jboss.modules.ModuleIdentifier#create()

The following examples show how to use org.jboss.modules.ModuleIdentifier#create() . 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: 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 2
Source File: ExtensionIndexService.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static ModuleIdentifier moduleIdentifier(final String name, final String minSpecVersion,
        final String minImplVersion, final String requiredVendorId) {
    StringBuilder nameBuilder = new StringBuilder();
    nameBuilder.append(MODULE_PREFIX);
    nameBuilder.append(name);
    if (minSpecVersion != null) {
        nameBuilder.append(".spec-");
        nameBuilder.append(minSpecVersion);
    }
    if (minImplVersion != null) {
        nameBuilder.append(".impl-");
        nameBuilder.append(minImplVersion);
    }
    if (requiredVendorId != null) {
        nameBuilder.append(".vendor-");
        nameBuilder.append(requiredVendorId);
    }
    return ModuleIdentifier.create(nameBuilder.toString());
}
 
Example 3
Source File: EmbeddedProcessFactory.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void setupVfsModule(final ModuleLoader moduleLoader) {
    final ModuleIdentifier vfsModuleID = ModuleIdentifier.create(MODULE_ID_VFS);
    final Module vfsModule;
    try {
        vfsModule = moduleLoader.loadModule(vfsModuleID);
    } catch (final ModuleLoadException mle) {
        throw EmbeddedLogger.ROOT_LOGGER.moduleLoaderError(mle,MODULE_ID_VFS, moduleLoader);
    }
    Module.registerURLStreamHandlerFactoryModule(vfsModule);
}
 
Example 4
Source File: ConfigSupport.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
public static void applyConfigChange(Path jbossHome, List<String> configs, boolean enable) throws Exception {

        IllegalStateAssertion.assertFalse(configs.isEmpty(), "No configurations specified");

        Iterator<ConfigPlugin> itsrv;
        ClassLoader classLoader = ConfigSupport.class.getClassLoader();

        // In wildfly every plugin lives in its own module.
        // The module identity corresponds to the config name
        if (classLoader instanceof ModuleClassLoader) {
            List<ConfigPlugin> plugins = new ArrayList<>();
            for (String config : configs) {
                ModuleLoader moduleLoader = Module.getCallerModuleLoader();
                ModuleIdentifier modid = ModuleIdentifier.create("org.wildfly.extras.config.plugin." + config);
                ModuleClassLoader modcl = moduleLoader.loadModule(modid).getClassLoader();
                Iterator<ConfigPlugin> auxit = ServiceLoader.load(ConfigPlugin.class, modcl).iterator();
                while (auxit.hasNext()) {
                    plugins.add(auxit.next());
                }
            }
            itsrv = plugins.iterator();
        } else {
            itsrv = ServiceLoader.load(ConfigPlugin.class, classLoader).iterator();
        }

        while (itsrv.hasNext()) {
            ConfigPlugin plugin = itsrv.next();
            if (configs.contains(plugin.getConfigName())) {

                ConfigLogger.info("Processing config for: " + plugin.getConfigName());

                applyLayerChanges(jbossHome, plugin, enable);
                applyConfigurationChanges(jbossHome, plugin, enable);
            }
        }
    }
 
Example 5
Source File: ManifestClassPathProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private ModuleIdentifier createAdditionalModule(final ResourceRoot resourceRoot, final DeploymentUnit topLevelDeployment, final VirtualFile topLevelRoot, final Map<VirtualFile, AdditionalModuleSpecification> additionalModules, final VirtualFile classPathFile, final ArrayDeque<RootEntry> resourceRoots) throws DeploymentUnitProcessingException {
    final ResourceRoot root = createResourceRoot(classPathFile, topLevelDeployment, topLevelRoot);
    final String pathName = root.getRoot().getPathNameRelativeTo(topLevelRoot);
    ModuleIdentifier identifier = ModuleIdentifier.create(ServiceModuleLoader.MODULE_PREFIX + topLevelDeployment.getName() + "." + pathName);
    AdditionalModuleSpecification module = new AdditionalModuleSpecification(identifier, root);
    topLevelDeployment.addToAttachmentList(Attachments.ADDITIONAL_MODULES, module);
    additionalModules.put(classPathFile, module);
    resourceRoot.addToAttachmentList(Attachments.CLASS_PATH_RESOURCE_ROOTS, root);

    //add this to the list of roots to be processed, so transitive class path entries will be respected
    resourceRoots.add(new RootEntry(module, root));
    return identifier;

}
 
Example 6
Source File: CXFResourcesTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testAccessFromCamelComponentModule() throws Exception {
    ModuleLoader moduleLoader = Module.getCallerModuleLoader();
    ModuleIdentifier modid = ModuleIdentifier.create("org.apache.camel.component");
    ModuleClassLoader classLoader = moduleLoader.loadModule(modid).getClassLoader();
    URL resurl = classLoader.getResource("META-INF/cxf/cxf.xml");
    Assert.assertNotNull("URL not null", resurl);
}
 
Example 7
Source File: ModuleIdentifierProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static ModuleIdentifier createModuleIdentifier(final String deploymentUnitName, final ResourceRoot deploymentRoot, final DeploymentUnit topLevelDeployment, final VirtualFile toplevelRoot, final boolean topLevel) {
    // generate the module identifier for the deployment
    final ModuleIdentifier moduleIdentifier;
    if (topLevel) {
        moduleIdentifier = ModuleIdentifier.create(ServiceModuleLoader.MODULE_PREFIX + deploymentUnitName);
    } else {
        String relativePath = deploymentRoot.getRoot().getPathNameRelativeTo(toplevelRoot);
        moduleIdentifier = ModuleIdentifier.create(ServiceModuleLoader.MODULE_PREFIX + topLevelDeployment.getName() + '.' + relativePath.replace('/', '.'));
    }
    return moduleIdentifier;
}
 
Example 8
Source File: CXFResourcesTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testAccessFromCXFComponentModule() throws Exception {
    ModuleLoader moduleLoader = Module.getCallerModuleLoader();
    ModuleIdentifier modid = ModuleIdentifier.create("org.apache.camel.component.cxf");
    ModuleClassLoader classLoader = moduleLoader.loadModule(modid).getClassLoader();
    URL resurl = classLoader.getResource("META-INF/cxf/cxf.xml");
    Assert.assertNotNull("URL not null", resurl);
}
 
Example 9
Source File: ExternalModuleService.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public ModuleIdentifier addExternalModule(String moduleName, String path, ServiceRegistry serviceRegistry, ServiceTarget serviceTarget) {
    ModuleIdentifier identifier = ModuleIdentifier.create(EXTERNAL_MODULE_PREFIX + moduleName);
    ServiceName serviceName = ServiceModuleLoader.moduleSpecServiceName(identifier);
    ServiceController<?> controller = serviceRegistry.getService(serviceName);
    if (controller == null) {
        ExternalModuleSpecService service = new ExternalModuleSpecService(identifier, new File(path));
        serviceTarget.addService(serviceName)
                .setInstance(service)
                .setInitialMode(Mode.ON_DEMAND)
                .install();
    }
    return identifier;
}
 
Example 10
Source File: SpringExcludedPathsTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testAccessFromCamelSpringModule() throws Exception {
    ModuleLoader moduleLoader = Module.getCallerModuleLoader();
    ModuleIdentifier modid = ModuleIdentifier.create("org.apache.camel.spring");
    ModuleClassLoader classLoader = moduleLoader.loadModule(modid).getClassLoader();
    Class<?> loadedClass = classLoader.loadClass("org.apache.camel.spring.SpringCamelContext");
    Assert.assertNotNull("Class not null", loadedClass);
    loadedClass = classLoader.loadClass("org.apache.camel.spring.remoting.CamelServiceExporter");
    Assert.assertNotNull("Class not null", loadedClass);
}
 
Example 11
Source File: CXFResourcesTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testAccessFromCXFModule() throws Exception {
    ModuleLoader moduleLoader = Module.getCallerModuleLoader();
    ModuleIdentifier modid = ModuleIdentifier.create("org.apache.cxf");
    ModuleClassLoader classLoader = moduleLoader.loadModule(modid).getClassLoader();
    URL resurl = classLoader.getResource("META-INF/cxf/cxf.xml");
    Assert.assertNotNull("URL not null", resurl);
}
 
Example 12
Source File: JBossModuleUtils.java    From Nicobar with Apache License 2.0 4 votes vote down vote up
/**
 * Helper method to create a revisionId in a consistent manner
 */
public static ModuleIdentifier createRevisionId(ModuleId scriptModuleId, long revisionNumber) {
    Objects.requireNonNull(scriptModuleId, "scriptModuleId");
    return ModuleIdentifier.create(scriptModuleId.toString(), Long.toString(revisionNumber));
}
 
Example 13
Source File: JBossModuleUtils.java    From Nicobar with Apache License 2.0 4 votes vote down vote up
/**
 * Create the {@link ModuleIdentifier} for the given ScriptCompilerPluginSpec ID
 */
public static ModuleIdentifier getPluginModuleId(String pluginId) {
    return ModuleIdentifier.create(pluginId);
}
 
Example 14
Source File: JBossDeploymentStructureParser10.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private static void parseModuleDependency(final XMLStreamReader reader, final ModuleStructureSpec specBuilder,
                                          ModuleLoader moduleLoader) throws XMLStreamException {
    String name = null;
    String slot = null;
    boolean export = false;
    boolean optional = false;
    Disposition services = Disposition.NONE;
    final Set<Attribute> required = EnumSet.of(Attribute.NAME);
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        final Attribute attribute = Attribute.of(reader.getAttributeName(i));
        required.remove(attribute);
        switch (attribute) {
            case NAME:
                name = reader.getAttributeValue(i);
                break;
            case SLOT:
                slot = reader.getAttributeValue(i);
                break;
            case EXPORT:
                export = Boolean.parseBoolean(reader.getAttributeValue(i));
                break;
            case SERVICES:
                services = Disposition.of(reader.getAttributeValue(i));
                break;
            case OPTIONAL:
                optional = Boolean.parseBoolean(reader.getAttributeValue(i));
                break;
            default:
                throw unexpectedContent(reader);
        }
    }
    if (!required.isEmpty()) {
        throw missingAttributes(reader.getLocation(), required);
    }
    ModuleDependency dependency = new ModuleDependency(moduleLoader, ModuleIdentifier.create(name, slot), optional, export,
            services == Disposition.IMPORT, true);
    specBuilder.addModuleDependency(dependency);
    while (reader.hasNext()) {
        switch (reader.nextTag()) {
            case XMLStreamConstants.END_ELEMENT: {
                if (services == Disposition.EXPORT) {
                    // If services are to be re-exported, add META-INF/services -> true near the end of the list
                    dependency.addExportFilter(PathFilters.getMetaInfServicesFilter(), true);
                }
                if (export) {
                    // If re-exported, add META-INF/** -> false at the end of the list (require explicit override)
                    dependency.addExportFilter(PathFilters.getMetaInfSubdirectoriesFilter(), false);
                    dependency.addExportFilter(PathFilters.getMetaInfFilter(), false);
                }
                if (dependency.getImportFilters().isEmpty()) {
                    dependency.addImportFilter(services == Disposition.NONE ? PathFilters.getDefaultImportFilter()
                            : PathFilters.getDefaultImportFilterWithServices(), true);
                } else {
                    if (services != Disposition.NONE) {
                        dependency.addImportFilter(PathFilters.getMetaInfServicesFilter(), true);
                    }
                    dependency.addImportFilter(PathFilters.getMetaInfSubdirectoriesFilter(), false);
                    dependency.addImportFilter(PathFilters.getMetaInfFilter(), false);
                }
                return;
            }
            case XMLStreamConstants.START_ELEMENT: {
                switch (Element.of(reader.getName())) {
                    case EXPORTS:
                        parseFilterList(reader, dependency.getExportFilters());
                        break;
                    case IMPORTS:
                        parseFilterList(reader, dependency.getImportFilters());
                        break;
                    default:
                        throw unexpectedContent(reader);
                }
                break;
            }
            default: {
                throw unexpectedContent(reader);
            }
        }
    }
}
 
Example 15
Source File: ErrorContextHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private static ClassLoader getClassLoader(final ModuleLoader moduleLoader, final String module, final String slot) throws ModuleLoadException {
    ModuleIdentifier id = ModuleIdentifier.create(module, slot);

    return moduleLoader.loadModule(id).getClassLoader();
}
 
Example 16
Source File: ConsoleMode.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected static ClassLoader getClassLoader(final ModuleLoader moduleLoader, final String module, final String slot) throws ModuleLoadException {
    ModuleIdentifier id = ModuleIdentifier.create(module, slot);

    return moduleLoader.loadModule(id).getClassLoader();
}
 
Example 17
Source File: ProductConfig.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private ProductConfProps(String slot) {
    this.productModuleId = slot == null ? null : ModuleIdentifier.create("org.jboss.as.product", slot);
    this.miscProperties = new Properties();
}
 
Example 18
Source File: ModuleDependency.java    From wildfly-core with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Construct a new instance.
 *
 * @param moduleLoader the module loader of the dependency (if {@code null}, then use the default server module loader)
 * @param identifier the module identifier
 * @param optional {@code true} if this is an optional dependency
 * @param export {@code true} if resources should be exported by default
 * @param importServices
 * @param userSpecified {@code true} if this dependency was specified by the user, {@code false} if it was automatically added
 */
public ModuleDependency(final ModuleLoader moduleLoader, final String identifier, final boolean optional, final boolean export, final boolean importServices, final boolean userSpecified) {
    this(moduleLoader, ModuleIdentifier.create(identifier), optional, export, importServices, userSpecified);
}