KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > task > OpenCCMTask


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2005 INRIA - USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Christophe Demarey.
23 Contributor(s): Philippe Merle.
24
25 ====================================================================
26 $Id: OpenCCMTask.java,v 1.4 2005/06/07 15:58:08 merle Exp $
27 ====================================================================*/

28
29 package org.objectweb.openccm.task;
30
31 //Package dependencies
32
import java.io.File JavaDoc;
33 import java.util.ArrayList JavaDoc;
34 import java.util.Iterator JavaDoc;
35 import java.util.List JavaDoc;
36 import org.apache.tools.ant.BuildException;
37 import org.apache.tools.ant.Task;
38 import org.apache.tools.ant.taskdefs.Delete;
39
40 /**
41  * This task run an OpenCCM application build process.
42  *
43  * @author <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</a>
44  *
45  * @version 0.1
46  */

47 public class OpenCCMTask
48      extends Task
49 {
50     // ==================================================================
51
//
52
// Internal states.
53
//
54
// ==================================================================
55

56     /** Ordered list of Runnable elements. */
57     protected List JavaDoc runnable_elements_;
58
59     /** The OpenCCM Interface Repository. */
60     protected IR3Start ir3_start_;
61
62     /** To disable OMG IDL2.x mappings. */
63     private boolean no_mappings_;
64
65     /** OpenCCM status before running the task */
66     private boolean ccm_installed;
67
68     // ==================================================================
69
//
70
// Constructors.
71
//
72
// ==================================================================
73

74     /**
75      * The default constructor.
76      */

77     public
78     OpenCCMTask()
79     {
80         // Init internal states
81
runnable_elements_ = new ArrayList JavaDoc();
82         ir3_start_ = null;
83         ccm_installed = false;
84     }
85
86     // ==================================================================
87
//
88
// Internal methods.
89
//
90
// ==================================================================
91

92     
93     /**
94      * Create a directory.
95      *
96      * @param dir - The full directory name.
97      */

98     private void
99     create_directory(String JavaDoc dir)
100     {
101         new File JavaDoc(dir).mkdir();
102     }
103     
104     /**
105      * Install the OpenCCM platform.
106      */

107     private void
108     ccm_install(String JavaDoc config_dir)
109     {
110         if ( new File JavaDoc(config_dir).exists() )
111         {
112             ccm_installed = true ;
113             System.out.println("An OpenCCM Platform has been found in "+config_dir+", we'll use it for code generation purpose.");
114         }
115         else
116         {
117             System.out.println("An OpenCCM Platform will be temporary installed in "+config_dir+" for code generation purpose.");
118
119             System.out.println("Creating the " + config_dir + " directory.");
120             create_directory(config_dir);
121
122             System.out.println("OpenCCM Platform is installed.");
123         }
124     }
125
126     /**
127      * Deinstall the OpenCCM platform.
128      */

129     private void
130     ccm_deinstall(String JavaDoc config_dir)
131     {
132         // de-install the platform if it wasn't running
133
if ( !ccm_installed )
134         {
135             Delete delete_task = new Delete();
136
137             delete_task.setProject( getProject() );
138             delete_task.setTaskName("ccm_deinstall");
139             delete_task.setDir(new File JavaDoc(config_dir));
140             delete_task.execute();
141         }
142     }
143     
144     /**
145      * Run the Interface Repository.
146      */

147     private void
148     ir3_start(String JavaDoc config_dir)
149     {
150         if ( new File JavaDoc(
151             getProject().getProperty("OpenCCM_CONFIG_DIR")
152             +System.getProperty("file.separator")
153             +"IR3.IOR")
154             .exists() )
155         {
156             System.out.println("An Interface Repository has been found, we'll use it for code generation purpose.");
157         }
158         else
159         {
160             System.out.println("An Interface Repository will be temporary started for code generation purpose.");
161
162             // Run the IR
163
ir3_start_ = new IR3Start( getProject().getProperties() );
164             ir3_start_.setNo_mappings(no_mappings_);
165             ir3_start_.run(true);
166
167             System.out.println("Interface Repository is started.");
168         }
169     }
170
171     /**
172      * Stop the Interface Repository.
173      */

174     private void
175     ir3_stop()
176     {
177         // stop the IR if it wasn't running
178
if( ir3_start_ != null )
179         {
180             // Stop the IR
181
ir3_start_.stop();
182         }
183     }
184
185     /**
186      * Run subtasks elements.
187      *
188      * @throws BuildException if an error occurs.
189      */

190     private void
191     run_elements()
192     throws BuildException
193     {
194         for (Iterator JavaDoc it = runnable_elements_.iterator(); it.hasNext();)
195         {
196             ((Runnable JavaDoc) it.next()).run();
197         }
198     }
199     
200     /**
201      * Run OpenCCM build process.
202      *
203      * @throws BuildException if an error occurs.
204      */

205     private void
206     run_openccm_build()
207     throws BuildException
208     {
209         IR3Feed ir3_feed = null;
210         String JavaDoc idl_dir = null;
211         
212         ir3_start( getProject().getProperty("OpenCCM_CONFIG_DIR") );
213         
214         // Get the OpenCCM idl dir
215
idl_dir = getProject().getProperty("OpenCCM_idl_dir");
216         
217         // Run user commands
218
run_elements();
219
220     }
221     
222     // ==================================================================
223
//
224
// Public methods.
225
//
226
// ==================================================================
227

228     /**
229      * To disable OMG IDL2.x mappings.
230      *
231      * @param b - If true, disables OMG IDL2.x mappings.
232      */

233     public void
234     setNo_mappings(boolean b)
235     {
236         this.no_mappings_ = b;
237     }
238
239     /**
240      * The method executing the task.
241      *
242      * @throws BuildException if an error occurs.
243      */

244     public void
245     execute()
246     throws BuildException
247     {
248         // Install the OpenCCM platform
249
ccm_install( getProject().getProperty("OpenCCM_CONFIG_DIR") );
250
251         try
252         {
253             run_openccm_build();
254         }catch (BuildException e){
255             //Stop the IR and deinstall the platform
256
ir3_stop();
257             ccm_deinstall( getProject().getProperty("OpenCCM_CONFIG_DIR") );
258             throw new BuildException("OpenCCM build failed!");
259         }
260
261         // Stop the IR.
262
ir3_stop();
263
264         // Deinstall the OpenCCM platform
265
ccm_deinstall( getProject().getProperty("OpenCCM_CONFIG_DIR") );
266     }
267     
268     /**
269      * Create an inner element for ir3_feed.
270      */

271     public IR3Feed
272     createIr3_feed()
273     {
274         IR3Feed ir3_feed = null;
275         
276         ir3_feed = new IR3Feed( getProject().getProperties() );
277         // Add to ordered list
278
runnable_elements_.add(ir3_feed);
279                 
280         return ir3_feed;
281     }
282     
283     /**
284      * Create an inner element for ir3_idl3.
285      */

286     public IR3toIDL3
287     createIr3_idl3()
288     {
289         IR3toIDL3 ir3_idl3 = null;
290         
291         ir3_idl3 = new IR3toIDL3( getProject().getProperties() );
292         // Add to ordered list
293
runnable_elements_.add(ir3_idl3);
294                 
295         return ir3_idl3;
296     }
297
298     /**
299      * Create an inner element for ir3_idl2.
300      */

301     public IR3toIDL2
302     createIr3_idl2()
303     {
304         IR3toIDL2 ir3_idl2 = null;
305         
306         ir3_idl2 = new IR3toIDL2( getProject().getProperties() );
307         // Add to ordered list
308
runnable_elements_.add(ir3_idl2);
309                 
310         return ir3_idl2;
311     }
312
313     /**
314      * Create an inner element for psdl_java.
315      */

316     public PSDLtoPSDL
317     createPsdl()
318     {
319         PSDLtoPSDL psdl_psdl = null;
320         
321         psdl_psdl = new PSDLtoPSDL( getProject().getProperties() );
322         // Add to ordered list
323
runnable_elements_.add(psdl_psdl);
324                 
325         return psdl_psdl;
326     }
327
328     /**
329      * Create an inner element for psdl_java.
330      */

331     public CIDLtoCIDL
332     createCidl()
333     {
334         CIDLtoCIDL cidl_cidl = null;
335         
336         cidl_cidl = new CIDLtoCIDL( getProject().getProperties() );
337         // Add to ordered list
338
runnable_elements_.add(cidl_cidl);
339                 
340         return cidl_cidl;
341     }
342
343     /**
344      * Create an inner element for psdl_java.
345      */

346     public PsdlToJava
347     createPsdl_java()
348     {
349         PsdlToJava psdl_java = null;
350         
351         psdl_java = new PsdlToJava( getProject().getProperties() );
352         // Add to ordered list
353
runnable_elements_.add(psdl_java);
354                 
355         return psdl_java;
356     }
357
358     /**
359      * Create an inner element for ir3_java.
360      */

361     public IR3toJava
362     createIr3_java()
363     {
364         IR3toJava ir3_java = null;
365         
366         ir3_java = new IR3toJava( getProject().getProperties() );
367         // Add to ordered list
368
runnable_elements_.add(ir3_java);
369                 
370         return ir3_java;
371     }
372
373     /**
374      * Create an inner element for cidl_cif.
375      */

376     public CIDLtoCIF
377     createCidl_cif()
378     {
379         CIDLtoCIF cidl_cif = null;
380         
381         cidl_cif = new CIDLtoCIF( getProject().getProperties() );
382         // Add to ordered list
383
runnable_elements_.add(cidl_cif);
384                 
385         return cidl_cif;
386     }
387 }
388
Popular Tags