Re: [aspectj-users] call and execution pointcut problem

2022-06-15 Thread Alexander Kriegisch
> The problem is the usage of 'call'.

No, it is not. The problem is what I explained: You do not fully
understand how to correctly configure your build and test run in order
to achieve that the 'call' pointcut works for the test class calling the
target method. You simply need to make sure that your tests are also
woven, that is all.

> I decided to use 'execution' instead and then use StackTraceElement
> for from a stacktrace to find the calling class and method.

Think about it for a minute: Just in order to make your test work
correctly and identify the caller from the aspect, you are changing your
production aspect to manually and slowly parse a stack trace. Besides,
as soon as you introduce more aspects, you might have to adjust the
stack trace analysis, because the stack trace can change if another
aspect intercepts the same joinpoint. But even without that it is the
wrong way.

By the way, if you use 'call' in combination with
'thisEnclosingJoinPointStaticPart' (native syntax) or
'JoinPoint.EnclosingStaticPart' (annotation syntax), you can directly
determine the caller, if you need that in your aspect. Just make sure to
configure the AspectJ compiler or load time weaver to also encompass
your test class. You might want to find
https://stackoverflow.com/a/66649082/1082681 or one of my other answers
linked off of there helpful.

-- 
Alexander Kriegisch
https://scrum-master.de
___
aspectj-users mailing list
aspectj-users@eclipse.org
To unsubscribe from this list, visit 
https://www.eclipse.org/mailman/listinfo/aspectj-users


Re: [aspectj-users] call and execution pointcut problem

2022-06-15 Thread Mikael Petterson
Hi Alexander,

The problem is the usage of 'call'. I decided to use 'execution' instead and 
then use StackTraceElement for from a stacktrace to find the calling class and 
method.

Then I had missed to use:


org.apache.maven.plugins
maven-compiler-plugin
${maven.compiler.plugin.version}

false
11
11




in my pom.xml for the module using my my aspect as a library.


So no need for  MCVE.


By the way if you need a tester of new versions of the maven aspectj plugin let 
me know if I can assist.


br,


//mike




Från: aspectj-users  för Mikael Petterson 

Skickat: den 10 juni 2022 19:49
Till: aspectj-users@eclipse.org 
Ämne: Re: [aspectj-users] call and execution pointcut problem

Hi Alexander,

Thanks for taking the time to reply.

I did not know 'call' was weaving into caller. Does this mean that my test 
module also need to be dependent on aspect module directly?

The basic idea I wanted to do with aspect was  to add it to our test framework. 
Then track all calls to  deprecated methods in our test framework from 
different test projects.

The maven module project is to test this idea.

I think I am using defauIt since I  don't specify the phase at all, in pom.xml. 
Correct?

I am working on a MCVE. Some more work is needed.

Br,

Mike


Hämta Outlook for Android


Från: aspectj-users  på uppdrag av Alexander 
Kriegisch 
Skickat: fredag 10 juni 2022 20:53
Till: aspectj-users@eclipse.org 
Ämne: Re: [aspectj-users] call and execution pointcut problem

Hi Mikael.

This is not a bug but to be expected. Please note that while
'execution()' is woven into the target method (callee), 'call()' is
woven into the calling method (caller). However, the caller is your
test, and probably you configured AspectJ Maven to use the 'compile'
goal, but not the 'test-compile' goal. Or maybe your plugin
configuration conflicts with Maven Compiler, which can happen if you are
not using the default phase but a custom one, leading to Maven Compiler
to recompile and overwrite code which previously was compiled by AspectJ
Maven already. Without an MCVE [1] this is difficult to say.

[1] https://stackoverflow.com/help/mcve

--
Alexander Kriegisch
https://scrum-master.de


Mikael Petterson:

> I have the following maven modules:
>
> 1.Aspects
>
> 2.Sim
>
> 3.Test
>
> Aspect looks like:
>
> (...)
> @annotation(Deprecated) && (call(public * *(..)) || call(*.new(..)));
> (...)
>
> I have built Aspect and weaved it into Sim module using the
>
> 
> 
>
> tags.
>
> I add a @Deprecated method in Sim module on a class method.
>
> Then I let one of my tests in Test module call the method annotated
> @Deprecated in Sim module.
>
> When using 'call' in the aspect I don't see the info, println in
> aspect, of my deprecated method in Sim module being called.
>
> However if I change to 'execution' in my aspect then I can see that
> the info of my method in Sim module being called. All other things the
> same.
>
> Problem with this is I cannot see the calling class. There is no info
> for that when using 'execution'.
>
> Is this is a bug? Or am I using it in the wrong way?
___
aspectj-users mailing list
aspectj-users@eclipse.org
To unsubscribe from this list, visit 
https://www.eclipse.org/mailman/listinfo/aspectj-users

___
aspectj-users mailing list
aspectj-users@eclipse.org
To unsubscribe from this list, visit 
https://www.eclipse.org/mailman/listinfo/aspectj-users