use of javassist.ClassClassPath in project ignite by apache.
the class GridActivationCacheAbstractTestSuit method transform.
/**
* @param c Class to transform.
* @return Transformed class.
*/
private static Class transform(Class c) {
try {
ClassPool pool = ClassPool.getDefault();
pool.insertClassPath(new ClassClassPath(GridActivationCacheAbstractTestSuit.class));
String path = c.getProtectionDomain().getCodeSource().getLocation().getPath();
CtClass ct = pool.get(c.getName());
String name = c.getName() + SUFFIX;
CtClass pr = pool.get(GridActivateExtensionTest.class.getName());
pr.setName(name);
pr.setSuperclass(ct);
pr.writeFile(path);
return Class.forName(name);
} catch (IOException e) {
System.out.println("Io exception: " + e.getMessage());
throw new IgniteException(e);
} catch (CannotCompileException e) {
System.out.println("Cannot compile exception: " + e.getMessage());
throw new IgniteException(e);
} catch (NotFoundException e) {
System.out.println("Not found exception: " + e.getMessage());
throw new IgniteException(e);
} catch (ClassNotFoundException e) {
System.out.println("Class not found exception: " + e.getMessage());
throw new IgniteException(e);
}
}
use of javassist.ClassClassPath in project ignite by apache.
the class IgniteExamplesMLTestSuite method makeTestClass.
/**
* Creates test class for given example.
*
* @param exampleCls Class of the example to be tested.
* @return Test class.
* @throws NotFoundException If class not found.
* @throws CannotCompileException If test class cannot be compiled.
*/
private static Class makeTestClass(Class<?> exampleCls) throws NotFoundException, CannotCompileException {
ClassPool cp = ClassPool.getDefault();
cp.insertClassPath(new ClassClassPath(IgniteExamplesMLTestSuite.class));
CtClass cl = cp.makeClass(basePkgForTests + "." + exampleCls.getSimpleName() + "SelfName");
cl.setSuperclass(cp.get(GridAbstractExamplesTest.class.getName()));
cl.addMethod(CtNewMethod.make("public void testExample() { " + exampleCls.getCanonicalName() + ".main(" + MLExamplesCommonArgs.class.getName() + ".EMPTY_ARGS_ML); }", cl));
return cl.toClass();
}
Aggregations