Browse Source

pathconvert preserveduplicates

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@734864 13f79535-47bb-0310-9956-ffa450edef68
master
Matthew Jason Benson 16 years ago
parent
commit
b7858a9322
5 changed files with 94 additions and 30 deletions
  1. +41
    -24
      src/main/org/apache/tools/ant/taskdefs/PathConvert.java
  2. +19
    -4
      src/main/org/apache/tools/ant/types/resources/BaseResourceCollectionContainer.java
  3. +14
    -1
      src/main/org/apache/tools/ant/types/resources/Resources.java
  4. +19
    -0
      src/main/org/apache/tools/ant/types/resources/Union.java
  5. +1
    -1
      src/tests/antunit/types/resources/comparators/test.xml

+ 41
- 24
src/main/org/apache/tools/ant/taskdefs/PathConvert.java View File

@@ -18,6 +18,7 @@
package org.apache.tools.ant.taskdefs; package org.apache.tools.ant.taskdefs;


import java.io.File; import java.io.File;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Vector; import java.util.Vector;
import java.util.ArrayList; 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.Reference;
import org.apache.tools.ant.types.ResourceCollection; import org.apache.tools.ant.types.ResourceCollection;
import org.apache.tools.ant.types.EnumeratedAttribute; 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.types.resources.Union;
import org.apache.tools.ant.util.FileNameMapper; import org.apache.tools.ant.util.FileNameMapper;
import org.apache.tools.ant.util.IdentityMapper;


/** /**
* Converts path and classpath information to a specific target OS * Converts path and classpath information to a specific target OS
@@ -52,7 +55,7 @@ public class PathConvert extends Task {
/** /**
* Path to be converted * Path to be converted
*/ */
private Union path = null;
private Resources path = null;
/** /**
* Reference to path/fileset to convert * Reference to path/fileset to convert
*/ */
@@ -89,6 +92,8 @@ public class PathConvert extends Task {
/** Filename mapper */ /** Filename mapper */
private Mapper mapper = null; private Mapper mapper = null;


private boolean preserveDuplicates;

/** /**
* Construct a new instance of the PathConvert task. * Construct a new instance of the PathConvert task.
*/ */
@@ -191,10 +196,9 @@ public class PathConvert extends Task {
getPath().add(rc); getPath().add(rc);
} }


