Search in sources :

Example 21 with ByteArrayAsset

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

the class AbstractBootstrapIntegrationTestCase method createBootstrapArchive.

protected JavaArchive createBootstrapArchive(String mainClassName, String appArtifact) throws IOException {
    JavaArchive archive = ShrinkWrap.create(JavaArchive.class);
    archive.as(ZipImporter.class).importFrom(new JarFile(findBootstrapJar()));
    Properties props = new Properties();
    if (appArtifact != null) {
        props.put(BootstrapProperties.APP_ARTIFACT, appArtifact);
    }
    ByteArrayOutputStream propsOut = new ByteArrayOutputStream();
    props.store(propsOut, "");
    propsOut.close();
    archive.addAsManifestResource(new ByteArrayAsset(propsOut.toByteArray()), "wildfly-swarm.properties");
    if (appArtifact != null) {
        WildFlySwarmManifest manifest = new WildFlySwarmManifest();
        manifest.setAsset(appArtifact);
        archive.add(new StringAsset(manifest.toString()), WildFlySwarmManifest.CLASSPATH_LOCATION);
    }
    if (mainClassName != null) {
        Manifest manifest = new Manifest();
        manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
        manifest.getMainAttributes().put(new Attributes.Name("Wildfly-Swarm-Main-Class"), mainClassName);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        manifest.write(out);
        out.close();
        archive.addAsManifestResource(new ByteArrayAsset(out.toByteArray()), "MANIFEST.MF");
    }
    return archive;
}
Also used : StringAsset(org.jboss.shrinkwrap.api.asset.StringAsset) ByteArrayAsset(org.jboss.shrinkwrap.api.asset.ByteArrayAsset) ZipImporter(org.jboss.shrinkwrap.api.importer.ZipImporter) Attributes(java.util.jar.Attributes) ByteArrayOutputStream(java.io.ByteArrayOutputStream) JarFile(java.util.jar.JarFile) Properties(java.util.Properties) BootstrapProperties(org.wildfly.swarm.bootstrap.util.BootstrapProperties) Manifest(java.util.jar.Manifest) WildFlySwarmManifest(org.wildfly.swarm.bootstrap.env.WildFlySwarmManifest) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) WildFlySwarmManifest(org.wildfly.swarm.bootstrap.env.WildFlySwarmManifest)

Example 22 with ByteArrayAsset

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

the class EarClassPath2TestCase method deploy.

@Deployment
public static Archive<?> deploy() {
    WebArchive war = ShrinkWrap.create(WebArchive.class);
    JavaArchive libJar = ShrinkWrap.create(JavaArchive.class);
    libJar.addClasses(TestAA.class, EarClassPath2TestCase.class);
    libJar.addAsManifestResource(new ByteArrayAsset("Class-Path: ../../../cp.jar\n".getBytes(StandardCharsets.UTF_8)), "MANIFEST.MF");
    war.addAsLibraries(libJar);
    EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class);
    ear.addAsModule(war);
    JavaArchive earLib = ShrinkWrap.create(JavaArchive.class, "cp.jar");
    earLib.addClass(TestBB.class);
    ear.addAsModule(earLib);
    return ear;
}
Also used : EnterpriseArchive(org.jboss.shrinkwrap.api.spec.EnterpriseArchive) ByteArrayAsset(org.jboss.shrinkwrap.api.asset.ByteArrayAsset) WebArchive(org.jboss.shrinkwrap.api.spec.WebArchive) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) Deployment(org.jboss.arquillian.container.test.api.Deployment)

Example 23 with ByteArrayAsset

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

the class WeldModuleDeploymentTestCase method createTestModule.

