From 334597d246c97f709d92d2be9c417d8d4dca4a96 Mon Sep 17 00:00:00 2001 From: Conor MacNeill Date: Sat, 2 Feb 2002 11:04:43 +0000 Subject: [PATCH] Add Support for JOnAS EJB server Submitted by: Cyrille Morvan git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271069 13f79535-47bb-0310-9956-ffa450edef68 --- docs/manual/OptionalTasks/ejb.html | 235 ++++++- .../ant/taskdefs/optional/ejb/EjbJar.java | 15 + .../optional/ejb/JonasDeploymentTool.java | 599 ++++++++++++++++++ 3 files changed, 837 insertions(+), 12 deletions(-) create mode 100644 src/main/org/apache/tools/ant/taskdefs/optional/ejb/JonasDeploymentTool.java diff --git a/docs/manual/OptionalTasks/ejb.html b/docs/manual/OptionalTasks/ejb.html index 5fb25aea8..a2ec806c8 100644 --- a/docs/manual/OptionalTasks/ejb.html +++ b/docs/manual/OptionalTasks/ejb.html @@ -16,7 +16,8 @@
  • Tim Fennell (tfenne@rcn.com)
  • Martin Gee (martin.gee@icsynergy.com)
  • Conor MacNeill (conor@cortexebusiness.com.au)
  • -
  • Greg Nelson (greg@netscape.com)
  • +
  • Cyrille Morvan (cmorvan@ingenosya.com)
  • +
  • Greg Nelson (gn@sun.com)
  • Version @VERSION@
    @@ -32,11 +33,10 @@ $Id$


    Introduction

    Ant provides a number of optional tasks for developing -Enterprise Java Beans (EJBs) -. In general these tasks are specific to the particular vendor's EJB Server.

    +Enterprise Java Beans (EJBs). +In general these tasks are specific to the particular vendor's EJB Server.

    At present the tasks support:
    -

    Over time we expect further optional tasks to support additional EJB Servers. - -

    Ant provides a number of optional tasks for developing -Enterprise Java Beans (EJBs). -In general these tasks are specific to the particular vendor's EJB Server. At present the tasks support -Weblogic 4.5.1 and 5.1 EJB servers. Over time we expect further optional tasks -to support additional EJB Servers.

    +

    EJB Tasks

    @@ -64,11 +61,12 @@ to support additional EJB Servers. - + + @@ -531,6 +529,7 @@ include:

  • Jboss 2.1 and above
  • Weblogic 5.1/6.0 session/entity beans using the weblogic.ejbc tool
  • TOPLink for WebLogic 2.5.1-enabled entity beans
  • +
  • JOnAS 2.4 Open Source EJB server
  • @@ -1282,12 +1281,224 @@ local DTDs are found in the [iAS-install-directory]/dtd directory. <dtd publicId="-//Sun Microsystems, Inc.//DTD iAS Enterprise JavaBeans 1.0//EN" location="${ias.home}/APPS/IASEjb_jar_1_0.dtd"/> </ejbjar> +

    +

    JOnAS (Java Open Application Server) element

    +
    +

    +

    The <jonas> nested element is used to build JOnAS-specific stubs +and skeletons thanks to the GenIC specific tool, and construct a JAR file +which may be deployed to the JOnAS Application Server. The build process +will always determine if the EJB stubs/skeletons and the EJB-JAR file are +up to date, and it will do the minimum amount of work required.

    + +

    Like the WebLogic element, a naming convention for the EJB descriptors + is most commonly used to specify the name for the completed JAR file. For + example, if the EJB descriptor ejb/Account.xml (or ejb/Account-ejb-jar.xml ) + is found in the descriptor directory, the jonas element will search for a + JOnAS-specific EJB descriptor file named ejb/Account-jonas-ejb-jar.xml + (if it isn't found, the task will fail) and a JAR file named ejb/Account.jar + will be written in the destination directory. Note that when the EJB + descriptors are added to the JAR file, they are automatically renamed + META-INF/ejb-jar.xml and META-INF/jonas-ejb-jar.xml.

    + But if you prefer, you can use JOnAS convention naming and keep your + XML file name : ejb/Account.xml and ejb/jonas-Account.xml, a JAR file named + ejb/Account.jar will be written in the destination directory. + +

    +

    Of course, this naming behavior can be modified by specifying attributes + in the ejbjar task (for example, basejarname, basenameterminator, and flatdestdir) + as well as the iplanet element (for example, suffix). Refer to the appropriate + documentation for more details.

    +

    Parameters:

    +
    ddcreatorWeblogic 4.5.1
    ejbcWeblogic 4.5.1
    iplanet-ejbciPlanet Application Server 6.0
    ejbjarNested Elements
    ejbjarNested Elements
    borlandBorland Application Server 4.5
    jBossjBoss
    iPlanetiPlanet Application Server 6.0
    weblogicWeblogic 5.1 & 6.0
    jonasJOnAS 2.4
    wlrunWeblogic 4.5.1, 5.1 & 6.0
    wlstopWeblogic 4.5.1, 5.1 & 6.0
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    AttributeDescriptionRequired
    destdirThe base directory into which the generated JAR files + will be written. Each JAR file is written in directories which correspond + to their location within the "descriptordir" namespace.Yes
    jonasroot
    +
    The root directory for JOnAS.
    +
    +
    Yes
    +
    +
    workdir
    +
    The work directory to use. Specify where to place +the generated files, before to add to the jar. The directory should be empty. +If omitted, it defaults to a temporary directory.
    +
    +
    No
    +
    +
    cleanworkdir
    +
    Clean the working directory after work. + If omitted, it defaults to false, but your jar will contain + wrong files if you don't clean the workdir yourself.
    + Temporary working directory is always cleaned.
    +
    +
    No
    +
    +
    classpathThe classpath used when generating EJB stubs and skeletons. + If omitted, the classpath specified in the "ejbjar" parent task will + be used. If specified, the classpath elements will be prepended to the + classpath specified in the parent "ejbjar" task (see also the ORB + attribute documentation below). Note that nested "classpath" elements + may also be used.No
    keepgeneratedIndicates whether or not the Java source files which + are generated by GenIC will be saved or automatically deleted. If "yes", the +source files will be retained. If omitted, it defaults to "no". No
    keepgenericThis controls whether the generic file used as input to + GenIC is retained.No, defaults to false
    secpropagModify the RMI Skel. and Stub. to implement the + implicit propagation of the security context (note that + the transactionnal context is always provided). + No, defaults to false.
    orb
    +
    Choose your ORB : RMI, JEREMIE, DAVID, ... If omitted, it defaults +to the one present in classpath. If specified, the corresponding JOnAS JAR is +automatically added to the classpath.
    +
    No
    noGENIC
    +
    If this attribute is set to true, JOnAS's GenIC will + not be run on the EJB jar. Use this if you prefer to + run GenIC at deployment time. +
    No
    +
    suffixString value appended to the JAR filename when creating each JAR. + If omitted, it defaults to ".jar". No
    verbose
    +
    Indicates whether or not to use -verbose switch. If +omitted, it defaults to "no". +
    No
    +
    +
    compiler
    +
    This allows for the selection of a different compiler + to be used for the compilation of the generated Java + files. This could be set, for example, to Jikes to + compile with the Jikes compiler. If this is not set + and the build.compiler property is set + to jikes, the Jikes compiler will be used. If this + is not desired, the value "default" + may be given to use the default compiler
    +
    +
    No
    +
    +
    args
    +
    Add additional args to GenIC.
    +
    +
    No
    +
    +
    +

    As noted above, the jonas element supports additional <classpath> + nested elements.

    +

    Examples

    +

    This example shows ejbjar being used to generate deployment jars using + a JOnAS EJB container. This example requires the naming standard to be + used for the deployment descriptors. Using this format will create a ejb + jar file for each variation of  '*-jar.xml' that is found in the +deployment descriptor directory. 

    +
    +      <ejbjar srcdir="${build.classes}"
    +              descriptordir="${descriptor.dir}">
    +        <jonas destdir="${deploymentjars.dir}"
    +             jonasroot="${jonas.root}"
    +             orb="RMI" />
    +        <include name="**/*.xml"/>
    +        <exclude name="**/jonas-*.xml"/>
    +        <support dir="${build.classes}">
    +             <include name="**/*.class"/>
    +        </support>
    +      </ejbjar>
    +
    +

    +

    This example shows ejbjar being used to generate a single deployment jar + using a JOnAS EJB container. This example does require the deployment + descriptors to use the naming standard. This will create only one ejb jar + file - 'TheEJBJar.jar'.

    +
    +      <ejbjar srcdir="${build.classes}"
    +              descriptordir="${descriptor.dir}"
    +              basejarname="TheEJBJar">
    +        <jonas destdir="${deploymentjars.dir}" 
    +                  jonasroot="${jonas.root}"
    +                  suffix=".jar"
    +                  classpath="${descriptorbuild.classpath}" />
    +        <include name="**/ejb-jar.xml"/>
    +        <exclude name="**/jonas-ejb-jar.xml"/>
    +      </ejbjar>
    +

    Copyright © 2001 Apache Software Foundation. All rights Reserved.

    + + - diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/EjbJar.java b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/EjbJar.java index 1a1a5b957..c53c5ac81 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/EjbJar.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/EjbJar.java @@ -274,6 +274,21 @@ public class EjbJar extends MatchingTask { return tool; } + /** + * Create a jonas nested element used to configure a + * deployment tool for JOnAS server. + * + * @return the deployment tool instance to be configured. + */ + public JonasDeploymentTool createJonas() { + log("JOnAS deployment tools", Project.MSG_VERBOSE); + + JonasDeploymentTool tool = new JonasDeploymentTool(); + tool.setTask(this); + deploymentTools.add(tool); + return tool; + } + /** * Create a nested element for weblogic when using the Toplink * Object- Relational mapping. diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/JonasDeploymentTool.java b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/JonasDeploymentTool.java new file mode 100644 index 000000000..6ab5fc740 --- /dev/null +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/JonasDeploymentTool.java @@ -0,0 +1,599 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "The Jakarta Project", "Ant", and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ +package org.apache.tools.ant.taskdefs.optional.ejb; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.types.Path; +import org.apache.tools.ant.taskdefs.Java; +import org.apache.tools.ant.util.FileUtils; + +import java.io.File; +import java.io.IOException; +import java.util.Hashtable; + + +/** + * The deployment tool to add the jonas specific deployment descriptors to + * the ejb jar file. JONAS only requires one additional file jonas-ejb-jar.xml. + * + * @author Cyrille Morvan, + * Ingenosya France + * @version 1.0 + * @see EjbJar#createJonas + */ +public class JonasDeploymentTool extends GenericDeploymentTool { + + protected static final String JONAS_DD = "jonas-ejb-jar.xml"; + + protected static final String GENIC_CLASS = + "org.objectweb.jonas_ejb.tools.GenWholeIC"; + + protected static final String OLD_GENIC_CLASS = + "org.objectweb.jonas_ejb.tools.GenIC"; + + protected static final String DEFAULT_ORB = "RMI"; + + /** Instance variable that stores the suffix for the jonas jarfile. */ + private String jarSuffix = ".jar"; + + /** + * Instance variable that stores the fully qualified classname + * of the JOnAS GenIC compiler. + **/ + private String genicClass; + + private String additionalArgs = ""; + + /** Instance variable that determines do not delete intermediate generated source files */ + private boolean keepgenerated = false; + + /** as websphere and WebLogic taskes */ + private boolean keepGeneric = false; + + /** Instance variable that determines the JOnAS Root directory */ + private File jonasroot; + + /** Instance variable that determines if we could -secpropag */ + private boolean secpropag = false; + + /** Instance variable that determines the ouput directory */ + private File ouputdirectory; + + /** Instance variable that determines the path to the compiler to use */ + private String compiler; + + /** Instance variable that determines if GenIC is verbose */ + private boolean verbose; + + /** Instance variable that determines the ORB to use (RMI, JEREMIE, DAVID)*/ + private String orb; + + /** clean the working directory after work **/ + private boolean cleanWorkDir = false; + + private boolean noGENIC = false; + + /** + * set the name of the GenIC compiler class. + **/ + public void setGenicClass(final String inGenicClass) { + genicClass = inGenicClass; + } + + + /** + * Set the ORB to construct classpath. + * @param inValue RMI, JEREMIE, DAVID,... + **/ + public void setOrb(final String inValue) { + orb = inValue; + } + + /** + * The compiler (switch -javac) to use. + **/ + public void setCompiler(final String inCompiler) { + compiler = inCompiler; + } + + /** + * Setter used to store the value of keepGeneric + * @param inValue a string, either 'true' or 'false'. + */ + public void setKeepgeneric(boolean inValue) { + this.keepGeneric = inValue; + } + + /** + * GenIC verbose or not + * @param inValue either 'true' or 'false' + **/ + public void setVerbose(final boolean inValue) { + verbose = inValue; + } + + /** + * GenIC run or not. + * @param inValue run or not + **/ + public void setNoGENIC(final boolean inValue) { + noGENIC = inValue; + } + + /** + * Sets whether -keepgenerated is passed to GenIC (that is, + * the .java source files are kept). + * @param inValue either 'true' or 'false' + **/ + public void setKeepgenerated(final boolean inValue) { + keepgenerated = inValue; + } + + /** + * set the jonas root directory (-Dinstall.root=). + * + * @throws BuildException if the file doesn't exist. + **/ + public void setJonasroot(final File inValue) { + jonasroot = inValue; + } + + /** + * Modify the RMI Skel. and Stub. to implement + * the implicit propagation of the transactionnal + * context and security context. + * For JOnAS 2.4 and next. + */ + public void setSecpropag(final boolean inValue) { + secpropag = inValue; + } + + /** + * set the output directory (-d ...). + *
    + * + * It's the GenIC working directory. It's not the + * DestDir, which is the 'jar' destination directory. + * + * @param inValue a file + **/ + public void setOuputdir(final File inValue) { + ouputdirectory = inValue; + } + + + /** + * set the output directory (-d ...). + * Same as setOuputdir(). + *
    + * But do not override setDestDir() + **/ + public void setWorkdir(final File inValue) { + setOuputdir(inValue); + } + + /** + * Clean the specified Work dir after work. + * @param inValue true : clean ; false : not clean + **/ + public void setCleanworkdir(final boolean inValue) { + cleanWorkDir = inValue; + } + + /** + * Setter used to store the suffix for the generated JOnAS jar file. + * @param inString the string to use as the suffix. + **/ + public void setSuffix(String inString) { + this.jarSuffix = inString; + } + + /** + * sets some additional args to send to GenIC. + **/ + public void setArgs(final String inArgs) { + additionalArgs = inArgs; + } + + /** + * Add any vendor specific files which should be included in the + * EJB Jar. + * @param aDdPrefix MyDirectories/MyEjb- or MyDirectories/ + **/ + protected void addVendorFiles(final Hashtable someEjbFiles,final String aDdPrefix) { + // Use Ant Naming convention + File aJonasDD = new File(getConfig().descriptorDir,aDdPrefix + JONAS_DD); + if ( aJonasDD.exists() ) { + someEjbFiles.put(META_DIR + JONAS_DD, aJonasDD); + } else { + // try with JOnAS Naming convention + if( ! addJonasVendorFiles(someEjbFiles,aDdPrefix) ) { + log("Unable to locate JOnAS deployment descriptor. It was expected to be in " + + aJonasDD.getPath() + ". Or please use JOnAS naming convention.", + Project.MSG_WARN); + } + } + } + + /** + * try to add JOnAS specific file, using JOnAS naming convention. + * For example : jonas-Account.xml or jonas-ejb-jar.xml + * @param aDdPrefix MyDirectories/MyEjb- or MyDirectories/ + * @return true if Ok + */ + private boolean addJonasVendorFiles(final Hashtable someEjbFiles,final String aDdPrefix) { + // replace \ by /, remove the last letter ( a dash - ) + final String aCanonicalDD = aDdPrefix.replace('\\', '/').substring(0,aDdPrefix.length()-1); + final int index = aCanonicalDD.lastIndexOf('/') + 1; + String anEjbJarName = aCanonicalDD.substring(index); + if( "ejb".equals( anEjbJarName ) ) { + anEjbJarName = "ejb-jar"; + } + final String aNewDdPrefix = + aDdPrefix.substring(0,index) + "jonas-" + anEjbJarName + ".xml"; + File aConventionNamingJonasDD = new File(getConfig().descriptorDir,aNewDdPrefix); + + log("look for jonas specific file using jonas naming convention " + aConventionNamingJonasDD, + Project.MSG_VERBOSE); + + if( aConventionNamingJonasDD.exists() ) { + someEjbFiles.put(META_DIR + JONAS_DD,aConventionNamingJonasDD); + return true; + } else { + return false; + } + } + + // include javadoc + // Determine the JAR filename (without filename extension) + protected String getJarBaseName(String aDescriptorFileName) { + String aBaseName = null; + EjbJar.Config aConfig = super.getConfig(); + if (aConfig.namingScheme.getValue().equals(EjbJar.NamingScheme.DESCRIPTOR)) { + // try to find JOnAS specific convention name + // ??/MyEJB.xml ( I will find later the ??/jonas-MyEJB.xml file ) + if( aDescriptorFileName.indexOf(aConfig.baseNameTerminator) == -1 ) { + String aCanonicalDescriptor = aDescriptorFileName.replace('\\','/'); + int lastSeparatorIndex = aCanonicalDescriptor.lastIndexOf('/'); + int endBaseName; + if (lastSeparatorIndex != -1) { + endBaseName = aDescriptorFileName.indexOf(".xml", lastSeparatorIndex); + } else { + endBaseName = aDescriptorFileName.indexOf(".xml"); + } + + if (endBaseName != -1) { + aBaseName = aDescriptorFileName.substring(0, endBaseName); + } + } + } + + if( aBaseName == null ) { + // else get standard BaseName + aBaseName = super.getJarBaseName(aDescriptorFileName); + } + return aBaseName; + } + + /** + * Method used to encapsulate the writing of the JAR file. Iterates over the + * filenames/java.io.Files in the Hashtable stored on the instance variable + * ejbFiles. + **/ + protected void writeJar(String baseName, File jarFile, Hashtable files, + String publicId) throws BuildException { + // need to create a generic jar first. + File genericJarFile = super.getVendorOutputJarFile(baseName); + super.writeJar(baseName, genericJarFile, files, publicId); + + // todo ? if (alwaysRebuild || isRebuildRequired(genericJarFile, jarFile)) + buildJOnASJar(baseName,genericJarFile, jarFile,files,publicId); + + if (!keepGeneric) { + log("deleting generic jar " + genericJarFile.toString(), + Project.MSG_VERBOSE); + genericJarFile.delete(); + } + } + + /** + * Helper method invoked by execute() for each JOnAS jar to be built. + * Encapsulates the logic of constructing a java task for calling + * GenIC and executing it. + * @param inBaseName the base name of the jar + * @param inSourceJar java.io.File representing the source (EJB1.1) jarfile. + * @param someFiles list of files in the jar. Add all the new genererated + * files. + * @param inPublicId the link to DTD (to rewrite JAR). + **/ + private void buildJOnASJar(final String inBaseName, + final File inSourceJar,final File inDestJar, + final Hashtable someFiles,String inPublicId) { + org.apache.tools.ant.taskdefs.Java aJavaTask = null; + String aGenIcClassName = genicClass; + boolean isOldGenIC = false; + boolean isTempDirectory = false; + File anOutputDirectoryFile = null; + + // do not call GenIC + // only copy file + if (noGENIC) { + try { + FileUtils.newFileUtils().copyFile(inSourceJar, inDestJar); + return; + } catch (IOException anIOException) { + throw new BuildException("Unable to write EJB jar", anIOException); + } + } + + // call GenIC + try { + aJavaTask = (Java) getTask().getProject().createTask("java"); + aJavaTask.setTaskName("genic"); + if(aGenIcClassName == null) { + aGenIcClassName = GENIC_CLASS; + } else if( OLD_GENIC_CLASS.equals(aGenIcClassName) ){ + isOldGenIC = true; + } + // ClassName + aJavaTask.setClassname(aGenIcClassName); + + // JVM Args + if( jonasroot == null ) { + throw new BuildException("Error : set the jonasroot parameter"); + } else if ( ! jonasroot.isDirectory() ) { + log("jonasroot attribut '" + jonasroot + "' is not a valid directory", + Project.MSG_ERR); + } + aJavaTask.createJvmarg().setValue("-Dinstall.root=" + jonasroot); + File aJavaPolicyFile = new File(jonasroot,"config/java.policy"); + if( aJavaPolicyFile.exists() ) { + aJavaTask.createJvmarg().setValue("-Djava.security.policy=" + + aJavaPolicyFile.toString() ); + } + + // Find output directory + if( ouputdirectory == null ) { + anOutputDirectoryFile = createTempDir(); + isTempDirectory = true; + log("Use temporary output directory : " + + anOutputDirectoryFile, Project.MSG_VERBOSE); + } else { + anOutputDirectoryFile = ouputdirectory; + log("Use temporary specific output directory : " + + anOutputDirectoryFile, Project.MSG_VERBOSE); + } + aJavaTask.createArg().setValue("-d"); + aJavaTask.createArg().setFile(anOutputDirectoryFile); + + // Additionnal args + aJavaTask.createArg().setLine(additionalArgs); + // KeepGenerated + if (keepgenerated) { + aJavaTask.createArg().setValue("-keepgenerated"); + } + + // Verbose + if( verbose ) { + aJavaTask.createArg().setValue("-verbose"); + } + + // -secpropag + if( secpropag ) { + aJavaTask.createArg().setValue("-secpropag"); + } + + // The compiler + if (compiler == null) { + // try to use the compiler specified by build.compiler. Right now we are just going + // to allow Jikes + String aBuildCompiler = getTask().getProject().getProperty("build.compiler"); + if ("jikes".equals(aBuildCompiler) ) { + aJavaTask.createArg().setValue("-javac"); + aJavaTask.createArg().setValue("jikes"); + } + } else { + if( ! "default".equals( compiler ) ) { + aJavaTask.createArg().setValue("-javac"); + aJavaTask.createArg().setLine(compiler); + } + } + + if( ! isOldGenIC ) { + // the add in jar features is buggy... + aJavaTask.createArg().setValue("-noaddinjar"); + } + + aJavaTask.createArg().setValue(inSourceJar.getPath()); + + // try to create the classpath for the correct ORB + Path aClasspath = getCombinedClasspath(); + if( aClasspath == null ) { + aClasspath = new Path(getTask().getProject()); + } + if( orb != null ) { + String aOrbJar = new File(jonasroot,"lib/" + orb + "_jonas.jar").toString(); + String aConfigDir = new File(jonasroot,"config/").toString(); + Path aJOnASOrbPath = new Path(aClasspath.getProject(), + aOrbJar + File.pathSeparator + aConfigDir ); + aClasspath.append( aJOnASOrbPath ); + } else { + log("No ORB propertie setup (RMI, JEREMIE, DAVID).", Project.MSG_WARN); + } + + // append the output directory + aClasspath.append( new Path(aClasspath.getProject(), anOutputDirectoryFile.getPath())); + aJavaTask.setClasspath(aClasspath); + + + aJavaTask.setFork(true); + + log("Calling " + aGenIcClassName + " for " + inSourceJar.toString(), + Project.MSG_VERBOSE); + + if (aJavaTask.executeJava() != 0) { + throw new BuildException("GenIC reported an error"); + } + // Update the list of files. + addAllFiles(anOutputDirectoryFile,"",someFiles); + + // rewrite the jar with the new files + super.writeJar(inBaseName, inDestJar, someFiles, inPublicId); + } catch(BuildException aBuildException) { + throw aBuildException; + } catch (Exception e) { + // Have to catch this because of the semantics of calling main() + String msg = "Exception while calling " + aGenIcClassName + ". Details: " + e.toString(); + throw new BuildException(msg, e); + } finally { + if( isTempDirectory && anOutputDirectoryFile != null) { + dellAllFiles(anOutputDirectoryFile); + } else if( cleanWorkDir && anOutputDirectoryFile != null) { + dellAllFilesInside(anOutputDirectoryFile); + } + } + } + + /** + * Get the vendor specific name of the Jar that will be output. The + * modification date of this jar will be checked against the dependent + * bean classes. + **/ + File getVendorOutputJarFile(final String aBaseName) { + return new File(getDestDir(), aBaseName + jarSuffix); + } + + /** + * Create a free tempory directory for GenIC output. + * @return directory file + * @throws BuildException if impossible to find a tempory directory + **/ + private File createTempDir() { + String theTempDir = System.getProperty("java.io.tmpdir"); + int anIndice = 0; + File aFile = null; + // try 50 times to find a free tempory directory + while( anIndice < 50 && aFile == null) { + aFile = new File(theTempDir,"GenicTemp" + anIndice); + if(aFile.exists()) { + anIndice++; + aFile = null; + } + } + + if( aFile == null ) { + // problem in temp directory + throw new BuildException("Impossible to find a free temp directory for output."); + } else { + aFile.mkdirs(); + return(aFile); + } + } + + + /** + * add all files in anOutputDir + ' / ' + aRootDir to the HashTable someFiles. + * + * @param anOutputDir - start directory + * @param aCurrentDirOrFile - a sub-directory to scan or a file to add. + * @param someFiles - where to add the files + **/ + private void addAllFiles(final File anOutputDir, String aCurrentDirOrFile, Hashtable someFiles) { + File aFile = new File(anOutputDir,aCurrentDirOrFile); + if( aFile.isDirectory() ) { + String aCurrentDir = ""; + if( aCurrentDirOrFile.length() > 0 ) { + aCurrentDir = aCurrentDirOrFile + '/'; + } + File theFiles[] = aFile.listFiles(); + for(int i=0;i