Search in sources :

Example 1 with Annotations

use of io.quarkus.arc.processor.Annotations in project quarkus by quarkusio.

the class MicrometerProcessor method registerAdditionalBeans.

@BuildStep(onlyIf = MicrometerEnabled.class)
UnremovableBeanBuildItem registerAdditionalBeans(CombinedIndexBuildItem indexBuildItem, BuildProducer<MicrometerRegistryProviderBuildItem> providerClasses, BuildProducer<ReflectiveClassBuildItem> reflectiveClasses, BuildProducer<AdditionalBeanBuildItem> additionalBeans, BuildProducer<InterceptorBindingRegistrarBuildItem> interceptorBindings) {
    // Create and keep some basic Providers
    additionalBeans.produce(AdditionalBeanBuildItem.builder().setUnremovable().addBeanClass(ClockProvider.class).addBeanClass(CompositeRegistryCreator.class).build());
    // Add annotations and associated interceptors
    additionalBeans.produce(AdditionalBeanBuildItem.builder().addBeanClass(MeterFilterConstraint.class).addBeanClass(MeterFilterConstraints.class).addBeanClass(TIMED_ANNOTATION.toString()).addBeanClass(TIMED_INTERCEPTOR.toString()).addBeanClass(COUNTED_ANNOTATION.toString()).addBeanClass(COUNTED_BINDING.toString()).addBeanClass(COUNTED_INTERCEPTOR.toString()).build());
    // @Timed is registered as an additional interceptor binding
    interceptorBindings.produce(new InterceptorBindingRegistrarBuildItem(new InterceptorBindingRegistrar() {

        @Override
        public List<InterceptorBinding> getAdditionalBindings() {
            return List.of(InterceptorBinding.of(Timed.class, m -> true));
        }
    }));
    IndexView index = indexBuildItem.getIndex();
    reflectiveClasses.produce(createReflectiveBuildItem(COUNTED_ANNOTATION, index));
    reflectiveClasses.produce(createReflectiveBuildItem(TIMED_ANNOTATION, index));
    reflectiveClasses.produce(ReflectiveClassBuildItem.builder("org.HdrHistogram.Histogram", "org.HdrHistogram.DoubleHistogram", "org.HdrHistogram.ConcurrentHistogram").constructors(true).build());
    return UnremovableBeanBuildItem.beanTypes(METER_REGISTRY, METER_BINDER, METER_FILTER, NAMING_CONVENTION);
}
Also used : InterceptorBindingRegistrar(io.quarkus.arc.processor.InterceptorBindingRegistrar) MeterFilter(io.micrometer.core.instrument.config.MeterFilter) UnremovableBeanBuildItem(io.quarkus.arc.deployment.UnremovableBeanBuildItem) MicrometerCounted(io.quarkus.micrometer.runtime.MicrometerCounted) InterceptorBindingRegistrar(io.quarkus.arc.processor.InterceptorBindingRegistrar) MeterBinder(io.micrometer.core.instrument.binder.MeterBinder) ShutdownContextBuildItem(io.quarkus.deployment.builditem.ShutdownContextBuildItem) NonApplicationRootPathBuildItem(io.quarkus.vertx.http.deployment.NonApplicationRootPathBuildItem) CombinedIndexBuildItem(io.quarkus.deployment.builditem.CombinedIndexBuildItem) BuildProducer(io.quarkus.deployment.annotations.BuildProducer) MetricsCapabilityBuildItem(io.quarkus.deployment.metrics.MetricsCapabilityBuildItem) MicrometerCountedInterceptor(io.quarkus.micrometer.runtime.MicrometerCountedInterceptor) BooleanSupplier(java.util.function.BooleanSupplier) MethodInfo(org.jboss.jandex.MethodInfo) AdditionalBeanBuildItem(io.quarkus.arc.deployment.AdditionalBeanBuildItem) FeatureBuildItem(io.quarkus.deployment.builditem.FeatureBuildItem) InterceptorBindingRegistrarBuildItem(io.quarkus.arc.deployment.InterceptorBindingRegistrarBuildItem) AnnotationTarget(org.jboss.jandex.AnnotationTarget) AnnotationsTransformerBuildItem(io.quarkus.arc.deployment.AnnotationsTransformerBuildItem) AnnotationValue(org.jboss.jandex.AnnotationValue) Collection(java.util.Collection) ExecutionTime(io.quarkus.deployment.annotations.ExecutionTime) Set(java.util.Set) Annotations(io.quarkus.arc.processor.Annotations) AnnotationsTransformer(io.quarkus.arc.processor.AnnotationsTransformer) Feature(io.quarkus.deployment.Feature) List(java.util.List) Counted(io.micrometer.core.annotation.Counted) CompositeRegistryCreator(io.quarkus.micrometer.runtime.CompositeRegistryCreator) AnnotationInstance(org.jboss.jandex.AnnotationInstance) BeanContainerBuildItem(io.quarkus.arc.deployment.BeanContainerBuildItem) ClockProvider(io.quarkus.micrometer.runtime.ClockProvider) ReflectiveClassBuildItem(io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem) Record(io.quarkus.deployment.annotations.Record) Timed(io.micrometer.core.annotation.Timed) DotName(org.jboss.jandex.DotName) MetricsFactoryConsumerBuildItem(io.quarkus.deployment.metrics.MetricsFactoryConsumerBuildItem) PrometheusRegistryProcessor(io.quarkus.micrometer.deployment.export.PrometheusRegistryProcessor) MetricsFactory(io.quarkus.runtime.metrics.MetricsFactory) HashSet(java.util.HashSet) BuildStep(io.quarkus.deployment.annotations.BuildStep) RuntimeValue(io.quarkus.runtime.RuntimeValue) Kind(org.jboss.jandex.AnnotationTarget.Kind) MeterFilterConstraint(io.quarkus.micrometer.runtime.MeterFilterConstraint) IndexView(org.jboss.jandex.IndexView) MicrometerTimedInterceptor(io.quarkus.micrometer.runtime.MicrometerTimedInterceptor) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) MicrometerRecorder(io.quarkus.micrometer.runtime.MicrometerRecorder) NamingConvention(io.micrometer.core.instrument.config.NamingConvention) MicrometerConfig(io.quarkus.micrometer.runtime.config.MicrometerConfig) MeterFilterConstraints(io.quarkus.micrometer.runtime.MeterFilterConstraints) InterceptorBindingRegistrarBuildItem(io.quarkus.arc.deployment.InterceptorBindingRegistrarBuildItem) Timed(io.micrometer.core.annotation.Timed) IndexView(org.jboss.jandex.IndexView) ClockProvider(io.quarkus.micrometer.runtime.ClockProvider) MeterFilterConstraints(io.quarkus.micrometer.runtime.MeterFilterConstraints) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 2 with Annotations

