diff --git a/src/main/org/apache/tools/ant/taskdefs/PathConvert.java b/src/main/org/apache/tools/ant/taskdefs/PathConvert.java
index 2a229bcfe..8589d1862 100644
--- a/src/main/org/apache/tools/ant/taskdefs/PathConvert.java
+++ b/src/main/org/apache/tools/ant/taskdefs/PathConvert.java
@@ -18,6 +18,7 @@
package org.apache.tools.ant.taskdefs;
import java.io.File;
+import java.util.Iterator;
import java.util.List;
import java.util.Vector;
import java.util.ArrayList;
@@ -31,8 +32,10 @@ import org.apache.tools.ant.types.Mapper;
import org.apache.tools.ant.types.Reference;
import org.apache.tools.ant.types.ResourceCollection;
import org.apache.tools.ant.types.EnumeratedAttribute;
+import org.apache.tools.ant.types.resources.Resources;
import org.apache.tools.ant.types.resources.Union;
import org.apache.tools.ant.util.FileNameMapper;
+import org.apache.tools.ant.util.IdentityMapper;
/**
* Converts path and classpath information to a specific target OS
@@ -52,7 +55,7 @@ public class PathConvert extends Task {
/**
* Path to be converted
*/
- private Union path = null;
+ private Resources path = null;
/**
* Reference to path/fileset to convert
*/
@@ -89,6 +92,8 @@ public class PathConvert extends Task {
/** Filename mapper */
private Mapper mapper = null;
+ private boolean preserveDuplicates;
+
/**
* Construct a new instance of the PathConvert task.
*/
@@ -191,10 +196,9 @@ public class PathConvert extends Task {
getPath().add(rc);
}
- private synchronized Union getPath() {
+ private synchronized Resources getPath() {
if (path == null) {
- path = new Union();
- path.setProject(getProject());
+ path = new Resources(getProject());
}
return path;
}
@@ -294,6 +298,24 @@ public class PathConvert extends Task {
dirSep = sep;
}
+ /**
+ * Set the preserveDuplicates.
+ * @param preserveDuplicates the boolean to set
+ * @since Ant 1.8
+ */
+ public void setPreserveDuplicates(boolean preserveDuplicates) {
+ this.preserveDuplicates = preserveDuplicates;
+ }
+
+ /**
+ * Get the preserveDuplicates.
+ * @return boolean
+ * @since Ant 1.8
+ */
+ public boolean isPreserveDuplicates() {
+ return preserveDuplicates;
+ }
+
/**
* Learn whether the refid attribute of this element been set.
* @return true if refid is valid.
@@ -307,7 +329,7 @@ public class PathConvert extends Task {
* @throws BuildException if something is invalid.
*/
public void execute() throws BuildException {
- Union savedPath = path;
+ Resources savedPath = path;
String savedPathSep = pathSep; // may be altered in validateSetup
String savedDirSep = dirSep; // may be altered in validateSetup
@@ -335,31 +357,27 @@ public class PathConvert extends Task {
StringBuffer rslt = new StringBuffer();
- // Get the list of path components in canonical form
- String[] elems = path.list();
-
- if (mapper != null) {
- FileNameMapper impl = mapper.getImplementation();
- List ret = new ArrayList();
- for (int i = 0; i < elems.length; ++i) {
- String[] mapped = impl.mapFileName(elems[i]);
- for (int m = 0; mapped != null && m < mapped.length; ++m) {
- ret.add(mapped[m]);
- }
+ ResourceCollection resources = isPreserveDuplicates() ? (ResourceCollection) path : new Union(path);
+ List ret = new ArrayList();
+ FileNameMapper mapperImpl = mapper == null ? new IdentityMapper() : mapper.getImplementation();
+ for (Iterator iter = resources.iterator(); iter.hasNext(); ) {
+ String[] mapped = mapperImpl.mapFileName(String.valueOf(iter.next()));
+ for (int m = 0; mapped != null && m < mapped.length; ++m) {
+ ret.add(mapped[m]);
}
- elems = (String[]) ret.toArray(new String[ret.size()]);
}
- for (int i = 0; i < elems.length; i++) {
- String elem = mapElement(elems[i]); // Apply the path prefix map
+ boolean first = true;
+ for (Iterator mappedIter = ret.iterator(); mappedIter.hasNext(); ) {
+ String elem = mapElement((String) mappedIter.next()); // Apply the path prefix map
// Now convert the path and file separator characters from the
// current os to the target os.
- if (i != 0) {
+ if (first) {
rslt.append(pathSep);
+ first = false;
}
- StringTokenizer stDirectory =
- new StringTokenizer(elem, fromDirSep, true);
+ StringTokenizer stDirectory = new StringTokenizer(elem, fromDirSep, true);
while (stDirectory.hasMoreTokens()) {
String token = stDirectory.nextToken();
@@ -373,8 +391,7 @@ public class PathConvert extends Task {
if (property == null) {
log(value);
} else {
- log("Set property " + property + " = " + value,
- Project.MSG_VERBOSE);
+ log("Set property " + property + " = " + value, Project.MSG_VERBOSE);
getProject().setNewProperty(property, value);
}
}
diff --git a/src/main/org/apache/tools/ant/types/resources/BaseResourceCollectionContainer.java b/src/main/org/apache/tools/ant/types/resources/BaseResourceCollectionContainer.java
index e2e6d42bd..212c5de65 100644
--- a/src/main/org/apache/tools/ant/types/resources/BaseResourceCollectionContainer.java
+++ b/src/main/org/apache/tools/ant/types/resources/BaseResourceCollectionContainer.java
@@ -28,7 +28,6 @@ import java.util.Collections;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.types.DataType;
-import org.apache.tools.ant.types.Resource;
import org.apache.tools.ant.types.ResourceCollection;
/**
@@ -41,6 +40,21 @@ public abstract class BaseResourceCollectionContainer
private Collection coll = null;
private boolean cache = true;
+ /**
+ * Create a new BaseResourceCollectionContainer.
+ */
+ public BaseResourceCollectionContainer() {
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * Create a new BaseResourceCollectionContainer.
+ * @since Ant 1.8
+ */
+ public BaseResourceCollectionContainer(Project project) {
+ setProject(project);
+ }
+
/**
* Set whether to cache collections.
* @param b boolean cache flag.
@@ -159,8 +173,7 @@ public abstract class BaseResourceCollectionContainer
/* now check each Resource in case the child only
lets through files from any children IT may have: */
for (Iterator i = cacheCollection().iterator(); i.hasNext();) {
- Resource r = (Resource) i.next();
- if (r.as(FileProvider.class) == null) {
+ if (!(i.next() instanceof FileProvider)) {
return false;
}
}
@@ -185,7 +198,9 @@ public abstract class BaseResourceCollectionContainer
for (Iterator i = rc.iterator(); i.hasNext();) {
Object o = i.next();
if (o instanceof DataType) {
- pushAndInvokeCircularReferenceCheck((DataType) o, stk, p);
+ stk.push(o);
+ invokeCircularReferenceCheck((DataType) o, stk, p);
+ stk.pop();
}
}
setChecked(true);
diff --git a/src/main/org/apache/tools/ant/types/resources/Resources.java b/src/main/org/apache/tools/ant/types/resources/Resources.java
index ffa0419c0..424c99ab5 100644
--- a/src/main/org/apache/tools/ant/types/resources/Resources.java
+++ b/src/main/org/apache/tools/ant/types/resources/Resources.java
@@ -107,6 +107,19 @@ public class Resources extends DataType implements ResourceCollection {
private Vector rc;
private Collection coll;
+ /**
+ * Create a new Resources.
+ */
+ public Resources() {
+ }
+
+ /**
+ * Create a new Resources.
+ */
+ public Resources(Project project) {
+ setProject(project);
+ }
+
/**
* Add a ResourceCollection.
* @param c the ResourceCollection to add.
@@ -208,7 +221,7 @@ public class Resources extends DataType implements ResourceCollection {
for (Iterator i = getNested().iterator(); i.hasNext();) {
Object o = i.next();
if (o instanceof DataType) {
- pushAndInvokeCircularReferenceCheck((DataType) o, stk, p);
+ invokeCircularReferenceCheck((DataType) o, stk, p);
}
}
setChecked(true);
diff --git a/src/main/org/apache/tools/ant/types/resources/Union.java b/src/main/org/apache/tools/ant/types/resources/Union.java
index c9c3b59c2..a6b82fc66 100644
--- a/src/main/org/apache/tools/ant/types/resources/Union.java
+++ b/src/main/org/apache/tools/ant/types/resources/Union.java
@@ -23,6 +23,7 @@ import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
+import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.Resource;
import org.apache.tools.ant.types.ResourceCollection;
@@ -47,11 +48,29 @@ public class Union extends BaseResourceCollectionContainer {
public Union() {
}
+ /**
+ * Create a new Union.
+ * @param project owning Project
+ */
+ public Union(Project project) {
+ super(project);
+ }
+
/**
* Convenience constructor.
* @param rc the ResourceCollection to add.
*/
public Union(ResourceCollection rc) {
+ this(Project.getProject(rc), rc);
+ }
+
+ /**
+ * Convenience constructor.
+ * @param project owning Project
+ * @param rc the ResourceCollection to add.
+ */
+ public Union(Project project, ResourceCollection rc) {
+ super(project);
add(rc);
}
diff --git a/src/tests/antunit/types/resources/comparators/test.xml b/src/tests/antunit/types/resources/comparators/test.xml
index ea10b3b43..50b367727 100755
--- a/src/tests/antunit/types/resources/comparators/test.xml
+++ b/src/tests/antunit/types/resources/comparators/test.xml
@@ -293,7 +293,7 @@
-
+