Class JarUtil
- java.lang.Object
-
- com.jogamp.common.util.JarUtil
-
public class JarUtil extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
JarUtil.Resolver
Interface allowing users to provide an URL resolver that will convert custom classloader URLs like Eclipse/OSGi bundleresource: URLs to normal jar: URLs.
-
Constructor Summary
Constructors Constructor Description JarUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
extract(File dest, Map<String,String> nativeLibMap, JarFile jarFile, String nativeLibraryPath, boolean extractNativeLibraries, boolean extractClassFiles, boolean extractOtherFiles)
Extract the files of the given jar file.static Uri.Encoded
getJarBasename(Uri classJarUri)
The Class's Jar Urijar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class
Jar basenamegluegen-rt.jar
will be returned.static Uri.Encoded
getJarBasename(String clazzBinName, ClassLoader cl)
The Class'scom.jogamp.common.GlueGenVersion
Urijar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class
Jar basenamegluegen-rt.jar
will be returned.static Uri.Encoded
getJarEntry(Uri classJarUri)
The Class's Jar Urijar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class
Jar file's entry/com/jogamp/common/GlueGenVersion.class
will be returned.static Uri
getJarEntryUri(Uri jarFileUri, Uri.Encoded jarEntry)
static JarFile
getJarFile(Uri jarFileUri)
static JarFile
getJarFile(String clazzBinName, ClassLoader cl)
static Uri
getJarFileUri(Uri jarSubUri)
static Uri
getJarFileUri(Uri.Encoded jarSubUriS)
static Uri
getJarFileUri(Uri baseUri, Uri.Encoded jarFileName)
static Uri
getJarFileUri(String clazzBinName, ClassLoader cl)
The Class's"com.jogamp.common.GlueGenVersion"
Urijar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class"
Jar file Urijar:sub_protocol:/some/path/gluegen-rt.jar!/
will be returned.static Uri
getJarUri(String clazzBinName, ClassLoader cl)
The Class's"com.jogamp.common.GlueGenVersion"
Urijar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class"
will be returned.static Map<String,String>
getNativeLibNames(JarFile jarFile)
Return a map from native-lib-base-name to entry-name.static Uri
getRelativeOf(Class<?> classFromJavaJar, Uri.Encoded cutOffInclSubDir, Uri.Encoded relResPath)
Locates theJar file Uri
of a given resource relative to a given class's Jar's Uri.static boolean
hasJarUri(String clazzBinName, ClassLoader cl)
Returnstrue
if the Class's"com.jogamp.common.GlueGenVersion"
is loaded from a JarFile and hence has a Jar URI like URIjar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class"
.static void
setResolver(JarUtil.Resolver r)
Setting a customJarUtil.Resolver
instance.static void
validateCertificates(Certificate[] rootCerts, JarFile jarFile)
Validate the certificates for each native Lib in the jar file.
-
-
-
Method Detail
-
setResolver
public static void setResolver(JarUtil.Resolver r) throws IllegalArgumentException, IllegalStateException, SecurityException
Setting a customJarUtil.Resolver
instance.- Parameters:
r
-JarUtil.Resolver
to use after querying class file URLs from the classloader.- Throws:
IllegalArgumentException
- if the passed resolver isnull
IllegalStateException
- if the resolver has already been set.SecurityException
- if the security manager doesn't have the setFactory permission
-
hasJarUri
public static boolean hasJarUri(String clazzBinName, ClassLoader cl)
Returnstrue
if the Class's"com.jogamp.common.GlueGenVersion"
is loaded from a JarFile and hence has a Jar URI like URIjar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class"
.sub_protocol may be "file", "http", etc..
- Parameters:
clazzBinName
- "com.jogamp.common.GlueGenVersion"cl
-- Returns:
- true if the class is loaded from a Jar file, otherwise false.
-
getJarUri
public static Uri getJarUri(String clazzBinName, ClassLoader cl) throws IllegalArgumentException, IOException, URISyntaxException
The Class's"com.jogamp.common.GlueGenVersion"
Urijar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class"
will be returned.sub_protocol may be "file", "http", etc..
- Parameters:
clazzBinName
- "com.jogamp.common.GlueGenVersion"cl
- ClassLoader to locate the JarFile- Returns:
- "jar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class"
- Throws:
IllegalArgumentException
- if the Uri doesn't match the expected formatting or null argumentsIOException
- if the class's Jar file could not been found by the ClassLoaderURISyntaxException
- if the Uri could not be translated into a RFC 2396 Uri
-
getJarBasename
public static Uri.Encoded getJarBasename(Uri classJarUri) throws IllegalArgumentException
The Class's Jar Urijar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class
Jar basenamegluegen-rt.jar
will be returned.sub_protocol may be "file", "http", etc..
- Parameters:
classJarUri
- as retrieved w/getJarUri("com.jogamp.common.GlueGenVersion", cl)
, i.e.jar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class
- Returns:
gluegen-rt.jar
- Throws:
IllegalArgumentException
- if the Uri doesn't match the expected formatting or is null
-
getJarBasename
public static Uri.Encoded getJarBasename(String clazzBinName, ClassLoader cl) throws IllegalArgumentException, IOException, URISyntaxException
The Class'scom.jogamp.common.GlueGenVersion
Urijar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class
Jar basenamegluegen-rt.jar
will be returned.sub_protocol may be "file", "http", etc..
- Parameters:
clazzBinName
-com.jogamp.common.GlueGenVersion
cl
-- Returns:
gluegen-rt.jar
- Throws:
IllegalArgumentException
- if the Uri doesn't match the expected formattingIOException
- if the class's Jar file could not been found by the ClassLoader.URISyntaxException
- if the Uri could not be translated into a RFC 2396 Uri
-
getJarEntry
public static Uri.Encoded getJarEntry(Uri classJarUri)
The Class's Jar Urijar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class
Jar file's entry/com/jogamp/common/GlueGenVersion.class
will be returned.- Parameters:
classJarUri
- as retrieved w/getJarUri("com.jogamp.common.GlueGenVersion", cl)
, i.e.jar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class
- Returns:
/com/jogamp/common/GlueGenVersion.class
-
getJarFileUri
public static Uri getJarFileUri(String clazzBinName, ClassLoader cl) throws IllegalArgumentException, IOException, URISyntaxException
The Class's"com.jogamp.common.GlueGenVersion"
Urijar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class"
Jar file Urijar:sub_protocol:/some/path/gluegen-rt.jar!/
will be returned.sub_protocol may be "file", "http", etc..
- Parameters:
clazzBinName
- "com.jogamp.common.GlueGenVersion"cl
-- Returns:
- "jar:sub_protocol:/some/path/gluegen-rt.jar!/"
- Throws:
IllegalArgumentException
- if the Uri doesn't match the expected formatting or null argumentsIOException
- if the class's Jar file could not been found by the ClassLoaderURISyntaxException
- if the Uri could not be translated into a RFC 2396 Uri
-
getJarFileUri
public static Uri getJarFileUri(Uri baseUri, Uri.Encoded jarFileName) throws IllegalArgumentException, URISyntaxException
- Parameters:
baseUri
- file:/some/path/jarFileName
- gluegen-rt.jar (Uri encoded)- Returns:
- jar:file:/some/path/gluegen-rt.jar!/
- Throws:
URISyntaxException
IllegalArgumentException
- null arguments
-
getJarFileUri
public static Uri getJarFileUri(Uri jarSubUri) throws IllegalArgumentException, URISyntaxException
- Parameters:
jarSubUri
- file:/some/path/gluegen-rt.jar- Returns:
- jar:file:/some/path/gluegen-rt.jar!/
- Throws:
IllegalArgumentException
- null argumentsURISyntaxException
-
getJarFileUri
public static Uri getJarFileUri(Uri.Encoded jarSubUriS) throws IllegalArgumentException, URISyntaxException
- Parameters:
jarSubUriS
- file:/some/path/gluegen-rt.jar (Uri encoded)- Returns:
- jar:file:/some/path/gluegen-rt.jar!/
- Throws:
IllegalArgumentException
- null argumentsURISyntaxException
-
getJarEntryUri
public static Uri getJarEntryUri(Uri jarFileUri, Uri.Encoded jarEntry) throws IllegalArgumentException, URISyntaxException
- Parameters:
jarFileUri
- jar:file:/some/path/gluegen-rt.jar!/jarEntry
- com/jogamp/common/GlueGenVersion.class- Returns:
- jar:file:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class
- Throws:
IllegalArgumentException
- null argumentsURISyntaxException
-
getJarFile
public static JarFile getJarFile(String clazzBinName, ClassLoader cl) throws IOException, IllegalArgumentException, URISyntaxException
- Parameters:
clazzBinName
- com.jogamp.common.util.cache.TempJarCachecl
- domain- Returns:
- JarFile containing the named class within the given ClassLoader
- Throws:
IOException
- if the class's Jar file could not been found by the ClassLoaderIllegalArgumentException
- null argumentsURISyntaxException
- if the Uri could not be translated into a RFC 2396 Uri
-
getJarFile
public static JarFile getJarFile(Uri jarFileUri) throws IOException, IllegalArgumentException, URISyntaxException
- Parameters:
jarFileUri
- jar:file:/some/path/gluegen-rt.jar!/- Returns:
- JarFile as named by Uri within the given ClassLoader
- Throws:
IllegalArgumentException
- null argumentsIOException
- if the Jar file could not been foundURISyntaxException
-
getRelativeOf
public static Uri getRelativeOf(Class<?> classFromJavaJar, Uri.Encoded cutOffInclSubDir, Uri.Encoded relResPath) throws IllegalArgumentException, IOException, URISyntaxException
Locates theJar file Uri
of a given resource relative to a given class's Jar's Uri.class's jar url path + cutOffInclSubDir + relResPath,
Example #1classFromJavaJar = com.lighting.Test (in: file:/storage/TestLighting.jar) cutOffInclSubDir = lights/ relResPath = LightAssets.jar Result : file:/storage/lights/LightAssets.jar
Example #2classFromJavaJar = com.lighting.Test (in: file:/storage/lights/TestLighting.jar) cutOffInclSubDir = lights/ relResPath = LightAssets.jar Result : file:/storage/lights/LightAssets.jar
TODO: Enhance documentation!- Parameters:
classFromJavaJar
- Used to get the root Uri for the class's Jar Uri.cutOffInclSubDir
- The cut off included sub-directory prepending the relative resource path. If the root Uri includes cutOffInclSubDir, it is no more added to the result.relResPath
- The relative resource path. (Uri encoded)- Returns:
- The resulting resource Uri, which is not tested.
- Throws:
IllegalArgumentException
IOException
URISyntaxException
-
getNativeLibNames
public static Map<String,String> getNativeLibNames(JarFile jarFile)
Return a map from native-lib-base-name to entry-name.
-
extract
public static final int extract(File dest, Map<String,String> nativeLibMap, JarFile jarFile, String nativeLibraryPath, boolean extractNativeLibraries, boolean extractClassFiles, boolean extractOtherFiles) throws IOException
Extract the files of the given jar file.If
extractNativeLibraries
is true, native libraries are added to the givennativeLibMap
with the base name to temp file location.
A file is identified as a native library, if it's name complies with the running platform's native library naming scheme.
Root entries are favored over non root entries in case of naming collisions.
Example on a Unix like machine:
mylib.jar!/sub1/libsour.so -> sour (mapped, unique name) mylib.jar!/sub1/libsweet.so (dropped, root entry favored) mylib.jar!/libsweet.so -> sweet (mapped, root entry favored) mylib.jar!/sweet.dll -> (dropped, not a unix library name)
In order to be compatible with Java Web Start, we need to extract all root entries from the jar file.
In this case, set all flags to trueextractNativeLibraries
.extractClassFiles
,extractOtherFiles
.- Parameters:
dest
-nativeLibMap
-jarFile
-nativeLibraryPath
- if not null, only extracts native libraries within this path.extractNativeLibraries
-extractClassFiles
-extractOtherFiles
-deepDirectoryTraversal
-- Returns:
- Throws:
IOException
-
validateCertificates
public static final void validateCertificates(Certificate[] rootCerts, JarFile jarFile) throws IOException, SecurityException
Validate the certificates for each native Lib in the jar file. Throws an IOException if any certificate is not valid.Certificate[] rootCerts = Something.class.getProtectionDomain(). getCodeSource().getCertificates();
- Throws:
IOException
SecurityException
-
-