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;
}
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;
}
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();
}
}
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();
}
}
Aggregations