Browse Source

Fix backwards compatibility

master
Gintas Grigelionis 6 years ago
parent
commit
c5b8dab910
3 changed files with 10 additions and 7 deletions
  1. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/Jar.java
  2. +8
    -5
      src/main/org/apache/tools/ant/taskdefs/Manifest.java
  3. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/ManifestTask.java

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

@@ -533,7 +533,7 @@ public class Jar extends Zip {
JAR_MARKER); JAR_MARKER);
// time to write the manifest // time to write the manifest
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStreamWriter osw = new OutputStreamWriter(baos, Manifest.JAR_ENCODING);
OutputStreamWriter osw = new OutputStreamWriter(baos, Manifest.JAR_CHARSET);
PrintWriter writer = new PrintWriter(osw); PrintWriter writer = new PrintWriter(osw);
manifest.write(writer, flattenClassPaths); manifest.write(writer, flattenClassPaths);
if (writer.checkError()) { if (writer.checkError()) {


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

@@ -91,8 +91,11 @@ public class Manifest {
public static final String ERROR_FROM_FORBIDDEN = "Manifest attributes should not start " public static final String ERROR_FROM_FORBIDDEN = "Manifest attributes should not start "
+ "with \"" + ATTRIBUTE_FROM + "\" in \""; + "with \"" + ATTRIBUTE_FROM + "\" in \"";


/** Charset to be used for JAR files. */
public static final Charset JAR_CHARSET = StandardCharsets.UTF_8;
/** Encoding to be used for JAR files. */ /** Encoding to be used for JAR files. */
public static final Charset JAR_ENCODING = StandardCharsets.UTF_8;
@Deprecated
public static final String JAR_ENCODING = JAR_CHARSET.name();


private static final String ATTRIBUTE_MANIFEST_VERSION_LC = private static final String ATTRIBUTE_MANIFEST_VERSION_LC =
ATTRIBUTE_MANIFEST_VERSION.toLowerCase(Locale.ENGLISH); ATTRIBUTE_MANIFEST_VERSION.toLowerCase(Locale.ENGLISH);
@@ -342,7 +345,7 @@ public class Manifest {
private void writeValue(PrintWriter writer, String value) private void writeValue(PrintWriter writer, String value)
throws IOException { throws IOException {
String line; String line;
int nameLength = name.getBytes(JAR_ENCODING).length;
int nameLength = name.getBytes(JAR_CHARSET).length;
if (nameLength > MAX_NAME_VALUE_LENGTH) { if (nameLength > MAX_NAME_VALUE_LENGTH) {
if (nameLength > MAX_NAME_LENGTH) { if (nameLength > MAX_NAME_LENGTH) {
throw new IOException("Unable to write manifest line " throw new IOException("Unable to write manifest line "
@@ -353,14 +356,14 @@ public class Manifest {
} else { } else {
line = name + ": " + value; line = name + ": " + value;
} }
while (line.getBytes(JAR_ENCODING).length > MAX_SECTION_LENGTH) {
while (line.getBytes(JAR_CHARSET).length > MAX_SECTION_LENGTH) {
// try to find a MAX_LINE_LENGTH byte section // try to find a MAX_LINE_LENGTH byte section
int breakIndex = MAX_SECTION_LENGTH; int breakIndex = MAX_SECTION_LENGTH;
if (breakIndex >= line.length()) { if (breakIndex >= line.length()) {
breakIndex = line.length() - 1; breakIndex = line.length() - 1;
} }
String section = line.substring(0, breakIndex); String section = line.substring(0, breakIndex);
while (section.getBytes(JAR_ENCODING).length > MAX_SECTION_LENGTH
while (section.getBytes(JAR_CHARSET).length > MAX_SECTION_LENGTH
&& breakIndex > 0) { && breakIndex > 0) {
breakIndex--; breakIndex--;
section = line.substring(0, breakIndex); section = line.substring(0, breakIndex);
@@ -756,7 +759,7 @@ public class Manifest {
throw new BuildException("Could not find default manifest: %s", throw new BuildException("Could not find default manifest: %s",
defManifest); defManifest);
} }
Manifest defaultManifest = new Manifest(new InputStreamReader(in, JAR_ENCODING));
Manifest defaultManifest = new Manifest(new InputStreamReader(in, JAR_CHARSET));
String version = System.getProperty("java.runtime.version"); String version = System.getProperty("java.runtime.version");
if (version == null) { if (version == null) {
version = System.getProperty("java.vm.version"); version = System.getProperty("java.vm.version");


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

@@ -264,7 +264,7 @@ public class ManifestTask extends Task {
} }


try (PrintWriter w = new PrintWriter(new OutputStreamWriter( try (PrintWriter w = new PrintWriter(new OutputStreamWriter(
Files.newOutputStream(manifestFile.toPath()), Manifest.JAR_ENCODING))) {
Files.newOutputStream(manifestFile.toPath()), Manifest.JAR_CHARSET))) {
toWrite.write(w, flattenClassPaths); toWrite.write(w, flattenClassPaths);
if (w.checkError()) { if (w.checkError()) {
throw new IOException("Encountered an error writing manifest"); throw new IOException("Encountered an error writing manifest");


Loading…
Cancel
Save