You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Ja...@rzf.fin-nrw.de on 2005/05/17 11:01:37 UTC

AW: cvs commit: ant/src/main/org/apache/tools/ant/taskdefs CopyPa th.java defaults.properties

>   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

Re: AW: cvs commit: ant/src/main/org/apache/tools/ant/taskdefs CopyPa th.java defaults.properties

Posted by Steve Loughran <st...@apache.org>.
Jan.Materne@rzf.fin-nrw.de wrote:

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

I looked at copy, and felt it was complex enough as it was.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org