ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ehatc...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/ejb AbstractEjbHotDeploymentTool.java EjbDeploy.java EjbHotDeploymentTool.java WebLogicHotDeploymentTool.java
Date Sun, 24 Mar 2002 14:49:48 GMT
ehatcher    02/03/24 06:49:48

  Added:       src/main/org/apache/tools/ant/taskdefs/optional/ejb
                        AbstractEjbHotDeploymentTool.java EjbDeploy.java
                        EjbHotDeploymentTool.java
                        WebLogicHotDeploymentTool.java
  Log:
  EJB hot deploy tool, contributed by Christopher A. Longo - cal@cloud9.net
  
  Revision  Changes    Path
  1.1                  jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/ejb/AbstractEjbHotDeploymentTool.java
  
  Index: AbstractEjbHotDeploymentTool.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Ant", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.tools.ant.taskdefs.optional.ejb;
  
  import org.apache.tools.ant.BuildException;
  import org.apache.tools.ant.Task;
  
  /**
   *  Abstract class to support vendor-specific hot deployment tools.
   *  This class will validate boilerplate attributes.
   *
   *  Subclassing this class for a vendor specific tool involves the
   *  following.
   *  <ol>
   *  <li>Implement the <code>getClassName()</code> method to supply the
   *  super-task class name of the vendor specific deployment tool to run.
   *  <li>Implement the <code>getArguments()</code> method to supply the
   *  super-task the command line to pass for the vendor specific deployment
   *  tool.
   *  <li>Implement the <code>isActionValid()<code> method to insure the
   *  action supplied as the "action" attribute of EjbDeploy is valid.
   *  <li>Implement the <code>validateAttributes()</code> method to insure
   *  all required attributes are supplied, and are in the correct format.
   *  <li>Add a <code>create&lt;TOOL&gt;</code> method to the EjbDeploy
   *  class.  This method will be called when Ant encounters a
   *  <code>create&lt;TOOL&gt;</code> task nested in the
   *  <code>ejbdeploy</code> task.
   *
   *  @author Christopher A. Longo - cal@cloud9.net
   *
   *  @see EjbHotDeploymentTool
   *  @see EjbDeploy
   */
  public abstract class AbstractEjbHotDeploymentTool
          extends Task
          implements EjbHotDeploymentTool
  {
      /** The super-task **/
      private EjbDeploy deploy;
  
      /**
       *  Constructor.
       *  @param deploy The super-task which wraps this one.
       */
      public AbstractEjbHotDeploymentTool(EjbDeploy deploy) {
          this.deploy = deploy;
      }
  
      /**
       *  Returns the class name of the weblogic.deploy tool to the super-task.
       *  <p>This is called by the super-task, EjbDeploy.
       *  <p>Subclasses should return the fully qualified class name of the
       *  vendor tool to run.  IE: "com.foobar.tools.DeployTool"
       *  @return A String representing the classname of the deployment tool to run
       */
      public abstract String getClassName();
  
      /**
       *  Returns a String containing the runtime commandline arguments
       *  of the deployment tool.
       *  <p>Subclasses should return the appropriate string from that
       *  vendor's tool.  IE: "-url=http://myserver:31337 -user=foo -passsword=bar"
       *  @return a String containing the runtime commandline arguments
       *  of the deployment tool.
       */
      public abstract String getArguments();
  
      /**
       *  Validates the passed in attributes.
       *  Subclasses should chain to this super-method to insure
       *  validation of boilerplate attributes.
       *  <p>Only the "action" and "password" attributes are required in the
       *  base class.  Subclasses should check attributes accordingly.
       *  @exception BuildException if the attributes are invalid or incomplete
       */
      public void validateAttributes() throws BuildException {
          String action = deploy.getAction();
  
          if(action == null)
              throw new BuildException("The \"action\" attribute must be set");
  
          if(!isActionValid())
              throw new BuildException("Invalid action \"" + action + "\" passed");
  
          if(deploy.getPassword() == null)
              throw new BuildException("The WebLogic system password must be set");
      }
  
      /**
       *  Determines if the "action" attribute defines a valid action.
       *  <p>Subclasses should determine if the action passed in is
       *  supported by the vendor's deployment tool.
       *  <p>Actions may by "deploy", "delete", etc... It all depends
       *  on the tool.
       *  @return true if the "action" attribute is valid, false if not.
       */
      protected abstract boolean isActionValid();
  
      /**
       *  Returns the super-task.
       *  @return An EjbDeploy object representing the super-task.
       */
      protected EjbDeploy getDeploy() {
          return deploy;
      }
  }
  
  
  
  1.1                  jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/ejb/EjbDeploy.java
  
  Index: EjbDeploy.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Ant", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.tools.ant.taskdefs.optional.ejb;
  
  import java.io.File;
  
  import org.apache.tools.ant.BuildException;
  import org.apache.tools.ant.Task;
  import org.apache.tools.ant.taskdefs.Java;
  import org.apache.tools.ant.types.Path;
  
  /**
   *  A task to support "hot" deployment tools for J2EE servers.
   *
   *  This class is used as a framework for the creation of vendor specific
   *  "hot" deployment tools.
   *
   *  @author Christopher A. Longo - cal@cloud9.net
   *
   *  @see EjbHotDeploymentTool
   *  @see AbstractEjbHotDeploymentTool
   *  @see WebLogicHotDeploymentTool
   */
  public class EjbDeploy extends Task
  {
      /** The action to be performed.  IE: "deploy", "delete", etc... **/
      private String action;
  
      /** The classpath passed to the JVM on execution. **/
      private Path classpath;
  
      /** The username for the deployment server. **/
      private String userName;
  
      /** The password for the deployment server. **/
      private String password;
  
      /** The URL of the deployment server **/
      private String serverUrl;
  
      /** The source (fully-qualified path) to the component being deployed **/
      private File source;
  
      /** The vendor specific tool for deploying the component **/
      private EjbHotDeploymentTool vendorTool;
  
      /**
       *  Creates a classpath.  Used to handle the nested classpath
       *  element.
       *  @return A Path object representing the classpath to be used.
       */
      public Path createClasspath() {
          if(classpath == null)
              classpath = new Path(project);
  
          return classpath.createPath();
      }
  
      ///////////////////////////////////////////////////////////////////////////
      //
      //	Place vendor specific tool creations here.
      //
      ///////////////////////////////////////////////////////////////////////////
  
      /**
       *  Creates a WebLogic deployment tool, for deployment to WebLogic servers.
       *  <p>Ant calls this method on creation to handle embedded "weblogic" tags
       *  in the EjbDeploy task.
       *  @return An instance of WebLogicHotDeployment tool.
       */
      public WebLogicHotDeploymentTool createWeblogic() {
          WebLogicHotDeploymentTool weblogic = new WebLogicHotDeploymentTool(this);
          vendorTool = (EjbHotDeploymentTool)weblogic;
          return weblogic;
      }
  
      /**
       *  Execute the task.
       *  <p>This will fork a JVM and run the vendor-specific deployment tool.
       *  The process will fail if the tool returns an error.
       *  @exception BuildException if the attributes are invalid or incomplete
       */
      public void execute() throws BuildException {
          if (vendorTool == null) {
              throw new BuildException("No vendor tool specified");
          }
          
          vendorTool.validateAttributes();
  
          Java deploy = (Java)project.createTask("java");
          deploy.setFork(true);
          deploy.setFailonerror(true);
          deploy.setClasspath(classpath);
  
          deploy.setClassname(vendorTool.getClassName());
          deploy.createArg().setLine(vendorTool.getArguments());
          deploy.execute();
  
          deploy = null;
      }
  
      ///////////////////////////////////////////////////////////////////////////
      //
      //	Set/get methods
      //
      ///////////////////////////////////////////////////////////////////////////
  
      /**
       *  Returns the action field.
       *  @return A string representing the "action" attribute.
       */
      public String getAction() {
          return action;
      }
  
      /**
       *  Sets the action field.
       *  This is a required attribute.
       *  @param action A String representing the "action" attribute.
       */
      public void setAction(String action) {
          this.action = action;
      }
  
      /**
       *  gets the classpath field.
       *  @return A Path representing the "classpath" attribute.
       */
      public Path getClasspath() {
          return classpath;
      }
  
      /**
       *  Sets the classpath field.
       *  This is not a required attribute.
       *  @param classpath A Path object representing the "classpath" attribute.
       */
      public void setClasspath(Path classpath) {
          this.classpath = classpath;
      }
  
      /**
       *  Returns the userName field.
       *  @return A String representing the "userName" attribute.
       */
      public String getUserName() {
          return userName;
      }
  
      /**
       *  Sets the userName field.
       *  This is not a required attribute.
       *  @param userName A String representing the "userName" attribute.
       */
      public void setUserName(String userName) {
          this.userName = userName;
      }
  
      /**
       *  Returns the password field.
       *  @return A String representing the "password" attribute.
       */
      public String getPassword() {
          return password;
      }
  
      /**
       *  Set the password field.
       *  This is a required attribute.
       *  @param A String representing the "password" attribute.
       */
      public void setPassword(String password) {
          this.password = password;
      }
  
      /**
       *  Returns the serverUrl field.
       *  @return A String representing the "serverUrl" attribute.
       */
      public String getServerUrl() {
          return serverUrl;
      }
  
      /**
       *  Sets the serverUrl field.
       *  This is not a required attribute.
       *  @param serverUrl A String representing the "serverUrl" attribute.
       */
      public void setServerUrl(String serverUrl) {
          this.serverUrl = serverUrl;
      }
  
      /**
       *  Returns the source field (the path/filename of the component to be
       *  deployed.
       *  @return A File object representing the "source" attribute.
       */
      public File getSource() {
          return source;
      }
  
      /**
       *  Sets the source field (the path/filename of the component to be
       *  deployed.
       *  This is not a required attribute.
       *  @param A String representing the "source" attribute.
       */
      public void setSource(File source) {
          this.source = source;
      }
  }
  
  
  
  1.1                  jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/ejb/EjbHotDeploymentTool.java
  
  Index: EjbHotDeploymentTool.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Ant", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.tools.ant.taskdefs.optional.ejb;
  
  import org.apache.tools.ant.BuildException;
  
  /**
   *  An interface for vendor-specific "hot" deployment tools.
   *
   *  @author Christopher A. Longo - cal@cloud9.net
   *
   *  @see AbstractEjbHotDeploymentTool
   *  @see EjbDeploy
   */
  public interface EjbHotDeploymentTool
  {
      /**
       *  Returns the class name of the weblogic.deploy tool to the super-task.
       *  <p>This is called by the super-task, EjbDeploy.
       *  <p>Subclasses should return the fully qualified class name of the
       *  vendor tool to run.  IE: "com.foobar.tools.DeployTool"
       *  @return A String representing the classname of the deployment tool to run
       */
      public String getClassName();
  
      /**
       *  Validates the passed in attributes.
       *  <p>The rules are:
       *  <ol><li>If action is "deploy" or "update" the "application" and "source"
       *  attributes must be supplied.
       *  <li>If action is "delete" or "undeploy" the "application" attribute must
       *  be supplied.
       *  @exception BuildException if the attributes are invalid or incomplete
       */
      public void validateAttributes() throws BuildException;
  
      /**
       *  Returns a String containing the runtime commandline arguments
       *  of the deployment tool.
       *  <p>Subclasses should return the appropriate string from that
       *  vendor's tool.  IE: "-url=http://myserver:31337 -user=foo -passsword=bar"
       *  @return a String containing the runtime commandline arguments
       *  of the deployment tool.
       */
      public String getArguments() throws BuildException;
  }
  
  
  
  1.1                  jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WebLogicHotDeploymentTool.java
  
  Index: WebLogicHotDeploymentTool.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Ant", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.tools.ant.taskdefs.optional.ejb;
  
  import org.apache.tools.ant.BuildException;
  
  /**
   *  An Ant wrapper task for the weblogic.deploy tool.  This is used to
   *  hot-deploy J2EE applications to a running WebLogic server.
   *  This is <b>not</b> the same as creating the application archive.
   *  This task assumes the archive (EAR, JAR, or WAR) file has been
   *  assembled and is supplied as the "source" attribute.
   *  <p>
   *  In the end, this task assembles the commadline parameters
   *  to run the weblogic.deploy tool.
   *
   *  @author Christopher A. Longo - cal@cloud9.net
   *
   *  @see EjbHotDeploymentTool
   *  @see AbstractEjbHotDeploymentTool
   *  @see EjbDeploy
   */
  public class WebLogicHotDeploymentTool
          extends AbstractEjbHotDeploymentTool
          implements EjbHotDeploymentTool
  {
      /** The delete action String **/
      public static final String ACTION_DELETE = "delete";
  
      /** The deploy action String **/
      public static final String ACTION_DEPLOY = "deploy";
  
      /** The list action String **/
      public static final String ACTION_LIST = "list";
  
      /** The undeploy action String **/
      public static final String ACTION_UNDEPLOY = "undeploy";
  
      /** The update action String **/
      public static final String ACTION_UPDATE = "update";
  
      /** The classname of the tool to run **/
      private static final String WEBLOGIC_DEPLOY_CLASS_NAME = "weblogic.deploy";
  
      /** All the valid actions that weblogic.deploy permits **/
      private static final String[] VALID_ACTIONS =
              {ACTION_DELETE, ACTION_DEPLOY, ACTION_LIST, ACTION_UNDEPLOY, ACTION_UPDATE};
  
      /** Represents the "-debug" flag from weblogic.deploy **/
      public boolean debug;
  
      /** The application name that is being deployed **/
      public String application;
  
      /** The component name:target(s) for the "-component" argument of weblogic.deploy **/
      public String component;
  
      /**
       *  Constructor
       *  @param deploy - The super-task which wraps this task
       */
      public WebLogicHotDeploymentTool(EjbDeploy deploy) {
          super(deploy);
      }
  
      /**
       *  Returns the class name of the weblogic.deploy tool to the super-task.
       *  <p>This is called by the super-task, EjbDeploy.
       *  @return A String representing the classname of the deployment tool to run
       */
      public String getClassName() {
          return WEBLOGIC_DEPLOY_CLASS_NAME;
      }
  
      /**
       *  Validates the passed in attributes.
       *  <p>The rules are:
       *  <ol><li>If action is "deploy" or "update" the "application" and "source"
       *  attributes must be supplied.
       *  <li>If action is "delete" or "undeploy" the "application" attribute must
       *  be supplied.
       *  @exception BuildException if the attributes are invalid or incomplete
       */
      public void validateAttributes() throws BuildException {
          super.validateAttributes();
  
          String action = getDeploy().getAction();
  
          // check for missing application on deploy & update
          if((action.equals(ACTION_DEPLOY) || action.equals(ACTION_UPDATE))
                  && application == null)
              throw new BuildException(
                      "The application attribute must be set if action = " + action);
  
          // check for missing source on deploy & update
          if((action.equals(ACTION_DEPLOY) || action.equals(ACTION_UPDATE))
                  && getDeploy().getSource() == null)
              throw new BuildException(
                      "The source attribute must be set if action = " + action);
  
          // check for missing application on delete & undeploy
          if((action.equals(ACTION_DELETE) || action.equals(ACTION_UNDEPLOY))
                  && application == null)
              throw new BuildException(
                      "The application attribute must be set if action = " + action);
      }
  
      /**
       *  Builds the arguments to pass to weblogic.deploy according to the
       *  supplied action.
       *  @return A String containing the arguments for the weblogic.deploy tool.
       */
      public String getArguments() throws BuildException {
          String action = getDeploy().getAction();
          String args = null;
  
          if(action.equals(ACTION_DEPLOY) || action.equals(ACTION_UPDATE))
              args = buildDeployArgs();
          else if(action.equals(ACTION_DELETE) || action.equals(ACTION_UNDEPLOY))
              args = buildUndeployArgs();
          else if(action.equals(ACTION_LIST))
              args = buildListArgs();
  
          return args;
      }
  
      /**
       *  Determines if the action supplied is valid.
       *  <p>Valid actions are contained in the static array VALID_ACTIONS
       *  @return true if the action attribute is valid, false if not.
       */
      protected boolean isActionValid() {
          boolean valid = false;
  
          String action = getDeploy().getAction();
  
          for(int i = 0; i < VALID_ACTIONS.length; i++) {
              if(action.equals(VALID_ACTIONS[i])) {
                  valid = true;
                  break;
              }
          }
  
          return valid;
      }
  
      /**
       *  Builds the prefix arguments to pass to weblogic.deploy.
       *  These arguments are generic across all actions.
       *  @return A StringBuffer containing the prefix arguments.
       *  The action-specific build methods will append to this StringBuffer.
       */
      protected StringBuffer buildArgsPrefix() {
          EjbDeploy deploy = getDeploy();
  
          // constructs the "-url <url> -debug <action> <password>" portion
          // of the commmand line
          return new StringBuffer(1024)
                  .append((deploy.getServerUrl() != null)
                  ? "-url " + deploy.getServerUrl()
                  : "")
                  .append(" ")
                  .append(debug ? "-debug " : "")
                  .append((deploy.getUserName() != null)
                  ? "-username " + deploy.getUserName()
                  : "")
                  .append(" ")
                  .append(deploy.getAction()).append(" ")
                  .append(deploy.getPassword()).append(" ");
      }
  
      /**
       *  Builds the arguments to pass to weblogic.deploy for deployment actions
       *  ("deploy" and "update").
       *  @return A String containing the full argument string for weblogic.deploy.
       */
      protected String buildDeployArgs() {
          String args = buildArgsPrefix()
                  .append(application).append(" ")
                  .append(getDeploy().getSource())
                  .toString();
  
          if(component != null)
              args = "-component " + component + " " + args;
  
          return args;
      }
  
      /**
       *  Builds the arguments to pass to weblogic.deploy for undeployment actions
       *  ("undeploy" and "delete").
       *  @return A String containing the full argument string for weblogic.deploy.
       */
      protected String buildUndeployArgs() {
          return buildArgsPrefix()
                  .append(application).append(" ")
                  .toString();
      }
  
      /**
       *  Builds the arguments to pass to weblogic.deploy for the list action
       *  @return A String containing the full argument string for weblogic.deploy.
       */
      protected String buildListArgs() {
          return buildArgsPrefix()
                  .toString();
      }
  
      /**
       *  Sets the debug field.
       *  <p>This attribute is not a required attribute.
       *  @param debug A boolean representing weblogic.deploy "-debug" flag.
       */
      public void setDebug(boolean debug) {
          this.debug = debug;
      }
  
      /**
       *  Sets the application field.
       *  <p>This attribute is a required attribute.
       *  @param application A String representing the application portion of the
       *  weblogic.deploy command line.
       */
      public void setApplication(String application) {
          this.application = application;
      }
  
      /**
       *  Sets the component attribute.
       *  <p>This attribute is not a required attribute.
       *  @param component A String representing the value of the "-component"
       *  argument of the weblogic.deploy command line argument.<br>
       *  This string should be in the format of
       *  &lt;<i>componentName</i>&gt;:&lt<i>target1</i>&gt;,&lt<i>target2</i>&gt;...
       */
      public void setComponent(String component) {
          this.component = component;
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message