Package org.apache.tools.ant.taskdefs
Class Manifest
- java.lang.Object
-
- org.apache.tools.ant.taskdefs.Manifest
-
public class Manifest extends java.lang.ObjectHolds 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
Nested Classes Modifier and Type Class Description static classManifest.AttributeAn attribute for the manifest.static classManifest.SectionA manifest section - you can nest attribute elements into sections.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringATTRIBUTE_CLASSPATHThe Class-Path Header is special - it can be duplicatedstatic java.lang.StringATTRIBUTE_FROMThe From Header is disallowed in a Manifeststatic java.lang.StringATTRIBUTE_MANIFEST_VERSIONThe standard manifest version headerstatic java.lang.StringATTRIBUTE_NAMEThe Name Attribute is the first in a named sectionstatic java.lang.StringATTRIBUTE_SIGNATURE_VERSIONThe standard Signature Version headerstatic java.lang.StringDEFAULT_MANIFEST_VERSIONDefault Manifest version if one is not specifiedstatic java.lang.StringEOLThe End-Of-Line marker in manifestsstatic java.lang.StringERROR_FROM_FORBIDDENError for attributesstatic java.nio.charset.CharsetJAR_CHARSETCharset to be used for JAR files.static java.lang.StringJAR_ENCODINGDeprecated.static intMAX_LINE_LENGTHThe max length of a line in a Manifeststatic intMAX_SECTION_LENGTHMax length of a line section which is continued.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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 manifestbooleanequals(java.lang.Object rhs)static ManifestgetDefaultManifest()Construct a manifest from Ant's default manifest file.Manifest.SectiongetMainSection()Get the main section of the manifestjava.lang.StringgetManifestVersion()Get the version of the manifestManifest.SectiongetSection(java.lang.String name)Get a particular section from the manifestjava.util.Enumeration<java.lang.String>getSectionNames()Get the section names in this manifest.java.util.Enumeration<java.lang.String>getWarnings()Get the warnings for this manifest.inthashCode()voidmerge(Manifest other)Merge the contents of the given manifest into this manifest without merging Class-Path attributes.voidmerge(Manifest other, boolean overwriteMain)Merge the contents of the given manifest into this manifest without merging Class-Path attributes.voidmerge(Manifest other, boolean overwriteMain, boolean mergeClassPaths)Merge the contents of the given manifest into this manifestjava.lang.StringtoString()Convert the manifest to its string representationvoidwrite(java.io.PrintWriter writer)Write the manifest out to a print writer without flattening multi-values attributes (i.e.voidwrite(java.io.PrintWriter writer, boolean flatten)Write the manifest out to a print writer.
-
-
-
Field Detail
-
ATTRIBUTE_MANIFEST_VERSION
public static final java.lang.String ATTRIBUTE_MANIFEST_VERSION
The standard manifest version header- See Also:
- Constant Field Values
-
ATTRIBUTE_SIGNATURE_VERSION
public static final java.lang.String ATTRIBUTE_SIGNATURE_VERSION
The standard Signature Version header- See Also:
- Constant Field Values
-
ATTRIBUTE_NAME
public static final java.lang.String ATTRIBUTE_NAME
The Name Attribute is the first in a named section- See Also:
- Constant Field Values
-
ATTRIBUTE_FROM
public static final java.lang.String ATTRIBUTE_FROM
The From Header is disallowed in a Manifest- See Also:
- Constant Field Values
-
ATTRIBUTE_CLASSPATH
public static final java.lang.String ATTRIBUTE_CLASSPATH
The Class-Path Header is special - it can be duplicated- See Also:
- Constant Field Values
-
DEFAULT_MANIFEST_VERSION
public static final java.lang.String DEFAULT_MANIFEST_VERSION
Default Manifest version if one is not specified- See Also:
- Constant Field Values
-
MAX_LINE_LENGTH
public static final int MAX_LINE_LENGTH
The max length of a line in a Manifest- See Also:
- Constant Field Values
-
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.- See Also:
- Constant Field Values
-
EOL
public static final java.lang.String EOL
The End-Of-Line marker in manifests- See Also:
- Constant Field Values
-
ERROR_FROM_FORBIDDEN
public static final java.lang.String ERROR_FROM_FORBIDDEN
Error for attributes- See Also:
- Constant Field Values
-
JAR_CHARSET
public static final java.nio.charset.Charset JAR_CHARSET
Charset to be used for JAR files.
-
JAR_ENCODING
@Deprecated public static final java.lang.String JAR_ENCODING
Deprecated.Encoding to be used for JAR files.
-
-
Constructor Detail
-
Manifest
public Manifest()
Construct an empty manifest
-
Manifest
public Manifest(java.io.Reader r) throws ManifestException, java.io.IOExceptionRead 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 specjava.io.IOException- if the manifest cannot be read from the reader.
-
-
Method Detail
-
getDefaultManifest
public static Manifest getDefaultManifest() throws BuildException
Construct a manifest from Ant's default manifest file.- Returns:
- the default manifest.
- Throws:
BuildException- if there is a problem loading the default manifest
-
addConfiguredSection
public void addConfiguredSection(Manifest.Section section) throws ManifestException
Add a section to the manifest- Parameters:
section- the manifest section to be added- Throws:
ManifestException- if the secti0on is not valid.
-
addConfiguredAttribute
public void addConfiguredAttribute(Manifest.Attribute attribute) throws ManifestException
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.
-
merge
public void merge(Manifest other) throws ManifestException
Merge the contents of the given manifest into this manifest without merging Class-Path attributes.- 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) throws ManifestException
Merge the contents of the given manifest into this manifest without merging Class-Path attributes.- 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.
-
merge
public void merge(Manifest other, boolean overwriteMain, boolean mergeClassPaths) throws ManifestException
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 manifestmergeClassPaths- whether Class-Path attributes should be merged.- Throws:
ManifestException- if there is a problem merging the manifest according to the Manifest spec.- Since:
- Ant 1.8.0
-
write
public void write(java.io.PrintWriter writer) throws java.io.IOExceptionWrite the manifest out to a print writer without flattening multi-values attributes (i.e. Class-Path).- Parameters:
writer- the Writer to which the manifest is written- Throws:
java.io.IOException- if the manifest cannot be written
-
write
public void write(java.io.PrintWriter writer, boolean flatten) throws java.io.IOExceptionWrite the manifest out to a print writer.- Parameters:
writer- the Writer to which the manifest is writtenflatten- whether to collapse multi-valued attributes (i.e. potentially Class-Path) Class-Path into a single attribute.- Throws:
java.io.IOException- if the manifest cannot be written- Since:
- Ant 1.8.0
-
toString
public java.lang.String toString()
Convert the manifest to its string representation- Overrides:
toStringin classjava.lang.Object- Returns:
- a multiline string with the Manifest as it appears in a Manifest file.
-
getWarnings
public java.util.Enumeration<java.lang.String> getWarnings()
Get the warnings for this manifest.- Returns:
- an enumeration of warning strings
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object- Returns:
- a hashcode based on the version, main and sections.
- See Also:
Object.hashCode()
-
equals
public boolean equals(java.lang.Object rhs)
- Overrides:
equalsin classjava.lang.Object- Parameters:
rhs- the object to check for equality.- Returns:
- true if the version, main and sections are the same.
- See Also:
Object.equals(java.lang.Object)
-
getManifestVersion
public java.lang.String getManifestVersion()
Get the version of the manifest- Returns:
- the manifest's version string
-
getMainSection
public Manifest.Section getMainSection()
Get the main section of the manifest- Returns:
- the main section of the manifest
-
getSection
public Manifest.Section getSection(java.lang.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 java.util.Enumeration<java.lang.String> getSectionNames()
Get the section names in this manifest.- Returns:
- an Enumeration of section names
-
-