Search in sources :

Example 1 with GeneratedBeanBuildItem

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

the class GrpcProcessor method createBindableServiceBeans.

@BuildStep
void createBindableServiceBeans(BuildProducer<GeneratedBeanBuildItem> generatedBean, BuildProducer<ReflectiveClassBuildItem> reflectiveClass, CombinedIndexBuildItem combinedIndexBuildItem) {
    IndexView index = combinedIndexBuildItem.getIndex();
    Collection<ClassInfo> bindableServiceImpls = index.getAllKnownImplementors(BINDABLE_SERVICE_DOT_NAME);
    // This mimics similar logic in DefaultBindableServiceFactory that uses Javassist ProxyFactory & MethodHandler
    for (ClassInfo service : bindableServiceImpls) {
        if (!Modifier.isAbstract(service.flags())) {
            continue;
        }
        if (service.name().withoutPackagePrefix().startsWith("Mutiny")) {
            /* The generate-code goal of quarkus-maven-plugin generates also Mutiny service that we do not use
                 * Not skipping it here results in randomly registering the Mutiny one or the right one.
                 * In case the Mutiny service one is registered, the client throws something like
                 * io.grpc.StatusRuntimeException: UNIMPLEMENTED */
            continue;
        }
        String superClassName = service.name().toString();
        String generatedClassName = superClassName + "QuarkusMethodHandler";
        // Register the service classes for reflection
        reflectiveClass.produce(new ReflectiveClassBuildItem(true, false, service.name().toString()));
        reflectiveClass.produce(new ReflectiveClassBuildItem(true, false, service.enclosingClass().toString()));
        reflectiveClass.produce(new ReflectiveClassBuildItem(true, false, generatedClassName));
        try (ClassCreator classCreator = ClassCreator.builder().classOutput(new GeneratedBeanGizmoAdaptor(generatedBean)).className(generatedClassName).superClass(superClassName).interfaces(CamelQuarkusBindableService.class).build()) {
            classCreator.addAnnotation(Dependent.class);
            FieldCreator serverMethodHandler = classCreator.getFieldCreator("methodHandler", GrpcMethodHandler.class.getName()).setModifiers(Modifier.PRIVATE);
            // Create constructor
            try (MethodCreator initMethod = classCreator.getMethodCreator("<init>", void.class)) {
                initMethod.setModifiers(Modifier.PUBLIC);
                initMethod.invokeSpecialMethod(MethodDescriptor.ofMethod(superClassName, "<init>", void.class), initMethod.getThis());
                initMethod.returnValue(null);
            }
            // Create setMethodHandler override
            try (MethodCreator setMethodHandlerMethod = classCreator.getMethodCreator("setMethodHandler", void.class, GrpcMethodHandler.class)) {
                setMethodHandlerMethod.setModifiers(Modifier.PUBLIC);
                ResultHandle self = setMethodHandlerMethod.getThis();
                ResultHandle methodHandlerInstance = setMethodHandlerMethod.getMethodParam(0);
                setMethodHandlerMethod.writeInstanceField(serverMethodHandler.getFieldDescriptor(), self, methodHandlerInstance);
                setMethodHandlerMethod.returnValue(null);
            }
            // Override service methods that the gRPC component is interested in
            // E.g methods with one or two parameters where one is of type StreamObserver
            List<MethodInfo> methods = service.methods();
            for (MethodInfo method : methods) {
                if (isCandidateServiceMethod(method)) {
                    String[] params = method.parameters().stream().map(type -> type.name().toString()).toArray(String[]::new);
                    ClassInfo classInfo = index.getClassByName(DotName.createSimple(GrpcMethodHandler.class.getName()));
                    String returnType = method.returnType().name().toString();
                    try (MethodCreator methodCreator = classCreator.getMethodCreator(method.name(), returnType, params)) {
                        method.exceptions().stream().map(type -> type.name().toString()).forEach(methodCreator::addException);
                        if (method.parameters().size() == 1) {
                            ResultHandle returnValue = generateGrpcDelegateMethod(classInfo, serverMethodHandler, methodCreator, method, "handleForConsumerStrategy");
                            methodCreator.returnValue(returnValue);
                        } else if (method.parameters().size() == 2) {
                            generateGrpcDelegateMethod(classInfo, serverMethodHandler, methodCreator, method, "handle");
                            methodCreator.returnValue(null);
                        }
                    }
                }
            }
        }
    }
}
Also used : BindableService(io.grpc.BindableService) ReflectiveClassBuildItem(io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem) AbstractFutureStub(io.grpc.stub.AbstractFutureStub) AbstractBlockingStub(io.grpc.stub.AbstractBlockingStub) MethodCreator(io.quarkus.gizmo.MethodCreator) DotName(org.jboss.jandex.DotName) Type(org.jboss.jandex.Type) ClassCreator(io.quarkus.gizmo.ClassCreator) ClassInfo(org.jboss.jandex.ClassInfo) CombinedIndexBuildItem(io.quarkus.deployment.builditem.CombinedIndexBuildItem) BuildProducer(io.quarkus.deployment.annotations.BuildProducer) GeneratedBeanBuildItem(io.quarkus.arc.deployment.GeneratedBeanBuildItem) BuildStep(io.quarkus.deployment.annotations.BuildStep) MethodInfo(org.jboss.jandex.MethodInfo) StreamObserver(io.grpc.stub.StreamObserver) AdditionalBeanBuildItem(io.quarkus.arc.deployment.AdditionalBeanBuildItem) FeatureBuildItem(io.quarkus.deployment.builditem.FeatureBuildItem) AbstractAsyncStub(io.grpc.stub.AbstractAsyncStub) IndexView(org.jboss.jandex.IndexView) MethodDescriptor(io.quarkus.gizmo.MethodDescriptor) Collection(java.util.Collection) CamelQuarkusBindableService(org.apache.camel.quarkus.grpc.runtime.CamelQuarkusBindableService) List(java.util.List) GeneratedBeanGizmoAdaptor(io.quarkus.arc.deployment.GeneratedBeanGizmoAdaptor) Dependent(javax.enterprise.context.Dependent) FieldCreator(io.quarkus.gizmo.FieldCreator) AbstractStub(io.grpc.stub.AbstractStub) Modifier(java.lang.reflect.Modifier) GrpcMethodHandler(org.apache.camel.component.grpc.server.GrpcMethodHandler) ResultHandle(io.quarkus.gizmo.ResultHandle) QuarkusBindableServiceFactory(org.apache.camel.quarkus.grpc.runtime.QuarkusBindableServiceFactory) IndexView(org.jboss.jandex.IndexView) FieldCreator(io.quarkus.gizmo.FieldCreator) CamelQuarkusBindableService(org.apache.camel.quarkus.grpc.runtime.CamelQuarkusBindableService) GeneratedBeanGizmoAdaptor(io.quarkus.arc.deployment.GeneratedBeanGizmoAdaptor) ClassCreator(io.quarkus.gizmo.ClassCreator) MethodCreator(io.quarkus.gizmo.MethodCreator) ResultHandle(io.quarkus.gizmo.ResultHandle) MethodInfo(org.jboss.jandex.MethodInfo) ReflectiveClassBuildItem(io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem) ClassInfo(org.jboss.jandex.ClassInfo) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 2 with GeneratedBeanBuildItem

