Fields Summary |
---|
private static final String | MANIFEST_VERSIONVersion of manifest spec that task generates. |
private static final String | CREATED_BY"Created-By" string used when creating manifest. |
private File | destFileThe library to display information about. |
private Extension | extensionThe extension supported by this library (if any). |
private final ArrayList | dependenciesExtensionAdapter objects representing
dependencies required by library. |
private final ArrayList | optionalsExtensionAdapter objects representing optional
dependencies required by library. |
private final ArrayList | extraAttributesExtra attributes the user specifies for main section
in manifest. |
Methods Summary |
---|
public void | addConfiguredAttribute(ExtraAttribute attribute)Adds an attribute that is to be put in main section of manifest.
extraAttributes.add(attribute);
|
public void | addConfiguredDepends(ExtensionSet extensionSet)Adds a set of extensions that this library requires.
dependencies.add(extensionSet);
|
public void | addConfiguredExtension(ExtensionAdapter extensionAdapter)Adds an extension that this library implements.
if (null != extension) {
final String message =
"Can not have multiple extensions defined in one library.";
throw new BuildException(message);
}
extension = extensionAdapter.toExtension();
|
public void | addConfiguredOptions(ExtensionSet extensionSet)Adds a set of extensions that this library optionally requires.
optionals.add(extensionSet);
|
private void | appendExtensionList(java.util.jar.Attributes attributes, java.util.jar.Attributes$Name extensionKey, java.lang.String listPrefix, int size)Append an attribute such as "Extension-List: lib0 lib1 lib2"
using specified prefix and counting up to specified size.
Also use specified extensionKey so that can generate list of
optional dependencies aswell.
final StringBuffer sb = new StringBuffer();
for (int i = 0; i < size; i++) {
sb.append(listPrefix);
sb.append(i);
sb.append(' ");
}
//add in something like
//"Extension-List: javahelp java3d"
attributes.put(extensionKey, sb.toString());
|
private void | appendExtraAttributes(java.util.jar.Attributes attributes)Add any extra attributes to the manifest.
final Iterator iterator = extraAttributes.iterator();
while (iterator.hasNext()) {
final ExtraAttribute attribute =
(ExtraAttribute) iterator.next();
attributes.putValue(attribute.getName(),
attribute.getValue());
}
|
private void | appendLibraryList(java.util.jar.Attributes attributes, java.lang.String listPrefix, java.util.ArrayList extensions)Append specified extensions to specified attributes.
Use the extensionKey to list the extensions, usually "Extension-List:"
for required dependencies and "Optional-Extension-List:" for optional
dependencies. NOTE: "Optional" dependencies are not part of the
specification.
final int size = extensions.size();
for (int i = 0; i < size; i++) {
final Extension ext = (Extension) extensions.get(i);
final String prefix = listPrefix + i + "-";
Extension.addExtension(ext, prefix, attributes);
}
|
public void | execute()Execute the task.
validate();
final Manifest manifest = new Manifest();
final Attributes attributes = manifest.getMainAttributes();
attributes.put(Attributes.Name.MANIFEST_VERSION, MANIFEST_VERSION);
final String createdBy = "Apache Ant " + getProject().getProperty(MagicNames.ANT_VERSION);
attributes.putValue(CREATED_BY, createdBy);
appendExtraAttributes(attributes);
if (null != extension) {
Extension.addExtension(extension, attributes);
}
//Add all the dependency data to manifest for dependencies
final ArrayList depends = toExtensions(dependencies);
appendExtensionList(attributes,
Extension.EXTENSION_LIST,
"lib",
depends.size());
appendLibraryList(attributes, "lib", depends);
//Add all the dependency data to manifest for "optional"
//dependencies
final ArrayList option = toExtensions(optionals);
appendExtensionList(attributes,
Extension.OPTIONAL_EXTENSION_LIST,
"opt",
option.size());
appendLibraryList(attributes, "opt", option);
try {
final String message = "Generating manifest " + destFile.getAbsoluteFile();
log(message, Project.MSG_INFO);
writeManifest(manifest);
} catch (final IOException ioe) {
throw new BuildException(ioe.getMessage(), ioe);
}
|
public void | setDestfile(java.io.File destFile)The location where generated manifest is placed.
this.destFile = destFile;
|
private java.util.ArrayList | toExtensions(java.util.ArrayList extensionSets)Convert a list of ExtensionSet objects to extensions.
final ArrayList results = new ArrayList();
final int size = extensionSets.size();
for (int i = 0; i < size; i++) {
final ExtensionSet set = (ExtensionSet) extensionSets.get(i);
final Extension[] extensions = set.toExtensions(getProject());
for (int j = 0; j < extensions.length; j++) {
results.add(extensions[ j ]);
}
}
return results;
|
private void | validate()Validate the tasks parameters.
if (null == destFile) {
final String message = "Destfile attribute not specified.";
throw new BuildException(message);
}
if (destFile.exists() && !destFile.isFile()) {
final String message = destFile + " is not a file.";
throw new BuildException(message);
}
|
private void | writeManifest(java.util.jar.Manifest manifest)Write out manifest to destfile.
FileOutputStream output = null;
try {
output = new FileOutputStream(destFile);
manifest.write(output);
output.flush();
} finally {
if (null != output) {
try {
output.close();
} catch (IOException e) {
// ignore
}
}
}
|