Search in sources :

Example 1 with LibraryContainer

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);
                }
            }
        }
    }
}
Also used : Produces(javax.enterprise.inject.Produces) DeploymentScoped(org.wildfly.swarm.spi.runtime.annotations.DeploymentScoped) Logger(org.jboss.logging.Logger) Node(org.jboss.shrinkwrap.api.Node) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Indexer(org.jboss.jandex.Indexer) ArchivePath(org.jboss.shrinkwrap.api.ArchivePath) ArchivePaths(org.jboss.shrinkwrap.api.ArchivePaths) CompositeIndex(org.jboss.jandex.CompositeIndex) Map(java.util.Map) Index(org.jboss.jandex.Index) DeploymentContext(org.wildfly.swarm.container.runtime.cdi.DeploymentContext) IndexView(org.jboss.jandex.IndexView) ZipImporter(org.jboss.shrinkwrap.api.importer.ZipImporter) ShrinkWrap(org.jboss.shrinkwrap.api.ShrinkWrap) IndexReader(org.jboss.jandex.IndexReader) JARArchive(org.wildfly.swarm.spi.api.JARArchive) IOException(java.io.IOException) Archive(org.jboss.shrinkwrap.api.Archive) List(java.util.List) LibraryContainer(org.jboss.shrinkwrap.api.container.LibraryContainer) ApplicationScoped(javax.enterprise.context.ApplicationScoped) InputStream(java.io.InputStream) ArchiveAsset(org.jboss.shrinkwrap.api.asset.ArchiveAsset) InputStream(java.io.InputStream) Node(org.jboss.shrinkwrap.api.Node) CompositeIndex(org.jboss.jandex.CompositeIndex) Index(org.jboss.jandex.Index) ArchiveAsset(org.jboss.shrinkwrap.api.asset.ArchiveAsset) IOException(java.io.IOException) ArchivePath(org.jboss.shrinkwrap.api.ArchivePath) Indexer(org.jboss.jandex.Indexer) IndexReader(org.jboss.jandex.IndexReader) LibraryContainer(org.jboss.shrinkwrap.api.container.LibraryContainer) JARArchive(org.wildfly.swarm.spi.api.JARArchive) Map(java.util.Map)

Aggregations

IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1 Produces (javax.enterprise.inject.Produces)1 Inject (javax.inject.Inject)1 CompositeIndex (org.jboss.jandex.CompositeIndex)1 Index (org.jboss.jandex.Index)1 IndexReader (org.jboss.jandex.IndexReader)1 IndexView (org.jboss.jandex.IndexView)1 Indexer (org.jboss.jandex.Indexer)1 Logger (org.jboss.logging.Logger)1 Archive (org.jboss.shrinkwrap.api.Archive)1 ArchivePath (org.jboss.shrinkwrap.api.ArchivePath)1 ArchivePaths (org.jboss.shrinkwrap.api.ArchivePaths)1 Node (org.jboss.shrinkwrap.api.Node)1 ShrinkWrap (org.jboss.shrinkwrap.api.ShrinkWrap)1 ArchiveAsset (org.jboss.shrinkwrap.api.asset.ArchiveAsset)1