Package org.codehaus.plexus.archiver.zip
Class AbstractZipArchiver
- java.lang.Object
-
- org.codehaus.plexus.logging.AbstractLogEnabled
-
- org.codehaus.plexus.archiver.AbstractArchiver
-
- org.codehaus.plexus.archiver.zip.AbstractZipArchiver
-
- All Implemented Interfaces:
Archiver,FinalizerEnabled,org.codehaus.plexus.logging.LogEnabled,org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable
- 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 java.lang.StringarchiveTypeprivate java.lang.Stringcommentprivate booleandoCompressprivate booleandoFilesonlyprotected booleandoubleFilePassprivate booleandoUpdateprotected java.lang.StringduplicateDeprecated.UseArchiver.setDuplicateBehavior(String)instead.private static longEMPTY_CRCprivate java.lang.StringencodingEncoding to use for filenames, defaults to the platform's default encoding.protected java.util.Hashtable<java.lang.String,java.lang.String>entriesprivate booleanrecompressAddedZipsprivate java.io.FilerenamedFileprivate booleansavedDoUpdateprotected booleanskipWritingprivate booleansuccessprotected org.apache.commons.compress.archivers.zip.ZipArchiveOutputStreamzipArchiveOutputStreamprivate java.io.FilezipFileprivate ConcurrentJarCreatorzOut-
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, ROLE
-
-
Constructor Summary
Constructors Constructor Description AbstractZipArchiver()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddParentDirs(ArchiveEntry archiveEntry, java.io.File baseDir, java.lang.String entry, ConcurrentJarCreator zOut)Ensure all parent dirs of a given entry have been added.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()private voidcreateArchiveMain()protected booleancreateEmptyZip(java.io.File zipFile)Create an empty zip fileprotected org.apache.commons.compress.parallel.InputStreamSuppliercreateInputStreamSupplier(java.io.InputStream inputStream)private static longdosToJavaTime(long dosTime)Converts DOS time to Java time (number of milliseconds since epoch).private byte[]encodeArchiveEntry(java.lang.String payload, java.lang.String encoding)protected voidexecute()protected voidfinalizeZipOutputStream(ConcurrentJarCreator zOut)protected java.lang.StringgetArchiveType()java.lang.StringgetComment()java.lang.StringgetEncoding()private org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream.UnicodeExtraFieldPolicygetUnicodeExtraFieldPolicy()Gets theUnicodeExtraFieldPolicyto apply.protected voidinitZipOutputStream(ConcurrentJarCreator zOut)method for subclasses to overridebooleanisCompress()booleanisFilesonly()booleanisInUpdateMode()booleanisRecompressAddedZips()booleanisSupportingForced()method for subclasses to overrideprotected java.util.DatenormalizeLastModifiedDate(java.util.Date lastModifiedDate)Normalize 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).voidreset()Makes this instance reset all attributes to their default values and forget all children.protected booleanrevert(java.lang.StringBuffer messageBuffer)voidsetComment(java.lang.String comment)voidsetCompress(boolean compress)voidsetEncoding(java.lang.String encoding)voidsetFilesonly(boolean f)If true, emulate Sun's jar utility by not adding parent directories; optional, defaults to false.voidsetRecompressAddedZips(boolean recompressAddedZips)private voidsetTime(java.util.zip.ZipEntry zipEntry, long lastModified)voidsetUpdateMode(boolean update)protected voidzipDir(org.codehaus.plexus.components.io.resources.PlexusIoResource dir, ConcurrentJarCreator zOut, java.lang.String vPath, int mode, java.lang.String encodingToUse)protected voidzipFile(org.apache.commons.compress.parallel.InputStreamSupplier in, ConcurrentJarCreator zOut, java.lang.String vPath, long lastModified, java.io.File fromArchive, int mode, java.lang.String symlinkDestination, boolean addInParallel)Adds a new entry to the archive, takes care of duplicates as well.protected voidzipFile(ArchiveEntry entry, ConcurrentJarCreator zOut, java.lang.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, contextualize, createArchive, getDefaultDirectoryMode, getDefaultFileMode, getDestFile, getDirectoryMode, getDuplicateBehavior, getFileMode, getFilenameComparator, getFiles, getIncludeEmptyDirs, getLastModifiedDate, getLogger, getOverrideDirectoryMode, getOverrideFileMode, getOverrideGid, getOverrideGroupName, getOverrideUid, getOverrideUserName, getRawDefaultFileMode, getResources, hasVirtualFiles, isForced, isIgnorePermissions, isUptodate, isUseJvmChmod, postCreateArchive, runArchiveFinalizers, setArchiveFinalizers, setDefaultDirectoryMode, setDefaultFileMode, setDestFile, setDirectoryMode, setDotFileDirectory, setDuplicateBehavior, setFileMode, setFilenameComparator, setForced, setIgnorePermissions, setIncludeEmptyDirs, setLastModifiedDate, setOverrideGid, setOverrideGroupName, setOverrideUid, setOverrideUserName, setUseJvmChmod, validate
-
-
-
-
Field Detail
-
comment
private java.lang.String comment
-
encoding
private java.lang.String encoding
Encoding to use for filenames, defaults to the platform's default encoding.
-
doCompress
private boolean doCompress
-
recompressAddedZips
private boolean recompressAddedZips
-
doUpdate
private boolean doUpdate
-
savedDoUpdate
private boolean savedDoUpdate
-
archiveType
protected java.lang.String archiveType
-
doFilesonly
private boolean doFilesonly
-
entries
protected final java.util.Hashtable<java.lang.String,java.lang.String> entries
-
addedDirs
protected final AddedDirs addedDirs
-
EMPTY_CRC
private static final long EMPTY_CRC
-
doubleFilePass
protected boolean doubleFilePass
-
skipWriting
protected boolean skipWriting
-
duplicate
protected final java.lang.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
-
renamedFile
private java.io.File renamedFile
-
zipFile
private java.io.File zipFile
-
success
private boolean success
-
zOut
private ConcurrentJarCreator zOut
-
zipArchiveOutputStream
protected org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream zipArchiveOutputStream
-
-
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()
-
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, java.io.IOException- Specified by:
executein classAbstractArchiver- Throws:
ArchiverExceptionjava.io.IOException
-
finalizeZipOutputStream
protected void finalizeZipOutputStream(ConcurrentJarCreator zOut) throws java.io.IOException, ArchiverException
- Throws:
java.io.IOExceptionArchiverException
-
createArchiveMain
private void createArchiveMain() throws ArchiverException, java.io.IOException- Throws:
ArchiverExceptionjava.io.IOException
-
getUnicodeExtraFieldPolicy
private org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream.UnicodeExtraFieldPolicy getUnicodeExtraFieldPolicy()
Gets theUnicodeExtraFieldPolicyto apply.- Returns:
ZipArchiveOutputStream.UnicodeExtraFieldPolicy.NEVER, if the effective encoding is UTF-8;ZipArchiveOutputStream.UnicodeExtraFieldPolicy.ALWAYS, if the effective encoding is not UTF-8.- See Also:
getEncoding()
-
addResources
protected final void addResources(ResourceIterator resources, ConcurrentJarCreator zOut) throws java.io.IOException, ArchiverException
Add the given resources.- Parameters:
resources- the resources to addzOut- the stream to write to- Throws:
java.io.IOExceptionArchiverException
-
addParentDirs
private void addParentDirs(ArchiveEntry archiveEntry, java.io.File baseDir, java.lang.String entry, ConcurrentJarCreator zOut) throws java.io.IOException
Ensure all parent dirs of a given entry have been added. This method is computed in terms of the potentially remapped entry (that may be disconnected from the file system) we do not *relly* know the entry's connection to the file system so establishing the attributes of the parents can be impossible and is not really supported.- Throws:
java.io.IOException
-
zipFile
protected void zipFile(org.apache.commons.compress.parallel.InputStreamSupplier in, ConcurrentJarCreator zOut, java.lang.String vPath, long lastModified, java.io.File fromArchive, int mode, java.lang.String symlinkDestination, boolean addInParallel) throws java.io.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:
java.io.IOExceptionArchiverException
-
zipFile
protected void zipFile(ArchiveEntry entry, ConcurrentJarCreator 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 archivezOut- the stream to write tovPath- the name this entry shall have in the archive- Throws:
java.io.IOExceptionArchiverException
-
setTime
private void setTime(java.util.zip.ZipEntry zipEntry, long lastModified)
-
zipDir
protected void zipDir(org.codehaus.plexus.components.io.resources.PlexusIoResource dir, ConcurrentJarCreator zOut, java.lang.String vPath, int mode, java.lang.String encodingToUse) throws java.io.IOException- Throws:
java.io.IOException
-
encodeArchiveEntry
private byte[] encodeArchiveEntry(java.lang.String payload, java.lang.String encoding) throws java.io.IOException- Throws:
java.io.IOException
-
createInputStreamSupplier
protected org.apache.commons.compress.parallel.InputStreamSupplier createInputStreamSupplier(java.io.InputStream inputStream)
-
createEmptyZip
protected boolean createEmptyZip(java.io.File zipFile) throws ArchiverExceptionCreate an empty zip file- Parameters:
zipFile- The file- Returns:
- true for historic reasons
- Throws:
ArchiverException
-
cleanUp
protected void cleanUp() throws java.io.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:
java.io.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, java.io.IOException
method for subclasses to override- Parameters:
zOut- The output stream- Throws:
ArchiverExceptionjava.io.IOException
-
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(java.lang.StringBuffer messageBuffer)
- Overrides:
revertin classAbstractArchiver
-
close
protected void close() throws java.io.IOException- Specified by:
closein classAbstractArchiver- Throws:
java.io.IOException
-
getArchiveType
protected java.lang.String getArchiveType()
- Specified by:
getArchiveTypein classAbstractArchiver
-
normalizeLastModifiedDate
protected java.util.Date normalizeLastModifiedDate(java.util.Date lastModifiedDate)
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:
normalizeLastModifiedDatein classAbstractArchiver- Returns:
-
dosToJavaTime
private static long dosToJavaTime(long dosTime)
Converts DOS time to Java time (number of milliseconds since epoch).- See Also:
ZipEntry.setTime(long),ZipUtils.dosToJavaTime(long)
-
-