You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by bo...@apache.org on 2001/07/12 15:26:47 UTC
cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs Available.java
bodewig 01/07/12 06:26:46
Modified: . WHATSNEW
src/main/org/apache/tools/ant/taskdefs Available.java
Log:
Add filepath attribute/element to available to search for a file in a
given path - handy if you want to search for an executable for example.
Submitted by: John Morrison <Jo...@uk.experian.com>
Revision Changes Path
1.130 +3 -0 jakarta-ant/WHATSNEW
Index: WHATSNEW
===================================================================
RCS file: /home/cvs/jakarta-ant/WHATSNEW,v
retrieving revision 1.129
retrieving revision 1.130
diff -u -r1.129 -r1.130
--- WHATSNEW 2001/07/12 13:02:32 1.129
+++ WHATSNEW 2001/07/12 13:26:35 1.130
@@ -112,6 +112,9 @@
* added vssver.scc to the default excludes
+* <available> has a new filepath attribute/nested element that allows
+ you top search for a file in a given path.
+
Fixed bugs:
-----------
1.22 +31 -8 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.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- Available.java 2001/07/10 14:55:32 1.21
+++ Available.java 2001/07/12 13:26:42 1.22
@@ -70,6 +70,7 @@
private String property;
private String classname;
private File file;
+ private Path filepath;
private String resource;
private String type;
private Path classpath;
@@ -77,11 +78,7 @@
private String value = "true";
public void setClasspath(Path classpath) {
- if (this.classpath == null) {
- this.classpath = classpath;
- } else {
- this.classpath.append(classpath);
- }
+ createClasspath().append(classpath);
}
public Path createClasspath() {
@@ -95,6 +92,17 @@
createClasspath().setRefid(r);
}
+ public void setFilepath(Path filepath) {
+ createFilepath().append(filepath);
+ }
+
+ public Path createFilepath() {
+ if (this.filepath == null) {
+ this.filepath = new Path(project);
+ }
+ return this.filepath.createPath();
+ }
+
public void setProperty(String property) {
this.property = property;
}
@@ -145,7 +153,7 @@
return;
}
- if ((file != null) && !checkFile(file)) {
+ if ((file != null) && !checkFile()) {
log("Unable to find " + file + " to set property " + property, Project.MSG_VERBOSE);
return;
}
@@ -158,11 +166,26 @@
this.project.setProperty(property, value);
}
+ private boolean checkFile() {
+ if (filepath == null) {
+ return checkFile(file);
+ } else {
+ String[] paths = filepath.list();
+ for(int i = 0; i < paths.length; ++i) {
+ log("Searching " + paths[i], Project.MSG_VERBOSE);
+ if(new File(paths[i], file.getName()).isFile()) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
private boolean checkFile(File file) {
if (type != null) {
- if (type.equalsIgnoreCase("dir")){
+ if (type.equalsIgnoreCase("dir")) {
return file.isDirectory();
- } else if (type.equalsIgnoreCase("file")){
+ } else if (type.equalsIgnoreCase("file")) {
return file.isFile();
}
}