holtdl 01/11/14 11:19:54
Modified: src/main/org/apache/tools/ant/taskdefs Available.java
Log:
- Fixed the search for a file or directory using the <filepath> element
(changes are in checkFile(), in case anyone wants to review this
and make sure I did it right).
- Added a BuildException for when the "type" attribute is used with
anything other than the "file" attribute.
- Changed the "Searching..." output to DEBUG level, since that
seemed more appropriate, and added "Found..." output for the
VERBOSE level.
Revision Changes Path
1.26 +37 -4
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.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- Available.java 2001/10/28 21:26:28 1.25
+++ Available.java 2001/11/14 19:19:54 1.26
@@ -150,6 +150,9 @@
}
if (type != null){
+ if (file == null){
+ throw new BuildException("The type attribute is only valid
when specifying the file attribute.");
+ }
if (!type.equalsIgnoreCase("file") &&
!type.equalsIgnoreCase("dir")){
throw new BuildException("Type must be one of either dir or
file");
}
@@ -166,7 +169,11 @@
}
if ((file != null) && !checkFile()) {
- log("Unable to find " + file + " to set property " + property,
Project.MSG_VERBOSE);
+ if (type != null) {
+ log("Unable to find " + type + " " + file.getName() + " to
set property " + property, Project.MSG_VERBOSE);
+ } else {
+ log("Unable to find " + file.getName() + " to set property "
+ property, Project.MSG_VERBOSE);
+ }
return false;
}
@@ -188,9 +195,32 @@
} 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;
+ log("Searching " + paths[i], Project.MSG_DEBUG);
+ File filename = new File(paths[i]);
+ if (type != null) {
+ if (type.equalsIgnoreCase("dir")) {
+ String dir = filename.getParent();
+ if(dir != null) {
+ int index = dir.lastIndexOf(File.separator);
+ String dirname = dir.substring(index + 1);
+ if(dirname.equals(file.getName())) {
+ log("Found directory: " + dir,
Project.MSG_VERBOSE);
+ return true;
+ }
+ }
+ } else if (type.equalsIgnoreCase("file")) {
+ if(filename.isFile()) {
+ if(filename.getName().equals(file.getName())) {
+ log("Found file: " + filename,
Project.MSG_VERBOSE);
+ return true;
+ }
+ }
+ }
+ } else if(filename.isFile()) {
+ if(filename.getName().equals(file.getName())) {
+ log("Found file: " + filename, Project.MSG_VERBOSE);
+ return true;
+ }
}
}
}
@@ -200,11 +230,14 @@
private boolean checkFile(File file) {
if (type != null) {
if (type.equalsIgnoreCase("dir")) {
+ log("Found directory: " + file, Project.MSG_VERBOSE);
return file.isDirectory();
} else if (type.equalsIgnoreCase("file")) {
+ log("Found file: " + file, Project.MSG_VERBOSE);
return file.isFile();
}
}
+ log("Found: " + file, Project.MSG_VERBOSE);
return file.exists();
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>