KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 2004-2005 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  * --------------------------------------------------------------------------
22  * $Id: JOnASBaseTask.java,v 1.7 2005/06/07 08:21:27 pelletib Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.ant;
27
28 import java.io.File JavaDoc;
29 import java.util.ArrayList JavaDoc;
30 import java.util.Iterator JavaDoc;
31 import java.util.List JavaDoc;
32
33 import org.apache.tools.ant.BuildException;
34 import org.apache.tools.ant.Project;
35 import org.apache.tools.ant.Task;
36 import org.apache.tools.ant.taskdefs.Copy;
37 import org.apache.tools.ant.types.FileSet;
38
39 import org.objectweb.jonas.ant.jonasbase.BaseTaskItf;
40 import org.objectweb.jonas.ant.jonasbase.Carol;
41 import org.objectweb.jonas.ant.jonasbase.Db;
42 import org.objectweb.jonas.ant.jonasbase.Dbm;
43 import org.objectweb.jonas.ant.jonasbase.Discovery;
44 import org.objectweb.jonas.ant.jonasbase.JdbcRa;
45 import org.objectweb.jonas.ant.jonasbase.Jms;
46 import org.objectweb.jonas.ant.jonasbase.Lib;
47 import org.objectweb.jonas.ant.jonasbase.Mail;
48 import org.objectweb.jonas.ant.jonasbase.Services;
49 import org.objectweb.jonas.ant.jonasbase.Tasks;
50 import org.objectweb.jonas.ant.jonasbase.WebContainer;
51 import org.objectweb.jonas.ant.jonasbase.wsdl.WsdlPublish;
52
53 /**
54  * Class used to create a JOnAS base with different configuration like port, url
55  * for JNDI, etc
56  * @author Florent Benoit
57  */