private synchronized Union getPath() {
private synchronized Resources getPath() {
if (path == null) { if (path == null) {
path = new Union();
path.setProject(getProject());
path = new Resources(getProject());
} }
return path; return path;
} }
@@ -294,6 +298,24 @@ public class PathConvert extends Task {
dirSep = sep; 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. * Learn whether the refid attribute of this element been set.
* @return true if refid is valid. * @return true if refid is valid.
@@ -307,7 +329,7 @@ public class PathConvert extends Task {
* @throws BuildException if something is invalid. * @throws BuildException if something is invalid.
*/ */
public void execute() throws BuildException { public void execute() throws BuildException {
Union savedPath = path;
Resources savedPath = path;
String savedPathSep = pathSep; // may be altered in validateSetup String savedPathSep = pathSep; // may be altered in validateSetup
String savedDirSep = dirSep; // 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(); 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 // Now convert the path and file separator characters from the
// current os to the target os. // current os to the target os.


if (i != 0) {
if (first) {
rslt.append(pathSep); rslt.append(pathSep);
first = false;
} }
StringTokenizer stDirectory =
new StringTokenizer(elem, fromDirSep, true);
StringTokenizer stDirectory = new StringTokenizer(elem, fromDirSep, true);


while (stDirectory.hasMoreTokens()) { while (stDirectory.hasMoreTokens()) {
String token = stDirectory.nextToken(); String token = stDirectory.nextToken();
@@ -373,8 +391,7 @@ public class PathConvert extends Task {
if (property == null) { if (property == null) {
log(value); log(value);
} else { } else {
log("Set property " + property + " = " + value,
Project.MSG_VERBOSE);
log("Set property " + property + " = " + value, Project.MSG_VERBOSE);
getProject().setNewProperty(property, value); getProject().setNewProperty(property, value);
} }
} }


+ 19
- 4
src/main/org/apache/tools/ant/types/resources/BaseResourceCollectionContainer.java View File

@@ -28,7 +28,6 @@ import java.util.Collections;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.types.DataType; import org.apache.tools.ant.types.DataType;
import org.apache.tools.ant.types.Resource;
import org.apache.tools.ant.types.ResourceCollection; import org.apache.tools.ant.types.ResourceCollection;


/** /**
@@ -41,6 +40,21 @@ public abstract class BaseResourceCollectionContainer
private Collection coll = null; private Collection coll = null;
private boolean cache = true; 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. * Set whether to cache collections.
* @param b boolean cache flag. * @param b boolean cache flag.
@@ -159,8 +173,7 @@ public abstract class BaseResourceCollectionContainer
/* now check each Resource in case the child only /* now check each Resource in case the child only
lets through files from any children IT may have: */ lets through files from any children IT may have: */
for (Iterator i = cacheCollection().iterator(); i.hasNext();) { 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; return false;
} }
} }
@@ -185,7 +198,9 @@ public abstract class BaseResourceCollectionContainer
for (Iterator i = rc.iterator(); i.hasNext();) { for (Iterator i = rc.iterator(); i.hasNext();) {
Object o = i.next(); Object o = i.next();
if (o instanceof DataType) { if (o instanceof DataType) {
pushAndInvokeCircularReferenceCheck((DataType) o, stk, p);
stk.push(o);
invokeCircularReferenceCheck((DataType) o, stk, p);
stk.pop();
} }
} }
setChecked(true); setChecked(true);


+ 14
- 1
src/main/org/apache/tools/ant/types/resources/Resources.java View File

@@ -107,6 +107,19 @@ public class Resources extends DataType implements ResourceCollection {
private Vector rc; private Vector rc;
private Collection coll; private Collection coll;


/**
* Create a new Resources.
*/
public Resources() {
}

/**
* Create a new Resources.
*/
public Resources(Project project) {
setProject(project);
}

/** /**
* Add a ResourceCollection. * Add a ResourceCollection.
* @param c the ResourceCollection to add. * @param c the ResourceCollection to add.
@@ -208,7 +221,7 @@ public class Resources extends DataType implements ResourceCollection {
for (Iterator i = getNested().iterator(); i.hasNext();) { for (Iterator i = getNested().iterator(); i.hasNext();) {
Object o = i.next(); Object o = i.next();
if (o instanceof DataType) { if (o instanceof DataType) {
pushAndInvokeCircularReferenceCheck((DataType) o, stk, p);
invokeCircularReferenceCheck((DataType) o, stk, p);
} }
} }
setChecked(true); setChecked(true);


+ 19
- 0
src/main/org/apache/tools/ant/types/resources/Union.java View File

@@ -23,6 +23,7 @@ import java.util.Iterator;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;


import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.Resource; import org.apache.tools.ant.types.Resource;
import org.apache.tools.ant.types.ResourceCollection; import org.apache.tools.ant.types.ResourceCollection;


@@ -47,11 +48,29 @@ public class Union extends BaseResourceCollectionContainer {
public Union() { public Union() {
} }


/**
* Create a new Union.
* @param project owning Project
*/
public Union(Project project) {
super(project);
}

/** /**
* Convenience constructor. * Convenience constructor.
* @param rc the ResourceCollection to add. * @param rc the ResourceCollection to add.
*/ */
public Union(ResourceCollection rc) { 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); add(rc);
} }




+ 1
- 1
src/tests/antunit/types/resources/comparators/test.xml View File

@@ -293,7 +293,7 @@
<resourcecount refid="testEquals" count="3" /> <resourcecount refid="testEquals" count="3" />
</au:assertTrue> </au:assertTrue>


<pathconvert refid="testEquals" property="testEquals" pathsep="">
<pathconvert refid="testEquals" property="testEquals" pathsep="" preserveduplicates="true">
<mergemapper to="X" /> <mergemapper to="X" />
</pathconvert> </pathconvert>




Loading…
Cancel
Save