use of io.quarkus.arc.processor.Annotations in project quarkus by quarkusio.

the class AnnotationHandler method transformAnnotations.

static AnnotationsTransformerBuildItem transformAnnotations(final IndexView index, DotName sourceAnnotation, DotName targetAnnotation) {
    return new AnnotationsTransformerBuildItem(new AnnotationsTransformer() {

        @Override
        public void transform(TransformationContext ctx) {
            final Collection<AnnotationInstance> annotations = ctx.getAnnotations();
            AnnotationInstance annotation = Annotations.find(annotations, sourceAnnotation);
            if (annotation == null) {
                return;
            }
            AnnotationTarget target = ctx.getTarget();
            ClassInfo classInfo = null;
            MethodInfo methodInfo = null;
            FieldInfo fieldInfo = null;
            if (ctx.isMethod()) {
                methodInfo = target.asMethod();
                classInfo = methodInfo.declaringClass();
            } else if (ctx.isField()) {
                fieldInfo = target.asField();
                classInfo = fieldInfo.declaringClass();
            } else if (ctx.isClass()) {
                classInfo = target.asClass();
                // skip @Interceptor
                if (target.asClass().classAnnotation(DotNames.INTERCEPTOR) != null) {
                    return;
                }
            }
            // Ignore @Metric with @Produces
            if (removeCountedWhenTimed(sourceAnnotation, target, classInfo, methodInfo) || removeMetricWhenProduces(sourceAnnotation, target, methodInfo, fieldInfo)) {
                ctx.transform().remove(x -> x == annotation).done();
                return;
            }
            // Make sure all attributes exist:
            MetricAnnotationInfo annotationInfo = new MetricAnnotationInfo(annotation, index, classInfo, methodInfo, fieldInfo);
            // Remove the existing annotation, and add a new one with all the fields
            ctx.transform().remove(x -> x == annotation).add(targetAnnotation, annotationInfo.getAnnotationValues()).done();
        }
    });
}
Also used : AnnotationsTransformer(io.quarkus.arc.processor.AnnotationsTransformer) DotNames(io.quarkus.arc.processor.DotNames) Collection(java.util.Collection) Logger(org.jboss.logging.Logger) Annotations(io.quarkus.arc.processor.Annotations) AnnotationsTransformerBuildItem(io.quarkus.arc.deployment.AnnotationsTransformerBuildItem) org.jboss.jandex(org.jboss.jandex) AnnotationsTransformerBuildItem(io.quarkus.arc.deployment.AnnotationsTransformerBuildItem) AnnotationsTransformer(io.quarkus.arc.processor.AnnotationsTransformer) Collection(java.util.Collection)

Aggregations

AnnotationsTransformerBuildItem (io.quarkus.arc.deployment.AnnotationsTransformerBuildItem)2 Annotations (io.quarkus.arc.processor.Annotations)2 AnnotationsTransformer (io.quarkus.arc.processor.AnnotationsTransformer)2 Collection (java.util.Collection)2 Counted (io.micrometer.core.annotation.Counted)1 Timed (io.micrometer.core.annotation.Timed)1 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)1 MeterBinder (io.micrometer.core.instrument.binder.MeterBinder)1 MeterFilter (io.micrometer.core.instrument.config.MeterFilter)1 NamingConvention (io.micrometer.core.instrument.config.NamingConvention)1 AdditionalBeanBuildItem (io.quarkus.arc.deployment.AdditionalBeanBuildItem)1 BeanContainerBuildItem (io.quarkus.arc.deployment.BeanContainerBuildItem)1 InterceptorBindingRegistrarBuildItem (io.quarkus.arc.deployment.InterceptorBindingRegistrarBuildItem)1 UnremovableBeanBuildItem (io.quarkus.arc.deployment.UnremovableBeanBuildItem)1 DotNames (io.quarkus.arc.processor.DotNames)1 InterceptorBindingRegistrar (io.quarkus.arc.processor.InterceptorBindingRegistrar)1 Feature (io.quarkus.deployment.Feature)1 BuildProducer (io.quarkus.deployment.annotations.BuildProducer)1 BuildStep (io.quarkus.deployment.annotations.BuildStep)1 ExecutionTime (io.quarkus.deployment.annotations.ExecutionTime)1