Java Code Examples for org.jboss.jandex.Indexer#complete()

The following examples show how to use org.jboss.jandex.Indexer#complete() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestClassIndexer.java    From quarkus with Apache License 2.0 6 votes vote down vote up
public static Index indexTestClasses(Class<?> testClass) {
    final Indexer indexer = new Indexer();
    final Path testClassesLocation = getTestClassesLocation(testClass);
    try {
        if (Files.isDirectory(testClassesLocation)) {
            indexTestClassesDir(indexer, testClassesLocation);
        } else {
            try (FileSystem jarFs = FileSystems.newFileSystem(testClassesLocation, null)) {
                for (Path p : jarFs.getRootDirectories()) {
                    indexTestClassesDir(indexer, p);
                }
            }
        }
    } catch (IOException e) {
        throw new UncheckedIOException("Unable to index the test-classes/ directory.", e);
    }
    return indexer.complete();
}
 
Example 2
Source File: BeanArchives.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private static IndexView buildAdditionalIndex() {
    Indexer indexer = new Indexer();
    // CDI API
    index(indexer, ActivateRequestContext.class.getName());
    index(indexer, Default.class.getName());
    index(indexer, Any.class.getName());
    index(indexer, Named.class.getName());
    index(indexer, Initialized.class.getName());
    index(indexer, BeforeDestroyed.class.getName());
    index(indexer, Destroyed.class.getName());
    index(indexer, Intercepted.class.getName());
    index(indexer, Model.class.getName());
    // Arc built-in beans
    index(indexer, ActivateRequestContextInterceptor.class.getName());
    index(indexer, InjectableRequestContextController.class.getName());
    return indexer.complete();
}
 
Example 3
Source File: JaxRsDataObjectScannerTestBase.java    From smallrye-open-api with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void createIndex() {
    Indexer indexer = new Indexer();

    // Stand-in stuff
    index(indexer, "io/smallrye/openapi/runtime/scanner/CollectionStandin.class");
    index(indexer, "io/smallrye/openapi/runtime/scanner/IterableStandin.class");
    index(indexer, "io/smallrye/openapi/runtime/scanner/MapStandin.class");

    // Test samples
    indexDirectory(indexer, "test/io/smallrye/openapi/runtime/scanner/entities/");

    // Microprofile TCK classes
    index(indexer, "org/eclipse/microprofile/openapi/apps/airlines/model/Airline.class");
    index(indexer, "org/eclipse/microprofile/openapi/apps/airlines/model/Booking.class");
    index(indexer, "org/eclipse/microprofile/openapi/apps/airlines/model/CreditCard.class");
    index(indexer, "org/eclipse/microprofile/openapi/apps/airlines/model/Flight.class");
    index(indexer, "org/eclipse/microprofile/openapi/apps/airlines/model/Airline.class");

    // Test containers
    //indexDirectory(indexer, "test/io/smallrye/openapi/runtime/scanner/entities/");

    index = indexer.complete();
}
 
Example 4
Source File: IndexInitializer.java    From smallrye-graphql with Apache License 2.0 6 votes vote down vote up
private IndexView createIndexView(Set<URL> urls) {
    Indexer indexer = new Indexer();
    for (URL url : urls) {
        try {
            if (url.toString().endsWith(DOT_JAR) || url.toString().endsWith(DOT_WAR)) {
                SmallRyeGraphQLServletLogging.log.processingFile(url.toString());
                processJar(url.openStream(), indexer);
            } else {
                processFolder(url, indexer);
            }
        } catch (IOException ex) {
            SmallRyeGraphQLServletLogging.log.cannotProcessFile(url.toString(), ex);
        }
    }

    return indexer.complete();
}
 
Example 5
Source File: NestedSchemaReferenceTests.java    From smallrye-open-api with Apache License 2.0 6 votes vote down vote up
@Test
public void testSimpleNestedSchemaOnParameter() throws IOException, JSONException {
    Indexer indexer = new Indexer();

    // Test samples
    index(indexer, "test/io/smallrye/openapi/runtime/scanner/resources/FooResource.class");
    index(indexer, "test/io/smallrye/openapi/runtime/scanner/resources/FooResource$Foo.class");
    index(indexer, "test/io/smallrye/openapi/runtime/scanner/resources/FooResource$Bar.class");

    OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner(nestingSupportConfig(), indexer.complete());

    OpenAPI result = scanner.scan();

    printToConsole(result);
    assertJsonEquals("refsEnabled.resource.simple.expected.json", result);
}
 
