Create a Zip file.
add
public void add(ResourceCollection a)
Add a collection of resources to be archived.
a
- the resources to archive
addFileset
public void addFileset(FileSet set)
Adds a set of files.
addParentDirs
protected final void addParentDirs(File baseDir,
String entry,
ZipOutputStream zOut,
String prefix,
int dirMode)
throws IOException
Ensure all parent dirs of a given entry have been added.
baseDir
- the base directory to use (may be null)entry
- the entry name to create directories fromzOut
- the stream to write toprefix
- a prefix to place on the created entriesdirMode
- the directory mode
addResources
protected final void addResources(FileSet fileset,
Resource[] resources,
ZipOutputStream zOut)
throws IOException
Add the given resources.
fileset
- may give additional information like fullpath or
permissions.resources
- the resources to addzOut
- the stream to write to
addResources
protected final void addResources(ResourceCollection rc,
Resource[] resources,
ZipOutputStream zOut)
throws IOException
Add the given resources.
rc
- may give additional information like fullpath or
permissions.resources
- the resources to addzOut
- the stream to write to
addZipGroupFileset
public void addZipGroupFileset(FileSet set)
Adds a group of zip files.
set
- the group (a fileset) to add
addZipfileset
public void addZipfileset(ZipFileSet set)
Adds a set of files that can be
read from an archive and be given a prefix/fullpath.
set
- the zipfileset to add
cleanUp
protected void cleanUp()
Do any clean up necessary to allow this instance to be used again.
When we get here, the Zip file has been closed and all we
need to do is to reset some globals.
This method will only reset globals that have been changed
during execute(), it will not alter the attributes or nested
child elements. If you want to reset the instance so that you
can later zip a completely different set of files, you must use
the reset method.
createEmptyZip
protected boolean createEmptyZip(File zipFile)
throws BuildException
Create an empty zip file
- true for historic reasons
executeMain
public void executeMain()
throws BuildException
Build the zip file.
This is called twice if doubleFilePass is true.
finalizeZipOutputStream
protected void finalizeZipOutputStream(ZipOutputStream zOut)
throws IOException,
BuildException
method for subclasses to override
zOut
- the zip output stream
getComment
public String getComment()
Comment of the archive
getDestFile
public File getDestFile()
The file to create.
getEncoding
public String getEncoding()
Encoding to use for filenames.
- the name of the encoding to use
getLevel
public int getLevel()
Get the compression level.
getNonFileSetResourcesToAdd
protected Zip.ArchiveState getNonFileSetResourcesToAdd(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.
rcs
- The filesets 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.
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.
filesets
- The filesets 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.
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.
This method first delegates to getNonFileSetResourceToAdd
and then invokes the FileSet-arg version. All this to keep
backwards compatibility for subclasses that don't know how to
deal with non-FileSet ResourceCollections.
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.
grabNonFileSetResources
protected Resource[][] grabNonFileSetResources(ResourceCollection[] rcs)
Fetch all included and not excluded resources from the collections.
Included directories will precede included files.
rcs
- an array of resource collections
grabResources
protected Resource[][] grabResources(FileSet[] filesets)
Fetch all included and not excluded resources from the sets.
Included directories will precede included files.
filesets
- an array of filesets
initZipOutputStream
protected void initZipOutputStream(ZipOutputStream zOut)
throws IOException,
BuildException
method for subclasses to override
zOut
- the zip output stream
isAddingNewFiles
protected final boolean isAddingNewFiles()
Indicates if the task is adding new files into the archive as opposed to
copying back unchanged files from the backup copy
isCompress
public boolean isCompress()
Whether we want to compress the files or only store them;
- true if the files are to be compressed
isEmpty
protected static final boolean isEmpty(Resource[][] r)
Check is the resource arrays are empty.
- true if all individual arrays are empty
isInUpdateMode
public boolean isInUpdateMode()
Are we updating an existing archive?
- true if updating an existing archive
reset
public void reset()
Makes this instance reset all attributes to their default
values and forget all children.
selectFileResources
protected Resource[] selectFileResources(Resource[] orig)
Drops all non-file resources from the given array.
orig
- the resources to filter
setBasedir
public void setBasedir(File baseDir)
Directory from which to archive files; optional.
baseDir
- the base directory
setComment
public void setComment(String comment)
Comment to use for archive.
comment
- The content of the comment.
setCompress
public void setCompress(boolean c)
Whether we want to compress the files or only store them;
optional, default=true;
c
- if true, compress the files
setDestFile
public void setDestFile(File destFile)
The file to create; required.
destFile
- The new destination File
setDuplicate
public void setDuplicate(Zip.Duplicate df)
Sets behavior for when a duplicate file is about to be added -
one of add
, preserve
or fail
.
Possible values are: add
(keep both
of the files); preserve
(keep the first version
of the file found); fail
halt a problem
Default for zip tasks is add
df
- a Duplicate
enumerated value
setEncoding
public void setEncoding(String encoding)
encoding
- the encoding name
setFile
public void setFile(File file)
since 1.5.x.
Use setDestFile(File) instead.
This is the name/location of where to
create the file.
file
- the path of the zipFile
setFilesonly
public void setFilesonly(boolean f)
If true, emulate Sun's jar utility by not adding parent directories;
optional, defaults to false.
f
- if true, emulate sun's jar by not adding parent directories
setKeepCompression
public void setKeepCompression(boolean keep)
Whether the original compression of entries coming from a ZIP
archive should be kept (for example when updating an archive).
Default is false.
keep
- if true, keep the original compression
setLevel
public void setLevel(int level)
Set the compression level to use. Default is
ZipOutputStream.DEFAULT_COMPRESSION.
level
- compression level.
setRoundUp
public void setRoundUp(boolean r)
Whether the file modification times will be rounded up to the
next even number of seconds.
Zip archives store file modification times with a
granularity of two seconds, so the times will either be rounded
up or down. If you round down, the archive will always seem
out-of-date when you rerun the task, so the default is to round
up. Rounding up may lead to a different type of problems like
JSPs inside a web archive that seem to be slightly more recent
than precompiled pages, rendering precompilation useless.
setUpdate
public void setUpdate(boolean c)
If true, updates an existing file, otherwise overwrite
any existing one; optional defaults to false.
c
- if true, updates an existing zip file
setWhenempty
public void setWhenempty(Zip.WhenEmpty we)
Sets behavior of the task when no files match.
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 no entries).
Default for zip tasks is skip
;
for jar tasks, create
.
we
- a WhenEmpty
enumerated value
setZipfile
public void setZipfile(File zipFile)
since 1.5.x.
Use setDestFile(File) instead.
This is the name/location of where to
create the .zip file.
zipFile
- the path of the zipFile
zipDir
protected void zipDir(File dir,
ZipOutputStream zOut,
String vPath,
int mode)
throws IOException
Add a directory to the zip stream.
dir
- the directort to add to the archivezOut
- the stream to write tovPath
- the name this entry shall have in the archivemode
- the Unix permissions to set.
zipDir
protected void zipDir(File dir,
ZipOutputStream zOut,
String vPath,
int mode,
ZipExtraField[] extra)
throws IOException
Add a directory to the zip stream.
dir
- the directort to add to the archivezOut
- the stream to write tovPath
- the name this entry shall have in the archivemode
- the Unix permissions to set.extra
- ZipExtraFields to add
zipFile
protected void zipFile(File file,
ZipOutputStream zOut,
String vPath,
int mode)
throws IOException
Method that gets called when adding from
java.io.File
instances.
This implementation delegates to the six-arg version.
file
- the file to add to the archivezOut
- the stream to write tovPath
- the name this entry shall have in the archivemode
- the Unix permissions to set.
zipFile
protected void zipFile(InputStream in,
ZipOutputStream zOut,
String vPath,
long lastModified,
File fromArchive,
int mode)
throws IOException
Adds a new entry to the archive, takes care of duplicates as well.
in
- the stream to read data for the entry from.zOut
- the stream to write to.vPath
- the name this entry shall have in the archive.lastModified
- 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.