Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 368   Methods: 20
NCLOC: 142   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
CCMCreateTask.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   
 
 55   
 package org.apache.tools.ant.taskdefs.optional.ccm;
 56   
 
 57   
 
 58   
 import java.io.BufferedReader;
 59   
 import java.io.IOException;
 60   
 import java.io.InputStream;
 61   
 import java.io.InputStreamReader;
 62   
 import java.io.OutputStream;
 63   
 import org.apache.tools.ant.BuildException;
 64   
 import org.apache.tools.ant.Project;
 65   
 import org.apache.tools.ant.taskdefs.ExecuteStreamHandler;
 66   
 import org.apache.tools.ant.types.Commandline;
 67   
 
 68   
 
 69   
 /**
 70   
  * Creates new Continuus ccm task and sets it as the default.
 71   
  *
 72   
  * @author Benoit Moussaud benoit.moussaud@criltelecom.com
 73   
  *
 74   
  * @ant.task name="ccmcreatetask" category="scm"
 75   
  */
 76   
 public class CCMCreateTask extends Continuus implements ExecuteStreamHandler {
 77   
 
 78   
     private String comment = null;
 79   
     private String platform = null;
 80   
     private String resolver = null;
 81   
     private String release = null;
 82   
     private String subSystem = null;
 83   
     private String task = null;
 84   
 
 85  0
     public CCMCreateTask() {
 86  0
         super();
 87  0
         setCcmAction(COMMAND_CREATE_TASK);
 88   
     }
 89   
 
 90   
 
 91   
     /**
 92   
      * Executes the task.
 93   
      * <p>
 94   
      * Builds a command line to execute ccm and then calls Exec's run method
 95   
      * to execute the command line.
 96   
      * </p>
 97   
      */
 98  0
     public void execute() throws BuildException {
 99  0
         Commandline commandLine = new Commandline();
 100  0
         int result = 0;
 101   
 
 102   
         // build the command line from what we got the format
 103   
         // as specified in the CCM.EXE help
 104  0
         commandLine.setExecutable(getCcmCommand());
 105  0
         commandLine.createArgument().setValue(getCcmAction());
 106   
 
 107  0
         checkOptions(commandLine);
 108   
 
 109  0
         result = run(commandLine, this);
 110  0
         if (result != 0) {
 111  0
             String msg = "Failed executing: " + commandLine.toString();
 112  0
             throw new BuildException(msg, getLocation());
 113   
         }
 114   
 
 115   
         //create task ok, set this task as the default one
 116  0
         Commandline commandLine2 = new Commandline();
 117  0
         commandLine2.setExecutable(getCcmCommand());
 118  0
         commandLine2.createArgument().setValue(COMMAND_DEFAULT_TASK);
 119  0
         commandLine2.createArgument().setValue(getTask());
 120   
 
 121  0
         log(commandLine.describeCommand(), Project.MSG_DEBUG);
 122   
 
 123  0
         result = run(commandLine2);
 124  0
         if (result != 0) {
 125  0
             String msg = "Failed executing: " + commandLine2.toString();
 126  0
             throw new BuildException(msg, getLocation());
 127   
         }
 128   
 
 129   
     }
 130   
 
 131   
 
 132   
     /**
 133   
      * Check the command line options.
 134   
      */
 135  0
     private void checkOptions(Commandline cmd) {
 136  0
         if (getComment() != null) {
 137  0
             cmd.createArgument().setValue(FLAG_COMMENT);
 138  0
             cmd.createArgument().setValue("\"" + getComment() + "\"");
 139   
         }
 140   
 
 141  0
         if (getPlatform() != null) {
 142  0
             cmd.createArgument().setValue(FLAG_PLATFORM);
 143  0
             cmd.createArgument().setValue(getPlatform());
 144   
         } // end of if ()
 145   
 
 146  0
         if (getResolver() != null) {
 147  0
             cmd.createArgument().setValue(FLAG_RESOLVER);
 148  0
             cmd.createArgument().setValue(getResolver());
 149   
         } // end of if ()
 150   
 
 151  0
         if (getSubSystem() != null) {
 152  0
             cmd.createArgument().setValue(FLAG_SUBSYSTEM);
 153  0
             cmd.createArgument().setValue("\"" + getSubSystem() + "\"");
 154   
         } // end of if ()
 155   
 
 156  0
         if (getRelease() != null) {
 157  0
             cmd.createArgument().setValue(FLAG_RELEASE);
 158  0
             cmd.createArgument().setValue(getRelease());
 159   
         } // end of if ()
 160   
     }
 161   
 
 162   
 
 163   
     /**
 164   
      * Get the value of comment.
 165   
      * @return value of comment.
 166   
      */
 167  0
     public String getComment() {
 168  0
         return comment;
 169   
     }
 170   
 
 171   
     /**
 172   
      * Specifies a comment.
 173   
      *
 174   
      * @param v  Value to assign to comment.
 175   
      */
 176  0
     public void setComment(String v) {
 177  0
         this.comment = v;
 178   
     }
 179   
 
 180   
 
 181   
     /**
 182   
      * Get the value of platform.
 183   
      * @return value of platform.
 184   
      */
 185  0
     public String getPlatform() {
 186  0
         return platform;
 187   
     }
 188   
 
 189   
     /**
 190   
      * Specifies the target platform.
 191   
      *
 192   
      * @param v  Value to assign to platform.
 193   
      */
 194  0
     public void setPlatform(String v) {
 195  0
         this.platform = v;
 196   
     }
 197   
 
 198   
 
 199   
     /**
 200   
      * Get the value of resolver.
 201   
      * @return value of resolver.
 202   
      */
 203  0
     public String getResolver() {
 204  0
         return resolver;
 205   
     }
 206   
 
 207   
     /**
 208   
      * Specifies the resolver.
 209   
      *
 210   
      * @param v  Value to assign to resolver.
 211   
      */
 212  0
     public void setResolver(String v) {
 213  0
         this.resolver = v;
 214   
     }
 215   
 
 216   
 
 217   
     /**
 218   
      * Get the value of release.
 219   
      * @return value of release.
 220   
      */
 221  0
     public String getRelease() {
 222  0
         return release;
 223   
     }
 224   
 
 225   
     /**
 226   
      * Specify the CCM release.
 227   
      *
 228   
      * @param v  Value to assign to release.
 229   
      */
 230  0
     public void setRelease(String v) {
 231  0
         this.release = v;
 232   
     }
 233   
 
 234   
     /**
 235   
      * Get the value of subSystem.
 236   
      * @return value of subSystem.
 237   
      */
 238  0
     public String getSubSystem() {
 239  0
         return subSystem;
 240   
     }
 241   
 
 242   
     /**
 243   
      * Specifies the subsystem.
 244   
      *
 245   
      * @param v  Value to assign to subSystem.
 246   
      */
 247  0
     public void setSubSystem(String v) {
 248  0
         this.subSystem = v;
 249   
     }
 250   
 
 251   
 
 252   
     /**
 253   
      * Get the value of task.
 254   
      * @return value of task.
 255   
      */
 256  0
     public String getTask() {
 257  0
         return task;
 258   
     }
 259   
 
 260   
     /**
 261   
      * Specifies the task number used to checkin
 262   
      * the file (may use 'default').
 263   
      *
 264   
      * @param v  Value to assign to task.
 265   
      */
 266  0
     public void setTask(String v) {
 267  0
         this.task = v;
 268   
     }
 269   
 
 270   
     /**
 271   
      * /comment -- comments associated to the task
 272   
      */
 273   
     public static final String FLAG_COMMENT = "/synopsis";
 274   
 
 275   
     /**
 276   
      *  /platform flag -- target platform
 277   
      */
 278   
     public static final String FLAG_PLATFORM = "/plat";
 279   
 
 280   
     /**
 281   
      * /resolver flag
 282   
      */
 283   
     public static final String FLAG_RESOLVER = "/resolver";
 284   
 
 285   
     /**
 286   
      * /release flag
 287   
      */
 288   
     public static final String FLAG_RELEASE = "/release";
 289   
 
 290   
     /**
 291   
      * /release flag
 292   
      */
 293   
     public static final String FLAG_SUBSYSTEM = "/subsystem";
 294   
 
 295   
     /**
 296   
      *  -task flag -- associate checckout task with task
 297   
      */
 298   
     public static final String FLAG_TASK = "/task";
 299   
 
 300   
 
 301   
     // implementation of org.apache.tools.ant.taskdefs.ExecuteStreamHandler interface
 302   
 
 303   
     /**
 304   
      *
 305   
      * @exception java.io.IOException
 306   
      */
 307  0
     public void start() throws IOException {
 308   
     }
 309   
 
 310   
     /**
 311   
      *
 312   
      */
 313  0
     public void stop() {
 314   
     }
 315   
 
 316   
     /**
 317   
      *
 318   
      * @param param1
 319   
      * @exception java.io.IOException
 320   
      */
 321  0
     public void setProcessInputStream(OutputStream param1) throws IOException {
 322   
     }
 323   
 
 324   
     /**
 325   
      *
 326   
      * @param is
 327   
      * @exception java.io.IOException
 328   
      */
 329  0
     public void setProcessErrorStream(InputStream is) throws IOException {
 330  0
         BufferedReader reader = new BufferedReader(new InputStreamReader(is));
 331  0
         String s = reader.readLine();
 332  0
         if (s != null) {
 333  0
             log("err " + s, Project.MSG_DEBUG);
 334   
         } // end of if ()
 335   
     }
 336   
 
 337   
     /**
 338   
      * read the output stream to retrieve the new task number.
 339   
      * @param is InputStream
 340   
      * @exception java.io.IOException
 341   
      */
 342  0
     public void setProcessOutputStream(InputStream is) throws IOException {
 343   
 
 344  0
         String buffer = "";
 345  0
         try {
 346  0
             BufferedReader reader = new BufferedReader(new InputStreamReader(is));
 347  0
             buffer = reader.readLine();
 348  0
             if (buffer != null) {
 349  0
                 log("buffer:" + buffer, Project.MSG_DEBUG);
 350  0
                 String taskstring = buffer.substring(buffer.indexOf(' ')).trim();
 351  0
                 taskstring = taskstring.substring(0, taskstring.lastIndexOf(' ')).trim();
 352  0
                 setTask(taskstring);
 353  0
                 log("task is " + getTask(), Project.MSG_DEBUG);
 354   
             } // end of if ()
 355   
         } catch (NullPointerException npe) {
 356  0
             log("error procession stream , null pointer exception", Project.MSG_ERR);
 357  0
             npe.printStackTrace();
 358  0
             throw new BuildException(npe.getClass().getName());
 359   
         } catch (Exception e) {
 360  0
             log("error procession stream " + e.getMessage(), Project.MSG_ERR);
 361  0
             throw new BuildException(e.getMessage());
 362   
         } // end of try-catch
 363   
 
 364   
     }
 365   
 
 366   
 }
 367   
 
 368