Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 279   Methods: 11
NCLOC: 104   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
WebLogicHotDeploymentTool.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.taskdefs.Java;
 59   
 
 60   
 /**
 61   
  *  An Ant wrapper task for the weblogic.deploy tool.  This is used to
 62   
  *  hot-deploy J2EE applications to a running WebLogic server.
 63   
  *  This is <b>not</b> the same as creating the application archive.
 64   
  *  This task assumes the archive (EAR, JAR, or WAR) file has been
 65   
  *  assembled and is supplied as the "source" attribute.
 66   
  *  <p>In the end, this task assembles the commadline parameters
 67   
  *  and runs the weblogic.deploy tool in a seperate JVM.
 68   
  *
 69   
  *  @author Christopher A. Longo - cal@cloud9.net
 70   
  *
 71   
  *  @see org.apache.tools.ant.taskdefs.optional.j2ee.HotDeploymentTool
 72   
  *  @see org.apache.tools.ant.taskdefs.optional.j2ee.AbstractHotDeploymentTool
 73   
  *  @see org.apache.tools.ant.taskdefs.optional.j2ee.ServerDeploy
 74   
  */
 75   
 public class WebLogicHotDeploymentTool extends AbstractHotDeploymentTool implements HotDeploymentTool
 76   
 {
 77   
     /** The classname of the tool to run **/
 78   
     private static final String WEBLOGIC_DEPLOY_CLASS_NAME = "weblogic.deploy";
 79   
 
 80   
     /** All the valid actions that weblogic.deploy permits **/
 81   
     private static final String[] VALID_ACTIONS =
 82   
             {ACTION_DELETE, ACTION_DEPLOY, ACTION_LIST, ACTION_UNDEPLOY, ACTION_UPDATE};
 83   
 
 84   
     /** Represents the "-debug" flag from weblogic.deploy **/
 85   
     private boolean debug;
 86   
 
 87   
     /** The application name that is being deployed **/
 88   
     private String application;
 89   
 
 90   
     /** The component name:target(s) for the "-component" argument of weblogic.deploy **/
 91   
     private String component;
 92   
 
 93   
     /**
 94   
      *  Perform the actual deployment.
 95   
      *  For this implementation, a JVM is spawned and the weblogic.deploy
 96   
      *  tools is executed.
 97   
      *  @exception org.apache.tools.ant.BuildException if the attributes are invalid or incomplete.
 98   
      */
 99  0
     public void deploy() {
 100  0
         Java java = (Java) getTask().getProject().createTask("java");
 101  0
         java.setFork(true);
 102  0
         java.setFailonerror(true);
 103  0
         java.setClasspath(getClasspath());
 104   
 
 105  0
         java.setClassname(WEBLOGIC_DEPLOY_CLASS_NAME);
 106  0
         java.createArg().setLine(getArguments());
 107  0
         java.execute();
 108   
     }
 109   
 
 110   
     /**
 111   
      *  Validates the passed in attributes.
 112   
      *  <p>The rules are:
 113   
      *  <ol><li>If action is "deploy" or "update" the "application" and "source"
 114   
      *  attributes must be supplied.
 115   
      *  <li>If action is "delete" or "undeploy" the "application" attribute must
 116   
      *  be supplied.
 117   
      *  @exception org.apache.tools.ant.BuildException if the attributes are invalid or incomplete
 118   
      */
 119  0
     public void validateAttributes() throws BuildException {
 120  0
         super.validateAttributes();
 121   
 
 122  0
         String action = getTask().getAction();
 123   
 
 124   
         // check that the password has been set
 125  0
         if ((getPassword() == null))
 126  0
             throw new BuildException("The password attribute must be set.");
 127   
 
 128   
         // check for missing application on deploy & update
 129  0
         if ((action.equals(ACTION_DEPLOY) || action.equals(ACTION_UPDATE)) 
 130   
             && application == null)
 131  0
             throw new BuildException("The application attribute must be set " 
 132   
                 + "if action = " + action);
 133   
 
 134   
         // check for missing source on deploy & update
 135  0
         if ((action.equals(ACTION_DEPLOY) || action.equals(ACTION_UPDATE)) 
 136   
             && getTask().getSource() == null)
 137  0
             throw new BuildException("The source attribute must be set if " 
 138   
                 + "action = " + action);
 139   
 
 140   
         // check for missing application on delete & undeploy
 141  0
         if ((action.equals(ACTION_DELETE) || action.equals(ACTION_UNDEPLOY)) 
 142   
             && application == null)
 143  0
             throw new BuildException("The application attribute must be set if " 
 144   
                 + "action = " + action);
 145   
     }
 146   
 
 147   
     /**
 148   
      *  Builds the arguments to pass to weblogic.deploy according to the
 149   
      *  supplied action.
 150   
      *  @return A String containing the arguments for the weblogic.deploy tool.
 151   
      */
 152  0
     public String getArguments() throws BuildException {
 153  0
         String action = getTask().getAction();
 154  0
         String args = null;
 155   
 
 156  0
         if (action.equals(ACTION_DEPLOY) || action.equals(ACTION_UPDATE))
 157  0
             args = buildDeployArgs();
 158  0
         else if (action.equals(ACTION_DELETE) || action.equals(ACTION_UNDEPLOY))
 159  0
             args = buildUndeployArgs();
 160  0
         else if (action.equals(ACTION_LIST))
 161  0
             args = buildListArgs();
 162   
 
 163  0
         return args;
 164   
     }
 165   
 
 166   
     /**
 167   
      *  Determines if the action supplied is valid.
 168   
      *  <p>Valid actions are contained in the static array VALID_ACTIONS
 169   
      *  @return true if the action attribute is valid, false if not.
 170   
      */
 171  0
     protected boolean isActionValid() {
 172  0
         boolean valid = false;
 173   
 
 174  0
         String action = getTask().getAction();
 175   
 
 176  0
         for (int i = 0; i < VALID_ACTIONS.length; i++) {
 177  0
             if (action.equals(VALID_ACTIONS[i])) {
 178  0
                 valid = true;
 179  0
                 break;
 180   
             }
 181   
         }
 182   
 
 183  0
         return valid;
 184   
     }
 185   
 
 186   
     /**
 187   
      *  Builds the prefix arguments to pass to weblogic.deploy.
 188   
      *  These arguments are generic across all actions.
 189   
      *  @return A StringBuffer containing the prefix arguments.
 190   
      *  The action-specific build methods will append to this StringBuffer.
 191   
      */
 192  0
     protected StringBuffer buildArgsPrefix() {
 193  0
         ServerDeploy task = getTask();
 194   
         // constructs the "-url <url> -debug <action> <password>" portion
 195   
         // of the commmand line
 196  0
         return new StringBuffer(1024)
 197   
                 .append((getServer() != null)
 198   
                     ? "-url " + getServer()
 199   
                     : "")
 200   
                 .append(" ")
 201   
                 .append(debug ? "-debug " : "")
 202   
                 .append((getUserName() != null)
 203   
                     ? "-username " + getUserName()
 204   
                     : "")
 205   
                 .append(" ")
 206   
                 .append(task.getAction()).append(" ")
 207   
                 .append(getPassword()).append(" ");
 208   
     }
 209   
 
 210   
     /**
 211   
      *  Builds the arguments to pass to weblogic.deploy for deployment actions
 212   
      *  ("deploy" and "update").
 213   
      *  @return A String containing the full argument string for weblogic.deploy.
 214   
      */
 215  0
     protected String buildDeployArgs() {
 216  0
         String args = buildArgsPrefix()
 217   
                 .append(application).append(" ")
 218   
                 .append(getTask().getSource())
 219   
                 .toString();
 220   
 
 221  0
         if (component != null) {
 222  0
             args = "-component " + component + " " + args;
 223   
         }
 224   
         
 225  0
         return args;
 226   
     }
 227   
 
 228   
     /**
 229   
      *  Builds the arguments to pass to weblogic.deploy for undeployment actions
 230   
      *  ("undeploy" and "delete").
 231   
      *  @return A String containing the full argument string for weblogic.deploy.
 232   
      */
 233  0
     protected String buildUndeployArgs() {
 234  0
         return buildArgsPrefix()
 235   
                 .append(application).append(" ")
 236   
                 .toString();
 237   
     }
 238   
 
 239   
     /**
 240   
      *  Builds the arguments to pass to weblogic.deploy for the list action
 241   
      *  @return A String containing the full argument string for weblogic.deploy.
 242   
      */
 243  0
     protected String buildListArgs() {
 244  0
         return buildArgsPrefix()
 245   
                 .toString();
 246   
     }
 247   
 
 248   
     /**
 249   
      *  If set to true, additional information will be
 250   
      *  printed during the deployment process; optional.
 251   
      *  @param debug A boolean representing weblogic.deploy "-debug" flag.
 252   
      */
 253  0
     public void setDebug(boolean debug) {
 254  0
         this.debug = debug;
 255   
     }
 256   
 
 257   
     /**
 258   
      *  The name of the application being deployed; required.
 259   
      *  @param application A String representing the application portion of the
 260   
      *  weblogic.deploy command line.
 261   
      */
 262  0
     public void setApplication(String application) {
 263  0
         this.application = application;
 264   
     }
 265   
 
 266   
     /**
 267   
      * the component string for the deployment targets; optional.
 268   
      * It is in the form <code>&lt;component&gt;:&lt;target1&gt;,&lt;target2&gt;...</code>
 269   
      * Where component is the archive name (minus the .jar, .ear, .war
 270   
      * extension).  Targets are the servers where the components will be deployed
 271   
     
 272   
      *  @param component A String representing the value of the "-component"
 273   
      *  argument of the weblogic.deploy command line argument.
 274   
      */
 275  0
     public void setComponent(String component) {
 276  0
         this.component = component;
 277   
     }
 278   
 }
 279