1 18 19 package org.apache.tools.ant.taskdefs; 20 21 import java.io.File ; 22 import java.io.IOException ; 23 import org.apache.tools.ant.BuildException; 24 import org.apache.tools.ant.Task; 25 26 34 35 public class Deltree extends Task { 36 37 private File dir; 38 39 44 public void setDir(File dir) { 45 this.dir = dir; 46 } 47 48 54 public void execute() throws BuildException { 55 log("DEPRECATED - The deltree task is deprecated. " 56 + "Use delete instead."); 57 58 if (dir == null) { 59 throw new BuildException("dir attribute must be set!", getLocation()); 60 } 61 62 if (dir.exists()) { 63 if (!dir.isDirectory()) { 64 if (!dir.delete()) { 65 throw new BuildException("Unable to delete directory " 66 + dir.getAbsolutePath(), 67 getLocation()); 68 } 69 return; 70 } 71 72 log("Deleting: " + dir.getAbsolutePath()); 73 74 try { 75 removeDir(dir); 76 } catch (IOException ioe) { 77 String msg = "Unable to delete " + dir.getAbsolutePath(); 78 throw new BuildException(msg, getLocation()); 79 } 80 } 81 } 82 83 private void removeDir(File dir) throws IOException { 84 85 89 String [] list = dir.list(); 93 for (int i = 0; i < list.length; i++) { 94 String s = list[i]; 95 File f = new File (dir, s); 96 if (f.isDirectory()) { 97 removeDir(f); 98 } else { 99 if (!f.delete()) { 100 throw new BuildException("Unable to delete file " 101 + f.getAbsolutePath()); 102 } 103 } 104 } 105 if (!dir.delete()) { 106 throw new BuildException("Unable to delete directory " 107 + dir.getAbsolutePath()); 108 } 109 } 110 } 111 112 | Popular Tags |