Search in sources :

Example 1 with GeneratedClassBuildItem

use of io.quarkus.deployment.builditem.GeneratedClassBuildItem 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 2 with GeneratedClassBuildItem

use of io.quarkus.deployment.builditem.GeneratedClassBuildItem in project camel-quarkus by apache.

the class XsltProcessor method xsltResources.

@BuildStep
void xsltResources(CamelXsltConfig config, BuildProducer<XsltGeneratedClassBuildItem> generatedNames, BuildProducer<GeneratedClassBuildItem> generatedClasses, BuildProducer<UriResolverEntryBuildItem> uriResolverEntries) throws Exception {
    final Path destination = Files.createTempDirectory(XsltFeature.FEATURE);
    final Set<String> translets = new LinkedHashSet<>();
    try {
        final BuildTimeUriResolver resolver = new BuildTimeUriResolver();
        for (String uri : config.sources.orElse(Collections.emptyList())) {
            ResolutionResult resolvedUri = resolver.resolve(uri);
            uriResolverEntries.produce(resolvedUri.toBuildItem());
            if (translets.contains(resolvedUri.transletClassName)) {
                throw new RuntimeException("XSLT translet name clash: cannot add '" + resolvedUri.transletClassName + "' to previously added translets " + translets);
            }
            translets.add(resolvedUri.transletClassName);
            try {
                TransformerFactory tf = new XalanTransformerFactory();
                for (Map.Entry<String, Boolean> entry : config.features.entrySet()) {
                    tf.setFeature(entry.getKey(), entry.getValue());
                }
                tf.setAttribute("generate-translet", true);
                tf.setAttribute("translet-name", resolvedUri.transletClassName);
                tf.setAttribute("package-name", config.packageName);
                tf.setAttribute("destination-directory", destination.toString());
                tf.setErrorListener(new CamelXsltErrorListener());
                tf.newTemplates(resolvedUri.source);
            } catch (TransformerException e) {
                throw new RuntimeException("Could not compile XSLT " + uri, e);
            }
        }
        Files.walk(destination).sorted(Comparator.reverseOrder()).filter(Files::isRegularFile).filter(path -> path.toString().endsWith(".class")).forEach(path -> {
            try {
                final Path rel = destination.relativize(path);
                final String fqcn = StringUtils.removeEnd(rel.toString(), ".class").replace(File.separatorChar, '.');
                final byte[] data = Files.readAllBytes(path);
                generatedClasses.produce(new GeneratedClassBuildItem(false, fqcn, data));
                generatedNames.produce(new XsltGeneratedClassBuildItem(fqcn));
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        });
    } finally {
        Files.walk(destination).sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
    }
}
Also used : Path(java.nio.file.Path) LinkedHashSet(java.util.LinkedHashSet) Record(io.quarkus.deployment.annotations.Record) TransformerException(javax.xml.transform.TransformerException) CamelXsltErrorListener(org.apache.camel.quarkus.component.xslt.CamelXsltErrorListener) XalanTransformerFactory(org.apache.camel.quarkus.support.xalan.XalanTransformerFactory) StringUtils(org.apache.commons.lang3.StringUtils) BuildProducer(io.quarkus.deployment.annotations.BuildProducer) BuildStep(io.quarkus.deployment.annotations.BuildStep) RuntimeValue(io.quarkus.runtime.RuntimeValue) Map(java.util.Map) Path(java.nio.file.Path) LinkedHashSet(java.util.LinkedHashSet) Builder(org.apache.camel.quarkus.component.xslt.RuntimeUriResolver.Builder) CamelXsltConfig(org.apache.camel.quarkus.component.xslt.CamelXsltConfig) Files(java.nio.file.Files) CamelBeanBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelBeanBuildItem) ExecutionTime(io.quarkus.deployment.annotations.ExecutionTime) Set(java.util.Set) IOException(java.io.IOException) CamelServiceFilterBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelServiceFilterBuildItem) File(java.io.File) List(java.util.List) ResolutionResult(org.apache.camel.quarkus.component.xslt.deployment.BuildTimeUriResolver.ResolutionResult) GeneratedClassBuildItem(io.quarkus.deployment.builditem.GeneratedClassBuildItem) XsltComponent(org.apache.camel.component.xslt.XsltComponent) TransformerFactory(javax.xml.transform.TransformerFactory) Comparator(java.util.Comparator) CamelXsltRecorder(org.apache.camel.quarkus.component.xslt.CamelXsltRecorder) Collections(java.util.Collections) CamelServiceFilter(org.apache.camel.quarkus.core.deployment.spi.CamelServiceFilter) XalanTransformerFactory(org.apache.camel.quarkus.support.xalan.XalanTransformerFactory) TransformerFactory(javax.xml.transform.TransformerFactory) ResolutionResult(org.apache.camel.quarkus.component.xslt.deployment.BuildTimeUriResolver.ResolutionResult) CamelXsltErrorListener(org.apache.camel.quarkus.component.xslt.CamelXsltErrorListener) IOException(java.io.IOException) GeneratedClassBuildItem(io.quarkus.deployment.builditem.GeneratedClassBuildItem) XalanTransformerFactory(org.apache.camel.quarkus.support.xalan.XalanTransformerFactory) Files(java.nio.file.Files) Map(java.util.Map) File(java.io.File) TransformerException(javax.xml.transform.TransformerException) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 3 with GeneratedClassBuildItem

