001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 2004 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * Initial developer: Florent BENOIT
022: * --------------------------------------------------------------------------
023: * $Id: BootstrapTask.java 8647 2006-06-16 13:26:10Z duvauchn $
024: * --------------------------------------------------------------------------
025: */package org.objectweb.jonas.ant;
026:
027: import java.io.File;
028:
029: import org.apache.tools.ant.BuildException;
030: import org.apache.tools.ant.Task;
031: import org.apache.tools.ant.taskdefs.Java;
032: import org.apache.tools.ant.types.Path;
033:
034: /**
035: * Allow to use the BootStrap class <br/>It allows to do some operations like
036: * <ul><li>starting/stopping JOnAS</li><li>Deploying some apps</li><li>
037: * etc... </li</ul>
038: * @author Florent Benoit
039: */
040: public abstract class BootstrapTask extends Task {
041:
042: /**
043: * Bootstrap class name
044: */
045: private static final String BOOTSTRAP_CLASS = "org.objectweb.jonas.server.Bootstrap";
046:
047: /**
048: * Default JOnAS server name
049: */
050: private static final String DEFAULT_SERVER_NAME = "jonas";
051:
052: /**
053: * Name of the task (to be displayed in log : default to JOnAS)
054: */
055: private String taskName = "JOnAS";
056:
057: /**
058: * JOnAS Root
059: */
060: private File jonasRoot = null;
061:
062: /**
063: * Name of the server (default 'jonas')
064: */
065: private String serverName = DEFAULT_SERVER_NAME;
066:
067: /**
068: * Name of the server (default 'jonas')
069: */
070: private String domainName = null;
071:
072: /**
073: * JOnAS Base
074: */
075: private File jonasBase = null;
076:
077: /**
078: * Catalina Home
079: */
080: private String catalinaHome = null;
081:
082: /**
083: * Jetty home
084: */
085: private String jettyHome = null;
086:
087: /**
088: * Options given to the JVM
089: */
090: private String jvmOpts = null;
091:
092: /**
093: * Classpath used for this task
094: */
095: private Path classpath = null;
096:
097: /**
098: * Set the JOnAS root directory.
099: * @param jonasRoot the JOnAS root directory.
100: */
101: public void setJonasRoot(File jonasRoot) {
102: this .jonasRoot = jonasRoot;
103: }
104:
105: /**
106: * Set the JOnAS base directory.
107: * @param jonasBase the JOnAS base directory.
108: */
109: public void setJonasbase(File jonasBase) {
110: this .jonasBase = jonasBase;
111: }
112:
113: /**
114: * Set the additional args to pass to the JVM.
115: * @param jvmOpts the options.
116: */
117: public void setJvmopts(String jvmOpts) {
118: this .jvmOpts = jvmOpts;
119: }
120:
121: /**
122: * Adds to the classpath the class of the project
123: * @return the path to be configured.
124: */
125: public Path createClasspath() {
126: return new Path(getProject());
127: }
128:
129: /**
130: * Set the classpath for this task
131: * @param classpath the classpath to use.
132: */
133: public void setClasspath(Path classpath) {
134: this .classpath = classpath;
135: }
136:
137: /**
138: * Run the task
139: * @see org.apache.tools.ant.Task#execute()
140: */
141: protected Java getBootstraptask(String definedClass) {
142:
143: if (jonasRoot == null) {
144: // get ant property
145: String jr = getProject().getProperty("jonas.root");
146: jonasRoot = new File(jr);
147:
148: if (jr == null) {
149: throw new BuildException(
150: "attribute jonasroot is necessary.");
151: }
152: }
153:
154: if (jonasBase == null) {
155: jonasBase = jonasRoot;
156: }
157:
158: Java bootstrapTask = (Java) getProject().createTask("java");
159: bootstrapTask.setTaskName(taskName);
160: bootstrapTask.setFork(true);
161: bootstrapTask.setFailonerror(true);
162:
163: // Name of the server
164: bootstrapTask.createJvmarg().setValue(
165: "-Djonas.name=" + serverName);
166:
167: // Name of the domain
168: if (domainName != null) {
169: bootstrapTask.createJvmarg().setValue(
170: "-Ddomain.name=" + domainName);
171: }
172:
173: // jonas root
174: bootstrapTask.createJvmarg().setValue(
175: "-Dinstall.root=" + jonasRoot);
176:
177: // jonas base
178: bootstrapTask.createJvmarg().setValue(
179: "-Djonas.base=" + jonasBase);
180:
181: // set headless (for unix without X running)
182: bootstrapTask.createJvmarg().setValue(
183: "-Djava.awt.headless=true");
184:
185: // Properties of JVM
186: bootstrapTask.createJvmarg().setValue(
187: "-Djonas.default.classloader=true");
188: bootstrapTask.createJvmarg().setValue("-Djonas.classpath=");
189: bootstrapTask
190: .createJvmarg()
191: .setValue(
192: "-Djava.naming.factory.initial=org.objectweb.carol.jndi.spi.MultiOrbInitialContextFactory");
193:
194: // iiop
195: bootstrapTask.createJvmarg().setValue(
196: "-Dorg.omg.CORBA.ORBClass=org.jacorb.orb.ORB");
197: bootstrapTask
198: .createJvmarg()
199: .setValue(
200: "-Dorg.omg.CORBA.ORBSingletonClass=org.jacorb.orb.ORBSingleton");
201: bootstrapTask
202: .createJvmarg()
203: .setValue(
204: "-Dorg.omg.PortableInterceptor.ORBInitializerClass.standard_init=org.jacorb.orb.standardInterceptors.IORInterceptorInitializer");
205:
206: File jonasLibDir = new File(jonasRoot, "lib");
207: File jonasLibEndorsedDir = new File(jonasLibDir, "endorsed");
208: bootstrapTask
209: .createJvmarg()
210: .setValue(
211: "-Djavax.rmi.CORBA.PortableRemoteObjectClass=org.objectweb.carol.rmi.multi.MultiPRODelegate");
212: bootstrapTask
213: .createJvmarg()
214: .setValue(
215: "-Djava.naming.factory.initial=org.objectweb.carol.jndi.spi.MultiOrbInitialContextFactory");
216: bootstrapTask.createJvmarg()
217: .setValue(
218: "-Djava.endorsed.dirs="
219: + jonasLibEndorsedDir.getPath());
220:
221: // Rmi annotation
222: bootstrapTask
223: .createJvmarg()
224: .setValue(
225: "-Djava.rmi.server.RMIClassLoaderSpi=org.objectweb.jonas.server.RemoteClassLoaderSpi");
226:
227: // Webcontainer
228: if (catalinaHome != null) {
229: bootstrapTask.createJvmarg().setValue(
230: "-Dcatalina.home=" + catalinaHome);
231: }
232: bootstrapTask.createJvmarg().setValue(
233: "-Dcatalina.base=" + jonasBase);
234:
235: if (jettyHome != null) {
236: bootstrapTask.createJvmarg().setValue(
237: "-Djetty.home=" + jettyHome);
238: }
239:
240: // java policy file
241: String jonasConfigDir = jonasBase + File.separator + "conf";
242: File javaPolicyFile = new File(jonasConfigDir, "java.policy");
243: if (javaPolicyFile.exists()) {
244: bootstrapTask.createJvmarg().setValue(
245: "-Djava.security.policy="
246: + javaPolicyFile.getPath());
247: }
248: File javaAuthLoginFile = new File(jonasConfigDir, "jaas.config");
249: bootstrapTask.createJvmarg().setValue(
250: "-Djava.security.auth.login.config="
251: + javaAuthLoginFile.getPath());
252:
253: // The bootstrap class must launch the defined class
254: bootstrapTask.createArg().setValue(definedClass);
255:
256: // add jonas_base/conf
257: classpath = new Path(getProject(), jonasConfigDir);
258:
259: // then add ow_jonas_bootstrap.jar to classloader
260: String bootJar = jonasRoot + File.separator + "lib"
261: + File.separator + "common" + File.separator
262: + "ow_jonas_bootstrap.jar";
263: classpath.append(new Path(getProject(), bootJar));
264:
265: // Add tools.jar
266: String toolsJar = System.getProperty("java.home")
267: + File.separator + ".." + File.separator + "lib"
268: + File.separator + "tools.jar";
269: classpath.append(new Path(getProject(), toolsJar));
270:
271: // Set the classpath
272: bootstrapTask.setClasspath(classpath);
273:
274: // class to use = bootstrap class
275: bootstrapTask.setClassname(BOOTSTRAP_CLASS);
276:
277: // add user defined jvmopts
278: if (jvmOpts != null && !jvmOpts.equals("")) {
279: bootstrapTask.createJvmarg().setLine(jvmOpts);
280: }
281:
282: // add jonas name
283: if (serverName != null) {
284: bootstrapTask.createArg().setValue("-n");
285: bootstrapTask.createArg().setValue(getServerName());
286: }
287:
288: return bootstrapTask;
289:
290: }
291:
292: /**
293: * @return the taskName.
294: */
295: public String getTaskName() {
296: return taskName;
297: }
298:
299: /**
300: * Set the name of the task
301: * @param taskName Name of the task
302: */
303: public void setTaskName(String taskName) {
304: this .taskName = taskName;
305: }
306:
307: /**
308: * @return the server Name.
309: */
310: public String getServerName() {
311: return serverName;
312: }
313:
314: /**
315: * Set the name of the server
316: * @param serverName The serverName to set.
317: */
318: public void setServerName(String serverName) {
319: this .serverName = serverName;
320: }
321:
322: /**
323: * @return the catalinaHome.
324: */
325: public String getCatalinaHome() {
326: return catalinaHome;
327: }
328:
329: /**
330: * Set catalina Home
331: * @param catalinaHome The catalinaHome to set.
332: */
333: public void setCatalinaHome(String catalinaHome) {
334: this .catalinaHome = catalinaHome;
335: }
336:
337: /**
338: * @return the jettyHome.
339: */
340: public String getJettyHome() {
341: return jettyHome;
342: }
343:
344: /**
345: * Set jetty home path
346: * @param jettyHome The jettyHome to set.
347: */
348: public void setJettyHome(String jettyHome) {
349: this .jettyHome = jettyHome;
350: }
351:
352: /**
353: * @return the jonasRoot.
354: */
355: public File getJonasRoot() {
356: return jonasRoot;
357: }
358:
359: /**
360: * @return the domainName.
361: */
362: public String getDomainName() {
363: return domainName;
364: }
365:
366: /**
367: * Set domainName
368: * @param domainName The domainName to set.
369: */
370: public void setDomainName(String domainName) {
371: this.domainName = domainName;
372: }
373:
374: }
|