Package org.codehaus.plexus.archiver.jar
Class JarArchiver
java.lang.Object
org.codehaus.plexus.archiver.AbstractArchiver
org.codehaus.plexus.archiver.zip.AbstractZipArchiver
org.codehaus.plexus.archiver.zip.ZipArchiver
org.codehaus.plexus.archiver.jar.JarArchiver
- All Implemented Interfaces:
Archiver,FinalizerEnabled
- Direct Known Subclasses:
EarArchiver,ModularJarArchiver,RarArchiver,WarArchiver
Base class for tasks that build archives in JAR file format.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Manifestmerged manifests added through addConfiguredManifestprivate booleanwhether to really create the archive in createEmptyZip, will get set in getResourcesToAdd.private Manifestmerged manifests added through filesetswhether to merge fileset manifests; value is true if filesetmanifest is 'merge' or 'mergewithoutmain'private booleanDeprecated.See JDK-8302819private static final StringDeprecated.See JDK-8302819Deprecated.See JDK-8302819private Manifestthe manifest specified by the 'manifest' attribute *private static final StringThe manifest file name.private FileThe file found from the 'manifest' attribute.private booleanwhether to merge the main section of fileset manifests; value is true if filesetmanifest is 'merge'private static final Stringthe name of the meta-inf dirprivate booleanCreates a minimal default manifest withManifest-Version: 1.0only.private ManifestManifest of original archive, will be set to null if not in update mode.Stores all files that are in the root of the archive (i.e.private Manifestshadow of the above if upToDate check alters the valueFields inherited from class org.codehaus.plexus.archiver.zip.AbstractZipArchiver
addedDirs, addingNewFiles, archiveType, doubleFilePass, duplicate, entries, skipWriting, zipArchiveOutputStreamFields 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 -
Method Summary
Modifier and TypeMethodDescriptionvoidaddConfiguredIndexJars(File indexJar) Deprecated.See JDK-8302819voidaddConfiguredManifest(Manifest newManifest) Allows the manifest for the archive file to be provided inline in the build file rather than in an external file.protected voidcleanUp()Make sure we don't think we already have a MANIFEST next time this task gets executed.protected booleancreateEmptyZip(File zipFile) Create an empty zip fileprivate voidDeprecated.See JDK-8302819protected ManifestCreates the manifest to be added to the JAR archive.private voidfilesetManifest(File file, InputStream is) protected voidprotected static StringfindJarName(String fileName, String[] classpath) try to guess the name of the given file.private ManifestgetManifest(File manifestFile) private Manifestprivate voidGrab lists of all root-level files and all directories contained in the given archive.protected booleanprotected voidmethod for subclasses to overridevoidreset()reset to default values.voidBehavior when a Manifest is found in a zipfileset or zipgroupfileset file.voidsetIndex(boolean flag) Deprecated.See JDK-8302819voidsetManifest(File manifestFile) The manifest file to use.voidsetManifestEncoding(String manifestEncoding) Deprecated.voidsetMinimalDefaultManifest(boolean minimalDefaultManifest) Set whether the default manifest is minimal, thus having onlyManifest-Version: 1.0in it.protected voidsetZipEntryTime(org.apache.commons.compress.archivers.zip.ZipArchiveEntry zipEntry, long lastModifiedTime) Override the behavior of the Zip Archiver to match the output of the JAR tool.protected final voidwriteIndexLikeList(List<String> dirs, List<String> files, PrintWriter writer) Deprecated.See JDK-8302819private voidwriteManifest(ConcurrentJarCreator zOut, Manifest manifest) protected voidzipFile(org.apache.commons.compress.parallel.InputStreamSupplier is, ConcurrentJarCreator zOut, String vPath, long lastModified, File fromArchive, int mode, String symlinkDestination, boolean addInParallel) Overridden from Zip class to deal with manifests and index lists.Methods inherited from class org.codehaus.plexus.archiver.zip.AbstractZipArchiver
addResources, close, execute, getArchiveType, getComment, getEncoding, isCompress, isFilesonly, isInUpdateMode, isRecompressAddedZips, isSupportingForced, normalizeLastModifiedTime, revert, setComment, setCompress, setEncoding, setFilesonly, setRecompressAddedZips, setUpdateMode, zipDir, zipFileMethods 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, 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 Details
-
META_INF_NAME
the name of the meta-inf dir- See Also:
-
INDEX_NAME
Deprecated.See JDK-8302819The index file name.- See Also:
-
MANIFEST_NAME
The manifest file name.- See Also:
-
configuredManifest
merged manifests added through addConfiguredManifest -
savedConfiguredManifest
shadow of the above if upToDate check alters the value -
filesetManifest
merged manifests added through filesets -
originalManifest
Manifest of original archive, will be set to null if not in update mode. -
filesetManifestConfig
whether to merge fileset manifests; value is true if filesetmanifest is 'merge' or 'mergewithoutmain' -
mergeManifestsMain
private boolean mergeManifestsMainwhether to merge the main section of fileset manifests; value is true if filesetmanifest is 'merge' -
manifest
the manifest specified by the 'manifest' attribute * -
manifestFile
The file found from the 'manifest' attribute. This can be either the location of a manifest, or the name of a jar added through a fileset. If its the name of an added jar, the manifest is looked for in META-INF/MANIFEST.MF -
index
Deprecated.See JDK-8302819jar index is JDK 1.3+ only -
createEmpty
private boolean createEmptywhether to really create the archive in createEmptyZip, will get set in getResourcesToAdd. -
rootEntries
Stores all files that are in the root of the archive (i.e. that have a name that doesn't contain a slash) so they can get listed in the index. Will not be filled unless the user has asked for an index. -
indexJars
Deprecated.See JDK-8302819Path containing jars that shall be indexed in addition to this archive. -
minimalDefaultManifest
private boolean minimalDefaultManifestCreates a minimal default manifest withManifest-Version: 1.0only.
-
-
Constructor Details
-
JarArchiver
public JarArchiver()constructor
-
-
Method Details
-
setIndex
Deprecated.See JDK-8302819Set whether or not to create an index list for classes. This may speed up classloading in some cases.- Parameters:
flag- true to create an index
-
setMinimalDefaultManifest
public void setMinimalDefaultManifest(boolean minimalDefaultManifest) Set whether the default manifest is minimal, thus having onlyManifest-Version: 1.0in it.- Parameters:
minimalDefaultManifest- true to create minimal default manifest
-
setManifestEncoding
Deprecated. -
addConfiguredManifest
Allows the manifest for the archive file to be provided inline in the build file rather than in an external file.- Parameters:
newManifest- The new manifest- Throws:
ManifestException
-
setManifest
The manifest file to use. This can be either the location of a manifest, or the name of a jar added through a fileset. If its the name of an added jar, the task expects the manifest to be in the jar at META-INF/MANIFEST.MF.- Parameters:
manifestFile- the manifest file to use.- Throws:
ArchiverException
-
getManifest
- Throws:
ArchiverException
-
getManifest
- Throws:
ArchiverException
-
setFilesetmanifest
Behavior when a Manifest is found in a zipfileset or zipgroupfileset file. Valid values are "skip", "merge", and "mergewithoutmain". "merge" will merge all of manifests together, and merge this into any other specified manifests. "mergewithoutmain" merges everything but the Main section of the manifests. Default value is "skip".Note: if this attribute's value is not "skip", the created jar will not be readable by using java.util.jar.JarInputStream
- Parameters:
config- setting for found manifest behavior.
-
addConfiguredIndexJars
Deprecated.See JDK-8302819- Parameters:
indexJar- The indexjar
-
initZipOutputStream
Description copied from class:AbstractZipArchivermethod for subclasses to override- Overrides:
initZipOutputStreamin classAbstractZipArchiver- Parameters:
zOut- The output stream- Throws:
ArchiverExceptionIOException
-
hasVirtualFiles
protected boolean hasVirtualFiles()- Overrides:
hasVirtualFilesin classAbstractArchiver
-
createManifest
Creates the manifest to be added to the JAR archive. Sub-classes may choose to override this method in order to inspect or modify the JAR manifest file.- Returns:
- the manifest for the JAR archive.
- Throws:
ArchiverException
-
writeManifest
private void writeManifest(ConcurrentJarCreator zOut, Manifest manifest) throws IOException, ArchiverException - Throws:
IOExceptionArchiverException
-
finalizeZipOutputStream
protected void finalizeZipOutputStream(ConcurrentJarCreator zOut) throws IOException, ArchiverException - Overrides:
finalizeZipOutputStreamin classAbstractZipArchiver- Throws:
IOExceptionArchiverException
-
createIndexList
@Deprecated private void createIndexList(ConcurrentJarCreator zOut) throws IOException, ArchiverException Deprecated.See JDK-8302819Create the index list to speed up classloading. This is a JDK 1.3+ specific feature and is enabled by default. See the JAR index specification for more details.- Parameters:
zOut- the zip stream representing the jar being built.- Throws:
IOException- thrown if there is an error while creating the index and adding it to the zip stream.ArchiverException
-
zipFile
protected void zipFile(org.apache.commons.compress.parallel.InputStreamSupplier is, ConcurrentJarCreator zOut, String vPath, long lastModified, File fromArchive, int mode, String symlinkDestination, boolean addInParallel) throws IOException, ArchiverException Overridden from Zip class to deal with manifests and index lists.- Overrides:
zipFilein classAbstractZipArchiver- Parameters:
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 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
-
filesetManifest
- Throws:
ArchiverException
-
createEmptyZip
Description copied from class:AbstractZipArchiverCreate an empty zip file- Overrides:
createEmptyZipin classAbstractZipArchiver- Parameters:
zipFile- The file- Returns:
- true for historic reasons
- Throws:
ArchiverException
-
cleanUp
Make sure we don't think we already have a MANIFEST next time this task gets executed.- Overrides:
cleanUpin classAbstractZipArchiver- Throws:
IOException- See Also:
-
reset
public void reset()reset to default values.- Overrides:
resetin classAbstractZipArchiver- See Also:
-
writeIndexLikeList
@Deprecated protected final void writeIndexLikeList(List<String> dirs, List<String> files, PrintWriter writer) Deprecated.See JDK-8302819Writes the directory entries from the first and the filenames from the second list to the given writer, one entry per line.- Parameters:
dirs- The directoriesfiles- The fileswriter- The printwriter ;)
-
findJarName
try to guess the name of the given file.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.
- Parameters:
fileName- .classpath- .- Returns:
- The guessed name
-
grabFilesAndDirs
private void grabFilesAndDirs(String file, List<String> dirs, List<String> files) throws IOException Grab lists of all root-level files and all directories contained in the given archive.- Parameters:
file- .dirs- .files- .- Throws:
IOException
-
setZipEntryTime
protected void setZipEntryTime(org.apache.commons.compress.archivers.zip.ZipArchiveEntry zipEntry, long lastModifiedTime) Override the behavior of the Zip Archiver to match the output of the JAR tool.- Overrides:
setZipEntryTimein classAbstractZipArchiver- Parameters:
zipEntry- to set the last modified timelastModifiedTime- to set in the zip entry only ifAbstractArchiver.getLastModifiedTime()returns null
-