Search in sources :

Example 1 with Resource

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

the class Swarm method initializeConfigFiltersFatJar.

private void initializeConfigFiltersFatJar() throws ModuleLoadException, IOException, ClassNotFoundException {
    Indexer indexer = new Indexer();
    Module appModule = Module.getBootModuleLoader().loadModule(APPLICATION_MODULE_NAME);
    Iterator<Resource> iter = appModule.iterateResources(PathFilters.acceptAll());
    while (iter.hasNext()) {
        Resource each = iter.next();
        if (each.getName().endsWith(".class")) {
            if (!each.getName().equals("module-info.class")) {
                try (InputStream is = each.openStream()) {
                    indexer.index(is);
                } catch (IOException e) {
                // ignore
                }
            }
        }
    }
    Index index = indexer.complete();
    Set<ClassInfo> impls = index.getAllKnownImplementors(DotName.createSimple(ConfigurationFilter.class.getName()));
    for (ClassInfo each : impls) {
        String name = each.name().toString();
        Class<? extends ConfigurationFilter> cls = (Class<? extends ConfigurationFilter>) appModule.getClassLoader().loadClass(name);
        try {
            ConfigurationFilter filter = cls.newInstance();
            this.configView.withFilter(filter);
        } catch (InstantiationException | IllegalAccessException e) {
            e.printStackTrace();
        }
    }
}
Also used : ConfigurationFilter(org.wildfly.swarm.spi.api.ConfigurationFilter) InputStream(java.io.InputStream) Resource(org.jboss.modules.Resource) Index(org.jboss.jandex.Index) IOException(java.io.IOException) Indexer(org.jboss.jandex.Indexer) Module(org.jboss.modules.Module) ClassInfo(org.jboss.jandex.ClassInfo)

Example 2 with Resource

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

the class OnDemandLocalLoader method loadResourceLocal.

public List<Resource> loadResourceLocal(String name) {
    String[] tokens = name.split("/");
    LocalLoader ll = doUpdate(tokens);
    return (ll != null ? ll.loadResourceLocal(name) : Collections.<Resource>emptyList());
}
Also used : Resource(org.jboss.modules.Resource) LocalLoader(org.jboss.modules.LocalLoader)

Example 3 with Resource

use of org.jboss.modules.Resource in project wildfly by wildfly.

the class HostExcludesTestCase method retrieveAvailableExtensions.

/**
 * Retrieve the list of all modules which export locally a resource that implements a org.jboss.as.controller.Extension.
 * This list is considered the list of all available extensions that can be added to a server.
 *
 * It is assumed that the module which is added as an extension has the org.jboss.as.controller.Extension service as
 * a local resource.
 */
private Set<String> retrieveAvailableExtensions() throws IOException {
    final Set<String> result = new HashSet<>();
    LocalModuleLoader ml = new LocalModuleLoader(getModuleRoots());
    Iterator<String> moduleNames = ml.iterateModules((String) null, true);
    while (moduleNames.hasNext()) {
        String moduleName = moduleNames.next();
        Module module;
        try {
            module = ml.loadModule(moduleName);
            List<Resource> resources = module.getClassLoader().loadResourceLocal("META-INF/services/org.jboss.as.controller.Extension");
            if (!resources.isEmpty()) {
                result.add(moduleName);
            }
        } catch (ModuleLoadException e) {
            Logger.getLogger(HostExcludesTestCase.class).warn("Failed to load module " + moduleName + " to check if it is an extension", e);
        }
    }
    return result;
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) Resource(org.jboss.modules.Resource) Module(org.jboss.modules.Module) LocalModuleLoader(org.jboss.modules.LocalModuleLoader) HashSet(java.util.HashSet)

Example 4 with Resource

use of org.jboss.modules.Resource in project wildfly by wildfly.

the class ExternalBeanArchiveProcessor method findExportedLocalBeansXml.

