From 44bbe5b1395e8cb74fc90cfb4f688c890c941024 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Thu, 6 Dec 2001 16:29:37 +0000 Subject: [PATCH] Speed up : Try to rename the top directory if we are moving complete directory trees. PR: Submitted by: Magesh Umasankar git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270081 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/tools/ant/DirectoryScanner.java | 29 +++++-- .../org/apache/tools/ant/taskdefs/Copy.java | 7 +- .../org/apache/tools/ant/taskdefs/Move.java | 85 ++++++++++++------- 3 files changed, 83 insertions(+), 38 deletions(-) diff --git a/src/main/org/apache/tools/ant/DirectoryScanner.java b/src/main/org/apache/tools/ant/DirectoryScanner.java index 0359dd603..63001ffeb 100644 --- a/src/main/org/apache/tools/ant/DirectoryScanner.java +++ b/src/main/org/apache/tools/ant/DirectoryScanner.java @@ -218,6 +218,11 @@ public class DirectoryScanner implements FileScanner { */ protected boolean isCaseSensitive = true; + /** + * Is everything we've seen so far included? + */ + protected boolean everythingIncluded = true; + /** * Constructor. */ @@ -522,7 +527,7 @@ strLoop: } return true; // String matches against pattern } - + if (patIdxEnd == 0) { 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 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 @@ public class Move extends Copy { 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 @@ public class Move extends Copy { if (destFile.exists()) { if (!destFile.delete()) { - throw new BuildException("Unable to remove existing file " + throw new BuildException("Unable to remove existing file " + destFile); } }