Class Jar
- All Implemented Interfaces:
Cloneable, SelectorContainer
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThe manifest config enumerated type.static classThe strict enumerated type.Nested classes/interfaces inherited from class Zip
Zip.ArchiveState, Zip.Duplicate, Zip.UnicodeExtraField, Zip.WhenEmpty, Zip.Zip64ModeAttributeModifier and TypeClassDescriptionstatic classHolds the up-to-date status and the out-of-date resources of the original archive.static classPossible behaviors when a duplicate file is added: "add", "preserve" or "fail"static final classPolicy for creation of Unicode extra fields: never, always or not-encodeable.static classPossible behaviors when there are no matching files for the task: "fail", "skip", or "create".static final classThe choices for Zip64 extensions. -
Field Summary
Fields inherited from class Zip
addedDirs, archiveType, doubleFilePass, duplicate, emptyBehavior, entries, skipWriting, zipFileModifier and TypeFieldDescriptionprotected Stringprotected booleanIf this flag is true, execute() will run most operations twice, the first time withskipWritingset to true and the second time with setting it to false.protected Stringprotected Stringprotected booleanwhether the methods should just perform some sort of dry-run.protected FileFields inherited from class MatchingTask
filesetFields inherited from class ProjectComponent
description, location, project -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a path to index jars.voidaddConfiguredIndexJarsMapper(Mapper mapper) Add a mapper used to convert the jars to entries in the index.voidaddConfiguredManifest(Manifest newManifest) Allows the manifest for the archive file to be provided inline in the build file rather than in an external file.voidaddConfiguredService(Service service) A nested SPI service element.voidaddMetainf(ZipFileSet fs) Adds a zipfileset to include in the META-INF directory.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 jar file.protected voidFinalize the zip output stream.protected static StringfindJarName(String fileName, String[] classpath) try to guess the name of the given file.Returns the mapper used to convert the jars to entries in the index.protected Zip.ArchiveStategetResourcesToAdd(ResourceCollection[] rcs, File zipFile, boolean needsUpdate) Collect the resources that are newer than the corresponding entries (or missing) in the original archive.protected static voidGrab lists of all root-level files and all directories contained in the given archive.protected voidInitialize the zip output stream.voidreset()reset to default values.voidBehavior when a Manifest is found in a zipfileset or zipgroupfileset file.voidsetFlattenAttributes(boolean b) Whether to flatten multi-valued attributes (i.e.voidsetIndex(boolean flag) Set whether or not to create an index list for classes.voidsetIndexMetaInf(boolean flag) Set whether or not to add META-INF and its children to the index.voidsetJarfile(File jarFile) Deprecated.since 1.5.x.voidsetManifest(File manifestFile) The manifest file to use.voidsetManifestEncoding(String manifestEncoding) The character encoding to use in the manifest file.voidsetMergeClassPathAttributes(boolean b) Whether to merge Class-Path attributes.voidsetStrict(Jar.StrictMode strict) Activate the strict mode.voidNot used for jar files.voidIndicates if a jar file should be created when it would only contain a manifest file.protected final voidwriteIndexLikeList(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 voidzipFile(InputStream is, ZipOutputStream zOut, String vPath, long lastModified, File fromArchive, int mode) Overridden from Zip class to deal with manifests and index lists.Methods inherited from class Zip
add, addFileset, addParentDirs, addResources, addResources, addZipfileset, addZipGroupFileset, execute, executeMain, getComment, getCreateUnicodeExtraFields, getCurrentExtraFields, getDestFile, getEncoding, getFallBackToUTF8, getLevel, getModificationtime, getNonFileSetResourcesToAdd, getPreserve0Permissions, getResourcesToAdd, getUseLanguageEnodingFlag, getZip64Mode, grabNonFileSetResources, grabResources, hasUpdatedFile, isAddingNewFiles, isCompress, isEmpty, isFirstPass, isInUpdateMode, logWhenWriting, selectDirectoryResources, selectFileResources, selectResources, setBasedir, setComment, setCompress, setCreateUnicodeExtraFields, setCurrentExtraFields, setDestFile, setDuplicate, setEncoding, setFallBackToUTF8, setFile, setFilesonly, setKeepCompression, setLevel, setModificationtime, setPreserve0Permissions, setRoundUp, setUpdate, setUseLanguageEncodingFlag, setZip64Mode, setZipfile, zipDir, zipDir, zipDir, zipFile, zipFileModifier and TypeMethodDescriptionvoidAdd a collection of resources to be archived.voidaddFileset(FileSet set) Adds a set of files.protected final voidaddParentDirs(File baseDir, String entry, ZipOutputStream zOut, String prefix, int dirMode) Ensure all parent dirs of a given entry have been added.protected final voidaddResources(FileSet fileset, Resource[] resources, ZipOutputStream zOut) Add the given resources.protected final voidaddResources(ResourceCollection rc, Resource[] resources, ZipOutputStream zOut) Add the given resources.voidaddZipfileset(ZipFileSet set) Adds a set of files that can be read from an archive and be given a prefix/fullpath.voidAdds a group of zip files.voidexecute()validate and buildvoidBuild the zip file.Comment of the archiveWhether Unicode extra fields will be created.protected final ZipExtraField[]Provides the extra fields for the zip entry currently being added to the archive - if any.The file to create.Encoding to use for filenames.booleanWhether to fall back to UTF-8 if a name cannot be encoded using the specified encoding.intgetLevel()Get the compression level.The file modification time previously provided toZip.setModificationtime(String)ornullif unset.protected Zip.ArchiveStategetNonFileSetResourcesToAdd(ResourceCollection[] rcs, File zipFile, boolean needsUpdate) Collect the resources that are newer than the corresponding entries (or missing) in the original archive.booleanAssume 0 Unix mode is intentional.protected Zip.ArchiveStategetResourcesToAdd(FileSet[] filesets, File zipFile, boolean needsUpdate) Collect the resources that are newer than the corresponding entries (or missing) in the original archive.booleanWhether the language encoding flag will be used.Whether Zip64 extensions will be used.protected Resource[][]Fetch all included and not excluded resources from the collections.protected Resource[][]grabResources(FileSet[] filesets) Fetch all included and not excluded resources from the sets.protected booleanGet the value of the updatedFile attribute.protected final booleanIndicates if the task is adding new files into the archive as opposed to copying back unchanged files from the backup copybooleanWhether we want to compress the files or only store them;protected static final booleanCheck is the resource arrays are empty.protected final booleanWhether this is the first time the archive building methods are invoked.booleanAre we updating an existing archive?protected voidlogWhenWriting(String msg, int level) Logs a message at the given output level, but only if this is the pass that will actually create the archive.protected Resource[]selectDirectoryResources(Resource[] orig) Drops all non-directory resources from the given array.protected Resource[]selectFileResources(Resource[] orig) Drops all non-file resources from the given array.protected Resource[]selectResources(Resource[] orig, ResourceSelector selector) Drops all resources from the given array that are not selectedvoidsetBasedir(File baseDir) Directory from which to archive files; optional.voidsetComment(String comment) Comment to use for archive.voidsetCompress(boolean c) Whether we want to compress the files or only store them; optional, default=true;voidWhether Unicode extra fields will be created.protected final voidsetCurrentExtraFields(ZipExtraField[] extra) Sets the extra fields for the zip entry currently being added to the archive - if any.voidsetDestFile(File destFile) The file to create; required.voidSets behavior for when a duplicate file is about to be added - one ofadd,preserveorfail.voidsetEncoding(String encoding) Encoding to use for filenames, defaults to the platform's default encoding.voidsetFallBackToUTF8(boolean b) Whether to fall back to UTF-8 if a name cannot be encoded using the specified encoding.voidDeprecated.since 1.5.x.voidsetFilesonly(boolean f) If true, emulate Sun's jar utility by not adding parent directories; optional, defaults to false.voidsetKeepCompression(boolean keep) Whether the original compression of entries coming from a ZIP archive should be kept (for example when updating an archive).voidsetLevel(int level) Set the compression level to use.voidsetModificationtime(String time) Set all stored file modification times totime.voidsetPreserve0Permissions(boolean b) Assume 0 Unix mode is intentional.voidsetRoundUp(boolean r) Whether the file modification times will be rounded up to the next even number of seconds.voidsetUpdate(boolean c) If true, updates an existing file, otherwise overwrite any existing one; optional defaults to false.voidsetUseLanguageEncodingFlag(boolean b) Whether to set the language encoding flag.voidWhether Zip64 extensions should be used.voidsetZipfile(File zipFile) Deprecated.since 1.5.x.protected voidzipDir(File dir, ZipOutputStream zOut, String vPath, int mode) Add a directory to the zip stream.protected voidzipDir(File dir, ZipOutputStream zOut, String vPath, int mode, ZipExtraField[] extra) Add a directory to the zip stream.protected voidzipDir(Resource dir, ZipOutputStream zOut, String vPath, int mode, ZipExtraField[] extra) Add a directory to the zip stream.protected voidzipFile(File file, ZipOutputStream zOut, String vPath, int mode) Method that gets called when adding fromjava.io.Fileinstances.protected final voidzipFile(InputStream in, ZipOutputStream zOut, String vPath, long lastModified, File fromArchive, int mode, ZipExtraField[] extra) Adds a new entry to the archive, takes care of duplicates as well.Methods inherited from class MatchingTask
add, addAnd, addContains, addContainsRegexp, addCustom, addDate, addDepend, addDepth, addDifferent, addFilename, addMajority, addModified, addNone, addNot, addOr, addPresent, addSelector, addSize, addType, appendSelector, createExclude, createExcludesFile, createInclude, createIncludesFile, createPatternSet, getDirectoryScanner, getImplicitFileSet, getSelectors, hasSelectors, selectorCount, selectorElements, setCaseSensitive, setDefaultexcludes, setExcludes, setExcludesfile, setFollowSymlinks, setIncludes, setIncludesfile, setProject, XsetIgnore, XsetItemsModifier and TypeMethodDescriptionvoidadd(FileSelector selector) add an arbitrary selectorvoidaddAnd(AndSelector selector) add an "And" selector entry on the selector listvoidaddContains(ContainsSelector selector) add a contains selector entry on the selector listvoidaddContainsRegexp(ContainsRegexpSelector selector) add a regular expression selector entry on the selector listvoidaddCustom(ExtendSelector selector) add an extended selector entry on the selector listvoidaddDate(DateSelector selector) add a selector date entry on the selector listvoidaddDepend(DependSelector selector) add a depends selector entry on the selector listvoidaddDepth(DepthSelector selector) add a depth selector entry on the selector listvoidaddDifferent(DifferentSelector selector) add a type selector entry on the type listvoidaddFilename(FilenameSelector selector) add a selector filename entry on the selector listvoidaddMajority(MajoritySelector selector) add a majority selector entry on the selector listvoidaddModified(ModifiedSelector selector) add the modified selectorvoidaddNone(NoneSelector selector) add a "None" selector entry on the selector listvoidaddNot(NotSelector selector) add a "Not" selector entry on the selector listvoidaddOr(OrSelector selector) add an "Or" selector entry on the selector listvoidaddPresent(PresentSelector selector) add a present selector entry on the selector listvoidaddSelector(SelectSelector selector) add a "Select" selector entry on the selector listvoidaddSize(SizeSelector selector) add a selector size entry on the selector listvoidaddType(TypeSelector selector) add a type selector entry on the type listvoidappendSelector(FileSelector selector) Add a new selector into this container.add a name entry on the exclude listadd a name entry on the include files listadd a name entry on the include listadd a name entry on the include files listadd a set of patternsprotected DirectoryScannergetDirectoryScanner(File baseDir) Returns the directory scanner needed to access the files to process.protected final FileSetAccessor for the implicit fileset.Returns the set of selectors as an array.booleanIndicates whether there are any selectors here.intGives the count of the number of selectors in this containerReturns an enumerator for accessing the set of selectors.voidsetCaseSensitive(boolean isCaseSensitive) Sets case sensitivity of the file systemvoidsetDefaultexcludes(boolean useDefaultExcludes) Sets whether default exclusions should be used or not.voidsetExcludes(String excludes) Sets the set of exclude patterns.voidsetExcludesfile(File excludesfile) Sets the name of the file containing the includes patterns.voidsetFollowSymlinks(boolean followSymlinks) Sets whether or not symbolic links or Windows junctions should be followed.voidsetIncludes(String includes) Sets the set of include patterns.voidsetIncludesfile(File includesfile) Sets the name of the file containing the includes patterns.voidsetProject(Project project) Sets the project object of this component.voidXsetIgnore(String ignoreString) List of filenames and directory names to not include.voidSet this to be the items in the base directory that you want to be included.Methods inherited from class Task
bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskTypeModifier and TypeMethodDescriptionfinal voidbindToOwner(Task owner) Bind a task to another; use this when configuring a newly created task to do work on behalf of another.Returns the container target of this task.Returns the wrapper used for runtime configuration.Returns the name to use in logging messages.Return the type of task.protected RuntimeConfigurableReturn the runtime configurable structure for this task.protected voidhandleErrorFlush(String output) Handles an error line by logging it with the WARN priority.protected voidhandleErrorOutput(String output) Handles an error output by logging it with the WARN priority.protected voidhandleFlush(String output) Handles output by logging it with the INFO priority.protected inthandleInput(byte[] buffer, int offset, int length) Handle an input request by this task.protected voidhandleOutput(String output) Handles output by logging it with the INFO priority.voidinit()Called by the project to let the task initialize properly.protected final booleanHas this task been marked invalid?voidLogs a message with the default (INFO) priority.voidLogs a message with the given priority.voidLogs a message with the given priority.voidLogs a message with the given priority.voidConfigures this task - if it hasn't been done already.final voidperform()Performs this task if it's still valid, or gets a replacement version and performs that otherwise.voidForce the task to be reconfigured from its RuntimeConfigurable.voidsetOwningTarget(Target target) Sets the target container of this task.voidSets the wrapper to be used for runtime configuration.voidsetTaskName(String name) Sets the name to use in logging messages.voidsetTaskType(String type) Sets the name with which the task has been invoked.Methods inherited from class ProjectComponent
clone, getDescription, getLocation, getProject, setDescription, setLocationModifier and TypeMethodDescriptionclone()Returns the description of the current action.Returns the file/location where this task was defined.Returns the project to which this component belongs.voidsetDescription(String desc) Sets a description of the current action.voidsetLocation(Location location) Sets the file/location where this task was defined.
-
Constructor Details
-
Jar
public Jar()constructor
-
-
Method Details
-
setWhenempty
Not used for jar files.- Overrides:
setWhenemptyin classZip- Parameters:
we- not used
-
setWhenmanifestonly
Indicates if a jar file should be created when it would only contain a manifest file. Possible values are:fail(throw an exception and halt the build);skip(do not create any archive, but issue a warning);create(make an archive with only a manifest file). Default iscreate;- Parameters:
we- aWhenEmptyenumerated value
-
setStrict
Activate the strict mode. When set to true a BuildException will be thrown if the Jar-Packaging specification was broken.- Parameters:
strict- New value of the strict mode.- Since:
- Ant 1.7.1
-
setJarfile
Deprecated.since 1.5.x. Use setDestFile(File) instead.Set the destination file.- Parameters:
jarFile- the destination file
-
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- abooleanvalue
-
setIndexMetaInf
public void setIndexMetaInf(boolean flag) Set whether or not to add META-INF and its children to the index.Doesn't have any effect if index is false.
Sun's jar implementation used to skip the META-INF directory and Ant followed that example. The behavior has been changed with Java 5. In order to avoid problems with Ant generated jars on Java 1.4 or earlier Ant will not include META-INF unless explicitly asked to.
- Parameters:
flag- abooleanvalue, defaults to false- Since:
- Ant 1.8.0
- See Also:
-
setManifestEncoding
The character encoding to use in the manifest file.- Parameters:
manifestEncoding- the character encoding
-
addConfiguredManifest
Allows the manifest for the archive file to be provided inline in the build file rather than in an external file.- Parameters:
newManifest- an embedded manifest element- Throws:
ManifestException- on error
-
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.
-
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.
-
addMetainf
Adds a zipfileset to include in the META-INF directory.- Parameters:
fs- zipfileset to add
-
addConfiguredIndexJars
Add a path to index jars.- Parameters:
p- a path- Since:
- Ant 1.6.2
-
addConfiguredIndexJarsMapper
Add a mapper used to convert the jars to entries in the index.- Parameters:
mapper- a mapper- Since:
- Ant 1.10.9
-
getIndexJarsMapper
Returns the mapper used to convert the jars to entries in the index. May be null.- Since:
- Ant 1.10.9
-
addConfiguredService
A nested SPI service element.- Parameters:
service- the nested element.- Since:
- Ant 1.7
-
setMergeClassPathAttributes
public void setMergeClassPathAttributes(boolean b) Whether to merge Class-Path attributes.- Parameters:
b- boolean- Since:
- Ant 1.8.0
-
setFlattenAttributes
public void setFlattenAttributes(boolean b) Whether to flatten multi-valued attributes (i.e. Class-Path) into a single one.- Parameters:
b- boolean- Since:
- Ant 1.8.0
-
initZipOutputStream
Initialize the zip output stream.- Overrides:
initZipOutputStreamin classZip- Parameters:
zOut- the zip output stream- Throws:
IOException- on I/O errorsBuildException- on other errors
-
finalizeZipOutputStream
Finalize the zip output stream. This creates an index list if the index attribute is true.- Overrides:
finalizeZipOutputStreamin classZip- Parameters:
zOut- the zip output stream- Throws:
IOException- on I/O errorsBuildException- on other errors
-
zipFile
protected void zipFile(InputStream is, ZipOutputStream zOut, String vPath, long lastModified, File fromArchive, int mode) throws IOException Overridden from Zip class to deal with manifests and index lists.- Overrides:
zipFilein classZip- Parameters:
is- the stream to read data for the entry from. The caller of the method is responsible for closing the stream.zOut- the zip output streamvPath- the name this entry shall have in the archivelastModified- last modification time for the entry.fromArchive- the original archive we are copying this entry from, will be null if we are not copying from an archive.mode- the Unix permissions to set.- Throws:
IOException- on error
-
getResourcesToAdd
protected Zip.ArchiveState getResourcesToAdd(ResourceCollection[] rcs, File zipFile, boolean needsUpdate) throws BuildException Collect the resources that are newer than the corresponding entries (or missing) in the original archive.If we are going to recreate the archive instead of updating it, all resources should be considered as new, if a single one is. Because of this, subclasses overriding this method must call
super.getResourcesToAddand indicate with the third arg if they already know that the archive is out-of-date.- Overrides:
getResourcesToAddin classZip- Parameters:
rcs- The resource collections to grab resources fromzipFile- intended archive file (may or may not exist)needsUpdate- whether we already know that the archive is out-of-date. Subclasses overriding this method are supposed to set this value correctly in their call to super.getResourcesToAdd.- Returns:
- an array of resources to add for each fileset passed in as well as a flag that indicates whether the archive is uptodate.
- Throws:
BuildException- if it likes
-
createEmptyZip
Create an empty jar file.- Overrides:
createEmptyZipin classZip- Parameters:
zipFile- the file to create- Returns:
- true for historic reasons
- Throws:
BuildException- on error
-
cleanUp
-
reset
-
writeIndexLikeList
Writes the directory entries from the first and the filenames from the second list to the given writer, one entry per line.- Parameters:
dirs- a list of directoriesfiles- a list of fileswriter- the writer to write to- Since:
- Ant 1.6.2
-
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- the name to look forclasspath- the classpath to look in (may be null)- Returns:
- the matching entry, or null if the file is not found
- Since:
- Ant 1.6.2
-
grabFilesAndDirs
protected static 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- the zip file to examinedirs- where to place the directories foundfiles- where to place the files found- Throws:
IOException- on error- Since:
- Ant 1.7
-