holtdl 01/05/03 00:41:12
Modified: docs/manual/CoreTasks available.html
src/main/org/apache/tools/ant/taskdefs Available.java
src/etc/testcases/taskdefs available.xml
Log:
Backed out previous change that added a "dir" attribute, as this caused
backwards-compatibility issues. Added a "type" attribute instead, which
works with the "file" attribute to specify either a file or a directory.
Revision Changes Path
1.4 +17 -11 jakarta-ant/docs/manual/CoreTasks/available.html
Index: available.html
===================================================================
RCS file: /home/cvs/jakarta-ant/docs/manual/CoreTasks/available.html,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- available.html 2001/04/30 23:25:32 1.3
+++ available.html 2001/05/03 07:41:06 1.4
@@ -12,8 +12,8 @@
<p>Sets a property if a resource is available at runtime. This resource can
be a
file, a directory, a class in the classpath, or a JVM system resource.</p>
<p>If the resource is present, the property value is set to true by
-default, otherwise the property is not set. You can set the value to
-something specific by specifying the <code>value</code> attribute.</p>
+default; otherwise, the property is not set. You can set the value to
+something other than the default by specifying the <code>value</code>
attribute.</p>
<p>Normally, this task is used to set properties that are useful to avoid
target
execution depending on system parameters.</p>
<h3>Parameters</h3>
@@ -36,13 +36,9 @@
<tr>
<td valign="top">classname</td>
<td valign="top">The class to look for in the classpath.</td>
- <td valign="middle" align="center" rowspan="4">Yes</td>
+ <td valign="middle" align="center" rowspan="3">Yes</td>
</tr>
<tr>
- <td valign="top">dir</td>
- <td valign="top">The directory to look for.</td>
- </tr>
- <tr>
<td valign="top">file</td>
<td valign="top">The file to look for.</td>
</tr>
@@ -51,13 +47,18 @@
<td valign="top">The resource to look for in the JVM.</td>
</tr>
<tr>
- <td valign="top">classpath</td> <td valign="top">The classpath to
- use when looking up <code>classname</code> or
<code>resource</code>.</td> <td
- align="center" valign="top">No</td>
+ <td valign="top">classpath</td>
+ <td valign="top">The classpath to use when looking up
<code>classname</code> or <code>resource</code>.</td>
+ <td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">classpathref</td>
- <td valign="top">The classpath to use, given as a <a
href="../using.html#references">reference</a> to a path defined elsewhere.</td>
+ <td valign="top">The classpath to use, given as a <a
href="../using.html#references">reference</a> to a path defined elsewhere.</td>
+ <td align="center" valign="top">No</td>
+ </tr>
+ <tr>
+ <td valign="top">type</td>
+ <td valign="top">The type of <code>file</code> to look for, either a
directory (<code>type="dir"</code>) or a file (<code>type="file"</code>). If
not set, the property will be set if the name specified in the
<code>file</code> attribute exists as either a file or a directory.</td>
<td align="center" valign="top">No</td>
</tr>
@@ -77,6 +78,11 @@
</pre>
<p>sets the <code>jaxp.jar.present</code> property to the value
"true"
if the file <code>./lib/jaxp11/jaxp.jar</code> is found.</p>
+<pre>
+<available file="/usr/local/lib" type="dir"
property="local.lib.present"/>
+</pre>
+<p>sets the <code>local.lib.present</code> property to the value
"true"
+if the directory <code>/usr/local/lib</code> is found.</p>
<pre>
...in project ...
<property name="jaxp.jar"
value="./lib/jaxp11/jaxp.jar"/>
1.20 +22 -18
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Available.java
Index: Available.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Available.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- Available.java 2001/04/30 23:25:36 1.19
+++ Available.java 2001/05/03 07:41:08 1.20
@@ -70,8 +70,8 @@
private String property;
private String classname;
private File file;
- private File dir;
private String resource;
+ private String type;
private Path classpath;
private AntClassLoader loader;
private String value = "true";
@@ -113,21 +113,27 @@
this.file = file;
}
- public void setDir(File dir) {
- this.dir = dir;
- }
-
public void setResource(String resource) {
this.resource = resource;
}
+ public void setType(String type) {
+ this.type = type;
+ }
+
public void execute() throws BuildException {
if (property == null) {
throw new BuildException("property attribute is required",
location);
}
- if (classname == null && file == null && dir == null && resource ==
null) {
- throw new BuildException("At least one of
(classname|file|dir|resource) is required", location);
+ if (classname == null && file == null && resource == null) {
+ throw new BuildException("At least one of
(classname|file|resource) is required", location);
+ }
+
+ if (type != null){
+ if (!type.equalsIgnoreCase("file") &&
!type.equalsIgnoreCase("dir")){
+ throw new BuildException("Type must be one of either dir or
file");
+ }
}
if (classpath != null) {
@@ -140,15 +146,10 @@
}
if ((file != null) && !checkFile(file)) {
- log("Unable to find file " + file + " to set property " +
property, Project.MSG_VERBOSE);
+ log("Unable to find " + file + " to set property " + property,
Project.MSG_VERBOSE);
return;
}
- if ((dir != null) && !checkDir(dir)) {
- log("Unable to find dir " + dir + " to set property " +
property, Project.MSG_VERBOSE);
- return;
- }
-
if ((resource != null) && !checkResource(resource)) {
log("Unable to load resource " + resource + " to set property "
+ property, Project.MSG_VERBOSE);
return;
@@ -158,11 +159,14 @@
}
private boolean checkFile(File file) {
- return file.isFile();
- }
-
- private boolean checkDir(File dir) {
- return dir.isDirectory();
+ if (type != null) {
+ if (type.equalsIgnoreCase("dir")){
+ return file.isDirectory();
+ } else if (type.equalsIgnoreCase("file")){
+ return file.isFile();
+ }
+ }
+ return file.exists();
}
private boolean checkResource(String resource) {
1.6 +3 -3 jakarta-ant/src/etc/testcases/taskdefs/available.xml
Index: available.xml
===================================================================
RCS file: /home/cvs/jakarta-ant/src/etc/testcases/taskdefs/available.xml,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- available.xml 2001/05/01 11:41:04 1.5
+++ available.xml 2001/05/03 07:41:11 1.6
@@ -80,17 +80,17 @@
<target name="test16">
<available property="test"
- dir=""/>
+ file="" type="dir"/>
</target>
<target name="test17">
<available property="test"
- dir="../taskdefs"/>
+ file="../taskdefs" type="dir"/>
</target>
<target name="test18">
<available property="test"
- dir="../this_dir_should_never_exist"/>
+ file="../this_dir_should_never_exist" type="dir"/>
</target>
</project>