58 public class JOnASBaseTask extends Task {
59
60     /**
61      * Name of JOnAS configuration file
62      */

63     public static final String JavaDoc JONAS_CONF_FILE = "jonas.properties";
64
65     /**
66      * Name of Joram configuration file
67      */

68     public static final String JavaDoc JORAM_CONF_FILE = "a3servers.xml";
69
70     /**
71      * Name of Joram admin configuration file (resource adaptor)
72      */

73     public static final String JavaDoc JORAM_ADMIN_CONF_FILE = "joram-admin.cfg";
74
75     /**
76      * Name of Carol configuration file
77      */

78     public static final String JavaDoc CAROL_CONF_FILE = "carol.properties";
79
80     /**
81      * Name of Tomcat configuration file
82      */

83     public static final String JavaDoc TOMCAT_CONF_FILE = "server.xml";
84
85     /**
86      * Name of Tomcat configuration file
87      */

88     public static final String JavaDoc JETTY_CONF_FILE = "jetty5.xml";
89
90     /**
91      * Name of P6Spy configuration file
92      */

93     public static final String JavaDoc P6SPY_CONF_FILE = "spy.properties";
94
95     /**
96      * List of Wars to copy for each JONAS_BASE
97      */

98     public static final String JavaDoc[] WARS_LIST = new String JavaDoc[] {"juddi.war", "autoload/jonasAdmin.war"};
99
100     /**
101      * List of Rars to copy for each JONAS_BASE
102      */

103     public static final String JavaDoc[] RARS_LIST = new String JavaDoc[] {"autoload/JOnAS_jdbcCP.rar", "autoload/JOnAS_jdbcDM.rar", "autoload/JOnAS_jdbcDS.rar", "autoload/JOnAS_jdbcXA.rar", "autoload/joram_for_jonas_ra.rar"};
104
105     /**
106      * List of EjbJars to copy for each JONAS_BASE
107      */

108     public static final String JavaDoc[] EJBJARS_LIST = new String JavaDoc[] {""};
109
110     /**
111      * List of Apps to copy for each JONAS_BASE
112      */

113     public static final String JavaDoc[] APPS_LIST = new String JavaDoc[] {"autoload/mejb.ear"};
114
115
116     /**
117      * Source directory (JOnAS root)
118      */

119     private File JavaDoc jonasRoot = null;
120
121     /**
122      * Destination directory (Where create the jonasBase)
123      */

124     private File JavaDoc destDir = null;
125
126     /**
127      * Update only JONAS_BASE without erasing it
128      */

129     private boolean onlyUpdate = false;
130
131     /**
132      * List of tasks to do
133      */

134     private List JavaDoc tasks = null;
135
136     /**
137      * Constructor
138      */

139     public JOnASBaseTask() {
140         tasks = new ArrayList JavaDoc();
141     }
142
143     /**
144      * Run this task
145      * @see org.apache.tools.ant.Task#execute()
146      */

147     public void execute() {
148         if (jonasRoot == null) {
149             throw new BuildException("jonasRoot element is not set");
150         }
151
152         if (destDir == null) {
153             throw new BuildException("destDir element is not set");
154         }
155
156         if (jonasRoot.getPath().equals(destDir.getPath())) {
157             throw new BuildException("jonasRoot and destDir is the same path !");
158         }
159
160         File JavaDoc jprops = new File JavaDoc(destDir.getPath() + File.separator + "conf" + File.separator + "jonas.properties");
161
162         if (onlyUpdate) {
163             if (jprops.exists()) {
164                 log("Only updating JONAS_BASE in the directory '" + destDir + "' from source directory '" + jonasRoot + "'",
165                     Project.MSG_INFO);
166                 JOnASAntTool.updateJonasBase(this, jonasRoot, destDir);
167                 return;
168             } else {
169                 throw new BuildException("JOnAS base directory '" + destDir.getPath() + "' doesn't exists. Cannot update.");
170             }
171         }
172
173         // First, create JOnAS base
174
log("Creating JONAS_BASE in the directory '" + destDir + "' from source directory '" + jonasRoot + "'",
175                 Project.MSG_INFO);
176         Copy copy = new Copy();
177         JOnASAntTool.configure(this, copy);
178         copy.setTodir(destDir);
179         FileSet fileSet = new FileSet();
180         fileSet.setDir(new File JavaDoc(new File JavaDoc(jonasRoot, "templates"), "conf"));
181         copy.addFileset(fileSet);
182         copy.setOverwrite(true);
183         copy.execute();
184
185         for (Iterator JavaDoc it = tasks.iterator(); it.hasNext();) {
186             BaseTaskItf task = (BaseTaskItf) it.next();
187             task.setDestDir(destDir);
188             task.setJonasRoot(jonasRoot);
189             JOnASAntTool.configure(this, (Task) task);
190             String JavaDoc info = task.getLogInfo();
191             if (info != null) {
192                 log(info, Project.MSG_INFO);
193             }
194             task.execute();
195         }
196
197         // Then update JonasBase
198
JOnASAntTool.updateJonasBase(this, jonasRoot, destDir);
199     }
200
201     /**
202      * Add tasks for configured object
203      * @param subTasks some tasks to do on files
204      */

205     public void addTasks(Tasks subTasks) {
206         if (subTasks != null) {
207             for (Iterator JavaDoc it = subTasks.getTasks().iterator(); it.hasNext();) {
208                 tasks.add(it.next());
209             }
210         }
211     }
212
213     /**
214      * Add a task for configure some objects
215      * @param task the task to do
216      */

217     public void addTask(BaseTaskItf task) {
218         if (task != null) {
219             tasks.add(task);
220         }
221     }
222
223     /**
224      * Add tasks for services (wrapped to default method)
225      * @param servicesTasks tasks to do on files
226      */

227     public void addConfiguredServices(Services servicesTasks) {
228         addTask(servicesTasks);
229     }
230
231     /**
232      * Add tasks for JMS configuration
233      * @param jmsTasks tasks to do on files
234      */

235     public void addConfiguredJms(Jms jmsTasks) {
236         addTasks(jmsTasks);
237     }
238
239     /**
240      * Add task for Resource adaptor
241      * @param jdbcRaTask task to do
242      */

243     public void addConfiguredJdbcRa(JdbcRa jdbcRaTask) {
244         addTask(jdbcRaTask);
245     }
246
247     /**
248      * Add task for Resource adaptor
249      * @param mailTask task to do
250      */

251     public void addConfiguredMail(Mail mailTask) {
252         addTask(mailTask);
253     }
254
255     /**
256      * Add task for the DB service
257      * @param dbTask task to do
258      */

259     public void addConfiguredDb(Db dbTask) {
260         addTask(dbTask);
261     }
262
263     /**
264      * Add task for the DBM service
265      * @param dbTask task to do
266      */

267     public void addConfiguredDbm(Dbm dbTask) {
268         addTask(dbTask);
269     }
270     /**
271      * Add task for library to put in JONAS_BASE/lib/ext
272      * @param libTask task to do
273      */

274     public void addConfiguredLib(Lib libTask) {
275         addTask(libTask);
276     }
277
278     /**
279      * Add task for WSDL
280      * @param wsdlTask task to do
281      */

282     public void addConfiguredWsdlPublish(WsdlPublish wsdlTask) {
283         addTask(wsdlTask);
284     }
285
286     /**
287      * Add tasks for Carol configuration
288      * @param carolTasks tasks to do on files
289      */

290     public void addConfiguredCarol(Carol carolTasks) {
291         addTasks(carolTasks);
292     }
293
294     /**
295      * Add tasks for Discovery configuration
296      * @param discoveryTasks tasks to do on files
297      */

298     public void addConfiguredDiscovery(Discovery discoveryTasks) {
299         addTasks(discoveryTasks);
300     }
301
302     /**
303      * Add tasks for the web container configuration
304      * @param webContainerTasks tasks to do on files
305      */

306     public void addConfiguredWebContainer(WebContainer webContainerTasks) {
307         addTasks(webContainerTasks);
308     }
309
310     /**
311      * Set the destination directory for the replacement
312      * @param destDir the destination directory
313      */

314     public void setDestDir(File JavaDoc destDir) {
315         this.destDir = destDir;
316     }
317
318     /**
319      * Set the source directory for the replacement
320      * @param jonasRoot the source directory
321      */

322     public void setJonasRoot(File JavaDoc jonasRoot) {
323         this.jonasRoot = jonasRoot;
324     }
325
326     /**
327      * Set if this is only an update or a new JONAS_BASE
328      * @param onlyUpdate If true update, else create and then update
329      */

330     public void setUpdate(boolean onlyUpdate) {
331         this.onlyUpdate = onlyUpdate;
332     }
333
334 }
Popular Tags