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
  • Loading branch information
britter committed Jan 30, 2023
1 parent 5df1f9a commit d63563b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.provider.Property;
import org.gradle.api.provider.Provider;
import org.gradle.api.provider.MapProperty;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.SourceSetContainer;
import org.gradle.api.tasks.testing.Test;
Expand All @@ -39,7 +40,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 +50,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 +100,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 +216,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 d63563b

Please sign in to comment.