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 |
|
---|
19 | import java.io.File;
|
---|
20 | import org.apache.tools.ant.BuildException;
|
---|
21 | import org.apache.tools.ant.taskdefs.Java;
|
---|
22 | import org.apache.tools.ant.types.Path;
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * An Ant wrapper task for the weblogic.deploy tool. This is used
|
---|
26 | * to hot-deploy J2EE applications to a running WebLogic server.
|
---|
27 | * This is <b>not</b> the same as creating the application
|
---|
28 | * archive. This task assumes the archive (EAR, JAR, or WAR) file
|
---|
29 | * has been assembled and is supplied as the "source" attribute.
|
---|
30 | * <p>
|
---|
31 | *
|
---|
32 | * In the end, this task assembles the commadline parameters and
|
---|
33 | * runs the weblogic.deploy tool in a seperate JVM.
|
---|
34 | *
|
---|
35 | *@see org.apache.tools.ant.taskdefs.optional.j2ee.HotDeploymentTool
|
---|
36 | *@see org.apache.tools.ant.taskdefs.optional.j2ee.AbstractHotDeploymentTool
|
---|
37 | *@see org.apache.tools.ant.taskdefs.optional.j2ee.ServerDeploy
|
---|
38 | */
|
---|
39 | public class JonasHotDeploymentTool extends GenericHotDeploymentTool implements HotDeploymentTool {
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * Description of the Field
|
---|
43 | */
|
---|
44 | protected static final String DEFAULT_ORB = "RMI";
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * The classname of the tool to run *
|
---|
48 | */
|
---|
49 | private static final String JONAS_DEPLOY_CLASS_NAME = "org.objectweb.jonas.adm.JonasAdmin";
|
---|
50 |
|
---|
51 | /**
|
---|
52 | * All the valid actions that weblogic.deploy permits *
|
---|
53 | */
|
---|
54 | private static final String[] VALID_ACTIONS
|
---|
55 | = {ACTION_DELETE, ACTION_DEPLOY, ACTION_LIST, ACTION_UNDEPLOY, ACTION_UPDATE};
|
---|
56 |
|
---|
57 | /**
|
---|
58 | * Description of the Field
|
---|
59 | */
|
---|
60 | private File jonasroot;
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * Description of the Field
|
---|
64 | */
|
---|
65 | private String orb = null;
|
---|
66 |
|
---|
67 | /**
|
---|
68 | * Description of the Field
|
---|
69 | */
|
---|
70 | private String davidHost;
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * Description of the Field
|
---|
74 | */
|
---|
75 | private int davidPort;
|
---|
76 |
|
---|
77 |
|
---|
78 | /**
|
---|
79 | * Set the host for the David ORB; required if
|
---|
80 | * ORB==david.
|
---|
81 | *
|
---|
82 | *@param inValue The new davidhost value
|
---|
83 | */
|
---|
84 | public void setDavidhost(final String inValue) {
|
---|
85 | davidHost = inValue;
|
---|
86 | }
|
---|
87 |
|
---|
88 |
|
---|
89 | /**
|
---|
90 | * Set the port for the David ORB; required if
|
---|
91 | * ORB==david.
|
---|
92 | *
|
---|
93 | *@param inValue The new davidport value
|
---|
94 | */
|
---|
95 | public void setDavidport(final int inValue) {
|
---|
96 | davidPort = inValue;
|
---|
97 | }
|
---|
98 |
|
---|
99 |
|
---|
100 | /**
|
---|
101 | * set the jonas root directory (-Dinstall.root=). This
|
---|
102 | * element is required.
|
---|
103 | *
|
---|
104 | *@param inValue The new jonasroot value
|
---|
105 | */
|
---|
106 | public void setJonasroot(final File inValue) {
|
---|
107 | jonasroot = inValue;
|
---|
108 | }
|
---|
109 |
|
---|
110 |
|
---|
111 | /**
|
---|
112 | *
|
---|
113 | * Choose your ORB : RMI, JEREMIE, DAVID, ...; optional.
|
---|
114 | * If omitted, it defaults
|
---|
115 | * to the one present in classpath. The corresponding JOnAS JAR is
|
---|
116 | * automatically added to the classpath. If your orb is DAVID (RMI/IIOP) you must
|
---|
117 | * specify davidhost and davidport properties.
|
---|
118 | *
|
---|
119 | *@param inValue RMI, JEREMIE, DAVID,...
|
---|
120 | */
|
---|
121 | public void setOrb(final String inValue) {
|
---|
122 | orb = inValue;
|
---|
123 | }
|
---|
124 |
|
---|
125 |
|
---|
126 | /**
|
---|
127 | * gets the classpath field.
|
---|
128 | *
|
---|
129 | *@return A Path representing the "classpath" attribute.
|
---|
130 | */
|
---|
131 | public Path getClasspath() {
|
---|
132 |
|
---|
133 | Path aClassPath = super.getClasspath();
|
---|
134 |
|
---|
135 | if (aClassPath == null) {
|
---|
136 | aClassPath = new Path(getTask().getProject());
|
---|
137 | }
|
---|
138 | if (orb != null) {
|
---|
139 | String aOrbJar = new File(jonasroot, "lib/" + orb + "_jonas.jar").toString();
|
---|
140 | String aConfigDir = new File(jonasroot, "config/").toString();
|
---|
141 | Path aJOnASOrbPath = new Path(aClassPath.getProject(),
|
---|
142 | aOrbJar + File.pathSeparator + aConfigDir);
|
---|
143 | aClassPath.append(aJOnASOrbPath);
|
---|
144 | }
|
---|
145 | return aClassPath;
|
---|
146 | }
|
---|
147 |
|
---|
148 |
|
---|
149 | /**
|
---|
150 | * Validates the passed in attributes. <p>
|
---|
151 | *
|
---|
152 | * The rules are:
|
---|
153 | * <ol>
|
---|
154 | * <li> If action is "deploy" or "update" the "application"
|
---|
155 | * and "source" attributes must be supplied.
|
---|
156 | * <li> If action is "delete" or "undeploy" the
|
---|
157 | * "application" attribute must be supplied.
|
---|
158 | *
|
---|
159 | *@exception BuildException Description
|
---|
160 | * of Exception
|
---|
161 | */
|
---|
162 | public void validateAttributes() throws BuildException {
|
---|
163 | // super.validateAttributes(); // don't want to call this method
|
---|
164 |
|
---|
165 | Java java = getJava();
|
---|
166 |
|
---|
167 | String action = getTask().getAction();
|
---|
168 | if (action == null) {
|
---|
169 | throw new BuildException("The \"action\" attribute must be set");
|
---|
170 | }
|
---|
171 |
|
---|
172 | if (!isActionValid()) {
|
---|
173 | throw new BuildException("Invalid action \"" + action + "\" 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("-Djava.security.policy=" + jonasroot
|
---|
183 | + "/config/java.policy");
|
---|
184 |
|
---|
185 | if ("DAVID".equals(orb)) {
|
---|
186 | java.createJvmarg().setValue("-Dorg.omg.CORBA.ORBClass"
|
---|
187 | + "=org.objectweb.david.libs.binding.orbs.iiop.IIOPORB");
|
---|
188 | java.createJvmarg().setValue("-Dorg.omg.CORBA.ORBSingletonClass="
|
---|
189 | + "org.objectweb.david.libs.binding.orbs.ORBSingletonClass");
|
---|
190 | java.createJvmarg().setValue("-Djavax.rmi.CORBA.StubClass="
|
---|
191 | + "org.objectweb.david.libs.stub_factories.rmi.StubDelegate");
|
---|
192 | java.createJvmarg().setValue("-Djavax.rmi.CORBA.PortableRemoteObjectClass="
|
---|
193 | + "org.objectweb.david.libs.binding.rmi.ORBPortableRemoteObjectDelegate");
|
---|
194 | java.createJvmarg().setValue("-Djavax.rmi.CORBA.UtilClass="
|
---|
195 | + "org.objectweb.david.libs.helpers.RMIUtilDelegate");
|
---|
196 | java.createJvmarg().setValue("-Ddavid.CosNaming.default_method=0");
|
---|
197 | java.createJvmarg().setValue("-Ddavid.rmi.ValueHandlerClass="
|
---|
198 | + "com.sun.corba.se.internal.io.ValueHandlerImpl");
|
---|
199 | if (davidHost != null) {
|
---|
200 | java.createJvmarg().setValue("-Ddavid.CosNaming.default_host="
|
---|
201 | + davidHost);
|
---|
202 | }
|
---|
203 | if (davidPort != 0) {
|
---|
204 | java.createJvmarg().setValue("-Ddavid.CosNaming.default_port="
|
---|
205 | + davidPort);
|
---|
206 | }
|
---|
207 | }
|
---|
208 | }
|
---|
209 |
|
---|
210 | if (getServer() != null) {
|
---|
211 | java.createArg().setLine("-n " + getServer());
|
---|
212 | }
|
---|
213 |
|
---|
214 | if (action.equals(ACTION_DEPLOY)
|
---|
215 | || action.equals(ACTION_UPDATE)
|
---|
216 | || action.equals("redeploy")) {
|
---|
217 | java.createArg().setLine("-a " + getTask().getSource());
|
---|
218 | } else if (action.equals(ACTION_DELETE) || action.equals(ACTION_UNDEPLOY)) {
|
---|
219 | java.createArg().setLine("-r " + getTask().getSource());
|
---|
220 | } else if (action.equals(ACTION_LIST)) {
|
---|
221 | java.createArg().setValue("-l");
|
---|
222 | }
|
---|
223 | }
|
---|
224 |
|
---|
225 |
|
---|
226 | /**
|
---|
227 | * Determines if the action supplied is valid. <p>
|
---|
228 | *
|
---|
229 | * Valid actions are contained in the static array
|
---|
230 | * VALID_ACTIONS
|
---|
231 | *
|
---|
232 | *@return true if the action attribute is valid, false if
|
---|
233 | * not.
|
---|
234 | */
|
---|
235 | protected boolean isActionValid() {
|
---|
236 | boolean valid = false;
|
---|
237 |
|
---|
238 | String action = getTask().getAction();
|
---|
239 |
|
---|
240 | for (int i = 0; i < VALID_ACTIONS.length; i++) {
|
---|
241 | if (action.equals(VALID_ACTIONS[i])) {
|
---|
242 | valid = true;
|
---|
243 | break;
|
---|
244 | }
|
---|
245 | }
|
---|
246 |
|
---|
247 | return valid;
|
---|
248 | }
|
---|
249 | }
|
---|
250 |
|
---|