Skip to content

Commit

Permalink
Use MapProperty instead of Map
Browse files Browse the repository at this point in the history
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 quarkusio#29971

(cherry picked from commit f29e918)
  • Loading branch information
britter authored and gsmet committed Jan 31, 2023
1 parent 07b244b commit 0a62669
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -39,7 +39,7 @@ public class QuarkusPluginExtension {

private final Property<String> finalName;

private Map<String, String> quarkusBuildProperties;
private final MapProperty<String, String> quarkusBuildProperties;
private final SourceSetExtension sourceSetExtension;

public QuarkusPluginExtension(Project project) {
Expand All @@ -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) {
Expand Down Expand Up @@ -99,7 +99,7 @@ public void beforeTest(Test task) {
public String buildNativeRunnerName(final Map<String, Object> 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()));
Expand Down Expand Up @@ -215,12 +215,16 @@ public Path appJarOrClasses() {
return classesDir;
}

public Map<String, String> getQuarkusBuildProperties() {
public MapProperty<String, String> getQuarkusBuildProperties() {
return quarkusBuildProperties;
}

public void set(String name, @Nullable String value) {
quarkusBuildProperties.put(String.format("quarkus.%s", name), value);
}

public void set(String name, Property<String> value) {
quarkusBuildProperties.put(String.format("quarkus.%s", name), value);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,9 @@ private String getPropValueWithPrecedence(final String propName, final java.util
}
});
}
if (extension().getQuarkusBuildProperties().containsKey(propName)) {
return extension().getQuarkusBuildProperties().get(propName);
Map<String, String> 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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> quarkusBuildProperties = extension().getQuarkusBuildProperties().get();
if (!quarkusBuildProperties.isEmpty()) {
quarkusBuildProperties.entrySet().stream().filter(entry -> entry.getKey().startsWith("quarkus."))
.forEach(entry -> {
realProperties.put(entry.getKey(), entry.getValue());
});
Expand Down

0 comments on commit 0a62669

Please sign in to comment.