Search in sources :

Example 56 with ModuleLoadException

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

the class ModuleXmlParser method parseModuleXml.

/**
 * Parse a {@code module.xml} file.
 *
 * @param factory the resource root factory to use (must not be {@code null})
 * @param mavenResolver the Maven artifact resolver to use (must not be {@code null})
 * @param rootPath the root path to send in to the resource root factory (must not be {@code null})
 * @param source a stream of the {@code module.xml} content (must not be {@code null})
 * @param moduleInfoFile the {@code File} of the {@code module.xml} content (must not be {@code null})
 * @param moduleLoader the module loader to use for dependency specifications (must not be {@code null})
 * @param moduleName the module name of the module to load
 * @return a module specification
 * @throws ModuleLoadException if a dependency could not be established or another error occurs
 * @throws IOException if I/O fails
 */
public static ModuleSpec parseModuleXml(final ResourceRootFactory factory, final MavenResolver mavenResolver, final String rootPath, InputStream source, final String moduleInfoFile, final ModuleLoader moduleLoader, final String moduleName) throws ModuleLoadException, IOException {
    try {
        final MXParser parser = new MXParser();
        parser.setFeature(FEATURE_PROCESS_NAMESPACES, true);
        parser.setInput(source, null);
        return parseDocument(mavenResolver, factory, rootPath, parser, moduleLoader, moduleName);
    } catch (XmlPullParserException e) {
        throw new ModuleLoadException("Error loading module from " + moduleInfoFile, e);
    } finally {
        safeClose(source);
    }
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException)

Example 57 with ModuleLoadException

use of org.jboss.modules.ModuleLoadException in project ceylon by eclipse.

the class CeylonModuleLoader method findModule.

