Search in sources :

Example 1 with AnnotationsTransformerBuildItem

use of io.quarkus.arc.deployment.AnnotationsTransformerBuildItem in project kogito-runtimes by kiegroup.

the class KogitoProcessMessagingProcessor method annotate.

@BuildStep
AnnotationsTransformerBuildItem annotate(KogitoMessagingMetadataBuildItem messagingMetadata) {
    Map<DotName, DotName> fieldMapping = new HashMap<>();
    Map<DotName, DotName> classMapping = new HashMap<>();
    for (Entry<DotName, EventGenerator> entry : messagingMetadata.generators().entrySet()) {
        DotName annotationName = DotNamesHelper.createAnnotationName(entry.getValue());
        fieldMapping.put(entry.getKey(), annotationName);
        classMapping.put(DotNamesHelper.createClassName(entry.getValue()), annotationName);
    }
    return new AnnotationsTransformerBuildItem(new MessagingAnnotationTransfomer(fieldMapping, classMapping));
}
Also used : AnnotationsTransformerBuildItem(io.quarkus.arc.deployment.AnnotationsTransformerBuildItem) HashMap(java.util.HashMap) DotName(org.jboss.jandex.DotName) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 2 with AnnotationsTransformerBuildItem

use of io.quarkus.arc.deployment.AnnotationsTransformerBuildItem in project quarkus-github-app by quarkiverse.

the class GitHubAppProcessor method generateClasses.

