org.apache.tools.ant.taskdefs
Class Zip

java.lang.Object
  |
  +--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

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, project, target, taskName, taskType, wrapper
 
Constructor Summary
Zip()
           
 
Method Summary
protected  void addFiles(FileScanner scanner, java.util.zip.ZipOutputStream zOut, java.lang.String prefix)
          Add all files of the given FileScanner to the ZipOutputStream prependig the given prefix to each filename.
 void addFileset(FileSet set)
          Adds a set of files (nested fileset attribute).
protected  void addParentDirs(java.io.File baseDir, java.lang.String entry, java.util.zip.ZipOutputStream zOut, java.lang.String prefix)
          Ensure all parent dirs of a given entry have been added.
 void execute()
          Called by the project to let the task do it's work.
protected static java.io.File[] grabFiles(FileScanner[] scanners)
           
protected  void initZipOutputStream(java.util.zip.ZipOutputStream zOut)
           
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.lang.String baseDirname)
          This is the base directory to look in for things to zip.
 void setCompress(java.lang.String compress)
          Sets whether we want to compress the files or only store them.
 void setWhenempty(java.lang.String 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, java.util.zip.ZipOutputStream zOut, java.lang.String vPath)
           
protected  void zipFile(java.io.File file, java.util.zip.ZipOutputStream zOut, java.lang.String vPath)
           
protected  void zipFile(java.io.InputStream in, java.util.zip.ZipOutputStream zOut, java.lang.String vPath, long lastModified)
           
 
Methods inherited from class org.apache.tools.ant.taskdefs.MatchingTask
createExclude, createInclude, createPatternSet, getDirectoryScanner, setDefaultexcludes, setExcludes, setExcludesfile, setIncludes, setIncludesfile, XsetIgnore, XsetItems
 
Methods inherited from class org.apache.tools.ant.Task
getDescription, getLocation, getOwningTarget, getProject, getRuntimeConfigurableWrapper, getTaskName, init, log, log, maybeConfigure, setDescription, setLocation, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName
 
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.lang.String baseDirname)
This is the base directory to look in for things to zip.

setCompress

public void setCompress(java.lang.String compress)
Sets whether we want to compress the files or only store them.

addFileset

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

setWhenempty

public void setWhenempty(java.lang.String we)
                  throws BuildException
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.

execute

public void execute()
             throws BuildException
Description copied from class: Task
Called by the project to let the task do it's work. Normally it does nothing.
Overrides:
execute in class Task
Following copied from class: org.apache.tools.ant.Task
Throws:
BuildException - if someting goes wrong with the build

addFiles

protected void addFiles(FileScanner scanner,
                        java.util.zip.ZipOutputStream zOut,
                        java.lang.String prefix)
                 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.


initZipOutputStream

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

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)

zipDir

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

zipFile

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

zipFile

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

addParentDirs

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


Copyright © 2000 Apache Software Foundation. All Rights Reserved.