Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 227   Methods: 7
NCLOC: 67   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
StarTeamLabel.java 0% 0% 0% 0%
 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.optional.starteam;
 55   
 
 56   
 import com.starbase.starteam.Label;
 57   
 import com.starbase.starteam.View;
 58   
 import com.starbase.starteam.ViewConfiguration;
 59   
 import com.starbase.util.OLEDate;
 60   
 import java.text.ParseException;
 61   
 import java.text.SimpleDateFormat;
 62   
 import java.util.Date;
 63   
 import org.apache.tools.ant.BuildException;
 64   
 
 65   
 /**
 66   
  * Creates a view label in StarTeam at the specified view.
 67   
  *
 68   
  * Ant Usage:
 69   
  * <pre>
 70   
  * &lt;taskdef name="stlabel"
 71   
  *          classname="org.apache.tools.ant.taskdefs.optional.starteam.StarTeamLabel"/&lt;
 72   
  *     &lt;stlabel
 73   
  * label="1.0" lastbuild="20011514100000" description="Successful Build"
 74   
  * username="BuildMaster" password="ant"
 75   
  * starteamurl="server:port/project/view"/&gt;
 76   
  * </pre>
 77   
  *
 78   
  * @author Christopher Charlier, ThoughtWorks, Inc. 2001
 79   
  * @author <a href="mailto:jcyip@thoughtworks.com">Jason Yip</a>
 80   
  * @see <A HREF="http://www.starbase.com/">StarBase Web Site</A>
 81   
  *
 82   
  * @ant.task name="stlabel" category="scm"
 83   
  */
 84   
 public class StarTeamLabel extends StarTeamTask {
 85   
 
 86   
     /**
 87   
      * The name of the label to be set in Starteam.
 88   
      */
 89   
     private String labelName;
 90   
 
 91   
     /**
 92   
      * The label description to be set in Starteam.
 93   
      */
 94   
     private String description;
 95   
 
 96   
     /**
 97   
      * If true, this will be a build label.  If false, it will be a build
 98   
      * label.  The default is false.  Has no effect if revision label is
 99   
      * true.
 100   
      */
 101   
     private boolean buildlabel = false;
 102   
     
 103   
     /**
 104   
      * If true, this will be a revision label.  If false, it will be a build
 105   
      * label.  The default is false.
 106   
      */
 107   
     private boolean revisionlabel = false;
 108   
 
 109   
     /**
 110   
      * The time of the last successful. The new label will be a snapshot of the
 111   
      * repository at this time. String should be formatted as "yyyyMMddHHmmss"
 112   
      */
 113   
     private OLEDate lastBuild = null;
 114   
 
 115   
     private static final SimpleDateFormat DATE_FORMAT =
 116   
             new SimpleDateFormat("yyyyMMddHHmmss");
 117   
 
 118   
 
 119   
     /**
 120   
     * The name to be given to the label; required.
 121   
     */
 122  0
     public void setLabel(String label) {
 123  0
         this.labelName = label;
 124   
     }
 125   
 
 126   
     /**
 127   
      * Optional description of the label to be stored in the StarTeam project.
 128   
      */
 129  0
     public void setDescription(String description) {
 130  0
         this.description = description;
 131   
     }
 132   
 
 133   
     /**
 134   
      * set the type of label based on the supplied value - if true, this 
 135   
      * label will be a revision label, if false, a build label.
 136   
      * 
 137   
      * @param revision If true this will be a revision label; if false, 
 138   
      * a build label
 139   
      */
 140  0
     public void setBuildLabel( boolean buildlabel ) {
 141  0
         this.buildlabel = buildlabel;
 142   
     }
 143   
     
 144   
     /**
 145   
      * set the type of label based on the supplied value - if true, this 
 146   
      * label will be a revision label, if false, a build label.
 147   
      * 
 148   
      * @param revision If true this will be a revision label; if false, 
 149   
      * a build label
 150   
      */
 151  0
     public void setRevisionLabel( boolean revisionlabel ) {
 152  0
         this.revisionlabel = revisionlabel;
 153   
     }
 154   
 
 155   
 
 156   
 
 157   
     /**
 158   
      * The timestamp of the build that will be stored with the label; required.  
 159   
      * Must be formatted <code>yyyyMMddHHmmss</code>
 160   
      */
 161  0
     public void setLastBuild(String lastbuild) throws BuildException {
 162  0
         try {
 163  0
             Date lastBuildTime = DATE_FORMAT.parse(lastbuild);
 164  0
             this.lastBuild = new OLEDate(lastBuildTime);
 165   
         } catch (ParseException e) {
 166  0
             throw new BuildException("Unable to parse the date '" + 
 167   
                                      lastbuild + "'", e);
 168   
         }
 169   
     }
 170   
 
 171   
     /**
 172   
      * This method does the work of creating the new view and checking it into
 173   
      * Starteam.
 174   
      *
 175   
      */
 176  0
     public void execute() throws BuildException {
 177   
 
 178  0
         if (this.revisionlabel && this.buildlabel) {
 179  0
             throw new BuildException(
 180   
                 "'revisionlabel' and 'buildlabel' both specified.  " +
 181   
                 "A revision label cannot be a build label.");
 182   
         }
 183   
 
 184  0
         View snapshot = openView();
 185   
 
 186   
         // Create the new label and update the repository
 187   
 
 188  0
         if (this.revisionlabel) {
 189  0
             new Label(snapshot, this.labelName, this.description).update();
 190  0
             log("Created Revision Label " + this.labelName);
 191   
         } 
 192  0
         else if (null != lastBuild){
 193  0
             new Label(snapshot, this.labelName, this.description,this.lastBuild,
 194   
                       this.buildlabel).update();
 195  0
             log("Created View Label (" 
 196   
                 +(this.buildlabel ? "" : "non-") + "build) " + this.labelName
 197   
                 +" as of " + this.lastBuild.toString());
 198   
         }
 199   
         else {
 200  0
             new Label(snapshot, this.labelName, this.description,
 201   
                       this.buildlabel).update();
 202  0
             log("Created View Label (" 
 203   
                 +(this.buildlabel ? "" : "non-") + "build) " + this.labelName);
 204   
         }
 205   
     }
 206   
 
 207   
     /**
 208   
      * Override of base-class abstract function creates an
 209   
      * appropriately configured view.  For labels this a view
 210   
      * configured as of this.lastBuild.
 211   
      *
 212   
      * @param raw the unconfigured <code>View</code>
 213   
      * @return the snapshot <code>View</code> appropriately configured.
 214   
      */
 215  0
     protected View createSnapshotView(View raw) {
 216   
         /*
 217   
         if (this.revisionlabel) {
 218   
             return raw;
 219   
         }
 220   
         return new View(raw, ViewConfiguration.createFromTime(this.lastBuild));
 221   
         */
 222  0
         return raw;
 223   
     }
 224   
 
 225   
 }
 226   
 
 227