org.apache.ant.compress.taskdefs
Class ArchiveBase

java.lang.Object
  extended by org.apache.tools.ant.ProjectComponent
      extended by org.apache.tools.ant.Task
          extended by org.apache.ant.compress.taskdefs.ArchiveBase
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
Ar, Cpio, Tar, Zip

public abstract class ArchiveBase
extends org.apache.tools.ant.Task

Base implementation of tasks creating archives.


Nested Class Summary
static class ArchiveBase.Duplicate
          Possible behaviors when a duplicate file is added: "add", "preserve" or "fail"
static interface ArchiveBase.EntryBuilder
          Creates an archive entry for the concrete format.
static interface ArchiveBase.FileSetBuilder
          Creates an archive fileset to read the target archive.
static class ArchiveBase.Mode
          Valid Modes for create/update/replace.
 class ArchiveBase.ResourceCollectionFlags
          Various flags a (archive) resource collection may hold.
 class ArchiveBase.ResourceFlags
          Various flags a (archive) resource may hold in addition to being a plain resource.
 class ArchiveBase.ResourceWithFlags
          Binds a resource to additional data that may be present.
static class ArchiveBase.WhenEmpty
          Possible behaviors when there are no matching files for the task: "fail", "skip".
 
Field Summary
 
Fields inherited from class org.apache.tools.ant.Task
target, taskName, taskType, wrapper
 
Fields inherited from class org.apache.tools.ant.ProjectComponent
description, location, project
 
Constructor Summary
protected ArchiveBase()
           
 
Method Summary
 void add(org.apache.tools.ant.types.ResourceCollection c)
          Sources for the archive.
 void addConfiguredDest(org.apache.tools.ant.types.resources.Resources r)
          The archive to create.
protected  boolean addDuplicate(java.lang.String name)
          Is invoked if a duplicate entry is found, decides whether the entry shall be added regardless.
protected  java.lang.String bendSlashesForward(java.lang.String s)
          Ensures a forward slash is used as file separator and strips leading slashes if preserveLeadingSlashes is false.
protected  void ensureParentDirs(ArchiveOutputStream out, ArchiveBase.ResourceWithFlags r, java.util.Set directoriesAdded)
          Adds records for all parent directories of the given resource that haven't already been added.
 void execute()
           
protected  java.util.Collection findSources()
          Find all the resources with their flags that should be added to the archive.
protected  java.util.Collection findUnmatchedTargets(org.apache.tools.ant.types.ArchiveFileSet target, java.util.Collection src)
          Find the resources from the target archive that don't have a matching resource in the sources to be added.
protected  org.apache.tools.ant.types.Resource getDest()
           
 java.lang.String getEncoding()
          Encoding of file names.
protected  ArchiveBase.EntryBuilder getEntryBuilder()
           
protected  ArchiveStreamFactory getFactory()
           
protected  ArchiveBase.FileSetBuilder getFileSetBuilder()
           
protected  ArchiveBase.ResourceFlags getFlags(org.apache.tools.ant.types.Resource r)
          Extracts flags from a resource.
protected  ArchiveBase.ResourceCollectionFlags getFlags(org.apache.tools.ant.types.ResourceCollection rc)
          Extracts flags from a resource collection.
protected  ArchiveBase.Mode getMode()
           
protected  boolean isFilesOnly()
          Whether only file entries should be added to the archive.
protected  boolean isUpToDate(java.util.Collection src, org.apache.tools.ant.types.ArchiveFileSet existingEntries)
          Checks whether the target is more recent than the resources that shall be added to it.
protected  long round(long millis, long granularity)
          Modify last modified timestamp based on the roundup attribute.
 void setDest(org.apache.tools.ant.types.Resource r)
          The archive to create.
 void setDestfile(java.io.File f)
          The archive to create.
 void setDuplicate(ArchiveBase.Duplicate df)
          Sets behavior for when a duplicate file is about to be added - one of add, preserve or fail.
 void setEncoding(java.lang.String e)
          Encoding of file names.
protected  void setEntryBuilder(ArchiveBase.EntryBuilder builder)
           
protected  void setFactory(ArchiveStreamFactory factory)
           
