From 081ce00eaad7568f5a651a34d0940feb5c9f9124 Mon Sep 17 00:00:00 2001 From: Kenneth Russel Date: Mon, 17 Apr 2006 08:24:48 +0000 Subject: Fixed Issue 215: Enhancement for NativeLibLoader Incorporated patch largely unmodified from user s_koehler. Cleaned up Cg library loading based on this work. git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@720 232f8b59-042b-4e1e-8c03-345bb8c30851 --- make/cg-common-CustomJavaCode.java | 17 +-- make/cg-common.cfg | 4 +- .../com/sun/opengl/impl/NativeLibLoader.java | 150 ++++++++++++--------- 3 files changed, 93 insertions(+), 78 deletions(-) diff --git a/make/cg-common-CustomJavaCode.java b/make/cg-common-CustomJavaCode.java index ba0df4ee9..63afdb65d 100755 --- a/make/cg-common-CustomJavaCode.java +++ b/make/cg-common-CustomJavaCode.java @@ -1,20 +1,5 @@ static { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - try { - // Workaround so that these don't need to be in the system - // path but can be referenced from java.library.path - // (this is intended to help with Webstarted applications) - System.loadLibrary("cg"); - System.loadLibrary("cgGL"); - } catch (UnsatisfiedLinkError e) { - // Consider this non-fatal - } - // Load the actual Cg binding - System.loadLibrary("jogl_cg"); - return null; - } - }); + NativeLibLoader.loadCgImpl(); } /** A convenience method which reads all available data from the InputStream and then calls cgCreateProgram. */ diff --git a/make/cg-common.cfg b/make/cg-common.cfg index f264fb2bf..6f73e7ed0 100644 --- a/make/cg-common.cfg +++ b/make/cg-common.cfg @@ -96,8 +96,8 @@ Ignore cgGetProgramOptions # Need to import New IO for Buffer classes # Import java.nio.* -# and java.security.* to allow unsigned Cg applications -Import java.security.* +# And NativeLibLoader for help loading the native libraries +Import com.sun.opengl.impl.* # Raise CgException instead of RuntimeException in glue code RuntimeExceptionType CgException diff --git a/src/classes/com/sun/opengl/impl/NativeLibLoader.java b/src/classes/com/sun/opengl/impl/NativeLibLoader.java index 9331b2f72..25c52e594 100644 --- a/src/classes/com/sun/opengl/impl/NativeLibLoader.java +++ b/src/classes/com/sun/opengl/impl/NativeLibLoader.java @@ -40,87 +40,117 @@ package com.sun.opengl.impl; import java.awt.Toolkit; -import java.security.*; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.HashSet; public class NativeLibLoader { - private static volatile boolean doLoading = true; + public interface LoaderAction { + /** + * Loads the library specified by libname. Optionally preloads the libraries specified by + * preload. The implementation should ignore, if the preload-libraries have already been + * loaded. + * @param libname the library to load + * @param preload the libraries to load before loading the main library + * @param doPreload true, iff the preload-libraries should be loaded + * @param ignoreError true, iff errors during loading the preload-libraries should be ignored + */ + void loadLibrary(String libname, String[] preload, + boolean doPreload, boolean ignoreError); + } + + private static class DefaultAction implements LoaderAction { + public void loadLibrary(String libname, String[] preload, + boolean doPreload, boolean ignoreError) { + if (doPreload) { + for (int i=0; i