use of io.quarkus.arc.deployment.GeneratedBeanBuildItem in project automatiko-engine by automatiko-io.

the class AutomatikoQuarkusProcessor method generatePersistenceInfo.

private void generatePersistenceInfo(AutomatikoBuildTimeConfig config, PackageConfig pconfig, AppPaths appPaths, BuildProducer<GeneratedBeanBuildItem> generatedBeans, BuildProducer<AdditionalIndexedClassesBuildItem> additionalIndexClass, IndexView index, LaunchModeBuildItem launchMode, BuildProducer<NativeImageResourceBuildItem> resource, CurateOutcomeBuildItem curateOutcomeBuildItem) throws Exception, BootstrapDependencyProcessingException {
    ClassInfo persistenceClass = index.getClassByName(createDotName(persistenceFactoryClass));
    boolean usePersistence = persistenceClass != null;
    List<String> parameters = new ArrayList<>();
    if (usePersistence) {
        for (MethodInfo mi : persistenceClass.methods()) {
            if (mi.name().equals("<init>") && !mi.parameters().isEmpty()) {
                parameters = mi.parameters().stream().map(p -> p.name().toString()).collect(Collectors.toList());
                break;
            }
        }
    }
    Collection<GeneratedFile> generatedFiles = getGeneratedPersistenceFiles(config, appPaths, index, usePersistence, parameters);
    if (!generatedFiles.isEmpty()) {
        writeGeneratedFiles(appPaths, generatedFiles);
        compile(appPaths, curateOutcomeBuildItem.getApplicationModel(), generatedFiles, launchMode.getLaunchMode(), generatedBeans, additionalIndexClass, GeneratedBeanBuildItem::new, pconfig);
    }
}
Also used : GeneratedBeanBuildItem(io.quarkus.arc.deployment.GeneratedBeanBuildItem) ArrayList(java.util.ArrayList) MethodInfo(org.jboss.jandex.MethodInfo) GeneratedFile(io.automatiko.engine.codegen.GeneratedFile) ClassInfo(org.jboss.jandex.ClassInfo)

