Java Code Examples for io.quarkus.deployment.builditem.CombinedIndexBuildItem#getIndex()

The following examples show how to use io.quarkus.deployment.builditem.CombinedIndexBuildItem#getIndex() . 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: PicocliProcessor.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@BuildStep
void picocliRunner(ApplicationIndexBuildItem applicationIndex,
        CombinedIndexBuildItem combinedIndex,
        BuildProducer<AdditionalBeanBuildItem> additionalBean,
        BuildProducer<QuarkusApplicationClassBuildItem> quarkusApplicationClass,
        BuildProducer<AnnotationsTransformerBuildItem> annotationsTransformer) {
    IndexView index = combinedIndex.getIndex();
    Collection<DotName> topCommands = classesAnnotatedWith(index, TopCommand.class.getName());
    if (topCommands.isEmpty()) {
        List<DotName> commands = classesAnnotatedWith(applicationIndex.getIndex(),
                CommandLine.Command.class.getName());
        if (commands.size() == 1) {
            annotationsTransformer.produce(createAnnotationTransformer(commands.get(0)));
        }
    }
    if (index.getAnnotations(DotName.createSimple(QuarkusMain.class.getName())).isEmpty()) {
        additionalBean.produce(AdditionalBeanBuildItem.unremovableOf(PicocliRunner.class));
        additionalBean.produce(AdditionalBeanBuildItem.unremovableOf(DefaultPicocliCommandLineFactory.class));
        quarkusApplicationClass.produce(new QuarkusApplicationClassBuildItem(PicocliRunner.class));
    }
}
 
Example 2
Source File: SmallRyeGraphQLProcessor.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@Record(ExecutionTime.STATIC_INIT)
@BuildStep
void buildExecutionService(
        BuildProducer<ReflectiveClassBuildItem> reflectiveClassProducer,
        BuildProducer<ReflectiveHierarchyBuildItem> reflectiveHierarchyProducer,
        SmallRyeGraphQLRecorder recorder,
        BeanContainerBuildItem beanContainer,
        CombinedIndexBuildItem combinedIndex) {

    IndexView index = combinedIndex.getIndex();
    Schema schema = SchemaBuilder.build(index);

    recorder.createExecutionService(beanContainer.getValue(), schema);

    // Make sure the complex object from the application can work in native mode
    for (String c : getClassesToRegisterForReflection(schema)) {
        DotName name = DotName.createSimple(c);
        org.jboss.jandex.Type type = org.jboss.jandex.Type.create(name, org.jboss.jandex.Type.Kind.CLASS);
        reflectiveHierarchyProducer.produce(new ReflectiveHierarchyBuildItem(type, index));
    }

    // Make sure the GraphQL Java classes needed for introspection can work in native mode
    reflectiveClassProducer.produce(new ReflectiveClassBuildItem(true, true, getGraphQLJavaClasses()));
}
 
Example 3
Source File: GoogleMailProcessor.java    From camel-quarkus with Apache License 2.0 6 votes vote down vote up
@BuildStep
void registerForReflection(BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
        BuildProducer<UnbannedReflectiveBuildItem> unbannedClass, CombinedIndexBuildItem combinedIndex) {
    IndexView index = combinedIndex.getIndex();

    // Google mail component configuration class reflection
    Collection<AnnotationInstance> uriParams = index
            .getAnnotations(DotName.createSimple("org.apache.camel.spi.UriParams"));

    String[] googleMailConfigClasses = uriParams.stream()
            .map(annotation -> annotation.target())
            .filter(annotationTarget -> annotationTarget.kind().equals(AnnotationTarget.Kind.CLASS))
            .map(annotationTarget -> annotationTarget.asClass().name().toString())
            .filter(className -> className.startsWith("org.apache.camel.component.google.mail"))
            .toArray(String[]::new);

    reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, googleMailConfigClasses));
    unbannedClass.produce(new UnbannedReflectiveBuildItem(googleMailConfigClasses));
}
 
