hi. i promised a patch, I took my time so not to interrupt 1.3b.
Attached is a patch to
org.apache.tools.ant.taskdefs.optional.ejb.GenericDeploymentTool
It used to have custom code to create Jar files. I patched it to use the
Jar task to create it's jar files now.
have a look.
fern
Index:
src/main/org/apache/tools/ant/taskdefs/optional/ejb/GenericDeploymentTool.java
===================================================================
RCS file:
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/ejb/GenericDeploymentTool.java,v
retrieving revision 1.14
diff -u -r1.14 GenericDeploymentTool.java
---
src/main/org/apache/tools/ant/taskdefs/optional/ejb/GenericDeploymentTool.java
2001/02/13 12:31:59 1.14
+++
src/main/org/apache/tools/ant/taskdefs/optional/ejb/GenericDeploymentTool.java
2001/02/27 05:45:13
@@ -65,6 +65,7 @@
import org.apache.tools.ant.*;
import org.apache.tools.ant.types.*;
+import org.apache.tools.ant.taskdefs.Jar;
/**
* A deployment tool which creates generic EJB jars. Generic jars contains
@@ -215,60 +216,6 @@
classpathLoader = null;
}
- /**
- * Utility method that encapsulates the logic of adding a file entry to
- * a .jar file. Used by execute() to add entries to the jar file as it is
- * constructed.
- * @param jStream A JarOutputStream into which to write the
- * jar entry.
- * @param inputFile A File from which to read the
- * contents the file being added.
- * @param logicalFilename A String representing the name, including
- * all relevant path information, that should be stored for the
entry
- * being added.
- */
- protected void addFileToJar(JarOutputStream jStream,
- File inputFile,
- String logicalFilename)
- throws BuildException {
- FileInputStream iStream = null;
- try {
- if (!addedfiles.contains(logicalFilename)) {
- iStream = new FileInputStream(inputFile);
- // Create the zip entry and add it to the jar file
- ZipEntry zipEntry = new
ZipEntry(logicalFilename.replace('\\','/'));
- jStream.putNextEntry(zipEntry);
-
- // Create the file input stream, and buffer everything over
- // to the jar output stream
- byte[] byteBuffer = new byte[2 * 1024];
- int count = 0;
- do {
- jStream.write(byteBuffer, 0, count);
- count = iStream.read(byteBuffer, 0, byteBuffer.length);
- } while (count != -1);
-
- //add it to list of files in jar
- addedfiles.add(logicalFilename);
- }
- }
- catch (IOException ioe) {
- String msg = "IOException while adding entry "
- + logicalFilename + " to jarfile from " +
inputFile.getPath() + "."
- + ioe.getMessage();
- throw new BuildException(msg, ioe);
- }
- finally {
- // Close up the file input stream for the class file
- if (iStream != null) {
- try {
- iStream.close();
- }
- catch (IOException closeException) {}
- }
- }
- }
-
protected DescriptorHandler getDescriptorHandler(File srcDir) {
return new DescriptorHandler(srcDir);
}
@@ -346,7 +293,8 @@
}
File jarFile = getVendorOutputJarFile(baseName);
-
+
+ /*
// By default we assume we need to build.
boolean needBuild = true;
@@ -388,6 +336,9 @@
log(jarFile.toString() + " is up to date.",
Project.MSG_VERBOSE);
}
+ */
+
+ writeJar(baseName, jarFile, ejbFiles);
}
catch (SAXException se) {
@@ -440,79 +391,21 @@
*/
protected void writeJar(String baseName, File jarfile, Hashtable files)
throws BuildException{
- JarOutputStream jarStream = null;
- try {
- // clean the addedfiles Vector
- addedfiles = new ArrayList();
+ Jar jarTask = (Jar) getTask().getProject().createTask( "jar" );
+ jarTask.setTaskName( getTask().getTaskName() );
+ jarTask.setJarfile( jarfile );
+ Iterator fullPaths = files.keySet().iterator();
+ while ( fullPaths.hasNext() ) {
+ String fullPath = (String) fullPaths.next();
+ File file = (File) files.get( fullPath );
+ ZipFileSet zf = new ZipFileSet();
+ zf.setFullpath( fullPath );
+ zf.setDir( file.getParentFile() );
+ zf.setIncludes( file.getName() );
+ jarTask.addZipfileset( zf );
+ }
+ jarTask.execute();
- /* If the jarfile already exists then whack it and recreate it.
- * Should probably think of a more elegant way to handle this
- * so that in case of errors we don't leave people worse off
- * than when we started =)
- */
- if (jarfile.exists()) {
- jarfile.delete();
- }
- jarfile.getParentFile().mkdirs();
- jarfile.createNewFile();
-
- String defaultManifest =
"/org/apache/tools/ant/defaultManifest.mf";
- InputStream in =
this.getClass().getResourceAsStream(defaultManifest);
- if ( in == null ) {
- throw new BuildException ( "Could not find: " +
defaultManifest );
- }
-
- Manifest manifest = new Manifest(in);
- // Create the streams necessary to write the jarfile
-
- jarStream = new JarOutputStream(new FileOutputStream(jarfile),
manifest);
- jarStream.setMethod(JarOutputStream.DEFLATED);
-
- // Loop through all the class files found and add them to the jar
- for (Iterator entryIterator = files.keySet().iterator();
entryIterator.hasNext(); ) {
- String entryName = (String) entryIterator.next();
- File entryFile = (File) files.get(entryName);
-
- log("adding file '" + entryName + "'",
- Project.MSG_VERBOSE);
-
- addFileToJar(jarStream, entryFile, entryName);
-
- // See if there are any inner classes for this class and add
them in if there are
- InnerClassFilenameFilter flt = new
InnerClassFilenameFilter(entryFile.getName());
- File entryDir = entryFile.getParentFile();
- String[] innerfiles = entryDir.list(flt);
- for (int i=0, n=innerfiles.length; i < n; i++) {
-
- //get and clean up innerclass name
- entryName = entryName.substring(0,
entryName.lastIndexOf(entryFile.getName())-1) + File.separatorChar +
innerfiles[i];
-
- // link the file
- entryFile = new File(config.srcDir, entryName);
-
- log("adding innerclass file '" + entryName + "'",
- Project.MSG_VERBOSE);
-
- addFileToJar(jarStream, entryFile, entryName);
-
- }
- }
- }
- catch(IOException ioe) {
- String msg = "IOException while processing ejb-jar file '"
- + jarfile.toString()
- + "'. Details: "
- + ioe.getMessage();
- throw new BuildException(msg, ioe);
- }
- finally {
- if (jarStream != null) {
- try {
- jarStream.close();
- }
- catch (IOException closeException) {}
- }
- }
} // end of writeJar
/**