Alrighty.

I looked over the code once more.  Sorry I missed the InnerClass thing.
Attached is the new patch.  Let me know what you think.

I would be willing! to look at refactoring, where do you think ZipUtil,
JarUtil should go?  I'm just afraid that it might touch a lot of the code,
or not be effective enough.

I believe someone mentioned something about recommending changing the
"FileSet" concept to be more in line with a file iterator.  This
recommendation might be very useful to proper task reuse..

By the way, Hi.  My name is Fernando Padilla - but most everyone calls me
fern - Internet Consultant from Boston.

g'night



<babble>
I feel that there is a second side to the coin on refactoring and reasons
for "refactoring", but it's too late for me to have a useful coherent
utterance.  So read below at your own risk..  skipping it at this moment
is totally fine.. I bet this topic will be dealt with later.


I'm going to look at some points for the other side of the coin for just a
sec:

One way to look at tasks, is as antsh might, commands to use and build
upon.  EJBJAR could then be considered a simple "Ant Script" that uses
other "Ant Commands".  The interfaces for tasks should not be varying
wildly, and if they do, it's for a reason.  Look at the thousands of sh
scripts that rely on how gcc, find, etc behave.

I'll say that the task name to task mapping is a short fall, but maybe we
can just instantiate the Task Class we want directly....

Essentially, collecting and reusing code is great.  That's why we should
be using the Jar task, and hopefully soon the Depend task ( another
submission I want to talk about ) to do our dirty work.  The question is,
what's the API into that code.  You want some lower level API?  The crux
of the matter is that the code has to do as much of our dirty work as
possible for it to be useful, yet has to do as little as possible to look
refactored...
</babble>





On Wed, 28 Feb 2001, Conor MacNeill wrote:

> Fern,
>
> Some comments.
>
> I am pretty much against further use of this construct.
>  Jar jarTask = (Jar) getTask().getProject().createTask( "jar" );
>
> I think a better approach would be to refactor the jar'ing code out of the
> Jar task into a utility class. This jaring would then be available as part
> of the core Ant services. I think then there would be a better approach
> than creating and adding a zipfileset for each file that is to go into the
> jar. You wouldn't need to be constrained by the interface made available by
> the Jar task. Of course as part of the refactor the jar task would be
> rewritten to use the new jaring service.
>
> I know this is done in a lot of places in Ant now for exec and java
> services but it is really not the right way to do it. There is an Execute
> class in Ant which provides the Execute service used by the <exec> task. An
> ExecuteJava is there for executing non-forking java classes as provided by
> the <java> task. Having that handle both forked and non-forked java use may
> be nicer. I'm a culprit here, I know, so I will be trying to eliminate all
> my current uses of the above construct.
>
> The fundamental problem with the construct is that a build file may
> redefine a task by taskdef'ing it which shouldn't, but currently could,
> break other tasks.
>
> The other problem with your patch is that it removes the check for Inner
> classes. These need to be included in the jar for it to be valid so it will
> be necessary to have this code come back. Perhaps an initial iteration
> which adds the inner classes to the set of files prior to jaring would
> work.
>
> Conor
>
>
> ----- Original Message -----
> From: "Fernando Padilla" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Tuesday, February 27, 2001 4:49 PM
> Subject: [PATCH] ejb/GenericDeploymentTool.java to use Jar task
>
>
> >
> > 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
> >
> >
>
>
> ---------------------------------------------------------------------------
> -----
>
>
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
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/03/02 06:11:31
@@ -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
@@ -347,48 +348,11 @@
             
             File jarFile = getVendorOutputJarFile(baseName);
             
-            // By default we assume we need to build.
-            boolean needBuild = true;
 
-            if (jarFile.exists()) {
-                long    lastBuild = jarFile.lastModified();
-                Iterator fileIter = ejbFiles.values().iterator();
-                // Set the need build to false until we find out otherwise.
-                needBuild = false;
-
-                // Loop through the files seeing if any has been touched
-                // more recently than the destination jar.
-                while( (needBuild == false) && (fileIter.hasNext()) ) {
-                    File currentFile = (File) fileIter.next();
-                    needBuild = ( lastBuild < currentFile.lastModified() );
-                    if (needBuild) {
-                        log("Build needed because " + currentFile.getPath() + 
" is out of date",
-                            Project.MSG_VERBOSE);
-                    }
-                }
-            }
-            
-            // Check to see if we need a build and start
-            // doing the work!
-            if (needBuild) {
-                // Log that we are going to build...
-                log( "building "
-                              + jarFile.getName()
-                              + " with "
-                              + String.valueOf(ejbFiles.size())
-                              + " files",
-                              Project.MSG_INFO);
-    
-                // Use helper method to write the jarfile
-                writeJar(baseName, jarFile, ejbFiles);
+           // write jar
+           // ( expect it to add inner classes, and do up-to-date checking )
+           writeJar(baseName, jarFile, ejbFiles);
 
-            }
-            else {
-                // Log that the file is up to date...
-                log(jarFile.toString() + " is up to date.",
-                              Project.MSG_VERBOSE);
-            }
-
         }
         catch (SAXException se) {
             String msg = "SAXException while parsing '"
@@ -434,85 +398,63 @@
     }
 
     /**
-     * Method used to encapsulate the writing of the JAR file. Iterates over 
the
-     * filenames/java.io.Files in the Hashtable stored on the instance variable
-     * ejbFiles.
-     */
+     * Method used to encapsulate the writing of the JAR
+     * file. Iterates over the filenames/java.io.Files in the
+     * Hashtable stored on the instance variable ejbFiles.  It also
+     * adds Inner Classes that relate to the given files.  This method
+     * calls on the "jar" task to create the jar.
+     *
+     * @param baseName unused parameter
+     * @param jarfile File Object identifying jar file to create
+     * @param files A list of filename/File pairs, filename as key
+     **/
     protected void writeJar(String baseName, File jarfile, Hashtable files) 
throws BuildException{
 
-        JarOutputStream jarStream = null;
-        try {
-            // clean the addedfiles Vector 
-            addedfiles = new ArrayList();
-
-            /* 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);
+       // clone of given files
+       Hashtable files2 = new Hashtable( files );
 
-                addFileToJar(jarStream, entryFile, entryName);
+       // add inner classes from requested class files, onto list of files to 
add to jar
+       // Loop through all the class files found and add any inner classes
+       for (Iterator entryIterator = files.keySet().iterator(); 
entryIterator.hasNext(); ) {
+           String entryName = (String) entryIterator.next();
+           File entryFile = (File) files.get(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);
+               
+               files2.put( entryName, entryFile );
+           }
+       }
+
+
+       // actually create the jar file
+       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();
 
-                // 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
 
     /**

Reply via email to