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/cocoa | |
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/cocoa')
-rw-r--r-- | bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/Platform.java | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/Platform.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/Platform.java index ef6bfb1040..d0d35b454e 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/Platform.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/Platform.java @@ -10,8 +10,48 @@ *******************************************************************************/ package org.eclipse.swt.internal; +import java.io.*; +import java.net.*; +import java.util.jar.*; + public class Platform { public static final String PLATFORM = "cocoa"; //$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 (); + + /* + * Cocoa has a special case since SWT's 32-bit library contains natives for both the + * x86 and PPC architectures. + */ + if (!Library.os ().equals (attributes.getValue ("SWT-OS"))) return false; //$NON-NLS-1$ + String libraryArch = Library.arch (); + String manifestArch = attributes.getValue ("SWT-Arch"); //$NON-NLS-1$ + return libraryArch.equals (manifestArch) || (manifestArch.equals ("x86") && libraryArch.equals ("ppc")); //$NON-NLS-1$ //$NON-NLS-2$ + } catch (IOException e) { + /* should never happen for a valid SWT jar with the expected manifest values */ + } + + return false; +} } |