private Set<URL> findExportedLocalBeansXml(Module dependencyModule) {
    HashSet<URL> ret = new HashSet<>();
    Enumeration<URL> exported = dependencyModule.getExportedResources(META_INF_BEANS_XML);
    if (exported.hasMoreElements()) {
        Set<URL> exportedSet = new HashSet<>(Collections.list(exported));
        Collection<Resource> locals = dependencyModule.getClassLoader().loadResourceLocal(META_INF_BEANS_XML);
        if (!locals.isEmpty()) {
            for (Resource local : locals) {
                URL url = local.getURL();
                if (exportedSet.contains(url)) {
                    ret.add(url);
                }
            }
            return ret;
        }
    }
    return null;
}
Also used : Resource(org.jboss.modules.Resource) URL(java.net.URL) HashSet(java.util.HashSet)

Example 5 with Resource

use of org.jboss.modules.Resource in project wildfly by wildfly.

the class ExternalTldParsingDeploymentProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (!DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) {
        // Skip non web deployments
        return;
    }
    final WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    if (warMetaData == null || warMetaData.getMergedJBossWebMetaData() == null) {
        return;
    }
    TldsMetaData tldsMetaData = deploymentUnit.getAttachment(TldsMetaData.ATTACHMENT_KEY);
    Map<String, TldMetaData> tlds = tldsMetaData.getTlds();
    Set<String> sharedTldUris = new HashSet<>();
    for (TldMetaData shared : tldsMetaData.getSharedTlds(deploymentUnit)) {
        sharedTldUris.add(shared.getUri());
    }
    Module module = deploymentUnit.getAttachment(Attachments.MODULE);
    try {
        Iterator<Resource> resources = module.globResources("META-INF/**.tld");
        while (resources.hasNext()) {
            final Resource resource = resources.next();
            // waste time re-parsing them
            if (resource.getURL().toString().contains("com/sun/jsf-impl/main")) {
                continue;
            }
            if (resource.getName().startsWith("META-INF/")) {
                if (tlds.containsKey(resource.getName())) {
                    continue;
                }
                if (resource.getURL().getProtocol().equals("vfs")) {
                    continue;
                }
                final TldMetaData value = parseTLD(resource);
                if (sharedTldUris.contains(value.getUri())) {
                    // don't re-include shared TLD's
                    continue;
                }
                String key = "/" + resource.getName();
                if (!tlds.containsKey(key)) {
                    tlds.put(key, value);
                }
                if (!tlds.containsKey(value.getUri())) {
                    tlds.put(value.getUri(), value);
                }
                if (value.getListeners() != null) {
                    for (ListenerMetaData l : value.getListeners()) {
                        List<ListenerMetaData> listeners = warMetaData.getMergedJBossWebMetaData().getListeners();
                        if (listeners == null) {
                            warMetaData.getMergedJBossWebMetaData().setListeners(listeners = new ArrayList<ListenerMetaData>());
                        }
                        listeners.add(l);
                    }
                }
            }
        }
    } catch (ModuleLoadException e) {
        throw new DeploymentUnitProcessingException(e);
    }
}
Also used : TldMetaData(org.jboss.metadata.web.spec.TldMetaData) ModuleLoadException(org.jboss.modules.ModuleLoadException) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) WarMetaData(org.jboss.as.web.common.WarMetaData) Resource(org.jboss.modules.Resource) ArrayList(java.util.ArrayList) ListenerMetaData(org.jboss.metadata.web.spec.ListenerMetaData) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) HashSet(java.util.HashSet)

Aggregations

Resource (org.jboss.modules.Resource)7 Module (org.jboss.modules.Module)4 HashSet (java.util.HashSet)3 InputStream (java.io.InputStream)2 ModuleLoadException (org.jboss.modules.ModuleLoadException)2 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Manifest (java.util.jar.Manifest)1 Produces (javax.enterprise.inject.Produces)1 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)1 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)1 WarMetaData (org.jboss.as.web.common.WarMetaData)1 ClassInfo (org.jboss.jandex.ClassInfo)1 Index (org.jboss.jandex.Index)1 Indexer (org.jboss.jandex.Indexer)1 ListenerMetaData (org.jboss.metadata.web.spec.ListenerMetaData)1 TldMetaData (org.jboss.metadata.web.spec.TldMetaData)1 LocalLoader (org.jboss.modules.LocalLoader)1