Example 6
Source File: AdvertisingMetadataProcessorTest.java    From thorntail with Apache License 2.0 5 votes vote down vote up
Index createIndex(Archive<?> archive) throws IOException {
    Indexer indexer = new Indexer();

    Map<ArchivePath, Node> c = archive.getContent();
    for (Map.Entry<ArchivePath, Node> each : c.entrySet()) {
        if (each.getKey().get().endsWith(".class")) {
            indexer.index(each.getValue().getAsset().openStream());
        }
    }


    return indexer.complete();
}
 
Example 7
Source File: ApplicationArchiveBuildStep.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private static Index indexJar(JarFile file) throws IOException {
    Indexer indexer = new Indexer();
    Enumeration<JarEntry> e = file.entries();
    while (e.hasMoreElements()) {
        JarEntry entry = e.nextElement();
        if (entry.getName().endsWith(".class")) {
            try (InputStream inputStream = file.getInputStream(entry)) {
                indexer.index(inputStream);
            }
        }
    }
    return indexer.complete();
}
 
Example 8
Source File: ArcTestContainer.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private Index index(Iterable<Class<?>> classes) throws IOException {
    Indexer indexer = new Indexer();
    for (Class<?> clazz : classes) {
        try (InputStream stream = ArcTestContainer.class.getClassLoader()
                .getResourceAsStream(clazz.getName().replace('.', '/') + ".class")) {
            indexer.index(stream);
        }
    }
    return indexer.complete();
}
 
Example 9
Source File: Basics.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public static Index index(Class<?>... classes) throws IOException {
    Indexer indexer = new Indexer();
    for (Class<?> clazz : classes) {
        try (InputStream stream = Basics.class.getClassLoader()
                .getResourceAsStream(clazz.getName().replace('.', '/') + ".class")) {
            indexer.index(stream);
        }
    }
    return indexer.complete();
}
 
Example 10
Source File: IndexScannerTestBase.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
public static Index indexOf(Class<?>... classes) {
    Indexer indexer = new Indexer();

    for (Class<?> klazz : classes) {
        index(indexer, pathOf(klazz));
    }

    return indexer.complete();
}
 
Example 11
Source File: ArchiveUtil.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
/**
 * Index the ShrinkWrap archive to produce a jandex index.
 * 
 * @param config OpenApiConfig
 * @param archive Shrinkwrap Archive
 * @return indexed classes in Archive
 */
public static IndexView archiveToIndex(OpenApiConfig config, Archive<?> archive) {
    if (archive == null) {
        throw TckMessages.msg.nullArchive();
    }

    Indexer indexer = new Indexer();
    index(indexer, "io/smallrye/openapi/runtime/scanner/CollectionStandin.class");
    index(indexer, "io/smallrye/openapi/runtime/scanner/IterableStandin.class");
    index(indexer, "io/smallrye/openapi/runtime/scanner/MapStandin.class");
    indexArchive(config, indexer, archive);
    return indexer.complete();
}
 
Example 12
Source File: SpringDataObjectScannerTestBase.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void createIndex() {
    Indexer indexer = new Indexer();

    // Test samples
    indexDirectory(indexer, "test/io/smallrye/openapi/runtime/scanner/entities/");

    index = indexer.complete();
}
 
Example 13
Source File: MicroOuterDeployer.java    From piranha with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private byte[] createIndex(ShrinkWrapResource applicationResource, List<ShrinkWrapResource> libResources) {
    Indexer indexer = new Indexer();
    
    // Add all classes from the library resources (the jar files in WEB-INF/lib)
    libResources
        .stream()
        .forEach(libResource -> 
            libResource.getAllLocations()
                       .filter(e -> e.endsWith(".class"))
                       .forEach(className -> addToIndex(className, libResource, indexer)));
    
    
    // Add all classes from the application resource (the class files in WEB-INF/classes to the indexer)
    // Note this must be done last as according to the Servlet spec, WEB-INF/classes overrides WEB-INF/lib)
    applicationResource
        .getAllLocations()
        .filter(e -> e.endsWith(".class"))
        .forEach(className -> addToIndex(className, applicationResource, indexer));
    
    
    Index index = indexer.complete();
    
    // Write the index out to a byte array
    
    ByteArrayOutputStream indexBytes = new ByteArrayOutputStream();
    
    IndexWriter writer = new IndexWriter(indexBytes);
    
    try {
        writer.write(index);
    } catch (IOException ioe) {
        if (LOGGER.isLoggable(WARNING)) {
            LOGGER.log(WARNING, "Unable to write out index", ioe);
        }
    }
    
    return indexBytes.toByteArray();
}
 
