Fixes issue 20

Applied a patch from tucu to disable the default behaviour with a JVM option org.xerial.snappy.disable.bundled.libs.
This commit is contained in:
Taro L. Saito 2011-06-23 10:07:58 +09:00
parent ba8a761010
commit 1607113e36
2 changed files with 34 additions and 30 deletions

View File

@ -86,9 +86,10 @@ public class SnappyLoader
return isLoaded; return isLoaded;
} }
public static final String KEY_SNAPPY_LIB_PATH = "org.xerial.snappy.lib.path"; public static final String KEY_SNAPPY_LIB_PATH = "org.xerial.snappy.lib.path";
public static final String KEY_SNAPPY_LIB_NAME = "org.xerial.snappy.lib.name"; public static final String KEY_SNAPPY_LIB_NAME = "org.xerial.snappy.lib.name";
public static final String KEY_SNAPPY_TEMPDIR = "org.xerial.snappy.tempdir"; public static final String KEY_SNAPPY_TEMPDIR = "org.xerial.snappy.tempdir";
public static final String KEY_SNAPPY_DISABLE_BUNDLED_LIBS = "org.xerial.snappy.disable.bundled.libs";
/** /**
* Computes the MD5 value of the input stream * Computes the MD5 value of the input stream
@ -204,36 +205,39 @@ public class SnappyLoader
if (isLoaded) if (isLoaded)
return; return;
// Try loading the library from org.xerial.snappy.lib.path library path */ if (System.getProperty(KEY_SNAPPY_DISABLE_BUNDLED_LIBS, "false").equals("false")) {
String snappyNativeLibraryPath = System.getProperty(KEY_SNAPPY_LIB_PATH); // Try to load the library from org.xerial.snappy.lib.path library path */
String snappyNativeLibraryName = System.getProperty(KEY_SNAPPY_LIB_NAME); String snappyNativeLibraryPath = System.getProperty(KEY_SNAPPY_LIB_PATH);
String snappyNativeLibraryName = System.getProperty(KEY_SNAPPY_LIB_NAME);
// Resolve the library file name with a suffix (e.g., dll, .so, etc.) // Resolve the library file name with a suffix (e.g., dll, .so, etc.)
if (snappyNativeLibraryName == null) if (snappyNativeLibraryName == null)
snappyNativeLibraryName = System.mapLibraryName("snappyjava"); snappyNativeLibraryName = System.mapLibraryName("snappyjava");
if (snappyNativeLibraryPath != null) { if (snappyNativeLibraryPath != null) {
if (loadNativeLibrary(snappyNativeLibraryPath, snappyNativeLibraryName)) { if (loadNativeLibrary(snappyNativeLibraryPath, snappyNativeLibraryName)) {
isLoaded = true; isLoaded = true;
return; return;
}
}
// Load an OS-dependent native library inside a jar file
snappyNativeLibraryPath = "/org/xerial/snappy/native/" + OSInfo.getNativeLibFolderPathForCurrentOS();
if (SnappyLoader.class.getResource(snappyNativeLibraryPath + "/" + snappyNativeLibraryName) != null) {
// Temporary library folder. Use the value of org.xerial.snappy.tempdir or java.io.tmpdir
String tempFolder = new File(System.getProperty(KEY_SNAPPY_TEMPDIR,
System.getProperty("java.io.tmpdir"))).getAbsolutePath();
// Extract and load a native library inside the jar file
if (extractAndLoadLibraryFile(snappyNativeLibraryPath, snappyNativeLibraryName, tempFolder)) {
isLoaded = true;
return;
}
} }
} }
// Load an os-dependent native library inside a jar file // Try to load snappyjava DLL in LD_LIBRARY_PATH
snappyNativeLibraryPath = "/org/xerial/snappy/native/" + OSInfo.getNativeLibFolderPathForCurrentOS();
if (SnappyLoader.class.getResource(snappyNativeLibraryPath + "/" + snappyNativeLibraryName) != null) {
// Temporary library folder. Use the value of java.io.tmpdir
String tempFolder = new File(System.getProperty(KEY_SNAPPY_TEMPDIR, System.getProperty("java.io.tmpdir")))
.getAbsolutePath();
// Try extracting the library from jar
if (extractAndLoadLibraryFile(snappyNativeLibraryPath, snappyNativeLibraryName, tempFolder)) {
isLoaded = true;
return;
}
}
// Try to load snappyjava DLL in LD_PATH
try { try {
System.loadLibrary("snappyjava"); System.loadLibrary("snappyjava");
isLoaded = true; isLoaded = true;

View File

@ -41,8 +41,8 @@ public class SnappyLoaderTest
ClassRealm L1 = cw.newRealm("l1", parent); ClassRealm L1 = cw.newRealm("l1", parent);
ClassRealm L2 = cw.newRealm("l2", parent); ClassRealm L2 = cw.newRealm("l2", parent);
Class< ? > snappyClass = L1.loadClass("org.xerial.snappy.Snappy"); //Class< ? > snappyClass = L1.loadClass("org.xerial.snappy.Snappy"); // not found
_logger.info(snappyClass.getName()); //_logger.info(snappyClass.getName());
} }
} }