diff --git a/WHATSNEW b/WHATSNEW
index 939c5dc29..e65a1ddac 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -84,6 +84,16 @@ Fixed bugs:
* TarEntry's constructor with a File and a String arg didn't
normalize the name.
+ * Between 1.8.4 and 1.9.5 TarArchiveInputStream started to parse file
+ names using the platform's default encoding rather than as ASCII.
+ This has been a breaking change that has never been marked as such
+ (in fact it went unnoticed). In order to allow
untar
task.unzip
and the
+ platform's default encoding for the untar
task. Use
+ the magic value
native-encoding
for the platform's default character
encoding.
The fullpath attribute can only be set for filesets that diff --git a/manual/Types/zipfileset.html b/manual/Types/zipfileset.html index 486148a70..955e2718e 100644 --- a/manual/Types/zipfileset.html +++ b/manual/Types/zipfileset.html @@ -97,7 +97,6 @@ directories. Default is 755. since Ant 1.5.2. inside the zip file. For a list of possible values see the Supported Encodings. Defaults to the platform's default character encoding. - Only supported by zipfileset.
For a list of possible values see http://java.sun.com/j2se/1.5.0/docs/guide/intl/encoding.doc.html.
+ * @param encoding the encoding name + * + * @since Ant 1.9.5 + */ + public void setEncoding(final String encoding) { + this.encoding = encoding; + } + /** * do the business * @throws BuildException on error @@ -304,7 +324,8 @@ public class Tar extends MatchingTask { tOut = new TarOutputStream( compression.compress( new BufferedOutputStream( - new FileOutputStream(tarFile)))); + new FileOutputStream(tarFile))), + encoding); tOut.setDebug(true); if (longFileMode.isTruncateMode()) { tOut.setLongFileMode(TarOutputStream.LONGFILE_TRUNCATE); diff --git a/src/main/org/apache/tools/ant/taskdefs/Untar.java b/src/main/org/apache/tools/ant/taskdefs/Untar.java index 5e033f7fb..8343aec52 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Untar.java +++ b/src/main/org/apache/tools/ant/taskdefs/Untar.java @@ -58,6 +58,10 @@ public class Untar extends Expand { */ private UntarCompressionMethod compression = new UntarCompressionMethod(); + public Untar() { + super(null); + } + /** * Set decompression algorithm to use; default=none. * @@ -74,18 +78,6 @@ public class Untar extends Expand { compression = method; } - /** - * No encoding support in Untar. - * @param encoding not used - * @throws BuildException always - * @since Ant 1.6 - */ - public void setEncoding(String encoding) { - throw new BuildException("The " + getTaskName() - + " task doesn't support the encoding" - + " attribute", getLocation()); - } - /** * No unicode extra fields in tar. * @@ -157,7 +149,8 @@ public class Untar extends Expand { try { tis = new TarInputStream(compression.decompress(name, - new BufferedInputStream(stream))); + new BufferedInputStream(stream)), + getEncoding()); log("Expanding: " + name + " into " + dir, Project.MSG_INFO); TarEntry te = null; boolean empty = true; diff --git a/src/main/org/apache/tools/ant/types/ArchiveFileSet.java b/src/main/org/apache/tools/ant/types/ArchiveFileSet.java index 2e1659a5b..e9a07303f 100644 --- a/src/main/org/apache/tools/ant/types/ArchiveFileSet.java +++ b/src/main/org/apache/tools/ant/types/ArchiveFileSet.java @@ -72,6 +72,8 @@ public abstract class ArchiveFileSet extends FileSet { private boolean errorOnMissingArchive = true; + private String encoding = null; + /** Constructor for ArchiveFileSet */ public ArchiveFileSet() { super(); @@ -100,6 +102,7 @@ public abstract class ArchiveFileSet extends FileSet { fileModeHasBeenSet = fileset.fileModeHasBeenSet; dirModeHasBeenSet = fileset.dirModeHasBeenSet; errorOnMissingArchive = fileset.errorOnMissingArchive; + encoding = fileset.encoding; } /** @@ -267,6 +270,33 @@ public abstract class ArchiveFileSet extends FileSet { return fullpath; } + /** + * Set the encoding used for this ZipFileSet. + * @param enc encoding as String. + * @since Ant 1.9.5 + */ + public void setEncoding(String enc) { + checkAttributesAllowed(); + this.encoding = enc; + } + + /** + * Get the encoding used for this ZipFileSet. + * @return String encoding. + * @since Ant 1.9.5 + */ + public String getEncoding() { + if (isReference()) { + AbstractFileSet ref = getRef(getProject()); + if (ref instanceof ArchiveFileSet) { + return ((ArchiveFileSet) ref).getEncoding(); + } else { + return null; + } + } + return encoding; + } + /** * Creates a scanner for this type of archive. * @return the scanner. diff --git a/src/main/org/apache/tools/ant/types/TarFileSet.java b/src/main/org/apache/tools/ant/types/TarFileSet.java index eec1dfa0c..6446e9bf0 100644 --- a/src/main/org/apache/tools/ant/types/TarFileSet.java +++ b/src/main/org/apache/tools/ant/types/TarFileSet.java @@ -180,6 +180,7 @@ public class TarFileSet extends ArchiveFileSet { */ protected ArchiveScanner newArchiveScanner() { TarScanner zs = new TarScanner(); + zs.setEncoding(getEncoding()); return zs; } diff --git a/src/main/org/apache/tools/ant/types/TarScanner.java b/src/main/org/apache/tools/ant/types/TarScanner.java index 1bac2f404..a3c7f6d52 100644 --- a/src/main/org/apache/tools/ant/types/TarScanner.java +++ b/src/main/org/apache/tools/ant/types/TarScanner.java @@ -58,7 +58,7 @@ public class TarScanner extends ArchiveScanner { try { try { - ti = new TarInputStream(src.getInputStream()); + ti = new TarInputStream(src.getInputStream(), encoding); } catch (IOException ex) { throw new BuildException("problem opening " + srcFile, ex); } @@ -84,4 +84,4 @@ public class TarScanner extends ArchiveScanner { FileUtils.close(ti); } } -} \ No newline at end of file +} diff --git a/src/main/org/apache/tools/ant/types/ZipFileSet.java b/src/main/org/apache/tools/ant/types/ZipFileSet.java index eb6a694dc..24f0ccd55 100644 --- a/src/main/org/apache/tools/ant/types/ZipFileSet.java +++ b/src/main/org/apache/tools/ant/types/ZipFileSet.java @@ -33,8 +33,6 @@ import org.apache.tools.ant.Project; */ public class ZipFileSet extends ArchiveFileSet { - private String encoding = null; - /** Constructor for ZipFileSet */ public ZipFileSet() { super(); @@ -54,34 +52,6 @@ public class ZipFileSet extends ArchiveFileSet { */ protected ZipFileSet(ZipFileSet fileset) { super(fileset); - encoding = fileset.encoding; - } - - /** - * Set the encoding used for this ZipFileSet. - * @param enc encoding as String. - * @since Ant 1.7 - */ - public void setEncoding(String enc) { - checkZipFileSetAttributesAllowed(); - this.encoding = enc; - } - - /** - * Get the encoding used for this ZipFileSet. - * @return String encoding. - * @since Ant 1.7 - */ - public String getEncoding() { - if (isReference()) { - AbstractFileSet ref = getRef(getProject()); - if (ref instanceof ZipFileSet) { - return ((ZipFileSet) ref).getEncoding(); - } else { - return null; - } - } - return encoding; } /** @@ -90,7 +60,7 @@ public class ZipFileSet extends ArchiveFileSet { */ protected ArchiveScanner newArchiveScanner() { ZipScanner zs = new ZipScanner(); - zs.setEncoding(encoding); + zs.setEncoding(getEncoding()); return zs; } diff --git a/src/tests/antunit/types/tarfileset-test.xml b/src/tests/antunit/types/tarfileset-test.xml index 02a2e6788..3c4d3a981 100644 --- a/src/tests/antunit/types/tarfileset-test.xml +++ b/src/tests/antunit/types/tarfileset-test.xml @@ -34,4 +34,15 @@