Search in sources :

Example 1 with SyntheticBeanBuildItem

use of io.quarkus.arc.deployment.SyntheticBeanBuildItem in project camel-quarkus by apache.

the class InjectionPointsProcessor method produceBeans.

void produceBeans(CamelRecorder recorder, List<CapabilityBuildItem> capabilities, BuildProducer<SyntheticBeanBuildItem> syntheticBeans, BuildProducer<NativeImageProxyDefinitionBuildItem> proxyDefinitions, AtomicReference<Boolean> beanCapabilityAvailable, AnnotationInstance annot, final DotName fieldType, String annotationTarget, DotName declaringClass) {
    try {
        Class<?> clazz = Class.forName(fieldType.toString(), false, Thread.currentThread().getContextClassLoader());
        if (ProducerTemplate.class.isAssignableFrom(clazz)) {
            syntheticBeans.produce(SyntheticBeanBuildItem.configure(fieldType).setRuntimeInit().scope(Singleton.class).supplier(recorder.createProducerTemplate(annot.value().asString())).addQualifier(annot).done());
        /*
                 * Note that ProducerTemplate injection points not having @EndpointInject are produced via
                 * CamelProducers.camelProducerTemplate()
                 */
        } else if (FluentProducerTemplate.class.isAssignableFrom(clazz)) {
            syntheticBeans.produce(SyntheticBeanBuildItem.configure(fieldType).setRuntimeInit().scope(Singleton.class).supplier(recorder.createFluentProducerTemplate(annot.value().asString())).addQualifier(annot).done());
        /*
                 * Note that FluentProducerTemplate injection points not having @EndpointInject are produced via
                 * CamelProducers.camelFluentProducerTemplate()
                 */
        } else if (clazz.isInterface()) {
            if (beanCapabilityAvailable.get() == null) {
                beanCapabilityAvailable.set(capabilities.stream().map(CapabilityBuildItem::getName).anyMatch(feature -> CamelCapabilities.BEAN.equals(feature)));
            }
            if (!beanCapabilityAvailable.get()) {
                throw new IllegalStateException("Add camel-quarkus-bean dependency to be able to use @org.apache.camel.Produce on fields with interface type: " + fieldType.toString() + " " + annotationTarget + " in " + declaringClass.toString());
            }
            proxyDefinitions.produce(new NativeImageProxyDefinitionBuildItem(fieldType.toString()));
            syntheticBeans.produce(SyntheticBeanBuildItem.configure(fieldType).setRuntimeInit().scope(Singleton.class).supplier(recorder.produceProxy(clazz, annot.value().asString())).addQualifier(annot).done());
        }
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
}
Also used : CamelRuntimeTaskBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelRuntimeTaskBuildItem) SyntheticBeanBuildItem(io.quarkus.arc.deployment.SyntheticBeanBuildItem) Record(io.quarkus.deployment.annotations.Record) EndpointInject(org.apache.camel.EndpointInject) Logger(org.jboss.logging.Logger) DotName(org.jboss.jandex.DotName) Type(org.jboss.jandex.Type) Component(org.apache.camel.Component) Endpoint(org.apache.camel.Endpoint) ClassInfo(org.jboss.jandex.ClassInfo) FieldInfo(org.jboss.jandex.FieldInfo) Singleton(javax.inject.Singleton) AtomicReference(java.util.concurrent.atomic.AtomicReference) Supplier(java.util.function.Supplier) CombinedIndexBuildItem(io.quarkus.deployment.builditem.CombinedIndexBuildItem) Produce(org.apache.camel.Produce) BuildProducer(io.quarkus.deployment.annotations.BuildProducer) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) Inject(javax.inject.Inject) BuildStep(io.quarkus.deployment.annotations.BuildStep) MethodInfo(org.jboss.jandex.MethodInfo) FluentProducerTemplate(org.apache.camel.FluentProducerTemplate) CamelRecorder(org.apache.camel.quarkus.core.CamelRecorder) Map(java.util.Map) Kind(org.jboss.jandex.AnnotationTarget.Kind) ProducerTemplate(org.apache.camel.ProducerTemplate) NativeImageProxyDefinitionBuildItem(io.quarkus.deployment.builditem.nativeimage.NativeImageProxyDefinitionBuildItem) AnnotationTarget(org.jboss.jandex.AnnotationTarget) Named(javax.inject.Named) CapabilityBuildItem(io.quarkus.deployment.builditem.CapabilityBuildItem) AnnotationsTransformerBuildItem(io.quarkus.arc.deployment.AnnotationsTransformerBuildItem) CamelCapabilities(org.apache.camel.quarkus.core.CamelCapabilities) BeanRegistrationPhaseBuildItem(io.quarkus.arc.deployment.BeanRegistrationPhaseBuildItem) Collection(java.util.Collection) ExecutionTime(io.quarkus.deployment.annotations.ExecutionTime) InjectionPointsRecorder(org.apache.camel.quarkus.core.InjectionPointsRecorder) Set(java.util.Set) InjectionPointInfo(io.quarkus.arc.processor.InjectionPointInfo) Objects(java.util.Objects) QualifierRegistrarBuildItem(io.quarkus.arc.deployment.QualifierRegistrarBuildItem) AnnotationsTransformer(io.quarkus.arc.processor.AnnotationsTransformer) QualifierRegistrar(io.quarkus.arc.processor.QualifierRegistrar) List(java.util.List) AnnotationInstance(org.jboss.jandex.AnnotationInstance) Collections(java.util.Collections) BuildExtension(io.quarkus.arc.processor.BuildExtension) FluentProducerTemplate(org.apache.camel.FluentProducerTemplate) Singleton(javax.inject.Singleton) CapabilityBuildItem(io.quarkus.deployment.builditem.CapabilityBuildItem) NativeImageProxyDefinitionBuildItem(io.quarkus.deployment.builditem.nativeimage.NativeImageProxyDefinitionBuildItem)

Aggregations

AnnotationsTransformerBuildItem (io.quarkus.arc.deployment.AnnotationsTransformerBuildItem)1 BeanRegistrationPhaseBuildItem (io.quarkus.arc.deployment.BeanRegistrationPhaseBuildItem)1 QualifierRegistrarBuildItem (io.quarkus.arc.deployment.QualifierRegistrarBuildItem)1 SyntheticBeanBuildItem (io.quarkus.arc.deployment.SyntheticBeanBuildItem)1 AnnotationsTransformer (io.quarkus.arc.processor.AnnotationsTransformer)1 BuildExtension (io.quarkus.arc.processor.BuildExtension)1 InjectionPointInfo (io.quarkus.arc.processor.InjectionPointInfo)1 QualifierRegistrar (io.quarkus.arc.processor.QualifierRegistrar)1 BuildProducer (io.quarkus.deployment.annotations.BuildProducer)1 BuildStep (io.quarkus.deployment.annotations.BuildStep)1 ExecutionTime (io.quarkus.deployment.annotations.ExecutionTime)1 Record (io.quarkus.deployment.annotations.Record)1 CapabilityBuildItem (io.quarkus.deployment.builditem.CapabilityBuildItem)1 CombinedIndexBuildItem (io.quarkus.deployment.builditem.CombinedIndexBuildItem)1 NativeImageProxyDefinitionBuildItem (io.quarkus.deployment.builditem.nativeimage.NativeImageProxyDefinitionBuildItem)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1