use of io.quarkus.deployment.builditem.GeneratedClassBuildItem in project camel-quarkus by apache.

the class CSimpleProcessor method compileCSimpleExpressions.

@BuildStep
void compileCSimpleExpressions(List<CSimpleExpressionSourceBuildItem> expressionSources, BuildProducer<CompiledCSimpleExpressionBuildItem> compiledCSimpleExpression, BuildProducer<GeneratedClassBuildItem> generatedClasses) throws IOException {
    if (!expressionSources.isEmpty()) {
        final Set<String> imports = new TreeSet<>();
        final Map<String, String> aliases = new LinkedHashMap<>();
        final ClassLoader loader = Thread.currentThread().getContextClassLoader();
        if (!(loader instanceof QuarkusClassLoader)) {
            throw new IllegalStateException(QuarkusClassLoader.class.getSimpleName() + " expected as the context class loader");
        }
        final QuarkusClassLoader quarkusClassLoader = (QuarkusClassLoader) loader;
        readConfig(imports, aliases, loader);
        final CSimpleCodeGenerator generator = new CSimpleCodeGenerator();
        generator.setAliases(aliases);
        generator.setImports(imports);
        final Path projectDir = Paths.get(".").toAbsolutePath().normalize();
        final Path csimpleGeneratedSourceDir = projectDir.resolve("target/generated/csimple");
        Files.createDirectories(csimpleGeneratedSourceDir);
        final Set<File> filesToCompile = new LinkedHashSet<>();
        /* We do not want to compile the same source twice, so we store here what we have compiled already */
        final Map<Boolean, Set<String>> compiledExpressions = new HashMap<>();
        compiledExpressions.put(true, new HashSet<>());
        compiledExpressions.put(false, new HashSet<>());
        /* Generate Java classes for the language expressions */
        for (CSimpleExpressionSourceBuildItem expr : expressionSources) {
            final boolean predicate = expr.isPredicate();
            final String script = expr.getSourceCode();
            if (!compiledExpressions.get(predicate).contains(script)) {
                final CSimpleGeneratedCode code = predicate ? generator.generatePredicate(expr.getClassNameBase(), script) : generator.generateExpression(expr.getClassNameBase(), script);
                compiledCSimpleExpression.produce(new CompiledCSimpleExpressionBuildItem(code.getCode(), predicate, code.getFqn()));
                final Path javaCsimpleFile = csimpleGeneratedSourceDir.resolve(code.getFqn().replace('.', '/') + ".java");
                Files.createDirectories(javaCsimpleFile.getParent());
                Files.write(javaCsimpleFile, code.getCode().getBytes(StandardCharsets.UTF_8));
                filesToCompile.add(javaCsimpleFile.toFile());
                compiledExpressions.get(predicate).add(script);
            }
        }
        final Path csimpleClassesDir = projectDir.resolve("target/csimple-classes");
        Files.createDirectories(csimpleClassesDir);
        /* Compile the generated sources */
        try (JavaCompilationProvider compiler = new JavaCompilationProvider()) {
            final Context context = compilationContext(projectDir, csimpleClassesDir, quarkusClassLoader);
            compiler.compile(filesToCompile, context);
        }
        /* Register the compiled classes via Quarkus GeneratedClassBuildItem */
        try (Stream<Path> classFiles = Files.walk(csimpleClassesDir)) {
            classFiles.filter(Files::isRegularFile).filter(p -> p.getFileName().toString().endsWith(CLASS_EXT)).forEach(p -> {
                final Path relPath = csimpleClassesDir.relativize(p);
                String className = FileUtils.nixifyPath(relPath.toString());
                className = className.substring(0, className.length() - CLASS_EXT.length());
                try {
                    final GeneratedClassBuildItem item = new GeneratedClassBuildItem(true, className, Files.readAllBytes(p));
                    generatedClasses.produce(item);
                } catch (IOException e) {
                    throw new RuntimeException("Could not read " + p);
                }
            });
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ExpressionNode(org.apache.camel.model.ExpressionNode) CamelContextBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelContextBuildItem) Enumeration(java.util.Enumeration) URL(java.net.URL) Listener(javax.xml.bind.Marshaller.Listener) LanguageExpressionContentHandler(org.apache.camel.quarkus.core.deployment.LanguageExpressionContentHandler) RecorderContext(io.quarkus.deployment.recording.RecorderContext) Constants(org.apache.camel.model.Constants) FailureRemedy(org.apache.camel.quarkus.core.CamelConfig.FailureRemedy) BuildProducer(io.quarkus.deployment.annotations.BuildProducer) FeatureBuildItem(io.quarkus.deployment.builditem.FeatureBuildItem) Map(java.util.Map) Context(io.quarkus.deployment.dev.CompilationProvider.Context) CSimpleLanguageRecorder(org.apache.camel.quarkus.component.csimple.CSimpleLanguageRecorder) NamedNode(org.apache.camel.NamedNode) Path(java.nio.file.Path) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Consume(io.quarkus.deployment.annotations.Consume) ExecutionTime(io.quarkus.deployment.annotations.ExecutionTime) Set(java.util.Set) QuarkusClassLoader(io.quarkus.bootstrap.classloading.QuarkusClassLoader) Collectors(java.util.stream.Collectors) JAXBException(javax.xml.bind.JAXBException) StandardCharsets(java.nio.charset.StandardCharsets) InvocationTargetException(java.lang.reflect.InvocationTargetException) List(java.util.List) Stream(java.util.stream.Stream) RouteBuilder(org.apache.camel.builder.RouteBuilder) CSimpleCodeGenerator(org.apache.camel.language.csimple.CSimpleCodeGenerator) Builder(org.apache.camel.language.csimple.CSimpleLanguage.Builder) CompilationProvider(io.quarkus.deployment.dev.CompilationProvider) CamelRoutesBuilderClassBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelRoutesBuilderClassBuildItem) CompiledCSimpleExpressionBuildItem(org.apache.camel.quarkus.core.deployment.spi.CompiledCSimpleExpressionBuildItem) Record(io.quarkus.deployment.annotations.Record) Marshaller(javax.xml.bind.Marshaller) Logger(org.jboss.logging.Logger) HashMap(java.util.HashMap) Exchange(org.apache.camel.Exchange) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) BuildStep(io.quarkus.deployment.annotations.BuildStep) JavaCompilationProvider(io.quarkus.deployment.dev.JavaCompilationProvider) RuntimeValue(io.quarkus.runtime.RuntimeValue) BiConsumer(java.util.function.BiConsumer) LinkedHashSet(java.util.LinkedHashSet) JAXBContext(javax.xml.bind.JAXBContext) CSimpleHelper(org.apache.camel.language.csimple.CSimpleHelper) CamelContext(org.apache.camel.CamelContext) CSimpleLanguage(org.apache.camel.language.csimple.CSimpleLanguage) ClassPathElement(io.quarkus.bootstrap.classloading.ClassPathElement) FileUtils(org.apache.camel.quarkus.core.util.FileUtils) Files(java.nio.file.Files) CamelBeanBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelBeanBuildItem) PropertiesHelper(org.apache.camel.util.PropertiesHelper) IOException(java.io.IOException) InputStreamReader(java.io.InputStreamReader) File(java.io.File) CamelConfig(org.apache.camel.quarkus.core.CamelConfig) GeneratedClassBuildItem(io.quarkus.deployment.builditem.GeneratedClassBuildItem) Paths(java.nio.file.Paths) CSimpleGeneratedCode(org.apache.camel.language.csimple.CSimpleGeneratedCode) BufferedReader(java.io.BufferedReader) Collections(java.util.Collections) CSimpleCodeGenerator(org.apache.camel.language.csimple.CSimpleCodeGenerator) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) LinkedHashMap(java.util.LinkedHashMap) TreeSet(java.util.TreeSet) GeneratedClassBuildItem(io.quarkus.deployment.builditem.GeneratedClassBuildItem) QuarkusClassLoader(io.quarkus.bootstrap.classloading.QuarkusClassLoader) Files(java.nio.file.Files) Path(java.nio.file.Path) JavaCompilationProvider(io.quarkus.deployment.dev.JavaCompilationProvider) RecorderContext(io.quarkus.deployment.recording.RecorderContext) Context(io.quarkus.deployment.dev.CompilationProvider.Context) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) JAXBContext(javax.xml.bind.JAXBContext) CamelContext(org.apache.camel.CamelContext) IOException(java.io.IOException) QuarkusClassLoader(io.quarkus.bootstrap.classloading.QuarkusClassLoader) CSimpleGeneratedCode(org.apache.camel.language.csimple.CSimpleGeneratedCode) File(java.io.File) CompiledCSimpleExpressionBuildItem(org.apache.camel.quarkus.core.deployment.spi.CompiledCSimpleExpressionBuildItem) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 4 with GeneratedClassBuildItem

