Search in sources :

Example 1 with ConfigurationFilter

use of org.wildfly.swarm.spi.api.ConfigurationFilter 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 ConfigurationFilter

use of org.wildfly.swarm.spi.api.ConfigurationFilter in project wildfly-swarm by wildfly-swarm.

the class Swarm method initializeConfigFiltersClassPath.

private void initializeConfigFiltersClassPath() throws IOException, ClassNotFoundException {
    String classpath = System.getProperty("java.class.path");
    String[] locations = classpath.split(System.getProperty("path.separator"));
    Indexer indexer = new Indexer();
    for (String location : locations) {
        File file = new File(location);
        JavaArchive archive = null;
        if (file.exists()) {
            if (file.isDirectory()) {
                archive = ShrinkWrap.create(ExplodedImporter.class).importDirectory(file).as(JavaArchive.class);
            } else {
                archive = ShrinkWrap.create(ZipImporter.class).importFrom(file).as(JavaArchive.class);
            }
            Map<ArchivePath, Node> content = archive.getContent();
            for (ArchivePath path : content.keySet()) {
                if (path.get().endsWith(".class") && !path.get().endsWith("module-info.class")) {
                    Node node = content.get(path);
                    try {
                        indexer.index(node.getAsset().openStream());
                    } 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>) Class.forName(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) Node(org.jboss.shrinkwrap.api.Node) Index(org.jboss.jandex.Index) IOException(java.io.IOException) ExplodedImporter(org.jboss.shrinkwrap.api.importer.ExplodedImporter) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) ArchivePath(org.jboss.shrinkwrap.api.ArchivePath) Indexer(org.jboss.jandex.Indexer) ZipImporter(org.jboss.shrinkwrap.api.importer.ZipImporter) JarFile(java.util.jar.JarFile) File(java.io.File) ClassInfo(org.jboss.jandex.ClassInfo)

Aggregations

IOException (java.io.IOException)2 ClassInfo (org.jboss.jandex.ClassInfo)2 Index (org.jboss.jandex.Index)2 Indexer (org.jboss.jandex.Indexer)2 ConfigurationFilter (org.wildfly.swarm.spi.api.ConfigurationFilter)2 File (java.io.File)1 InputStream (java.io.InputStream)1 JarFile (java.util.jar.JarFile)1 Module (org.jboss.modules.Module)1 Resource (org.jboss.modules.Resource)1 ArchivePath (org.jboss.shrinkwrap.api.ArchivePath)1 Node (org.jboss.shrinkwrap.api.Node)1 ExplodedImporter (org.jboss.shrinkwrap.api.importer.ExplodedImporter)1 ZipImporter (org.jboss.shrinkwrap.api.importer.ZipImporter)1 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)1