Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 161   Methods: 5
NCLOC: 34   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
TempFile.java 0% 0% 0% 0%
 1   
 /*
 2   
  *  The Apache Software License, Version 1.1
 3   
  *
 4   
  *  Copyright (c) 2002 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.taskdefs;
 55   
 
 56   
 import java.io.File;
 57   
 import org.apache.tools.ant.BuildException;
 58   
 import org.apache.tools.ant.Task;
 59   
 import org.apache.tools.ant.util.FileUtils;
 60   
 
 61   
 /**
 62   
  *  This task sets a property to  the name of a temporary file. 
 63   
  *  Unlike the Java1.2 method to create a temporary file, this task
 64   
  *  does work on Java1.1. Also, it does not actually create the
 65   
  *  temporary file, but it does guarantee that the file did not
 66   
  *  exist when the task was executed. 
 67   
  * <p>  
 68   
  * Examples
 69   
  * <pre>&lt;tempfile property="temp.file" /&gt;</pre>
 70   
  * create a temporary file
 71   
  * <pre>&lt;tempfile property="temp.file" suffix=".xml" /&gt;</pre>
 72   
  * create a temporary file with the .xml suffix.
 73   
  * <pre>&lt;tempfile property="temp.file" destDir="build"/&gt;</pre>
 74   
  * create a temp file in the build subdir
 75   
  *@author      steve loughran
 76   
  *@since       Ant 1.5
 77   
  *@ant.task
 78   
  */
 79   
 
 80   
 public class TempFile extends Task {
 81   
 
 82   
     /**
 83   
      * Name of property to set.
 84   
      */
 85   
     private String property;
 86   
 
 87   
     /**
 88   
      * Directory to create the file in. Can be null.
 89   
      */
 90   
     private File destDir = null;
 91   
 
 92   
     /**
 93   
      * Prefix for the file.
 94   
      */
 95   
     private String prefix;
 96   
 
 97   
     /**
 98   
      * Suffix for the file.
 99   
      */
 100   
     private String suffix = "";
 101   
 
 102   
 
 103   
     /**
 104   
      * Sets the property you wish to assign the temporary file to.
 105   
      *
 106   
      * @param  property  The property to set
 107   
      */
 108  0
     public void setProperty(String property) {
 109  0
         this.property = property;
 110   
     }
 111   
 
 112   
 
 113   
     /**
 114   
      * Sets the destination directory. If null, 
 115   
      * the parent directory is used instead.
 116   
      *
 117   
      * @param  destDir  The new destDir value
 118   
      */
 119  0
     public void setDestDir(File destDir) {
 120  0
         this.destDir = destDir;
 121   
     }
 122   
 
 123   
 
 124   
     /**
 125   
      * Sets the optional prefix string.
 126   
      *
 127   
      * @param  prefix  string to prepend to generated string
 128   
      */
 129  0
     public void setPrefix(String prefix) {
 130  0
         this.prefix = prefix;
 131   
     }
 132   
 
 133   
 
 134   
     /**
 135   
      * Sets the suffix string for the temp file (optional)
 136   
      *
 137   
      * @param  suffix  suffix including any "." , e.g ".xml"
 138   
      */
 139  0
     public void setSuffix(String suffix) {
 140  0
         this.suffix = suffix;
 141   
     }
 142   
 
 143   
 
 144   
     /**
 145   
      * Creates the temporary file.
 146   
      *
 147   
      *@exception  BuildException  if something goes wrong with the build
 148   
      */
 149  0
     public void execute() throws BuildException {
 150  0
         if (property == null || property.length() == 0) {
 151  0
             throw new BuildException("no property specified");
 152   
         }
 153  0
         if (destDir == null) {
 154  0
             destDir = getProject().resolveFile(".");
 155   
         }
 156  0
         FileUtils utils = FileUtils.newFileUtils();
 157  0
         File tfile = utils.createTempFile(prefix, suffix, destDir);
 158  0
         getProject().setNewProperty(property, tfile.toString());
 159   
     }
 160   
 }
 161