hmi.util
Class Lib

java.lang.Object
  extended by hmi.util.Lib

public final class Lib
extends Object

Lib contains some utils for dealing with the system library path. (This is the library dealing with stuff like DLL's );

Author:
Job Zwiers

Field Summary
static String TMPDIR
           
 
Constructor Summary
private Lib()
           
 
Method Summary
static void addLibraryPath(String path)
          Attempt to add the specified path to the java library path, and enforces this java library path to be reloaded when the next System.loadLibrary is executed.
static List<String> extractIfRunningFrom(String regex)
          extracts java.library.path files, if running from a code source that matches the specified regular expression
static List<String> extractIfRunningFrom(String regex, boolean addToLibraryPath)
          extracts java.library.path files, if running from a code source that matches the specified regular expression
static List<String> extractIfRunningFrom(String regex, String extractDir)
          extracts java.library.path files, if running from a code source that matches the specified regular expression, and adds them to the library path
static List<String> extractIfRunningFrom(String regex, String extractDir, boolean addToLibraryPath)
          extracts java.library.path files, if running from a code source that matches the specified regular expression
static void extractLib(boolean addToLibraryPath)
          UnJars dll files from the jar file into java.io.tmpdir, and adds them to the java.library.path.
static List<String> extractLib(Class<?> cl, boolean addToLibraryPath)
          UnJars dll files from the jar file into java.io.tmpdir, and adds them to the java.library.path.
static List<String> extractLib(Class<?> cl, String extractDir, boolean addToLibraryPath)
          UnJars dll files from the jar file, and adds them to the java.library.path.
static List<String> extractLib(String extractDir, boolean addToLibraryPath)
          UnJars dll files from the jar file where hmi.util.Lib is found, and adds them to the java.library.path.
static List<String> extractLib(String jar, String extractDir, boolean addToLibraryPath)
          UnJars dll files from the jar file, and adds them to the java.library.path.
static String getCodeSourceLocation(Class<?> cl)
          Return the location of class or jar file from which the specified Class is running.
static String getJarName(String jarpath)
           
static boolean isRunningFrom(Class<?> cl, String regex)
          Checks whether the result of getCodeSourceLocation from the specified Class ends with a String matching the specified regular expression.
static boolean isRunningFrom(String regex)
          Checks whether the result of getCodeSourceLocation from this hmi.util.Lib class ends with a String matching the specified regular expression.
static void startProc(String jarName, String libPath, String mainClass, List<String> params)
          Starts up a Java program, pacakges within a jar file, within a new and separate Java process.
static boolean startProcessIfRunningFrom(String regex, String mainClass, List<String> params)
          Checks whether this Lib class is being accessed from a jar file that matches the specified regular expression.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TMPDIR

public static final String TMPDIR
Constructor Detail

Lib

private Lib()
Method Detail

addLibraryPath

public static void addLibraryPath(String path)
Attempt to add the specified path to the java library path, and enforces this java library path to be reloaded when the next System.loadLibrary is executed.


isRunningFrom

public static boolean isRunningFrom(String regex)
Checks whether the result of getCodeSourceLocation from this hmi.util.Lib class ends with a String matching the specified regular expression. For instance, isRunningFrom(hmi.graphics.jogl.FirstOpenGL.class, "-demo.jar") would return true when we are running FirstOpenGL from a jar file like HmiGraphics-demo.jar, but it would return false when running from a location like .../build/classes. or from a jar file like HmiGraphics-2.1.0.jar


isRunningFrom

public static boolean isRunningFrom(Class<?> cl,
                                    String regex)
Checks whether the result of getCodeSourceLocation from the specified Class ends with a String matching the specified regular expression. For instance, isRunningFrom(hmi.graphics.jogl.FirstOpenGL.class, "-demo.jar") would return true when we are running FirstOpenGL from a jar file like HmiGraphics-demo.jar, but it would return false when running from a location like .../build/classes. or from a jar file like HmiGraphics-2.1.0.jar


getCodeSourceLocation

public static String getCodeSourceLocation(Class<?> cl)
Return the location of class or jar file from which the specified Class is running. For instance, getCodeSourceLocation(hmi.graphics.jogl.FirstOpenGL.class) would return a location String ending in /build/classes, when running from a local ant build, or ending in something like /HmiGraphics1.2.3-demo.jar, when running from an executable jar


getJarName

public static String getJarName(String jarpath)

extractIfRunningFrom

public static List<String> extractIfRunningFrom(String regex)
extracts java.library.path files, if running from a code source that matches the specified regular expression


extractIfRunningFrom

public static List<String> extractIfRunningFrom(String regex,
                                                boolean addToLibraryPath)
extracts java.library.path files, if running from a code source that matches the specified regular expression


extractIfRunningFrom

public static List<String> extractIfRunningFrom(String regex,
                                                String extractDir,
                                                boolean addToLibraryPath)
extracts java.library.path files, if running from a code source that matches the specified regular expression


extractIfRunningFrom

public static List<String> extractIfRunningFrom(String regex,
                                                String extractDir)
extracts java.library.path files, if running from a code source that matches the specified regular expression, and adds them to the library path


extractLib

public static void extractLib(boolean addToLibraryPath)
UnJars dll files from the jar file into java.io.tmpdir, and adds them to the java.library.path. It is assumed that this hmi.util.Lib class resides in the same jar file as where the library files are to be found. Should be run from the main method, before any of the libraries is actually needed.


extractLib

public static List<String> extractLib(Class<?> cl,
                                      boolean addToLibraryPath)
UnJars dll files from the jar file into java.io.tmpdir, and adds them to the java.library.path. Should be run from the main method, before any of the libraries is actually needed.


extractLib

public static List<String> extractLib(String extractDir,
                                      boolean addToLibraryPath)
UnJars dll files from the jar file where hmi.util.Lib is found, and adds them to the java.library.path. Should be run from the main method, before any of the libraries is actually needed.


extractLib

public static List<String> extractLib(Class<?> cl,
                                      String extractDir,
                                      boolean addToLibraryPath)
UnJars dll files from the jar file, and adds them to the java.library.path. Should be run from the main method, before any of the libraries is actually needed.


extractLib

public static List<String> extractLib(String jar,
                                      String extractDir,
                                      boolean addToLibraryPath)
UnJars dll files from the jar file, and adds them to the java.library.path. The file names of files actually extracted are returned in a List. For the complete list of matching files, the corresponding base directory is added to the library path. Should be run from the main method, before any of the libraries is actually needed.


startProc

public static void startProc(String jarName,
                             String libPath,
                             String mainClass,
                             List<String> params)
Starts up a Java program, pacakges within a jar file, within a new and separate Java process. This allows for specifying java jvm command line options, like -Xmx1024m, that cannot be specified within a jar manifest file. Similar is the java.livrary.path option, which is included here by means of the libPath argument.


startProcessIfRunningFrom

public static boolean startProcessIfRunningFrom(String regex,
                                                String mainClass,
                                                List<String> params)
Checks whether this Lib class is being accessed from a jar file that matches the specified regular expression. If so, and no -DisProc=true attribute has been set, it extracts java.library.path files (i.e. either .dll or .so files) from the jar file, and starts a new Java process with the jar files on the classpath, the extracted files on the java.library.path, the parameters, specified in the param List, as "java command line arguments", an extra -DisProc=true is added, and finally the specified mainClass is used as the java "main" class to run. The call returns "true" in this case. When the startProcessIfRunningFrom call does not result in a new Java process, either because the Lib class was not part of a jar file (that matches the regular expression), or becauase the -DisProc=true prevented it, the result returned is "false". Typical example: params.add("-Xmx1024m"); if (! Lib.startProcessIfRunningFrom("ColladaTest.jar", "hmi.graphics.colladatest.ColladaTest", params) ) { new ColladaTest(); }