Example 14
Source File: JaxRsAnnotationScannerTest.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testHiddenOperationPathNotPresent() throws IOException, JSONException {
    Indexer indexer = new Indexer();

    // Test samples
    index(indexer, "test/io/smallrye/openapi/runtime/scanner/resources/HiddenOperationResource.class");

    OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner(emptyConfig(), indexer.complete());

    OpenAPI result = scanner.scan();

    printToConsole(result);
    assertJsonEquals("resource.testHiddenOperationPathNotPresent.json", result);
}
 
Example 15
Source File: JaxRsAnnotationScannerTest.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testHiddenOperationNotPresent() throws IOException, JSONException {
    Indexer indexer = new Indexer();

    // Test samples
    index(indexer, "test/io/smallrye/openapi/runtime/scanner/resources/HiddenOperationResource.class");
    index(indexer, "test/io/smallrye/openapi/runtime/scanner/resources/VisibleOperationResource.class");

    OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner(emptyConfig(), indexer.complete());

    OpenAPI result = scanner.scan();

    printToConsole(result);
    assertJsonEquals("resource.testHiddenOperationNotPresent.json", result);
}
 
Example 16
Source File: Jar.java    From helidon-build-tools with Apache License 2.0 5 votes vote down vote up
private Index buildIndex() {
    Log.info("  creating missing index for CDI beans archive %s", this);
    final Indexer indexer = new Indexer();
    classEntries().forEach(entry -> {
        try {
            indexer.index(entry.data());
        } catch (IOException e) {
            Log.warn("  could not index class %s in %s: %s", entry.path(), this, e.getMessage());
        }
    });
    return indexer.complete();
}
 
