From: <eli...@us...> - 2006-07-03 10:22:25
|
Revision: 2418 Author: elias_naur Date: 2006-07-03 03:21:44 -0700 (Mon, 03 Jul 2006) ViewCVS: http://svn.sourceforge.net/java-game-lib/?rev=2418&view=rev Log Message: ----------- Made sure no dependency from core LWJGL to LWJGLInstaller exists Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/LWJGLUtil.java trunk/LWJGL/src/java/org/lwjgl/Sys.java trunk/LWJGL/src/java/org/lwjgl/applet/LWJGLInstaller.java trunk/LWJGL/src/java/org/lwjgl/devil/ILNative.java trunk/LWJGL/src/java/org/lwjgl/fmod3/FMOD.java trunk/LWJGL/src/java/org/lwjgl/test/applet/AppletTest.java Modified: trunk/LWJGL/src/java/org/lwjgl/LWJGLUtil.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/LWJGLUtil.java 2006-07-02 22:45:56 UTC (rev 2417) +++ trunk/LWJGL/src/java/org/lwjgl/LWJGLUtil.java 2006-07-03 10:21:44 UTC (rev 2418) @@ -42,7 +42,6 @@ import java.util.List; import java.util.StringTokenizer; -import org.lwjgl.applet.LWJGLInstaller; /** * <p> @@ -280,7 +279,7 @@ * @return the current platform type */ public static int getPlatform() { - String osName = System.getProperty("os.name"); + String osName = getPrivilegedProperty("os.name"); if (osName.startsWith("Windows")) { return PLATFORM_WINDOWS; @@ -358,16 +357,13 @@ } // add Installer path - if (LWJGLInstaller.installed) { - possible_paths.add(LWJGLInstaller.installDirectory + File.separator + platform_lib_name); + String alternative_path = getPrivilegedProperty("org.lwjgl.librarypath"); + if (alternative_path != null) { + possible_paths.add(alternative_path + File.separator + platform_lib_name); } // Add all possible paths from java.library.path - String java_library_path = (String)AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - return System.getProperty("java.library.path"); - } - }); + String java_library_path = getPrivilegedProperty("java.library.path"); StringTokenizer st = new StringTokenizer(java_library_path, File.pathSeparator); while (st.hasMoreTokens()) { @@ -376,11 +372,7 @@ } //add current path - String current_dir = (String)AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - return System.getProperty("user.dir"); - } - }); + String current_dir = getPrivilegedProperty("user.dir"); possible_paths.add(current_dir + File.separator + platform_lib_name); //add pure library (no path, let OS search) @@ -393,6 +385,14 @@ return paths; } + private static String getPrivilegedProperty(final String property_name) { + return (String)AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + return System.getProperty(property_name); + } + }); + } + /** * Tries to locate named library from the current ClassLoader * This method exists because native libraries are loaded from native code, and as such @@ -460,7 +460,7 @@ * specific code and will not work for any other platform. */ public static boolean isMacOSXEqualsOrBetterThan(int major_required, int minor_required) { - String os_version = System.getProperty("os.version"); + String os_version = getPrivilegedProperty("os.version"); StringTokenizer version_tokenizer = new StringTokenizer(os_version, "."); int major; int minor; Modified: trunk/LWJGL/src/java/org/lwjgl/Sys.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/Sys.java 2006-07-02 22:45:56 UTC (rev 2417) +++ trunk/LWJGL/src/java/org/lwjgl/Sys.java 2006-07-03 10:21:44 UTC (rev 2418) @@ -39,7 +39,6 @@ import java.security.PrivilegedAction; import java.security.PrivilegedExceptionAction; -import org.lwjgl.applet.LWJGLInstaller; import org.lwjgl.input.Mouse; /** @@ -58,31 +57,28 @@ /** The implementation instance to delegate platform specific behavior to */ private final static SysImplementation implementation; - /** - * utility loadlibrary to load the native library using elevated priviledges - * @param name Name of library to load, or full path if usingPath is true - * @param usingPath true if using the full path to the native - */ - private static void loadLibrary(final String name, final boolean usingPath) { + private static void loadLibrary(final String lib_name) { AccessController.doPrivileged(new PrivilegedAction() { public Object run() { - if(usingPath) { - System.load(name); + String library_path = System.getProperty("org.lwjgl.librarypath"); + if (library_path != null) { + System.load(library_path + File.separator + + System.mapLibraryName(lib_name)); } else { - System.loadLibrary(name); + System.loadLibrary(lib_name); } return null; } }); - } - + } + static { implementation = createImplementation(); String[] library_names = implementation.getNativeLibraryNames(); UnsatisfiedLinkError last_load_error = null; for (int i = 0; i < library_names.length; i++) { try { - loadLibrary(library_names[i], false); + loadLibrary(library_names[i]); last_load_error = null; break; } catch (UnsatisfiedLinkError e) { @@ -90,19 +86,6 @@ } } - // failed normal loading - check installer - if (last_load_error != null && LWJGLInstaller.installed) { - for (int i = 0; i < library_names.length; i++) { - try { - loadLibrary(LWJGLInstaller.installDirectory + File.separator + System.mapLibraryName(library_names[i]), true); - last_load_error = null; - break; - } catch (UnsatisfiedLinkError e) { - last_load_error = e; - } - } - } - // check for error if (last_load_error != null) { throw last_load_error; Modified: trunk/LWJGL/src/java/org/lwjgl/applet/LWJGLInstaller.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/applet/LWJGLInstaller.java 2006-07-02 22:45:56 UTC (rev 2417) +++ trunk/LWJGL/src/java/org/lwjgl/applet/LWJGLInstaller.java 2006-07-03 10:21:44 UTC (rev 2418) @@ -41,8 +41,8 @@ import java.io.OutputStream; import java.security.AccessController; import java.security.PrivilegedAction; +import java.security.PrivilegedExceptionAction; -import org.lwjgl.LWJGLException; import org.lwjgl.LWJGLUtil; /** @@ -71,9 +71,6 @@ /** Whether to hook uninstall rutine. Must be called prior to installation */ public static boolean disableUninstall = false; - /** Directory that was installed into */ - public static String installDirectory; - /** Buffer used when copying files */ private static final byte[] COPY_BUFFER = new byte[4096]; @@ -94,53 +91,55 @@ * will always be present in the users temp dir. * * @see java.lang.ClassLoader#getResource(String) - * @return true if the installation was successfull */ - public static boolean tempInstall() throws LWJGLException { + public static void tempInstall() throws Exception { // only need to install once if (installed) { - return true; + return; } - - // libraries to validate and install - String[] libraries = PLATFORM_FILES[LWJGLUtil.getPlatform() - 1]; - - // Validate the certificates of the native files - validateCertificates(); - // install shutdown installer hook - if(!disableUninstall) { + try { + // libraries to validate and install + String[] libraries = PLATFORM_FILES[LWJGLUtil.getPlatform() - 1]; + + // Validate the certificates of the native files + validateCertificates(); + + // install shutdown installer hook + if(!disableUninstall) { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + Runtime.getRuntime().addShutdownHook(new Thread() { + public void run() { + uninstall(); + } + }); + return null; + } + }); + } + + // create a temporary dir for the native files + String user_temp_dir = getPriviledgedString("java.io.tmpdir"); + final String path = createTemporaryDir(user_temp_dir); + + // extract natives + for (int i = 0; i < libraries.length; i++) { + String library = System.mapLibraryName(libraries[i]); + extract(library, path); + } + AccessController.doPrivileged(new PrivilegedAction() { public Object run() { - Runtime.getRuntime().addShutdownHook(new Thread() { - public void run() { - LWJGLInstaller.uninstall(); - } - }); + System.setProperty("org.lwjgl.librarypath", path); return null; } }); + } catch (Exception e) { + LWJGLUtil.log("Failed extraction e = " + e.getMessage()); + uninstall(); + throw e; } - - // create a temporary dir for the native files - String user_temp_dir = getPriviledgedString("java.io.tmpdir"); - String path = createTemporaryDir(user_temp_dir); - if(path == null) { - throw new LWJGLException("Failed creation of temporary directory in " + user_temp_dir); - } - - // extract natives - for (int i = 0; i < libraries.length; i++) { - String library = System.mapLibraryName(libraries[i]); - if(!extract(library, path)) { - LWJGLUtil.log("Failed extract of " + library + " to " + path); - uninstall(); - return false; - } - } - - installDirectory = path; - return installed = true; } /** @@ -150,9 +149,9 @@ * before the "real" LWJGL jar, containing native libraries with unwanted code. * By forcing all the native libraries to have the same certificate as the signed * installer, we can also be sure that the native libraries indeed are correct. - * @throws LWJGLException If we encounter a certificate mismatch + * @throws Exception If we encounter a certificate mismatch */ - private static void validateCertificates() throws LWJGLException { + private static void validateCertificates() throws Exception { /* TODO */ } @@ -161,15 +160,14 @@ * * @param file File to extract * @param path Path to extract to - * @return true if the file was extracted successdully */ - private static boolean extract(final String file, final String path) throws LWJGLException { - return (Boolean) AccessController.doPrivileged(new PrivilegedAction() { + private static void extract(final String file, final String path) { + AccessController.doPrivileged(new PrivilegedAction() { public Object run() { // check for existing file, and get out File out = new File(path + File.separator + file); if (out.exists()) { - return false; + return null; } // create the new file and copy it to its destination @@ -183,12 +181,12 @@ // =========================================== if (os == null) { LWJGLUtil.log("Unable to write to outputstream at " + out.getAbsolutePath()); - return false; + return null; } if (is == null) { LWJGLUtil.log("Unable to read classpath inputstream from " + in); - return false; + return null; } // ------------------------------------------- @@ -196,9 +194,9 @@ copyFile(is, os); } catch (IOException ioe) { LWJGLUtil.log("Exception while extracting " + file + ": " + ioe.getMessage()); - return false; + return null; } - return true; + return null; } }); } @@ -225,23 +223,19 @@ * called '.lwjglinstaller' will also be created in the directory. * @return Name of temp directory or null if directory creation failed */ - static String createTemporaryDir(final String user_temp_dir) { - return (String) AccessController.doPrivileged(new PrivilegedAction() { + static String createTemporaryDir(final String user_temp_dir) throws Exception { + return (String) AccessController.doPrivileged(new PrivilegedExceptionAction() { public Object run() { // create the temp directory File tempDir = new File(user_temp_dir + File.separator + "lwjgl-" + System.currentTimeMillis()); if(!tempDir.mkdir()) { - return null; + throw new IOException("Failed to create directory: " + tempDir); } // add the watermark file // TODO: Write some info to the file ? - try { - File watermark = new File(tempDir.getAbsolutePath() + File.separator + ".lwjglinstaller"); - watermark.createNewFile(); - } catch (IOException ioe) { - return null; - } + File watermark = new File(tempDir.getAbsolutePath() + File.separator + ".lwjglinstaller"); + watermark.createNewFile(); return tempDir.getAbsolutePath(); } }); Modified: trunk/LWJGL/src/java/org/lwjgl/devil/ILNative.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/devil/ILNative.java 2006-07-02 22:45:56 UTC (rev 2417) +++ trunk/LWJGL/src/java/org/lwjgl/devil/ILNative.java 2006-07-03 10:21:44 UTC (rev 2418) @@ -37,7 +37,6 @@ import org.lwjgl.LWJGLException; import org.lwjgl.LWJGLUtil; -import org.lwjgl.applet.LWJGLInstaller; /** * <p> @@ -56,30 +55,23 @@ /** Version of IL */ public static final String VERSION = "1.0beta2"; - /** - * utility loadlibrary to load the native library using elevated priviledges - * @param name Name of library to load, or full path if usingPath is true - * @param usingPath true if using the full path to the native - */ - private static void loadLibrary(final String name, final boolean usingPath) { + private static void loadLibrary(final String lib_name) { AccessController.doPrivileged(new PrivilegedAction() { public Object run() { - if(usingPath) { - System.load(name); + String library_path = System.getProperty("org.lwjgl.librarypath"); + if (library_path != null) { + System.load(library_path + File.separator + + System.mapLibraryName(lib_name)); } else { - System.loadLibrary(name); + System.loadLibrary(lib_name); } return null; } }); - } - + } + static { - if (LWJGLInstaller.installed) { - loadLibrary(LWJGLInstaller.installDirectory + File.separator + System.mapLibraryName(JNI_LIBRARY_NAME), true); - } else { - loadLibrary(JNI_LIBRARY_NAME, false); - } + loadLibrary(JNI_LIBRARY_NAME); // check for mismatch String nativeVersion = getNativeLibraryVersion(); Modified: trunk/LWJGL/src/java/org/lwjgl/fmod3/FMOD.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/fmod3/FMOD.java 2006-07-02 22:45:56 UTC (rev 2417) +++ trunk/LWJGL/src/java/org/lwjgl/fmod3/FMOD.java 2006-07-03 10:21:44 UTC (rev 2418) @@ -41,7 +41,6 @@ import org.lwjgl.LWJGLException; import org.lwjgl.LWJGLUtil; -import org.lwjgl.applet.LWJGLInstaller; /** * <br> @@ -209,11 +208,7 @@ } initialized = true; - if (LWJGLInstaller.installed) { - loadLibrary(LWJGLInstaller.installDirectory + File.separator + System.mapLibraryName(JNI_LIBRARY_NAME), true); - } else { - loadLibrary(JNI_LIBRARY_NAME, false); - } + loadLibrary(JNI_LIBRARY_NAME); // check for mismatch String nativeVersion = getNativeLibraryVersion(); @@ -229,13 +224,15 @@ } } - private static void loadLibrary(final String name, final boolean usingPath) { + private static void loadLibrary(final String lib_name) { AccessController.doPrivileged(new PrivilegedAction() { public Object run() { - if(usingPath) { - System.load(name); + String library_path = System.getProperty("org.lwjgl.librarypath"); + if (library_path != null) { + System.load(library_path + File.separator + + System.mapLibraryName(lib_name)); } else { - System.loadLibrary(name); + System.loadLibrary(lib_name); } return null; } Modified: trunk/LWJGL/src/java/org/lwjgl/test/applet/AppletTest.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/applet/AppletTest.java 2006-07-02 22:45:56 UTC (rev 2417) +++ trunk/LWJGL/src/java/org/lwjgl/test/applet/AppletTest.java 2006-07-03 10:21:44 UTC (rev 2418) @@ -44,19 +44,16 @@ Test test = null; - @Override public void destroy() { super.destroy(); System.out.println("*** destroy ***"); } - @Override public void start() { super.start(); System.out.println("*** start ***"); } - @Override public void stop() { super.stop(); System.out.println("*** stop ***"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |