Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 229   Methods: 12
NCLOC: 55   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
AbstractHotDeploymentTool.java 0% 0% 0% 0%
 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   
 
 55   
 package org.apache.tools.ant.taskdefs.optional.j2ee;
 56   
 
 57   
 import org.apache.tools.ant.BuildException;
 58   
 import org.apache.tools.ant.types.Path;
 59   
 
 60   
 /**
 61   
  *  Abstract class to support vendor-specific hot deployment tools.
 62   
  *  This class will validate boilerplate attributes.
 63   
  *
 64   
  *  Subclassing this class for a vendor specific tool involves the
 65   
  *  following.
 66   
  *  <ol><li>Implement the <code>isActionValid()<code> method to insure the
 67   
  *  action supplied as the "action" attribute of ServerDeploy is valid.
 68   
  *  <li>Implement the <code>validateAttributes()</code> method to insure
 69   
  *  all required attributes are supplied, and are in the correct format.
 70   
  *  <li>Add a <code>add&lt;TOOL&gt;</code> method to the ServerDeploy
 71   
  *  class.  This method will be called when Ant encounters a
 72   
  *  <code>add&lt;TOOL&gt;</code> task nested in the
 73   
  *  <code>serverdeploy</code> task.
 74   
  *  <li>Define the <code>deploy</code> method.  This method should perform
 75   
  *  whatever task it takes to hot-deploy the component.  IE: spawn a JVM and
 76   
  *  run class, exec a native executable, run Java code...
 77   
  *
 78   
  *  @author Christopher A. Longo - cal@cloud9.net
 79   
  *
 80   
  *  @see org.apache.tools.ant.taskdefs.optional.j2ee.HotDeploymentTool
 81   
  *  @see org.apache.tools.ant.taskdefs.optional.j2ee.ServerDeploy
 82   
  */
 83   
 public abstract class AbstractHotDeploymentTool implements HotDeploymentTool {
 84   
     /** The parent task **/
 85   
     private ServerDeploy task;
 86   
 
 87   
     /** The classpath passed to the JVM on execution. **/
 88   
     private Path classpath;
 89   
 
 90   
     /** The username for the deployment server. **/
 91   
     private String userName;
 92   
 
 93   
     /** The password for the deployment server. **/
 94   
     private String password;
 95   
 
 96   
     /** The address of the deployment server **/
 97   
     private String server;
 98   
 
 99   
     /**
 100   
      *  Add a classpath as a nested element.
 101   
      *  @return A Path object representing the classpath to be used.
 102   
      */
 103  0
     public Path createClasspath() {
 104  0
         if (classpath == null)
 105  0
             classpath = new Path(task.getProject());
 106   
 
 107  0
         return classpath.createPath();
 108   
     }
 109   
 
 110   
     /**
 111   
      *  Determines if the "action" attribute defines a valid action.
 112   
      *  <p>Subclasses should determine if the action passed in is
 113   
      *  supported by the vendor's deployment tool.
 114   
      *  <p>Actions may by "deploy", "delete", etc... It all depends
 115   
      *  on the tool.
 116   
      *  @return true if the "action" attribute is valid, false if not.
 117   
      */
 118   
     protected abstract boolean isActionValid();
 119   
 
 120   
     /**
 121   
      *  Validates the passed in attributes.
 122   
      *  Subclasses should chain to this super-method to insure
 123   
      *  validation of boilerplate attributes.
 124   
      *  <p>Only the "action" attribute is required in the
 125   
      *  base class.  Subclasses should check attributes accordingly.
 126   
      *  @exception org.apache.tools.ant.BuildException if the attributes are invalid or incomplete.
 127   
      */
 128  0
     public void validateAttributes() throws BuildException {
 129  0
         if (task.getAction() == null)
 130  0
             throw new BuildException("The \"action\" attribute must be set");
 131   
 
 132  0
         if (!isActionValid())
 133  0
             throw new BuildException("Invalid action \"" + task.getAction() + "\" passed");
 134   
 
 135  0
         if (classpath == null)
 136  0
             throw new BuildException("The classpath attribute must be set");
 137   
     }
 138   
 
 139   
     /**
 140   
      *  Perform the actual deployment.
 141   
      *  It's up to the subclasses to implement the actual behavior.
 142   
      *  @exception org.apache.tools.ant.BuildException if the attributes are invalid or incomplete.
 143   
      */
 144   
     public abstract void deploy() throws BuildException;
 145   
 
 146   
     /**
 147   
      *  Sets the parent task.
 148   
      *  @param task a ServerDeploy object representing the parent task.
 149   
      *  @ant.attribute ignore="true" 
 150   
      */
 151  0
     public void setTask(ServerDeploy task) {
 152  0
         this.task = task;
 153   
     }
 154   
 
 155   
     /**
 156   
      *  Returns the task field, a ServerDeploy object.
 157   
      *  @return An ServerDeploy representing the parent task.
 158   
      */
 159  0
     protected ServerDeploy getTask() {
 160  0
         return task;
 161   
     }
 162   
 
 163   
     /**
 164   
      *  gets the classpath field.
 165   
      *  @return A Path representing the "classpath" attribute.
 166   
      */
 167  0
     public Path getClasspath() {
 168  0
         return classpath;
 169   
     }
 170   
 
 171   
     /**
 172   
      *  The classpath to be passed to the JVM running the tool; 
 173   
      *  optional depending upon the tool. 
 174   
      *  The classpath may also be supplied as a nested element.
 175   
      *  @param classpath A Path object representing the "classpath" attribute.
 176   
      */
 177  0
     public void setClasspath(Path classpath) {
 178  0
         this.classpath = classpath;
 179   
     }
 180   
 
 181   
     /**
 182   
      *  Returns the userName field.
 183   
      *  @return A String representing the "userName" attribute.
 184   
      */
 185  0
     public String getUserName() {
 186  0
         return userName;
 187   
     }
 188   
 
 189   
     /**
 190   
      *  The user with privileges to deploy applications to the server; optional.
 191   
      *  @param userName A String representing the "userName" attribute.
 192   
      */
 193  0
     public void setUserName(String userName) {
 194  0
         this.userName = userName;
 195   
     }
 196   
 
 197   
     /**
 198   
      *  Returns the password field.
 199   
      *  @return A String representing the "password" attribute.
 200   
      */
 201  0
     public String getPassword() {
 202  0
         return password;
 203   
     }
 204   
 
 205   
     /**
 206   
      *  The password of the user; optional. 
 207   
      *  @param password A String representing the "password" attribute.
 208   
      */
 209  0
     public void setPassword(String password) {
 210  0
         this.password = password;
 211   
     }
 212   
 
 213   
     /**
 214   
      *  Returns the server field.
 215   
      *  @return A String representing the "server" attribute.
 216   
      */
 217  0
     public String getServer() {
 218  0
         return server;
 219   
     }
 220   
 
 221   
     /**
 222   
      *  The address or URL for the server where the component will be deployed.
 223   
      *  @param server A String representing the "server" attribute.
 224   
      */
 225  0
     public void setServer(String server) {
 226  0
         this.server = server;
 227   
     }
 228   
 }
 229