1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.vfs2.tasks;
18
19 import java.util.StringTokenizer;
20
21 import org.apache.commons.vfs2.FileObject;
22 import org.apache.commons.vfs2.util.Messages;
23 import org.apache.tools.ant.BuildException;
24
25
26
27
28
29
30
31 public class DeleteTask extends VfsTask {
32 private String file;
33 private String srcDirUrl;
34 private String filesList;
35
36
37
38
39
40
41 public void setFile(final String file) {
42 this.file = file;
43 }
44
45
46
47
48
49
50 public void setSrcDir(final String srcDir) {
51 this.srcDirUrl = srcDir;
52 }
53
54
55
56
57
58
59 public void setIncludes(final String filesList) {
60 this.filesList = filesList;
61 }
62
63
64
65
66
67
68 @Override
69 public void execute() throws BuildException {
70 if ((file == null && srcDirUrl == null) || (srcDirUrl != null && filesList == null)) {
71 final String message = Messages.getString("vfs.tasks/delete.no-source-files.error");
72 throw new BuildException(message);
73 }
74
75 try {
76 if (srcDirUrl != null) {
77 log("Deleting " + filesList + " in the directory " + srcDirUrl);
78 if (!srcDirUrl.endsWith("/")) {
79 srcDirUrl += "/";
80 }
81 final StringTokenizer tok = new StringTokenizer(filesList, ", \t\n\r\f", false);
82 while (tok.hasMoreTokens()) {
83 final String nextFile = tok.nextToken();
84 final FileObject srcFile = resolveFile(srcDirUrl + nextFile);
85 srcFile.deleteAll();
86 }
87 } else {
88 final FileObject srcFile = resolveFile(file);
89 log("Deleting " + srcFile.getPublicURIString());
90 srcFile.deleteAll();
91 }
92 } catch (final Exception e) {
93 throw new BuildException(e);
94 }
95 }
96 }