From 38c7cb80528704b6771220448f36da4199f66453 Mon Sep 17 00:00:00 2001 From: megacz Date: Fri, 30 Jan 2004 06:48:52 +0000 Subject: [PATCH] 2002/07/15 23:14:55 darcs-hash:20040130064852-2ba56-68d186e871b0b8c6dbd51930bd3853a8152b7a10.gz --- CHANGES | 5 +++- src/org/xwt/Platform.java | 45 ++++++++++++++++++++++++++++++++-- src/org/xwt/plat/POSIX.java | 57 +++---------------------------------------- src/org/xwt/plat/Win32.cc | 13 +++++++++- src/org/xwt/plat/Win32.java | 1 + 5 files changed, 63 insertions(+), 58 deletions(-) diff --git a/CHANGES b/CHANGES index 3ae9cbd..d984fd6 100644 --- a/CHANGES +++ b/CHANGES @@ -251,4 +251,7 @@ 15-Jul megacz HTTP.java: implemented isInNet(), weekdayRange(), now checks environment vars for proxies -15-Jul megacz PNG.java: fixed 8bpp bug \ No newline at end of file +15-Jul megacz PNG.java: fixed 8bpp bug + +15-Jul megacz Platform.java, Win32.cc, Win32.java, POSIX.java: + getEnv(), engine knows its own build-id diff --git a/src/org/xwt/Platform.java b/src/org/xwt/Platform.java index 4fee620..a7f0627 100644 --- a/src/org/xwt/Platform.java +++ b/src/org/xwt/Platform.java @@ -36,6 +36,9 @@ public class Platform { /** the result of proxy autodetection */ static HTTP.ProxyInfo cachedProxyInfo = null; + /** the current build */ + public static String build = "unknown"; + // VM Detection Logic ///////////////////////////////////////////////////////////////////// /** do-nothing method that forces <clinit> to run */ @@ -67,9 +70,19 @@ public class Platform { platform.init(); } + try { + build = (String)Class.forName("org.xwt.Build").getField("build").get(null); + } catch (ClassNotFoundException cnfe) { + } catch (Exception e) { + if (Log.on) Log.log(Platform.class, "exception while detecting build:"); + if (Log.on) Log.log(Platform.class, e); + } + if (Log.on) Log.log(Platform.class, "XWT build: " + build); + if (Log.on) Log.log(Platform.class, "XWT VM detection: vendor = " + vendor); if (Log.on) Log.log(Platform.class, " version = " + version); if (Log.on) Log.log(Platform.class, " os = " + os_name); + if (Log.on && Main.applet != null) Log.log(Platform.class, " browser = " + Main.applet.getParameter("browser")); if (platform_class == null) { if (Log.on) Log.log(Platform.class, "Unable to detect JVM"); @@ -78,6 +91,7 @@ public class Platform { if (Log.on) Log.log(Platform.class, " platform = " + platform.getDescriptiveName()); if (Log.on) Log.log(Platform.class, " class = " + platform.getClass().getName()); + platform.postInit(); } catch (Exception e) { if (Log.on) Log.log(Platform.class, "Exception while trying to detect JVM"); @@ -95,6 +109,7 @@ public class Platform { /** this initializes the platform; code in here can invoke methods on Platform since Platform.platform has already been set */ protected void init() { } + protected void postInit() { } /** creates and returns a doublebuffer 'belonging' to owner; we need to associate DoubleBuffers to surfaces * due to AWT 1.1 requirements (definately for Navigator, possibly also for MSJVM). @@ -163,7 +178,7 @@ public class Platform { System.exit(0); } else { // just block ourselves forever - // FIXME: implement this with an exit variable for MessageQueue and plat.*.eventThread + // FIXME new Semaphore().block(); } } @@ -194,6 +209,29 @@ public class Platform { /** returns true iff the platform has a case-sensitive filesystem */ protected boolean _isCaseSensitive() { return true; } + /** returns the value of the environment variable key, or null if no such key exists */ + protected String _getEnv(String key) { + try { + String os = System.getProperty("os.name").toLowerCase(); + Process p; + if (os.indexOf("windows 9") > -1) { + p = Runtime.getRuntime().exec("command.com /c set"); + } else if ( (os.indexOf("nt") > -1) || (os.indexOf("windows 2000") > -1) ) { + p = Runtime.getRuntime().exec("cmd.exe /c set"); + } else { + p = Runtime.getRuntime().exec("env"); + } + BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); + String s; + while ((s = br.readLine()) != null) + if (s.startsWith(key + "=")) + return s.substring(0, key.length() + 1); + } catch (Exception e) { + if (Log.on) Log.log(this, "Exception while reading from environment:"); + if (Log.on) Log.log(this, e); + } + return null; + } // Static methods -- thunk to the instance ///////////////////////////////////////////////////////////////////////// @@ -259,6 +297,9 @@ public class Platform { /** returns true iff the platform has a case-sensitive filesystem */ public static boolean isCaseSensitive() { return platform._isCaseSensitive(); } + /** returns the value of the environment variable key, or null if no such key exists */ + public static String getEnv(String key) { return platform._getEnv(key); } + /** displays a platform-specific "open file" dialog and returns the chosen filename, or null if the user hit cancel */ public static String fileDialog(String suggestedFileName, boolean write) { if (!ThreadMessage.suspendThread()) return null; @@ -341,7 +382,7 @@ public class Platform { if (alreadyDetectedProxy) return null; alreadyDetectedProxy = true; - if (Log.on) Log.log(Platform.class, "attempting xwt-proxy DNS proxy detection"); + if (Log.on) Log.log(Platform.class, "attempting environment-variable DNS proxy detection"); cachedProxyInfo = HTTP.ProxyInfo.detectProxyViaManual(); if (cachedProxyInfo != null) return cachedProxyInfo; diff --git a/src/org/xwt/plat/POSIX.java b/src/org/xwt/plat/POSIX.java index f8766ba..d522834 100644 --- a/src/org/xwt/plat/POSIX.java +++ b/src/org/xwt/plat/POSIX.java @@ -52,63 +52,12 @@ public class POSIX extends GCJ { protected native void eventThread(); private native void natInit(); - /** returns the $BROWSER environment variable, since System.getEnv() is useless */ - private static native String getEnv(String key); - + /** returns the value of the environment variable key, or null if no such key exists */ + protected native String _getEnv(String key); + /** spawns a process which is immune to SIGHUP */ private static native void spawnChildProcess(String[] command); - protected synchronized HTTP.ProxyInfo _detectProxy() { - - HTTP.ProxyInfo ret = new HTTP.ProxyInfo(); - - ret.httpProxyHost = getEnv("http_proxy"); - if (ret.httpProxyHost != null) { - if (ret.httpProxyHost.startsWith("http://")) ret.httpProxyHost = ret.httpProxyHost.substring(7); - if (ret.httpProxyHost.endsWith("/")) ret.httpProxyHost = ret.httpProxyHost.substring(0, ret.httpProxyHost.length() - 1); - if (ret.httpProxyHost.indexOf(':') != -1) { - ret.httpProxyPort = Integer.parseInt(ret.httpProxyHost.substring(ret.httpProxyHost.indexOf(':') + 1)); - ret.httpProxyHost = ret.httpProxyHost.substring(0, ret.httpProxyHost.indexOf(':')); - } else { - ret.httpProxyPort = 80; - } - } - - ret.httpsProxyHost = getEnv("https_proxy"); - if (ret.httpsProxyHost != null) { - if (ret.httpsProxyHost.startsWith("https://")) ret.httpsProxyHost = ret.httpsProxyHost.substring(7); - if (ret.httpsProxyHost.endsWith("/")) ret.httpsProxyHost = ret.httpsProxyHost.substring(0, ret.httpsProxyHost.length() - 1); - if (ret.httpsProxyHost.indexOf(':') != -1) { - ret.httpsProxyPort = Integer.parseInt(ret.httpsProxyHost.substring(ret.httpsProxyHost.indexOf(':') + 1)); - ret.httpsProxyHost = ret.httpsProxyHost.substring(0, ret.httpsProxyHost.indexOf(':')); - } else { - ret.httpsProxyPort = 80; - } - } - - ret.socksProxyHost = getEnv("socks_proxy"); - if (ret.socksProxyHost != null) { - if (ret.socksProxyHost.startsWith("socks://")) ret.socksProxyHost = ret.socksProxyHost.substring(7); - if (ret.socksProxyHost.endsWith("/")) ret.socksProxyHost = ret.socksProxyHost.substring(0, ret.socksProxyHost.length() - 1); - if (ret.socksProxyHost.indexOf(':') != -1) { - ret.socksProxyPort = Integer.parseInt(ret.socksProxyHost.substring(ret.socksProxyHost.indexOf(':') + 1)); - ret.socksProxyHost = ret.socksProxyHost.substring(0, ret.socksProxyHost.indexOf(':')); - } else { - ret.socksProxyPort = 80; - } - } - - String noproxy = getEnv("no_proxy"); - if (noproxy != null) { - StringTokenizer st = new StringTokenizer(noproxy, ","); - ret.excluded = new String[st.countTokens()]; - for(int i=0; st.hasMoreTokens(); i++) ret.excluded[i] = st.nextToken(); - } - - if (ret.httpProxyHost == null && ret.socksProxyHost == null) return null; - return ret; - } - protected void _newBrowserWindow(String url) { String browserString = getEnv("BROWSER"); if (browserString == null) { diff --git a/src/org/xwt/plat/Win32.cc b/src/org/xwt/plat/Win32.cc index 195171b..28023a1 100644 --- a/src/org/xwt/plat/Win32.cc +++ b/src/org/xwt/plat/Win32.cc @@ -236,6 +236,17 @@ void org::xwt::plat::Win32::natInit() { // Platform Methods /////////////////////////////////////////////////////////////////// +jstring org::xwt::plat::Win32::_getEnv(jstring key) { + int len = JvGetStringUTFLength(key); + char buf[len + 1]; + JvGetStringUTFRegion(key, 0, len, buf); + buf[len] = '\0'; + char buf2[1024]; + DWORD ret = GetEnvironmentVariable(buf, buf2, 1024); + if (ret > 0 && ret < 1024) return JvNewStringLatin1(buf2); + return NULL; +} + jstring org::xwt::plat::Win32::_fileDialog(jstring suggestedFileName, jboolean write) { char buf[1024]; @@ -602,7 +613,7 @@ void org::xwt::plat::Win32$Win32Surface::natInit(jboolean framed) { hdc = (jint)GetDC((HWND)hwnd); } -void org::xwt::plat::Win32$Win32Surface::finalize() { /* DeleteObject((void*)hwnd); */ } +void org::xwt::plat::Win32$Win32Surface::finalize() { DeleteObject((void*)hwnd); } void org::xwt::plat::Win32$Win32Surface::toFront() { BringWindowToTop((HWND)hwnd); } void org::xwt::plat::Win32$Win32Surface::toBack() { SetWindowPos((HWND)hwnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); } void org::xwt::plat::Win32$Win32Surface::_dispose() { PostMessage((HWND)hwnd, WM_USER_DISPOSE, 0, 0); } diff --git a/src/org/xwt/plat/Win32.java b/src/org/xwt/plat/Win32.java index 421e34a..9717e96 100644 --- a/src/org/xwt/plat/Win32.java +++ b/src/org/xwt/plat/Win32.java @@ -107,6 +107,7 @@ public class Win32 extends GCJ { // Implementation of Platform methods ///////////////////////////////////////////////////////// + protected native String _getEnv(String key); protected boolean _needsAutoClick() { return true; } protected String getDescriptiveName() { return "GCJ Win32 Binary"; } protected Surface _createSurface(Box b, boolean framed) { return new Win32Surface(b, framed); } -- 1.7.10.4