Example 3 with GeneratedBeanBuildItem

use of io.quarkus.arc.deployment.GeneratedBeanBuildItem 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 4 with GeneratedBeanBuildItem

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

the class KogitoAssetsProcessor method indexBuildItems.

private KogitoGeneratedClassesBuildItem indexBuildItems(KogitoBuildContext context, Collection<GeneratedBeanBuildItem> buildItems) {
    Indexer kogitoIndexer = new Indexer();
    Set<DotName> kogitoIndex = new HashSet<>();
    for (GeneratedBeanBuildItem generatedBeanBuildItem : buildItems) {
        IndexingUtil.indexClass(generatedBeanBuildItem.getName(), kogitoIndexer, combinedIndexBuildItem.getIndex(), kogitoIndex, context.getClassLoader(), generatedBeanBuildItem.getData());
    }
    Map<String, byte[]> generatedClasses = buildItems.stream().collect(Collectors.toMap(GeneratedBeanBuildItem::getName, GeneratedBeanBuildItem::getData));
    return new KogitoGeneratedClassesBuildItem(kogitoIndexer.complete(), generatedClasses);
}
Also used : GeneratedBeanBuildItem(io.quarkus.arc.deployment.GeneratedBeanBuildItem) Indexer(org.jboss.jandex.Indexer) DotName(org.jboss.jandex.DotName) HashSet(java.util.HashSet)

Example 5 with GeneratedBeanBuildItem

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

the class KogitoQuarkusResourceUtils method makeBuildItems.

private static Collection<GeneratedBeanBuildItem> makeBuildItems(AppPaths appPaths, ResourceReader resources) throws IOException {
    Collection<GeneratedBeanBuildItem> buildItems = new ArrayList<>();
    for (KiePath path : resources.getFilePaths()) {
        byte[] data = resources.getBytes(path);
        String className = toClassName(path.asString());
        // TODO this can be removed when we will use a version of quarkus having that fix
        if (className.equals(HOT_RELOAD_SUPPORT_FQN)) {
            for (Path classPath : appPaths.getClassesPaths()) {
                // Write the class bytecode in the first available directory class path if any
                if (classPath.toFile().isDirectory()) {
                    Files.write(pathOf(classPath.toString(), HOT_RELOAD_SUPPORT_PATH + ".class"), data);
                    break;
                }
            }
        }
        buildItems.add(new GeneratedBeanBuildItem(className, data));
    }
    return buildItems;
}
Also used : GeneratedBeanBuildItem(io.quarkus.arc.deployment.GeneratedBeanBuildItem) KiePath(org.kie.memorycompiler.resources.KiePath) Path(java.nio.file.Path) ArrayList(java.util.ArrayList) KiePath(org.kie.memorycompiler.resources.KiePath)

Aggregations

GeneratedBeanBuildItem (io.quarkus.arc.deployment.GeneratedBeanBuildItem)6 ArrayList (java.util.ArrayList)4 DotName (org.jboss.jandex.DotName)4 AdditionalBeanBuildItem (io.quarkus.arc.deployment.AdditionalBeanBuildItem)3 GeneratedBeanGizmoAdaptor (io.quarkus.arc.deployment.GeneratedBeanGizmoAdaptor)3 BuildProducer (io.quarkus.deployment.annotations.BuildProducer)3 BuildStep (io.quarkus.deployment.annotations.BuildStep)3 CombinedIndexBuildItem (io.quarkus.deployment.builditem.CombinedIndexBuildItem)3 FeatureBuildItem (io.quarkus.deployment.builditem.FeatureBuildItem)3 ReflectiveClassBuildItem (io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem)3 ClassInfo (org.jboss.jandex.ClassInfo)3 MethodInfo (org.jboss.jandex.MethodInfo)3 GitHubApiClassWithBridgeMethodsBuildItem (io.quarkiverse.githubapi.deployment.GitHubApiClassWithBridgeMethodsBuildItem)2 Actions (io.quarkiverse.githubapp.event.Actions)2 ClassCreator (io.quarkus.gizmo.ClassCreator)2 FieldCreator (io.quarkus.gizmo.FieldCreator)2 MethodCreator (io.quarkus.gizmo.MethodCreator)2 MethodDescriptor (io.quarkus.gizmo.MethodDescriptor)2 ResultHandle (io.quarkus.gizmo.ResultHandle)2 Modifier (java.lang.reflect.Modifier)2