Google

Zip (Apache Ant API)

org.apache.tools.ant.taskdefs
Class Zip


java.lang.Object

  |

  +--org.apache.tools.ant.ProjectComponent

        |

        +--org.apache.tools.ant.Task

              |

              +--org.apache.tools.ant.taskdefs.MatchingTask

                    |

                    +--org.apache.tools.ant.taskdefs.Zip

All Implemented Interfaces:
SelectorContainer
Direct Known Subclasses:
Jar

public class Zip
extends MatchingTask

Create a Zip file.

Since:
Ant 1.1
Author:
James Davidson duncan@x180.com
, Jon S. Stevens jon@clearink.com , Stefan Bodewig

Nested Class Summary
static class Zip.Duplicate
          Possible behaviors when a duplicate file is added: "add", "preserve" or "fail"
static class Zip.WhenEmpty
          Possible behaviors when there are no matching files for the task: "fail", "skip", or "create".
 
Field Summary
protected  java.util.Hashtable addedDirs
           
protected  java.lang.String archiveType
           
protected  java.lang.String duplicate
           
protected  java.lang.String emptyBehavior
           
protected  java.util.Hashtable entries
           
protected  java.io.File zipFile
           
 
Fields inherited from class org.apache.tools.ant.taskdefs.MatchingTask
fileset, useDefaultExcludes
 
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
Zip()
           
 
Method Summary
protected  void addFiles(FileScanner scanner, ZipOutputStream zOut, java.lang.String prefix, java.lang.String fullpath)
          Add all files of the given FileScanner to the ZipOutputStream prependig the given prefix to each filename.
protected  void addFiles(java.util.Vector filesets, ZipOutputStream zOut)
          Iterate over the given Vector of (zip)filesets and add all files to the ZipOutputStream using the given prefix or fullpath.
 void addFileset(FileSet set)
          Adds a set of files.
protected  void addParentDirs(java.io.File baseDir, java.lang.String entry, ZipOutputStream zOut, java.lang.String prefix)
          Ensure all parent dirs of a given entry have been added.
protected  void addZipEntries(ZipFileSet fs, DirectoryScanner ds, ZipOutputStream zOut, java.lang.String prefix, java.lang.String fullpath)
           
 void addZipfileset(ZipFileSet set)
          Adds a set of files that can be read from an archive and be given a prefix/fullpath.
 void addZipGroupFileset(FileSet set)
          Adds a group of zip files.
protected  void cleanUp()
          Do any clean up necessary to allow this instance to be used again.
protected  boolean createEmptyZip(java.io.File zipFile)
          Create an empty zip file
 void execute()
          validate and build
protected  void finalizeZipOutputStream(ZipOutputStream zOut)
          method for subclasses to override
protected static java.lang.String[][] grabFileNames(FileScanner[] scanners)
           
protected static java.io.File[] grabFiles(FileScanner[] scanners)
           
protected static java.io.File[] grabFiles(FileScanner[] scanners, java.lang.String[][] fileNames)
           
protected  void initZipOutputStream(ZipOutputStream zOut)
          method for subclasses to override
protected  boolean isAddingNewFiles()
          Indicates if the task is adding new files into the archive as opposed to copying back unchanged files from the backup copy
 boolean isInUpdateMode()
          Are we updating an existing archive?
