Search in sources :

Example 1 with ArchiveAsset

use of org.jboss.shrinkwrap.api.asset.ArchiveAsset 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)

Example 2 with ArchiveAsset

use of org.jboss.shrinkwrap.api.asset.ArchiveAsset in project wildfly by wildfly.

the class SubDirectoryModuleDeploymentTestCase method createDeployment.

@Deployment
public static Archive<?> createDeployment() {
    final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, "subdirectory.ear");
    final JavaArchive jarOne = ShrinkWrap.create(JavaArchive.class, "ejb.jar");
    jarOne.addClass(MessageBean.class);
    ear.addAsModule(new ArchiveAsset(jarOne, ZipExporter.class), "subdir/ejb/ejb.jar");
    final WebArchive war = ShrinkWrap.create(WebArchive.class, "web.war");
    war.addClass(MessageServlet.class);
    ear.addAsModule(new ArchiveAsset(war, ZipExporter.class), "subdir/web/web.war");
    return ear;
}
Also used : EnterpriseArchive(org.jboss.shrinkwrap.api.spec.EnterpriseArchive) ZipExporter(org.jboss.shrinkwrap.api.exporter.ZipExporter) WebArchive(org.jboss.shrinkwrap.api.spec.WebArchive) ArchiveAsset(org.jboss.shrinkwrap.api.asset.ArchiveAsset) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) Deployment(org.jboss.arquillian.container.test.api.Deployment)

Example 3 with ArchiveAsset

use of org.jboss.shrinkwrap.api.asset.ArchiveAsset in project camel by apache.

the class ManagedSEDeployableContainer method deploy.

@Override
public ProtocolMetaData deploy(final Archive<?> archive) throws DeploymentException {
    LOGGER.info("Deploying " + archive.getName());
    // First of all clear the list of previously materialized deployments - otherwise the class path would grow indefinitely
    materializedFiles.clear();
    // Create a new classpath
    classpathDependencies.clear();
    if (ClassPath.isRepresentedBy(archive)) {
        for (Node child : archive.get(ClassPath.ROOT_ARCHIVE_PATH).getChildren()) {
            Asset asset = child.getAsset();
            if (asset instanceof ArchiveAsset) {
                Archive<?> assetArchive = ((ArchiveAsset) asset).getArchive();
                if (ClassPathDirectory.isRepresentedBy(assetArchive)) {
                    materializeDirectory(assetArchive);
                } else {
                    materializeArchive(assetArchive);
                }
            }
        }
    } else {
        materializeArchive(archive);
    }
    Properties systemProperties = getSystemProperties(archive);
    readJarFilesFromDirectory();
    addTestResourcesDirectory(systemProperties);
    List<String> processCommand = buildProcessCommand(systemProperties);
    logExecutedCommand(processCommand);
    // Launch the process
    final ProcessBuilder processBuilder = new ProcessBuilder(processCommand);
    String path = systemProperties.getProperty("container.user.dir");
    if (path != null) {
        processBuilder.directory(new File(path));
    }
    processBuilder.environment().put("JAVA_HOME", new File(System.getProperty(SYSPROP_KEY_JAVA_HOME)).getAbsolutePath());
    processBuilder.redirectErrorStream(true);
    processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
    processBuilder.redirectOutput(ProcessBuilder.Redirect.INHERIT);
    try {
        process = processBuilder.start();
    } catch (final IOException e) {
        throw new DeploymentException("Could not start process", e);
    }
    int finalWaitTime = debugModeEnabled ? (3 * waitTime) : waitTime;
    // Wait for socket connection
    if (!isServerStarted(host, port, finalWaitTime)) {
        throw new DeploymentException("Child JVM process failed to start within " + finalWaitTime + " seconds.");
    }
    if (!isJMXTestRunnerMBeanRegistered(host, port, finalWaitTime)) {
        throw new DeploymentException("JMXTestRunnerMBean not registered within " + finalWaitTime + " seconds.");
    }
    ProtocolMetaData protocolMetaData = new ProtocolMetaData();
    protocolMetaData.addContext(new JMXContext(host, port));
    return protocolMetaData;
}
Also used : Node(org.jboss.shrinkwrap.api.Node) ArchiveAsset(org.jboss.shrinkwrap.api.asset.ArchiveAsset) IOException(java.io.IOException) Properties(java.util.Properties) ClassAsset(org.jboss.shrinkwrap.api.asset.ClassAsset) Asset(org.jboss.shrinkwrap.api.asset.Asset) ArchiveAsset(org.jboss.shrinkwrap.api.asset.ArchiveAsset) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException) ProtocolMetaData(org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData) File(java.io.File) JMXContext(org.jboss.arquillian.container.spi.client.protocol.metadata.JMXContext)

