Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 210   Methods: 9
NCLOC: 75   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
War.java 50% 67.9% 66.7% 64.4%
 1   
 /*
 2   
  * The Apache Software License, Version 1.1
 3   
  *
 4   
  * Copyright (c) 2000-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   
 
 55   
 package org.apache.tools.ant.taskdefs;
 56   
 
 57   
 import java.io.File;
 58   
 import java.io.IOException;
 59   
 import org.apache.tools.ant.BuildException;
 60   
 import org.apache.tools.ant.Project;
 61   
 import org.apache.tools.ant.types.ZipFileSet;
 62   
 import org.apache.tools.ant.util.FileUtils;
 63   
 import org.apache.tools.zip.ZipOutputStream;
 64   
 
 65   
 
 66   
 /**
 67   
  * An extension of &lt;jar&gt; to create a WAR archive.
 68   
  * Contains special treatment for files that should end up in the
 69   
  * <code>WEB-INF/lib</code>, <code>WEB-INF/classes</code> or
 70   
  * <code>WEB-INF</code> directories of the Web Application Archive.</p>
 71   
  * <p>(The War task is a shortcut for specifying the particular layout of a WAR file.
 72   
  * The same thing can be accomplished by using the <i>prefix</i> and <i>fullpath</i>
 73   
  * attributes of zipfilesets in a Zip or Jar task.)</p>
 74   
  * <p>The extended zipfileset element from the zip task (with attributes <i>prefix</i>, <i>fullpath</i>, and <i>src</i>) is available in the War task.</p>
 75   
  *
 76   
  * @author Stefan Bodewig
 77   
  *
 78   
  * @since Ant 1.2
 79   
  *
 80   
  * @ant.task category="packaging"
 81   
  * @see Jar
 82   
  */
 83   
 public class War extends Jar {
 84   
 
 85   
     /**
 86   
      * our web.xml deployment descriptor
 87   
      */
 88   
     private File deploymentDescriptor;
 89   
 
 90   
     /**
 91   
      * flag set if the descriptor is added
 92   
      */
 93   
     private boolean descriptorAdded;
 94   
 
 95   
     private static final FileUtils fu = FileUtils.newFileUtils();
 96   
 
 97  1
     public War() {
 98  1
         super();
 99  1
         archiveType = "war";
 100  1
         emptyBehavior = "create";
 101   
     }
 102   
 
 103   
     /**
 104   
      * <i>Deprecated<i> name of the file to create
 105   
      * -use <tt>destfile</tt> instead.
 106   
      * @deprecated Use setDestFile(File) instead
 107   
      * @ant.attribute ignore="true"
 108   
      */
 109  0
     public void setWarfile(File warFile) {
 110  0
         setDestFile(warFile);
 111   
     }
 112   
 
 113   
     /**
 114   
      * set the deployment descriptor to use (WEB-INF/web.xml);
 115   
      * required unless <tt>update=true</tt>
 116   
      */
 117  1
     public void setWebxml(File descr) {
 118  1
         deploymentDescriptor = descr;
 119  1
         if (!deploymentDescriptor.exists()) {
 120  0
             throw new BuildException("Deployment descriptor: "
 121   
                                      + deploymentDescriptor
 122   
                                      + " does not exist.");
 123   
         }
 124   
 
 125   
         // Create a ZipFileSet for this file, and pass it up.
 126  1
         ZipFileSet fs = new ZipFileSet();
 127  1
         fs.setFile(deploymentDescriptor);
 128  1
         fs.setFullpath("WEB-INF/web.xml");
 129  1
         super.addFileset(fs);
 130   
     }
 131   
 
 132   
     /**
 133   
      * add files under WEB-INF/lib/
 134   
      */
 135   
 
 136  1
     public void addLib(ZipFileSet fs) {
 137   
         // We just set the prefix for this fileset, and pass it up.
 138  1
         fs.setPrefix("WEB-INF/lib/");
 139  1
         super.addFileset(fs);
 140   
     }
 141   
 
 142   
     /**
 143   
      * add files under WEB-INF/classes
 144   
      */
 145  0
     public void addClasses(ZipFileSet fs) {
 146   
         // We just set the prefix for this fileset, and pass it up.
 147  0
         fs.setPrefix("WEB-INF/classes/");
 148  0
         super.addFileset(fs);
 149   
     }
 150   
 
 151   
     /**
 152   
      * files to add under WEB-INF;
 153   
      */
 154  0
     public void addWebinf(ZipFileSet fs) {
 155   
         // We just set the prefix for this fileset, and pass it up.
 156  0
         fs.setPrefix("WEB-INF/");
 157  0
         super.addFileset(fs);
 158   
     }
 159   
 
 160   
     /**
 161   
      * override of  parent; validates configuration
 162   
      * before initializing the output stream.
 163   
      */
 164  1
     protected void initZipOutputStream(ZipOutputStream zOut)
 165   
         throws IOException, BuildException {
 166   
         // If no webxml file is specified, it's an error.
 167  1
         if (deploymentDescriptor == null && !isInUpdateMode()) {
 168  0
             throw new BuildException("webxml attribute is required", getLocation());
 169   
         }
 170   
 
 171  1
         super.initZipOutputStream(zOut);
 172   
     }
 173   
 
 174   
     /**
 175   
      * Overriden from Zip class to deal with web.xml
 176   
      */
 177  1
     protected void zipFile(File file, ZipOutputStream zOut, String vPath, 
 178   
                            int mode)
 179   
         throws IOException {
 180   
         // If the file being added is WEB-INF/web.xml, we warn if it's
 181   
         // not the one specified in the "webxml" attribute - or if
 182   
         // it's being added twice, meaning the same file is specified
 183   
         // by the "webxml" attribute and in a <fileset> element.
 184  1
         if (vPath.equalsIgnoreCase("WEB-INF/web.xml"))  {
 185  1
             if (deploymentDescriptor == null
 186   
                 || !fu.fileNameEquals(deploymentDescriptor, file)
 187   
                 || descriptorAdded) {
 188  0
                 log("Warning: selected " + archiveType
 189   
                     + " files include a WEB-INF/web.xml which will be ignored "
 190   
                     + "(please use webxml attribute to "
 191   
                     + archiveType + " task)", Project.MSG_WARN);
 192   
             } else {
 193  1
                 super.zipFile(file, zOut, vPath, mode);
 194  1
                 descriptorAdded = true;
 195   
             }
 196   
         } else {
 197  0
             super.zipFile(file, zOut, vPath, mode);
 198   
         }
 199   
     }
 200   
 
 201   
     /**
 202   
      * Make sure we don't think we already have a web.xml next time this task
 203   
      * gets executed.
 204   
      */
 205  1
     protected void cleanUp() {
 206  1
         descriptorAdded = false;
 207  1
         super.cleanUp();
 208   
     }
 209   
 }
 210