use of io.quarkus.deployment.builditem.GeneratedClassBuildItem 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

BuildProducer (io.quarkus.deployment.annotations.BuildProducer)4 BuildStep (io.quarkus.deployment.annotations.BuildStep)4 GeneratedClassBuildItem (io.quarkus.deployment.builditem.GeneratedClassBuildItem)4 ExecutionTime (io.quarkus.deployment.annotations.ExecutionTime)3 Record (io.quarkus.deployment.annotations.Record)3 FeatureBuildItem (io.quarkus.deployment.builditem.FeatureBuildItem)3 Collections (java.util.Collections)3 List (java.util.List)3 Map (java.util.Map)3 Set (java.util.Set)3 GitHubApiClassWithBridgeMethodsBuildItem (io.quarkiverse.githubapi.deployment.GitHubApiClassWithBridgeMethodsBuildItem)2 Actions (io.quarkiverse.githubapp.event.Actions)2 AdditionalBeanBuildItem (io.quarkus.arc.deployment.AdditionalBeanBuildItem)2 RuntimeValue (io.quarkus.runtime.RuntimeValue)2 File (java.io.File)2 IOException (java.io.IOException)2 Files (java.nio.file.Files)2 Path (java.nio.file.Path)2 HashMap (java.util.HashMap)2 LinkedHashSet (java.util.LinkedHashSet)2