ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From co...@locus.apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/ejb DDCreator.java DDCreatorHelper.java Ejbc.java EjbcHelper.java WLRun.java WLStop.java
Date Wed, 05 Jul 2000 15:36:31 GMT
conor       00/07/05 08:36:29

  Modified:    .        build.xml
               src/main/org/apache/tools/ant/taskdefs defaults.properties
  Added:       src/main/org/apache/tools/ant/taskdefs/optional/ejb
                        DDCreator.java DDCreatorHelper.java Ejbc.java
                        EjbcHelper.java WLRun.java WLStop.java
  Log:
  Tasks for EJB development under Weblogic Server 4.51
  
  This consists of four tasks - (documentation is coming)
  ddcreator - converts deployment descriptors form text description to .ser files
  ejbc - wrapper around weblogic ejbc compiler
  wlrun - a task to run a weblogic server
  wlstop - a task to stop a weblogic server
  
  The last two tasks are most useful when they can be run asynchronously (also coming).
  
  Revision  Changes    Path
  1.31      +8 -1      jakarta-ant/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/build.xml,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- build.xml	2000/07/05 10:02:03	1.30
  +++ build.xml	2000/07/05 15:35:37	1.31
  @@ -41,6 +41,9 @@
                  classname="com.kvisco.xsl.XSLProcessor" />
       <available property="xalan.present" 
                  classname="org.apache.xalan.xslt.XSLTProcessorFactory" />
  +    <available property="ejb.ejbc.present" classname="weblogic.ejbc" />
  +    <available property="ejb.DDCreator.present" classname="weblogic.ejb.utils.DDCreator" />
  +    <available property="ejb.wls.present" classname="weblogic.Server" />
     </target>
   
     <!-- =================================================================== -->
  @@ -64,11 +67,15 @@
              deprecation="off"
              optimize="on" >
         <include name="**/*.java"/>
  +      <exclude name="**/version.txt" />
         <exclude name="**/Script.java" unless="bsf.present" />
         <exclude name="**/NetRexxC.java" unless="netrexx.present" />
         <exclude name="**/XslpLiaison.java" unless="xslp.present" />
         <exclude name="**/XalanLiaison.java" unless="xalan.present" />
  -      <exclude name="**/version.txt" />
  +      <exclude name="**/Ejbc*.java" unless="ejb.ejbc.present" />
  +      <exclude name="**/DDCreator*.java" unless="ejb.DDCreator.present" />
  +      <exclude name="**/WLRun.java" unless="ejb.wls.present" />
  +      <exclude name="**/WLStop.java" unless="ejb.wls.present" />
       </javac>
    
       <copydir src="${src.dir}" dest="${build.classes}">
  
  
  
  1.17      +4 -0      jakarta-ant/src/main/org/apache/tools/ant/taskdefs/defaults.properties
  
  Index: defaults.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/defaults.properties,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- defaults.properties	2000/06/29 10:23:41	1.16
  +++ defaults.properties	2000/07/05 15:35:51	1.17
  @@ -38,6 +38,10 @@
   script=org.apache.tools.ant.taskdefs.optional.Script
   netrexxc=org.apache.tools.ant.taskdefs.optional.NetRexxC
   renameext=org.apache.tools.ant.taskdefs.optional.RenameExtensions
  +ejbc=org.apache.tools.ant.taskdefs.optional.ejb.Ejbc
  +ddcreator=org.apache.tools.ant.taskdefs.optional.ejb.DDCreator
  +wlrun=org.apache.tools.ant.taskdefs.optional.ejb.WLRun
  +wlstop=org.apache.tools.ant.taskdefs.optional.ejb.WLStop
   
   # deprecated ant tasks (kept for back compatibility)
   javadoc2=org.apache.tools.ant.taskdefs.Javadoc
  
  
  
  1.1                  jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/ejb/DDCreator.java
  
  Index: DDCreator.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 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", "Tomcat", 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
   * <http://www.apache.org/>.
   */
  package org.apache.tools.ant.taskdefs.optional.ejb;
  
  import org.apache.tools.ant.*;
  import org.apache.tools.ant.taskdefs.*;
  
  import java.io.File;
  
  /**
   * Build a serialised deployment descriptor given a text file description of the 
   * descriptor in the format supported by WebLogic.
   *
   * This ant task is a front end for the weblogic DDCreator tool.
   *
   * @author <a href="mailto:conor@cortexebusiness.com.au">Conor MacNeill</a>, Cortex ebusiness Pty Limited
   */
  public class DDCreator extends MatchingTask {
      /**
       * The root directory of the tree containing the textual deployment desciptors. The actual
       * deployment descriptor files are selected using include and exclude constructs
       * on the EJBC task, as supported by the MatchingTask superclass.
       */
      private File descriptorDirectory;
      
      /**
       * The directory where generated serialised deployment descriptors are placed.
       */
      private File generatedFilesDirectory;
          
      /**
       * The classpath to be used in the weblogic ejbc calls. It must contain the weblogic
       * classes necessary fro DDCreator <b>and</b> the implementation classes of the 
       * home and remote interfaces.
       */
      private String classpath;
      
      /**
       * Do the work.
       *
       * The work is actually done by creating a helper task. This approach allows
       * the classpath of the helper task to be set. Since the weblogic tools require
       * the class files of the project's home and remote interfaces to be available in
       * the classpath, this also avoids having to start ant with the class path of the
       * project it is building.
       *
       * @exception BuildException if someting goes wrong with the build
       */
      public void execute() throws BuildException {
          if (!descriptorDirectory.isDirectory()) {
              throw new BuildException("descriptors directory " + descriptorDirectory.getPath() + 
                                       " is not valid");
          }
          if (!generatedFilesDirectory.isDirectory()) {
              throw new BuildException("dest directory " + generatedFilesDirectory.getPath() + 
                                       " is not valid");
          }
                                      
          String args = descriptorDirectory + " " + generatedFilesDirectory;
              
          // get all the files in the descriptor directory
          DirectoryScanner ds = super.getDirectoryScanner(descriptorDirectory);
      
          String[] files = ds.getIncludedFiles();
  
          for (int i = 0; i < files.length; ++i) {
              args += " " + files[i];
          }
              
          String systemClassPath = System.getProperty("java.class.path");
          String execClassPath = project.translatePath(systemClassPath + ":" + classpath);
          Java ddCreatorTask = (Java)project.createTask("java");
          ddCreatorTask.setFork("yes");
          ddCreatorTask.setClassname("org.apache.tools.ant.taskdefs.optional.ejb.DDCreatorHelper");
          ddCreatorTask.setArgs(args);
          ddCreatorTask.setClasspath(execClassPath);                         
          if (ddCreatorTask.executeJava() != 0) {                         
              throw new BuildException("Execution of ddcreator helper failed");
          }
      }
  
      /**
       * Set the directory from where the text descriptions of the deployment descriptors are
       * to be read.
       *
       * @param dirName the name of the directory containing the text deployment descriptor files.
       */
      public void setDescriptors(String dirName) {
          descriptorDirectory = new File(dirName);
      }
      
      /**
       * Set the directory into which the serialised deployment descriptors are to 
       * be written.
       *
       * @param dirName the name of the directory into which the serialised deployment
       *                descriptors are written.
       */
      public void setDest(String dirName) {
          generatedFilesDirectory = new File(dirName);
      }
  
      /**
       * Set the classpath to be used for this compilation.
       *
       * @param s the classpath to use for the ddcreator tool.
       */
      public void setClasspath(String s) {
          this.classpath = project.translatePath(s);
      }
  }
  
  
  
  1.1                  jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/ejb/DDCreatorHelper.java
  
  Index: DDCreatorHelper.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 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", "Tomcat", 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
   * <http://www.apache.org/>.
   */
  package org.apache.tools.ant.taskdefs.optional.ejb;
  
  import java.io.File;
  
  /**
   * A helper class which performs the actual work of the ddcreator task.
   *
   * This class is run with a classpath which includes the weblogic tools and the home and remote
   * interface class files referenced in the deployment descriptors being built.
   *
   * @author <a href="mailto:conor@cortexebusiness.com.au">Conor MacNeill</a>, Cortex ebusiness Pty Limited
   */
  public class DDCreatorHelper {
      /**
       * The root directory of the tree containing the textual deployment desciptors. 
       */
      private File descriptorDirectory;
      
      /**
       * The directory where generated serialised desployment descriptors are written.
       */
      private File generatedFilesDirectory;
  
      /**
       * The descriptor text files for which a serialised descriptor is to be created.
       */
      String[] descriptors; 
  
      /**
       * The main method.
       *
       * The main method creates an instance of the DDCreatorHelper, passing it the 
       * args which it then processes.
       */    
      public static void main(String[] args) throws Exception {
          DDCreatorHelper helper = new DDCreatorHelper(args);
          helper.process();
      }
    
      /**
       * Initialise the helper with the command arguments.
       *
       */
      private DDCreatorHelper(String[] args) {
          int index = 0;
          descriptorDirectory = new File(args[index++]);
          generatedFilesDirectory = new File(args[index++]);
          
          descriptors = new String[args.length - index];
          for (int i = 0; index < args.length; ++i) {
              descriptors[i] = args[index++];
          }
      }
      
      /**
       * Do the actual work.
       *
       * The work proceeds by examining each descriptor given. If the serialised
       * file does not exist or is older than the text description, the weblogic
       * DDCreator tool is invoked directly to build the serialised descriptor.
       */    
      private void process() throws Exception {
          for (int i = 0; i < descriptors.length; ++i) {
              String descriptorName = descriptors[i];
              File descriptorFile = new File(descriptorDirectory, descriptorName);
              int extIndex = descriptorName.lastIndexOf(".");
              String serName = null;
              if (extIndex != -1) {
                  serName = descriptorName.substring(0, extIndex) + ".ser";
              }
              else {
                  serName = descriptorName + ".ser";
              }
              File serFile = new File(generatedFilesDirectory, serName);
                  
              // do we need to regenerate the file
              if (!serFile.exists() || serFile.lastModified() < descriptorFile.lastModified()) {
                  
                  String[] args = {"-noexit", 
                                   "-d", generatedFilesDirectory.getPath(),
                                   "-outputfile", serFile.getName(),
                                   descriptorFile.getPath()};
                  try {
                      weblogic.ejb.utils.DDCreator.main(args);
                  }
                  catch (Exception e) {
                      // there was an exception - run with no exit to get proper error
                      String[] newArgs = {"-d", generatedFilesDirectory.getPath(),
                                   "-outputfile", serFile.getName(),
                                   descriptorFile.getPath()};
                      weblogic.ejb.utils.DDCreator.main(newArgs);
                  }
              }
          }
      }
  }
  
  
  
  1.1                  jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/ejb/Ejbc.java
  
  Index: Ejbc.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 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", "Tomcat", 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
   * <http://www.apache.org/>.
   */
  package org.apache.tools.ant.taskdefs.optional.ejb;
  
  
  import org.apache.tools.ant.*;
  import org.apache.tools.ant.taskdefs.*;
  
  import java.io.File;
  
  /**
   * Build EJB support classes using Weblogic's ejbc tool from a directory containing
   * a set of deployment descriptors.
   
   *
   * @author <a href="mailto:conor@cortexebusiness.com.au">Conor MacNeill</a>, Cortex ebusiness Pty Limited
   */
  public class Ejbc extends MatchingTask {
      /**
       * The root directory of the tree containing the serialised deployment desciptors. The actual
       * deployment descriptor files are selected using include and exclude constructs
       * on the ejbc task provided by the MatchingTask superclass.
       */
      private File descriptorDirectory;
      
      /**
       * The directory where generated files are placed.
       */
      private File generatedFilesDirectory;
      
      /**
       * The name of the manifest file generated for the EJB jar.
       */
      private File generatedManifestFile;
      
      /**
       * The classpath to be used in the weblogic ejbc calls. It must contain the weblogic
       * classes <b>and</b> the implementation classes of the home and remote interfaces.
       */
      private String classpath;
      
      /**
       * The source directory for the home and remote interfaces. This is used to determine if
       * the generated deployment classes are out of date.
       */
      private File sourceDirectory;
      
      /**
       * Do the work.
       *
       * The work is actually done by creating a separate JVM to run a helper task. 
       * This approach allows the classpath of the helper task to be set. Since the 
       * weblogic tools require the class files of the project's home and remote 
       * interfaces to be available in the classpath, this also avoids having to 
       * start ant with the class path of the project it is building.
       *
       * @exception BuildException if someting goes wrong with the build
       */
      public void execute() throws BuildException {
          if (!descriptorDirectory.isDirectory()) {
              throw new BuildException("descriptors directory " + descriptorDirectory.getPath() + 
                                       " is not valid");
          }
          if (!generatedFilesDirectory.isDirectory()) {
              throw new BuildException("dest directory " + generatedFilesDirectory.getPath() + 
                                       " is not valid");
          }
                                      
          if (!sourceDirectory.isDirectory()) {
              throw new BuildException("src directory " + sourceDirectory.getPath() + 
                                       " is not valid");
          }
          
          String systemClassPath = System.getProperty("java.class.path");
          String execClassPath = project.translatePath(systemClassPath + ":" + classpath +
                                                           ":" + generatedFilesDirectory);
          // get all the files in the descriptor directory
          DirectoryScanner ds = super.getDirectoryScanner(descriptorDirectory);
     
          String[] files = ds.getIncludedFiles();
  
          Java helperTask = (Java)project.createTask("java");
          helperTask.setFork("yes");
          helperTask.setClassname("org.apache.tools.ant.taskdefs.optional.ejb.EjbcHelper");
          String args = "";
          args += " " + descriptorDirectory;
          args += " " + generatedFilesDirectory;
          args += " " + sourceDirectory;
          args += " " + generatedManifestFile;
          for (int i = 0; i < files.length; ++i) {
              args += " " + files[i];
          }
                                      
          helperTask.setArgs(args);
          helperTask.setClasspath(execClassPath);
          if (helperTask.executeJava() != 0) {                         
              throw new BuildException("Execution of ejbc helper failed");
          }
      }
  
      /**
       * Set the directory from where the serialised deployment descriptors are
       * to be read.
       *
       * @param dirName the name of the directory containing the serialised deployment descriptors.
       */
      public void setDescriptors(String dirName) {
          descriptorDirectory = new File(dirName);
      }
      
      /**
       * Set the directory into which the support classes, RMI stubs, etc are to be written
       *
       * @param dirName the name of the directory into which code is generated
       */
      public void setDest(String dirName) {
          generatedFilesDirectory = new File(dirName);
      }
  
      /**
       * Set the generated manifest file. 
       *
       * For each EJB that is processed an entry is created in this file. This can then be used
       * to create a jar file for dploying the beans.
       *
       * @param manfestFilename the name of the manifest file to be generated.
       */
      public void setManifest(String manifestFilename) {
          generatedManifestFile = new File(manifestFilename);
      }
      
      /**
       * Set the classpath to be used for this compilation.
       */
      public void setClasspath(String s) {
          this.classpath = project.translatePath(s);
      }
  
      /**
       * Set the directory containing the source code for the home interface, remote interface
       * and public key class definitions.
       *
       * @param dirName the directory containg the source tree for the EJB's interface classes.
       */
      public void setSrc(String dirName) {
          sourceDirectory = new File(dirName);
      }
                  
  }
  
  
  
  1.1                  jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/ejb/EjbcHelper.java
  
  Index: EjbcHelper.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 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", "Tomcat", 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
   * <http://www.apache.org/>.
   */
  package org.apache.tools.ant.taskdefs.optional.ejb;
  
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.ObjectInputStream;
  import java.io.IOException;
  import java.io.PrintWriter;
  import java.io.FileWriter;
  
  import javax.ejb.deployment.EntityDescriptor;
  import javax.ejb.deployment.DeploymentDescriptor;
  
  
  /**
   * A helper class which performs the actual work of the ejbc task.
   *
   * This class is run with a classpath which includes the weblogic tools and the home and remote
   * interface class files referenced in the deployment descriptors being processed.
   *
   * @author <a href="mailto:conor@cortexebusiness.com.au">Conor MacNeill</a>, Cortex ebusiness Pty Limited
   */
  public class EjbcHelper {
      /**
       * The root directory of the tree containing the serialised deployment desciptors. 
       */
      private File descriptorDirectory;
      
      /**
       * The directory where generated files are placed.
       */
      private File generatedFilesDirectory;
      
      /**
       * The name of the manifest file generated for the EJB jar.
       */
      private File manifestFile;
      
      /**
       * The classpath to be used in the weblogic ejbc calls. It must contain the weblogic
       * classes <b>and</b> the implementation classes of the home and remote interfaces.
       */
      private String classpath;
      
      /**
       * The source directory for the home and remote interfaces. This is used to determine if
       * the generated deployment classes are out of date.
       */
      private File sourceDirectory;
     
      /**
       * The names of the serialised deployment descriptors
       */
      String[] descriptors; 
  
      /**
       * Command line interface for the ejbc helper task.
       */    
      public static void main(String[] args) throws Exception {
          EjbcHelper helper = new EjbcHelper(args);
          helper.process();
      }
  
      /**
       * Initialise the EjbcHelper by reading the command arguments.
       */    
      private EjbcHelper(String[] args) {
          int index = 0;
          descriptorDirectory = new File(args[index++]);
          generatedFilesDirectory = new File(args[index++]);
          sourceDirectory = new File(args[index++]);
          manifestFile = new File(args[index++]);
          
          descriptors = new String[args.length - index];
          for (int i = 0; index < args.length; ++i) {
              descriptors[i] = args[index++];
          }
      }
  
      /**
       * Determine if the weblogic EJB support classes need to be regenerated
       * for a given deployment descriptor.
       *
       * This process attempts to determine if the support classes need to be
       * rebuilt. It does this by examining only some of the support classes 
       * which are typically generated. If the ejbc task is interrupted generating
       * the support classes for a bean, all of the support classes should be removed
       * to force regeneration of the support classes.
       *
       * @param descriptorFile the serialised deployment descriptor
       *
       * @return true if the support classes need to be regenerated.
       *
       * @throws IOException if the descriptor file cannot be closed.
       */
      private boolean isRegenRequired(File descriptorFile) throws IOException {
          // read in the descriptor. Under weblogic, the descriptor is a weblogic
          // specific subclass which has references to the implementation classes.
          // These classes must, therefore, be in the classpath when the deployment
          // descriptor is loaded from the .ser file
          FileInputStream fis = null;
          try {
              fis = new FileInputStream(descriptorFile);
              ObjectInputStream ois = new ObjectInputStream(fis);
              DeploymentDescriptor dd = (DeploymentDescriptor)ois.readObject();
              fis.close();
              
              String homeInterfacePath = dd.getHomeInterfaceClassName().replace('.', '/') + ".java";
              String remoteInterfacePath = dd.getRemoteInterfaceClassName().replace('.', '/') + ".java";
              String primaryKeyClassPath = null;
              if (dd instanceof EntityDescriptor) {
                  primaryKeyClassPath = ((EntityDescriptor)dd).getPrimaryKeyClassName().replace('.', '/') + ".java";;
              }
          
              File homeInterfaceSource = new File(sourceDirectory, homeInterfacePath);
              File remoteInterfaceSource = new File(sourceDirectory, remoteInterfacePath);
              File primaryKeyClassSource = null;
              if (primaryKeyClassPath != null) {
                  primaryKeyClassSource = new File(sourceDirectory, remoteInterfacePath);
              }
              
              // are any of the above out of date. 
              // we find the implementation classes and see if they are older than any
              // of the above or the .ser file itself.
              String beanClassBase = dd.getEnterpriseBeanClassName().replace('.', '/');
              File ejbImplentationClass 
                  = new File(generatedFilesDirectory, beanClassBase + "EOImpl.class");
              File homeImplementationClass 
                  = new File(generatedFilesDirectory, beanClassBase + "HomeImpl.class");
              File beanStubClass 
                  = new File(generatedFilesDirectory, beanClassBase + "EOImpl_WLStub.class");
                  
              // if the implementation classes don;t exist regenerate                
              if (!ejbImplentationClass.exists() || !homeImplementationClass.exists() ||
                      !beanStubClass.exists()) {
                  return true;
              }
                  
              // Is the ser file or any of the source files newer then the class files.
              // firstly find the oldest of the two class files.
              long classModificationTime = ejbImplentationClass.lastModified();
              if (homeImplementationClass.lastModified() < classModificationTime) {
                  classModificationTime = homeImplementationClass.lastModified();
              }
              if (beanStubClass.lastModified() < classModificationTime) {
                  classModificationTime = beanStubClass.lastModified();
              }
              
              if (descriptorFile.lastModified() > classModificationTime ||
                      homeInterfaceSource.lastModified() > classModificationTime ||
                      remoteInterfaceSource.lastModified() > classModificationTime) {
                  return true;
              }
              
              if (primaryKeyClassSource != null && 
                      primaryKeyClassSource.lastModified() > classModificationTime) {
                  return true;
              }
          }
          catch (Throwable descriptorLoadException) {
              System.out.println("Exception occurred reading " + descriptorFile.getName() + " - continuing");
              // any problems - just regenerate
              return true;
          }
          finally {
              if (fis != null) {
                  fis.close();
              }
          }
          
          return false;
      }
  
      /**
       * Process the descriptors in turn generating support classes for each and a manifest
       * file for all of the beans.
       */            
      private void process() throws Exception {
          String manifest = "Manifest-Version: 1.0\n\n";
          for (int i = 0; i < descriptors.length; ++i) {
              String descriptorName = descriptors[i];
              File descriptorFile = new File(descriptorDirectory, descriptorName);
              
              if (isRegenRequired(descriptorFile)) {
                  System.out.println("Running ejbc for " + descriptorFile.getName());
                  regenerateSupportClasses(descriptorFile);
              }
              else {
                  System.out.println(descriptorFile.getName() + " is up to date");
              }
              manifest += "Name: " + descriptorFile.getName() + "\nEnterprise-Bean: True\n\n";
          }
          
          FileWriter fw = new FileWriter(manifestFile);
          PrintWriter pw = new PrintWriter(fw);
          pw.print(manifest);
          fw.flush();
          fw.close();
      }
  
      /**
       * Perform the weblogic.ejbc call to regenerate the support classes.
       *
       * Note that this method relies on an undocumented -noexit option to the 
       * ejbc tool to stop the ejbc tool exiting the VM altogether.
       */
      private void regenerateSupportClasses(File descriptorFile) throws Exception {
          // create a Java task to do the rebuild
  
          String[] args = {"-noexit",
                           "-keepgenerated",
                           "-d", generatedFilesDirectory.getPath(),
                           descriptorFile.getPath()};
          
          try {
              weblogic.ejbc.main(args);
          }
          catch (Exception e) {
              // run with no exit for better reporting
              String[] newArgs = {"-keepgenerated",
                           "-d", generatedFilesDirectory.getPath(),
                           descriptorFile.getPath()};
              weblogic.ejbc.main(newArgs);
          }
      }
  }
  
  
  
  1.1                  jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WLRun.java
  
  Index: WLRun.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 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", "Tomcat", 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
   * <http://www.apache.org/>.
   */
  package org.apache.tools.ant.taskdefs.optional.ejb;
  
  
  import org.apache.tools.ant.*;
  import org.apache.tools.ant.taskdefs.*;
  
  import java.io.File;
  
  /**
   * Execute a Weblogic server.
   
   *
   * @author <a href="mailto:conor@cortexebusiness.com.au">Conor MacNeill</a>, Cortex ebusiness Pty Limited
   */
  public class WLRun extends Task {
      static private final String defaultPolicyFile = "weblogic.policy";
  
      /**
       * The classpath to be used in the weblogic ejbc calls. It must contain the weblogic
       * classes <b>and</b> the implementation classes of the home and remote interfaces.
       */
      private String classpath;
  
      /**
       * The weblogic classpath to the be used when running weblogic.
       */
      private String weblogicClasspath = "";
      
      /**
       * The security policy to use when running the weblogic server
       */
      private String securityPolicy;
      
      /**
       * The weblogic system home directory
       */
      private File weblogicSystemHome;
      
      /**
       * The name of the weblogic server - used to select the server's directory in the 
       * weblogic home directory.
       */
      private String weblogicSystemName = "myserver";
      
      /**
       * The file containing the weblogic properties for this server.
       */
      private String weblogicPropertiesFile = "weblogic.properties";
      
      /**
       * Do the work.
       *
       * The work is actually done by creating a separate JVM to run a helper task. 
       * This approach allows the classpath of the helper task to be set. Since the 
       * weblogic tools require the class files of the project's home and remote 
       * interfaces to be available in the classpath, this also avoids having to 
       * start ant with the class path of the project it is building.
       *
       * @exception BuildException if someting goes wrong with the build
       */
      public void execute() throws BuildException {
          if (weblogicSystemHome == null) {
              throw new BuildException("weblogic home must be set");
          }
          if (!weblogicSystemHome.isDirectory()) {
              throw new BuildException("weblogic home directory " + weblogicSystemHome.getPath() + 
                                       " is not valid");
          }
                  
          File propertiesFile = new File(weblogicSystemHome, weblogicPropertiesFile);
          
          if (!propertiesFile.exists()) {
              throw new BuildException("Properties file " + weblogicPropertiesFile +
                                       " not found in weblogic home " + weblogicSystemHome);
          }
  
          File securityPolicyFile = null;
          if (securityPolicy == null) {
              securityPolicyFile = new File(weblogicSystemHome, defaultPolicyFile);
          }
          else {
              securityPolicyFile = new File(weblogicSystemHome, securityPolicy);
          }
          
          if (!securityPolicyFile.exists()) {
              throw new BuildException("Security policy " + securityPolicyFile +
                                       " was not found.");
          }
  
          String execClassPath = project.translatePath(classpath);
              
          Java weblogicServer = (Java)project.createTask("java");
          weblogicServer.setFork("yes");
          weblogicServer.setClassname("weblogic.Server");
          String jvmArgs = "";
          if (weblogicClasspath != null) {
              jvmArgs += "-Dweblogic.class.path=" + project.translatePath(weblogicClasspath);
          }
              
          jvmArgs += " -Djava.security.manager -Djava.security.policy==" + securityPolicyFile;
          jvmArgs += " -Dweblogic.system.home=" + weblogicSystemHome;
          jvmArgs += " -Dweblogic.system.name=" + weblogicSystemName;
          jvmArgs += " -Dweblogic.system.propertiesFile=" + weblogicPropertiesFile;
  
          weblogicServer.setJvmargs(jvmArgs);
          weblogicServer.setClasspath(execClassPath);                         
          if (weblogicServer.executeJava() != 0) {                         
              throw new BuildException("Execution of weblogic server failed");
          }
      }
  
      
      /**
       * Set the classpath to be used for this compilation.
       *
       * @param s the classpath to use when executing the weblogic task.
       */
      public void setClasspath(String s) {
          this.classpath = project.translatePath(s);
      }
      
      /**
       * Set the weblogic classpath.
       *
       * The weblogic classpath is used by weblogic to support dynamic class loading.
       *
       * @param weblogicClasspath the weblogic classpath
       */
      public void setWlclasspath(String weblogicClasspath) {
          this.weblogicClasspath = weblogicClasspath;
      }
      
      /**
       * Set the security policy for this invocation of weblogic.
       *
       * @param securityPolicy the security policy to use.
       */
      public void setPolicy(String securityPolicy) {
          this.securityPolicy = securityPolicy;
      }
      
      /**
       * The location where weblogic lives.
       *
       * @param weblogicHome the home directory of weblogic.
       *
       */
      public void setHome(String weblogicHome) {
          weblogicSystemHome = new File(weblogicHome);
      }
      
      /**
       * Set the name of the server to run
       *
       * @param systemName the name of the server.
       */
      public void setName(String serverName) {
          this.weblogicSystemName = serverName;
      }
      
      /**
       * Set the properties file to use.
       *
       * The location of the properties file is relative to the weblogi system home
       *
       * @param propertiesFilename the properties file name
       */
      public void setProperties(String propertiesFilename) {
          this.weblogicPropertiesFile = propertiesFilename;
      }
  }
  
  
  
  1.1                  jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WLStop.java
  
  Index: WLStop.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 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", "Tomcat", 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
   * <http://www.apache.org/>.
   */
  package org.apache.tools.ant.taskdefs.optional.ejb;
  
  
  import org.apache.tools.ant.*;
  import org.apache.tools.ant.taskdefs.*;
  
  import java.io.File;
  
  /**
   * Shutdown a Weblogic server.
   
   *
   * @author <a href="mailto:conor@cortexebusiness.com.au">Conor MacNeill</a>, Cortex ebusiness Pty Limited
   */
  public class WLStop extends Task {
      /**
       * The classpath to be used. It must contains the weblogic.Admin class.
       */
      private String classpath;
  
      /**
       * The weblogic username to use to request the shutdown.
       */
      private String username;
      
      /**
       * The password to use to shutdown the weblogic server.
       */
      private String password;
      
      /**
       * The URL which the weblogic server is listening on.
       */
      private String serverURL;
      
      /**
       * The delay (in seconds) to wait before shutting down.
       */
      private int delay = 0;
      
      /**
       * Do the work.
       *
       * The work is actually done by creating a separate JVM to run the weblogic admin task
       * This approach allows the classpath of the helper task to be set. 
       *
       * @exception BuildException if someting goes wrong with the build
       */
      public void execute() throws BuildException {
          if (username == null || password == null) {
              throw new BuildException("weblogic username and password must both be set");
          }
              
          if (serverURL == null) {
              throw new BuildException("The url of the weblogic server must be provided.");
          }
  
          String execClassPath = project.translatePath(classpath);
          
          Java weblogicAdmin = (Java)project.createTask("java");
          weblogicAdmin.setFork("yes");
          weblogicAdmin.setClassname("weblogic.Admin");
          String args = serverURL + " SHUTDOWN " + username + " " + password + " " + delay;
  
          weblogicAdmin.setArgs(args);
          weblogicAdmin.setClasspath(execClassPath);                         
          weblogicAdmin.execute();
      }
      
      /**
       * Set the classpath to be used for this compilation.
       *
       * @param s the classpath to use when executing the weblogic admin task.
       */
      public void setClasspath(String s) {
          this.classpath = project.translatePath(s);
      }
      
      /**
       * Set the username to use to request shutdown of the server.
       *
       * @param s the username.
       */
      public void setUser(String s) {
          this.username = s;
      }
      
      /**
       * Set the password to use to request shutdown of the server.
       *
       * @param s the password.
       */
      public void setPassword(String s) {
          this.password = s;
      }
      
      /**
       * Set the URL to which the weblogic server is listening.
       *
       * @param s the url.
       */
      public void setUrl(String s) {
          this.serverURL = s;
      }
  
  
      /**
       * Set the delay (in seconds) before shutting down the server.
       *
       * @param s the selay.
       */
      public void setDelay(String s) {
          delay = Integer.parseInt(s);
      }
  }
  
  
  

Mime
View raw message