1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
package org.mule.tools.anttasks; |
11 | |
|
12 | |
import org.apache.tools.ant.BuildException; |
13 | |
import org.apache.tools.ant.Location; |
14 | |
import org.apache.tools.ant.Task; |
15 | |
|
16 | |
import java.io.File; |
17 | |
import java.text.MessageFormat; |
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
public class FileChecker extends Task |
23 | |
{ |
24 | |
private Location location; |
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
public FileChecker(Location location) |
30 | 0 | { |
31 | 0 | this.location = location; |
32 | 0 | } |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
public void checkFile(File file, String parameterName, boolean isDirectory, boolean needWrite) throws BuildException |
38 | |
{ |
39 | 0 | if (file == null) |
40 | |
{ |
41 | 0 | throw new BuildException(MessageFormat.format("No {0} specified", parameterName), getLocation()); |
42 | |
} |
43 | 0 | if (!file.exists()) |
44 | |
{ |
45 | 0 | throw new BuildException( |
46 | |
MessageFormat.format("{0} \"{1}\" does not exist", parameterName, file), |
47 | |
getLocation()); |
48 | |
} |
49 | 0 | if (!file.canRead()) |
50 | |
{ |
51 | 0 | throw new BuildException( |
52 | |
MessageFormat.format("{0} \"{1}\" is not readable", parameterName, file), |
53 | |
getLocation()); |
54 | |
} |
55 | 0 | if (needWrite && !file.canWrite()) |
56 | |
{ |
57 | 0 | throw new BuildException( |
58 | |
MessageFormat.format("{0} \"{1}\" is not writable", parameterName, file), |
59 | |
getLocation()); |
60 | |
} |
61 | 0 | if (isDirectory) |
62 | |
{ |
63 | 0 | if (!file.isDirectory()) |
64 | |
{ |
65 | 0 | throw new BuildException( |
66 | |
MessageFormat.format("{0} \"{1}\" is not a directory", parameterName, file), |
67 | |
getLocation()); |
68 | |
} |
69 | |
} |
70 | |
else |
71 | |
{ |
72 | 0 | if (file.isDirectory()) |
73 | |
{ |
74 | 0 | throw new BuildException( |
75 | |
MessageFormat.format("{0} \"{1}\" is a directory", parameterName, file), |
76 | |
getLocation()); |
77 | |
} |
78 | |
} |
79 | 0 | } |
80 | |
} |
81 | |
|