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);
// time to write the manifest
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);
manifest.write(writer, flattenClassPaths);
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 "
+ "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. */
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 =
ATTRIBUTE_MANIFEST_VERSION.toLowerCase(Locale.ENGLISH);
@@ -342,7 +345,7 @@ public class Manifest {
private void writeValue(PrintWriter writer, String value)
throws IOException {
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_LENGTH) {
throw new IOException("Unable to write manifest line "
@@ -353,14 +356,14 @@ public class Manifest {
} else {
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
int breakIndex = MAX_SECTION_LENGTH;
if (breakIndex >= line.length()) {
breakIndex = line.length() - 1;
}
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--;
section = line.substring(0, breakIndex);
@@ -756,7 +759,7 @@ public class Manifest {
throw new BuildException("Could not find default manifest: %s",
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");
if (version == null) {
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(
Files.newOutputStream(manifestFile.toPath()), Manifest.JAR_ENCODING))) {
Files.newOutputStream(manifestFile.toPath()), Manifest.JAR_CHARSET))) {
toWrite.write(w, flattenClassPaths);
if (w.checkError()) {
throw new IOException("Encountered an error writing manifest");


Loading…
Cancel
Save