Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 250   Methods: 10
NCLOC: 98   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
P4Base.java 0% 0% 0% 0%
 1   
 /*
 2   
  * The Apache Software License, Version 1.1
 3   
  *
 4   
  * Copyright (c) 2000-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   
 import java.io.IOException;
 63   
 import org.apache.oro.text.perl.Perl5Util;
 64   
 import org.apache.tools.ant.BuildException;
 65   
 import org.apache.tools.ant.Project;
 66   
 import org.apache.tools.ant.taskdefs.Execute;
 67   
 import org.apache.tools.ant.types.Commandline;
 68   
 
 69   
 
 70   
 /** Base class for Perforce (P4) ANT tasks. See individual task for example usage.
 71   
  *
 72   
  * @see P4Sync
 73   
  * @see P4Have
 74   
  * @see P4Change
 75   
  * @see P4Edit
 76   
  * @see P4Submit
 77   
  * @see P4Label
 78   
  * @see org.apache.tools.ant.taskdefs.Exec
 79   
  * @author <A HREF="mailto:leslie.hughes@rubus.com">Les Hughes</A>
 80   
  */
 81   
 public abstract class P4Base extends org.apache.tools.ant.Task {
 82   
 
 83   
     /**Perl5 regexp in Java - cool eh? */
 84   
     protected Perl5Util util = null;
 85   
     /** The OS shell to use (cmd.exe or /bin/sh) */
 86   
     protected String shell;
 87   
 
 88   
     //P4 runtime directives
 89   
     /** Perforce Server Port (eg KM01:1666) */
 90   
     protected String P4Port = "";
 91   
     /** Perforce Client (eg myclientspec) */
 92   
     protected String P4Client = "";
 93   
     /** Perforce User (eg fbloggs) */
 94   
     protected String P4User = "";
 95   
     /** Perforce view for commands. (eg //projects/foobar/main/source/... )*/
 96   
     protected String P4View = "";
 97   
 
 98   
     // Perforce task directives
 99   
     /** Keep going or fail on error - defaults to fail. */
 100   
     protected boolean failOnError = true;
 101   
 
 102   
     //P4 g-opts and cmd opts (rtfm)
 103   
     /** Perforce 'global' opts.
 104   
      * Forms half of low level API */
 105   
     protected String P4Opts = "";
 106   
     /** Perforce command opts.
 107   
      * Forms half of low level API */
 108   
     protected String P4CmdOpts = "";
 109   
 
 110   
     //Setters called by Ant
 111   
 
 112   
     /**
 113   
      * The p4d server and port to connect to;
 114   
      * optional, default "perforce:1666"
 115   
      */
 116  0
     public void setPort(String P4Port) {
 117  0
         this.P4Port = "-p" + P4Port;
 118   
     }
 119   
 
 120   
     /**
 121   
      * The p4 client spec to use;
 122   
      * optional, defaults to the current user
 123   
      */
 124  0
     public void setClient(String P4Client) {
 125  0
         this.P4Client = "-c" + P4Client;
 126   
     }
 127   
 
 128   
     /**
 129   
      * The p4 username;
 130   
      * optional, defaults to the current user
 131   
      */
 132  0
     public void setUser(String P4User) {
 133  0
         this.P4User = "-u" + P4User;
 134   
     }
 135   
     
 136   
     /**
 137   
      * Set global P4 options; Used on all
 138   
      * of the Perforce tasks.
 139   
      */ 
 140  0
     public void setGlobalopts(String P4Opts) {
 141  0
         this.P4Opts = P4Opts;
 142   
     }
 143   
 
 144   
     /**
 145   
      * The client, branch or label view to operate upon;
 146   
      * optional default "//..."
 147   
      */
 148  0
     public void setView(String P4View) {
 149  0
         this.P4View = P4View;
 150   
     }
 151   
 
 152   
     /**
 153   
      * Set extra command options; only used on some
 154   
      * of the Perforce tasks.
 155   
      */
 156  0
     public void setCmdopts(String P4CmdOpts) {
 157  0
         this.P4CmdOpts = P4CmdOpts;
 158   
     }
 159   
 
 160   
     /**
 161   
      * whether to stop the build (true, default)
 162   
      * or keep going if an error is returned from the p4 command
 163   
      */
 164  0
     public void setFailonerror(boolean fail) {
 165  0
         failOnError = fail;
 166   
     }
 167   
 
 168  0
     public void init() {
 169   
 
 170  0
         util = new Perl5Util();
 171   
 
 172   
         //Get default P4 settings from environment - Mark would have done something cool with
 173   
         //introspection here.....:-)
 174  0
         String tmpprop;
 175  0
         if ((tmpprop = getProject().getProperty("p4.port")) != null) {
 176  0
             setPort(tmpprop);
 177   
         }
 178  0
         if ((tmpprop = getProject().getProperty("p4.client")) != null) {
 179  0
             setClient(tmpprop);
 180   
         }
 181  0
         if ((tmpprop = getProject().getProperty("p4.user")) != null) {
 182  0
             setUser(tmpprop);
 183   
         }
 184   
     }
 185   
 
 186  0
     protected void execP4Command(String command) throws BuildException {
 187  0
         execP4Command(command, null);
 188   
     }
 189   
 
 190   
     /** Execute P4 command assembled by subclasses.
 191   
      @param command The command to run
 192   
      @param handler A P4Handler to process any input and output
 193   
      */
 194  0
     protected void execP4Command(String command, P4Handler handler) throws BuildException {
 195  0
         try {
 196   
 
 197  0
             Commandline commandline = new Commandline();
 198  0
             commandline.setExecutable("p4");
 199   
 
 200   
             //Check API for these - it's how CVS does it...
 201  0
             if (P4Port != null && P4Port.length() != 0) {
 202  0
                 commandline.createArgument().setValue(P4Port);
 203   
             }
 204  0
             if (P4User != null && P4User.length() != 0) {
 205  0
                 commandline.createArgument().setValue(P4User);
 206   
             }
 207  0
             if (P4Client != null && P4Client.length() != 0) {
 208  0
                 commandline.createArgument().setValue(P4Client);
 209   
             }
 210  0
             if (P4Opts != null && P4Opts.length() != 0) {
 211  0
                 commandline.createArgument().setValue(P4Opts);
 212   
             }
 213  0
             commandline.createArgument().setLine(command);
 214   
 
 215  0
             log(commandline.describeCommand(), Project.MSG_VERBOSE);
 216   
 
 217  0
             if (handler == null) {
 218  0
                 handler = new SimpleP4OutputHandler(this);
 219   
             }
 220   
 
 221  0
             Execute exe = new Execute(handler, null);
 222   
 
 223  0
             exe.setAntRun(getProject());
 224   
 
 225  0
             exe.setCommandline(commandline.getCommandline());
 226   
 
 227  0
             try {
 228  0
                 exe.execute();
 229   
             } catch (IOException e) {
 230  0
                 throw new BuildException(e);
 231   
             } finally {
 232  0
                 try {
 233  0
                     handler.stop();
 234   
                 } catch (Exception e) {
 235   
                 }
 236   
             }
 237   
 
 238   
 
 239   
         } catch (Exception e) {
 240  0
             String failMsg = "Problem exec'ing P4 command: " + e.getMessage();
 241  0
             if (failOnError) {
 242  0
                 throw new BuildException(failMsg);
 243   
             } else {
 244  0
                 log(failMsg, Project.MSG_ERR);
 245   
             }
 246   
 
 247   
         }
 248   
     }
 249   
 }
 250