FileDocCategorySizeDatePackage
Deltree.javaAPI DocApache Ant 1.703492Wed Dec 13 06:16:20 GMT 2006org.apache.tools.ant.taskdefs

Deltree

public class Deltree extends org.apache.tools.ant.Task
since
Ant 1.1
deprecated
The deltree task is deprecated since Ant 1.2. Use delete instead.

Fields Summary
private File
dir
Constructors Summary
Methods Summary
public voidexecute()
Do the work.

exception
BuildException if the task is not configured correctly or the tree cannot be removed.

        log("DEPRECATED - The deltree task is deprecated.  "
            + "Use delete instead.");

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

        if (dir.exists()) {
            if (!dir.isDirectory()) {
                if (!dir.delete()) {
                    throw new BuildException("Unable to delete directory "
                                             + dir.getAbsolutePath(),
                                             getLocation());
                }
                return;
            }

            log("Deleting: " + dir.getAbsolutePath());

            try {
                removeDir(dir);
            } catch (IOException ioe) {
                String msg = "Unable to delete " + dir.getAbsolutePath();
                throw new BuildException(msg, getLocation());
            }
        }
    
private voidremoveDir(java.io.File dir)


        // check to make sure that the given dir isn't a symlink
        // the comparison of absolute path and canonical path
        // catches this

        //        if (dir.getCanonicalPath().equals(dir.getAbsolutePath())) {
        // (costin) It will not work if /home/costin is symlink to
        // /da0/home/costin ( taz for example )
        String[] list = dir.list();
        for (int i = 0; i < list.length; i++) {
            String s = list[i];
            File f = new File(dir, s);
            if (f.isDirectory()) {
                removeDir(f);
            } else {
                if (!f.delete()) {
                    throw new BuildException("Unable to delete file "
                                             + f.getAbsolutePath());
                }
            }
        }
        if (!dir.delete()) {
            throw new BuildException("Unable to delete directory "
                                     + dir.getAbsolutePath());
        }
    
public voidsetDir(java.io.File dir)
Set the directory to be deleted

param
dir the root of the tree to be removed.

        this.dir = dir;