001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018: package org.apache.tools.ant.taskdefs.optional.j2ee;
019:
020: import java.io.File;
021: import org.apache.tools.ant.BuildException;
022: import org.apache.tools.ant.taskdefs.Java;
023: import org.apache.tools.ant.types.Path;
024:
025: /**
026: * An Ant wrapper task for the weblogic.deploy tool. This is used
027: * to hot-deploy J2EE applications to a running WebLogic server.
028: * This is <b>not</b> the same as creating the application
029: * archive. This task assumes the archive (EAR, JAR, or WAR) file
030: * has been assembled and is supplied as the "source" attribute.
031: * <p>
032: *
033: * In the end, this task assembles the commadline parameters and
034: * runs the weblogic.deploy tool in a seperate JVM.
035: *
036: *@see org.apache.tools.ant.taskdefs.optional.j2ee.HotDeploymentTool
037: *@see org.apache.tools.ant.taskdefs.optional.j2ee.AbstractHotDeploymentTool
038: *@see org.apache.tools.ant.taskdefs.optional.j2ee.ServerDeploy
039: */
040: public class JonasHotDeploymentTool extends GenericHotDeploymentTool
041: implements HotDeploymentTool {
042:
043: /**
044: * Description of the Field
045: */
046: protected static final String DEFAULT_ORB = "RMI";
047:
048: /**
049: * The classname of the tool to run *
050: */
051: private static final String JONAS_DEPLOY_CLASS_NAME = "org.objectweb.jonas.adm.JonasAdmin";
052:
053: /**
054: * All the valid actions that weblogic.deploy permits *
055: */
056: private static final String[] VALID_ACTIONS = { ACTION_DELETE,
057: ACTION_DEPLOY, ACTION_LIST, ACTION_UNDEPLOY, ACTION_UPDATE };
058:
059: /**
060: * Description of the Field
061: */
062: private File jonasroot;
063:
064: /**
065: * Description of the Field
066: */
067: private String orb = null;
068:
069: /**
070: * Description of the Field
071: */
072: private String davidHost;
073:
074: /**
075: * Description of the Field
076: */
077: private int davidPort;
078:
079: /**
080: * Set the host for the David ORB; required if
081: * ORB==david.
082: *
083: *@param inValue The new davidhost value
084: */
085: public void setDavidhost(final String inValue) {
086: davidHost = inValue;
087: }
088:
089: /**
090: * Set the port for the David ORB; required if
091: * ORB==david.
092: *
093: *@param inValue The new davidport value
094: */
095: public void setDavidport(final int inValue) {
096: davidPort = inValue;
097: }
098:
099: /**
100: * set the jonas root directory (-Dinstall.root=). This
101: * element is required.
102: *
103: *@param inValue The new jonasroot value
104: */
105: public void setJonasroot(final File inValue) {
106: jonasroot = inValue;
107: }
108:
109: /**
110: *
111: * Choose your ORB : RMI, JEREMIE, DAVID, ...; optional.
112: * If omitted, it defaults
113: * to the one present in classpath. The corresponding JOnAS JAR is
114: * automatically added to the classpath. If your orb is DAVID (RMI/IIOP) you must
115: * specify davidhost and davidport properties.
116: *
117: *@param inValue RMI, JEREMIE, DAVID,...
118: */
119: public void setOrb(final String inValue) {
120: orb = inValue;
121: }
122:
123: /**
124: * gets the classpath field.
125: *
126: *@return A Path representing the "classpath" attribute.
127: */
128: public Path getClasspath() {
129:
130: Path aClassPath = super .getClasspath();
131:
132: if (aClassPath == null) {
133: aClassPath = new Path(getTask().getProject());
134: }
135: if (orb != null) {
136: String aOrbJar = new File(jonasroot, "lib/" + orb
137: + "_jonas.jar").toString();
138: String aConfigDir = new File(jonasroot, "config/")
139: .toString();
140: Path aJOnASOrbPath = new Path(aClassPath.getProject(),
141: aOrbJar + File.pathSeparator + aConfigDir);
142: aClassPath.append(aJOnASOrbPath);
143: }
144: return aClassPath;
145: }
146:
147: /**
148: * Validates the passed in attributes. <p>
149: *
150: * The rules are:
151: * <ol>
152: * <li> If action is "deploy" or "update" the "application"
153: * and "source" attributes must be supplied.
154: * <li> If action is "delete" or "undeploy" the
155: * "application" attribute must be supplied.
156: *
157: *@exception BuildException Description
158: * of Exception
159: */
160: public void validateAttributes() throws BuildException {
161: // super.validateAttributes(); // don't want to call this method
162:
163: Java java = getJava();
164:
165: String action = getTask().getAction();
166: if (action == null) {
167: throw new BuildException(
168: "The \"action\" attribute must be set");
169: }
170:
171: if (!isActionValid()) {
172: throw new BuildException("Invalid action \"" + action
173: + "\" passed");
174: }
175:
176: if (getClassName() == null) {
177: setClassName(JONAS_DEPLOY_CLASS_NAME);
178: }
179:
180: if (jonasroot == null || jonasroot.isDirectory()) {
181: java.createJvmarg().setValue("-Dinstall.root=" + jonasroot);
182: java.createJvmarg().setValue(
183: "-Djava.security.policy=" + jonasroot
184: + "/config/java.policy");
185:
186: if ("DAVID".equals(orb)) {
187: java
188: .createJvmarg()
189: .setValue(
190: "-Dorg.omg.CORBA.ORBClass"
191: + "=org.objectweb.david.libs.binding.orbs.iiop.IIOPORB");
192: java
193: .createJvmarg()
194: .setValue(
195: "-Dorg.omg.CORBA.ORBSingletonClass="
196: + "org.objectweb.david.libs.binding.orbs.ORBSingletonClass");
197: java
198: .createJvmarg()
199: .setValue(
200: "-Djavax.rmi.CORBA.StubClass="
201: + "org.objectweb.david.libs.stub_factories.rmi.StubDelegate");
202: java
203: .createJvmarg()
204: .setValue(
205: "-Djavax.rmi.CORBA.PortableRemoteObjectClass="
206: + "org.objectweb.david.libs.binding.rmi.ORBPortableRemoteObjectDelegate");
207: java
208: .createJvmarg()
209: .setValue(
210: "-Djavax.rmi.CORBA.UtilClass="
211: + "org.objectweb.david.libs.helpers.RMIUtilDelegate");
212: java.createJvmarg().setValue(
213: "-Ddavid.CosNaming.default_method=0");
214: java
215: .createJvmarg()
216: .setValue(
217: "-Ddavid.rmi.ValueHandlerClass="
218: + "com.sun.corba.se.internal.io.ValueHandlerImpl");
219: if (davidHost != null) {
220: java.createJvmarg().setValue(
221: "-Ddavid.CosNaming.default_host="
222: + davidHost);
223: }
224: if (davidPort != 0) {
225: java.createJvmarg().setValue(
226: "-Ddavid.CosNaming.default_port="
227: + davidPort);
228: }
229: }
230: }
231:
232: if (getServer() != null) {
233: java.createArg().setLine("-n " + getServer());
234: }
235:
236: if (action.equals(ACTION_DEPLOY)
237: || action.equals(ACTION_UPDATE)
238: || action.equals("redeploy")) {
239: java.createArg().setLine("-a " + getTask().getSource());
240: } else if (action.equals(ACTION_DELETE)
241: || action.equals(ACTION_UNDEPLOY)) {
242: java.createArg().setLine("-r " + getTask().getSource());
243: } else if (action.equals(ACTION_LIST)) {
244: java.createArg().setValue("-l");
245: }
246: }
247:
248: /**
249: * Determines if the action supplied is valid. <p>
250: *
251: * Valid actions are contained in the static array
252: * VALID_ACTIONS
253: *
254: *@return true if the action attribute is valid, false if
255: * not.
256: */
257: protected boolean isActionValid() {
258: boolean valid = false;
259:
260: String action = getTask().getAction();
261:
262: for (int i = 0; i < VALID_ACTIONS.length; i++) {
263: if (action.equals(VALID_ACTIONS[i])) {
264: valid = true;
265: break;
266: }
267: }
268:
269: return valid;
270: }
271: }
|