ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hol...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs Available.java
Date Tue, 27 Nov 2001 15:41:05 GMT
holtdl      01/11/27 07:41:05

  Modified:    src/main/org/apache/tools/ant/taskdefs Available.java
  Log:
  Fix my previous fix. First time thru, I thought filepath was only used
  with a <fileset> (oops). Changed passed-in file to be a string, so it
  doesn't end up becoming a full-pathname prepended with the base dir,
  which wasn't really needed and was complicating using it when a filepath
  was specified. Also fixed some of the logging. (Also, hopefully the Java
  is a bit better this time :)
  
  Revision  Changes    Path
  1.27      +77 -27    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.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- Available.java	2001/11/14 19:19:54	1.26
  +++ Available.java	2001/11/27 15:41:04	1.27
  @@ -74,7 +74,7 @@
   
       private String property;
       private String classname;
  -    private File file;
  +    private String file;
       private Path filepath;
       private String resource;
       private String type;
  @@ -122,7 +122,7 @@
           }
       }
   
  -    public void setFile(File file) {
  +    public void setFile(String file) {
           this.file = file;
       }
   
  @@ -144,7 +144,7 @@
           }
       }
           
  -    public boolean  eval() throws BuildException {
  +    public boolean eval() throws BuildException {
           if (classname == null && file == null && resource == null) {
               throw new BuildException("At least one of (classname|file|resource) is required",
location);
           }
  @@ -170,9 +170,9 @@
           
           if ((file != null) && !checkFile()) {
               if (type != null) {
  -                log("Unable to find " + type + " " + file.getName() + " to set property
" + property, Project.MSG_VERBOSE);
  +                log("Unable to find " + type + " " + file + " to set property " + property,
Project.MSG_VERBOSE);
               } else {
  -                log("Unable to find " + file.getName() + " to set property " + property,
Project.MSG_VERBOSE);
  +                log("Unable to find " + file + " to set property " + property, Project.MSG_VERBOSE);
               }
               return false;
           }
  @@ -196,30 +196,73 @@
               String[] paths = filepath.list();
               for(int i = 0; i < paths.length; ++i) {
                   log("Searching " + paths[i], Project.MSG_DEBUG);
  -                File filename = new File(paths[i]);
  +                /* 
  +                ** filepath can be a list of directory and/or
  +                ** file names (gen'd via <fileset>)
  +                **
  +                ** look for:
  +                **   full-pathname specified == path in list
  +                **   full-pathname specified == parent dir of path in list
  +                **   simple name specified   == path in list
  +                **   simple name specified   == path in list + name
  +                **   simple name specified   == parent dir + name
  +                **   simple name specified   == parent of parent dir + name
  +                **
  +                */
  +                File path = new File(paths[i]);
  +                String dirname = path.getParent();
                   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);
  +                        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;
                           }
  -                    } else if (type.equalsIgnoreCase("file")) {
  -                        if(filename.isFile()) {
  -                            if(filename.getName().equals(file.getName())) {
  -                                log("Found file: " + filename, Project.MSG_VERBOSE);
  +                    /* 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;
                           }
                       }
  -                } else if(filename.isFile()) {
  -                    if(filename.getName().equals(file.getName())) {
  -                        log("Found file: " + filename, Project.MSG_VERBOSE);
  +                /* end check for specified type */
  +                } else {
  +                    if (path.toString().equals(new File(file).toString())) {
  +                        log("Found: " + path, Project.MSG_VERBOSE);
  +                        return true;
  +                    } else if (new File(path, file).exists()) {
  +                        log("Found: " + path + File.separator + file, Project.MSG_VERBOSE);
                           return true;
  +                    } else if (new File(dirname, file).exists()) {
  +                        log("Found: " + dirname + File.separator + file, 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);
  +                            return true;
  +                        }
                       }
                   }
               }
  @@ -227,18 +270,25 @@
           return false;
       }
   
  -    private boolean checkFile(File file) {
  +    private boolean checkFile(String file) {
  +        File filename = new File(file);
           if (type != null) {
               if (type.equalsIgnoreCase("dir")) {
  -                log("Found directory: " + file, Project.MSG_VERBOSE);
  -                return file.isDirectory();
  +                if( filename.isDirectory()) {
  +                    log("Found directory: " + file, Project.MSG_VERBOSE);
  +                }
  +                return filename.isDirectory();
               } else if (type.equalsIgnoreCase("file")) {
  -                log("Found file: " + file, Project.MSG_VERBOSE);
  -                return file.isFile();
  +                if( filename.isFile()) {
  +                    log("Found file: " + file, Project.MSG_VERBOSE);
  +                }
  +                return filename.isFile();
               }
  +        }
  +        if (filename.exists()) {
  +            log("Found: " + file, Project.MSG_VERBOSE);
           }
  -        log("Found: " + file, Project.MSG_VERBOSE);
  -        return file.exists();
  +        return filename.exists();
       }
   
       private boolean checkResource(String resource) {
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message