Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 164   Methods: 5
NCLOC: 53   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
P4Counter.java 0% 0% 0% 0%
 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   
 /*
 55   
  * Portions of this software are based upon public domain software
 56   
  * originally written at the National Center for Supercomputing Applications,
 57   
  * University of Illinois, Urbana-Champaign.
 58   
  */
 59   
 
 60   
 package org.apache.tools.ant.taskdefs.optional.perforce;
 61   
 
 62   
 import org.apache.tools.ant.BuildException;
 63   
 import org.apache.tools.ant.Project;
 64   
 
 65   
 /**
 66   
  * Obtains or sets the value of a counter.
 67   
  *
 68   
  * <p> When used in its base form
 69   
  * (where only the counter name is provided), the counter value will be
 70   
  * printed to the output stream. When the value is provided, the counter
 71   
  * will be set to the value provided. When a property name is provided,
 72   
  * the property will be filled with the value of the counter. You may
 73   
  * not specify to both get and set the value of the counter in the same
 74   
  * Task.
 75   
  * </p>
 76   
  * <P>
 77   
  * The user performing this task must have Perforce &quot;review&quot; permissions
 78   
  * as defined by Perforce protections in order for this task to succeed.
 79   
 </P>
 80   
 
 81   
  * Example Usage:<br>
 82   
  * &lt;p4counter name="${p4.counter}" property=${p4.change}"/&gt;
 83   
  * @author <a href="mailto:kirk@radik.com">Kirk Wylie</a>
 84   
  *
 85   
  * @ant.task category="scm"
 86   
  */
 87   
 
 88   
 public class P4Counter extends P4Base {
 89   
     public String counter = null;
 90   
     public String property = null;
 91   
     public boolean shouldSetValue = false;
 92   
     public boolean shouldSetProperty = false;
 93   
     public int value = 0;
 94   
 
 95   
     /**
 96   
      * The name of the counter; required
 97   
      */
 98  0
     public void setName(String counter) {
 99  0
         this.counter = counter;
 100   
     }
 101   
 
 102   
     /**
 103   
      * The new value for the counter; optional.
 104   
      */
 105  0
     public void setValue(int value) {
 106  0
         this.value = value;
 107  0
         shouldSetValue = true;
 108   
     }
 109   
 
 110   
     /**
 111   
      * A property to be set with the value of the counter
 112   
      */
 113  0
     public void setProperty(String property) {
 114  0
         this.property = property;
 115  0
         shouldSetProperty = true;
 116   
     }
 117   
 
 118   
     /**
 119   
      * again, properties are mutable in this tsk
 120   
      */
 121  0
     public void execute() throws BuildException {
 122   
 
 123  0
         if ((counter == null) || counter.length() == 0) {
 124  0
             throw new BuildException("No counter specified to retrieve");
 125   
         }
 126   
 
 127  0
         if (shouldSetValue && shouldSetProperty) {
 128  0
             throw new BuildException("Cannot both set the value of the property and retrieve the value of the property.");
 129   
         }
 130   
 
 131  0
         String command = "counter " + P4CmdOpts + " " + counter;
 132  0
         if (!shouldSetProperty) {
 133   
             // NOTE kirk@radik.com 04-April-2001 -- If you put in the -s, you
 134   
             // have to start running through regular expressions here. Much easier
 135   
             // to just not include the scripting information than to try to add it
 136   
             // and strip it later.
 137  0
             command = "-s " + command;
 138   
         }
 139  0
         if (shouldSetValue) {
 140  0
             command += " " + value;
 141   
         }
 142   
 
 143  0
         if (shouldSetProperty) {
 144  0
             final Project myProj = getProject();
 145   
 
 146  0
             P4Handler handler = new P4HandlerAdapter() {
 147  0
                 public void process(String line) {
 148  0
                     log("P4Counter retrieved line \"" + line + "\"", Project.MSG_VERBOSE);
 149  0
                     try {
 150  0
                         value = Integer.parseInt(line);
 151  0
                         myProj.setProperty(property, "" + value);
 152   
                     } catch (NumberFormatException nfe) {
 153  0
                         throw new BuildException("Perforce error. Could not retrieve counter value.");
 154   
                     }
 155   
                 }
 156   
             };
 157   
 
 158  0
             execP4Command(command, handler);
 159   
         } else {
 160  0
             execP4Command(command, new SimpleP4OutputHandler(this));
 161   
         }
 162   
     }
 163   
 }
 164