static boolean tryLoad(boolean withLinuxVendor, StringBuffer message) { String libShortName = computeLibraryShortName(withLinuxVendor); String libFullName = computeLibraryFullName(withLinuxVendor); String ideLocation = System.getProperty("user.dir") + SEPARATOR + "jni" + SEPARATOR + libFullName; /* Try loading library from java library path */ if (load(libFullName, message)) { return true; } if (load(libShortName, message)) { return true; } /* Try loading library from the IDE location */ if (new File(ideLocation).exists()) { if (load(ideLocation, message)) { return true; } } return false; }
static boolean extract(String libPath, boolean withLinuxVendor, StringBuffer message) { String libFullName = computeLibraryFullName(withLinuxVendor); return extract(libPath + SEPARATOR + libFullName, libFullName, message); }
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 ( isAndroid() ) { System.loadLibrary("j2v8"); return; String libShortName = computeLibraryShortName(); String libFullName = computeLibraryFullName(); String ideLocation = System.getProperty("user.dir") + SEPARATOR + "jni" + SEPARATOR + computeLibraryFullName(); String path = null; if (load(libShortName, message)) { return; if (load(ideLocation, message)) { return; if (extract(path + SEPARATOR + libFullName, libFullName, message)) { return;
static String getOSFileExtension() { if (isWindows()) { return "dll"; } else if (isMac()) { return "dylib"; } else if (isLinux()) { return "so"; } else if (isNativeClient()) { return "so"; } throw new UnsatisfiedLinkError("Unsupported platform: " + getOsName()); }
private void performTests(final String expectedOsName, final String expectedVendor, final String expectedLibExtension) { String libName = LibraryLoader.computeLibraryShortName(true); String[] parts = libName.split("-"); libName = LibraryLoader.computeLibraryShortName(false); parts = libName.split("-"); libName = LibraryLoader.computeLibraryFullName(false);
private static void checkNativeLibraryLoaded() { if (!nativeLibraryLoaded) { String vendorName = LibraryLoader.computeLibraryShortName(true); String baseName = LibraryLoader.computeLibraryShortName(false); String message = "J2V8 native library not loaded (" + baseName + "/" + vendorName + ")"; if (nativeLoadError != null) { throw new IllegalStateException(message, nativeLoadError); } else if (nativeLoadException != null) { throw new IllegalStateException(message, nativeLoadException); } else { throw new IllegalStateException(message); } } }
private static String computeLibraryFullName() { return "lib" + computeLibraryShortName() + "." + getOSFileExtension(); }
private synchronized static void load(final String tmpDirectory) { try { LibraryLoader.loadLibrary(tmpDirectory); nativeLibraryLoaded = true; } catch (Error e) { nativeLoadError = e; } catch (Exception e) { nativeLoadException = e; } }
static boolean isWindows() { return getOsName().startsWith("Windows"); }
private static String computeLibraryShortName() { String base = "j2v8"; String osSuffix = getOS(); String archSuffix = getArchSuffix(); return base + "_" + osSuffix + "_" + archSuffix; }
static void loadLibrary(final String tempDirectory) { if ( isAndroid() ) { System.loadLibrary("j2v8"); return; String libShortName = computeLibraryShortName(); String libFullName = computeLibraryFullName(); String ideLocation = System.getProperty("user.dir") + SEPARATOR + "jni" + SEPARATOR + computeLibraryFullName(); String path = null; if (load(libShortName, message)) { return; if (load(ideLocation, message)) { return; if (extract(path + SEPARATOR + libFullName, libFullName, message)) { return;
static String getOSFileExtension() { if (isWindows()) { return "dll"; } else if (isMac()) { return "dylib"; } else if (isLinux()) { return "so"; } else if (isNativeClient()) { return "so"; } throw new UnsatisfiedLinkError("Unsupported platform: " + getOsName()); }
public static String computeLibraryFullName(boolean withLinuxVendor) { return "lib" + computeLibraryShortName(withLinuxVendor) + "." + PlatformDetector.OS.getLibFileExtension(); }
private static String computeLibraryFullName() { return "lib" + computeLibraryShortName() + "." + getOSFileExtension(); }
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$ }
private synchronized static void load(final String tmpDirectory) { try { LibraryLoader.loadLibrary(tmpDirectory); nativeLibraryLoaded = true; } catch (Error e) { nativeLoadError = e; } catch (Exception e) { nativeLoadException = e; } }