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