diff --git a/docs/manual/CoreTasks/available.html b/docs/manual/CoreTasks/available.html index b487bf8f8..0d8f70957 100644 --- a/docs/manual/CoreTasks/available.html +++ b/docs/manual/CoreTasks/available.html @@ -10,10 +10,10 @@
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.
+file, a directory, a class in the classpath, or a JVM system resource.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.
+something specific by specifying thevalue
attribute.
Normally, this task is used to set properties that are useful to avoid target execution depending on system parameters.
classname
.classname
or resource
.Available
's classpath attribute is a Available
's classpath
attribute is a path-like structure and can also be set via a nested
-classpath element.
<classpath>
element.
<available classname="org.whatever.Myclass" property="Myclass.present"/>-
sets the property Myclass.present
to the value "true"
-if the class org.whatever.Myclass is found in Ant's classpath.
sets the Myclass.present
property to the value "true"
+if the class org.whatever.Myclass
is found in Ant's classpath.
<property name="jaxp.jar" value="./lib/jaxp11/jaxp.jar"/> <available file="${jaxp.jar}" property="jaxp.jar.present"/>-
sets the property jaxp.jar.present
to the value "true"
-if the file ./lib/jaxp11/jaxp.jar is found.
sets the jaxp.jar.present
property to the value "true"
+if the file ./lib/jaxp11/jaxp.jar
is found.
...in project ... <property name="jaxp.jar" value="./lib/jaxp11/jaxp.jar"/> @@ -80,8 +84,19 @@ if the file ./lib/jaxp11/jaxp.jar is found. ...in target ... <available classname="javax.xml.transform.Transformer" classpathref="jaxp" property="jaxp11.present"/>-
sets the property jaxp11.present
to the value "true"
-if the class javax.xml.transform.Transformer is found in the classpath referenced by jaxp
(in this case, it is ./lib/jaxp11/jaxp.jar
).
+
sets the jaxp11.present
property to the value "true"
+if the class javax.xml.transform.Transformer
is found in the classpath referenced by jaxp
(in this case, ./lib/jaxp11/jaxp.jar
).
+
+
+<available property="have.extras" resource="extratasks.properties"> + <classpath> + <pathelement location="/usr/local/ant/extra.jar/> + </classpath> +</available> ++
sets the have.extras
property to the value "true"
+if the resource-file extratasks.properties
is found.
Copyright © 2000,2001 Apache Software Foundation. All rights Reserved.
diff --git a/src/main/org/apache/tools/ant/taskdefs/Available.java b/src/main/org/apache/tools/ant/taskdefs/Available.java index 0ff188a7f..0dab4f376 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Available.java +++ b/src/main/org/apache/tools/ant/taskdefs/Available.java @@ -70,6 +70,7 @@ public class Available extends Task { 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 @@ public class Available extends Task { this.file = file; } + public void setDir(File dir) { + this.dir = dir; + } + public void setResource(String resource) { this.resource = resource; } @@ -121,8 +126,8 @@ public class Available extends Task { 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 @@ public class Available extends Task { 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 @@ public class Available extends Task { } private boolean checkFile(File file) { - return file.exists(); + return file.isFile(); + } + + private boolean checkDir(File dir) { + return dir.isDirectory(); } private boolean checkResource(String resource) {