protected  boolean isUpToDate(FileScanner[] scanners, java.io.File zipFile)
          Check whether the archive is up-to-date; and handle behavior for empty archives.
 void reset()
          Makes this instance reset all attributes to their default values and forget all children.
 void setBasedir(java.io.File baseDir)
          Directory from which to archive files; optional.
 void setCompress(boolean c)
          Whether we want to compress the files or only store them; optional, default=true;
 void setDestFile(java.io.File destFile)
          The file to create; required.
 void setDuplicate(Zip.Duplicate df)
          Sets behavior for when a duplicate file is about to be added - one of keep, skip or overwrite.
 void setEncoding(java.lang.String encoding)
          Encoding to use for filenames, defaults to the platform's default encoding.
 void setFile(java.io.File file)
          Deprecated. Use setDestFile(File) instead
 void setFilesonly(boolean f)
          If true, emulate Sun's jar utility by not adding parent directories; optional, defaults to false.
 void setUpdate(boolean c)
          If true, updates an existing file, otherwise overwrite any existing one; optional defaults to false.
 void setWhenempty(Zip.WhenEmpty we)
          Sets behavior of the task when no files match.
 void setZipfile(java.io.File zipFile)
          Deprecated. Use setDestFile(File) instead.
protected  void zipDir(java.io.File dir, ZipOutputStream zOut, java.lang.String vPath)
           
protected  void zipFile(java.io.File file, ZipOutputStream zOut, java.lang.String vPath)
           
protected  void zipFile(java.io.InputStream in, ZipOutputStream zOut, java.lang.String vPath, long lastModified, java.io.File file)
           
 
Methods inherited from class org.apache.tools.ant.taskdefs.MatchingTask
addAnd, addContains, addCustom, addDate, addDepend, addDepth, addFilename, addMajority, addNone, addNot, addOr, addPresent, addSelector, addSize, appendSelector, createExclude, createExcludesFile, createInclude, createIncludesFile, createPatternSet, getDirectoryScanner, getSelectors, hasSelectors, selectorCount, selectorElements, setCaseSensitive, setDefaultexcludes, setExcludes, setExcludesfile, setFollowSymlinks, setIncludes, setIncludesfile, setProject, XsetIgnore, XsetItems
 
Methods inherited from class org.apache.tools.ant.Task
getDescription, getLocation, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, handleErrorOutput, handleOutput, init, isInvalid, log, log, maybeConfigure, perform, setDescription, setLocation, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName
 
Methods inherited from class org.apache.tools.ant.ProjectComponent
getProject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

zipFile


protected java.io.File zipFile

entries


protected java.util.Hashtable entries

duplicate


protected java.lang.String duplicate

archiveType


protected java.lang.String archiveType

emptyBehavior


protected java.lang.String emptyBehavior

addedDirs


protected java.util.Hashtable addedDirs
Constructor Detail

Zip


public Zip()
Method Detail

setZipfile


public void setZipfile(java.io.File zipFile)
Deprecated. Use setDestFile(File) instead.

This is the name/location of where to create the .zip file.


setFile


public void setFile(java.io.File file)
Deprecated. Use setDestFile(File) instead

This is the name/location of where to create the file.

Since:
Ant 1.5

setDestFile


public void setDestFile(java.io.File destFile)
The file to create; required.

Parameters:
destFile - The new destination File
Since:
Ant 1.5

setBasedir


public void setBasedir(java.io.File baseDir)
Directory from which to archive files; optional.


setCompress


public void setCompress(boolean c)
Whether we want to compress the files or only store them; optional, default=true;


setFilesonly


public void setFilesonly(boolean f)
If true, emulate Sun's jar utility by not adding parent directories; optional, defaults to false.


setUpdate


public void setUpdate(boolean c)
If true, updates an existing file, otherwise overwrite any existing one; optional defaults to false.


isInUpdateMode


public boolean isInUpdateMode()
Are we updating an existing archive?


addFileset


public void addFileset(FileSet set)
Adds a set of files.


addZipfileset


public void addZipfileset(ZipFileSet set)
Adds a set of files that can be read from an archive and be given a prefix/fullpath.


addZipGroupFileset


public void addZipGroupFileset(FileSet set)
Adds a group of zip files.


setDuplicate


public void setDuplicate(Zip.Duplicate df)
Sets behavior for when a duplicate file is about to be added - one of keep, skip or overwrite. Possible values are: keep (keep both of the files); skip (keep the first version of the file found); overwrite overwrite the file with the new file Default for zip tasks is keep


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.


