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
@Named("jar") public class JarArchiver extends ZipArchiver
Base class for tasks that build archives in JAR file format.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
JarArchiver.FilesetManifestConfig
-
Field Summary
-
Fields inherited from class org.codehaus.plexus.archiver.zip.AbstractZipArchiver
addedDirs, addingNewFiles, archiveType, doubleFilePass, duplicate, entries, skipWriting, zipArchiveOutputStream
-
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 JarArchiver()
constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addConfiguredIndexJars(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(File zipFile)
Create an empty zip fileprotected Manifest
createManifest()
Creates the manifest to be added to the JAR archive.protected void
finalizeZipOutputStream(ConcurrentJarCreator zOut)
protected static String
findJarName(String fileName, String[] classpath)
try to guess the name of the given file.protected boolean
hasVirtualFiles()
protected void
initZipOutputStream(ConcurrentJarCreator zOut)
method for subclasses to overridevoid
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(File manifestFile)
The manifest file to use.void
setManifestEncoding(String manifestEncoding)
Deprecated.void
setMinimalDefaultManifest(boolean minimalDefaultManifest)
Set whether the default manifest is minimal, thus having onlyManifest-Version: 1.0
in it.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.protected void
writeIndexLikeList(List<String> dirs, List<String> files, PrintWriter writer)
Writes the directory entries from the first and the filenames from the second list to the given writer, one entry per line.protected void
zipFile(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, zipFile
-
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, isForced, isIgnorePermissions, isUptodate, isUseJvmChmod, postCreateArchive, runArchiveFinalizers, setArchiveFinalizers, setDefaultDirectoryMode, setDefaultFileMode, setDestFile, setDirectoryMode, setDotFileDirectory, setDuplicateBehavior, setFileMode, setFilenameComparator, setForced, setIgnorePermissions, setIncludeEmptyDirs, setLastModifiedDate, setLastModifiedTime, setOverrideGid, setOverrideGroupName, setOverrideUid, setOverrideUserName, setUseJvmChmod, validate
-
-
-
-
Method Detail
-
setIndex
public void setIndex(boolean flag)
Set 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.0
in it.- Parameters:
minimalDefaultManifest
- true to create minimal default manifest
-
setManifestEncoding
@Deprecated public void setManifestEncoding(String manifestEncoding)
Deprecated.
-
addConfiguredManifest
public void addConfiguredManifest(Manifest newManifest) throws ManifestException
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
public void setManifest(File manifestFile) throws ArchiverException
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
-
setFilesetmanifest
public void setFilesetmanifest(JarArchiver.FilesetManifestConfig config)
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
public void addConfiguredIndexJars(File indexJar)
- Parameters:
indexJar
- The indexjar
-
initZipOutputStream
protected void initZipOutputStream(ConcurrentJarCreator zOut) throws ArchiverException, IOException
Description copied from class:AbstractZipArchiver
method for subclasses to override- Overrides:
initZipOutputStream
in classAbstractZipArchiver
- Parameters:
zOut
- The output stream- Throws:
ArchiverException
IOException
-
hasVirtualFiles
protected boolean hasVirtualFiles()
- Overrides:
hasVirtualFiles
in classAbstractArchiver
-
createManifest
protected Manifest createManifest() throws ArchiverException
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
-
finalizeZipOutputStream
protected void finalizeZipOutputStream(ConcurrentJarCreator zOut) throws IOException, ArchiverException
- Overrides:
finalizeZipOutputStream
in classAbstractZipArchiver
- Throws:
IOException
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:
zipFile
in 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 thisaddInParallel
- Indicates if the entry should be add in parallel. If set tofalse
it is added synchronously. If the entry is symbolic link this parameter is ignored.- Throws:
IOException
ArchiverException
-
createEmptyZip
protected boolean createEmptyZip(File zipFile) throws ArchiverException
Description copied from class:AbstractZipArchiver
Create an empty zip file- Overrides:
createEmptyZip
in classAbstractZipArchiver
- Parameters:
zipFile
- The file- Returns:
- true for historic reasons
- Throws:
ArchiverException
-
cleanUp
protected void cleanUp() throws IOException
Make sure we don't think we already have a MANIFEST next time this task gets executed.- Overrides:
cleanUp
in classAbstractZipArchiver
- Throws:
IOException
- See Also:
AbstractZipArchiver.cleanUp()
-
reset
public void reset()
reset to default values.- Overrides:
reset
in classAbstractZipArchiver
- See Also:
AbstractZipArchiver.reset()
-
writeIndexLikeList
protected final void writeIndexLikeList(List<String> dirs, List<String> files, PrintWriter writer)
Writes 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
protected static String findJarName(String fileName, String[] classpath)
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
-
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:
setZipEntryTime
in classAbstractZipArchiver
- Parameters:
zipEntry
- to set the last modified timelastModifiedTime
- to set in the zip entry only ifAbstractArchiver.getLastModifiedTime()
returns null
-
-