Browse Source

Speed up <move>: Try to rename the top directory if we are moving

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-ffa450edef68
master
Stefan Bodewig 23 years ago
parent
commit
44bbe5b139
3 changed files with 83 additions and 38 deletions
  1. +24
    -5
      src/main/org/apache/tools/ant/DirectoryScanner.java
  2. +6
    -1
      src/main/org/apache/tools/ant/taskdefs/Copy.java
  3. +53
    -32
      src/main/org/apache/tools/ant/taskdefs/Move.java

+ 24
- 5
src/main/org/apache/tools/ant/DirectoryScanner.java View File

@@ -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<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 @@ strLoop:
* 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 @@ strLoop:
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 @@ strLoop:
if (!isExcluded(name)) {
filesIncluded.addElement(name);
} else {
everythingIncluded = false;
filesExcluded.addElement(name);
}
} else {
everythingIncluded = false;
filesNotIncluded.addElement(name);
}
}


+ 6
- 1
src/main/org/apache/tools/ant/taskdefs/Copy.java View File

@@ -104,6 +104,7 @@ public class Copy extends Task {

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 @@ public class Copy extends Task {

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);
}



+ 53
- 32
src/main/org/apache/tools/ant/taskdefs/Move.java View File

@@ -94,6 +94,24 @@ public class Move extends Copy {
//************************************************************************

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 @@ 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);
}
}


Loading…
Cancel
Save