@BuildStep
void generateClasses(CombinedIndexBuildItem combinedIndex, LaunchModeBuildItem launchMode, BuildProducer<AdditionalBeanBuildItem> additionalBeans, BuildProducer<GeneratedBeanBuildItem> generatedBeans, BuildProducer<GeneratedClassBuildItem> generatedClasses, BuildProducer<ReflectiveClassBuildItem> reflectiveClasses, BuildProducer<AnnotationsTransformerBuildItem> annotationsTransformer) {
    Collection<EventDefinition> allEventDefinitions = getAllEventDefinitions(combinedIndex.getIndex());
    // Add @Vetoed to all the user-defined event listening classes
    annotationsTransformer.produce(new AnnotationsTransformerBuildItem(new VetoUserDefinedEventListeningClassesAnnotationsTransformer(allEventDefinitions.stream().map(d -> d.getAnnotation()).collect(Collectors.toSet()))));
    // Add the qualifiers as beans
    String[] subscriberAnnotations = allEventDefinitions.stream().map(d -> d.getAnnotation().toString()).toArray(String[]::new);
    additionalBeans.produce(new AdditionalBeanBuildItem(subscriberAnnotations));
    DispatchingConfiguration dispatchingConfiguration = getDispatchingConfiguration(combinedIndex.getIndex(), allEventDefinitions);
    ClassOutput classOutput = new GeneratedClassGizmoAdaptor(generatedClasses, true);
    generateAnnotationLiterals(classOutput, dispatchingConfiguration);
    ClassOutput beanClassOutput = new GeneratedBeanGizmoAdaptor(generatedBeans);
    generateDispatcher(beanClassOutput, combinedIndex, launchMode, dispatchingConfiguration, reflectiveClasses);
    generateMultiplexers(beanClassOutput, dispatchingConfiguration, reflectiveClasses);
}
Also used : GitHubService(io.quarkiverse.githubapp.runtime.github.GitHubService) DotNames(io.quarkus.arc.processor.DotNames) GeneratedClassGizmoAdaptor(io.quarkus.deployment.GeneratedClassGizmoAdaptor) Arrays(java.util.Arrays) GHRepository(org.kohsuke.github.GHRepository) ClassOutput(io.quarkus.gizmo.ClassOutput) ShutdownContextBuildItem(io.quarkus.deployment.builditem.ShutdownContextBuildItem) AdditionalBeanBuildItem(io.quarkus.arc.deployment.AdditionalBeanBuildItem) AnnotationLiteral(javax.enterprise.util.AnnotationLiteral) Map(java.util.Map) BytecodeCreator(io.quarkus.gizmo.BytecodeCreator) GHEventPayload(org.kohsuke.github.GHEventPayload) PayloadHelper(io.quarkiverse.githubapp.runtime.github.PayloadHelper) EVENT(io.quarkiverse.githubapp.deployment.GitHubAppDotNames.EVENT) MethodParameterInfo(org.jboss.jandex.MethodParameterInfo) AnnotationsTransformerBuildItem(io.quarkus.arc.deployment.AnnotationsTransformerBuildItem) AnnotationValue(org.jboss.jandex.AnnotationValue) ReflectiveHierarchyBuildItem(io.quarkus.deployment.builditem.nativeimage.ReflectiveHierarchyBuildItem) EventDispatchingMethod(io.quarkiverse.githubapp.deployment.DispatchingConfiguration.EventDispatchingMethod) Set(java.util.Set) EventAnnotationLiteral(io.quarkiverse.githubapp.deployment.DispatchingConfiguration.EventAnnotationLiteral) Reader(java.io.Reader) BuiltinScope(io.quarkus.arc.processor.BuiltinScope) CompletionStage(java.util.concurrent.CompletionStage) AnnotationInstance(org.jboss.jandex.AnnotationInstance) HashUtil(io.quarkus.runtime.util.HashUtil) ResultHandle(io.quarkus.gizmo.ResultHandle) TryBlock(io.quarkus.gizmo.TryBlock) Record(io.quarkus.deployment.annotations.Record) CatchBlockCreator(io.quarkus.gizmo.CatchBlockCreator) DotName(org.jboss.jandex.DotName) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) MultiplexedEvent(io.quarkiverse.githubapp.runtime.MultiplexedEvent) ConfigFileReader(io.quarkiverse.githubapp.runtime.ConfigFileReader) CONFIG_FILE(io.quarkiverse.githubapp.deployment.GitHubAppDotNames.CONFIG_FILE) Gizmo(io.quarkus.gizmo.Gizmo) Opcodes(org.objectweb.asm.Opcodes) GitHubAppRecorder(io.quarkiverse.githubapp.runtime.GitHubAppRecorder) IOException(java.io.IOException) FieldDescriptor(io.quarkus.gizmo.FieldDescriptor) GeneratedBeanGizmoAdaptor(io.quarkus.arc.deployment.GeneratedBeanGizmoAdaptor) StringReader(java.io.StringReader) GeneratedClassBuildItem(io.quarkus.deployment.builditem.GeneratedClassBuildItem) LaunchModeBuildItem(io.quarkus.deployment.builditem.LaunchModeBuildItem) FieldCreator(io.quarkus.gizmo.FieldCreator) BytecodeTransformerBuildItem(io.quarkus.deployment.builditem.BytecodeTransformerBuildItem) GitHubEvent(io.quarkiverse.githubapp.GitHubEvent) WebJarResultsBuildItem(io.quarkus.vertx.http.deployment.webjar.WebJarResultsBuildItem) MethodVisitor(org.objectweb.asm.MethodVisitor) DefaultErrorHandler(io.quarkiverse.githubapp.runtime.error.DefaultErrorHandler) ClassInfo(org.jboss.jandex.ClassInfo) RoutingContext(io.vertx.ext.web.RoutingContext) CombinedIndexBuildItem(io.quarkus.deployment.builditem.CombinedIndexBuildItem) BuildProducer(io.quarkus.deployment.annotations.BuildProducer) Multiplexer(io.quarkiverse.githubapp.runtime.Multiplexer) GeneratedBeanBuildItem(io.quarkus.arc.deployment.GeneratedBeanBuildItem) MethodInfo(org.jboss.jandex.MethodInfo) FeatureBuildItem(io.quarkus.deployment.builditem.FeatureBuildItem) NotFoundPageDisplayableEndpointBuildItem(io.quarkus.vertx.http.deployment.devmode.NotFoundPageDisplayableEndpointBuildItem) ClassVisitor(org.objectweb.asm.ClassVisitor) GitHub(org.kohsuke.github.GitHub) Collection(java.util.Collection) ExecutionTime(io.quarkus.deployment.annotations.ExecutionTime) Collectors(java.util.stream.Collectors) MethodDescriptors(io.quarkus.arc.processor.MethodDescriptors) List(java.util.List) GitHubApiClassWithBridgeMethodsBuildItem(io.quarkiverse.githubapi.deployment.GitHubApiClassWithBridgeMethodsBuildItem) Actions(io.quarkiverse.githubapp.event.Actions) GACT(io.quarkus.maven.dependency.GACT) WebJarBuildItem(io.quarkus.vertx.http.deployment.webjar.WebJarBuildItem) Modifier(java.lang.reflect.Modifier) Annotation(java.lang.annotation.Annotation) Entry(java.util.Map.Entry) EventAnnotation(io.quarkiverse.githubapp.deployment.DispatchingConfiguration.EventAnnotation) Optional(java.util.Optional) ReflectiveClassBuildItem(io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem) RouteBuildItem(io.quarkus.vertx.http.deployment.RouteBuildItem) Logger(org.jboss.logging.Logger) MethodCreator(io.quarkus.gizmo.MethodCreator) Type(org.jboss.jandex.Type) AnnotatedElement(io.quarkus.gizmo.AnnotatedElement) LaunchMode(io.quarkus.runtime.LaunchMode) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) ClassCreator(io.quarkus.gizmo.ClassCreator) Singleton(javax.inject.Singleton) ErrorHandlerBridgeFunction(io.quarkiverse.githubapp.runtime.error.ErrorHandlerBridgeFunction) Function(java.util.function.Function) HttpRootPathBuildItem(io.quarkus.vertx.http.deployment.HttpRootPathBuildItem) Inject(javax.inject.Inject) BuildStep(io.quarkus.deployment.annotations.BuildStep) Kind(org.jboss.jandex.AnnotationTarget.Kind) PrintStream(java.io.PrintStream) Event(javax.enterprise.event.Event) IndexView(org.jboss.jandex.IndexView) MethodDescriptor(io.quarkus.gizmo.MethodDescriptor) DynamicGraphQLClient(io.smallrye.graphql.client.dynamic.api.DynamicGraphQLClient) EventDispatchingConfiguration(io.quarkiverse.githubapp.deployment.DispatchingConfiguration.EventDispatchingConfiguration) GITHUB(io.quarkiverse.githubapp.deployment.GitHubAppDotNames.GITHUB) DYNAMIC_GRAPHQL_CLIENT(io.quarkiverse.githubapp.deployment.GitHubAppDotNames.DYNAMIC_GRAPHQL_CLIENT) Handler(io.vertx.core.Handler) Collections(java.util.Collections) AnnotationsTransformerBuildItem(io.quarkus.arc.deployment.AnnotationsTransformerBuildItem) AdditionalBeanBuildItem(io.quarkus.arc.deployment.AdditionalBeanBuildItem) EventDispatchingConfiguration(io.quarkiverse.githubapp.deployment.DispatchingConfiguration.EventDispatchingConfiguration) ClassOutput(io.quarkus.gizmo.ClassOutput) GeneratedBeanGizmoAdaptor(io.quarkus.arc.deployment.GeneratedBeanGizmoAdaptor) GeneratedClassGizmoAdaptor(io.quarkus.deployment.GeneratedClassGizmoAdaptor) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 3 with AnnotationsTransformerBuildItem

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

