source: release-kits/lirk3/resources/gs3-release-maker/apache-ant-1.6.5/src/main/org/apache/tools/ant/taskdefs/optional/ejb/BorlandGenerateClient.java@ 14982

Last change on this file since 14982 was 14982, checked in by oranfry, 16 years ago

initial import of LiRK3

File size: 9.5 KB
Line 
1/*
2 * Copyright 2001-2004 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18
19package org.apache.tools.ant.taskdefs.optional.ejb;
20
21import java.io.File;
22import org.apache.tools.ant.BuildException;
23import org.apache.tools.ant.Project;
24import org.apache.tools.ant.Task;
25import org.apache.tools.ant.taskdefs.ExecTask;
26import org.apache.tools.ant.taskdefs.Java;
27import org.apache.tools.ant.types.Path;
28import org.apache.tools.ant.types.Reference;
29
30/**
31 * Generates a Borland Application Server 4.5 client JAR using as
32 * input the EJB JAR file.
33 *
34 * Two mode are available: java mode (default) and fork mode. With the fork mode,
35 * it is impossible to add classpath to the command line.
36 *
37 *
38 * @ant.task name="blgenclient" category="ejb"
39 */
40public class BorlandGenerateClient extends Task {
41 static final String JAVA_MODE = "java";
42 static final String FORK_MODE = "fork";
43
44 /** debug the generateclient task */
45 boolean debug = false;
46
47 /** hold the ejbjar file name */
48 File ejbjarfile = null;
49
50 /** hold the client jar file name */
51 File clientjarfile = null;
52
53 /** hold the classpath */
54 Path classpath;
55
56 /** hold the mode (java|fork) */
57 String mode = FORK_MODE;
58
59 /** hold the version */
60 int version = BorlandDeploymentTool.BAS;
61
62 public void setVersion(int version) {
63 this.version = version;
64 }
65
66 /**
67 * Command launching mode: java or fork.
68 */
69 public void setMode(String s) {
70 mode = s;
71 }
72
73 /**
74 * If true, turn on the debug mode for each of the Borland tools launched.
75 */
76 public void setDebug(boolean debug) {
77 this.debug = debug;
78 }
79
80 /**
81 * EJB JAR file.
82 */
83 public void setEjbjar(File ejbfile) {
84 ejbjarfile = ejbfile;
85 }
86
87 /**
88 * Client JAR file name.
89 */
90 public void setClientjar(File clientjar) {
91 clientjarfile = clientjar;
92 }
93
94 /**
95 * Path to use for classpath.
96 */
97 public void setClasspath(Path classpath) {
98 if (this.classpath == null) {
99 this.classpath = classpath;
100 } else {
101 this.classpath.append(classpath);
102 }
103 }
104
105 /**
106 * Adds path to the classpath.
107 */
108 public Path createClasspath() {
109 if (this.classpath == null) {
110 this.classpath = new Path(getProject());
111 }
112 return this.classpath.createPath();
113 }
114
115 /**
116 * Reference to existing path, to use as a classpath.
117 */
118 public void setClasspathRef(Reference r) {
119 createClasspath().setRefid(r);
120 }
121
122
123 /**
124 * Do the work.
125 *
126 * The work is actually done by creating a separate JVM to run a java task.
127 *
128 * @exception BuildException if something goes wrong with the build
129 */
130 public void execute() throws BuildException {
131 if (ejbjarfile == null || ejbjarfile.isDirectory()) {
132 throw new BuildException("invalid ejb jar file.");
133 }
134
135 if (clientjarfile == null || clientjarfile.isDirectory()) {
136 log("invalid or missing client jar file.", Project.MSG_VERBOSE);
137 String ejbjarname = ejbjarfile.getAbsolutePath();
138 //clientname = ejbjarfile+client.jar
139 String clientname = ejbjarname.substring(0, ejbjarname.lastIndexOf("."));
140 clientname = clientname + "client.jar";
141 clientjarfile = new File(clientname);
142 }
143
144 if (mode == null) {
145 log("mode is null default mode is java");
146 setMode(JAVA_MODE);
147 }
148
149 if (!(version == BorlandDeploymentTool.BES
150 || version == BorlandDeploymentTool.BAS)) {
151 throw new BuildException("version " + version
152 + " is not supported");
153 }
154
155 log("client jar file is " + clientjarfile);
156
157 if (mode.equalsIgnoreCase(FORK_MODE)) {
158 executeFork();
159 } else {
160 executeJava();
161 } // end of else
162 }
163
164 /** launch the generate client using java api */
165 protected void executeJava() throws BuildException {
166 try {
167 if (version == BorlandDeploymentTool.BES) {
168 throw new BuildException("java mode is supported only for "
169 + "previous version <=" + BorlandDeploymentTool.BAS);
170 }
171
172 log("mode : java");
173
174 org.apache.tools.ant.taskdefs.Java execTask = null;
175 execTask = (Java) getProject().createTask("java");
176
177 execTask.setDir(new File("."));
178 execTask.setClassname("com.inprise.server.commandline.EJBUtilities");
179 //classpath
180 //add at the end of the classpath
181 //the system classpath in order to find the tools.jar file
182 execTask.setClasspath(classpath.concatSystemClasspath());
183
184 execTask.setFork(true);
185 execTask.createArg().setValue("generateclient");
186 if (debug) {
187 execTask.createArg().setValue("-trace");
188 }
189
190 execTask.createArg().setValue("-short");
191 execTask.createArg().setValue("-jarfile");
192 // ejb jar file
193 execTask.createArg().setValue(ejbjarfile.getAbsolutePath());
194 //client jar file
195 execTask.createArg().setValue("-single");
196 execTask.createArg().setValue("-clientjarfile");
197 execTask.createArg().setValue(clientjarfile.getAbsolutePath());
198
199 log("Calling EJBUtilities", Project.MSG_VERBOSE);
200 execTask.execute();
201
202 } catch (Exception e) {
203 // Have to catch this because of the semantics of calling main()
204 String msg = "Exception while calling generateclient Details: " + e.toString();
205 throw new BuildException(msg, e);
206 }
207 }
208
209 /** launch the generate client using system api */
210 protected void executeFork() throws BuildException {
211 if (version == BorlandDeploymentTool.BAS) {
212 executeForkV4();
213 }
214 if (version == BorlandDeploymentTool.BES) {
215 executeForkV5();
216 }
217 }
218
219 /** launch the generate client using system api */
220 protected void executeForkV4() throws BuildException {
221 try {
222
223 log("mode : fork " + BorlandDeploymentTool.BAS, Project.MSG_DEBUG);
224
225 org.apache.tools.ant.taskdefs.ExecTask execTask = null;
226 execTask = (ExecTask) getProject().createTask("exec");
227
228 execTask.setDir(new File("."));
229 execTask.setExecutable("iastool");
230 execTask.createArg().setValue("generateclient");
231 if (debug) {
232 execTask.createArg().setValue("-trace");
233 }
234
235 execTask.createArg().setValue("-short");
236 execTask.createArg().setValue("-jarfile");
237 // ejb jar file
238 execTask.createArg().setValue(ejbjarfile.getAbsolutePath());
239 //client jar file
240 execTask.createArg().setValue("-single");
241 execTask.createArg().setValue("-clientjarfile");
242 execTask.createArg().setValue(clientjarfile.getAbsolutePath());
243
244 log("Calling iastool", Project.MSG_VERBOSE);
245 execTask.execute();
246 } catch (Exception e) {
247 // Have to catch this because of the semantics of calling main()
248 String msg = "Exception while calling generateclient Details: "
249 + e.toString();
250 throw new BuildException(msg, e);
251 }
252
253 }
254 /** launch the generate client using system api */
255 protected void executeForkV5() throws BuildException {
256 try {
257 log("mode : fork " + BorlandDeploymentTool.BES, Project.MSG_DEBUG);
258 org.apache.tools.ant.taskdefs.ExecTask execTask = null;
259 execTask = (ExecTask) getProject().createTask("exec");
260
261 execTask.setDir(new File("."));
262
263 execTask.setExecutable("iastool");
264 if (debug) {
265 execTask.createArg().setValue("-debug");
266 }
267 execTask.createArg().setValue("-genclient");
268 execTask.createArg().setValue("-jars");
269 // ejb jar file
270 execTask.createArg().setValue(ejbjarfile.getAbsolutePath());
271 //client jar file
272 execTask.createArg().setValue("-target");
273 execTask.createArg().setValue(clientjarfile.getAbsolutePath());
274 //classpath
275 execTask.createArg().setValue("-cp");
276 execTask.createArg().setValue(classpath.toString());
277 log("Calling iastool", Project.MSG_VERBOSE);
278 execTask.execute();
279 } catch (Exception e) {
280 // Have to catch this because of the semantics of calling main()
281 String msg = "Exception while calling generateclient Details: "
282 + e.toString();
283 throw new BuildException(msg, e);
284 }
285
286 }
287
288}
Note: See TracBrowser for help on using the repository browser.