1
|
|
/*
|
2
|
|
* The Apache Software License, Version 1.1
|
3
|
|
*
|
4
|
|
* Copyright (c) 2001-2002 The Apache Software Foundation. All rights
|
5
|
|
* reserved.
|
6
|
|
*
|
7
|
|
* Redistribution and use in source and binary forms, with or without
|
8
|
|
* modification, are permitted provided that the following conditions
|
9
|
|
* are met:
|
10
|
|
*
|
11
|
|
* 1. Redistributions of source code must retain the above copyright
|
12
|
|
* notice, this list of conditions and the following disclaimer.
|
13
|
|
*
|
14
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
15
|
|
* notice, this list of conditions and the following disclaimer in
|
16
|
|
* the documentation and/or other materials provided with the
|
17
|
|
* distribution.
|
18
|
|
*
|
19
|
|
* 3. The end-user documentation included with the redistribution, if
|
20
|
|
* any, must include the following acknowlegement:
|
21
|
|
* "This product includes software developed by the
|
22
|
|
* Apache Software Foundation (http://www.apache.org/)."
|
23
|
|
* Alternately, this acknowlegement may appear in the software itself,
|
24
|
|
* if and wherever such third-party acknowlegements normally appear.
|
25
|
|
*
|
26
|
|
* 4. The names "Ant" and "Apache Software
|
27
|
|
* Foundation" must not be used to endorse or promote products derived
|
28
|
|
* from this software without prior written permission. For written
|
29
|
|
* permission, please contact apache@apache.org.
|
30
|
|
*
|
31
|
|
* 5. Products derived from this software may not be called "Apache"
|
32
|
|
* nor may "Apache" appear in their names without prior written
|
33
|
|
* permission of the Apache Group.
|
34
|
|
*
|
35
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
36
|
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
37
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
38
|
|
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
39
|
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
40
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
41
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
42
|
|
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
43
|
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
44
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
45
|
|
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
46
|
|
* SUCH DAMAGE.
|
47
|
|
* ====================================================================
|
48
|
|
*
|
49
|
|
* This software consists of voluntary contributions made by many
|
50
|
|
* individuals on behalf of the Apache Software Foundation. For more
|
51
|
|
* information on the Apache Software Foundation, please see
|
52
|
|
* <http://www.apache.org/>.
|
53
|
|
*/
|
54
|
|
|
55
|
|
|
56
|
|
package org.apache.tools.ant.taskdefs.optional.ejb;
|
57
|
|
|
58
|
|
import java.io.File;
|
59
|
|
import org.apache.tools.ant.BuildException;
|
60
|
|
import org.apache.tools.ant.Project;
|
61
|
|
import org.apache.tools.ant.Task;
|
62
|
|
import org.apache.tools.ant.taskdefs.ExecTask;
|
63
|
|
import org.apache.tools.ant.taskdefs.Java;
|
64
|
|
import org.apache.tools.ant.types.Path;
|
65
|
|
import org.apache.tools.ant.types.Reference;
|
66
|
|
|
67
|
|
/**
|
68
|
|
* Generates a Borland Application Server 4.5 client JAR using as
|
69
|
|
* input the EJB JAR file.
|
70
|
|
*
|
71
|
|
* Two mode are available: java mode (default) and fork mode. With the fork mode,
|
72
|
|
* it is impossible to add classpath to the commmand line.
|
73
|
|
*
|
74
|
|
* @author <a href="mailto:benoit.moussaud@criltelecom.com">Benoit Moussaud</a>
|
75
|
|
*
|
76
|
|
* @ant.task name="blgenclient" category="ejb"
|
77
|
|
*/
|
78
|
|
public class BorlandGenerateClient extends Task {
|
79
|
|
static final String JAVA_MODE = "java";
|
80
|
|
static final String FORK_MODE = "fork";
|
81
|
|
|
82
|
|
/** debug the generateclient task */
|
83
|
|
boolean debug = false;
|
84
|
|
|
85
|
|
/** hold the ejbjar file name */
|
86
|
|
File ejbjarfile = null;
|
87
|
|
|
88
|
|
/** hold the client jar file name */
|
89
|
|
File clientjarfile = null;
|
90
|
|
|
91
|
|
/** hold the classpath */
|
92
|
|
Path classpath;
|
93
|
|
|
94
|
|
/** hold the mode (java|fork) */
|
95
|
|
String mode = FORK_MODE;
|
96
|
|
|
97
|
|
/** hold the version */
|
98
|
|
int version = BorlandDeploymentTool.BAS;
|
99
|
|
|
100
|
0
|
public void setVersion(int version) {
|
101
|
0
|
this.version = version;
|
102
|
|
}
|
103
|
|
|
104
|
|
/**
|
105
|
|
* Command launching mode: java or fork.
|
106
|
|
*/
|
107
|
0
|
public void setMode(String s) {
|
108
|
0
|
mode = s;
|
109
|
|
}
|
110
|
|
|
111
|
|
/**
|
112
|
|
* If true, turn on the debug mode for each of the Borland tools launched.
|
113
|
|
*/
|
114
|
0
|
public void setDebug(boolean debug) {
|
115
|
0
|
this.debug = debug;
|
116
|
|
}
|
117
|
|
|
118
|
|
/**
|
119
|
|
* EJB JAR file.
|
120
|
|
*/
|
121
|
0
|
public void setEjbjar(File ejbfile) {
|
122
|
0
|
ejbjarfile = ejbfile;
|
123
|
|
}
|
124
|
|
|
125
|
|
/**
|
126
|
|
* Client JAR file name.
|
127
|
|
*/
|
128
|
0
|
public void setClientjar(File clientjar) {
|
129
|
0
|
clientjarfile = clientjar;
|
130
|
|
}
|
131
|
|
|
132
|
|
/**
|
133
|
|
* Path to use for classpath.
|
134
|
|
*/
|
135
|
0
|
public void setClasspath(Path classpath) {
|
136
|
0
|
if (this.classpath == null) {
|
137
|
0
|
this.classpath = classpath;
|
138
|
|
} else {
|
139
|
0
|
this.classpath.append(classpath);
|
140
|
|
}
|
141
|
|
}
|
142
|
|
|
143
|
|
/**
|
144
|
|
* Adds path to the classpath.
|
145
|
|
*/
|
146
|
0
|
public Path createClasspath() {
|
147
|
0
|
if (this.classpath == null) {
|
148
|
0
|
this.classpath = new Path(getProject());
|
149
|
|
}
|
150
|
0
|
return this.classpath.createPath();
|
151
|
|
}
|
152
|
|
|
153
|
|
/**
|
154
|
|
* Reference to existing path, to use as a classpath.
|
155
|
|
*/
|
156
|
0
|
public void setClasspathRef(Reference r) {
|
157
|
0
|
createClasspath().setRefid(r);
|
158
|
|
}
|
159
|
|
|
160
|
|
|
161
|
|
/**
|
162
|
|
* Do the work.
|
163
|
|
*
|
164
|
|
* The work is actually done by creating a separate JVM to run a java task.
|
165
|
|
*
|
166
|
|
* @exception BuildException if someting goes wrong with the build
|
167
|
|
*/
|
168
|
0
|
public void execute() throws BuildException {
|
169
|
0
|
if (ejbjarfile == null || ejbjarfile.isDirectory()) {
|
170
|
0
|
throw new BuildException("invalid ejb jar file.");
|
171
|
|
}
|
172
|
|
|
173
|
0
|
if (clientjarfile == null || clientjarfile.isDirectory()) {
|
174
|
0
|
log("invalid or missing client jar file.", Project.MSG_VERBOSE);
|
175
|
0
|
String ejbjarname = ejbjarfile.getAbsolutePath();
|
176
|
|
//clientname = ejbjarfile+client.jar
|
177
|
0
|
String clientname = ejbjarname.substring(0, ejbjarname.lastIndexOf("."));
|
178
|
0
|
clientname = clientname + "client.jar";
|
179
|
0
|
clientjarfile = new File(clientname);
|
180
|
|
}
|
181
|
|
|
182
|
0
|
if (mode == null) {
|
183
|
0
|
log("mode is null default mode is java");
|
184
|
0
|
setMode(JAVA_MODE);
|
185
|
|
}
|
186
|
|
|
187
|
0
|
if ( !(version == BorlandDeploymentTool.BES || version == BorlandDeploymentTool.BAS)) {
|
188
|
0
|
throw new BuildException("version "+version+" is not supported");
|
189
|
|
}
|
190
|
|
|
191
|
0
|
log("client jar file is " + clientjarfile);
|
192
|
|
|
193
|
0
|
if (mode.equalsIgnoreCase(FORK_MODE)) {
|
194
|
0
|
executeFork();
|
195
|
|
} else {
|
196
|
0
|
executeJava();
|
197
|
|
} // end of else
|
198
|
|
}
|
199
|
|
|
200
|
|
/** launch the generate client using java api */
|
201
|
0
|
protected void executeJava() throws BuildException {
|
202
|
0
|
try {
|
203
|
0
|
if ( version == BorlandDeploymentTool.BES) {
|
204
|
0
|
throw new BuildException("java mode is supported only for previous version <="+BorlandDeploymentTool.BAS);
|
205
|
|
}
|
206
|
|
|
207
|
0
|
log("mode : java");
|
208
|
|
|
209
|
0
|
org.apache.tools.ant.taskdefs.Java execTask = null;
|
210
|
0
|
execTask = (Java) getProject().createTask("java");
|
211
|
|
|
212
|
0
|
execTask.setDir(new File("."));
|
213
|
0
|
execTask.setClassname("com.inprise.server.commandline.EJBUtilities");
|
214
|
|
//classpath
|
215
|
|
//add at the end of the classpath
|
216
|
|
//the system classpath in order to find the tools.jar file
|
217
|
0
|
execTask.setClasspath(classpath.concatSystemClasspath());
|
218
|
|
|
219
|
0
|
execTask.setFork(true);
|
220
|
0
|
execTask.createArg().setValue("generateclient");
|
221
|
0
|
if (debug) {
|
222
|
0
|
execTask.createArg().setValue("-trace");
|
223
|
|
}
|
224
|
|
|
225
|
0
|
execTask.createArg().setValue("-short");
|
226
|
0
|
execTask.createArg().setValue("-jarfile");
|
227
|
|
// ejb jar file
|
228
|
0
|
execTask.createArg().setValue(ejbjarfile.getAbsolutePath());
|
229
|
|
//client jar file
|
230
|
0
|
execTask.createArg().setValue("-single");
|
231
|
0
|
execTask.createArg().setValue("-clientjarfile");
|
232
|
0
|
execTask.createArg().setValue(clientjarfile.getAbsolutePath());
|
233
|
|
|
234
|
0
|
log("Calling EJBUtilities", Project.MSG_VERBOSE);
|
235
|
0
|
execTask.execute();
|
236
|
|
|
237
|
|
} catch (Exception e) {
|
238
|
|
// Have to catch this because of the semantics of calling main()
|
239
|
0
|
String msg = "Exception while calling generateclient Details: " + e.toString();
|
240
|
0
|
throw new BuildException(msg, e);
|
241
|
|
}
|
242
|
|
}
|
243
|
|
|
244
|
|
/** launch the generate client using system api */
|
245
|
0
|
protected void executeFork() throws BuildException {
|
246
|
0
|
if ( version == BorlandDeploymentTool.BAS) {
|
247
|
0
|
executeForkV4();
|
248
|
|
}
|
249
|
0
|
if ( version == BorlandDeploymentTool.BES ) {
|
250
|
0
|
executeForkV5();
|
251
|
|
}
|
252
|
|
}
|
253
|
|
|
254
|
|
/** launch the generate client using system api */
|
255
|
0
|
protected void executeForkV4() throws BuildException {
|
256
|
0
|
try {
|
257
|
|
|
258
|
0
|
log("mode : fork "+BorlandDeploymentTool.BAS,Project.MSG_DEBUG);
|
259
|
|
|
260
|
0
|
org.apache.tools.ant.taskdefs.ExecTask execTask = null;
|
261
|
0
|
execTask = (ExecTask) getProject().createTask("exec");
|
262
|
|
|
263
|
0
|
execTask.setDir(new File("."));
|
264
|
0
|
execTask.setExecutable("iastool");
|
265
|
0
|
execTask.createArg().setValue("generateclient");
|
266
|
0
|
if (debug) {
|
267
|
0
|
execTask.createArg().setValue("-trace");
|
268
|
|
}
|
269
|
|
|
270
|
0
|
execTask.createArg().setValue("-short");
|
271
|
0
|
execTask.createArg().setValue("-jarfile");
|
272
|
|
// ejb jar file
|
273
|
0
|
execTask.createArg().setValue(ejbjarfile.getAbsolutePath());
|
274
|
|
//client jar file
|
275
|
0
|
execTask.createArg().setValue("-single");
|
276
|
0
|
execTask.createArg().setValue("-clientjarfile");
|
277
|
0
|
execTask.createArg().setValue(clientjarfile.getAbsolutePath());
|
278
|
|
|
279
|
0
|
log("Calling iastool", Project.MSG_VERBOSE);
|
280
|
0
|
execTask.execute();
|
281
|
|
} catch (Exception e) {
|
282
|
|
// Have to catch this because of the semantics of calling main()
|
283
|
0
|
String msg = "Exception while calling generateclient Details: "
|
284
|
|
+ e.toString();
|
285
|
0
|
throw new BuildException(msg, e);
|
286
|
|
}
|
287
|
|
|
288
|
|
}
|
289
|
|
/** launch the generate client using system api */
|
290
|
0
|
protected void executeForkV5() throws BuildException {
|
291
|
0
|
try {
|
292
|
0
|
log("mode : fork "+BorlandDeploymentTool.BES,Project.MSG_DEBUG);
|
293
|
0
|
org.apache.tools.ant.taskdefs.ExecTask execTask = null;
|
294
|
0
|
execTask = (ExecTask) getProject().createTask("exec");
|
295
|
|
|
296
|
0
|
execTask.setDir(new File("."));
|
297
|
|
|
298
|
0
|
execTask.setExecutable("iastool");
|
299
|
0
|
if (debug) {
|
300
|
0
|
execTask.createArg().setValue("-debug");
|
301
|
|
}
|
302
|
0
|
execTask.createArg().setValue("-genclient");
|
303
|
0
|
execTask.createArg().setValue("-jars");
|
304
|
|
// ejb jar file
|
305
|
0
|
execTask.createArg().setValue(ejbjarfile.getAbsolutePath());
|
306
|
|
//client jar file
|
307
|
0
|
execTask.createArg().setValue("-target");
|
308
|
0
|
execTask.createArg().setValue(clientjarfile.getAbsolutePath());
|
309
|
|
//classpath
|
310
|
0
|
execTask.createArg().setValue("-cp");
|
311
|
0
|
execTask.createArg().setValue(classpath.toString());
|
312
|
0
|
log("Calling iastool", Project.MSG_VERBOSE);
|
313
|
0
|
execTask.execute();
|
314
|
|
} catch (Exception e) {
|
315
|
|
// Have to catch this because of the semantics of calling main()
|
316
|
0
|
String msg = "Exception while calling generateclient Details: "
|
317
|
|
+ e.toString();
|
318
|
0
|
throw new BuildException(msg, e);
|
319
|
|
}
|
320
|
|
|
321
|
|
}
|
322
|
|
|
323
|
|
}
|
324
|
|
|