Search in sources :

Example 1 with IndexWriter

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;
}
Also used : StringAsset(org.jboss.shrinkwrap.api.asset.StringAsset) Indexer(org.jboss.jandex.Indexer) ByteArrayAsset(org.jboss.shrinkwrap.api.asset.ByteArrayAsset) IndexWriter(org.jboss.jandex.IndexWriter) InputStream(java.io.InputStream) Index(org.jboss.jandex.Index) ByteArrayOutputStream(java.io.ByteArrayOutputStream) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive)

Example 2 with IndexWriter

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());
}
Also used : Indexer(org.jboss.jandex.Indexer) ByteArrayAsset(org.jboss.shrinkwrap.api.asset.ByteArrayAsset) IndexWriter(org.jboss.jandex.IndexWriter) InputStream(java.io.InputStream) Index(org.jboss.jandex.Index) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 3 with IndexWriter

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);
    }
}
Also used : IndexWriter(org.jboss.jandex.IndexWriter) URISyntaxException(java.net.URISyntaxException) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 4 with IndexWriter

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();
    }
}
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 5 with IndexWriter

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

IndexWriter (org.jboss.jandex.IndexWriter)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 InputStream (java.io.InputStream)4 Index (org.jboss.jandex.Index)4 Indexer (org.jboss.jandex.Indexer)4 ByteArrayAsset (org.jboss.shrinkwrap.api.asset.ByteArrayAsset)4 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)3 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 URL (java.net.URL)2 StringAsset (org.jboss.shrinkwrap.api.asset.StringAsset)2 ZipExporter (org.jboss.shrinkwrap.api.exporter.ZipExporter)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 PlatformException (org.eclipse.scout.rt.platform.exception.PlatformException)1