Search in sources :

Example 1 with ModuleSpec

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

the class BootstrapClasspathModuleFinderTest method testMissingSlot.

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

Example 2 with ModuleSpec

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

the class ClasspathModuleFinderTest method testMain.

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

Example 3 with ModuleSpec

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

the class ClasspathModuleFinderTest method testMissingMain.

@Test
public void testMissingMain() {
    ClasspathModuleFinder finder = new ClasspathModuleFinder();
    try {
        ModuleSpec spec = finder.findModule("classpath.module.load.test.missing", null);
        assertNull(spec);
    } catch (ModuleLoadException e) {
        fail();
    }
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) ModuleSpec(org.jboss.modules.ModuleSpec) Test(org.junit.Test)

Example 4 with ModuleSpec

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

the class ClasspathModuleFinderTest method testSlot.

@Test
public void testSlot() {
    ClasspathModuleFinder finder = new ClasspathModuleFinder();
    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)

Example 5 with ModuleSpec

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

the class ClasspathModuleFinder 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: Classpath")) {
        final String[] nameAndSlot = identifier.split("\\:", 2);
        final String path = "modules/" + nameAndSlot[0].replace('.', MODULE_SEPARATOR) + MODULE_SEPARATOR + nameAndSlot[1] + "/module.xml";
        if (LOG.isTraceEnabled()) {
            LOG.trace("attempt:" + identifier);
        }
        try {
            ClassLoader cl = ApplicationEnvironment.get().getBootstrapClassLoader();
            if (LOG.isTraceEnabled()) {
                LOG.trace("classloader: " + cl);
                LOG.trace("path: " + path);
            }
            URL url = cl.getResource(path);
            if (url == null && cl != ClasspathModuleFinder.class.getClassLoader()) {
                url = ClasspathModuleFinder.class.getClassLoader().getResource(path);
            }
            if (url == null) {
                if (LOG.isTraceEnabled()) {
                    LOG.trace("not found: " + identifier);
                }
                return null;
            }
            final URL base = new URL(url, "./");
            if (LOG.isTraceEnabled()) {
                LOG.trace("base of " + identifier + ": " + base);
            }
            InputStream in = url.openStream();
            Path explodedJar = NestedJarResourceLoader.explodedJar(base);
            ModuleSpec moduleSpec = null;
            try {
                moduleSpec = ModuleXmlParser.parseModuleXml((rootPath, loaderPath, loaderName) -> NestedJarResourceLoader.loaderFor(base, rootPath, loaderPath, loaderName), MavenResolvers.get(), (explodedJar == null ? "/" : explodedJar.toAbsolutePath().toString()), in, path.toString(), delegateLoader, simpleIdentifier);
            } catch (IOException e) {
                throw new ModuleLoadException(e);
            } finally {
                try {
                    in.close();
                } catch (IOException e) {
                    throw new ModuleLoadException(e);
                }
            }
            if (LOG.isTraceEnabled()) {
                LOG.trace("Loaded ModuleSpec: " + moduleSpec.getName());
            }
            return moduleSpec;
        } catch (IOException e) {
            throw new ModuleLoadException(e);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : Path(java.nio.file.Path) ModuleLoader(org.jboss.modules.ModuleLoader) ModuleFinder(org.jboss.modules.ModuleFinder) ApplicationEnvironment(org.wildfly.swarm.bootstrap.env.ApplicationEnvironment) ModuleLoadException(org.jboss.modules.ModuleLoadException) URL(java.net.URL) BootstrapLogger(org.wildfly.swarm.bootstrap.logging.BootstrapLogger) ModuleXmlParser(org.jboss.modules.xml.ModuleXmlParser) IOException(java.io.IOException) Performance(org.wildfly.swarm.bootstrap.performance.Performance) Path(java.nio.file.Path) 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)

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