Example 4
Source File: GoogleCalendarProcessor.java    From camel-quarkus with Apache License 2.0 6 votes vote down vote up
@BuildStep
void registerForReflection(BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
        BuildProducer<UnbannedReflectiveBuildItem> unbannedClass, CombinedIndexBuildItem combinedIndex) {
    IndexView index = combinedIndex.getIndex();

    // Google calendar component configuration class reflection
    Collection<AnnotationInstance> uriParams = index
            .getAnnotations(DotName.createSimple("org.apache.camel.spi.UriParams"));

    String[] googleDriveConfigClasses = uriParams.stream()
            .map(annotation -> annotation.target())
            .filter(annotationTarget -> annotationTarget.kind().equals(AnnotationTarget.Kind.CLASS))
            .map(annotationTarget -> annotationTarget.asClass().name().toString())
            .filter(className -> className.startsWith("org.apache.camel.component.google.calendar"))
            .toArray(String[]::new);

    reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, googleDriveConfigClasses));
    unbannedClass.produce(new UnbannedReflectiveBuildItem(googleDriveConfigClasses));
}
 
Example 5
Source File: ResteasyCommonProcessor.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private void registerJsonContextResolver(
        DotName jsonImplementation,
        DotName jsonContextResolver,
        CombinedIndexBuildItem combinedIndexBuildItem,
        BuildProducer<ResteasyJaxrsProviderBuildItem> jaxrsProvider,
        BuildProducer<AdditionalBeanBuildItem> additionalBean,
        BuildProducer<UnremovableBeanBuildItem> unremovable) {

    IndexView index = combinedIndexBuildItem.getIndex();

    jaxrsProvider.produce(new ResteasyJaxrsProviderBuildItem(jsonContextResolver.toString()));

    // this needs to be registered manually since the runtime module is not indexed by Jandex
    additionalBean.produce(AdditionalBeanBuildItem.unremovableOf(jsonContextResolver.toString()));
    Set<String> userSuppliedProducers = getUserSuppliedJsonProducerBeans(index, jsonImplementation);
    if (!userSuppliedProducers.isEmpty()) {
        unremovable.produce(
                new UnremovableBeanBuildItem(new UnremovableBeanBuildItem.BeanClassNamesExclusion(userSuppliedProducers)));
    }
}
 
Example 6
Source File: SpringDataJPAProcessor.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@BuildStep
void build(CombinedIndexBuildItem index,
        BuildProducer<GeneratedClassBuildItem> generatedClasses,
        BuildProducer<GeneratedBeanBuildItem> generatedBeans,
        BuildProducer<AdditionalBeanBuildItem> additionalBeans, BuildProducer<ReflectiveClassBuildItem> reflectiveClasses) {

    detectAndLogSpecificSpringPropertiesIfExist();

    IndexView indexIndex = index.getIndex();
    List<ClassInfo> interfacesExtendingCrudRepository = getAllInterfacesExtending(DotNames.SUPPORTED_REPOSITORIES,
            indexIndex);

    removeNoRepositoryBeanClasses(interfacesExtendingCrudRepository);
    implementCrudRepositories(generatedBeans, generatedClasses, additionalBeans, reflectiveClasses,
            interfacesExtendingCrudRepository, indexIndex);
}
 
Example 7
Source File: GoogleSheetsProcessor.java    From camel-quarkus with Apache License 2.0 6 votes vote down vote up
@BuildStep
void registerForReflection(BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
        BuildProducer<UnbannedReflectiveBuildItem> unbannedClass, CombinedIndexBuildItem combinedIndex) {
    IndexView index = combinedIndex.getIndex();

    // Google sheets component configuration class reflection
    Collection<AnnotationInstance> uriParams = index
            .getAnnotations(DotName.createSimple("org.apache.camel.spi.UriParams"));

    String[] googleMailConfigClasses = uriParams.stream()
            .map(annotation -> annotation.target())
            .filter(annotationTarget -> annotationTarget.kind().equals(AnnotationTarget.Kind.CLASS))
            .map(annotationTarget -> annotationTarget.asClass().name().toString())
            .filter(className -> className.startsWith("org.apache.camel.component.google.sheets"))
            .toArray(String[]::new);

    reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, googleMailConfigClasses));
    unbannedClass.produce(new UnbannedReflectiveBuildItem(googleMailConfigClasses));
}
 
