summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGrant Gayed <grant_gayed@ca.ibm.com>2012-02-23 10:42:28 -0500
committerGrant Gayed <grant_gayed@ca.ibm.com>2012-02-23 10:42:28 -0500
commitf1be364c1b97911cbcdda6fd507fc5d82efe8be0 (patch)
tree3bf3b379de93e5055c91da596195cea496791491
parent8d4da55406072249d48f3dfaa17c5286b0556072 (diff)
downloadeclipse.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
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/Platform.java40
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/Platform.java34
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/Platform.java40
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java15
-rw-r--r--bundles/org.eclipse.swt/buildFragment.xml21
5 files changed, 143 insertions, 7 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;
+}
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/Platform.java b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/Platform.java
index 7881f7080a..a334894c5c 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/Platform.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/Platform.java
@@ -14,7 +14,41 @@
*******************************************************************************/
package org.eclipse.swt.internal;
+import java.io.*;
+import java.net.*;
+import java.util.jar.*;
+
public class Platform {
public static final String PLATFORM = "gtk"; //$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;
+}
+
}
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;
+}
+
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java
index 399bf07e82..fc2f81950e 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java
@@ -4069,7 +4069,20 @@ public class SWT {
*/
public static final String SKIN_ID = "org.eclipse.swt.skin.id";
-
+/**
+ * Returns a boolean indicating whether this SWT implementation can
+ * be loaded. Examples of criteria that may be used to determine this
+ * include the OS and architecture of the JRE that is being used.
+ *
+ * @return <code>true</code> if this SWT implementation can be loaded
+ * and <code>false</code> otherwise
+ *
+ * @since 3.8
+ */
+public static boolean isLoadable () {
+ return Platform.IsLoadable ();
+}
+
/**
* Answers a concise, human readable description of the error code.
*
diff --git a/bundles/org.eclipse.swt/buildFragment.xml b/bundles/org.eclipse.swt/buildFragment.xml
index a983168835..6363a9c71b 100644
--- a/bundles/org.eclipse.swt/buildFragment.xml
+++ b/bundles/org.eclipse.swt/buildFragment.xml
@@ -491,14 +491,24 @@
<param name="debug" value="true" />
<param name="jar.filename" value="swt-debug.jar" />
</antcall>
- <jar jarfile="${build.result.folder}/swt-debug.jar" basedir="${fragmentdir}" update="true" includes="swt*.dll,libswt*.so,libswt*.sl,libswt*.a,libswt*.jnilib,libXm.so.2" />
+ <jar jarfile="${build.result.folder}/swt-debug.jar" basedir="${fragmentdir}" update="true" includes="swt*.dll,libswt*.so,libswt*.sl,libswt*.a,libswt*.jnilib,libXm.so.2">
+ <manifest>
+ <attribute name="SWT-OS" value="${swt.os}"/>
+ <attribute name="SWT-Arch" value="${swt.arch}"/>
+ </manifest>
+ </jar>
<copy file="${build.result.folder}/swt-debug.jar" todir="${temp.folder}/swtdownload" />
<delete dir="${build.result.folder}/@dot" />
<antcall target="build.jars">
<param name="debug" value="false" />
<param name="jar.filename" value="swt.jar" />
</antcall>
- <jar jarfile="${build.result.folder}/swt.jar" basedir="${fragmentdir}" update="true" includes="swt*.dll,libswt*.so,libswt*.sl,libswt*.a,libswt*.jnilib,libXm.so.2" />
+ <jar jarfile="${build.result.folder}/swt.jar" basedir="${fragmentdir}" update="true" includes="swt*.dll,libswt*.so,libswt*.sl,libswt*.a,libswt*.jnilib,libXm.so.2">
+ <manifest>
+ <attribute name="SWT-OS" value="${swt.os}"/>
+ <attribute name="SWT-Arch" value="${swt.arch}"/>
+ </manifest>
+ </jar>
<copy file="${build.result.folder}/swt.jar" todir="${temp.folder}/swtdownload" />
<antcall target="build.sources" />
<copy file="${build.result.folder}/src.zip" todir="${temp.folder}/swtdownload" />
@@ -553,7 +563,12 @@
<antcall target="gather.bin.parts">
<param name="destination.temp.folder" value="${temp.folder}/" />
</antcall>
- <jar jarfile="${plugin.destination}/${full.name}.jar" basedir="${temp.folder}/${full.name}" filesonly="true" manifest="${fragmentdir}/META-INF/MANIFEST.MF"/>
+ <jar jarfile="${plugin.destination}/${full.name}.jar" basedir="${temp.folder}/${full.name}" filesonly="true" manifest="${fragmentdir}/META-INF/MANIFEST.MF">
+ <manifest>
+ <attribute name="SWT-OS" value="${swt.os}"/>
+ <attribute name="SWT-Arch" value="${swt.arch}"/>
+ </manifest>
+ </jar>
<delete dir="${temp.folder}" />
</target>