KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > ecm > taskdefs > IR3toIDL2Task


1 // ====================================================================
2
//
3
// ECM: The Extensible Container Model
4
// Copyright (C) 2004 THALES
5
// Contact: openccm-ecm@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): Mathieu Vadet.
23
// Initial Funding: IST COACH European project (IST-2001-34445)
24
// http://www.ist-coach.org
25
//
26
// ====================================================================
27

28
29
30 package org.objectweb.ecm.taskdefs;
31
32 /**
33  ** <p>Generates the equivalent OMG IDL2 for a OMG IDL3 declaration.</p>
34  **
35  ** <p><bold>Parameters</bold></p>
36  ** <tr>
37  ** <td><bold>Attributes</bold></td>
38  ** <td><bold>Description</bold></td>
39  ** <td><bold>Required</bold></td>
40  ** </tr>
41  ** <tr>
42  ** <td>scope</td>
43  ** <td>The scoped name of the OMG IDL3 declaration for which the equivalent OMG IDL2
44  ** is generated.</td>
45  ** <td>Yes</td>
46  ** </tr>
47  ** <tr>
48  ** <td>generateto</td>
49  ** <td>Directory of the generated OMG IDL2 files.</td>
50  ** <td>Yes</td>
51  ** </tr>
52  ** <tr>
53  ** <td>cfgdir</td>
54  ** <td>The directory corresponding to the OpenCCM_CONFIG_DIR environment variable and where the
55  ** IR3-related executables of OpenCCM store and lookup IORs, PIDs, etc. Can be set to a
56  ** temporary directory.</td>
57  ** <td>Yes</td>
58  ** </tr>
59  **
60  ** <p>NOTE: the generated OMG IDL2 files are: "name.idl" and "name_local.idl", where "name" is
61  ** built from the scoped name by replacing "::" with an underscore ('_').</p>
62  **
63  ** <tr>
64  ** <td><bold>Properties</bold></td>
65  ** <td><bold>Description</bold></td>
66  ** <td><bold>Required</bold></td>
67  ** </tr>
68  ** <tr>
69  ** <td>OpenCCM.install.bin.dir</td>
70  ** <td>Location of the OpenCCM binaries installation directory.</td>
71  ** <td>Yes</td>
72  ** </tr>
73  **
74  ** <p>NOTE: the OpenCCM IR3 must be started before calling this task.</p>
75  **
76  ** @see org.objectweb.corba.build.IR3StartTask IR3StartTask
77  **/

