From 0a6266970d878f262d8ca43002b74dc1d13f691d Mon Sep 17 00:00:00 2001 From: Benedikt Ritter Date: Mon, 30 Jan 2023 15:22:57 +0100 Subject: [PATCH] Use MapProperty instead of Map Changes the type of quarkusBuildProperties from Map to MapProperty. This allows build authors to specify values which may only become available later in the build by passed into the build using providers. Follow up to #29971 (cherry picked from commit f29e918b7f829a5b3254c49440568310f3b1ad6d) --- .../gradle/extension/QuarkusPluginExtension.java | 14 +++++++++----- .../java/io/quarkus/gradle/tasks/QuarkusBuild.java | 5 +++-- .../java/io/quarkus/gradle/tasks/QuarkusTask.java | 5 +++-- 3 files changed, 15 insertions(+), 9 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 ee4fd9f4100fc..499ca60d7a3cc 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,7 +3,6 @@ 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; @@ -19,6 +18,7 @@ import org.gradle.api.file.FileCollection; import org.gradle.api.file.RegularFile; import org.gradle.api.plugins.JavaPlugin; +import org.gradle.api.provider.MapProperty; import org.gradle.api.provider.Property; import org.gradle.api.provider.Provider; import org.gradle.api.tasks.SourceSet; @@ -39,7 +39,7 @@ public class QuarkusPluginExtension { private final Property finalName; - private Map quarkusBuildProperties; + private final MapProperty quarkusBuildProperties; private final SourceSetExtension sourceSetExtension; public QuarkusPluginExtension(Project project) { @@ -49,7 +49,7 @@ public QuarkusPluginExtension(Project project) { finalName.convention(project.provider(() -> String.format("%s-%s", project.getName(), project.getVersion()))); this.sourceSetExtension = new SourceSetExtension(); - quarkusBuildProperties = new HashMap<>(); + this.quarkusBuildProperties = project.getObjects().mapProperty(String.class, String.class); } public void beforeTest(Test task) { @@ -99,7 +99,7 @@ public void beforeTest(Test task) { public String buildNativeRunnerName(final Map taskSystemProps) { Properties properties = new Properties(taskSystemProps.size()); properties.putAll(taskSystemProps); - quarkusBuildProperties.entrySet() + quarkusBuildProperties.get().entrySet() .forEach(buildEntry -> properties.putIfAbsent(buildEntry.getKey(), buildEntry.getValue())); System.getProperties().entrySet() .forEach(propEntry -> properties.putIfAbsent(propEntry.getKey(), propEntry.getValue())); @@ -215,7 +215,7 @@ public Path appJarOrClasses() { return classesDir; } - public Map getQuarkusBuildProperties() { + public MapProperty getQuarkusBuildProperties() { return quarkusBuildProperties; } @@ -223,4 +223,8 @@ public void set(String name, @Nullable String value) { quarkusBuildProperties.put(String.format("quarkus.%s", name), value); } + public void set(String name, Property 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 4d98e2e99a3d8..1b3698e4f668a 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 @@ -256,8 +256,9 @@ private String getPropValueWithPrecedence(final String propName, final java.util } }); } - if (extension().getQuarkusBuildProperties().containsKey(propName)) { - return extension().getQuarkusBuildProperties().get(propName); + Map quarkusBuildProperties = extension().getQuarkusBuildProperties().get(); + if (quarkusBuildProperties.containsKey(propName)) { + return quarkusBuildProperties.get(propName); } else if (applicationProperties.contains(propName)) { return applicationProperties.getProperty(propName); } else if (getQuarkusBuildEnvProperties().containsKey(propName)) { 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 62a24bbdc5abc..e16c737d6009f 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 @@ -34,8 +34,9 @@ protected Properties getBuildSystemProperties(ResolvedDependency appArtifact) { realProperties.setProperty(key, (String) value); } } - if (!extension().getQuarkusBuildProperties().isEmpty()) { - extension().getQuarkusBuildProperties().entrySet().stream().filter(entry -> entry.getKey().startsWith("quarkus.")) + Map quarkusBuildProperties = extension().getQuarkusBuildProperties().get(); + if (!quarkusBuildProperties.isEmpty()) { + quarkusBuildProperties.entrySet().stream().filter(entry -> entry.getKey().startsWith("quarkus.")) .forEach(entry -> { realProperties.put(entry.getKey(), entry.getValue()); });