1 | /*
|
---|
2 | * Copyright 2002-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 | package org.apache.tools.ant.taskdefs.optional.ejb;
|
---|
18 |
|
---|
19 | import java.io.File;
|
---|
20 | import java.io.IOException;
|
---|
21 | import java.util.Enumeration;
|
---|
22 | import java.util.Hashtable;
|
---|
23 | import javax.xml.parsers.SAXParser;
|
---|
24 | import org.apache.tools.ant.AntClassLoader;
|
---|
25 | import org.apache.tools.ant.BuildException;
|
---|
26 | import org.apache.tools.ant.Project;
|
---|
27 | import org.apache.tools.ant.taskdefs.Java;
|
---|
28 | import org.apache.tools.ant.types.Path;
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * The deployment tool to add the jonas specific deployment descriptors to the
|
---|
32 | * ejb JAR file. JONAS only requires one additional file jonas-ejb-jar.xml.
|
---|
33 | *
|
---|
34 | * @version 1.0
|
---|
35 | * @see EjbJar#createJonas
|
---|
36 | */
|
---|
37 | public class JonasDeploymentTool extends GenericDeploymentTool {
|
---|
38 |
|
---|
39 | /** Public Id of the standard deployment descriptor DTD. */
|
---|
40 | protected static final String EJB_JAR_1_1_PUBLIC_ID
|
---|
41 | = "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN";
|
---|
42 | protected static final String EJB_JAR_2_0_PUBLIC_ID
|
---|
43 | = "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN";
|
---|
44 |
|
---|
45 | /** Public Id of the JOnAS-specific deployment descriptor DTD. */
|
---|
46 | protected static final String JONAS_EJB_JAR_2_4_PUBLIC_ID
|
---|
47 | = "-//ObjectWeb//DTD JOnAS 2.4//EN";
|
---|
48 | protected static final String JONAS_EJB_JAR_2_5_PUBLIC_ID
|
---|
49 | = "-//ObjectWeb//DTD JOnAS 2.5//EN";
|
---|
50 |
|
---|
51 | /** RMI ORB. */
|
---|
52 | protected static final String RMI_ORB = "RMI";
|
---|
53 |
|
---|
54 | /** JEREMIE ORB. */
|
---|
55 | protected static final String JEREMIE_ORB = "JEREMIE";
|
---|
56 |
|
---|
57 | /** DAVID ORB. */
|
---|
58 | protected static final String DAVID_ORB = "DAVID";
|
---|
59 |
|
---|
60 | /**
|
---|
61 | * Name of the standard deployment descriptor DTD (these files are stored in
|
---|
62 | * the ${JONAS_ROOT}/xml directory).
|
---|
63 | */
|
---|
64 | protected static final String EJB_JAR_1_1_DTD = "ejb-jar_1_1.dtd";
|
---|
65 | protected static final String EJB_JAR_2_0_DTD = "ejb-jar_2_0.dtd";
|
---|
66 |
|
---|
67 | /**
|
---|
68 | * Name of the JOnAS-specific deployment descriptor DTD (these files are
|
---|
69 | * stored in the ${JONAS_ROOT}/xml directory).
|
---|
70 | */
|
---|
71 | protected static final String JONAS_EJB_JAR_2_4_DTD
|
---|
72 | = "jonas-ejb-jar_2_4.dtd";
|
---|
73 | protected static final String JONAS_EJB_JAR_2_5_DTD
|
---|
74 | = "jonas-ejb-jar_2_5.dtd";
|
---|
75 |
|
---|
76 | /** Default JOnAS deployment descriptor name. */
|
---|
77 | protected static final String JONAS_DD = "jonas-ejb-jar.xml";
|
---|
78 |
|
---|
79 | /** GenIC class name (JOnAS 2.5) */
|
---|
80 | protected static final String GENIC_CLASS =
|
---|
81 | "org.objectweb.jonas_ejb.genic.GenIC";
|
---|
82 |
|
---|
83 | /** Old GenIC class name (JOnAS 2.4.x). */
|
---|
84 | protected static final String OLD_GENIC_CLASS_1 =
|
---|
85 | "org.objectweb.jonas_ejb.tools.GenWholeIC";
|
---|
86 |
|
---|
87 | /** Old GenIC class name. */
|
---|
88 | protected static final String OLD_GENIC_CLASS_2 =
|
---|
89 | "org.objectweb.jonas_ejb.tools.GenIC";
|
---|
90 |
|
---|
91 | /**
|
---|
92 | * Filename of the standard EJB descriptor (which is passed to this class
|
---|
93 | * from the parent "ejbjar" task). This file is relative to the directory
|
---|
94 | * specified by the "srcdir" attribute in the ejbjar task.
|
---|
95 | */
|
---|
96 | private String descriptorName;
|
---|
97 |
|
---|
98 | /**
|
---|
99 | * Filename of the JOnAS-specific EJB descriptor (which is passed to this
|
---|
100 | * class from the parent "ejbjar" task). This file is relative to the
|
---|
101 | * directory specified by the "srcdir" attribute in the ejbjar task.
|
---|
102 | */
|
---|
103 | private String jonasDescriptorName;
|
---|
104 |
|
---|
105 | /* ------------- */
|
---|
106 | /* GenIC options */
|
---|
107 | /* ------------- */
|
---|
108 |
|
---|
109 | /**
|
---|
110 | * Temporary output directory used by GenIC.
|
---|
111 | */
|
---|
112 | private File outputdir;
|
---|
113 |
|
---|
114 | /**
|
---|
115 | * <code>true</code> if the intermediate Java source files generated by
|
---|
116 | * GenIC must be deleted or not. The default is <code>false</code>
|
---|
117 | */
|
---|
118 | private boolean keepgenerated = false;
|
---|
119 |
|
---|
120 | /**
|
---|
121 | * <code>true</code> if the generated source files must not be compiled via
|
---|
122 | * the java and rmi compilers. The default is <code>false</code>.
|
---|
123 | */
|
---|
124 | private boolean nocompil = false;
|
---|
125 |
|
---|
126 | /**
|
---|
127 | * <code>true</code> if the XML deployment descriptors must be parsed
|
---|
128 | * without validation. The default is <code>false</code>.
|
---|
129 | */
|
---|
130 | private boolean novalidation = false;
|
---|
131 |
|
---|
132 | /**
|
---|
133 | * Java compiler to use. The default is the value of
|
---|
134 | * <code>build.compiler</code> property.
|
---|
135 | */
|
---|
136 | private String javac;
|
---|
137 |
|
---|
138 | /** Options to pass to the java compiler. */
|
---|
139 | private String javacopts;
|
---|
140 |
|
---|
141 | /** Options to pass to the rmi compiler. */
|
---|
142 | private String rmicopts;
|
---|
143 |
|
---|
144 | /**
|
---|
145 | * Whether or not the RMI skeleton and stub must be modified to
|
---|
146 | * implement the implicit propagation of the security context (the
|
---|
147 | * transactional context is always provided). The default is
|
---|
148 | * <code>false</code>.
|
---|
149 | */
|
---|
150 | private boolean secpropag = false;
|
---|
151 |
|
---|
152 | /**
|
---|
153 | * <code>true</code> if the GenIC call must be verbose. The default
|
---|
154 | * is <code>false</code>.
|
---|
155 | */
|
---|
156 | private boolean verbose = false;
|
---|
157 |
|
---|
158 | /** Additional args to send to GenIC. */
|
---|
159 | private String additionalargs;
|
---|
160 |
|
---|
161 | /* ------------- */
|
---|
162 | /* other options */
|
---|
163 | /* ------------- */
|
---|
164 |
|
---|
165 | /** JOnAS root directory. */
|
---|
166 | private File jonasroot;
|
---|
167 |
|
---|
168 | /**
|
---|
169 | * <code>true</code> if the generic JAR file used as input to GenIC must be
|
---|
170 | * retained. The default is <code>false</code>.
|
---|
171 | */
|
---|
172 | private boolean keepgeneric = false;
|
---|
173 |
|
---|
174 | /** Stores the suffix for the JOnAS JAR file. The default is '.jar'. */
|
---|
175 | private String suffix = ".jar";
|
---|
176 |
|
---|
177 | /**
|
---|
178 | * ORB to use (RMI, JEREMIE or DAVID). If omitted, it defaults to the one
|
---|
179 | * present in classpath. If specified, the corresponding JOnAS JAR is
|
---|
180 | * automatically added to the classpath.
|
---|
181 | */
|
---|
182 | private String orb;
|
---|
183 |
|
---|
184 | /**
|
---|
185 | * <code>true</code> if GenIC must not be run on the EJB JAR.
|
---|
186 | * The default is <code>false</code>.
|
---|
187 | */
|
---|
188 | private boolean nogenic = false;
|
---|
189 |
|
---|
190 | /* -------------------- */
|
---|
191 | /* GenIC options setter */
|
---|
192 | /* -------------------- */
|
---|
193 |
|
---|
194 | /**
|
---|
195 | * Sets the <code>keepgenerated</code> flag.
|
---|
196 | *
|
---|
197 | * @param aBoolean <code>true</code> if the flag must be set.
|
---|
198 | */
|
---|
199 | public void setKeepgenerated(boolean aBoolean) {
|
---|
200 | keepgenerated = aBoolean;
|
---|
201 | }
|
---|
202 |
|
---|
203 | /**
|
---|
204 | * Sets the additional arguments.
|
---|
205 | *
|
---|
206 | * @param aString additional args.
|
---|
207 | */
|
---|
208 | public void setAdditionalargs(String aString) {
|
---|
209 | additionalargs = aString;
|
---|
210 | }
|
---|
211 |
|
---|
212 | /**
|
---|
213 | * Sets the <code>nocompil</code> flag.
|
---|
214 | *
|
---|
215 | * @param aBoolean <code>true</code> if the flag must be set.
|
---|
216 | */
|
---|
217 | public void setNocompil(boolean aBoolean) {
|
---|
218 | nocompil = aBoolean;
|
---|
219 | }
|
---|
220 |
|
---|
221 | /**
|
---|
222 | * Sets the <code>novalidation</code> flag.
|
---|
223 | *
|
---|
224 | * @param aBoolean <code>true</code> if the flag must be set.
|
---|
225 | */
|
---|
226 | public void setNovalidation(boolean aBoolean) {
|
---|
227 | novalidation = aBoolean;
|
---|
228 | }
|
---|
229 |
|
---|
230 | /**
|
---|
231 | * Sets the java compiler to use.
|
---|
232 | *
|
---|
233 | * @param aString the java compiler.
|
---|
234 | */
|
---|
235 | public void setJavac(String aString) {
|
---|
236 | javac = aString;
|
---|
237 | }
|
---|
238 |
|
---|
239 | /**
|
---|
240 | * Set the options to pass to the java compiler.
|
---|
241 | *
|
---|
242 | * @param aString the options.
|
---|
243 | */
|
---|
244 | public void setJavacopts(String aString) {
|
---|
245 | javacopts = aString;
|
---|
246 | }
|
---|
247 |
|
---|
248 | /**
|
---|
249 | * Set the options to pass to the rmi compiler.
|
---|
250 | *
|
---|
251 | * @param aString the options.
|
---|
252 | */
|
---|
253 | public void setRmicopts(String aString) {
|
---|
254 | rmicopts = aString;
|
---|
255 | }
|
---|
256 |
|
---|
257 | /**
|
---|
258 | * Sets the <code>secpropag</code> flag.
|
---|
259 | *
|
---|
260 | * @param aBoolean <code>true</code> if the flag must be set.
|
---|
261 | */
|
---|
262 | public void setSecpropag(boolean aBoolean) {
|
---|
263 | secpropag = aBoolean;
|
---|
264 | }
|
---|
265 |
|
---|
266 | /**
|
---|
267 | * Sets the <code>verbose</code> flag.
|
---|
268 | *
|
---|
269 | * @param aBoolean <code>true</code> if the flag must be set.
|
---|
270 | */
|
---|
271 | public void setVerbose(boolean aBoolean) {
|
---|
272 | verbose = aBoolean;
|
---|
273 | }
|
---|
274 |
|
---|
275 | /* -------------------- */
|
---|
276 | /* other options setter */
|
---|
277 | /* -------------------- */
|
---|
278 |
|
---|
279 | /**
|
---|
280 | * Set the JOnAS root directory.
|
---|
281 | *
|
---|
282 | * @param aFile the JOnAS root directory.
|
---|
283 | */
|
---|
284 | public void setJonasroot(File aFile) {
|
---|
285 | jonasroot = aFile;
|
---|
286 | }
|
---|
287 |
|
---|
288 | /**
|
---|
289 | * Sets the <code>keepgeneric</code> flag.
|
---|
290 | *
|
---|
291 | * @param aBoolean <code>true</code> if the flag must be set.
|
---|
292 | */
|
---|
293 | public void setKeepgeneric(boolean aBoolean) {
|
---|
294 | keepgeneric = aBoolean;
|
---|
295 | }
|
---|
296 |
|
---|
297 | /**
|
---|
298 | * Sets the jar suffix.
|
---|
299 | *
|
---|
300 | * @param aString the string to use as the suffix.
|
---|
301 | */
|
---|
302 | public void setJarsuffix(String aString) {
|
---|
303 | suffix = aString;
|
---|
304 | }
|
---|
305 |
|
---|
306 | /**
|
---|
307 | * Sets the <code>orb</code> to construct classpath.
|
---|
308 | *
|
---|
309 | * @param aString 'RMI', 'JEREMIE', or 'DAVID'.
|
---|
310 | */
|
---|
311 | public void setOrb(String aString) {
|
---|
312 | orb = aString;
|
---|
313 | }
|
---|
314 |
|
---|
315 | /**
|
---|
316 | * Sets the <code>nogenic</code> flag.
|
---|
317 | *
|
---|
318 | * @param aBoolean <code>true</code> if the flag must be set.
|
---|
319 | */
|
---|
320 | public void setNogenic(boolean aBoolean) {
|
---|
321 | nogenic = aBoolean;
|
---|
322 | }
|
---|
323 |
|
---|
324 | /* ------------- */
|
---|
325 | /* other methods */
|
---|
326 | /* ------------- */
|
---|
327 |
|
---|
328 | public void processDescriptor(String aDescriptorName, SAXParser saxParser) {
|
---|
329 |
|
---|
330 | descriptorName = aDescriptorName;
|
---|
331 |
|
---|
332 | log("JOnAS Deployment Tool processing: " + descriptorName,
|
---|
333 | Project.MSG_VERBOSE);
|
---|
334 |
|
---|
335 | super.processDescriptor(descriptorName, saxParser);
|
---|
336 |
|
---|
337 | if (outputdir != null) {
|
---|
338 | // the method deleteOnExit() do not work because the directory is not empty
|
---|
339 | log("Deleting temp output directory '" + outputdir + "'.", Project.MSG_VERBOSE);
|
---|
340 | deleteAllFiles(outputdir);
|
---|
341 | }
|
---|
342 | }
|
---|
343 |
|
---|
344 | protected void writeJar(String baseName, File jarfile, Hashtable ejbFiles, String publicId)
|
---|
345 | throws BuildException {
|
---|
346 |
|
---|
347 | // create the generic jar first
|
---|
348 | File genericJarFile = super.getVendorOutputJarFile(baseName);
|
---|
349 | super.writeJar(baseName, genericJarFile, ejbFiles, publicId);
|
---|
350 |
|
---|
351 | // GenIC call on generic jar
|
---|
352 | addGenICGeneratedFiles(genericJarFile, ejbFiles);
|
---|
353 |
|
---|
354 | // create the real jar
|
---|
355 | super.writeJar(baseName, getVendorOutputJarFile(baseName), ejbFiles, publicId);
|
---|
356 |
|
---|
357 | if (!keepgeneric) {
|
---|
358 | log("Deleting generic JAR " + genericJarFile.toString(), Project.MSG_VERBOSE);
|
---|
359 | genericJarFile.delete();
|
---|
360 | }
|
---|
361 | }
|
---|
362 |
|
---|
363 | protected void addVendorFiles(Hashtable ejbFiles, String ddPrefix) {
|
---|
364 |
|
---|
365 | // JOnAS-specific descriptor deployment
|
---|
366 | jonasDescriptorName = getJonasDescriptorName();
|
---|
367 | File jonasDD = new File(getConfig().descriptorDir, jonasDescriptorName);
|
---|
368 |
|
---|
369 | if (jonasDD.exists()) {
|
---|
370 | ejbFiles.put(META_DIR + JONAS_DD, jonasDD);
|
---|
371 | } else {
|
---|
372 | log("Unable to locate the JOnAS deployment descriptor. It was expected to be in: "
|
---|
373 | + jonasDD.getPath() + ".", Project.MSG_WARN);
|
---|
374 | }
|
---|
375 | }
|
---|
376 |
|
---|
377 | protected File getVendorOutputJarFile(String baseName) {
|
---|
378 | return new File(getDestDir(), baseName + suffix);
|
---|
379 | }
|
---|
380 |
|
---|
381 | /**
|
---|
382 | * Determines the name of the JOnAS-specific EJB descriptor using the
|
---|
383 | * specified standard EJB descriptor name. In general, the standard
|
---|
384 | * descriptor will be named "[basename]-ejb-jar.xml", and this method will
|
---|
385 | * return "[basename]-jonas-ejb-jar.xml" or "jonas-[basename].xml"
|
---|
386 | *
|
---|
387 | * @return The name of the JOnAS-specific EJB descriptor file.
|
---|
388 | */
|
---|
389 | private String getJonasDescriptorName() {
|
---|
390 |
|
---|
391 | // descriptorName = <path><basename><basenameterminator><remainder>
|
---|
392 | // examples = /org/objectweb/fooAppli/foo/Foo-ejb-jar.xml
|
---|
393 | // examples = /org/objectweb/fooAppli/foo/Foo.xml (JOnAS convention)
|
---|
394 |
|
---|
395 | String jonasDescriptorName; // JOnAS-specific DD
|
---|
396 | boolean jonasConvention = false; // true if the JOnAS convention is used for the DD
|
---|
397 | String path; // Directory path of the EJB descriptor
|
---|
398 | String fileName; // EJB descriptor file name
|
---|
399 | String baseName; // Filename appearing before name terminator
|
---|
400 | String remainder; // Filename appearing after the name terminator
|
---|
401 |
|
---|
402 | int startOfFileName = descriptorName.lastIndexOf(File.separatorChar);
|
---|
403 | if (startOfFileName != -1) {
|
---|
404 | // extract path info
|
---|
405 | path = descriptorName.substring(0, startOfFileName + 1);
|
---|
406 | fileName = descriptorName.substring(startOfFileName + 1);
|
---|
407 | } else {
|
---|
408 | // descriptorName is just a file without path
|
---|
409 | path = "";
|
---|
410 | fileName = descriptorName;
|
---|
411 | }
|
---|
412 |
|
---|
413 | if (fileName.startsWith(EJB_DD)) {
|
---|
414 | return path + JONAS_DD;
|
---|
415 | }
|
---|
416 |
|
---|
417 | int endOfBaseName = descriptorName.indexOf(getConfig().baseNameTerminator, startOfFileName);
|
---|
418 |
|
---|
419 | /*
|
---|
420 | * Check for the odd case where the terminator and/or filename
|
---|
421 | * extension aren't found. These will ensure "jonas-" appears at the
|
---|
422 | * end of the name and before the '.' (if present).
|
---|
423 | */
|
---|
424 | if (endOfBaseName < 0) {
|
---|
425 | // baseNameTerminator not found: the descriptor use the
|
---|
426 | // JOnAS naming convention, ie [Foo.xml,jonas-Foo.xml] and
|
---|
427 | // not [Foo<baseNameTerminator>-ejb-jar.xml,
|
---|
428 | // Foo<baseNameTerminator>-jonas-ejb-jar.xml].
|
---|
429 | endOfBaseName = descriptorName.lastIndexOf('.') - 1;
|
---|
430 | if (endOfBaseName < 0) {
|
---|
431 | // no . found
|
---|
432 | endOfBaseName = descriptorName.length() - 1;
|
---|
433 | }
|
---|
434 |
|
---|
435 | jonasConvention = true;
|
---|
436 | }
|
---|
437 |
|
---|
438 | baseName = descriptorName.substring(startOfFileName + 1, endOfBaseName + 1);
|
---|
439 | remainder = descriptorName.substring(endOfBaseName + 1);
|
---|
440 |
|
---|
441 | if (jonasConvention) {
|
---|
442 | jonasDescriptorName = path + "jonas-" + baseName + ".xml";
|
---|
443 | } else {
|
---|
444 | jonasDescriptorName = path + baseName + "jonas-" + remainder;
|
---|
445 | }
|
---|
446 |
|
---|
447 | log("Standard EJB descriptor name: " + descriptorName, Project.MSG_VERBOSE);
|
---|
448 | log("JOnAS-specific descriptor name: " + jonasDescriptorName, Project.MSG_VERBOSE);
|
---|
449 |
|
---|
450 | return jonasDescriptorName;
|
---|
451 | }
|
---|
452 |
|
---|
453 | protected String getJarBaseName(String descriptorFileName) {
|
---|
454 |
|
---|
455 | String baseName = null;
|
---|
456 |
|
---|
457 | if (getConfig().namingScheme.getValue().equals(EjbJar.NamingScheme.DESCRIPTOR)) {
|
---|
458 |
|
---|
459 | // try to find JOnAS specific convention name
|
---|
460 | if (descriptorFileName.indexOf(getConfig().baseNameTerminator) == -1) {
|
---|
461 |
|
---|
462 | // baseNameTerminator not found: the descriptor use the
|
---|
463 | // JOnAS naming convention, ie [Foo.xml,jonas-Foo.xml] and
|
---|
464 | // not [Foo<baseNameTerminator>-ejb-jar.xml,
|
---|
465 | // Foo<baseNameTerminator>-jonas-ejb-jar.xml].
|
---|
466 |
|
---|
467 | String aCanonicalDescriptor = descriptorFileName.replace('\\', '/');
|
---|
468 | int lastSeparatorIndex = aCanonicalDescriptor.lastIndexOf('/');
|
---|
469 | int endOfBaseName;
|
---|
470 |
|
---|
471 | if (lastSeparatorIndex != -1) {
|
---|
472 | endOfBaseName = descriptorFileName.indexOf(".xml", lastSeparatorIndex);
|
---|
473 | } else {
|
---|
474 | endOfBaseName = descriptorFileName.indexOf(".xml");
|
---|
475 | }
|
---|
476 |
|
---|
477 | if (endOfBaseName != -1) {
|
---|
478 | baseName = descriptorFileName.substring(0, endOfBaseName);
|
---|
479 | }
|
---|
480 | }
|
---|
481 | }
|
---|
482 |
|
---|
483 | if (baseName == null) {
|
---|
484 | // else get standard baseName
|
---|
485 | baseName = super.getJarBaseName(descriptorFileName);
|
---|
486 | }
|
---|
487 |
|
---|
488 | log("JAR base name: " + baseName, Project.MSG_VERBOSE);
|
---|
489 |
|
---|
490 | return baseName;
|
---|
491 | }
|
---|
492 |
|
---|
493 | protected void registerKnownDTDs(DescriptorHandler handler) {
|
---|
494 | handler.registerDTD(EJB_JAR_1_1_PUBLIC_ID,
|
---|
495 | jonasroot + File.separator + "xml" + File.separator + EJB_JAR_1_1_DTD);
|
---|
496 | handler.registerDTD(EJB_JAR_2_0_PUBLIC_ID,
|
---|
497 | jonasroot + File.separator + "xml" + File.separator + EJB_JAR_2_0_DTD);
|
---|
498 |
|
---|
499 | handler.registerDTD(JONAS_EJB_JAR_2_4_PUBLIC_ID,
|
---|
500 | jonasroot + File.separator + "xml" + File.separator + JONAS_EJB_JAR_2_4_DTD);
|
---|
501 | handler.registerDTD(JONAS_EJB_JAR_2_5_PUBLIC_ID,
|
---|
502 | jonasroot + File.separator + "xml" + File.separator + JONAS_EJB_JAR_2_5_DTD);
|
---|
503 | }
|
---|
504 |
|
---|
505 | /**
|
---|
506 | * Add to the given hashtable all the file generated by GenIC.
|
---|
507 | *
|
---|
508 | * @param genericJarFile jar file.
|
---|
509 | * @param ejbFiles the hashtable.
|
---|
510 | */
|
---|
511 | private void addGenICGeneratedFiles(File genericJarFile, Hashtable ejbFiles) {
|
---|
512 | // GenIC task
|
---|
513 | Java genicTask = null;
|
---|
514 |
|
---|
515 | // GenIC class (3 GenIC classes for various versions of JOnAS
|
---|
516 | // are supported)
|
---|
517 | String genicClass = null;
|
---|
518 |
|
---|
519 | if (nogenic) {
|
---|
520 | return;
|
---|
521 | }
|
---|
522 |
|
---|
523 | genicTask = (Java) getTask().getProject().createTask("java");
|
---|
524 | genicTask.setTaskName("genic");
|
---|
525 | genicTask.setFork(true);
|
---|
526 |
|
---|
527 | // jonasroot
|
---|
528 | genicTask.createJvmarg().setValue("-Dinstall.root=" + jonasroot);
|
---|
529 |
|
---|
530 | // java policy file
|
---|
531 | String jonasConfigDir = jonasroot + File.separator + "config";
|
---|
532 | File javaPolicyFile = new File(jonasConfigDir, "java.policy");
|
---|
533 | if (javaPolicyFile.exists()) {
|
---|
534 | genicTask.createJvmarg().setValue("-Djava.security.policy="
|
---|
535 | + javaPolicyFile.toString());
|
---|
536 | }
|
---|
537 |
|
---|
538 | // outputdir
|
---|
539 | try {
|
---|
540 | outputdir = createTempDir();
|
---|
541 | } catch (IOException aIOException) {
|
---|
542 | String msg = "Cannot create temp dir: " + aIOException.getMessage();
|
---|
543 | throw new BuildException(msg, aIOException);
|
---|
544 | }
|
---|
545 | log("Using temporary output directory: " + outputdir, Project.MSG_VERBOSE);
|
---|
546 |
|
---|
547 | genicTask.createArg().setValue("-d");
|
---|
548 | genicTask.createArg().setFile(outputdir);
|
---|
549 |
|
---|
550 | // work around a bug of GenIC 2.5
|
---|
551 | String key;
|
---|
552 | File f;
|
---|
553 | Enumeration keys = ejbFiles.keys();
|
---|
554 | while (keys.hasMoreElements()) {
|
---|
555 | key = (String) keys.nextElement();
|
---|
556 | f = new File(outputdir + File.separator + key);
|
---|
557 | f.getParentFile().mkdirs();
|
---|
558 | }
|
---|
559 | log("Worked around a bug of GenIC 2.5.", Project.MSG_VERBOSE);
|
---|
560 |
|
---|
561 | // classpath
|
---|
562 | Path classpath = getCombinedClasspath();
|
---|
563 | if (classpath == null) {
|
---|
564 | classpath = new Path(getTask().getProject());
|
---|
565 | }
|
---|
566 | classpath.append(new Path(classpath.getProject(), jonasConfigDir));
|
---|
567 | classpath.append(new Path(classpath.getProject(), outputdir.toString()));
|
---|
568 |
|
---|
569 | // try to create the classpath for the correct ORB
|
---|
570 | if (orb != null) {
|
---|
571 | String orbJar = jonasroot + File.separator + "lib"
|
---|
572 | + File.separator + orb + "_jonas.jar";
|
---|
573 | classpath.append(new Path(classpath.getProject(), orbJar));
|
---|
574 | }
|
---|
575 |
|
---|
576 | log("Using classpath: " + classpath.toString(), Project.MSG_VERBOSE);
|
---|
577 | genicTask.setClasspath(classpath);
|
---|
578 |
|
---|
579 | // class name (search in the classpath provided for the ejbjar element)
|
---|
580 | genicClass = getGenicClassName(classpath);
|
---|
581 | if (genicClass == null) {
|
---|
582 | log("Cannot find GenIC class in classpath.", Project.MSG_ERR);
|
---|
583 | throw new BuildException("GenIC class not found, please check the classpath.");
|
---|
584 | } else {
|
---|
585 | log("Using '" + genicClass + "' GenIC class." , Project.MSG_VERBOSE);
|
---|
586 | genicTask.setClassname(genicClass);
|
---|
587 | }
|
---|
588 |
|
---|
589 | // keepgenerated
|
---|
590 | if (keepgenerated) {
|
---|
591 | genicTask.createArg().setValue("-keepgenerated");
|
---|
592 | }
|
---|
593 |
|
---|
594 | // nocompil
|
---|
595 | if (nocompil) {
|
---|
596 | genicTask.createArg().setValue("-nocompil");
|
---|
597 | }
|
---|
598 |
|
---|
599 | // novalidation
|
---|
600 | if (novalidation) {
|
---|
601 | genicTask.createArg().setValue("-novalidation");
|
---|
602 | }
|
---|
603 |
|
---|
604 | // javac
|
---|
605 | if (javac != null) {
|
---|
606 | genicTask.createArg().setValue("-javac");
|
---|
607 | genicTask.createArg().setLine(javac);
|
---|
608 | }
|
---|
609 |
|
---|
610 | // javacopts
|
---|
611 | if (javacopts != null && !javacopts.equals("")) {
|
---|
612 | genicTask.createArg().setValue("-javacopts");
|
---|
613 | genicTask.createArg().setLine(javacopts);
|
---|
614 | }
|
---|
615 |
|
---|
616 | // rmicopts
|
---|
617 | if (rmicopts != null && !rmicopts.equals("")) {
|
---|
618 | genicTask.createArg().setValue("-rmicopts");
|
---|
619 | genicTask.createArg().setLine(rmicopts);
|
---|
620 | }
|
---|
621 |
|
---|
622 | // secpropag
|
---|
623 | if (secpropag) {
|
---|
624 | genicTask.createArg().setValue("-secpropag");
|
---|
625 | }
|
---|
626 |
|
---|
627 | // verbose
|
---|
628 | if (verbose) {
|
---|
629 | genicTask.createArg().setValue("-verbose");
|
---|
630 | }
|
---|
631 |
|
---|
632 | // additionalargs
|
---|
633 | if (additionalargs != null) {
|
---|
634 | genicTask.createArg().setValue(additionalargs);
|
---|
635 | }
|
---|
636 |
|
---|
637 | // the generated classes must not be added in the generic JAR!
|
---|
638 | // is that buggy on old JOnAS (2.4) ??
|
---|
639 | genicTask.createArg().setValue("-noaddinjar");
|
---|
640 |
|
---|
641 | // input file to process by GenIC
|
---|
642 | genicTask.createArg().setValue(genericJarFile.getPath());
|
---|
643 |
|
---|
644 | // calling GenIC task
|
---|
645 | log("Calling " + genicClass + " for " + getConfig().descriptorDir
|
---|
646 | + File.separator + descriptorName + ".", Project.MSG_VERBOSE);
|
---|
647 |
|
---|
648 | if (genicTask.executeJava() != 0) {
|
---|
649 |
|
---|
650 | // the method deleteOnExit() do not work because the directory is not empty
|
---|
651 | log("Deleting temp output directory '" + outputdir + "'.", Project.MSG_VERBOSE);
|
---|
652 | deleteAllFiles(outputdir);
|
---|
653 |
|
---|
654 | if (!keepgeneric) {
|
---|
655 | log("Deleting generic JAR " + genericJarFile.toString(), Project.MSG_VERBOSE);
|
---|
656 | genericJarFile.delete();
|
---|
657 | }
|
---|
658 |
|
---|
659 | throw new BuildException("GenIC reported an error.");
|
---|
660 | }
|
---|
661 |
|
---|
662 | // add the generated files to the ejbFiles
|
---|
663 | addAllFiles(outputdir, "", ejbFiles);
|
---|
664 | }
|
---|
665 |
|
---|
666 | /**
|
---|
667 | * Get the GenIC class name to use in the given classpath.
|
---|
668 | *
|
---|
669 | * @param classpath classpath where the GenIC class must be searched.
|
---|
670 | * @return the GenIC class name. Return <code>null</code> if the class name
|
---|
671 | * cannot be found.
|
---|
672 | */
|
---|
673 | String getGenicClassName(Path classpath) {
|
---|
674 |
|
---|
675 | log("Looking for GenIC class in classpath: "
|
---|
676 | + classpath.toString(), Project.MSG_VERBOSE);
|
---|
677 |
|
---|
678 | AntClassLoader cl = classpath.getProject().createClassLoader(classpath);
|
---|
679 |
|
---|
680 | try {
|
---|
681 | cl.loadClass(JonasDeploymentTool.GENIC_CLASS);
|
---|
682 | log("Found GenIC class '" + JonasDeploymentTool.GENIC_CLASS
|
---|
683 | + "' in classpath.", Project.MSG_VERBOSE);
|
---|
684 | return JonasDeploymentTool.GENIC_CLASS;
|
---|
685 |
|
---|
686 | } catch (ClassNotFoundException cnf1) {
|
---|
687 | log("GenIC class '" + JonasDeploymentTool.GENIC_CLASS
|
---|
688 | + "' not found in classpath.",
|
---|
689 | Project.MSG_VERBOSE);
|
---|
690 | }
|
---|
691 |
|
---|
692 | try {
|
---|
693 | cl.loadClass(JonasDeploymentTool.OLD_GENIC_CLASS_1);
|
---|
694 | log("Found GenIC class '" + JonasDeploymentTool.OLD_GENIC_CLASS_1
|
---|
695 | + "' in classpath.", Project.MSG_VERBOSE);
|
---|
696 | return JonasDeploymentTool.OLD_GENIC_CLASS_1;
|
---|
697 |
|
---|
698 | } catch (ClassNotFoundException cnf2) {
|
---|
699 | log("GenIC class '" + JonasDeploymentTool.OLD_GENIC_CLASS_1
|
---|
700 | + "' not found in classpath.",
|
---|
701 | Project.MSG_VERBOSE);
|
---|
702 | }
|
---|
703 |
|
---|
704 | try {
|
---|
705 | cl.loadClass(JonasDeploymentTool.OLD_GENIC_CLASS_2);
|
---|
706 | log("Found GenIC class '" + JonasDeploymentTool.OLD_GENIC_CLASS_2
|
---|
707 | + "' in classpath.", Project.MSG_VERBOSE);
|
---|
708 | return JonasDeploymentTool.OLD_GENIC_CLASS_2;
|
---|
709 |
|
---|
710 | } catch (ClassNotFoundException cnf3) {
|
---|
711 | log("GenIC class '" + JonasDeploymentTool.OLD_GENIC_CLASS_2
|
---|
712 | + "' not found in classpath.",
|
---|
713 | Project.MSG_VERBOSE);
|
---|
714 | }
|
---|
715 | return null;
|
---|
716 | }
|
---|
717 |
|
---|
718 | protected void checkConfiguration(String descriptorFileName,
|
---|
719 | SAXParser saxParser) throws BuildException {
|
---|
720 |
|
---|
721 | // jonasroot
|
---|
722 | if (jonasroot == null) {
|
---|
723 | throw new BuildException("The jonasroot attribut is not set.");
|
---|
724 | } else if (!jonasroot.isDirectory()) {
|
---|
725 | throw new BuildException("The jonasroot attribut '" + jonasroot
|
---|
726 | + "' is not a valid directory.");
|
---|
727 | }
|
---|
728 |
|
---|
729 | // orb
|
---|
730 | if (orb != null && !orb.equals(RMI_ORB) && !orb.equals(JEREMIE_ORB)
|
---|
731 | && !orb.equals(DAVID_ORB)) {
|
---|
732 | throw new BuildException("The orb attribut '" + orb
|
---|
733 | + "' is not valid (must be either "
|
---|
734 | + RMI_ORB + ", " + JEREMIE_ORB + " or " + DAVID_ORB + ").");
|
---|
735 | }
|
---|
736 |
|
---|
737 | // additionalargs
|
---|
738 | if (additionalargs != null && additionalargs.equals("")) {
|
---|
739 | throw new BuildException("Empty additionalargs attribut.");
|
---|
740 | }
|
---|
741 |
|
---|
742 | // javac
|
---|
743 | if (javac != null && javac.equals("")) {
|
---|
744 | throw new BuildException("Empty javac attribut.");
|
---|
745 | }
|
---|
746 | }
|
---|
747 |
|
---|
748 | /* ----------------------------------------------------------------------------------- */
|
---|
749 | /* utilitary methods */
|
---|
750 | /* ----------------------------------------------------------------------------------- */
|
---|
751 |
|
---|
752 | /**
|
---|
753 | * Create a temporary directory for GenIC output.
|
---|
754 | *
|
---|
755 | * @return the temp directory.
|
---|
756 | * @throws BuildException if a temp directory cannot be created.
|
---|
757 | */
|
---|
758 | private File createTempDir() throws IOException {
|
---|
759 | File tmpDir = File.createTempFile("genic", null, null);
|
---|
760 | tmpDir.delete();
|
---|
761 | if (!tmpDir.mkdir()) {
|
---|
762 | throw new IOException("Cannot create the temporary directory '" + tmpDir + "'.");
|
---|
763 | }
|
---|
764 | return tmpDir;
|
---|
765 | }
|
---|
766 |
|
---|
767 | /**
|
---|
768 | * Delete a file. If the file is a directory, delete recursivly all the
|
---|
769 | * files inside.
|
---|
770 | *
|
---|
771 | * @param aFile file to delete.
|
---|
772 | */
|
---|
773 | private void deleteAllFiles(File aFile) {
|
---|
774 | if (aFile.isDirectory()) {
|
---|
775 | File[] someFiles = aFile.listFiles();
|
---|
776 |
|
---|
777 | for (int i = 0; i < someFiles.length; i++) {
|
---|
778 | deleteAllFiles(someFiles[i]);
|
---|
779 | }
|
---|
780 | }
|
---|
781 | aFile.delete();
|
---|
782 | }
|
---|
783 |
|
---|
784 | /**
|
---|
785 | * Add a file to the a given hashtable. If the file is a directory, add
|
---|
786 | * recursivly all the files inside to the hashtable.
|
---|
787 | *
|
---|
788 | * @param file the file to add.
|
---|
789 | * @param rootDir the current sub-directory to scan.
|
---|
790 | * @param hashtable the hashtable where to add the files.
|
---|
791 | */
|
---|
792 | private void addAllFiles(File file, String rootDir, Hashtable hashtable) {
|
---|
793 |
|
---|
794 | if (!file.exists()) {
|
---|
795 | throw new IllegalArgumentException();
|
---|
796 | }
|
---|
797 |
|
---|
798 | String newRootDir;
|
---|
799 | if (file.isDirectory()) {
|
---|
800 | File[] files = file.listFiles();
|
---|
801 | for (int i = 0; i < files.length; i++) {
|
---|
802 | if (rootDir.length() > 0) {
|
---|
803 | newRootDir = rootDir + File.separator + files[i].getName();
|
---|
804 | } else {
|
---|
805 | newRootDir = files[i].getName();
|
---|
806 | }
|
---|
807 | addAllFiles(files[i], newRootDir, hashtable);
|
---|
808 | }
|
---|
809 | } else {
|
---|
810 | hashtable.put(rootDir, file);
|
---|
811 | }
|
---|
812 | }
|
---|
813 | }
|
---|