public class JarArchiver extends ZipArchiver
Modifier and Type | Class and Description |
---|---|
static class |
JarArchiver.FilesetManifestConfig |
Modifier and Type | Field and Description |
---|---|
private Manifest |
configuredManifest
merged manifests added through addConfiguredManifest
|
private boolean |
createEmpty
whether to really create the archive in createEmptyZip, will
get set in getResourcesToAdd.
|
private Manifest |
filesetManifest
merged manifests added through filesets
|
private JarArchiver.FilesetManifestConfig |
filesetManifestConfig
whether to merge fileset manifests;
value is true if filesetmanifest is 'merge' or 'mergewithoutmain'
|
private boolean |
index
jar index is JDK 1.3+ only
|
private static java.lang.String |
INDEX_NAME
The index file name.
|
private java.util.ArrayList<java.lang.String> |
indexJars
Path containing jars that shall be indexed in addition to this archive.
|
private Manifest |
manifest
the manifest specified by the 'manifest' attribute *
|
private static java.lang.String |
MANIFEST_NAME
The manifest file name.
|
private java.io.File |
manifestFile
The file found from the 'manifest' attribute.
|
private boolean |
mergeManifestsMain
whether to merge the main section of fileset manifests;
value is true if filesetmanifest is 'merge'
|
private static java.lang.String |
META_INF_NAME
the name of the meta-inf dir
|
private boolean |
minimalDefaultManifest
Creates a minimal default manifest with
Manifest-Version: 1.0 only. |
private Manifest |
originalManifest
Manifest of original archive, will be set to null if not in
update mode.
|
private java.util.Vector<java.lang.String> |
rootEntries
Stores all files that are in the root of the archive (i.e.
|
private Manifest |
savedConfiguredManifest
shadow of the above if upToDate check alters the value
|
addedDirs, addingNewFiles, archiveType, doubleFilePass, duplicate, entries, skipWriting, zipArchiveOutputStream
DEFAULT_DIR_MODE, DEFAULT_FILE_MODE, DEFAULT_SYMLILNK_MODE, DUPLICATES_ADD, DUPLICATES_FAIL, DUPLICATES_PRESERVE, DUPLICATES_SKIP, DUPLICATES_VALID_BEHAVIORS, ROLE
Constructor and Description |
---|
JarArchiver()
constructor
|
Modifier and Type | Method and Description |
---|---|
void |
addConfiguredIndexJars(java.io.File indexJar) |
void |
addConfiguredManifest(Manifest newManifest)
Allows the manifest for the archive file to be provided inline
in the build file rather than in an external file.
|
protected void |
cleanUp()
Make sure we don't think we already have a MANIFEST next time this task
gets executed.
|
protected boolean |
createEmptyZip(java.io.File zipFile)
Create an empty zip file
|
private void |
createIndexList(ConcurrentJarCreator zOut)
Create the index list to speed up classloading.
|
protected Manifest |
createManifest()
Creates the manifest to be added to the JAR archive.
|
private void |
filesetManifest(java.io.File file,
java.io.InputStream is) |
protected void |
finalizeZipOutputStream(ConcurrentJarCreator zOut) |
protected static java.lang.String |
findJarName(java.lang.String fileName,
java.lang.String[] classpath)
try to guess the name of the given file.
|
private Manifest |
getManifest(java.io.File manifestFile) |
private Manifest |
getManifest(java.io.InputStream is) |
protected static void |
grabFilesAndDirs(java.lang.String file,
java.util.List<java.lang.String> dirs,
java.util.List<java.lang.String> files)
Grab lists of all root-level files and all directories
contained in the given archive.
|
protected boolean |
hasVirtualFiles() |
protected void |
initZipOutputStream(ConcurrentJarCreator zOut)
method for subclasses to override
|
void |
reset()
reset to default values.
|
void |
setFilesetmanifest(JarArchiver.FilesetManifestConfig config)
Behavior when a Manifest is found in a zipfileset or zipgroupfileset file.
|
void |
setIndex(boolean flag)
Set whether or not to create an index list for classes.
|
void |
setManifest(java.io.File manifestFile)
The manifest file to use.
|
void |
setManifestEncoding(java.lang.String manifestEncoding)
Deprecated.
|
void |
setMinimalDefaultManifest(boolean minimalDefaultManifest)
Set whether the default manifest is minimal, thus having only
Manifest-Version: 1.0 in it. |
protected void |
writeIndexLikeList(java.util.List<java.lang.String> dirs,
java.util.List<java.lang.String> files,
java.io.PrintWriter writer)
Writes the directory entries from the first and the filenames
from the second list to the given writer, one entry per line.
|
private void |
writeManifest(ConcurrentJarCreator zOut,
Manifest manifest) |
protected void |
zipFile(org.apache.commons.compress.parallel.InputStreamSupplier is,
ConcurrentJarCreator zOut,
java.lang.String vPath,
long lastModified,
java.io.File fromArchive,
int mode,
java.lang.String symlinkDestination,
boolean addInParallel)
Overridden from Zip class to deal with manifests and index lists.
|
addResources, close, createInputStreamSupplier, execute, getArchiveType, getComment, getEncoding, isCompress, isFilesonly, isInUpdateMode, isRecompressAddedZips, isSupportingForced, revert, setComment, setCompress, setEncoding, setFilesonly, setRecompressAddedZips, setUpdateMode, zipDir, zipFile
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, isForced, isIgnorePermissions, isUptodate, isUseJvmChmod, postCreateArchive, runArchiveFinalizers, setArchiveFinalizers, setDefaultDirectoryMode, setDefaultFileMode, setDestFile, setDirectoryMode, setDotFileDirectory, setDuplicateBehavior, setFileMode, setForced, setIgnorePermissions, setIncludeEmptyDirs, setUseJvmChmod, validate
private static final java.lang.String META_INF_NAME
private static final java.lang.String INDEX_NAME
private static final java.lang.String MANIFEST_NAME
private Manifest configuredManifest
private Manifest savedConfiguredManifest
private Manifest filesetManifest
private Manifest originalManifest
private JarArchiver.FilesetManifestConfig filesetManifestConfig
private boolean mergeManifestsMain
private Manifest manifest
private java.io.File manifestFile
private boolean index
private boolean createEmpty
private java.util.Vector<java.lang.String> rootEntries
private java.util.ArrayList<java.lang.String> indexJars
private boolean minimalDefaultManifest
Manifest-Version: 1.0
only.public void setIndex(boolean flag)
flag
- true to create an indexpublic void setMinimalDefaultManifest(boolean minimalDefaultManifest)
Manifest-Version: 1.0
in it.minimalDefaultManifest
- true to create minimal default manifest@Deprecated public void setManifestEncoding(java.lang.String manifestEncoding)
public void addConfiguredManifest(Manifest newManifest) throws ManifestException
newManifest
- The new manifestManifestException
- .public void setManifest(java.io.File manifestFile) throws ArchiverException
manifestFile
- the manifest file to use.ArchiverException
- .private Manifest getManifest(java.io.File manifestFile) throws ArchiverException
ArchiverException
private Manifest getManifest(java.io.InputStream is) throws ArchiverException
ArchiverException
public void setFilesetmanifest(JarArchiver.FilesetManifestConfig config)
Note: if this attribute's value is not "skip", the created jar will not be readable by using java.util.jar.JarInputStream
config
- setting for found manifest behavior.public void addConfiguredIndexJars(java.io.File indexJar)
indexJar
- The indexjarprotected void initZipOutputStream(ConcurrentJarCreator zOut) throws ArchiverException, java.io.IOException
AbstractZipArchiver
initZipOutputStream
in class AbstractZipArchiver
zOut
- The output streamArchiverException
java.io.IOException
protected boolean hasVirtualFiles()
hasVirtualFiles
in class AbstractArchiver
protected Manifest createManifest() throws ArchiverException
ArchiverException
private void writeManifest(ConcurrentJarCreator zOut, Manifest manifest) throws java.io.IOException, ArchiverException
java.io.IOException
ArchiverException
protected void finalizeZipOutputStream(ConcurrentJarCreator zOut) throws java.io.IOException, ArchiverException
finalizeZipOutputStream
in class AbstractZipArchiver
java.io.IOException
ArchiverException
private void createIndexList(ConcurrentJarCreator zOut) throws java.io.IOException, ArchiverException
zOut
- the zip stream representing the jar being built.java.io.IOException
- thrown if there is an error while creating the
index and adding it to the zip stream.ArchiverException
- .protected void zipFile(org.apache.commons.compress.parallel.InputStreamSupplier is, 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
zipFile
in class AbstractZipArchiver
is
- 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 thisaddInParallel
- 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 void filesetManifest(java.io.File file, java.io.InputStream is) throws ArchiverException
ArchiverException
protected boolean createEmptyZip(java.io.File zipFile) throws ArchiverException
AbstractZipArchiver
createEmptyZip
in class AbstractZipArchiver
zipFile
- The fileArchiverException
protected void cleanUp() throws java.io.IOException
cleanUp
in class AbstractZipArchiver
java.io.IOException
AbstractZipArchiver.cleanUp()
public void reset()
reset
in class AbstractZipArchiver
AbstractZipArchiver.reset()
protected final void writeIndexLikeList(java.util.List<java.lang.String> dirs, java.util.List<java.lang.String> files, java.io.PrintWriter writer)
dirs
- The directoriesfiles
- The fileswriter
- The printwriter ;)protected static java.lang.String findJarName(java.lang.String fileName, java.lang.String[] classpath)
If this jar has a classpath attribute in its manifest, we can assume that it will only require an index of jars listed there. try to find which classpath entry is most likely the one the given file name points to.
In the absence of a classpath attribute, assume the other files will be placed inside the same directory as this jar and use their basename.
if there is a classpath and the given file doesn't match any of its entries, return null.
fileName
- .classpath
- .protected static void grabFilesAndDirs(java.lang.String file, java.util.List<java.lang.String> dirs, java.util.List<java.lang.String> files) throws java.io.IOException
file
- .files
- .dirs
- .java.io.IOException
- .