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
Direct Known Subclasses:
Jar

public class Zip
extends MatchingTask

Create a ZIP archive.

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

Inner Class Summary
static class Zip.WhenEmpty
          Possible behaviors when there are no matching files for the task.
 
Field Summary
protected  java.lang.String archiveType
           
protected  java.lang.String emptyBehavior
           
 
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 (nested fileset attribute).
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 (nested zipfileset attribute) that can be read from an archive and be given a prefix/fullpath.
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()
          Called by the project to let the task do it's work.
protected  void finalizeZipOutputStream(ZipOutputStream zOut)
           
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)
           
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
protected  boolean isUpToDate(FileScanner[] scanners, java.io.File zipFile)
          Check whether the archive is up-to-date; and handle behavior for empty archives.
 void setBasedir(java.io.File baseDir)
          This is the base directory to look in for things to zip.
 void setCompress(boolean c)
          Sets whether we want to compress the files or only store them.
 void setEncoding(java.lang.String encoding)
          Encoding to use for filenames, defaults to the platform's default encoding.
 void setFilesonly(boolean f)
          Emulate Sun's jar utility by not adding parent dirs
 void setUpdate(boolean c)
          Sets whether we want to update the file (if it exists) or create a new one.
 void setWhenempty(Zip.WhenEmpty we)
          Sets behavior of the task when no files match.
 void setZipfile(java.io.File zipFile)
          This is the name/location of where to create the .zip file.
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)
           
 
Methods inherited from class org.apache.tools.ant.taskdefs.MatchingTask
createExclude, createExcludesFile, createInclude, createIncludesFile, createPatternSet, getDirectoryScanner, setDefaultexcludes, setExcludes, setExcludesfile, setIncludes, setIncludesfile, XsetIgnore, XsetItems
 
Methods inherited from class org.apache.tools.ant.Task
getDescription, getLocation, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, handleErrorOutput, handleOutput, init, log, log, maybeConfigure, perform, setDescription, setLocation, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName
 
Methods inherited from class org.apache.tools.ant.ProjectComponent
getProject, setProject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

archiveType

protected java.lang.String archiveType

emptyBehavior

protected java.lang.String emptyBehavior
Constructor Detail

Zip

public Zip()
Method Detail

setZipfile

public void setZipfile(java.io.File zipFile)
This is the name/location of where to create the .zip file.

setBasedir

public void setBasedir(java.io.File baseDir)
This is the base directory to look in for things to zip.

setCompress

public void setCompress(boolean c)
Sets whether we want to compress the files or only store them.

setFilesonly

public void setFilesonly(boolean f)
Emulate Sun's jar utility by not adding parent dirs

setUpdate

public void setUpdate(boolean c)
Sets whether we want to update the file (if it exists) or create a new one.

addFileset

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

addZipfileset

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

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
Description copied from class: Task
Called by the project to let the task do it's work. This method may be called more than once, if the task is invoked more than once. For example, if target1 and target2 both depend on target3, then running "ant target1 target2" will run all tasks in target3 twice.
Overrides:
execute in class Task
Following copied from class: org.apache.tools.ant.Task
Throws:
BuildException - if someting 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.


addZipEntries

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

initZipOutputStream

protected void initZipOutputStream(ZipOutputStream zOut)
                            throws java.io.IOException,
                                   BuildException

finalizeZipOutputStream

protected void finalizeZipOutputStream(ZipOutputStream zOut)
                                throws 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

zipFile

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

zipFile

protected void zipFile(java.io.File file,
                       ZipOutputStream zOut,
                       java.lang.String vPath)
                throws 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.

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.

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.



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