Package aQute.bnd.osgi
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 TypeMethodDescriptionboolean
boolean
addAll
(Jar sub, Instruction filter) Add all the resources in the given jar that match the given filter.boolean
addAll
(Jar sub, Instruction filter, String destination) Add all the resources in the given jar that match the given filter.boolean
addDirectory
(Map<String, Resource> directory, boolean overwrite) void
calcChecksums
(String[] algorithms) Calculate the checksums and set them in the manifest.void
close()
void
void
doChecksums
(OutputStream out) void
Make sure we have a manifestboolean
void
Expand the JAR file to a directory.static Jar
fromResource
(String name, Resource resource) getBsn()
Get the jar bsn from theConstants.BUNDLE_SYMBOLICNAME
manifest header.getDataURI
(String path, String mime, int max) Return a data uri from the JAR.getDirectory
(String path) int
Get 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_VERSION
manifest header.boolean
hasDirectory
(String path) boolean
isEmpty()
boolean
Answer if the manifest was the first entryboolean
long
static void
outputManifest
(Manifest manifest, OutputStream out) Main function to output a manifest properly in UTF-8.boolean
putResource
(String path, Resource resource) boolean
putResource
(String path, Resource resource, boolean overwrite) void
removePrefix
(String prefixLow) void
removeSubDirs
(String dir) boolean
setCalculateFileDigest
(boolean onOrOff) Make this jar calculate the SHA256 when it is saved as a file.void
setCompression
(Jar.Compression compression) void
setDigestAlgorithms
(String[] algorithms) void
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.void
setManifest
(File file) void
setManifest
(Manifest manifest) void
setManifestName
(String manifestName) void
void
setReproducible
(boolean reproducible) Deprecated.void
setReproducible
(String outputTimestamp) void
void
toString()
void
updateModified
(long time, String reason) void
void
write
(OutputStream to) void
void
writeFolder
(File dir) void
Cleanup the manifest for writing.static void
writeManifest
(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
- Throws:
Exception
-
getResources
public static Stream<Resource> getResources(Resource jarResource, Predicate<String> filter) throws Exception - Throws:
Exception
-
setName
-
toString
-
putResource
-
putResource
-
getResource
-
getResourceNames
-
getResources
-
getDirectories
-
getDirectory
-
getResources
-
addDirectory
-
getManifest
- Throws:
Exception
-
getModuleName
- Throws:
Exception
-
getModuleVersion
- Throws:
Exception
-
exists
-
isEmpty
public boolean isEmpty() -
setManifest
-
setManifest
- Throws:
IOException
-
getManifestName
-
setManifestName
-
write
- Throws:
Exception
-
write
- Throws:
Exception
-
write
- Throws:
Exception
-
writeFolder
- Throws:
Exception
-
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:
IOException
Exception
-
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:
close
in interfaceAutoCloseable
- Specified by:
close
in 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
Calculate the checksums and set them in the manifest.- Throws:
Exception
-
getBsn
Get the jar bsn from theConstants.BUNDLE_SYMBOLICNAME
manifest header.- Returns:
- null when the jar has no manifest, when the manifest has no
Constants.BUNDLE_SYMBOLICNAME
header, 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_VERSION
manifest header.- Returns:
- null when the jar has no manifest or when the manifest has no
Constants.BUNDLE_VERSION
header - Throws:
Exception
- when the jar is closed or when the manifest could not be retrieved.
-
expand
Expand the JAR file to a directory.- Parameters:
dir
- the dst directory, is not required to exist- Throws:
Exception
- if anything does not work as expected.
-
ensureManifest
Make sure we have a manifest- Throws:
Exception
-
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
Return a data uri from the JAR. The data must be less than 32k- Parameters:
path
- the path in the jarmime
- the mime type- Returns:
- a URI or null if conversion could not take place
- Throws:
Exception
-
setDigestAlgorithms
-
getTimelessDigest
- Throws:
Exception
-
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)
.