Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 398   Methods: 20
NCLOC: 119   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
StarTeamTask.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.BuildNumber;
 57   
 import com.starbase.starteam.Server;
 58   
 import com.starbase.starteam.StarTeamFinder;
 59   
 import com.starbase.starteam.TypeNames;
 60   
 import com.starbase.starteam.User;
 61   
 import com.starbase.starteam.View;
 62   
 import java.util.StringTokenizer;
 63   
 import org.apache.tools.ant.BuildException;
 64   
 import org.apache.tools.ant.Project;
 65   
 import org.apache.tools.ant.Task;
 66   
 
 67   
 /**
 68   
  * Common super class for all StarTeam tasks.
 69   
  * At this level of the hierarchy we are concerned only with obtaining a
 70   
  * connection to the StarTeam server.  The subclass <code>TreeBasedTask</code>,
 71   
  * also abstract defines the tree-walking behavior common to many subtasks.
 72   
  *
 73   
  * @see TreeBasedTask
 74   
  * @author <a href="mailto:jcyip@thoughtworks.com">Jason Yip</a>
 75   
  * @version 1.1
 76   
  * @author <a href="mailto:stevec@ignitesports.com">Steve Cohen</a>
 77   
  */
 78   
 
 79   
 public abstract class StarTeamTask extends Task {
 80   
 
 81   
     // ATTRIBUTES
 82   
 
 83   
     /**
 84   
      * The username of the connection
 85   
      */
 86   
     private String userName;
 87   
 
 88   
     /**
 89   
      * The username of the connection
 90   
      */
 91   
     private String password;
 92   
 
 93   
     /**
 94   
      * name of Starteam server to connect to
 95   
      */
 96   
     private String servername;
 97   
 
 98   
     /**
 99   
      * port of Starteam server to connect to
 100   
      */
 101   
     private String serverport;
 102   
 
 103   
     /**
 104   
      * name of Starteam project to connect to
 105   
      */
 106   
     private String projectname;
 107   
 
 108   
     /**
 109   
      * name of Starteam view to connect to
 110   
      */
 111   
     private String viewname;
 112   
 
 113   
     /**
 114   
      *The starteam server through which all activities will be done.
 115   
      */
 116   
     private Server server = null;
 117   
 
 118  0
     private void logStarteamVersion() {
 119  0
         log("StarTeam version: "+ 
 120   
             BuildNumber.getDisplayString(), Project.MSG_DEBUG);
 121   
     }
 122   
 
 123   
 
 124   
     /////////////////////////////////////////////////////////
 125   
     // GET/SET methods.
 126   
     // Setters, of course are where ant user passes in values.
 127   
     /////////////////////////////////////////////////////////
 128   
 
 129   
     /**
 130   
      * Set the name of StarTeamServer;
 131   
      * required if <tt>URL</tt> is not set.
 132   
      * @param servername a <code>String</code> value
 133   
      * @see #setURL(String)
 134   
      */
 135  0
     public final void setServername(String servername) {
 136  0
         this.servername = servername;
 137   
     }
 138   
 
 139   
     /**
 140   
      * returns the name of the StarTeamServer
 141   
      *
 142   
      * @return the name of the StarTeam server
 143   
      * @see #getURL()
 144   
      */
 145  0
     public final String getServername() {
 146  0
         return this.servername;
 147   
     }
 148   
 
 149   
     /**
 150   
      * set the port number of the StarTeam connection;
 151   
      * required if <tt>URL</tt> is not set.
 152   
      * @param serverport port number to be set
 153   
      * @see #setURL(String)
 154   
      */
 155  0
     public final void setServerport(String serverport) {
 156  0
         this.serverport = serverport;
 157   
     }
 158   
 
 159   
     /**
 160   
      * returns the port number of the StarTeam connection
 161   
      *
 162   
      * @return the port number of the StarTeam connection
 163   
      * @see #getURL()
 164   
      */
 165  0
     public final String getServerport() {
 166  0
         return this.serverport;
 167   
     }
 168   
 
 169   
     /**
 170   
      * set the name of the StarTeam project to be acted on;
 171   
      * required if <tt>URL</tt> is not set.
 172   
      *
 173   
      * @param projectname the name of the StarTeam project to be acted on
 174   
      * @see #setURL(String)
 175   
      */
 176  0
     public final void setProjectname(String projectname) {
 177  0
         this.projectname = projectname;
 178   
     }
 179   
 
 180   
     /**
 181   
      * returns the name of the StarTeam project to be acted on
 182   
      *
 183   
      * @return the name of the StarTeam project to be acted on
 184   
      * @see #getURL()
 185   
      */
 186  0
     public final String getProjectname() {
 187  0
         return this.projectname;
 188   
     }
 189   
 
 190   
     /**
 191   
      * set the name of the StarTeam view to be acted on;
 192   
      * required if <tt>URL</tt> is not set.
 193   
      *
 194   
      * @param projectname the name of the StarTeam view to be acted on
 195   
      * @see #setURL(String)
 196   
      */
 197  0
     public final void setViewname(String viewname) {
 198  0
         this.viewname = viewname;
 199   
     }
 200   
 
 201   
     /**
 202   
      * returns the name of the StarTeam view to be acted on
 203   
      *
 204   
      * @return the name of the StarTeam view to be acted on
 205   
      * @see #getURL()
 206   
      */
 207  0
     public final String getViewname() {
 208  0
         return this.viewname;
 209   
     }
 210   
 
 211   
 
 212   
     /**
 213   
      * Set the server name, server port,
 214   
      * project name and project folder in one shot;
 215   
      * optional, but the server connection must be specified somehow. 
 216   
      *
 217   
      * @param url a <code>String</code> of the form
 218   
      *             "servername:portnum/project/view"
 219   
      * @see #setServername(String)
 220   
      * @see #setServerport(String)
 221   
      * @see #setProjectname(String)
 222   
      * @see #setViewname(String)
 223   
      */
 224  0
     public final void setURL(String url) {
 225  0
         StringTokenizer t = new StringTokenizer(url, "/");
 226  0
         if (t.hasMoreTokens()) {
 227  0
             String unpw = t.nextToken();
 228  0
             int pos = unpw.indexOf(":");
 229  0
             if (pos > 0) {
 230  0
                 this.servername = unpw.substring(0, pos);
 231  0
                 this.serverport = unpw.substring(pos + 1);
 232  0
                 if (t.hasMoreTokens()) {
 233  0
                     this.projectname = t.nextToken();
 234  0
                     if (t.hasMoreTokens()) {
 235  0
                         this.viewname = t.nextToken();
 236   
                     }
 237   
                 }
 238   
             }
 239   
         }
 240   
     }
 241   
 
 242   
     /**
 243   
      * convenience method returns whole URL at once
 244   
      * returns
 245   
      * as a single string
 246   
      */
 247   
     /**
 248   
      * a convenience method which returns the whole StarTeam
 249   
      * connection information as a single URL string of
 250   
      *
 251   
      * @return a <code>String</code> of the form
 252   
      *         "servername:portnum/project/view"
 253   
      * @see #getServername()
 254   
      * @see #getServerport()
 255   
      * @see #getProjectname()
 256   
      * @see #getViewname()
 257   
      */
 258  0
     public final String getURL() {
 259  0
         return
 260   
                 this.servername + ":" +
 261   
                 this.serverport + "/" +
 262   
                 this.projectname + "/" +
 263   
                 ((null == this.viewname) ? "" : this.viewname);
 264   
     }
 265   
 
 266   
     /**
 267   
      * returns an URL string useful for interacting with many StarTeamFinder
 268   
      * methods.
 269   
      * 
 270   
      * @return the URL string for this task.
 271   
      */
 272  0
     protected final String getViewURL() {
 273  0
         return getUserName() + ":" + getPassword() + "@" + getURL();
 274   
     }
 275   
     /**
 276   
      * set the name of the StarTeam user, needed for the connection
 277   
      *
 278   
      * @param userName name of the user to be logged in
 279   
      */
 280  0
     public final void setUserName(String userName) {
 281  0
         this.userName = userName;
 282   
     }
 283   
 
 284   
     /**
 285   
      * returns the name of the StarTeam user
 286   
      *
 287   
      * @return the name of the StarTeam user
 288   
      */
 289  0
     public final String getUserName() {
 290  0
         return this.userName;
 291   
     }
 292   
 
 293   
     /**
 294   
      * set the password to be used for login; required.
 295   
      *
 296   
      * @param password the password to be used for login
 297   
      */
 298  0
     public final void setPassword(String password) {
 299  0
         this.password = password;
 300   
     }
 301   
 
 302   
     /**
 303   
      * returns the password used for login
 304   
      *
 305   
      * @return the password used for login
 306   
      */
 307  0
     public final String getPassword() {
 308  0
         return this.password;
 309   
     }
 310   
 
 311   
     /**
 312   
      * returns a reference to the server which may be used for informational
 313   
      * purposes by subclasses.
 314   
      *
 315   
      * @return a reference to the server
 316   
      */
 317  0
     protected final Server getServer() {
 318  0
         return this.server;
 319   
     }
 320   
 
 321   
     /**
 322   
      * returns a list of TypeNames known to the server.
 323   
      *
 324   
      * @return a reference to the server's TypeNames
 325   
      */
 326  0
     protected final TypeNames getTypeNames() {
 327  0
         return this.server.getTypeNames();
 328   
     }
 329   
     /**
 330   
      * Derived classes must override <code>createSnapshotView</code>
 331   
      * defining the kind of configured view appropriate to its task.
 332   
      *
 333   
      * @param rawview the unconfigured <code>View</code>
 334   
      * @return the snapshot <code>View</code> appropriately configured.
 335   
      */
 336   
     protected abstract View createSnapshotView(View rawview) 
 337   
     throws BuildException;
 338   
 
 339   
     /**
 340   
      * All subclasses will call on this method to open the view needed for
 341   
      * processing.  This method also saves a reference to the
 342   
      * <code>Server</code> that may be accessed for information at various
 343   
      * points in the process.
 344   
      *
 345   
      * @return the <code>View</code> that will be used for processing.
 346   
      * @see #createSnapshotView(View)
 347   
      * @see #getServer()
 348   
      */
 349  0
     protected View openView() throws BuildException {
 350   
 
 351  0
         logStarteamVersion();
 352  0
         View view = null;
 353  0
         try {
 354  0
             view = StarTeamFinder.openView(getViewURL());
 355   
         } catch (Exception e) {
 356  0
             throw new BuildException(
 357   
                 "Failed to connect to " + getURL(), e);
 358   
         }
 359   
 
 360  0
         if (null == view) {
 361  0
             throw new BuildException("Cannot find view" + getURL() +
 362   
                     " in repository()");
 363   
         }
 364   
 
 365  0
         View snapshot = createSnapshotView(view);
 366  0
         this.server = snapshot.getServer();
 367  0
         return snapshot;
 368   
     }
 369   
 
 370   
     /**
 371   
      * Returns the name of the user with the supplied ID or a blank string
 372   
      * if user not found.
 373   
      *
 374   
      * @param userID a user's ID
 375   
      * @return the name of the user with ID userID
 376   
      */
 377  0
     protected final String getUserName(int userID) {
 378  0
         User u = this.server.getUser(userID);
 379  0
         if (null == u) {
 380  0
             return "";
 381   
         }
 382  0
         return u.getName();
 383   
     }
 384   
 
 385   
 }
 386   
 
 387   
 
 388   
 
 389   
 
 390   
 
 391   
 
 392   
 
 393   
 
 394   
 
 395   
 
 396   
 
 397   
 
 398