From 69d537e4f9e6e5d206719723094ea192ab51ef43 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Mon, 19 Sep 2011 13:48:45 +0200 Subject: Enhancement/GenericStyle: - NativeLibrary: - add isValidNativeLibraryName(..) - generic style - Platform - add getOSAndArch(), getOSAndArch(..) - IOUtil - add getClassFileName(..) - add getBasename(..) - add getDirname(..) - added doc - ReflectionUtil - generic style --- src/java/com/jogamp/common/os/NativeLibrary.java | 71 ++++++++++++++++-------- 1 file changed, 49 insertions(+), 22 deletions(-) (limited to 'src/java/com/jogamp/common/os/NativeLibrary.java') diff --git a/src/java/com/jogamp/common/os/NativeLibrary.java b/src/java/com/jogamp/common/os/NativeLibrary.java index 1df0e61..f5c3264 100755 --- a/src/java/com/jogamp/common/os/NativeLibrary.java +++ b/src/java/com/jogamp/common/os/NativeLibrary.java @@ -39,6 +39,7 @@ package com.jogamp.common.os; +import com.jogamp.common.util.IOUtil; import com.jogamp.gluegen.runtime.NativeLibLoader; import jogamp.common.Debug; import jogamp.common.os.MacOSXDynamicLinkerImpl; @@ -162,14 +163,14 @@ public class NativeLibrary implements DynamicLookupHelper { String macOSXLibName, boolean searchSystemPathFirst, ClassLoader loader, boolean global) { - List possiblePaths = enumerateLibraryPaths(windowsLibName, - unixLibName, - macOSXLibName, - searchSystemPathFirst, - loader); + List possiblePaths = enumerateLibraryPaths(windowsLibName, + unixLibName, + macOSXLibName, + searchSystemPathFirst, + loader); // Iterate down these and see which one if any we can actually find. - for (Iterator iter = possiblePaths.iterator(); iter.hasNext(); ) { - String path = (String) iter.next(); + for (Iterator iter = possiblePaths.iterator(); iter.hasNext(); ) { + String path = iter.next(); if (DEBUG) { System.err.println("Trying to load " + path); } @@ -232,15 +233,41 @@ public class NativeLibrary implements DynamicLookupHelper { dynLink.closeLibrary(handle); } + /** + * Comparison of prefix and suffix of the given libName's basename + * is performed case insensitive
+ * + * @param libName the full path library name with prefix and suffix + * @param isLowerCaseAlready indicates if libName is already lower-case + * + * @return basename of libName w/o path, ie. /usr/lib/libDrinkBeer.so -> DrinkBeer on Unix systems, but null on Windows. + */ + public static String isValidNativeLibraryName(String libName, boolean isLowerCaseAlready) { + libName = IOUtil.getBasename(libName); + final String libNameLC = isLowerCaseAlready ? libName : libName.toLowerCase(); + for(int i=0; i enumerateLibraryPaths(String windowsLibName, + String unixLibName, + String macOSXLibName, + boolean searchSystemPathFirst, + ClassLoader loader) { + List paths = new ArrayList(); String libName = selectName(windowsLibName, unixLibName, macOSXLibName); if (libName == null) { return paths; @@ -274,8 +301,8 @@ public class NativeLibrary implements DynamicLookupHelper { // Add entries from java.library.path String javaLibraryPath = - (String) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + AccessController.doPrivileged(new PrivilegedAction() { + public String run() { return System.getProperty("java.library.path"); } }); @@ -288,8 +315,8 @@ public class NativeLibrary implements DynamicLookupHelper { // Add current working directory String userDir = - (String) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + AccessController.doPrivileged(new PrivilegedAction() { + public String run() { return System.getProperty("user.dir"); } }); @@ -372,7 +399,7 @@ public class NativeLibrary implements DynamicLookupHelper { return res; } - private static void addPaths(String path, String[] baseNames, List paths) { + private static void addPaths(String path, String[] baseNames, List paths) { for (int j = 0; j < baseNames.length; j++) { paths.add(path + File.separator + baseNames[j]); } @@ -384,7 +411,7 @@ public class NativeLibrary implements DynamicLookupHelper { if (loader == null) return null; if (!initializedFindLibraryMethod) { - AccessController.doPrivileged(new PrivilegedAction() { + AccessController.doPrivileged(new PrivilegedAction() { public Object run() { try { findLibraryMethod = ClassLoader.class.getDeclaredMethod("findLibrary", @@ -400,10 +427,10 @@ public class NativeLibrary implements DynamicLookupHelper { } if (findLibraryMethod != null) { try { - return (String) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + return AccessController.doPrivileged(new PrivilegedAction() { + public String run() { try { - return findLibraryMethod.invoke(loader, new Object[] { libName }); + return (String) findLibraryMethod.invoke(loader, new Object[] { libName }); } catch (Exception e) { throw new RuntimeException(e); } -- cgit v1.2.3