diff --git a/WHATSNEW b/WHATSNEW
index f00f94c1c..a0cafee24 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -741,6 +741,10 @@ Other changes:
optional prefix and suffix attributes.
Bugzilla Report 47365
+ * false
). If you need to place it somewhere different,
use a nested <srcfile>
element between your
<arg>
elements to mark the insertion point.
Attribute | +Description | +Required | +
prefix | +a prefix to place in front of the file name when + building the command line argument. Since Ant 1.8.0 | +No. | +
suffix | +a suffix to append to the file name when + building the command line argument. Since Ant 1.8.0 | +No. | +
<targetfile>
is similar to
<srcfile>
and marks the position of the target
filename on the command line. If omitted, the target filenames will
not be added to the command line at all. This element can only be
specified if you also define a nested mapper.
Attribute | +Description | +Required | +
prefix | +a prefix to place in front of the file name when + building the command line argument. Since Ant 1.8.0 | +No. | +
suffix | +a suffix to append to the file name when + building the command line argument. Since Ant 1.8.0 | +No. | +
It is possible to specify environment variables to pass to the
system command via nested <env>
elements. See the
diff --git a/src/main/org/apache/tools/ant/taskdefs/ExecuteOn.java b/src/main/org/apache/tools/ant/taskdefs/ExecuteOn.java
index 0e3147190..d2903eb59 100644
--- a/src/main/org/apache/tools/ant/taskdefs/ExecuteOn.java
+++ b/src/main/org/apache/tools/ant/taskdefs/ExecuteOn.java
@@ -576,10 +576,10 @@ public class ExecuteOn extends ExecTask {
srcIndex + srcFiles.length,
targetIndex - srcIndex);
- // targets are already absolute file names
- System.arraycopy(targetFiles, 0, result,
- targetIndex + srcFiles.length,
- targetFiles.length);
+ insertTargetFiles(targetFiles, result,
+ targetIndex + srcFiles.length,
+ targetFilePos.getPrefix(),
+ targetFilePos.getSuffix());
// targetIndex --> end
System.arraycopy(orig, targetIndex, result,
@@ -589,10 +589,9 @@ public class ExecuteOn extends ExecTask {
// 0 --> targetIndex
System.arraycopy(orig, 0, result, 0, targetIndex);
- // targets are already absolute file names
- System.arraycopy(targetFiles, 0, result,
- targetIndex,
- targetFiles.length);
+ insertTargetFiles(targetFiles, result, targetIndex,
+ targetFilePos.getPrefix(),
+ targetFilePos.getSuffix());
// targetIndex --> srcIndex
System.arraycopy(orig, targetIndex, result,
@@ -626,6 +625,11 @@ public class ExecuteOn extends ExecTask {
if (forwardSlash && fileSeparator != '/') {
src = src.replace(fileSeparator, '/');
}
+ if (srcFilePos != null &&
+ (srcFilePos.getPrefix().length() > 0
+ || srcFilePos.getSuffix().length() > 0)) {
+ src = srcFilePos.getPrefix() + src + srcFilePos.getSuffix();
+ }
result[srcIndex + i] = src;
}
return result;
@@ -735,6 +739,26 @@ public class ExecuteOn extends ExecTask {
}
}
+ /**
+ * Inserts target file names (which are already absolute paths)
+ * into the list of arguments, taking prefix and postfix into
+ * account.
+ */
+ private static void insertTargetFiles(String[] targetFiles,
+ String[] arguments,
+ int insertPosition,
+ String prefix, String suffix) {
+ if (prefix.length() == 0 && suffix.length() == 0) {
+ System.arraycopy(targetFiles, 0, arguments, insertPosition,
+ targetFiles.length);
+ } else {
+ for (int i = 0; i < targetFiles.length; i++) {
+ arguments[insertPosition + i] =
+ prefix + targetFiles[i] + suffix;
+ }
+ }
+ }
+
/**
* Enumerated attribute with the values "file", "dir" and "both"
* for the type attribute.
diff --git a/src/main/org/apache/tools/ant/types/Commandline.java b/src/main/org/apache/tools/ant/types/Commandline.java
index c53979093..0a800ae30 100644
--- a/src/main/org/apache/tools/ant/types/Commandline.java
+++ b/src/main/org/apache/tools/ant/types/Commandline.java
@@ -202,14 +202,16 @@ public class Commandline implements Cloneable {
/**
* Class to keep track of the position of an Argument.
-
This class is there to support the srcfile and targetfile - elements of <execon> and <transform> - don't know - whether there might be additional use cases.
--SB + * + *This class is there to support the srcfile and targetfile + * elements of <apply>.
*/ public class Marker { private int position; private int realPos = -1; + private String prefix = ""; + private String suffix = ""; /** * Construct a marker for the specified position. @@ -236,6 +238,45 @@ public class Commandline implements Cloneable { } return realPos; } + + /** + * Set the prefix to be placed in front of the inserted argument. + * + * @param prefix fixed prefix string. + * @since Ant 1.8.0 + */ + public void setPrefix(String prefix) { + this.prefix = prefix != null ? prefix : ""; + } + + /** + * Get the prefix to be placed in front of the inserted argument. + * + * @since Ant 1.8.0 + */ + public String getPrefix() { + return prefix; + } + + /** + * Set the suffix to be placed at the end of the inserted argument. + * + * @param suffix fixed suffix string. + * @since Ant 1.8.0 + */ + public void setSuffix(String suffix) { + this.suffix = suffix != null ? suffix : ""; + } + + /** + * Get the suffix to be placed at the end of the inserted argument. + * + * @since Ant 1.8.0 + */ + public String getSuffix() { + return suffix; + } + } /** diff --git a/src/tests/antunit/taskdefs/exec/apply-test.xml b/src/tests/antunit/taskdefs/exec/apply-test.xml index 89f384153..56067a798 100755 --- a/src/tests/antunit/taskdefs/exec/apply-test.xml +++ b/src/tests/antunit/taskdefs/exec/apply-test.xml @@ -731,6 +731,29 @@ +