From 3859b5a0a96578ce7c63005236af3f07c53580c7 Mon Sep 17 00:00:00 2001 From: Roberto Cortez Date: Thu, 22 Feb 2024 23:55:40 +0000 Subject: [PATCH] Propagate quarkus.test.profile to Gradle worker (cherry picked from commit a19f144957a29cecea76bce04af7c4ca1600e30c) --- .../extension/QuarkusPluginExtension.java | 23 ++++++++++++------- .../quarkus/gradle/tasks/EffectiveConfig.java | 6 ++--- 2 files changed, 18 insertions(+), 11 deletions(-) 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 6f7df0aad8e79..1a6c34842d24c 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 @@ -1,5 +1,7 @@ package io.quarkus.gradle.extension; +import static io.quarkus.runtime.LaunchMode.*; + import java.io.File; import java.nio.file.Path; import java.nio.file.Paths; @@ -38,6 +40,7 @@ import io.quarkus.gradle.tasks.QuarkusGradleUtils; import io.quarkus.gradle.tooling.ToolingUtils; import io.quarkus.runtime.LaunchMode; +import io.smallrye.config.SmallRyeConfig; public abstract class QuarkusPluginExtension extends AbstractQuarkusExtension { private final SourceSetExtension sourceSetExtension; @@ -67,10 +70,14 @@ public void manifest(Action action) { public void beforeTest(Test task) { try { - final Map props = task.getSystemProperties(); + Map props = task.getSystemProperties(); + ApplicationModel appModel = getApplicationModel(TEST); + + SmallRyeConfig config = buildEffectiveConfiguration(appModel.getAppArtifact()).config(); + config.getOptionalValue(TEST.getProfileKey(), String.class) + .ifPresent(value -> props.put(TEST.getProfileKey(), value)); - final ApplicationModel appModel = getApplicationModel(LaunchMode.TEST); - final Path serializedModel = ToolingUtils.serializeAppModel(appModel, task, true); + Path serializedModel = ToolingUtils.serializeAppModel(appModel, task, true); props.put(BootstrapConstants.SERIALIZED_TEST_APP_MODEL, serializedModel.toString()); StringJoiner outputSourcesDir = new StringJoiner(","); @@ -79,10 +86,10 @@ public void beforeTest(Test task) { } props.put(BootstrapConstants.OUTPUT_SOURCES_DIR, outputSourcesDir.toString()); - final SourceSetContainer sourceSets = getSourceSets(); - final SourceSet mainSourceSet = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME); + SourceSetContainer sourceSets = getSourceSets(); + SourceSet mainSourceSet = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME); - final File outputDirectoryAsFile = getLastFile(mainSourceSet.getOutput().getClassesDirs()); + File outputDirectoryAsFile = getLastFile(mainSourceSet.getOutput().getClassesDirs()); Path projectDirPath = projectDir.toPath(); @@ -167,7 +174,7 @@ public Set combinedOutputSourceDirs() { } public AppModelResolver getAppModelResolver() { - return getAppModelResolver(LaunchMode.NORMAL); + return getAppModelResolver(NORMAL); } public AppModelResolver getAppModelResolver(LaunchMode mode) { @@ -175,7 +182,7 @@ public AppModelResolver getAppModelResolver(LaunchMode mode) { } public ApplicationModel getApplicationModel() { - return getApplicationModel(LaunchMode.NORMAL); + return getApplicationModel(NORMAL); } public ApplicationModel getApplicationModel(LaunchMode mode) { diff --git a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/EffectiveConfig.java b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/EffectiveConfig.java index 37cff3614d779..1166d55e410d3 100644 --- a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/EffectiveConfig.java +++ b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/EffectiveConfig.java @@ -41,7 +41,7 @@ * Eventually used to construct a map with the effective config options from all the sources above and expose * the Quarkus config objects like {@link PackageConfig}, {@link ClassLoadingConfig} and the underlying {@link SmallRyeConfig}. */ -final class EffectiveConfig { +public final class EffectiveConfig { private final Map fullConfig; private final SmallRyeConfig config; @@ -84,7 +84,7 @@ private EffectiveConfig(Builder builder) { this.fullConfig = generateFullConfigMap(config); } - SmallRyeConfig config() { + public SmallRyeConfig config() { return config; } @@ -126,7 +126,7 @@ static Builder builder() { return new Builder(); } - Map configMap() { + public Map configMap() { return fullConfig; }