use of org.jboss.jandex.IndexWriter in project wildfly by wildfly.
the class EarModuleDeploymentTestCase method jarArchive.
public static JavaArchive jarArchive(String name, Class<?>... classes) throws Exception {
JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class, name).addAsResource(new StringAsset("<ejb-jar version=\"3.0\" metadata-complete=\"true\"></ejb-jar>"), "META-INF/ejb-jar.xml");
Indexer indexer = new Indexer();
for (Class<?> aClass : classes) {
javaArchive.addClass(aClass);
try (InputStream resource = aClass.getResourceAsStream(aClass.getSimpleName() + ".class")) {
indexer.index(resource);
}
}
Index index = indexer.complete();
ByteArrayOutputStream data = new ByteArrayOutputStream();
IndexWriter writer = new IndexWriter(data);
writer.write(index);
javaArchive.addAsManifestResource(new ByteArrayAsset(data.toByteArray()), "jandex.idx");
return javaArchive;
}
use of org.jboss.jandex.IndexWriter in project wildfly-swarm by wildfly-swarm.
the class DeploymentIndexTest method createIndexAsset.
private Asset createIndexAsset(Class<?>... classes) throws IOException {
Indexer indexer = new Indexer();
for (Class<?> clazz : classes) {
try (InputStream stream = DeploymentIndexTest.class.getClassLoader().getResourceAsStream(clazz.getName().replace(".", "/") + ".class")) {
if (stream != null) {
indexer.index(stream);
}
}
}
Index index = indexer.complete();
ByteArrayOutputStream out = new ByteArrayOutputStream();
new IndexWriter(out).write(index);
return new ByteArrayAsset(out.toByteArray());
}
use of org.jboss.jandex.IndexWriter in project scout.rt by eclipse.
the class JandexInventoryBuilder method writeIndex.
protected void writeIndex(Index index, LockedFile f) {
try {
LOG.debug("Write jandex index file '{}'", f);
new IndexWriter(f.newOutputStream()).write(index);
} catch (Exception ex) {
LOG.warn("Error while writing jandex index file '{}'", f, ex);
}
}
use of org.jboss.jandex.IndexWriter 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.jandex.IndexWriter 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