KickJava   Java API By Example, From Geeks To Geeks.

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


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>Feeds the OpenCCM Interface Repository with an OMG IDL3 file.</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>idl3file</td>
43  ** <td>The OMG IDL3 file to be compiled.</td>
44  ** <td>Yes</td>
45  ** </tr>
46  ** <tr>
47  ** <td>generateto</td>
48  ** <td>Directory of the generated OMG IDL2 files.</td>
49  ** <td>No, if provided then some uptodate checks are performed.</td>
50  ** </tr>
51  ** <tr>
52  ** <td>cfgdir</td>
53  ** <td>The directory corresponding to the OpenCCM_CONFIG_DIR environment variable and where the
54  ** IR3-related executables of OpenCCM store and lookup IORs, PIDs, etc. Can be set to a
55  ** temporary directory.</td>
56  ** <td>Yes</td>
57  ** </tr>
58  **
59  ** <tr>
60  ** <td><bold>Properties</bold></td>
61  ** <td><bold>Description</bold></td>
62  ** <td><bold>Required</bold></td>
63  ** </tr>
64  ** <tr>
65  ** <td>OpenCCM.install.bin.dir</td>
66  ** <td>Location of the OpenCCM binaries installation directory.</td>
67  ** <td>Yes</td>
68  ** </tr>
69  **
70  ** <p>NOTE: the OpenCCM IR3 must be started before calling this task.</p>
71  **
72  ** @see org.objectweb.corba.build.IR3StartTask IR3StartTask
73  **/

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

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

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

236     final public void
237     execute()
238     throws org.apache.tools.ant.BuildException
239     {
240         validate();
241
242         // check if OMG IDL3 is uptodate
243
if (!idl3fileUpToDate(_idl3file, _generateto)) {
244             log("[execute] OMG IDL3 file is not uptodate");
245             ir3feed(_cfgdir, _idl3file);
246         }
247     }
248 }
249
Popular Tags