1 16 package org.apache.commons.vfs.tasks; 17 18 import org.apache.commons.vfs.FileObject; 19 import org.apache.commons.vfs.Selectors; 20 import org.apache.commons.vfs.util.Messages; 21 import org.apache.tools.ant.BuildException; 22 23 import java.util.StringTokenizer ; 24 25 31 public class DeleteTask 32 extends VfsTask 33 { 34 private String file; 35 private String srcDirUrl; 36 private String filesList; 37 38 43 public void setFile(final String file) 44 { 45 this.file = file; 46 } 47 48 51 public void setSrcDir(final String srcDir) 52 { 53 this.srcDirUrl = srcDir; 54 } 55 56 59 public void setIncludes(final String filesList) 60 { 61 this.filesList = filesList; 62 } 63 64 67 public void execute() throws BuildException 68 { 69 if ((file == null && srcDirUrl == null) || (srcDirUrl != null && filesList == null)) 70 { 71 final String message = Messages.getString("vfs.tasks/delete.no-source-files.error"); 72 throw new BuildException(message); 73 } 74 75 try 76 { 77 if (srcDirUrl != null && filesList != null) 78 { 79 log("Deleting " + filesList + " in the directory " + srcDirUrl); 80 if (!srcDirUrl.endsWith("/")) 81 { 82 srcDirUrl += "/"; 83 } 84 StringTokenizer tok = new StringTokenizer (filesList, ", \t\n\r\f", false); 85 while (tok.hasMoreTokens()) 86 { 87 String nextFile = tok.nextToken(); 88 final FileObject srcFile = resolveFile(srcDirUrl + nextFile); 89 srcFile.delete(Selectors.SELECT_ALL); 90 } 91 } 92 else 93 { 94 final FileObject srcFile = resolveFile(file); 95 log("Deleting " + srcFile); 96 srcFile.delete(Selectors.SELECT_ALL); 97 } 98 } 99 catch (final Exception e) 100 { 101 throw new BuildException(e); 102 } 103 } 104 } 105 | Popular Tags |