diff -r f1dfa6adbb00 jfxmedia/src/com/sun/media/jfxmediaimpl/NativeLibLoader.java --- a/jfxmedia/src/com/sun/media/jfxmediaimpl/NativeLibLoader.java Thu Oct 04 16:11:12 2012 -0700 +++ b/jfxmedia/src/com/sun/media/jfxmediaimpl/NativeLibLoader.java Tue Oct 16 12:32:38 2012 -0400 @@ -23,38 +23,214 @@ * questions. */ +// *************************************************************************** +// IMPORTANT: Because the media repository and the glass and javafx-common +// projects in the rt-closed repository are built independently from one +// another, there are three separate copies of this file: +// +// rt-closed: javafx-common/src/com/sun/javafx/runtime/NativeLibLoader.java +// rt-closed: glass/glass-mat/src/com/sun/glass/utils/NativeLibLoader.java +// media: jfxmedia/src/com/sun/media/jfxmediaimpl/NativeLibLoader.java +// +// All three files must be modified whenever a bug fix or enhancement is made. +// The only difference between the copies is the package name: a one line diff. +// *************************************************************************** + package com.sun.media.jfxmediaimpl; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - +import java.io.File; +import java.net.URI; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.HashSet; public class NativeLibLoader { + private static final HashSet loaded = new HashSet(); - /* Use reflection to access the NativeLibLoader until the build order is fixed */ public static synchronized void loadLibrary(String libname) { + if (!loaded.contains(libname)) { + loadLibraryInternal(libname); + loaded.add(libname); + } + } + + private static boolean verbose = false; + private static File libDir = null; + private static String libPrefix = ""; + private static String libSuffix = ""; + private static String libSuffixAlt = null; + + static { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + verbose = Boolean.getBoolean("javafx.verbose"); + return null; + } + }); + } + + private static String[] initializePath(String propname) { + String ldpath = System.getProperty(propname, ""); + String ps = File.pathSeparator; + int ldlen = ldpath.length(); + int i, j, n; + // Count the separators in the path + i = ldpath.indexOf(ps); + n = 0; + while (i >= 0) { + n++; + i = ldpath.indexOf(ps, i + 1); + } + + // allocate the array of paths - n :'s = n + 1 path elements + String[] paths = new String[n + 1]; + + // Fill the array with paths from the ldpath + n = i = 0; + j = ldpath.indexOf(ps); + while (j >= 0) { + if (j - i > 0) { + paths[n++] = ldpath.substring(i, j); + } else if (j - i == 0) { + paths[n++] = "."; + } + i = j + 1; + j = ldpath.indexOf(ps, i); + } + paths[n] = ldpath.substring(i, ldlen); + return paths; + } + + private static void loadLibraryInternal(String libraryName) { + // Look for the library in the same directory as the jar file + // containing this class. + // If that fails, then try System.loadLibrary as a last resort. try { - Class clazz = Class.forName("com.sun.glass.utils.NativeLibLoader"); - Method method = clazz.getDeclaredMethod("loadLibrary", new Class[]{String.class}); - method.invoke(libname, libname); - } catch (ClassNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (NoSuchMethodException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (InvocationTargetException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + loadLibraryFullPath(libraryName); + } catch (UnsatisfiedLinkError ex) { + // Try System.loadLibrary as a last resort. If it succeeds, then + // print a warning. If it fails, rethrow the exception from + // the earlier System.load() + // + // NOTE: First attempt to load the libraries from the java.library.path. + // This allows FX to find more recent versions of the shared libraries + // from java.library.path instead of ones that might be part of the JRE + // + // This fix does not check for .jnilib on Mac + // + String [] libPath = initializePath("java.library.path"); + for (int i=0; i