bodewig 01/11/28 01:21:37
Modified: src/main/org/apache/tools/ant/taskdefs Available.java
Log:
Make testcase for <available> pass again, by re-applying the
resolveFile magic unless a filepaths has been specified.
Note that I've rewritten the checkFile() method in the filepath case
to match the comment in the sources (at least I think so).
Actually, I think we are generating too many passed checks, especially
with simple name specified == parent of parent dir + name but this is
a different issue.
Revision Changes Path
1.28 +66 -59
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.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- Available.java 2001/11/27 15:41:04 1.27
+++ Available.java 2001/11/28 09:21:37 1.28
@@ -63,6 +63,7 @@
import org.apache.tools.ant.taskdefs.condition.Condition;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.Reference;
+import org.apache.tools.ant.util.FileUtils;
/**
* Will set the given property if the requested resource is available at
runtime.
@@ -191,7 +192,7 @@
private boolean checkFile() {
if (filepath == null) {
- return checkFile(file);
+ return checkFile(project.resolveFile(file), file);
} else {
String[] paths = filepath.list();
for(int i = 0; i < paths.length; ++i) {
@@ -210,57 +211,64 @@
**
*/
File path = new File(paths[i]);
- String dirname = path.getParent();
- if (type != null) {
- if (type.equalsIgnoreCase("dir")) {
- if (path.isFile()) {
- // full-pathname specified
- if (dirname.equals(path.toString())) {
- log("Found directory: " + path,
Project.MSG_VERBOSE);
- return true;
- // simple name specified
- } else if(new File(dirname, file).isDirectory())
{
- log("Found directory: " + dirname +
File.separator + file, Project.MSG_VERBOSE);
- return true;
- }
- // full-pathname specified
- } else if (path.toString().equals(new
File(file).toString()) && path.isDirectory()) {
- log("Found directory: " + path,
Project.MSG_VERBOSE);
- return true;
- // simple name specified
- } else if (new File(path, file).isDirectory()) {
- log("Found directory: " + path +
File.separator + file, Project.MSG_VERBOSE);
- return true;
- }
- /* end check for type dir */
- } else {
- if (path.toString().equals(new
File(file).toString()) && path.isFile()) {
- log("Found file: " + path,
Project.MSG_VERBOSE);
- return true;
- } else if (new File(path, file).isFile()) {
- log("Found file: " + path + File.separator +
file, Project.MSG_VERBOSE);
- return true;
- } else if (new File(dirname, file).isFile()) {
- log("Found file: " + dirname + File.separator +
file, Project.MSG_VERBOSE);
- return true;
- }
- }
- /* end check for specified type */
- } else {
- if (path.toString().equals(new File(file).toString())) {
+
+ // ** full-pathname specified == path in list
+ // ** simple name specified == path in list
+ if (path.exists() && file.equals(paths[i])) {
+ if (type == null) {
log("Found: " + path, Project.MSG_VERBOSE);
+ return true;
+ } else if (type.equalsIgnoreCase("dir")
+ && path.isDirectory()) {
+ log("Found directory: " + path, Project.MSG_VERBOSE);
+ return true;
+ } else if (type.equalsIgnoreCase("file")
+ && path.isFile()) {
+ log("Found file: " + path, Project.MSG_VERBOSE);
return true;
- } else if (new File(path, file).exists()) {
- log("Found: " + path + File.separator + file,
Project.MSG_VERBOSE);
+ }
+ // not the requested type
+ return false;
+ }
+
+ FileUtils fileUtils = FileUtils.newFileUtils();
+ File parent = fileUtils.getParentFile(path);
+ // ** full-pathname specified == parent dir of path in list
+ if (parent != null && parent.exists()
+ && file.equals(parent.getAbsolutePath())) {
+ if (type == null) {
+ log("Found: " + parent, Project.MSG_VERBOSE);
return true;
- } else if (new File(dirname, file).exists()) {
- log("Found: " + dirname + File.separator + file,
Project.MSG_VERBOSE);
+ } else if (type.equalsIgnoreCase("dir")) {
+ log("Found directory: " + parent,
Project.MSG_VERBOSE);
return true;
- } else {
- File dir = new File(dirname);
- dirname = dir.getParent();
- if (new File(dirname, file).exists()) {
- log("Found: " + dirname + File.separator + file,
Project.MSG_VERBOSE);
+ }
+ // not the requested type
+ return false;
+ }
+
+ // ** simple name specified == path in list + name
+ if (path.exists() && path.isDirectory()) {
+ if (checkFile(new File(path, file),
+ file + " in " + path)) {
+ return true;
+ }
+ }
+
+ // ** simple name specified == parent dir + name
+ if (parent != null && parent.exists()) {
+ if (checkFile(new File(parent, file),
+ file + " in " + parent)) {
+ return true;
+ }
+ }
+
+ // ** simple name specified == parent of parent dir +
name
+ if (parent != null) {
+ File grandParent = fileUtils.getParentFile(parent);
+ if (grandParent != null && grandParent.exists()) {
+ if (checkFile(new File(grandParent, file),
+ file + " in " + grandParent)) {
return true;
}
}
@@ -270,25 +278,24 @@
return false;
}
- private boolean checkFile(String file) {
- File filename = new File(file);
+ private boolean checkFile(File f, String text) {
if (type != null) {
if (type.equalsIgnoreCase("dir")) {
- if( filename.isDirectory()) {
- log("Found directory: " + file, Project.MSG_VERBOSE);
+ if( f.isDirectory()) {
+ log("Found directory: " + text, Project.MSG_VERBOSE);
}
- return filename.isDirectory();
+ return f.isDirectory();
} else if (type.equalsIgnoreCase("file")) {
- if( filename.isFile()) {
- log("Found file: " + file, Project.MSG_VERBOSE);
+ if( f.isFile()) {
+ log("Found file: " + text, Project.MSG_VERBOSE);
}
- return filename.isFile();
+ return f.isFile();
}
}
- if (filename.exists()) {
- log("Found: " + file, Project.MSG_VERBOSE);
+ if (f.exists()) {
+ log("Found: " + text, Project.MSG_VERBOSE);
}
- return filename.exists();
+ return f.exists();
}
private boolean checkResource(String resource) {
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>