Browse Source

Add manifest encoding options to control the encoding used to read in

manifests

PR:	17634


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274301 13f79535-47bb-0310-9956-ffa450edef68
master
Conor MacNeill 22 years ago
parent
commit
709e8bb7a2
5 changed files with 75 additions and 9 deletions
  1. +5
    -0
      docs/manual/CoreTasks/jar.html
  2. +5
    -0
      docs/manual/CoreTasks/manifest.html
  3. +2
    -1
      src/main/org/apache/tools/ant/loader/AntClassLoader2.java
  4. +45
    -7
      src/main/org/apache/tools/ant/taskdefs/Jar.java
  5. +18
    -1
      src/main/org/apache/tools/ant/taskdefs/ManifestTask.java

+ 5
- 0
docs/manual/CoreTasks/jar.html View File

@@ -151,6 +151,11 @@ being wrapped and continued on the next line.
<td valign="top">whether to create an <A HREF="http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html#JAR%20Index">index list</A> to speed up classloading. This is a JDK 1.3+ specific feature. Defaults to false. </td> <td valign="top">whether to create an <A HREF="http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html#JAR%20Index">index list</A> to speed up classloading. This is a JDK 1.3+ specific feature. Defaults to false. </td>
<td valign="top" align="center">No</td> <td valign="top" align="center">No</td>
</tr> </tr>
<tr>
<td valign="top">manifestencoding</td>
<td valign="top">The encoding used to read the JAR manifest, when a manifest file is specified.</td>
<td valign="top" align="center">No, defaults to the platform encoding.</td>
</tr>
</table> </table>


<h3>Nested elements</h3> <h3>Nested elements</h3>


+ 5
- 0
docs/manual/CoreTasks/manifest.html View File

@@ -39,6 +39,11 @@ line.</p>
<td valign="top">One of "update" or "replace", default is "replace".</td> <td valign="top">One of "update" or "replace", default is "replace".</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">The encoding used to read the existing manifest when updating.</td>
<td valign="top" align="center">No, defaults to UTF-8 encoding.</td>
</tr>
</table> </table>


<h3>Nested elements</h3> <h3>Nested elements</h3>


+ 2
- 1
src/main/org/apache/tools/ant/loader/AntClassLoader2.java View File

@@ -283,7 +283,8 @@ public class AntClassLoader2 extends AntClassLoader {
if (manifestStream == null) { if (manifestStream == null) {
return; return;
} }
Reader manifestReader = new InputStreamReader(manifestStream);
Reader manifestReader
= new InputStreamReader(manifestStream, "UTF-8");
org.apache.tools.ant.taskdefs.Manifest manifest org.apache.tools.ant.taskdefs.Manifest manifest
= new org.apache.tools.ant.taskdefs.Manifest(manifestReader); = new org.apache.tools.ant.taskdefs.Manifest(manifestReader);
classpath classpath


+ 45
- 7
src/main/org/apache/tools/ant/taskdefs/Jar.java View File

@@ -61,6 +61,7 @@ import java.io.FileOutputStream;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.io.PrintWriter; import java.io.PrintWriter;
@@ -124,6 +125,9 @@ public class Jar extends Zip {
/** the manifest specified by the 'manifest' attribute **/ /** the manifest specified by the 'manifest' attribute **/
private Manifest manifest; 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 * The file found from the 'manifest' attribute. This can be
* either the location of a manifest, or the name of a jar added * either the location of a manifest, or the name of a jar added
@@ -172,6 +176,14 @@ public class Jar extends Zip {
index = flag; 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 * Allows the manifest for the archive file to be provided inline
* in the build file rather than in an external file. * in the build file rather than in an external file.
@@ -212,8 +224,15 @@ public class Jar extends Zip {
InputStreamReader isr = null; InputStreamReader isr = null;
try { try {
fis = new FileInputStream(manifestFile); 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); newManifest = getManifest(isr);
} catch (UnsupportedEncodingException e) {
throw new BuildException("Unsupported encoding while reading manifest: "
+ e.getMessage(), e);
} catch (IOException e) { } catch (IOException e) {
throw new BuildException("Unable to read manifest file: " throw new BuildException("Unable to read manifest file: "
+ manifestFile + manifestFile
@@ -466,10 +485,21 @@ public class Jar extends Zip {
// 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) {
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 && } else if (filesetManifestConfig != null &&
!filesetManifestConfig.getValue().equals("skip")) { !filesetManifestConfig.getValue().equals("skip")) {
@@ -480,8 +510,13 @@ public class Jar extends Zip {
try { try {
Manifest newManifest = null; Manifest newManifest = null;
if (is != 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 { } else {
newManifest = getManifest(file); newManifest = getManifest(file);
} }
@@ -491,6 +526,9 @@ public class Jar extends Zip {
} else { } else {
filesetManifest.merge(newManifest); filesetManifest.merge(newManifest);
} }
} catch (UnsupportedEncodingException e) {
throw new BuildException("Unsupported encoding while reading "
+ "manifest: " + e.getMessage(), e);
} catch (ManifestException e) { } catch (ManifestException e) {
log("Manifest in file " + file + " is invalid: " log("Manifest in file " + file + " is invalid: "
+ e.getMessage(), Project.MSG_ERR); + e.getMessage(), Project.MSG_ERR);


+ 18
- 1
src/main/org/apache/tools/ant/taskdefs/ManifestTask.java View File

@@ -96,6 +96,11 @@ public class ManifestTask extends Task {
*/ */
private Mode mode; private Mode mode;


/**
* The encoding of the manifest file
*/
private String encoding;
/** /**
* Helper class for Manifest's mode attribute. * Helper class for Manifest's mode attribute.
*/ */
@@ -148,6 +153,14 @@ public class ManifestTask extends Task {
manifestFile = f; 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". * Update policy: either "update" or "replace"; default is "replace".
* @param m the mode value - update or replace. * @param m the mode value - update or replace.
@@ -175,7 +188,11 @@ public class ManifestTask extends Task {
InputStreamReader isr = null; InputStreamReader isr = null;
try { try {
fis = new FileInputStream(manifestFile); 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); current = new Manifest(isr);
} catch (ManifestException m) { } catch (ManifestException m) {
error = new BuildException("Existing manifest " + manifestFile error = new BuildException("Existing manifest " + manifestFile


Loading…
Cancel
Save