Skip to content

Commit

Permalink
Add support for Gradle Kotlin DSL
Browse files Browse the repository at this point in the history
  • Loading branch information
mgorniew committed May 17, 2020
1 parent d63095b commit 8cf38b8
Show file tree
Hide file tree
Showing 39 changed files with 1,147 additions and 250 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
import org.aesh.io.Resource;

import io.quarkus.cli.commands.file.BuildFile;
import io.quarkus.cli.commands.file.GradleBuildFile;
import io.quarkus.cli.commands.file.GroovyGradleBuildFile;
import io.quarkus.cli.commands.file.KotlinGradleBuildFile;
import io.quarkus.cli.commands.file.MavenBuildFile;
import io.quarkus.cli.commands.writer.FileProjectWriter;
import io.quarkus.platform.tools.config.QuarkusPlatformConfig;
Expand Down Expand Up @@ -47,9 +48,10 @@ public CommandResult execute(CommandInvocation commandInvocation) throws Command
if (path != null) {
File projectDirectory = new File(path.getAbsolutePath());
try (FileProjectWriter writer = new FileProjectWriter(projectDirectory)) {
if (new File(projectDirectory, "build.gradle").exists()
|| new File(projectDirectory, "build.gradle.kts").exists()) {
buildFile = new GradleBuildFile(writer);
if (new File(projectDirectory, "build.gradle").exists()) {
buildFile = new GroovyGradleBuildFile(writer);
} else if (new File(projectDirectory, "build.gradle.kts").exists()) {
buildFile = new KotlinGradleBuildFile(writer);
} else {
buildFile = new MavenBuildFile(writer);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.quarkus.gradle;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;

import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.GradleRunner;
import org.junit.jupiter.api.Test;

import io.quarkus.bootstrap.util.IoUtils;

import static org.assertj.core.api.Assertions.assertThat;


public class AddExtensionToModuleInMultiModuleKotlinProjectTest extends QuarkusGradleTestBase {

@Test
public void testBasicMultiModuleBuild() throws Exception {

final File projectDir = getProjectDir("add-extension-multi-module-kotlin-dsl");

BuildResult build = GradleRunner.create()
.forwardOutput()
.withPluginClasspath()
.withArguments(arguments(":application:addExtension", "--extensions=hibernate-orm"))
.withProjectDir(projectDir)
.build();

final Path applicationLib = projectDir.toPath().resolve("application").resolve("settings.gradle.kts");
assertThat(applicationLib).doesNotExist();

final Path appBuild = projectDir.toPath().resolve("application").resolve("build.gradle.kts");
assertThat(appBuild).exists();
assertThat(IoUtils.readFile(appBuild)).contains("implementation(\"io.quarkus:quarkus-hibernate-orm\")");
}
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
package io.quarkus.gradle;

import static org.assertj.core.api.Assertions.assertThat;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.quarkus.platform.descriptor.QuarkusPlatformDescriptor;
import io.quarkus.cli.commands.CreateProject;
import io.quarkus.cli.commands.writer.FileProjectWriter;
import io.quarkus.generators.BuildTool;
import io.quarkus.generators.SourceType;
import io.quarkus.platform.tools.config.QuarkusPlatformConfig;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.GradleRunner;
import org.gradle.testkit.runner.TaskOutcome;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.ArgumentsProvider;
import org.junit.jupiter.params.provider.ArgumentsSource;
import org.junit.jupiter.params.provider.EnumSource;

import io.quarkus.cli.commands.CreateProject;
import io.quarkus.cli.commands.writer.FileProjectWriter;
import io.quarkus.generators.BuildTool;
import io.quarkus.generators.SourceType;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

import static org.assertj.core.api.Assertions.assertThat;

public class QuarkusPluginFunctionalTest extends QuarkusGradleTestBase {

Expand All @@ -36,9 +37,10 @@ void setUp(@TempDir File projectRoot) {
this.projectRoot = projectRoot;
}

@Test
public void canRunListExtensions() throws IOException {
createProject(SourceType.JAVA);
@ParameterizedTest(name = "Create project with {0}")
@EnumSource(value = BuildTool.class, names = "GRADLE.*", mode = EnumSource.Mode.MATCH_ANY)
public void canRunListExtensions(BuildTool buildTool) throws IOException {
createProject(SourceType.JAVA, buildTool);

BuildResult build = GradleRunner.create()
.forwardOutput()
Expand All @@ -51,9 +53,10 @@ public void canRunListExtensions() throws IOException {
assertThat(build.getOutput()).contains("Quarkus - Core");
}

@Test
public void canGenerateConfig() throws IOException {
createProject(SourceType.JAVA);
@ParameterizedTest(name = "Create project with {0}")
@EnumSource(value = BuildTool.class, names = "GRADLE.*", mode = EnumSource.Mode.MATCH_ANY)
public void canGenerateConfig(BuildTool buildTool) throws IOException {
createProject(SourceType.JAVA, buildTool);

BuildResult build = GradleRunner.create()
.forwardOutput()
Expand All @@ -67,10 +70,10 @@ public void canGenerateConfig() throws IOException {
}


@ParameterizedTest(name = "Build {0} project")
@EnumSource(SourceType.class)
public void canBuild(SourceType sourceType) throws IOException, InterruptedException {
createProject(sourceType);
@ParameterizedTest(name = "Build {0} project created with {1}")
@ArgumentsSource(SourceTypeBuildToolProvider.class)
public void canBuild(SourceType sourceType, BuildTool buildTool) throws IOException, InterruptedException {
createProject(sourceType, buildTool);

BuildResult build = GradleRunner.create()
.forwardOutput()
Expand All @@ -87,19 +90,29 @@ public void canBuild(SourceType sourceType) throws IOException, InterruptedExcep
assertThat(buildDir.resolve("foo-1.0.0-SNAPSHOT-runner")).doesNotExist();
}

private void createProject(SourceType sourceType) throws IOException {
private void createProject(SourceType sourceType, BuildTool buildTool) throws IOException {
Map<String, Object> context = new HashMap<>();
context.put("path", "/greeting");
assertThat(new CreateProject(new FileProjectWriter(projectRoot),
QuarkusPlatformConfig.getGlobalDefault().getPlatformDescriptor())
.groupId("com.acme.foo")
.artifactId("foo")
.version("1.0.0-SNAPSHOT")
.buildTool(BuildTool.GRADLE)
.buildTool(buildTool)
.className("org.acme.GreetingResource")
.sourceType(sourceType)
.doCreateProject(context))
.withFailMessage("Project was not created")
.isTrue();
}

public static class SourceTypeBuildToolProvider implements ArgumentsProvider {

@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext extensionContext) {
List<SourceType> sourceTypes = Arrays.asList(SourceType.values());
return Stream.of(BuildTool.GRADLE, BuildTool.GRADLE_KOTLIN_DSL)
.flatMap(buildTool -> sourceTypes.stream().map(sourceType -> Arguments.of(sourceType, buildTool)));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
plugins {
id("io.quarkus")
}

val quarkusPlatformGroupId: String by project
val quarkusPlatformArtifactId: String by project
val quarkusPlatformVersion: String by project

dependencies {
implementation(project(":common"))
implementation("io.quarkus:quarkus-resteasy")

testImplementation("io.quarkus:quarkus-junit5")
testImplementation("io.rest-assured:rest-assured")

implementation(enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}"))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.acme.quarkus.sample;

import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.acme.common.CommonBean;

@Path("/hello")
public class HelloResource {

@Inject
CommonBean common;

@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
return "hello " + common.getName();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>my-quarkus-project - 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.quarkus.sample</li>
<li>ArtifactId: my-quarkus-project</li>
<li>Version: 1.0-SNAPSHOT</li>
<li>Quarkus Version: 999-SNAPSHOT</li>
</ul>
</div>
<div class="right-section">
<h3>Next steps</h3>
<ul>
<li><a href="https://quarkus.io/guides/maven-tooling.html" target="_blank">Setup your IDE</a></li>
<li><a href="https://quarkus.io/guides/getting-started.html" target="_blank">Getting started</a></li>
<li><a href="https://quarkus.io" target="_blank">Quarkus Web Site</a></li>
</ul>
</div>
</div>
</div>


</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Configuration file
# key = value
Loading

0 comments on commit 8cf38b8

Please sign in to comment.