org.jboss.modules.ModuleIdentifier Java Examples

The following examples show how to use org.jboss.modules.ModuleIdentifier. 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: ModuleSpecProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
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 #2
Source File: AddonModuleLoader.java    From furnace with Eclipse Public License 1.0 6 votes vote down vote up
private void addAddonDependency(Set<AddonView> views, AddonId found, Builder builder,
         AddonDependencyEntry dependency)
{
   AddonId addonId = stateManager.resolveAddonId(views, dependency.getName());
   ModuleIdentifier moduleId = null;
   if (addonId != null)
   {
      Addon addon = lifecycleManager.getAddon(views, addonId);
      moduleId = findCompatibleInstalledModule(addonId);
      if (moduleId != null)
      {
         builder.addDependency(DependencySpec.createModuleDependencySpec(
                  PathFilters.not(PathFilters.getMetaInfFilter()),
                  dependency.isExported() ? PathFilters.acceptAll() : PathFilters.rejectAll(),
                  this,
                  moduleCache.getModuleId(addon),
                  dependency.isOptional()));
      }
   }

   if (!dependency.isOptional() && (addonId == null || moduleId == null))
      throw new ContainerException("Dependency [" + dependency + "] could not be loaded for addon [" + found
               + "]");
}
 
Example #3
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 #4
Source File: AbstractModuleSpecProvider.java    From furnace with Eclipse Public License 1.0 6 votes vote down vote up
@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 #5
Source File: AddonModuleLoader.java    From furnace with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Loads a module for the given Addon.
 */
public final Module loadAddonModule(Addon addon) throws ModuleLoadException
{
   try
   {
      this.currentAddon.set(addon);
      ModuleIdentifier moduleId = moduleCache.getModuleId(addon);
      Module result = loadModule(moduleId);
      return result;
   }
   catch (ModuleLoadException e)
   {
      throw e;
   }
   finally
   {
      this.currentAddon.remove();
   }
}
 
Example #6
Source File: DeferredExtensionContext.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private XMLStreamException loadModule(final String moduleName, final XMLMapper xmlMapper) throws XMLStreamException {
    // Register element handlers for this extension
    try {
        final Module module = moduleLoader.loadModule(ModuleIdentifier.fromString(moduleName));
        boolean initialized = false;
        for (final Extension extension : module.loadService(Extension.class)) {
            ClassLoader oldTccl = WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(extension.getClass());
            try {
                extensionRegistry.initializeParsers(extension, moduleName, xmlMapper);
            } finally {
                WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(oldTccl);
            }
            if (!initialized) {
                initialized = true;
            }
        }
        if (!initialized) {
            throw ControllerLogger.ROOT_LOGGER.notFound("META-INF/services/", Extension.class.getName(), module.getName());
        }
        return null;
    } catch (final ModuleLoadException e) {
        throw ControllerLogger.ROOT_LOGGER.failedToLoadModule(e);
    }
}
 
Example #7
Source File: ContextCreateHandlerRegistryIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void testHandlerRegistry() throws Exception {
    ContextCreateHandlerRegistry handlerRegistry = ServiceLocator.getRequiredService(CamelConstants.CONTEXT_CREATE_HANDLER_REGISTRY_SERVICE_NAME, ContextCreateHandlerRegistry.class);
    ModuleLoader moduleLoader = Module.getCallerModuleLoader();

    deployer.deploy(CAMEL_TEST_JAR);

    Module module = moduleLoader.loadModule(ModuleIdentifier.create("deployment.camel-test.jar"));
    ClassLoader classLoader = module.getClassLoader();

    // Registry should have classloader key after deploy
    Assert.assertTrue(handlerRegistry.containsKey(classLoader));

    deployer.undeploy(CAMEL_TEST_JAR);

    // Registry should have removed classloader key after undeploy
    Assert.assertFalse("Expected registry to not contain key: " + classLoader, handlerRegistry.containsKey(classLoader));
}
 
