org.codehaus.plexus.archiver.zip
Class AbstractZipArchiver

java.lang.Object
  extended by org.codehaus.plexus.logging.AbstractLogEnabled
      extended by org.codehaus.plexus.archiver.AbstractArchiver
          extended by org.codehaus.plexus.archiver.zip.AbstractZipArchiver
All Implemented Interfaces:
Archiver, org.codehaus.plexus.logging.LogEnabled
Direct Known Subclasses:
ZipArchiver

public abstract class AbstractZipArchiver
extends AbstractArchiver

Version:
$Revision: 2436 $ $Date: 2005-09-01 10:20:41 -0700 (Thu, 01 Sep 2005) $

Field Summary
protected  java.util.Hashtable addedDirs
           
protected  boolean addingNewFiles
          true when we are adding new files into the Zip file, as opposed to adding back the unchanged files
protected  java.lang.String archiveType
           
protected  boolean doubleFilePass
           
protected  java.lang.String duplicate
           
protected  java.util.Hashtable entries
           
protected  boolean skipWriting
           
 
Fields inherited from class org.codehaus.plexus.archiver.AbstractArchiver
DEFAULT_DIR_MODE, DEFAULT_FILE_MODE
 
Fields inherited from interface org.codehaus.plexus.archiver.Archiver
ROLE
 
Constructor Summary
AbstractZipArchiver()
           
 
Method Summary
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 addResources(java.util.Map resources, ZipOutputStream zOut)
          Add the given resources.
protected  void cleanUp()
          Do any clean up necessary to allow this instance to be used again.
 void createArchive()
           
protected  boolean createEmptyZip(java.io.File zipFile)
          Create an empty zip file
protected  void finalizeZipOutputStream(ZipOutputStream zOut)
          method for subclasses to override
 java.lang.String getComment()
           
 int getDirMode()
          Deprecated. use AbstractArchiver.getDefaultDirectoryMode() instead.
 java.lang.String getEncoding()
           
 int getFileMode()
          Deprecated. use AbstractArchiver.getDefaultFileMode() instead.
protected  java.util.Map getResourcesToAdd(java.io.File file)
           
protected  java.util.Map getResourcesToUpdate(java.io.File file)
           
protected  void initZipOutputStream(ZipOutputStream zOut)
          method for subclasses to override
 boolean isCompress()
           
 boolean isFilesonly()
           
 boolean isInUpdateMode()
           
 boolean isRoundUp()
           
 void reset()
          Makes this instance reset all attributes to their default values and forget all children.
 void setComment(java.lang.String comment)
           
 void setCompress(boolean compress)
           
 void setDirMode(java.lang.String octalString)
          Deprecated. use AbstractArchiver.setDefaultDirectoryMode(int).
 void setEncoding(java.lang.String encoding)
           
 void setFileMode(java.lang.String octalString)
          Deprecated. use AbstractArchiver.setDefaultFileMode(int) instead.
 void setFilesonly(boolean f)
          If true, emulate Sun's jar utility by not adding parent directories; optional, defaults to false.
 void setRoundUp(boolean r)
          Whether the file modification times will be rounded up to the next even number of seconds.
 void setUpdateMode(boolean update)
           
protected  void zipDir(java.io.File dir, ZipOutputStream zOut, java.lang.String vPath, int mode)
           
protected  void zipFile(ArchiveEntry entry, ZipOutputStream zOut, java.lang.String vPath)
          Method that gets called when adding from java.io.File instances.
protected  void zipFile(java.io.InputStream in, ZipOutputStream zOut, java.lang.String vPath, long lastModified, java.io.File fromArchive, int mode)
          Adds a new entry to the archive, takes care of duplicates as well.
 
Methods inherited from class org.codehaus.plexus.archiver.AbstractArchiver
addDirectory, addDirectory, addDirectory, addDirectory, addFile, addFile, getDefaultDirectoryMode, getDefaultFileMode, getDestFile, getDirs, getFiles, getIncludeEmptyDirs, getLogger, setDefaultDirectoryMode, setDefaultFileMode, setDestFile, setIncludeEmptyDirs
 