@Override
protected ModuleSpec findModule(ModuleIdentifier moduleIdentifier) throws ModuleLoadException {
    try {
        final ArtifactResult artifact = findArtifact(moduleIdentifier);
        if (artifact == null)
            return null;
        if (!artifact.version().equals(moduleIdentifier.getSlot())) {
            AliasModuleSpec alias = (AliasModuleSpec) ModuleSpec.buildAlias(moduleIdentifier, ModuleIdentifier.create(artifact.name(), artifact.version())).create();
            return alias;
        }
        final File moduleFile = artifact.artifact();
        final boolean isDefault = RepositoryManager.DEFAULT_MODULE.equals(moduleIdentifier.getName());
        boolean isMaven = artifact.type() == ArtifactResultType.MAVEN;
        final List<DependencySpec> deps = new ArrayList<>();
        ModuleSpec.Builder builder = ModuleSpec.build(moduleIdentifier);
        if (!ModuleUtil.isMavenJarlessModule(moduleFile)) {
            // add module's jar
            ResourceLoader resourceLoader = ResourceLoaderProvider.getResourceLoader(moduleIdentifier, repository, moduleFile);
            // filter
            PathFilter filter = (artifact.filter() != null ? new CMRPathFilter(artifact.filter()) : PathFilters.acceptAll());
            // module resource root
            ResourceLoaderSpec rls = ResourceLoaderSpec.createResourceLoaderSpec(resourceLoader, filter);
            builder.addResourceRoot(rls);
        }
        // add potential native lib lookup
        ResourceLoader nativeLoader = new NativeLibraryResourceLoader(new File(moduleFile.getParent(), "lib"));
        builder.addResourceRoot(ResourceLoaderSpec.createResourceLoaderSpec(nativeLoader));
        Graph.Vertex<ModuleIdentifier, Boolean> vertex = graph.createVertex(moduleIdentifier, moduleIdentifier);
        DependencySpec lds = DependencySpec.createLocalDependencySpec();
        // local resources
        builder.addDependency(lds);
        deps.add(lds);
        if (isDefault == false) {
            Node<ArtifactResult> root = new Node<>();
            for (ArtifactResult i : artifact.dependencies()) {
                // Skip test scopes
                if (i.moduleScope() == ModuleScope.TEST)
                    continue;
                final String name = i.name();
                // route logging to JBoss LogManager
                if (isLogging(deps, builder, i)) {
                    continue;
                }
                // skip JDK modules
                if (JDK_MODULE_NAMES.contains(name)) {
                    continue;
                }
                boolean isDepMaven = MavenArtifactContext.NAMESPACE.equals(i.namespace());
                if (i.optional()) {
                    Node<ArtifactResult> current = root;
                    String[] tokens = name.split("\\.");
                    for (String token : tokens) {
                        Node<ArtifactResult> child = current.getChild(token);
                        if (child == null)
                            child = current.addChild(token);
                        current = child;
                    }
                    current.setValue(i);
                } else {
                    DependencySpec mds = createModuleDependency(i, exportMavenImports && isMaven && isDepMaven);
                    builder.addDependency(mds);
                    deps.add(mds);
                }
                ModuleIdentifier mi = createModuleIdentifier(i);
                Graph.Vertex<ModuleIdentifier, Boolean> dv = graph.createVertex(mi, mi);
                Graph.Edge.create(i.exported() || (exportMavenImports && isMaven && isDepMaven), vertex, dv);
            }
            if (root.isEmpty() == false) {
                LocalLoader onDemandLoader = new OnDemandLocalLoader(moduleIdentifier, this, root);
                builder.setFallbackLoader(onDemandLoader);
            }
        }
        // automagically import the JDK module
        builder.addDependency(JDK_DEPENDENCY);
        // no need to track system deps -- cannot be updated anyway
        createModuleDependency(vertex, deps, builder, LANGUAGE, false);
        // add runtime utils
        final DependencySpec sds = DependencySpec.createModuleDependencySpec(PathFilters.match(CEYLON_RUNTIME_PATH), PathFilters.rejectAll(), this, RUNTIME, true);
        builder.addDependency(sds);
        deps.add(sds);
        Graph.Vertex<ModuleIdentifier, Boolean> sdsv = graph.createVertex(RUNTIME, RUNTIME);
        Graph.Edge.create(false, vertex, sdsv);
        dependencies.put(moduleIdentifier, deps);
        // Stef: enable back when we upgrade jboss modules
        // index(artifact.artifact(), moduleIdentifier);
        UtilRegistryTransformer transformer = new UtilRegistryTransformer(moduleIdentifier, artifact);
        builder.setClassFileTransformer(transformer);
        // make sure we set our own class loader factory so we can find the transformer back from the class loader
        // this is used in the language module to force module metamodel registration
        builder.setModuleClassLoaderFactory(new CeylonModuleClassLoader.CeylonModuleClassLoaderFactory(transformer));
        return builder.create();
    } catch (Exception e) {
        throw new ModuleLoadException(e);
    }
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) NativeLibraryResourceLoader(org.jboss.modules.NativeLibraryResourceLoader) ResourceLoader(org.jboss.modules.ResourceLoader) PathFilter(org.jboss.modules.filter.PathFilter) ArrayList(java.util.ArrayList) AliasModuleSpec(org.jboss.modules.AliasModuleSpec) ModuleSpec(org.jboss.modules.ModuleSpec) AliasModuleSpec(org.jboss.modules.AliasModuleSpec) DependencySpec(org.jboss.modules.DependencySpec) ModuleIdentifier(org.jboss.modules.ModuleIdentifier) LocalLoader(org.jboss.modules.LocalLoader) Builder(org.jboss.modules.ModuleSpec.Builder) ModuleLoadException(org.jboss.modules.ModuleLoadException) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult) ResourceLoaderSpec(org.jboss.modules.ResourceLoaderSpec) NativeLibraryResourceLoader(org.jboss.modules.NativeLibraryResourceLoader) File(java.io.File)

Example 58 with ModuleLoadException

use of org.jboss.modules.ModuleLoadException in project ceylon by eclipse.

the class ModuleXmlParser method parseResourcePaths.

