Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 371   Methods: 16
NCLOC: 107   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
CCCheckin.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 checkin.
 66   
  *
 67   
  * <p>
 68   
  * The following attributes are interpreted:
 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>comment</td>
 82   
  *      <td>Specify a comment. Only one of comment or cfile may be used.</td>
 83   
  *      <td>No</td>
 84   
  *   <tr>
 85   
  *   <tr>
 86   
  *      <td>commentfile</td>
 87   
  *      <td>Specify a file containing a comment. Only one of comment or cfile may be used.</td>
 88   
  *      <td>No</td>
 89   
  *   <tr>
 90   
  *   <tr>
 91   
  *      <td>nowarn</td>
 92   
  *      <td>Suppress warning messages</td>
 93   
  *      <td>No</td>
 94   
  *   <tr>
 95   
  *   <tr>
 96   
  *      <td>preservetime</td>
 97   
  *      <td>Preserve the modification time</td>
 98   
  *      <td>No</td>
 99   
  *   <tr>
 100   
  *   <tr>
 101   
  *      <td>keepcopy</td>
 102   
  *      <td>Keeps a copy of the file with a .keep extension</td>
 103   
  *      <td>No</td>
 104   
  *   <tr>
 105   
  *   <tr>
 106   
  *      <td>identical</td>
 107   
  *      <td>Allows the file to be checked in even if it is identical to the original</td>
 108   
  *      <td>No</td>
 109   
  *   <tr>
 110   
  * </table>
 111   
  *
 112   
  * @author Curtis White
 113   
  */
 114   
 public class CCCheckin extends ClearCase {
 115   
     private String m_Comment = null;
 116   
     private String m_Cfile = null;
 117   
     private boolean m_Nwarn = false;
 118   
     private boolean m_Ptime = false;
 119   
     private boolean m_Keep = false;
 120   
     private boolean m_Identical = true;
 121   
 
 122   
     /**
 123   
      * Executes the task.
 124   
      * <p>
 125   
      * Builds a command line to execute cleartool and then calls Exec's run method
 126   
      * to execute the command line.
 127   
      */
 128  0
     public void execute() throws BuildException {
 129  0
         Commandline commandLine = new Commandline();
 130  0
         Project aProj = getProject();
 131  0
         int result = 0;
 132   
 
 133   
         // Default the viewpath to basedir if it is not specified
 134  0
         if (getViewPath() == null) {
 135  0
             setViewPath(aProj.getBaseDir().getPath());
 136   
         }
 137   
 
 138   
         // build the command line from what we got. the format is
 139   
         // cleartool checkin [options...] [viewpath ...]
 140   
         // as specified in the CLEARTOOL.EXE help
 141  0
         commandLine.setExecutable(getClearToolCommand());
 142  0
         commandLine.createArgument().setValue(COMMAND_CHECKIN);
 143   
 
 144  0
         checkOptions(commandLine);
 145   
 
 146  0
         result = run(commandLine);
 147  0
         if (result != 0) {
 148  0
             String msg = "Failed executing: " + commandLine.toString();
 149  0
             throw new BuildException(msg, getLocation());
 150   
         }
 151   
     }
 152   
 
 153   
 
 154   
     /**
 155   
      * Check the command line options.
 156   
      */
 157  0
     private void checkOptions(Commandline cmd) {
 158  0
         if (getComment() != null) {
 159   
             // -c
 160  0
             getCommentCommand(cmd);
 161   
         } else {
 162  0
             if (getCommentFile() != null) {
 163   
                 // -cfile
 164  0
                 getCommentFileCommand(cmd);
 165   
             } else {
 166  0
                 cmd.createArgument().setValue(FLAG_NOCOMMENT);
 167   
             }
 168   
         }
 169   
 
 170  0
         if (getNoWarn()) {
 171   
             // -nwarn
 172  0
             cmd.createArgument().setValue(FLAG_NOWARN);
 173   
         }
 174   
 
 175  0
         if (getPreserveTime()) {
 176   
             // -ptime
 177  0
             cmd.createArgument().setValue(FLAG_PRESERVETIME);
 178   
         }
 179   
 
 180  0
         if (getKeepCopy()) {
 181   
             // -keep
 182  0
             cmd.createArgument().setValue(FLAG_KEEPCOPY);
 183   
         }
 184   
 
 185  0
         if (getIdentical()) {
 186   
             // -identical
 187  0
             cmd.createArgument().setValue(FLAG_IDENTICAL);
 188   
         }
 189   
 
 190   
         // viewpath
 191  0
         cmd.createArgument().setValue(getViewPath());
 192   
     }
 193   
 
 194   
 
 195   
     /**
 196   
      * Sets the comment string.
 197   
      *
 198   
      * @param comment the comment string
 199   
      */
 200  0
     public void setComment(String comment) {
 201  0
         m_Comment = comment;
 202   
     }
 203   
 
 204   
     /**
 205   
      * Get comment string
 206   
      *
 207   
      * @return String containing the comment
 208   
      */
 209  0
     public String getComment() {
 210  0
         return m_Comment;
 211   
     }
 212   
 
 213   
     /**
 214   
      * Specifies a file containing a comment.
 215   
      *
 216   
      * @param cfile the path to the comment file
 217   
      */
 218  0
     public void setCommentFile(String cfile) {
 219  0
         m_Cfile = cfile;
 220   
     }
 221   
 
 222   
     /**
 223   
      * Get comment file
 224   
      *
 225   
      * @return String containing the path to the comment file
 226   
      */
 227  0
     public String getCommentFile() {
 228  0
         return m_Cfile;
 229   
     }
 230   
 
 231   
     /**
 232   
      * If true, suppress warning messages.
 233   
      *
 234   
      * @param nwarn the status to set the flag to
 235   
      */
 236  0
     public void setNoWarn(boolean nwarn) {
 237  0
         m_Nwarn = nwarn;
 238   
     }
 239   
 
 240   
     /**
 241   
      * Get nowarn flag status
 242   
      *
 243   
      * @return boolean containing status of nwarn flag
 244   
      */
 245  0
     public boolean getNoWarn() {
 246  0
         return m_Nwarn;
 247   
     }
 248   
 
 249   
     /**
 250   
      * If true, preserve the modification time.
 251   
      *
 252   
      * @param ptime the status to set the flag to
 253   
      */
 254  0
     public void setPreserveTime(boolean ptime) {
 255  0
         m_Ptime = ptime;
 256   
     }
 257   
 
 258   
     /**
 259   
      * Get preservetime flag status
 260   
      *
 261   
      * @return boolean containing status of preservetime flag
 262   
      */
 263  0
     public boolean getPreserveTime() {
 264  0
         return m_Ptime;
 265   
     }
 266   
 
 267   
     /**
 268   
      * If true, keeps a copy of the file with a .keep extension.
 269   
      *
 270   
      * @param keep the status to set the flag to
 271   
      */
 272  0
     public void setKeepCopy(boolean keep) {
 273  0
         m_Keep = keep;
 274   
     }
 275   
 
 276   
     /**
 277   
      * Get keepcopy flag status
 278   
      *
 279   
      * @return boolean containing status of keepcopy flag
 280   
      */
 281  0
     public boolean getKeepCopy() {
 282  0
         return m_Keep;
 283   
     }
 284   
 
 285   
     /**
 286   
      * If true, allows the file to be checked in even
 287   
      * if it is identical to the original.
 288   
      *
 289   
      * @param identical the status to set the flag to
 290   
      */
 291  0
     public void setIdentical(boolean identical) {
 292  0
         m_Identical = identical;
 293   
     }
 294   
 
 295   
     /**
 296   
      * Get identical flag status
 297   
      *
 298   
      * @return boolean containing status of identical flag
 299   
      */
 300  0
     public boolean getIdentical() {
 301  0
         return m_Identical;
 302   
     }
 303   
 
 304   
 
 305   
     /**
 306   
      * Get the 'comment' command
 307   
      *
 308   
      * @param cmd containing the command line string with or without the comment flag and string appended
 309   
      */
 310  0
     private void getCommentCommand(Commandline cmd) {
 311  0
         if (getComment() != null) {
 312   
             /* Had to make two separate commands here because if a space is
 313   
                inserted between the flag and the value, it is treated as a
 314   
                Windows filename with a space and it is enclosed in double
 315   
                quotes ("). This breaks clearcase.
 316   
             */
 317  0
             cmd.createArgument().setValue(FLAG_COMMENT);
 318  0
             cmd.createArgument().setValue(getComment());
 319   
         }
 320   
     }
 321   
 
 322   
     /**
 323   
      * Get the 'commentfile' command
 324   
      *
 325   
      * @param cmd containing the command line string with or without the commentfile flag and file appended
 326   
      */
 327  0
     private void getCommentFileCommand(Commandline cmd) {
 328  0
         if (getCommentFile() != null) {
 329   
             /* Had to make two separate commands here because if a space is
 330   
                inserted between the flag and the value, it is treated as a
 331   
                Windows filename with a space and it is enclosed in double
 332   
                quotes ("). This breaks clearcase.
 333   
             */
 334  0
             cmd.createArgument().setValue(FLAG_COMMENTFILE);
 335  0
             cmd.createArgument().setValue(getCommentFile());
 336   
         }
 337   
     }
 338   
 
 339   
 
 340   
         /**
 341   
      * -c flag -- comment to attach to the file
 342   
      */
 343   
     public static final String FLAG_COMMENT = "-c";
 344   
         /**
 345   
      * -cfile flag -- file containing a comment to attach to the file
 346   
      */
 347   
     public static final String FLAG_COMMENTFILE = "-cfile";
 348   
         /**
 349   
      * -nc flag -- no comment is specified
 350   
      */
 351   
     public static final String FLAG_NOCOMMENT = "-nc";
 352   
         /**
 353   
      * -nwarn flag -- suppresses warning messages
 354   
      */
 355   
     public static final String FLAG_NOWARN = "-nwarn";
 356   
         /**
 357   
      * -ptime flag -- preserves the modification time
 358   
      */
 359   
     public static final String FLAG_PRESERVETIME = "-ptime";
 360   
         /**
 361   
      * -keep flag -- keeps a copy of the file with a .keep extension
 362   
      */
 363   
     public static final String FLAG_KEEPCOPY = "-keep";
 364   
         /**
 365   
      * -identical flag -- allows the file to be checked in even if it is identical to the original
 366   
      */
 367   
     public static final String FLAG_IDENTICAL = "-identical";
 368   
 
 369   
 }
 370   
 
 371