Revert to xerial-core-1.0.21 for compiling with JDK5
This commit is contained in:
parent
2097c32314
commit
d19a00ddb6
2
pom.xml
2
pom.xml
|
@ -229,7 +229,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.xerial</groupId>
|
<groupId>org.xerial</groupId>
|
||||||
<artifactId>xerial-core</artifactId>
|
<artifactId>xerial-core</artifactId>
|
||||||
<version>2.0.2</version>
|
<version>1.0.21</version>
|
||||||
<type>jar</type>
|
<type>jar</type>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
|
@ -24,72 +24,57 @@
|
||||||
//--------------------------------------
|
//--------------------------------------
|
||||||
package org.xerial.snappy;
|
package org.xerial.snappy;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.security.ProtectionDomain;
|
|
||||||
|
|
||||||
import javassist.ClassPool;
|
|
||||||
import javassist.CtClass;
|
|
||||||
import javassist.CtField;
|
|
||||||
import javassist.CtNewMethod;
|
|
||||||
|
|
||||||
import org.codehaus.plexus.classworlds.ClassWorld;
|
|
||||||
import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.xerial.util.FileResource;
|
|
||||||
import org.xerial.util.log.Logger;
|
import org.xerial.util.log.Logger;
|
||||||
|
|
||||||
public class SnappyLoaderTest
|
public class SnappyLoaderTest
|
||||||
{
|
{
|
||||||
private static Logger _logger = Logger.getLogger(SnappyLoaderTest.class);
|
private static Logger _logger = Logger.getLogger(SnappyLoaderTest.class);
|
||||||
|
|
||||||
@Ignore
|
// @Ignore
|
||||||
@Test
|
// @Test
|
||||||
public void loadFromSytemClassLoader() throws Exception {
|
// public void loadFromSytemClassLoader() throws Exception {
|
||||||
|
//
|
||||||
ClassLoader parent = this.getClass().getClassLoader().getParent();
|
// ClassLoader parent = this.getClass().getClassLoader().getParent();
|
||||||
ClassWorld cw = new ClassWorld();
|
// ClassWorld cw = new ClassWorld();
|
||||||
ClassRealm L1 = cw.newRealm("l1", parent);
|
// ClassRealm L1 = cw.newRealm("l1", parent);
|
||||||
ClassRealm L2 = cw.newRealm("l2", parent);
|
// ClassRealm L2 = cw.newRealm("l2", parent);
|
||||||
|
//
|
||||||
File nativeLib = SnappyLoader.findNativeLibrary();
|
// File nativeLib = SnappyLoader.findNativeLibrary();
|
||||||
assertNotNull(nativeLib);
|
// assertNotNull(nativeLib);
|
||||||
|
//
|
||||||
ClassPool pool = ClassPool.getDefault();
|
// ClassPool pool = ClassPool.getDefault();
|
||||||
CtClass cl = pool.makeClass("org.xerial.snappy.SnappyNativeLoader");
|
// CtClass cl = pool.makeClass("org.xerial.snappy.SnappyNativeLoader");
|
||||||
cl.addField(CtField.make("static boolean isLoaded = false;", cl));
|
// cl.addField(CtField.make("static boolean isLoaded = false;", cl));
|
||||||
String m1 = FileResource.loadIntoString(SnappyLoaderTest.class, "load.code");
|
// String m1 = FileResource.loadIntoString(SnappyLoaderTest.class, "load.code");
|
||||||
String m2 = FileResource.loadIntoString(SnappyLoaderTest.class, "loadLibrary.code");
|
// String m2 = FileResource.loadIntoString(SnappyLoaderTest.class, "loadLibrary.code");
|
||||||
cl.addMethod(CtNewMethod.make(m1, cl));
|
// cl.addMethod(CtNewMethod.make(m1, cl));
|
||||||
cl.addMethod(CtNewMethod.make(m2, cl));
|
// cl.addMethod(CtNewMethod.make(m2, cl));
|
||||||
|
//
|
||||||
ProtectionDomain systemPD = System.class.getProtectionDomain();
|
// ProtectionDomain systemPD = System.class.getProtectionDomain();
|
||||||
byte[] bytecode = cl.toBytecode();
|
// byte[] bytecode = cl.toBytecode();
|
||||||
FileOutputStream f = new FileOutputStream("src/main/resources/org/xerial/snappy/SnappyNativeLoader.bytecode");
|
// FileOutputStream f = new FileOutputStream("src/main/resources/org/xerial/snappy/SnappyNativeLoader.bytecode");
|
||||||
f.write(bytecode);
|
// f.write(bytecode);
|
||||||
f.close();
|
// f.close();
|
||||||
|
//
|
||||||
//Class< ? > loaderClass = cl.toClass(parent, System.class.getProtectionDomain());
|
// //Class< ? > loaderClass = cl.toClass(parent, System.class.getProtectionDomain());
|
||||||
//_logger.info(cl.getName());
|
// //_logger.info(cl.getName());
|
||||||
//Class< ? > loaderClass = cl.toClass();
|
// //Class< ? > loaderClass = cl.toClass();
|
||||||
|
//
|
||||||
Class< ? > classLoader = Class.forName("java.lang.ClassLoader");
|
// Class< ? > classLoader = Class.forName("java.lang.ClassLoader");
|
||||||
java.lang.reflect.Method defineClass = classLoader.getDeclaredMethod("defineClass", new Class[] { String.class,
|
// java.lang.reflect.Method defineClass = classLoader.getDeclaredMethod("defineClass", new Class[] { String.class,
|
||||||
byte[].class, int.class, int.class, ProtectionDomain.class });
|
// byte[].class, int.class, int.class, ProtectionDomain.class });
|
||||||
|
//
|
||||||
defineClass.setAccessible(true);
|
// defineClass.setAccessible(true);
|
||||||
defineClass.invoke(parent, cl.getName(), bytecode, 0, bytecode.length, System.class.getProtectionDomain());
|
// defineClass.invoke(parent, cl.getName(), bytecode, 0, bytecode.length, System.class.getProtectionDomain());
|
||||||
|
//
|
||||||
Class< ? > forName = parent.loadClass("org.xerial.snappy.SnappyNativeLoader");
|
// Class< ? > forName = parent.loadClass("org.xerial.snappy.SnappyNativeLoader");
|
||||||
_logger.info(forName.toString());
|
// _logger.info(forName.toString());
|
||||||
|
//
|
||||||
//Class< ? > snappyClass = L1.loadClass("org.xerial.snappy.Snappy"); // not found
|
// //Class< ? > snappyClass = L1.loadClass("org.xerial.snappy.Snappy"); // not found
|
||||||
//_logger.info(snappyClass.getName());
|
// //_logger.info(snappyClass.getName());
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void load() throws Exception {
|
public void load() throws Exception {
|
||||||
|
|
Loading…
Reference in New Issue