Skip to content

Commit

Permalink
Incorporate review comments
Browse files Browse the repository at this point in the history
* Use a constant for sharing data between the two processes
* Raise an exception if the mapping data is invalid.
* Include a functional-test for verifying the plugin behavior
  • Loading branch information
roguexz committed Sep 26, 2020
1 parent ec7612c commit f4f780f
Show file tree
Hide file tree
Showing 10 changed files with 189 additions and 6 deletions.
43 changes: 40 additions & 3 deletions devtools/gradle/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ repositories {
mavenCentral()
}

sourceSets {
// Functional Tests
funcTest {
java.srcDir 'src/funcTest/java'
resources.srcDir 'src/funcTest/resources'

compileClasspath += sourceSets.main.output + configurations.testRuntimeClasspath + configurations.compileOnly
runtimeClasspath += output + compileClasspath
}
}

configurations.all {
exclude group: 'io.quarkus', module: 'quarkus-bootstrap-maven-resolver'
}
Expand Down Expand Up @@ -64,9 +75,9 @@ javadoc {
}

pluginBundle {
website = 'https://quarkus.io/'
vcsUrl = 'https://github.com/quarkusio/quarkus'
tags = ['quarkus', 'quarkusio', 'graalvm']
website = 'https://quarkus.io/'
vcsUrl = 'https://github.com/quarkusio/quarkus'
tags = ['quarkus', 'quarkusio', 'graalvm']
}

