org.jboss.modules.ModuleSpec Java Examples
The following examples show how to use
org.jboss.modules.ModuleSpec.
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: 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 #2
Source File: JBossModuleLoader.java From Nicobar with Apache License 2.0 | 6 votes |
/** * Extract the Module dependencies for the given module in the form * of ScriptModule ids. */ public static Set<ModuleId> getDependencyScriptModuleIds(ModuleSpec moduleSpec) { Objects.requireNonNull(moduleSpec, "moduleSpec"); if (!(moduleSpec instanceof ConcreteModuleSpec)) { throw new IllegalArgumentException("Unsupported ModuleSpec implementation: " + moduleSpec.getClass().getName()); } Set<ModuleId> dependencyNames = new LinkedHashSet<ModuleId>(); ConcreteModuleSpec concreteSpec = (ConcreteModuleSpec)moduleSpec; for (DependencySpec dependencSpec : concreteSpec.getDependencies()) { if (dependencSpec instanceof ModuleDependencySpec) { ModuleIdentifier revisionId = ((ModuleDependencySpec)dependencSpec).getIdentifier(); dependencyNames.add(ModuleId.fromString(revisionId.getName())); } } return dependencyNames; }
Example #3
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 #4
Source File: ServiceModuleLoader.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@SuppressWarnings("unchecked") @Override public ModuleSpec findModule(ModuleIdentifier identifier) throws ModuleLoadException { ServiceController<ModuleDefinition> controller = (ServiceController<ModuleDefinition>) serviceContainer.getService(moduleSpecServiceName(identifier)); if (controller == null) { ServerLogger.MODULE_SERVICE_LOGGER.debugf("Could not load module '%s' as corresponding module spec service '%s' was not found", identifier, identifier); return null; } UninterruptibleCountDownLatch latch = new UninterruptibleCountDownLatch(1); ModuleSpecLoadListener listener = new ModuleSpecLoadListener(latch); try { synchronized (controller) { final State state = controller.getState(); if (state == State.UP || state == State.START_FAILED) { listener.done(controller, controller.getStartException()); } } controller.addListener(listener); } finally { latch.countDown(); } return listener.getModuleSpec(); }
Example #5
Source File: ModuleSpecProcessor.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
private void installAliases(final ModuleSpecification moduleSpecification, final ModuleIdentifier moduleIdentifier, final DeploymentUnit deploymentUnit, final DeploymentPhaseContext phaseContext) { ModuleLoader moduleLoader = deploymentUnit.getAttachment(Attachments.SERVICE_MODULE_LOADER); for (final ModuleIdentifier alias : moduleSpecification.getAliases()) { final ServiceName moduleSpecServiceName = ServiceModuleLoader.moduleSpecServiceName(alias); final ModuleSpec spec = ModuleSpec.buildAlias(alias, moduleIdentifier).create(); HashSet<ModuleDependency> dependencies = new HashSet<>(moduleSpecification.getAllDependencies()); //we need to add the module we are aliasing as a dependency, to make sure that it will be resolved dependencies.add(new ModuleDependency(moduleLoader, moduleIdentifier, false, false, false, false)); ModuleDefinition moduleDefinition = new ModuleDefinition(alias, dependencies, spec); 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(); ModuleLoadService.installAliases(phaseContext.getServiceTarget(), alias, Collections.singletonList(moduleIdentifier)); ModuleResolvePhaseService.installService(phaseContext.getServiceTarget(), moduleDefinition); } }
Example #6
Source File: WildFlySwarmBootstrapConf.java From ARCHIVE-wildfly-swarm with Apache License 2.0 | 6 votes |
void apply(ModuleSpec.Builder builder, MavenArtifactDescriptor entry) throws IOException { File artifact = MavenResolvers.get().resolveJarArtifact(entry.mscCoordinates()); if (artifact == null) { throw new IOException("Unable to locate artifact: " + entry.mscGav()); } if (LOG.isTraceEnabled()) { LOG.trace("adding bootstrap artifact: " + artifact.getAbsolutePath()); } builder.addResourceRoot( ResourceLoaderSpec.createResourceLoaderSpec( ResourceLoaders.createJarResourceLoader(artifact.getName(), new JarFile(artifact)) ) ); }
Example #7
Source File: ModuleSpecProcessor.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
private void addResourceRoot(final ModuleSpec.Builder specBuilder, final ResourceRoot resource, final List<PermissionFactory> permFactories) throws DeploymentUnitProcessingException { try { final VirtualFile root = resource.getRoot(); if (resource.getExportFilters().isEmpty()) { specBuilder.addResourceRoot(ResourceLoaderSpec.createResourceLoaderSpec(new VFSResourceLoader(resource .getRootName(), root, resource.isUsePhysicalCodeSource()))); } else { final MultiplePathFilterBuilder filterBuilder = PathFilters.multiplePathFilterBuilder(true); for (final FilterSpecification filter : resource.getExportFilters()) { filterBuilder.addFilter(filter.getPathFilter(), filter.isInclude()); } specBuilder.addResourceRoot(ResourceLoaderSpec.createResourceLoaderSpec(new VFSResourceLoader(resource .getRootName(), root, resource.isUsePhysicalCodeSource()), filterBuilder.create())); } // 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))); } catch (IOException e) { throw ServerLogger.ROOT_LOGGER.failedToCreateVFSResourceLoader(resource.getRootName(), e); } }
Example #8
Source File: ApplicationModuleFinder.java From thorntail with Apache License 2.0 | 6 votes |
private void addClasspathJars(ModuleSpec.Builder builder) throws IOException { String driversList = System.getProperty("thorntail.classpath"); if (driversList != null && driversList.trim().length() > 0) { String[] drivers = driversList.split(";"); for (String driver : drivers) { File driverFile = new File(driver); if (driverFile.exists()) { builder.addResourceRoot( ResourceLoaderSpec.createResourceLoaderSpec( ResourceLoaders.createJarResourceLoader(driverFile.getName(), JarFiles.create(driverFile)) ) ); } } } }
Example #9
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 #10
Source File: BootstrapClasspathModuleFinderTest.java From thorntail with Apache License 2.0 | 5 votes |
@Test public void testMain() { BootstrapClasspathModuleFinder finder = new BootstrapClasspathModuleFinder(); try { ModuleSpec spec = finder.findModule("classpath.module.load.test", null); assertNotNull(spec); } catch (ModuleLoadException e) { fail(); } }
Example #11
Source File: JBossModuleLoader.java From Nicobar with Apache License 2.0 | 5 votes |
/** * Construct the Module dependency graph of a module loader where each vertex is the module name * @return a mutable snapshot of the underlying dependency */ public DirectedGraph<ModuleId, DefaultEdge> getModuleNameGraph() { SimpleDirectedGraph<ModuleId, DefaultEdge> graph = new SimpleDirectedGraph<ModuleId, DefaultEdge>(DefaultEdge.class); Map<ModuleId, ModuleIdentifier> moduleIdentifiers = getLatestRevisionIds(); GraphUtils.addAllVertices(graph, moduleIdentifiers.keySet()); for (Entry<ModuleId, ModuleIdentifier> entry : moduleIdentifiers.entrySet()) { ModuleId scriptModuleId = entry.getKey(); ModuleIdentifier revisionID = entry.getValue(); ModuleSpec moduleSpec = moduleSpecs.get(revisionID); Set<ModuleId> dependencyNames = getDependencyScriptModuleIds(moduleSpec); GraphUtils.addOutgoingEdges(graph, scriptModuleId, dependencyNames); } return graph; }
Example #12
Source File: SQLServerDriverInfo.java From thorntail with Apache License 2.0 | 5 votes |
@Override protected void addModuleDependencies(ModuleSpec.Builder builder) { // JDBC driver for SQL Server 6.0 - 6.2 is using javax.xml.bind.DatatypeConverter builder.addDependency(new ModuleDependencySpecBuilder() .setName("javax.xml.bind.api") .build()); }
Example #13
Source File: JBossModuleUtils.java From Nicobar with Apache License 2.0 | 5 votes |
/** * Populates a module spec builder with core dependencies on JRE, Nicobar, itself, and compiler plugins. * * @param moduleSpecBuilder builder to populate * @param scriptArchive {@link ScriptArchive} to copy from */ public static void populateModuleSpecWithCoreDependencies(ModuleSpec.Builder moduleSpecBuilder, ScriptArchive scriptArchive) throws ModuleLoadException { Objects.requireNonNull(moduleSpecBuilder, "moduleSpecBuilder"); Objects.requireNonNull(scriptArchive, "scriptArchive"); Set<String> compilerPlugins = scriptArchive.getModuleSpec().getCompilerPluginIds(); for (String compilerPluginId : compilerPlugins) { moduleSpecBuilder.addDependency(DependencySpec.createModuleDependencySpec(getPluginModuleId(compilerPluginId), false)); } moduleSpecBuilder.addDependency(JRE_DEPENDENCY_SPEC); // TODO: Why does a module need a dependency on Nicobar itself? moduleSpecBuilder.addDependency(NICOBAR_CORE_DEPENDENCY_SPEC); moduleSpecBuilder.addDependency(DependencySpec.createLocalDependencySpec()); }
Example #14
Source File: JBossModuleUtils.java From Nicobar with Apache License 2.0 | 5 votes |
/** * Populate a module spec builder with a dependencies on other modules. * @param moduleSpecBuilder builder to populate * @param moduleImportFilterPaths paths valid for importing into the module being built. * Can be null or empty to indicate that no filters should be applied. * @param dependencyExportFilterPaths export paths for the dependency being linked * @param dependentModuleIdentifier used to lookup the latest dependencies. see {@link JBossModuleLoader#getLatestRevisionIds()} */ public static void populateModuleSpecWithModuleDependency(ModuleSpec.Builder moduleSpecBuilder, @Nullable Set<String> moduleImportFilterPaths, @Nullable Set<String> dependencyExportFilterPaths, ModuleIdentifier dependentModuleIdentifier) { Objects.requireNonNull(moduleSpecBuilder, "moduleSpecBuilder"); PathFilter moduleImportFilters = buildFilters(moduleImportFilterPaths, false); PathFilter dependencyExportFilters = buildFilters(dependencyExportFilterPaths, false); PathFilter importFilters = PathFilters.all(dependencyExportFilters, moduleImportFilters); moduleSpecBuilder.addDependency(DependencySpec.createModuleDependencySpec(importFilters, dependencyExportFilters, null, dependentModuleIdentifier, false)); }
Example #15
Source File: JBossModuleUtils.java From Nicobar with Apache License 2.0 | 5 votes |
/** * Populates a builder with a {@link ResourceLoaderSpec} to a filesystem resource root. * {@link ScriptArchive} * @param moduleSpecBuilder builder to populate * @param compilationRoot a path to the compilation resource root directory */ public static void populateModuleSpecWithCompilationRoot(ModuleSpec.Builder moduleSpecBuilder, Path compilationRoot) { Objects.requireNonNull(moduleSpecBuilder, "moduleSpecBuilder"); Objects.requireNonNull(compilationRoot, "resourceRoot"); ResourceLoader resourceLoader = ResourceLoaders.createFileResourceLoader(compilationRoot.toString(), compilationRoot.toFile()); moduleSpecBuilder.addResourceRoot(ResourceLoaderSpec.createResourceLoaderSpec(resourceLoader)); }
Example #16
Source File: WildFlySwarmApplicationConf.java From ARCHIVE-wildfly-swarm with Apache License 2.0 | 5 votes |
@Override void apply(ModuleSpec.Builder builder) throws IOException { File artifact = MavenResolvers.get().resolveJarArtifact(this.descriptor.mscCoordinates()); if (artifact == null) { throw new IOException("Unable to locate artifact: " + this.descriptor.mscGav()); } builder.addResourceRoot( ResourceLoaderSpec.createResourceLoaderSpec( ResourceLoaders.createJarResourceLoader(artifact.getName(), new JarFile(artifact)) ) ); }
Example #17
Source File: BootstrapClasspathModuleFinderTest.java From thorntail with Apache License 2.0 | 5 votes |
@Test public void testMissingMain() { BootstrapClasspathModuleFinder finder = new BootstrapClasspathModuleFinder(); try { ModuleSpec spec = finder.findModule("classpath.module.load.test.missing", null); assertNull(spec); } catch (ModuleLoadException e) { fail(); } }
Example #18
Source File: ApplicationModuleFinderTest.java From thorntail with Apache License 2.0 | 5 votes |
@Test public void testDependencyHasClassifier() { // Mocks ApplicationEnvironment env = mock(ApplicationEnvironment.class); when(env.getDependencies()).thenReturn(Collections.singleton("org.jboss.forge.addon:ui-spi:jar:forge-addon:3.4.0.Final")); ModuleSpec.Builder builder = mock(ModuleSpec.Builder.class); ApplicationModuleFinder sut = new ApplicationModuleFinder(); sut.addDependencies(builder, env); verify(builder, times(1)).addResourceRoot(any()); }
Example #19
Source File: JBossModuleLoader.java From Nicobar with Apache License 2.0 | 5 votes |
/** * Get a map of the the moduleId to {@link ModuleIdentifier} with the highest revision * @return immutable snapshot of the latest module revisionIds */ public Map<ModuleId, ModuleIdentifier> getLatestRevisionIds() { Map<ModuleId, ModuleIdentifier> nameToIdMap = new HashMap<ModuleId, ModuleIdentifier>(moduleSpecs.size()*2); for (Entry<ModuleIdentifier, ModuleSpec> entry : moduleSpecs.entrySet()) { ModuleId scriptModuleId = ModuleId.fromString(entry.getKey().getName()); ModuleSpec moduleSpec = entry.getValue(); nameToIdMap.put(scriptModuleId, moduleSpec.getModuleIdentifier()); } // reserve the ability to convert this to an immutable view later return Collections.unmodifiableMap(nameToIdMap); }
Example #20
Source File: ExternalModuleSpecService.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private static void addEEDependencies(ModuleSpec.Builder specBuilder) { DependencySpec dependencySpec = new ModuleDependencySpecBuilder() .setName(ServerRootResourceDefinition.WILDFLY_EE_API) .setOptional(true) .build(); specBuilder.addDependency(dependencySpec); }
Example #21
Source File: JBossModuleLoader.java From Nicobar with Apache License 2.0 | 5 votes |
/** * Find the highest revision for the given scriptModuleId * @param scriptModuleId name to search for * @return the highest revision number or -1 if no revisions exist */ public long getLatestRevisionNumber(ModuleId scriptModuleId) { Objects.requireNonNull(scriptModuleId, "scriptModuleId"); ModuleIdentifier searchIdentifier = JBossModuleUtils.createRevisionId(scriptModuleId, 0); SortedMap<ModuleIdentifier,ModuleSpec> tailMap = moduleSpecs.tailMap(searchIdentifier); long revisionNumber = -1; for (ModuleIdentifier revisionId : tailMap.keySet()) { if (revisionId.getName().equals(scriptModuleId.toString())) { revisionNumber = getRevisionNumber(revisionId); } else { break; } } return revisionNumber; }
Example #22
Source File: ServiceModuleLoader.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void handleEvent(final ServiceController<?> controller, final LifecycleEvent event) { latch.awaitUninterruptibly(); switch (event) { case UP: log.tracef("serviceStarted: %s", controller); done(controller, null); break; case FAILED: log.tracef(controller.getStartException(), "serviceFailed: %s", controller); done(controller, controller.getStartException()); break; case DOWN: { log.tracef("serviceStopping: %s", controller); ModuleSpec moduleSpec = this.moduleSpec; if (moduleSpec != null) { String identifier = moduleSpec.getName(); Module module = findLoadedModuleLocal(identifier); if (module != null) unloadModuleLocal(identifier, module); } // TODO: what if the service is restarted? controller.removeListener(this); break; } } }
Example #23
Source File: JBossModuleLoader.java From Nicobar with Apache License 2.0 | 5 votes |
/** * Add a {@link ModuleSpec} to the internal repository making it ready to load. Note, this doesn't * actually load the {@link Module}. * @see #loadModule(ModuleIdentifier) * * @param moduleSpec spec to add * @return true if the instance was added */ @Nullable public boolean addModuleSpec(ModuleSpec moduleSpec) { Objects.requireNonNull(moduleSpec, "moduleSpec"); ModuleIdentifier revisionId = moduleSpec.getModuleIdentifier(); boolean available = !moduleSpecs.containsKey(revisionId); if (available) { moduleSpecs.put(revisionId, moduleSpec); } return available; }
Example #24
Source File: DriverModuleBuilder.java From thorntail with Apache License 2.0 | 5 votes |
public boolean detect(final String moduleName) { Messages.MESSAGES.attemptToAutoDetectDriver(this.name); File primaryJar = attemptDetection(); if (primaryJar != null) { Set<File> optionalJars = findOptionalJars(); optionalJars.add(primaryJar); DynamicModuleFinder.register(moduleName, (id, loader) -> { ModuleSpec.Builder builder = ModuleSpec.build(id); for (File eachJar : optionalJars) { try { JarFile jar = JarFileManager.INSTANCE.addJarFile(eachJar); builder.addResourceRoot(ResourceLoaderSpec.createResourceLoaderSpec( ResourceLoaders.createIterableJarResourceLoader(jar.getName(), jar) )); } catch (IOException e) { Messages.MESSAGES.errorLoadingAutodetectedDriver(this.name, e); return null; } } for (String eachModuleIdentifier : driverModuleDependencies) { builder.addDependency(new ModuleDependencySpecBuilder() .setName(eachModuleIdentifier) .build()); } builder.addDependency(DependencySpec.createLocalDependencySpec()); return builder.create(); }); this.installed = true; } return this.installed; }
Example #25
Source File: JBossModuleLoader.java From Nicobar with Apache License 2.0 | 5 votes |
private JBossModuleLoader(final SortedMap<ModuleIdentifier, ModuleSpec> moduleSpecs) { // create a finder that is backed by the local module spec map super(new ModuleFinder[] { new ModuleFinder() { @Override public ModuleSpec findModule(ModuleIdentifier revisionId, ModuleLoader delegateLoader) throws ModuleLoadException { return moduleSpecs.get(revisionId); } }}); this.moduleSpecs = Objects.requireNonNull(moduleSpecs); }
Example #26
Source File: AddonModuleLoader.java From furnace with Eclipse Public License 1.0 | 5 votes |
@Override protected ModuleSpec findModule(ModuleIdentifier id) { ModuleSpec result = findRegularModule(id); if (result == null && currentAddon.get() != null) result = findAddonModule(id); return result; }
Example #27
Source File: AddonModuleLoader.java From furnace with Eclipse Public License 1.0 | 5 votes |
private ModuleSpec findRegularModule(ModuleIdentifier id) { ModuleSpec result = null; for (ModuleSpecProvider p : getModuleProviders()) { result = p.get(this, id); if (result != null) break; } return result; }
Example #28
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 #29
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 #30
Source File: WildFlySwarmApplicationConf.java From ARCHIVE-wildfly-swarm with Apache License 2.0 | 5 votes |
@Override void apply(ModuleSpec.Builder builder) throws IOException { int slashLoc = this.path.lastIndexOf('/'); String name = this.path; if (slashLoc > 0) { name = this.path.substring(slashLoc + 1); } String ext = ".jar"; int dotLoc = name.lastIndexOf('.'); if (dotLoc > 0) { ext = name.substring(dotLoc); name = name.substring(0, dotLoc); } File tmp = TempFileManager.INSTANCE.newTempFile(name, ext); try (InputStream artifactIn = getClass().getClassLoader().getResourceAsStream(this.path)) { Files.copy(artifactIn, tmp.toPath(), StandardCopyOption.REPLACE_EXISTING); } final String jarName = tmp.getName().toString(); final JarFile jarFile = new JarFile(tmp); final ResourceLoader jarLoader = ResourceLoaders.createJarResourceLoader(jarName, jarFile); builder.addResourceRoot(ResourceLoaderSpec.createResourceLoaderSpec(jarLoader)); if (".war".equals(ext)) { final ResourceLoader warLoader = ResourceLoaders.createJarResourceLoader(jarName, jarFile, "WEB-INF/classes"); builder.addResourceRoot(ResourceLoaderSpec.createResourceLoaderSpec(warLoader)); } }