From 6ca00c2391dc6d7bcda85a5d8021f630224d9fc7 Mon Sep 17 00:00:00 2001 From: Conor MacNeill Date: Sat, 20 Jan 2001 12:41:51 +0000 Subject: [PATCH] Allow ejbjar to specify support classes. You can add support classes to all the generated jar fils by including a nested element. This is effectively a fileset and includes the ability to reference another fileset by refid So ... or ... Please note the following. ========================== If your ejbjar task generates multiple jar files, the support classes will be added to each one. The nested element name may change. I am using it to test a facility I added to the core. If it does change, it will change to git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268486 13f79535-47bb-0310-9956-ffa450edef68 --- .../optional/ejb/EJBDeploymentTool.java | 5 ++++- .../ant/taskdefs/optional/ejb/EjbJar.java | 20 ++++++++++++++++--- .../optional/ejb/GenericDeploymentTool.java | 20 ++++++++++++++++--- 3 files changed, 38 insertions(+), 7 deletions(-) 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 5edcd8ea8..f8a2e2260 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 @@ -69,8 +69,11 @@ public interface EJBDeploymentTool { * * @param descriptorFilename the name of the deployment descriptor * @param saxParser a SAX parser which can be used to parse the deployment descriptor. + * @param supportFileSet a fileset containing all the files to be included in the + * ` generated jarfile as support classes. */ - public void processDescriptor(String descriptorFilename, SAXParser saxParser) + public void processDescriptor(String descriptorFilename, SAXParser saxParser, + FileSet supportFileSet) throws BuildException; /** 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 396679e98..21afc5380 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 @@ -137,6 +137,11 @@ public class EjbJar extends MatchingTask { */ private ArrayList deploymentTools = new ArrayList(); + /** + * A Fileset of support classes + */ + private FileSet supportClasses = null; + /** * Create a weblogic nested element used to configure a * deployment tool for Weblogic server. @@ -178,6 +183,16 @@ public class EjbJar extends MatchingTask { return classpath.createPath(); } + public Object createElement(String elementName) { + if (elementName.equals("support-classes")) { + supportClasses = new FileSet(); + return supportClasses; + } + + return null; + } + + /** * Set the srcdir attribute. The source directory is the directory that contains * the classes that will be added to the EJB jar. Typically this will include the @@ -301,7 +316,7 @@ public class EjbJar extends MatchingTask { if (srcDir == null) { throw new BuildException("The srcDir attribute must be specified"); } - + if (deploymentTools.size() == 0) { GenericDeploymentTool genericTool = new GenericDeploymentTool(); genericTool.setDestdir(destDir); @@ -335,14 +350,13 @@ public class EjbJar extends MatchingTask { log(files.length + " deployment descriptors located.", Project.MSG_VERBOSE); - // Loop through the files. Each file represents one deployment // descriptor, and hence one bean in our model. for (int index = 0; index < files.length; ++index) { // process the deployment descriptor in each tool for (Iterator i = deploymentTools.iterator(); i.hasNext(); ) { EJBDeploymentTool tool = (EJBDeploymentTool)i.next(); - tool.processDescriptor(files[index], saxParser); + tool.processDescriptor(files[index], saxParser, supportClasses); } } } 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 c43869079..2249d18d5 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 @@ -264,7 +264,7 @@ public class GenericDeploymentTool implements EJBDeploymentTool { if (!addedfiles.contains(logicalFilename)) { iStream = new FileInputStream(inputFile); // Create the zip entry and add it to the jar file - ZipEntry zipEntry = new ZipEntry(logicalFilename); + ZipEntry zipEntry = new ZipEntry(logicalFilename.replace('\\','/')); jStream.putNextEntry(zipEntry); // Create the file input stream, and buffer everything over @@ -301,7 +301,8 @@ public class GenericDeploymentTool implements EJBDeploymentTool { return new DescriptorHandler(srcDir); } - public void processDescriptor(String descriptorFileName, SAXParser saxParser) { + public void processDescriptor(String descriptorFileName, SAXParser saxParser, + FileSet supportFileSet) { FileInputStream descriptorStream = null; try { @@ -315,7 +316,20 @@ public class GenericDeploymentTool implements EJBDeploymentTool { saxParser.parse(new InputSource(descriptorStream), handler); Hashtable ejbFiles = handler.getFiles(); - + + // add in support classes if any + if (supportFileSet != null) { + Project project = task.getProject(); + File supportBaseDir = supportFileSet.getDir(project); + + DirectoryScanner supportScanner = supportFileSet.getDirectoryScanner(project); + supportScanner.scan(); + String[] supportFiles = supportScanner.getIncludedFiles(); + for (int i = 0; i < supportFiles.length; ++i) { + ejbFiles.put(supportFiles[i], new File(supportBaseDir, supportFiles[i])); + } + } + String baseName = ""; // Work out what the base name is