summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatt Benson <mbenson@apache.org>2022-02-17 10:23:54 -0600
committerMatt Benson <mbenson@apache.org>2022-02-17 10:23:54 -0600
commitc6c75799166233a6993c0d0071e19838ee51fc97 (patch)
tree4a179fb46fca592ad434cdb3de55a9b258170d62 /src
parent0d7d3dd045e8cf2fc5c2d1b608483723fe2f1349 (diff)
parent0db467a379916a3d1fcf6956a0fedaf94cc25be3 (diff)
downloadant-c6c75799166233a6993c0d0071e19838ee51fc97.tar.gz
Merge branch 'master' into script-manager
Diffstat (limited to 'src')
-rw-r--r--src/main/org/apache/tools/ant/taskdefs/PathConvert.java42
-rw-r--r--src/tests/antunit/taskdefs/pathconvert-test.xml20
2 files changed, 52 insertions, 10 deletions
diff --git a/src/main/org/apache/tools/ant/taskdefs/PathConvert.java b/src/main/org/apache/tools/ant/taskdefs/PathConvert.java
index be46bbdd2..cc7581de0 100644
--- a/src/main/org/apache/tools/ant/taskdefs/PathConvert.java
+++ b/src/main/org/apache/tools/ant/taskdefs/PathConvert.java
@@ -37,6 +37,7 @@ import org.apache.tools.ant.types.EnumeratedAttribute;
import org.apache.tools.ant.types.Mapper;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.Reference;
+import org.apache.tools.ant.types.Resource;
import org.apache.tools.ant.types.ResourceCollection;
import org.apache.tools.ant.types.resources.Resources;
import org.apache.tools.ant.types.resources.Union;
@@ -62,19 +63,19 @@ public class PathConvert extends Task {
/**
* Path to be converted
*/
- private Resources path = null;
+ private Resources path;
/**
* Reference to path/fileset to convert
*/
- private Reference refid = null;
+ private Reference refid;
/**
* The target OS type
*/
- private String targetOS = null;
+ private String targetOS;
/**
* Set when targetOS is set to windows
*/
- private boolean targetWindows = false;
+ private boolean targetWindows;
/**
* Set if we should create a new property even if the result is empty
*/
@@ -82,7 +83,7 @@ public class PathConvert extends Task {
/**
* The property to receive the conversion
*/
- private String property = null;
+ private String property;
/**
* Path prefix map
*/
@@ -90,17 +91,20 @@ public class PathConvert extends Task {
/**
* User override on path sep char
*/
- private String pathSep = null;
+ private String pathSep;
/**
* User override on directory sep char
*/
- private String dirSep = null;
+ private String dirSep;
/** Filename mapper */
- private Mapper mapper = null;
+ private Mapper mapper;
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;
@@ -328,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.
*/
@@ -370,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);
}
@@ -451,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..02ca11013 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="${ant.file}" />
+ </pathconvert>
+ <au:assertFileExists file="${output}/destfile" />
+ <au:assertTrue>
+ <resourcesmatch astext="true">
+ <file file="${output}/destfile" />
+ <string value="${ant.file}" />
+ </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>