diff options
author | Grant Gayed <grant_gayed@ca.ibm.com> | 2012-02-23 10:42:28 -0500 |
---|---|---|
committer | Grant Gayed <grant_gayed@ca.ibm.com> | 2012-02-23 10:42:28 -0500 |
commit | f1be364c1b97911cbcdda6fd507fc5d82efe8be0 (patch) | |
tree | 3bf3b379de93e5055c91da596195cea496791491 /bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal | |
parent | 8d4da55406072249d48f3dfaa17c5286b0556072 (diff) | |
download | eclipse.platform.swt-f1be364c1b97911cbcdda6fd507fc5d82efe8be0.tar.gz eclipse.platform.swt-f1be364c1b97911cbcdda6fd507fc5d82efe8be0.tar.xz eclipse.platform.swt-f1be364c1b97911cbcdda6fd507fc5d82efe8be0.zip |
Bug 292062 - Provide a way to dynamically introspect an SWT port info
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal')
-rw-r--r-- | bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/Platform.java | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/Platform.java b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/Platform.java index 9fae8d8b3b..39cb197c22 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/Platform.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/Platform.java @@ -10,8 +10,42 @@ *******************************************************************************/ package org.eclipse.swt.internal; +import java.io.*; +import java.net.*; +import java.util.jar.*; + public class Platform { - -public static final String PLATFORM = "win32"; //$NON-NLS-1$ -public static final Lock lock = new Lock (); + + public static final String PLATFORM = "win32"; //$NON-NLS-1$ + public static final Lock lock = new Lock (); + +public static boolean IsLoadable () { + URL url = Platform.class.getClassLoader ().getResource ("org/eclipse/swt/SWT.class"); //$NON-NLS-1$ + if (!url.getProtocol ().equals ("jar")) { //$NON-NLS-1$ + /* SWT is presumably running in a development environment */ + return true; + } + + try { + url = new URL (url.getPath ()); + } catch (MalformedURLException e) { + /* should never happen since url's initial path value must be valid */ + } + String path = url.getPath (); + int index = path.indexOf ('!'); + File file = new File (path.substring (0, index)); + + try { + JarFile jar = new JarFile (file); + Manifest manifest = jar.getManifest (); + Attributes attributes = manifest.getMainAttributes (); + return Library.arch ().equals (attributes.getValue ("SWT-Arch")) && //$NON-NLS-1$ + Library.os ().equals (attributes.getValue ("SWT-OS")); //$NON-NLS-1$ + } catch (IOException e) { + /* should never happen for a valid SWT jar with the expected manifest values */ + } + + return false; +} + } |