Browse Source

Changed the copy task to support a nested mapper.

This adds a lot of power to copy and move, we can drop the optional
RenameExt task for example as

<renamext srcdir="src" destdir="dest" fromextension=".java.keep"
          toextension=".java" replace="true" />

can now be written as

<move todir="dest" overwrite="true">
  <fileset dir="src" />
  <mapper type="glob" from="*.java.keep" to="*.java" />
</move>

but more difficult transformations can be done as well.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268203 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 24 years ago
parent
commit
b40d79d60a
1 changed files with 18 additions and 1 deletions
  1. +18
    -1
      src/main/org/apache/tools/ant/taskdefs/Copy.java

+ 18
- 1
src/main/org/apache/tools/ant/taskdefs/Copy.java View File

@@ -72,6 +72,7 @@ import java.util.*;
* copyfile/copydir tasks.</p>
*
* @author Glenn McAllister <a href="mailto:glennm@ca.ibm.com">glennm@ca.ibm.com</a>
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
*/
public class Copy extends Task {
protected File file = null; // the source file
@@ -88,6 +89,8 @@ public class Copy extends Task {
protected Hashtable fileCopyMap = new Hashtable();
protected Hashtable dirCopyMap = new Hashtable();

protected Mapper mapperElement = null;

/**
* Sets a single source file to copy.
*/
@@ -159,6 +162,18 @@ public class Copy extends Task {
filesets.addElement(set);
}

/**
* Defines the FileNameMapper to use (nested mapper element).
*/
public Mapper createMapper() throws BuildException {
if (mapperElement != null) {
throw new BuildException("Cannot define more than one mapper",
location);
}
mapperElement = new Mapper(project);
return mapperElement;
}

/**
* Performs the copy operation.
*/
@@ -246,7 +261,9 @@ public class Copy extends Task {
*/
protected void scan(File fromDir, File toDir, String[] files, String[] dirs) {
FileNameMapper mapper = null;
if (flatten) {
if (mapperElement != null) {
mapper = mapperElement.getImplementation();
} else if (flatten) {
mapper = new FlatFileNameMapper();
} else {
mapper = new IdentityMapper();


Loading…
Cancel
Save