org.apache.tools.ant.taskdefs

Class Jar

Implemented Interfaces:
SelectorContainer
Known Direct Subclasses:
Ear, War

public class Jar
extends Zip

Creates a JAR archive.
Since:
Ant 1.1

Nested Class Summary

static class
Jar.FilesetManifestConfig

Nested classes/interfaces inherited from class org.apache.tools.ant.taskdefs.Zip

Zip.ArchiveState, Zip.Duplicate, Zip.WhenEmpty

Field Summary

Fields inherited from class org.apache.tools.ant.taskdefs.Zip

addedDirs, archiveType, doubleFilePass, duplicate, emptyBehavior, entries, skipWriting, zipFile

Fields inherited from class org.apache.tools.ant.taskdefs.MatchingTask

fileset

Fields inherited from class org.apache.tools.ant.Task

description, location, target, taskName, taskType, wrapper

Fields inherited from class org.apache.tools.ant.ProjectComponent

project

Constructor Summary

Jar()
constructor

Method Summary

void
addConfiguredIndexJars(Path p)
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.
void
addMetainf(ZipFileSet fs)
Adds a zipfileset to include in the META-INF directory.
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)
Create an empty zip file
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.
protected Zip.ArchiveState
getResourcesToAdd(FileSet[] filesets, File zipFile, boolean needsUpdate)
Collect the resources that are newer than the corresponding entries (or missing) in the original archive.
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(Jar.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
setJarfile(File jarFile)
Deprecated. Use setDestFile(File) instead
void
setManifest(File manifestFile)
The manifest file to use.
void
setManifestEncoding(String manifestEncoding)
Set whether or not to create an index list for classes.
void
setWhenempty(Zip.WhenEmpty we)
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.
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.apache.tools.ant.taskdefs.Zip

addFileset, addParentDirs, addResources, addZipGroupFileset, addZipfileset, cleanUp, createEmptyZip, execute, executeMain, finalizeZipOutputStream, getComment, getDestFile, getEncoding, getResourcesToAdd, grabResources, initZipOutputStream, isAddingNewFiles, isCompress, isEmpty, isInUpdateMode, reset, selectFileResources, setBasedir, setComment, setCompress, setDestFile, setDuplicate, setEncoding, setFile, setFilesonly, setKeepCompression, setRoundUp, setUpdate, setWhenempty, setZipfile, zipDir, zipDir, zipFile, zipFile

Methods inherited from class org.apache.tools.ant.taskdefs.MatchingTask

XsetIgnore, XsetItems, add, addAnd, addContains, addContainsRegexp, addCustom, addDate, addDepend, addDepth, addDifferent, addFilename, addMajority, addModified, addNone, addNot, addOr, addPresent, addSelector, addSize, addType, appendSelector, createExclude, createExcludesFile, createInclude, createIncludesFile, createPatternSet, getDirectoryScanner, getImplicitFileSet, getSelectors, hasSelectors, selectorCount, selectorElements, setCaseSensitive, setDefaultexcludes, setExcludes, setExcludesfile, setFollowSymlinks, setIncludes, setIncludesfile, setProject

Methods inherited from class org.apache.tools.ant.Task

execute, getDescription, getLocation, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, maybeConfigure, perform, reconfigure, setDescription, setLocation, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType

Methods inherited from class org.apache.tools.ant.ProjectComponent

getProject, log, log, setProject

Constructor Details

Jar

public Jar()
constructor

Method Details

addConfiguredIndexJars

public void addConfiguredIndexJars(Path p)
Since:
Ant 1.6.2

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 -

addMetainf

public void addMetainf(ZipFileSet fs)
Adds a zipfileset to include in the META-INF directory.
Parameters:
fs - zipfileset to add

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 Zip
See Also:
Zip.cleanUp()

createEmptyZip

protected boolean createEmptyZip(File zipFile)
            throws BuildException
Create an empty zip file
Overrides:
createEmptyZip in interface Zip
Returns:
true for historic reasons

finalizeZipOutputStream

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

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.

Since:
Ant 1.7

getResourcesToAdd

protected Zip.ArchiveState getResourcesToAdd(FileSet[] filesets,
                                             File zipFile,
                                             boolean needsUpdate)
            throws BuildException
Collect the resources that are newer than the corresponding entries (or missing) in the original archive.

If we are going to recreate the archive instead of updating it, all resources should be considered as new, if a single one is. Because of this, subclasses overriding this method must call super.getResourcesToAdd and indicate with the third arg if they already know that the archive is out-of-date.

Overrides:
getResourcesToAdd in interface Zip
Parameters:
filesets - The filesets to grab resources from
zipFile - intended archive file (may or may not exist)
needsUpdate - whether we already know that the archive is out-of-date. Subclasses overriding this method are supposed to set this value correctly in their call to super.getResourcesToAdd.
Returns:
an array of resources to add for each fileset passed in as well as a flag that indicates whether the archive is uptodate.
Throws:
BuildException - if it likes

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.
Since:
Ant 1.7

initZipOutputStream

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

reset

public void reset()
reset to default values.
Overrides:
reset in interface Zip
Since:
1.44, Ant 1.5
See Also:
Zip.reset()

setFilesetmanifest

public void setFilesetmanifest(Jar.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.

setJarfile

public void setJarfile(File jarFile)

Deprecated. Use setDestFile(File) instead


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.

setWhenempty

public void setWhenempty(Zip.WhenEmpty we)
Overrides:
setWhenempty in interface Zip

writeIndexLikeList

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

zipFile

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

Copyright B) 2000-2008 Apache Software Foundation. All Rights Reserved.