mbenson 2005/02/02 15:55:51
Modified: . WHATSNEW
docs/manual/CoreTasks zip.html ear.html jar.html war.html
src/main/org/apache/tools/ant/taskdefs Zip.java
src/etc/testcases/taskdefs zip.xml
src/testcases/org/apache/tools/ant/taskdefs ZipTest.java
src/main/org/apache/tools/zip ZipOutputStream.java
Log:
Added level attribute to zip & subclasses.
PR: 25513
Revision Changes Path
1.739 +3 -0 ant/WHATSNEW
Index: WHATSNEW
===================================================================
RCS file: /home/cvs/ant/WHATSNEW,v
retrieving revision 1.738
retrieving revision 1.739
diff -u -r1.738 -r1.739
--- WHATSNEW 2 Feb 2005 20:08:57 -0000 1.738
+++ WHATSNEW 2 Feb 2005 23:55:49 -0000 1.739
@@ -101,6 +101,9 @@
* mail task accepts nested header element. Bugzilla report 24713.
+* zip/jar/war/ear supports level attribute for deflate compression level.
+ Bugzilla report 25513.
+
Changes from Ant 1.6.2 to current Ant 1.6 CVS version
=====================================================
1.30 +7 -0 ant/docs/manual/CoreTasks/zip.html
Index: zip.html
===================================================================
RCS file: /home/cvs/ant/docs/manual/CoreTasks/zip.html,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- zip.html 21 Jan 2005 07:12:52 -0000 1.29
+++ zip.html 2 Feb 2005 23:55:49 -0000 1.30
@@ -189,6 +189,13 @@
<td valign="top">Comment to store in the archive. <em>Since Ant
1.6.3</em></td>
<td valign="top" align="center">No</td>
</tr>
+ <tr>
+ <td valign="top">level</td>
+ <td valign="top">Non-default level at which file compression should be
+ performed. Valid values range from 0 (no compression/fastest) to 9
+ (maximum compression/slowest). <em>Since Ant 1.7</em></td>
+ <td valign="top" align="center">No</td>
+ </tr>
</table>
<h3>Parameters specified as nested elements</h3>
<h4>fileset</h4>
1.21 +7 -0 ant/docs/manual/CoreTasks/ear.html
Index: ear.html
===================================================================
RCS file: /home/cvs/ant/docs/manual/CoreTasks/ear.html,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- ear.html 22 Nov 2004 22:53:50 -0000 1.20
+++ ear.html 2 Feb 2005 23:55:49 -0000 1.21
@@ -134,6 +134,13 @@
Defaults to true. <em>Since Ant 1.6.2</em></td>
<td align="center" valign="top">No</td>
</tr>
+ <tr>
+ <td valign="top">level</td>
+ <td valign="top">Non-default level at which file compression should be
+ performed. Valid values range from 0 (no compression/fastest) to 9
+ (maximum compression/slowest). <em>Since Ant 1.7</em></td>
+ <td valign="top" align="center">No</td>
+ </tr>
</table>
<h3>Nested elements</h3>
<h4>metainf</h4>
1.34 +7 -0 ant/docs/manual/CoreTasks/jar.html
Index: jar.html
===================================================================
RCS file: /home/cvs/ant/docs/manual/CoreTasks/jar.html,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- jar.html 22 Nov 2004 22:53:50 -0000 1.33
+++ jar.html 2 Feb 2005 23:55:49 -0000 1.34
@@ -194,6 +194,13 @@
Defaults to true. <em>Since Ant 1.6.2</em></td>
<td align="center" valign="top">No</td>
</tr>
+ <tr>
+ <td valign="top">level</td>
+ <td valign="top">Non-default level at which file compression should be
+ performed. Valid values range from 0 (no compression/fastest) to 9
+ (maximum compression/slowest). <em>Since Ant 1.7</em></td>
+ <td valign="top" align="center">No</td>
+ </tr>
</table>
<h3>Nested elements</h3>
1.25 +7 -0 ant/docs/manual/CoreTasks/war.html
Index: war.html
===================================================================
RCS file: /home/cvs/ant/docs/manual/CoreTasks/war.html,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- war.html 22 Nov 2004 22:53:50 -0000 1.24
+++ war.html 2 Feb 2005 23:55:49 -0000 1.25
@@ -141,6 +141,13 @@
Defaults to true. <em>Since Ant 1.6.2</em></td>
<td align="center" valign="top">No</td>
</tr>
+ <tr>
+ <td valign="top">level</td>
+ <td valign="top">Non-default level at which file compression should be
+ performed. Valid values range from 0 (no compression/fastest) to 9
+ (maximum compression/slowest). <em>Since Ant 1.7</em></td>
+ <td valign="top" align="center">No</td>
+ </tr>
</table>
<h3>Nested elements</h3>
<h4>lib</h4>
1.135 +30 -12 ant/src/main/org/apache/tools/ant/taskdefs/Zip.java
Index: Zip.java
===================================================================
RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Zip.java,v
retrieving revision 1.134
retrieving revision 1.135
diff -u -r1.134 -r1.135
--- Zip.java 18 Jan 2005 12:48:57 -0000 1.134
+++ Zip.java 2 Feb 2005 23:55:50 -0000 1.135
@@ -120,6 +120,8 @@
*/
private String comment = "";
+ private int level = ZipOutputStream.DEFAULT_COMPRESSION;
+
/**
* This is the name/location of where to
* create the .zip file.
@@ -336,6 +338,25 @@
}
/**
+ * Set the compression level to use. Default is
+ * ZipOutputStream.DEFAULT_COMPRESSION.
+ * @param level compression level.
+ * @since Ant 1.7
+ */
+ public void setLevel(int level) {
+ this.level = level;
+ }
+
+ /**
+ * Get the compression level.
+ * @return compression level.
+ * @since Ant 1.7
+ */
+ public int getLevel() {
+ return level;
+ }
+
+ /**
* Whether the file modification times will be rounded up to the
* next even number of seconds.
*
@@ -481,16 +502,13 @@
ZipOutputStream zOut = null;
try {
-
if (!skipWriting) {
zOut = new ZipOutputStream(zipFile);
zOut.setEncoding(encoding);
- if (doCompress) {
- zOut.setMethod(ZipOutputStream.DEFLATED);
- } else {
- zOut.setMethod(ZipOutputStream.STORED);
- }
+ zOut.setMethod(doCompress
+ ? ZipOutputStream.DEFLATED : ZipOutputStream.STORED);
+ zOut.setLevel(level);
}
initZipOutputStream(zOut);
@@ -1080,12 +1098,12 @@
ze.setMethod(doCompress ? ZipEntry.DEFLATED : ZipEntry.STORED);
/*
- * ZipOutputStream.putNextEntry expects the ZipEntry to
- * know its size and the CRC sum before you start writing
- * the data when using STORED mode - unless it is seekable.
- *
- * This forces us to process the data twice.
- */
+ * ZipOutputStream.putNextEntry expects the ZipEntry to
+ * know its size and the CRC sum before you start writing
+ * the data when using STORED mode - unless it is seekable.
+ *
+ * This forces us to process the data twice.
+ */
if (!zOut.isSeekable() && !doCompress) {
long size = 0;
CRC32 cal = new CRC32();
1.17 +17 -0 ant/src/etc/testcases/taskdefs/zip.xml
Index: zip.xml
===================================================================
RCS file: /home/cvs/ant/src/etc/testcases/taskdefs/zip.xml,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- zip.xml 27 Dec 2004 10:15:05 -0000 1.16
+++ zip.xml 2 Feb 2005 23:55:51 -0000 1.17
@@ -139,6 +139,23 @@
<zip destfile="test3.zip" basedir="empty" whenempty="create"
includes="*.xyz"/>
</target>
+ <target name="testCompressionLevel" depends="test6">
+ <length property="test6.length" file="test6.zip" />
+ <zip destFile="testLevel.zip" basedir="." level="9">
+ <include name="*.xml" />
+ <exclude name="zip.*" />
+ </zip>
+ <fail>
+ <condition>
+ <not>
+ <isfileselected file="testLevel.zip">
+ <size when="less" value="${test6.length}" />
+ </isfileselected>
+ </not>
+ </condition>
+ </fail>
+ </target>
+
<target name="cleanup">
<delete file="test3.zip"/>
<delete file="test4.zip"/>
1.24 +4 -1
ant/src/testcases/org/apache/tools/ant/taskdefs/ZipTest.java
Index: ZipTest.java
===================================================================
RCS file:
/home/cvs/ant/src/testcases/org/apache/tools/ant/taskdefs/ZipTest.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- ZipTest.java 27 Dec 2004 10:15:05 -0000 1.23
+++ ZipTest.java 2 Feb 2005 23:55:51 -0000 1.24
@@ -143,6 +143,9 @@
executeTarget("zipEmptyCreate");
assertTrue("archive should be created",
getProject().resolveFile("test3.zip").exists());
-
+ }
+ // Bugzilla Report 25513
+ public void testCompressionLevel() {
+ executeTarget("testCompressionLevel");
}
}
1.33 +33 -20 ant/src/main/org/apache/tools/zip/ZipOutputStream.java
Index: ZipOutputStream.java
===================================================================
RCS file: /home/cvs/ant/src/main/org/apache/tools/zip/ZipOutputStream.java,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -r1.32 -r1.33
--- ZipOutputStream.java 6 Jan 2005 18:27:36 -0000 1.32
+++ ZipOutputStream.java 2 Feb 2005 23:55:51 -0000 1.33
@@ -55,6 +55,27 @@
public class ZipOutputStream extends FilterOutputStream {
/**
+ * Compression method for deflated entries.
+ *
+ * @since 1.1
+ */
+ public static final int DEFLATED = java.util.zip.ZipEntry.DEFLATED;
+
+ /**
+ * Default compression level for deflated entries.
+ *
+ * @since Ant 1.7
+ */
+ public static final int DEFAULT_COMPRESSION =
Deflater.DEFAULT_COMPRESSION;
+
+ /**
+ * Compression method for stored entries.
+ *
+ * @since 1.1
+ */
+ public static final int STORED = java.util.zip.ZipEntry.STORED;
+
+ /**
* Current entry.
*
* @since 1.1
@@ -73,7 +94,7 @@
*
* @since 1.1
*/
- private int level = Deflater.DEFAULT_COMPRESSION;
+ private int level = DEFAULT_COMPRESSION;
/**
* Has the compression level changed when compared to the last
@@ -182,7 +203,7 @@
*
* @since 1.14
*/
- protected Deflater def = new Deflater(Deflater.DEFAULT_COMPRESSION,
true);
+ protected Deflater def = new Deflater(level, true);
/**
* This buffer servers as a Deflater.
@@ -204,20 +225,6 @@
private RandomAccessFile raf = null;
/**
- * Compression method for deflated entries.
- *
- * @since 1.1
- */
- public static final int DEFLATED = java.util.zip.ZipEntry.DEFLATED;
-
- /**
- * Compression method for stored entries.
- *
- * @since 1.1
- */
- public static final int STORED = java.util.zip.ZipEntry.STORED;
-
- /**
* Creates a new ZIP OutputStream filtering the underlying stream.
* @param out the outputstream to zip
* @since 1.1
@@ -430,10 +437,16 @@
* Sets the compression level for subsequent entries.
*
* <p>Default is Deflater.DEFAULT_COMPRESSION.</p>
- * @param level the compression level
+ * @param level the compression level.
+ * @throws IllegalArgumentException if an invalid compression level is
specified.
* @since 1.1
*/
public void setLevel(int level) {
+ if (level < Deflater.DEFAULT_COMPRESSION
+ || level > Deflater.BEST_COMPRESSION) {
+ throw new IllegalArgumentException(
+ "Invalid compression level: " + level);
+ }
hasCompressionLevelChanged = (this.level != level);
this.level = level;
}
@@ -843,7 +856,7 @@
*
* @since 1.14
*/
- protected final void writeOut(byte [] data) throws IOException {
+ protected final void writeOut(byte[] data) throws IOException {
writeOut(data, 0, data.length);
}
@@ -856,7 +869,7 @@
*
* @since 1.14
*/
- protected final void writeOut(byte [] data, int offset, int length)
+ protected final void writeOut(byte[] data, int offset, int length)
throws IOException {
if (raf != null) {
raf.write(data, offset, length);
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]