Return-Path: Mailing-List: contact ant-dev-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list ant-dev@jakarta.apache.org Received: (qmail 11010 invoked from network); 7 May 2000 12:57:20 -0000 Received: from fepa.mail.ozemail.net (203.2.192.101) by locus.apache.org with SMTP; 7 May 2000 12:57:20 -0000 Received: from cognetnt (1Cust205.tnt3.syd2.da.uu.net [63.12.2.205]) by fepa.mail.ozemail.net (8.9.0/8.6.12) with SMTP id WAA15475 for ; Sun, 7 May 2000 22:57:06 +1000 (EST) From: "Conor MacNeill" To: "Ant-Dev Apache." Subject: Tasks for ejbc compile of weblogic EJBs Date: Sun, 7 May 2000 22:56:07 +1000 Message-ID: <000f01bfb823$9c736e80$80dc1fcb@cognet.com.au> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0010_01BFB877.6E1F7E80" X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook 8.5, Build 4.71.2173.0 Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6600 X-Spam-Rating: locus.apache.org 1.6.2 0/1000/N This is a multi-part message in MIME format. ------=_NextPart_000_0010_01BFB877.6E1F7E80 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Hi, Attached are two task definitions and a small set of patches to allow you to use ant to build weblogic EJBs. I developed these tasks for building EJBs here at Cortex and Cortex have agreed to let me give them to the ant project. The new code consists of two optional ant tasks: ddcreator and ejbc. ddcreator takes a set of deployment descriptor definitions according to the weblogic definition language and generates the serialised deployment descriptors, while ejbc takes the serialised deployment descriptor and generates the various EJB support files required by Weblogic, including the RMI stubs and skeletons. Both tasks only generate a result if it is out of date with respect to the source. Example usage of the ddcreator task would be where descriptors is the directory where the text descriptor defintions are located dest is the directory where the serialised deployment descriptors are written classpath should include the weblogic tools and the classes containing the home and remote interfaces for the various EJBs The ejbc task is a little more complicated. where descriptors in this case is the directory where the serialised deployment descriptors are located src is the directory containing the source defining the home and remote interfaces dest is the directory where the generated support classes are written manifest is a generated jar manifest file defining all of the EJBs to be included classpath should again contains the weblogic tools plus the home, remote and bean classes. Both tasks are MatchingTasks and the include element is generally used to select the appropriate files. The implementation of these tasks supports the way we have been building EJBs at Cortex. In particular I set the ejbc options to those we currently use. If it doesn't fit with other organisations, let me know. Also this is geared to WebLogic 4.5. I have not yet looked at 5.1. The implementation details of the two tasks are worth looking at a little bit more closely. Both tasks are implemented as an ant task with a separate helper class which is executed in a separate JVM. This is done because I wanted to control the classpath under which the weblogic tools were executed. The weblogic tools generally require the classpath to include the class files for the home and remote interfaces of the beans you are developing. I did not want to have to startup ant with its classpath including the project it is compiling. Thus the ant tasks simply delegate all the work to the helper in a separate JVM. To create that JVM and have its output pumped into the project log, I used a Java task object. I needed to modify the ant Task object, however, to make the setProject method public so I could connect the project to the Java task. I also added a validateDirectory method which allows any task to validate that a given File object represents a directory and that the directory exists. This could probably be used by a few other tasks. Let me know what you think, especially if you are using WebLogic. Cheers Conor -- Conor MacNeill conor@cortexebusiness.com.au Cortex ebusiness Pty Limited ------=_NextPart_000_0010_01BFB877.6E1F7E80 Content-Type: text/plain; name="diffs.txt" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="diffs.txt" ? src/main/org/apache/tools/ant/taskdefs/optional/DDCreator.java ? src/main/org/apache/tools/ant/taskdefs/optional/DDCreatorHelper.java ? src/main/org/apache/tools/ant/taskdefs/optional/ejbc.java ? src/main/org/apache/tools/ant/taskdefs/optional/ejbcHelper.java Index: build.xml =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /home/cvspublic/jakarta-ant/build.xml,v retrieving revision 1.21 diff -u -r1.21 build.xml --- build.xml 2000/04/27 19:52:52 1.21 +++ build.xml 2000/05/07 12:04:01 @@ -37,6 +37,8 @@ + + =20 @@ -60,6 +62,8 @@ optimize=3D"on" > + + =20 Index: src/main/org/apache/tools/ant/Task.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: = /home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/Task.java,v retrieving revision 1.5 diff -u -r1.5 Task.java --- src/main/org/apache/tools/ant/Task.java 2000/04/26 19:09:17 1.5 +++ src/main/org/apache/tools/ant/Task.java 2000/05/07 12:04:02 @@ -54,6 +54,8 @@ =20 package org.apache.tools.ant; =20 +import java.io.File; + /** * Base class for all tasks. */ @@ -73,7 +75,7 @@ * * @param project Project in whose scope this task belongs. */ - void setProject(Project project) { + public void setProject(Project project) { this.project =3D project; } =20 @@ -124,5 +126,27 @@ public void setLocation(Location location) { this.location =3D location; } + =20 + /** + * Validate that a given directory exists and is in fact a = directory. + * + * If the directory does not exists or is not a directory, a build = exception + * is thrown. + * + * @param dir the directory to be validated + * @param usage indicates the role the directory is being used for = (source, dest, etc) + * + * @throws BuildException if the given directory is not valid. + */ + protected void validateDirectory(File dir, String usage) { + if (!dir.exists()) {=20 + throw new BuildException("The " + usage + " directory, " + = dir.getName() + ", does not exist."); + } + =20 + if (!dir.isDirectory()) { + throw new BuildException("The " + usage + " directory, " + = dir.getName() + ", is not a directory"); + } + } + =20 } =20 Index: src/main/org/apache/tools/ant/taskdefs/defaults.properties =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: = /home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/defaul= ts.properties,v retrieving revision 1.10 diff -u -r1.10 defaults.properties --- src/main/org/apache/tools/ant/taskdefs/defaults.properties = 2000/03/23 03:40:32 1.10 +++ src/main/org/apache/tools/ant/taskdefs/defaults.properties = 2000/05/07 12:04:03 @@ -32,6 +32,8 @@ script=3Dorg.apache.tools.ant.taskdefs.optional.Script netrexxc=3Dorg.apache.tools.ant.taskdefs.optional.NetRexxC renameext=3Dorg.apache.tools.ant.taskdefs.optional.RenameExtensions +ejbc=3Dorg.apache.tools.ant.taskdefs.optional.ejbc +ddcreator=3Dorg.apache.tools.ant.taskdefs.optional.DDCreator =20 # deprecated ant tasks (kept for back compatibility) javadoc2=3Dorg.apache.tools.ant.taskdefs.Javadoc ------=_NextPart_000_0010_01BFB877.6E1F7E80 Content-Type: application/octet-stream; name="ejbc.java" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="ejbc.java" /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights=20 * 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.=20 * * 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: =20 * "This product includes software developed by the=20 * 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=20 * 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. * = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D * * 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; 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. =20 * * @author Conor = MacNeill, 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; =20 /** * The directory where generated files are placed. */ private File generatedFilesDirectory; =20 /** * The name of the manifest file generated for the EJB jar. */ private File generatedManifestFile; =20 /** * The classpath to be used in the weblogic ejbc calls. It must = contain the weblogic * classes and the implementation classes of the home and = remote interfaces. */ private String classpath; =20 /** * 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; =20 /** * Do the work. * * The work is actually done by creating a separate JVM to run a = helper task.=20 * This approach allows the classpath of the helper task to be set. = Since the=20 * weblogic tools require the class files of the project's home and = remote=20 * interfaces to be available in the classpath, this also avoids = having to=20 * 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 { try { validateDirectory(descriptorDirectory, "descriptor"); validateDirectory(generatedFilesDirectory, "generated = descriptors"); validateDirectory(sourceDirectory, "source"); =20 String systemClassPath =3D = System.getProperty("java.class.path"); String execClassPath =3D = project.translatePath(systemClassPath + ":" + classpath + ":" + = generatedFilesDirectory); =20 // get all the files in the descriptor directory DirectoryScanner ds =3D = super.getDirectoryScanner(descriptorDirectory); =20 String[] files =3D ds.getIncludedFiles(); Java helperTask =3D new Java(); helperTask.setProject(project); helperTask.setFork("yes"); = helperTask.setClassname("org.apache.tools.ant.taskdefs.optional.ejbcHelpe= r"); String args =3D ""; args +=3D " " + descriptorDirectory; args +=3D " " + generatedFilesDirectory; args +=3D " " + sourceDirectory; args +=3D " " + generatedManifestFile; for (int i =3D 0; i < files.length; ++i) { args +=3D " " + files[i]; } =20 helperTask.setArgs(args); helperTask.setClasspath(execClassPath); = =20 helperTask.execute(); } catch (Exception e) { e.printStackTrace(); throw new BuildException("Exception in ejbc: " + = e.getMessage()); } } /** * 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 =3D new File(dirName); } =20 /** * 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 =3D new File(dirName); } /** * Set the generated manifest file.=20 * * 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 =3D new File(manifestFilename); } =20 /** * Set the classpath to be used for this compilation. */ public void setClasspath(String s) { this.classpath =3D 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 =3D new File(dirName); } =20 } ------=_NextPart_000_0010_01BFB877.6E1F7E80 Content-Type: application/octet-stream; name="DDCreator.java" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="DDCreator.java" /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights=20 * 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.=20 * * 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: =20 * "This product includes software developed by the=20 * 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=20 * 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. * = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D * * 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; 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=20 * descriptor in the format supported by WebLogic. * * This ant task is a front end for the weblogic DDCreator tool. * * @author Conor = MacNeill, 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; =20 /** * The directory where generated serialised deployment descriptors = are placed. */ private File generatedFilesDirectory; =20 /** * The classpath to be used in the weblogic ejbc calls. It must = contain the weblogic * classes necessary fro DDCreator and the implementation = classes of the=20 * home and remote interfaces. */ private String classpath; =20 /** * 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 { try { validateDirectory(descriptorDirectory, "descriptor"); validateDirectory(generatedFilesDirectory, "destination"); =20 String args =3D descriptorDirectory + " " + = generatedFilesDirectory; =20 // get all the files in the descriptor directory DirectoryScanner ds =3D = super.getDirectoryScanner(descriptorDirectory); =20 String[] files =3D ds.getIncludedFiles(); for (int i =3D 0; i < files.length; ++i) { args +=3D " " + files[i]; } =20 String systemClassPath =3D = System.getProperty("java.class.path"); String execClassPath =3D = project.translatePath(systemClassPath + ":" + classpath); Java ddCreatorTask =3D new Java(); ddCreatorTask.setProject(project); ddCreatorTask.setFork("yes"); = ddCreatorTask.setClassname("org.apache.tools.ant.taskdefs.optional.DDCrea= torHelper"); ddCreatorTask.setArgs(args); ddCreatorTask.setClasspath(execClassPath); = =20 ddCreatorTask.execute(); } catch (Exception e) { e.printStackTrace(); throw new BuildException("Exception in DDCreator: " + = e.getMessage()); } } /** * 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 =3D new File(dirName); } =20 /** * Set the directory into which the serialised deployment = descriptors are to=20 * be written. * * @param dirName the name of the directory into which the = serialised deployment * descriptors are written. */ public void setDest(String dirName) { generatedFilesDirectory =3D 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 =3D project.translatePath(s); } } ------=_NextPart_000_0010_01BFB877.6E1F7E80 Content-Type: application/octet-stream; name="ejbcHelper.java" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="ejbcHelper.java" /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights=20 * 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.=20 * * 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: =20 * "This product includes software developed by the=20 * 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=20 * 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. * = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D * * 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; 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 Conor = MacNeill, Cortex ebusiness Pty Limited */ public class ejbcHelper { /** * The root directory of the tree containing the serialised = deployment desciptors.=20 */ private File descriptorDirectory; =20 /** * The directory where generated files are placed. */ private File generatedFilesDirectory; =20 /** * The name of the manifest file generated for the EJB jar. */ private File manifestFile; =20 /** * The classpath to be used in the weblogic ejbc calls. It must = contain the weblogic * classes and the implementation classes of the home and = remote interfaces. */ private String classpath; =20 /** * 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; =20 /** * The names of the serialised deployment descriptors */ String[] descriptors;=20 /** * Command line interface for the ejbc helper task. */ =20 public static void main(String[] args) throws Exception { System.out.println("Hello"); ejbcHelper helper =3D new ejbcHelper(args); helper.process(); } /** * Initialise the ejbcHelper by reading the command arguments. */ =20 private ejbcHelper(String[] args) { int index =3D 0; descriptorDirectory =3D new File(args[index++]); generatedFilesDirectory =3D new File(args[index++]); sourceDirectory =3D new File(args[index++]); manifestFile =3D new File(args[index++]); =20 descriptors =3D new String[args.length - index]; for (int i =3D 0; index < args.length; ++i) { descriptors[i] =3D 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=20 * 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 =3D null; try { fis =3D new FileInputStream(descriptorFile); ObjectInputStream ois =3D new ObjectInputStream(fis); DeploymentDescriptor dd =3D = (DeploymentDescriptor)ois.readObject(); fis.close(); =20 String homeInterfacePath =3D = dd.getHomeInterfaceClassName().replace('.', '/') + ".java"; String remoteInterfacePath =3D = dd.getRemoteInterfaceClassName().replace('.', '/') + ".java"; String primaryKeyClassPath =3D null; if (dd instanceof EntityDescriptor) { primaryKeyClassPath =3D = ((EntityDescriptor)dd).getPrimaryKeyClassName().replace('.', '/') + = ".java";; } =20 File homeInterfaceSource =3D new File(sourceDirectory, = homeInterfacePath); File remoteInterfaceSource =3D new File(sourceDirectory, = remoteInterfacePath); File primaryKeyClassSource =3D null; if (primaryKeyClassPath !=3D null) { primaryKeyClassSource =3D new File(sourceDirectory, = remoteInterfacePath); } =20 // are any of the above out of date.=20 // we find the implementation classes and see if they are = older than any // of the above or the .ser file itself. String beanClassBase =3D = dd.getEnterpriseBeanClassName().replace('.', '/'); File ejbImplentationClass=20 =3D new File(generatedFilesDirectory, beanClassBase + = "EOImpl.class"); File homeImplementationClass=20 =3D new File(generatedFilesDirectory, beanClassBase + = "HomeImpl.class"); File beanStubClass=20 =3D new File(generatedFilesDirectory, beanClassBase + = "EOImpl_WLStub.class"); =20 // if the implementation classes don;t exist regenerate = =20 if (!ejbImplentationClass.exists() || = !homeImplementationClass.exists() || !beanStubClass.exists()) { return true; } =20 // 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 =3D = ejbImplentationClass.lastModified(); if (homeImplementationClass.lastModified() < = classModificationTime) { classModificationTime =3D = homeImplementationClass.lastModified(); } if (beanStubClass.lastModified() < classModificationTime) { classModificationTime =3D beanStubClass.lastModified(); } =20 if (descriptorFile.lastModified() > classModificationTime || homeInterfaceSource.lastModified() > = classModificationTime || remoteInterfaceSource.lastModified() > = classModificationTime) { return true; } =20 if (primaryKeyClassSource !=3D null &&=20 primaryKeyClassSource.lastModified() > = classModificationTime) { return true; } } catch (Exception descriptorLoadException) { descriptorLoadException.printStackTrace(); System.out.println("Exception occurred reading " + = descriptorFile.getName() + " - continuing"); // any problems - just regenerate return true; } finally { if (fis !=3D null) { fis.close(); } } =20 return false; } /** * Process the descriptors in turn generating support classes for = each and a manifest * file for all of the beans. */ =20 private void process() throws Exception { String manifest =3D "Manifest-Version: 1.0\n\n"; for (int i =3D 0; i < descriptors.length; ++i) { String descriptorName =3D descriptors[i]; File descriptorFile =3D new File(descriptorDirectory, = descriptorName); =20 if (isRegenRequired(descriptorFile)) { System.out.println("Running ejbc for " + = descriptorFile.getName()); regenerateSupportClasses(descriptorFile); } else { System.out.println(descriptorFile.getName() + " is up to = date"); } manifest +=3D "Name: " + descriptorFile.getName() + = "\nEnterprise-Bean: True\n\n"; } =20 FileWriter fw =3D new FileWriter(manifestFile); PrintWriter pw =3D 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=20 * 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 =3D {"-noexit", "-keepgenerated", "-d", generatedFilesDirectory.getPath(), descriptorFile.getPath()}; =20 weblogic.ejbc.main(args); } } ------=_NextPart_000_0010_01BFB877.6E1F7E80 Content-Type: application/octet-stream; name="DDCreatorHelper.java" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="DDCreatorHelper.java" /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights=20 * 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.=20 * * 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: =20 * "This product includes software developed by the=20 * 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=20 * 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. * = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D * * 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; 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 Conor = MacNeill, Cortex ebusiness Pty Limited */ public class DDCreatorHelper { /** * The root directory of the tree containing the textual deployment = desciptors.=20 */ private File descriptorDirectory; =20 /** * 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;=20 /** * The main method. * * The main method creates an instance of the DDCreatorHelper, = passing it the=20 * args which it then processes. */ =20 public static void main(String[] args) throws Exception { DDCreatorHelper helper =3D new DDCreatorHelper(args); helper.process(); } =20 /** * Initialise the helper with the command arguments. * */ private DDCreatorHelper(String[] args) { int index =3D 0; descriptorDirectory =3D new File(args[index++]); generatedFilesDirectory =3D new File(args[index++]); =20 descriptors =3D new String[args.length - index]; for (int i =3D 0; index < args.length; ++i) { descriptors[i] =3D args[index++]; } } =20 /** * 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. */ =20 private void process() throws Exception { for (int i =3D 0; i < descriptors.length; ++i) { String descriptorName =3D descriptors[i]; File descriptorFile =3D new File(descriptorDirectory, = descriptorName); int extIndex =3D descriptorName.lastIndexOf("."); String serName =3D null; if (extIndex !=3D -1) { serName =3D descriptorName.substring(0, extIndex) + = ".ser"; } else { serName =3D descriptorName + ".ser"; } File serFile =3D new File(generatedFilesDirectory, serName); =20 // do we need to regenerate the file if (!serFile.exists() || serFile.lastModified() < = descriptorFile.lastModified()) { =20 String[] args =3D {"-noexit",=20 "-d", = generatedFilesDirectory.getPath(), "-outputfile", serFile.getName(), descriptorFile.getPath()}; =20 weblogic.ejb.utils.DDCreator.main(args); } } } } ------=_NextPart_000_0010_01BFB877.6E1F7E80--