Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 167   Methods: 5
NCLOC: 59   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
P4Add.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   
  * Portions of this software are based upon public domain software
 56   
  * originally written at the National Center for Supercomputing Applications,
 57   
  * University of Illinois, Urbana-Champaign.
 58   
  */
 59   
 
 60   
 package org.apache.tools.ant.taskdefs.optional.perforce;
 61   
 
 62   
 
 63   
 import java.io.File;
 64   
 import java.util.Vector;
 65   
 import org.apache.tools.ant.BuildException;
 66   
 import org.apache.tools.ant.DirectoryScanner;
 67   
 import org.apache.tools.ant.Project;
 68   
 import org.apache.tools.ant.types.FileSet;
 69   
 
 70   
 /** Adds specified files to Perforce.
 71   
  *
 72   
  * <b>Example Usage:</b>
 73   
  * <table border="1">
 74   
  * <th>Function</th><th>Command</th>
 75   
  * <tr><td>Add files using P4USER, P4PORT and P4CLIENT settings specified</td><td>&lt;P4add <br>P4view="//projects/foo/main/source/..." <br>P4User="fbloggs" <br>P4Port="km01:1666" <br>P4Client="fbloggsclient"&gt;<br>&lt;fileset basedir="dir" includes="**&#47;*.java"&gt;<br>&lt;/p4add&gt;</td></tr>
 76   
  * <tr><td>Add files using P4USER, P4PORT and P4CLIENT settings defined in environment</td><td>&lt;P4add P4view="//projects/foo/main/source/..." /&gt;<br>&lt;fileset basedir="dir" includes="**&#47;*.java"&gt;<br>&lt;/p4add&gt;</td></tr>
 77   
  * <tr><td>Specify the length of command line arguments to pass to each invocation of p4</td><td>&lt;p4add Commandlength="450"&gt;</td></tr>
 78   
  * </table>
 79   
  *
 80   
  * @author <A HREF="mailto:leslie.hughes@rubus.com">Les Hughes</A>
 81   
  * @author <A HREF="mailto:ashundi@tibco.com">Anli Shundi</A>
 82   
  *
 83   
  * @ant.task category="scm"
 84   
  */
 85   
 public class P4Add extends P4Base {
 86   
 
 87   
     private int changelist;
 88   
     private String addCmd = "";
 89   
     private Vector filesets = new Vector();
 90   
     private int cmdLength = 450;
 91   
 
 92   
     /**
 93   
      *   positive integer specifying the maximum length
 94   
      *   of the commandline when calling Perforce to add the files.
 95   
      *   Defaults to 450, higher values mean faster execution,
 96   
      *   but also possible failures.
 97   
      */
 98   
 
 99  0
     public void setCommandlength(int len) throws BuildException {
 100  0
         if (len <= 0) {
 101  0
             throw new BuildException("P4Add: Commandlength should be a positive number");
 102   
         }
 103  0
         this.cmdLength = len;
 104   
     }
 105   
 
 106   
     /**
 107   
      * If specified the open files are associated with the
 108   
      * specified pending changelist number; otherwise the open files are
 109   
      * associated with the default changelist.
 110   
      */
 111  0
     public void setChangelist(int changelist) throws BuildException {
 112  0
         if (changelist <= 0) {
 113  0
             throw new BuildException("P4Add: Changelist# should be a positive number");
 114   
         }
 115   
 
 116  0
         this.changelist = changelist;
 117   
     }
 118   
 
 119   
     /**
 120   
      * files to add
 121   
      */
 122  0
     public void addFileset(FileSet set) {
 123  0
         filesets.addElement(set);
 124   
     }
 125   
 
 126  0
     public void execute() throws BuildException {
 127   
 
 128  0
         if (P4View != null) {
 129  0
             addCmd = P4View;
 130   
         }
 131   
 
 132  0
         P4CmdOpts = (changelist > 0) ? ("-c " + changelist) : "";
 133   
 
 134  0
         StringBuffer filelist = new StringBuffer();
 135   
 
 136  0
         for (int i = 0; i < filesets.size(); i++) {
 137  0
             FileSet fs = (FileSet) filesets.elementAt(i);
 138  0
             DirectoryScanner ds = fs.getDirectoryScanner(getProject());
 139   
             //File fromDir = fs.getDir(project);
 140   
 
 141  0
             String[] srcFiles = ds.getIncludedFiles();
 142  0
             if (srcFiles != null) {
 143  0
                 for (int j = 0; j < srcFiles.length; j++) {
 144  0
                     File f = new File(ds.getBasedir(), srcFiles[j]);
 145  0
                     filelist.append(" ").append('"').append(f.getAbsolutePath()).append('"');
 146  0
                     if (filelist.length() > cmdLength) {
 147  0
                         execP4Add(filelist);
 148  0
                         filelist = new StringBuffer();
 149   
                     }
 150   
                 }
 151  0
                 if (filelist.length() > 0) {
 152  0
                     execP4Add(filelist);
 153   
                 }
 154   
             } else {
 155  0
                 log("No files specified to add!", Project.MSG_WARN);
 156   
             }
 157   
         }
 158   
 
 159   
     }
 160   
 
 161  0
     private void execP4Add(StringBuffer list) {
 162  0
         log("Execing add " + P4CmdOpts + " " + addCmd + list, Project.MSG_INFO);
 163   
 
 164  0
         execP4Command("-s add " + P4CmdOpts + " " + addCmd + list, new SimpleP4OutputHandler(this));
 165   
     }
 166   
 }
 167