use of org.jboss.jandex.IndexReader in project core by weld.
the class JandexIndexBeanArchiveHandler method getIndex.
private Index getIndex(final File beanArchiveFile) {
Preconditions.checkArgumentNotNull(beanArchiveFile, "beanArchiveFile");
logger.debugv("Try to get Jandex index for: {0}", beanArchiveFile);
Index index = null;
try (ZipFile zip = new ZipFile(beanArchiveFile)) {
// Open the bean archive and try to find the index file
ZipEntry entry = zip.getEntry(JANDEX_INDEX_NAME);
if (entry != null) {
index = new IndexReader(zip.getInputStream(entry)).read();
}
} catch (IllegalArgumentException e) {
CommonLogger.LOG.warnv("Jandex index is not valid: {0}", beanArchiveFile);
} catch (UnsupportedVersion e) {
CommonLogger.LOG.warnv("Version of Jandex index is not supported: {0}", beanArchiveFile);
} catch (IOException e) {
CommonLogger.LOG.warnv("Cannot get Jandex index from: {0}", beanArchiveFile);
CommonLogger.LOG.catchingDebug(e);
}
logger.debugv("Jandex index {0}found: {1}", index == null ? "NOT " : "", beanArchiveFile);
return index;
}
use of org.jboss.jandex.IndexReader in project wildfly-swarm by wildfly-swarm.
the class DeploymentProducer method index.
private void index(Archive<?> archive, List<IndexView> indexes) throws IOException {
LOGGER.debugv("Indexing archive: {0}", archive.getName());
// First try to load attached index
Node indexNode = archive.get(ArchivePaths.create(INDEX_LOCATION));
if (indexNode != null) {
try (InputStream indexStream = indexNode.getAsset().openStream()) {
LOGGER.debugv("Loading attached index from archive: {0}", archive.getName());
indexes.add(new IndexReader(indexStream).read());
}
} else {
// No index found - index all classes found
Indexer indexer = new Indexer();
for (Map.Entry<ArchivePath, Node> entry : archive.getContent(this::isClass).entrySet()) {
try (InputStream contentStream = entry.getValue().getAsset().openStream()) {
LOGGER.debugv("Indexing asset: {0} from archive: {1}", entry.getKey().get(), archive.getName());
indexer.index(contentStream);
} catch (IOException indexerIOException) {
LOGGER.warnv(indexerIOException, "Failed parsing: {0} from archive: {1}", entry.getKey().get(), archive.getName());
}
}
Index index = indexer.complete();
indexes.add(index);
}
if (archive instanceof LibraryContainer) {
for (Map.Entry<ArchivePath, Node> entry : archive.getContent(a -> a.get().endsWith(JAR_SUFFIX)).entrySet()) {
if (entry.getValue().getAsset() instanceof ArchiveAsset) {
ArchiveAsset archiveAsset = (ArchiveAsset) entry.getValue().getAsset();
index(archiveAsset.getArchive(), indexes);
} else {
try (InputStream contentStream = entry.getValue().getAsset().openStream()) {
JARArchive jarArchive = ShrinkWrap.create(JARArchive.class, entry.getKey().get()).as(ZipImporter.class).importFrom(contentStream).as(JARArchive.class);
index(jarArchive, indexes);
}
}
}
}
}
use of org.jboss.jandex.IndexReader in project wildfly-swarm by wildfly-swarm.
the class FractionProducingExtension method uninstalledFractionClasses.
@SuppressWarnings("unchecked")
private Set<Class<? extends Fraction>> uninstalledFractionClasses(Set<Type> installedClasses) throws ModuleLoadException, IOException, ClassNotFoundException {
Set<String> installedClassNames = installedClasses.stream().map(Type::getTypeName).collect(Collectors.toSet());
List<String> moduleNames = ApplicationEnvironment.get().bootstrapModules();
ClassLoader cl = Module.getBootModuleLoader().loadModule("swarm.container").getClassLoader();
Set<Class<? extends Fraction>> fractionClasses = new HashSet<>();
for (String moduleName : moduleNames) {
Module module = Module.getBootModuleLoader().loadModule(moduleName);
InputStream indexStream = module.getClassLoader().getResourceAsStream("META-INF/jandex.idx");
if (indexStream != null) {
IndexReader reader = new IndexReader(indexStream);
Index index = reader.read();
Set<ClassInfo> impls = index.getAllKnownImplementors(DotName.createSimple(Fraction.class.getName()));
for (ClassInfo impl : impls) {
if (!installedClassNames.contains(impl.name().toString())) {
Class<? extends Fraction> fractionClass = (Class<? extends Fraction>) cl.loadClass(impl.name().toString());
fractionClasses.add(fractionClass);
}
}
}
}
return fractionClasses;
}
use of org.jboss.jandex.IndexReader in project scout.rt by eclipse.
the class JandexInventoryBuilder method readIndex.
/**
* @param indexUri
* @return index or null
*/
protected Index readIndex(URI indexUri, InputStream in) {
try {
Index index = new IndexReader(in).read();
LOG.debug("Found pre-built {}", indexUri);
return index;
} catch (Exception ex) {
throw new PlatformException("Error reading index '{}'", indexUri, ex);
}
}
Aggregations