Search in sources :

Example 6 with ModuleSpec

use of org.jboss.modules.ModuleSpec in project jboss-modules by jboss-modules.

the class ModuleXmlParser method parseDocument.

private static ModuleSpec parseDocument(final MavenResolver mavenResolver, final ResourceRootFactory factory, final String rootPath, XmlPullParser reader, final ModuleLoader moduleLoader, final String moduleName) throws XmlPullParserException, IOException {
    int eventType;
    for (; ; ) {
        eventType = reader.nextTag();
        switch(eventType) {
            case START_DOCUMENT:
                {
                    return parseRootElement(mavenResolver, factory, rootPath, reader, moduleLoader, moduleName);
                }
            case START_TAG:
                {
                    validateNamespace(reader);
                    final String element = reader.getName();
                    switch(element) {
                        case E_MODULE:
                            {
                                final ModuleSpec.Builder specBuilder = parseModuleContents(mavenResolver, reader, factory, moduleLoader, moduleName, rootPath);
                                parseEndDocument(reader);
                                return specBuilder.create();
                            }
                        case E_MODULE_ALIAS:
                            {
                                final ModuleSpec moduleSpec = parseModuleAliasContents(reader, moduleName);
                                parseEndDocument(reader);
                                return moduleSpec;
                            }
                        case E_MODULE_ABSENT:
                            {
                                parseModuleAbsentContents(reader, moduleName);
                                return null;
                            }
                        default:
                            {
                                throw unexpectedContent(reader);
                            }
                    }
                }
            default:
                {
                    throw unexpectedContent(reader);
                }
        }
    }
}
Also used : ModuleSpec(org.jboss.modules.ModuleSpec)

Example 7 with ModuleSpec

use of org.jboss.modules.ModuleSpec in project jboss-modules by jboss-modules.

the class ModuleXmlParser method parseRootElement.

private static ModuleSpec parseRootElement(final MavenResolver mavenResolver, final ResourceRootFactory factory, final String rootPath, final XmlPullParser reader, final ModuleLoader moduleLoader, final String moduleName) throws XmlPullParserException, IOException {
    assertNoAttributes(reader);
    int eventType;
    while ((eventType = reader.nextTag()) != END_DOCUMENT) {
        switch(eventType) {
            case START_TAG:
                {
                    validateNamespace(reader);
                    final String element = reader.getName();
                    switch(element) {
                        case E_MODULE:
                            {
                                final ModuleSpec.Builder specBuilder = parseModuleContents(mavenResolver, reader, factory, moduleLoader, moduleName, rootPath);
                                parseEndDocument(reader);
                                return specBuilder.create();
                            }
                        case E_MODULE_ALIAS:
                            {
                                final ModuleSpec moduleSpec = parseModuleAliasContents(reader, moduleName);
                                parseEndDocument(reader);
                                return moduleSpec;
                            }
                        case E_MODULE_ABSENT:
                            {
                                parseModuleAbsentContents(reader, moduleName);
                                return null;
                            }
                        default:
                            {
                                throw unexpectedContent(reader);
                            }
                    }
                }
            default:
                {
                    throw unexpectedContent(reader);
                }
        }
    }
    throw endOfDocument(reader);
}
Also used : ModuleSpec(org.jboss.modules.ModuleSpec)

Example 8 with ModuleSpec

use of org.jboss.modules.ModuleSpec in project pentaho-platform by pentaho.

the class SystemPackageExtrapolatorTest method testJBossProvider.

@Test
public void testJBossProvider() {
    SystemPackageExtrapolator.JBossModulePackageProvider jBossModulePackageProvider = new SystemPackageExtrapolator.JBossModulePackageProvider();
    Set<String> packages = jBossModulePackageProvider.getPackages();
    assertThat(packages, is(empty()));
    ModuleIdentifier moduleIdentifier = ModuleIdentifier.create("org.pentaho.test.module");
    ModuleSpec.Builder builder = ModuleSpec.build(moduleIdentifier);
    builder.addDependency(DependencySpec.createSystemDependencySpec(new HashSet<String>(Arrays.asList("org.apache", "org.apache.log4j"))));
    final ModuleSpec moduleSpec = builder.create();
    ModuleLoader loader = new ModuleLoader(new ModuleFinder[] { new ModuleFinder() {

        @Override
        public ModuleSpec findModule(ModuleIdentifier moduleIdentifier, ModuleLoader moduleLoader) throws ModuleLoadException {
            return moduleSpec;
        }
    } });
    try {
        Module module = loader.loadModule(moduleIdentifier);
        jBossModulePackageProvider.setModule(module);
    } catch (ModuleLoadException e) {
        e.printStackTrace();
    }
    packages = jBossModulePackageProvider.getPackages();
    assertThat(packages, contains("org.apache.log4j", "org.apache"));
    assertThat(packages, not(contains("org.not.there")));
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) ModuleLoader(org.jboss.modules.ModuleLoader) ModuleFinder(org.jboss.modules.ModuleFinder) ModuleSpec(org.jboss.modules.ModuleSpec) ModuleIdentifier(org.jboss.modules.ModuleIdentifier) Module(org.jboss.modules.Module) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with ModuleSpec

