grimsell 2005/04/26 02:57:59 Modified: samples/servlet/src/scripts/share build.xml integration/ant/src/test-input/org/apache/cactus/integration/ant test-cactifywar.xml test-cactifyear.xml integration/ant/src/java/org/apache/cactus/integration/ant CactusWar.java CactifyEarTask.java CactifyWarTask.java WebXmlMergeTask.java . dependencies.xml.default download.xml build.properties.default integration/ant build.xml integration/ant/src/test/org/apache/cactus/integration/ant TestCactifyWarTask.java TestCactifyEarTask.java Added: integration/ant/src/test-input/org/apache/cactus/integration/ant weblogic.ear weblogic.war Log: Added feature to add ejb-refs to a cactified war. This feature depends on cargo. PR: CACTUS-191 Revision Changes Path 1.31 +1 -0 jakarta-cactus/samples/servlet/src/scripts/share/build.xml Index: build.xml =================================================================== RCS file: /home/cvs/jakarta-cactus/samples/servlet/src/scripts/share/build.xml,v retrieving revision 1.30 retrieving revision 1.31 diff -u -r1.30 -r1.31 --- build.xml 23 Mar 2004 09:29:17 -0000 1.30 +++ build.xml 26 Apr 2005 09:57:58 -0000 1.31 @@ -125,6 +125,7 @@ <pathelement location="${aspectjrt.jar}"/> <pathelement location="${cactus.jar}"/> <pathelement location="${cactus.ant.jar}"/> + <pathelement location="${cargo.jar}"/> <pathelement location="${commons.httpclient.jar}"/> <pathelement location="${commons.logging.jar}"/> <pathelement location="${junit.jar}"/> 1.11 +11 -0 jakarta-cactus/integration/ant/src/test-input/org/apache/cactus/integration/ant/test-cactifywar.xml Index: test-cactifywar.xml =================================================================== RCS file: /home/cvs/jakarta-cactus/integration/ant/src/test-input/org/apache/cactus/integration/ant/test-cactifywar.xml,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- test-cactifywar.xml 21 Apr 2005 11:56:33 -0000 1.10 +++ test-cactifywar.xml 26 Apr 2005 09:57:58 -0000 1.11 @@ -137,6 +137,17 @@ destfile="${work.dir}/destfile.war"/> </target> + <target name="testAddWeblogicEjbRefs"> + <cactifywar srcfile="weblogic.war" + destfile="${work.dir}/destfile.war"> + <ejbref name="MyEjb" + localInterface="com.wombat.MyEjb" + localHomeInterface="com.wombat.MyEjbHome" + jndiName="/wombat/MyEjb" + type="Session"/> + </cactifywar> + </target> + <target name="tearDown"> <delete dir="${work.dir}"/> </target> 1.2 +8 -0 jakarta-cactus/integration/ant/src/test-input/org/apache/cactus/integration/ant/test-cactifyear.xml Index: test-cactifyear.xml =================================================================== RCS file: /home/cvs/jakarta-cactus/integration/ant/src/test-input/org/apache/cactus/integration/ant/test-cactifyear.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- test-cactifyear.xml 15 Feb 2005 10:31:44 -0000 1.1 +++ test-cactifyear.xml 26 Apr 2005 09:57:58 -0000 1.2 @@ -16,6 +16,14 @@ <cactuswar context="/myTestFramework" version="2.3"/> </cactifyear> </target> + + <target name="testAddEjbReferences"> + <cactifyear srcfile="weblogic.ear" + destfile="${work.dir}/cactified.ear" + addEjbReferences="yes"> + <cactuswar srcfile="weblogic.war"/> + </cactifyear> + </target> <target name="tearDown"> <delete dir="${work.dir}"/> 1.1 jakarta-cactus/integration/ant/src/test-input/org/apache/cactus/integration/ant/weblogic.ear <<Binary file>> 1.1 jakarta-cactus/integration/ant/src/test-input/org/apache/cactus/integration/ant/weblogic.war <<Binary file>> 1.2 +4 -2 jakarta-cactus/integration/ant/src/java/org/apache/cactus/integration/ant/CactusWar.java Index: CactusWar.java =================================================================== RCS file: /home/cvs/jakarta-cactus/integration/ant/src/java/org/apache/cactus/integration/ant/CactusWar.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- CactusWar.java 15 Feb 2005 10:31:44 -0000 1.1 +++ CactusWar.java 26 Apr 2005 09:57:59 -0000 1.2 @@ -20,7 +20,9 @@ package org.apache.cactus.integration.ant; /** - * + * Implements the nested element cactuswar of the cactifyear task. + * This element can be configured exactly as the cactifywar task + * with som additions as context within the ear file. * * * @version $Id$ 1.2 +118 -5 jakarta-cactus/integration/ant/src/java/org/apache/cactus/integration/ant/CactifyEarTask.java Index: CactifyEarTask.java =================================================================== RCS file: /home/cvs/jakarta-cactus/integration/ant/src/java/org/apache/cactus/integration/ant/CactifyEarTask.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- CactifyEarTask.java 15 Feb 2005 10:31:44 -0000 1.1 +++ CactifyEarTask.java 26 Apr 2005 09:57:59 -0000 1.2 @@ -21,17 +21,23 @@ import java.io.File; import java.io.IOException; +import java.util.Iterator; import javax.xml.parsers.ParserConfigurationException; -import org.apache.cactus.integration.ant.deployment.application.ApplicationXml; -import org.apache.cactus.integration.ant.deployment.application.ApplicationXmlIo; -import org.apache.cactus.integration.ant.deployment.application.DefaultEarArchive; -import org.apache.cactus.integration.ant.deployment.application.EarArchive; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.taskdefs.Ear; import org.apache.tools.ant.types.ZipFileSet; import org.apache.tools.ant.util.FileUtils; +import org.codehaus.cargo.module.application.ApplicationXml; +import org.codehaus.cargo.module.application.ApplicationXmlIo; +import org.codehaus.cargo.module.application.DefaultEarArchive; +import org.codehaus.cargo.module.application.EarArchive; +import org.codehaus.cargo.module.ejb.EjbArchive; +import org.codehaus.cargo.module.ejb.EjbJarXml; +import org.codehaus.cargo.module.ejb.Entity; +import org.codehaus.cargo.module.ejb.Session; +import org.codehaus.cargo.module.ejb.VendorEjbDescriptor; import org.xml.sax.SAXException; /** @@ -51,6 +57,12 @@ * The archive that contains the web-app that should be cactified. */ private File srcFile; + + /** + * Indicates whether or not we should add ejb references to local ejbs + * in the deployment descriptor. + */ + private boolean addEjbReferences; /** * @@ -70,6 +82,25 @@ } /** + * @return Returns the addEjbReferences. + */ + public boolean getAddEjbReferences() + { + return addEjbReferences; + } + /** + * Indicates whether or not ejb references should be added. + * If set to true all local ejbs will be accessible via + * java:comp/env/ejb/<EJB_NAME> + * + * @param isAddEjbReferences if ejb references should be added. + */ + public void setAddEjbReferences(boolean isAddEjbReferences) + { + this.addEjbReferences = isAddEjbReferences; + } + + /** * @see org.apache.tools.ant.Task#execute() */ public void execute() throws BuildException @@ -169,6 +200,12 @@ getProject().getBaseDir()); tmpCactusWar.deleteOnExit(); cactusWar.setDestFile(tmpCactusWar); + + if (addEjbReferences) + { + addEjbReferencesToWar(tmpCactusWar); + } + cactusWar.execute(); return tmpCactusWar; @@ -203,4 +240,80 @@ return cactusWarConfig; } + + /** + * Add ejb references. + * + * @param theWar temporary cactus war + */ + private void addEjbReferencesToWar(File theWar) + { + try + { + EarArchive ear = new DefaultEarArchive(srcFile); + ApplicationXml appXml = ear.getApplicationXml(); + Iterator ejbModules = appXml.getEjbModules(); + while (ejbModules.hasNext()) + { + String module = (String) ejbModules.next(); + EjbArchive ejbArchive = ear.getEjbModule(module); + EjbJarXml descr = ejbArchive.getEjbJarXml(); + Iterator ejbs = descr.getSessionEjbs(); + while (ejbs.hasNext()) + { + Session ejb = (Session) ejbs.next(); + String name = ejb.getName(); + String local = ejb.getLocal(); + String localHome = ejb.getLocalHome(); + if (local != null) + { + CactifyWarTask.EjbRef ref = new CactifyWarTask.EjbRef(); + ref.setType("Session"); + ref.setName("ejb/" + name); + ref.setLocalInterface(local); + ref.setLocalHomeInterface(localHome); + VendorEjbDescriptor vendorDescr = + descr.getVendorDescriptor(); + String jndiName = vendorDescr.getJndiName(ejb); + ref.setJndiName(jndiName); + cactusWar.addConfiguredEjbref(ref); + } + } + ejbs = descr.getEntityEjbs(); + while (ejbs.hasNext()) + { + Entity ejb = (Entity) ejbs.next(); + String name = ejb.getName(); + String local = ejb.getLocal(); + String localHome = ejb.getLocalHome(); + if (local != null) + { + CactifyWarTask.EjbRef ref = new CactifyWarTask.EjbRef(); + ref.setType("Entity"); + ref.setName("ejb/" + name); + ref.setLocalInterface(local); + ref.setLocalHomeInterface(localHome); + VendorEjbDescriptor vendorDescr = + descr.getVendorDescriptor(); + String jndiName = vendorDescr.getJndiName(ejb); + ref.setJndiName(jndiName); + cactusWar.addConfiguredEjbref(ref); + } + } + } + } + catch (IOException e) + { + throw new BuildException("Could not merge deployment " + + "descriptors", e); + } + catch (SAXException e) + { + throw new BuildException("Parsing of merge file failed", e); + } + catch (ParserConfigurationException e) + { + throw new BuildException("XML parser configuration error", e); + } + } } 1.34 +202 -14 jakarta-cactus/integration/ant/src/java/org/apache/cactus/integration/ant/CactifyWarTask.java Index: CactifyWarTask.java =================================================================== RCS file: /home/cvs/jakarta-cactus/integration/ant/src/java/org/apache/cactus/integration/ant/CactifyWarTask.java,v retrieving revision 1.33 retrieving revision 1.34 diff -u -r1.33 -r1.34 --- CactifyWarTask.java 21 Apr 2005 11:56:33 -0000 1.33 +++ CactifyWarTask.java 26 Apr 2005 09:57:59 -0000 1.34 @@ -28,14 +28,7 @@ import javax.xml.parsers.ParserConfigurationException; -import org.apache.cactus.integration.ant.util.AntLog; import org.apache.cactus.integration.ant.util.ResourceUtils; -import org.apache.cactus.integration.ant.deployment.webapp.DefaultWarArchive; -import org.apache.cactus.integration.ant.deployment.webapp.WarArchive; -import org.apache.cactus.integration.ant.deployment.webapp.WebXml; -import org.apache.cactus.integration.ant.deployment.webapp.WebXmlIo; -import org.apache.cactus.integration.ant.deployment.webapp.WebXmlMerger; -import org.apache.cactus.integration.ant.deployment.webapp.WebXmlVersion; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; import org.apache.tools.ant.taskdefs.War; @@ -44,6 +37,13 @@ import org.apache.tools.ant.types.XMLCatalog; import org.apache.tools.ant.types.ZipFileSet; import org.apache.tools.ant.util.FileUtils; +import org.codehaus.cargo.module.webapp.DefaultWarArchive; +import org.codehaus.cargo.module.webapp.WarArchive; +import org.codehaus.cargo.module.webapp.WebXml; +import org.codehaus.cargo.module.webapp.WebXmlIo; +import org.codehaus.cargo.module.webapp.WebXmlMerger; +import org.codehaus.cargo.module.webapp.WebXmlVersion; +import org.codehaus.cargo.util.monitor.AntMonitor; import org.xml.sax.SAXException; /** @@ -303,6 +303,131 @@ } + /** + * Implements the nested element ejbref + */ + public static final class EjbRef + { + /** + * The name + */ + private String name; + /** + * The local interface + */ + private String localInterface; + /** + * The local home interface + */ + private String localHomeInterface; + /** + * The jndi name + */ + private String jndiName; + /** + * The type + */ + private String type; + + /** + * Returns the jndi name + * + * @return Returns the jndiName. + */ + public String getJndiName() + { + return jndiName; + } + /** + * Sets the jndiName + * + * @param theJndiName The jndiName to set. + */ + public void setJndiName(String theJndiName) + { + this.jndiName = theJndiName; + } + + /** + * Returns the local home interface + * + * @return Returns the localHomeInterface. + */ + public String getLocalHomeInterface() + { + return localHomeInterface; + } + + /** + * Sets the local home interface + * + * @param theLocalHomeInterface The localHomeInterface to set. + */ + public void setLocalHomeInterface(String theLocalHomeInterface) + { + this.localHomeInterface = theLocalHomeInterface; + } + + /** + * Return the local interface + * + * @return Returns the localInterface. + */ + public String getLocalInterface() + { + return localInterface; + } + + /** + * Sets the local interface + * + * @param theLocalInterface The localInterface to set. + */ + public void setLocalInterface(String theLocalInterface) + { + this.localInterface = theLocalInterface; + } + + /** + * Returns the name + * + * @return Returns the name. + */ + public String getName() + { + return name; + } + + /** + * Sets the name + * + * @param theName The name to set. + */ + public void setName(String theName) + { + this.name = theName; + } + + /** + * Returns the type + * + * @return Returns the type. + */ + public String getType() + { + return type; + } + + /** + * Sets the type + * + * @param theType The type to set. + */ + public void setType(String theType) + { + this.type = theType; + } + } // Instance Variables ------------------------------------------------------ /** @@ -330,6 +455,11 @@ * The web-app version to use when creating a WAR from scratch. */ private String version = null; + + /** + * List of ejb-refs to add to the deployment descriptor of the cactified war + */ + private List ejbRefs = new ArrayList(); // Public Methods ---------------------------------------------------------- @@ -348,6 +478,9 @@ ZipFileSet currentFiles = new ZipFileSet(); currentFiles.setSrc(this.srcFile); currentFiles.createExclude().setName("WEB-INF/web.xml"); + currentFiles.createExclude().setName("WEB-INF/weblogic.xml"); + currentFiles.createExclude().setName("WEB-INF/orion-web.xml"); + currentFiles.createExclude().setName("WEB-INF/ibm-web-bnd.xmi"); addZipfileset(currentFiles); // Parse the original deployment descriptor @@ -445,6 +578,16 @@ } /** + * Adds a configured EjbRef instance. Called by Ant. + * + * @param theEjbRef the EjbRef to add + */ + public final void addConfiguredEjbref(EjbRef theEjbRef) + { + ejbRefs.add(theEjbRef); + } + + /** * The descriptor to merge into the original file. * * @param theMergeFile the <code>web.xml</code> to merge @@ -622,6 +765,7 @@ { addRedirectorDefinitions(theWebXml); addJspRedirector(); + addEjbRefs(theWebXml); // If the user has specified a deployment descriptor to merge into the // cactified descriptor, perform the merge @@ -632,9 +776,7 @@ WebXml parsedMergeWebXml = WebXmlIo.parseWebXmlFromFile( this.mergeWebXml, this.xmlCatalog); WebXmlMerger merger = new WebXmlMerger(theWebXml); - merger.setLog(new AntLog(this)); - merger = new WebXmlMerger(theWebXml); - merger.setLog(new AntLog(this)); + merger.setMonitor(new AntMonitor(this)); merger.merge(parsedMergeWebXml); } catch (IOException e) @@ -655,19 +797,38 @@ // Serialize the cactified deployment descriptor into a temporary file, // so that it can get picked up by the War task FileUtils fileUtils = FileUtils.newFileUtils(); - File tmpWebXml = fileUtils.createTempFile("cactus", "web.xml", + File tmpDir = fileUtils.createTempFile("cactus", "tmp.dir", getProject().getBaseDir()); - tmpWebXml.deleteOnExit(); + tmpDir.mkdirs(); + tmpDir.deleteOnExit(); + File webXmlFile = null; try { - WebXmlIo.writeWebXml(theWebXml, tmpWebXml, null, true); + ZipFileSet fileSet = new ZipFileSet(); + fileSet.setDir(tmpDir); + File[] files = WebXmlIo.writeAll(theWebXml, tmpDir); + for (int i = 0; i < files.length; i++) + { + File f = files[i]; + f.deleteOnExit(); + if (f.getName().equals("web.xml")) + { + setWebxml(f); + webXmlFile = f; + } + else + { + fileSet.createInclude().setName(f.getName()); + } + } + addWebinf(fileSet); } catch (IOException ioe) { throw new BuildException( "Could not write temporary deployment descriptor", ioe); } - return tmpWebXml; + return webXmlFile; } /** @@ -703,4 +864,31 @@ } } + /** + * Add ejb references to a web.xml. + * + * @param theWebXml the web.xml to modify + */ + private void addEjbRefs(WebXml theWebXml) + { + Iterator i = ejbRefs.iterator(); + while (i.hasNext()) + { + EjbRef ref = (EjbRef) i.next(); + if ("Session".equals(ref.getType())) + { + theWebXml.addLocalSessionEjbRef(ref.getName(), + ref.getLocalInterface(), + ref.getLocalHomeInterface(), + ref.getJndiName()); + } + else if ("Entity".equals(ref.getType())) + { + theWebXml.addLocalEntityEjbRef(ref.getName(), + ref.getLocalInterface(), + ref.getLocalHomeInterface(), + ref.getJndiName()); + } + } + } } 1.21 +6 -6 jakarta-cactus/integration/ant/src/java/org/apache/cactus/integration/ant/WebXmlMergeTask.java Index: WebXmlMergeTask.java =================================================================== RCS file: /home/cvs/jakarta-cactus/integration/ant/src/java/org/apache/cactus/integration/ant/WebXmlMergeTask.java,v retrieving revision 1.20 retrieving revision 1.21 diff -u -r1.20 -r1.21 --- WebXmlMergeTask.java 31 May 2004 20:05:24 -0000 1.20 +++ WebXmlMergeTask.java 26 Apr 2005 09:57:59 -0000 1.21 @@ -24,14 +24,14 @@ import javax.xml.parsers.ParserConfigurationException; -import org.apache.cactus.integration.ant.util.AntLog; -import org.apache.cactus.integration.ant.deployment.webapp.WebXml; -import org.apache.cactus.integration.ant.deployment.webapp.WebXmlIo; -import org.apache.cactus.integration.ant.deployment.webapp.WebXmlMerger; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; import org.apache.tools.ant.types.XMLCatalog; +import org.codehaus.cargo.module.webapp.WebXml; +import org.codehaus.cargo.module.webapp.WebXmlIo; +import org.codehaus.cargo.module.webapp.WebXmlMerger; +import org.codehaus.cargo.util.monitor.AntMonitor; import org.xml.sax.SAXException; /** @@ -115,7 +115,7 @@ WebXml mergeWebXml = WebXmlIo.parseWebXmlFromFile( this.mergeFile, this.xmlCatalog); WebXmlMerger merger = new WebXmlMerger(srcWebXml); - merger.setLog(new AntLog(this)); + merger.setMonitor(new AntMonitor(this)); merger.merge(mergeWebXml); WebXmlIo.writeWebXml(srcWebXml, this.destFile, this.encoding, this.indent); 1.8 +2 -0 jakarta-cactus/dependencies.xml.default Index: dependencies.xml.default =================================================================== RCS file: /home/cvs/jakarta-cactus/dependencies.xml.default,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- dependencies.xml.default 26 Jan 2005 15:04:47 -0000 1.7 +++ dependencies.xml.default 26 Apr 2005 09:57:59 -0000 1.8 @@ -9,6 +9,8 @@ artifact="aspectjrt" version="1.2.1"/> <aspectj-tools project="aspectj" artifact="aspectjtools" version="1.2.1"/> + <cargo project="cargo" + artifact="cargo" version="0.5-SNAPSHOT"/> <checkstyle project="checkstyle" artifact="checkstyle" version="3.4"/> <clover project="clover" 1.7 +2 -1 jakarta-cactus/download.xml Index: download.xml =================================================================== RCS file: /home/cvs/jakarta-cactus/download.xml,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- download.xml 23 May 2004 14:37:04 -0000 1.6 +++ download.xml 26 Apr 2005 09:57:59 -0000 1.7 @@ -108,6 +108,7 @@ <download jar="antlr"/> <download jar="aspectjrt"/> <download jar="aspectj-tools"/> + <download jar="cargo"/> <download jar="checkstyle"/> <download jar="clover"/> <download jar="commons.beanutils"/> 1.8 +4 -1 jakarta-cactus/build.properties.default Index: build.properties.default =================================================================== RCS file: /home/cvs/jakarta-cactus/build.properties.default,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- build.properties.default 27 Jan 2005 20:55:31 -0000 1.7 +++ build.properties.default 26 Apr 2005 09:57:59 -0000 1.8 @@ -190,6 +190,9 @@ jsp.12.jar = ${servlet.23.jar} jsp.20.jar = ${lib.repo}/${jsp.20.project}/jars/${jsp.20.artifact}-${jsp.20.version}.jar +# The location of the Cargo jar +cargo.jar = ${lib.repo}/${cargo.project}/jars/${cargo.artifact}-${cargo.version}.jar + # The location of the Commons Logging jar commons.logging.jar = ${lib.repo}/${commons.logging.project}/jars/${commons.logging.artifact}-${commons.logging.version}.jar 1.61 +4 -1 jakarta-cactus/integration/ant/build.xml Index: build.xml =================================================================== RCS file: /home/cvs/jakarta-cactus/integration/ant/build.xml,v retrieving revision 1.60 retrieving revision 1.61 diff -u -r1.60 -r1.61 --- build.xml 15 Feb 2005 10:31:44 -0000 1.60 +++ build.xml 26 Apr 2005 09:57:59 -0000 1.61 @@ -77,6 +77,7 @@ depends="init.common, properties, init.clover"> <echo>Dependencies:</echo> + <echo> cargo.jar = [${cargo.jar}]</echo> <echo> commons.logging.jar = [${commons.logging.jar}]</echo> <echo> junit.jar = [${junit.jar}]</echo> <echo> mockobjects.jar = [${mockobjects.jar}]</echo> @@ -88,6 +89,7 @@ <echo> clover.jar = [${clover.jar}]</echo> <path id="project.classpath"> + <pathelement location="${cargo.jar}"/> <pathelement location="${commons.logging.jar}"/> <pathelement location="${xerces.jar}"/> <pathelement location="${xmlapis.jar}"/> @@ -99,6 +101,7 @@ <condition property="properties.ok"> <and> + <available file="${cargo.jar}"/> <available file="${commons.logging.jar}"/> <available file="${junit.jar}"/> <available file="${mockobjects.jar}"/> 1.25 +71 -28 jakarta-cactus/integration/ant/src/test/org/apache/cactus/integration/ant/TestCactifyWarTask.java Index: TestCactifyWarTask.java =================================================================== RCS file: /home/cvs/jakarta-cactus/integration/ant/src/test/org/apache/cactus/integration/ant/TestCactifyWarTask.java,v retrieving revision 1.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- TestCactifyWarTask.java 25 Apr 2005 00:29:34 -0000 1.24 +++ TestCactifyWarTask.java 26 Apr 2005 09:57:59 -0000 1.25 @@ -22,13 +22,15 @@ import java.io.File; import java.util.Iterator; -import org.apache.cactus.integration.ant.deployment.webapp.DefaultWarArchive; -import org.apache.cactus.integration.ant.deployment.webapp.WarArchive; -import org.apache.cactus.integration.ant.deployment.webapp.WebXml; -import org.apache.cactus.integration.ant.deployment.webapp.WebXmlTag; -import org.apache.cactus.integration.ant.deployment.webapp.WebXmlVersion; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; +import org.codehaus.cargo.module.webapp.DefaultWarArchive; +import org.codehaus.cargo.module.webapp.WarArchive; +import org.codehaus.cargo.module.webapp.WebXml; +import org.codehaus.cargo.module.webapp.WebXmlTag; +import org.codehaus.cargo.module.webapp.WebXmlVersion; +import org.codehaus.cargo.module.webapp.weblogic.WeblogicXml; +import org.codehaus.cargo.module.webapp.weblogic.WeblogicXmlTag; import org.w3c.dom.Element; import org.w3c.dom.NodeList; @@ -125,17 +127,17 @@ catch (BuildException expected) { assertEquals("You need to specify either the [srcfile] or the " - + "[version] attribute", - expected.getMessage()); + + "[version] attribute", + expected.getMessage()); } } - + /** - * Verifies an empty web was created when the source archive does not - * contain a web deployment descriptor but specifies the version. - * - * @throws Exception If an unexpected error occurs - */ + * Verifies an empty web was created when the source archive does not + * contain a web deployment descriptor but specifies the version. + * + * @throws Exception If an unexpected error occurs + */ public void testSrcFileWithoutWebXmlNewWebXml22() throws Exception { try @@ -145,17 +147,17 @@ catch (BuildException e) { fail("The WAR source file does not contain a " - + "WEB-INF/web.xml deployment descriptor, but Cactus " - + "should have created an empty one"); + + "WEB-INF/web.xml deployment descriptor, but Cactus " + + "should have created an empty one"); } - } - + } + /** - * Verifies an empty web was created when the source archive does not - * contain a web deployment descriptor but specifies the version. - * - * @throws Exception If an unexpected error occurs - */ + * Verifies an empty web was created when the source archive does not + * contain a web deployment descriptor but specifies the version. + * + * @throws Exception If an unexpected error occurs + */ public void testSrcFileWithoutWebXmlNewWebXml23() throws Exception { try @@ -164,12 +166,12 @@ } catch (BuildException e) { - fail("The WAR source file does not contain a " - + "WEB-INF/web.xml deployment descriptor, but Cactus " - + "should have created an empty one"); + fail("The WAR source file does not contain a " + + "WEB-INF/web.xml deployment descriptor, but Cactus " + + "should have created an empty one"); } - } - + } + /** * Tests whether the Cactus test redirectors are correctly added to the * descriptor of the cactified WAR. @@ -519,6 +521,47 @@ Project.MSG_VERBOSE); } + /** + * Tests that ejb refs can be added for weblogic + * + * @throws Exception iIf an unexpected error occurs + */ + public void testAddWeblogicEjbRefs() throws Exception + { + executeTestTarget(); + + File destFile = getProject().resolveFile("work/destfile.war"); + WarArchive destWar = new DefaultWarArchive(destFile); + + // test web.xml + WebXml webXml = destWar.getWebXml(); + Iterator i = webXml.getElements(WebXmlTag.EJB_LOCAL_REF); + Element e = (Element) i.next(); + NodeList nl = e.getElementsByTagName("ejb-ref-name"); + Element f = (Element) nl.item(0); + assertEquals("MyEjb", f.getFirstChild().getNodeValue()); + nl = e.getElementsByTagName("ejb-ref-type"); + f = (Element) nl.item(0); + assertEquals("Session", f.getFirstChild().getNodeValue()); + nl = e.getElementsByTagName("local-home"); + f = (Element) nl.item(0); + assertEquals("com.wombat.MyEjbHome", f.getFirstChild().getNodeValue()); + nl = e.getElementsByTagName("local"); + f = (Element) nl.item(0); + assertEquals("com.wombat.MyEjb", f.getFirstChild().getNodeValue()); + + // test weblogic.xml + WeblogicXml weblogicXml = (WeblogicXml) webXml.getVendorDescriptor(); + i = weblogicXml.getElements(WeblogicXmlTag.EJB_REFERENCE_DESCRIPTION); + e = (Element) i.next(); + nl = e.getElementsByTagName("ejb-ref-name"); + f = (Element) nl.item(0); + assertEquals("MyEjb", f.getFirstChild().getNodeValue()); + nl = e.getElementsByTagName("jndi-name"); + f = (Element) nl.item(0); + assertEquals("/wombat/MyEjb", f.getFirstChild().getNodeValue()); + } + // Private Methods --------------------------------------------------------- /** 1.2 +87 -6 jakarta-cactus/integration/ant/src/test/org/apache/cactus/integration/ant/TestCactifyEarTask.java Index: TestCactifyEarTask.java =================================================================== RCS file: /home/cvs/jakarta-cactus/integration/ant/src/test/org/apache/cactus/integration/ant/TestCactifyEarTask.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- TestCactifyEarTask.java 15 Feb 2005 10:31:44 -0000 1.1 +++ TestCactifyEarTask.java 26 Apr 2005 09:57:59 -0000 1.2 @@ -20,12 +20,18 @@ package org.apache.cactus.integration.ant; import java.io.File; +import java.util.Iterator; -import org.apache.cactus.integration.ant.deployment.application.ApplicationXml; -import org.apache.cactus.integration.ant.deployment.application.DefaultEarArchive; -import org.apache.cactus.integration.ant.deployment.application.EarArchive; -import org.apache.cactus.integration.ant.deployment.webapp.WarArchive; -import org.apache.cactus.integration.ant.deployment.webapp.WebXml; +import org.codehaus.cargo.module.application.ApplicationXml; +import org.codehaus.cargo.module.application.DefaultEarArchive; +import org.codehaus.cargo.module.application.EarArchive; +import org.codehaus.cargo.module.webapp.WarArchive; +import org.codehaus.cargo.module.webapp.WebXml; +import org.codehaus.cargo.module.webapp.WebXmlTag; +import org.codehaus.cargo.module.webapp.weblogic.WeblogicXml; +import org.codehaus.cargo.module.webapp.weblogic.WeblogicXmlTag; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; /** * Test class for the CactifyEar task. @@ -86,4 +92,79 @@ assertEquals("/myTestFramework", appXml.getWebModuleContextRoot("cactus.war")); } + + /** + * @throws Exception If an unexpected error occurs + */ + public void testAddEjbReferences() throws Exception + { + executeTestTarget(); + + File destFile = getProject().resolveFile("work/cactified.ear"); + EarArchive destEar = new DefaultEarArchive(destFile); + WarArchive cactusWar = destEar.getWebModule("cactus.war"); + + // test web.xml + WebXml webXml = cactusWar.getWebXml(); + Iterator i = webXml.getElements(WebXmlTag.EJB_LOCAL_REF); + assertEjbRef((Element) i.next(), "ejb/Session2", "Session", + "com.wombat.Session2", "com.wombat.Session2Home"); + assertEjbRef((Element) i.next(), "ejb/Entity1", "Entity", + "com.wombat.Entity1", "com.wombat.Entity1Home"); + assertFalse(i.hasNext()); + + // test weblogic.xml + WeblogicXml weblogicXml = (WeblogicXml) webXml.getVendorDescriptor(); + i = weblogicXml.getElements(WeblogicXmlTag.EJB_REFERENCE_DESCRIPTION); + assertWeblogicEjbRef((Element) i.next(), + "ejb/Session2", "/wombat/Session2"); + assertWeblogicEjbRef((Element) i.next(), + "ejb/Entity1", "/wombat/Entity1"); + assertFalse(i.hasNext()); + } + + /** + * Help method to check that a given element is a correct ejb-ref + * + * @param theElement the Element to check + * @param theName correct name of the ejb-ref + * @param theType correct ejb-ref type + * @param theLocal correct local interface of the ejb-ref + * @param theLocalHome correct local home interface of the ejb-ref + */ + private void assertEjbRef(Element theElement, String theName, + String theType, String theLocal, + String theLocalHome) + { + NodeList nl = theElement.getElementsByTagName("ejb-ref-name"); + Element f = (Element) nl.item(0); + assertEquals(theName, f.getFirstChild().getNodeValue()); + nl = theElement.getElementsByTagName("ejb-ref-type"); + f = (Element) nl.item(0); + assertEquals(theType, f.getFirstChild().getNodeValue()); + nl = theElement.getElementsByTagName("local-home"); + f = (Element) nl.item(0); + assertEquals(theLocalHome, f.getFirstChild().getNodeValue()); + nl = theElement.getElementsByTagName("local"); + f = (Element) nl.item(0); + assertEquals(theLocal, f.getFirstChild().getNodeValue()); + } + + /** + * Help method to check that a given element is a correct weblogic ejb-ref + * + * @param theElement the Element to check + * @param theName correct name of the ejb-ref + * @param theJndiName correct jndi name of the ejb-ref + */ + private void assertWeblogicEjbRef(Element theElement, String theName, + String theJndiName) + { + NodeList nl = theElement.getElementsByTagName("ejb-ref-name"); + Element f = (Element) nl.item(0); + assertEquals(theName, f.getFirstChild().getNodeValue()); + nl = theElement.getElementsByTagName("jndi-name"); + f = (Element) nl.item(0); + assertEquals(theJndiName, f.getFirstChild().getNodeValue()); + } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]