Example 17
Source File: JandexUtilTest.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private static Index index(Class<?>... classes) {
    Indexer indexer = new Indexer();
    for (Class<?> clazz : classes) {
        try {
            try (InputStream stream = JandexUtilTest.class.getClassLoader()
                    .getResourceAsStream(clazz.getName().replace('.', '/') + ".class")) {
                indexer.index(stream);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    return indexer.complete();
}
 
Example 18
Source File: FieldNameTest.java    From smallrye-graphql with Apache License 2.0 5 votes vote down vote up
@Test
public void testFieldNamePriority() {
    Indexer indexer = new Indexer();
    indexDirectory(indexer, "io/smallrye/graphql/schema/creator/fieldnameapp");
    IndexView index = indexer.complete();

    ClassInfo classInfo = index.getClassByName(DotName.createSimple(SomeObjectAnnotatedGetters.class.getName()));
    // @Name
    MethodInfo methodInfo = classInfo.method("getName");
    Annotations annotations = Annotations.getAnnotationsForMethod(methodInfo);
    assertEquals("a", FieldCreator.getFieldName(Direction.OUT, annotations, "name"));

    // @Query
    methodInfo = classInfo.method("getQuery");
    annotations = Annotations.getAnnotationsForMethod(methodInfo);
    assertEquals("d", FieldCreator.getFieldName(Direction.OUT, annotations, "query"));

    // @JsonbProperty
    methodInfo = classInfo.method("getJsonbProperty");
    annotations = Annotations.getAnnotationsForMethod(methodInfo);
    assertEquals("f", FieldCreator.getFieldName(Direction.OUT, annotations, "jsonbProperty"));

    // no annotation
    methodInfo = classInfo.method("getFieldName");
    annotations = Annotations.getAnnotationsForMethod(methodInfo);
    assertEquals("fieldName", FieldCreator.getFieldName(Direction.OUT, annotations, "fieldName"));
}
 
Example 19
Source File: SchemaBuilderTest.java    From smallrye-graphql with Apache License 2.0 5 votes vote down vote up
static IndexView getTCKIndex() {
    Indexer indexer = new Indexer();
    indexDirectory(indexer, "org/eclipse/microprofile/graphql/tck/apps/basic/api");
    indexDirectory(indexer, "org/eclipse/microprofile/graphql/tck/apps/superhero/api");
    indexDirectory(indexer, "org/eclipse/microprofile/graphql/tck/apps/superhero/db");
    indexDirectory(indexer, "org/eclipse/microprofile/graphql/tck/apps/superhero/model");
    return indexer.complete();
}
 
Example 20
Source File: KogitoAssetsProcessor.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@BuildStep(loadsApplicationClasses = true)
public void generateModel(ArchiveRootBuildItem root,
                          BuildProducer<GeneratedBeanBuildItem> generatedBeans,
                          CombinedIndexBuildItem combinedIndexBuildItem,
                          LaunchModeBuildItem launchMode,
                          LiveReloadBuildItem liveReload,
                          BuildProducer<NativeImageResourceBuildItem> resource,
                          BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
                          CurateOutcomeBuildItem curateOutcomeBuildItem) throws IOException, BootstrapDependencyProcessingException {

    if (liveReload.isLiveReload()) {
        return;
    }

    AppPaths appPaths = new AppPaths( root.getPaths() );

    ApplicationGenerator appGen = createApplicationGenerator(appPaths, combinedIndexBuildItem);
    Collection<GeneratedFile> generatedFiles = appGen.generate();

    Collection<GeneratedFile> javaFiles = generatedFiles.stream().filter( f -> f.relativePath().endsWith( ".java" ) ).collect( Collectors.toCollection( ArrayList::new ));
    writeGeneratedFiles(appPaths, generatedFiles);

    if (!javaFiles.isEmpty()) {

        Indexer kogitoIndexer = new Indexer();
        Set<DotName> kogitoIndex = new HashSet<>();

        MemoryFileSystem trgMfs = new MemoryFileSystem();
        CompilationResult result = compile( appPaths, trgMfs, curateOutcomeBuildItem.getEffectiveModel(), javaFiles, launchMode.getLaunchMode() );
        register(appPaths, trgMfs, generatedBeans,
                (className, data) -> generateBeanBuildItem( combinedIndexBuildItem, kogitoIndexer, kogitoIndex, className, data ),
                launchMode.getLaunchMode(), result);


        Index index = kogitoIndexer.complete();

        generatePersistenceInfo(appPaths, generatedBeans, CompositeIndex.create(combinedIndexBuildItem.getIndex(), index),
                launchMode, resource, curateOutcomeBuildItem);


        reflectiveClass.produce(
                new ReflectiveClassBuildItem(true, true, "org.kie.kogito.event.AbstractDataEvent"));
        reflectiveClass.produce(
                new ReflectiveClassBuildItem(true, true, "org.kie.kogito.services.event.AbstractProcessDataEvent"));
        reflectiveClass.produce(
                new ReflectiveClassBuildItem(true, true, "org.kie.kogito.services.event.ProcessInstanceDataEvent"));
        reflectiveClass.produce(
                new ReflectiveClassBuildItem(true, true, "org.kie.kogito.services.event.VariableInstanceDataEvent"));
        reflectiveClass.produce(
                new ReflectiveClassBuildItem(true, true, "org.kie.kogito.services.event.impl.ProcessInstanceEventBody"));
        reflectiveClass.produce(
                new ReflectiveClassBuildItem(true, true, "org.kie.kogito.services.event.impl.NodeInstanceEventBody"));
        reflectiveClass.produce(
                new ReflectiveClassBuildItem(true, true, "org.kie.kogito.services.event.impl.ProcessErrorEventBody"));
        reflectiveClass.produce(
                new ReflectiveClassBuildItem(true, true, "org.kie.kogito.services.event.impl.VariableInstanceEventBody"));
        reflectiveClass.produce(
                new ReflectiveClassBuildItem(true, true, "org.kie.kogito.services.event.UserTaskInstanceDataEvent"));
        reflectiveClass.produce(
                new ReflectiveClassBuildItem(true, true, "org.kie.kogito.services.event.impl.UserTaskInstanceEventBody"));

        Collection<ClassInfo> dataEvents = index
                .getAllKnownSubclasses(createDotName("org.kie.kogito.event.AbstractDataEvent"));

        dataEvents.forEach(c -> reflectiveClass.produce(
                new ReflectiveClassBuildItem(true, true, c.name().toString())));

        writeGeneratedFiles(appPaths, getJsonSchemaFiles(index, trgMfs));
    }
}