diff --git a/src/main/java/io/openliberty/tools/ant/ServerTask.java b/src/main/java/io/openliberty/tools/ant/ServerTask.java index 8c4fce51..7f886f77 100644 --- a/src/main/java/io/openliberty/tools/ant/ServerTask.java +++ b/src/main/java/io/openliberty/tools/ant/ServerTask.java @@ -22,12 +22,14 @@ import java.net.URLClassLoader; import java.text.MessageFormat; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Properties; import java.util.concurrent.Future; import java.util.concurrent.atomic.AtomicBoolean; +import io.openliberty.tools.ant.types.EnvironmentVariable; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; @@ -121,6 +123,18 @@ protected void initTask() { } } + /** + * used in gradle closure while calling ant task using project.ant.server + * this method is called automatically when we create an object of EnvironmentVariable using closure + * @param var environment object + */ + public void addConfiguredEnvironmentVariable(EnvironmentVariable var) { + if (this.environmentVariables == null) { + this.environmentVariables = new HashMap<>(); + } + this.environmentVariables.put(var.getName(), var.getValue()); + } + @Override public void execute() { @@ -689,6 +703,10 @@ public int getValue() { } } + public Map getEnvironmentVariables() { + return environmentVariables; + } + public void setEnvironmentVariables(Map environmentVariables) { this.environmentVariables = environmentVariables; } diff --git a/src/main/java/io/openliberty/tools/ant/types/EnvironmentVariable.java b/src/main/java/io/openliberty/tools/ant/types/EnvironmentVariable.java new file mode 100644 index 00000000..112e9aaf --- /dev/null +++ b/src/main/java/io/openliberty/tools/ant/types/EnvironmentVariable.java @@ -0,0 +1,37 @@ +/** + * (C) Copyright IBM Corporation 2025. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.openliberty.tools.ant.types; + +public class EnvironmentVariable { + private String name; + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +}