com.jogamp.common.util
Class JarUtil

java.lang.Object
  extended by com.jogamp.common.util.JarUtil

public class JarUtil
extends Object


Constructor Summary
JarUtil()
           
 
Method Summary
static int extract(File dest, Map<String,String> nativeLibMap, JarFile jarFile, boolean extractNativeLibraries, boolean extractClassFiles, boolean extractOtherFiles)
          Extract the files of the given jar file.
static String getJarBasename(String clazzBinName, ClassLoader cl)
          The Class's com.jogamp.common.GlueGenVersion URL jar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class Jar basename gluegen-rt.jar will be returned.
static String getJarBasename(URL classJarURL)
          The Class's Jar URL jar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class Jar basename gluegen-rt.jar will be returned.
static URL getJarEntryURL(URL jarFileURL, String jarEntry)
           
static JarFile getJarFile(String clazzBinName, ClassLoader cl)
           
static JarFile getJarFile(URL jarFileUrl)
           
static URL getJarFileURL(String clazzBinName, ClassLoader cl)
          The Class's "com.jogamp.common.GlueGenVersion" URL jar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class" Jar file URL jar:sub_protocol:/some/path/gluegen-rt.jar!/ will be returned.
static URL getJarFileURL(URL jarSubUrl)
           
static URL getJarFileURL(URL baseUrl, String jarFileName)
           
static URL getJarSubURL(String clazzBinName, ClassLoader cl)
          The Class's com.jogamp.common.GlueGenVersion URL jar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class Jar file's sub URL sub_protocol:/some/path/gluegen-rt.jar will be returned.
static URL getJarSubURL(URL classJarURL)
          The Class's Jar URL jar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class Jar file's sub URL sub_protocol:/some/path/gluegen-rt.jar will be returned.
static URL getJarURL(String clazzBinName, ClassLoader cl)
          The Class's "com.jogamp.common.GlueGenVersion" URL jar: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 URL getURLDirname(URL aURL)
          The URL's protocol:/some/path/gluegen-rt.jar parent dirname URL protocol:/some/path/ will be returned.
static boolean hasJarURL(String clazzBinName, ClassLoader cl)
          Returns true if the Class's "com.jogamp.common.GlueGenVersion" is loaded from a JarFile and hence has a Jar URL like URL jar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class".
static void validateCertificates(Certificate[] rootCerts, JarFile jarFile)
          Validate the certificates for each native Lib in the jar file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JarUtil

public JarUtil()
Method Detail

hasJarURL

public static boolean hasJarURL(String clazzBinName,
                                ClassLoader cl)
Returns true if the Class's "com.jogamp.common.GlueGenVersion" is loaded from a JarFile and hence has a Jar URL like URL jar: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.
See Also:
#getJarURL(String, ClassLoader)}

getJarURL

public static URL getJarURL(String clazzBinName,
                            ClassLoader cl)
                     throws IllegalArgumentException,
                            IOException
The Class's "com.jogamp.common.GlueGenVersion" URL jar: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 URL doesn't match the expected formatting or null arguments
IOException - if the class's Jar file could not been found by the ClassLoader
See Also:
IOUtil#getClassURL(String, ClassLoader)}

getJarBasename

public static String getJarBasename(URL classJarURL)
                             throws IllegalArgumentException
The Class's Jar URL jar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class Jar basename gluegen-rt.jar will be returned.

sub_protocol may be "file", "http", etc..

