in src/main/org/apache/tools/ant/taskdefs/Move.java [107:203]
protected void doFileOperations() {
//Attempt complete directory renames, if any, first.
if (completeDirMap.size() > 0) {
for (Map.Entry<File, File> entry : completeDirMap.entrySet()) {
File fromDir = entry.getKey();
File toDir = entry.getValue();
boolean renamed = false;
try {
log("Attempting to rename dir: " + fromDir + " to " + toDir, verbosity);
renamed = 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, getLocation());
}
if (!renamed) {
FileSet fs = new FileSet();
fs.setProject(getProject());
fs.setDir(fromDir);
addFileset(fs);
DirectoryScanner ds = fs.getDirectoryScanner(getProject());
scan(fromDir, toDir, ds.getIncludedFiles(), ds.getIncludedDirectories());
}
}
}
int moveCount = fileCopyMap.size();
if (moveCount > 0) { // files to move
log("Moving " + moveCount + " file" + ((moveCount == 1) ? "" : "s")
+ " to " + destDir.getAbsolutePath());
for (Map.Entry<String, String[]> entry : fileCopyMap.entrySet()) {
String fromFile = entry.getKey();
File f = new File(fromFile);
boolean selfMove = false;
if (f.exists()) { //Is this file still available to be moved?
String[] toFiles = entry.getValue();
for (int i = 0; i < toFiles.length; i++) {
String toFile = toFiles[i];
if (fromFile.equals(toFile)) {
log("Skipping self-move of " + fromFile, verbosity);
selfMove = true;
// if this is the last time through the loop then
// move will not occur, but that's what we want
continue;
}
File d = new File(toFile);
if ((i + 1) == toFiles.length && !selfMove) {
// Only try to move if this is the last mapped file
// and one of the mappings isn't to itself
moveFile(f, d, filtering, forceOverwrite);
} else {
copyFile(f, d, filtering, forceOverwrite);
}
}
}
}
}
if (includeEmpty) {
int createCount = 0;
for (Map.Entry<String, String[]> entry : dirCopyMap.entrySet()) {
String fromDirName = entry.getKey();
boolean selfMove = false;
for (String toDirName : entry.getValue()) {
if (fromDirName.equals(toDirName)) {
log("Skipping self-move of " + fromDirName, verbosity);
selfMove = true;
continue;
}
File d = new File(toDirName);
if (!d.exists()) {
if (!d.mkdirs() && !d.exists()) {
log("Unable to create directory "
+ d.getAbsolutePath(), Project.MSG_ERR);
} else {
createCount++;
}
}
}
File fromDir = new File(fromDirName);
if (!selfMove && okToDelete(fromDir)) {
deleteDir(fromDir);
}
}
if (createCount > 0) {
log("Moved " + dirCopyMap.size()
+ " empty director"
+ (dirCopyMap.size() == 1 ? "y" : "ies")
+ " to " + createCount
+ " empty director"
+ (createCount == 1 ? "y" : "ies") + " under "
+ destDir.getAbsolutePath());
}
}
}