Browse Source

Merge branch 'master' into script-manager

master
Matt Benson 3 years ago
parent
commit
c6c7579916
3 changed files with 62 additions and 12 deletions
  1. +10
    -2
      manual/Tasks/pathconvert.html
  2. +32
    -10
      src/main/org/apache/tools/ant/taskdefs/PathConvert.java
  3. +20
    -0
      src/tests/antunit/taskdefs/pathconvert-test.xml

+ 10
- 2
manual/Tasks/pathconvert.html View File

@@ -28,7 +28,8 @@
<h3>Description</h3>
<p>Converts nested <a href="../Types/resources.html#collection">resource collections</a>, or a
reference to just one, into a path form for a particular platform, optionally storing the result
into a given property. It can also be used when you need to convert a resource collection into a
into a property or writing to an Ant <a href="../Types/resources.html">resource</a>.
It can also be used when you need to convert a resource collection into a
list, separated by a given character, such as a comma or space, or, conversely, e.g. to convert a
list of files in a FileList into a path.</p>
<p>Nested <code>&lt;map&gt;</code> elements can be specified to map Windows drive letters to Unix
@@ -65,7 +66,14 @@ nested <a href="../Types/mapper.html"><code>&lt;mapper&gt;</code></a> (<em>since
<tr>
<td>property</td>
<td>The name of the property in which to place the converted path.</td>
<td>No, result will be logged if unset</td>
<td>No, result will be logged if neither <code>@property</code> nor <code>@dest</code> is set</td>
</tr>
<tr>
<td>dest</td>
<td>A destination resource into which to write the converted path (Ant interprets this as a
<code>File</code> by default).
</td>
<td>No, result will be logged if neither <code>@property</code> nor <code>@dest</code> is set</td>
</tr>
<tr>
<td>refid</td>


+ 32
- 10
src/main/org/apache/tools/ant/taskdefs/PathConvert.java View File

@@ -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;
@@ -327,6 +331,19 @@ public class PathConvert extends Task {
return refid != null;
}

/**
* 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;


+ 20
- 0
src/tests/antunit/taskdefs/pathconvert-test.xml View File

@@ -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>

Loading…
Cancel
Save