From af0505dd8ad69538cef3c64f9674c27c1d1775fb Mon Sep 17 00:00:00 2001 From: Conor MacNeill Date: Sun, 29 Jul 2001 13:57:13 +0000 Subject: [PATCH] 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 --- .../apache/tools/ant/taskdefs/Manifest.java | 48 +++++++++++-------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/Manifest.java b/src/main/org/apache/tools/ant/taskdefs/Manifest.java index 2d55f95d3..30756df96 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Manifest.java +++ b/src/main/org/apache/tools/ant/taskdefs/Manifest.java @@ -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); } }