ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs Copy.java Move.java
Date Sun, 09 Dec 2001 01:07:01 GMT
bodewig     01/12/06 08:29:37

  Modified:    src/main/org/apache/tools/ant DirectoryScanner.java
               src/main/org/apache/tools/ant/taskdefs Copy.java Move.java
  Log:
  Speed up <move>: Try to rename the top directory if we are moving
  complete directory trees.
  
  Submitted by:	Magesh Umasankar <umagesh@rediffmail.com>
  
  Revision  Changes    Path
  1.19      +24 -5     jakarta-ant/src/main/org/apache/tools/ant/DirectoryScanner.java
  
  Index: DirectoryScanner.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/DirectoryScanner.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- DirectoryScanner.java	2001/11/21 07:31:01	1.18
  +++ DirectoryScanner.java	2001/12/06 16:29:37	1.19
  @@ -219,6 +219,11 @@
       protected boolean isCaseSensitive = true;
   
       /**
  +     * Is everything we've seen so far included?
  +     */
  +    protected boolean everythingIncluded = true;
  +
  +    /**
        * Constructor.
        */
       public DirectoryScanner() {
  @@ -522,7 +527,7 @@
               }
               return true; // String matches against pattern
           }
  -        
  +
           if (patIdxEnd == 0) {
               return true; // Pattern contains only '*', which matches anything
           }
  @@ -735,6 +740,16 @@
           }
       }
   
  +    /**
  +     * Has the scanner excluded or omitted any files or directories it
  +     * came accross?
  +     *
  +     * @return true if all files and directories that have been found,
  +     * are included.
  +     */
  +    public boolean isEverythingIncluded() {
  +        return everythingIncluded;
  +    }
   
   
       /**
  @@ -802,14 +817,14 @@
   
           for (int i=0; i<excl.length; i++) {
               if (!couldHoldIncluded(excl[i])) {
  -                scandir(new File(basedir, excl[i]), 
  +                scandir(new File(basedir, excl[i]),
                           excl[i]+File.separator, false);
               }
           }
  -        
  +
           for (int i=0; i<notIncl.length; i++) {
               if (!couldHoldIncluded(notIncl[i])) {
  -                scandir(new File(basedir, notIncl[i]), 
  +                scandir(new File(basedir, notIncl[i]),
                           notIncl[i]+File.separator, false);
               }
           }
  @@ -843,7 +858,7 @@
                * two reasons are mentioned in the API docs for File.list
                * (1) dir is not a directory. This is impossible as
                *     we wouldn't get here in this case.
  -             * (2) an IO error occurred (why doesn't it throw an exception 
  +             * (2) an IO error occurred (why doesn't it throw an exception
                *     then???)
                */
               throw new BuildException("IO error scanning directory "
  @@ -861,12 +876,14 @@
                               scandir(file, name+File.separator, fast);
                           }
                       } else {
  +                        everythingIncluded = false;
                           dirsExcluded.addElement(name);
                           if (fast && couldHoldIncluded(name)) {
                               scandir(file, name+File.separator, fast);
                           }
                       }
                   } else {
  +                    everythingIncluded = false;
                       dirsNotIncluded.addElement(name);
                       if (fast && couldHoldIncluded(name)) {
                           scandir(file, name+File.separator, fast);
  @@ -880,9 +897,11 @@
                       if (!isExcluded(name)) {
                           filesIncluded.addElement(name);
                       } else {
  +                        everythingIncluded = false;
                           filesExcluded.addElement(name);
                       }
                   } else {
  +                    everythingIncluded = false;
                       filesNotIncluded.addElement(name);
                   }
               }
  
  
  
  1.25      +6 -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.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- Copy.java	2001/12/05 20:22:19	1.24
  +++ Copy.java	2001/12/06 16:29:37	1.25
  @@ -104,6 +104,7 @@
   
       protected Hashtable fileCopyMap = new Hashtable();
       protected Hashtable dirCopyMap = new Hashtable();
  +    protected Hashtable completeDirMap = new Hashtable();
   
       protected Mapper mapperElement = null;
       private Vector filterSets = new Vector();
  @@ -270,7 +271,11 @@
   
               String[] srcFiles = ds.getIncludedFiles();
               String[] srcDirs = ds.getIncludedDirectories();
  -
  +            boolean isEverythingIncluded = ds.isEverythingIncluded();
  +            if (isEverythingIncluded
  +                && !flatten && mapperElement == null) {
  +                completeDirMap.put(fromDir, destDir);
  +            }
               scan(fromDir, destDir, srcFiles, srcDirs);
           }
   
  
  
  
  1.10      +53 -32    jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Move.java
  
  Index: Move.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Move.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- Move.java	2001/10/28 21:26:29	1.9
  +++ Move.java	2001/12/06 16:29:37	1.10
  @@ -94,6 +94,24 @@
   //************************************************************************
   
       protected void doFileOperations() {
  +        //Attempt complete directory renames, if any, first.
  +        if (completeDirMap.size() > 0) {
  +            Enumeration e = completeDirMap.keys();
  +            while (e.hasMoreElements()) {
  +                File fromDir = (File) e.nextElement();
  +                File toDir = (File) completeDirMap.get(fromDir);
  +                try {
  +                    log("Attempting to rename dir: " + fromDir +
  +                        " to " + toDir, verbosity);
  +                    renameFile(fromDir, toDir, filtering, forceOverwrite);
  +                } catch (IOException ioe) {
  +                    String msg = "Failed to rename dir " + fromDir
  +                        + " to " + toDir
  +                        + " due to " + ioe.getMessage();
  +                    throw new BuildException(msg, ioe, location);
  +                }
  +            }
  +        }
           if (fileCopyMap.size() > 0) {   // files to move
               log("Moving " + fileCopyMap.size() + " files to " +
                   destDir.getAbsolutePath() );
  @@ -110,44 +128,47 @@
   
                   boolean moved = false;
                   File f = new File(fromFile);
  -                File d = new File(toFile);
   
  -                try {
  -                    log("Attempting to rename: " + fromFile +
  -                        " to " + toFile, verbosity);
  -                    moved = renameFile(f, d, filtering, forceOverwrite);
  -                } catch (IOException ioe) {
  -                    String msg = "Failed to rename " + fromFile 
  -                        + " to " + toFile
  -                        + " due to " + ioe.getMessage();
  -                    throw new BuildException(msg, ioe, location);
  -                }
  +                if (f.exists()) { //Is this file still available to be moved?
  +                    File d = new File(toFile);
   
  -                if (!moved) {
                       try {
  -                        log("Moving " + fromFile + " to " + toFile, verbosity);
  -                    
  -                        FilterSetCollection executionFilters = new FilterSetCollection();
  -                        if (filtering) {
  -                            executionFilters.addFilterSet(project.getGlobalFilterSet());
  -                        }
  -                        for (Enumeration filterEnum = getFilterSets().elements(); filterEnum.hasMoreElements();)
{
  -                            executionFilters.addFilterSet((FilterSet)filterEnum.nextElement());
  -                        }
  -                        getFileUtils().copyFile(f, d, executionFilters,
  -                                                forceOverwrite);
  -                        
  -                        f = new File(fromFile);
  -                        if (!f.delete()) {
  -                            throw new BuildException("Unable to delete file " 
  -                                                     + f.getAbsolutePath());
  -                        }
  +                        log("Attempting to rename: " + fromFile +
  +                            " to " + toFile, verbosity);
  +                        moved = renameFile(f, d, filtering, forceOverwrite);
                       } catch (IOException ioe) {
  -                        String msg = "Failed to copy " + fromFile + " to " 
  -                            + toFile
  +                        String msg = "Failed to rename " + fromFile
  +                            + " to " + toFile
                               + " due to " + ioe.getMessage();
                           throw new BuildException(msg, ioe, location);
                       }
  +
  +                    if (!moved) {
  +                        try {
  +                            log("Moving " + fromFile + " to " + toFile, verbosity);
  +
  +                            FilterSetCollection executionFilters = new FilterSetCollection();
  +                            if (filtering) {
  +                                executionFilters.addFilterSet(project.getGlobalFilterSet());
  +                            }
  +                            for (Enumeration filterEnum = getFilterSets().elements(); filterEnum.hasMoreElements();)
{
  +                                executionFilters.addFilterSet((FilterSet)filterEnum.nextElement());
  +                            }
  +                            getFileUtils().copyFile(f, d, executionFilters,
  +                                                    forceOverwrite);
  +
  +                            f = new File(fromFile);
  +                            if (!f.delete()) {
  +                                throw new BuildException("Unable to delete file "
  +                                                         + f.getAbsolutePath());
  +                            }
  +                        } catch (IOException ioe) {
  +                            String msg = "Failed to copy " + fromFile + " to "
  +                                + toFile
  +                                + " due to " + ioe.getMessage();
  +                            throw new BuildException(msg, ioe, location);
  +                        }
  +                    }
                   }
               }
           }
  @@ -255,7 +276,7 @@
   
               if (destFile.exists()) {
                   if (!destFile.delete()) {
  -                    throw new BuildException("Unable to remove existing file " 
  +                    throw new BuildException("Unable to remove existing file "
                                                + destFile);
                   }
               }
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>



--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message