org.codehaus.plexus.archiver.jar

Class JarArchiver

public class JarArchiver extends ZipArchiver

Base class for tasks that build archives in JAR file format.

Version: $Revision: 3560 $ $Date: 2006-07-25 01:14:00 -0400 (Tue, 25 Jul 2006) $

Nested Class Summary
static classJarArchiver.FilesetManifestConfig
Field Summary
ManifestconfiguredManifest
merged manifests added through addConfiguredManifest
booleancreateEmpty
whether to really create the archive in createEmptyZip, will get set in getResourcesToAdd.
ManifestfilesetManifest
merged manifests added through filesets
JarArchiver.FilesetManifestConfigfilesetManifestConfig
whether to merge fileset manifests; value is true if filesetmanifest is 'merge' or 'mergewithoutmain'
booleanindex
jar index is JDK 1.3+ only
ArrayListindexJars
Path containing jars that shall be indexed in addition to this archive.
static StringINDEX_NAME
The index file name.
Manifestmanifest
the manifest specified by the 'manifest' attribute *
StringmanifestEncoding
The encoding to use when reading in a manifest file
FilemanifestFile
The file found from the 'manifest' attribute.
booleanmergeManifestsMain
whether to merge the main section of fileset manifests; value is true if filesetmanifest is 'merge'
static StringMANIFEST_NAME
The manifest file name.
ManifestoriginalManifest
Manifest of original archive, will be set to null if not in update mode.
VectorrootEntries
Stores all files that are in the root of the archive (i.e. that have a name that doesn't contain a slash) so they can get listed in the index.
ManifestsavedConfiguredManifest
shadow of the above if upToDate check alters the value
Constructor Summary
JarArchiver()
constructor
Method Summary
voidaddConfiguredIndexJars(File indexJar)
voidaddConfiguredManifest(Manifest newManifest)
Allows the manifest for the archive file to be provided inline in the build file rather than in an external file.
protected voidcleanUp()
Make sure we don't think we already have a MANIFEST next time this task gets executed.
protected booleancreateEmptyZip(File zipFile)
voidcreateIndexList(ZipOutputStream zOut)
Create the index list to speed up classloading.
ManifestcreateManifest()
voidfilesetManifest(File file, InputStream is)
protected voidfinalizeZipOutputStream(ZipOutputStream zOut)
protected static StringfindJarName(String fileName, String[] classpath)
try to guess the name of the given file.
ManifestgetManifest(File manifestFile)
ManifestgetManifest(Reader r)
protected static voidgrabFilesAndDirs(String file, List dirs, List files)
Grab lists of all root-level files and all directories contained in the given archive.
protected voidinitZipOutputStream(ZipOutputStream zOut)
voidreset()
reset to default values.
voidsetFilesetmanifest(JarArchiver.FilesetManifestConfig config)
Behavior when a Manifest is found in a zipfileset or zipgroupfileset file.
voidsetIndex(boolean flag)
Set whether or not to create an index list for classes.
voidsetManifest(File manifestFile)
The manifest file to use.
voidsetManifestEncoding(String manifestEncoding)
Set whether or not to create an index list for classes.
protected voidwriteIndexLikeList(List dirs, List files, PrintWriter writer)
Writes the directory entries from the first and the filenames from the second list to the given writer, one entry per line.
voidwriteManifest(ZipOutputStream zOut, Manifest manifest)
protected voidzipFile(InputStream is, ZipOutputStream zOut, String vPath, long lastModified, File fromArchive, int mode)
Overridden from Zip class to deal with manifests and index lists.

Field Detail

configuredManifest

private Manifest configuredManifest
merged manifests added through addConfiguredManifest

createEmpty

private boolean createEmpty
whether to really create the archive in createEmptyZip, will get set in getResourcesToAdd.

filesetManifest

private Manifest filesetManifest
merged manifests added through filesets

filesetManifestConfig

private JarArchiver.FilesetManifestConfig filesetManifestConfig
whether to merge fileset manifests; value is true if filesetmanifest is 'merge' or 'mergewithoutmain'

index

private boolean index
jar index is JDK 1.3+ only

indexJars

private ArrayList indexJars
Path containing jars that shall be indexed in addition to this archive.

INDEX_NAME

private static final String INDEX_NAME
The index file name.

manifest

private Manifest manifest
the manifest specified by the 'manifest' attribute *

manifestEncoding

private String manifestEncoding
The encoding to use when reading in a manifest file

manifestFile

private File manifestFile
The file found from the 'manifest' attribute. This can be either the location of a manifest, or the name of a jar added through a fileset. If its the name of an added jar, the manifest is looked for in META-INF/MANIFEST.MF

mergeManifestsMain

private boolean mergeManifestsMain
whether to merge the main section of fileset manifests; value is true if filesetmanifest is 'merge'

MANIFEST_NAME

private static final String MANIFEST_NAME
The manifest file name.

originalManifest

private Manifest originalManifest
Manifest of original archive, will be set to null if not in update mode.

rootEntries

private Vector rootEntries
Stores all files that are in the root of the archive (i.e. that have a name that doesn't contain a slash) so they can get listed in the index.

Will not be filled unless the user has asked for an index.

savedConfiguredManifest

private Manifest savedConfiguredManifest
shadow of the above if upToDate check alters the value

Constructor Detail

JarArchiver

public JarArchiver()
constructor

Method Detail

addConfiguredIndexJars

public void addConfiguredIndexJars(File indexJar)

addConfiguredManifest

public void addConfiguredManifest(Manifest newManifest)
Allows the manifest for the archive file to be provided inline in the build file rather than in an external file.

Parameters: newManifest

Throws: ManifestException

cleanUp

protected void cleanUp()
Make sure we don't think we already have a MANIFEST next time this task gets executed.

See Also: ZipArchiver

createEmptyZip

protected boolean createEmptyZip(File zipFile)

createIndexList

private void createIndexList(ZipOutputStream zOut)
Create the index list to speed up classloading. This is a JDK 1.3+ specific feature and is enabled by default. See the JAR index specification for more details.

Parameters: zOut the zip stream representing the jar being built.

Throws: IOException thrown if there is an error while creating the index and adding it to the zip stream.

createManifest

private Manifest createManifest()

filesetManifest

private void filesetManifest(File file, InputStream is)

finalizeZipOutputStream

protected void finalizeZipOutputStream(ZipOutputStream zOut)

findJarName

protected static final String findJarName(String fileName, String[] classpath)
try to guess the name of the given file.

If this jar has a classpath attribute in its manifest, we can assume that it will only require an index of jars listed there. try to find which classpath entry is most likely the one the given file name points to.

In the absence of a classpath attribute, assume the other files will be placed inside the same directory as this jar and use their basename.

if there is a classpath and the given file doesn't match any of its entries, return null.

getManifest

private Manifest getManifest(File manifestFile)

getManifest

private Manifest getManifest(Reader r)

grabFilesAndDirs

protected static final void grabFilesAndDirs(String file, List dirs, List files)
Grab lists of all root-level files and all directories contained in the given archive.

initZipOutputStream

protected void initZipOutputStream(ZipOutputStream zOut)

reset

public void reset()
reset to default values.

See Also: ZipArchiver

setFilesetmanifest

public void setFilesetmanifest(JarArchiver.FilesetManifestConfig config)
Behavior when a Manifest is found in a zipfileset or zipgroupfileset file. Valid values are "skip", "merge", and "mergewithoutmain". "merge" will merge all of manifests together, and merge this into any other specified manifests. "mergewithoutmain" merges everything but the Main section of the manifests. Default value is "skip".

Note: if this attribute's value is not "skip", the created jar will not be readable by using java.util.jar.JarInputStream

Parameters: config setting for found manifest behavior.

setIndex

public void setIndex(boolean flag)
Set whether or not to create an index list for classes. This may speed up classloading in some cases.

setManifest

public void setManifest(File manifestFile)
The manifest file to use. This can be either the location of a manifest, or the name of a jar added through a fileset. If its the name of an added jar, the task expects the manifest to be in the jar at META-INF/MANIFEST.MF.

Parameters: manifestFile the manifest file to use.

setManifestEncoding

public void setManifestEncoding(String manifestEncoding)
Set whether or not to create an index list for classes. This may speed up classloading in some cases.

writeIndexLikeList

protected final void writeIndexLikeList(List dirs, List files, PrintWriter writer)
Writes the directory entries from the first and the filenames from the second list to the given writer, one entry per line.

writeManifest

private void writeManifest(ZipOutputStream zOut, Manifest manifest)

zipFile

protected void zipFile(InputStream is, ZipOutputStream zOut, String vPath, long lastModified, File fromArchive, int mode)
Overridden from Zip class to deal with manifests and index lists.