Browse Source

Use the proper encoding for the default manifest.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270114 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 23 years ago
parent
commit
9a9e3a3581
2 changed files with 20 additions and 15 deletions
  1. +15
    -9
      src/main/org/apache/tools/ant/taskdefs/Jar.java
  2. +5
    -6
      src/main/org/apache/tools/ant/taskdefs/Manifest.java

+ 15
- 9
src/main/org/apache/tools/ant/taskdefs/Jar.java View File

@@ -128,10 +128,10 @@ public class Jar extends Zip {


this.manifestFile = manifestFile; this.manifestFile = manifestFile;
InputStream is = null;
Reader r = null;
try { try {
is = new FileInputStream(manifestFile);
Manifest newManifest = new Manifest(is);
r = new FileReader(manifestFile);
Manifest newManifest = new Manifest(r);
if (manifest == null) { if (manifest == null) {
manifest = getDefaultManifest(); manifest = getDefaultManifest();
} }
@@ -145,9 +145,9 @@ public class Jar extends Zip {
throw new BuildException("Unable to read manifest file: " + manifestFile, e); throw new BuildException("Unable to read manifest file: " + manifestFile, e);
} }
finally { finally {
if (is != null) {
if (r != null) {
try { try {
is.close();
r.close();
} }
catch (IOException e) { catch (IOException e) {
// do nothing // do nothing
@@ -259,7 +259,13 @@ public class Jar extends Zip {
if (in == null) { if (in == null) {
throw new BuildException("Could not find default manifest: " + s); throw new BuildException("Could not find default manifest: " + s);
} }
return new Manifest(in);
try {
return new Manifest(new InputStreamReader(in, "ASCII"));
} catch (UnsupportedEncodingException e) {
// impossible with ASCII encoding
log("ASCII encoding not supported by JVM", Project.MSG_ERR);
return new Manifest(new InputStreamReader(in));
}
} }
catch (ManifestException e) { catch (ManifestException e) {
throw new BuildException("Default manifest is invalid !!"); throw new BuildException("Default manifest is invalid !!");
@@ -280,10 +286,10 @@ public class Jar extends Zip {
private void zipManifestEntry(InputStream is) throws IOException { private void zipManifestEntry(InputStream is) throws IOException {
try { try {
if (execManifest == null) { if (execManifest == null) {
execManifest = new Manifest(is);
execManifest = new Manifest(new InputStreamReader(is));
} }
else if (isAddingNewFiles()) { else if (isAddingNewFiles()) {
execManifest.merge(new Manifest(is));
execManifest.merge(new Manifest(new InputStreamReader(is)));
} }
} }
catch (ManifestException e) { catch (ManifestException e) {
@@ -344,7 +350,7 @@ public class Jar extends Zip {
log("Updating jar since the current jar has no manifest", Project.MSG_VERBOSE); log("Updating jar since the current jar has no manifest", Project.MSG_VERBOSE);
return false; return false;
} }
Manifest currentManifest = new Manifest(theZipFile.getInputStream(entry));
Manifest currentManifest = new Manifest(new InputStreamReader(theZipFile.getInputStream(entry)));
if (manifest == null) { if (manifest == null) {
manifest = getDefaultManifest(); manifest = getDefaultManifest();
} }


+ 5
- 6
src/main/org/apache/tools/ant/taskdefs/Manifest.java View File

@@ -60,8 +60,7 @@ import java.util.Enumeration;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringWriter; import java.io.StringWriter;


import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
@@ -504,15 +503,15 @@ public class Manifest {
} }


/** /**
* Read a manifest file from the given input stream
* Read a manifest file from the given reader
* *
* @param is the input stream from which the Manifest is read
* @param is the reader from which the Manifest is read
* *
* @throws ManifestException if the manifest is not valid according to the JAR spec * @throws ManifestException if the manifest is not valid according to the JAR spec
* @throws IOException if the manifest cannot be read from the reader. * @throws IOException if the manifest cannot be read from the reader.
*/ */
public Manifest(InputStream is) throws ManifestException, IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
public Manifest(Reader r) throws ManifestException, IOException {
BufferedReader reader = new BufferedReader(r);
// This should be the manifest version // This should be the manifest version
String nextSectionName = mainSection.read(reader); String nextSectionName = mainSection.read(reader);
String readManifestVersion = mainSection.getAttributeValue(ATTRIBUTE_MANIFEST_VERSION); String readManifestVersion = mainSection.getAttributeValue(ATTRIBUTE_MANIFEST_VERSION);


Loading…
Cancel
Save