You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by bo...@apache.org on 2003/02/19 08:57:30 UTC

cvs commit: ant/src/testcases/org/apache/tools/ant/util ResourceUtilsTest.java SourceSelectorTest.java

bodewig     2003/02/18 23:57:30

  Modified:    docs/manual/CoreTasks zip.html
               src/main/org/apache/tools/ant/taskdefs Execute.java Zip.java
               src/main/org/apache/tools/ant/types ZipFileSet.java
               src/main/org/apache/tools/ant/util SourceFileScanner.java
               src/main/org/apache/tools/zip ZipEntry.java
  Added:       src/main/org/apache/tools/ant/util ResourceUtils.java
               src/testcases/org/apache/tools/ant/util
                        ResourceUtilsTest.java
  Removed:     src/main/org/apache/tools/ant/util SourceSelector.java
               src/testcases/org/apache/tools/ant/util
                        SourceSelectorTest.java
  Log:
  Preparing merge to 1.5 branch
  
  Revision  Changes    Path
  1.17      +3 -3      ant/docs/manual/CoreTasks/zip.html
  
  Index: zip.html
  ===================================================================
  RCS file: /home/cvs/ant/docs/manual/CoreTasks/zip.html,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- zip.html	5 Feb 2003 11:20:17 -0000	1.16
  +++ zip.html	19 Feb 2003 07:57:29 -0000	1.17
  @@ -58,7 +58,7 @@
   and set it to UTF8 to create zip files that can safely be read by
   Java.</p>
   
  -<p>Starting with Ant 1.6, &lt;zip&gt; can store Unix permissions
  +<p>Starting with Ant 1.5.2, &lt;zip&gt; can store Unix permissions
   inside the archive (see description of the filemode and dirmode
   attributes for <a href="#zipfileset">&lt;zipfileset&gt;</a>).
   Unfortunately there is no portable way to store these permissions.
  @@ -196,14 +196,14 @@
       <td valign="top">filemode</td>
       <td valign="top">A 3 digit octal string, specify the user, group
       and other modes in the standard Unix fashion.  Only applies to
  -    plain files.  Default is 644. <em>since Ant 1.6</em>.</td>
  +    plain files.  Default is 644. <em>since Ant 1.5.2</em>.</td>
       <td align="center" valign="top">No</td>
     </tr>
     <tr>
       <td valign="top">dirmode</td>
       <td valign="top">A 3 digit octal string, specify the user, group
       and other modes in the standard Unix fashion.  Only applies to
  -    directories.  Default is 755. <em>since Ant 1.6</em>.</td>
  +    directories.  Default is 755. <em>since Ant 1.5.2</em>.</td>
       <td align="center" valign="top">No</td>
     </tr>
   </table>
  
  
  
  1.51      +1 -2      ant/src/main/org/apache/tools/ant/taskdefs/Execute.java
  
  Index: Execute.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Execute.java,v
  retrieving revision 1.50
  retrieving revision 1.51
  diff -u -r1.50 -r1.51
  --- Execute.java	11 Feb 2003 10:08:39 -0000	1.50
  +++ Execute.java	19 Feb 2003 07:57:29 -0000	1.51
  @@ -216,7 +216,6 @@
       private static String[] getProcEnvCommand() {
           if (Os.isFamily("os/2")) {
               // OS/2 - use same mechanism as Windows 2000
  -            // Not sure
               String[] cmd = {"cmd", "/c", "set" };
               return cmd;
           } else if (Os.isFamily("windows")) {
  
  
  
  1.97      +13 -13    ant/src/main/org/apache/tools/ant/taskdefs/Zip.java
  
  Index: Zip.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Zip.java,v
  retrieving revision 1.96
  retrieving revision 1.97
  diff -u -r1.96 -r1.97
  --- Zip.java	17 Feb 2003 13:48:35 -0000	1.96
  +++ Zip.java	19 Feb 2003 07:57:29 -0000	1.97
  @@ -84,7 +84,7 @@
   import org.apache.tools.ant.util.GlobPatternMapper;
   import org.apache.tools.ant.util.IdentityMapper;
   import org.apache.tools.ant.util.MergingMapper;
  -import org.apache.tools.ant.util.SourceSelector;
  +import org.apache.tools.ant.util.ResourceUtils;
   import org.apache.tools.zip.ZipEntry;
   import org.apache.tools.zip.ZipOutputStream;
   
  @@ -521,7 +521,7 @@
        * @param resources the resources to add
        * @param zOut the stream to write to
        *
  -     * @since Ant 1.6
  +     * @since Ant 1.5.2
        */
       protected final void addResources(FileSet fileset, Resource[] resources,
                                         ZipOutputStream zOut)
  @@ -660,7 +660,7 @@
       }
   
       /**
  -     * @since Ant 1.6
  +     * @since Ant 1.5.2
        */
       private synchronized ZipScanner getZipScanner() {
           if (zs == null) {
  @@ -778,10 +778,10 @@
                   }
               }
               newerResources[i] = 
  -                SourceSelector.selectOutOfDateSources(this,
  -                                                      initialResources[i],
  -                                                      myMapper,
  -                                                      getZipScanner());
  +                ResourceUtils.selectOutOfDateSources(this,
  +                                                     initialResources[i],
  +                                                     myMapper,
  +                                                     getZipScanner());
               needsUpdate = needsUpdate || (newerResources[i].length > 0);
   
               if (needsUpdate && !doUpdate) {
  @@ -804,7 +804,7 @@
        *
        * <p>Included directories will preceede included files.</p> 
        *
  -     * @since Ant 1.6
  +     * @since Ant 1.5.2
        */
       protected Resource[][] grabResources(FileSet[] filesets) {
           Resource[][] result = new Resource[filesets.length][];
  @@ -828,7 +828,7 @@
       }
   
       /**
  -     * @since Ant 1.6
  +     * @since Ant 1.5.2
        */
       protected void zipDir(File dir, ZipOutputStream zOut, String vPath,
                             int mode)
  @@ -872,7 +872,7 @@
        * entry from, will be null if we are not copying from an archive.
        * @param mode the Unix permissions to set.
        *
  -     * @since Ant 1.6
  +     * @since Ant 1.5.2
        */
       protected void zipFile(InputStream in, ZipOutputStream zOut, String vPath,
                              long lastModified, File fromArchive, int mode)
  @@ -969,7 +969,7 @@
        * @param vPath the name this entry shall have in the archive
        * @param mode the Unix permissions to set.
        *
  -     * @since Ant 1.6
  +     * @since Ant 1.5.2
        */
       protected void zipFile(File file, ZipOutputStream zOut, String vPath, 
                              int mode)
  @@ -991,7 +991,7 @@
       /**
        * Ensure all parent dirs of a given entry have been added.
        *
  -     * @since Ant 1.6
  +     * @since Ant 1.5.2
        */
       protected final void addParentDirs(File baseDir, String entry,
                                          ZipOutputStream zOut, String prefix,
  @@ -1075,7 +1075,7 @@
       /**
        * @return true if all individual arrays are empty
        * 
  -     * @since Ant 1.6
  +     * @since Ant 1.5.2
        */
       protected final static boolean isEmpty(Resource[][] r) {
           for (int i = 0; i < r.length; i++) {
  
  
  
  1.15      +5 -5      ant/src/main/org/apache/tools/ant/types/ZipFileSet.java
  
  Index: ZipFileSet.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/types/ZipFileSet.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- ZipFileSet.java	10 Feb 2003 14:14:31 -0000	1.14
  +++ ZipFileSet.java	19 Feb 2003 07:57:29 -0000	1.15
  @@ -1,7 +1,7 @@
   /*
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2001-2002 The Apache Software Foundation.  All rights
  + * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -83,7 +83,7 @@
       /**
        * Default value for the dirmode attribute.
        *
  -     * @since Ant 1.6
  +     * @since Ant 1.5.2
        */
       public static final int DEFAULT_DIR_MODE =
           UnixStat.DIR_FLAG  | UnixStat.DEFAULT_DIR_PERM;
  @@ -91,7 +91,7 @@
       /**
        * Default value for the filemode attribute.
        *
  -     * @since Ant 1.6
  +     * @since Ant 1.5.2
        */
       public static final int DEFAULT_FILE_MODE =
           UnixStat.FILE_FLAG | UnixStat.DEFAULT_FILE_PERM;
  @@ -216,7 +216,7 @@
        * other modes in the standard Unix fashion; 
        * optional, default=0644
        *
  -     * @since Ant 1.6
  +     * @since Ant 1.5.2
        */
       public void setFileMode(String octalString) {
           this.fileMode = 
  @@ -224,7 +224,7 @@
       }
       
       /**
  -     * @since Ant 1.6
  +     * @since Ant 1.5.2
        */
       public int getFileMode() {
           return fileMode;
  
  
  
  1.18      +2 -2      ant/src/main/org/apache/tools/ant/util/SourceFileScanner.java
  
  Index: SourceFileScanner.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/util/SourceFileScanner.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- SourceFileScanner.java	10 Feb 2003 14:14:38 -0000	1.17
  +++ SourceFileScanner.java	19 Feb 2003 07:57:30 -0000	1.18
  @@ -115,8 +115,8 @@
           // build the list of sources which are out of date with
           // respect to the target
           Resource[] outofdate = 
  -            SourceSelector.selectOutOfDateSources(task, sourceresources,
  -                                                  mapper, this);
  +            ResourceUtils.selectOutOfDateSources(task, sourceresources,
  +                                                 mapper, this);
           String[] result = new String[outofdate.length];
           for (int counter=0; counter < outofdate.length; counter++) {
               result[counter] = outofdate[counter].getName();
  
  
  
  1.1                  ant/src/main/org/apache/tools/ant/util/ResourceUtils.java
  
  Index: ResourceUtils.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "Ant" and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.tools.ant.util;
  
  import org.apache.tools.ant.Project;
  import org.apache.tools.ant.ProjectComponent;
  import org.apache.tools.ant.taskdefs.condition.Os;
  import org.apache.tools.ant.types.Resource;
  import org.apache.tools.ant.types.ResourceFactory;
  
  import java.io.File;
  import java.util.Vector;
  
  /**
   * this class provides utility methods to process resources
   *
   * @author <a href="mailto:levylambert@tiscali-dsl.de">Antoine Levy-Lambert</a>
   * @since Ant 1.5.2
   */
  public class ResourceUtils {
  
      /**                                                                      {
       * tells which source files should be reprocessed based on the
       * last modification date of target files
       * @param logTo where to send (more or less) interesting output
       * @param source array of resources bearing relative path and last
       * modification date
       * @param mapper filename mapper indicating how to find the target
       * files
       * @param targets object able to map as a resource a relative path
       * at <b>destination</b>
       * @return array containing the source files which need to be
       * copied or processed, because the targets are out of date or do
       * not exist
       */
      public static Resource[] selectOutOfDateSources(ProjectComponent logTo,
                                                      Resource[] source,
                                                      FileNameMapper mapper,
                                                      ResourceFactory targets) {
          long now = (new java.util.Date()).getTime();
          StringBuffer targetList = new StringBuffer();
  
          /*
            If we're on Windows, we have to munge the time up to 2 secs to
            be able to check file modification times.
            (Windows has a max resolution of two secs for modification times)
            Actually this is a feature of the FAT file system, NTFS does
            not have it, so if we could reliably passively test for an NTFS
            file systems we could turn this off...
          */
          if (Os.isFamily("windows")) {
              now += 2000;
          }
  
          Vector vresult = new Vector();
          for (int counter = 0; counter < source.length; counter++) {
              if (source[counter].getLastModified() > now) {
                  logTo.log("Warning: " + source[counter].getName() 
                           + " modified in the future.", 
                           Project.MSG_WARN);
              }
  
              String[] targetnames = 
                  mapper.mapFileName(source[counter].getName()
                                     .replace('/', File.separatorChar));
              if (targetnames != null) {
                  boolean added = false;
                  targetList.setLength(0);
                  for (int ctarget = 0; !added && ctarget < targetnames.length; 
                       ctarget++) {
                      Resource atarget = 
                          targets.getResource(targetnames[ctarget]
                                              .replace(File.separatorChar, '/'));
                      // if the target does not exist, or exists and
                      // is older than the source, then we want to
                      // add the resource to what needs to be copied
                      if (!atarget.isExists()) {
                          logTo.log(source[counter].getName() + " added as " 
                                    + atarget.getName()
                                    + " doesn\'t exist.", Project.MSG_VERBOSE);
                          vresult.addElement(source[counter]);
                          added = true;
                      } else if (atarget.getLastModified() 
                                 < source[counter].getLastModified()) {
                          logTo.log(source[counter].getName() + " added as " 
                                    + atarget.getName()
                                    + " is outdated.", Project.MSG_VERBOSE);
                          vresult.addElement(source[counter]);
                          added = true;
                      } else {
                          if (targetList.length() > 0) {
                              targetList.append(", ");
                          }
                          targetList.append(atarget.getName());
                      }
                  }
  
                  if (!added) {
                      logTo.log(source[counter].getName() 
                                + " omitted as " + targetList.toString()
                                + (targetnames.length == 1 ? " is" : " are ")
                                + " up to date.", Project.MSG_VERBOSE);
                  }
              } else {
                  logTo.log(source[counter].getName() 
                            + " skipped - don\'t know how to handle it",
                            Project.MSG_VERBOSE);
              }
          }
          Resource[] result= new Resource[vresult.size()];
          vresult.copyInto(result);
          return result;
      }
  }
  
  
  
  1.7       +4 -4      ant/src/main/org/apache/tools/zip/ZipEntry.java
  
  Index: ZipEntry.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/zip/ZipEntry.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ZipEntry.java	10 Feb 2003 14:14:43 -0000	1.6
  +++ ZipEntry.java	19 Feb 2003 07:57:30 -0000	1.7
  @@ -1,7 +1,7 @@
   /*
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2001-2002 The Apache Software Foundation.  All rights
  + * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -194,7 +194,7 @@
        * Sets Unix permissions in a way that is understood by Info-Zip's
        * unzip command.
        *
  -     * @since Ant 1.6
  +     * @since Ant 1.5.2
        */
       public void setUnixMode(int mode) {
           setExternalAttributes((mode << 16)
  @@ -212,7 +212,7 @@
        * @return 0 (MS-DOS FAT) unless {@link #setUnixMode setUnixMode}
        * has been called, in which case 3 (Unix) will be returned.
        *
  -     * @since Ant 1.6
  +     * @since Ant 1.5.2
        */
       public int getPlatform() {
           return platform;
  
  
  
  1.1                  ant/src/testcases/org/apache/tools/ant/util/ResourceUtilsTest.java
  
  Index: ResourceUtilsTest.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "Ant" and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.tools.ant.util;
  
  import org.apache.tools.ant.Project;
  import org.apache.tools.ant.taskdefs.Echo;
  import org.apache.tools.ant.types.Resource;
  import org.apache.tools.ant.types.ResourceFactory;
  
  import java.io.File;
  
  import junit.framework.TestCase;
  
  /**
   * Tests for org.apache.tools.ant.util.ResourceUtils.
   */
  public class ResourceUtilsTest extends TestCase
      implements ResourceFactory, FileNameMapper {
  
      private Echo taskINeedForLogging = new Echo();
  
      public ResourceUtilsTest(String name) {
          super(name);
          taskINeedForLogging.setProject(new Project());
      }
  
      public void testNoDuplicates() {
          Resource r = new Resource("samual vimes", true, 1, false);
          Resource[] toNew = 
              ResourceUtils.selectOutOfDateSources(taskINeedForLogging,
                                                   new Resource[] {r},
                                                   this, this);
          assertEquals(1, toNew.length);
      }
  
      /* ============ ResourceFactory interface ====================== */
      public Resource getResource(String name) {
          return new Resource(name); // implies lastModified == 0
      }
  
      /* ============ FileNameMapper interface ======================= */
      public void setFrom(String s) {}
      public void setTo(String s) {}
      public String[] mapFileName(String s) {
          return new String[] {"fred colon", "carrot ironfoundersson"};
      }
  }