Skip to content

Commit

Permalink
WIP to be squashed
Browse files Browse the repository at this point in the history
  • Loading branch information
Ladicek committed May 29, 2024
1 parent 4600672 commit 9353a6a
Show file tree
Hide file tree
Showing 18 changed files with 303 additions and 241 deletions.
2 changes: 1 addition & 1 deletion bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1898,7 +1898,7 @@
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx-kotlin</artifactId>
<artifactId>quarkus-vertx-deployment-spi</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
Expand Down
8 changes: 8 additions & 0 deletions extensions/kotlin/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-kotlin</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx-deployment-spi</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jackson-spi</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

import static io.quarkus.deployment.builditem.nativeimage.NativeImageResourcePatternsBuildItem.builder;

import java.util.function.BiConsumer;

import org.jboss.jandex.MethodInfo;

import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.arc.processor.InvokerBuilder;
import io.quarkus.arc.processor.KotlinUtils;
import io.quarkus.bootstrap.classloading.QuarkusClassLoader;
import io.quarkus.deployment.Feature;
import io.quarkus.deployment.annotations.BuildProducer;
Expand All @@ -11,10 +18,14 @@
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassFinalFieldsWritablePredicateBuildItem;
import io.quarkus.jackson.spi.ClassPathJacksonModuleBuildItem;
import io.quarkus.kotlin.runtime.ApplicationCoroutineScope;
import io.quarkus.kotlin.runtime.CoroutineInvoker;
import io.quarkus.vertx.deployment.spi.EventConsumerInvokerCustomizerBuildItem;

public class KotlinProcessor {

private static final String KOTLIN_JACKSON_MODULE = "com.fasterxml.jackson.module.kotlin.KotlinModule";
private static final String KOTLIN_COROUTINE_SCOPE = "kotlinx.coroutines.CoroutineScope";

@BuildStep
FeatureBuildItem feature() {
Expand Down Expand Up @@ -68,4 +79,34 @@ void registerKotlinReflection(final BuildProducer<ReflectiveClassBuildItem> refl
".*.kotlin_builtins")
.build());
}

@BuildStep
void produceCoroutineScope(BuildProducer<AdditionalBeanBuildItem> additionalBean) {
if (!QuarkusClassLoader.isClassPresentAtRuntime(KOTLIN_COROUTINE_SCOPE)) {
return;
}

additionalBean.produce(AdditionalBeanBuildItem.builder()
.addBeanClass(ApplicationCoroutineScope.class)
.setUnremovable()
.build());
}

@BuildStep
void produceInvokerCustomizerForSuspendConsumeEventMethods(
BuildProducer<EventConsumerInvokerCustomizerBuildItem> customizers) {
if (!QuarkusClassLoader.isClassPresentAtRuntime(KOTLIN_COROUTINE_SCOPE)) {
return;
}

customizers.produce(new EventConsumerInvokerCustomizerBuildItem(new BiConsumer<MethodInfo, InvokerBuilder>() {
@Override
public void accept(MethodInfo method, InvokerBuilder invokerBuilder) {
if (KotlinUtils.isKotlinSuspendMethod(method)) {
invokerBuilder.withInvocationWrapper(CoroutineInvoker.class, "inNewCoroutine");
}
}
}));
}

}
120 changes: 101 additions & 19 deletions extensions/kotlin/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,16 @@
<artifactId>quarkus-kotlin</artifactId>
<name>Quarkus - Kotlin - Runtime</name>
<description>Write your services in Kotlin</description>
<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-maven-plugin</artifactId>
<configuration>
<lesserPriorityArtifacts>
<!--
see https://github.com/quarkusio/quarkus/issues/8405
-->
<lesserPriorityArtifact>org.jetbrains.kotlin:kotlin-compiler</lesserPriorityArtifact>
</lesserPriorityArtifacts>
<capabilities>
<provides>io.quarkus.kotlin</provides>
</capabilities>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-core</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
Expand All @@ -59,6 +45,10 @@
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
</dependency>
<!-- Is this the right place for this? We don't really want users to have to add it-->
<dependency>
<groupId>io.smallrye.reactive</groupId>
Expand All @@ -79,4 +69,96 @@
<artifactId>kotlinx-coroutines-jdk8</artifactId>
</dependency>
</dependencies>

<build>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-maven-plugin</artifactId>
<configuration>
<lesserPriorityArtifacts>
<!--
see https://github.com/quarkusio/quarkus/issues/8405
-->
<lesserPriorityArtifact>org.jetbrains.kotlin:kotlin-compiler</lesserPriorityArtifact>
</lesserPriorityArtifacts>
<capabilities>
<provides>io.quarkus.kotlin</provides>
</capabilities>
</configuration>
</plugin>

<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile</id>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<configuration>
<jvmTarget>${maven.compiler.target}</jvmTarget>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
<executions>
<!-- Replacing default-compile as it is treated specially by maven -->
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<!-- Replacing default-testCompile as it is treated specially by maven -->
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
<execution>
<id>java-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>java-test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<failOnError>false</failOnError>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.vertx.kotlin.runtime
package io.quarkus.kotlin.runtime

import jakarta.annotation.PreDestroy
import jakarta.inject.Singleton
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.vertx.kotlin.runtime
package io.quarkus.kotlin.runtime

import io.quarkus.arc.Arc
import io.vertx.core.Vertx
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.vertx.kotlin.runtime
package io.quarkus.kotlin.runtime

import io.quarkus.arc.Arc
import io.vertx.core.Context
Expand Down
26 changes: 26 additions & 0 deletions extensions/vertx/deployment-spi/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>quarkus-vertx-parent</artifactId>
<groupId>io.quarkus</groupId>
<version>999-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>quarkus-vertx-deployment-spi</artifactId>
<name>Quarkus - Vert.x - Deployment - SPI</name>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-core-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus.arc</groupId>
<artifactId>arc-processor</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.quarkus.vertx.deployment.spi;

import java.util.function.BiConsumer;

import org.jboss.jandex.MethodInfo;

import io.quarkus.arc.processor.InvokerBuilder;
import io.quarkus.builder.item.MultiBuildItem;

/**
* This build item should be considered private and should not be used outside of core Quarkus.
* It can be changed without notice.
*/
public final class EventConsumerInvokerCustomizerBuildItem extends MultiBuildItem {
private final BiConsumer<MethodInfo, InvokerBuilder> invokerCustomizer;

public EventConsumerInvokerCustomizerBuildItem(BiConsumer<MethodInfo, InvokerBuilder> invokerCustomizer) {
this.invokerCustomizer = invokerCustomizer;
}

public BiConsumer<MethodInfo, InvokerBuilder> getInvokerCustomizer() {
return invokerCustomizer;
}
}
Loading

0 comments on commit 9353a6a

Please sign in to comment.