Java Code Examples for io.quarkus.arc.deployment.AdditionalBeanBuildItem#Builder

The following examples show how to use io.quarkus.arc.deployment.AdditionalBeanBuildItem#Builder . 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: JtaProcessor.java    From camel-quarkus with Apache License 2.0 6 votes vote down vote up
@BuildStep
void transactedPolicy(
        BuildProducer<AdditionalBeanBuildItem> additionalBeans,
        BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
        Capabilities capabilities) {
    if (capabilities.isCapabilityPresent(Capabilities.TRANSACTIONS)) {
        AdditionalBeanBuildItem.Builder builder = AdditionalBeanBuildItem.builder();
        builder.addBeanClass(RequiredJtaTransactionPolicy.class);
        builder.addBeanClass(RequiresNewJtaTransactionPolicy.class);
        builder.addBeanClass(MandatoryJtaTransactionPolicy.class);
        builder.addBeanClass(NeverJtaTransactionPolicy.class);
        builder.addBeanClass(NotSupportedJtaTransactionPolicy.class);
        builder.addBeanClass(SupportsJtaTransactionPolicy.class);

        additionalBeans.produce(builder.build());

        reflectiveClass.produce(new ReflectiveClassBuildItem(false, false,
                IllegalStateException.class.getName()));
    }
}
 
Example 2
Source File: SmallRyeJwtProcessor.java    From quarkus with Apache License 2.0 6 votes vote down vote up
/**
 * Register the CDI beans that are needed by the MP-JWT extension
 *
 * @param additionalBeans - producer for additional bean items
 */
@BuildStep
void registerAdditionalBeans(BuildProducer<AdditionalBeanBuildItem> additionalBeans,
        BuildProducer<ReflectiveClassBuildItem> reflectiveClasses) {
    if (config.enabled) {
        AdditionalBeanBuildItem.Builder unremovable = AdditionalBeanBuildItem.builder().setUnremovable();
        unremovable.addBeanClass(MpJwtValidator.class);
        unremovable.addBeanClass(JWTAuthMechanism.class);
        unremovable.addBeanClass(ClaimValueProducer.class);
        additionalBeans.produce(unremovable.build());
    }
    AdditionalBeanBuildItem.Builder removable = AdditionalBeanBuildItem.builder();
    removable.addBeanClass(JWTAuthContextInfoProvider.class);
    removable.addBeanClass(DefaultJWTParser.class);
    removable.addBeanClass(CommonJwtProducer.class);
    removable.addBeanClass(RawClaimTypeProducer.class);
    removable.addBeanClass(JsonValueProducer.class);
    removable.addBeanClass(JwtPrincipalProducer.class);
    removable.addBeanClass(Claim.class);
    additionalBeans.produce(removable.build());

    reflectiveClasses.produce(new ReflectiveClassBuildItem(true, true, SignatureAlgorithm.class));
    reflectiveClasses.produce(new ReflectiveClassBuildItem(true, true, JwtProviderImpl.class));
}
 
Example 3
Source File: OidcBuildStep.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@BuildStep(onlyIf = IsEnabled.class)
AdditionalBeanBuildItem jwtClaimIntegration(Capabilities capabilities) {
    if (!capabilities.isPresent(Capability.JWT)) {
        AdditionalBeanBuildItem.Builder removable = AdditionalBeanBuildItem.builder();
        removable.addBeanClass(CommonJwtProducer.class);
        removable.addBeanClass(RawClaimTypeProducer.class);
        removable.addBeanClass(JsonValueProducer.class);
        removable.addBeanClass(Claim.class);
        return removable.build();
    }
    return null;
}
 
