summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatt Benson <mbenson@apache.org>2022-02-16 13:30:29 -0600
committerMatt Benson <mbenson@apache.org>2022-02-16 13:30:29 -0600
commit0d0971ab8a53e412089e48b59fd12fe16ea0beb1 (patch)
treec03f49e4da0b88185623603b43456f912a94ec7e /src
parentc9ed89099d29819a7e4358cf7c603a7415954299 (diff)
downloadant-0d0971ab8a53e412089e48b59fd12fe16ea0beb1.tar.gz
support writing pathconvert output to resource
Diffstat (limited to 'src')
-rw-r--r--src/main/org/apache/tools/ant/taskdefs/PathConvert.java25
-rw-r--r--src/tests/antunit/taskdefs/pathconvert-test.xml20
2 files changed, 43 insertions, 2 deletions
diff --git a/src/main/org/apache/tools/ant/taskdefs/PathConvert.java b/src/main/org/apache/tools/ant/taskdefs/PathConvert.java
index b962f568d..cc7581de0 100644
--- a/src/main/org/apache/tools/ant/taskdefs/PathConvert.java
+++ b/src/main/org/apache/tools/ant/taskdefs/PathConvert.java
@@ -102,6 +102,9 @@ public class PathConvert extends Task {
private boolean preserveDuplicates;
+ /** Destination {@link Resource} */
+ private Resource dest;
+
/**
* Helper class, holds the nested &lt;map&gt; values. Elements will look like
* this: &lt;map from=&quot;d:&quot; to=&quot;/foo&quot;/&gt;
@@ -329,6 +332,19 @@ public class PathConvert extends Task {
}
/**
+ * Set destination resource.
+ * @param dest
+ */
+ public void setDest(Resource dest) {
+ if (dest != null) {
+ if (this.dest != null) {
+ throw new BuildException("@dest already set");
+ }
+ }
+ this.dest = dest;
+ }
+
+ /**
* Do the execution.
* @throws BuildException if something is invalid.
*/
@@ -371,7 +387,10 @@ public class PathConvert extends Task {
}
}
- private OutputStream createOutputStream() {
+ private OutputStream createOutputStream() throws IOException {
+ if (dest != null) {
+ return dest.getOutputStream();
+ }
if (property == null) {
return new LogOutputStream(this);
}
@@ -452,10 +471,12 @@ public class PathConvert extends Task {
* @throws BuildException if something is not set up properly.
*/
private void validateSetup() throws BuildException {
-
if (path == null) {
throw new BuildException("You must specify a path to convert");
}
+ if (property != null && dest != null) {
+ throw new BuildException("@property and @dest are mutually exclusive");
+ }
// Determine the separator strings. The dirsep and pathsep attributes
// override the targetOS settings.
String dsep = File.separator;
diff --git a/src/tests/antunit/taskdefs/pathconvert-test.xml b/src/tests/antunit/taskdefs/pathconvert-test.xml
index d43eeac9f..b5d02014b 100644
--- a/src/tests/antunit/taskdefs/pathconvert-test.xml
+++ b/src/tests/antunit/taskdefs/pathconvert-test.xml
@@ -109,4 +109,24 @@
<isset property="result" />
</au:assertFalse>
</target>
+
+ <target name="testDest">
+ <au:assertFileDoesntExist file="${output}/destfile" />
+ <pathconvert dest="${output}/destfile">
+ <file file="foo/bar/baz" />
+ </pathconvert>
+ <au:assertFileExists file="${output}/destfile" />
+ <au:assertTrue>
+ <resourcesmatch>
+ <file file="${output}/destfile" />
+ <string value="${basedir}/foo/bar/baz" />
+ </resourcesmatch>
+ </au:assertTrue>
+ </target>
+
+ <target name="testDestPropertyMutex">
+ <au:expectfailure message="@property and @dest are mutually exclusive">
+ <pathconvert property="someprop" dest="somefile" refid="testpath" />
+ </au:expectfailure>
+ </target>
</project>