use of org.jboss.modules.ModuleSpec in project wildfly-swarm by wildfly-swarm.

the class BootstrapClasspathModuleFinder method findModule.

@Override
public ModuleSpec findModule(String identifier, ModuleLoader delegateLoader) throws ModuleLoadException {
    String simpleIdentifier = identifier;
    if (!identifier.contains(":")) {
        identifier = identifier + ":main";
    }
    try (AutoCloseable handle = Performance.accumulate("module: BootstrapClassPath")) {
        final String[] nameAndSlot = identifier.split("\\:", 2);
        final String path = "modules/" + nameAndSlot[0].replace('.', MODULE_SEPARATOR) + MODULE_SEPARATOR + nameAndSlot[1] + "/module.xml";
        ClassLoader cl = BootstrapClasspathModuleFinder.class.getClassLoader();
        URL url = cl.getResource(path);
        if (url == null) {
            return null;
        }
        ModuleSpec moduleSpec = null;
        InputStream in = null;
        try {
            final URL base = new URL(url, "./");
            in = url.openStream();
            moduleSpec = ModuleXmlParser.parseModuleXml((rootPath, loaderPath, loaderName) -> NestedJarResourceLoader.loaderFor(base, rootPath, loaderPath, loaderName), MavenResolvers.get(), "/", in, path.toString(), delegateLoader, simpleIdentifier);
        } catch (IOException e) {
            throw new ModuleLoadException(e);
        } catch (Throwable t) {
            throw t;
        } finally {
            try {
                if (in != null) {
                    in.close();
                }
            } catch (IOException e) {
                throw new ModuleLoadException(e);
            }
        }
        return moduleSpec;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : ModuleLoader(org.jboss.modules.ModuleLoader) ModuleFinder(org.jboss.modules.ModuleFinder) ModuleLoadException(org.jboss.modules.ModuleLoadException) URL(java.net.URL) ModuleXmlParser(org.jboss.modules.xml.ModuleXmlParser) IOException(java.io.IOException) Performance(org.wildfly.swarm.bootstrap.performance.Performance) ModuleSpec(org.jboss.modules.ModuleSpec) InputStream(java.io.InputStream) ModuleLoadException(org.jboss.modules.ModuleLoadException) InputStream(java.io.InputStream) IOException(java.io.IOException) URL(java.net.URL) ModuleLoadException(org.jboss.modules.ModuleLoadException) IOException(java.io.IOException) ModuleSpec(org.jboss.modules.ModuleSpec)

Example 10 with ModuleSpec

use of org.jboss.modules.ModuleSpec in project wildfly-swarm by wildfly-swarm.

the class BootstrapClasspathModuleFinderTest method testSlot.

@Test
public void testSlot() {
    BootstrapClasspathModuleFinder finder = new BootstrapClasspathModuleFinder();
    try {
        ModuleSpec spec = finder.findModule("classpath.module.load.test:1.0.0.Final", null);
        assertNotNull(spec);
    } catch (ModuleLoadException e) {
        fail();
    }
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) ModuleSpec(org.jboss.modules.ModuleSpec) Test(org.junit.Test)

Aggregations

ModuleSpec (org.jboss.modules.ModuleSpec)14 ModuleLoadException (org.jboss.modules.ModuleLoadException)12 Test (org.junit.Test)9 ModuleFinder (org.jboss.modules.ModuleFinder)3 ModuleLoader (org.jboss.modules.ModuleLoader)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 URL (java.net.URL)2 ModuleIdentifier (org.jboss.modules.ModuleIdentifier)2 ModuleXmlParser (org.jboss.modules.xml.ModuleXmlParser)2 Performance (org.wildfly.swarm.bootstrap.performance.Performance)2 File (java.io.File)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ArtifactResult (org.eclipse.ceylon.model.cmr.ArtifactResult)1 AliasModuleSpec (org.jboss.modules.AliasModuleSpec)1 DependencySpec (org.jboss.modules.DependencySpec)1 LocalLoader (org.jboss.modules.LocalLoader)1 Module (org.jboss.modules.Module)1