Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 238   Methods: 11
NCLOC: 93   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
CCMCheck.java 0% 0% 0% 0%
 1   
 /*
 2   
  * The Apache Software License, Version 1.1
 3   
  *
 4   
  * Copyright (c) 2001-2003 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.File;
 59   
 import java.util.Vector;
 60   
 import org.apache.tools.ant.BuildException;
 61   
 import org.apache.tools.ant.DirectoryScanner;
 62   
 import org.apache.tools.ant.Project;
 63   
 import org.apache.tools.ant.types.Commandline;
 64   
 import org.apache.tools.ant.types.FileSet;
 65   
 
 66   
 
 67   
 /**
 68   
  * Class common to all check commands (checkout, checkin,checkin default task);
 69   
  * @author Benoit Moussaud benoit.moussaud@criltelecom.com
 70   
  * @ant.task ignore="true"
 71   
  */
 72   
 public class CCMCheck extends Continuus {
 73   
 
 74   
     private File file = null;
 75   
     private String comment = null;
 76   
     private String task = null;
 77   
  
 78   
     protected Vector filesets = new Vector();
 79   
 
 80  0
     public CCMCheck() {
 81  0
         super();
 82   
     }
 83   
 
 84   
     /**
 85   
      * Get the value of file.
 86   
      * @return value of file.
 87   
      */
 88  0
     public File getFile() {
 89  0
         return file;
 90   
     }
 91   
 
 92   
     /**
 93   
      * Sets the path to the file that the command will operate on.
 94   
      * @param v  Value to assign to file.
 95   
      */
 96  0
     public void setFile(File v) {
 97  0
         log("working file "+v, Project.MSG_VERBOSE);
 98  0
         this.file = v;
 99   
     }
 100   
 
 101   
     /**
 102   
      * Get the value of comment.
 103   
      * @return value of comment.
 104   
      */
 105  0
     public String getComment() {
 106  0
         return comment;
 107   
     }
 108   
 
 109   
     /**
 110   
      * Specifies a comment.
 111   
      * @param v  Value to assign to comment.
 112   
      */
 113  0
     public void setComment(String v) {
 114  0
         this.comment = v;
 115   
     }
 116   
 
 117   
 
 118   
     /**
 119   
      * Get the value of task.
 120   
      * @return value of task.
 121   
      */
 122  0
     public String getTask() {
 123  0
         return task;
 124   
     }
 125   
 
 126   
     /**
 127   
      * Specifies the task number used to check
 128   
      * in the file (may use 'default').
 129   
      * @param v  Value to assign to task.
 130   
      */
 131  0
     public void setTask(String v) {
 132  0
         this.task = v;
 133   
     }
 134   
 
 135   
 
 136   
     /**
 137   
      * Adds a set of files to copy.
 138   
      */
 139  0
     public void addFileset(FileSet set) {
 140  0
         filesets.addElement(set);
 141   
     }
 142   
 
 143   
 
 144   
     /**
 145   
      * Executes the task.
 146   
      * <p>
 147   
      * Builds a command line to execute ccm and then calls Exec's run method
 148   
      * to execute the command line.
 149   
      * </p>
 150   
      */
 151  0
     public void execute() throws BuildException {
 152   
 
 153  0
         if (file == null && filesets.size() == 0) {
 154  0
             throw new BuildException(
 155   
                 "Specify at least one source - a file or a fileset.");
 156   
         }
 157   
 
 158  0
         if (file != null && file.exists() && file.isDirectory()) {
 159  0
             throw new BuildException("CCMCheck cannot be generated for directories");
 160   
         }
 161   
         
 162  0
         if (file != null  && filesets.size() > 0) {
 163  0
             throw new BuildException("Choose between file and fileset !");
 164   
         }
 165   
 
 166  0
         if ( getFile() !=null ) {
 167  0
             doit();
 168  0
             return ;
 169   
         }
 170   
                         
 171  0
         int sizeofFileSet = filesets.size();
 172  0
         for (int i = 0; i < sizeofFileSet; i++) {
 173  0
             FileSet fs = (FileSet) filesets.elementAt(i);
 174  0
             DirectoryScanner ds = fs.getDirectoryScanner(project);
 175  0
             String[] srcFiles = ds.getIncludedFiles();
 176  0
             for (int j = 0; j < srcFiles.length; j++) {
 177  0
                 File src = new File(fs.getDir(project), srcFiles[j]);
 178  0
                 setFile(src);
 179  0
                 doit();
 180   
             }
 181   
         }
 182   
     }
 183   
     
 184   
     /**
 185   
      * check the file given by getFile().
 186   
      */
 187  0
     private void doit()
 188   
     {
 189  0
         Commandline commandLine = new Commandline();
 190   
 
 191   
         // build the command line from what we got the format is
 192   
         // ccm co /t .. files
 193   
         // as specified in the CCM.EXE help
 194   
 
 195  0
         commandLine.setExecutable(getCcmCommand());
 196  0
         commandLine.createArgument().setValue(getCcmAction());
 197   
         
 198  0
         checkOptions(commandLine);
 199   
         
 200  0
         int result = run(commandLine);
 201  0
         if (result != 0) {
 202  0
             String msg = "Failed executing: " + commandLine.toString();
 203  0
             throw new BuildException(msg, getLocation());
 204   
         }
 205   
     }
 206   
 
 207   
 
 208   
     /**
 209   
      * Check the command line options.
 210   
      */
 211  0
     private void checkOptions(Commandline cmd) {
 212  0
         if (getComment() != null) {
 213  0
             cmd.createArgument().setValue(FLAG_COMMENT);
 214  0
             cmd.createArgument().setValue(getComment());
 215   
         }
 216   
 
 217  0
         if (getTask() != null) {
 218  0
             cmd.createArgument().setValue(FLAG_TASK);
 219  0
             cmd.createArgument().setValue(getTask());
 220   
         } 
 221   
 
 222  0
         if (getFile() != null) {
 223  0
             cmd.createArgument().setValue(file.getAbsolutePath());
 224   
         } 
 225   
     }
 226   
 
 227   
     /**
 228   
      * -comment flag -- comment to attach to the file
 229   
      */
 230   
     public static final String FLAG_COMMENT = "/comment";
 231   
 
 232   
     /**
 233   
      *  -task flag -- associate checckout task with task
 234   
      */
 235   
     public static final String FLAG_TASK = "/task";
 236   
 }
 237   
 
 238