gradlePlugin {
Expand All @@ -83,3 +94,29 @@ gradlePlugin {
wrapper {
distributionType = Wrapper.DistributionType.ALL
}

/*
* Functional tests for this module.
*/
task functionalTest(type: Test, description: 'Functional tests', dependsOn: [processResources, classes]) {
description = 'Run the functional tests.'
group = 'verification'

useJUnitPlatform()
testClassesDirs = sourceSets.funcTest.output.classesDirs
classpath = sourceSets.funcTest.runtimeClasspath
environment 'QUARKUS_VERSION', "${version}"
mustRunAfter test

// propagate the custom local maven repo, in case it's configured
if (System.properties.containsKey('maven.repo.local')) {
systemProperty 'maven.repo.local', System.properties.get('maven.repo.local')
}
testLogging {
events "passed", "skipped", "failed"
}
// Circumvent issue: https://github.com/gradle/gradle/issues/1675
systemProperty 'org.gradle.testkit.dir', file("${buildDir}/tmp/test-kit")
}

check.dependsOn functionalTest
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package io.quarkus.gradle.functional.test;

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

import java.io.File;
import java.net.URISyntaxException;
import java.net.URL;

import static org.junit.jupiter.api.Assertions.assertNotNull;

/**
* Functional test for verifying that the plugin can work with test sources which are included as part of a custom
* source set.
*/
public class AdditionalSourceSetsTest {

private static final String BUILD_FILE = "additional-source-sets/build.gradle";

@Test
public void executeFunctionalTest() throws URISyntaxException {
File buildFile = getBuildFile(BUILD_FILE);
GradleRunner runner = GradleRunner.create()
.withPluginClasspath()
.withProjectDir(buildFile.getParentFile());
BuildResult result = runner.withArguments(
"-s",
"-DQUARKUS_VERSION=" + System.getenv("QUARKUS_VERSION"),
"functionalTest")
.build();
String buildOutput = result.getOutput();
System.out.println(buildOutput);
}

/**
* Get the build file by searching for it on the classpath.
*
* @param path the path to the build file.
* @return the build file reference.
*/
private File getBuildFile(String path) throws URISyntaxException {
URL resource = Thread.currentThread().getContextClassLoader().getResource(BUILD_FILE);
assertNotNull(resource, "Build file not found.");
return new File(resource.toURI());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
plugins {
id 'java'
id 'io.quarkus'
}

repositories {
mavenLocal()
mavenCentral()
}

String quarkusVersion = System.getProperty('QUARKUS_VERSION')
dependencies {
implementation "io.quarkus:quarkus-arc:${quarkusVersion}"
testImplementation "io.quarkus:quarkus-junit5:${quarkusVersion}"
}

sourceSets {
// Functional Tests
funcTest {
java.srcDir 'src/funcTest/java'
if (file('src/funcTest/resources').exists()) {
resources.srcDir 'src/funcTest/resources'
}

compileClasspath += sourceSets.main.output + configurations.testRuntimeClasspath + configurations.compileOnly
runtimeClasspath += output + compileClasspath
}
}

compileJava {
options.compilerArgs << '-parameters'
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

/*
* Functional tests for this module.
*/
task functionalTest(type: Test, description: 'Functional tests', dependsOn: [processResources, classes]) {
description = 'Run the functional tests.'
group = 'verification'

useJUnitPlatform()
testClassesDirs = sourceSets.funcTest.output.classesDirs
classpath = sourceSets.funcTest.runtimeClasspath

// Show standard streams on the console.
testLogging {
showStandardStreams = true
}
systemProperty 'quarkus.http.host', 'localhost'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'functional-test'
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package ft;

import javax.inject.Inject;
import org.junit.jupiter.api.Test;
import io.quarkus.test.junit.QuarkusTest;

import static org.junit.jupiter.api.Assertions.assertEquals;

@QuarkusTest
public class SimpleBeanTest {

@Inject
SimpleBean bean;

@Test
public void verify() {
assertEquals("hello", bean.hello(), "Did the implementation of the SimpleBean change?");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ft;

import javax.enterprise.context.ApplicationScoped;

@ApplicationScoped
public class SimpleBean {

public String hello() {
return "hello";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_2_0.xsd"
bean-discovery-mode="all">
</beans>
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void beforeTest(Test task) {
project.relativePath(outputDirectory()));
joiner.add(mapping);
});
task.environment("TEST_TO_MAIN_MAPPINGS", joiner.toString());
task.environment(BootstrapConstants.TEST_TO_MAIN_MAPPINGS, joiner.toString());

final String nativeRunner = task.getProject().getBuildDir().toPath().resolve(finalName() + "-runner")
.toAbsolutePath()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ public interface BootstrapConstants {
String SERIALIZED_APP_MODEL = "quarkus-internal.serialized-app-model.path";
String DESCRIPTOR_FILE_NAME = "quarkus-extension.properties";

/**
* Constant for sharing the additional mappings between test-sources and the corresponding application-sources.
* The Gradle plugin populates this data which is then read by the PathTestHelper when executing tests.
*/
String TEST_TO_MAIN_MAPPINGS = "TEST_TO_MAIN_MAPPINGS";

@Deprecated
String EXTENSION_PROPS_JSON_FILE_NAME = "quarkus-extension.json";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.Map;
import java.util.stream.Stream;

import io.quarkus.bootstrap.BootstrapConstants;
import io.quarkus.runtime.util.ClassPathUtils;

/**
Expand Down Expand Up @@ -101,7 +102,7 @@ public final class PathTestHelper {
File.separator + "classes");
//endregion

String mappings = System.getenv("TEST_TO_MAIN_MAPPINGS");
String mappings = System.getenv(BootstrapConstants.TEST_TO_MAIN_MAPPINGS);
if (mappings != null) {
Stream.of(mappings.split(","))
.filter(s -> !s.isEmpty())
Expand All @@ -110,7 +111,7 @@ public final class PathTestHelper {
if (entry.length == 2) {
TEST_TO_MAIN_DIR_FRAGMENTS.put(entry[0], entry[1]);
} else {
System.err.println("Unable to parse additional test-to-main mapping: " + s);
throw new IllegalStateException("Unable to parse additional test-to-main mapping: " + s);
}
});
}
Expand Down

0 comments on commit f4f780f

Please sign in to comment.