Example 8
Source File: DeploymentProcessor.java    From camel-k-runtime with Apache License 2.0 6 votes vote down vote up
@BuildStep
void registerServices(
        BuildProducer<ServiceProviderBuildItem> serviceProvider,
        BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
        CombinedIndexBuildItem combinedIndexBuildItem) {

    final IndexView view = combinedIndexBuildItem.getIndex();
    final String serviceType = "org.apache.camel.k.Runtime$Listener";

    getAllKnownImplementors(view, serviceType).forEach(i -> {
        serviceProvider.produce(
            new ServiceProviderBuildItem(
                serviceType,
                i.name().toString())
        );
    });
}
 
Example 9
Source File: HibernateSearchElasticsearchProcessor.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@BuildStep
@Record(ExecutionTime.STATIC_INIT)
public void build(HibernateSearchElasticsearchRecorder recorder,
        CombinedIndexBuildItem combinedIndexBuildItem,
        BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
        BuildProducer<ReflectiveHierarchyBuildItem> reflectiveHierarchy,
        BuildProducer<HibernateOrmIntegrationBuildItem> integrations,
        BuildProducer<FeatureBuildItem> feature) throws Exception {
    feature.produce(new FeatureBuildItem(Feature.HIBERNATE_SEARCH_ELASTICSEARCH));

    IndexView index = combinedIndexBuildItem.getIndex();

    if (index.getAnnotations(INDEXED).isEmpty()) {
        // we don't have any indexed entity, we can bail out
        return;
    }

    checkConfig(buildTimeConfig);

    // Register the Hibernate Search integration
    integrations.produce(new HibernateOrmIntegrationBuildItem(HIBERNATE_SEARCH_ELASTICSEARCH));

    // Register the required reflection declarations
    registerReflection(index, reflectiveClass, reflectiveHierarchy);

    // Register the Hibernate Search integration listener
    recorder.registerHibernateSearchIntegration(buildTimeConfig);
}
 
Example 10
Source File: HibernateUserTypeProcessor.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@BuildStep
public void build(BuildProducer<ReflectiveClassBuildItem> reflectiveClass, CombinedIndexBuildItem combinedIndexBuildItem) {
    IndexView index = combinedIndexBuildItem.getIndex();

    final Set<String> userTypes = new HashSet<>();

    Collection<AnnotationInstance> typeAnnotationInstances = index.getAnnotations(TYPE);
    Collection<AnnotationInstance> typeDefinitionAnnotationInstances = index.getAnnotations(TYPE_DEFINITION);
    Collection<AnnotationInstance> typeDefinitionsAnnotationInstances = index.getAnnotations(TYPE_DEFINITIONS);

    userTypes.addAll(getUserTypes(typeDefinitionAnnotationInstances));

    for (AnnotationInstance typeDefinitionAnnotationInstance : typeDefinitionsAnnotationInstances) {
        final AnnotationValue typeDefinitionsAnnotationValue = typeDefinitionAnnotationInstance.value();

        if (typeDefinitionsAnnotationValue == null) {
            continue;
        }

        userTypes.addAll(getUserTypes(Arrays.asList(typeDefinitionsAnnotationValue.asNestedArray())));
    }

    for (AnnotationInstance typeAnnotationInstance : typeAnnotationInstances) {
        final AnnotationValue typeValue = typeAnnotationInstance.value(TYPE_VALUE);
        if (typeValue == null) {
            continue;
        }

        final String type = typeValue.asString();
        final DotName className = DotName.createSimple(type);
        if (index.getClassByName(className) == null) {
            continue; // Either already registered through TypeDef annotation scanning or not present in the index
        }
        userTypes.add(type);
    }

    if (!userTypes.isEmpty()) {
        reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, userTypes.toArray(new String[] {})));
    }
}
 
Example 11
Source File: ConstructorPropertiesProcessor.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@BuildStep
void build(BuildProducer<ReflectiveClassBuildItem> reflectiveClass, CombinedIndexBuildItem indexBuildItem) {
    IndexView index = indexBuildItem.getIndex();
    for (AnnotationInstance annotationInstance : index.getAnnotations(CONSTRUCTOR_PROPERTIES)) {
        registerInstance(reflectiveClass, annotationInstance);
    }
}
 