Example #8
Source File: CompositeIndexProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private Map<ModuleIdentifier, DeploymentUnit> buildSubdeploymentDependencyMap(DeploymentUnit deploymentUnit) {
    Set<ModuleIdentifier> depModuleIdentifiers = new HashSet<>();
    for (ModuleDependency dep: deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION).getAllDependencies()) {
        depModuleIdentifiers.add(dep.getIdentifier());
    }

    DeploymentUnit top = deploymentUnit.getParent()==null?deploymentUnit:deploymentUnit.getParent();
    Map<ModuleIdentifier, DeploymentUnit> res = new HashMap<>();
    AttachmentList<DeploymentUnit> subDeployments = top.getAttachment(Attachments.SUB_DEPLOYMENTS);
    if (subDeployments != null) {
        for (DeploymentUnit subDeployment : subDeployments) {
            ModuleIdentifier moduleIdentifier = subDeployment.getAttachment(Attachments.MODULE_IDENTIFIER);
            if (depModuleIdentifiers.contains(moduleIdentifier)) {
                res.put(moduleIdentifier, subDeployment);
            }
        }
    }
    return res;
}
 
Example #9
Source File: JBossModuleUtilsTest.java    From Nicobar with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #10
Source File: JBossModuleLoader.java    From Nicobar with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #11
Source File: FaviconHandler.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 6 votes vote down vote up
public Response toResponse(NotFoundException e) {
    if (e.getMessage().contains("favicon.ico")) {
        try {
            Module module = Module.getBootModuleLoader().loadModule(ModuleIdentifier.create("org.wildfly.swarm.undertow", "runtime"));
            ClassLoader cl = module.getClassLoader();
            final InputStream in = cl.getResourceAsStream("favicon.ico");
            if (in != null) {
                Response.ResponseBuilder builder = Response.ok();
                builder.entity(in);
                return builder.build();
            }
        } catch (ModuleLoadException e1) {
            throw e;
        }
    }

    // can't handle it, rethrow.
    throw e;
}
 
Example #12
Source File: RuntimeServer.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unused")
public RuntimeServer() {
    try {
        Module loggingModule = Module.getBootModuleLoader().loadModule(ModuleIdentifier.create("org.wildfly.swarm.logging", "runtime"));

        ClassLoader originalCl = Thread.currentThread().getContextClassLoader();
        try {
            Thread.currentThread().setContextClassLoader(loggingModule.getClassLoader());
            System.setProperty("java.util.logging.manager", "org.jboss.logmanager.LogManager");
            System.setProperty("org.jboss.logmanager.configurator", LoggingConfigurator.class.getName());
            //force logging init
            LogManager.getLogManager();
            BootstrapLogger.setBackingLoggerManager(new JBossLoggingManager());
        } finally {
            Thread.currentThread().setContextClassLoader(originalCl);
        }
    } catch (ModuleLoadException e) {
        System.err.println("[WARN] logging not available, logging will not be configured");
    }
}
 
Example #13
Source File: Swarm.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 6 votes vote down vote up
/**
 * Main entry-point.
 *
 * @param args Ignored.
 * @throws Exception if an error occurs.
 */
public static void main(String... args) throws Exception {
    if (System.getProperty("boot.module.loader") == null) {
        System.setProperty("boot.module.loader", "org.wildfly.swarm.bootstrap.modules.BootModuleLoader");
    }
    Module bootstrap = Module.getBootModuleLoader().loadModule(ModuleIdentifier.create("swarm.application"));

    ServiceLoader<ContainerFactory> factory = bootstrap.loadService(ContainerFactory.class);
    Iterator<ContainerFactory> factoryIter = factory.iterator();

    if (!factoryIter.hasNext()) {
        simpleMain(args);
    } else {
        factoryMain(factoryIter.next(), args);
    }
}
 
Example #14
Source File: DaemonServiceActivator.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 6 votes vote down vote up
@Override
public void start(StartContext context) throws StartException {
    try {
        final String artifactName = System.getProperty(BootstrapProperties.APP_ARTIFACT);
        if (artifactName == null) {
            throw new StartException("Failed to find artifact name under " + BootstrapProperties.APP_ARTIFACT);
        }

        final ModuleLoader serviceLoader = this.serviceLoader.getValue();
        final String moduleName = "deployment." + artifactName;
        final Module module = serviceLoader.loadModule(ModuleIdentifier.create(moduleName));
        if (module == null) {
            throw new StartException("Failed to find deployment module under " + moduleName);
        }

        //TODO: allow overriding the default port?
        this.server = Server.create("localhost", 12345, module.getClassLoader());
        this.server.start();
    } catch (ModuleLoadException | ServerLifecycleException e) {
        throw new StartException(e);
    }
}
 
