cvs commit: ant/src/main/org/apache/tools/ant/taskdefs Copy.java Move.java

2003-05-19 Thread bodewig
bodewig 2003/05/19 07:43:17

  Modified:src/main/org/apache/tools/ant/taskdefs Copy.java Move.java
  Log:
  Don't remove basedirectories of filesets that just happen to be
  matched completely.
  PR: 18886
  
  Revision  ChangesPath
  1.56  +3 -2  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.55
  retrieving revision 1.56
  diff -u -r1.55 -r1.56
  --- Copy.java 28 Mar 2003 08:06:53 -  1.55
  +++ Copy.java 19 May 2003 14:43:17 -  1.56
  @@ -391,7 +391,8 @@
   
   String[] srcFiles = ds.getIncludedFiles();
   String[] srcDirs = ds.getIncludedDirectories();
  -boolean isEverythingIncluded = ds.isEverythingIncluded();
  +boolean isEverythingIncluded = ds.isEverythingIncluded()
  + (!fs.hasSelectors()  !fs.hasPatterns());
   if (isEverythingIncluded
!flatten  mapperElement == null) {
   completeDirMap.put(fromDir, destDir);
  
  
  
  1.34  +1 -66 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.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- Move.java 27 Mar 2003 16:32:18 -  1.33
  +++ Move.java 19 May 2003 14:43:17 -  1.34
  @@ -213,71 +213,6 @@
   + destDir.getAbsolutePath());
   }
   }
  -
  -if (filesets.size()  0) {
  -Enumeration e = filesets.elements();
  -while (e.hasMoreElements()) {
  -FileSet fs = (FileSet) e.nextElement();
  -File dir = fs.getDir(getProject());
  -
  -if (okToDelete(dir)) {
  -deleteDir(dir);
  -}
  -}
  -}
  -}
  -
  -/**
  - * 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());
  -}
   }
   
   /**
  
  
  


Re: cvs commit: ant/src/main/org/apache/tools/ant/taskdefs Copy.java Move.java

2003-05-19 Thread Stefan Bodewig
On 19 May 2003, [EMAIL PROTECTED] wrote:

   Don't remove basedirectories of filesets that just happen to be
   matched completely.

This introduces a backwards incompatibility and maybe even
inconsistency, that's why I haven't closed the bug report yet.  I'm
asking for feedback here.

The bug report complains about this situation:

move todir=foo
  fileset dir=bar includes=baz/
/move

will remove the directory bar, if there is no other file but baz in
in.  If there happens to be a file zyzzy, the directory is retained.
The complaint is that Ant could know that you didn't intend to move
the whole set - you wouldn't have used includes otherwise.

So now the above will retain the bar directory while

move todir=foo
  fileset dir=bar/
/move

will remove it.

This seems to be consistent with the docs that say 

,
| Move a set of files to a new directory
| 
|   move todir=some/new/dir
| fileset dir=my/src/dir
|   include name=**/*.jar/
|   exclude name=**/ant.jar/
| /fileset
|   /move
`

and not move a complete directory tree if all files are included.

Stefan


cvs commit: ant/src/main/org/apache/tools/ant/taskdefs Copy.java Move.java

2003-05-19 Thread bodewig
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  ChangesPath
  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 -  1.378
  +++ build.xml 19 May 2003 15:21:14 -  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 -  1.34
  +++ Move.java 19 May 2003 15:21:15 -  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());
   }
   }