diff --git a/WHATSNEW b/WHATSNEW index 7d8f4c724..7fe66f6eb 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -112,6 +112,9 @@ Other changes: * added vssver.scc to the default excludes +* has a new filepath attribute/nested element that allows + you top search for a file in a given path. + Fixed bugs: ----------- diff --git a/src/main/org/apache/tools/ant/taskdefs/Available.java b/src/main/org/apache/tools/ant/taskdefs/Available.java index f41b476b0..6d7124254 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 Path filepath; private String resource; private String type; private Path classpath; @@ -77,11 +78,7 @@ public class Available extends Task { 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 @@ public class Available extends Task { 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 @@ public class Available extends Task { 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 @@ public class Available extends Task { 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(); } }