public static boolean isAndroid() { return getName().equals(Platform.ANDROID); }
public static boolean isMac() { return getName().equals(Platform.MACOSX); }
public static boolean isLinux() { return getName().equals(Platform.LINUX); }
public static boolean isNativeClient() { return getName().equals(Platform.NATIVE_CLIENT); }
private static boolean skipTest() { return "android".equalsIgnoreCase(PlatformDetector.OS.getName()); }
public static String getLibFileExtension() { if (isWindows()) { return "dll"; } if (isMac()) { return "dylib"; } if (isLinux() || isAndroid() || isNativeClient()) { return "so"; } throw new UnsatisfiedLinkError("Unsupported platform library-extension for: " + getName()); } }
public static boolean isAndroid() { return getName().equals(Platform.ANDROID); }
private static boolean skipTest() { return "android".equalsIgnoreCase(PlatformDetector.OS.getName()); }
public static boolean isLinux() { return getName().equals(Platform.LINUX); }
public static boolean isWindows() { return getName().equals(Platform.WINDOWS); }
public static boolean isMac() { return getName().equals(Platform.MACOSX); }
@Test public void testGetOSUnknown() { assumeFalse(skipMessage, skipTest()); // conditional skip System.setProperty("os.name", "???"); System.setProperty("java.specification.vendor", "???"); try { PlatformDetector.OS.getName(); } catch (Error e) { assertTrue("Expected UnsatisfiedLinkError", e instanceof UnsatisfiedLinkError); assertTrue(e.getMessage().startsWith("Unsupported platform/vendor")); return; } fail("Expected exception"); }
@Test public void testGetOSWindows() { assumeFalse(skipMessage, skipTest()); // conditional skip System.setProperty("os.name", "Windows"); System.setProperty("java.specification.vendor", "Microsoft"); assertEquals("windows", PlatformDetector.OS.getName()); }
@Test public void testGetOSMac() { assumeFalse(skipMessage, skipTest()); // conditional skip System.setProperty("os.name", "Mac OS X"); System.setProperty("java.specification.vendor", "Apple"); assertEquals("macosx", PlatformDetector.OS.getName()); }
@Test public void testGetOSAndroid() { System.setProperty("os.name", "Linux"); System.setProperty("java.specification.vendor", "The Android Project"); assertEquals("android", PlatformDetector.OS.getName()); }
@Test public void testGetOSLinux() { assumeFalse(skipMessage, skipTest()); // conditional skip System.setProperty("os.name", "Linux"); System.setProperty("java.specification.vendor", "OSS"); assertEquals("linux", PlatformDetector.OS.getName()); }
/** * Returns the base-name for the native J2V8 library file. * @param withLinuxVendor include/exclude the {vendor} part from the returned filename * <p>NOTE: Vendors are only included for linux systems</p> * @return The filename string has the following structure: * <pre><code>{arch}-[vendor]-{operating_system}</pre></code> */ public static String computeLibraryShortName(boolean withLinuxVendor) { String prefix = "j2v8"; String vendor = withLinuxVendor && PlatformDetector.OS.isLinux() ? PlatformDetector.Vendor.getName() : null; String os = PlatformDetector.OS.getName(); String arch = PlatformDetector.Arch.getName(); final String separator = "-"; return prefix + (vendor != null ? separator + vendor : "") + separator + os + separator + arch; }
public static String getLibFileExtension() { if (isWindows()) { return "dll"; } if (isMac()) { return "dylib"; } if (isLinux() || isAndroid() || isNativeClient()) { return "so"; } throw new UnsatisfiedLinkError("Unsupported platform library-extension for: " + getName()); } }
public static boolean isNativeClient() { return getName().equals(Platform.NATIVE_CLIENT); }
public static boolean isWindows() { return getName().equals(Platform.WINDOWS); }