FileDocCategorySizeDatePackage
Copydir.javaAPI DocApache Ant 1.705189Wed Dec 13 06:16:22 GMT 2006org.apache.tools.ant.taskdefs

Copydir

public class Copydir extends MatchingTask
Copies a directory.
since
Ant 1.1
deprecated
The copydir task is deprecated since Ant 1.2. Use copy instead.

Fields Summary
private File
srcDir
private File
destDir
private boolean
filtering
private boolean
flatten
private boolean
forceOverwrite
private Hashtable
filecopyList
Constructors Summary
Methods Summary
public voidexecute()
Execute the task.

throws
BuildException on error

        log("DEPRECATED - The copydir task is deprecated.  Use copy instead.");

        if (srcDir == null) {
            throw new BuildException("src attribute must be set!",
                                     getLocation());
        }

        if (!srcDir.exists()) {
            throw new BuildException("srcdir " + srcDir.toString()
                                     + " does not exist!", getLocation());
        }

        if (destDir == null) {
            throw new BuildException("The dest attribute must be set.",
                                     getLocation());
        }

        if (srcDir.equals(destDir)) {
            log("Warning: src == dest", Project.MSG_WARN);
        }

        DirectoryScanner ds = super.getDirectoryScanner(srcDir);

        try {
            String[] files = ds.getIncludedFiles();
            scanDir(srcDir, destDir, files);
            if (filecopyList.size() > 0) {
                log("Copying " + filecopyList.size() + " file"
                    + (filecopyList.size() == 1 ? "" : "s")
                    + " to " + destDir.getAbsolutePath());
                Enumeration e = filecopyList.keys();
                while (e.hasMoreElements()) {
                    String fromFile = (String) e.nextElement();
                    String toFile = (String) filecopyList.get(fromFile);
                    try {
                        getProject().copyFile(fromFile, toFile, filtering,
                                         forceOverwrite);
                    } catch (IOException ioe) {
                        String msg = "Failed to copy " + fromFile + " to "
                            + toFile + " due to " + ioe.getMessage();
                        throw new BuildException(msg, ioe, getLocation());
                    }
                }
            }
        } finally {
            filecopyList.clear();
        }
    
private voidscanDir(java.io.File from, java.io.File to, java.lang.String[] files)

        for (int i = 0; i < files.length; i++) {
            String filename = files[i];
            File srcFile = new File(from, filename);
            File destFile;
            if (flatten) {
                destFile = new File(to, new File(filename).getName());
            } else {
                destFile = new File(to, filename);
            }
            if (forceOverwrite
                || (srcFile.lastModified() > destFile.lastModified())) {
                filecopyList.put(srcFile.getAbsolutePath(),
                                 destFile.getAbsolutePath());
            }
        }
    
public voidsetDest(java.io.File dest)
The dest attribute

param
dest the destination file

        destDir = dest;
    
public voidsetFiltering(boolean filter)
The filtering attribute. Default is false.

param
filter if true use filtering

        filtering = filter;
    
public voidsetFlatten(boolean flatten)
The flattening attribute. Default is false.

param
flatten if true use flattening

        this.flatten = flatten;
    
public voidsetForceoverwrite(boolean force)
The forceoverwrite attribute. Default is false.

param
force if true overwrite even if the destination file is newer that the source file

        forceOverwrite = force;
    
public voidsetSrc(java.io.File src)
The src attribute

param
src the source file


                 
        
        srcDir = src;