org.codehaus.plexus.archiver.jar

Class JarArchiver

Implemented Interfaces:
Archiver
Known Direct Subclasses:
EarArchiver, WarArchiver

public class JarArchiver
extends ZipArchiver

Base class for tasks that build archives in JAR file format.
Version:
$Revision: 3290 $ $Date: 2006-05-08 14:26:26 -0400 (Mon, 08 May 2006) $

Nested Class Summary

static class
JarArchiver.FilesetManifestConfig

Field Summary

private static String
INDEX_NAME
The index file name.
private static String
MANIFEST_NAME
The manifest file name.
private Manifest
configuredManifest
merged manifests added through addConfiguredManifest
private boolean
createEmpty
whether to really create the archive in createEmptyZip, will get set in getResourcesToAdd.
private Manifest
filesetManifest
merged manifests added through filesets
private JarArchiver.FilesetManifestConfig
filesetManifestConfig
whether to merge fileset manifests; value is true if filesetmanifest is 'merge' or 'mergewithoutmain'
private boolean
index
jar index is JDK 1.3+ only
private ArrayList
indexJars
Path containing jars that shall be indexed in addition to this archive.
private Manifest
manifest
the manifest specified by the 'manifest' attribute *
private String
manifestEncoding
The encoding to use when reading in a manifest file
private File
manifestFile
The file found from the 'manifest' attribute.
private boolean
mergeManifestsMain
whether to merge the main section of fileset manifests; value is true if filesetmanifest is 'merge'
private Manifest
originalManifest
Manifest of original archive, will be set to null if not in update mode.
private Vector
rootEntries
Stores all files that are in the root of the archive (i.e.
private Manifest
savedConfiguredManifest
shadow of the above if upToDate check alters the value

Fields inherited from class org.codehaus.plexus.archiver.zip.AbstractZipArchiver

EMPTY_CRC, addedDirs, addedFiles, addingNewFiles, archiveType, comment, doCompress, doFilesonly, doUpdate, doubleFilePass, duplicate, encoding, entries, roundUp, savedDoUpdate, skipWriting

Fields inherited from class org.codehaus.plexus.archiver.AbstractArchiver

DEFAULT_DIR_MODE, DEFAULT_FILE_MODE, defaultDirectoryMode, defaultFileMode, destFile, dirsMap, filesMap, includeEmptyDirs, logger

Fields inherited from interface org.codehaus.plexus.archiver.Archiver

ROLE

Constructor Summary

JarArchiver()
constructor

Method Summary

void
addConfiguredIndexJars(File indexJar)
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.
protected void
cleanUp()
Make sure we don't think we already have a MANIFEST next time this task gets executed.
protected boolean
createEmptyZip(File zipFile)
private void
createIndexList(ZipOutputStream zOut)
Create the index list to speed up classloading.
private Manifest
createManifest()
private void
filesetManifest(File file, InputStream is)
protected void
finalizeZipOutputStream(ZipOutputStream zOut)
method for subclasses to override
protected static String
findJarName(String fileName, String[] classpath)
try to guess the name of the given file.
private Manifest
getManifest(File manifestFile)
private Manifest
getManifest(Reader r)
protected static void
grabFilesAndDirs(String file, List dirs, List files)
Grab lists of all root-level files and all directories contained in the given archive.
protected void
initZipOutputStream(ZipOutputStream zOut)
method for subclasses to override
void
reset()
reset to default values.
void
setFilesetmanifest(JarArchiver.FilesetManifestConfig config)
Behavior when a Manifest is found in a zipfileset or zipgroupfileset file.
void
setIndex(boolean flag)
Set whether or not to create an index list for classes.
void
setManifest(File manifestFile)
The manifest file to use.
void
setManifestEncoding(String manifestEncoding)
Set whether or not to create an index list for classes.
protected 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.
private void
writeManifest(ZipOutputStream zOut, Manifest manifest)
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.

Methods inherited from class org.codehaus.plexus.archiver.zip.AbstractZipArchiver

addParentDirs, addResources, cleanUp, createArchive, createArchiveMain, createEmptyZip, finalizeZipOutputStream, getComment, getDirMode, getEncoding, getFileMode, getResourcesToAdd, getResourcesToUpdate, initZipOutputStream, isCompress, isFilesonly, isInUpdateMode, isRoundUp, reset, setComment, setCompress, setDirMode, setEncoding, setFileMode, setFilesonly, setRoundUp, setUpdateMode, zipDir, zipFile, zipFile

Methods inherited from class org.codehaus.plexus.archiver.AbstractArchiver

addDirectory, addDirectory, addDirectory, addDirectory, addFile, addFile, getDefaultDirectoryMode, getDefaultFileMode, getDestFile, getDirs, getFiles, getIncludeEmptyDirs, getLogger, setDefaultDirectoryMode, setDefaultFileMode, setDestFile, setIncludeEmptyDirs

Field Details

INDEX_NAME

private static final String INDEX_NAME
The index file name.

MANIFEST_NAME

private static final String MANIFEST_NAME
The manifest file name.

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.

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'

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 Details

JarArchiver

public JarArchiver()
constructor

Method Details

addConfiguredIndexJars

public void addConfiguredIndexJars(File indexJar)

addConfiguredManifest

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

cleanUp

protected void cleanUp()
Make sure we don't think we already have a MANIFEST next time this task gets executed.
Overrides:
cleanUp in interface AbstractZipArchiver
See Also:
ZipArchiver

createEmptyZip

protected boolean createEmptyZip(File zipFile)
            throws ArchiverException
Overrides:
createEmptyZip in interface AbstractZipArchiver

createIndexList

private void createIndexList(ZipOutputStream zOut)
            throws IOException,
                   ArchiverException
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.

createManifest

private Manifest createManifest()
            throws ArchiverException

filesetManifest

private void filesetManifest(File file,
                             InputStream is)
            throws ArchiverException

finalizeZipOutputStream

protected void finalizeZipOutputStream(ZipOutputStream zOut)
            throws IOException,
                   ArchiverException
method for subclasses to override
Overrides:
finalizeZipOutputStream in interface AbstractZipArchiver

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)
            throws ArchiverException

getManifest

private Manifest getManifest(Reader r)
            throws ArchiverException

grabFilesAndDirs

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

initZipOutputStream

protected void initZipOutputStream(ZipOutputStream zOut)
            throws IOException,
                   ArchiverException
method for subclasses to override
Overrides:
initZipOutputStream in interface AbstractZipArchiver

reset

public void reset()
reset to default values.
Overrides:
reset in interface AbstractZipArchiver
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)
            throws ArchiverException
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)
            throws IOException,
                   ArchiverException

zipFile

protected void zipFile(InputStream is,
                       ZipOutputStream zOut,
                       String vPath,
                       long lastModified,
                       File fromArchive,
                       int mode)
            throws IOException,
                   ArchiverException
Overridden from Zip class to deal with manifests and index lists.
Overrides:
zipFile in interface AbstractZipArchiver