Skip to content

Commit

Permalink
Propagate quarkus.test.profile to Gradle worker
Browse files Browse the repository at this point in the history
(cherry picked from commit a19f144)
  • Loading branch information
radcortez authored and gsmet committed Feb 27, 2024
1 parent 1175950 commit 3859b5a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -67,10 +70,14 @@ public void manifest(Action<Manifest> action) {

public void beforeTest(Test task) {
try {
final Map<String, Object> props = task.getSystemProperties();
Map<String, Object> 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(",");
Expand All @@ -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();

Expand Down Expand Up @@ -167,15 +174,15 @@ public Set<File> combinedOutputSourceDirs() {
}

public AppModelResolver getAppModelResolver() {
return getAppModelResolver(LaunchMode.NORMAL);
return getAppModelResolver(NORMAL);
}

public AppModelResolver getAppModelResolver(LaunchMode mode) {
return new AppModelGradleResolver(project, mode);
}

public ApplicationModel getApplicationModel() {
return getApplicationModel(LaunchMode.NORMAL);
return getApplicationModel(NORMAL);
}

public ApplicationModel getApplicationModel(LaunchMode mode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
* Eventually used to construct a map with the <em>effective</em> 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<String, String> fullConfig;

private final SmallRyeConfig config;
Expand Down Expand Up @@ -84,7 +84,7 @@ private EffectiveConfig(Builder builder) {
this.fullConfig = generateFullConfigMap(config);
}

SmallRyeConfig config() {
public SmallRyeConfig config() {
return config;
}

Expand Down Expand Up @@ -126,7 +126,7 @@ static Builder builder() {
return new Builder();
}

Map<String, String> configMap() {
public Map<String, String> configMap() {
return fullConfig;
}

Expand Down

0 comments on commit 3859b5a

Please sign in to comment.