holtdl 01/04/30 16:25:40
Modified: docs/manual/CoreTasks available.html
src/main/org/apache/tools/ant/taskdefs Available.java
Log:
Make "file" attribute only check for a file; add "dir" attribute for checking
for a directory; update doc.
Revision Changes Path
1.3 +35 -20 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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- available.html 2001/02/13 12:31:50 1.2
+++ available.html 2001/04/30 23:25:32 1.3
@@ -10,10 +10,10 @@
<h2><a name="available">Available</a></h2>
<h3>Description</h3>
<p>Sets a property if a resource is available at runtime. This resource can
be a
-file resource, a class in classpath or a JVM system resource.</p>
+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 using the value attribute.</p>
+something specific 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>
@@ -25,63 +25,78 @@
</tr>
<tr>
<td valign="top">property</td>
- <td valign="top">the name of the property to set.</td>
+ <td valign="top">The name of the property to set.</td>
<td valign="top" align="center">Yes</td>
</tr>
<tr>
<td valign="top">value</td>
- <td valign="top">the value to set the property to. Defaults to
"true".</td>
+ <td valign="top">The value to set the property to. Defaults to
"true".</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">classname</td>
- <td valign="top">the class to look for in classpath.</td>
- <td valign="middle" align="center" rowspan="3">Yes</td>
+ <td valign="top">The class to look for in the classpath.</td>
+ <td valign="middle" align="center" rowspan="4">Yes</td>
</tr>
<tr>
- <td valign="top">resource</td>
- <td valign="top">the resource to look for in the JVM</td>
+ <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>
+ <td valign="top">The file to look for.</td>
+ </tr>
+ <tr>
+ <td valign="top">resource</td>
+ <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>.</td> <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
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>
</table>
<h3>Parameters specified as nested elements</h3>
<h4>classpath</h4>
-<p><code>Available</code>'s <i>classpath</i> attribute is a <a
+<p><code>Available</code>'s <code>classpath</code> attribute is a <a
href="../using.html#path">path-like structure</a> and can also be set via a
nested
-<i>classpath</i> element.</p>
+<code><classpath></code> element.</p>
<h3>Examples</h3>
<pre> <available classname="org.whatever.Myclass"
property="Myclass.present"/></pre>
-<p>sets the property <code><i>Myclass.present</i></code> to the value
"true"
-if the class <i>org.whatever.Myclass</i> is found in Ant's classpath.</p>
+<p>sets the <code>Myclass.present</code> property to the value
"true"
+if the class <code>org.whatever.Myclass</code> is found in Ant's
classpath.</p>
<pre>
<property name="jaxp.jar"
value="./lib/jaxp11/jaxp.jar"/>
<available file="${jaxp.jar}"
property="jaxp.jar.present"/>
</pre>
-<p>sets the property <code><i>jaxp.jar.present</i></code> to the value
"true"
-if the file <i>./lib/jaxp11/jaxp.jar</i> is found.</p>
+<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>
...in project ...
<property name="jaxp.jar"
value="./lib/jaxp11/jaxp.jar"/>
<path id="jaxp" location="${jaxp.jar}"/>
...in target ...
<available classname="javax.xml.transform.Transformer"
classpathref="jaxp" property="jaxp11.present"/>
+</pre>
+<p>sets the <code>jaxp11.present</code> property to the value
"true"
+if the class <code>javax.xml.transform.Transformer</code> is found in the
classpath referenced by <code>jaxp</code> (in this case,
<code>./lib/jaxp11/jaxp.jar</code>).
+</p>
+<p>
+<pre>
+<available property="have.extras"
resource="extratasks.properties">
+ <classpath>
+ <pathelement location="/usr/local/ant/extra.jar/>
+ </classpath>
+</available>
</pre>
-<p>sets the property <code><i>jaxp11.present</i></code> to the value
"true"
-if the class <i>javax.xml.transform.Transformer</i> is found in the
classpath referenced by <code>jaxp</code> (in this case, it is
<code>./lib/jaxp11/jaxp.jar</code>).
+<p>sets the <code>have.extras</code> property to the value "true"
+if the resource-file <code>extratasks.properties</code> is found.
</p>
<hr><p align="center">Copyright © 2000,2001 Apache Software Foundation.
All rights
Reserved.</p>
1.19 +17 -3
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.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- Available.java 2001/02/13 12:31:58 1.18
+++ Available.java 2001/04/30 23:25:36 1.19
@@ -70,6 +70,7 @@
private String property;
private String classname;
private File file;
+ private File dir;
private String resource;
private Path classpath;
private AntClassLoader loader;
@@ -112,6 +113,10 @@
this.file = file;
}
+ public void setDir(File dir) {
+ this.dir = dir;
+ }
+
public void setResource(String resource) {
this.resource = resource;
}
@@ -121,8 +126,8 @@
throw new BuildException("property attribute is required",
location);
}
- if (classname == null && file == null && resource == null) {
- throw new BuildException("At least one of
(classname|file|resource) 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 (classpath != null) {
@@ -139,6 +144,11 @@
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;
@@ -148,7 +158,11 @@
}
private boolean checkFile(File file) {
- return file.exists();
+ return file.isFile();
+ }
+
+ private boolean checkDir(File dir) {
+ return dir.isDirectory();
}
private boolean checkResource(String resource) {