public class Jar extends Zip
Modifier and Type | Class and Description |
---|---|
static class |
Jar.FilesetManifestConfig
The manifest config enumerated type.
|
static class |
Jar.StrictMode
The strict enumerated type.
|
Zip.ArchiveState, Zip.Duplicate, Zip.UnicodeExtraField, Zip.WhenEmpty, Zip.Zip64ModeAttribute
addedDirs, archiveType, doubleFilePass, duplicate, emptyBehavior, entries, skipWriting, zipFile
fileset
Constructor and Description |
---|
Jar()
constructor
|
Modifier and Type | Method and Description |
---|---|
void |
addConfiguredIndexJars(Path p)
Add a path to index jars.
|
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 |
addConfiguredService(Service service)
A nested SPI service element.
|
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 jar file.
|
protected void |
finalizeZipOutputStream(ZipOutputStream zOut)
Finalize the zip output stream.
|
protected static String |
findJarName(String fileName,
String[] classpath)
try to guess the name of the given file.
|
protected Zip.ArchiveState |
getResourcesToAdd(ResourceCollection[] rcs,
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<String> dirs,
List<String> files)
Grab lists of all root-level files and all directories
contained in the given archive.
|
protected void |
initZipOutputStream(ZipOutputStream zOut)
Initialize the zip output stream.
|
void |
reset()
reset to default values.
|
void |
setFilesetmanifest(Jar.FilesetManifestConfig config)
Behavior when a Manifest is found in a zipfileset or zipgroupfileset file.
|
void |
setFlattenAttributes(boolean b)
Whether to flatten multi-valued attributes (i.e.
|
void |
setIndex(boolean flag)
Set whether or not to create an index list for classes.
|
void |
setIndexMetaInf(boolean flag)
Set whether or not to add META-INF and its children to the index.
|
void |
setManifest(File manifestFile)
The manifest file to use.
|
void |
setManifestEncoding(String manifestEncoding)
The character encoding to use in the manifest file.
|
void |
setMergeClassPathAttributes(boolean b)
Whether to merge Class-Path attributes.
|
void |
setStrict(Jar.StrictMode strict)
Activate the strict mode.
|
void |
setWhenempty(Zip.WhenEmpty we)
Not used for jar files.
|
void |
setWhenmanifestonly(Zip.WhenEmpty we)
Indicates if a jar file should be created when it would only contain a
manifest file.
|
protected void |
writeIndexLikeList(List<String> dirs,
List<String> 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.
|
add, addFileset, addParentDirs, addResources, addResources, addZipfileset, addZipGroupFileset, execute, executeMain, getComment, getCreateUnicodeExtraFields, getCurrentExtraFields, getDestFile, getEncoding, getFallBackToUTF8, getLevel, getNonFileSetResourcesToAdd, getPreserve0Permissions, getResourcesToAdd, getUseLanguageEnodingFlag, getZip64Mode, grabNonFileSetResources, grabResources, hasUpdatedFile, isAddingNewFiles, isCompress, isEmpty, isFirstPass, isInUpdateMode, logWhenWriting, selectDirectoryResources, selectFileResources, selectResources, setBasedir, setComment, setCompress, setCreateUnicodeExtraFields, setCurrentExtraFields, setDestFile, setDuplicate, setEncoding, setFallBackToUTF8, setFilesonly, setKeepCompression, setLevel, setPreserve0Permissions, setRoundUp, setUpdate, setUseLanguageEncodingFlag, setZip64Mode, zipDir, zipDir, zipDir, zipFile, zipFile
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, XsetIgnore, XsetItems
bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType
clone, getDescription, getLocation, getProject, setDescription, setLocation
public void addConfiguredIndexJars(Path p)
p
- a pathpublic void addConfiguredManifest(Manifest newManifest) throws ManifestException
newManifest
- an embedded manifest elementManifestException
- on errorpublic void addConfiguredService(Service service)
service
- the nested element.public void addMetainf(ZipFileSet fs)
fs
- zipfileset to addprotected void cleanUp()
cleanUp
in class Zip
Zip.cleanUp()
protected boolean createEmptyZip(File zipFile) throws BuildException
createEmptyZip
in class Zip
zipFile
- the file to createBuildException
- on errorprotected void finalizeZipOutputStream(ZipOutputStream zOut) throws IOException, BuildException
finalizeZipOutputStream
in class Zip
zOut
- the zip output streamIOException
- on I/O errorsBuildException
- on other errorsprotected static String findJarName(String fileName, String[] classpath)
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.
fileName
- the name to look forclasspath
- the classpath to look in (may be null)protected Zip.ArchiveState getResourcesToAdd(ResourceCollection[] rcs, File zipFile, boolean needsUpdate) throws BuildException
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.
getResourcesToAdd
in class Zip
rcs
- The resource collections to grab resources fromzipFile
- 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.BuildException
- if it likesprotected static void grabFilesAndDirs(String file, List<String> dirs, List<String> files) throws IOException
file
- the zip file to examinedirs
- where to place the directories foundfiles
- where to place the files foundIOException
- on errorprotected void initZipOutputStream(ZipOutputStream zOut) throws IOException, BuildException
initZipOutputStream
in class Zip
zOut
- the zip output streamIOException
- on I/O errorsBuildException
- on other errorspublic void reset()
reset
in class Zip
Zip.reset()
public void setFilesetmanifest(Jar.FilesetManifestConfig config)
config
- setting for found manifest behavior.public void setFlattenAttributes(boolean b)
public void setIndex(boolean flag)
flag
- a boolean
valuepublic void setIndexMetaInf(boolean flag)
Doesn't have any effect if index is false.
Sun's jar implementation used to skip the META-INF directory and Ant followed that example. The behavior has been changed with Java 5. In order to avoid problems with Ant generated jars on Java 1.4 or earlier Ant will not include META-INF unless explicitly asked to.
flag
- a boolean
value, defaults to falsepublic void setManifest(File manifestFile)
manifestFile
- the manifest file to use.public void setManifestEncoding(String manifestEncoding)
manifestEncoding
- the character encodingpublic void setMergeClassPathAttributes(boolean b)
public void setStrict(Jar.StrictMode strict)
strict
- New value of the strict mode.public void setWhenempty(Zip.WhenEmpty we)
setWhenempty
in class Zip
we
- not usedpublic void setWhenmanifestonly(Zip.WhenEmpty we)
fail
(throw an exception
and halt the build); skip
(do not create
any archive, but issue a warning); create
(make an archive with only a manifest file).
Default is create
;we
- a WhenEmpty
enumerated valueprotected final void writeIndexLikeList(List<String> dirs, List<String> files, PrintWriter writer)
dirs
- a list of directoriesfiles
- a list of fileswriter
- the writer to write toIOException
- on errorprotected void zipFile(InputStream is, ZipOutputStream zOut, String vPath, long lastModified, File fromArchive, int mode) throws IOException
zipFile
in class Zip
is
- the stream to read data for the entry from. The
caller of the method is responsible for closing the stream.zOut
- the zip output streamvPath
- the name this entry shall have in the archivelastModified
- last modification time for the entry.fromArchive
- the original archive we are copying this
entry from, will be null if we are not copying from an archive.mode
- the Unix permissions to set.IOException
- on error