KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > ant > BootstrapTask


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 2004 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * Initial developer: Florent BENOIT
22  * --------------------------------------------------------------------------
23  * $Id: BootstrapTask.java,v 1.4 2005/03/09 12:55:50 sauthieg Exp $
24  * --------------------------------------------------------------------------
25  */

26 package org.objectweb.jonas.ant;
27
28 import java.io.File JavaDoc;
29
30 import org.apache.tools.ant.BuildException;
31 import org.apache.tools.ant.Task;
32 import org.apache.tools.ant.taskdefs.Java;
33 import org.apache.tools.ant.types.Path;
34
35 /**
36  * Allow to use the BootStrap class <br/>It allows to do some operations like
37  * <ul><li>starting/stopping JOnAS</li><li>Deploying some apps</li><li>
38  * etc... </li</ul>
39  * @author Florent Benoit
40  */

41 public abstract class BootstrapTask extends Task {
42
43     /**
44      * Bootstrap class name
45      */

46     private static final String JavaDoc BOOTSTRAP_CLASS = "org.objectweb.jonas.server.Bootstrap";
47
48     /**
49      * Default JOnAS server name
50      */

51     private static final String JavaDoc DEFAULT_SERVER_NAME = "jonas";
52
53     /**
54      * Name of the task (to be displayed in log : default to JOnAS)
55      */

56     private String JavaDoc taskName = "JOnAS";
57
58     /**
59      * JOnAS Root
60      */

61     private File JavaDoc jonasRoot = null;
62
63     /**
64      * Name of the server (default 'jonas')
65      */

66     private String JavaDoc serverName = DEFAULT_SERVER_NAME;
67
68     /**
69      * JOnAS Base
70      */

71     private File JavaDoc jonasBase = null;
72
73     /**
74      * Catalina Home
75      */

76     private String JavaDoc catalinaHome = null;
77
78     /**
79      * Jetty home
80      */

81     private String JavaDoc jettyHome = null;
82
83     /**
84      * Options given to the JVM
85      */

86     private String JavaDoc jvmOpts = null;
87
88     /**
89      * Classpath used for this task
90      */

91     private Path classpath = null;
92
93     /**
94      * Set the JOnAS root directory.
95      * @param jonasRoot the JOnAS root directory.
96      */

97     public void setJonasRoot(File JavaDoc jonasRoot) {
98         this.jonasRoot = jonasRoot;
99     }
100
101     /**
102      * Set the JOnAS base directory.
103      * @param jonasBase the JOnAS base directory.
104      */

105     public void setJonasbase(File JavaDoc jonasBase) {
106         this.jonasBase = jonasBase;
107     }
108
109     /**
110      * Set the additional args to pass to the JVM.
111      * @param jvmOpts the options.
112      */

113     public void setJvmopts(String JavaDoc jvmOpts) {
114         this.jvmOpts = jvmOpts;
115     }
116
117     /**
118      * Adds to the classpath the class of the project
119      * @return the path to be configured.
120      */

121     public Path createClasspath() {
122         return new Path(getProject());
123     }
124
125     /**
126      * Set the classpath for this task
127      * @param classpath the classpath to use.
128      */

129     public void setClasspath(Path classpath) {
130         this.classpath = classpath;
131     }
132
133     /**
134      * Run the task
135      * @see org.apache.tools.ant.Task#execute()
136      */

137     protected Java getBootstraptask(String JavaDoc definedClass) {
138
139         if (jonasRoot == null) {
140             // get ant property
141
String JavaDoc jr = getProject().getProperty("jonas.root");
142             jonasRoot = new File JavaDoc(jr);
143
144             if (jr == null) {
145                 throw new BuildException("attribute jonasroot is necessary.");
146             }
147         }
148
149         if (jonasBase == null) {
150             jonasBase = jonasRoot;
151         }
152
153         Java bootstrapTask = (Java) getProject().createTask("java");
154         bootstrapTask.setTaskName(taskName);
155         bootstrapTask.setFork(true);
156         bootstrapTask.setFailonerror(true);
157
158         // Name of the server
159
bootstrapTask.createJvmarg().setValue("-Djonas.name=" + serverName);
160
161         // jonas root
162
bootstrapTask.createJvmarg().setValue("-Dinstall.root=" + jonasRoot);
163
164         // jonas base
165
bootstrapTask.createJvmarg().setValue("-Djonas.base=" + jonasBase);
166
167         // Properties of JVM
168
bootstrapTask.createJvmarg().setValue("-Djonas.default.classloader=true");
169         bootstrapTask.createJvmarg().setValue("-Djonas.classpath=");
170         bootstrapTask.createJvmarg().setValue(
171                 "-Djava.naming.factory.initial=org.objectweb.carol.jndi.spi.MultiOrbInitialContextFactory");
172
173         // iiop
174
File JavaDoc jonasLibDir = new File JavaDoc(jonasRoot, "lib");
175         File JavaDoc jonasLibEndorsedDir = new File JavaDoc(jonasLibDir, "endorsed");
176         bootstrapTask.createJvmarg().setValue(
177                 "-Djavax.rmi.CORBA.PortableRemoteObjectClass=org.objectweb.carol.rmi.multi.MultiPRODelegate");
178         bootstrapTask.createJvmarg().setValue(
179                 "-Djava.naming.factory.initial=org.objectweb.carol.jndi.spi.MultiOrbInitialContextFactory");
180         bootstrapTask.createJvmarg().setValue("-Djava.endorsed.dirs=" + jonasLibEndorsedDir.getPath());
181
182         // Rmi annotation
183
bootstrapTask.createJvmarg().setValue(
184                 "-Djava.rmi.server.RMIClassLoaderSpi=org.objectweb.jonas.server.RemoteClassLoaderSpi");
185
186         // Webcontainer
187
if (catalinaHome != null) {
188             bootstrapTask.createJvmarg().setValue("-Dcatalina.home=" + catalinaHome);
189         }
190         bootstrapTask.createJvmarg().setValue("-Dcatalina.base=" + jonasBase);
191
192         if (jettyHome != null) {
193             bootstrapTask.createJvmarg().setValue("-Djetty.home=" + jettyHome);
194         }
195
196         // java policy file
197
String JavaDoc jonasConfigDir = jonasBase + File.separator + "conf";
198         File JavaDoc javaPolicyFile = new File JavaDoc(jonasConfigDir, "java.policy");
199         if (javaPolicyFile.exists()) {
200             bootstrapTask.createJvmarg().setValue("-Djava.security.policy=" + javaPolicyFile.getPath());
201         }
202         File JavaDoc javaAuthLoginFile = new File JavaDoc(jonasConfigDir, "jaas.config");
203         bootstrapTask.createJvmarg().setValue("-Djava.security.auth.login.config=" + javaAuthLoginFile.getPath());
204
205         // The bootstrap class must launch the defined class
206
bootstrapTask.createArg().setValue(definedClass);
207
208         // add jonas_base/conf
209
classpath = new Path(getProject(), jonasConfigDir);
210
211         // then add ow_jonas_bootstrap.jar to classloader
212
String JavaDoc bootJar = jonasRoot + File.separator + "lib" + File.separator + "common" + File.separator
213                 + "ow_jonas_bootstrap.jar";
214         classpath.append(new Path(getProject(), bootJar));
215
216         // Add tools.jar
217
String JavaDoc toolsJar = System.getProperty("java.home") + File.separator + ".." + File.separator + "lib"
218                 + File.separator + "tools.jar";
219         classpath.append(new Path(getProject(), toolsJar));
220
221         // Set the classpath
222
bootstrapTask.setClasspath(classpath);
223
224         // class to use = bootstrap class
225
bootstrapTask.setClassname(BOOTSTRAP_CLASS);
226
227         // add user defined jvmopts
228
if (jvmOpts != null && !jvmOpts.equals("")) {
229             bootstrapTask.createJvmarg().setLine(jvmOpts);
230         }
231
232         // add jonas name
233
if (serverName != null) {
234             bootstrapTask.createArg().setValue("-n");
235             bootstrapTask.createArg().setValue(getServerName());
236         }
237
238         return bootstrapTask;
239
240     }
241
242     /**
243      * @return the taskName.
244      */

245     public String JavaDoc getTaskName() {
246         return taskName;
247     }
248
249     /**
250      * Set the name of the task
251      * @param taskName Name of the task
252      */

253     public void setTaskName(String JavaDoc taskName) {
254         this.taskName = taskName;
255     }
256
257     /**
258      * @return the server Name.
259      */

260     public String JavaDoc getServerName() {
261         return serverName;
262     }
263
264     /**
265      * Set the name of the server
266      * @param serverName The serverName to set.
267      */

268     public void setServerName(String JavaDoc serverName) {
269         this.serverName = serverName;
270     }
271
272     /**
273      * @return the catalinaHome.
274      */

275     public String JavaDoc getCatalinaHome() {
276         return catalinaHome;
277     }
278
279     /**
280      * Set catalina Home
281      * @param catalinaHome The catalinaHome to set.
282      */

283     public void setCatalinaHome(String JavaDoc catalinaHome) {
284         this.catalinaHome = catalinaHome;
285     }
286
287     /**
288      * @return the jettyHome.
289      */

290     public String JavaDoc getJettyHome() {
291         return jettyHome;
292     }
293
294     /**
295      * Set jetty home path
296      * @param jettyHome The jettyHome to set.
297      */

298     public void setJettyHome(String JavaDoc jettyHome) {
299         this.jettyHome = jettyHome;
300     }
301     /**
302      * @return the jonasRoot.
303      */

304     public File JavaDoc getJonasRoot() {
305         return jonasRoot;
306     }
307
308 }
Popular Tags