Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 228   Methods: 10
NCLOC: 62   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
Sleep.java 100% 94.7% 90% 93.9%
 1   
 /*
 2   
  * The Apache Software License, Version 1.1
 3   
  *
 4   
  * Copyright (c) 2001-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 org.apache.tools.ant.BuildException;
 57   
 import org.apache.tools.ant.Project;
 58   
 import org.apache.tools.ant.Task;
 59   
 
 60   
 /**
 61   
  * Sleep, or pause, for a period of time.
 62   
  *
 63   
  * A task for sleeping a short period of time, useful when a
 64   
  * build or deployment process requires an interval between tasks.
 65   
  *<p>
 66   
  * A negative value can be supplied to any of attributes provided the total sleep time
 67   
  * is positive, pending fundamental changes in physics and JVM
 68   
  * execution tims</p>
 69   
  * Note that sleep times are always hints to be interpred by the OS how it feels
 70   
  * small times may either be ignored or rounded up to a minimum timeslice. Note
 71   
  * also that the system clocks often have a fairly low granularity too, which complicates
 72   
  * measuring how long a sleep actually took.</p>
 73   
  *
 74   
  * @author steve_l@iseran.com steve loughran
 75   
  * @since Ant 1.4
 76   
  * @ant.task category="utility"
 77   
  */
 78   
 
 79   
 public class Sleep extends Task {
 80   
     /**
 81   
      * failure flag
 82   
      */
 83   
     private boolean failOnError = true;
 84   
 
 85   
     /**
 86   
      * sleep seconds
 87   
      */
 88   
     private int seconds = 0;
 89   
 
 90   
     /**
 91   
      * sleep hours
 92   
      */
 93   
     private int hours = 0;
 94   
     /**
 95   
      * sleep minutes
 96   
      */
 97   
     private int minutes = 0;
 98   
 
 99   
     /**
 100   
      * sleep milliseconds
 101   
      */
 102   
     private int milliseconds = 0;
 103   
 
 104   
 
 105   
 
 106   
     /**
 107   
      * Creates new instance
 108   
      */
 109  52
     public Sleep() {
 110   
     }
 111   
 
 112   
 
 113   
     /**
 114   
      * seconds to add to the sleep time
 115   
      *
 116   
      * @param seconds The new Seconds value
 117   
      */
 118  35
     public void setSeconds(int seconds) {
 119  35
         this.seconds = seconds;
 120   
     }
 121   
 
 122   
 
 123   
     /**
 124   
      * hours to add to the sleep time.
 125   
      *
 126   
      * @param hours The new Hours value
 127   
      */
 128  0
     public void setHours(int hours) {
 129  0
         this.hours = hours;
 130   
     }
 131   
 
 132   
 
 133   
     /**
 134   
      * minutes to add to the sleep time
 135   
      *
 136   
      * @param minutes The new Minutes value
 137   
      */
 138  2
     public void setMinutes(int minutes) {
 139  2
         this.minutes = minutes;
 140   
     }
 141   
 
 142   
 
 143   
     /**
 144   
      * milliseconds to add to the sleep time
 145   
      *
 146   
      * @param milliseconds The new Milliseconds value
 147   
      */
 148  16
     public void setMilliseconds(int milliseconds) {
 149  16
         this.milliseconds = milliseconds;
 150   
     }
 151   
 
 152   
 
 153   
     /**
 154   
      * sleep for a period of time
 155   
      *
 156   
      * @param millis time to sleep
 157   
      */
 158  50
     public void doSleep(long millis) {
 159  50
         try {
 160  50
             Thread.sleep(millis);
 161   
         } catch (InterruptedException ie) {
 162   
         }
 163   
     }
 164   
 
 165   
 
 166   
     /**
 167   
      * flag controlling whether to break the build on an error.
 168   
      *
 169   
      * @param failOnError The new FailOnError value
 170   
      */
 171  1
     public void setFailOnError(boolean failOnError) {
 172  1
         this.failOnError = failOnError;
 173   
     }
 174   
 
 175   
 
 176   
     /**
 177   
      * return time to sleep
 178   
      *
 179   
      * @return sleep time. if below 0 then there is an error
 180   
      */
 181   
 
 182  102
     private long getSleepTime() {
 183  102
         return ((((long) hours * 60) + minutes) * 60 + seconds) * 1000
 184   
             + milliseconds;
 185   
     }
 186   
 
 187   
 
 188   
     /**
 189   
      * verify parameters
 190   
      *
 191   
      * @throws BuildException if something is invalid
 192   
      */
 193  52
     public void validate()
 194   
         throws BuildException {
 195  52
         if (getSleepTime() < 0) {
 196  2
             throw new BuildException("Negative sleep periods are not "
 197   
                                      + "supported");
 198   
         }
 199   
     }
 200   
 
 201   
 
 202   
     /**
 203   
      * Executes this build task. Throws org.apache.tools.ant.BuildException
 204   
      * if there is an error during task execution.
 205   
      *
 206   
      * @exception BuildException Description of Exception
 207   
      */
 208  52
     public void execute()
 209   
         throws BuildException {
 210  52
         try {
 211  52
             validate();
 212  50
             long sleepTime = getSleepTime();
 213  50
             log("sleeping for " + sleepTime + " milliseconds",
 214   
                 Project.MSG_VERBOSE);
 215  50
             doSleep(sleepTime);
 216   
         } catch (Exception e) {
 217  2
             if (failOnError) {
 218  1
                 throw new BuildException(e);
 219   
             } else {
 220  1
                 String text = e.toString();
 221  1
                 log(text, Project.MSG_ERR);
 222   
             }
 223   
         }
 224   
     }
 225   
 
 226   
 }
 227   
 
 228