diff --git a/WHATSNEW b/WHATSNEW index da6d95c0f..fa5575b68 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -453,6 +453,10 @@ Other changes: * FileUtils#createTempFile will now create temporary files in the directory pointed to by the property java.io.tmpdir +* and friends now supports an optional encoding attribute to + enable it to expand archives created with filenames using an encoding + other than UTF8. Bugzilla Report 10504. + Changes from Ant 1.5.2 to Ant 1.5.3 =================================== diff --git a/docs/manual/CoreTasks/unzip.html b/docs/manual/CoreTasks/unzip.html index 6433dc4e3..0dc4f95b9 100644 --- a/docs/manual/CoreTasks/unzip.html +++ b/docs/manual/CoreTasks/unzip.html @@ -46,11 +46,25 @@ to perform unarchival upon. compression - compression method for untar. Allowable values are - "none", "gzip" and "bzip2". Default is - "none". + Note: This attribute is only available for + the untar task.
+ compression method. Allowable values are "none", + "gzip" and "bzip2". Default is + "none". No + + encoding + Note: This attribute is not available for + the untar task.
+ The character encoding that has been used for filenames + inside the zip file. For a list of possible values see http://java.sun.com/products/jdk/1.2/docs/guide/internat/encoding.doc.html.
+ Defaults to "UTF8", use the magic value + native-encoding for the platform's default character + encoding. + No +

Examples

@@ -89,7 +103,7 @@ to perform unarchival upon.


-

Copyright © 2000-2002 Apache Software Foundation. All rights +

Copyright © 2000-2003 Apache Software Foundation. All rights Reserved.

diff --git a/src/etc/testcases/taskdefs/untar.xml b/src/etc/testcases/taskdefs/untar.xml index 801045c2a..e1a34cfa6 100644 --- a/src/etc/testcases/taskdefs/untar.xml +++ b/src/etc/testcases/taskdefs/untar.xml @@ -41,4 +41,7 @@ + + + diff --git a/src/etc/testcases/taskdefs/unzip.xml b/src/etc/testcases/taskdefs/unzip.xml index b61bf6165..9b979f6e0 100644 --- a/src/etc/testcases/taskdefs/unzip.xml +++ b/src/etc/testcases/taskdefs/unzip.xml @@ -78,4 +78,13 @@
+ + + + + + + + + diff --git a/src/main/org/apache/tools/ant/taskdefs/Expand.java b/src/main/org/apache/tools/ant/taskdefs/Expand.java index cbea9be85..7768a4fa6 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Expand.java +++ b/src/main/org/apache/tools/ant/taskdefs/Expand.java @@ -95,9 +95,10 @@ public class Expand extends Task { private boolean overwrite = true; private Vector patternsets = new Vector(); private Vector filesets = new Vector(); - private static final byte[] ZIPMARKER = {0x50, 0x4b, 0x03, 0x04}; - private static final int MARKER_SIZE = ZIPMARKER.length; - private static final int MAX_LOOKAHEAD = 50 * 1024; // 50K. + + private static final String NATIVE_ENCODING = "native-encoding"; + + private String encoding = "UTF8"; /** * Do the work. @@ -155,7 +156,7 @@ public class Expand extends Task { log("Expanding: " + srcF + " into " + dir, Project.MSG_INFO); ZipFile zf = null; try { - zf = new ZipFile(srcF, "UTF8"); + zf = new ZipFile(srcF, encoding); Enumeration enum = zf.getEntries(); while (enum.hasMoreElements()) { ZipEntry ze = (ZipEntry) enum.nextElement(); @@ -324,4 +325,19 @@ public class Expand extends Task { filesets.addElement(set); } + /** + * Sets the encoding to assume for file names and comments. + * + *

Set to native-encoding if you want your + * platform's native encoding, defaults to UTF8.

+ * + * @since Ant 1.6 + */ + public void setEncoding(String encoding) { + if (NATIVE_ENCODING.equals(encoding)) { + encoding = null; + } + this.encoding = encoding; + } + } diff --git a/src/main/org/apache/tools/ant/taskdefs/Untar.java b/src/main/org/apache/tools/ant/taskdefs/Untar.java index 1e40799a1..a2642b69b 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Untar.java +++ b/src/main/org/apache/tools/ant/taskdefs/Untar.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2000-2002 The Apache Software Foundation. All rights + * Copyright (c) 2000-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -112,6 +112,17 @@ public class Untar extends Expand { compression = method; } + /** + * No encoding support in Untar. + * + * @since Ant 1.6 + */ + public void setEncoding(String encoding) { + throw new BuildException("The " + getTaskName() + + " task doesn't support the encoding" + + " attribute", getLocation()); + } + protected void expandFile(FileUtils fileUtils, File srcF, File dir) { TarInputStream tis = null; try { diff --git a/src/testcases/org/apache/tools/ant/taskdefs/UntarTest.java b/src/testcases/org/apache/tools/ant/taskdefs/UntarTest.java index 57540172f..2470719ca 100644 --- a/src/testcases/org/apache/tools/ant/taskdefs/UntarTest.java +++ b/src/testcases/org/apache/tools/ant/taskdefs/UntarTest.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2001-2002 The Apache Software Foundation. All rights + * Copyright (c) 2001-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -53,7 +53,6 @@ */ package org.apache.tools.ant.taskdefs; -import java.io.File; import org.apache.tools.ant.BuildFileTest; import org.apache.tools.ant.util.FileUtils; @@ -117,8 +116,15 @@ public class UntarTest extends BuildFileTest { project.resolveFile("asf-logo.gif"))); } - public void testSrcDirTest() throws java.io.IOException { - FileUtils fileUtils = FileUtils.newFileUtils(); + public void testSrcDirTest() { expectBuildException("srcDirTest", "Src cannot be a directory."); } + + public void testEncoding() { + expectSpecificBuildException("encoding", + " overrides setEncoding.", + "The untar task doesn't support the " + + "encoding attribute"); + } + } diff --git a/src/testcases/org/apache/tools/ant/taskdefs/UnzipTest.java b/src/testcases/org/apache/tools/ant/taskdefs/UnzipTest.java index 103bfabec..09f0fee4b 100644 --- a/src/testcases/org/apache/tools/ant/taskdefs/UnzipTest.java +++ b/src/testcases/org/apache/tools/ant/taskdefs/UnzipTest.java @@ -153,4 +153,13 @@ public class UnzipTest extends BuildFileTest { getProject().resolveFile("unziptestout/2/bar").exists()); } + /* + * PR 10504 + */ + public void testEncoding() { + executeTarget("encodingTest"); + assertTrue("foo has been properly named", + getProject().resolveFile("unziptestout/foo").exists()); + } + }