| 42 | |
| 43 | |
| 44 | public class Platform { |
| 45 | static DefaultPlatform inst; |
| 46 | |
| 47 | /* |
| 48 | static Map<Integer, String> platformNames = new HashMap<>(); |
| 49 | static { |
| 50 | platformNames.put(PConstants.WINDOWS, "windows"); //$NON-NLS-1$ |
| 51 | platformNames.put(PConstants.MACOS, "macos"); //$NON-NLS-1$ |
| 52 | platformNames.put(PConstants.LINUX, "linux"); //$NON-NLS-1$ |
| 53 | } |
| 54 | */ |
| 55 | |
| 56 | // TODO only used in one place, probably overkill for this to be a map |
| 57 | static Map<String, Integer> platformIndices = new HashMap<>(); |
| 58 | static { |
| 59 | platformIndices.put("windows", PConstants.WINDOWS); //$NON-NLS-1$ |
| 60 | platformIndices.put("macos", PConstants.MACOS); //$NON-NLS-1$ |
| 61 | platformIndices.put("linux", PConstants.LINUX); //$NON-NLS-1$ |
| 62 | } |
| 63 | |
| 64 | /** How many bits this machine is */ |
| 65 | static int nativeBits; |
| 66 | static { |
| 67 | nativeBits = 32; // perhaps start with 32 |
| 68 | String bits = System.getProperty("sun.arch.data.model"); //$NON-NLS-1$ |
| 69 | if (bits != null) { |
| 70 | if (bits.equals("64")) { //$NON-NLS-1$ |
| 71 | nativeBits = 64; |
| 72 | } |
| 73 | } else { |
| 74 | // if some other strange vm, maybe try this instead |
| 75 | if (System.getProperty("java.vm.name").contains("64")) { //$NON-NLS-1$ //$NON-NLS-2$ |
| 76 | nativeBits = 64; |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | |
| 82 | // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
| 83 | |
| 84 | |
| 85 | static public boolean isAvailable() { |
| 86 | return inst != null; |
| 87 | } |
| 88 | |
| 89 | |
| 90 | static public void init() { |
| 91 | try { |
| 92 | // Start with DefaultPlatform, but try to upgrade to a known platform |
| 93 | final String packageName = DefaultPlatform.class.getPackageName(); |
| 94 | Class<?> platformClass = |
| 95 | Class.forName(packageName + ".DefaultPlatform"); |
| 96 | |
| 97 | if (Platform.isMacOS()) { |
| 98 | platformClass = Class.forName(packageName + ".MacPlatform"); |
| 99 | } else if (Platform.isWindows()) { |
| 100 | platformClass = Class.forName(packageName + ".WindowsPlatform"); |
| 101 | } else if (Platform.isLinux()) { |