Search in sources :

Example 6 with Indexer

use of org.jboss.jandex.Indexer in project wildfly by wildfly.

the class AnnotationsTestCase method testProcessConnectionDefinition.

/**
     * Process: ConnectionDefinition -- verification of the
     * processConnectionDefinition method
     *
     * @throws Throwable throwable exception
     */
@Test
public void testProcessConnectionDefinition() throws Throwable {
    try {
        URI uri = getURI("/ra16annoconndef.rar");
        final VirtualFile virtualFile = VFS.getChild(uri);
        final Indexer indexer = new Indexer();
        final List<VirtualFile> classChildren = virtualFile.getChildren(new SuffixMatchFilter(".class", VisitorAttributes.RECURSE_LEAVES_ONLY));
        for (VirtualFile classFile : classChildren) {
            InputStream inputStream = null;
            try {
                inputStream = classFile.openStream();
                indexer.index(inputStream);
            } finally {
                VFSUtils.safeClose(inputStream);
            }
        }
        final Index index = indexer.complete();
        AnnotationRepository ar = new JandexAnnotationRepositoryImpl(index, Thread.currentThread().getContextClassLoader());
        annotations.process(ar, null, Thread.currentThread().getContextClassLoader());
    } catch (Throwable t) {
        fail(t.getMessage());
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) Indexer(org.jboss.jandex.Indexer) InputStream(java.io.InputStream) SuffixMatchFilter(org.jboss.vfs.util.SuffixMatchFilter) AnnotationRepository(org.jboss.jca.common.spi.annotations.repository.AnnotationRepository) Index(org.jboss.jandex.Index) URI(java.net.URI) Test(org.junit.Test)

Example 7 with Indexer

use of org.jboss.jandex.Indexer in project wildfly by wildfly.

the class AnnotationsTestCase method testProcessConnector.

/**
     * Process: Connector -- verification of the processConnector method
     *
     * @throws Throwable throwable exception
     */
@Test
public void testProcessConnector() throws Throwable {
    try {
        URI uri = getURI("/ra16inoutanno.rar");
        final VirtualFile virtualFile = VFS.getChild(uri);
        final Indexer indexer = new Indexer();
        final List<VirtualFile> classChildren = virtualFile.getChildren(new SuffixMatchFilter(".class", VisitorAttributes.RECURSE_LEAVES_ONLY));
        for (VirtualFile classFile : classChildren) {
            InputStream inputStream = null;
            try {
                inputStream = classFile.openStream();
                indexer.index(inputStream);
            } finally {
                VFSUtils.safeClose(inputStream);
            }
        }
        final Index index = indexer.complete();
        AnnotationRepository ar = new JandexAnnotationRepositoryImpl(index, Thread.currentThread().getContextClassLoader());
        annotations.process(ar, null, Thread.currentThread().getContextClassLoader());
    } catch (Throwable t) {
        t.printStackTrace();
        fail(t.getMessage());
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) Indexer(org.jboss.jandex.Indexer) InputStream(java.io.InputStream) SuffixMatchFilter(org.jboss.vfs.util.SuffixMatchFilter) AnnotationRepository(org.jboss.jca.common.spi.annotations.repository.AnnotationRepository) Index(org.jboss.jandex.Index) URI(java.net.URI) Test(org.junit.Test)

Example 8 with Indexer

use of org.jboss.jandex.Indexer in project wildfly by wildfly.

the class AnnotationsTestCase method testProcessAuthenticationMechanism.

/**
     * Process: AuthenticationMechanism -- verification of the
     * processAuthenticationMechanism method
     *
     * @throws Throwable throwable exception
     */
@Test
public void testProcessAuthenticationMechanism() throws Throwable {
    try {
        URI uri = getURI("/ra16annoauthmech.rar");
        final VirtualFile virtualFile = VFS.getChild(uri);
        final Indexer indexer = new Indexer();
        final List<VirtualFile> classChildren = virtualFile.getChildren(new SuffixMatchFilter(".class", VisitorAttributes.RECURSE_LEAVES_ONLY));
        for (VirtualFile classFile : classChildren) {
            InputStream inputStream = null;
            try {
                inputStream = classFile.openStream();
                indexer.index(inputStream);
            } finally {
                VFSUtils.safeClose(inputStream);
            }
        }
        final Index index = indexer.complete();
        AnnotationRepository ar = new JandexAnnotationRepositoryImpl(index, Thread.currentThread().getContextClassLoader());
        annotations.process(ar, null, Thread.currentThread().getContextClassLoader());
    } catch (Throwable t) {
        fail(t.getMessage());
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) Indexer(org.jboss.jandex.Indexer) InputStream(java.io.InputStream) SuffixMatchFilter(org.jboss.vfs.util.SuffixMatchFilter) AnnotationRepository(org.jboss.jca.common.spi.annotations.repository.AnnotationRepository) Index(org.jboss.jandex.Index) URI(java.net.URI) Test(org.junit.Test)

Example 9 with Indexer

use of org.jboss.jandex.Indexer in project wildfly by wildfly.

the class AnnotationsTestCase method testProcessAdministeredObject.

/**
     * Process: AdministeredObject -- verification of the
     * processAdministeredObject method
     *
     * @throws Throwable throwable exception
     */
@Test
public void testProcessAdministeredObject() throws Throwable {
    try {
        URI uri = getURI("/ra16annoadminobj.rar");
        final VirtualFile virtualFile = VFS.getChild(uri);
        final Indexer indexer = new Indexer();
        final List<VirtualFile> classChildren = virtualFile.getChildren(new SuffixMatchFilter(".class", VisitorAttributes.RECURSE_LEAVES_ONLY));
        for (VirtualFile classFile : classChildren) {
            InputStream inputStream = null;
            try {
                inputStream = classFile.openStream();
                indexer.index(inputStream);
            } finally {
                VFSUtils.safeClose(inputStream);
            }
        }
        final Index index = indexer.complete();
        AnnotationRepository ar = new JandexAnnotationRepositoryImpl(index, Thread.currentThread().getContextClassLoader());
        annotations.process(ar, null, Thread.currentThread().getContextClassLoader());
    } catch (Throwable t) {
        fail(t.getMessage());
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) Indexer(org.jboss.jandex.Indexer) InputStream(java.io.InputStream) SuffixMatchFilter(org.jboss.vfs.util.SuffixMatchFilter) AnnotationRepository(org.jboss.jca.common.spi.annotations.repository.AnnotationRepository) Index(org.jboss.jandex.Index) URI(java.net.URI) Test(org.junit.Test)

Example 10 with Indexer

use of org.jboss.jandex.Indexer 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 (final 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

Index (org.jboss.jandex.Index)11 Indexer (org.jboss.jandex.Indexer)11 InputStream (java.io.InputStream)10 URI (java.net.URI)8 AnnotationRepository (org.jboss.jca.common.spi.annotations.repository.AnnotationRepository)8 VirtualFile (org.jboss.vfs.VirtualFile)8 SuffixMatchFilter (org.jboss.vfs.util.SuffixMatchFilter)8 Test (org.junit.Test)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 URL (java.net.URL)2 IndexWriter (org.jboss.jandex.IndexWriter)2 ByteArrayAsset (org.jboss.shrinkwrap.api.asset.ByteArrayAsset)2 ZipExporter (org.jboss.shrinkwrap.api.exporter.ZipExporter)2 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)2 CompositeIndex (org.jboss.as.server.deployment.annotation.CompositeIndex)1