complete directory trees. PR: Submitted by: Magesh Umasankar <umagesh@rediffmail.com> git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270081 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -218,6 +218,11 @@ public class DirectoryScanner implements FileScanner { | |||||
| */ | */ | ||||
| protected boolean isCaseSensitive = true; | protected boolean isCaseSensitive = true; | ||||
| /** | |||||
| * Is everything we've seen so far included? | |||||
| */ | |||||
| protected boolean everythingIncluded = true; | |||||
| /** | /** | ||||
| * Constructor. | * Constructor. | ||||
| */ | */ | ||||
| @@ -522,7 +527,7 @@ strLoop: | |||||
| } | } | ||||
| return true; // String matches against pattern | return true; // String matches against pattern | ||||
| } | } | ||||
| if (patIdxEnd == 0) { | if (patIdxEnd == 0) { | ||||
| return true; // Pattern contains only '*', which matches anything | return true; // Pattern contains only '*', which matches anything | ||||
| } | } | ||||
| @@ -735,6 +740,16 @@ strLoop: | |||||
| } | } | ||||
| } | } | ||||
| /** | |||||
| * 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 @@ strLoop: | |||||
| for (int i=0; i<excl.length; i++) { | for (int i=0; i<excl.length; i++) { | ||||
| if (!couldHoldIncluded(excl[i])) { | if (!couldHoldIncluded(excl[i])) { | ||||
| scandir(new File(basedir, excl[i]), | |||||
| scandir(new File(basedir, excl[i]), | |||||
| excl[i]+File.separator, false); | excl[i]+File.separator, false); | ||||
| } | } | ||||
| } | } | ||||
| for (int i=0; i<notIncl.length; i++) { | for (int i=0; i<notIncl.length; i++) { | ||||
| if (!couldHoldIncluded(notIncl[i])) { | if (!couldHoldIncluded(notIncl[i])) { | ||||
| scandir(new File(basedir, notIncl[i]), | |||||
| scandir(new File(basedir, notIncl[i]), | |||||
| notIncl[i]+File.separator, false); | notIncl[i]+File.separator, false); | ||||
| } | } | ||||
| } | } | ||||
| @@ -843,7 +858,7 @@ strLoop: | |||||
| * two reasons are mentioned in the API docs for File.list | * two reasons are mentioned in the API docs for File.list | ||||
| * (1) dir is not a directory. This is impossible as | * (1) dir is not a directory. This is impossible as | ||||
| * we wouldn't get here in this case. | * 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???) | * then???) | ||||
| */ | */ | ||||
| throw new BuildException("IO error scanning directory " | throw new BuildException("IO error scanning directory " | ||||
| @@ -861,12 +876,14 @@ strLoop: | |||||
| scandir(file, name+File.separator, fast); | scandir(file, name+File.separator, fast); | ||||
| } | } | ||||
| } else { | } else { | ||||
| everythingIncluded = false; | |||||
| dirsExcluded.addElement(name); | dirsExcluded.addElement(name); | ||||
| if (fast && couldHoldIncluded(name)) { | if (fast && couldHoldIncluded(name)) { | ||||
| scandir(file, name+File.separator, fast); | scandir(file, name+File.separator, fast); | ||||
| } | } | ||||
| } | } | ||||
| } else { | } else { | ||||
| everythingIncluded = false; | |||||
| dirsNotIncluded.addElement(name); | dirsNotIncluded.addElement(name); | ||||
| if (fast && couldHoldIncluded(name)) { | if (fast && couldHoldIncluded(name)) { | ||||
| scandir(file, name+File.separator, fast); | scandir(file, name+File.separator, fast); | ||||
| @@ -880,9 +897,11 @@ strLoop: | |||||
| if (!isExcluded(name)) { | if (!isExcluded(name)) { | ||||
| filesIncluded.addElement(name); | filesIncluded.addElement(name); | ||||
| } else { | } else { | ||||
| everythingIncluded = false; | |||||
| filesExcluded.addElement(name); | filesExcluded.addElement(name); | ||||
| } | } | ||||
| } else { | } else { | ||||
| everythingIncluded = false; | |||||
| filesNotIncluded.addElement(name); | filesNotIncluded.addElement(name); | ||||
| } | } | ||||
| } | } | ||||
| @@ -104,6 +104,7 @@ public class Copy extends Task { | |||||
| protected Hashtable fileCopyMap = new Hashtable(); | protected Hashtable fileCopyMap = new Hashtable(); | ||||
| protected Hashtable dirCopyMap = new Hashtable(); | protected Hashtable dirCopyMap = new Hashtable(); | ||||
| protected Hashtable completeDirMap = new Hashtable(); | |||||
| protected Mapper mapperElement = null; | protected Mapper mapperElement = null; | ||||
| private Vector filterSets = new Vector(); | private Vector filterSets = new Vector(); | ||||
| @@ -270,7 +271,11 @@ public class Copy extends Task { | |||||
| String[] srcFiles = ds.getIncludedFiles(); | String[] srcFiles = ds.getIncludedFiles(); | ||||
| String[] srcDirs = ds.getIncludedDirectories(); | String[] srcDirs = ds.getIncludedDirectories(); | ||||
| boolean isEverythingIncluded = ds.isEverythingIncluded(); | |||||
| if (isEverythingIncluded | |||||
| && !flatten && mapperElement == null) { | |||||
| completeDirMap.put(fromDir, destDir); | |||||
| } | |||||
| scan(fromDir, destDir, srcFiles, srcDirs); | scan(fromDir, destDir, srcFiles, srcDirs); | ||||
| } | } | ||||
| @@ -94,6 +94,24 @@ public class Move extends Copy { | |||||
| //************************************************************************ | //************************************************************************ | ||||
| protected void doFileOperations() { | 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 | if (fileCopyMap.size() > 0) { // files to move | ||||
| log("Moving " + fileCopyMap.size() + " files to " + | log("Moving " + fileCopyMap.size() + " files to " + | ||||
| destDir.getAbsolutePath() ); | destDir.getAbsolutePath() ); | ||||
| @@ -110,44 +128,47 @@ public class Move extends Copy { | |||||
| boolean moved = false; | boolean moved = false; | ||||
| File f = new File(fromFile); | 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 { | 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) { | } catch (IOException ioe) { | ||||
| String msg = "Failed to copy " + fromFile + " to " | |||||
| + toFile | |||||
| String msg = "Failed to rename " + fromFile | |||||
| + " to " + toFile | |||||
| + " due to " + ioe.getMessage(); | + " due to " + ioe.getMessage(); | ||||
| throw new BuildException(msg, ioe, location); | 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 @@ public class Move extends Copy { | |||||
| if (destFile.exists()) { | if (destFile.exists()) { | ||||
| if (!destFile.delete()) { | if (!destFile.delete()) { | ||||
| throw new BuildException("Unable to remove existing file " | |||||
| throw new BuildException("Unable to remove existing file " | |||||
| + destFile); | + destFile); | ||||
| } | } | ||||
| } | } | ||||