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, FilterEnabled, FinalizerEnabled, org.codehaus.plexus.logging.LogEnabled, org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable
Direct Known Subclasses:
ZipArchiver

public abstract class AbstractZipArchiver
extends AbstractArchiver

Version:
$Revision$ $Date$

Field Summary
protected  Hashtable<String,String> addedDirs
           
protected  boolean addingNewFiles
          true when we are adding new files into the Zip file, as opposed to adding back the unchanged files
protected  String archiveType
           
protected  boolean doubleFilePass
           
protected  String duplicate
          Deprecated. Use Archiver.setDuplicateBehavior(String) instead.
protected  Hashtable<String,String> entries
           
protected  boolean skipWriting
           
 
Fields inherited from interface org.codehaus.plexus.archiver.Archiver
DEFAULT_DIR_MODE, DEFAULT_FILE_MODE, DUPLICATES_ADD, DUPLICATES_FAIL, DUPLICATES_PRESERVE, DUPLICATES_SKIP, DUPLICATES_VALID_BEHAVIORS, ROLE
 
Constructor Summary
AbstractZipArchiver()
           
 
Method Summary
protected  void addParentDirs(File baseDir, String entry, ZipOutputStream zOut, String prefix)
          Ensure all parent dirs of a given entry have been added.
protected  void addResources(ResourceIterator resources, ZipOutputStream zOut)
          Add the given resources.
protected  void cleanUp()
          Do any clean up necessary to allow this instance to be used again.
protected  void close()
           
protected  boolean createEmptyZip(File zipFile)
          Create an empty zip file
protected  void execute()
           
protected  void finalizeZipOutputStream(ZipOutputStream zOut)
           
protected  String getArchiveType()
           
 String getComment()
           
 String getEncoding()
           
protected  Map<String,Long> getZipEntryNames(File file)
           
protected  void initZipOutputStream(ZipOutputStream zOut)
          method for subclasses to override
 boolean isCompress()
           
protected  boolean isFileAdded(ArchiveEntry entry, Map entries)
           
 boolean isFilesonly()
           
protected  boolean isFileUpdated(ArchiveEntry entry, Map entries)
           
 boolean isInUpdateMode()
           
 boolean isRoundUp()
           
 boolean isSupportingForced()
          method for subclasses to override
 void reset()
          Makes this instance reset all attributes to their default values and forget all children.
protected  boolean revert(StringBuffer messageBuffer)
           
 void setComment(String comment)
           
 void setCompress(boolean compress)
           
 void setEncoding(String encoding)
           
 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(org.codehaus.plexus.components.io.resources.PlexusIoResource dir, ZipOutputStream zOut, String vPath, int mode)
           
protected  void zipFile(ArchiveEntry entry, ZipOutputStream zOut, String vPath)
          Method that gets called when adding from java.io.File instances.
protected  void zipFile(InputStream in, ZipOutputStream zOut, String vPath, long lastModified, 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
addArchivedFileSet, addArchivedFileSet, addArchivedFileSet, addArchivedFileSet, addArchivedFileSet, addArchiveFinalizer, addDirectory, addDirectory, addDirectory, addDirectory, addFile, addFile, addFileSet, addResource, addResources, asArchiveEntry, asArchiveEntry, asResourceCollection, checkForced, contextualize, createArchive, getArchiveFinalizers, getDefaultDirectoryMode, getDefaultFileMode, getDestFile, getDirectoryMode, getDirs, getDuplicateBehavior, getFileMode, getFiles, getIncludeEmptyDirs, getLogger, getOverrideDirectoryMode, getOverrideFileMode, getRawDefaultDirectoryMode, getRawDefaultFileMode, getResources, hasVirtualFiles, isForced, isIgnorePermissions, isUptodate, isUseJvmChmod, runArchiveFinalizers, setArchiveFilters, setArchiveFinalizers, setDefaultDirectoryMode, setDefaultFileMode, setDestFile, setDirectoryMode, setDotFileDirectory, setDuplicateBehavior, setFileMode, setForced, setIgnorePermissions, setIncludeEmptyDirs, setUseJvmChmod, validate
 
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 String archiveType

entries

protected Hashtable<String,String> entries

addedDirs

protected Hashtable<String,String> addedDirs

doubleFilePass

protected boolean doubleFilePass

skipWriting

protected boolean skipWriting

duplicate

protected String duplicate
Deprecated. Use Archiver.setDuplicateBehavior(String) instead.

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 String getComment()

setComment

public void setComment(String comment)

getEncoding

public String getEncoding()

setEncoding

public void setEncoding(String encoding)

setCompress

public void setCompress(boolean compress)

isCompress

public boolean isCompress()

setUpdateMode

public void setUpdateMode(boolean update)

isInUpdateMode

public boolean isInUpdateMode()

setFilesonly

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

Parameters:
f - true to emilate sun jar utility

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.

Parameters:
r - true to round

isRoundUp

public boolean isRoundUp()

execute

protected void execute()
                throws ArchiverException,
                       IOException
Specified by:
execute in class AbstractArchiver
Throws:
ArchiverException
IOException

finalizeZipOutputStream

protected void finalizeZipOutputStream(ZipOutputStream zOut)
                                throws IOException,
                                       ArchiverException
Throws:
IOException
ArchiverException

getZipEntryNames

protected Map<String,Long> getZipEntryNames(File file)
                                     throws IOException
Throws:
IOException

isFileAdded

protected boolean isFileAdded(ArchiveEntry entry,
                              Map entries)

isFileUpdated

protected boolean isFileUpdated(ArchiveEntry entry,
                                Map entries)

addResources

protected final void addResources(ResourceIterator resources,
                                  ZipOutputStream zOut)
                           throws IOException,
                                  ArchiverException
Add the given resources.

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

addParentDirs

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

Throws:
IOException

zipFile

protected void zipFile(InputStream in,
                       ZipOutputStream zOut,
                       String vPath,
                       long lastModified,
                       File fromArchive,
                       int mode)
                throws 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:
IOException
ArchiverException

zipFile

protected void zipFile(ArchiveEntry entry,
                       ZipOutputStream zOut,
                       String vPath)
                throws 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:
IOException
ArchiverException

zipDir

protected void zipDir(org.codehaus.plexus.components.io.resources.PlexusIoResource dir,
                      ZipOutputStream zOut,
                      String vPath,
                      int mode)
               throws IOException
Throws:
IOException

createEmptyZip

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

Parameters:
zipFile - The 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.

Overrides:
cleanUp in class AbstractArchiver
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 IOException,
                                   ArchiverException
method for subclasses to override

Throws:
IOException
ArchiverException

isSupportingForced

public boolean isSupportingForced()
method for subclasses to override

Specified by:
isSupportingForced in interface Archiver
Overrides:
isSupportingForced in class AbstractArchiver
Returns:
True, if the archiver does support uptodate checks, false otherwise
See Also:
Archiver.setForced(boolean), Archiver.isForced()

revert

protected boolean revert(StringBuffer messageBuffer)
Overrides:
revert in class AbstractArchiver

close

protected void close()
              throws IOException
Specified by:
close in class AbstractArchiver
Throws:
IOException

getArchiveType

protected String getArchiveType()
Specified by:
getArchiveType in class AbstractArchiver


Copyright © 2008-2012 Sonatype, Inc.. All Rights Reserved.