Fixes issue 20

org.xerial.snappy.enable.bundled.libs is used with the default value = true.
This commit is contained in:
Taro L. Saito 2011-08-16 11:16:21 +09:00
parent c73d2e104b
commit 6540318a12
2 changed files with 33 additions and 33 deletions

View File

@ -85,7 +85,7 @@ public class SnappyLoader
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_TEMPDIR = "org.xerial.snappy.tempdir";
public static final String KEY_SNAPPY_DISABLE_BUNDLED_LIBS = "org.xerial.snappy.disable.bundled.libs";
public static final String KEY_SNAPPY_ENABLE_BUNDLED_LIBS = "org.xerial.snappy.enable.bundled.libs";
private static boolean isLoaded = false;
private static SnappyNativeAPI api = null;
@ -364,7 +364,7 @@ public class SnappyLoader
String snappyNativeLibraryPath = System.getProperty(KEY_SNAPPY_LIB_PATH);
String snappyNativeLibraryName = System.getProperty(KEY_SNAPPY_LIB_NAME);
if (System.getProperty(KEY_SNAPPY_DISABLE_BUNDLED_LIBS, "false").equals("false")) {
if (System.getProperty(KEY_SNAPPY_ENABLE_BUNDLED_LIBS, "true").equals("true")) {
// Resolve the library file name with a suffix (e.g., dll, .so, etc.)
if (snappyNativeLibraryName == null)
snappyNativeLibraryName = System.mapLibraryName("snappyjava");
@ -374,7 +374,6 @@ public class SnappyLoader
if (nativeLib.exists())
return nativeLib;
}
}
{
// Load an OS-dependent native library inside a jar file
@ -389,8 +388,9 @@ public class SnappyLoader
return extractLibraryFile(snappyNativeLibraryPath, snappyNativeLibraryName, tempFolder);
}
}
}
return null;
return null; // Use a pre-installed snappyjava
}
public static String getVersion() {

View File

@ -95,29 +95,29 @@ public class SnappyLoaderTest
ClassRealm L1 = cw.newRealm("l1", URLClassLoader.newInstance(new URL[] { classPath }, parent));
ClassRealm L2 = cw.newRealm("l2", URLClassLoader.newInstance(new URL[] { classPath }, parent));
// Actually load Snappy.class in a class loader
try {
// Actually load Snappy.class in a child class loader
Class< ? > S1 = L1.loadClass("org.xerial.snappy.Snappy");
Method m = S1.getMethod("getNativeLibraryVersion");
String v = (String) m.invoke(null);
// Load Snappy.class from another class loader
// Load Snappy.class from another child class loader
Class< ? > S2 = L2.loadClass("org.xerial.snappy.Snappy");
Method m2 = S2.getMethod("getNativeLibraryVersion");
String v2 = (String) m2.invoke(null);
assertEquals(v, v2);
}
catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void load() throws Exception {
SnappyLoader.load();
_logger.debug(Snappy.getNativeLibraryVersion());
}
public static void main(String[] args) {
// Test for loading native library specified in -Djava.library.path
System.setProperty(SnappyLoader.KEY_SNAPPY_ENABLE_BUNDLED_LIBS, "false");
_logger.debug(Snappy.getNativeLibraryVersion());
}
}