Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 487   Methods: 22
NCLOC: 146   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
CCCheckout.java 0% 0% 0% 0%
 1   
 /*
 2   
  * The Apache Software License, Version 1.1
 3   
  *
 4   
  * Copyright (c) 2000,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   
 
 55   
 package org.apache.tools.ant.taskdefs.optional.clearcase;
 56   
 
 57   
 import org.apache.tools.ant.BuildException;
 58   
 import org.apache.tools.ant.Project;
 59   
 import org.apache.tools.ant.types.Commandline;
 60   
 
 61   
 
 62   
 
 63   
 
 64   
 /**
 65   
  * Performs ClearCase checkout.
 66   
  *
 67   
  * <p>
 68   
  * The following attributes are interpretted:
 69   
  * <table border="1">
 70   
  *   <tr>
 71   
  *     <th>Attribute</th>
 72   
  *     <th>Values</th>
 73   
  *     <th>Required</th>
 74   
  *   </tr>
 75   
  *   <tr>
 76   
  *      <td>viewpath</td>
 77   
  *      <td>Path to the ClearCase view file or directory that the command will operate on</td>
 78   
  *      <td>No</td>
 79   
  *   <tr>
 80   
  *   <tr>
 81   
  *      <td>reserved</td>
 82   
  *      <td>Specifies whether to check out the file as reserved or not</td>
 83   
  *      <td>Yes</td>
 84   
  *   <tr>
 85   
  *   <tr>
 86   
  *      <td>out</td>
 87   
  *      <td>Creates a writable file under a different filename</td>
 88   
  *      <td>No</td>
 89   
  *   <tr>
 90   
  *   <tr>
 91   
  *      <td>nodata</td>
 92   
  *      <td>Checks out the file but does not create an editable file containing its data</td>
 93   
  *      <td>No</td>
 94   
  *   <tr>
 95   
  *   <tr>
 96   
  *      <td>branch</td>
 97   
  *      <td>Specify a branch to check out the file to</td>
 98   
  *      <td>No</td>
 99   
  *   <tr>
 100   
  *   <tr>
 101   
  *      <td>version</td>
 102   
  *      <td>Allows checkout of a version other than main latest</td>
 103   
  *      <td>No</td>
 104   
  *   <tr>
 105   
  *   <tr>
 106   
  *      <td>nowarn</td>
 107   
  *      <td>Suppress warning messages</td>
 108   
  *      <td>No</td>
 109   
  *   <tr>
 110   
  *   <tr>
 111   
  *      <td>comment</td>
 112   
  *      <td>Specify a comment. Only one of comment or cfile may be used.</td>
 113   
  *      <td>No</td>
 114   
  *   <tr>
 115   
  *   <tr>
 116   
  *      <td>commentfile</td>
 117   
  *      <td>Specify a file containing a comment. Only one of comment or cfile may be used.</td>
 118   
  *      <td>No</td>
 119   
  *   <tr>
 120   
  * </table>
 121   
  *
 122   
  * @author Curtis White
 123   
  */
 124   
 public class CCCheckout extends ClearCase {
 125   
     private boolean m_Reserved = true;
 126   
     private String m_Out = null;
 127   
     private boolean m_Ndata = false;
 128   
     private String m_Branch = null;
 129   
     private boolean m_Version = false;
 130   
     private boolean m_Nwarn = false;
 131   
     private String m_Comment = null;
 132   
     private String m_Cfile = null;
 133   
 
 134   
     /**
 135   
      * Executes the task.
 136   
      * <p>
 137   
      * Builds a command line to execute cleartool and then calls Exec's run method
 138   
      * to execute the command line.
 139   
      */
 140  0
     public void execute() throws BuildException {
 141  0
         Commandline commandLine = new Commandline();
 142  0
         Project aProj = getProject();
 143  0
         int result = 0;
 144   
 
 145   
         // Default the viewpath to basedir if it is not specified
 146  0
         if (getViewPath() == null) {
 147  0
             setViewPath(aProj.getBaseDir().getPath());
 148   
         }
 149   
 
 150   
         // build the command line from what we got the format is
 151   
         // cleartool checkout [options...] [viewpath ...]
 152   
         // as specified in the CLEARTOOL.EXE help
 153  0
         commandLine.setExecutable(getClearToolCommand());
 154  0
         commandLine.createArgument().setValue(COMMAND_CHECKOUT);
 155   
 
 156  0
         checkOptions(commandLine);
 157   
 
 158  0
         result = run(commandLine);
 159  0
         if (result != 0) {
 160  0
             String msg = "Failed executing: " + commandLine.toString();
 161  0
             throw new BuildException(msg, getLocation());
 162   
         }
 163   
     }
 164   
 
 165   
 
 166   
     /**
 167   
      * Check the command line options.
 168   
      */
 169  0
     private void checkOptions(Commandline cmd) {
 170   
         // ClearCase items
 171  0
         if (getReserved()) {
 172   
             // -reserved
 173  0
             cmd.createArgument().setValue(FLAG_RESERVED);
 174   
         } else {
 175   
             // -unreserved
 176  0
             cmd.createArgument().setValue(FLAG_UNRESERVED);
 177   
         }
 178   
 
 179  0
         if (getOut() != null) {
 180   
             // -out
 181  0
             getOutCommand(cmd);
 182   
         } else {
 183  0
             if (getNoData()) {
 184   
                 // -ndata
 185  0
                 cmd.createArgument().setValue(FLAG_NODATA);
 186   
             }
 187   
 
 188   
         }
 189   
 
 190  0
         if (getBranch() != null) {
 191   
             // -branch
 192  0
             getBranchCommand(cmd);
 193   
         } else {
 194  0
             if (getVersion()) {
 195   
                 // -version
 196  0
                 cmd.createArgument().setValue(FLAG_VERSION);
 197   
             }
 198   
 
 199   
         }
 200   
 
 201  0
         if (getNoWarn()) {
 202   
             // -nwarn
 203  0
             cmd.createArgument().setValue(FLAG_NOWARN);
 204   
         }
 205   
 
 206  0
         if (getComment() != null) {
 207   
             // -c
 208  0
             getCommentCommand(cmd);
 209   
         } else {
 210  0
             if (getCommentFile() != null) {
 211   
                 // -cfile
 212  0
                 getCommentFileCommand(cmd);
 213   
             } else {
 214  0
                 cmd.createArgument().setValue(FLAG_NOCOMMENT);
 215   
             }
 216   
         }
 217   
 
 218   
         // viewpath
 219  0
         cmd.createArgument().setValue(getViewPath());
 220   
     }
 221   
 
 222   
     /**
 223   
      * If true, checks out the file as reserved.
 224   
      *
 225   
      * @param reserved the status to set the flag to
 226   
      */
 227  0
     public void setReserved(boolean reserved) {
 228  0
         m_Reserved = reserved;
 229   
     }
 230   
 
 231   
     /**
 232   
      * Get reserved flag status
 233   
      *
 234   
      * @return boolean containing status of reserved flag
 235   
      */
 236  0
     public boolean getReserved() {
 237  0
         return m_Reserved;
 238   
     }
 239   
 
 240   
     /**
 241   
      * Creates a writable file under a different filename.
 242   
      *
 243   
      * @param outf the path to the out file
 244   
      */
 245  0
     public void setOut(String outf) {
 246  0
         m_Out = outf;
 247   
     }
 248   
 
 249   
     /**
 250   
      * Get out file
 251   
      *
 252   
      * @return String containing the path to the out file
 253   
      */
 254  0
     public String getOut() {
 255  0
         return m_Out;
 256   
     }
 257   
 
 258   
     /**
 259   
      * If true, checks out the file but does not create an
 260   
      * editable file containing its data.
 261   
      *
 262   
      * @param ndata the status to set the flag to
 263   
      */
 264  0
     public void setNoData(boolean ndata) {
 265  0
         m_Ndata = ndata;
 266   
     }
 267   
 
 268   
     /**
 269   
      * Get nodata flag status
 270   
      *
 271   
      * @return boolean containing status of ndata flag
 272   
      */
 273  0
     public boolean getNoData() {
 274  0
         return m_Ndata;
 275   
     }
 276   
 
 277   
     /**
 278   
      * Specify a branch to check out the file to.
 279   
      *
 280   
      * @param branch the name of the branch
 281   
      */
 282  0
     public void setBranch(String branch) {
 283  0
         m_Branch = branch;
 284   
     }
 285   
 
 286   
     /**
 287   
      * Get branch name
 288   
      *
 289   
      * @return String containing the name of the branch
 290   
      */
 291  0
     public String getBranch() {
 292  0
         return m_Branch;
 293   
     }
 294   
 
 295   
     /**
 296   
      * If true, allows checkout of a version other than main latest.
 297   
      *
 298   
      * @param version the status to set the flag to
 299   
      */
 300  0
     public void setVersion(boolean version) {
 301  0
         m_Version = version;
 302   
     }
 303   
 
 304   
     /**
 305   
      * Get version flag status
 306   
      *
 307   
      * @return boolean containing status of version flag
 308   
      */
 309  0
     public boolean getVersion() {
 310  0
         return m_Version;
 311   
     }
 312   
 
 313   
     /**
 314   
      * If true, warning messages are suppressed.
 315   
      *
 316   
      * @param nwarn the status to set the flag to
 317   
      */
 318  0
     public void setNoWarn(boolean nwarn) {
 319  0
         m_Nwarn = nwarn;
 320   
     }
 321   
 
 322   
     /**
 323   
      * Get nowarn flag status
 324   
      *
 325   
      * @return boolean containing status of nwarn flag
 326   
      */
 327  0
     public boolean getNoWarn() {
 328  0
         return m_Nwarn;
 329   
     }
 330   
 
 331   
     /**
 332   
      * Sets the comment string.
 333   
      *
 334   
      * @param comment the comment string
 335   
      */
 336  0
     public void setComment(String comment) {
 337  0
         m_Comment = comment;
 338   
     }
 339   
 
 340   
     /**
 341   
      * Get comment string
 342   
      *
 343   
      * @return String containing the comment
 344   
      */
 345  0
     public String getComment() {
 346  0
         return m_Comment;
 347   
     }
 348   
 
 349   
     /**
 350   
      * Specifies a file containing a comment.
 351   
      *
 352   
      * @param cfile the path to the comment file
 353   
      */
 354  0
     public void setCommentFile(String cfile) {
 355  0
         m_Cfile = cfile;
 356   
     }
 357   
 
 358   
     /**
 359   
      * Get comment file
 360   
      *
 361   
      * @return String containing the path to the comment file
 362   
      */
 363  0
     public String getCommentFile() {
 364  0
         return m_Cfile;
 365   
     }
 366   
 
 367   
     /**
 368   
      * Get the 'out' command
 369   
      *
 370   
      * @return the 'out' command if the attribute was specified, otherwise an empty string
 371   
      *
 372   
      * @param CommandLine containing the command line string with or without the out flag and path appended
 373   
      */
 374  0
     private void getOutCommand(Commandline cmd) {
 375  0
         if (getOut() != null) {
 376   
             /* Had to make two separate commands here because if a space is
 377   
                inserted between the flag and the value, it is treated as a
 378   
                Windows filename with a space and it is enclosed in double
 379   
                quotes ("). This breaks clearcase.
 380   
             */
 381  0
             cmd.createArgument().setValue(FLAG_OUT);
 382  0
             cmd.createArgument().setValue(getOut());
 383   
         }
 384   
     }
 385   
 
 386   
     /**
 387   
      * Get the 'branch' command
 388   
      *
 389   
      * @return the 'branch' command if the attribute was specified, otherwise an empty string
 390   
      *
 391   
      * @param CommandLine containing the command line string with or without the branch flag and name appended
 392   
      */
 393  0
     private void getBranchCommand(Commandline cmd) {
 394  0
         if (getBranch() != null) {
 395   
             /* Had to make two separate commands here because if a space is
 396   
                inserted between the flag and the value, it is treated as a
 397   
                Windows filename with a space and it is enclosed in double
 398   
                quotes ("). This breaks clearcase.
 399   
             */
 400  0
             cmd.createArgument().setValue(FLAG_BRANCH);
 401  0
             cmd.createArgument().setValue(getBranch());
 402   
         }
 403   
     }
 404   
 
 405   
 
 406   
     /**
 407   
      * Get the 'comment' command
 408   
      *
 409   
      * @return the 'comment' command if the attribute was specified, otherwise an empty string
 410   
      *
 411   
      * @param CommandLine containing the command line string with or without the comment flag and string appended
 412   
      */
 413  0
     private void getCommentCommand(Commandline cmd) {
 414  0
         if (getComment() != null) {
 415   
             /* Had to make two separate commands here because if a space is
 416   
                inserted between the flag and the value, it is treated as a
 417   
                Windows filename with a space and it is enclosed in double
 418   
                quotes ("). This breaks clearcase.
 419   
             */
 420  0
             cmd.createArgument().setValue(FLAG_COMMENT);
 421  0
             cmd.createArgument().setValue(getComment());
 422   
         }
 423   
     }
 424   
 
 425   
     /**
 426   
      * Get the 'cfile' command
 427   
      *
 428   
      * @return the 'cfile' command if the attribute was specified, otherwise an empty string
 429   
      *
 430   
      * @param CommandLine containing the command line string with or without the cfile flag and file appended
 431   
      */
 432  0
     private void getCommentFileCommand(Commandline cmd) {
 433  0
         if (getCommentFile() != null) {
 434   
             /* Had to make two separate commands here because if a space is
 435   
                inserted between the flag and the value, it is treated as a
 436   
                Windows filename with a space and it is enclosed in double
 437   
                quotes ("). This breaks clearcase.
 438   
             */
 439  0
             cmd.createArgument().setValue(FLAG_COMMENTFILE);
 440  0
             cmd.createArgument().setValue(getCommentFile());
 441   
         }
 442   
     }
 443   
 
 444   
         /**
 445   
      *  -reserved flag -- check out the file as reserved
 446   
      */
 447   
     public static final String FLAG_RESERVED = "-reserved";
 448   
         /**
 449   
      *  -reserved flag -- check out the file as unreserved
 450   
      */
 451   
     public static final String FLAG_UNRESERVED = "-unreserved";
 452   
         /**
 453   
      * -out flag -- create a writable file under a different filename
 454   
      */
 455   
     public static final String FLAG_OUT = "-out";
 456   
         /**
 457   
      * -ndata flag -- checks out the file but does not create an editable file containing its data
 458   
      */
 459   
     public static final String FLAG_NODATA = "-ndata";
 460   
         /**
 461   
      * -branch flag -- checks out the file on a specified branch
 462   
      */
 463   
     public static final String FLAG_BRANCH = "-branch";
 464   
         /**
 465   
      * -version flag -- allows checkout of a version that is not main latest
 466   
      */
 467   
     public static final String FLAG_VERSION = "-version";
 468   
         /**
 469   
      * -nwarn flag -- suppresses warning messages
 470   
      */
 471   
     public static final String FLAG_NOWARN = "-nwarn";
 472   
         /**
 473   
      * -c flag -- comment to attach to the file
 474   
      */
 475   
     public static final String FLAG_COMMENT = "-c";
 476   
         /**
 477   
      * -cfile flag -- file containing a comment to attach to the file
 478   
      */
 479   
     public static final String FLAG_COMMENTFILE = "-cfile";
 480   
         /**
 481   
      * -nc flag -- no comment is specified
 482   
      */
 483   
     public static final String FLAG_NOCOMMENT = "-nc";
 484   
 
 485   
 }
 486   
 
 487