setEncoding


public void setEncoding(java.lang.String encoding)
Encoding to use for filenames, defaults to the platform's default encoding.

For a list of possible values see http://java.sun.com/products/jdk/1.2/docs/guide/internat/encoding.doc.html.


execute


public void execute()
             throws BuildException
validate and build

Overrides:
execute in class Task
Throws:
BuildException - if something goes wrong with the build

isAddingNewFiles


protected boolean isAddingNewFiles()
Indicates if the task is adding new files into the archive as opposed to copying back unchanged files from the backup copy


addFiles


protected void addFiles(FileScanner scanner,
                        ZipOutputStream zOut,
                        java.lang.String prefix,
                        java.lang.String fullpath)
                 throws java.io.IOException
Add all files of the given FileScanner to the ZipOutputStream prependig the given prefix to each filename.

Ensure parent directories have been added as well.

java.io.IOException

addZipEntries


protected void addZipEntries(ZipFileSet fs,
                             DirectoryScanner ds,
                             ZipOutputStream zOut,
                             java.lang.String prefix,
                             java.lang.String fullpath)
                      throws java.io.IOException
java.io.IOException

initZipOutputStream


protected void initZipOutputStream(ZipOutputStream zOut)
                            throws java.io.IOException,
                                   BuildException
method for subclasses to override

java.io.IOException
BuildException

finalizeZipOutputStream


protected void finalizeZipOutputStream(ZipOutputStream zOut)
                                throws java.io.IOException,
                                       BuildException
method for subclasses to override

java.io.IOException
BuildException

createEmptyZip


protected boolean createEmptyZip(java.io.File zipFile)
Create an empty zip file

Returns:
true if the file is then considered up to date.

isUpToDate


protected boolean isUpToDate(FileScanner[] scanners,
                             java.io.File zipFile)
                      throws BuildException
Check whether the archive is up-to-date; and handle behavior for empty archives.

Parameters:
scanners - list of prepared scanners containing files to archive
zipFile - intended archive file (may or may not exist)
Returns:
true if nothing need be done (may have done something already); false if archive creation should proceed
Throws:
BuildException - if it likes

grabFiles


protected static java.io.File[] grabFiles(FileScanner[] scanners)

grabFiles


protected static java.io.File[] grabFiles(FileScanner[] scanners,
                                          java.lang.String[][] fileNames)

grabFileNames


protected static java.lang.String[][] grabFileNames(FileScanner[] scanners)

zipDir


protected void zipDir(java.io.File dir,
                      ZipOutputStream zOut,
                      java.lang.String vPath)
               throws java.io.IOException
java.io.IOException

zipFile


protected void zipFile(java.io.InputStream in,
                       ZipOutputStream zOut,
                       java.lang.String vPath,
                       long lastModified,
                       java.io.File file)
                throws java.io.IOException
java.io.IOException

zipFile


protected void zipFile(java.io.File file,
                       ZipOutputStream zOut,
                       java.lang.String vPath)
                throws java.io.IOException
java.io.IOException

addParentDirs


protected void addParentDirs(java.io.File baseDir,
                             java.lang.String entry,
                             ZipOutputStream zOut,
                             java.lang.String prefix)
                      throws java.io.IOException
Ensure all parent dirs of a given entry have been added.

java.io.IOException

addFiles


protected void addFiles(java.util.Vector filesets,
                        ZipOutputStream zOut)
                 throws java.io.IOException
Iterate over the given Vector of (zip)filesets and add all files to the ZipOutputStream using the given prefix or fullpath.

java.io.IOException

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.

See Also:
reset()

reset


public void reset()
Makes this instance reset all attributes to their default values and forget all children.

Since:
Ant 1.5
See Also:
cleanUp()


Copyright © 2000-2002 Apache Software Foundation. All Rights Reserved.