org.codehaus.plexus.archiver.jar

Class Manifest

public class Manifest extends Object

Holds the data of a jar manifest.

Manifests are processed according to the Jar file specification.. Specifically, a manifest element consists of a set of attributes and sections. These sections in turn may contain attributes. Note in particular that this may result in manifest lines greater than 72 bytes being wrapped and continued on the next line. If an application can not handle the continuation mechanism, it is a defect in the application, not this task.

Since: Ant 1.4

Nested Class Summary
static classManifest.Attribute
An attribute for the manifest.
static classManifest.Section
A manifest section - you can nest attribute elements into sections.
Field Summary
static StringATTRIBUTE_CLASSPATH
The Class-Path Header is special - it can be duplicated
static StringATTRIBUTE_FROM
The From Header is disallowed in a Manifest
static StringATTRIBUTE_MANIFEST_VERSION
The standard manifest version header
static StringATTRIBUTE_NAME
The Name Attribute is the first in a named section
static StringATTRIBUTE_SIGNATURE_VERSION
The standard Signature Version header
static StringDEFAULT_MANIFEST_VERSION
Default Manifest version if one is not specified
static StringEOL
The End-Of-Line marker in manifests
Manifest.SectionmainSection
The main section of this manifest
StringmanifestVersion
The version of this manifest
static intMAX_LINE_LENGTH
The max length of a line in a Manifest
static intMAX_SECTION_LENGTH
Max length of a line section which is continued.
VectorsectionIndex
Index of sections - used to retain order of sections in manifest
Hashtablesections
The named sections of this manifest
Constructor Summary
Manifest()
Construct an empty manifest
Manifest(Reader r)
Read a manifest file from the given reader
Method Summary
voidaddConfiguredAttribute(Manifest.Attribute attribute)
Add an attribute to the manifest - it is added to the main section.
voidaddConfiguredSection(Manifest.Section section)
Add a section to the manifest
booleanequals(Object rhs)
static ManifestgetDefaultManifest()
Construct a manifest from Ant's default manifest file.
Manifest.SectiongetMainSection()
Get the main section of the manifest
StringgetManifestVersion()
Get the version of the manifest
Manifest.SectiongetSection(String name)
Get a particular section from the manifest
EnumerationgetSectionNames()
Get the section names in this manifest.
EnumerationgetWarnings()
Get the warnings for this manifest.
inthashCode()
voidmerge(Manifest other)
Merge the contents of the given manifest into this manifest
voidmerge(Manifest other, boolean overwriteMain)
Merge the contents of the given manifest into this manifest
StringtoString()
Convert the manifest to its string representation
voidwrite(PrintWriter writer)
Write the manifest out to a print writer.

Field Detail

ATTRIBUTE_CLASSPATH

public static final String ATTRIBUTE_CLASSPATH
The Class-Path Header is special - it can be duplicated

ATTRIBUTE_FROM

public static final String ATTRIBUTE_FROM
The From Header is disallowed in a Manifest

ATTRIBUTE_MANIFEST_VERSION

public static final String ATTRIBUTE_MANIFEST_VERSION
The standard manifest version header

ATTRIBUTE_NAME

public static final String ATTRIBUTE_NAME
The Name Attribute is the first in a named section

ATTRIBUTE_SIGNATURE_VERSION

public static final String ATTRIBUTE_SIGNATURE_VERSION
The standard Signature Version header

DEFAULT_MANIFEST_VERSION

public static final String DEFAULT_MANIFEST_VERSION
Default Manifest version if one is not specified

EOL

public static final String EOL
The End-Of-Line marker in manifests

mainSection

private Manifest.Section mainSection
The main section of this manifest

manifestVersion

private String manifestVersion
The version of this manifest

MAX_LINE_LENGTH

public static final int MAX_LINE_LENGTH
The max length of a line in a Manifest

MAX_SECTION_LENGTH

public static final int MAX_SECTION_LENGTH
Max length of a line section which is continued. Need to allow for the CRLF.

sectionIndex

private Vector sectionIndex
Index of sections - used to retain order of sections in manifest

sections

private Hashtable sections
The named sections of this manifest

Constructor Detail

Manifest

public Manifest()
Construct an empty manifest

Manifest

public Manifest(Reader r)
Read a manifest file from the given reader

Parameters: r is the reader from which the Manifest is read

Throws: ManifestException if the manifest is not valid according to the JAR spec IOException if the manifest cannot be read from the reader.

Method Detail

addConfiguredAttribute

public void addConfiguredAttribute(Manifest.Attribute attribute)
Add an attribute to the manifest - it is added to the main section.

Parameters: attribute the attribute to be added.

Throws: ManifestException if the attribute is not valid.

addConfiguredSection

public void addConfiguredSection(Manifest.Section section)
Add a section to the manifest

Parameters: section the manifest section to be added

Throws: ManifestException if the secti0on is not valid.

equals

public boolean equals(Object rhs)

See Also: java.lang.Object#equals

getDefaultManifest

public static Manifest getDefaultManifest()
Construct a manifest from Ant's default manifest file.

Returns: the default manifest.

Throws: ArchiverException if there is a problem loading the default manifest

getMainSection

public Manifest.Section getMainSection()
Get the main section of the manifest

Returns: the main section of the manifest

getManifestVersion

public String getManifestVersion()
Get the version of the manifest

Returns: the manifest's version string

getSection

public Manifest.Section getSection(String name)
Get a particular section from the manifest

Parameters: name the name of the section desired.

Returns: the specified section or null if that section does not exist in the manifest

getSectionNames

public Enumeration getSectionNames()
Get the section names in this manifest.

Returns: an Enumeration of section names

getWarnings

public Enumeration getWarnings()
Get the warnings for this manifest.

Returns: an enumeration of warning strings

hashCode

public int hashCode()

See Also: java.lang.Object#hashCode

merge

public void merge(Manifest other)
Merge the contents of the given manifest into this manifest

Parameters: other the Manifest to be merged with this one.

Throws: ManifestException if there is a problem merging the manifest according to the Manifest spec.

merge

public void merge(Manifest other, boolean overwriteMain)
Merge the contents of the given manifest into this manifest

Parameters: other the Manifest to be merged with this one. overwriteMain whether to overwrite the main section of the current manifest

Throws: ManifestException if there is a problem merging the manifest according to the Manifest spec.

toString

public String toString()
Convert the manifest to its string representation

Returns: a multiline string with the Manifest as it appears in a Manifest file.

write

public void write(PrintWriter writer)
Write the manifest out to a print writer.

Parameters: writer the Writer to which the manifest is written

Throws: IOException if the manifest cannot be written