1 18 19 package org.apache.tools.ant.taskdefs; 20 21 import java.io.File ; 22 import org.apache.tools.ant.BuildException; 23 import org.apache.tools.ant.Task; 24 import org.apache.tools.ant.Project; 25 26 35 36 public class Mkdir extends Task { 37 38 private static final int MKDIR_RETRY_SLEEP_MILLIS = 10; 39 42 private File dir; 43 44 48 public void execute() throws BuildException { 49 if (dir == null) { 50 throw new BuildException("dir attribute is required", getLocation()); 51 } 52 53 if (dir.isFile()) { 54 throw new BuildException("Unable to create directory as a file " 55 + "already exists with that name: " 56 + dir.getAbsolutePath()); 57 } 58 59 if (!dir.exists()) { 60 boolean result = mkdirs(dir); 61 if (!result) { 62 String msg = "Directory " + dir.getAbsolutePath() 63 + " creation was not successful for an unknown reason"; 64 throw new BuildException(msg, getLocation()); 65 } 66 log("Created dir: " + dir.getAbsolutePath()); 67 } else { 68 log("Skipping " + dir.getAbsolutePath() 69 + " because it already exists.", Project.MSG_VERBOSE); 70 } 71 } 72 73 78 public void setDir(File dir) { 79 this.dir = dir; 80 } 81 86 private boolean mkdirs(File f) { 87 if (!f.mkdirs()) { 88 try { 89 Thread.sleep(MKDIR_RETRY_SLEEP_MILLIS); 90 return f.mkdirs(); 91 } catch (InterruptedException ex) { 92 return f.mkdirs(); 93 } 94 } 95 return true; 96 } 97 } 98 99 | Popular Tags |