Example 4
Source File: RestClientProcessor.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@BuildStep
AdditionalBeanBuildItem registerProviderBeans(CombinedIndexBuildItem combinedIndex) {
    IndexView index = combinedIndex.getIndex();
    List<AnnotationInstance> allInstances = new ArrayList<>(index.getAnnotations(REGISTER_PROVIDER));
    for (AnnotationInstance annotation : index.getAnnotations(REGISTER_PROVIDERS)) {
        allInstances.addAll(Arrays.asList(annotation.value().asNestedArray()));
    }
    AdditionalBeanBuildItem.Builder builder = AdditionalBeanBuildItem.builder().setUnremovable();
    for (AnnotationInstance annotationInstance : allInstances) {
        // Make sure all providers not annotated with @Provider but used in @RegisterProvider are registered as beans
        builder.addBeanClass(annotationInstance.value().asClass().toString());
    }
    return builder.build();
}
 
Example 5
Source File: AmazonLambdaProcessor.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@BuildStep
void processProvidedLambda(Optional<ProvidedAmazonLambdaHandlerBuildItem> providedLambda,
        BuildProducer<AdditionalBeanBuildItem> additionalBeanBuildItemBuildProducer,
        BuildProducer<ReflectiveClassBuildItem> reflectiveClassBuildItemBuildProducer) {
    if (!providedLambda.isPresent())
        return;

    AdditionalBeanBuildItem.Builder builder = AdditionalBeanBuildItem.builder().setUnremovable();
    Class handlerClass = providedLambda.get().getHandlerClass();
    builder.addBeanClass(handlerClass);
    additionalBeanBuildItemBuildProducer.produce(builder.build());

    reflectiveClassBuildItemBuildProducer
            .produce(new ReflectiveClassBuildItem(true, true, true, handlerClass));

    // TODO
    // This really isn't good enough.  We should recursively add reflection for all method and field types of the parameter
    // and return type.  Otherwise Jackson won't work.  In AWS Lambda HTTP extension, the whole jackson model is registered
    // for reflection.  Shouldn't have to do this.
    for (Method method : handlerClass.getMethods()) {
        if (method.getName().equals("handleRequest")
                && method.getParameterTypes().length == 2
                && !method.getParameterTypes()[0].equals(Object.class)) {
            reflectiveClassBuildItemBuildProducer
                    .produce(new ReflectiveClassBuildItem(true, true, true, method.getParameterTypes()[0].getName()));
            reflectiveClassBuildItemBuildProducer
                    .produce(new ReflectiveClassBuildItem(true, true, true, method.getReturnType().getName()));
            reflectiveClassBuildItemBuildProducer.produce(new ReflectiveClassBuildItem(true, true, true,
                    DateTime.class));
            break;
        }
    }
}
 
Example 6
Source File: NarayanaJtaProcessor.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@BuildStep
@Record(RUNTIME_INIT)
public void build(NarayanaJtaRecorder recorder,
        BuildProducer<AdditionalBeanBuildItem> additionalBeans,
        BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
        BuildProducer<RuntimeInitializedClassBuildItem> runtimeInit,
        BuildProducer<FeatureBuildItem> feature,
        TransactionManagerConfiguration transactions) {
    feature.produce(new FeatureBuildItem(Feature.NARAYANA_JTA));
    additionalBeans.produce(new AdditionalBeanBuildItem(NarayanaJtaProducers.class));
    additionalBeans.produce(new AdditionalBeanBuildItem(CDIDelegatingTransactionManager.class));
    runtimeInit.produce(new RuntimeInitializedClassBuildItem(
            "com.arjuna.ats.internal.jta.resources.arjunacore.CommitMarkableResourceRecord"));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, JTAEnvironmentBean.class.getName(),
            UserTransactionImple.class.getName(),
            CheckedActionFactoryImple.class.getName(),
            TransactionManagerImple.class.getName(),
            TransactionSynchronizationRegistryImple.class.getName(),
            ObjectStoreEnvironmentBean.class.getName(),
            ShadowNoFileLockStore.class.getName()));

    AdditionalBeanBuildItem.Builder builder = AdditionalBeanBuildItem.builder();
    builder.addBeanClass(TransactionalInterceptorSupports.class);
    builder.addBeanClass(TransactionalInterceptorNever.class);
    builder.addBeanClass(TransactionalInterceptorRequired.class);
    builder.addBeanClass(TransactionalInterceptorRequiresNew.class);
    builder.addBeanClass(TransactionalInterceptorMandatory.class);
    builder.addBeanClass(TransactionalInterceptorNotSupported.class);
    additionalBeans.produce(builder.build());

    //we want to force Arjuna to init at static init time
    Properties defaultProperties = PropertiesFactory.getDefaultProperties();
    //we don't want to store the system properties here
    //we re-apply them at runtime
    for (Object i : System.getProperties().keySet()) {
        defaultProperties.remove(i);
    }
    recorder.setDefaultProperties(defaultProperties);
    // This must be done before setNodeName as the code in setNodeName will create a TSM based on the value of this property
    recorder.disableTransactionStatusManager();
    recorder.setNodeName(transactions);
    recorder.setDefaultTimeout(transactions);
}
 
