public static boolean isNativeClient() { return getName().equals(Platform.NATIVE_CLIENT); }
static void loadLibrary(final String tempDirectory) { if (PlatformDetector.OS.isAndroid()) { System.loadLibrary("j2v8"); return; } StringBuffer message = new StringBuffer(); // try loading a vendor-specific library first if (tryLoad(true, message)) return; // if there is no vendor-specific library, just try to load the default OS library if (tryLoad(false, message)) return; String path = null; if (tempDirectory != null) { path = tempDirectory; } else { path = System.getProperty("java.io.tmpdir"); //$NON-NLS-1$ } // try extracting a vendor-specific library first if (extract(path, true, message)) return; // if there is no vendor-specific library, just try to extract the default OS library if (extract(path, false, message)) return; /* Failed to find the library */ throw new UnsatisfiedLinkError("Could not load J2V8 library. Reasons: " + message.toString()); //$NON-NLS-1$ }
static void loadLibrary(final String tempDirectory) { if (PlatformDetector.OS.isAndroid()) { System.loadLibrary("j2v8"); return; } StringBuffer message = new StringBuffer(); // try loading a vendor-specific library first if (tryLoad(true, message)) return; // if there is no vendor-specific library, just try to load the default OS library if (tryLoad(false, message)) return; String path = null; if (tempDirectory != null) { path = tempDirectory; } else { path = System.getProperty("java.io.tmpdir"); //$NON-NLS-1$ } // try extracting a vendor-specific library first if (extract(path, true, message)) return; // if there is no vendor-specific library, just try to extract the default OS library if (extract(path, false, message)) return; /* Failed to find the library */ throw new UnsatisfiedLinkError("Could not load J2V8 library. Reasons: " + message.toString()); //$NON-NLS-1$ }
@Test public void testLinuxLibNameStructure() throws Exception { // skip this test on android if (PlatformDetector.OS.isAndroid()) { return; } System.setProperty("os.name", "Linux"); System.setProperty("java.specification.vendor", "OSS"); System.setProperty("os.arch", "x64"); final String os_release_test_path = "./test-mockup-os-release"; final String test_vendor = "linux_vendor"; // mock /etc/os-release file releaseFilesField.set(null, new String[] { os_release_test_path }); PrintWriter out = new PrintWriter(os_release_test_path); out.println( "NAME=The-Linux-Vendor\n" + "VERSION=\"towel_42\"\n" + "ID=" + test_vendor + "\n" + "VERSION_ID=42\n" ); out.close(); performTests(Platform.LINUX, test_vendor, ".so"); }
/** * 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 boolean isNativeClient() { return getName().equals(Platform.NATIVE_CLIENT); }
private static boolean skipTest() { return "android".equalsIgnoreCase(PlatformDetector.OS.getName()); }
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"); }
public static String computeLibraryFullName(boolean withLinuxVendor) { return "lib" + computeLibraryShortName(withLinuxVendor) + "." + PlatformDetector.OS.getLibFileExtension(); }
public static boolean isLinux() { return getName().equals(Platform.LINUX); }
public static boolean isWindows() { return getName().equals(Platform.WINDOWS); }
public static boolean isAndroid() { return getName().equals(Platform.ANDROID); }
private static boolean skipTest() { return "android".equalsIgnoreCase(PlatformDetector.OS.getName()); }
@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 testGetOSFileExtensionAndroid() { System.setProperty("os.name", "naclthe android project"); System.setProperty("java.specification.vendor", "The Android Project"); assertEquals("so", PlatformDetector.OS.getLibFileExtension()); }
@Test public void testGetOSAndroid() { System.setProperty("os.name", "Linux"); System.setProperty("java.specification.vendor", "The Android Project"); assertEquals("android", PlatformDetector.OS.getName()); }