From b8f3061fd5b7039b3594f18c6831d62d3275c9b5 Mon Sep 17 00:00:00 2001 From: Grant Gayed Date: Fri, 24 Feb 2012 15:42:13 -0500 Subject: handle missing Arch variable on 32-bit Mac --- .../org/eclipse/swt/internal/Library.java | 36 ++++++++++++++++++++++ .../org/eclipse/swt/internal/Library.java | 13 ++++---- bundles/org.eclipse.swt/buildFragment.xml | 9 ++++-- 3 files changed, 50 insertions(+), 8 deletions(-) (limited to 'bundles') diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/common_j2me/org/eclipse/swt/internal/Library.java b/bundles/org.eclipse.swt/Eclipse SWT PI/common_j2me/org/eclipse/swt/internal/Library.java index ecf1082c9f..1c06357c14 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/common_j2me/org/eclipse/swt/internal/Library.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/common_j2me/org/eclipse/swt/internal/Library.java @@ -10,6 +10,10 @@ *******************************************************************************/ package org.eclipse.swt.internal; +import java.io.*; +import java.net.*; +import java.util.jar.*; + public class Library { /* SWT Version - Mmmm (M=major, mmm=minor) */ @@ -83,6 +87,38 @@ public static int SWT_VERSION (int major, int minor) { return major * 1000 + minor; } +static boolean isLoadable () { + URL url = Platform.class.getClassLoader ().getResource ("org/eclipse/swt/internal/Library.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)); + + Attributes attributes = null; + try { + JarFile jar = new JarFile (file); + attributes = jar.getManifest ().getMainAttributes (); + } catch (IOException e) { + /* should never happen for a valid SWT jar with the expected manifest values */ + return false; + } + + String os = System.getProperty ("os.name"); //$NON-NLS-1$; + String arch = System.getProperty ("os.arch"); //$NON-NLS-1$ + String manifestOS = attributes.getValue ("SWT-OS"); //$NON-NLS-1$ + String manifestArch = attributes.getValue ("SWT-Arch"); //$NON-NLS-1$ + return arch.equals (manifestArch) && os.equals (manifestOS); +} + /** * Loads the shared library that matches the version of the * Java code which is currently running. SWT shared libraries diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/common_j2se/org/eclipse/swt/internal/Library.java b/bundles/org.eclipse.swt/Eclipse SWT PI/common_j2se/org/eclipse/swt/internal/Library.java index f46ad3d27d..c7c79a115b 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/common_j2se/org/eclipse/swt/internal/Library.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/common_j2se/org/eclipse/swt/internal/Library.java @@ -189,20 +189,21 @@ static boolean isLoadable () { return false; } - String libraryOS = os (); - String libraryArch = arch (); + String os = os (); + String arch = arch (); String manifestOS = attributes.getValue ("SWT-OS"); //$NON-NLS-1$ String manifestArch = attributes.getValue ("SWT-Arch"); //$NON-NLS-1$ - if (libraryArch.equals (manifestArch) && libraryOS.equals (manifestOS)) { + if (arch.equals (manifestArch) && os.equals (manifestOS)) { return true; } /* * Mac has a special case since SWT's 32-bit libraries on Mac contain natives - * for both the x86 and PPC architectures. + * for both the x86 and PPC architectures. For this reason SWT's manifest file + * for 32-bit Mac does not specify a value for SWT-Arch. */ - if (libraryOS.equals ("macosx") && libraryOS.equals (manifestOS)) { - return manifestArch.equals ("x86") && libraryArch.equals ("ppc"); //$NON-NLS-1$ //$NON-NLS-2$ + if (os.equals ("macosx") && os.equals (manifestOS)) { //$NON-NLS-1$ + return manifestArch.length () == 0 && (arch.equals ("ppc") || arch.equals ("x86")); //$NON-NLS-1$ //$NON-NLS-2$ } return false; } diff --git a/bundles/org.eclipse.swt/buildFragment.xml b/bundles/org.eclipse.swt/buildFragment.xml index 6363a9c71b..3c2d3ee793 100644 --- a/bundles/org.eclipse.swt/buildFragment.xml +++ b/bundles/org.eclipse.swt/buildFragment.xml @@ -491,10 +491,14 @@ + + + - + + @@ -506,7 +510,8 @@ - + + -- cgit