Example 4 with ArchiveAsset

use of org.jboss.shrinkwrap.api.asset.ArchiveAsset in project teiid by teiid.

the class IntegrationTestDynamicViewDefinition method testVdbZipWithDDLAndUDF.

@Test
public void testVdbZipWithDDLAndUDF() throws Exception {
    JavaArchive udfJar = ShrinkWrap.create(JavaArchive.class, "func.jar").addClasses(SampleFunctions.class);
    JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "temp.jar").addAsManifestResource(UnitTestUtil.getTestDataFile("vdb.xml")).addAsResource(UnitTestUtil.getTestDataFile("test.ddl")).addAsResource(new ArchiveAsset(udfJar, ZipExporter.class), "lib/udf.jar");
    admin.deploy("dynamic-ddl.vdb", jar.as(ZipExporter.class).exportAsInputStream());
    assertTrue(AdminUtil.waitForVDBLoad(admin, "dynamic-ddl", 1, 3));
    this.internalConnection = TeiidDriver.getInstance().connect("jdbc:teiid:dynamic-ddl@mm://localhost:31000;user=user;password=user", null);
    // $NON-NLS-1$
    execute("SELECT * from stock");
    assertRowCount(1);
    // $NON-NLS-1$
    execute("SELECT func('a')");
    assertRowCount(1);
}
Also used : ZipExporter(org.jboss.shrinkwrap.api.exporter.ZipExporter) ArchiveAsset(org.jboss.shrinkwrap.api.asset.ArchiveAsset) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) Test(org.junit.Test)

Example 5 with ArchiveAsset

use of org.jboss.shrinkwrap.api.asset.ArchiveAsset in project wildfly-swarm by wildfly-swarm.

the class JAXRSArchiveImpl method isJAXRS.

private static boolean isJAXRS(ArchivePath path, Asset asset) {
    if (asset == null) {
        return false;
    }
    if (asset instanceof ArchiveAsset) {
        return isJAXRS(((ArchiveAsset) asset).getArchive());
    }
    if (!path.get().endsWith(".class")) {
        return false;
    }
    try (InputStream in = asset.openStream()) {
        ClassReader reader = new ClassReader(in);
        JAXRSAnnotationSeekingClassVisitor visitor = new JAXRSAnnotationSeekingClassVisitor();
        reader.accept(visitor, 0);
        return visitor.isFound();
    } catch (IOException ignored) {
    }
    return false;
}
Also used : InputStream(java.io.InputStream) ClassReader(org.objectweb.asm.ClassReader) ArchiveAsset(org.jboss.shrinkwrap.api.asset.ArchiveAsset) IOException(java.io.IOException)

Aggregations

ArchiveAsset (org.jboss.shrinkwrap.api.asset.ArchiveAsset)6 IOException (java.io.IOException)4 InputStream (java.io.InputStream)3 Node (org.jboss.shrinkwrap.api.Node)2 ZipExporter (org.jboss.shrinkwrap.api.exporter.ZipExporter)2 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)2 ClassReader (org.objectweb.asm.ClassReader)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Properties (java.util.Properties)1 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1 Produces (javax.enterprise.inject.Produces)1 Inject (javax.inject.Inject)1 DeploymentException (org.jboss.arquillian.container.spi.client.container.DeploymentException)1 JMXContext (org.jboss.arquillian.container.spi.client.protocol.metadata.JMXContext)1 ProtocolMetaData (org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData)1 Deployment (org.jboss.arquillian.container.test.api.Deployment)1 CompositeIndex (org.jboss.jandex.CompositeIndex)1