diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/EJBDeploymentTool.java b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/EJBDeploymentTool.java index 603f8f344..deabe5c72 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/EJBDeploymentTool.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/EJBDeploymentTool.java @@ -63,13 +63,13 @@ import org.apache.tools.ant.Task; public interface EJBDeploymentTool { /** - * Process a deployment descriptor, generating the necessary vendor specifi + * Process a deployment descriptor, generating the necessary vendor specific * deployment files. * * @param descriptorFilename the name of the deployment descriptor * @param saxParser a SAX parser which can be used to parse the deployment descriptor. */ - public void processDescriptor(File srcDir, File descriptorDir, String descriptorFilename, SAXParser saxParser) + public void processDescriptor(String descriptorFilename, SAXParser saxParser) throws BuildException; /** @@ -86,5 +86,6 @@ public interface EJBDeploymentTool { /** * Configure this tool for use in the ejbjar task. */ - public void configure(String basenameTerminator, boolean flatDestDir); + public void configure(File srcDir, File descriptorDir, String basenameTerminator, + String baseJarName, boolean flatDestDir); } \ No newline at end of file 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 896a86da7..852bf4dd8 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 @@ -79,7 +79,7 @@ import org.apache.tools.ant.taskdefs.MatchingTask; * parsing them to locate the names of the classes which should be placed in * the jar. The classnames are translated to java.io.Files by replacing periods * with File.separatorChar and resolving the generated filename as a relative - * path under the srcdir attribute. All necessary files are then assembled into + * path under the srcDir attribute. All necessary files are then assembled into * a jarfile. One jarfile is constructed for each deployment descriptor found. *
* @@ -87,15 +87,15 @@ import org.apache.tools.ant.taskdefs.MatchingTask; * 5.1 jars. The weblogic deployment descriptors, used in constructing the * Weblogic jar, are located based on a simple naming convention. The name of the * standard deployment descriptor is taken upto the first instance of a String, - * specified by the attribute basenameTerminator, and then the regular Weblogic - * descriptor name is appended. For example if basenameTerminator is set to '-', + * specified by the attribute baseNameTerminator, and then the regular Weblogic + * descriptor name is appended. For example if baseNameTerminator is set to '-', * its default value, and a standard descriptor is called Foo-ejb-jar.xml then * the files Foo-weblogic-ejb-jar.xml and Foo-weblogic-cmp-rdbms-jar.xml will be * looked for, and if found, included in the jarfile. * *Attributes and setter methods are provided to support optional generation * of Weblogic5.1 jars, optional deletion of generic jar files, setting alternate - * values for basenameTerminator, and setting the strings to append to the names + * values for baseNameTerminator, and setting the strings to append to the names * of the generated jarfiles.
* * @author Tim Fennell @@ -103,25 +103,28 @@ import org.apache.tools.ant.taskdefs.MatchingTask; public class EjbJar extends MatchingTask { /** Stores a handle to the directory under which to search for class files */ - private File srcdir = null; + private File srcDir; /** Stores a handle to the directory under which to search for deployment descriptors */ - private File descriptordir = null; + private File descriptorDir; /** Stores a handle to the directory to put the Jar files in */ - private File destdir = null; + private File destDir; + /** Stores a handle to the destination EJB Jar file */ + private String baseJarName; + /** * Instance variable that determines whether to use a package structure * of a flat directory as the destination for the jar files. */ - private boolean flatdestdir = false; + private boolean flatDestDir = false; /** Instance variable that marks the end of the 'basename' */ - private String basenameTerminator = "-"; + private String baseNameTerminator = "-"; /** Instance variable that stores the suffix for the generated jarfile. */ - private String genericjarsuffix = "-generic.jar"; + private String genericJarSuffix = "-generic.jar"; /** * The list of deployment tools we are going to run. @@ -135,20 +138,35 @@ public class EjbJar extends MatchingTask { return tool; } + public WeblogicTOPLinkDeploymentTool createWeblogictoplink() { + WeblogicTOPLinkDeploymentTool tool = new WeblogicTOPLinkDeploymentTool(); + tool.setTask(this); + deploymentTools.add(tool); + return tool; + } + /** - * Setter used to store the value of srcdir prior to execute() being called. + * Setter used to store the value of srcDir prior to execute() being called. * @param inDir the source directory. */ public void setSrcdir(File inDir) { - this.srcdir = inDir; + this.srcDir = inDir; } /** - * Setter used to store the value of descriptordir prior to execute() being called. + * Setter used to store the value of descriptorDir prior to execute() being called. * @param inDir the directory containing the deployment descriptors. */ public void setDescriptordir(File inDir) { - this.descriptordir = inDir; + this.descriptorDir = inDir; + } + + /** + * Setter used to store the value of descriptorDir prior to execute() being called. + * @param inDir the directory containing the deployment descriptors. + */ + public void setBasejarname(String inValue) { + this.baseJarName = inValue; } /** @@ -157,15 +175,15 @@ public class EjbJar extends MatchingTask { * @param inFile the destination directory. */ public void setDestdir(File inDir) { - this.destdir = inDir; + this.destDir = inDir; } /** - * Setter used to store the value of flatdestdir. + * Setter used to store the value of flatDestDir. * @param inValue a string, either 'true' or 'false'. */ public void setFlatdestdir(boolean inValue) { - this.flatdestdir = inValue; + this.flatDestDir = inValue; } /** @@ -173,15 +191,15 @@ public class EjbJar extends MatchingTask { * @param inString the string to use as the suffix. */ public void setGenericjarsuffix(String inString) { - this.genericjarsuffix = inString; + this.genericJarSuffix = inString; } /** - * Setter used to store the value of basenameTerminator + * Setter used to store the value of baseNameTerminator * @param inValue a string which marks the end of the basename. */ - public void setBasenameTerminator(String inValue) { - if (inValue != null) this.basenameTerminator = inValue; + public void setBasenameterminator(String inValue) { + this.baseNameTerminator = inValue; } /** @@ -196,25 +214,27 @@ public class EjbJar extends MatchingTask { * that a major problem occurred within this task. */ public void execute() throws BuildException { - if (srcdir == null) { - throw new BuildException("The srcdir attribute must be specified"); - } - if (descriptordir == null) { - throw new BuildException("The descriptordir attribute must be specified"); + if (srcDir == null) { + throw new BuildException("The srcDir attribute must be specified"); } if (deploymentTools.size() == 0) { GenericDeploymentTool genericTool = new GenericDeploymentTool(); - genericTool.setDestdir(destdir); + genericTool.setDestdir(destDir); genericTool.setTask(this); - genericTool.setGenericjarsuffix(genericjarsuffix); + genericTool.setGenericJarSuffix(genericJarSuffix); deploymentTools.add(genericTool); } + File scanDir = descriptorDir; + if (scanDir == null) { + scanDir = srcDir; + } + for (Iterator i = deploymentTools.iterator(); i.hasNext(); ) { EJBDeploymentTool tool = (EJBDeploymentTool)i.next(); - tool.configure(basenameTerminator, flatdestdir); + tool.configure(srcDir, scanDir, baseNameTerminator, baseJarName, flatDestDir); tool.validateConfigured(); } @@ -224,7 +244,8 @@ public class EjbJar extends MatchingTask { saxParserFactory.setValidating(true); SAXParser saxParser = saxParserFactory.newSAXParser(); - DirectoryScanner ds = getDirectoryScanner(descriptordir); + + DirectoryScanner ds = getDirectoryScanner(scanDir); ds.scan(); String[] files = ds.getIncludedFiles(); @@ -238,7 +259,7 @@ public class EjbJar extends MatchingTask { // process the deployment descriptor in each tool for (Iterator i = deploymentTools.iterator(); i.hasNext(); ) { EJBDeploymentTool tool = (EJBDeploymentTool)i.next(); - processDescriptor(files[index], saxParser, tool); + tool.processDescriptor(files[index], saxParser); } } } @@ -254,13 +275,6 @@ public class EjbJar extends MatchingTask { throw new BuildException(msg, pce); } } // end of execute() - - - private void processDescriptor(String descriptorFilename, SAXParser saxParser, - EJBDeploymentTool tool) { - - tool.processDescriptor(srcdir, descriptordir, descriptorFilename, saxParser); - } } diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/GenericDeploymentTool.java b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/GenericDeploymentTool.java index 1aeb67e4b..5dec9e36f 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/GenericDeploymentTool.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/GenericDeploymentTool.java @@ -72,9 +72,18 @@ public class GenericDeploymentTool implements EJBDeploymentTool { protected static final String META_DIR = "META-INF/"; protected static final String EJB_DD = "ejb-jar.xml"; + /** Stores a handle to the directory of the source tree */ + private File srcDir; + + /** Stores a handle to the directory of the deployment descriptors */ + private File descriptorDir; + /** Stores a handle to the directory to put the Jar files in */ - private File destDir = null; + private File destDir; + /** Instance variable that stores the jar file name when not using the naming standard */ + private String baseJarName; + /** * Instance variable that determines whether to use a package structure * of a flat directory as the destination for the jar files. @@ -82,10 +91,10 @@ public class GenericDeploymentTool implements EJBDeploymentTool { private boolean flatDestDir = false; /** Instance variable that marks the end of the 'basename' */ - private String basenameTerminator = "-"; + private String baseNameTerminator = "-"; /** Instance variable that stores the suffix for the generated jarfile. */ - private String genericjarsuffix = "-generic.jar"; + private String genericJarSuffix = "-generic.jar"; /** * The task to which this tool belongs. @@ -126,23 +135,56 @@ public class GenericDeploymentTool implements EJBDeploymentTool { /** * Get the basename terminator. */ - protected String getBasenameTerminator() { - return basenameTerminator; + protected String getBaseNameTerminator() { + return baseNameTerminator; + } + + /** + * Get the base jar name. + */ + protected String getBaseJarName() { + return baseJarName; + } + + /** + * Get the source dir. + */ + protected File getSrcDir() { + return srcDir; + } + + /** + * Get the meta-inf dir. + * + */ + protected File getDescriptorDir() { + return descriptorDir; + } + + /** + * Returns true, if the meta-inf dir is being explicitly set, false otherwise. + */ + protected boolean usingBaseJarName() { + return baseJarName != null; } /** * Setter used to store the suffix for the generated jar file. * @param inString the string to use as the suffix. */ - public void setGenericjarsuffix(String inString) { - this.genericjarsuffix = inString; + public void setGenericJarSuffix(String inString) { + this.genericJarSuffix = inString; } /** * Configure this tool for use in the ejbjar task. */ - public void configure(String basenameTerminator, boolean flatDestDir) { - this.basenameTerminator = basenameTerminator; + public void configure(File srcDir, File descriptorDir, String baseNameTerminator, + String baseJarName, boolean flatDestDir) { + this.srcDir = srcDir; + this.descriptorDir = descriptorDir; + this.baseJarName = baseJarName; + this.baseNameTerminator = baseNameTerminator; this.flatDestDir = flatDestDir; } @@ -191,8 +233,7 @@ public class GenericDeploymentTool implements EJBDeploymentTool { return new DescriptorHandler(srcDir); } - public void processDescriptor(File srcDir, File descriptorDir, - String descriptorFilename, SAXParser saxParser) { + public void processDescriptor(String descriptorFileName, SAXParser saxParser) { try { DescriptorHandler handler = getDescriptorHandler(srcDir); @@ -202,7 +243,7 @@ public class GenericDeploymentTool implements EJBDeploymentTool { */ saxParser.parse(new InputSource (new FileInputStream - (new File(descriptorDir, descriptorFilename))), + (new File(getDescriptorDir(), descriptorFileName))), handler); Hashtable ejbFiles = handler.getFiles(); @@ -210,25 +251,30 @@ public class GenericDeploymentTool implements EJBDeploymentTool { String baseName = ""; // Work out what the base name is - int lastSeparatorIndex = descriptorFilename.lastIndexOf(File.separator); - int endBaseName = -1; - if (lastSeparatorIndex != -1) { - endBaseName = descriptorFilename.indexOf(basenameTerminator, - lastSeparatorIndex); - } - else { - endBaseName = descriptorFilename.indexOf(basenameTerminator); - } - - if (endBaseName != -1) { - baseName = descriptorFilename.substring(0, endBaseName); + if (baseJarName != null) { + baseName = baseJarName; + } else { + int lastSeparatorIndex = descriptorFileName.lastIndexOf(File.separator); + int endBaseName = -1; + if (lastSeparatorIndex != -1) { + endBaseName = descriptorFileName.indexOf(baseNameTerminator, + lastSeparatorIndex); + } + else { + endBaseName = descriptorFileName.indexOf(baseNameTerminator); + } + + if (endBaseName != -1) { + baseName = descriptorFileName.substring(0, endBaseName); + } + baseName = descriptorFileName.substring(0, endBaseName); } // First the regular deployment descriptor ejbFiles.put(META_DIR + EJB_DD, - new File(descriptorDir, descriptorFilename)); + new File(getDescriptorDir(), descriptorFileName)); - addVendorFiles(ejbFiles, srcDir, descriptorDir, baseName); + addVendorFiles(ejbFiles, baseName); // Lastly create File object for the Jar files. If we are using // a flat destination dir, then we need to redefine baseName! @@ -281,7 +327,7 @@ public class GenericDeploymentTool implements EJBDeploymentTool { } catch (SAXException se) { String msg = "SAXException while parsing '" - + descriptorFilename.toString() + + descriptorFileName.toString() + "'. This probably indicates badly-formed XML." + " Details: " + se.getMessage(); @@ -289,7 +335,7 @@ public class GenericDeploymentTool implements EJBDeploymentTool { } catch (IOException ioe) { String msg = "IOException while parsing'" - + descriptorFilename.toString() + + descriptorFileName.toString() + "'. This probably indicates that the descriptor" + " doesn't exist. Details: " + ioe.getMessage(); @@ -301,7 +347,7 @@ public class GenericDeploymentTool implements EJBDeploymentTool { * Add any vendor specific files which should be included in the * EJB Jar. */ - protected void addVendorFiles(Hashtable ejbFiles, File srcDir, File descriptorDir, String baseName) { + protected void addVendorFiles(Hashtable ejbFiles, String baseName) { } @@ -310,7 +356,7 @@ public class GenericDeploymentTool implements EJBDeploymentTool { * of this jar will be checked against the dependent bean classes. */ File getVendorOutputJarFile(String baseName) { - return new File(destDir, baseName + genericjarsuffix); + return new File(destDir, baseName + genericJarSuffix); } /** diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicDeploymentTool.java b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicDeploymentTool.java index eb2aabc4a..b846c9afc 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicDeploymentTool.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicDeploymentTool.java @@ -67,14 +67,19 @@ import org.apache.tools.ant.taskdefs.Java; public class WeblogicDeploymentTool extends GenericDeploymentTool { protected static final String WL_DD = "weblogic-ejb-jar.xml"; protected static final String WL_CMP_DD = "weblogic-cmp-rdbms-jar.xml"; + protected static final String WL_DTD = "/weblogic/ejb/deployment/xml/ejb-jar.dtd"; + protected static final String WL_HTTP_DTD = "http://www.bea.com/servers/wls510/dtd/weblogic-ejb-jar.dtd"; /** Instance variable that stores the suffix for the weblogic jarfile. */ private String jarSuffix = ".jar"; + /** Instance variable that stores the location of the weblogic DTD file. */ + private String weblogicDTD; + private Path classpath; /** Instance variable that determines whether generic ejb jars are kept. */ - private boolean keepgeneric = false; + private boolean keepGeneric = false; /** * Set the classpath to be used for this compilation. @@ -92,17 +97,39 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { } /** - * Setter used to store the value of keepgeneric + * Setter used to store the value of keepGeneric * @param inValue a string, either 'true' or 'false'. */ - public void setKeepgeneric(String inValue) { - this.keepgeneric = Boolean.valueOf(inValue).booleanValue(); + public void setKeepgeneric(boolean inValue) { + this.keepGeneric = inValue; } + /** + * Setter used to store the location of the weblogic DTD. This can be a file on the system + * or a resource on the classpath. + * @param inString the string to use as the DTD location. + */ + public void setWeblogicdtd(String inString) { + this.weblogicDTD = inString; + } + protected DescriptorHandler getDescriptorHandler(File srcDir) { DescriptorHandler handler = new DescriptorHandler(srcDir); - handler.registerResourceDTD("-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN", - "/weblogic/ejb/deployment/xml/ejb-jar.dtd"); + if (weblogicDTD != null) { + // is the DTD a local file? + File dtdFile = new File(weblogicDTD); + if (dtdFile.exists()) { + handler.registerFileDTD("-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN", + dtdFile); + } else { + handler.registerResourceDTD("-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN", + weblogicDTD); + } + } else { + handler.registerResourceDTD("-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN", + WL_DTD); + } + return handler; } @@ -110,10 +137,10 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { * Add any vendor specific files which should be included in the * EJB Jar. */ - protected void addVendorFiles(Hashtable ejbFiles, File srcdir, File descriptorDir, String baseName) { - // Then the weblogic deployment descriptor - File weblogicDD = new File(descriptorDir, - baseName + getBasenameTerminator() + WL_DD); + protected void addVendorFiles(Hashtable ejbFiles, String baseName) { + String ddPrefix = (usingBaseJarName() ? "" : baseName + getBaseNameTerminator()); + + File weblogicDD = new File(getDescriptorDir(), ddPrefix + WL_DD); if (weblogicDD.exists()) { ejbFiles.put(META_DIR + WL_DD, @@ -121,8 +148,7 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { } // The the weblogic cmp deployment descriptor - File weblogicCMPDD = new File(descriptorDir, - baseName + getBasenameTerminator() + WL_CMP_DD); + File weblogicCMPDD = new File(getDescriptorDir(), ddPrefix + WL_CMP_DD); if (weblogicCMPDD.exists()) { ejbFiles.put(META_DIR + WL_CMP_DD, @@ -188,7 +214,7 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { super.writeJar(baseName, genericJarFile, files); buildWeblogicJar(genericJarFile, jarFile); - if (!keepgeneric) { + if (!keepGeneric) { getTask().log("deleting generic jar " + genericJarFile.toString(), Project.MSG_VERBOSE); genericJarFile.delete(); diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicTOPLinkDeploymentTool.java b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicTOPLinkDeploymentTool.java new file mode 100644 index 000000000..c0186f5ab --- /dev/null +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicTOPLinkDeploymentTool.java @@ -0,0 +1,129 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2000 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 + *