bodewig 00/11/17 02:25:10
Modified: src/main/org/apache/tools/ant/taskdefs Copy.java
Log:
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.
Revision Changes Path
1.9 +18 -1
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Copy.java
Index: Copy.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Copy.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- Copy.java 2000/11/16 08:59:26 1.8
+++ Copy.java 2000/11/17 10:25:09 1.9
@@ -72,6 +72,7 @@
* copyfile/copydir tasks.</p>
*
* @author Glenn McAllister <a href="mailto:[EMAIL PROTECTED]">[EMAIL
PROTECTED]</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Stefan Bodewig</a>
*/
public class Copy extends Task {
protected File file = null; // the source file
@@ -88,6 +89,8 @@
protected Hashtable fileCopyMap = new Hashtable();
protected Hashtable dirCopyMap = new Hashtable();
+ protected Mapper mapperElement = null;
+
/**
* Sets a single source file to copy.
*/
@@ -160,6 +163,18 @@
}
/**
+ * 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.
*/
public void execute() throws BuildException {
@@ -246,7 +261,9 @@
*/
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();