Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 359   Methods: 15
NCLOC: 104   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
CCUpdate.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   
 /**
 66   
  * Performs a ClearCase Update command.
 67   
  *
 68   
  * <p>
 69   
  * The following attributes are interpretted:
 70   
  * <table border="1">
 71   
  *   <tr>
 72   
  *     <th>Attribute</th>
 73   
  *     <th>Values</th>
 74   
  *     <th>Required</th>
 75   
  *   </tr>
 76   
  *   <tr>
 77   
  *      <td>viewpath</td>
 78   
  *      <td>Path to the ClearCase view file or directory that the command will operate on</td>
 79   
  *      <td>No</td>
 80   
  *   <tr>
 81   
  *   <tr>
 82   
  *      <td>graphical</td>
 83   
  *      <td>Displays a graphical dialog during the update</td>
 84   
  *      <td>No</td>
 85   
  *   <tr>
 86   
  *   <tr>
 87   
  *      <td>log</td>
 88   
  *      <td>Specifies a log file for ClearCase to write to</td>
 89   
  *      <td>No</td>
 90   
  *   <tr>
 91   
  *   <tr>
 92   
  *      <td>overwrite</td>
 93   
  *      <td>Specifies whether to overwrite hijacked files or not</td>
 94   
  *      <td>No</td>
 95   
  *   <tr>
 96   
  *   <tr>
 97   
  *      <td>rename</td>
 98   
  *      <td>Specifies that hijacked files should be renamed with a .keep extension</td>
 99   
  *      <td>No</td>
 100   
  *   <tr>
 101   
  *   <tr>
 102   
  *      <td>currenttime</td>
 103   
  *      <td>Specifies that modification time should be written as the current time. Either currenttime or preservetime can be specified.</td>
 104   
  *      <td>No</td>
 105   
  *   <tr>
 106   
  *   <tr>
 107   
  *      <td>preservetime</td>
 108   
  *      <td>Specifies that modification time should preserved from the VOB time. Either currenttime or preservetime can be specified.</td>
 109   
  *      <td>No</td>
 110   
  *   <tr>
 111   
  * </table>
 112   
  *
 113   
  * @author Curtis White
 114   
  */
 115   
 public class CCUpdate extends ClearCase {
 116   
     private boolean m_Graphical = false;
 117   
     private boolean m_Overwrite = false;
 118   
     private boolean m_Rename = false;
 119   
     private boolean m_Ctime = false;
 120   
     private boolean m_Ptime = false;
 121   
     private String m_Log = null;
 122   
 
 123   
     /**
 124   
      * Executes the task.
 125   
      * <p>
 126   
      * Builds a command line to execute cleartool and then calls Exec's run method
 127   
      * to execute the command line.
 128   
      */
 129  0
     public void execute() throws BuildException {
 130  0
         Commandline commandLine = new Commandline();
 131  0
         Project aProj = getProject();
 132  0
         int result = 0;
 133   
 
 134   
         // Default the viewpath to basedir if it is not specified
 135  0
         if (getViewPath() == null) {
 136  0
             setViewPath(aProj.getBaseDir().getPath());
 137   
         }
 138   
 
 139   
         // build the command line from what we got the format is
 140   
         // cleartool update [options...] [viewpath ...]
 141   
         // as specified in the CLEARTOOL.EXE help
 142  0
         commandLine.setExecutable(getClearToolCommand());
 143  0
         commandLine.createArgument().setValue(COMMAND_UPDATE);
 144   
 
 145   
         // Check the command line options
 146  0
         checkOptions(commandLine);
 147   
 
 148   
         // For debugging
 149  0
         System.out.println(commandLine.toString());
 150   
 
 151  0
         result = run(commandLine);
 152  0
         if (result != 0) {
 153  0
             String msg = "Failed executing: " + commandLine.toString();
 154  0
             throw new BuildException(msg, getLocation());
 155   
         }
 156   
     }
 157   
 
 158   
     /**
 159   
      * Check the command line options.
 160   
      */
 161  0
     private void checkOptions(Commandline cmd) {
 162   
         // ClearCase items
 163  0
         if (getGraphical()) {
 164   
             // -graphical
 165  0
             cmd.createArgument().setValue(FLAG_GRAPHICAL);
 166   
         } else {
 167  0
             if (getOverwrite()) {
 168   
                 // -overwrite
 169  0
                 cmd.createArgument().setValue(FLAG_OVERWRITE);
 170   
             } else {
 171  0
                 if (getRename()) {
 172   
                     // -rename
 173  0
                     cmd.createArgument().setValue(FLAG_RENAME);
 174   
                 } else {
 175   
                     // -noverwrite
 176  0
                     cmd.createArgument().setValue(FLAG_NOVERWRITE);
 177   
                 }
 178   
             }
 179   
 
 180  0
             if (getCurrentTime()) {
 181   
                 // -ctime
 182  0
                 cmd.createArgument().setValue(FLAG_CURRENTTIME);
 183   
             } else {
 184  0
                 if (getPreserveTime()) {
 185   
                     // -ptime
 186  0
                     cmd.createArgument().setValue(FLAG_PRESERVETIME);
 187   
                 }
 188   
             }
 189   
 
 190   
             // -log logname
 191  0
             getLogCommand(cmd);
 192   
         }
 193   
 
 194   
         // viewpath
 195  0
         cmd.createArgument().setValue(getViewPath());
 196   
     }
 197   
 
 198   
     /**
 199   
      * If true, displays a graphical dialog during the update.
 200   
      *
 201   
      * @param graphical the status to set the flag to
 202   
      */
 203  0
     public void setGraphical(boolean graphical) {
 204  0
         m_Graphical = graphical;
 205   
     }
 206   
 
 207   
     /**
 208   
      * Get graphical flag status
 209   
      *
 210   
      * @return boolean containing status of graphical flag
 211   
      */
 212  0
     public boolean getGraphical() {
 213  0
         return m_Graphical;
 214   
     }
 215   
 
 216   
     /**
 217   
      * If true, overwrite hijacked files.
 218   
      *
 219   
      * @param ow the status to set the flag to
 220   
      */
 221  0
     public void setOverwrite(boolean ow) {
 222  0
         m_Overwrite = ow;
 223   
     }
 224   
 
 225   
     /**
 226   
      * Get overwrite hijacked files status
 227   
      *
 228   
      * @return boolean containing status of overwrite flag
 229   
      */
 230  0
     public boolean getOverwrite() {
 231  0
         return m_Overwrite;
 232   
     }
 233   
 
 234   
     /**
 235   
      * If true, hijacked files are renamed with a .keep extension.
 236   
      *
 237   
      * @param ren the status to set the flag to
 238   
      */
 239  0
     public void setRename(boolean ren) {
 240  0
         m_Rename = ren;
 241   
     }
 242   
 
 243   
     /**
 244   
      * Get rename hijacked files status
 245   
      *
 246   
      * @return boolean containing status of rename flag
 247   
      */
 248  0
     public boolean getRename() {
 249  0
         return m_Rename;
 250   
     }
 251   
 
 252   
     /**
 253   
      * If true, modification time should be written as the current time.
 254   
      * Either currenttime or preservetime can be specified.
 255   
      *
 256   
      * @param ct the status to set the flag to
 257   
      */
 258  0
     public void setCurrentTime(boolean ct) {
 259  0
         m_Ctime = ct;
 260   
     }
 261   
 
 262   
     /**
 263   
      * Get current time status
 264   
      *
 265   
      * @return boolean containing status of current time flag
 266   
      */
 267  0
     public boolean getCurrentTime() {
 268  0
         return m_Ctime;
 269   
     }
 270   
 
 271   
     /**
 272   
      * If true, modification time should be preserved from the VOB time.
 273   
      * Either currenttime or preservetime can be specified.
 274   
      *
 275   
      * @param pt the status to set the flag to
 276   
      */
 277  0
     public void setPreserveTime(boolean pt) {
 278  0
         m_Ptime = pt;
 279   
     }
 280   
 
 281   
     /**
 282   
      * Get preserve time status
 283   
      *
 284   
      * @return boolean containing status of preserve time flag
 285   
      */
 286  0
     public boolean getPreserveTime() {
 287  0
         return m_Ptime;
 288   
     }
 289   
 
 290   
     /**
 291   
      * Sets the log file where cleartool records
 292   
      * the status of the command.
 293   
      *
 294   
      * @param log the path to the log file
 295   
      */
 296  0
     public void setLog(String log) {
 297  0
         m_Log = log;
 298   
     }
 299   
 
 300   
     /**
 301   
      * Get log file
 302   
      *
 303   
      * @return String containing the path to the log file
 304   
      */
 305  0
     public String getLog() {
 306  0
         return m_Log;
 307   
     }
 308   
 
 309   
     /**
 310   
      * Get the 'log' command
 311   
      *
 312   
      * @param cmd containing the command line string with or without the log flag and path appended
 313   
      */
 314  0
     private void getLogCommand(Commandline cmd) {
 315  0
         if (getLog() == null) {
 316  0
             return;
 317   
         } else {
 318   
             /* Had to make two separate commands here because if a space is
 319   
                inserted between the flag and the value, it is treated as a
 320   
                Windows filename with a space and it is enclosed in double
 321   
                quotes ("). This breaks clearcase.
 322   
             */
 323  0
             cmd.createArgument().setValue(FLAG_LOG);
 324  0
             cmd.createArgument().setValue(getLog());
 325   
         }
 326   
     }
 327   
 
 328   
     /**
 329   
      *  -graphical flag -- display graphical dialog during update operation
 330   
      */
 331   
     public static final String FLAG_GRAPHICAL = "-graphical";
 332   
     /**
 333   
      * -log flag -- file to log status to
 334   
      */
 335   
     public static final String FLAG_LOG = "-log";
 336   
     /**
 337   
      * -overwrite flag -- overwrite hijacked files
 338   
      */
 339   
     public static final String FLAG_OVERWRITE = "-overwrite";
 340   
     /**
 341   
      * -noverwrite flag -- do not overwrite hijacked files
 342   
      */
 343   
     public static final String FLAG_NOVERWRITE = "-noverwrite";
 344   
     /**
 345   
      * -rename flag -- rename hijacked files with .keep extension
 346   
      */
 347   
     public static final String FLAG_RENAME = "-rename";
 348   
     /**
 349   
      * -ctime flag -- modified time is written as the current time
 350   
      */
 351   
     public static final String FLAG_CURRENTTIME = "-ctime";
 352   
     /**
 353   
      * -ptime flag -- modified time is written as the VOB time
 354   
      */
 355   
     public static final String FLAG_PRESERVETIME = "-ptime";
 356   
 
 357   
 }
 358   
 
 359