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