1. /*
  2. * Copyright 2002,2004 The Apache Software Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *
  16. */
  17. package org.apache.tools.ant.taskdefs.optional.j2ee;
  18. import java.io.File;
  19. import org.apache.tools.ant.BuildException;
  20. import org.apache.tools.ant.taskdefs.Java;
  21. import org.apache.tools.ant.types.Path;
  22. /**
  23. * An Ant wrapper task for the weblogic.deploy tool. This is used
  24. * to hot-deploy J2EE applications to a running WebLogic server.
  25. * This is <b>not</b> the same as creating the application
  26. * archive. This task assumes the archive (EAR, JAR, or WAR) file
  27. * has been assembled and is supplied as the "source" attribute.
  28. * <p>
  29. *
  30. * In the end, this task assembles the commadline parameters and
  31. * runs the weblogic.deploy tool in a seperate JVM.
  32. *
  33. *@see org.apache.tools.ant.taskdefs.optional.j2ee.HotDeploymentTool
  34. *@see org.apache.tools.ant.taskdefs.optional.j2ee.AbstractHotDeploymentTool
  35. *@see org.apache.tools.ant.taskdefs.optional.j2ee.ServerDeploy
  36. */
  37. public class JonasHotDeploymentTool extends GenericHotDeploymentTool implements HotDeploymentTool {
  38. /**
  39. * Description of the Field
  40. */
  41. protected static final String DEFAULT_ORB = "RMI";
  42. /**
  43. * The classname of the tool to run *
  44. */
  45. private static final String JONAS_DEPLOY_CLASS_NAME = "org.objectweb.jonas.adm.JonasAdmin";
  46. /**
  47. * All the valid actions that weblogic.deploy permits *
  48. */
  49. private static final String[] VALID_ACTIONS
  50. = {ACTION_DELETE, ACTION_DEPLOY, ACTION_LIST, ACTION_UNDEPLOY, ACTION_UPDATE};
  51. /**
  52. * Description of the Field
  53. */
  54. private File jonasroot;
  55. /**
  56. * Description of the Field
  57. */
  58. private String orb = null;
  59. /**
  60. * Description of the Field
  61. */
  62. private String davidHost;
  63. /**
  64. * Description of the Field
  65. */
  66. private int davidPort;
  67. /**
  68. * Set the host for the David ORB; required if
  69. * ORB==david.
  70. *
  71. *@param inValue The new davidhost value
  72. */
  73. public void setDavidhost(final String inValue) {
  74. davidHost = inValue;
  75. }
  76. /**
  77. * Set the port for the David ORB; required if
  78. * ORB==david.
  79. *
  80. *@param inValue The new davidport value
  81. */
  82. public void setDavidport(final int inValue) {
  83. davidPort = inValue;
  84. }
  85. /**
  86. * set the jonas root directory (-Dinstall.root=). This
  87. * element is required.
  88. *
  89. *@param inValue The new jonasroot value
  90. */
  91. public void setJonasroot(final File inValue) {
  92. jonasroot = inValue;
  93. }
  94. /**
  95. *
  96. * Choose your ORB : RMI, JEREMIE, DAVID, ...; optional.
  97. * If omitted, it defaults
  98. * to the one present in classpath. The corresponding JOnAS JAR is
  99. * automatically added to the classpath. If your orb is DAVID (RMI/IIOP) you must
  100. * specify davidhost and davidport properties.
  101. *
  102. *@param inValue RMI, JEREMIE, DAVID,...
  103. */
  104. public void setOrb(final String inValue) {
  105. orb = inValue;
  106. }
  107. /**
  108. * gets the classpath field.
  109. *
  110. *@return A Path representing the "classpath" attribute.
  111. */
  112. public Path getClasspath() {
  113. Path aClassPath = super.getClasspath();
  114. if (aClassPath == null) {
  115. aClassPath = new Path(getTask().getProject());
  116. }
  117. if (orb != null) {
  118. String aOrbJar = new File(jonasroot, "lib/" + orb + "_jonas.jar").toString();
  119. String aConfigDir = new File(jonasroot, "config/").toString();
  120. Path aJOnASOrbPath = new Path(aClassPath.getProject(),
  121. aOrbJar + File.pathSeparator + aConfigDir);
  122. aClassPath.append(aJOnASOrbPath);
  123. }
  124. return aClassPath;
  125. }
  126. /**
  127. * Validates the passed in attributes. <p>
  128. *
  129. * The rules are:
  130. * <ol>
  131. * <li> If action is "deploy" or "update" the "application"
  132. * and "source" attributes must be supplied.
  133. * <li> If action is "delete" or "undeploy" the
  134. * "application" attribute must be supplied.
  135. *
  136. *@exception BuildException Description
  137. * of Exception
  138. */
  139. public void validateAttributes() throws BuildException {
  140. // super.validateAttributes(); // don't want to call this method
  141. Java java = getJava();
  142. String action = getTask().getAction();
  143. if (action == null) {
  144. throw new BuildException("The \"action\" attribute must be set");
  145. }
  146. if (!isActionValid()) {
  147. throw new BuildException("Invalid action \"" + action + "\" passed");
  148. }
  149. if (getClassName() == null) {
  150. setClassName(JONAS_DEPLOY_CLASS_NAME);
  151. }
  152. if (jonasroot == null || jonasroot.isDirectory()) {
  153. java.createJvmarg().setValue("-Dinstall.root=" + jonasroot);
  154. java.createJvmarg().setValue("-Djava.security.policy=" + jonasroot
  155. + "/config/java.policy");
  156. if ("DAVID".equals(orb)) {
  157. java.createJvmarg().setValue("-Dorg.omg.CORBA.ORBClass"
  158. + "=org.objectweb.david.libs.binding.orbs.iiop.IIOPORB");
  159. java.createJvmarg().setValue("-Dorg.omg.CORBA.ORBSingletonClass="
  160. + "org.objectweb.david.libs.binding.orbs.ORBSingletonClass");
  161. java.createJvmarg().setValue("-Djavax.rmi.CORBA.StubClass="
  162. + "org.objectweb.david.libs.stub_factories.rmi.StubDelegate");
  163. java.createJvmarg().setValue("-Djavax.rmi.CORBA.PortableRemoteObjectClass="
  164. + "org.objectweb.david.libs.binding.rmi.ORBPortableRemoteObjectDelegate");
  165. java.createJvmarg().setValue("-Djavax.rmi.CORBA.UtilClass="
  166. + "org.objectweb.david.libs.helpers.RMIUtilDelegate");
  167. java.createJvmarg().setValue("-Ddavid.CosNaming.default_method=0");
  168. java.createJvmarg().setValue("-Ddavid.rmi.ValueHandlerClass="
  169. + "com.sun.corba.se.internal.io.ValueHandlerImpl");
  170. if (davidHost != null) {
  171. java.createJvmarg().setValue("-Ddavid.CosNaming.default_host="
  172. + davidHost);
  173. }
  174. if (davidPort != 0) {
  175. java.createJvmarg().setValue("-Ddavid.CosNaming.default_port="
  176. + davidPort);
  177. }
  178. }
  179. }
  180. if (getServer() != null) {
  181. java.createArg().setLine("-n " + getServer());
  182. }
  183. if (action.equals(ACTION_DEPLOY)
  184. || action.equals(ACTION_UPDATE)
  185. || action.equals("redeploy")) {
  186. java.createArg().setLine("-a " + getTask().getSource());
  187. } else if (action.equals(ACTION_DELETE) || action.equals(ACTION_UNDEPLOY)) {
  188. java.createArg().setLine("-r " + getTask().getSource());
  189. } else if (action.equals(ACTION_LIST)) {
  190. java.createArg().setValue("-l");
  191. }
  192. }
  193. /**
  194. * Determines if the action supplied is valid. <p>
  195. *
  196. * Valid actions are contained in the static array
  197. * VALID_ACTIONS
  198. *
  199. *@return true if the action attribute is valid, false if
  200. * not.
  201. */
  202. protected boolean isActionValid() {
  203. boolean valid = false;
  204. String action = getTask().getAction();
  205. for (int i = 0; i < VALID_ACTIONS.length; i++) {
  206. if (action.equals(VALID_ACTIONS[i])) {
  207. valid = true;
  208. break;
  209. }
  210. }
  211. return valid;
  212. }
  213. }