KickJava   Java API By Example, From Geeks To Geeks.

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


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>Starts the OpenCCM Interface Repository.</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>cfgdir</td>
43  ** <td>The directory corresponding to the OpenCCM_CONFIG_DIR environment variable and where the
44  ** IR3-related executables of OpenCCM store and lookup IORs, PIDs, etc. Can be set to a
45  ** temporary directory.</td>
46  ** <td>Yes</td>
47  ** </tr>
48  **
49  ** <tr>
50  ** <td><bold>Properties</bold></td>
51  ** <td><bold>Description</bold></td>
52  ** <td><bold>Required</bold></td>
53  ** </tr>
54  ** <tr>
55  ** <td>OpenCCM.install.bin.dir</td>
56  ** <td>Location of the OpenCCM binaries installation directory.</td>
57  ** <td>Yes</td>
58  ** </tr>
59  **/

60 public class IR3StartTask
61 extends org.apache.tools.ant.Task
62 {
63     // params
64
private java.io.File JavaDoc _cfgdir;
65
66     // default constructor
67
public
68     IR3StartTask()
69     {
70         // params
71
_cfgdir = null;
72     }
73
74     //
75
// internal operations
76
//
77

78
79     // NOTE: check required attributes, properties, environment, ...
80
private void
81     validate()
82     throws org.apache.tools.ant.BuildException
83     {
84         String JavaDoc msg = "";
85
86         // check OS family
87
if (!OSHelper.isUnix() && !OSHelper.isWindows()) {
88             msg = "target os must be of unix or windows family";
89             throw new org.apache.tools.ant.BuildException(msg);
90         }
91
92         // check cfgdir
93
if (_cfgdir==null) {
94             msg = "cfgdir attribute is missing";
95             throw new org.apache.tools.ant.BuildException(msg);
96         }
97         if ((!_cfgdir.exists()) || (!_cfgdir.isDirectory())) {
98             msg = "Configuration directory does not exist or is not a directory";
99             throw new org.apache.tools.ant.BuildException(msg);
100         }
101
102         // check "OpenCCM.install.bin.dir" property
103
String JavaDoc bindir = getProject().getProperty("OpenCCM.install.bin.dir");
104         if (bindir==null) {
105             msg = "OpenCCM.install.bin.dir property must be set";
106             throw new org.apache.tools.ant.BuildException(msg);
107         }
108     }
109
110     //
111
// attribute setter
112
//
113

114     final public void
115     setCfgdir(java.io.File JavaDoc cfgdir)
116     {
117         _cfgdir = cfgdir;
118     }
119
120     //
121
// org.apache.tools.ant.Task
122
//
123

124     final public void
125     execute()
126     throws org.apache.tools.ant.BuildException
127     {
128         validate();
129
130         // launch IR3 in a separate thread
131
IR3StartWorker worker = new IR3StartWorker(getProject(), _cfgdir);
132         worker.start();
133
134         // wait for the completion of the start process
135
java.io.File JavaDoc output = new java.io.File JavaDoc(_cfgdir.getPath(), "IR3.start");
136         while (!output.exists()) {
137             try { Thread.currentThread().sleep(50); } catch (InterruptedException JavaDoc ex) {}
138         }
139     }
140 }
141
142 //
143
//
144
//
145
class IR3StartWorker
146 extends java.lang.Thread JavaDoc
147 {
148     //
149
private org.apache.tools.ant.Project _project;
150     private java.io.File JavaDoc _cfgdir;
151
152     // default constructor
153
public
154     IR3StartWorker(org.apache.tools.ant.Project project,
155                    java.io.File JavaDoc cfgdir)
156     {
157         //
158
_project = project;
159         _cfgdir = cfgdir;
160     }
161
162
163     //
164
// java.lang.Thread
165
//
166

167     final public void
168     run()
169     {
170         try {
171             // uses exec ant task to execute the ir3_start command
172
org.apache.tools.ant.taskdefs.ExecTask cmd = null;
173             cmd = (org.apache.tools.ant.taskdefs.ExecTask)_project.createTask("exec");
174
175             // build executable name
176
String JavaDoc cmdname = null;
177             // convert OpenCCM.install.bin.dir path
178
OSHelper.pathConvert(_project, "os.OpenCCM.install.bin.dir", "OpenCCM.install.bin.dir");
179             String JavaDoc bindir = _project.getProperty("os.OpenCCM.install.bin.dir");
180             if (OSHelper.isUnix()) {
181                 cmdname = bindir+"/ir3_start";
182             }
183             else if (OSHelper.isWindows()) {
184                 cmdname = bindir+"\\ir3_start.bat";
185             }
186             else {
187                 String JavaDoc msg = "Unsupported OS";
188                 _project.log(msg, org.apache.tools.ant.Project.MSG_ERR);
189             }
190
191             cmd.setExecutable(cmdname);
192
193             // add environment variables
194
org.apache.tools.ant.types.Environment.Variable openccm_homedir = null;
195             org.apache.tools.ant.types.Environment.Variable openccm_cfgdir = null;
196
197             // convert OpenCCM.install.dir path
198
OSHelper.pathConvert(_project, "os.OpenCCM.install.dir", "OpenCCM.install.dir");
199             String JavaDoc homedir = _project.getProperty("os.OpenCCM.install.dir");
200             openccm_homedir = new org.apache.tools.ant.types.Environment.Variable();
201             openccm_homedir.setKey("OpenCCM_HOMEDIR");
202             openccm_homedir.setValue(homedir);
203             cmd.addEnv(openccm_homedir);
204
205             openccm_cfgdir = new org.apache.tools.ant.types.Environment.Variable();
206             openccm_cfgdir.setKey("OpenCCM_CONFIG_DIR");
207             openccm_cfgdir.setValue(_cfgdir.getPath());
208             cmd.addEnv(openccm_cfgdir);
209
210             // launch
211
cmd.execute();
212         } catch (Exception JavaDoc ex) {
213             String JavaDoc msg = "Exception caught: "+ex.getMessage();
214             _project.log(msg, org.apache.tools.ant.Project.MSG_ERR);
215         }
216     }
217 }
218
Popular Tags