From 74da3d7b6b7ab38d914b2f92832d4ee11d9d4cc1 Mon Sep 17 00:00:00 2001 From: Antonio Jacob Costa Date: Tue, 13 Dec 2022 16:29:17 +0100 Subject: [PATCH] import properties from build.gradle and remove hardcoded quarkus.package.output-directory value tests: IT for the build.gradle configuration --- .../extension/QuarkusPluginExtension.java | 15 +++ .../io/quarkus/gradle/tasks/QuarkusBuild.java | 44 ++++++- .../io/quarkus/gradle/tasks/QuarkusTask.java | 6 + .../build-configuration/build.gradle | 20 ++++ .../build-configuration/gradle.properties | 3 + .../build-configuration/settings.gradle | 18 +++ .../with-application-properties/build.gradle | 44 +++++++ .../settings.gradle | 15 +++ .../main/java/org/acme/ExampleResource.java | 19 +++ .../src/main/resources/application.properties | 5 + .../src/test/resources/application.properties | 4 + .../with-build-configuration/build.gradle | 44 +++++++ .../with-build-configuration/settings.gradle | 15 +++ .../main/java/org/acme/ExampleResource.java | 19 +++ .../src/main/resources/application.properties | 3 + .../src/test/resources/application.properties | 4 + .../without-configuration/build.gradle | 37 ++++++ .../without-configuration/settings.gradle | 15 +++ .../main/java/org/acme/ExampleResource.java | 19 +++ .../src/main/resources/application.properties | 3 + .../src/test/resources/application.properties | 4 + .../gradle/BuildConfigurationTest.java | 108 ++++++++++++++++++ 22 files changed, 463 insertions(+), 1 deletion(-) create mode 100644 integration-tests/gradle/src/main/resources/build-configuration/build.gradle create mode 100644 integration-tests/gradle/src/main/resources/build-configuration/gradle.properties create mode 100644 integration-tests/gradle/src/main/resources/build-configuration/settings.gradle create mode 100644 integration-tests/gradle/src/main/resources/build-configuration/with-application-properties/build.gradle create mode 100644 integration-tests/gradle/src/main/resources/build-configuration/with-application-properties/settings.gradle create mode 100644 integration-tests/gradle/src/main/resources/build-configuration/with-application-properties/src/main/java/org/acme/ExampleResource.java create mode 100644 integration-tests/gradle/src/main/resources/build-configuration/with-application-properties/src/main/resources/application.properties create mode 100644 integration-tests/gradle/src/main/resources/build-configuration/with-application-properties/src/test/resources/application.properties create mode 100644 integration-tests/gradle/src/main/resources/build-configuration/with-build-configuration/build.gradle create mode 100644 integration-tests/gradle/src/main/resources/build-configuration/with-build-configuration/settings.gradle create mode 100644 integration-tests/gradle/src/main/resources/build-configuration/with-build-configuration/src/main/java/org/acme/ExampleResource.java create mode 100644 integration-tests/gradle/src/main/resources/build-configuration/with-build-configuration/src/main/resources/application.properties create mode 100644 integration-tests/gradle/src/main/resources/build-configuration/with-build-configuration/src/test/resources/application.properties create mode 100644 integration-tests/gradle/src/main/resources/build-configuration/without-configuration/build.gradle create mode 100644 integration-tests/gradle/src/main/resources/build-configuration/without-configuration/settings.gradle create mode 100644 integration-tests/gradle/src/main/resources/build-configuration/without-configuration/src/main/java/org/acme/ExampleResource.java create mode 100644 integration-tests/gradle/src/main/resources/build-configuration/without-configuration/src/main/resources/application.properties create mode 100644 integration-tests/gradle/src/main/resources/build-configuration/without-configuration/src/test/resources/application.properties create mode 100644 integration-tests/gradle/src/test/java/io/quarkus/gradle/BuildConfigurationTest.java diff --git a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/extension/QuarkusPluginExtension.java b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/extension/QuarkusPluginExtension.java index ec9e5bf3d5058..925eec91f0979 100644 --- a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/extension/QuarkusPluginExtension.java +++ b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/extension/QuarkusPluginExtension.java @@ -3,6 +3,7 @@ import java.io.File; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.HashMap; import java.util.LinkedHashSet; import java.util.Map; import java.util.Objects; @@ -10,6 +11,8 @@ import java.util.StringJoiner; import java.util.stream.Collectors; +import javax.annotation.Nullable; + import org.gradle.api.Action; import org.gradle.api.Project; import org.gradle.api.file.FileCollection; @@ -34,6 +37,8 @@ public class QuarkusPluginExtension { private final Project project; private final Property finalName; + + private Map quarkusBuildProperties; private final SourceSetExtension sourceSetExtension; public QuarkusPluginExtension(Project project) { @@ -43,6 +48,7 @@ public QuarkusPluginExtension(Project project) { finalName.convention(project.provider(() -> String.format("%s-%s", project.getName(), project.getVersion()))); this.sourceSetExtension = new SourceSetExtension(); + quarkusBuildProperties = new HashMap<>(); } public void beforeTest(Test task) { @@ -182,4 +188,13 @@ public Path appJarOrClasses() { } return classesDir; } + + public Map getQuarkusBuildProperties() { + return quarkusBuildProperties; + } + + public void set(String name, @Nullable String value) { + quarkusBuildProperties.put(String.format("quarkus.%s", name), value); + } + } diff --git a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusBuild.java b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusBuild.java index 5e956adb7e82d..ff7f3372ccd5c 100644 --- a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusBuild.java +++ b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusBuild.java @@ -1,6 +1,8 @@ package io.quarkus.gradle.tasks; import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; @@ -16,6 +18,7 @@ import org.gradle.api.file.FileCollection; import org.gradle.api.java.archives.Attributes; import org.gradle.api.provider.MapProperty; +import org.gradle.api.tasks.CacheableTask; import org.gradle.api.tasks.Classpath; import org.gradle.api.tasks.Input; import org.gradle.api.tasks.Internal; @@ -35,15 +38,20 @@ import io.quarkus.maven.dependency.GACTV; import io.quarkus.runtime.util.StringUtil; +@CacheableTask public abstract class QuarkusBuild extends QuarkusTask { private static final String NATIVE_PROPERTY_NAMESPACE = "quarkus.native"; private static final String MANIFEST_SECTIONS_PROPERTY_PREFIX = "quarkus.package.manifest.manifest-sections"; private static final String MANIFEST_ATTRIBUTES_PROPERTY_PREFIX = "quarkus.package.manifest.attributes"; + private static final String OUTPUT_DIRECTORY = "quarkus.package.output-directory"; + private List ignoredEntries = new ArrayList<>(); private Manifest manifest = new Manifest(); + private Properties applicationProperties = new Properties(); + @Inject public QuarkusBuild() { super("Quarkus builds a runner jar based on the build jar"); @@ -131,7 +139,8 @@ public File getNativeRunner() { @OutputDirectory public File getFastJar() { - return new File(getProject().getBuildDir(), "quarkus-app"); + return new File(getProject().getBuildDir(), + this.getPropValueWithPrecedence(OUTPUT_DIRECTORY, java.util.Optional.of("quarkus-app"))); } @TaskAction @@ -223,4 +232,37 @@ private String expandConfigurationKey(String shortKey) { } return String.format("%s.%s", NATIVE_PROPERTY_NAMESPACE, hyphenatedKey); } + + private String getPropValueWithPrecedence(final String propName, final java.util.Optional defaultValue) { + if (applicationProperties.isEmpty()) { + FileCollection classpathFiles = getClasspath() + .filter(file -> "application.properties".equalsIgnoreCase(file.getName())); + classpathFiles.forEach(file -> { + FileInputStream appPropsIS = null; + try { + appPropsIS = new FileInputStream(file.getAbsoluteFile()); + applicationProperties.load(appPropsIS); + appPropsIS.close(); + } catch (IOException e) { + if (appPropsIS != null) { + try { + appPropsIS.close(); + } catch (IOException ex) { + // Ignore exception closing. + } + } + } + }); + } + if (extension().getQuarkusBuildProperties().containsKey(propName)) { + return extension().getQuarkusBuildProperties().get(propName); + } else if (applicationProperties.contains(propName)) { + return applicationProperties.getProperty(propName); + } else if (getQuarkusBuildEnvProperties().containsKey(propName)) { + return getQuarkusBuildEnvProperties().get(propName); + } else if (defaultValue.isPresent()) { + return defaultValue.get(); + } + return null; + } } diff --git a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusTask.java b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusTask.java index 41600035f4b47..254433b5155c3 100644 --- a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusTask.java +++ b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusTask.java @@ -36,6 +36,12 @@ protected Properties getBuildSystemProperties(ResolvedDependency appArtifact) { realProperties.setProperty(key, (String) value); } } + if (!extension().getQuarkusBuildProperties().isEmpty()) { + extension().getQuarkusBuildProperties().entrySet().stream().filter(entry -> entry.getKey().startsWith("quarkus.")) + .forEach(entry -> { + realProperties.put(entry.getKey(), entry.getValue()); + }); + } realProperties.putIfAbsent("quarkus.application.name", appArtifact.getArtifactId()); realProperties.putIfAbsent("quarkus.application.version", appArtifact.getVersion()); return realProperties; diff --git a/integration-tests/gradle/src/main/resources/build-configuration/build.gradle b/integration-tests/gradle/src/main/resources/build-configuration/build.gradle new file mode 100644 index 0000000000000..bdaca17877991 --- /dev/null +++ b/integration-tests/gradle/src/main/resources/build-configuration/build.gradle @@ -0,0 +1,20 @@ +plugins { + id 'java' + id 'io.quarkus' apply false +} + +repositories { + mavenLocal { + content { + includeGroupByRegex 'io.quarkus.*' + } + } + mavenCentral() +} + +test { + systemProperty "java.util.logging.manager", "org.jboss.logmanager.LogManager" +} + +group = 'io.quarkus.gradle.test' +version = '1.0' \ No newline at end of file diff --git a/integration-tests/gradle/src/main/resources/build-configuration/gradle.properties b/integration-tests/gradle/src/main/resources/build-configuration/gradle.properties new file mode 100644 index 0000000000000..aa65be16d3a05 --- /dev/null +++ b/integration-tests/gradle/src/main/resources/build-configuration/gradle.properties @@ -0,0 +1,3 @@ +quarkusPlatformArtifactId=quarkus-bom +quarkusPlatformGroupId=io.quarkus +quarkusPluginId=io.quarkus diff --git a/integration-tests/gradle/src/main/resources/build-configuration/settings.gradle b/integration-tests/gradle/src/main/resources/build-configuration/settings.gradle new file mode 100644 index 0000000000000..05b828cc6fb01 --- /dev/null +++ b/integration-tests/gradle/src/main/resources/build-configuration/settings.gradle @@ -0,0 +1,18 @@ +pluginManagement { + repositories { + mavenLocal { + content { + includeGroupByRegex 'io.quarkus.*' + } + } + mavenCentral() + gradlePluginPortal() + } + plugins { + id "${quarkusPluginId}" version "${quarkusPluginVersion}" + } +} + +include 'with-application-properties' +include 'with-build-configuration' +include 'without-configuration' \ No newline at end of file diff --git a/integration-tests/gradle/src/main/resources/build-configuration/with-application-properties/build.gradle b/integration-tests/gradle/src/main/resources/build-configuration/with-application-properties/build.gradle new file mode 100644 index 0000000000000..81bcea39ef58e --- /dev/null +++ b/integration-tests/gradle/src/main/resources/build-configuration/with-application-properties/build.gradle @@ -0,0 +1,44 @@ +plugins { + id 'java' + id 'io.quarkus' +} + +repositories { + mavenLocal { + content { + includeGroupByRegex 'io.quarkus.*' + } + } + mavenCentral() +} + +dependencies { + implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}") + implementation 'io.quarkus:quarkus-resteasy' + + testImplementation 'io.quarkus:quarkus-junit5' + testImplementation 'io.rest-assured:rest-assured' +} + +group 'org.acme' +version '1.0.0-SNAPSHOT' + +quarkus { + properties { + set("package.type", "fast-jar") + set("package.output-directory", "build-gradle-output-dir") + } +} + +compileJava { + options.encoding = 'UTF-8' + options.compilerArgs << '-parameters' +} + +compileTestJava { + options.encoding = 'UTF-8' +} + +test { + systemProperty "java.util.logging.manager", "org.jboss.logmanager.LogManager" +} diff --git a/integration-tests/gradle/src/main/resources/build-configuration/with-application-properties/settings.gradle b/integration-tests/gradle/src/main/resources/build-configuration/with-application-properties/settings.gradle new file mode 100644 index 0000000000000..c782004cf00aa --- /dev/null +++ b/integration-tests/gradle/src/main/resources/build-configuration/with-application-properties/settings.gradle @@ -0,0 +1,15 @@ +pluginManagement { + repositories { + mavenLocal { + content { + includeGroupByRegex 'io.quarkus.*' + } + } + mavenCentral() + gradlePluginPortal() + } + plugins { + id "${quarkusPluginId}" version "${quarkusPluginVersion}" + } +} +rootProject.name='with-application-properties' \ No newline at end of file diff --git a/integration-tests/gradle/src/main/resources/build-configuration/with-application-properties/src/main/java/org/acme/ExampleResource.java b/integration-tests/gradle/src/main/resources/build-configuration/with-application-properties/src/main/java/org/acme/ExampleResource.java new file mode 100644 index 0000000000000..2cd1720641843 --- /dev/null +++ b/integration-tests/gradle/src/main/resources/build-configuration/with-application-properties/src/main/java/org/acme/ExampleResource.java @@ -0,0 +1,19 @@ +package org.acme; + +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.eclipse.microprofile.config.inject.ConfigProperty; + +@Path("/hello") +public class ExampleResource { + @GET + @Produces(MediaType.TEXT_PLAIN) + public String hello() { + return "hello"; + } + +} \ No newline at end of file diff --git a/integration-tests/gradle/src/main/resources/build-configuration/with-application-properties/src/main/resources/application.properties b/integration-tests/gradle/src/main/resources/build-configuration/with-application-properties/src/main/resources/application.properties new file mode 100644 index 0000000000000..b266d74653a4d --- /dev/null +++ b/integration-tests/gradle/src/main/resources/build-configuration/with-application-properties/src/main/resources/application.properties @@ -0,0 +1,5 @@ +# Configuration file +# key = value +my-app-name=${quarkus.application.name} +quarkus.package.type=uber-jar +quarkus.package.output-directory=application-properties-output-dir \ No newline at end of file diff --git a/integration-tests/gradle/src/main/resources/build-configuration/with-application-properties/src/test/resources/application.properties b/integration-tests/gradle/src/main/resources/build-configuration/with-application-properties/src/test/resources/application.properties new file mode 100644 index 0000000000000..754b481eb7a97 --- /dev/null +++ b/integration-tests/gradle/src/main/resources/build-configuration/with-application-properties/src/test/resources/application.properties @@ -0,0 +1,4 @@ +# Configuration file +# key = value +example.message=Hello from Test +test-only=Test only diff --git a/integration-tests/gradle/src/main/resources/build-configuration/with-build-configuration/build.gradle b/integration-tests/gradle/src/main/resources/build-configuration/with-build-configuration/build.gradle new file mode 100644 index 0000000000000..12a23ee2e865d --- /dev/null +++ b/integration-tests/gradle/src/main/resources/build-configuration/with-build-configuration/build.gradle @@ -0,0 +1,44 @@ +plugins { + id 'java' + id 'io.quarkus' +} + +repositories { + mavenLocal { + content { + includeGroupByRegex 'io.quarkus.*' + } + } + mavenCentral() +} + +dependencies { + implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}") + implementation 'io.quarkus:quarkus-resteasy' + + testImplementation 'io.quarkus:quarkus-junit5' + testImplementation 'io.rest-assured:rest-assured' +} + +group 'org.acme' +version '1.0.0-SNAPSHOT' + +quarkus { + properties { + set("package.type", "uber-jar") + set("package.output-directory", "build-gradle-output-dir") + } +} + +compileJava { + options.encoding = 'UTF-8' + options.compilerArgs << '-parameters' +} + +compileTestJava { + options.encoding = 'UTF-8' +} + +test { + systemProperty "java.util.logging.manager", "org.jboss.logmanager.LogManager" +} diff --git a/integration-tests/gradle/src/main/resources/build-configuration/with-build-configuration/settings.gradle b/integration-tests/gradle/src/main/resources/build-configuration/with-build-configuration/settings.gradle new file mode 100644 index 0000000000000..4e0f0988bc2b2 --- /dev/null +++ b/integration-tests/gradle/src/main/resources/build-configuration/with-build-configuration/settings.gradle @@ -0,0 +1,15 @@ +pluginManagement { + repositories { + mavenLocal { + content { + includeGroupByRegex 'io.quarkus.*' + } + } + mavenCentral() + gradlePluginPortal() + } + plugins { + id "${quarkusPluginId}" version "${quarkusPluginVersion}" + } +} +rootProject.name='with-build-configuration' \ No newline at end of file diff --git a/integration-tests/gradle/src/main/resources/build-configuration/with-build-configuration/src/main/java/org/acme/ExampleResource.java b/integration-tests/gradle/src/main/resources/build-configuration/with-build-configuration/src/main/java/org/acme/ExampleResource.java new file mode 100644 index 0000000000000..2cd1720641843 --- /dev/null +++ b/integration-tests/gradle/src/main/resources/build-configuration/with-build-configuration/src/main/java/org/acme/ExampleResource.java @@ -0,0 +1,19 @@ +package org.acme; + +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.eclipse.microprofile.config.inject.ConfigProperty; + +@Path("/hello") +public class ExampleResource { + @GET + @Produces(MediaType.TEXT_PLAIN) + public String hello() { + return "hello"; + } + +} \ No newline at end of file diff --git a/integration-tests/gradle/src/main/resources/build-configuration/with-build-configuration/src/main/resources/application.properties b/integration-tests/gradle/src/main/resources/build-configuration/with-build-configuration/src/main/resources/application.properties new file mode 100644 index 0000000000000..b18c72feda9df --- /dev/null +++ b/integration-tests/gradle/src/main/resources/build-configuration/with-build-configuration/src/main/resources/application.properties @@ -0,0 +1,3 @@ +# Configuration file +# key = value +my-app-name=${quarkus.application.name} diff --git a/integration-tests/gradle/src/main/resources/build-configuration/with-build-configuration/src/test/resources/application.properties b/integration-tests/gradle/src/main/resources/build-configuration/with-build-configuration/src/test/resources/application.properties new file mode 100644 index 0000000000000..754b481eb7a97 --- /dev/null +++ b/integration-tests/gradle/src/main/resources/build-configuration/with-build-configuration/src/test/resources/application.properties @@ -0,0 +1,4 @@ +# Configuration file +# key = value +example.message=Hello from Test +test-only=Test only diff --git a/integration-tests/gradle/src/main/resources/build-configuration/without-configuration/build.gradle b/integration-tests/gradle/src/main/resources/build-configuration/without-configuration/build.gradle new file mode 100644 index 0000000000000..8eb1883b4f761 --- /dev/null +++ b/integration-tests/gradle/src/main/resources/build-configuration/without-configuration/build.gradle @@ -0,0 +1,37 @@ +plugins { + id 'java' + id 'io.quarkus' +} + +repositories { + mavenLocal { + content { + includeGroupByRegex 'io.quarkus.*' + } + } + mavenCentral() +} + +dependencies { + implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}") + implementation 'io.quarkus:quarkus-resteasy' + + testImplementation 'io.quarkus:quarkus-junit5' + testImplementation 'io.rest-assured:rest-assured' +} + +group 'org.acme' +version '1.0.0-SNAPSHOT' + +compileJava { + options.encoding = 'UTF-8' + options.compilerArgs << '-parameters' +} + +compileTestJava { + options.encoding = 'UTF-8' +} + +test { + systemProperty "java.util.logging.manager", "org.jboss.logmanager.LogManager" +} diff --git a/integration-tests/gradle/src/main/resources/build-configuration/without-configuration/settings.gradle b/integration-tests/gradle/src/main/resources/build-configuration/without-configuration/settings.gradle new file mode 100644 index 0000000000000..c782004cf00aa --- /dev/null +++ b/integration-tests/gradle/src/main/resources/build-configuration/without-configuration/settings.gradle @@ -0,0 +1,15 @@ +pluginManagement { + repositories { + mavenLocal { + content { + includeGroupByRegex 'io.quarkus.*' + } + } + mavenCentral() + gradlePluginPortal() + } + plugins { + id "${quarkusPluginId}" version "${quarkusPluginVersion}" + } +} +rootProject.name='with-application-properties' \ No newline at end of file diff --git a/integration-tests/gradle/src/main/resources/build-configuration/without-configuration/src/main/java/org/acme/ExampleResource.java b/integration-tests/gradle/src/main/resources/build-configuration/without-configuration/src/main/java/org/acme/ExampleResource.java new file mode 100644 index 0000000000000..2cd1720641843 --- /dev/null +++ b/integration-tests/gradle/src/main/resources/build-configuration/without-configuration/src/main/java/org/acme/ExampleResource.java @@ -0,0 +1,19 @@ +package org.acme; + +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.eclipse.microprofile.config.inject.ConfigProperty; + +@Path("/hello") +public class ExampleResource { + @GET + @Produces(MediaType.TEXT_PLAIN) + public String hello() { + return "hello"; + } + +} \ No newline at end of file diff --git a/integration-tests/gradle/src/main/resources/build-configuration/without-configuration/src/main/resources/application.properties b/integration-tests/gradle/src/main/resources/build-configuration/without-configuration/src/main/resources/application.properties new file mode 100644 index 0000000000000..b18c72feda9df --- /dev/null +++ b/integration-tests/gradle/src/main/resources/build-configuration/without-configuration/src/main/resources/application.properties @@ -0,0 +1,3 @@ +# Configuration file +# key = value +my-app-name=${quarkus.application.name} diff --git a/integration-tests/gradle/src/main/resources/build-configuration/without-configuration/src/test/resources/application.properties b/integration-tests/gradle/src/main/resources/build-configuration/without-configuration/src/test/resources/application.properties new file mode 100644 index 0000000000000..754b481eb7a97 --- /dev/null +++ b/integration-tests/gradle/src/main/resources/build-configuration/without-configuration/src/test/resources/application.properties @@ -0,0 +1,4 @@ +# Configuration file +# key = value +example.message=Hello from Test +test-only=Test only diff --git a/integration-tests/gradle/src/test/java/io/quarkus/gradle/BuildConfigurationTest.java b/integration-tests/gradle/src/test/java/io/quarkus/gradle/BuildConfigurationTest.java new file mode 100644 index 0000000000000..78cb93b8ccba2 --- /dev/null +++ b/integration-tests/gradle/src/test/java/io/quarkus/gradle/BuildConfigurationTest.java @@ -0,0 +1,108 @@ +package io.quarkus.gradle; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; +import java.nio.file.Path; + +import org.junit.jupiter.api.Test; + +public class BuildConfigurationTest extends QuarkusGradleWrapperTestBase { + + private static final String WITHOUT_CONFIGURATION_PROJECT_NAME = "without-configuration"; + + private static final String ROOT_PROJECT_NAME = "build-configuration"; + + private static final String BUILD_GRADLE_PROJECT_NAME = "with-build-configuration"; + + private static final String BUILD_GRADLE_OUTPUT_DIR = "build-gradle-output-dir"; + + private static final String BUILD_GRADLE_UBER_JAR_FILE = "with-build-configuration-1.0.0-SNAPSHOT-runner.jar"; + + private static final String APPLICATION_PROPERTIES_PROJECT_NAME = "with-application-properties"; + + private static final String APPLICATION_PROPERTIES_OUTPUT_DIR = "application-properties-output-dir"; + private static final String APPLICATION_PROPERTIES_UBER_JAR_FILE = "with-application-properties-1.0.0-SNAPSHOT-runner.jar"; + + @Test + public void buildUseApplicationPropertiesUberJar() throws IOException, InterruptedException, URISyntaxException { + final File projectDir = getProjectDir(ROOT_PROJECT_NAME); + runGradleWrapper(projectDir, "clean", "quarkusBuild"); + final Path projectPath = projectDir.toPath(); + final Path buildDirPath = projectPath.resolve(APPLICATION_PROPERTIES_PROJECT_NAME).resolve("build"); + assertThat(buildDirPath.resolve(APPLICATION_PROPERTIES_OUTPUT_DIR)).exists(); + final Path quarkusAppPath = buildDirPath.resolve(APPLICATION_PROPERTIES_OUTPUT_DIR); + final Path jar = quarkusAppPath.resolve(APPLICATION_PROPERTIES_UBER_JAR_FILE); + assertThat(jar).exists(); + } + + @Test + public void applicationPropertiesWithDPropsFastJar() + throws IOException, InterruptedException, URISyntaxException { + final File projectDir = getProjectDir(ROOT_PROJECT_NAME); + runGradleWrapper(projectDir, "clean", "quarkusBuild", "-Dquarkus.package.type=fast-jar"); + final Path projectPath = projectDir.toPath(); + final Path buildDirPath = projectPath.resolve(APPLICATION_PROPERTIES_PROJECT_NAME).resolve("build"); + assertThat(buildDirPath.resolve(APPLICATION_PROPERTIES_OUTPUT_DIR)).exists(); + final Path quarkusAppPath = buildDirPath.resolve(APPLICATION_PROPERTIES_OUTPUT_DIR); + assertThat(quarkusAppPath.resolve("quarkus-run.jar")).exists(); + assertThat(quarkusAppPath.resolve(APPLICATION_PROPERTIES_UBER_JAR_FILE)).doesNotExist(); + final Path deploymentDirPath = quarkusAppPath.resolve("lib").resolve("deployment"); + assertThat(deploymentDirPath).doesNotExist(); + } + + @Test + public void applicationPropertiesWithDPropsUnmutableJar() + throws IOException, InterruptedException, URISyntaxException { + final File projectDir = getProjectDir(ROOT_PROJECT_NAME); + runGradleWrapper(projectDir, "clean", "quarkusBuild", "-Dquarkus.package.type=mutable-jar"); + final Path projectPath = projectDir.toPath(); + final Path buildDirPath = projectPath.resolve(APPLICATION_PROPERTIES_PROJECT_NAME).resolve("build"); + assertThat(buildDirPath.resolve(APPLICATION_PROPERTIES_OUTPUT_DIR)).exists(); + final Path quarkusAppPath = buildDirPath.resolve(APPLICATION_PROPERTIES_OUTPUT_DIR); + assertThat(quarkusAppPath.resolve("quarkus-run.jar")).exists(); + assertThat(quarkusAppPath.resolve(APPLICATION_PROPERTIES_UBER_JAR_FILE)).doesNotExist(); + final Path deploymentDirPath = quarkusAppPath.resolve("lib").resolve("deployment"); + assertThat(deploymentDirPath).exists(); + } + + @Test + public void buildConfigUberJar() throws IOException, URISyntaxException, InterruptedException { + final File projectDir = getProjectDir(ROOT_PROJECT_NAME); + runGradleWrapper(projectDir, "clean", "quarkusBuild"); + final Path projectPath = projectDir.toPath(); + final Path buildDirPath = projectPath.resolve(BUILD_GRADLE_PROJECT_NAME).resolve("build"); + assertThat(buildDirPath.resolve(BUILD_GRADLE_OUTPUT_DIR)).exists(); + final Path quarkusAppPath = buildDirPath.resolve(BUILD_GRADLE_OUTPUT_DIR); + final Path jar = quarkusAppPath.resolve(BUILD_GRADLE_UBER_JAR_FILE); + assertThat(jar).exists(); + } + + @Test + public void buildConfigFastJarOverride() throws IOException, URISyntaxException, InterruptedException { + final File projectDir = getProjectDir(ROOT_PROJECT_NAME); + runGradleWrapper(projectDir, "clean", "quarkusBuild", "-Dquarkus.package.type=fast-jar"); + final Path projectPath = projectDir.toPath(); + final Path buildDirPath = projectPath.resolve(BUILD_GRADLE_PROJECT_NAME).resolve("build"); + assertThat(buildDirPath.resolve(BUILD_GRADLE_OUTPUT_DIR)).exists(); + final Path quarkusAppPath = buildDirPath.resolve(BUILD_GRADLE_OUTPUT_DIR); + assertThat(quarkusAppPath.resolve("quarkus-run.jar")).exists(); + assertThat(quarkusAppPath.resolve(BUILD_GRADLE_UBER_JAR_FILE)).doesNotExist(); + final Path deploymentDirPath = quarkusAppPath.resolve("lib").resolve("deployment"); + assertThat(deploymentDirPath).doesNotExist(); + } + + @Test + public void withoutConfigurationBuildsDefaults() throws IOException, InterruptedException, URISyntaxException { + final File projectDir = getProjectDir(ROOT_PROJECT_NAME); + runGradleWrapper(projectDir, "clean", "quarkusBuild"); + final Path projectPath = projectDir.toPath(); + final Path buildDirPath = projectPath.resolve(WITHOUT_CONFIGURATION_PROJECT_NAME).resolve("build"); + assertThat(buildDirPath.resolve("quarkus-app")).exists(); + final Path quarkusAppPath = buildDirPath.resolve("quarkus-app"); + final Path jar = quarkusAppPath.resolve("quarkus-run.jar"); + assertThat(jar).exists(); + } +}