Skip to content

Commit 28eecf2

Browse files
committed
Avoid compatibility check failure for Uber JARs and Universal Binaries
When packaging SWT into an Uber Jar or using universal binaries (for multiple architectures), the Jar manifest cannot reference a single OS and/or architecture. As a result, the compatibility check implemented in Library.isLaodable() can never succeed for such a packaging. With those compatibility checks always being executed upon initialization of SWT with a recent change, using such packaging of SWT became difficult or impossible. This change makes the initialization of SWT not fail in case the JAR manifest is completely lacking the according entries for OS and architecture. This will still make the initialization fail if an OS and/or architecture is specified in the manifest that is incompatible to the current environment, but in case the manifest does not contain such entries, the library will just (try to) boot. The behavior of Platform.isLoadable() is preserved. That method will still return false in case the Manifest does not contain according entries, as this is the long-standing behavior of that method. Fixes #2928
1 parent 588e560 commit 28eecf2

4 files changed

Lines changed: 14 additions & 12 deletions

File tree

bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/Platform.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static boolean isLoadable () {
2121
}
2222

2323
public static void exitIfNotLoadable() {
24-
if (!Library.isLoadable ()) {
24+
if (!Library.isLoadable (true)) {
2525
System.err.println("Libraries for platform " + Platform.PLATFORM + " cannot be loaded because of incompatible environment");
2626
System.exit(1);
2727
}

bundles/org.eclipse.swt/Eclipse SWT PI/common/org/eclipse/swt/internal/Library.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,10 @@
1313
*******************************************************************************/
1414
package org.eclipse.swt.internal;
1515

16-
import java.io.File;
17-
import java.io.IOException;
18-
import java.io.InputStream;
19-
import java.net.JarURLConnection;
20-
import java.net.URL;
21-
import java.net.URLConnection;
22-
import java.nio.file.Files;
23-
import java.nio.file.StandardCopyOption;
24-
import java.util.jar.Attributes;
16+
import java.io.*;
17+
import java.net.*;
18+
import java.nio.file.*;
19+
import java.util.jar.*;
2520

2621
public class Library {
2722

@@ -192,6 +187,10 @@ static boolean extract (String extractToFilePath, String mappedName) {
192187
}
193188

194189
static boolean isLoadable () {
190+
return isLoadable(false);
191+
}
192+
193+
static boolean isLoadable (boolean ignoreMissingManifest) {
195194
URL url = Platform.class.getClassLoader ().getResource ("org/eclipse/swt/internal/Library.class"); //$NON-NLS-1$
196195
if (!url.getProtocol ().equals ("jar")) { //$NON-NLS-1$
197196
/* SWT is presumably running in a development environment */
@@ -218,6 +217,9 @@ static boolean isLoadable () {
218217
if (arch.equals (manifestArch) && os.equals (manifestOS)) {
219218
return true;
220219
}
220+
if (manifestArch == null && manifestOS == null && ignoreMissingManifest) {
221+
return true;
222+
}
221223

222224
return false;
223225
}

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/Platform.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static boolean isLoadable () {
2222
}
2323

2424
public static void exitIfNotLoadable() {
25-
if (!Library.isLoadable ()) {
25+
if (!Library.isLoadable (true)) {
2626
System.err.println("Libraries for platform " + Platform.PLATFORM + " cannot be loaded because of incompatible environment");
2727
System.exit(1);
2828
}

bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/Platform.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static boolean isLoadable () {
2323
}
2424

2525
public static void exitIfNotLoadable() {
26-
if (!Library.isLoadable ()) {
26+
if (!Library.isLoadable (true)) {
2727
System.err.println("Libraries for platform " + Platform.PLATFORM + " cannot be loaded because of incompatible environment");
2828
System.exit(1);
2929
}

0 commit comments

Comments
 (0)