KickJava   Java API By Example, From Geeks To Geeks.

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


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 home and component implementation 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 servants are
44  ** generated. The declaration must be a module or a component.</td>
45  ** <td>Yes</td>
46  ** </tr>
47  ** <tr>
48  ** <td>generateto</td>
49  ** <td>Directory of the generated implementations.</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 CIDLJImplTask
76 extends org.apache.tools.ant.Task
77 {
78     // params
79
private String JavaDoc _scope;
80     private java.io.File JavaDoc _generateto;
81     private java.io.File JavaDoc _cfgdir;
82
83     // default constructor
84
public
85     CIDLJImplTask()
86     {
87         // params
88
_scope = null;
89         _generateto = null;
90         _cfgdir = null;
91     }
92
93     //
94
// internal operations
95
//
96

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

201     final public void
202     setGenerateto(java.io.File JavaDoc dir)
203     {
204         _generateto = dir;
205     }
206
207     final public void
208     setScope(String JavaDoc scope)
209     {
210         _scope = scope;
211     }
212
213     final public void
214     setCfgdir(java.io.File JavaDoc cfgdir)
215     {
216         _cfgdir = cfgdir;
217     }
218
219     //
220
// org.apache.tools.ant.Task
221
//
222

223     final public void
224     execute()
225     throws org.apache.tools.ant.BuildException
226     {
227         validate();
228
229         // NOTE: should check if generation is needed
230
cidltojimpl(_cfgdir, _scope, _generateto);
231     }
232 }
233
Popular Tags