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 JarFile getJarFile(String clazzBinName, ClassLoader cl)
           
static JarFile getJarFile(URL jarUrl, ClassLoader cl)
           
static String getJarName(String clazzBinName, ClassLoader cl)
           
static URL getJarURL(String clazzBinName, ClassLoader cl)
           
static URL getJarURL(URL baseUrl, String jarFileName)
           
static URL getJarURLDirname(URL jarURL)
           
static Map<String,String> getNativeLibNames(JarFile jarFile)
          Return a map from native-lib-base-name to entry-name.
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

getJarName

public static String getJarName(String clazzBinName,
                                ClassLoader cl)
                         throws IOException
Parameters:
clazzBinName - com.jogamp.common.util.cache.TempJarCache
cl -
Returns:
gluegen-rt.jar
Throws:
IOException
See Also:
IOUtil#getClassURL(String, ClassLoader)}

getJarURL

public static URL getJarURL(String clazzBinName,
                            ClassLoader cl)
                     throws IOException
Parameters:
clazzBinName - com.jogamp.common.util.cache.TempJarCache
cl -
Returns:
jar:file:/usr/local/projects/JOGL/gluegen/build-x86_64/gluegen-rt.jar!/
Throws:
IOException
See Also:
IOUtil#getClassURL(String, ClassLoader)}

getJarURLDirname

public static URL getJarURLDirname(URL jarURL)
                            throws IOException
Parameters:
jarURL - jar:file:/usr/local/projects/JOGL/gluegen/build-x86_64/gluegen-rt.jar!/com/jogamp/common/util/cache/TempJarCache.class
Returns:
file:/usr/local/projects/JOGL/gluegen/build-x86_64/
Throws:
IOException

getJarURL

public static URL getJarURL(URL baseUrl,
                            String jarFileName)
                     throws IOException
Parameters:
baseUrl - file:/usr/local/projects/JOGL/gluegen/build-x86_64/
jarFileName - gluegen-rt.jar
Returns:
jar:file:/usr/local/projects/JOGL/gluegen/build-x86_64/gluegen-rt.jar!/
Throws:
IOException

getJarFile

public static JarFile getJarFile(String clazzBinName,
                                 ClassLoader cl)
                          throws IOException
Parameters:
clazzBinName - com.jogamp.common.util.cache.TempJarCache
cl - domain
Returns:
JarFile containing the named class within the given ClassLoader
Throws:
IOException
See Also:
#getJarURL(String, ClassLoader)}

getJarFile

public static JarFile getJarFile(URL jarUrl,
                                 ClassLoader cl)
                          throws IOException
Parameters:
jarURL - jar:file:/usr/local/projects/JOGL/gluegen/build-x86_64/gluegen-rt.jar!/
cl - domain
Returns:
JarFile as named by URL within the given ClassLoader
Throws:
IOException

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