Creates a JAR archive.
addConfiguredIndexJars
public void addConfiguredIndexJars(Path p)
Add a path to index jars.
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.
newManifest
- an embedded manifest element
addConfiguredService
public void addConfiguredService(Service service)
A nested SPI service element.
service
- the nested element.
addMetainf
public void addMetainf(ZipFileSet fs)
Adds a zipfileset to include in the META-INF directory.
cleanUp
protected void cleanUp()
Make sure we don't think we already have a MANIFEST next time this task
gets executed.
- cleanUp in interface Zip
createEmptyZip
protected boolean createEmptyZip(File zipFile)
throws BuildException
Create an empty jar file.
- createEmptyZip in interface Zip
zipFile
- the file to create
- true for historic reasons
finalizeZipOutputStream
protected void finalizeZipOutputStream(ZipOutputStream zOut)
throws IOException,
BuildException
Finalize the zip output stream.
This creates an index list if the index attribute is true.
- finalizeZipOutputStream in interface Zip
zOut
- the zip output stream
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.
fileName
- the name to look forclasspath
- the classpath to look in (may be null)
- the matching entry, or null if the file is not found
getResourcesToAdd
protected Zip.ArchiveState getResourcesToAdd(ResourceCollection[] rcs,
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.
- getResourcesToAdd in interface 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.
- an array of resources to add for each fileset passed in as well
as a flag that indicates whether the archive is uptodate.
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.
file
- the zip file to examinedirs
- where to place the directories foundfiles
- where to place the files found
reset
public void reset()
reset to default values.
- reset in interface Zip
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
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)
since 1.5.x.
Use setDestFile(File) instead.
Set the destination file.
jarFile
- the destination file
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.
manifestFile
- the manifest file to use.
setManifestEncoding
public void setManifestEncoding(String manifestEncoding)
The character encoding to use in the manifest file.
manifestEncoding
- the character encoding
setWhenmanifestonly
public void setWhenmanifestonly(Zip.WhenEmpty we)
Indicates if a jar file should be created when it would only contain a
manifest file.
Possible values are: 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 value
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.
dirs
- a list of directoriesfiles
- a list of fileswriter
- the writer to write to
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.
- zipFile in interface Zip
is
- the input streamzOut
- 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.