FileDocCategorySizeDatePackage
WebLogicHotDeploymentTool.javaAPI DocApache Ant 1.709219Wed Dec 13 06:16:20 GMT 2006org.apache.tools.ant.taskdefs.optional.j2ee

WebLogicHotDeploymentTool

public class WebLogicHotDeploymentTool extends AbstractHotDeploymentTool implements HotDeploymentTool
An Ant wrapper task for the weblogic.deploy tool. This is used to hot-deploy J2EE applications to a running WebLogic server. This is not 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.

In the end, this task assembles the commadline parameters and runs the weblogic.deploy tool in a seperate JVM.

see
org.apache.tools.ant.taskdefs.optional.j2ee.HotDeploymentTool
see
org.apache.tools.ant.taskdefs.optional.j2ee.AbstractHotDeploymentTool
see
org.apache.tools.ant.taskdefs.optional.j2ee.ServerDeploy

Fields Summary
private static final String
WEBLOGIC_DEPLOY_CLASS_NAME
The classname of the tool to run
private static final String[]
VALID_ACTIONS
All the valid actions that weblogic.deploy permits
private boolean
debug
Represents the "-debug" flag from weblogic.deploy
private String
application
The application name that is being deployed
private String
component
The component name:target(s) for the "-component" argument of weblogic.deploy
Constructors Summary
Methods Summary
protected java.lang.StringBufferbuildArgsPrefix()
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.

        ServerDeploy task = getTask();
        // constructs the "-url <url> -debug <action> <password>" portion
        // of the commmand line
        return new StringBuffer(1024)
                .append((getServer() != null)
                    ? "-url " + getServer()
                    : "")
                .append(" ")
                .append(debug ? "-debug " : "")
                .append((getUserName() != null)
                    ? "-username " + getUserName()
                    : "")
                .append(" ")
                .append(task.getAction()).append(" ")
                .append(getPassword()).append(" ");
    
protected java.lang.StringbuildDeployArgs()
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.

        String args = buildArgsPrefix()
                .append(application).append(" ")
                .append(getTask().getSource())
                .toString();

        if (component != null) {
            args = "-component " + component + " " + args;
        }

        return args;
    
protected java.lang.StringbuildListArgs()
Builds the arguments to pass to weblogic.deploy for the list action

return
A String containing the full argument string for weblogic.deploy.

        return buildArgsPrefix()
                .toString();
    
protected java.lang.StringbuildUndeployArgs()
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.

        return buildArgsPrefix()
                .append(application).append(" ")
                .toString();
    
public voiddeploy()
Perform the actual deployment. For this implementation, a JVM is spawned and the weblogic.deploy tools is executed.

exception
org.apache.tools.ant.BuildException if the attributes are invalid or incomplete.


                                       
       
        Java java = new Java(getTask());
        java.setFork(true);
        java.setFailonerror(true);
        java.setClasspath(getClasspath());

        java.setClassname(WEBLOGIC_DEPLOY_CLASS_NAME);
        java.createArg().setLine(getArguments());
        java.execute();
    
public java.lang.StringgetArguments()
Builds the arguments to pass to weblogic.deploy according to the supplied action.

return
A String containing the arguments for the weblogic.deploy tool.
throws
BuildException if there is an error.

        String action = getTask().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;
    
protected booleanisActionValid()
Determines if the action supplied is valid.

Valid actions are contained in the static array VALID_ACTIONS

return
true if the action attribute is valid, false if not.

        boolean valid = false;

        String action = getTask().getAction();

        for (int i = 0; i < VALID_ACTIONS.length; i++) {
            if (action.equals(VALID_ACTIONS[i])) {
                valid = true;
                break;
            }
        }

        return valid;
    
public voidsetApplication(java.lang.String application)
The name of the application being deployed; required.

param
application A String representing the application portion of the weblogic.deploy command line.

        this.application = application;
    
public voidsetComponent(java.lang.String component)
the component string for the deployment targets; optional. It is in the form <component>:<target1>,<target2>... Where component is the archive name (minus the .jar, .ear, .war extension). Targets are the servers where the components will be deployed

param
component A String representing the value of the "-component" argument of the weblogic.deploy command line argument.

        this.component = component;
    
public voidsetDebug(boolean debug)
If set to true, additional information will be printed during the deployment process; optional.

param
debug A boolean representing weblogic.deploy "-debug" flag.

        this.debug = debug;
    
public voidvalidateAttributes()
Validates the passed in attributes.

The rules are:

  1. If action is "deploy" or "update" the "application" and "source" attributes must be supplied.
  2. If action is "delete" or "undeploy" the "application" attribute must be supplied.

    exception
    org.apache.tools.ant.BuildException if the attributes are invalid or incomplete

            super.validateAttributes();
    
            String action = getTask().getAction();
    
            // check that the password has been set
            if ((getPassword() == null)) {
                throw new BuildException("The password attribute must be set.");
            }
    
            // 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))
                && getTask().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);
            }