~ubuntu-branches/ubuntu/jaunty/ant/jaunty-proposed

« back to all changes in this revision

Viewing changes to src/main/org/apache/tools/ant/taskdefs/optional/ejb/BorlandGenerateClient.java

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Gybas
  • Date: 2002-02-14 14:28:48 UTC
  • Revision ID: james.westby@ubuntu.com-20020214142848-2ww7ynmqkj31vlmn
Tags: upstream-1.4.1
ImportĀ upstreamĀ versionĀ 1.4.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * The Apache Software License, Version 1.1
 
3
 *
 
4
 * Copyright (c) 2001 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 "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.
 
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.*;
 
59
import java.net.*;
 
60
import java.util.*;
 
61
import javax.xml.parsers.*;
 
62
 
 
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;
 
68
import org.xml.sax.*;
 
69
 
 
70
/**
 
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.
 
75
 * 
 
76
 * @author  <a href="mailto:benoit.moussaud@criltelecom.com">Benoit Moussaud</a>
 
77
 *
 
78
 */
 
79
public class BorlandGenerateClient extends Task
 
80
{
 
81
    static final String JAVA_MODE = "java";
 
82
    static final String FORK_MODE = "fork";
 
83
 
 
84
    /** debug the generateclient task */
 
85
    boolean debug = false;
 
86
 
 
87
    /** hold the ejbjar file name */
 
88
    File ejbjarfile = null;
 
89
 
 
90
    /** hold the client jar file name */
 
91
    File clientjarfile = null;
 
92
 
 
93
    /** hold the classpath */
 
94
    Path classpath;
 
95
 
 
96
    /** hold the mode (java|fork) */
 
97
    String mode = JAVA_MODE;
 
98
 
 
99
    public void setMode(String s) {
 
100
        mode = s;
 
101
    }
 
102
    public void setDebug(boolean debug) {
 
103
        this.debug = debug;
 
104
    }
 
105
 
 
106
    public void setEjbjar(File ejbfile) {
 
107
        ejbjarfile = ejbfile;
 
108
    }
 
109
    
 
110
    public void setClientjar(File clientjar) {
 
111
        clientjarfile = clientjar;
 
112
    }
 
113
 
 
114
    public void setClasspath(Path classpath) {
 
115
        if (this.classpath == null) {
 
116
            this.classpath = classpath;
 
117
        }
 
118
        else {
 
119
            this.classpath.append(classpath);
 
120
        }
 
121
    }
 
122
    
 
123
    public Path createClasspath() {
 
124
        if (this.classpath == null) {
 
125
            this.classpath = new Path(project);
 
126
        }
 
127
        return this.classpath.createPath();
 
128
    }
 
129
    
 
130
    public void setClasspathRef(Reference r) {
 
131
        createClasspath().setRefid(r);
 
132
    }
 
133
    
 
134
 
 
135
    /**
 
136
     * Do the work.
 
137
     *
 
138
     * The work is actually done by creating a separate JVM to run a java task. 
 
139
     *
 
140
     * @exception BuildException if someting goes wrong with the build
 
141
     */
 
142
    public void execute() throws BuildException {
 
143
        if ( ejbjarfile == null ||
 
144
             ejbjarfile.isDirectory()) {
 
145
            throw new BuildException("invalid ejb jar file.");
 
146
        } // end of if ()
 
147
 
 
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);
 
156
 
 
157
        } // end of if ()
 
158
 
 
159
        if ( mode == null ) {
 
160
            log("mode is null default mode  is java");
 
161
            setMode(JAVA_MODE);
 
162
        } // end of if ()
 
163
 
 
164
        log("client jar file is " + clientjarfile);
 
165
 
 
166
        if ( mode.equalsIgnoreCase(FORK_MODE)) {
 
167
            executeFork();
 
168
        } // end of if ()
 
169
        else {            
 
170
            executeJava();
 
171
        } // end of else                       
 
172
    }
 
173
    
 
174
    /** launch the generate client using java api */
 
175
    protected void executeJava() throws BuildException {
 
176
        try {
 
177
            log("mode : java");
 
178
 
 
179
            org.apache.tools.ant.taskdefs.Java execTask = null;                
 
180
            execTask = (Java) getProject().createTask("java");
 
181
                       
 
182
            execTask.setDir(new File("."));
 
183
            execTask.setClassname("com.inprise.server.commandline.EJBUtilities");
 
184
            //classpath
 
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());
 
188
 
 
189
            execTask.setFork(true);
 
190
            execTask.createArg().setValue("generateclient");
 
191
            if ( debug ) {
 
192
                execTask.createArg().setValue("-trace");                
 
193
            } // end of if ()
 
194
 
 
195
            //
 
196
            execTask.createArg().setValue("-short");
 
197
            execTask.createArg().setValue("-jarfile");
 
198
            // ejb jar file
 
199
            execTask.createArg().setValue(ejbjarfile.getAbsolutePath());
 
200
            //client jar file
 
201
            execTask.createArg().setValue("-single");
 
202
            execTask.createArg().setValue("-clientjarfile");
 
203
            execTask.createArg().setValue(clientjarfile.getAbsolutePath());
 
204
 
 
205
            log("Calling EJBUtilities",Project.MSG_VERBOSE);                       
 
206
            execTask.execute();        
 
207
 
 
208
        }
 
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);
 
213
        }
 
214
    }
 
215
 
 
216
    /** launch the generate client using system api */
 
217
    protected  void executeFork() throws BuildException {
 
218
        try {
 
219
            log("mode : fork");
 
220
 
 
221
            org.apache.tools.ant.taskdefs.ExecTask execTask = null;                
 
222
            execTask = (ExecTask) getProject().createTask("exec");
 
223
                       
 
224
            execTask.setDir(new File("."));
 
225
            execTask.setExecutable("iastool");
 
226
            execTask.createArg().setValue("generateclient");
 
227
            if ( debug ){
 
228
                execTask.createArg().setValue("-trace");                
 
229
            } // end of if ()
 
230
 
 
231
            //
 
232
            execTask.createArg().setValue("-short");
 
233
            execTask.createArg().setValue("-jarfile");
 
234
            // ejb jar file
 
235
            execTask.createArg().setValue(ejbjarfile.getAbsolutePath());
 
236
            //client jar file
 
237
            execTask.createArg().setValue("-single");
 
238
            execTask.createArg().setValue("-clientjarfile");
 
239
            execTask.createArg().setValue(clientjarfile.getAbsolutePath());
 
240
 
 
241
            log("Calling java2iiop",Project.MSG_VERBOSE);                       
 
242
            execTask.execute();        
 
243
        }
 
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);
 
248
        }
 
249
 
 
250
    }
 
251
}