ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jan.Mate...@rzf.fin-nrw.de
Subject AW: cvs commit: ant/src/main/org/apache/tools/ant/taskdefs CopyPa th.java defaults.properties
Date Tue, 17 May 2005 09:01:37 GMT
>   Added:       src/main/org/apache/tools/ant/taskdefs CopyPath.java
>   Log:
>   utterly without documents or tests, a utility task to 
> extract a path to a dir, by way of a mapper.
>   
>   Index: defaults.properties
>   ===================================================================
>   +copypath=org.apache.tools.ant.taskdefs.CopyPath
>
>   Index: CopyPath.java
>   ===================================================================
>   package org.apache.tools.ant.taskdefs;
>   
>   /**
>    * Copy the contents of a path to a destination, using the mapper of
choice
>    * @since Ant 1.7
>    *
>    * @ant.task category="filesystem"
>    */
>   
>   public class CopyPath extends Task {
>   
>       /**
>        * Set the path to be used when running the Java class.
>        *
>        * @param s an Ant Path object containing the path.
>        */
>       public void setPath(Path s) {
>           createPath().append(s);
>       }
>   
>       /**
>        * This is a very minimal derivative of the nomal copy logic.
>        *
>        * @throws BuildException if something goes wrong with 
> the build.
>        */
>       public void execute() throws BuildException {
>           validateAttributes();
>           String[] sourceFiles = path.list();
>           if (sourceFiles.length == 0) {
>               log("Path is empty", Project.MSG_VERBOSE);
>               return;
>           }
>   
>           for (int sources = 0; sources < sourceFiles.length; 
> sources++) {
>   
>               String sourceFileName = sourceFiles[sources];
>               File sourceFile=new File(sourceFileName);
>               String[] toFiles = (String[]) 
> mapper.mapFileName(sourceFileName);
>   
>               for (int i = 0; i < toFiles.length; i++) {
>                   String destFileName = toFiles[i];
>                   File destFile=new File(destDir,destFileName);
>   
>   
>                   if (sourceFile.equals(destFile)) {
>                       log("Skipping self-copy of " + sourceFileName,
>                               Project.MSG_VERBOSE);
>                       continue;
>                   }
>                   try {
>                       log("Copying " + sourceFile + " to " + destFile,
>                               Project.MSG_VERBOSE);
>   
>                       fileUtils.copyFile(sourceFile, destFile, null,
>                               null, false,
>                               preserveLastModified, null,
>                               null, getProject());
>                   } catch (IOException ioe) {
>                       String msg = "Failed to copy " +
>                               sourceFile +
>                               " to " +
>                               destFile
>                               + " due to " + ioe.getMessage();
>                       if (destFile.exists() && !destFile.delete()) {
>                           msg += " and I couldn't delete the 
> corrupt " + destFile;
>                       }
>                       throw new BuildException(msg, ioe, 
> getLocation());
>                   }
>               }
>   
>           }
>   
>       }
>   }
>   



Mmh, would it make more sense to add nested <path>s to <copy>? See 20635
[1].


Jan

[1] http://issues.apache.org/bugzilla/show_bug.cgi?id=20635

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message