Search in sources :

Example 46 with ModuleLoadException

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

the class Swarm method initializeConfigView.

private void initializeConfigView(Properties props) throws IOException, ModuleLoadException {
    try (AutoCloseable handle = Performance.time("Loading YAML")) {
        if (System.getProperty(SwarmProperties.PROJECT_STAGE_FILE) != null) {
            String file = System.getProperty(SwarmProperties.PROJECT_STAGE_FILE);
            boolean loaded = false;
            try {
                Path path = Paths.get(file);
                if (Files.exists(path)) {
                    this.configView.load("stages", path.toUri().toURL());
                    loaded = true;
                }
            } catch (InvalidPathException e) {
            // ignore
            }
            if (!loaded) {
                // try it as a URL
                try {
                    URL url = new URL(file);
                    this.configView.load("stages", url);
                } catch (MalformedURLException e) {
                // oh well
                }
            }
        }
        // List<String> activatedNames = new ArrayList<>();
        String projectStageProp = System.getProperty(SwarmProperties.PROJECT_STAGE);
        if (projectStageProp == null && props != null) {
            projectStageProp = props.getProperty(SwarmProperties.PROJECT_STAGE);
        }
        if (projectStageProp == null) {
            projectStageProp = this.configView.get().resolve(SwarmProperties.PROJECT_STAGE).withDefault("NOT_FOUND").getValue();
            if (projectStageProp != null && projectStageProp.equals("NOT_FOUND")) {
                projectStageProp = null;
            }
        }
        if (projectStageProp != null) {
            String[] activated = projectStageProp.split(",");
            for (String each : activated) {
                this.configView.load(each);
                this.configView.withProfile(each);
            }
        }
        int counter = 0;
        for (URL config : this.configs) {
            String syntheticName = "cli-" + (++counter);
            this.configView.load(syntheticName, config);
            this.configView.withProfile(syntheticName);
        }
        this.configView.load("stages");
        for (String profile : this.profiles) {
            this.configView.load(profile);
            this.configView.withProfile(profile);
        }
        this.configView.load("defaults");
        initializeConfigFilters();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : Path(java.nio.file.Path) ArchivePath(org.jboss.shrinkwrap.api.ArchivePath) MalformedURLException(java.net.MalformedURLException) InvalidPathException(java.nio.file.InvalidPathException) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) DeploymentException(org.wildfly.swarm.container.DeploymentException) InvalidPathException(java.nio.file.InvalidPathException) ModuleLoadException(org.jboss.modules.ModuleLoadException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 47 with ModuleLoadException

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

the class CommandLine method resolveResource.

private static URL resolveResource(String path) {
    Path candidate = Paths.get(path);
    if (Files.exists(candidate)) {
        try {
            return candidate.toUri().toURL();
        } catch (MalformedURLException e) {
        // ignore
        }
    }
    URL yml = null;
    try {
        Module appModule = Module.getBootModuleLoader().loadModule("swarm.application");
        yml = appModule.getClassLoader().getResource(path);
        if (yml != null) {
            return yml;
        }
    } catch (ModuleLoadException e) {
    // ignore;
    }
    yml = ClassLoader.getSystemClassLoader().getResource(path);
    return yml;
}
Also used : Path(java.nio.file.Path) ModuleLoadException(org.jboss.modules.ModuleLoadException) MalformedURLException(java.net.MalformedURLException) Module(org.jboss.modules.Module) URL(java.net.URL)

Example 48 with ModuleLoadException

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

the class MainInvoker method getMainClass.

public static Class<?> getMainClass(String mainClassName) throws IOException, URISyntaxException, ModuleLoadException, ClassNotFoundException {
    Class<?> mainClass = null;
    try {
        Module module = Module.getBootModuleLoader().loadModule("swarm.application");
        ClassLoader cl = module.getClassLoader();
        mainClass = cl.loadClass(mainClassName);
    } catch (ClassNotFoundException | ModuleLoadException e) {
        ClassLoader cl = ClassLoader.getSystemClassLoader();
        mainClass = cl.loadClass(mainClassName);
    }
    if (mainClass == null) {
        throw new ClassNotFoundException(mainClassName);
    }
    return mainClass;
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) Module(org.jboss.modules.Module)

Example 49 with ModuleLoadException

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

the class ApplicationEnvironment method loadFractionManifestsFromUberjar.

private void loadFractionManifestsFromUberjar() throws IOException, ModuleLoadException {
    if (this.manifests != null) {
        return;
    }
    this.manifests = new ArrayList<>();
    Set<String> modulesManifests = new HashSet<>();
    this.bootstrapModules.forEach(moduleName -> {
        try {
            Module module = Module.getBootModuleLoader().loadModule(moduleName);
            ClassLoader cl = module.getClassLoader();
            Enumeration<URL> results = cl.getResources(FractionManifest.CLASSPATH_LOCATION);
            while (results.hasMoreElements()) {
                URL each = results.nextElement();
                FractionManifest manifest = new FractionManifest(each);
                this.manifests.add(manifest);
                modulesManifests.add(manifest.getGroupId() + manifest.getArtifactId());
            }
        } catch (ModuleLoadException | IOException e) {
            throw new RuntimeException(e);
        }
    });
    bootstrapArtifactsAsCoordinates().forEach((coords) -> {
        try {
            File artifactFile = MavenResolvers.get().resolveJarArtifact(coords);
            if (artifactFile == null) {
                throw new RuntimeException("Unable to resolve artifact from coordinates: " + coords);
            }
            try (ZipFile zip = new ZipFile(artifactFile)) {
                ZipEntry manifestEntry = zip.getEntry(FractionManifest.CLASSPATH_LOCATION);
                if (manifestEntry != null) {
                    FractionManifest manifest = new FractionManifest(zip.getInputStream(manifestEntry));
                    if (!modulesManifests.contains(manifest.getGroupId() + manifest.getArtifactId())) {
                        this.manifests.add(manifest);
                    }
                }
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    });
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException) URL(java.net.URL) ZipFile(java.util.zip.ZipFile) Module(org.jboss.modules.Module) ZipFile(java.util.zip.ZipFile) File(java.io.File) HashSet(java.util.HashSet)

Example 50 with ModuleLoadException

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

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