the class ConsumeProcessor method annotationsTransformers.

@BuildStep
void annotationsTransformers(BuildProducer<AnnotationsTransformerBuildItem> annotationsTransformers) {
    annotationsTransformers.produce(new AnnotationsTransformerBuildItem(new AnnotationsTransformer() {

        public boolean appliesTo(org.jboss.jandex.AnnotationTarget.Kind kind) {
            return kind == Kind.CLASS;
        }

        @Override
        public void transform(TransformationContext ctx) {
            final ClassInfo classInfo = ctx.getTarget().asClass();
            if (hasConsumeMethod(classInfo)) {
                /* If there is @Consume on a method, make the declaring class a named injectable bean */
                String beanName = namedValue(classInfo);
                final Transformation transform = ctx.transform();
                if (!classInfo.annotations().keySet().stream().anyMatch(BEAN_DEFINING_ANNOTATIONS::contains)) {
                    /* Only add @Singleton if there is no other bean defining annotation yet */
                    transform.add(Singleton.class);
                }
                if (beanName == null) {
                    beanName = ConsumeProcessor.uniqueBeanName(classInfo);
                    transform.add(Named.class, AnnotationValue.createStringValue("value", beanName));
                }
                transform.done();
            }
        }
    }));
}
Also used : AnnotationsTransformerBuildItem(io.quarkus.arc.deployment.AnnotationsTransformerBuildItem) Transformation(io.quarkus.arc.processor.Transformation) AnnotationsTransformer(io.quarkus.arc.processor.AnnotationsTransformer) Kind(org.jboss.jandex.AnnotationTarget.Kind) ClassInfo(org.jboss.jandex.ClassInfo) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 4 with AnnotationsTransformerBuildItem

