Hello,
I have been trying to use AspectJ to modify the behavior of a third-party Java library (Hibernate) that I am including as an SBT dependency. I specify the javaagent as an environment variable using something like
export ACTIVATOR_OPTS="-javaagent:/home/brp/.ivy2/cache/org.aspectj/aspectjweaver/jars/aspectjweaver-1.8.2.jar"
And the weaver is picking up my from "conf/META-INF/aop.xml". I know that because the debug messages show me that my aspect has been registered, plus if I specify an incorrect format for the xml, I get an exception originating from some aspectj class.
Also, AspectJ is atleast picking up by Aspect class and reading it as well. If I use incorrect syntax for my pointcut, I get a parse exception from aspectj.
If the advised class is one of the classes in my source code, the advice seems to be getting applied. However, if I specify a third party package like
<include within="org.hibernate.cfg.*" />
The aspect is never applied. I know this bacause my debug statements in the aspect never get printed. Also, in the AspectJ debug log, I get the following output
[ [36mdebug [0m] o.a.w.t.WeavingAdaptor - RETURN false
[ [36mdebug [0m] o.a.weaver.Dump - ENTRY null
[ [36mdebug [0m] o.a.weaver.Dump - ENTRY org.aspectj.weaver.tools.WeavingAdaptor$WeavingAdaptorMessageHolder@3bba665
[ [36mdebug [0m] o.a.weaver.Dump - ENTRY null
[ [36mdebug [0m] o.a.weaver.Dump - ENTRY org.aspectj.weaver.tools.WeavingAdaptor$WeavingAdaptorMessageHolder@3bba665
[ [36mdebug [0m] o.a.weaver.Dump - EVENT
[ [36mdebug [0m] o.a.weaver.Dump - EVENT
[ [36mdebug [0m] o.a.weaver.Dump - RETURN false
[ [36mdebug [0m] o.a.weaver.Dump - RETURN Excluded
[ [36mdebug [0m] o.a.w.l.Aj - RETURN byte[5851]
As the debug log says, my intended class is getting "Excluded".
My pointcut is getting applied to a static, private method. And the pointcut definition is correct. I have tried with very generic, all encompassing pointcuts and even those are not getting applied. My aspect class is:
@Aspect
public class ComponentAspect {
@Around("execution (private static * buildBaseMapping())")
public Object setupTuplizer(ProceedingJoinPoint pjp) throws Throwable {
System.out.println("\n\n\n\nDoitdoit \n\n\n\n\n");
return pjp.proceed();
}
}
I am not sure if this has something to do with play framework or not. For ex. I have ran this SBT project
activator-akka-aspectj and it is working correctly, applying aspects around the akka actor classes. The akka classes are a third party dependency in that project. I have been looking around and I have tried out several things. The sbt-aspectj plugin is not an answer here since it is working fine in that project.
I am going to keep looking around, but if anybody has any idea why this could be happening, that would be helpful.