Package org.hotswap.agent.javassist

Examples of org.hotswap.agent.javassist.ClassPool


        assertNull("Mapping class$1 -> class$1", stateInfo.getCompatibleTransition(AnonymousTestClass1.class.getName() + "$1"));
    }


    private AnonymousClassInfos getClassPoolInfos(Class clazz) throws ClassNotFoundException {
        ClassPool classPool = new ClassPool();
        classPool.insertClassPath(new LoaderClassPath(getClass().getClassLoader()));
        return new AnonymousClassInfos(classPool, clazz.getName());
    }
View Full Code Here


    }

    public AnonymousClassInfo getAnonymousCtClassInfo() throws NotFoundException, ClassNotFoundException, IOException, CannotCompileException {
        Class clazz = getClass().getClassLoader().loadClass(AnonymousTestClass1.class.getName() + "$1");

        ClassPool classPool = new ClassPool();
        classPool.appendClassPath(new LoaderClassPath(getClass().getClassLoader()));
        return new AnonymousClassInfo(classPool.get(clazz.getName()));
    }
View Full Code Here

    public Set<CtClass> scanPlugins(ClassLoader classLoader) throws IOException {
        if (!pluginDefs.containsKey(classLoader)) {
            synchronized (pluginDefs) {
                if (!pluginDefs.containsKey(classLoader)) {
                    final Set<CtClass> plugins = new HashSet<CtClass>();
                    final ClassPool classPool = ClassPool.getDefault();

                    scanner.scan(getClass().getClassLoader(), PLUGIN_PATH, new ScannerVisitor() {
                        @Override
                        public void visit(InputStream file) throws IOException {
                            plugins.add(classPool.makeClass(file));
                        }
                    });
                }
            }
        }
View Full Code Here

        assertFalse(AnnotationHelper.hasAnnotation(AnonymousClassPatchPlugin.class, "xxxx"));
    }

    @Test
    public void testHasAnnotationJavassist() throws Exception {
        ClassPool ctPool = ClassPool.getDefault();
        CtClass ctClass = ctPool.getCtClass(AnonymousClassPatchPlugin.class.getName());

        assertTrue(AnnotationHelper.hasAnnotation(ctClass, "org.hotswap.agent.annotation.Plugin"));
        assertFalse(AnnotationHelper.hasAnnotation(ctClass, "xxxx"));
    }
View Full Code Here

        String s = PluginManagerInvoker.buildCallPluginMethod(plugin.getClass(),
                "callPluginMethod",
                "Boolean.TRUE", "java.lang.Boolean");

        ClassPool classPool = ClassPool.getDefault();
        classPool.appendSystemPath();

        CtClass clazz = classPool.makeClass("Test");
        clazz.addMethod(CtNewMethod.make("public void test() {" + s + "}", clazz));
        Class<?> testClass = clazz.toClass();


        Method testMethod = testClass.getDeclaredMethod("test");
View Full Code Here

     * @param classLoader loader
     * @return created class
     * @throws org.hotswap.agent.javassist.NotFoundException
     */
    private CtClass createCtClass(URI uri, ClassLoader classLoader) throws NotFoundException, IOException {
        ClassPool cp = new ClassPool();
        cp.appendClassPath(new LoaderClassPath(classLoader));

        return cp.makeClass(new ByteArrayInputStream(IOUtils.toByteArray(uri)));
    }
View Full Code Here

     * @param swap     fully qualified class name of class to swap
     * @throws Exception swap exception
     */
    public void swapClasses(Class original, String swap) throws Exception {
        // need to recreate classpool on each swap to avoid stale class definition
        ClassPool classPool = new ClassPool();
        classPool.appendClassPath(new LoaderClassPath(original.getClassLoader()));

        CtClass ctClass = classPool.getAndRename(swap, original.getName());

        reload(original.getName(), ctClass.toBytecode());
    }
View Full Code Here

     * @param swap     fully qualified class name of class to swap
     * @throws Exception swap exception
     */
    public static void swapClasses(Class original, String swap) throws Exception {
        // need to recreate classpool on each swap to avoid stale class definition
        ClassPool classPool = new ClassPool();
        classPool.appendClassPath(new LoaderClassPath(original.getClassLoader()));

        CtClass ctClass = classPool.getAndRename(swap, original.getName());

        reload(original, ctClass.toBytecode());
    }
View Full Code Here

            this.equinoxPlugin = equinoxPlugin;
        }

        @Override
        public void onEvent(WatchFileEvent event) {
            ClassPool pool = ClassPool.getDefault();

            if (!event.getURI().getPath().endsWith(".class")) {
                return;
            }

            URI fileURI = event.getURI();

            File classFile = new File(fileURI);
            CtClass ctClass = null;

            boolean doHotswap = false;
            try {
                ctClass = pool.makeClass(new FileInputStream(classFile));
                doHotswap = equinoxPlugin.loadClassToTargetClassLoaders(ctClass, fileURI, true);
            } catch (Exception e) {
                LOGGER.warning("MakeClass exception : {}",  e.getMessage());
            } finally {
                if (ctClass != null) {
View Full Code Here

TOP

Related Classes of org.hotswap.agent.javassist.ClassPool

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.