use of io.quarkus.arc.deployment.AnnotationsTransformerBuildItem in project quarkus-github-action by quarkiverse.

the class GitHubActionProcessor method generateClasses.

@BuildStep
void generateClasses(CombinedIndexBuildItem combinedIndex, LaunchModeBuildItem launchMode, BuildProducer<AdditionalBeanBuildItem> additionalBeans, BuildProducer<GeneratedBeanBuildItem> generatedBeans, BuildProducer<GeneratedClassBuildItem> generatedClasses, BuildProducer<ReflectiveClassBuildItem> reflectiveClasses, BuildProducer<AnnotationsTransformerBuildItem> annotationsTransformer) {
    Collection<EventDefinition> allEventDefinitions = getAllEventDefinitions(combinedIndex.getIndex());
    // Add @Vetoed to all the user-defined event listening classes
    annotationsTransformer.produce(new AnnotationsTransformerBuildItem(new VetoUserDefinedEventListeningClassesAnnotationsTransformer(allEventDefinitions.stream().map(d -> d.getAnnotation()).collect(Collectors.toSet()))));
    // Add the qualifiers as beans
    String[] subscriberAnnotations = allEventDefinitions.stream().map(d -> d.getAnnotation().toString()).toArray(String[]::new);
    additionalBeans.produce(new AdditionalBeanBuildItem(subscriberAnnotations));
    additionalBeans.produce(new AdditionalBeanBuildItem(Action.class));
    DispatchingConfiguration dispatchingConfiguration = getDispatchingConfiguration(combinedIndex.getIndex(), allEventDefinitions);
    ClassOutput classOutput = new GeneratedClassGizmoAdaptor(generatedClasses, true);
    generateAnnotationLiterals(classOutput, dispatchingConfiguration);
    ClassOutput beanClassOutput = new GeneratedBeanGizmoAdaptor(generatedBeans);
    generatePayloadTypeResolver(beanClassOutput, reflectiveClasses, allEventDefinitions);
    generateActionMain(beanClassOutput, combinedIndex, launchMode, dispatchingConfiguration, reflectiveClasses);
    generateMultiplexers(beanClassOutput, dispatchingConfiguration, reflectiveClasses);
}
Also used : DotNames(io.quarkus.arc.processor.DotNames) GeneratedClassGizmoAdaptor(io.quarkus.deployment.GeneratedClassGizmoAdaptor) Arrays(java.util.Arrays) MethodVisitor(org.objectweb.asm.MethodVisitor) PayloadTypeResolver(io.quarkiverse.githubaction.runtime.PayloadTypeResolver) ClassOutput(io.quarkus.gizmo.ClassOutput) RunTimeConfigurationDefaultBuildItem(io.quarkus.deployment.builditem.RunTimeConfigurationDefaultBuildItem) ClassInfo(org.jboss.jandex.ClassInfo) CombinedIndexBuildItem(io.quarkus.deployment.builditem.CombinedIndexBuildItem) BuildProducer(io.quarkus.deployment.annotations.BuildProducer) GeneratedBeanBuildItem(io.quarkus.arc.deployment.GeneratedBeanBuildItem) MethodInfo(org.jboss.jandex.MethodInfo) Context(io.quarkiverse.githubaction.Context) AdditionalBeanBuildItem(io.quarkus.arc.deployment.AdditionalBeanBuildItem) FeatureBuildItem(io.quarkus.deployment.builditem.FeatureBuildItem) AnnotationLiteral(javax.enterprise.util.AnnotationLiteral) Map(java.util.Map) BytecodeCreator(io.quarkus.gizmo.BytecodeCreator) GHEventPayload(org.kohsuke.github.GHEventPayload) ConfigFileReader(io.quarkiverse.githubaction.runtime.ConfigFileReader) MethodParameterInfo(org.jboss.jandex.MethodParameterInfo) ClassVisitor(org.objectweb.asm.ClassVisitor) GitHub(org.kohsuke.github.GitHub) AnnotationsTransformerBuildItem(io.quarkus.arc.deployment.AnnotationsTransformerBuildItem) ActionDispatchingConfiguration(io.quarkiverse.githubaction.deployment.DispatchingConfiguration.ActionDispatchingConfiguration) AnnotationValue(org.jboss.jandex.AnnotationValue) ReflectiveHierarchyBuildItem(io.quarkus.deployment.builditem.nativeimage.ReflectiveHierarchyBuildItem) EventAnnotationLiteral(io.quarkiverse.githubaction.deployment.DispatchingConfiguration.EventAnnotationLiteral) Collection(java.util.Collection) Set(java.util.Set) ActionLiteral(io.quarkiverse.githubaction.Action.ActionLiteral) BuiltinScope(io.quarkus.arc.processor.BuiltinScope) Collectors(java.util.stream.Collectors) MethodDescriptors(io.quarkus.arc.processor.MethodDescriptors) List(java.util.List) GitHubEvent(io.quarkiverse.githubaction.runtime.GitHubEvent) GitHubApiClassWithBridgeMethodsBuildItem(io.quarkiverse.githubapi.deployment.GitHubApiClassWithBridgeMethodsBuildItem) ActionDispatchingMethod(io.quarkiverse.githubaction.deployment.DispatchingConfiguration.ActionDispatchingMethod) Actions(io.quarkiverse.githubapp.event.Actions) AnnotationInstance(org.jboss.jandex.AnnotationInstance) Modifier(java.lang.reflect.Modifier) Annotation(java.lang.annotation.Annotation) Entry(java.util.Map.Entry) Optional(java.util.Optional) Multiplexer(io.quarkiverse.githubaction.runtime.Multiplexer) HashUtil(io.quarkus.runtime.util.HashUtil) ResultHandle(io.quarkus.gizmo.ResultHandle) ReflectiveClassBuildItem(io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem) Logger(org.jboss.logging.Logger) MethodCreator(io.quarkus.gizmo.MethodCreator) DotName(org.jboss.jandex.DotName) Type(org.jboss.jandex.Type) AnnotatedElement(io.quarkus.gizmo.AnnotatedElement) HashMap(java.util.HashMap) ClassCreator(io.quarkus.gizmo.ClassCreator) Singleton(javax.inject.Singleton) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) EVENT(io.quarkiverse.githubaction.deployment.GitHubActionDotNames.EVENT) Inject(javax.inject.Inject) BuildStep(io.quarkus.deployment.annotations.BuildStep) INJECTABLE_TYPES(io.quarkiverse.githubaction.deployment.GitHubActionDotNames.INJECTABLE_TYPES) Kind(org.jboss.jandex.AnnotationTarget.Kind) EventAnnotation(io.quarkiverse.githubaction.deployment.DispatchingConfiguration.EventAnnotation) Gizmo(io.quarkus.gizmo.Gizmo) PrintStream(java.io.PrintStream) Event(javax.enterprise.event.Event) IndexView(org.jboss.jandex.IndexView) Opcodes(org.objectweb.asm.Opcodes) MethodDescriptor(io.quarkus.gizmo.MethodDescriptor) CONFIG_FILE(io.quarkiverse.githubaction.deployment.GitHubActionDotNames.CONFIG_FILE) GitHubEventHandler(io.quarkiverse.githubaction.runtime.GitHubEventHandler) FieldDescriptor(io.quarkus.gizmo.FieldDescriptor) Action(io.quarkiverse.githubaction.Action) GeneratedBeanGizmoAdaptor(io.quarkus.arc.deployment.GeneratedBeanGizmoAdaptor) ACTION(io.quarkiverse.githubaction.deployment.GitHubActionDotNames.ACTION) GeneratedClassBuildItem(io.quarkus.deployment.builditem.GeneratedClassBuildItem) LaunchModeBuildItem(io.quarkus.deployment.builditem.LaunchModeBuildItem) FieldCreator(io.quarkus.gizmo.FieldCreator) BytecodeTransformerBuildItem(io.quarkus.deployment.builditem.BytecodeTransformerBuildItem) Collections(java.util.Collections) AdditionalBeanBuildItem(io.quarkus.arc.deployment.AdditionalBeanBuildItem) Action(io.quarkiverse.githubaction.Action) GeneratedBeanGizmoAdaptor(io.quarkus.arc.deployment.GeneratedBeanGizmoAdaptor) GeneratedClassGizmoAdaptor(io.quarkus.deployment.GeneratedClassGizmoAdaptor) AnnotationsTransformerBuildItem(io.quarkus.arc.deployment.AnnotationsTransformerBuildItem) ActionDispatchingConfiguration(io.quarkiverse.githubaction.deployment.DispatchingConfiguration.ActionDispatchingConfiguration) ClassOutput(io.quarkus.gizmo.ClassOutput) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Aggregations

