Skip to content

Commit

Permalink
Register generated output dir for kotlin gradle plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
glefloch committed Dec 14, 2020
1 parent bec5cc2 commit cd89070
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 4 deletions.
12 changes: 12 additions & 0 deletions devtools/gradle/src/main/java/io/quarkus/gradle/QuarkusPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,18 @@ public void execute(Task test) {
project.getPlugins().withId("org.jetbrains.kotlin.jvm", plugin -> {
tasks.getByName("compileKotlin").dependsOn(quarkusGenerateCode);
tasks.getByName("compileTestKotlin").dependsOn(quarkusGenerateCodeTests);

// Register the quarkus-generated-code
SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class)
.getSourceSets();
SourceSet mainSourceSet = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
SourceSet testSourceSet = sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME);
SourceSet generatedSourceSet = sourceSets.getByName(QuarkusGenerateCode.QUARKUS_GENERATED_SOURCES);
SourceSet generatedTestSourceSet = sourceSets.getByName(QuarkusGenerateCode.QUARKUS_TEST_GENERATED_SOURCES);
for (String provider : QuarkusGenerateCode.CODE_GENERATION_PROVIDER) {
mainSourceSet.getJava().srcDir(new File(generatedSourceSet.getJava().getOutputDir(), provider));
testSourceSet.getJava().srcDir(new File(generatedTestSourceSet.getJava().getOutputDir(), provider));
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class QuarkusGenerateCode extends QuarkusTask {

public static final String QUARKUS_GENERATED_SOURCES = "quarkus-generated-sources";
public static final String QUARKUS_TEST_GENERATED_SOURCES = "quarkus-test-generated-sources";
// TODO dynamically load generation provider, or make them write code directly in quarkus-generated-sources
public static final String[] CODE_GENERATION_PROVIDER = new String[] { "grpc" };

public static final String INIT_AND_RUN = "initAndRun";
private Set<Path> sourcesDirectories;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@

import java.io.File;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

public class KotlinGRPCProjectBuildTest extends QuarkusGradleWrapperTestBase {

@Test
@Disabled
public void testBasicMultiModuleBuild() throws Exception {
final File projectDir = getProjectDir("kotlin-grpc-project");
final BuildResult build = runGradleWrapper(projectDir, "clean", "build");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import javax.ws.rs.Path
import javax.ws.rs.Produces
import javax.ws.rs.core.MediaType

import io.quarkus.example.HelloMsg

@Path("/hello")
class ExampleResource {

@GET
@Produces(MediaType.TEXT_PLAIN)
fun hello() = "hello"
fun hello() = "hello" + HelloMsg.Status.TEST_ONE.getNumber()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
syntax = "proto3";
package io.quarkus.example;

option java_multiple_files = true;
option java_package = "io.quarkus.example";

import "google/protobuf/timestamp.proto";


message HelloMsg {
enum Status {
UNKNOWN = 0;
NOT_SERVING = 1;
TEST_ONE = 2;
}
string message = 1;
google.protobuf.Timestamp date_time = 2;
Status status = 3;
}

service DevModeService {
rpc Check(HelloMsg) returns (HelloMsg);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ExampleResourceTest {
.`when`().get("/hello")
.then()
.statusCode(200)
.body(`is`("hello"))
.body(`is`("hello2"))
}

}

0 comments on commit cd89070

Please sign in to comment.