Java Code Examples for org.jboss.modules.ModuleSpec#build()
The following examples show how to use
org.jboss.modules.ModuleSpec#build() .
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: AbstractModuleSpecProvider.java From furnace with Eclipse Public License 1.0 | 6 votes |
@Override public ModuleSpec get(ModuleLoader loader, ModuleIdentifier id) { if (getId().equals(id)) { Builder builder = ModuleSpec.build(id); builder.addDependency(DependencySpec.createClassLoaderDependencySpec(PathFilters.acceptAll(), PathFilters.acceptAll(), AbstractModuleSpecProvider.class.getClassLoader(), getPaths())); builder.addDependency(DependencySpec.createClassLoaderDependencySpec(PathFilters.acceptAll(), PathFilters.acceptAll(), ClassLoader.getSystemClassLoader(), getPaths())); configure(loader, builder); return builder.create(); } return null; }
Example 2
Source File: JBossModuleUtilsTest.java From Nicobar with Apache License 2.0 | 6 votes |
/** * Verify that the module creates the expected set of dependencies for a {@link PathScriptArchive} */ @Test public void testPathResources() throws Exception { Path jarPath = CoreTestResourceUtil.getResourceAsPath(TEST_TEXT_PATH); ScriptArchive jarScriptArchive = new PathScriptArchive.Builder(jarPath) .setModuleSpec(new ScriptModuleSpec.Builder(ModuleId.create("testModuleId")) .addMetadata(METADATA_NAME, METADATA_VALUE) .build()) .build(); ModuleIdentifier revisionId = JBossModuleUtils.createRevisionId(TEST_TEXT_PATH.getModuleId(), 1); ModuleSpec.Builder moduleSpecBuilder = ModuleSpec.build(revisionId); JBossModuleLoader moduleLoader = new JBossModuleLoader(); JBossModuleUtils.populateModuleSpecWithCoreDependencies(moduleSpecBuilder, jarScriptArchive); JBossModuleUtils.populateModuleSpecWithResources(moduleSpecBuilder, jarScriptArchive); moduleLoader.addModuleSpec(moduleSpecBuilder.create()); Module module = moduleLoader.loadModule(revisionId); ModuleClassLoader moduleClassLoader = module.getClassLoader(); // verify the metadata was transfered assertEquals(module.getProperty(METADATA_NAME), METADATA_VALUE); // verify that the archive resource match exactly the module resources Set<String> actualPaths = getResourcePaths(moduleClassLoader); assertEquals(actualPaths, TEST_TEXT_PATH.getContentPaths()); }
Example 3
Source File: AbstractSingleModuleFinder.java From thorntail with Apache License 2.0 | 5 votes |
@Override public ModuleSpec findModule(String identifier, ModuleLoader delegateLoader) throws ModuleLoadException { if (!this.moduleName.equals(identifier)) { return null; } ModuleSpec.Builder builder = ModuleSpec.build(identifier); buildModule(builder, delegateLoader); return builder.create(); }
Example 4
Source File: AbstractSingleModuleFinder.java From ARCHIVE-wildfly-swarm with Apache License 2.0 | 5 votes |
@Override public ModuleSpec findModule(ModuleIdentifier identifier, ModuleLoader delegateLoader) throws ModuleLoadException { if (!identifier.getName().equals(this.moduleName) || !identifier.getSlot().equals(this.moduleSlot)) { return null; } ModuleSpec.Builder builder = ModuleSpec.build(identifier); buildModule(builder, delegateLoader); return builder.create(); }
Example 5
Source File: ScriptModuleLoader.java From Nicobar with Apache License 2.0 | 5 votes |
/** * Create a JBoss module spec for an about to be created script module. * @param archive the script archive being converted to a module. * @param moduleId the JBoss module identifier. * @param moduleIdMap a map of loaded script module IDs to jboss module identifiers * @param moduleCompilationRoot a path to a directory that will hold compiled classes for this module. * @throws ModuleLoadException */ protected ModuleSpec createModuleSpec(ScriptArchive archive, ModuleIdentifier moduleId, Map<ModuleId, ModuleIdentifier> moduleIdMap, Path moduleCompilationRoot) throws ModuleLoadException { ScriptModuleSpec archiveSpec = archive.getModuleSpec(); // create the jboss module pre-cursor artifact ModuleSpec.Builder moduleSpecBuilder = ModuleSpec.build(moduleId); JBossModuleUtils.populateModuleSpecWithResources(moduleSpecBuilder, archive); JBossModuleUtils.populateModuleSpecWithCoreDependencies(moduleSpecBuilder, archive); JBossModuleUtils.populateModuleSpecWithAppImports(moduleSpecBuilder, appClassLoader, archiveSpec.getAppImportFilterPaths() == null ? appPackagePaths : archiveSpec.getAppImportFilterPaths()); // Allow compiled class files to fetched as resources later on. JBossModuleUtils.populateModuleSpecWithCompilationRoot(moduleSpecBuilder, moduleCompilationRoot); // Populate the modulespec with the scriptArchive dependencies for (ModuleId dependencyModuleId : archiveSpec.getModuleDependencies()) { ScriptModule dependencyModule = getScriptModule(dependencyModuleId); Set<String> exportPaths = dependencyModule.getSourceArchive().getModuleSpec().getModuleExportFilterPaths(); JBossModuleUtils.populateModuleSpecWithModuleDependency(moduleSpecBuilder, archiveSpec.getModuleImportFilterPaths(), exportPaths, moduleIdMap.get(dependencyModuleId)); } return moduleSpecBuilder.create(); }
Example 6
Source File: ScriptModuleLoader.java From Nicobar with Apache License 2.0 | 5 votes |
/** * Add a language plugin to this module * @param pluginSpec * @throws ModuleLoadException */ public synchronized void addCompilerPlugin(ScriptCompilerPluginSpec pluginSpec) throws ModuleLoadException { Objects.requireNonNull(pluginSpec, "pluginSpec"); ModuleIdentifier pluginModuleId = JBossModuleUtils.getPluginModuleId(pluginSpec); ModuleSpec.Builder moduleSpecBuilder = ModuleSpec.build(pluginModuleId); Map<ModuleId, ModuleIdentifier> latestRevisionIds = jbossModuleLoader.getLatestRevisionIds(); JBossModuleUtils.populateCompilerModuleSpec(moduleSpecBuilder, pluginSpec, latestRevisionIds); // Add app package dependencies, while blocking them from leaking (being exported) to downstream modules // TODO: We expose the full set of app packages to the compiler too. // Maybe more control over what is exposed is needed here. JBossModuleUtils.populateModuleSpecWithAppImports(moduleSpecBuilder, appClassLoader, appPackagePaths); ModuleSpec moduleSpec = moduleSpecBuilder.create(); // spin up the module, and get the compiled classes from it's classloader String providerClassName = pluginSpec.getPluginClassName(); if (providerClassName != null) { jbossModuleLoader.addModuleSpec(moduleSpec); Module pluginModule = jbossModuleLoader.loadModule(pluginModuleId); ModuleClassLoader pluginClassLoader = pluginModule.getClassLoader(); Class<?> compilerProviderClass; try { compilerProviderClass = pluginClassLoader.loadClass(providerClassName); ScriptCompilerPlugin pluginBootstrap = (ScriptCompilerPlugin) compilerProviderClass.newInstance(); Set<? extends ScriptArchiveCompiler> pluginCompilers = pluginBootstrap.getCompilers(pluginSpec.getCompilerParams()); compilers.addAll(pluginCompilers); } catch (Exception e) { throw new ModuleLoadException(e); } // Save classloader away, in case clients would like access to compiler plugin's classes. compilerClassLoaders.put(pluginSpec.getPluginId(), pluginModule.getClassLoader()); } }
Example 7
Source File: JBossModuleUtilsTest.java From Nicobar with Apache License 2.0 | 5 votes |
/** * Verify that the module creates the expected set of dependencies for a {@link ScriptCompilerPlugin} */ @Test public void testExpectedPluginDependencies() throws Exception { ScriptCompilerPluginSpec pluginSpec = new ScriptCompilerPluginSpec.Builder("TestPlugin") .addMetatdata(METADATA_NAME, METADATA_VALUE) .build(); ModuleIdentifier pluginId = JBossModuleUtils.getPluginModuleId(pluginSpec); ModuleSpec.Builder moduleSpecBuilder = ModuleSpec.build(pluginId); JBossModuleUtils.populateCompilerModuleSpec(moduleSpecBuilder, pluginSpec, Collections.<ModuleId, ModuleIdentifier>emptyMap()); JBossModuleLoader moduleLoader = new JBossModuleLoader(); moduleLoader.addModuleSpec(moduleSpecBuilder.create()); Module module = moduleLoader.loadModule(pluginId); assertNotNull(module); ModuleClassLoader moduleClassLoader = module.getClassLoader(); // verify the metadata was transfered assertEquals(module.getProperty(METADATA_NAME), METADATA_VALUE); // verify the module can import the core classes assertNotNull(moduleClassLoader.loadClass(ScriptCompilerPlugin.class.getName())); // verify the module can find the JDK classes assertNotNull(moduleClassLoader.loadClass("org.w3c.dom.Element")); // verify that nothing else from the classpath leaked through assertClassNotFound(TestNG.class.getName(), moduleClassLoader); }
Example 8
Source File: JBossModuleUtilsTest.java From Nicobar with Apache License 2.0 | 5 votes |
/** * Verify that the module creates the expected set of dependencies for a {@link JarScriptArchive} */ @Test public void testJarResources() throws Exception { Path jarPath = CoreTestResourceUtil.getResourceAsPath(TEST_TEXT_JAR); ScriptArchive jarScriptArchive = new JarScriptArchive.Builder(jarPath) .setModuleSpec(new ScriptModuleSpec.Builder(ModuleId.create("testModuleId")) .addMetadata(METADATA_NAME, METADATA_VALUE) .build()) .build(); ModuleIdentifier revisionId = JBossModuleUtils.createRevisionId(TEST_TEXT_JAR.getModuleId(), 1); ModuleSpec.Builder moduleSpecBuilder = ModuleSpec.build(revisionId); JBossModuleLoader moduleLoader = new JBossModuleLoader(); JBossModuleUtils.populateModuleSpecWithCoreDependencies(moduleSpecBuilder, jarScriptArchive); JBossModuleUtils.populateModuleSpecWithResources(moduleSpecBuilder, jarScriptArchive); moduleLoader.addModuleSpec(moduleSpecBuilder.create()); Module module = moduleLoader.loadModule(revisionId); ModuleClassLoader moduleClassLoader = module.getClassLoader(); // verify the metadata was transfered assertEquals(module.getProperty(METADATA_NAME), METADATA_VALUE); // verify that the archive resource match exactly the module resources Set<String> actualPaths = getResourcePaths(moduleClassLoader); assertEquals(actualPaths, TEST_TEXT_JAR.getContentPaths()); }
Example 9
Source File: ModuleSpecProcessor.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
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); }