diff --git a/docs/index.html b/docs/index.html
index b47ed6a79..23a1ecce9 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -5655,6 +5655,9 @@ supports all attributes of <fileset>
+Deprecated
+This task has been deprecated. Use the move
+task with a glob mapper instead.
Description
Renames files in the srcDir
directory ending with the
fromExtension
string so that they end with the
diff --git a/src/main/org/apache/tools/ant/taskdefs/MatchingTask.java b/src/main/org/apache/tools/ant/taskdefs/MatchingTask.java
index 9db268046..ddf995587 100644
--- a/src/main/org/apache/tools/ant/taskdefs/MatchingTask.java
+++ b/src/main/org/apache/tools/ant/taskdefs/MatchingTask.java
@@ -68,7 +68,7 @@ import java.util.*;
* @author Stefano Mazzocchi stefano@apache.org
* @author Sam Ruby rubys@us.ibm.com
* @author Jon S. Stevens jon@clearink.com
- * @author Stefan Bodewig
+ * @author Stefan Bodewig
*/
public abstract class MatchingTask extends Task {
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/RenameExtensions.java b/src/main/org/apache/tools/ant/taskdefs/optional/RenameExtensions.java
index 651501aaa..08cac8167 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/RenameExtensions.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/RenameExtensions.java
@@ -58,9 +58,6 @@
*
srcDir:
* replace:
*
- *
- * @author dIon Gillard dion@multitask.com.au
- * @version 1.2
*/
package org.apache.tools.ant.taskdefs.optional;
@@ -69,10 +66,13 @@ import java.io.*;
import java.util.*;
import org.apache.tools.ant.*;
import org.apache.tools.ant.taskdefs.*;
+import org.apache.tools.ant.types.Mapper;
/**
*
- * @author dion
+ * @author dIon Gillard dion@multitask.com.au
+ * @author Stefan Bodewig
+ * @version 1.2
*/
public class RenameExtensions extends MatchingTask {
@@ -81,10 +81,14 @@ public class RenameExtensions extends MatchingTask {
private boolean replace = false;
private File srcDir;
+ private Mapper.MapperType globType;
+
/** Creates new RenameExtensions */
public RenameExtensions() {
super();
+ globType = new Mapper.MapperType();
+ globType.setValue("glob");
}
/** store fromExtension **/
@@ -108,8 +112,8 @@ public class RenameExtensions extends MatchingTask {
/**
* Set the source dir to find the files to be renamed.
*/
- public void setSrcDir(String srcDirName) {
- srcDir = project.resolveFile(srcDirName);
+ public void setSrcDir(File srcDir) {
+ this.srcDir = srcDir;
}
/**
@@ -123,50 +127,35 @@ public class RenameExtensions extends MatchingTask {
"attributes must be set!" );
}
- // scan source and dest dirs to build up rename list
- DirectoryScanner ds = getDirectoryScanner(srcDir);
-
- String[] files = ds.getIncludedFiles();
-
- Hashtable renameList = scanDir(srcDir, files);
-
- Enumeration e = renameList.keys();
- File fromFile = null;
- File toFile = null;
- while (e.hasMoreElements()) {
- fromFile = (File)e.nextElement();
- toFile = (File)renameList.get(fromFile);
- if (toFile.exists() && replace) toFile.delete();
- if (!fromFile.renameTo(toFile)) {
- throw new BuildException( "Rename from: '" + fromFile + "' to '" +
- toFile + "' failed." );
- }
- }
-
- }
- private Hashtable scanDir(File srcDir, String[] files) {
- Hashtable list = new Hashtable();
- for (int i = 0; i < files.length; i++) {
- File srcFile = new File(srcDir, files[i]);
- String filename = files[i];
- // if it's a file that ends in the fromExtension, copy to the rename list
- if (filename.toLowerCase().endsWith(fromExtension)) {
- File destFile =
- new File( srcDir,
- filename.substring(0, filename.lastIndexOf(fromExtension)) +
- toExtension );
-
- if (replace || !destFile.exists()) {
- list.put(srcFile, destFile);
- } else {
- log( "Rejecting file: '" + srcFile + "' for rename as " +
- "replace is false and file exists", Project.MSG_VERBOSE );
- }
- } else {
- log( "File '"+ filename + "' doesn't match fromExtension: '" +
- fromExtension + "'", Project.MSG_VERBOSE );
- }
- }
- return list;
+ log("DEPRECATED - The renameext task is deprecated. Use move instead.",
+ Project.MSG_WARN);
+ log("Replace this with:", Project.MSG_INFO);
+ log("",
+ Project.MSG_INFO);
+ log(" ", Project.MSG_INFO);
+ log(" ", Project.MSG_INFO);
+ log("", Project.MSG_INFO);
+ log("using the same patterns on as you\'ve used here",
+ Project.MSG_INFO);
+
+ Move move = (Move)project.createTask("move");
+ move.setOwningTarget(target);
+ move.setTaskName(getTaskName());
+ move.setLocation(getLocation());
+ move.setTodir(srcDir);
+ move.setOverwrite(replace);
+
+ fileset.setDir(srcDir);
+ move.addFileset(fileset);
+
+ Mapper me = move.createMapper();
+ me.setType(globType);
+ me.setFrom("*"+fromExtension);
+ me.setTo("*"+toExtension);
+
+ move.execute();
}
+
}