Browse Source

Read/Write manifests in UTF-8

PR:	17075


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274074 13f79535-47bb-0310-9956-ffa450edef68
master
Conor MacNeill 22 years ago
parent
commit
a4be70fbf0
2 changed files with 31 additions and 21 deletions
  1. +16
    -12
      src/main/org/apache/tools/ant/taskdefs/Jar.java
  2. +15
    -9
      src/main/org/apache/tools/ant/taskdefs/ManifestTask.java

+ 16
- 12
src/main/org/apache/tools/ant/taskdefs/Jar.java View File

@@ -58,7 +58,7 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
@@ -204,7 +204,7 @@ public class Jar extends Zip {
* or the name of a jar added through a fileset. If its the name of an added * or the name of a jar added through a fileset. If its the name of an added
* jar, the task expects the manifest to be in the jar at META-INF/MANIFEST.MF. * jar, the task expects the manifest to be in the jar at META-INF/MANIFEST.MF.
* *
* @param manifestFile
* @param manifestFile the manifest file to use.
*/ */
public void setManifest(File manifestFile) { public void setManifest(File manifestFile) {
if (!manifestFile.exists()) { if (!manifestFile.exists()) {
@@ -218,18 +218,20 @@ public class Jar extends Zip {
private Manifest getManifest(File manifestFile) { private Manifest getManifest(File manifestFile) {


Manifest newManifest = null; Manifest newManifest = null;
Reader r = null;
FileInputStream fis = null;
InputStreamReader isr = null;
try { try {
r = new FileReader(manifestFile);
newManifest = getManifest(r);
fis = new FileInputStream(manifestFile);
isr = new InputStreamReader(fis, "UTF-8");
newManifest = getManifest(isr);
} catch (IOException e) { } catch (IOException e) {
throw new BuildException("Unable to read manifest file: " throw new BuildException("Unable to read manifest file: "
+ manifestFile + manifestFile
+ " (" + e.getMessage() + ")", e); + " (" + e.getMessage() + ")", e);
} finally { } finally {
if (r != null) {
if (isr != null) {
try { try {
r.close();
isr.close();
} catch (IOException e) { } catch (IOException e) {
// do nothing // do nothing
} }
@@ -254,8 +256,9 @@ public class Jar extends Zip {
while (enum.hasMoreElements()) { while (enum.hasMoreElements()) {
ZipEntry ze = (ZipEntry) enum.nextElement(); ZipEntry ze = (ZipEntry) enum.nextElement();
if (ze.getName().equalsIgnoreCase(MANIFEST_NAME)) { if (ze.getName().equalsIgnoreCase(MANIFEST_NAME)) {
return getManifest(new InputStreamReader(zf
.getInputStream(ze)));
InputStreamReader isr =
new InputStreamReader(zf.getInputStream(ze), "UTF-8");
return getManifest(isr);
} }
} }
return null; return null;
@@ -467,13 +470,13 @@ public class Jar extends Zip {
} }
} }


private void filesetManifest(File file, InputStream is) {
private void filesetManifest(File file, InputStream is) throws IOException {
if (manifestFile != null && manifestFile.equals(file)) { if (manifestFile != null && manifestFile.equals(file)) {
// If this is the same name specified in 'manifest', this // If this is the same name specified in 'manifest', this
// is the manifest to use // is the manifest to use
log("Found manifest " + file, Project.MSG_VERBOSE); log("Found manifest " + file, Project.MSG_VERBOSE);
if (is != null) { if (is != null) {
manifest = getManifest(new InputStreamReader(is));
manifest = getManifest(new InputStreamReader(is, "UTF-8"));
} else { } else {
manifest = getManifest(file); manifest = getManifest(file);
} }
@@ -486,7 +489,8 @@ public class Jar extends Zip {
try { try {
Manifest newManifest = null; Manifest newManifest = null;
if (is != null) { if (is != null) {
newManifest = getManifest(new InputStreamReader(is));
newManifest
= getManifest(new InputStreamReader(is, "UTF-8"));
} else { } else {
newManifest = getManifest(file); newManifest = getManifest(file);
} }


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

@@ -1,7 +1,7 @@
/* /*
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
* *
* Copyright (c) 2002 The Apache Software Foundation. All rights
* Copyright (c) 2002-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
@@ -55,8 +55,10 @@
package org.apache.tools.ant.taskdefs; package org.apache.tools.ant.taskdefs;


import java.io.File; import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
@@ -169,10 +171,12 @@ public class ManifestTask extends Task {
BuildException error = null; BuildException error = null;


if (manifestFile.exists()) { if (manifestFile.exists()) {
FileReader f = null;
FileInputStream fis = null;
InputStreamReader isr = null;
try { try {
f = new FileReader(manifestFile);
current = new Manifest(f);
fis = new FileInputStream(manifestFile);
isr = new InputStreamReader(fis, "UTF-8");
current = new Manifest(isr);
} catch (ManifestException m) { } catch (ManifestException m) {
error = new BuildException("Existing manifest " + manifestFile error = new BuildException("Existing manifest " + manifestFile
+ " is invalid", m, getLocation()); + " is invalid", m, getLocation());
@@ -180,9 +184,9 @@ public class ManifestTask extends Task {
error = new BuildException("Failed to read " + manifestFile, error = new BuildException("Failed to read " + manifestFile,
e, getLocation()); e, getLocation());
} finally { } finally {
if (f != null) {
if (isr != null) {
try { try {
f.close();
isr.close();
} catch (IOException e) {} } catch (IOException e) {}
} }
} }
@@ -210,7 +214,9 @@ public class ManifestTask extends Task {


PrintWriter w = null; PrintWriter w = null;
try { try {
w = new PrintWriter(new FileWriter(manifestFile));
FileOutputStream fos = new FileOutputStream(manifestFile);
OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8");
w = new PrintWriter(osw);
toWrite.write(w); toWrite.write(w);
} catch (IOException e) { } catch (IOException e) {
throw new BuildException("Failed to write " + manifestFile, throw new BuildException("Failed to write " + manifestFile,


Loading…
Cancel
Save