KickJava   Java API By Example, From Geeks To Geeks.

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


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 IDL mapping for an 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 IDL mapping is
44  ** generated. The declaration must be a module or a component.</td>
45  ** <td>Yes, if cidlfile attribute is not set</td>
46  ** </tr>
47  ** <tr>
48  ** <td>generateto</td>
49  ** <td>Directory of the generated IDL file.</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  ** <tr>
61  ** <td><bold>Properties</bold></td>
62  ** <td><bold>Description</bold></td>
63  ** <td><bold>Required</bold></td>
64  ** </tr>
65  ** <tr>
66  ** <td>ECM.install.dir</td>
67  ** <td>Location of the ECM installation directory.</td>
68  ** <td>Yes</td>
69  ** </tr>
70  **
71  ** <p>NOTE: the OpenCCM IR3 must be started before calling this task.</p>
72  **
73  ** @see org.objectweb.corba.build.IR3StartTask IR3StartTask
74  **/

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

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

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

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