Search in sources :

Example 1 with ClassClassPath

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);
    }
}
Also used : CtClass(javassist.CtClass) IgniteException(org.apache.ignite.IgniteException) ClassPool(javassist.ClassPool) NotFoundException(javassist.NotFoundException) IOException(java.io.IOException) CannotCompileException(javassist.CannotCompileException) ClassClassPath(javassist.ClassClassPath)

Example 2 with ClassClassPath

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();
}
Also used : CtClass(javassist.CtClass) ClassPool(javassist.ClassPool) ClassClassPath(javassist.ClassClassPath)

Aggregations

ClassClassPath (javassist.ClassClassPath)2 ClassPool (javassist.ClassPool)2 CtClass (javassist.CtClass)2 IOException (java.io.IOException)1 CannotCompileException (javassist.CannotCompileException)1 NotFoundException (javassist.NotFoundException)1 IgniteException (org.apache.ignite.IgniteException)1