| Method from org.apache.tools.ant.taskdefs.Manifest Detail: |
public void addConfiguredAttribute(Attribute attribute) throws ManifestException {
if (attribute.getKey() == null || attribute.getValue() == null) {
throw new BuildException("Attributes must have name and value");
}
if (attribute.getKey().equals(ATTRIBUTE_MANIFEST_VERSION_LC)) {
manifestVersion = attribute.getValue();
} else {
mainSection.addConfiguredAttribute(attribute);
}
}
Add an attribute to the manifest - it is added to the main section. |
public void addConfiguredSection(Section section) throws ManifestException {
String sectionName = section.getName();
if (sectionName == null) {
throw new BuildException("Sections must have a name");
}
sections.put(sectionName, section);
}
Add a section to the manifest |
public boolean equals(Object rhs) {
if (rhs == null || rhs.getClass() != getClass()) {
return false;
}
if (rhs == this) {
return true;
}
Manifest rhsManifest = (Manifest) rhs;
if (manifestVersion == null) {
if (rhsManifest.manifestVersion != null) {
return false;
}
} else if (!manifestVersion.equals(rhsManifest.manifestVersion)) {
return false;
}
if (!mainSection.equals(rhsManifest.mainSection)) {
return false;
}
return sections.equals(rhsManifest.sections);
}
|
public static Manifest getDefaultManifest() throws BuildException {
InputStream in = null;
InputStreamReader insr = null;
try {
String defManifest = "/org/apache/tools/ant/defaultManifest.mf";
in = Manifest.class.getResourceAsStream(defManifest);
if (in == null) {
throw new BuildException("Could not find default manifest: "
+ defManifest);
}
try {
insr = new InputStreamReader(in, "UTF-8");
Manifest defaultManifest = new Manifest(insr);
String version = System.getProperty("java.runtime.version");
if (version == null) {
version = System.getProperty("java.vm.version");
}
Attribute createdBy = new Attribute("Created-By",
version + " ("
+ System.getProperty("java.vm.vendor") + ")");
defaultManifest.getMainSection().storeAttribute(createdBy);
return defaultManifest;
} catch (UnsupportedEncodingException e) {
insr = new InputStreamReader(in);
return new Manifest(insr);
}
} catch (ManifestException e) {
throw new BuildException("Default manifest is invalid !!", e);
} catch (IOException e) {
throw new BuildException("Unable to read default manifest", e);
} finally {
FileUtils.close(insr);
FileUtils.close(in);
}
}
Construct a manifest from Ant's default manifest file. |
public Section getMainSection() {
return mainSection;
}
Get the main section of the manifest |
public String getManifestVersion() {
return manifestVersion;
}
Get the version of the manifest |
public Section getSection(String name) {
return (Section) sections.get(name);
}
Get a particular section from the manifest |
public Enumeration getSectionNames() {
return CollectionUtils.asEnumeration(sections.keySet().iterator());
}
Get the section names in this manifest. |
public Enumeration getWarnings() {
Vector warnings = new Vector();
Enumeration warnEnum = mainSection.getWarnings();
while (warnEnum.hasMoreElements()) {
warnings.addElement(warnEnum.nextElement());
}
// create a vector and add in the warnings for all the sections
Iterator e = sections.values().iterator();
while (e.hasNext()) {
Section section = (Section) e.next();
Enumeration e2 = section.getWarnings();
while (e2.hasMoreElements()) {
warnings.addElement(e2.nextElement());
}
}
return warnings.elements();
}
Get the warnings for this manifest. |
public int hashCode() {
int hashCode = 0;
if (manifestVersion != null) {
hashCode += manifestVersion.hashCode();
}
hashCode += mainSection.hashCode();
hashCode += sections.hashCode();
return hashCode;
}
|
public void merge(Manifest other) throws ManifestException {
merge(other, false);
}
Merge the contents of the given manifest into this manifest
without merging Class-Path attributes. |
public void merge(Manifest other,
boolean overwriteMain) throws ManifestException {
merge(other, overwriteMain, false);
}
Merge the contents of the given manifest into this manifest
without merging Class-Path attributes. |
public void merge(Manifest other,
boolean overwriteMain,
boolean mergeClassPaths) throws ManifestException {
if (other != null) {
if (overwriteMain) {
mainSection = (Section) other.mainSection.clone();
} else {
mainSection.merge(other.mainSection, mergeClassPaths);
}
if (other.manifestVersion != null) {
manifestVersion = other.manifestVersion;
}
Enumeration e = other.getSectionNames();
while (e.hasMoreElements()) {
String sectionName = (String) e.nextElement();
Section ourSection = (Section) sections.get(sectionName);
Section otherSection
= (Section) other.sections.get(sectionName);
if (ourSection == null) {
if (otherSection != null) {
addConfiguredSection((Section) otherSection.clone());
}
} else {
ourSection.merge(otherSection, mergeClassPaths);
}
}
}
}
Merge the contents of the given manifest into this manifest |
public String toString() {
StringWriter sw = new StringWriter();
try {
write(new PrintWriter(sw));
} catch (IOException e) {
return null;
}
return sw.toString();
}
Convert the manifest to its string representation |
public void write(PrintWriter writer) throws IOException {
write(writer, false);
}
Write the manifest out to a print writer without flattening
multi-values attributes (i.e. Class-Path). |
public void write(PrintWriter writer,
boolean flatten) throws IOException {
writer.print(ATTRIBUTE_MANIFEST_VERSION + ": " + manifestVersion + EOL);
String signatureVersion
= mainSection.getAttributeValue(ATTRIBUTE_SIGNATURE_VERSION);
if (signatureVersion != null) {
writer.print(ATTRIBUTE_SIGNATURE_VERSION + ": "
+ signatureVersion + EOL);
mainSection.removeAttribute(ATTRIBUTE_SIGNATURE_VERSION);
}
mainSection.write(writer, flatten);
// add it back
if (signatureVersion != null) {
try {
Attribute svAttr = new Attribute(ATTRIBUTE_SIGNATURE_VERSION,
signatureVersion);
mainSection.addConfiguredAttribute(svAttr);
} catch (ManifestException e) {
// shouldn't happen - ignore
}
}
Iterator e = sections.keySet().iterator();
while (e.hasNext()) {
String sectionName = (String) e.next();
Section section = getSection(sectionName);
section.write(writer, flatten);
}
}
Write the manifest out to a print writer. |