Methods inherited from class org.codehaus.plexus.logging.AbstractLogEnabled
enableLogging, setupLogger, setupLogger, setupLogger
 
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

entries

protected java.util.Hashtable entries

duplicate

protected java.lang.String duplicate

addedDirs

protected java.util.Hashtable addedDirs

doubleFilePass

protected boolean doubleFilePass

skipWriting

protected boolean skipWriting

addingNewFiles

protected boolean addingNewFiles
true when we are adding new files into the Zip file, as opposed to adding back the unchanged files

Constructor Detail

AbstractZipArchiver

public AbstractZipArchiver()
Method Detail

getComment

public java.lang.String getComment()

setComment

public void setComment(java.lang.String comment)

getEncoding

public java.lang.String getEncoding()

setEncoding

public void setEncoding(java.lang.String encoding)

setCompress

public void setCompress(boolean compress)

isCompress

public boolean isCompress()

setUpdateMode

public void setUpdateMode(boolean update)

isInUpdateMode

public boolean isInUpdateMode()

setFileMode

public void setFileMode(java.lang.String octalString)
Deprecated. use AbstractArchiver.setDefaultFileMode(int) instead.

A 3 digit octal string, specify the user, group and other modes in the standard Unix fashion; optional, default=0644


getFileMode

public int getFileMode()
Deprecated. use AbstractArchiver.getDefaultFileMode() instead.


setDirMode

public void setDirMode(java.lang.String octalString)
Deprecated. use AbstractArchiver.setDefaultDirectoryMode(int).

A 3 digit octal string, specify the user, group and other modes in the standard Unix fashion; optional, default=0755


getDirMode

public int getDirMode()
Deprecated. use AbstractArchiver.getDefaultDirectoryMode() instead.


setFilesonly

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


isFilesonly

public boolean isFilesonly()

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.


isRoundUp

public boolean isRoundUp()

createArchive

public void createArchive()
                   throws ArchiverException,
                          java.io.IOException
Throws:
ArchiverException
java.io.IOException

getResourcesToAdd

protected java.util.Map getResourcesToAdd(java.io.File file)
                                   throws java.io.IOException
Throws:
java.io.IOException

getResourcesToUpdate

protected java.util.Map getResourcesToUpdate(java.io.File file)
                                      throws java.io.IOException
Throws:
java.io.IOException

addResources

protected final void addResources(java.util.Map resources,
                                  ZipOutputStream zOut)
                           throws java.io.IOException,
                                  ArchiverException
Add the given resources.

Parameters:
resources - the resources to add
zOut - the stream to write to
Throws:
java.io.IOException
ArchiverException

addParentDirs

protected final 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.

Throws:
java.io.IOException

zipFile

protected void zipFile(java.io.InputStream in,
                       ZipOutputStream zOut,
                       java.lang.String vPath,
                       long lastModified,
                       java.io.File fromArchive,
                       int mode)
                throws java.io.IOException,
                       ArchiverException
Adds a new entry to the archive, takes care of duplicates as well.

Parameters:
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.
Throws:
java.io.IOException
ArchiverException

zipFile

protected void zipFile(ArchiveEntry entry,
                       ZipOutputStream zOut,
                       java.lang.String vPath)
                throws java.io.IOException,
                       ArchiverException
Method that gets called when adding from java.io.File instances.

This implementation delegates to the six-arg version.

Parameters:
entry - the file to add to the archive
zOut - the stream to write to
vPath - the name this entry shall have in the archive
Throws:
java.io.IOException
ArchiverException

zipDir

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

createEmptyZip

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

Returns:
true for historic reasons
Throws:
ArchiverException

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.

See Also:
cleanUp()

initZipOutputStream

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

Throws:
java.io.IOException
ArchiverException

finalizeZipOutputStream

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

Throws:
java.io.IOException
ArchiverException


Copyright 2001-2001-2006 Codehaus. All Rights Reserved.