Search in sources :

Example 1 with AspectWeaverClass

use of com.navercorp.pinpoint.profiler.instrument.aspect.AspectWeaverClass in project pinpoint by naver.

the class AspectWeaverClassTest method createAspect.

public Object createAspect(String originalName, String aspectName) {
    try {
        ClassPool classPool = new ClassPool(true);
        Loader loader = getLoader(classPool);
        CtClass ctOriginal = classPool.get(originalName);
        CtClass ctAdvice = classPool.get(aspectName);
        AspectWeaverClass weaver = new AspectWeaverClass();
        weaver.weaving(ctOriginal, ctAdvice);
        Class aClass = loader.loadClass(originalName);
        return aClass.newInstance();
    } catch (Exception e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}
Also used : AspectWeaverClass(com.navercorp.pinpoint.profiler.instrument.aspect.AspectWeaverClass) AspectWeaverClass(com.navercorp.pinpoint.profiler.instrument.aspect.AspectWeaverClass)

Example 2 with AspectWeaverClass

use of com.navercorp.pinpoint.profiler.instrument.aspect.AspectWeaverClass in project pinpoint by naver.

the class JavassistClass method weave.

@Override
public void weave(String adviceClassName) throws InstrumentException {
    pluginContext.injectClass(classLoader, adviceClassName);
    CtClass adviceClass;
    try {
        adviceClass = getCtClass(adviceClassName);
    } catch (NotFoundException e) {
        throw new NotFoundInstrumentException(adviceClassName + " not found. Caused:" + e.getMessage(), e);
    }
    try {
        AspectWeaverClass weaverClass = new AspectWeaverClass();
        weaverClass.weaving(ctClass, adviceClass);
    } catch (CannotCompileException e) {
        throw new InstrumentException("weaving fail. sourceClassName:" + ctClass.getName() + " adviceClassName:" + adviceClassName + " Caused:" + e.getMessage(), e);
    } catch (NotFoundException e) {
        throw new InstrumentException("weaving fail. sourceClassName:" + ctClass.getName() + " adviceClassName:" + adviceClassName + " Caused:" + e.getMessage(), e);
    }
}
Also used : CtClass(javassist.CtClass) NotFoundException(javassist.NotFoundException) CannotCompileException(javassist.CannotCompileException) AspectWeaverClass(com.navercorp.pinpoint.profiler.instrument.aspect.AspectWeaverClass)

Aggregations

AspectWeaverClass (com.navercorp.pinpoint.profiler.instrument.aspect.AspectWeaverClass)2 CannotCompileException (javassist.CannotCompileException)1 CtClass (javassist.CtClass)1 NotFoundException (javassist.NotFoundException)1