Class Jar
java.lang.Object
aQute.bnd.osgi.Jar
- All Implemented Interfaces:
Closeable, AutoCloseable
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleanaddAll(Jar sub, Instruction filter) Add all the resources in the given jar that match the given filter.booleanaddAll(Jar sub, Instruction filter, String destination) Add all the resources in the given jar that match the given filter.booleanaddDirectory(Map<String, Resource> directory, boolean overwrite) voidcalcChecksums(String[] algorithms) Calculate the checksums and set them in the manifest.voidclose()voidvoiddoChecksums(OutputStream out) voidMake sure we have a manifestbooleanvoidExpand the JAR file to a directory.static JarfromResource(String name, Resource resource) getBsn()Get the jar bsn from theConstants.BUNDLE_SYMBOLICNAMEmanifest header.getDataURI(String path, String mime, int max) Return a data uri from the JAR.getDirectory(String path) intGet the length of the last written file or -1 if unavailable.getName()getResource(String path) getResourceNames(Predicate<String> matches) getResources(Resource jarResource, Predicate<String> filter) getResources(Predicate<String> matches) Optional<byte[]> Get the SHA256 digest of the last write operation whensetCalculateFileDigest(boolean)was on.byte[]Get the jar version from theConstants.BUNDLE_VERSIONmanifest header.booleanhasDirectory(String path) booleanisEmpty()booleanAnswer if the manifest was the first entrybooleanlongstatic voidoutputManifest(Manifest manifest, OutputStream out) Main function to output a manifest properly in UTF-8.booleanputResource(String path, Resource resource) booleanputResource(String path, Resource resource, boolean overwrite) voidremovePrefix(String prefixLow) voidremoveSubDirs(String dir) booleansetCalculateFileDigest(boolean onOrOff) Make this jar calculate the SHA256 when it is saved as a file.voidsetCompression(Jar.Compression compression) voidsetDigestAlgorithms(String[] algorithms) voidMake sure nobody touches the manifest! If the bundle is signed, we do not want anybody to touch the manifest after the digests have been calculated.voidsetManifest(File file) voidsetManifest(Manifest manifest) voidsetManifestName(String manifestName) voidvoidsetReproducible(boolean reproducible) Deprecated.voidsetReproducible(String outputTimestamp) voidvoidtoString()voidupdateModified(long time, String reason) voidvoidwrite(OutputStream to) voidvoidwriteFolder(File dir) voidCleanup the manifest for writing.static voidwriteManifest(Manifest manifest, OutputStream out)
-
Field Details
-
EMPTY_ARRAY
-
METAINF_SIGNING_P
-
-
Constructor Details
-
Jar
-
Jar
- Throws:
IOException
-
Jar
- Throws:
IOException
-
Jar
- Throws:
IOException
-
Jar
- Throws:
IOException
-
Jar
- Throws:
IOException
-
Jar
- Throws:
IOException
-
-
Method Details
-
fromResource
-
getResources
-
setName
-
toString
-
putResource
-
putResource
-
getResource
-
getResourceNames
-
getResources
-
getDirectories
-
getDirectory
-
getResources
-
addDirectory
-
getManifest
-
getModuleName
-
getModuleVersion
-
exists
-
isEmpty
public boolean isEmpty() -
setManifest
-
setManifest
- Throws:
IOException
-
getManifestName
-
setManifestName
-
write
-
write
-
write
- Throws:
Exception
-
writeFolder
-
doChecksums
- Throws:
Exception
-
writeManifest
Cleanup the manifest for writing. Cleaning up consists of adding a space after any \n to prevent the manifest to see this newline as a delimiter.- Parameters:
out- Output- Throws:
IOExceptionException
-
writeManifest
- Throws:
IOException
-
outputManifest
Main function to output a manifest properly in UTF-8.- Parameters:
manifest- The manifest to outputout- The output stream- Throws:
IOException- when something fails
-
getName
-
addAll
Add all the resources in the given jar that match the given filter.- Parameters:
sub- the jarfilter- a pattern that should match the resoures in sub to be added
-
addAll
Add all the resources in the given jar that match the given filter.- Parameters:
sub- the jarfilter- a pattern that should match the resoures in sub to be added
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
lastModified
public long lastModified() -
updateModified
-
hasDirectory
-
getPackages
-
getSource
-
setSource
-
addAll
-
rename
-
remove
-
setDoNotTouchManifest
public void setDoNotTouchManifest()Make sure nobody touches the manifest! If the bundle is signed, we do not want anybody to touch the manifest after the digests have been calculated. -
calcChecksums
-
getBsn
Get the jar bsn from theConstants.BUNDLE_SYMBOLICNAMEmanifest header.- Returns:
- null when the jar has no manifest, when the manifest has no
Constants.BUNDLE_SYMBOLICNAMEheader, or when the value of the header is not a valid bsn according toBSN. - Throws:
Exception- when the jar is closed or when the manifest could not be retrieved.
-
getVersion
Get the jar version from theConstants.BUNDLE_VERSIONmanifest header.- Returns:
- null when the jar has no manifest or when the manifest has no
Constants.BUNDLE_VERSIONheader - Throws:
Exception- when the jar is closed or when the manifest could not be retrieved.
-
expand
-
ensureManifest
-
isManifestFirst
public boolean isManifestFirst()Answer if the manifest was the first entry -
isReproducible
public boolean isReproducible() -
setReproducible
-
setReproducible
Deprecated.Replaced bysetReproducible(String). -
copy
-
setCompression
-
hasCompression
-
getDataURI
-
setDigestAlgorithms
-
getTimelessDigest
-
stripSignatures
public void stripSignatures() -
removePrefix
-
removeSubDirs
-
getPomXmlResources
-
setCalculateFileDigest
Make this jar calculate the SHA256 when it is saved as a file. When this JAR is written, the digest is always cleared. If this flag is on, it will be calculated and set when the file is successfully saved.- Parameters:
onOrOff- state of calculating the digest when writing this jar. true is on, otherwise off
-
getSHA256
Get the SHA256 digest of the last write operation whensetCalculateFileDigest(boolean)was on.- Returns:
- the SHA 256 digest or empty
-
getLength
public int getLength()Get the length of the last written file or -1 if unavailable. The length is only calculated when the checksum calculation was on during the write.- Returns:
- the length of the last written file or -1 if unavailable.
-
setReproducible(String).