Example 12
Source File: DebeziumSupportProcessor.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
@BuildStep
ReflectiveClassBuildItem registerForReflection(CombinedIndexBuildItem combinedIndex) {
    IndexView index = combinedIndex.getIndex();

    String[] dtos = index.getKnownClasses().stream().map(ci -> ci.name().toString())
            .filter(n -> n.startsWith("org.apache.kafka.connect.json")
                    || n.startsWith("io.debezium.embedded.spi"))
            .sorted()
            .toArray(String[]::new);

    return new ReflectiveClassBuildItem(false, true, dtos);
}
 
Example 13
Source File: BraintreeProcessor.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
@BuildStep
void registerForReflection(BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
        BuildProducer<UnbannedReflectiveBuildItem> unbannedClass, CombinedIndexBuildItem combinedIndex) {
    IndexView index = combinedIndex.getIndex();
    Collection<AnnotationInstance> uriParams = index
            .getAnnotations(DotName.createSimple("org.apache.camel.spi.UriParams"));

    String[] braintreeConfigClasses = uriParams.stream()
            .map(annotation -> annotation.target())
            .filter(annotationTarget -> annotationTarget.kind().equals(AnnotationTarget.Kind.CLASS))
            .map(annotationTarget -> annotationTarget.asClass().name().toString())
            .filter(className -> className.startsWith("org.apache.camel.component.braintree"))
            .collect(Collectors.toList())
            .toArray(new String[0]);

    reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, braintreeConfigClasses));
    unbannedClass.produce(new UnbannedReflectiveBuildItem(braintreeConfigClasses));

    reflectiveClass.produce(new ReflectiveClassBuildItem(true, false,
            "com.braintreegateway.Address",
            "com.braintreegateway.BraintreeGateway",
            "com.braintreegateway.Customer",
            "com.braintreegateway.DisputeEvidence",
            "com.braintreegateway.DocumentUpload",
            "com.braintreegateway.MerchantAccount",
            "com.braintreegateway.PaymentMethod",
            "com.braintreegateway.Transaction"));
}
 
Example 14
Source File: ResteasyServerCommonProcessor.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private static void registerReflectionForSerialization(BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
        BuildProducer<ReflectiveHierarchyBuildItem> reflectiveHierarchy,
        CombinedIndexBuildItem combinedIndexBuildItem,
        BeanArchiveIndexBuildItem beanArchiveIndexBuildItem,
        List<AdditionalJaxRsResourceMethodAnnotationsBuildItem> additionalJaxRsResourceMethodAnnotations) {
    IndexView index = combinedIndexBuildItem.getIndex();
    IndexView beanArchiveIndex = beanArchiveIndexBuildItem.getIndex();

    // This is probably redundant with the automatic resolution we do just below but better be safe
    for (AnnotationInstance annotation : index.getAnnotations(JSONB_ANNOTATION)) {
        if (annotation.target().kind() == AnnotationTarget.Kind.CLASS) {
            reflectiveClass
                    .produce(new ReflectiveClassBuildItem(true, true, annotation.target().asClass().name().toString()));
        }
    }

    final List<DotName> annotations = new ArrayList<>(METHOD_ANNOTATIONS.length);
    annotations.addAll(Arrays.asList(METHOD_ANNOTATIONS));
    for (AdditionalJaxRsResourceMethodAnnotationsBuildItem additionalJaxRsResourceMethodAnnotation : additionalJaxRsResourceMethodAnnotations) {
        annotations.addAll(additionalJaxRsResourceMethodAnnotation.getAnnotationClasses());
    }

    // Declare reflection for all the types implicated in the Rest end points (return types and parameters).
    // It might be needed for serialization.
    for (DotName annotationType : annotations) {
        scanMethodParameters(annotationType, reflectiveHierarchy, index);
        scanMethodParameters(annotationType, reflectiveHierarchy, beanArchiveIndex);
    }

    // In the case of a constraint violation, these elements might be returned as entities and will be serialized
    reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, ViolationReport.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, ResteasyConstraintViolation.class.getName()));
}
 
