Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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 @@ -105,7 +105,6 @@ private EffectiveConfigProvider effectiveProvider() {
extensionView.getForcedProperties(),
extensionView.getProjectProperties(),
extensionView.getQuarkusBuildProperties(),
extensionView.getQuarkusRelevantProjectProperties(),
manifestAttributes,
manifestSections,
extensionView.getNativeBuild(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
package io.quarkus.gradle.tasks;

import static io.quarkus.gradle.tasks.QuarkusGradleUtils.getSourceSet;
import static io.smallrye.common.expression.Expression.Flag.DOUBLE_COLON;
import static io.smallrye.common.expression.Expression.Flag.LENIENT_SYNTAX;
import static io.smallrye.common.expression.Expression.Flag.NO_SMART_BRACES;
import static io.smallrye.common.expression.Expression.Flag.NO_TRIM;
import static java.util.Collections.emptyList;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand All @@ -32,7 +27,6 @@
import io.quarkus.deployment.pkg.PackageConfig;
import io.quarkus.gradle.dsl.Manifest;
import io.quarkus.maven.dependency.ResolvedDependency;
import io.smallrye.common.expression.Expression;

/**
* This base class exists to hide internal properties, make those only available in the {@link io.quarkus.gradle.tasks}
Expand Down Expand Up @@ -81,15 +75,7 @@ private BaseConfig buildBaseConfig() {
Set<File> resourcesDirs = getSourceSet(project, SourceSet.MAIN_SOURCE_SET_NAME).getResources().getSourceDirectories()
.getFiles();

// Used to handle the (deprecated) buildNative and testNative tasks.
project.getExtensions().getExtraProperties().getProperties().forEach((k, v) -> {
if (k.startsWith("quarkus.") || k.startsWith("platform.quarkus.")) {
forcedPropertiesProperty.put(k, v.toString());
}
});

EffectiveConfig effectiveConfig = EffectiveConfig.builder()
.withForcedProperties(forcedPropertiesProperty.get())
.withTaskProperties(Collections.emptyMap())
.withBuildProperties(quarkusBuildProperties.get())
.withProjectProperties(project.getProperties())
Expand Down Expand Up @@ -145,13 +131,6 @@ protected EffectiveConfig buildEffectiveConfiguration(ApplicationModel appModel)
Set<File> resourcesDirs = getSourceSet(project, SourceSet.MAIN_SOURCE_SET_NAME).getResources().getSourceDirectories()
.getFiles();

// Used to handle the (deprecated) buildNative and testNative tasks.
project.getExtensions().getExtraProperties().getProperties().forEach((k, v) -> {
if (k.startsWith("quarkus.") || k.startsWith("platform.quarkus.")) {
forcedPropertiesProperty.put(k, v.toString());
}
});

Map<String, String> defaultProperties = new HashMap<>();
String userIgnoredEntries = String.join(",", ignoredEntries.get());
if (!userIgnoredEntries.isEmpty()) {
Expand All @@ -162,7 +141,6 @@ protected EffectiveConfig buildEffectiveConfiguration(ApplicationModel appModel)

return EffectiveConfig.builder()
.withPlatformProperties(appModel.getPlatformProperties())
.withForcedProperties(forcedPropertiesProperty.get())
.withTaskProperties(properties)
.withBuildProperties(quarkusBuildProperties.get())
.withProjectProperties(project.getProperties())
Expand All @@ -172,65 +150,6 @@ protected EffectiveConfig buildEffectiveConfiguration(ApplicationModel appModel)
.build();
}

/**
* Filters resolved Gradle configuration for properties in the Quarkus namespace
* (as in start with <code>quarkus.</code>). This avoids exposing configuration that may contain secrets or
* passwords not related to Quarkus (for instance environment variables storing sensitive data for other systems).
*
* @param appArtifact the application dependency to retrive the quarkus application name and version.
* @return a filtered view of the configuration only with <code>quarkus.</code> names.
*/
protected Map<String, String> buildSystemProperties(ResolvedDependency appArtifact, Map<String, String> quarkusProperties) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This was removed because the method was copied in https://github.com/quarkusio/quarkus/pull/48769/files#diff-c7c4670b6f52fa54bf95459cc59308526b7b4331fe8bfb512245ba93413344f5R384, but the original code was not deleted.

Map<String, String> buildSystemProperties = new HashMap<>();
buildSystemProperties.putIfAbsent("quarkus.application.name", appArtifact.getArtifactId());
buildSystemProperties.putIfAbsent("quarkus.application.version", appArtifact.getVersion());

for (Map.Entry<String, String> entry : forcedPropertiesProperty.get().entrySet()) {
if (entry.getKey().startsWith("quarkus.") || entry.getKey().startsWith("platform.quarkus.")) {
buildSystemProperties.put(entry.getKey(), entry.getValue());
}
}
for (Map.Entry<String, String> entry : quarkusBuildProperties.get().entrySet()) {
if (entry.getKey().startsWith("quarkus.") || entry.getKey().startsWith("platform.quarkus.")) {
buildSystemProperties.put(entry.getKey(), entry.getValue());
}
}
for (Map.Entry<String, ?> entry : project.getProperties().entrySet()) {
if ((entry.getKey().startsWith("quarkus.") || entry.getKey().startsWith("platform.quarkus."))
&& entry.getValue() != null) {
buildSystemProperties.put(entry.getKey(), entry.getValue().toString());
}
}

Set<String> quarkusValues = new HashSet<>();
quarkusValues.addAll(quarkusProperties.values());
quarkusValues.addAll(buildSystemProperties.values());

for (String value : quarkusValues) {
Expression expression = Expression.compile(value, LENIENT_SYNTAX, NO_TRIM, NO_SMART_BRACES, DOUBLE_COLON);
for (String reference : expression.getReferencedStrings()) {
String expanded = forcedPropertiesProperty.get().get(reference);
if (expanded != null) {
buildSystemProperties.put(reference, expanded);
continue;
}

expanded = quarkusBuildProperties.get().get(reference);
if (expanded != null) {
buildSystemProperties.put(reference, expanded);
continue;
}

expanded = (String) project.getProperties().get(reference);
if (expanded != null) {
buildSystemProperties.put(reference, expanded);
}
}
}

return buildSystemProperties;
}

private String quarkusProfile() {
String profile = System.getProperty(QUARKUS_PROFILE);
if (profile == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public class EffectiveConfigProvider {
final MapProperty<String, String> forcedProperties;
final MapProperty<String, Object> projectProperties;
final MapProperty<String, String> quarkusBuildProperties;
final MapProperty<String, String> quarkusRelevantProjectProperties;
final MapProperty<String, Object> manifestAttributes;
final MapProperty<String, Attributes> manifestSections;
final Property<Boolean> nativeBuild;
Expand All @@ -36,7 +35,6 @@ public EffectiveConfigProvider(ListProperty<String> ignoredEntries,
MapProperty<String, String> forcedProperties,
MapProperty<String, Object> projectProperties,
MapProperty<String, String> quarkusBuildProperties,
MapProperty<String, String> quarkusRelevantProjectProperties,
MapProperty<String, Object> manifestAttributes,
MapProperty<String, Attributes> manifestSections,
Property<Boolean> nativeBuild,
Expand All @@ -47,7 +45,6 @@ public EffectiveConfigProvider(ListProperty<String> ignoredEntries,
this.forcedProperties = forcedProperties;
this.projectProperties = projectProperties;
this.quarkusBuildProperties = quarkusBuildProperties;
this.quarkusRelevantProjectProperties = quarkusRelevantProjectProperties;
this.manifestAttributes = manifestAttributes;
this.manifestSections = manifestSections;
this.nativeBuild = nativeBuild;
Expand All @@ -72,10 +69,6 @@ public EffectiveConfig buildEffectiveConfiguration(ApplicationModel appModel,
defaultProperties.putIfAbsent("quarkus.application.version", appArtifact.getVersion());

Map<String, String> forced = new HashMap<>(forcedProperties.get());
projectProperties.get().forEach((k, v) -> {
forced.put(k, v.toString());

});
additionalForcedProperties.forEach((k, v) -> {
forced.put(k, v.toString());
});
Expand All @@ -87,7 +80,7 @@ public EffectiveConfig buildEffectiveConfiguration(ApplicationModel appModel,
.withForcedProperties(forced)
.withTaskProperties(properties)
.withBuildProperties(quarkusBuildProperties.get())
.withProjectProperties(quarkusRelevantProjectProperties.get())
Copy link
Member Author

Choose a reason for hiding this comment

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

Unsure why we have these quarkusRelevantProjectProperties, created from:

private Provider<Map<String, String>> getQuarkusRelevantProjectProperties(Project project) {
if (GradleVersion.current().compareTo(GradleVersion.version("8.0")) >= 0) {
// This is more efficient, i.e.: configuration cache is invalidated only when quarkus properties change
return getProviderFactory().gradlePropertiesPrefixedBy("quarkus.");
} else {
return getProviderFactory().provider(() -> project.getProperties().entrySet().stream()
.filter(e -> e.getValue() != null)
.map(e -> Map.entry(e.getKey(), e.getValue().toString()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
}
}

And was being passed down as Project Properties, where in every other place we don't do that filter and pass Project Properties directly:

private BaseConfig buildBaseConfig() {
// Using common code to construct the "base config", which is all the configuration (system properties,
// environment, application.properties/yaml/yml, project properties) that is available in a Gradle task's
// _configuration phase_.
Set<File> resourcesDirs = getSourceSet(project, SourceSet.MAIN_SOURCE_SET_NAME).getResources().getSourceDirectories()
.getFiles();
EffectiveConfig effectiveConfig = EffectiveConfig.builder()
.withTaskProperties(Collections.emptyMap())
.withBuildProperties(quarkusBuildProperties.get())
.withProjectProperties(project.getProperties())
.withSourceDirectories(resourcesDirs)
.withProfile(quarkusProfile())
.build();
return new BaseConfig(effectiveConfig);
}

protected EffectiveConfig buildEffectiveConfiguration(ApplicationModel appModel) {
ResolvedDependency appArtifact = appModel.getAppArtifact();
Map<String, Object> properties = new HashMap<>();
exportCustomManifestProperties(properties);
Set<File> resourcesDirs = getSourceSet(project, SourceSet.MAIN_SOURCE_SET_NAME).getResources().getSourceDirectories()
.getFiles();
Map<String, String> defaultProperties = new HashMap<>();
String userIgnoredEntries = String.join(",", ignoredEntries.get());
if (!userIgnoredEntries.isEmpty()) {
defaultProperties.put("quarkus.package.jar.user-configured-ignored-entries", userIgnoredEntries);
}
defaultProperties.putIfAbsent("quarkus.application.name", appArtifact.getArtifactId());
defaultProperties.putIfAbsent("quarkus.application.version", appArtifact.getVersion());
return EffectiveConfig.builder()
.withPlatformProperties(appModel.getPlatformProperties())
.withTaskProperties(properties)
.withBuildProperties(quarkusBuildProperties.get())
.withProjectProperties(project.getProperties())
.withDefaultProperties(defaultProperties)
.withSourceDirectories(resourcesDirs)
.withProfile(quarkusProfile())
.build();
}

.withProjectProperties(projectProperties.get())
.withDefaultProperties(defaultProperties)
.withSourceDirectories(resourcesDirs)
.withProfile(getQuarkusProfile())
Expand Down Expand Up @@ -117,7 +110,7 @@ private String getQuarkusProfile() {
profile = quarkusBuildProperties.get().get(QUARKUS_PROFILE);
}
if (profile == null) {
Object p = quarkusRelevantProjectProperties.get().get(QUARKUS_PROFILE);
Object p = projectProperties.get().get(QUARKUS_PROFILE);
if (p != null) {
profile = p.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,15 @@ protected static void deleteFileIfExists(Path file) {
}
}

private Map<String, String> buildSystemProperties(ResolvedDependency appArtifact, Map<String, String> quarkusProperties) {
/**
* Filters resolved Gradle configuration for properties in the Quarkus namespace
* (as in start with <code>quarkus.</code>). This avoids exposing configuration that may contain secrets or
* passwords not related to Quarkus (for instance environment variables storing sensitive data for other systems).
*
* @param appArtifact the application dependency to retrive the quarkus application name and version.
* @return a filtered view of the configuration only with <code>quarkus.</code> names.
*/
protected Map<String, String> buildSystemProperties(ResolvedDependency appArtifact, Map<String, String> quarkusProperties) {
Map<String, String> buildSystemProperties = new HashMap<>();
buildSystemProperties.putIfAbsent("quarkus.application.name", appArtifact.getArtifactId());
buildSystemProperties.putIfAbsent("quarkus.application.version", appArtifact.getVersion());
Expand All @@ -390,11 +398,6 @@ private Map<String, String> buildSystemProperties(ResolvedDependency appArtifact
buildSystemProperties.putIfAbsent("quarkus.package.output-timestamp", "1970-01-02T00:00:00Z");
}

for (Map.Entry<String, String> entry : getExtensionView().getForcedProperties().get().entrySet()) {
if (entry.getKey().startsWith("quarkus.") || entry.getKey().startsWith("platform.quarkus.")) {
buildSystemProperties.put(entry.getKey(), entry.getValue());
}
}
for (Map.Entry<String, String> entry : getExtensionView().getQuarkusBuildProperties().get().entrySet()) {
if (entry.getKey().startsWith("quarkus.") || entry.getKey().startsWith("platform.quarkus.")) {
buildSystemProperties.put(entry.getKey(), entry.getValue());
Expand All @@ -414,23 +417,19 @@ private Map<String, String> buildSystemProperties(ResolvedDependency appArtifact
for (String value : quarkusValues) {
Expression expression = Expression.compile(value, LENIENT_SYNTAX, NO_TRIM, NO_SMART_BRACES, DOUBLE_COLON);
for (String reference : expression.getReferencedStrings()) {
String expanded = getExtensionView().getForcedProperties().get().get(reference);
String expanded = getExtensionView().getQuarkusBuildProperties().get().get(reference);
if (expanded != null) {
buildSystemProperties.put(reference, expanded);
continue;
}

expanded = getExtensionView().getQuarkusBuildProperties().get().get(reference);
if (expanded != null) {
buildSystemProperties.put(reference, expanded);
continue;
}
expanded = (String) getExtensionView().getProjectProperties().get().get(reference);
if (expanded != null) {
buildSystemProperties.put(reference, expanded);
}
}
}

return buildSystemProperties;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public EffectiveConfigProvider effectiveProvider() {
getExtensionView().getForcedProperties(),
getExtensionView().getProjectProperties(),
getExtensionView().getQuarkusBuildProperties(),
getExtensionView().getQuarkusRelevantProjectProperties(),
getManifestAttributes(),
getManifestSections(),
getExtensionView().getNativeBuild(),
Expand Down
Loading