static List<String> parseResourcePaths(final InputStream source, ModuleIdentifier mi) throws ModuleLoadException {
    try {
        final XMLInputFactory inputFactory = INPUT_FACTORY;
        setIfSupported(inputFactory, XMLInputFactory.IS_VALIDATING, Boolean.FALSE);
        setIfSupported(inputFactory, XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
        final XMLStreamReader streamReader = inputFactory.createXMLStreamReader(source);
        try {
            List<String> resourcePaths = new ArrayList<String>();
            parseResourcePaths(streamReader, resourcePaths);
            return resourcePaths;
        } finally {
            safeClose(streamReader);
        }
    } catch (XMLStreamException e) {
        throw new ModuleLoadException("Error reading resource paths: " + mi, e);
    } finally {
        safeClose(source);
    }
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) XMLStreamReader(javax.xml.stream.XMLStreamReader) XMLStreamException(javax.xml.stream.XMLStreamException) ArrayList(java.util.ArrayList) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Example 59 with ModuleLoadException

use of org.jboss.modules.ModuleLoadException in project ceylon by eclipse.

the class RemoteModuleLoader method fetchRemoteModule.

protected boolean fetchRemoteModule(ModuleIdentifier moduleIdentifier) throws ModuleLoadException {
    try {
        String localPath = toPathString(moduleIdentifier, false);
        String remotePath = toPathString(moduleIdentifier, true);
        InputStream moduleXMLStream;
        File localModuleXML = getLocalFile(localPath + XML);
        boolean existsLocally = localModuleXML.exists();
        if (existsLocally)
            moduleXMLStream = new FileInputStream(localModuleXML);
        else
            moduleXMLStream = getInputStream(remotePath, XML);
        if (moduleXMLStream != null) {
            if (existsLocally == false) {
                File moduleXML = writeStream(moduleXMLStream, localPath + XML);
                moduleXMLStream = new FileInputStream(moduleXML);
            }
            List<String> resourcePaths = parseResourcePaths(moduleXMLStream, moduleIdentifier);
            for (String resource : resourcePaths) {
                String fullName = localPath + resource;
                if (getLocalFile(fullName).exists() == false) {
                    InputStream jarStream = getInputStream(remotePath, resource);
                    if (jarStream != null) {
                        writeStream(jarStream, fullName);
                    }
                }
                if (getLocalFile(fullName + INDEX).exists() == false) {
                    InputStream indexStream = getInputStream(remotePath, resource + INDEX);
                    if (indexStream != null) {
                        writeStream(indexStream, fullName + INDEX);
                    }
                }
            }
            log("Module fetch completed OK: " + moduleIdentifier);
            return true;
        } else {
            return false;
        }
    } catch (IOException e) {
        e.printStackTrace();
        throw new ModuleLoadException("Cannot fetch remote resource: " + moduleIdentifier, e);
    }
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 60 with ModuleLoadException

use of org.jboss.modules.ModuleLoadException in project ceylon by eclipse.

the class OnDemandLocalLoader method doUpdate.

protected LocalLoader doUpdate(String[] tokens) {
    Node<ArtifactResult> current = root;
    for (String token : tokens) {
        current = current.getChild(token);
        if (current == null)
            return null;
        // noinspection SynchronizationOnLocalVariableOrMethodParameter
        synchronized (current) {
            ArtifactResult i = current.getValue();
            if (i != null) {
                // remove, so we don't loop; should not happen though
                current.remove();
                DependencySpec mds = loader.createModuleDependency(i, false);
                try {
                    Module owner = loader.preloadModule(target);
                    // update / add lazy dep
                    loader.updateModule(owner, mds);
                    Module module = loader.loadModule(CeylonModuleLoader.createModuleIdentifier(i));
                    return new ModuleLocalLoader(module);
                } catch (ModuleLoadException ignored) {
                    return null;
                }
            }
        }
    }
    return null;
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) DependencySpec(org.jboss.modules.DependencySpec) Module(org.jboss.modules.Module) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult)

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