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

Mkdir

public class Mkdir extends org.apache.tools.ant.Task
Creates a given directory. Creates a directory and any non-existent parent directories, when necessary
since
Ant 1.1
ant.task
category="filesystem"

Fields Summary
private static final int
MKDIR_RETRY_SLEEP_MILLIS
private File
dir
our little directory
Constructors Summary
Methods Summary
public voidexecute()
create the directory and all parents

throws
BuildException if dir is somehow invalid, or creation failed.


                         
         
        if (dir == null) {
            throw new BuildException("dir attribute is required", getLocation());
        }

        if (dir.isFile()) {
            throw new BuildException("Unable to create directory as a file "
                                     + "already exists with that name: "
                                     + dir.getAbsolutePath());
        }

        if (!dir.exists()) {
            boolean result = mkdirs(dir);
            if (!result) {
                String msg = "Directory " + dir.getAbsolutePath()
                    + " creation was not successful for an unknown reason";
                throw new BuildException(msg, getLocation());
            }
            log("Created dir: " + dir.getAbsolutePath());
        } else {
            log("Skipping " + dir.getAbsolutePath()
                + " because it already exists.", Project.MSG_VERBOSE);
        }
    
private booleanmkdirs(java.io.File f)
Attempt to fix possible race condition when creating directories on WinXP. If the mkdirs does not work, wait a little and try again.

        if (!f.mkdirs()) {
            try {
                Thread.sleep(MKDIR_RETRY_SLEEP_MILLIS);
                return f.mkdirs();
            } catch (InterruptedException ex) {
                return f.mkdirs();
            }
        }
        return true;
    
public voidsetDir(java.io.File dir)
the directory to create; required.

param
dir the directory to be made.

        this.dir = dir;