On Tue, 7 Aug 2001, Conor MacNeill <[EMAIL PROTECTED]> wrote:

>Or perhaps we should just try to make <move> smarter
>when doing dir - dir moves. Thoughts?


Here is what I have in mind:

If the user wishes to perform a direct straighforward 
move, We let the user specify something along the lines 
of:

    <target name="all">
        <move file="srcdir" tofile="destdir">
        </move>
    </target>

First of all, we let the user use file, tofile and todir to move directories 
too.

Note that the user must not override any of the other
default options, nor use FileSets.  Further, we caution
the user that s/he must use FileSet (as it is now) if 
move across volumes is gonna be attempted.

I suggest we do something along these lines.  If you feel
this is worthwhile to pursue let me know and I will 
clean up the code, document it, etc.

Scratchpad Patch to Move.java is attached.

Cheers,
Magesh


_________________________________________________________
For Rs. 2,000,000 worth of Aptech scholarships click below
http://clients.rediff.com/clients/aptechsch/index.htm

Index: Move.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Move.java,v
retrieving revision 1.7
diff -u -w -r1.7 Move.java
--- Move.java   2001/08/07 06:59:35     1.7
+++ Move.java   2001/08/11 00:34:36
@@ -79,6 +79,7 @@
  * @author <a href="mailto:[EMAIL PROTECTED]">Magesh Umasankar</a>
  */
 public class Move extends Copy {
+    protected boolean attemptDirRename = false;
 
     public Move() {
         super();
@@ -89,6 +90,42 @@
 //  protected and private methods
 //************************************************************************
 
+    /**
+     * Ensure we have a consistent and legal set of attributes, and set
+     * any internal flags necessary based on different combinations
+     * of attributes.
+     */
+    protected void validateAttributes() throws BuildException {
+        if (file == null && filesets.size() == 0) {
+            throw new BuildException("Specify at least one source - a file or 
a fileset.");
+        }
+
+        if (destFile != null && destDir != null) {
+            throw new BuildException("Only one of destfile and destdir may be 
set.");
+        }
+
+        if (destFile == null && destDir == null) {
+            throw new BuildException("One of destfile or destdir must be 
set.");
+        }
+
+        if (file != null && file.exists() && file.isDirectory()) {
+            if (filtering || !forceOverwrite || flatten || !includeEmpty ) {
+                throw new BuildException("To move directories when using" +
+                    " other non-default options, please use FileSet.");
+            }
+            attemptDirRename = true;
+        }
+
+        if (destFile != null && filesets.size() > 0) {
+            throw new BuildException("Cannot concatenate multple files into a 
single file.");
+        }
+
+        if (destFile != null) {
+            destDir = new File(destFile.getParent());   // be 1.1 friendly
+        }
+
+    }
+
     protected void doFileOperations() {
         if (fileCopyMap.size() > 0) {   // files to move
             log("Moving " + fileCopyMap.size() + " files to " +
@@ -120,6 +157,10 @@
                 }
 
                 if (!moved) {
+                    if (attemptDirRename) {
+                        throw new BuildException("To move directories across" +
+                            " volumes, please use FileSet.");
+                    }
                     try {
                         log("Moving " + fromFile + " to " + toFile, verbosity);
                     

Reply via email to