Last active
August 29, 2015 14:14
-
-
Save fab1an/34acabfa0af96f3f4d34 to your computer and use it in GitHub Desktop.
Capsule/Caplet for multi-platform SWT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static com.google.common.base.Preconditions.checkState; | |
import java.nio.file.Path; | |
import java.util.Iterator; | |
import java.util.List; | |
public final class SWTLoader extends Capsule { | |
// ~ Constructors ---------------------------------------------------------------------------------------------- | |
protected SWTLoader(final Capsule pred) { | |
super(pred); | |
} | |
// ~ Methods --------------------------------------------------------------------------------------------------- | |
@Override | |
protected List<Path> buildClassPath() { | |
List<Path> path = super.buildClassPath(); | |
String dataModel = System.getProperty("sun.arch.data.model"); | |
log(LOG_DEBUG, "sun.arch.data.model: '" + dataModel + "'"); | |
boolean bit64 = false; | |
if (dataModel.equals("32")) { | |
bit64 = false; | |
} else if (dataModel.equals("64")) { | |
bit64 = true; | |
} else { | |
checkState(false, "unknown data-model: '%s'", dataModel); | |
} | |
Iterator<Path> myIt = path.iterator(); | |
while (myIt.hasNext()) { | |
Path p = myIt.next(); | |
if (p.toString() | |
.contains("org.eclipse.swt.win32.win32.x86_64-")) { | |
if (!isWindows() || !bit64) { | |
log(LOG_DEBUG, "removed " + p); | |
myIt.remove(); | |
} | |
} | |
if (p.toString() | |
.contains("org.eclipse.swt.win32.win32.x86-")) { | |
if (!isWindows() || bit64) { | |
log(LOG_DEBUG, "removed " + p); | |
myIt.remove(); | |
} | |
} | |
if (p.toString() | |
.contains("org.eclipse.swt.cocoa.macosx.x86_64-")) { | |
if (!isMac()) { | |
log(LOG_DEBUG, "removed " + p); | |
myIt.remove(); | |
} | |
} | |
} | |
return path; | |
} | |
@Override | |
protected List<String> buildJVMArgs() { | |
List<String> args = super.buildJVMArgs(); | |
if (isMac()) { | |
args.add("-XstartOnFirstThread"); | |
} | |
return args; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment