2
* The Apache Software License, Version 1.1
4
* Copyright (c) 2001 The Apache Software Foundation. All rights
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions
11
* 1. Redistributions of source code must retain the above copyright
12
* notice, this list of conditions and the following disclaimer.
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
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.
26
* 4. The names "The Jakarta Project", "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.
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.
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
47
* ====================================================================
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/>.
56
package org.apache.tools.ant.taskdefs.optional.ejb;
61
import javax.xml.parsers.*;
63
import org.apache.tools.ant.*;
64
import org.apache.tools.ant.taskdefs.ExecTask;
65
import org.apache.tools.ant.taskdefs.Java;
66
import org.apache.tools.ant.types.*;
67
import org.apache.tools.ant.types.Commandline.Argument;
71
* BorlandGenerateClient is dedicated to the Borland Application Server 4.5
72
* This task generates the client jar using as input the ejb jar file.
73
* Two mode are available: java mode (default) and fork mode. With the fork mode,
74
* it is impossible to add classpath to the commmand line.
76
* @author <a href="mailto:benoit.moussaud@criltelecom.com">Benoit Moussaud</a>
79
public class BorlandGenerateClient extends Task
81
static final String JAVA_MODE = "java";
82
static final String FORK_MODE = "fork";
84
/** debug the generateclient task */
85
boolean debug = false;
87
/** hold the ejbjar file name */
88
File ejbjarfile = null;
90
/** hold the client jar file name */
91
File clientjarfile = null;
93
/** hold the classpath */
96
/** hold the mode (java|fork) */
97
String mode = JAVA_MODE;
99
public void setMode(String s) {
102
public void setDebug(boolean debug) {
106
public void setEjbjar(File ejbfile) {
107
ejbjarfile = ejbfile;
110
public void setClientjar(File clientjar) {
111
clientjarfile = clientjar;
114
public void setClasspath(Path classpath) {
115
if (this.classpath == null) {
116
this.classpath = classpath;
119
this.classpath.append(classpath);
123
public Path createClasspath() {
124
if (this.classpath == null) {
125
this.classpath = new Path(project);
127
return this.classpath.createPath();
130
public void setClasspathRef(Reference r) {
131
createClasspath().setRefid(r);
138
* The work is actually done by creating a separate JVM to run a java task.
140
* @exception BuildException if someting goes wrong with the build
142
public void execute() throws BuildException {
143
if ( ejbjarfile == null ||
144
ejbjarfile.isDirectory()) {
145
throw new BuildException("invalid ejb jar file.");
148
if ( clientjarfile == null ||
149
clientjarfile.isDirectory()) {
150
log("invalid or missing client jar file.",Project.MSG_VERBOSE);
151
String ejbjarname = ejbjarfile.getAbsolutePath();
152
//clientname = ejbjarfile+client.jar
153
String clientname = ejbjarname.substring(0,ejbjarname.lastIndexOf("."));
154
clientname = clientname + "client.jar";
155
clientjarfile = new File(clientname);
159
if ( mode == null ) {
160
log("mode is null default mode is java");
164
log("client jar file is " + clientjarfile);
166
if ( mode.equalsIgnoreCase(FORK_MODE)) {
174
/** launch the generate client using java api */
175
protected void executeJava() throws BuildException {
179
org.apache.tools.ant.taskdefs.Java execTask = null;
180
execTask = (Java) getProject().createTask("java");
182
execTask.setDir(new File("."));
183
execTask.setClassname("com.inprise.server.commandline.EJBUtilities");
185
//add at the end of the classpath
186
//the system classpath in order to find the tools.jar file
187
execTask.setClasspath(classpath.concatSystemClasspath());
189
execTask.setFork(true);
190
execTask.createArg().setValue("generateclient");
192
execTask.createArg().setValue("-trace");
196
execTask.createArg().setValue("-short");
197
execTask.createArg().setValue("-jarfile");
199
execTask.createArg().setValue(ejbjarfile.getAbsolutePath());
201
execTask.createArg().setValue("-single");
202
execTask.createArg().setValue("-clientjarfile");
203
execTask.createArg().setValue(clientjarfile.getAbsolutePath());
205
log("Calling EJBUtilities",Project.MSG_VERBOSE);
209
catch (Exception e) {
210
// Have to catch this because of the semantics of calling main()
211
String msg = "Exception while calling generateclient Details: " + e.toString();
212
throw new BuildException(msg, e);
216
/** launch the generate client using system api */
217
protected void executeFork() throws BuildException {
221
org.apache.tools.ant.taskdefs.ExecTask execTask = null;
222
execTask = (ExecTask) getProject().createTask("exec");
224
execTask.setDir(new File("."));
225
execTask.setExecutable("iastool");
226
execTask.createArg().setValue("generateclient");
228
execTask.createArg().setValue("-trace");
232
execTask.createArg().setValue("-short");
233
execTask.createArg().setValue("-jarfile");
235
execTask.createArg().setValue(ejbjarfile.getAbsolutePath());
237
execTask.createArg().setValue("-single");
238
execTask.createArg().setValue("-clientjarfile");
239
execTask.createArg().setValue(clientjarfile.getAbsolutePath());
241
log("Calling java2iiop",Project.MSG_VERBOSE);
244
catch (Exception e) {
245
// Have to catch this because of the semantics of calling main()
246
String msg = "Exception while calling generateclient Details: " + e.toString();
247
throw new BuildException(msg, e);