Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 272   Methods: 16
NCLOC: 106   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ZipFileSet.java 66.7% 68.2% 75% 69.4%
 1   
 /*
 2   
  * The Apache Software License, Version 1.1
 3   
  *
 4   
  * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
 5   
  * reserved.
 6   
  *
 7   
  * Redistribution and use in source and binary forms, with or without
 8   
  * modification, are permitted provided that the following conditions
 9   
  * are met:
 10   
  *
 11   
  * 1. Redistributions of source code must retain the above copyright
 12   
  *    notice, this list of conditions and the following disclaimer.
 13   
  *
 14   
  * 2. Redistributions in binary form must reproduce the above copyright
 15   
  *    notice, this list of conditions and the following disclaimer in
 16   
  *    the documentation and/or other materials provided with the
 17   
  *    distribution.
 18   
  *
 19   
  * 3. The end-user documentation included with the redistribution, if
 20   
  *    any, must include the following acknowlegement:
 21   
  *       "This product includes software developed by the
 22   
  *        Apache Software Foundation (http://www.apache.org/)."
 23   
  *    Alternately, this acknowlegement may appear in the software itself,
 24   
  *    if and wherever such third-party acknowlegements normally appear.
 25   
  *
 26   
  * 4. The names "Ant" and "Apache Software
 27   
  *    Foundation" must not be used to endorse or promote products derived
 28   
  *    from this software without prior written permission. For written
 29   
  *    permission, please contact apache@apache.org.
 30   
  *
 31   
  * 5. Products derived from this software may not be called "Apache"
 32   
  *    nor may "Apache" appear in their names without prior written
 33   
  *    permission of the Apache Group.
 34   
  *
 35   
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 36   
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 37   
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 38   
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 39   
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 40   
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 41   
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 42   
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 43   
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 44   
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 45   
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 46   
  * SUCH DAMAGE.
 47   
  * ====================================================================
 48   
  *
 49   
  * This software consists of voluntary contributions made by many
 50   
  * individuals on behalf of the Apache Software Foundation.  For more
 51   
  * information on the Apache Software Foundation, please see
 52   
  * <http://www.apache.org/>.
 53   
  */
 54   
 package org.apache.tools.ant.types;
 55   
 
 56   
 import java.io.File;
 57   
 import java.util.Stack;
 58   
 import org.apache.tools.ant.BuildException;
 59   
 import org.apache.tools.ant.DirectoryScanner;
 60   
 import org.apache.tools.ant.Project;
 61   
 import org.apache.tools.zip.UnixStat;
 62   
 
 63   
 /**
 64   
  * A ZipFileSet is a FileSet with extra attributes useful in the context of
 65   
  * Zip/Jar tasks.
 66   
  *
 67   
  * A ZipFileSet extends FileSets with the ability to extract a subset of the
 68   
  * entries of a Zip file for inclusion in another Zip file.  It also includes
 69   
  * a prefix attribute which is prepended to each entry in the output Zip file.
 70   
  *
 71   
  * At present, ZipFileSets are not surfaced in the public API.  FileSets
 72   
  * nested in a Zip task are instantiated as ZipFileSets, and their attributes
 73   
  * are only recognized in the context of the the Zip task.
 74   
  * It is not possible to define a ZipFileSet outside of the Zip task and
 75   
  * refer to it via a refid.  However a standard FileSet may be included by
 76   
  * reference in the Zip task, and attributes in the refering ZipFileSet
 77   
  * can augment FileSet definition.
 78   
  *
 79   
  * @author Don Ferguson <a href="mailto:don@bea.com">don@bea.com</a>
 80   
  */
 81   
 public class ZipFileSet extends FileSet {
 82   
 
 83   
     /**
 84   
      * Default value for the dirmode attribute.
 85   
      *
 86   
      * @since Ant 1.5.2
 87   
      */
 88   
     public static final int DEFAULT_DIR_MODE =
 89   
         UnixStat.DIR_FLAG  | UnixStat.DEFAULT_DIR_PERM;
 90   
 
 91   
     /**
 92   
      * Default value for the filemode attribute.
 93   
      *
 94   
      * @since Ant 1.5.2
 95   
      */
 96   
     public static final int DEFAULT_FILE_MODE =
 97   
         UnixStat.FILE_FLAG | UnixStat.DEFAULT_FILE_PERM;
 98   
 
 99   
     private File srcFile          = null;
 100   
     private String prefix         = "";
 101   
     private String fullpath       = "";
 102   
     private boolean hasDir        = false;
 103   
     private int fileMode          = DEFAULT_FILE_MODE;
 104   
     private int dirMode           = DEFAULT_DIR_MODE;
 105   
 
 106  19
     public ZipFileSet() {
 107  19
         super();
 108   
     }
 109   
 
 110  0
     protected ZipFileSet(FileSet fileset) {
 111  0
         super(fileset);
 112   
     }
 113   
 
 114  0
     protected ZipFileSet(ZipFileSet fileset) {
 115  0
         super(fileset);
 116  0
         srcFile = fileset.srcFile;
 117  0
         prefix = fileset.prefix;
 118  0
         fullpath = fileset.fullpath;
 119  0
         hasDir = fileset.hasDir;
 120  0
         fileMode = fileset.fileMode;
 121  0
         dirMode = fileset.dirMode;
 122   
     }
 123   
 
 124   
     /**
 125   
      * Set the directory for the fileset.  Prevents both "dir" and "src"
 126   
      * from being specified.
 127   
      */
 128  2
     public void setDir(File dir) throws BuildException {
 129  2
         if (srcFile != null) {
 130  0
             throw new BuildException("Cannot set both dir and src attributes");
 131   
         } else {
 132  2
             super.setDir(dir);
 133  2
             hasDir = true;
 134   
         }
 135   
     }
 136   
 
 137   
     /**
 138   
      * Set the source Zip file for the zipfileset.  Prevents both
 139   
      * "dir" and "src" from being specified.
 140   
      *
 141   
      * @param srcFile The zip file from which to extract entries.
 142   
      */
 143  16
     public void setSrc(File srcFile) {
 144  16
         if (hasDir) {
 145  0
             throw new BuildException("Cannot set both dir and src attributes");
 146   
         }
 147  16
         this.srcFile = srcFile;
 148   
     }
 149   
 
 150   
     /**
 151   
      * Get the zip file from which entries will be extracted.
 152   
      * References are not followed, since it is not possible
 153   
      * to have a reference to a ZipFileSet, only to a FileSet.
 154   
      */
 155  272
     public File getSrc() {
 156  272
         return srcFile;
 157   
     }
 158   
 
 159   
     /**
 160   
      * Prepend this prefix to the path for each zip entry.
 161   
      * Does not perform reference test; the referenced file set
 162   
      * can be augmented with a prefix.
 163   
      *
 164   
      * @param prefix The prefix to prepend to entries in the zip file.
 165   
      */
 166  2
     public void setPrefix(String prefix) {
 167  2
         this.prefix = prefix;
 168   
     }
 169   
 
 170   
     /**
 171   
      * Return the prefix prepended to entries in the zip file.
 172   
      */
 173  28
     public String getPrefix() {
 174  28
         return prefix;
 175   
     }
 176   
 
 177   
     /**
 178   
      * Set the full pathname of the single entry in this fileset.
 179   
      *
 180   
      * @param fullpath the full pathname of the single entry in this fileset.
 181   
      */
 182  1
     public void setFullpath(String fullpath) {
 183  1
         this.fullpath = fullpath;
 184   
     }
 185   
 
 186   
     /**
 187   
      * Return the full pathname of the single entry in this fileset.
 188   
      */
 189  28
     public String getFullpath() {
 190  28
         return fullpath;
 191   
     }
 192   
 
 193   
     /**
 194   
      * Return the DirectoryScanner associated with this FileSet.
 195   
      * If the ZipFileSet defines a source Zip file, then a ZipScanner
 196   
      * is returned instead.
 197   
      */
 198  19
     public DirectoryScanner getDirectoryScanner(Project p) {
 199  19
         if (isReference()) {
 200  1
             return getRef(p).getDirectoryScanner(p);
 201   
         }
 202  18
         if (srcFile != null) {
 203  16
             ZipScanner zs = new ZipScanner();
 204  16
             zs.setSrc(srcFile);
 205  16
             super.setDir(p.getBaseDir());
 206  16
             setupDirectoryScanner(zs, p);
 207  16
             zs.init();
 208  16
             return zs;
 209   
         } else {
 210  2
             return super.getDirectoryScanner(p);
 211   
         }
 212   
     }
 213   
 
 214   
     /**
 215   
      * A 3 digit octal string, specify the user, group and 
 216   
      * other modes in the standard Unix fashion; 
 217   
      * optional, default=0644
 218   
      *
 219   
      * @since Ant 1.5.2
 220   
      */
 221  0
     public void setFileMode(String octalString) {
 222  0
         this.fileMode = 
 223   
             UnixStat.FILE_FLAG | Integer.parseInt(octalString, 8);
 224   
     }
 225   
     
 226   
     /**
 227   
      * @since Ant 1.5.2
 228   
      */
 229  16
     public int getFileMode() {
 230  16
         return fileMode;
 231   
     }
 232   
     
 233   
     /**
 234   
      * A 3 digit octal string, specify the user, group and 
 235   
      * other modes in the standard Unix fashion; 
 236   
      * optional, default=0755
 237   
      *
 238   
      * @since Ant 1.6
 239   
      */
 240  0
     public void setDirMode(String octalString) {
 241  0
         this.dirMode = 
 242   
             UnixStat.DIR_FLAG | Integer.parseInt(octalString, 8);
 243   
     }
 244   
     
 245   
     /**
 246   
      * @since Ant 1.6
 247   
      */
 248  16
     public int getDirMode() {
 249  16
         return dirMode;
 250   
     }
 251   
 
 252   
     /**
 253   
      * A ZipFileset can accept any fileset as a reference as it just uses the
 254   
      * standard directory scanner.
 255   
      */
 256  1
     protected AbstractFileSet getRef(Project p) {
 257  1
         if (!isChecked()) {
 258  1
             Stack stk = new Stack();
 259  1
             stk.push(this);
 260  1
             dieOnCircularReference(stk, p);
 261   
         }
 262   
 
 263  1
         Object o = getRefid().getReferencedObject(p);
 264  1
         if (!(o instanceof FileSet)) {
 265  0
             String msg = getRefid().getRefId() + " doesn\'t denote a fileset";
 266  0
             throw new BuildException(msg);
 267   
         } else {
 268  1
             return (AbstractFileSet) o;
 269   
         }
 270   
     }
 271   
 }
 272