Example #15
Source File: ModuleExtensionNameProcessor.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();

    final ExtensionInfo extensionInfo = deploymentUnit.getAttachment(Attachments.EXTENSION_INFORMATION);
    if (extensionInfo == null) {
        return;
    }
    final ServiceController<?> extensionIndexController = phaseContext.getServiceRegistry().getRequiredService(
            Services.JBOSS_DEPLOYMENT_EXTENSION_INDEX);
    final ExtensionIndex extensionIndexService = (ExtensionIndex) extensionIndexController.getValue();
    final ModuleIdentifier moduleIdentifier = deploymentUnit.getAttachment(Attachments.MODULE_IDENTIFIER);
    extensionIndexService.addDeployedExtension(moduleIdentifier, extensionInfo);
}
 
Example #16
Source File: AddonModuleLoader.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
private void addLocalResources(AddonRepository repository, AddonId found, Builder builder, ModuleIdentifier id)
{
   List<File> resources = repository.getAddonResources(found);
   for (File file : resources)
   {
      try
      {
         if (file.isDirectory())
         {
            builder.addResourceRoot(
                     ResourceLoaderSpec.createResourceLoaderSpec(
                              ResourceLoaders.createFileResourceLoader(file.getName(), file),
                              PathFilters.acceptAll()));
         }
         else if (file.length() > 0)
         {
            JarFile jarFile = new JarFile(file);
            moduleJarFileCache.addJarFileReference(id, jarFile);
            builder.addResourceRoot(
                     ResourceLoaderSpec.createResourceLoaderSpec(
                              ResourceLoaders.createJarResourceLoader(file.getName(), jarFile),
                              PathFilters.acceptAll()));
         }
      }
      catch (IOException e)
      {
         throw new ContainerException("Could not load resources from [" + file.getAbsolutePath() + "]", e);
      }
   }
}
 
Example #17
Source File: JBossModuleLoader.java    From Nicobar with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #18
Source File: JBossModuleUtilsTest.java    From Nicobar with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #19
Source File: JBossModuleUtilsTest.java    From Nicobar with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #20
Source File: JBossDeploymentStructureParser10.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void parseModuleExclusion(final XMLStreamReader reader, final ModuleStructureSpec specBuilder) throws XMLStreamException {
    String name = null;
    String slot = "main";
    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;
            default:
                throw unexpectedContent(reader);
        }
    }
    if (!required.isEmpty()) {
        throw missingAttributes(reader.getLocation(), required);
    }
    specBuilder.getExclusions().add(ModuleIdentifier.create(name, slot));
    if (reader.hasNext()) {
        switch (reader.nextTag()) {
            case XMLStreamConstants.END_ELEMENT:
                return;
            default:
                throw unexpectedContent(reader);
        }
    }
}
 
