Last active
March 9, 2017 06:10
-
-
Save fab1an/34d418143a1d42227c0d50da15cc8f0d to your computer and use it in GitHub Desktop.
Caplet: changing JVM classpath according to platform and architecture
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.util.ArrayList; | |
import java.util.Iterator; | |
import java.util.List; | |
import java.util.Map.Entry; | |
public final class SWTLoader extends Capsule { | |
// ~ Constructors ---------------------------------------------------------------------------------------------- | |
protected SWTLoader(final Capsule pred) { | |
super(pred); | |
} | |
// ~ Methods --------------------------------------------------------------------------------------------------- | |
@Override | |
@SuppressWarnings("unchecked") | |
protected <T> T attribute(final Entry<String, T> attr) { | |
if (ATTR_JVM_ARGS == attr && isMac()) { | |
final List<String> args = new ArrayList<>(super.attribute(ATTR_JVM_ARGS)); | |
args.add("-XstartOnFirstThread"); | |
return (T) args; | |
} else if (ATTR_APP_CLASS_PATH == attr) { | |
List<Object> appClassPath = new ArrayList<>(super.attribute(ATTR_APP_CLASS_PATH)); | |
appClassPath.set(1, new ArrayList<>((List<Object>) appClassPath.get(1))); | |
String dataModel = System.getProperty("sun.arch.data.model"); | |
boolean bit64 = false; | |
switch (dataModel) { | |
case "32": | |
bit64 = false; | |
break; | |
case "64": | |
bit64 = true; | |
break; | |
default: | |
checkState(false, "unknown data-model: '%s'", dataModel); | |
break; | |
} | |
Iterator<Object> myIt = ((List<Object>) appClassPath.get(1)).iterator(); | |
while (myIt.hasNext()) { | |
Object 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 (T) appClassPath; | |
} else { | |
return super.attribute(attr); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment