Class AbstractZipArchiver
- java.lang.Object
-
- org.codehaus.plexus.archiver.AbstractArchiver
-
- org.codehaus.plexus.archiver.zip.AbstractZipArchiver
-
- All Implemented Interfaces:
Archiver,FinalizerEnabled
- Direct Known Subclasses:
ZipArchiver
public abstract class AbstractZipArchiver extends AbstractArchiver
-
-
Field Summary
Fields Modifier and Type Field Description protected AddedDirsaddedDirsprotected booleanaddingNewFilestrue when we are adding new files into the Zip file, as opposed to adding back the unchanged filesprotected StringarchiveTypeprotected booleandoubleFilePassprotected StringduplicateDeprecated.UseArchiver.setDuplicateBehavior(String)instead.protected Hashtable<String,String>entriesprotected booleanskipWritingprotected org.apache.commons.compress.archivers.zip.ZipArchiveOutputStreamzipArchiveOutputStream-
Fields inherited from interface org.codehaus.plexus.archiver.Archiver
DEFAULT_DIR_MODE, DEFAULT_FILE_MODE, DEFAULT_SYMLILNK_MODE, DUPLICATES_ADD, DUPLICATES_FAIL, DUPLICATES_PRESERVE, DUPLICATES_SKIP, DUPLICATES_VALID_BEHAVIORS
-
-
Constructor Summary
Constructors Constructor Description AbstractZipArchiver()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddResources(ResourceIterator resources, ConcurrentJarCreator zOut)Add the given resources.protected voidcleanUp()Do any clean up necessary to allow this instance to be used again.protected voidclose()protected booleancreateEmptyZip(File zipFile)Create an empty zip fileprotected voidexecute()protected voidfinalizeZipOutputStream(ConcurrentJarCreator zOut)protected StringgetArchiveType()StringgetComment()StringgetEncoding()protected voidinitZipOutputStream(ConcurrentJarCreator zOut)method for subclasses to overridebooleanisCompress()booleanisFilesonly()booleanisInUpdateMode()booleanisRecompressAddedZips()booleanisSupportingForced()method for subclasses to overrideprotected FileTimenormalizeLastModifiedTime(FileTime lastModifiedTime)Normalize last modified time value to get reproducible archive entries, based on archive binary format.voidreset()Makes this instance reset all attributes to their default values and forget all children.protected booleanrevert(StringBuffer messageBuffer)voidsetComment(String comment)voidsetCompress(boolean compress)voidsetEncoding(String encoding)voidsetFilesonly(boolean f)If true, emulate Sun's jar utility by not adding parent directories; optional, defaults to false.voidsetRecompressAddedZips(boolean recompressAddedZips)voidsetUpdateMode(boolean update)protected voidsetZipEntryTime(org.apache.commons.compress.archivers.zip.ZipArchiveEntry zipEntry, long lastModifiedTime)Set the ZipEntry dostime using the date if specified otherwise the original time.protected voidzipDir(org.codehaus.plexus.components.io.resources.PlexusIoResource dir, ConcurrentJarCreator zOut, String vPath, int mode, String encodingToUse)protected voidzipFile(org.apache.commons.compress.parallel.InputStreamSupplier in, ConcurrentJarCreator zOut, String vPath, long lastModified, File fromArchive, int mode, String symlinkDestination, boolean addInParallel)Adds a new entry to the archive, takes care of duplicates as well.protected voidzipFile(ArchiveEntry entry, ConcurrentJarCreator zOut, String vPath)Method that gets called when adding from java.io.File instances.-
Methods inherited from class org.codehaus.plexus.archiver.AbstractArchiver
addArchivedFileSet, addArchivedFileSet, addArchivedFileSet, addArchivedFileSet, addArchivedFileSet, addArchivedFileSet, addArchiveFinalizer, addDirectory, addDirectory, addDirectory, addDirectory, addFile, addFile, addFileSet, addResource, addResources, addSymlink, addSymlink, asArchiveEntry, asResourceCollection, checkForced, configureReproducible, configureReproducibleBuild, createArchive, getDefaultDirectoryMode, getDefaultFileMode, getDestFile, getDirectoryMode, getDuplicateBehavior, getFileMode, getFilenameComparator, getFiles, getIncludeEmptyDirs, getLastModifiedDate, getLastModifiedTime, getLogger, getOverrideDirectoryMode, getOverrideFileMode, getOverrideGid, getOverrideGroupName, getOverrideUid, getOverrideUserName, getRawDefaultFileMode, getResources, getUmask, hasVirtualFiles, isForced, isIgnorePermissions, isUptodate, isUseJvmChmod, postCreateArchive, runArchiveFinalizers, setArchiveFinalizers, setDefaultDirectoryMode, setDefaultFileMode, setDestFile, setDirectoryMode, setDotFileDirectory, setDuplicateBehavior, setFileMode, setFilenameComparator, setForced, setIgnorePermissions, setIncludeEmptyDirs, setLastModifiedDate, setLastModifiedTime, setOverrideGid, setOverrideGroupName, setOverrideUid, setOverrideUserName, setUmask, setUseJvmChmod, validate
-
-
-
-
Field Detail
-
archiveType
protected String archiveType
-
addedDirs
protected final AddedDirs addedDirs
-
doubleFilePass
protected boolean doubleFilePass
-
skipWriting
protected boolean skipWriting
-
duplicate
@Deprecated protected final String duplicate
Deprecated.UseArchiver.setDuplicateBehavior(String)instead.- See Also:
- Constant Field Values
-
addingNewFiles
protected boolean addingNewFiles
true when we are adding new files into the Zip file, as opposed to adding back the unchanged files
-
zipArchiveOutputStream
protected org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream zipArchiveOutputStream
-
-
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()
-
isRecompressAddedZips
public boolean isRecompressAddedZips()
-
setRecompressAddedZips
public void setRecompressAddedZips(boolean recompressAddedZips)
-
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()
-
execute
protected void execute() throws ArchiverException, IOException- Specified by:
executein classAbstractArchiver- Throws:
ArchiverExceptionIOException
-
finalizeZipOutputStream
protected void finalizeZipOutputStream(ConcurrentJarCreator zOut) throws IOException, ArchiverException
- Throws:
IOExceptionArchiverException
-
addResources
protected final void addResources(ResourceIterator resources, ConcurrentJarCreator zOut) throws IOException, ArchiverException
Add the given resources.- Parameters:
resources- the resources to addzOut- the stream to write to- Throws:
IOExceptionArchiverException
-
zipFile
protected void zipFile(org.apache.commons.compress.parallel.InputStreamSupplier in, ConcurrentJarCreator zOut, String vPath, long lastModified, File fromArchive, int mode, String symlinkDestination, boolean addInParallel) throws IOException, ArchiverExceptionAdds 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 thissymlinkDestination-addInParallel- Indicates if the entry should be add in parallel. If set tofalseit is added synchronously. If the entry is symbolic link this parameter is ignored.- Throws:
IOExceptionArchiverException
-
zipFile
protected void zipFile(ArchiveEntry entry, ConcurrentJarCreator 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 archivezOut- the stream to write tovPath- the name this entry shall have in the archive- Throws:
IOExceptionArchiverException
-
setZipEntryTime
protected void setZipEntryTime(org.apache.commons.compress.archivers.zip.ZipArchiveEntry zipEntry, long lastModifiedTime)Set the ZipEntry dostime using the date if specified otherwise the original time.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. plexus-archiver chooses to round up.
- Parameters:
zipEntry- to set the last modified timelastModifiedTime- to set in the zip entry only ifAbstractArchiver.getLastModifiedTime()returns null
-
zipDir
protected void zipDir(org.codehaus.plexus.components.io.resources.PlexusIoResource dir, ConcurrentJarCreator zOut, String vPath, int mode, String encodingToUse) 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() throws IOExceptionDo 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:
cleanUpin classAbstractArchiver- Throws:
IOException- 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(ConcurrentJarCreator zOut) throws ArchiverException, IOException
method for subclasses to override- Parameters:
zOut- The output stream- Throws:
ArchiverExceptionIOException
-
isSupportingForced
public boolean isSupportingForced()
method for subclasses to override- Specified by:
isSupportingForcedin interfaceArchiver- Overrides:
isSupportingForcedin classAbstractArchiver- 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:
revertin classAbstractArchiver
-
close
protected void close() throws IOException- Specified by:
closein classAbstractArchiver- Throws:
IOException
-
getArchiveType
protected String getArchiveType()
- Specified by:
getArchiveTypein classAbstractArchiver
-
normalizeLastModifiedTime
protected FileTime normalizeLastModifiedTime(FileTime lastModifiedTime)
Description copied from class:AbstractArchiverNormalize last modified time value to get reproducible archive entries, based on archive binary format.tar uses UTC timestamp, but zip uses local time then requires tweaks to make the value reproducible whatever the current timezone is.
- Overrides:
normalizeLastModifiedTimein classAbstractArchiver- Parameters:
lastModifiedTime- The last modification time- Returns:
- The normalized last modification time
- See Also:
AbstractArchiver.configureReproducibleBuild(FileTime)
-
-