Search in sources :

Example 51 with ModuleLoadException

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

the class BootstrapModuleFinder method buildModule.

@Override
public void buildModule(ModuleSpec.Builder builder, ModuleLoader delegateLoader) throws ModuleLoadException {
    try (AutoCloseable handle = Performance.accumulate("module: Bootstrap")) {
        if (LOG.isTraceEnabled()) {
            LOG.trace("Loading module");
        }
        ApplicationEnvironment env = ApplicationEnvironment.get();
        PathFilter filter = new PathFilter() {

            @Override
            public boolean accept(String path) {
                return path.endsWith("/module.xml");
            }
        };
        env.bootstrapArtifactsAsCoordinates().forEach((coords) -> {
            try {
                File artifact = MavenResolvers.get().resolveJarArtifact(coords);
                if (artifact == null) {
                    throw new RuntimeException("Unable to resolve artifact from coordinates: " + coords);
                }
                JarFile jar = JarFileManager.INSTANCE.addJarFile(artifact);
                ResourceLoader originaloader = ResourceLoaders.createJarResourceLoader(artifact.getName(), jar);
                builder.addResourceRoot(ResourceLoaderSpec.createResourceLoaderSpec(ResourceLoaders.createFilteredResourceLoader(filter, originaloader)));
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        });
        builder.addDependency(DependencySpec.createLocalDependencySpec());
        builder.addDependency(DependencySpec.createModuleDependencySpec("org.jboss.modules"));
        builder.addDependency(DependencySpec.createModuleDependencySpec("org.jboss.shrinkwrap"));
        builder.addDependency(DependencySpec.createModuleDependencySpec("org.yaml.snakeyaml"));
        HashSet<String> paths = new HashSet<>();
        paths.add("org/wildfly/swarm/bootstrap/env");
        paths.add("org/wildfly/swarm/bootstrap/logging");
        paths.add("org/wildfly/swarm/bootstrap/modules");
        paths.add("org/wildfly/swarm/bootstrap/performance");
        paths.add("org/wildfly/swarm/bootstrap/util");
        builder.addDependency(DependencySpec.createSystemDependencySpec(paths, true));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : ResourceLoader(org.jboss.modules.ResourceLoader) PathFilter(org.jboss.modules.filter.PathFilter) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) ApplicationEnvironment(org.wildfly.swarm.bootstrap.env.ApplicationEnvironment) JarFile(java.util.jar.JarFile) File(java.io.File) IOException(java.io.IOException) ModuleLoadException(org.jboss.modules.ModuleLoadException) HashSet(java.util.HashSet)

Example 52 with ModuleLoadException

use of org.jboss.modules.ModuleLoadException 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)

Example 53 with ModuleLoadException

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

the class BootstrapClasspathModuleFinderTest method testMain.

@Test
public void testMain() {
    BootstrapClasspathModuleFinder finder = new BootstrapClasspathModuleFinder();
    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 54 with ModuleLoadException

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

the class BootstrapClasspathModuleFinderTest method testMissingMain.

@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();
    }
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) ModuleSpec(org.jboss.modules.ModuleSpec) Test(org.junit.Test)

Example 55 with ModuleLoadException

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

the class ClasspathModuleFinderTest method testMissingSlot.

@Test
public void testMissingSlot() {
    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)

Aggregations

ModuleLoadException (org.jboss.modules.ModuleLoadException)62 Module (org.jboss.modules.Module)30 IOException (java.io.IOException)17 ModuleIdentifier (org.jboss.modules.ModuleIdentifier)13 ModuleSpec (org.jboss.modules.ModuleSpec)12 ModuleLoader (org.jboss.modules.ModuleLoader)10 Test (org.junit.Test)9 URL (java.net.URL)8 File (java.io.File)7 InputStream (java.io.InputStream)7 ArrayList (java.util.ArrayList)7 ModuleClassLoader (org.jboss.modules.ModuleClassLoader)7 HashSet (java.util.HashSet)6 OperationFailedException (org.jboss.as.controller.OperationFailedException)6 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)6 ModelNode (org.jboss.dmr.ModelNode)6 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)5 TldMetaData (org.jboss.metadata.web.spec.TldMetaData)5 ModuleNotFoundException (org.jboss.modules.ModuleNotFoundException)5 HashMap (java.util.HashMap)4