I am using AspectJ for logging when tests execution only, so I use load time weaving. I pack Interceptor to a jar file to use with another Maven project. But with below config, aspectjweaver will weave methods of external libraries. I want it only weave my source code (include test) without specific config like <include within="hello.*"/>
, for generic using like dependency.
Sorry, my English is quite bad. Thanks so much !!!
In aop.xml of this jar file, it likes
<aspectj>
<aspects>
<aspect name="log.Interceptor"/>
<weaver options="-verbose -showWeaveInfo">
<include within="*"/>
</weaver>
</aspects>
</aspectj>
// Interceptor
pointcut traceMethods() : (execution(* *(..)) && !cflow(within(Interceptor)) && !within(*Test) && !within(Test*) && !within(*Tests) && !within(*TestCase));
before(): traceMethods(){
Method method = ((MethodSignature) thisJoinPointStaticPart.getSignature()).getMethod();
logDebug(method, LogPattern.METHOD_START);
}
after(): traceMethods(){
Method method = ((MethodSignature) thisJoinPointStaticPart.getSignature()).getMethod();
logDebug(method, LogPattern.METHOD_FINISH);
}`
Well, you cannot eat the cake and keep it at the same time. So either your solution is generic with pointcuts targeting the whole world or it is specific via includes and/or excludes.
What you could try is to use an additional META-INF/aop.xml
locally when building or deploying projects using you generic library and specify in-/excludes there. As far as I remember AspectJ will find all those files on the classpath and merge the settings found there.
Alternatively, you can define an abstract pointcut and tell your users to make it concrete in an aop.xml
file in their project.
Both suggested solutions should work, but they require your library's users to have a basic understanding of AspectJ or at least pointcut syntax. Either you do that and document your library accordingly with sample pointcuts or whole sample AOP config files or you have to be more specific in your own pointcuts and/or in-/excludes. There is no magic solution, the AspectJ weaver cannot guess what you want to weave and what not.