public abstract class AbstractZipArchiver extends AbstractArchiver
Modifier and Type | Field and Description |
---|---|
protected AddedDirs |
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 |
private java.lang.String |
comment |
private boolean |
doCompress |
private boolean |
doFilesonly |
protected boolean |
doubleFilePass |
private boolean |
doUpdate |
protected java.lang.String |
duplicate
Deprecated.
Use
Archiver.setDuplicateBehavior(String) instead. |
private static long |
EMPTY_CRC |
private java.lang.String |
encoding
Encoding to use for filenames, defaults to the platform's
default encoding.
|
protected java.util.Hashtable<java.lang.String,java.lang.String> |
entries |
private static boolean |
isJava7OrLower
Whether the file modification times will be rounded up to the
next even number of seconds.
|
private boolean |
recompressAddedZips |
private java.io.File |
renamedFile |
private boolean |
savedDoUpdate |
protected boolean |
skipWriting |
private boolean |
success |
protected org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream |
zipArchiveOutputStream |
private java.io.File |
zipFile |
private ConcurrentJarCreator |
zOut |
DEFAULT_DIR_MODE, DEFAULT_FILE_MODE, DEFAULT_SYMLILNK_MODE, DUPLICATES_ADD, DUPLICATES_FAIL, DUPLICATES_PRESERVE, DUPLICATES_SKIP, DUPLICATES_VALID_BEHAVIORS, ROLE
Constructor and Description |
---|
AbstractZipArchiver() |
Modifier and Type | Method and Description |
---|---|
private void |
addParentDirs(ArchiveEntry archiveEntry,
java.io.File baseDir,
java.lang.String entry,
ConcurrentJarCreator zOut)
Ensure all parent dirs of a given entry have been added.
|
protected void |
addResources(ResourceIterator resources,
ConcurrentJarCreator zOut)
Add the given resources.
|
protected void |
cleanUp()
Do any clean up necessary to allow this instance to be used again.
|
protected void |
close() |
private void |
createArchiveMain() |
protected boolean |
createEmptyZip(java.io.File zipFile)
Create an empty zip file
|
protected org.apache.commons.compress.parallel.InputStreamSupplier |
createInputStreamSupplier(java.io.InputStream inputStream) |
protected void |
execute() |
protected void |
finalizeZipOutputStream(ConcurrentJarCreator zOut) |
protected java.lang.String |
getArchiveType() |
java.lang.String |
getComment() |
java.lang.String |
getEncoding() |
private static int |
getJavaVersion() |
private org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream.UnicodeExtraFieldPolicy |
getUnicodeExtraFieldPolicy()
Gets the
UnicodeExtraFieldPolicy to apply. |
protected void |
initZipOutputStream(ConcurrentJarCreator zOut)
method for subclasses to override
|
boolean |
isCompress() |
boolean |
isFilesonly() |
boolean |
isInUpdateMode() |
boolean |
isRecompressAddedZips() |
boolean |
isSupportingForced()
method for subclasses to override
|
private boolean |
isZipHeader(byte[] header) |
private java.io.InputStream |
maybeSequence(byte[] header,
int hdrBytes,
java.io.InputStream in) |
void |
reset()
Makes this instance reset all attributes to their default
values and forget all children.
|
protected boolean |
revert(java.lang.StringBuffer messageBuffer) |
void |
setComment(java.lang.String comment) |
void |
setCompress(boolean compress) |
void |
setEncoding(java.lang.String encoding) |
void |
setFilesonly(boolean f)
If true, emulate Sun's jar utility by not adding parent directories;
optional, defaults to false.
|
void |
setRecompressAddedZips(boolean recompressAddedZips) |
private void |
setTime(java.util.zip.ZipEntry zipEntry,
long lastModified) |
void |
setUpdateMode(boolean update) |
private org.apache.commons.compress.parallel.InputStreamSupplier |
wrappedRecompressor(org.apache.commons.compress.archivers.zip.ZipArchiveEntry ze,
org.apache.commons.compress.parallel.InputStreamSupplier other) |
protected void |
zipDir(org.codehaus.plexus.components.io.resources.PlexusIoResource dir,
ConcurrentJarCreator zOut,
java.lang.String vPath,
int mode,
java.lang.String encodingToUse) |
protected void |
zipFile(ArchiveEntry entry,
ConcurrentJarCreator zOut,
java.lang.String vPath)
Method that gets called when adding from java.io.File instances.
|
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)
Adds a new entry to the archive, takes care of duplicates as well.
|
addArchivedFileSet, addArchivedFileSet, addArchivedFileSet, addArchivedFileSet, addArchivedFileSet, addArchivedFileSet, addArchiveFinalizer, addDirectory, addDirectory, addDirectory, addDirectory, addFile, addFile, addFileSet, addResource, addResources, addSymlink, addSymlink, asArchiveEntry, asResourceCollection, checkForced, contextualize, createArchive, getDefaultDirectoryMode, getDefaultFileMode, getDestFile, getDirectoryMode, getDuplicateBehavior, getFileMode, getFiles, getIncludeEmptyDirs, getLogger, getOverrideDirectoryMode, getOverrideFileMode, getRawDefaultFileMode, getResources, hasVirtualFiles, isForced, isIgnorePermissions, isUptodate, isUseJvmChmod, runArchiveFinalizers, setArchiveFinalizers, setDefaultDirectoryMode, setDefaultFileMode, setDestFile, setDirectoryMode, setDotFileDirectory, setDuplicateBehavior, setFileMode, setForced, setIgnorePermissions, setIncludeEmptyDirs, setUseJvmChmod, validate
private java.lang.String comment
private java.lang.String encoding
private boolean doCompress
private boolean recompressAddedZips
private boolean doUpdate
private boolean savedDoUpdate
protected java.lang.String archiveType
private boolean doFilesonly
protected final java.util.Hashtable<java.lang.String,java.lang.String> entries
protected final AddedDirs addedDirs
private static final long EMPTY_CRC
protected boolean doubleFilePass
protected boolean skipWriting
protected final java.lang.String duplicate
Archiver.setDuplicateBehavior(String)
instead.protected boolean addingNewFiles
private static final boolean isJava7OrLower
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. Java versions up to java7 round timestamp down, which means we add a heuristic value (which is slightly questionable) Java versions from 8 and up round timestamp up. sprivate java.io.File renamedFile
private java.io.File zipFile
private boolean success
private ConcurrentJarCreator zOut
protected org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream zipArchiveOutputStream
private static int getJavaVersion()
public java.lang.String getComment()
public void setComment(java.lang.String comment)
public java.lang.String getEncoding()
public void setEncoding(java.lang.String encoding)
public void setCompress(boolean compress)
public boolean isCompress()
public boolean isRecompressAddedZips()
public void setRecompressAddedZips(boolean recompressAddedZips)
public void setUpdateMode(boolean update)
public boolean isInUpdateMode()
public void setFilesonly(boolean f)
f
- true to emilate sun jar utilitypublic boolean isFilesonly()
protected void execute() throws ArchiverException, java.io.IOException
execute
in class AbstractArchiver
ArchiverException
java.io.IOException
protected void finalizeZipOutputStream(ConcurrentJarCreator zOut) throws java.io.IOException, ArchiverException
java.io.IOException
ArchiverException
private void createArchiveMain() throws ArchiverException, java.io.IOException
ArchiverException
java.io.IOException
private org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream.UnicodeExtraFieldPolicy getUnicodeExtraFieldPolicy()
UnicodeExtraFieldPolicy
to apply.ZipArchiveOutputStream.UnicodeExtraFieldPolicy.NEVER
, if the effective encoding is
UTF-8; ZipArchiveOutputStream.UnicodeExtraFieldPolicy.ALWAYS
, if the effective encoding is not
UTF-8.getEncoding()
protected final void addResources(ResourceIterator resources, ConcurrentJarCreator zOut) throws java.io.IOException, ArchiverException
resources
- the resources to addzOut
- the stream to write tojava.io.IOException
ArchiverException
private void addParentDirs(ArchiveEntry archiveEntry, java.io.File baseDir, java.lang.String entry, ConcurrentJarCreator zOut) throws java.io.IOException
java.io.IOException
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, ArchiverException
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 to false
it is added synchronously.
If the entry is symbolic link this parameter is ignored.java.io.IOException
ArchiverException
private java.io.InputStream maybeSequence(byte[] header, int hdrBytes, java.io.InputStream in)
private boolean isZipHeader(byte[] header)
protected void zipFile(ArchiveEntry entry, ConcurrentJarCreator zOut, java.lang.String vPath) throws java.io.IOException, ArchiverException
This implementation delegates to the six-arg version.
entry
- the file to add to the archivezOut
- the stream to write tovPath
- the name this entry shall have in the archivejava.io.IOException
ArchiverException
private void setTime(java.util.zip.ZipEntry zipEntry, long lastModified)
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
java.io.IOException
private org.apache.commons.compress.parallel.InputStreamSupplier wrappedRecompressor(org.apache.commons.compress.archivers.zip.ZipArchiveEntry ze, org.apache.commons.compress.parallel.InputStreamSupplier other)
protected org.apache.commons.compress.parallel.InputStreamSupplier createInputStreamSupplier(java.io.InputStream inputStream)
protected boolean createEmptyZip(java.io.File zipFile) throws ArchiverException
zipFile
- The fileArchiverException
protected void cleanUp() throws java.io.IOException
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.
cleanUp
in class AbstractArchiver
java.io.IOException
reset()
public void reset()
cleanUp()
protected void initZipOutputStream(ConcurrentJarCreator zOut) throws ArchiverException, java.io.IOException
zOut
- The output streamArchiverException
java.io.IOException
public boolean isSupportingForced()
isSupportingForced
in interface Archiver
isSupportingForced
in class AbstractArchiver
Archiver.setForced(boolean)
,
Archiver.isForced()
protected boolean revert(java.lang.StringBuffer messageBuffer)
revert
in class AbstractArchiver
protected void close() throws java.io.IOException
close
in class AbstractArchiver
java.io.IOException
protected java.lang.String getArchiveType()
getArchiveType
in class AbstractArchiver