Java's 'jar' command does not add parent directories to jar files that it creates. This patch adds a 'filesonly' attribute that enables this behaviour to 'zip' and classes that extend it.

This is the same patch as I attached to bug 2053, but adds the attribute to the docs for zip as well.

--
fix, n., v.  What one does when a problem has been reported too many
times to be ignored.
  --The New Hacker's Dictionary, 3rd ed.
Index: docs/manual/CoreTasks/zip.html
===================================================================
RCS file: /home/cvspublic/jakarta-ant/docs/manual/CoreTasks/zip.html,v
retrieving revision 1.2
diff -u -w -u -r1.2 zip.html
--- docs/manual/CoreTasks/zip.html      2001/02/13 12:31:52     1.2
+++ docs/manual/CoreTasks/zip.html      2001/06/11 17:11:12
@@ -61,6 +61,11 @@
     <td align="center" valign="top">No</td>
   </tr>
   <tr>
+    <td valign="top">filesonly</td>
+    <td valign="top">Store only file entries, defaults to false</td>
+    <td align="center" valign="top">No</td>
+  </tr>
+  <tr>
     <td valign="top">includes</td>
     <td valign="top">comma separated list of patterns of files that must be
       included. All files are included when omitted.</td>
Index: src/main/org/apache/tools/ant/taskdefs/Zip.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Zip.java,v
retrieving revision 1.35
diff -u -w -u -r1.35 Zip.java
--- src/main/org/apache/tools/ant/taskdefs/Zip.java     2001/03/27 08:17:14     
1.35
+++ src/main/org/apache/tools/ant/taskdefs/Zip.java     2001/06/11 17:11:15
@@ -76,6 +76,7 @@
     private File zipFile;
     private File baseDir;
     private boolean doCompress = true;
+    private boolean doFilesonly = false;
     protected String archiveType = "zip";
     // For directories:
     private static long emptyCrc = new CRC32 ().getValue ();
@@ -107,6 +108,13 @@
     }
 
     /**
+     * Emulate Sun's jar utility by not adding parent dirs
+     */
+    public void setFilesonly(boolean f) {
+        doFilesonly = f;
+    }
+
+    /**
      * Adds a set of files (nested fileset attribute).
      */
     public void addFileset(FileSet set) {
@@ -499,7 +507,8 @@
     protected void addParentDirs(File baseDir, String entry,
                                  ZipOutputStream zOut, String prefix)
         throws IOException {
-
+        if( !doFilesonly )
+        {
         Stack directories = new Stack();
         int slashPos = entry.length();
 
@@ -520,6 +529,7 @@
                 f = new File(dir);
             }
             zipDir(f, zOut, prefix+dir);
+            }
         }
     }
 

Reply via email to