protected  void setFileSetBuilder(ArchiveBase.FileSetBuilder builder)
           
 void setFilesOnly(boolean b)
          Whether only file entries should be added to the archive.
 void setMode(ArchiveBase.Mode m)
          How to treat the target archive.
 void setPreserve0permissions(boolean b)
          Whether 0 permissions read from an archive should be considered real permissions (that should be preserved) or missing permissions (which is the default).
 void setPreserveLeadingSlashes(boolean b)
          Flag to indicates whether leading `/'s should be preserved in the file names.
 void setRoundUp(boolean r)
          Whether the file modification times will be rounded up to the next timestamp (second or even second depending on the archive format).
 void setWhenempty(ArchiveBase.WhenEmpty we)
          Sets behavior of the task when no resources are to be added.
protected  void sort(java.util.List l)
          Sorts the list of resources to add.
protected  void validate()
          Argument validation.
protected  void writeArchive(java.util.Collection src)
          Creates the archive archiving the given resources.
 
Methods inherited from class org.apache.tools.ant.Task
bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType
 
Methods inherited from class org.apache.tools.ant.ProjectComponent
clone, getDescription, getLocation, getProject, setDescription, setLocation, setProject
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArchiveBase

protected ArchiveBase()
Method Detail

setFactory

protected final void setFactory(ArchiveStreamFactory factory)

getFactory

protected final ArchiveStreamFactory getFactory()

setEntryBuilder

protected final void setEntryBuilder(ArchiveBase.EntryBuilder builder)

getEntryBuilder

protected final ArchiveBase.EntryBuilder getEntryBuilder()

setFileSetBuilder

protected final void setFileSetBuilder(ArchiveBase.FileSetBuilder builder)

getFileSetBuilder

protected final ArchiveBase.FileSetBuilder getFileSetBuilder()

setDestfile

public void setDestfile(java.io.File f)
The archive to create.


addConfiguredDest

public void addConfiguredDest(org.apache.tools.ant.types.resources.Resources r)
The archive to create.


setDest

public void setDest(org.apache.tools.ant.types.Resource r)
The archive to create.


getDest

protected org.apache.tools.ant.types.Resource getDest()

add

public void add(org.apache.tools.ant.types.ResourceCollection c)
Sources for the archive.


setMode

public void setMode(ArchiveBase.Mode m)
How to treat the target archive.


getMode

protected ArchiveBase.Mode getMode()

setEncoding

public void setEncoding(java.lang.String e)
Encoding of file names.


getEncoding

public java.lang.String getEncoding()
Encoding of file names.


setFilesOnly

public void setFilesOnly(boolean b)
Whether only file entries should be added to the archive.


isFilesOnly

protected boolean isFilesOnly()
Whether only file entries should be added to the archive.


setPreserve0permissions

public void setPreserve0permissions(boolean b)
Whether 0 permissions read from an archive should be considered real permissions (that should be preserved) or missing permissions (which is the default).


setRoundUp

public void setRoundUp(boolean r)
Whether the file modification times will be rounded up to the next timestamp (second or even second depending on the archive format).

Zip archives store file modification times with a granularity of two seconds, ar, tar and cpio use a granularity of one second. 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.

Parameters:
r - a boolean value

setPreserveLeadingSlashes

public void setPreserveLeadingSlashes(boolean b)
Flag to indicates whether leading `/'s should be preserved in the file names. Optional, default is false.

Parameters:
b - the leading slashes flag.

setDuplicate

public void setDuplicate(ArchiveBase.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 is fail

Parameters:
df - a Duplicate enumerated value

setWhenempty

public void setWhenempty(ArchiveBase.WhenEmpty we)
Sets behavior of the task when no resources are to be added. Possible values are: fail (throw an exception and halt the build); skip (do not create any archive, but issue a warning);. Default is fail;

Parameters:
we - a WhenEmpty enumerated value

execute

public void execute()
Overrides:
execute in class org.apache.tools.ant.Task

validate

protected void validate()
                 throws org.apache.tools.ant.BuildException
Argument validation.

Throws:
org.apache.tools.ant.BuildException

findSources

protected java.util.Collection findSources()
                                    throws java.io.IOException
Find all the resources with their flags that should be added to the archive.

Throws:
java.io.IOException

isUpToDate

protected boolean isUpToDate(java.util.Collection src,
                             org.apache.tools.ant.types.ArchiveFileSet existingEntries)
                      throws java.io.IOException
Checks whether the target is more recent than the resources that shall be added to it.

Will only ever be invoked if the target exists.

Parameters:
src - the resources that have been found as sources, may be modified in "update" mode to remove entries that are up to date
existingEntries - the target archive as fileset
Returns:
true if the target is up-to-date
Throws:
java.io.IOException

findUnmatchedTargets

protected java.util.Collection findUnmatchedTargets(org.apache.tools.ant.types.ArchiveFileSet target,
                                                    java.util.Collection src)
                                             throws java.io.IOException
Find the resources from the target archive that don't have a matching resource in the sources to be added.

Throws:
java.io.IOException

sort

protected void sort(java.util.List l)
Sorts the list of resources to add.


writeArchive

protected void writeArchive(java.util.Collection src)
                     throws java.io.IOException
Creates the archive archiving the given resources.

Throws:
java.io.IOException

ensureParentDirs

protected void ensureParentDirs(ArchiveOutputStream out,
                                ArchiveBase.ResourceWithFlags r,
                                java.util.Set directoriesAdded)
                         throws java.io.IOException
Adds records for all parent directories of the given resource that haven't already been added.

Flags for the "missing" directories will be taken from the ResourceCollection that contains the resource to be added.

Throws:
java.io.IOException

getFlags

protected ArchiveBase.ResourceFlags getFlags(org.apache.tools.ant.types.Resource r)
                                      throws java.util.zip.ZipException
Extracts flags from a resource.

ZipExceptions are only here for the code that translates Ant's ZipExtraFields to CC ZipExtraFields and should never actually be thrown.

Throws:
java.util.zip.ZipException

getFlags

protected ArchiveBase.ResourceCollectionFlags getFlags(org.apache.tools.ant.types.ResourceCollection rc)
Extracts flags from a resource collection.


bendSlashesForward

protected java.lang.String bendSlashesForward(java.lang.String s)
Ensures a forward slash is used as file separator and strips leading slashes if preserveLeadingSlashes is false.


round

protected long round(long millis,
                     long granularity)
Modify last modified timestamp based on the roundup attribute.

Parameters:
millis - the timestamp
granularity - the granularity of timestamps in the archive format in millis

addDuplicate

protected boolean addDuplicate(java.lang.String name)
Is invoked if a duplicate entry is found, decides whether the entry shall be added regardless.