Example 15
Source File: MicroProfileHealthProcessor.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
@BuildStep
List<CamelBeanBuildItem> camelHealthDiscovery(
        CombinedIndexBuildItem combinedIndex,
        CamelMicroProfileHealthConfig config) {

    List<CamelBeanBuildItem> buildItems = new ArrayList<>();
    if (config.enabled) {
        IndexView index = combinedIndex.getIndex();
        Collection<ClassInfo> healthChecks = index.getAllKnownImplementors(CAMEL_HEALTH_CHECK_DOTNAME);
        Collection<ClassInfo> healthCheckRepositories = index
                .getAllKnownImplementors(CAMEL_HEALTH_CHECK_REPOSITORY_DOTNAME);

        // Create CamelBeanBuildItem to bind instances of HealthCheck to the camel registry
        healthChecks.stream()
                .filter(CamelSupport::isConcrete)
                .filter(CamelSupport::isPublic)
                .filter(ClassInfo::hasNoArgsConstructor)
                .map(classInfo -> new CamelBeanBuildItem(classInfo.simpleName(), classInfo.name().toString()))
                .forEach(buildItems::add);

        // Create CamelBeanBuildItem to bind instances of HealthCheckRepository to the camel registry
        healthCheckRepositories.stream()
                .filter(CamelSupport::isConcrete)
                .filter(CamelSupport::isPublic)
                .filter(ClassInfo::hasNoArgsConstructor)
                .filter(classInfo -> !classInfo.simpleName().equals(DefaultHealthCheckRegistry.class.getSimpleName()))
                .map(classInfo -> new CamelBeanBuildItem(classInfo.simpleName(), classInfo.name().toString()))
                .forEach(buildItems::add);
    }

    return buildItems;
}
 
Example 16
Source File: InfluxdbProcessor.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
@BuildStep
ReflectiveClassBuildItem registerForReflection(CombinedIndexBuildItem combinedIndex) {
    IndexView index = combinedIndex.getIndex();

    String[] dtos = index.getKnownClasses().stream()
            .map(ci -> ci.name().toString())
            .filter(n -> n.startsWith(INFLUXDB_DTO_PACKAGE))
            .sorted()
            .toArray(String[]::new);

    return new ReflectiveClassBuildItem(false, true, dtos);
}
 
Example 17
Source File: PicocliNativeImageProcessor.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@BuildStep(onlyIf = NativeImageProcessingEnabled.class)
void reflectionConfiguration(CombinedIndexBuildItem combinedIndexBuildItem,
        BuildProducer<ReflectiveFieldBuildItem> reflectiveFields,
        BuildProducer<ReflectiveClassBuildItem> reflectiveClasses,
        BuildProducer<NativeImageProxyDefinitionBuildItem> nativeImageProxies) {
    IndexView index = combinedIndexBuildItem.getIndex();

    Collection<DotName> annotationsToAnalyze = Arrays.asList(
            DotName.createSimple(CommandLine.ArgGroup.class.getName()),
            DotName.createSimple(CommandLine.Command.class.getName()),
            DotName.createSimple(CommandLine.Mixin.class.getName()),
            DotName.createSimple(CommandLine.Option.class.getName()),
            DotName.createSimple(CommandLine.Parameters.class.getName()),
            DotName.createSimple(CommandLine.ParentCommand.class.getName()),
            DotName.createSimple(CommandLine.Spec.class.getName()),
            DotName.createSimple(CommandLine.Unmatched.class.getName()));

    Set<ClassInfo> foundClasses = new HashSet<>();
    Set<FieldInfo> foundFields = new HashSet<>();
    for (DotName analyzedAnnotation : annotationsToAnalyze) {
        for (AnnotationInstance ann : index.getAnnotations(analyzedAnnotation)) {
            AnnotationTarget target = ann.target();
            switch (target.kind()) {
                case CLASS:
                    foundClasses.add(target.asClass());
                    break;
                case FIELD:
                    foundFields.add(target.asField());
                    // This may be class which will be used as Mixin. We need to be sure that Picocli will be able
                    // to initialize those even if they are not beans.
                    foundClasses.add(target.asField().declaringClass());
                    break;
                case METHOD:
                    foundClasses.add(target.asMethod().declaringClass());
                    break;
                case METHOD_PARAMETER:
                    foundClasses.add(target.asMethodParameter().method().declaringClass());
                    break;
                default:
                    LOGGER.warnf("Unsupported type %s annotated with %s", target.kind().name(), analyzedAnnotation);
                    break;
            }
        }
    }

    Arrays.asList(DotName.createSimple(CommandLine.IVersionProvider.class.getName()),
            DotName.createSimple(CommandLine.class.getName()))
            .forEach(interfaceName -> foundClasses.addAll(index.getAllKnownImplementors(interfaceName)));

    foundClasses.forEach(classInfo -> {
        if (Modifier.isInterface(classInfo.flags())) {
            nativeImageProxies
                    .produce(new NativeImageProxyDefinitionBuildItem(classInfo.name().toString()));
            reflectiveClasses
                    .produce(new ReflectiveClassBuildItem(false, true, false, classInfo.name().toString()));
        } else {
            reflectiveClasses
                    .produce(new ReflectiveClassBuildItem(true, true, false, classInfo.name().toString()));
        }
    });
    foundFields.forEach(fieldInfo -> reflectiveFields.produce(new ReflectiveFieldBuildItem(fieldInfo)));
}
 