Example 7
Source File: AmazonLambdaProcessor.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@BuildStep
List<AmazonLambdaBuildItem> discover(CombinedIndexBuildItem combinedIndexBuildItem,
        Optional<ProvidedAmazonLambdaHandlerBuildItem> providedLambda,
        BuildProducer<AdditionalBeanBuildItem> additionalBeanBuildItemBuildProducer,
        BuildProducer<ReflectiveHierarchyBuildItem> reflectiveHierarchy,
        BuildProducer<ReflectiveClassBuildItem> reflectiveClassBuildItemBuildProducer) throws BuildException {

    Collection<ClassInfo> allKnownImplementors = combinedIndexBuildItem.getIndex().getAllKnownImplementors(REQUEST_HANDLER);
    allKnownImplementors.addAll(combinedIndexBuildItem.getIndex()
            .getAllKnownImplementors(REQUEST_STREAM_HANDLER));
    allKnownImplementors.addAll(combinedIndexBuildItem.getIndex()
            .getAllKnownSubclasses(SKILL_STREAM_HANDLER));

    if (allKnownImplementors.size() > 0 && providedLambda.isPresent()) {
        throw new BuildException(
                "Multiple handler classes.  You have a custom handler class and the " + providedLambda.get().getProvider()
                        + " extension.  Please remove one of them from your deployment.",
                Collections.emptyList());

    }
    AdditionalBeanBuildItem.Builder builder = AdditionalBeanBuildItem.builder().setUnremovable();
    List<AmazonLambdaBuildItem> ret = new ArrayList<>();

    for (ClassInfo info : allKnownImplementors) {
        if (Modifier.isAbstract(info.flags())) {
            continue;
        }

        final DotName name = info.name();
        final String lambda = name.toString();
        builder.addBeanClass(lambda);
        reflectiveClassBuildItemBuildProducer.produce(new ReflectiveClassBuildItem(true, false, lambda));

        String cdiName = null;
        AnnotationInstance named = info.classAnnotation(NAMED);
        if (named != null) {
            cdiName = named.value().asString();
        }

        ClassInfo current = info;
        boolean done = false;
        boolean streamHandler = info.superName().equals(SKILL_STREAM_HANDLER) ? true : false;
        while (current != null && !done) {
            for (MethodInfo method : current.methods()) {
                if (method.name().equals("handleRequest")) {
                    if (method.parameters().size() == 3) {
                        streamHandler = true;
                        done = true;
                        break;
                    } else if (method.parameters().size() == 2
                            && !method.parameters().get(0).name().equals(DotName.createSimple(Object.class.getName()))) {
                        reflectiveHierarchy.produce(new ReflectiveHierarchyBuildItem(method.parameters().get(0)));
                        reflectiveHierarchy.produce(new ReflectiveHierarchyBuildItem(method.returnType()));
                        done = true;
                        break;
                    }
                }
            }
            current = combinedIndexBuildItem.getIndex().getClassByName(current.superName());
        }
        ret.add(new AmazonLambdaBuildItem(lambda, cdiName, streamHandler));
    }
    additionalBeanBuildItemBuildProducer.produce(builder.build());
    reflectiveClassBuildItemBuildProducer
            .produce(new ReflectiveClassBuildItem(true, true, true, FunctionError.class));
    return ret;
}