You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by um...@apache.org on 2001/12/27 22:31:43 UTC

cvs commit: jakarta-ant/src/main/org/apache/tools/ant/types DestDir.java DestFile.java

umagesh     01/12/27 13:31:43

  Modified:    src/main/org/apache/tools/ant/types DestDir.java
                        DestFile.java
  Log:
  If DestFile or DestDir does not exist, ensure that the path representing the
  directory or the file is valid, by checking if the path contains any existing
  non-directory element, thereby making sure the file/dir is constructible.
  
  Revision  Changes    Path
  1.3       +24 -8     jakarta-ant/src/main/org/apache/tools/ant/types/DestDir.java
  
  Index: DestDir.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/types/DestDir.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DestDir.java	2001/12/27 05:25:09	1.2
  +++ DestDir.java	2001/12/27 21:31:43	1.3
  @@ -64,21 +64,21 @@
    */
   public final class DestDir extends ValidatedFileAttribute {
   
  -    /** 
  +    private String message = null;
  +
  +    /**
        * empty constructor
        */
       public DestDir() {}
  -    
  -    
  -     /** 
  -     * file constructor; performs validation 
  +
  +
  +     /**
  +     * file constructor; performs validation
        * @param file the file to use
        */
       public DestDir(File file) throws BuildException {
  -        setFile(file);    
  +        setFile(file);
       }
  -    
  -    private String message = null;
   
       protected final String getMessage() {
           return message;
  @@ -97,6 +97,22 @@
           if (f.exists() && !f.isDirectory()) {
               message = "DestDir " + f + " is not a directory.";
               return false;
  +        }
  +        //If DestDir does not exist, make sure it is well formed.
  +        if (!f.exists()) {
  +            File tmp = f;
  +            while (tmp.getParent() != null) {
  +                File parent = new File(tmp.getParent());
  +                if (parent.exists()) {
  +                    if (!parent.isDirectory()) {
  +                        message = "DestDir " + f + " contains the path "
  +                                  + parent + " that is not a directory.";
  +                        return false;
  +                    }
  +                    break;
  +                }
  +                tmp = parent;
  +            }
           }
           return true;
       }
  
  
  
  1.3       +27 -12    jakarta-ant/src/main/org/apache/tools/ant/types/DestFile.java
  
  Index: DestFile.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/types/DestFile.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DestFile.java	2001/12/27 05:25:09	1.2
  +++ DestFile.java	2001/12/27 21:31:43	1.3
  @@ -64,22 +64,21 @@
    */
   public final class DestFile extends ValidatedFileAttribute {
   
  +    private String message;
   
  -    /** 
  +    /**
        * empty constructor
        */
       public DestFile() {}
  -    
  -    
  -     /** 
  -     * file constructor; performs validation 
  +
  +
  +     /**
  +     * file constructor; performs validation
        * @param file the file to use
        */
       public DestFile(File file) throws BuildException {
  -        setFile(file);    
  +        setFile(file);
       }
  -    
  -    private String message;
   
       protected final String getMessage() {
           return message;
  @@ -99,9 +98,25 @@
               message = "DestFile " + f + " is not a file.";
               return false;
           }
  +        //If DestFile does not exist, make sure it is well formed.
  +        if (!f.exists()) {
  +            File tmp = f;
  +            while (tmp.getParent() != null) {
  +                File parent = new File(tmp.getParent());
  +                if (parent.exists()) {
  +                    if (!parent.isDirectory()) {
  +                        message = "DestFile " + f + " contains the path "
  +                                  + parent + " that is not a directory.";
  +                        return false;
  +                    }
  +                    break;
  +                }
  +                tmp = parent;
  +            }
  +        }
           return true;
       }
  -    
  +
       /**
        * test for the dest file being newer than the file passed in.
        * returns true iff the dest exists and is the same age or newer
  @@ -112,13 +127,13 @@
       public boolean isUpToDate(File dependent) {
         if(!getFile().exists())
             return false;
  -      return getFile().lastModified() >= dependent.lastModified();    
  +      return getFile().lastModified() >= dependent.lastModified();
       }
  -    
  +
       /**
        * test for the dest file being newer than the SrcFile passed in.
        * returns true iff the dest exists and is the same age or newer
  -     * @pre getFile()!=null  
  +     * @pre getFile()!=null
        * @pre dependent!=null && depedent.getFile!=null;
        * @param dependent file we are dependent on
        * @return true iff we are up to date
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>