bodewig 2003/05/19 08:21:15
Modified: . build.xml
src/main/org/apache/tools/ant/taskdefs Copy.java Move.java
Log:
Remove directories explicitly matched with includes.
PR: 11732
Revision Changes Path
1.379 +0 -1 ant/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/ant/build.xml,v
retrieving revision 1.378
retrieving revision 1.379
diff -u -r1.378 -r1.379
--- build.xml 19 May 2003 14:12:15 -0000 1.378
+++ build.xml 19 May 2003 15:21:14 -0000 1.379
@@ -276,7 +276,6 @@
<patternset id="teststhatfail">
<exclude name="${optional.package}/BeanShellScriptTest.java"/>
<exclude name="${ant.package}/taskdefs/ImportTest.java"/>
- <exclude name="${ant.package}/taskdefs/MoveTest.java"/>
</patternset>
<!--
1.57 +0 -0 ant/src/main/org/apache/tools/ant/taskdefs/Copy.java
Index: Copy.java
===================================================================
RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Copy.java,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -r1.56 -r1.57
1.35 +64 -5 ant/src/main/org/apache/tools/ant/taskdefs/Move.java
Index: Move.java
===================================================================
RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Move.java,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -r1.34 -r1.35
--- Move.java 19 May 2003 14:43:17 -0000 1.34
+++ Move.java 19 May 2003 15:21:15 -0000 1.35
@@ -194,24 +194,83 @@
}
if (includeEmpty) {
- Enumeration e = dirCopyMap.elements();
+ Enumeration e = dirCopyMap.keys();
int count = 0;
while (e.hasMoreElements()) {
- File d = new File((String) e.nextElement());
- if (!d.exists()) {
- if (!d.mkdirs()) {
+ String fromDirName = (String) e.nextElement();
+ String toDirName = (String) dirCopyMap.get(fromDirName);
+ File fromDir = new File(fromDirName);
+ File toDir = new File(toDirName);
+ if (!toDir.exists()) {
+ if (!toDir.mkdirs()) {
log("Unable to create directory "
- + d.getAbsolutePath(), Project.MSG_ERR);
+ + toDirName, Project.MSG_ERR);
} else {
count++;
}
}
+ if (okToDelete(fromDir)) {
+ deleteDir(fromDir);
+ }
}
if (count > 0) {
log("Moved " + count + " empty directories to "
+ destDir.getAbsolutePath());
}
+ }
+ }
+
+ /**
+ * Its only ok to delete a directory tree if there are
+ * no files in it.
+ * @return true if a deletion can go ahead
+ */
+ protected boolean okToDelete(File d) {
+ String[] list = d.list();
+ if (list == null) {
+ return false;
+ } // maybe io error?
+
+ for (int i = 0; i < list.length; i++) {
+ String s = list[i];
+ File f = new File(d, s);
+ if (f.isDirectory()) {
+ if (!okToDelete(f)) {
+ return false;
+ }
+ } else {
+ return false; // found a file
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * Go and delete the directory tree.
+ */
+ protected void deleteDir(File d) {
+ String[] list = d.list();
+ if (list == null) {
+ return;
+ } // on an io error list() can return null
+
+ for (int i = 0; i < list.length; i++) {
+ String s = list[i];
+ File f = new File(d, s);
+ if (f.isDirectory()) {
+ deleteDir(f);
+ } else {
+ throw new BuildException("UNEXPECTED ERROR - The file "
+ + f.getAbsolutePath()
+ + " should not exist!");
+ }
+ }
+ log("Deleting directory " + d.getAbsolutePath(), verbosity);
+ if (!d.delete()) {
+ throw new BuildException("Unable to delete directory "
+ + d.getAbsolutePath());
}
}