private static void createTestModule(File testModuleRoot) throws IOException {
    if (testModuleRoot.exists()) {
        throw new IllegalArgumentException(testModuleRoot + " already exists");
    }
    File file = new File(testModuleRoot, "main");
    if (!file.mkdirs()) {
        throw new IllegalArgumentException("Could not create " + file);
    }
    URL url = WeldModuleDeploymentTestCase.class.getResource("module.xml");
    if (url == null) {
        throw new IllegalStateException("Could not find module.xml");
    }
    copyFile(new File(file, "module.xml"), url.openStream());
    JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "weldTest.jar");
    jar.addClasses(SimpleBean.class, ModuleEjb.class);
    jar.addAsManifestResource(new StringAsset("<beans bean-discovery-mode=\"all\"></beans>"), "beans.xml");
    Indexer indexer = new Indexer();
    try (InputStream resource = ModuleEjb.class.getResourceAsStream(ModuleEjb.class.getSimpleName() + ".class")) {
        indexer.index(resource);
    }
    Index index = indexer.complete();
    ByteArrayOutputStream data = new ByteArrayOutputStream();
    IndexWriter writer = new IndexWriter(data);
    writer.write(index);
    jar.addAsManifestResource(new ByteArrayAsset(data.toByteArray()), "jandex.idx");
    FileOutputStream jarFile = new FileOutputStream(new File(file, "weldTest.jar"));
    try {
        jar.as(ZipExporter.class).exportTo(jarFile);
    } finally {
        jarFile.flush();
        jarFile.close();
    }
}
Also used : StringAsset(org.jboss.shrinkwrap.api.asset.StringAsset) ByteArrayAsset(org.jboss.shrinkwrap.api.asset.ByteArrayAsset) InputStream(java.io.InputStream) ZipExporter(org.jboss.shrinkwrap.api.exporter.ZipExporter) Index(org.jboss.jandex.Index) ByteArrayOutputStream(java.io.ByteArrayOutputStream) URL(java.net.URL) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) Indexer(org.jboss.jandex.Indexer) IndexWriter(org.jboss.jandex.IndexWriter) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 24 with ByteArrayAsset

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

the class WebModuleDeploymentTestCase method createTestModule.

private static void createTestModule(File testModuleRoot) throws IOException {
    if (testModuleRoot.exists()) {
        throw new IllegalArgumentException(testModuleRoot + " already exists");
    }
    File file = new File(testModuleRoot, "main");
    if (!file.mkdirs()) {
        throw new IllegalArgumentException("Could not create " + file);
    }
    URL url = WebModuleDeploymentTestCase.class.getResource("module.xml");
    if (url == null) {
        throw new IllegalStateException("Could not find module.xml");
    }
    copyFile(new File(file, "module.xml"), url.openStream());
    JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "webTest.jar");
    jar.addClasses(ModuleServlet.class);
    Indexer indexer = new Indexer();
    try (InputStream resource = ModuleServlet.class.getResourceAsStream(ModuleServlet.class.getSimpleName() + ".class")) {
        indexer.index(resource);
    }
    Index index = indexer.complete();
    ByteArrayOutputStream data = new ByteArrayOutputStream();
    IndexWriter writer = new IndexWriter(data);
    writer.write(index);
    jar.addAsManifestResource(new ByteArrayAsset(data.toByteArray()), "jandex.idx");
    FileOutputStream jarFile = new FileOutputStream(new File(file, "webTest.jar"));
    try {
        jar.as(ZipExporter.class).exportTo(jarFile);
    } finally {
        jarFile.flush();
        jarFile.close();
    }
}
Also used : ByteArrayAsset(org.jboss.shrinkwrap.api.asset.ByteArrayAsset) InputStream(java.io.InputStream) ZipExporter(org.jboss.shrinkwrap.api.exporter.ZipExporter) Index(org.jboss.jandex.Index) ByteArrayOutputStream(java.io.ByteArrayOutputStream) URL(java.net.URL) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) Indexer(org.jboss.jandex.Indexer) IndexWriter(org.jboss.jandex.IndexWriter) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Aggregations

ByteArrayAsset (org.jboss.shrinkwrap.api.asset.ByteArrayAsset)24 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)11 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 Deployment (org.jboss.arquillian.container.test.api.Deployment)8 WebArchive (org.jboss.shrinkwrap.api.spec.WebArchive)6 EnterpriseArchive (org.jboss.shrinkwrap.api.spec.EnterpriseArchive)5 InputStream (java.io.InputStream)4 Index (org.jboss.jandex.Index)4 IndexWriter (org.jboss.jandex.IndexWriter)4 Indexer (org.jboss.jandex.Indexer)4 StringAsset (org.jboss.shrinkwrap.api.asset.StringAsset)4 File (java.io.File)3 WildFlySwarmManifest (org.wildfly.swarm.bootstrap.env.WildFlySwarmManifest)3 JAXRSArchive (org.wildfly.swarm.jaxrs.JAXRSArchive)3 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 URL (java.net.URL)2 Properties (java.util.Properties)2 Attributes (java.util.jar.Attributes)2 Manifest (java.util.jar.Manifest)2