Search in sources :

Example 1 with JarIndexer

use of org.jboss.jandex.JarIndexer in project core by weld.

the class BeanDiscoveryWithJandexIndexTest method createJandexIndexAsset.

/**
 * Exports the JavaArchive to a temporary file and uses {@link JarIndexer} to write an jandex.idx file.
 */
private static Asset createJandexIndexAsset(JavaArchive archiveToIndex) {
    Asset jandexIndexAsset = EmptyAsset.INSTANCE;
    try {
        final File tempJarFile = File.createTempFile("BeanDiscoveryWithJandexIndexTest", ".jar");
        tempJarFile.deleteOnExit();
        archiveToIndex.as(ZipExporter.class).exportTo(tempJarFile, true);
        final Indexer indexer = new Indexer();
        final Result result = JarIndexer.createJarIndex(tempJarFile, indexer, false, false, false);
        final File indexFile = result.getOutputFile();
        indexFile.deleteOnExit();
        jandexIndexAsset = new FileAsset(indexFile);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return jandexIndexAsset;
}
Also used : FileAsset(org.jboss.shrinkwrap.api.asset.FileAsset) JarIndexer(org.jboss.jandex.JarIndexer) Indexer(org.jboss.jandex.Indexer) ZipExporter(org.jboss.shrinkwrap.api.exporter.ZipExporter) EmptyAsset(org.jboss.shrinkwrap.api.asset.EmptyAsset) Asset(org.jboss.shrinkwrap.api.asset.Asset) FileAsset(org.jboss.shrinkwrap.api.asset.FileAsset) IOException(java.io.IOException) File(java.io.File) Result(org.jboss.jandex.Result)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 Indexer (org.jboss.jandex.Indexer)1 JarIndexer (org.jboss.jandex.JarIndexer)1 Result (org.jboss.jandex.Result)1 Asset (org.jboss.shrinkwrap.api.asset.Asset)1 EmptyAsset (org.jboss.shrinkwrap.api.asset.EmptyAsset)1 FileAsset (org.jboss.shrinkwrap.api.asset.FileAsset)1 ZipExporter (org.jboss.shrinkwrap.api.exporter.ZipExporter)1