From fe7b43adf1015ec8525b0653766e569a5bf62836 Mon Sep 17 00:00:00 2001 From: Guillaume Le Floch Date: Mon, 8 Mar 2021 20:52:29 +0100 Subject: [PATCH] Handle kotlin compiler args in dev mode --- .../deployment/KotlinCompilationProvider.java | 10 +- extensions/kotlin/runtime/pom.xml | 4 + .../kotlin/maven/it/KotlinDevModeIT.java | 18 ++ .../projects/kotlin-compiler-args/pom.xml | 126 ++++++++++++++ .../src/main/kotlin/org/acme/HelloResource.kt | 19 +++ .../resources/META-INF/resources/index.html | 156 ++++++++++++++++++ .../src/main/resources/application.properties | 7 + .../test/kotlin/org/acme/HelloResourceTest.kt | 21 +++ 8 files changed, 359 insertions(+), 2 deletions(-) create mode 100644 integration-tests/kotlin/src/test/resources/projects/kotlin-compiler-args/pom.xml create mode 100644 integration-tests/kotlin/src/test/resources/projects/kotlin-compiler-args/src/main/kotlin/org/acme/HelloResource.kt create mode 100644 integration-tests/kotlin/src/test/resources/projects/kotlin-compiler-args/src/main/resources/META-INF/resources/index.html create mode 100644 integration-tests/kotlin/src/test/resources/projects/kotlin-compiler-args/src/main/resources/application.properties create mode 100644 integration-tests/kotlin/src/test/resources/projects/kotlin-compiler-args/src/test/kotlin/org/acme/HelloResourceTest.kt diff --git a/extensions/kotlin/deployment/src/main/java/io/quarkus/kotlin/deployment/KotlinCompilationProvider.java b/extensions/kotlin/deployment/src/main/java/io/quarkus/kotlin/deployment/KotlinCompilationProvider.java index ea7340edf98de..74675d8a24c75 100644 --- a/extensions/kotlin/deployment/src/main/java/io/quarkus/kotlin/deployment/KotlinCompilationProvider.java +++ b/extensions/kotlin/deployment/src/main/java/io/quarkus/kotlin/deployment/KotlinCompilationProvider.java @@ -46,7 +46,7 @@ public void compile(Set filesToCompile, Context context) { compilerArguments.setPluginClasspaths(context.getCompilePluginArtifacts().toArray(new String[0])); } if (context.getCompilerPluginOptions() != null && !context.getCompilerPluginOptions().isEmpty()) { - List sanitizedOptions = new ArrayList<>(context.getCompilerOptions().size()); + List sanitizedOptions = new ArrayList<>(context.getCompilerPluginOptions().size()); for (String rawOption : context.getCompilerPluginOptions()) { Matcher matcher = OPTION_PATTERN.matcher(rawOption); if (!matcher.matches()) { @@ -70,9 +70,15 @@ public void compile(Set filesToCompile, Context context) { context.getClasspath().stream().map(File::getAbsolutePath).collect(Collectors.joining(File.pathSeparator))); compilerArguments.setDestination(context.getOutputDirectory().getAbsolutePath()); compilerArguments.setFreeArgs(filesToCompile.stream().map(File::getAbsolutePath).collect(Collectors.toList())); + compilerArguments.setSuppressWarnings(true); SimpleKotlinCompilerMessageCollector messageCollector = new SimpleKotlinCompilerMessageCollector(); - ExitCode exitCode = new K2JVMCompiler().exec( + K2JVMCompiler compiler = new K2JVMCompiler(); + if (context.getCompilerOptions() != null && !context.getCompilerOptions().isEmpty()) { + compiler.parseArguments(context.getCompilerOptions().toArray(new String[0]), compilerArguments); + } + + ExitCode exitCode = compiler.exec( messageCollector, new Services.Builder().build(), compilerArguments); diff --git a/extensions/kotlin/runtime/pom.xml b/extensions/kotlin/runtime/pom.xml index 2aa750bf436f8..204e7ad1b0da6 100644 --- a/extensions/kotlin/runtime/pom.xml +++ b/extensions/kotlin/runtime/pom.xml @@ -56,6 +56,10 @@ org.jetbrains.kotlin kotlin-stdlib-jdk8 + + org.jetbrains.kotlin + kotlin-reflect + io.smallrye.reactive diff --git a/integration-tests/kotlin/src/test/java/io/quarkus/kotlin/maven/it/KotlinDevModeIT.java b/integration-tests/kotlin/src/test/java/io/quarkus/kotlin/maven/it/KotlinDevModeIT.java index 563f95f0293e5..e86b85c457dde 100644 --- a/integration-tests/kotlin/src/test/java/io/quarkus/kotlin/maven/it/KotlinDevModeIT.java +++ b/integration-tests/kotlin/src/test/java/io/quarkus/kotlin/maven/it/KotlinDevModeIT.java @@ -55,4 +55,22 @@ public void testThatTheApplicationIsReloadedOnKotlinChange() throws MavenInvocat .pollDelay(1, TimeUnit.SECONDS) .atMost(1, TimeUnit.MINUTES).until(() -> DevModeTestUtils.getHttpResponse("/app/hello/bean").contains(newUuid)); } + + @Test + @Tag("failsOnJDK16") + public void testThatTheApplicationIsReloadedOnKotlinChangeWithCustomCompilerArgs() + throws MavenInvocationException, IOException { + testDir = initProject("projects/kotlin-compiler-args", "projects/kotlin-compiler-args-change"); + runAndCheck(false); + + // Edit the "Hello" message. + File jaxRsResource = new File(testDir, "src/main/kotlin/org/acme/HelloResource.kt"); + String uuid = UUID.randomUUID().toString(); + filter(jaxRsResource, ImmutableMap.of("\"hello\"", "\"" + uuid + "\"")); + + // Wait until we get "uuid" + await() + .pollDelay(1, TimeUnit.SECONDS) + .atMost(1, TimeUnit.MINUTES).until(() -> DevModeTestUtils.getHttpResponse("/app/hello").contains(uuid)); + } } diff --git a/integration-tests/kotlin/src/test/resources/projects/kotlin-compiler-args/pom.xml b/integration-tests/kotlin/src/test/resources/projects/kotlin-compiler-args/pom.xml new file mode 100644 index 0000000000000..b0b9fa1b902cd --- /dev/null +++ b/integration-tests/kotlin/src/test/resources/projects/kotlin-compiler-args/pom.xml @@ -0,0 +1,126 @@ + + + 4.0.0 + org.acme + acme + 1.0-SNAPSHOT + + @project.version@ + 11 + UTF-8 + 11 + 1.3.72 + + + + + io.quarkus + quarkus-bom + ${quarkus.version} + pom + import + + + + + + io.quarkus + quarkus-resteasy + + + io.quarkus + quarkus-arc + + + io.quarkus + quarkus-kotlin + + + io.quarkus + quarkus-websockets + + + io.quarkus + quarkus-junit5 + test + + + io.rest-assured + rest-assured + test + + + + src/main/kotlin + src/test/kotlin + + + io.quarkus + quarkus-maven-plugin + ${quarkus.version} + + + -Xallow-result-return-type + + + + + + build + + + + + + kotlin-maven-plugin + org.jetbrains.kotlin + ${kotlin.version} + + + compile + + compile + + + + test-compile + + test-compile + + + + + + all-open + + + + + + + + -Xallow-result-return-type + + + + + org.jetbrains.kotlin + kotlin-maven-allopen + ${kotlin.version} + + + + + + + + native + + native + + + + diff --git a/integration-tests/kotlin/src/test/resources/projects/kotlin-compiler-args/src/main/kotlin/org/acme/HelloResource.kt b/integration-tests/kotlin/src/test/resources/projects/kotlin-compiler-args/src/main/kotlin/org/acme/HelloResource.kt new file mode 100644 index 0000000000000..e657754d5421b --- /dev/null +++ b/integration-tests/kotlin/src/test/resources/projects/kotlin-compiler-args/src/main/kotlin/org/acme/HelloResource.kt @@ -0,0 +1,19 @@ +package org.acme + + +import javax.ws.rs.GET +import javax.ws.rs.Path +import javax.ws.rs.Produces +import javax.ws.rs.core.MediaType + +@Path("/app/hello") +class HelloResource() { + + @GET + @Produces(MediaType.TEXT_PLAIN) + fun hello4() = getAGreetingFailure().getOrDefault("hello") + + fun getAGreetingFailure(): Result = kotlin.runCatching { + throw Error("Something else 2") + } +} diff --git a/integration-tests/kotlin/src/test/resources/projects/kotlin-compiler-args/src/main/resources/META-INF/resources/index.html b/integration-tests/kotlin/src/test/resources/projects/kotlin-compiler-args/src/main/resources/META-INF/resources/index.html new file mode 100644 index 0000000000000..c09bb5c96b869 --- /dev/null +++ b/integration-tests/kotlin/src/test/resources/projects/kotlin-compiler-args/src/main/resources/META-INF/resources/index.html @@ -0,0 +1,156 @@ + + + + + acme - 1.0-SNAPSHOT + + + + + + +
+
+

Congratulations, you have created a new Quarkus application.

+ +

Why do you see this?

+ +

This page is served by Quarkus. The source is in + src/main/resources/META-INF/resources/index.html.

+ +

What can I do from here?

+ +

If not already done, run the application in dev mode using: mvn compile quarkus:dev. +

+
    +
  • Add REST resources, Servlets, functions and other services in src/main/java.
  • +
  • Your static assets are located in src/main/resources/META-INF/resources.
  • +
  • Configure your application in src/main/resources/application.properties. +
  • +
+ +

Do you like Quarkus?

+

Go give it a star on GitHub.

+ +

How do I get rid of this page?

+

Just delete the src/main/resources/META-INF/resources/index.html file.

+
+
+
+

Application

+
    +
  • GroupId: org.acme
  • +
  • ArtifactId: acme
  • +
  • Version: 1.0-SNAPSHOT
  • +
  • Quarkus Version: 999-SNAPSHOT
  • +
+
+
+

Next steps

+ +
+
+
+ + + + \ No newline at end of file diff --git a/integration-tests/kotlin/src/test/resources/projects/kotlin-compiler-args/src/main/resources/application.properties b/integration-tests/kotlin/src/test/resources/projects/kotlin-compiler-args/src/main/resources/application.properties new file mode 100644 index 0000000000000..5c0db73f4dc1a --- /dev/null +++ b/integration-tests/kotlin/src/test/resources/projects/kotlin-compiler-args/src/main/resources/application.properties @@ -0,0 +1,7 @@ +# Configuration file +key = value +greeting=bonjour + +quarkus.live-reload.password=secret +quarkus.live-reload.url=http://localhost:8080 +quarkus.package.type=mutable-jar diff --git a/integration-tests/kotlin/src/test/resources/projects/kotlin-compiler-args/src/test/kotlin/org/acme/HelloResourceTest.kt b/integration-tests/kotlin/src/test/resources/projects/kotlin-compiler-args/src/test/kotlin/org/acme/HelloResourceTest.kt new file mode 100644 index 0000000000000..3ef29b13a6fe7 --- /dev/null +++ b/integration-tests/kotlin/src/test/resources/projects/kotlin-compiler-args/src/test/kotlin/org/acme/HelloResourceTest.kt @@ -0,0 +1,21 @@ +package org.acme + +import io.quarkus.test.junit.QuarkusTest +import org.junit.jupiter.api.Test + +import io.restassured.RestAssured.given +import org.hamcrest.CoreMatchers.`is` + +@QuarkusTest +class HelloResourceTest { + + @Test + fun testHelloEndpoint() { + given() + .`when`().get("/app/hello") + .then() + .statusCode(200) + .body(`is`("hello")) + } + +}