You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Jerry Huth <je...@Sun.COM> on 2001/01/02 23:39:15 UTC

Small addition/patch for the Copy task

I have a subclass of Copy that does "custom filtering" (i.e. filters
that can be different for each file).  It works OK, but I had to
override the doFileOperations() function, which is a pretty big
function, and copy its code from Copy.java.

However if the Copy class had some notification functions that were
called before and after copying each file, then I could just override
the notification functions and I wouldn't have to copy any code from
Copy.java.

So, I added these notification functions to Copy.java (revision id
1.12) which I've attached.  Is there any chance of getting this change
in the next version of ANT?  Here are the context diffs for my
changes:


RCS file:
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Copy.java,v
retrieving revision 1.12
diff -c -r1.12 Copy.java
*** Copy.java	2000/12/15 09:49:30	1.12
--- Copy.java	2001/01/02 22:14:42
***************
*** 311,317 ****
  
      /**
       * Actually does the file (and possibly empty directory) copies.
!      * This is a good method for subclasses to override.
       */
      protected void doFileOperations() {
          if (fileCopyMap.size() > 0) {
--- 311,318 ----
  
      /**
       * Actually does the file (and possibly empty directory) copies.
!      * This is a good method for subclasses to override if overriding
!      * preCopyNotify() and postCopyNotify() is not sufficient.
       */
      protected void doFileOperations() {
          if (fileCopyMap.size() > 0) {
***************
*** 330,335 ****
--- 331,337 ----
                  }
  
                  try {
+                     preCopyNotify( fromFile, toFile, filtering, forceOverwrite) ;
                      log("Copying " + fromFile + " to " + toFile, verbosity);
                      
                      project.copyFile(fromFile, 
***************
*** 337,343 ****
--- 339,348 ----
                                       filtering, 
                                       forceOverwrite,
                                       preserveLastModified);
+ 
+                     postCopyNotify( fromFile, toFile, filtering, forceOverwrite) ;
                  } catch (IOException ioe) {
+                     postCopyNotify( fromFile, toFile, filtering, forceOverwrite) ;
                      String msg = "Failed to copy " + fromFile + " to " + toFile
                          + " due to " + ioe.getMessage();
                      throw new BuildException(msg, ioe, location);
***************
*** 364,368 ****
--- 369,385 ----
              }
          }
      }
+ 
+     /**
+      * This is called just before a file is copied.
+      */
+     protected void preCopyNotify( String fromFile, String toFile, 
+                                   boolean filtering, boolean forceOverwrite) {}
+ 
+     /**
+      * This is called just after a file is copied.
+      */
+     protected void postCopyNotify( String fromFile, String toFile, 
+                                    boolean filtering, boolean forceOverwrite) {}
  
  }