Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gradle - Resolve platform properties when possible #45681

Merged
merged 2 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ public void beforeTest(Test task) {
Map<String, Object> props = task.getSystemProperties();
ApplicationModel appModel = getApplicationModel(TEST);

SmallRyeConfig config = buildEffectiveConfiguration(appModel.getAppArtifact()).getConfig();
SmallRyeConfig config = buildEffectiveConfiguration(appModel.getAppArtifact(), appModel.getPlatformProperties())
.getConfig();
config.getOptionalValue(TEST.getProfileKey(), String.class)
.ifPresent(value -> props.put(TEST.getProfileKey(), value));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ protected Manifest manifest() {
return baseConfig().manifest();
}

protected EffectiveConfig buildEffectiveConfiguration(ResolvedDependency appArtifact) {
protected EffectiveConfig buildEffectiveConfiguration(ResolvedDependency appArtifact,
Map<String, String> platformProperties) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A minor comment, it looks like you could pass an ApplicationModel here now? Every invocation seems to be obtaining the two arguments from it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I tried to reduce my changes to the minimum. I pushed an additional commit.

Map<String, Object> properties = new HashMap<>();
exportCustomManifestProperties(properties);

Expand All @@ -140,6 +141,7 @@ protected EffectiveConfig buildEffectiveConfiguration(ResolvedDependency appArti
defaultProperties.putIfAbsent("quarkus.application.version", appArtifact.getVersion());

return EffectiveConfig.builder()
.withPlatformProperties(platformProperties)
.withForcedProperties(forcedPropertiesProperty.get())
.withTaskProperties(properties)
.withBuildProperties(quarkusBuildProperties.get())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ public Deploy() {
public void checkRequiredExtensions() {
ApplicationModel appModel = resolveAppModelForBuild();
Properties sysProps = new Properties();
sysProps.putAll(extension().buildEffectiveConfiguration(appModel.getAppArtifact()).getValues());
sysProps.putAll(extension().buildEffectiveConfiguration(appModel.getAppArtifact(), appModel.getPlatformProperties())
.getValues());
try (CuratedApplication curatedApplication = QuarkusBootstrap.builder()
.setBaseClassLoader(getClass().getClassLoader())
.setExistingModel(appModel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ private EffectiveConfig(Builder builder) {
// 100 -> microprofile.properties in classpath (provided by default sources)
// 0 -> fallback config source for error workaround (see below)

PropertiesConfigSource platformPropertiesConfigSource;
if (builder.platformProperties.isEmpty()) {
// we don't have the model yet so we don't have the Platform properties around
platformPropertiesConfigSource = new PropertiesConfigSource(
Map.of("platform.quarkus.native.builder-image", "<<ignored>>"), "platformProperties", 0);
} else {
platformPropertiesConfigSource = new PropertiesConfigSource(builder.platformProperties, "platformProperties", 0);
}

this.config = ConfigUtils.emptyConfigBuilder()
.forClassLoader(toUrlClassloader(builder.sourceDirectories))
.withSources(new PropertiesConfigSource(builder.forcedProperties, "forcedProperties", 600))
Expand All @@ -70,9 +79,7 @@ private EffectiveConfig(Builder builder) {
.withSources(new YamlConfigSourceLoader.InFileSystem())
.withSources(new YamlConfigSourceLoader.InClassPath())
.addPropertiesSources()
// todo: this is due to ApplicationModel#getPlatformProperties not being included in the effective config
.withSources(new PropertiesConfigSource(Map.of("platform.quarkus.native.builder-image", "<<ignored>>"),
"NativeConfig#builderImage", 0))
.withSources(platformPropertiesConfigSource)
.withDefaultValues(builder.defaultProperties)
.withProfile(builder.profile)
.withMapping(PackageConfig.class)
Expand Down Expand Up @@ -122,6 +129,7 @@ static Builder builder() {
}

static final class Builder {
private Map<String, String> platformProperties = emptyMap();
private Map<String, String> forcedProperties = emptyMap();
private Map<String, ?> taskProperties = emptyMap();
private Map<String, String> buildProperties = emptyMap();
Expand All @@ -134,6 +142,11 @@ EffectiveConfig build() {
return new EffectiveConfig(this);
}

Builder withPlatformProperties(Map<String, String> platformProperties) {
this.platformProperties = platformProperties;
return this;
}

Builder withForcedProperties(Map<String, String> forcedProperties) {
this.forcedProperties = forcedProperties;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ private void jarDependencies(Path libBoot, Path libMain) {
}

ApplicationModel appModel = resolveAppModelForBuild();
SmallRyeConfig config = getExtensionView().buildEffectiveConfiguration(appModel.getAppArtifact(), new HashMap<>())
SmallRyeConfig config = getExtensionView()
.buildEffectiveConfiguration(appModel.getAppArtifact(), appModel.getPlatformProperties(), new HashMap<>())
.getConfig();

// see https://quarkus.io/guides/class-loading-reference#configuring-class-loading
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ void generateBuild() {

ApplicationModel appModel = resolveAppModelForBuild();
SmallRyeConfig config = getExtensionView()
.buildEffectiveConfiguration(appModel.getAppArtifact(), getAdditionalForcedProperties().get().getProperties())
.buildEffectiveConfiguration(appModel.getAppArtifact(), appModel.getPlatformProperties(),
getAdditionalForcedProperties().get().getProperties())
.getConfig();
Map<String, String> quarkusProperties = Expressions.withoutExpansion(() -> {
Map<String, String> values = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ public Set<File> getInputDirectory() {
public void generateCode() throws IOException {
ApplicationModel appModel = ToolingUtils.deserializeAppModel(getApplicationModel().get().getAsFile().toPath());
Map<String, String> configMap = getExtensionView()
.buildEffectiveConfiguration(appModel.getAppArtifact(), new HashMap<>()).getValues();
.buildEffectiveConfiguration(appModel.getAppArtifact(), appModel.getPlatformProperties(), new HashMap<>())
.getValues();

File outputPath = getGeneratedOutputDirectory().get().getAsFile();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ private void exportCustomManifestProperties(Map<String, Object> properties) {
}

protected EffectiveConfig buildEffectiveConfiguration(ResolvedDependency appArtifact,
Map<String, ?> additionalForcedProperties) {
Map<String, String> platformProperties, Map<String, ?> additionalForcedProperties) {
Map<String, Object> properties = new HashMap<>();
exportCustomManifestProperties(properties);

Expand All @@ -235,6 +235,7 @@ protected EffectiveConfig buildEffectiveConfiguration(ResolvedDependency appArti
forced.put("quarkus.native.enabled", "true");
}
return EffectiveConfig.builder()
.withPlatformProperties(platformProperties)
.withForcedProperties(forced)
.withTaskProperties(properties)
.withBuildProperties(getQuarkusBuildProperties().get())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ public void setJvmArgs(List<String> jvmArgs) {
public void runQuarkus() {
ApplicationModel appModel = resolveAppModelForBuild();
Properties sysProps = new Properties();
sysProps.putAll(extension().buildEffectiveConfiguration(appModel.getAppArtifact()).getValues());
sysProps.putAll(extension().buildEffectiveConfiguration(appModel.getAppArtifact(), appModel.getPlatformProperties())
.getValues());
try (CuratedApplication curatedApplication = QuarkusBootstrap.builder()
.setBaseClassLoader(getClass().getClassLoader())
.setExistingModel(appModel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void dumpEffectiveConfiguration() {
try {
ApplicationModel appModel = resolveAppModelForBuild();
EffectiveConfig effectiveConfig = getExtensionView()
.buildEffectiveConfiguration(appModel.getAppArtifact(),
.buildEffectiveConfiguration(appModel.getAppArtifact(), appModel.getPlatformProperties(),
getAdditionalForcedProperties().get().getProperties());
SmallRyeConfig config = effectiveConfig.getConfig();
List<String> sourceNames = new ArrayList<>();
Expand Down
Loading