From: <eli...@us...> - 2007-06-29 22:11:34
|
Revision: 2856 http://svn.sourceforge.net/java-game-lib/?rev=2856&view=rev Author: elias_naur Date: 2007-06-29 15:11:31 -0700 (Fri, 29 Jun 2007) Log Message: ----------- Merge Windows and Linux privileged Runtime.exec usage into a method in LWJGLUtil. Linux: Added the recent freedesktop.org standard xdg-open script to the list of possible URL handlers. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/LWJGLUtil.java trunk/LWJGL/src/java/org/lwjgl/LinuxSysImplementation.java trunk/LWJGL/src/java/org/lwjgl/WindowsSysImplementation.java Modified: trunk/LWJGL/src/java/org/lwjgl/LWJGLUtil.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/LWJGLUtil.java 2007-06-20 08:58:26 UTC (rev 2855) +++ trunk/LWJGL/src/java/org/lwjgl/LWJGLUtil.java 2007-06-29 22:11:31 UTC (rev 2856) @@ -380,6 +380,22 @@ return paths; } + static void execPrivileged(final String[] cmd_array) throws Exception { + try { + Process process = (Process)AccessController.doPrivileged(new PrivilegedExceptionAction() { + public Object run() throws Exception { + return Runtime.getRuntime().exec(cmd_array); + } + }); + // Close unused streams to make sure the child process won't hang + process.getInputStream().close(); + process.getOutputStream().close(); + process.getErrorStream().close(); + } catch (PrivilegedActionException e) { + throw (Exception)e.getCause(); + } + } + private static String getPrivilegedProperty(final String property_name) { return (String)AccessController.doPrivileged(new PrivilegedAction() { public Object run() { Modified: trunk/LWJGL/src/java/org/lwjgl/LinuxSysImplementation.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/LinuxSysImplementation.java 2007-06-20 08:58:26 UTC (rev 2855) +++ trunk/LWJGL/src/java/org/lwjgl/LinuxSysImplementation.java 2007-06-29 22:11:31 UTC (rev 2856) @@ -32,8 +32,6 @@ package org.lwjgl; import java.security.AccessController; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; /** * @@ -50,19 +48,14 @@ // Linux may as well resort to pure Java hackery, as there's no Linux native way of doing it // right anyway. - String[] browsers = {"firefox", "mozilla", "opera", "konqueror", "nautilus", "galeon", "netscape"}; + String[] browsers = {"xdg-open", "firefox", "mozilla", "opera", "konqueror", "nautilus", "galeon", "netscape"}; for (int i = 0; i < browsers.length; i ++) { final String browser = browsers[i]; try { - AccessController.doPrivileged(new PrivilegedExceptionAction() { - public Object run() throws Exception { - Runtime.getRuntime().exec(new String[] { browser, url }); - return null; - } - }); + LWJGLUtil.execPrivileged(new String[] { browser, url }); return true; - } catch (PrivilegedActionException e) { + } catch (Exception e) { // Ignore e.printStackTrace(System.err); } Modified: trunk/LWJGL/src/java/org/lwjgl/WindowsSysImplementation.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/WindowsSysImplementation.java 2007-06-20 08:58:26 UTC (rev 2855) +++ trunk/LWJGL/src/java/org/lwjgl/WindowsSysImplementation.java 2007-06-29 22:11:31 UTC (rev 2856) @@ -32,8 +32,6 @@ package org.lwjgl; import java.security.AccessController; -import java.security.PrivilegedExceptionAction; -import java.security.PrivilegedActionException; /** * <p> @@ -56,15 +54,10 @@ public boolean openURL(final String url) { try { - AccessController.doPrivileged(new PrivilegedExceptionAction() { - public Object run() throws Exception { - Runtime.getRuntime().exec(new String[]{"rundll32", "url.dll,FileProtocolHandler", url}); - return null; - } - }); + LWJGLUtil.execPrivileged(new String[]{"rundll32", "url.dll,FileProtocolHandler", url}); return true; - } catch (PrivilegedActionException e) { - LWJGLUtil.log("Failed to open url (" + url + "): " + e.getCause().getMessage()); + } catch (Exception e) { + LWJGLUtil.log("Failed to open url (" + url + "): " + e.getMessage()); return false; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |