Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 280   Methods: 7
NCLOC: 96   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
JonasHotDeploymentTool.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   
 package org.apache.tools.ant.taskdefs.optional.j2ee;
 55   
 
 56   
 import java.io.File;
 57   
 import org.apache.tools.ant.BuildException;
 58   
 import org.apache.tools.ant.taskdefs.Java;
 59   
 import org.apache.tools.ant.types.Path;
 60   
 
 61   
 /**
 62   
  *  An Ant wrapper task for the weblogic.deploy tool. This is used
 63   
  *  to hot-deploy J2EE applications to a running WebLogic server.
 64   
  *  This is <b>not</b> the same as creating the application
 65   
  *  archive. This task assumes the archive (EAR, JAR, or WAR) file
 66   
  *  has been assembled and is supplied as the "source" attribute.
 67   
  *  <p>
 68   
  *
 69   
  *  In the end, this task assembles the commadline parameters and
 70   
  *  runs the weblogic.deploy tool in a seperate JVM.
 71   
  *
 72   
  *@author Cyrille Morvan
 73   
  *@see org.apache.tools.ant.taskdefs.optional.j2ee.HotDeploymentTool
 74   
  *@see org.apache.tools.ant.taskdefs.optional.j2ee.AbstractHotDeploymentTool
 75   
  *@see org.apache.tools.ant.taskdefs.optional.j2ee.ServerDeploy
 76   
  */
 77   
 public class JonasHotDeploymentTool extends GenericHotDeploymentTool implements HotDeploymentTool {
 78   
 
 79   
     /**
 80   
      *  Description of the Field
 81   
      */
 82   
     protected static final String DEFAULT_ORB = "RMI";
 83   
 
 84   
     /**
 85   
      *  The classname of the tool to run *
 86   
      */
 87   
     private static final String JONAS_DEPLOY_CLASS_NAME = "org.objectweb.jonas.adm.JonasAdmin";
 88   
 
 89   
     /**
 90   
      *  All the valid actions that weblogic.deploy permits *
 91   
      */
 92   
     private static final String[] VALID_ACTIONS =
 93   
             {ACTION_DELETE, ACTION_DEPLOY, ACTION_LIST, ACTION_UNDEPLOY, ACTION_UPDATE};
 94   
 
 95   
     /**
 96   
      *  Description of the Field
 97   
      */
 98   
     private File jonasroot;
 99   
     
 100   
     /**
 101   
      *  Description of the Field
 102   
      */
 103   
     private String orb = null;
 104   
 
 105   
     /**
 106   
      *  Description of the Field
 107   
      */
 108   
     private String davidHost;
 109   
     
 110   
     /**
 111   
      *  Description of the Field
 112   
      */
 113   
     private int davidPort;
 114   
 
 115   
 
 116   
     /**
 117   
      *  Set the host for the David ORB; required if 
 118   
      *  ORB==david.
 119   
      *
 120   
      *@param  inValue  The new davidhost value
 121   
      */
 122  0
     public void setDavidhost(final String inValue) {
 123  0
         davidHost = inValue;
 124   
     }
 125   
 
 126   
 
 127   
     /**
 128   
      *  Set the port for the David ORB; required if 
 129   
      *  ORB==david.
 130   
      *
 131   
      *@param  inValue  The new davidport value
 132   
      */
 133  0
     public void setDavidport(final int inValue) {
 134  0
         davidPort = inValue;
 135   
     }
 136   
 
 137   
 
 138   
     /**
 139   
      *  set the jonas root directory (-Dinstall.root=). This
 140   
      *  element is required.
 141   
      *
 142   
      *@param  inValue  The new jonasroot value
 143   
      */
 144  0
     public void setJonasroot(final File inValue) {
 145  0
         jonasroot = inValue;
 146   
     }
 147   
 
 148   
 
 149   
     /**
 150   
      * 
 151   
      * Choose your ORB : RMI, JEREMIE, DAVID, ...; optional.
 152   
      * If omitted, it defaults
 153   
      * to the one present in classpath. The corresponding JOnAS JAR is
 154   
      * automatically added to the classpath. If your orb is DAVID (RMI/IIOP) you must 
 155   
      * specify davidhost and davidport properties.
 156   
      *
 157   
      *@param  inValue  RMI, JEREMIE, DAVID,...
 158   
      */
 159  0
     public void setOrb(final String inValue) {
 160  0
         orb = inValue;
 161   
     }
 162   
 
 163   
 
 164   
     /**
 165   
      *  gets the classpath field.
 166   
      *
 167   
      *@return    A Path representing the "classpath" attribute.
 168   
      */
 169  0
     public Path getClasspath() {
 170   
 
 171  0
         Path aClassPath = super.getClasspath();
 172   
 
 173  0
         if (aClassPath == null) {
 174  0
             aClassPath = new Path(getTask().getProject());
 175   
         }
 176  0
         if (orb != null) {
 177  0
             String aOrbJar = new File(jonasroot, "lib/" + orb + "_jonas.jar").toString();
 178  0
             String aConfigDir = new File(jonasroot, "config/").toString();
 179  0
             Path aJOnASOrbPath = new Path(aClassPath.getProject(),
 180   
                     aOrbJar + File.pathSeparator + aConfigDir);
 181  0
             aClassPath.append(aJOnASOrbPath);
 182   
         }
 183  0
         return aClassPath;
 184   
     }
 185   
 
 186   
 
 187   
     /**
 188   
      *  Validates the passed in attributes. <p>
 189   
      *
 190   
      *  The rules are:
 191   
      *  <ol>
 192   
      *    <li> If action is "deploy" or "update" the "application"
 193   
      *    and "source" attributes must be supplied.
 194   
      *    <li> If action is "delete" or "undeploy" the
 195   
      *    "application" attribute must be supplied.
 196   
      *
 197   
      *@exception  BuildException                       Description
 198   
      *      of Exception
 199   
      */
 200  0
     public void validateAttributes() throws BuildException {
 201   
         // super.validateAttributes(); // don't want to call this method
 202   
 
 203  0
         Java java = getJava();
 204   
 
 205  0
         String action = getTask().getAction();
 206  0
         if (action == null) {
 207  0
             throw new BuildException("The \"action\" attribute must be set");
 208   
         }
 209   
 
 210  0
         if (!isActionValid()) {
 211  0
             throw new BuildException("Invalid action \"" + action + "\" passed");
 212   
         }
 213   
 
 214  0
         if (getClassName() == null) {
 215  0
             setClassName(JONAS_DEPLOY_CLASS_NAME);
 216   
         }
 217   
 
 218  0
         if (jonasroot == null || jonasroot.isDirectory()) {
 219  0
             java.createJvmarg().setValue("-Dinstall.root=" + jonasroot);
 220  0
             java.createJvmarg().setValue("-Djava.security.policy=" + jonasroot + "/config/java.policy");
 221   
 
 222  0
             if ("DAVID".equals(orb)) {
 223  0
                 java.createJvmarg().setValue("-Dorg.omg.CORBA.ORBClass=org.objectweb.david.libs.binding.orbs.iiop.IIOPORB");
 224  0
                 java.createJvmarg().setValue("-Dorg.omg.CORBA.ORBSingletonClass=org.objectweb.david.libs.binding.orbs.ORBSingletonClass");
 225  0
                 java.createJvmarg().setValue("-Djavax.rmi.CORBA.StubClass=org.objectweb.david.libs.stub_factories.rmi.StubDelegate");
 226  0
                 java.createJvmarg().setValue("-Djavax.rmi.CORBA.PortableRemoteObjectClass=org.objectweb.david.libs.binding.rmi.ORBPortableRemoteObjectDelegate");
 227  0
                 java.createJvmarg().setValue("-Djavax.rmi.CORBA.UtilClass=org.objectweb.david.libs.helpers.RMIUtilDelegate");
 228  0
                 java.createJvmarg().setValue("-Ddavid.CosNaming.default_method=0");
 229  0
                 java.createJvmarg().setValue("-Ddavid.rmi.ValueHandlerClass=com.sun.corba.se.internal.io.ValueHandlerImpl");
 230  0
                 if (davidHost != null) {
 231  0
                     java.createJvmarg().setValue("-Ddavid.CosNaming.default_host=" + davidHost);
 232   
                 }
 233  0
                 if (davidPort != 0) {
 234  0
                     java.createJvmarg().setValue("-Ddavid.CosNaming.default_port=" + davidPort);
 235   
                 }
 236   
             }
 237   
         }
 238   
 
 239  0
         if (getServer() != null) {
 240  0
             java.createArg().setLine("-n " + getServer());
 241   
         }
 242   
 
 243  0
         if (action.equals(ACTION_DEPLOY) ||
 244   
                 action.equals(ACTION_UPDATE) ||
 245   
                 action.equals("redeploy")) {
 246  0
             java.createArg().setLine("-a " + getTask().getSource());
 247  0
         } else if (action.equals(ACTION_DELETE) || action.equals(ACTION_UNDEPLOY)) {
 248  0
             java.createArg().setLine("-r " + getTask().getSource());
 249  0
         } else if (action.equals(ACTION_LIST)) {
 250  0
             java.createArg().setValue("-l");
 251   
         }
 252   
     }
 253   
 
 254   
 
 255   
     /**
 256   
      *  Determines if the action supplied is valid. <p>
 257   
      *
 258   
      *  Valid actions are contained in the static array
 259   
      *  VALID_ACTIONS
 260   
      *
 261   
      *@return    true if the action attribute is valid, false if
 262   
      *      not.
 263   
      */
 264  0
     protected boolean isActionValid() {
 265  0
         boolean valid = false;
 266   
 
 267  0
         String action = getTask().getAction();
 268   
 
 269  0
         for (int i = 0; i < VALID_ACTIONS.length; i++) {
 270  0
             if (action.equals(VALID_ACTIONS[i])) {
 271  0
                 valid = true;
 272  0
                 break;
 273   
             }
 274   
         }
 275   
 
 276  0
         return valid;
 277   
     }
 278   
 }
 279   
 
 280