Skip to content

Commit

Permalink
Merge branch 'main' of github.com:SAP/commerce-gradle-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
mpern committed Jun 15, 2022
2 parents 243e63e + 03ac5d0 commit edcef4f
Showing 1 changed file with 34 additions and 6 deletions.
40 changes: 34 additions & 6 deletions src/main/java/mpern/sap/commerce/build/tasks/HybrisAntTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

import static mpern.sap.commerce.build.HybrisPlugin.HYBRIS_EXTENSION;

import java.util.HashMap;
import java.util.Map;

import org.gradle.api.Task;
import org.gradle.api.execution.TaskExecutionAdapter;
import org.gradle.api.file.ConfigurableFileTree;
import org.gradle.api.provider.MapProperty;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Internal;
import org.gradle.api.tasks.JavaExec;

Expand All @@ -20,14 +21,18 @@
public class HybrisAntTask extends JavaExec {
private static final Version V_2205 = Version.parseVersion("2205.0");

private Map<String, String> antProperties;
private final MapProperty<String, String> antProperties;

private final MapProperty<String, String> fallbackAntProperties;

private final Property<Boolean> noOp;

public HybrisAntTask() {
super();
antProperties = new HashMap<>();
noOp = getProject().getObjects().property(Boolean.class);
fallbackAntProperties = getProject().getObjects().mapProperty(String.class, String.class);
antProperties = getProject().getObjects().mapProperty(String.class, String.class);
antProperties.put("maven.update.dbdrivers", "false");
}

@Override
Expand All @@ -53,8 +58,11 @@ public void beforeExecute(Task task) {
t.systemProperty("ant.home", platform.getAntHome().get().getAsFile());
t.systemProperty("file.encoding", "UTF-8");

t.antProperty("maven.update.dbdrivers", "false");
t.antProperties.forEach((k, v) -> t.args("-D" + k + "=" + v));
Map<String, String> props = t.antProperties.get();

t.fallbackAntProperties.get().forEach(props::putIfAbsent);

props.forEach((k, v) -> t.args("-D" + k + "=" + v));

final HybrisPluginExtension plugin = (HybrisPluginExtension) t.getProject().getExtensions()
.getByName(HYBRIS_EXTENSION);
Expand Down Expand Up @@ -97,11 +105,31 @@ public void antProperty(String key, String value) {
* @param antProperties ant properties to use for the target
*/
public void setAntProperties(Map<String, String> antProperties) {
this.antProperties = new HashMap<>(antProperties);
this.antProperties.set(antProperties);
}

/**
* Add a new runtime property to configure the ant target
*
* @param key key of the property
* @param value value of the property
*/
public void fallbackAntProperty(String key, String value) {
fallbackAntProperties.put(key, value);
}

@Internal
public Property<Boolean> getNoOp() {
return noOp;
}

@Input
public MapProperty<String, String> getAntProperties() {
return antProperties;
}

@Input
public MapProperty<String, String> getFallbackAntProperties() {
return fallbackAntProperties;
}
}

0 comments on commit edcef4f

Please sign in to comment.