Browse Source

Make the manifest class more accomodating to malformed manifests

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269405 13f79535-47bb-0310-9956-ffa450edef68
master
Conor MacNeill 24 years ago
parent
commit
af0505dd8a
1 changed files with 29 additions and 19 deletions
  1. +29
    -19
      src/main/org/apache/tools/ant/taskdefs/Manifest.java

+ 29
- 19
src/main/org/apache/tools/ant/taskdefs/Manifest.java View File

@@ -158,12 +158,12 @@ public class Manifest {
return name;
}
public void read(BufferedReader reader) throws IOException {
public String read(BufferedReader reader) throws IOException {
Attribute attribute = null;
while (true) {
String line = reader.readLine();
if (line == null || line.length() == 0) {
return;
return null;
}
if (line.charAt(0) == ' ') {
// continuation line
@@ -174,8 +174,8 @@ public class Manifest {
}
else {
attribute = new Attribute(line);
if (name == null && attribute.getName().equalsIgnoreCase(ATTR_NAME)) {
throw new IOException("The " + ATTR_NAME + " header may not occur in the main section ");
if (attribute.getName().equalsIgnoreCase(ATTR_NAME)) {
return attribute.getValue();
}
if (attribute.getName().toLowerCase().startsWith(ATTR_FROM.toLowerCase())) {
@@ -254,27 +254,37 @@ public class Manifest {
}
// This should be the manifest version
Attribute version = new Attribute(line);
if (!version.getName().equalsIgnoreCase(ATTR_MANIFEST_VERSION)) {
throw new IOException("Manifest must start with \"" + ATTR_MANIFEST_VERSION +
"\" and not \"" + line + "\"");
String nextSectionName = mainSection.read(reader);
String readManifestVersion = mainSection.getAttributeValue(ATTR_MANIFEST_VERSION);
if (readManifestVersion != null) {
manifestVersion = readManifestVersion;
mainSection.removeAttribute(ATTR_MANIFEST_VERSION);
}
manifestVersion = version.getValue();
mainSection.read(reader);

while ((line = reader.readLine()) != null) {
if (line.length() == 0) {
continue;
}
Attribute sectionName = new Attribute(line);
if (!sectionName.getName().equalsIgnoreCase(ATTR_NAME)) {
throw new IOException("Manifest sections should start with a \"" + ATTR_NAME +
"\" attribute and not \"" + sectionName.getName() + "\"");
}
Section section = new Section();
section.setName(sectionName.getValue());
section.read(reader);
if (nextSectionName == null) {
Attribute sectionName = new Attribute(line);
if (!sectionName.getName().equalsIgnoreCase(ATTR_NAME)) {
throw new IOException("Manifest sections should start with a \"" + ATTR_NAME +
"\" attribute and not \"" + sectionName.getName() + "\"");
}
nextSectionName = sectionName.getValue();
}
else {
// we have already started reading this section
// this line is the first attribute. set it and then let the normal
// read handle the rest
Attribute firstAttribute = new Attribute(line);
section.addAttribute(firstAttribute);
}
section.setName(nextSectionName);
nextSectionName = section.read(reader);
sections.put(section.getName().toLowerCase(), section);
}
}


Loading…
Cancel
Save