Bug 52170

Summary: Zip task does not support DEFLATE method for directories
Product: Ant Reporter: Matt Accola <mraccola>
Component: Core tasksAssignee: Ant Notifications List <notifications>
Status: NEW ---    
Severity: enhancement    
Priority: P2    
Version: 1.8.1   
Target Milestone: ---   
Hardware: PC   
OS: All   

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:

https://github.com/gradle/gradle/blob/master/subprojects/core/src/main/groovy/org/gradle/api/internal/file/archive/ZipCopySpecVisitor.java