org.jboss.modules.Resource Java Examples

The following examples show how to use org.jboss.modules.Resource. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CompositeIndexProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private Index calculateModuleIndex(final Module module) throws ModuleLoadException, IOException {
    final Indexer indexer = new Indexer();
    final PathFilter filter = PathFilters.getDefaultImportFilter();
    final Iterator<Resource> iterator = module.iterateResources(filter);
    while (iterator.hasNext()) {
        Resource resource = iterator.next();
        if(resource.getName().endsWith(".class")) {
            try (InputStream in = resource.openStream()) {
                indexer.index(in);
            } catch (Exception e) {
                ServerLogger.DEPLOYMENT_LOGGER.cannotIndexClass(resource.getName(), resource.getURL().toExternalForm(), e);
            }
        }
    }
    return indexer.complete();
}
 
Example #2
Source File: VFSResourceLoader.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/** {@inheritDoc} */
public Resource getResource(final String name) {
    return doPrivileged(new PrivilegedAction<Resource>() {
        public Resource run() {
            try {
                final VirtualFile file = getExistentVirtualFile(PathUtils.canonicalize(name));
                if (file == null) {
                    return null;
                }
                return new VFSEntryResource(file.getPathNameRelativeTo(root), file, file.toURL());
            } catch (MalformedURLException e) {
                // must be invalid...?  (todo: check this out)
                return null;
            }
        }
    });
}
 
Example #3
Source File: ManagementConsoleDeploymentProducer.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@Produces
public Archive managementConsoleWar() throws Exception {
    // Load the management-ui webjars.
    WARArchive war = ShrinkWrap.create(WARArchive.class, "management-console-ui.war");
    Module module = Module.getBootModuleLoader().loadModule("org.jboss.as.console");
    Iterator<Resource> resources = module.globResources("*");
    while (resources.hasNext()) {
        Resource each = resources.next();
        war.add(new UrlAsset(each.getURL()), each.getName());
    }
    war.setContextRoot(this.fraction.contextRoot());
    return war;
}
 
Example #4
Source File: PackageScanClassResolverAssociationHandler.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Override
protected void find(PackageScanFilter filter, String packageName, ClassLoader classLoader, Set<Class<?>> classes) {
    LOGGER.debug("Searching for: {} in package: {} using classloader: {}", new Object[] { filter, packageName, classLoader });

    // Would be the case for the system classloader
    if (!(classLoader instanceof ModuleClassLoader)) {
        super.find(filter, packageName, classLoader, classes);
        return;
    }

    int classLoadCount = classes.size();

    ModuleClassLoader moduleClassLoader = (ModuleClassLoader) classLoader;
    Iterator<Resource> itres = moduleClassLoader.iterateResources("/", true);
    while (itres.hasNext()) {
        Resource resource = itres.next();
        String resname = resource.getName();
        if (resname.startsWith(packageName) && resname.endsWith(".class")) {
            String className = resname.substring(0, resname.length() - 6).replace('/', '.');
            try {
                Class<?> loadedClass = moduleClassLoader.loadClass(className);
                if (filter.matches(loadedClass)) {
                    LOGGER.debug("Found type in package scan: {}", loadedClass.getName());
                    classes.add(loadedClass);
                }
            } catch (ClassNotFoundException ex) {
                //ignore
            }
        }
    }

    // No classes found by previous package scan so delegate to super
    if(classes.size() == classLoadCount) {
        super.find(filter, packageName, classLoader, classes);
    }
}
 
Example #5
Source File: JBossModuleUtilsTest.java    From Nicobar with Apache License 2.0 5 votes vote down vote up
private Set<String> getResourcePaths(ModuleClassLoader moduleClassLoader) {
    Set<String> result = new HashSet<String>();
    Iterator<Resource> resources = moduleClassLoader.iterateResources("", true);
    while (resources.hasNext()) {
        Resource resource = resources.next();
        result.add(resource.getName());
    }
    return result;
}