diff --git a/docs/manual/CoreTasks/jar.html b/docs/manual/CoreTasks/jar.html
index 9ce35407b..a3284abd0 100644
--- a/docs/manual/CoreTasks/jar.html
+++ b/docs/manual/CoreTasks/jar.html
@@ -151,6 +151,11 @@ being wrapped and continued on the next line.
whether to create an index list to speed up classloading. This is a JDK 1.3+ specific feature. Defaults to false. |
No |
+
+ manifestencoding |
+ The encoding used to read the JAR manifest, when a manifest file is specified. |
+ No, defaults to the platform encoding. |
+
Nested elements
diff --git a/docs/manual/CoreTasks/manifest.html b/docs/manual/CoreTasks/manifest.html
index a602a7f18..d64c785d7 100644
--- a/docs/manual/CoreTasks/manifest.html
+++ b/docs/manual/CoreTasks/manifest.html
@@ -39,6 +39,11 @@ line.
One of "update" or "replace", default is "replace". |
No |
+
+ encoding |
+ The encoding used to read the existing manifest when updating. |
+ No, defaults to UTF-8 encoding. |
+
Nested elements
diff --git a/src/main/org/apache/tools/ant/loader/AntClassLoader2.java b/src/main/org/apache/tools/ant/loader/AntClassLoader2.java
index 3b891f791..f9a91920f 100644
--- a/src/main/org/apache/tools/ant/loader/AntClassLoader2.java
+++ b/src/main/org/apache/tools/ant/loader/AntClassLoader2.java
@@ -283,7 +283,8 @@ public class AntClassLoader2 extends AntClassLoader {
if (manifestStream == null) {
return;
}
- Reader manifestReader = new InputStreamReader(manifestStream);
+ Reader manifestReader
+ = new InputStreamReader(manifestStream, "UTF-8");
org.apache.tools.ant.taskdefs.Manifest manifest
= new org.apache.tools.ant.taskdefs.Manifest(manifestReader);
classpath
diff --git a/src/main/org/apache/tools/ant/taskdefs/Jar.java b/src/main/org/apache/tools/ant/taskdefs/Jar.java
index c8a3904d3..c3e90e2db 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Jar.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Jar.java
@@ -61,6 +61,7 @@ import java.io.FileOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
@@ -124,6 +125,9 @@ public class Jar extends Zip {
/** the manifest specified by the 'manifest' attribute **/
private Manifest manifest;
+ /** The encoding to use when reading in a manifest file */
+ private String manifestEncoding;
+
/**
* The file found from the 'manifest' attribute. This can be
* either the location of a manifest, or the name of a jar added
@@ -172,6 +176,14 @@ public class Jar extends Zip {
index = flag;
}
+ /**
+ * Set whether or not to create an index list for classes.
+ * This may speed up classloading in some cases.
+ */
+ public void setManifestEncoding(String manifestEncoding) {
+ this.manifestEncoding = manifestEncoding;
+ }
+
/**
* Allows the manifest for the archive file to be provided inline
* in the build file rather than in an external file.
@@ -212,8 +224,15 @@ public class Jar extends Zip {
InputStreamReader isr = null;
try {
fis = new FileInputStream(manifestFile);
- isr = new InputStreamReader(fis, "UTF-8");
+ if (manifestEncoding == null) {
+ isr = new InputStreamReader(fis);
+ } else {
+ isr = new InputStreamReader(fis, manifestEncoding);
+ }
newManifest = getManifest(isr);
+ } catch (UnsupportedEncodingException e) {
+ throw new BuildException("Unsupported encoding while reading manifest: "
+ + e.getMessage(), e);
} catch (IOException e) {
throw new BuildException("Unable to read manifest file: "
+ manifestFile
@@ -466,10 +485,21 @@ public class Jar extends Zip {
// If this is the same name specified in 'manifest', this
// is the manifest to use
log("Found manifest " + file, Project.MSG_VERBOSE);
- if (is != null) {
- manifest = getManifest(new InputStreamReader(is, "UTF-8"));
- } else {
- manifest = getManifest(file);
+ try {
+ if (is != null) {
+ InputStreamReader isr;
+ if (manifestEncoding == null) {
+ isr = new InputStreamReader(is);
+ } else {
+ isr = new InputStreamReader(is, manifestEncoding);
+ }
+ manifest = getManifest(isr);
+ } else {
+ manifest = getManifest(file);
+ }
+ } catch (UnsupportedEncodingException e) {
+ throw new BuildException("Unsupported encoding while reading "
+ + "manifest: " + e.getMessage(), e);
}
} else if (filesetManifestConfig != null &&
!filesetManifestConfig.getValue().equals("skip")) {
@@ -480,8 +510,13 @@ public class Jar extends Zip {
try {
Manifest newManifest = null;
if (is != null) {
- newManifest
- = getManifest(new InputStreamReader(is, "UTF-8"));
+ InputStreamReader isr;
+ if (manifestEncoding == null) {
+ isr = new InputStreamReader(is);
+ } else {
+ isr = new InputStreamReader(is, manifestEncoding);
+ }
+ newManifest = getManifest(isr);
} else {
newManifest = getManifest(file);
}
@@ -491,6 +526,9 @@ public class Jar extends Zip {
} else {
filesetManifest.merge(newManifest);
}
+ } catch (UnsupportedEncodingException e) {
+ throw new BuildException("Unsupported encoding while reading "
+ + "manifest: " + e.getMessage(), e);
} catch (ManifestException e) {
log("Manifest in file " + file + " is invalid: "
+ e.getMessage(), Project.MSG_ERR);
diff --git a/src/main/org/apache/tools/ant/taskdefs/ManifestTask.java b/src/main/org/apache/tools/ant/taskdefs/ManifestTask.java
index cd2667cfa..4355e38e1 100644
--- a/src/main/org/apache/tools/ant/taskdefs/ManifestTask.java
+++ b/src/main/org/apache/tools/ant/taskdefs/ManifestTask.java
@@ -96,6 +96,11 @@ public class ManifestTask extends Task {
*/
private Mode mode;
+ /**
+ * The encoding of the manifest file
+ */
+ private String encoding;
+
/**
* Helper class for Manifest's mode attribute.
*/
@@ -148,6 +153,14 @@ public class ManifestTask extends Task {
manifestFile = f;
}
+ /**
+ * The encoding to use for reading in an existing manifest file
+ * @param encoding the maniofets file encoding.
+ */
+ public void setEncoding(String encoding) {
+ this.encoding = encoding;
+ }
+
/**
* Update policy: either "update" or "replace"; default is "replace".
* @param m the mode value - update or replace.
@@ -175,7 +188,11 @@ public class ManifestTask extends Task {
InputStreamReader isr = null;
try {
fis = new FileInputStream(manifestFile);
- isr = new InputStreamReader(fis, "UTF-8");
+ if (encoding == null) {
+ isr = new InputStreamReader(fis, "UTF-8");
+ } else {
+ isr = new InputStreamReader(fis, encoding);
+ }
current = new Manifest(isr);
} catch (ManifestException m) {
error = new BuildException("Existing manifest " + manifestFile