78 public class IR3toIDL2Task
79 extends org.apache.tools.ant.Task
80 {
81     // params
82
private String JavaDoc _scope;
83     private java.io.File JavaDoc _generateto;
84     private java.io.File JavaDoc _cfgdir;
85
86     // default constructor
87
public
88     IR3toIDL2Task()
89     {
90         // params
91
_scope = null;
92         _generateto = null;
93         _cfgdir = null;
94     }
95
96     //
97
// internal operations
98
//
99

100
101     // NOTE: check required attributes, properties, environment, ...
102
private void
103     validate()
104     throws org.apache.tools.ant.BuildException
105     {
106         String JavaDoc msg = "";
107
108         // check OS family
109
if (!OSHelper.isUnix() && !OSHelper.isWindows()) {
110             msg = "target os must be of unix or windows family";
111             throw new org.apache.tools.ant.BuildException(msg);
112         }
113
114         // check scope
115
if (_scope==null) {
116             msg = "scope attribute is missing";
117             throw new org.apache.tools.ant.BuildException(msg);
118         }
119
120         // check generateto
121
if (_generateto==null) {
122             msg = "generateto attribute is missing";
123             throw new org.apache.tools.ant.BuildException(msg);
124         }
125         if ((!_generateto.exists()) || (!_generateto.isDirectory())) {
126             msg = "Generation directory does not exist or is not a directory";
127             throw new org.apache.tools.ant.BuildException(msg);
128         }
129
130         // check cfgdir
131
if (_cfgdir==null) {
132             msg = "cfgdir attribute is missing";
133             throw new org.apache.tools.ant.BuildException(msg);
134         }
135         if ((!_cfgdir.exists()) || (!_cfgdir.isDirectory())) {
136             msg = "Configuration directory does not exist or is not a directory";
137             throw new org.apache.tools.ant.BuildException(msg);
138         }
139
140         // check "OpenCCM.install.bin.dir" property
141
String JavaDoc bindir = getProject().getProperty("OpenCCM.install.bin.dir");
142         if (bindir==null) {
143             msg = "OpenCCM.install.bin.dir property must be set";
144             throw new org.apache.tools.ant.BuildException(msg);
145         }
146     }
147
148     private void
149     ir3toidl2(java.io.File JavaDoc cfgdir,
150               String JavaDoc scope,
151               java.io.File JavaDoc gento)
152     throws org.apache.tools.ant.BuildException
153     {
154         // uses exec ant task to execute the ir3_idl2 command
155
org.apache.tools.ant.taskdefs.ExecTask cmd = null;
156         cmd = (org.apache.tools.ant.taskdefs.ExecTask)getProject().createTask("exec");
157
158         // build executable name
159
String JavaDoc cmdname = null;
160         // convert OpenCCM.install.bin.dir path
161
OSHelper.pathConvert(getProject(), "os.OpenCCM.install.bin.dir", "OpenCCM.install.bin.dir");
162         String JavaDoc bindir = getProject().getProperty("os.OpenCCM.install.bin.dir");
163         if (OSHelper.isUnix()) {
164             cmdname = bindir+"/ir3_idl2";
165         }
166         else if (OSHelper.isWindows()) {
167             cmdname = bindir+"\\ir3_idl2.bat";
168         }
169
170         cmd.setExecutable(cmdname);
171
172         // add environment variables
173
org.apache.tools.ant.types.Environment.Variable openccm_homedir = null;
174         org.apache.tools.ant.types.Environment.Variable openccm_cfgdir = null;
175
176         // convert OpenCCM.install.dir path
177
OSHelper.pathConvert(getProject(), "os.OpenCCM.install.dir", "OpenCCM.install.dir");
178         String JavaDoc homedir = getProject().getProperty("os.OpenCCM.install.dir");
179         openccm_homedir = new org.apache.tools.ant.types.Environment.Variable();
180         openccm_homedir.setKey("OpenCCM_HOMEDIR");
181         openccm_homedir.setValue(homedir);
182         cmd.addEnv(openccm_homedir);
183
184         openccm_cfgdir = new org.apache.tools.ant.types.Environment.Variable();
185         openccm_cfgdir.setKey("OpenCCM_CONFIG_DIR");
186         openccm_cfgdir.setValue(cfgdir.getPath());
187         cmd.addEnv(openccm_cfgdir);
188
189         // build IDL2 filename
190
String JavaDoc filename = scope.replaceAll("::", "_")+".idl";
191         if (filename.startsWith("_")) {
192             filename = filename.substring(1);
193         }
194
195         java.io.File JavaDoc idl2file = new java.io.File JavaDoc(gento, filename);
196
197         // add IDL2 file as an argument
198
org.apache.tools.ant.types.Commandline.Argument arg = cmd.createArg();
199         arg.setLine(" -o "+idl2file.getPath());
200
201         arg = cmd.createArg();
202         arg.setValue(scope);
203
204         // launch
205
cmd.execute();
206     }
207
208     //
209
// attribute setters
210
//
211

212     final public void
213     setGenerateto(java.io.File JavaDoc dir)
214     {
215         _generateto = dir;
216     }
217
218     final public void
219     setScope(String JavaDoc scope)
220     {
221         _scope = scope;
222     }
223
224     final public void
225     setCfgdir(java.io.File JavaDoc cfgdir)
226     {
227         _cfgdir = cfgdir;
228     }
229
230     //
231
// org.apache.tools.ant.Task
232
//
233

234     final public void
235     execute()
236     throws org.apache.tools.ant.BuildException
237     {
238         validate();
239
240         // NOTE: should check if generation is needed
241
ir3toidl2(_cfgdir, _scope, _generateto);
242     }
243 }
244
Popular Tags