diff --git a/WHATSNEW b/WHATSNEW
index da9f06c8c..f00f94c1c 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -737,6 +737,10 @@ Other changes:
*
arg
elements can be used.
It is highly recommended to avoid the line
version
diff --git a/src/main/org/apache/tools/ant/types/Commandline.java b/src/main/org/apache/tools/ant/types/Commandline.java
index a12811763..c53979093 100644
--- a/src/main/org/apache/tools/ant/types/Commandline.java
+++ b/src/main/org/apache/tools/ant/types/Commandline.java
@@ -103,6 +103,9 @@ public class Commandline implements Cloneable {
private String[] parts;
+ private String prefix = "";
+ private String suffix = "";
+
/**
* Set a single commandline argument.
*
@@ -158,12 +161,42 @@ public class Commandline implements Cloneable {
parts = new String[] {value.getAbsolutePath()};
}
+ /**
+ * Set the prefix to be placed in front of every part of the
+ * argument.
+ *
+ * @param prefix fixed prefix string.
+ * @since Ant 1.8.0
+ */
+ public void setPrefix(String prefix) {
+ this.prefix = prefix != null ? prefix : "";
+ }
+
+ /**
+ * Set the suffix to be placed at the end of every part of the
+ * argument.
+ *
+ * @param suffix fixed suffix string.
+ * @since Ant 1.8.0
+ */
+ public void setSuffix(String suffix) {
+ this.suffix = suffix != null ? suffix : "";
+ }
+
/**
* Return the constituent parts of this Argument.
* @return an array of strings.
*/
public String[] getParts() {
- return parts;
+ if (parts == null || parts.length == 0
+ || (prefix.length() == 0 && suffix.length() == 0)) {
+ return parts;
+ }
+ String[] fullParts = new String[parts.length];
+ for (int i = 0; i < fullParts.length; ++i) {
+ fullParts[i] = prefix + parts[i] + suffix;
+ }
+ return fullParts;
}
}
diff --git a/src/tests/junit/org/apache/tools/ant/types/CommandlineTest.java b/src/tests/junit/org/apache/tools/ant/types/CommandlineTest.java
index 559c5f76d..2fac757c5 100644
--- a/src/tests/junit/org/apache/tools/ant/types/CommandlineTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/CommandlineTest.java
@@ -130,7 +130,7 @@ public class CommandlineTest extends TestCase {
assertEquals("1 \'2\"3\'", Commandline.toString(new String[] {"1", "2\"3"}));
}
- public void testAwkCommand(){
+ public void testAwkCommand() {
Commandline c = new Commandline();
c.setExecutable("awk");
c.createArgument().setValue("'NR == 2 { print $NF }'");
@@ -140,4 +140,24 @@ public class CommandlineTest extends TestCase {
assertEquals("awk", s[0]);
assertEquals("'NR == 2 { print $NF }'", s[1]);
}
+
+ public void testPrefix() {
+ Commandline c = new Commandline();
+ Commandline.Argument a = c.createArgument();
+ a.setValue("foo");
+ a.setPrefix("-f=");
+ String[] s = c.getCommandline();
+ assertEquals(1, s.length);
+ assertEquals("-f=foo", s[0]);
+ }
+
+ public void testSuffix() {
+ Commandline c = new Commandline();
+ Commandline.Argument a = c.createArgument();
+ a.setValue("foo");
+ a.setSuffix(",1");
+ String[] s = c.getCommandline();
+ assertEquals(1, s.length);
+ assertEquals("foo,1", s[0]);
+ }
}