Example 18
Source File: ResteasyCommonProcessor.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@BuildStep
JaxrsProvidersToRegisterBuildItem setupProviders(BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
        CombinedIndexBuildItem indexBuildItem,
        BeanArchiveIndexBuildItem beanArchiveIndexBuildItem,
        List<ResteasyJaxrsProviderBuildItem> contributedProviderBuildItems,
        List<RestClientBuildItem> restClients, Capabilities capabilities) throws Exception {

    Set<String> contributedProviders = new HashSet<>();
    for (ResteasyJaxrsProviderBuildItem contributedProviderBuildItem : contributedProviderBuildItems) {
        contributedProviders.add(contributedProviderBuildItem.getName());
    }

    for (AnnotationInstance i : indexBuildItem.getIndex().getAnnotations(ResteasyDotNames.PROVIDER)) {
        if (i.target().kind() == AnnotationTarget.Kind.CLASS) {
            contributedProviders.add(i.target().asClass().name().toString());
        }
        checkProperConfigAccessInProvider(i);
        checkProperConstructorInProvider(i);
    }

    Set<String> availableProviders = ServiceUtil.classNamesNamedIn(getClass().getClassLoader(),
            "META-INF/services/" + Providers.class.getName());

    MediaTypeMap<String> categorizedReaders = new MediaTypeMap<>();
    MediaTypeMap<String> categorizedWriters = new MediaTypeMap<>();
    MediaTypeMap<String> categorizedContextResolvers = new MediaTypeMap<>();
    Set<String> otherProviders = new HashSet<>();

    categorizeProviders(availableProviders, categorizedReaders, categorizedWriters, categorizedContextResolvers,
            otherProviders);

    // add the other providers detected
    Set<String> providersToRegister = new HashSet<>(otherProviders);

    if (!capabilities.isPresent(Capability.RESTEASY_JSON)) {

        boolean needJsonSupport = restJsonSupportNeeded(indexBuildItem, ResteasyDotNames.CONSUMES)
                || restJsonSupportNeeded(indexBuildItem, ResteasyDotNames.PRODUCES)
                || restJsonSupportNeeded(indexBuildItem, ResteasyDotNames.RESTEASY_SSE_ELEMENT_TYPE);
        if (needJsonSupport) {
            LOGGER.warn(
                    "Quarkus detected the need of REST JSON support but you have not provided the necessary JSON " +
                            "extension for this. You can visit https://quarkus.io/guides/rest-json for more " +
                            "information on how to set one.");
        }
    }
    if (!capabilities.isPresent(Capability.RESTEASY_MUTINY)) {
        String needsMutinyClasses = mutinySupportNeeded(indexBuildItem);
        if (needsMutinyClasses != null) {
            LOGGER.warn(
                    "Quarkus detected the need for Mutiny reactive programming support, however the quarkus-resteasy-mutiny extension"
                            + "was not present. Reactive REST endpoints in your application that return Uni or Multi " +
                            "will not function as you expect until you add this extension. Endpoints that need Mutiny are: "
                            + needsMutinyClasses);
        }

    }

    // we add a couple of default providers
    providersToRegister.add(StringTextStar.class.getName());
    providersToRegister.addAll(categorizedWriters.getPossible(MediaType.APPLICATION_JSON_TYPE));

    IndexView index = indexBuildItem.getIndex();
    IndexView beansIndex = beanArchiveIndexBuildItem.getIndex();

    // find the providers declared in our services
    boolean useBuiltinProviders = collectDeclaredProviders(restClients, providersToRegister, categorizedReaders,
            categorizedWriters, categorizedContextResolvers, index, beansIndex);

    if (useBuiltinProviders) {
        providersToRegister = new HashSet<>(contributedProviders);
        providersToRegister.addAll(availableProviders);
    } else {
        providersToRegister.addAll(contributedProviders);
    }

    if (providersToRegister.contains("org.jboss.resteasy.plugins.providers.jsonb.JsonBindingProvider")) {
        // This abstract one is also accessed directly via reflection
        reflectiveClass.produce(new ReflectiveClassBuildItem(true, true,
                "org.jboss.resteasy.plugins.providers.jsonb.AbstractJsonBindingProvider"));
    }

    return new JaxrsProvidersToRegisterBuildItem(providersToRegister, contributedProviders, useBuiltinProviders);
}
 
Example 19
Source File: PanacheMongoResourceProcessor.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@BuildStep
ReflectiveHierarchyBuildItem registerForReflection(CombinedIndexBuildItem index) {
    Type type = Type.create(DOTNAME_OBJECT_ID, Type.Kind.CLASS);
    return new ReflectiveHierarchyBuildItem(type, index.getIndex());
}
 
Example 20
Source File: JaxbProcessor.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@BuildStep
void processAnnotationsAndIndexFiles(
        BuildProducer<NativeImageSystemPropertyBuildItem> nativeImageProps,
        BuildProducer<ServiceProviderBuildItem> providerItem,
        BuildProducer<NativeImageProxyDefinitionBuildItem> proxyDefinitions,
        CombinedIndexBuildItem combinedIndexBuildItem,
        List<JaxbFileRootBuildItem> fileRoots) {

    IndexView index = combinedIndexBuildItem.getIndex();

    // Register classes for reflection based on JAXB annotations
    boolean jaxbRootAnnotationsDetected = false;

    for (DotName jaxbRootAnnotation : JAXB_ROOT_ANNOTATIONS) {
        for (AnnotationInstance jaxbRootAnnotationInstance : index
                .getAnnotations(jaxbRootAnnotation)) {
            if (jaxbRootAnnotationInstance.target().kind() == Kind.CLASS) {
                addReflectiveClass(true, true,
                        jaxbRootAnnotationInstance.target().asClass().name().toString());
                jaxbRootAnnotationsDetected = true;
            }
        }
    }

    if (!jaxbRootAnnotationsDetected && fileRoots.isEmpty()) {
        return;
    }

    // Register package-infos for reflection
    for (AnnotationInstance xmlSchemaInstance : index.getAnnotations(XML_SCHEMA)) {
        if (xmlSchemaInstance.target().kind() == Kind.CLASS) {
            reflectiveClass.produce(
                    new ReflectiveClassBuildItem(false, false, xmlSchemaInstance.target().asClass().name().toString()));
        }
    }

    // Register XML Java type adapters for reflection
    for (AnnotationInstance xmlJavaTypeAdapterInstance : index.getAnnotations(XML_JAVA_TYPE_ADAPTER)) {
        reflectiveClass.produce(
                new ReflectiveClassBuildItem(true, true, xmlJavaTypeAdapterInstance.value().asClass().name().toString()));
    }

    if (!index.getAnnotations(XML_ANY_ELEMENT).isEmpty()) {
        addReflectiveClass(false, false, "javax.xml.bind.annotation.W3CDomHandler");
    }

    JAXB_ANNOTATIONS.stream()
            .map(Class::getName)
            .forEach(className -> {
                proxyDefinitions.produce(new NativeImageProxyDefinitionBuildItem(className, Locatable.class.getName()));
                addReflectiveClass(true, false, className);
            });

    for (JaxbFileRootBuildItem i : fileRoots) {
        try (Stream<Path> stream = iterateResources(i.getFileRoot())) {
            stream.filter(p -> p.getFileName().toString().equals("jaxb.index"))
                    .forEach(this::handleJaxbFile);
        }
    }
}