Bug 52170 - Zip task does not support DEFLATE method for directories
Summary: Zip task does not support DEFLATE method for directories
Status: NEW
Alias: None
Product: Ant
Classification: Unclassified
Component: Core tasks (show other bugs)
Version: 1.8.1
Hardware: PC All
: P2 enhancement (vote)
Target Milestone: ---
Assignee: Ant Notifications List
Depends on:
Reported: 2011-11-11 14:14 UTC by Matt Accola
Modified: 2011-11-11 16:34 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Matt Accola 2011-11-11 14:14:16 UTC
The Zip task provides a "compress" attribute which tells Ant to set the compression "method" to DEFLATE for the archive itself. However, the directires within the archive still use the STORE method. There should be a way to tell Ant to set the "method" for all directories in the Zip to DEFLATE.

In version 1.8.1 I have tracked this to line 63 in ZipCopySpecVisitor.java
Comment 1 Stefan Bodewig 2011-11-11 14:25:36 UTC
ZipCopySpecVisitor.java is not part of Ant.

Why would anybody want to create archives using DEFLATE for directories?  They don't have any content to compress and a DEFLATEd diretory entry will end up requiring more space than a STOREd one.
Comment 2 Matt Accola 2011-11-11 15:35:09 UTC
Sorry about the bad reference. The source code reference is line 1664 of Zip.java.

I'm no expert on compression methods so I don't know the value of setting the method at the directory level. The reason why I personally need it is so that I can compare a JAR file created by Ant's jar task to another JAR file produced by a different tool (in my case Gradle). This is important for me to make sure that the artifacts produced are identical.
Comment 3 Stefan Bodewig 2011-11-11 16:17:33 UTC
If gradle doesn't use Ant's zip package (or Apache Commons Compress) but rather java.util.zip there will be many differences (internal and external attributes, possibly UTF encoding flags, likely more).  I don't think you can achieve binary identical archives if the underlying implementations are different at all.

Outside of your very specific use-case adding an attribute to the zip task to DEFLATE directory entries (along with the cost of testing, documenting and maintaining said flag) doesn't really seem to make sense.
Comment 4 Matt Accola 2011-11-11 16:34:37 UTC
I really appreciate your quick responses and understand your position. For now I am working around by changing the Ant source code and building my own custom Ant JARs. That is working well. Actually after the change I can do a complete comparison using the ZipDiff tool located here, http://zipdiff.sourceforge.net/

Just as an FYI here is a link to the Gradle class that sets the DEFLATED method: