Search in sources :

Example 1 with ACTION

use of io.quarkiverse.githubaction.deployment.GitHubActionDotNames.ACTION in project quarkus-github-action by quarkiverse.

the class GitHubActionProcessor method getDispatchingConfiguration.

private static DispatchingConfiguration getDispatchingConfiguration(IndexView index, Collection<EventDefinition> allEventDefinitions) {
    DispatchingConfiguration configuration = new DispatchingConfiguration();
    Collection<AnnotationInstance> actionInstances = index.getAnnotations(ACTION).stream().filter(ai -> ai.target().kind() == Kind.METHOD).collect(Collectors.toList());
    for (AnnotationInstance actionInstance : actionInstances) {
        String name = actionInstance.valueWithDefault(index).asString();
        MethodInfo methodInfo = actionInstance.target().asMethod();
        boolean hasEventListeners = false;
        for (EventDefinition eventDefinition : allEventDefinitions) {
            Collection<AnnotationInstance> eventSubscriberInstances = methodInfo.annotations(eventDefinition.getAnnotation());
            for (AnnotationInstance eventSubscriberInstance : eventSubscriberInstances) {
                String action = eventDefinition.getAction() != null ? eventDefinition.getAction() : (eventSubscriberInstance.value() != null ? eventSubscriberInstance.value().asString() : Actions.ALL);
                MethodParameterInfo annotatedParameter = eventSubscriberInstance.target().asMethodParameter();
                DotName annotatedParameterType = annotatedParameter.method().parameters().get(annotatedParameter.position()).name();
                if (!eventDefinition.getPayloadType().equals(annotatedParameterType)) {
                    throw new IllegalStateException("Parameter subscribing to a GitHub '" + eventDefinition.getEvent() + "' event should be of type '" + eventDefinition.getPayloadType() + "'. Offending method: " + methodInfo.declaringClass().name() + "#" + methodInfo);
                }
                configuration.getOrCreateActionConfiguration(name, eventDefinition.getEvent(), eventDefinition.getPayloadType().toString()).addEventAnnotation(action, eventSubscriberInstance);
                configuration.addActionDispatchingMethod(new ActionDispatchingMethod(name, eventSubscriberInstance, methodInfo));
                hasEventListeners = true;
            }
        }
        if (!hasEventListeners) {
            configuration.getOrCreateActionConfiguration(name, EventDefinition.ALL, null);
            configuration.addActionDispatchingMethod(new ActionDispatchingMethod(name, null, methodInfo));
        }
    }
    // Methods listening to an event but with no @Action annotation, we consider them unnamed.
    for (EventDefinition eventDefinition : allEventDefinitions) {
        Collection<AnnotationInstance> eventSubscriberInstances = index.getAnnotations(eventDefinition.getAnnotation()).stream().filter(ai -> ai.target().kind() == Kind.METHOD_PARAMETER).filter(ai -> !ai.target().asMethodParameter().method().hasAnnotation(ACTION)).collect(Collectors.toList());
        for (AnnotationInstance eventSubscriberInstance : eventSubscriberInstances) {
            MethodParameterInfo annotatedParameter = eventSubscriberInstance.target().asMethodParameter();
            MethodInfo methodInfo = annotatedParameter.method();
            String name = Action.UNNAMED;
            String action = eventDefinition.getAction() != null ? eventDefinition.getAction() : (eventSubscriberInstance.value() != null ? eventSubscriberInstance.value().asString() : Actions.ALL);
            DotName annotatedParameterType = annotatedParameter.method().parameters().get(annotatedParameter.position()).name();
            if (!eventDefinition.getPayloadType().equals(annotatedParameterType)) {
                throw new IllegalStateException("Parameter subscribing to a GitHub '" + eventDefinition.getEvent() + "' action should be of type '" + eventDefinition.getPayloadType() + "'. Offending method: " + methodInfo.declaringClass().name() + "#" + methodInfo);
            }
            configuration.getOrCreateActionConfiguration(name, eventDefinition.getEvent(), eventDefinition.getPayloadType().toString()).addEventAnnotation(action, eventSubscriberInstance);
            configuration.addActionDispatchingMethod(new ActionDispatchingMethod(name, eventSubscriberInstance, methodInfo));
        }
    }
    return configuration;
}
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) ActionDispatchingConfiguration(io.quarkiverse.githubaction.deployment.DispatchingConfiguration.ActionDispatchingConfiguration) ActionDispatchingMethod(io.quarkiverse.githubaction.deployment.DispatchingConfiguration.ActionDispatchingMethod) MethodInfo(org.jboss.jandex.MethodInfo) MethodParameterInfo(org.jboss.jandex.MethodParameterInfo) DotName(org.jboss.jandex.DotName) AnnotationInstance(org.jboss.jandex.AnnotationInstance)

Aggregations

Action (io.quarkiverse.githubaction.Action)1 ActionLiteral (io.quarkiverse.githubaction.Action.ActionLiteral)1 Context (io.quarkiverse.githubaction.Context)1 ActionDispatchingConfiguration (io.quarkiverse.githubaction.deployment.DispatchingConfiguration.ActionDispatchingConfiguration)1 ActionDispatchingMethod (io.quarkiverse.githubaction.deployment.DispatchingConfiguration.ActionDispatchingMethod)1 EventAnnotation (io.quarkiverse.githubaction.deployment.DispatchingConfiguration.EventAnnotation)1 EventAnnotationLiteral (io.quarkiverse.githubaction.deployment.DispatchingConfiguration.EventAnnotationLiteral)1 ACTION (io.quarkiverse.githubaction.deployment.GitHubActionDotNames.ACTION)1 CONFIG_FILE (io.quarkiverse.githubaction.deployment.GitHubActionDotNames.CONFIG_FILE)1 EVENT (io.quarkiverse.githubaction.deployment.GitHubActionDotNames.EVENT)1 INJECTABLE_TYPES (io.quarkiverse.githubaction.deployment.GitHubActionDotNames.INJECTABLE_TYPES)1 ConfigFileReader (io.quarkiverse.githubaction.runtime.ConfigFileReader)1 GitHubEvent (io.quarkiverse.githubaction.runtime.GitHubEvent)1 GitHubEventHandler (io.quarkiverse.githubaction.runtime.GitHubEventHandler)1 Multiplexer (io.quarkiverse.githubaction.runtime.Multiplexer)1 PayloadTypeResolver (io.quarkiverse.githubaction.runtime.PayloadTypeResolver)1 GitHubApiClassWithBridgeMethodsBuildItem (io.quarkiverse.githubapi.deployment.GitHubApiClassWithBridgeMethodsBuildItem)1 Actions (io.quarkiverse.githubapp.event.Actions)1 AdditionalBeanBuildItem (io.quarkus.arc.deployment.AdditionalBeanBuildItem)1 AnnotationsTransformerBuildItem (io.quarkus.arc.deployment.AnnotationsTransformerBuildItem)1