use of org.jboss.shrinkwrap.api.container.LibraryContainer 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);
}
}
}
}
}
Aggregations