Example #21
Source File: JBossModuleLoader.java    From Nicobar with Apache License 2.0 5 votes vote down vote up
/**
 * 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: 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 #23
Source File: JBossDeploymentStructureParser11.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void parseModule(XMLStreamReader reader, ParseResult result) throws XMLStreamException {
    final int count = reader.getAttributeCount();
    String name = null;
    String slot = null;
    final Set<Attribute> required = EnumSet.of(Attribute.NAME);
    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;
            default:
                throw unexpectedContent(reader);
        }
    }
    if (!required.isEmpty()) {
        throw missingAttributes(reader.getLocation(), required);
    }
    if (!name.startsWith(MODULE_PREFIX)) {
        throw ServerLogger.ROOT_LOGGER.invalidModuleName(name);
    }
    final ModuleStructureSpec moduleSpecification = new ModuleStructureSpec();
    moduleSpecification.setModuleIdentifier(ModuleIdentifier.create(name, slot));
    result.getAdditionalModules().add(moduleSpecification);
    parseModuleStructureSpec(result.getDeploymentUnit(), reader, moduleSpecification, result.getModuleLoader());
}
 
Example #24
Source File: JBossDeploymentStructureParser12.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void parseModule(XMLStreamReader reader, ParseResult result) throws XMLStreamException {
    final int count = reader.getAttributeCount();
    String name = null;
    String slot = null;
    final Set<Attribute> required = EnumSet.of(Attribute.NAME);
    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;
            default:
                throw unexpectedContent(reader);
        }
    }
    if (!required.isEmpty()) {
        throw missingAttributes(reader.getLocation(), required);
    }
    if (!name.startsWith(MODULE_PREFIX)) {
        throw ServerLogger.ROOT_LOGGER.invalidModuleName(name);
    }
    final ModuleStructureSpec moduleSpecification = new ModuleStructureSpec();
    moduleSpecification.setModuleIdentifier(ModuleIdentifier.create(name, slot));
    result.getAdditionalModules().add(moduleSpecification);
    parseModuleStructureSpec(result.getDeploymentUnit(), reader, moduleSpecification, result.getModuleLoader());
}
 
Example #25
Source File: JBossDeploymentStructureParser13.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void parseModule(XMLStreamReader reader, ParseResult result) throws XMLStreamException {
    final int count = reader.getAttributeCount();
    String name = null;
    String slot = null;
    final Set<Attribute> required = EnumSet.of(Attribute.NAME);
    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;
            default:
                throw unexpectedContent(reader);
        }
    }
    if (!required.isEmpty()) {
        throw missingAttributes(reader.getLocation(), required);
    }
    if (!name.startsWith(MODULE_PREFIX)) {
        throw ServerLogger.ROOT_LOGGER.invalidModuleName(name);
    }
    final ModuleStructureSpec moduleSpecification = new ModuleStructureSpec();
    moduleSpecification.setModuleIdentifier(ModuleIdentifier.create(name, slot));
    result.getAdditionalModules().add(moduleSpecification);
    parseModuleStructureSpec(result.getDeploymentUnit(), reader, moduleSpecification, result.getModuleLoader());
}
 
Example #26
Source File: AddonModuleFileCache.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
public void addJarFileReference(ModuleIdentifier id, JarFile file)
{
   Assert.notNull(id, "Module reference must not be null.");
   Assert.notNull(file, "JarFile reference must not be null.");

   logger.log(Level.FINE, "Adding JarFile [" + file.getName() + "] for module [" + id + "]");
   Set<JarFile> files = map.get(id);
   if (files == null)
   {
      files = Sets.getConcurrentSet();
      map.put(id, files);
   }

   files.add(file);
}
 
Example #27
Source File: AddonModuleIdentifierCache.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public String toString()
{
   StringBuilder builder = new StringBuilder();
   Iterator<Entry<Addon, ModuleIdentifier>> iterator = map.entrySet().iterator();
   while (iterator.hasNext())
   {
      Entry<Addon, ModuleIdentifier> entry = iterator.next();
      builder.append(entry.getKey()).append(" -> ").append(entry.getValue());
      if (iterator.hasNext())
         builder.append("\n");
   }
   return builder.toString();
}
 
Example #28
Source File: ServiceModuleLoader.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns the corresponding ModuleLoadService service name for the given module.
 *
 * @param identifier The module identifier
 * @return The service name of the ModuleLoadService service
 */
public static ServiceName moduleServiceName(ModuleIdentifier identifier) {
    if (!identifier.getName().startsWith(MODULE_PREFIX)) {
        throw ServerLogger.ROOT_LOGGER.missingModulePrefix(identifier, MODULE_PREFIX);
    }
    return MODULE_SERVICE_PREFIX.append(identifier.getName()).append(identifier.getSlot());
}
 
Example #29
Source File: ExtensionIndexService.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/** {@inheritDoc} */
public synchronized void addDeployedExtension(ModuleIdentifier identifier, ExtensionInfo extensionInfo) {
    final ExtensionJar extensionJar = new ExtensionJar(identifier, extensionInfo);
    Set<ExtensionJar> jars = this.extensions.get(extensionInfo.getName());
    if (jars == null) {
        this.extensions.put(extensionInfo.getName(), jars = new HashSet<ExtensionJar>());
    }
    jars.add(extensionJar);
}
 
Example #30
Source File: ModuleProviderLoaderFactory.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Override
public ProviderLoader create(KeycloakDeploymentInfo info, ClassLoader baseClassLoader, String resource) {
    try {
        Module module = Module.getContextModuleLoader().loadModule(ModuleIdentifier.fromString(resource));
        ModuleClassLoader classLoader = module.getClassLoader();
        return new DefaultProviderLoader(info, classLoader);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}