Skip to content

Commit

Permalink
Merge pull request #15552 from glefloch/fix/15418
Browse files Browse the repository at this point in the history
Handle kotlin compiler args in dev mode
  • Loading branch information
glefloch authored May 27, 2021
2 parents fe07bc0 + fe7b43a commit 0a2f3ff
Show file tree
Hide file tree
Showing 8 changed files with 359 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void compile(Set<File> filesToCompile, Context context) {
compilerArguments.setPluginClasspaths(context.getCompilePluginArtifacts().toArray(new String[0]));
}
if (context.getCompilerPluginOptions() != null && !context.getCompilerPluginOptions().isEmpty()) {
List<String> sanitizedOptions = new ArrayList<>(context.getCompilerOptions().size());
List<String> sanitizedOptions = new ArrayList<>(context.getCompilerPluginOptions().size());
for (String rawOption : context.getCompilerPluginOptions()) {
Matcher matcher = OPTION_PATTERN.matcher(rawOption);
if (!matcher.matches()) {
Expand All @@ -71,9 +71,15 @@ public void compile(Set<File> 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);
Expand Down
4 changes: 4 additions & 0 deletions extensions/kotlin/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>org.acme</groupId>
<artifactId>acme</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<quarkus.version>@project.version@</quarkus.version>
<maven.compiler.source>11</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>11</maven.compiler.target>
<kotlin.version>1.3.72</kotlin.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bom</artifactId>
<version>${quarkus.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-kotlin</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-websockets</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/main/kotlin</sourceDirectory>
<testSourceDirectory>src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>${quarkus.version}</version>
<configuration>
<compilerArgs>
<arg>-Xallow-result-return-type</arg>
</compilerArgs>
</configuration>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<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>
<compilerPlugins>
<plugin>all-open</plugin>
</compilerPlugins>
<pluginOptions>
<!-- Each annotation is placed on its own line -->
<option>all-open:annotation=javax.enterprise.context.ApplicationScoped</option>
<option>all-open:annotation=javax.ws.rs.Path</option>
</pluginOptions>
<args>
<arg>-Xallow-result-return-type</arg>
</args>
</configuration>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-allopen</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>native</id>
<properties>
<quarkus.package.type>native</quarkus.package.type>
</properties>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -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<String> = kotlin.runCatching {
throw Error("Something else 2")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>acme - 1.0-SNAPSHOT</title>
<style>
h1, h2, h3, h4, h5, h6 {
margin-bottom: 0.5rem;
font-weight: 400;
line-height: 1.5;
}

h1 {
font-size: 2.5rem;
}

h2 {
font-size: 2rem
}

h3 {
font-size: 1.75rem
}

h4 {
font-size: 1.5rem
}

h5 {
font-size: 1.25rem
}

h6 {
font-size: 1rem
}

.lead {
font-weight: 300;
font-size: 2rem;
}

.banner {
font-size: 2.7rem;
margin: 0;
padding: 2rem 1rem;
background-color: #00A1E2;
color: white;
}

body {
margin: 0;
font-family: -apple-system, system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
}

code {
font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
font-size: 87.5%;
color: #e83e8c;
word-break: break-word;
}

.left-column {
padding: .75rem;
max-width: 75%;
min-width: 55%;
}

.right-column {
padding: .75rem;
max-width: 25%;
}

.container {
display: flex;
width: 100%;
}

li {
margin: 0.75rem;
}

.right-section {
margin-left: 1rem;
padding-left: 0.5rem;
}

.right-section h3 {
padding-top: 0;
font-weight: 200;
}

.right-section ul {
border-left: 0.3rem solid #00A1E2;
list-style-type: none;
padding-left: 0;
}

</style>
</head>
<body>

<div class="banner lead">
Your new Cloud-Native application is ready!
</div>

<div class="container">
<div class="left-column">
<p class="lead"> Congratulations, you have created a new Quarkus application.</p>

<h2>Why do you see this?</h2>

<p>This page is served by Quarkus. The source is in
<code>src/main/resources/META-INF/resources/index.html</code>.</p>

<h2>What can I do from here?</h2>

<p>If not already done, run the application in <em>dev mode</em> using: <code>mvn compile quarkus:dev</code>.
</p>
<ul>
<li>Add REST resources, Servlets, functions and other services in <code>src/main/java</code>.</li>
<li>Your static assets are located in <code>src/main/resources/META-INF/resources</code>.</li>
<li>Configure your application in <code>src/main/resources/application.properties</code>.
</li>
</ul>

<h2>Do you like Quarkus?</h2>
<p>Go give it a star on <a href="https://github.com/quarkusio/quarkus">GitHub</a>.</p>

<h2>How do I get rid of this page?</h2>
<p>Just delete the <code>src/main/resources/META-INF/resources/index.html</code> file.</p>
</div>
<div class="right-column">
<div class="right-section">
<h3>Application</h3>
<ul>
<li>GroupId: org.acme</li>
<li>ArtifactId: acme</li>
<li>Version: 1.0-SNAPSHOT</li>
<li>Quarkus Version: 999-SNAPSHOT</li>
</ul>
</div>
<div class="right-section">
<h3>Next steps</h3>
<ul>
<!-- the url have been erased on purpose -->
<li><a href="#">Setup your IDE</a></li>
<li><a href="#">Getting started</a></li>
<li><a href="#">Documentation</a></li>
</ul>
</div>
</div>
</div>


</body>
</html>
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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"))
}

}

0 comments on commit 0a2f3ff

Please sign in to comment.