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();
}
}
}
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();
}
}
}
Aggregations