Browse Source

Add support for filename-encodings other than UTF8 to <untar>.

PR: 10504


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274746 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 22 years ago
parent
commit
f2eb856ffd
8 changed files with 85 additions and 13 deletions
  1. +4
    -0
      WHATSNEW
  2. +18
    -4
      docs/manual/CoreTasks/unzip.html
  3. +3
    -0
      src/etc/testcases/taskdefs/untar.xml
  4. +9
    -0
      src/etc/testcases/taskdefs/unzip.xml
  5. +20
    -4
      src/main/org/apache/tools/ant/taskdefs/Expand.java
  6. +12
    -1
      src/main/org/apache/tools/ant/taskdefs/Untar.java
  7. +10
    -4
      src/testcases/org/apache/tools/ant/taskdefs/UntarTest.java
  8. +9
    -0
      src/testcases/org/apache/tools/ant/taskdefs/UnzipTest.java

+ 4
- 0
WHATSNEW View File

@@ -453,6 +453,10 @@ Other changes:
* FileUtils#createTempFile will now create temporary files in the * FileUtils#createTempFile will now create temporary files in the
directory pointed to by the property java.io.tmpdir directory pointed to by the property java.io.tmpdir


* <unzip> 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 Changes from Ant 1.5.2 to Ant 1.5.3
=================================== ===================================




+ 18
- 4
docs/manual/CoreTasks/unzip.html View File

@@ -46,11 +46,25 @@ to perform unarchival upon.
</tr> </tr>
<tr> <tr>
<td valign="top">compression</td> <td valign="top">compression</td>
<td valign="top">compression method for untar. Allowable values are
&quot;none&quot;, &quot;gzip&quot; and &quot;bzip2&quot;. Default is
&quot;none&quot;.</td>
<td valign="top"><b>Note:</b> This attribute is only available for
the <code>untar</code> task.<br>
compression method. Allowable values are &quot;none&quot;,
&quot;gzip&quot; and &quot;bzip2&quot;. Default is
&quot;none&quot;.</td>
<td valign="top" align="center">No</td> <td valign="top" align="center">No</td>
</tr> </tr>
<tr>
<td valign="top">encoding</td>
<td valign="top"><b>Note:</b> This attribute is not available for
the <code>untar</code> task.<br>
The character encoding that has been used for filenames
inside the zip file. For a list of possible values see <a
href="http://java.sun.com/products/jdk/1.2/docs/guide/internat/encoding.doc.html">http://java.sun.com/products/jdk/1.2/docs/guide/internat/encoding.doc.html</a>.<br>
Defaults to &quot;UTF8&quot;, use the magic value
<code>native-encoding</code> for the platform's default character
encoding.</td>
<td align="center" valign="top">No</td>
</tr>


</table> </table>
<h3>Examples</h3> <h3>Examples</h3>
@@ -89,7 +103,7 @@ to perform unarchival upon.
</pre></p> </pre></p>
</blockquote> </blockquote>
<hr> <hr>
<p align="center">Copyright &copy; 2000-2002 Apache Software Foundation. All rights
<p align="center">Copyright &copy; 2000-2003 Apache Software Foundation. All rights
Reserved.</p> Reserved.</p>


</body> </body>


+ 3
- 0
src/etc/testcases/taskdefs/untar.xml View File

@@ -41,4 +41,7 @@
<untar src="." dest="." /> <untar src="." dest="." />
</target> </target>


<target name="encoding">
<untar src="expected/asf-logo.gif.tar" dest="." encoding="foo"/>
</target>
</project> </project>

+ 9
- 0
src/etc/testcases/taskdefs/unzip.xml View File

@@ -78,4 +78,13 @@
</unzip> </unzip>
</target> </target>


<!-- Bugzilla Report 10504 -->
<target name="encodingTest">
<mkdir dir="unziptestin"/>
<touch file="unziptestin/foo"/>
<zip zipfile="unziptest.zip" basedir="unziptestin" encoding="UTF16"/>
<mkdir dir="unziptestout"/>
<unzip src="unziptest.zip" dest="unziptestout" encoding="UTF16"/>
</target>

</project> </project>

+ 20
- 4
src/main/org/apache/tools/ant/taskdefs/Expand.java View File

@@ -95,9 +95,10 @@ public class Expand extends Task {
private boolean overwrite = true; private boolean overwrite = true;
private Vector patternsets = new Vector(); private Vector patternsets = new Vector();
private Vector filesets = 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. * Do the work.
@@ -155,7 +156,7 @@ public class Expand extends Task {
log("Expanding: " + srcF + " into " + dir, Project.MSG_INFO); log("Expanding: " + srcF + " into " + dir, Project.MSG_INFO);
ZipFile zf = null; ZipFile zf = null;
try { try {
zf = new ZipFile(srcF, "UTF8");
zf = new ZipFile(srcF, encoding);
Enumeration enum = zf.getEntries(); Enumeration enum = zf.getEntries();
while (enum.hasMoreElements()) { while (enum.hasMoreElements()) {
ZipEntry ze = (ZipEntry) enum.nextElement(); ZipEntry ze = (ZipEntry) enum.nextElement();
@@ -324,4 +325,19 @@ public class Expand extends Task {
filesets.addElement(set); filesets.addElement(set);
} }


/**
* Sets the encoding to assume for file names and comments.
*
* <p>Set to <code>native-encoding</code> if you want your
* platform's native encoding, defaults to UTF8.</p>
*
* @since Ant 1.6
*/
public void setEncoding(String encoding) {
if (NATIVE_ENCODING.equals(encoding)) {
encoding = null;
}
this.encoding = encoding;
}

} }

+ 12
- 1
src/main/org/apache/tools/ant/taskdefs/Untar.java View File

@@ -1,7 +1,7 @@
/* /*
* The Apache Software License, Version 1.1 * 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. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -112,6 +112,17 @@ public class Untar extends Expand {
compression = method; 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) { protected void expandFile(FileUtils fileUtils, File srcF, File dir) {
TarInputStream tis = null; TarInputStream tis = null;
try { try {


+ 10
- 4
src/testcases/org/apache/tools/ant/taskdefs/UntarTest.java View File

@@ -1,7 +1,7 @@
/* /*
* The Apache Software License, Version 1.1 * 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. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -53,7 +53,6 @@
*/ */
package org.apache.tools.ant.taskdefs; package org.apache.tools.ant.taskdefs;


import java.io.File;
import org.apache.tools.ant.BuildFileTest; import org.apache.tools.ant.BuildFileTest;
import org.apache.tools.ant.util.FileUtils; import org.apache.tools.ant.util.FileUtils;


@@ -117,8 +116,15 @@ public class UntarTest extends BuildFileTest {
project.resolveFile("asf-logo.gif"))); 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."); expectBuildException("srcDirTest", "Src cannot be a directory.");
} }

public void testEncoding() {
expectSpecificBuildException("encoding",
"<untar> overrides setEncoding.",
"The untar task doesn't support the "
+ "encoding attribute");
}

} }

+ 9
- 0
src/testcases/org/apache/tools/ant/taskdefs/UnzipTest.java View File

@@ -153,4 +153,13 @@ public class UnzipTest extends BuildFileTest {
getProject().resolveFile("unziptestout/2/bar").exists()); getProject().resolveFile("unziptestout/2/bar").exists());
} }


/*
* PR 10504
*/
public void testEncoding() {
executeTarget("encodingTest");
assertTrue("foo has been properly named",
getProject().resolveFile("unziptestout/foo").exists());
}

} }

Loading…
Cancel
Save