ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject cvs commit: ant/src/main/org/apache/tools/ant DirectoryScanner.java
Date Thu, 27 Jan 2005 22:31:07 GMT
mbenson     2005/01/27 14:31:07

  Modified:    src/main/org/apache/tools/ant/types Tag: ANT_16_BRANCH
                        ZipScanner.java Resource.java
               src/main/org/apache/tools/ant Tag: ANT_16_BRANCH
                        DirectoryScanner.java
  Log:
  Add size to Resource; also add DS changes
  that will allow <apply> merges to work.
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.22.2.5  +3 -2      ant/src/main/org/apache/tools/ant/types/ZipScanner.java
  
  Index: ZipScanner.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/types/ZipScanner.java,v
  retrieving revision 1.22.2.4
  retrieving revision 1.22.2.5
  diff -u -r1.22.2.4 -r1.22.2.5
  --- ZipScanner.java	9 Mar 2004 17:01:55 -0000	1.22.2.4
  +++ ZipScanner.java	27 Jan 2005 22:31:07 -0000	1.22.2.5
  @@ -1,5 +1,5 @@
   /*
  - * Copyright  2001-2004 The Apache Software Foundation
  + * Copyright  2001-2005 The Apache Software Foundation
    *
    *  Licensed under the Apache License, Version 2.0 (the "License");
    *  you may not use this file except in compliance with the License.
  @@ -226,7 +226,8 @@
                   myentries.put(new String(entry.getName()),
                                 new Resource(entry.getName(), true,
                                              entry.getTime(),
  -                                           entry.isDirectory()));
  +                                           entry.isDirectory(),
  +                                           entry.getSize()));
               }
           } finally {
               if (zf != null) {
  
  
  
  1.5.2.5   +87 -19    ant/src/main/org/apache/tools/ant/types/Resource.java
  
  Index: Resource.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/types/Resource.java,v
  retrieving revision 1.5.2.4
  retrieving revision 1.5.2.5
  diff -u -r1.5.2.4 -r1.5.2.5
  --- Resource.java	9 Mar 2004 17:01:55 -0000	1.5.2.4
  +++ Resource.java	27 Jan 2005 22:31:07 -0000	1.5.2.5
  @@ -1,5 +1,5 @@
   /*
  - * Copyright  2003-2004 The Apache Software Foundation
  + * Copyright  2003-2005 The Apache Software Foundation
    *
    *  Licensed under the Apache License, Version 2.0 (the "License");
    *  you may not use this file except in compliance with the License.
  @@ -17,28 +17,32 @@
   package org.apache.tools.ant.types;
   
   /**
  - * describes a File or a ZipEntry
  + * Describes a File or a ZipEntry.
    *
  - * this class is meant to be used by classes needing to record path
  + * This class is meant to be used by classes needing to record path
    * and date/time information about a file, a zip entry or some similar
  - * resource (URL, archive in a version control repository, ...)
  + * resource (URL, archive in a version control repository, ...).
    *
    * @since Ant 1.5.2
    */
   public class Resource implements Cloneable, Comparable {
  +    /** Constant unknown size */
  +    public static final long UNKNOWN_SIZE = -1;
  +
       private String name = null;
       private boolean exists = true;
       private long lastmodified = 0;
       private boolean directory = false;
  +    private long size = UNKNOWN_SIZE;
   
       /**
  -     * default constructor
  +     * Default constructor.
        */
       public Resource() {
       }
   
       /**
  -     * only sets the name.
  +     * Only sets the name.
        *
        * <p>This is a dummy, used for not existing resources.</p>
        *
  @@ -50,29 +54,53 @@
       }
   
       /**
  -     * sets the name, lastmodified flag, and exists flag
  +     * Sets the name, lastmodified flag, and exists flag.
        *
        * @param name relative path of the resource.  Expects
        * &quot;/&quot; to be used as the directory separator.
  +     * @param exists if true, this resource exists.
  +     * @param lastmodified the last modification time of this resource.
        */
       public Resource(String name, boolean exists, long lastmodified) {
           this(name, exists, lastmodified, false);
       }
   
       /**
  +     * Sets the name, lastmodified flag, exists flag, and directory flag.
  +     *
        * @param name relative path of the resource.  Expects
        * &quot;/&quot; to be used as the directory separator.
  +     * @param exists if true the resource exists
  +     * @param lastmodified the last modification time of the resource
  +     * @param directory    if true, this resource is a directory
        */
       public Resource(String name, boolean exists, long lastmodified,
                       boolean directory) {
  +        this(name, exists, lastmodified, directory, UNKNOWN_SIZE);
  +    }
  +
  +    /**
  +     * Sets the name, lastmodified flag, exists flag, directory flag, and size.
  +     *
  +     * @param name relative path of the resource.  Expects
  +     * &quot;/&quot; to be used as the directory separator.
  +     * @param exists if true the resource exists
  +     * @param lastmodified the last modification time of the resource
  +     * @param directory    if true, this resource is a directory
  +     * @param size the size of this resource.
  +     */
  +    public Resource(String name, boolean exists, long lastmodified,
  +                    boolean directory, long size) {
           this.name = name;
  -        this.exists = exists;
  -        this.lastmodified = lastmodified;
  -        this.directory = directory;
  +        setName(name);
  +        setExists(exists);
  +        setLastModified(lastmodified);
  +        setDirectory(directory);
  +        setSize(size);
       }
   
       /**
  -     * name attribute will contain the path of a file relative to the
  +     * Name attribute will contain the path of a file relative to the
        * root directory of its fileset or the recorded path of a zip
        * entry.
        *
  @@ -81,56 +109,93 @@
        * adm/resource.txt.</p>
        *
        * <p>&quot;/&quot; will be used as the directory separator.</p>
  +     * @return the name of this resource.
        */
       public String getName() {
           return name;
       }
   
       /**
  +     * Set the name of this Resource.
        * @param name relative path of the resource.  Expects
        * &quot;/&quot; to be used as the directory separator.
        */
       public void setName(String name) {
           this.name = name;
       }
  +
       /**
  -     * the exists attribute tells whether a file exists
  +     * The exists attribute tells whether a file exists.
  +     * @return true if this resource exists.
        */
       public boolean isExists() {
           return exists;
       }
   
  +    /**
  +     * Set the exists attribute.
  +     * @param exists if true, this resource exists.
  +     */
       public void setExists(boolean exists) {
           this.exists = exists;
       }
   
       /**
  -     * tells the modification time in milliseconds since 01.01.1970 of
  +     * Tells the modification time in milliseconds since 01.01.1970 .
        *
        * @return 0 if the resource does not exist to mirror the behavior
        * of {@link java.io.File File}.
        */
       public long getLastModified() {
  -        return !exists || lastmodified < 0 ? 0 : lastmodified;
  +        return !exists || lastmodified < 0 ? 0L : lastmodified;
       }
   
  +    /**
  +     * Set the last modification attribute.
  +     * @param lastmodified the modification time in milliseconds since 01.01.1970.
  +     */
       public void setLastModified(long lastmodified) {
           this.lastmodified = lastmodified;
       }
  +
       /**
  -     * tells if the resource is a directory
  -     * @return boolean flag indicating if the resource is a directory
  +     * Tells if the resource is a directory.
  +     * @return boolean flag indicating if the resource is a directory.
        */
       public boolean isDirectory() {
           return directory;
       }
   
  +    /**
  +     * Set the directory attribute.
  +     * @param directory if true, this resource is a directory.
  +     */
       public void setDirectory(boolean directory) {
           this.directory = directory;
       }
   
       /**
  -     * @return copy of this
  +     * Set the size of this Resource.
  +     * @param size the size, as a long.
  +     * @since Ant 1.7
  +     */
  +    public void setSize(long size) {
  +        this.size = (size > UNKNOWN_SIZE) ? size : UNKNOWN_SIZE;
  +    }
  +
  +    /**
  +     * Get the size of this Resource.
  +     * @return the size, as a long, 0 if the Resource does not exist (for
  +     *         compatibility with java.io.File), or UNKNOWN_SIZE if not known.
  +     * @since Ant 1.7
  +     */
  +    public long getSize() {
  +        return (exists) ? size : 0L;
  +    }
  +
  +    /**
  +     * Clone this Resource.
  +     * @return copy of this.
        */
       public Object clone() {
           try {
  @@ -142,8 +207,10 @@
       }
   
       /**
  -     * delegates to a comparison of names.
  -     *
  +     * Delegates to a comparison of names.
  +     * @param other the object to compare to.
  +     * @return a negative integer, zero, or a positive integer as this Resource
  +     *         is less than, equal to, or greater than the specified Resource.
        * @since Ant 1.6
        */
       public int compareTo(Object other) {
  @@ -154,4 +221,5 @@
           Resource r = (Resource) other;
           return getName().compareTo(r.getName());
       }
  +
   }
  
  
  
  No                   revision
  No                   revision
  1.64.2.8  +26 -2     ant/src/main/org/apache/tools/ant/DirectoryScanner.java
  
  Index: DirectoryScanner.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/DirectoryScanner.java,v
  retrieving revision 1.64.2.7
  retrieving revision 1.64.2.8
  diff -u -r1.64.2.7 -r1.64.2.8
  --- DirectoryScanner.java	15 Mar 2004 17:33:24 -0000	1.64.2.7
  +++ DirectoryScanner.java	27 Jan 2005 22:31:07 -0000	1.64.2.8
  @@ -422,7 +422,7 @@
        * @since Ant 1.6
        */
       public static void resetDefaultExcludes() {
  -    defaultExcludes = new Vector();
  +        defaultExcludes = new Vector();
   
           for (int i = 0; i < DEFAULTEXCLUDES.length; i++) {
               defaultExcludes.add(DEFAULTEXCLUDES[i]);
  @@ -1054,6 +1054,18 @@
       }
   
       /**
  +     * Return the count of included files.
  +     * @return <CODE>int</CODE>.
  +     * @since Ant 1.6.3
  +     */
  +    public int getIncludedFilesCount() {
  +        if (filesIncluded == null) {
  +            throw new IllegalStateException();
  +        }
  +        return filesIncluded.size();
  +    }
  +
  +    /**
        * Returns the names of the files which matched none of the include
        * patterns. The names are relative to the base directory. This involves
        * performing a slow scan if one has not already been completed.
  @@ -1122,6 +1134,18 @@
       }
   
       /**
  +     * Return the count of included directories.
  +     * @return <CODE>int</CODE>.
  +     * @since Ant 1.6.3
  +     */
  +    public int getIncludedDirsCount() {
  +        if (dirsIncluded == null) {
  +            throw new IllegalStateException();
  +        }
  +        return dirsIncluded.size();
  +    }
  +
  +    /**
        * Returns the names of the directories which matched none of the include
        * patterns. The names are relative to the base directory. This involves
        * performing a slow scan if one has not already been completed.
  @@ -1203,7 +1227,7 @@
       public Resource getResource(String name) {
           File f = FILE_UTILS.resolveFile(basedir, name);
           return new Resource(name, f.exists(), f.lastModified(),
  -                            f.isDirectory());
  +                            f.isDirectory(), f.length());
       }
   
       /**
  
  
  

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


Mime
View raw message