Hi All,
I extended the server deploy task to support SUNs RI j2ee server (1.2, 1.3).
Patches are against vanila 1.5.1
Comments?
/James
/* * 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 [EMAIL PROTECTED] * * 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.j2ee; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.taskdefs.Java; /** * An Ant wrapper task for the j2eeri.deploy tool. This is used to * hot-deploy J2EE applications to a running Sun J2EE RI 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 * and runs the j2eeri.deploy tool in a seperate JVM. * * @author James Nord * * @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 */ public class J2EERIHotDeploymentTool extends AbstractHotDeploymentTool implements HotDeploymentTool { /** The classname of the tool to run **/ private static final String J2EE_DEPLOY_CLASS_NAME = "com.sun.enterprise.tools.deployment.main.Main"; /** All the valid actions that j2eeri.deploy permits **/ private static final String[] VALID_ACTIONS = {ACTION_DELETE, ACTION_DEPLOY, ACTION_LIST, ACTION_UNDEPLOY, ACTION_UPDATE}; // /** The home of the j2ee installation */ // private String j2eeHome; /** The application name that is being undeployed **/ private String application; /** * Perform the actual deployment. * For this implementation, a JVM is spawned and the j2ee.deploy * tools is executed. * @exception org.apache.tools.ant.BuildException if the attributes are invalid or incomplete. */ public void deploy() { Java java = (Java) getTask().getProject().createTask("java"); java.setFork(true); java.setFailonerror(true); java.setClasspath(getClasspath()); java.setClassname(J2EE_DEPLOY_CLASS_NAME); java.createArg().setLine(getArguments()); java.execute(); } /** * 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 org.apache.tools.ant.BuildException if the attributes are invalid or incomplete */ public void validateAttributes() throws BuildException { super.validateAttributes(); String action = getTask().getAction(); // 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); } // 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); } if (getServer() == null) { throw new BuildException("The server attribute must be set if " + "action = " + action); } } /** * Builds the arguments to pass to j2eeri.deploy according to the * supplied action. * @return A String containing the arguments for the j2eeri.deploy tool. */ public String getArguments() throws BuildException { 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; } /** * 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 = getTask().getAction(); for (int i = 0; i < VALID_ACTIONS.length; i++) { if (action.equals(VALID_ACTIONS[i])) { valid = true; break; } } return valid; } /** * Builds the arguments to pass to j2eeri.deploy for deployment actions * ("deploy" and "update"). * @return A String containing the full argument string for j2eeri.deploy. */ protected String buildDeployArgs() { StringBuffer sb = new StringBuffer(); sb.append("-deploy ").append(getTask().getSource()) .append(" ").append(getServer()); // TODO: handle setting jar? return sb.toString(); } /** * Builds the arguments to pass to j2eeri.deploy for undeployment actions * ("undeploy" and "delete"). * @return A String containing the full argument string for j2eeri.deploy. */ protected String buildUndeployArgs() { StringBuffer sb = new StringBuffer(); sb.append("-uninstall ").append(application) .append(" ").append(getServer()); return sb.toString(); } /** * Builds the arguments to pass to j2eeri.deploy for the list action * @return A String containing the full argument string for j2eeri.deploy. */ protected String buildListArgs() { StringBuffer sb = new StringBuffer(); sb.append("-listApps ").append(getServer()); return sb.toString(); } /** * The name of the application being deployed; required. * @param application A String representing the application portion of the * j2eeri.deploy command line. */ public void setApplication(String application) { this.application = application; } // /** // * The j2eehome string for the deployment targets. // * Should point to the installation dir of the J2EE RI. // * @param j2eehome A String representing the installation dir // * of the J2EE reference implementation // */ // public void setJ2eeHome(String j2eeHome) { // this.j2eeHome = j2eeHome; // } }
--- ServerDeploy.java.org 2002-10-02 16:08:30.000000000 +0100 +++ ServerDeploy.java 2003-01-24 17:32:15.000000000 +0000 @@ -101,6 +101,18 @@ vendorTools.addElement(tool); } + /** + * Creates a J2EERI deployment tool, for deployment to Sun's reference + * implementation J2EE servers. + * <p>Ant calls this method on creation to handle embedded "j2eeri" elements + * in the ServerDeploy task. + * @param tool An instance of GenericHotDeployment tool, passed in by Ant. + */ + public void addJ2eeri(J2EERIHotDeploymentTool tool) { + tool.setTask(this); + vendorTools.addElement(tool); + } + /** * Creates a WebLogic deployment tool, for deployment to WebLogic servers. * <p>Ant calls this method on creation to handle embedded "weblogic" elements
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>