Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 216   Methods: 8
NCLOC: 105   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
P4Fstat.java 0% 0% 0% 0%
 1   
 /*
 2   
  * The Apache Software License, Version 1.1
 3   
  *
 4   
  * Copyright (c) 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 java.util.ArrayList;
 66   
 
 67   
 import org.apache.tools.ant.BuildException;
 68   
 import org.apache.tools.ant.DirectoryScanner;
 69   
 import org.apache.tools.ant.Project;
 70   
 import org.apache.tools.ant.types.FileSet;
 71   
 
 72   
 /**
 73   
  * P4Fstat  - find out which files are under Perforce control and which are not.
 74   
  *
 75   
  * <br><b>Example Usage:</b><br>
 76   
  * <pre>
 77   
  * &lt;project name=&quot;p4fstat&quot; default=&quot;p4fstat&quot; basedir=&quot;C:\dev\gnu&quot;&gt;
 78   
  *     &lt;target name=&quot;p4fstat&quot; &gt;
 79   
  *         &lt;p4fstat showfilter=&quot;all&quot;&gt;
 80   
  *             &lt;fileset dir=&quot;depot&quot; includes=&quot;**\/*&quot;/&gt;
 81   
  *         &lt;/p4fstat&gt;
 82   
  *     &lt;/target&gt;
 83   
  * &lt;/project&gt;
 84   
  * </pre>
 85   
  *
 86   
  * @author <A HREF="mailto:miha@softhome.net">Miha</A>
 87   
  * @author <A HREF="mailto:leslie.hughes@rubus.com">Les Hughes</A>
 88   
  * @author <A HREF="mailto:ashundi@tibco.com">Anli Shundi</A>
 89   
  *
 90   
  * @ant.task category="scm"
 91   
  */
 92   
 public class P4Fstat extends P4Base {
 93   
 
 94   
     private int changelist;
 95   
     private String addCmd = "";
 96   
     private Vector filesets = new Vector();
 97   
     private int cmdLength = 300;
 98   
     private static final int SHOW_ALL = 0;
 99   
     private static final int SHOW_EXISTING = 1;
 100   
     private static final int SHOW_NON_EXISTING = 2;
 101   
     private int show = SHOW_NON_EXISTING;
 102   
     private FStatP4OutputHandler handler;
 103   
     private StringBuffer filelist;
 104   
     private int fileNum = 0;
 105   
     private int doneFileNum = 0;
 106   
     private boolean debug = false;
 107   
 
 108   
     private static final String EXISTING_HEADER
 109   
         = "Following files exist in perforce";
 110   
     private static final String NONEXISTING_HEADER
 111   
         = "Following files do not exist in perforce";
 112   
 
 113   
 
 114  0
     public void setShowFilter(String filter) {
 115  0
         if (filter.equalsIgnoreCase("all")) {
 116  0
             show = SHOW_ALL;
 117  0
         } else if (filter.equalsIgnoreCase("existing")) {
 118  0
             show = SHOW_EXISTING;
 119  0
         } else if (filter.equalsIgnoreCase("non-existing")) {
 120  0
             show = SHOW_NON_EXISTING;
 121   
         } else {
 122  0
             throw new BuildException("P4Fstat: ShowFilter should be one of: "
 123   
                 + "all, existing, non-existing");
 124   
         }
 125   
     }
 126   
 
 127   
 
 128  0
     public void setChangelist(int changelist) throws BuildException {
 129  0
         if (changelist <= 0) {
 130  0
             throw new BuildException("P4FStat: Changelist# should be a "
 131   
                 + "positive number");
 132   
         }
 133   
 
 134  0
         this.changelist = changelist;
 135   
     }
 136   
 
 137  0
     public void addFileset(FileSet set) {
 138  0
         filesets.addElement(set);
 139   
     }
 140   
 
 141  0
     public void execute() throws BuildException {
 142   
 
 143  0
         handler = new FStatP4OutputHandler(this);
 144  0
         if (P4View != null) {
 145  0
             addCmd = P4View;
 146   
         }
 147   
 
 148  0
         P4CmdOpts = (changelist > 0) ? ("-c " + changelist) : "";
 149   
 
 150  0
         filelist = new StringBuffer();
 151   
 
 152  0
         for (int i = 0; i < filesets.size(); i++) {
 153  0
             FileSet fs = (FileSet) filesets.elementAt(i);
 154  0
             DirectoryScanner ds = fs.getDirectoryScanner(getProject());
 155   
             //File fromDir = fs.getDir(project);
 156   
 
 157  0
             String[] srcFiles = ds.getIncludedFiles();
 158  0
             fileNum = srcFiles.length;
 159   
 
 160  0
             if (srcFiles != null) {
 161  0
                 for (int j = 0; j < srcFiles.length; j++) {
 162  0
                     File f = new File(ds.getBasedir(), srcFiles[j]);
 163  0
                     filelist.append(" ").append('"').append(f.getAbsolutePath()).append('"');
 164  0
                     doneFileNum++;
 165  0
                     if (filelist.length() > cmdLength) {
 166   
 
 167  0
                         execP4Fstat(filelist);
 168  0
                         filelist = new StringBuffer();
 169   
                     }
 170   
                 }
 171  0
                 if (filelist.length() > 0) {
 172  0
                     execP4Fstat(filelist);
 173   
                 }
 174   
             } else {
 175  0
                 log("No files specified to add!", Project.MSG_WARN);
 176   
             }
 177   
         }
 178   
 
 179  0
         if (show == SHOW_ALL || show == SHOW_EXISTING) {
 180  0
             printRes(handler.getExisting(), EXISTING_HEADER);
 181   
         }
 182   
 
 183  0
         if (show == SHOW_ALL || show == SHOW_NON_EXISTING) {
 184  0
             printRes(handler.getNonExisting(), NONEXISTING_HEADER);
 185   
         }
 186   
 
 187   
     }
 188   
 
 189   
 
 190  0
     public int getLengthOfTask() {
 191  0
         return fileNum;
 192   
     }
 193   
 
 194  0
     int getPasses() {
 195  0
         return filesets.size();
 196   
     }
 197   
 
 198   
 
 199  0
     private void printRes(ArrayList ar, String header) {
 200  0
         log(header, Project.MSG_INFO);
 201  0
         for (int i = 0; i < ar.size(); i++) {
 202  0
             log((String) ar.get(i), Project.MSG_INFO);
 203   
         }
 204   
     }
 205   
 
 206  0
     private void execP4Fstat(StringBuffer list) {
 207  0
         String l = list.substring(0);
 208  0
         if (debug) {
 209  0
             log("Executing fstat " + P4CmdOpts + " " + addCmd + l + "\n",
 210   
                 Project.MSG_INFO);
 211   
         }
 212  0
         execP4Command("fstat " + P4CmdOpts + " " + addCmd + l, handler);
 213   
     }
 214   
 
 215   
 }
 216