From b40d79d60a437f163f28f709c54ef95778a89b5f Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Fri, 17 Nov 2000 10:25:09 +0000 Subject: [PATCH] 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 can now be written as 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 --- .../org/apache/tools/ant/taskdefs/Copy.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/Copy.java b/src/main/org/apache/tools/ant/taskdefs/Copy.java index 2560f8846..3bbd5cc73 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Copy.java +++ b/src/main/org/apache/tools/ant/taskdefs/Copy.java @@ -72,6 +72,7 @@ import java.util.*; * copyfile/copydir tasks.

* * @author Glenn McAllister glennm@ca.ibm.com + * @author Stefan Bodewig */ 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();