Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 325   Methods: 11
NCLOC: 158   Classes: 2
 
 Source file Conditionals Statements Methods TOTAL
StarTeamList.java 6.7% 5.6% 9.1% 6.2%
 1   
 /*
 2   
  * The Apache Software License, Version 1.1
 3   
  *
 4   
  * Copyright (c) 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   
 package org.apache.tools.ant.taskdefs.optional.starteam;
 55   
 
 56   
 import com.starbase.starteam.File;
 57   
 import com.starbase.starteam.Folder;
 58   
 import com.starbase.starteam.Item;
 59   
 import com.starbase.starteam.Status;
 60   
 import com.starbase.starteam.View;
 61   
 import com.starbase.starteam.ViewConfiguration;
 62   
 import java.io.IOException;
 63   
 import java.text.SimpleDateFormat;
 64   
 import java.util.Enumeration;
 65   
 import java.util.Hashtable;
 66   
 import org.apache.tools.ant.BuildException;
 67   
 import org.apache.tools.ant.Project;
 68   
 
 69   
 /**
 70   
  * Produces a listing of the contents of the StarTeam repository
 71   
  * at the specified view and StarTeamFolder.
 72   
  *
 73   
  * Created: Tue Dec 25 06:51:14 2001
 74   
  *
 75   
  * @author <a href="mailto:stevec@ignitesports.com">Steve Cohen</a>
 76   
  * @version 1.0
 77   
  *
 78   
  * @ant.task name="stlist" category="scm"
 79   
  */
 80   
 
 81   
 public class StarTeamList extends TreeBasedTask {
 82   
     private boolean listUncontrolled = true;
 83   
     /**
 84   
      * List files, dates, and statuses as of this label; optional.
 85   
      * The label must exist in starteam or an exception will be thrown.  
 86   
      * If not specified, the most recent version of each file will be listed.
 87   
      *
 88   
      * @param label the label to be listed
 89   
      */
 90  0
     public void setLabel(String label) {
 91  0
         _setLabel(label);
 92   
     }
 93   
 
 94   
     /**
 95   
      * Override of base-class abstract function creates an
 96   
      * appropriately configured view for checkoutlists - either
 97   
      * the current view or a view from this.label.   
 98   
      *
 99   
      * @param raw the unconfigured <code>View</code>
 100   
      * @return the snapshot <code>View</code> appropriately configured.
 101   
      */
 102  0
     protected View createSnapshotView(View raw) {
 103   
 
 104  0
         int labelID = getLabelID(raw);
 105   
 
 106   
         // if a label has been supplied, use it to configure the view
 107   
         // otherwise use current view
 108  0
         if (labelID >= 0) {
 109  0
             return new View(raw, ViewConfiguration.createFromLabel(labelID));
 110   
         } else {
 111  0
             return new View(raw, ViewConfiguration.createTip());
 112   
         }
 113   
     }
 114   
 
 115   
     /**
 116   
      * Required base-class abstract function implementation is a no-op here.
 117   
      *
 118   
      * @exception BuildException not thrown in this implementation
 119   
      */
 120  0
     protected void testPreconditions() throws BuildException {
 121   
         //intentionally do nothing.
 122   
     }
 123   
 
 124   
     /**
 125   
      * extenders should emit to the log an entry describing the parameters
 126   
      * that will be used by this operation.
 127   
      *
 128   
      * @param starteamrootFolder
 129   
      *               root folder in StarTeam for the operation
 130   
      * @param targetrootFolder
 131   
      *               root local folder for the operation (whether specified by the user or not.
 132   
      */
 133  0
     protected void logOperationDescription(Folder starteamrootFolder, java.io.File targetrootFolder) {
 134  0
         log((this.isRecursive() ? "Recursive" : "Non-recursive") + 
 135   
             " Listing of: " + starteamrootFolder.getFolderHierarchy());
 136   
 
 137  0
         log("Listing against local folder" 
 138   
             + (null == getRootLocalFolder() ? " (default): " : ": ") 
 139   
             + targetrootFolder.getAbsolutePath(),
 140   
                     Project.MSG_INFO);
 141  0
         logLabel();
 142  0
         logIncludes();
 143  0
         logExcludes();
 144   
 
 145   
 
 146   
     }
 147   
     /**
 148   
      * Implements base-class abstract function to perform the checkout
 149   
      * operation on the files in each folder of the tree.
 150   
      *
 151   
      * @param starteamFolder the StarTeam folder from which files to be
 152   
      *                       checked out
 153   
      * @param targetFolder the local mapping of rootStarteamFolder
 154   
      */
 155  0
     protected void visit(Folder starteamFolder, java.io.File targetFolder)
 156   
             throws BuildException {
 157  0
         try {
 158  0
             if (null != getRootLocalFolder()) {
 159  0
                 starteamFolder.setAlternatePathFragment(
 160   
                     targetFolder.getAbsolutePath());
 161   
 
 162   
             }
 163  0
             Folder[] subFolders = starteamFolder.getSubFolders();
 164  0
             Item[] files = starteamFolder.getItems(getTypeNames().FILE);
 165   
             
 166  0
             UnmatchedFileMap ufm = 
 167   
                 new UnmatchedListingMap().init(
 168   
                     targetFolder.getAbsoluteFile(), starteamFolder);
 169   
 
 170  0
             log("");
 171  0
             log("Listing StarTeam folder " + 
 172   
                 starteamFolder.getFolderHierarchy()); 
 173  0
             log(" against local folder " + 
 174   
                 targetFolder.getAbsolutePath());
 175   
 
 176   
 
 177   
             // For all Files in this folder, we need to check
 178   
             // if there have been modifications.
 179   
 
 180  0
             for (int i = 0; i < files.length; i++) {
 181  0
                 File eachFile = (File) files[i];
 182  0
                 String filename = eachFile.getName();
 183  0
                 java.io.File localFile =
 184   
                         new java.io.File(targetFolder, filename);
 185   
 
 186  0
                 ufm.removeControlledItem(localFile);
 187   
 
 188   
                 // If the file doesn't pass the include/exclude tests, skip it.
 189  0
                 if (!shouldProcess(filename)) {
 190  0
                     continue;
 191   
                 }
 192   
 
 193  0
                 list(eachFile, localFile);
 194   
             }
 195   
 
 196   
 
 197   
             // Now we recursively call this method on all sub folders in this
 198   
             // folder unless recursive attribute is off.
 199  0
             for (int i = 0; i < subFolders.length; i++) {
 200  0
                 java.io.File targetSubfolder =
 201   
                         new java.io.File(targetFolder, subFolders[i].getName());
 202  0
                 ufm.removeControlledItem(targetSubfolder);
 203  0
                 if (isRecursive()) {
 204  0
                     visit(subFolders[i], targetSubfolder);
 205   
                 }
 206   
             }
 207  0
             if (this.listUncontrolled) {
 208  0
                 ufm.processUncontrolledItems();
 209   
             }
 210   
 
 211   
         } catch (IOException e) {
 212  0
             throw new BuildException(e);
 213   
         }
 214   
     }
 215   
 
 216   
     private static final SimpleDateFormat SDF = 
 217   
         new SimpleDateFormat("yyyy-MM-dd hh:mm:ss zzz");
 218   
 
 219  0
     protected void list(File reposFile, java.io.File localFile)
 220   
             throws IOException {
 221  0
         StringBuffer b = new StringBuffer();
 222  0
         int status = reposFile.getStatus();
 223  0
         java.util.Date displayDate = null;
 224  0
         if (status==Status.NEW) {
 225  0
             displayDate = new java.util.Date(localFile.lastModified());
 226   
         } else {
 227  0
             displayDate = reposFile.getModifiedTime().createDate();
 228   
         }
 229  0
         b.append(pad(Status.name(status), 12)).append(' ');
 230  0
         b.append(pad(getUserName(reposFile.getLocker()), 20))
 231   
                 .append(' ')
 232   
                 .append(SDF.format(displayDate))
 233   
                 .append(rpad(String.valueOf(reposFile.getSize()), 9))
 234   
                 .append(' ')
 235   
                 .append(reposFile.getName());
 236   
 
 237  0
         log(b.toString());
 238   
     }
 239   
 
 240   
     private static final String blankstr = blanks(30);
 241   
 
 242  1
     private static String blanks(int len) {
 243  1
         StringBuffer b = new StringBuffer();
 244  1
         for (int i = 0; i < len; i++) {
 245  30
             b.append(' ');
 246   
         }
 247  1
         return b.toString();
 248   
     }
 249   
 
 250  0
     protected static String pad(String s, int padlen) {
 251  0
         return (s + blankstr).substring(0, padlen);
 252   
     }
 253   
 
 254  0
     protected static String rpad(String s, int padlen) {
 255  0
         s = blankstr + s;
 256  0
         return s.substring(s.length() - padlen);
 257   
     }
 258   
 
 259   
     /**
 260   
      * handles the list of uncontrolled items
 261   
      */
 262   
     private class UnmatchedListingMap extends UnmatchedFileMap {
 263   
 
 264  0
         protected boolean isActive() {
 265  0
             return StarTeamList.this.listUncontrolled;
 266   
         }
 267   
     
 268   
         /**
 269   
          * lists uncontrolled items from the local tree.  It is assumed
 270   
          * that this method will not be called until all the items in the
 271   
          * corresponding folder have been processed, and that the internal map
 272   
          * will contain only uncontrolled items.
 273   
          */
 274  0
         void processUncontrolledItems() throws BuildException{
 275  0
             if (this.isActive()) {
 276  0
                 Enumeration e = this.keys();
 277   
                 
 278   
                 // handle the files so they appear first
 279  0
                 while (e.hasMoreElements()) {
 280  0
                     java.io.File local = (java.io.File) e.nextElement();
 281  0
                     Item remoteItem = (Item) this.get(local);
 282   
 
 283   
                     // once we find a folder that isn't in the repository, 
 284   
                     // we know we can add it.
 285  0
                     if (local.isFile()) {
 286  0
                         com.starbase.starteam.File remoteFile =
 287   
                             (com.starbase.starteam.File) remoteItem;
 288  0
                         try {
 289  0
                             list(remoteFile, local);
 290   
                         } catch (IOException ie) {
 291  0
                             throw new BuildException("IOError in stlist",ie);
 292   
                         }
 293   
                     }
 294   
                 }
 295   
                 // now do it again for the directories so they appear last.
 296  0
                 e = this.keys();
 297  0
                 while (e.hasMoreElements()) {
 298  0
                     java.io.File local = (java.io.File) e.nextElement();
 299  0
                     Item remoteItem = (Item) this.get(local);
 300   
 
 301   
                     // once we find a folder that isn't in the repository, 
 302   
                     // we know we can add it.
 303  0
                     if (local.isDirectory()) {
 304  0
                         Folder folder = (Folder) remoteItem;
 305  0
                         if (isRecursive()) {
 306  0
                             log("Listing uncontrolled folder " 
 307   
                                 + folder.getFolderHierarchy()
 308   
                                 + " from " + local.getAbsoluteFile());
 309  0
                             UnmatchedFileMap submap = 
 310   
                                 new UnmatchedListingMap().init(local, folder);
 311  0
                             submap.processUncontrolledItems();
 312   
                         }
 313   
                     }
 314   
                 }
 315   
             }
 316   
         }
 317   
 
 318   
 
 319   
     }
 320   
 
 321   
 
 322   
 }// StarTeamList
 323   
 
 324   
 
 325