AnnotationsTransformerBuildItem (io.quarkus.arc.deployment.AnnotationsTransformerBuildItem)4 BuildStep (io.quarkus.deployment.annotations.BuildStep)4 GitHubApiClassWithBridgeMethodsBuildItem (io.quarkiverse.githubapi.deployment.GitHubApiClassWithBridgeMethodsBuildItem)2 Actions (io.quarkiverse.githubapp.event.Actions)2 AdditionalBeanBuildItem (io.quarkus.arc.deployment.AdditionalBeanBuildItem)2 GeneratedBeanBuildItem (io.quarkus.arc.deployment.GeneratedBeanBuildItem)2 GeneratedBeanGizmoAdaptor (io.quarkus.arc.deployment.GeneratedBeanGizmoAdaptor)2 BuiltinScope (io.quarkus.arc.processor.BuiltinScope)2 DotNames (io.quarkus.arc.processor.DotNames)2 MethodDescriptors (io.quarkus.arc.processor.MethodDescriptors)2 GeneratedClassGizmoAdaptor (io.quarkus.deployment.GeneratedClassGizmoAdaptor)2 BuildProducer (io.quarkus.deployment.annotations.BuildProducer)2 BytecodeTransformerBuildItem (io.quarkus.deployment.builditem.BytecodeTransformerBuildItem)2 CombinedIndexBuildItem (io.quarkus.deployment.builditem.CombinedIndexBuildItem)2 FeatureBuildItem (io.quarkus.deployment.builditem.FeatureBuildItem)2 GeneratedClassBuildItem (io.quarkus.deployment.builditem.GeneratedClassBuildItem)2 LaunchModeBuildItem (io.quarkus.deployment.builditem.LaunchModeBuildItem)2 ReflectiveClassBuildItem (io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem)2 HashMap (java.util.HashMap)2 Kind (org.jboss.jandex.AnnotationTarget.Kind)2