Parameters:
classJarURL - as retrieved w/ getJarURL("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 URL doesn't match the expected formatting or is null
See Also:
IOUtil#getClassURL(String, ClassLoader)}

getJarBasename

public static String getJarBasename(String clazzBinName,
                                    ClassLoader cl)
                             throws IllegalArgumentException,
                                    IOException
The Class's com.jogamp.common.GlueGenVersion URL jar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class Jar basename gluegen-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 URL doesn't match the expected formatting
IOException - if the class's Jar file could not been found by the ClassLoader
See Also:
IOUtil#getClassURL(String, ClassLoader)}

getJarSubURL

public static URL getJarSubURL(URL classJarURL)
                        throws IllegalArgumentException,
                               MalformedURLException
The Class's Jar URL jar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class Jar file's sub URL sub_protocol:/some/path/gluegen-rt.jar will be returned.

sub_protocol may be "file", "http", etc..

Parameters:
classJarURL - as retrieved w/ getJarURL("com.jogamp.common.GlueGenVersion", cl), i.e. jar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class
cl -
Returns:
sub_protocol:/some/path/gluegen-rt.jar
Throws:
IllegalArgumentException - if the URL doesn't match the expected formatting or is null
MalformedURLException - if the computed URL specifies an unknown protocol
See Also:
IOUtil#getClassURL(String, ClassLoader)}

getJarSubURL

public static URL getJarSubURL(String clazzBinName,
                               ClassLoader cl)
                        throws IllegalArgumentException,
                               IOException
The Class's com.jogamp.common.GlueGenVersion URL jar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class Jar file's sub URL 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:
sub_protocol:/some/path/gluegen-rt.jar
Throws:
IllegalArgumentException - if the URL doesn't match the expected formatting
IOException - if the class's Jar file could not been found by the ClassLoader
See Also:
IOUtil#getClassURL(String, ClassLoader)}

getJarFileURL

public static URL getJarFileURL(String clazzBinName,
                                ClassLoader cl)
                         throws IllegalArgumentException,
                                IOException
The Class's "com.jogamp.common.GlueGenVersion" URL jar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class" Jar file URL jar: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 URL doesn't match the expected formatting or null arguments
IOException - if the class's Jar file could not been found by the ClassLoader
See Also:
IOUtil#getClassURL(String, ClassLoader)}

getURLDirname

public static URL getURLDirname(URL aURL)
                         throws IllegalArgumentException,
                                MalformedURLException
The URL's protocol:/some/path/gluegen-rt.jar parent dirname URL protocol:/some/path/ will be returned.

protocol may be "file", "http", etc..

Parameters:
aURL - "protocol:/some/path/gluegen-rt.jar"
Returns:
"protocol:/some/path/"
Throws:
IllegalArgumentException - if the URL doesn't match the expected formatting, or is null
MalformedURLException

getJarFileURL

public static URL getJarFileURL(URL baseUrl,
                                String jarFileName)
                         throws IOException,
                                MalformedURLException
Parameters:
baseUrl - file:/some/path/
jarFileName - gluegen-rt.jar
Returns:
jar:file:/some/path/gluegen-rt.jar!/
Throws:
MalformedURLException
IllegalArgumentException - null arguments
IOException

getJarFileURL

public static URL getJarFileURL(URL jarSubUrl)
                         throws MalformedURLException,
                                IllegalArgumentException
Parameters:
jarSubUrl - file:/some/path/gluegen-rt.jar
Returns:
jar:file:/some/path/gluegen-rt.jar!/
Throws:
MalformedURLException
IllegalArgumentException - null arguments

getJarEntryURL

public static URL getJarEntryURL(URL jarFileURL,
                                 String jarEntry)
                          throws MalformedURLException,
                                 IllegalArgumentException
Parameters:
jarFileURL - 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:
MalformedURLException
IllegalArgumentException - null arguments

getJarFile

public static JarFile getJarFile(String clazzBinName,
                                 ClassLoader cl)
                          throws IOException,
                                 IllegalArgumentException
Parameters:
clazzBinName - com.jogamp.common.util.cache.TempJarCache
cl - 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 ClassLoader
IllegalArgumentException - null arguments
See Also:
#getJarFileURL(String, ClassLoader)}

getJarFile

public static JarFile getJarFile(URL jarFileUrl)
                          throws IOException,
                                 IllegalArgumentException
Parameters:
jarFileURL - jar:file:/some/path/gluegen-rt.jar!/
Returns:
JarFile as named by URL within the given ClassLoader
Throws:
IllegalArgumentException - null arguments
IOException - if the Jar file could not been found

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,
                                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 given nativeLibMap 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 true extractNativeLibraries . extractClassFiles, extractOtherFiles.

Parameters:
dest -
nativeLibMap -
jarFile -
deepDirectoryTraversal -
extractNativeLibraries -
extractClassFiles -
extractOtherFiles -
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