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