Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Load-time weaving issue

OK, I think this is due to my misunderstanding about how aspectj weave aspects.
My own main method was not in test.services, but in a different package.
If I include the package containing my Main class, then it works

I understood that <include within="foo.*"/> actually meant that all the method that match the pointcut in foo.* would be weaved. 
Actually, it means that only the callers (that call the method matching the pointcut) should be in foo.*

This is not intuitive to me because I thought that weaving meant that the methods bytecode matching the pointcut would be modified by the weaving process. Actually, it seems to indicate that every place (that match the include statement) where the method is called will be modified.

-----Original Message-----
From: aspectj-users-bounces@xxxxxxxxxxx [mailto:aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of marc.brette@xxxxxxx
Sent: jeudi 23 février 2012 18:45
To: aspectj-users@xxxxxxxxxxx
Subject: Re: [aspectj-users] Load-time weaving issue

Thanks for testing.

I see the following line:
[AppClassLoader@535ff48b] debug weaving 'test.services.SearchService2'

But not this one:
[AppClassLoader@535ff48b] weaveinfo Join point

And I don't see the aspect output (Before search for:foo op:null)

I'll try to compile the aspect and run it like you do. So far I compiled it from Intellij IDEA, maybe there is some issue there.

-----Original Message-----
From: aspectj-users-bounces@xxxxxxxxxxx [mailto:aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Andy Clement
Sent: jeudi 23 février 2012 17:14
To: aspectj-users@xxxxxxxxxxx
Subject: Re: [aspectj-users] Load-time weaving issue

Hi,

I took the code as-is and set it up to run ltw from the command line.

The only change I made was adding a main method to the SearchService2
class just so that I could 'run' something:

    public static void main(String[] argv) {
      new SearchService2().get("foo",null);
    }

I then ran it:

java -javaagent:/Users/aclement/installs/aspectj170m1/lib/aspectjweaver.jar
test.services.SearchService2
[AppClassLoader@535ff48b] info AspectJ Weaver Version 1.7.0.M1 built
on Friday Dec 16, 2011 at 16:56:09 GMT
[AppClassLoader@535ff48b] info register classloader
sun.misc.Launcher$AppClassLoader@535ff48b
[AppClassLoader@535ff48b] info using configuration
/Users/aclement/installs/aspectj170m1/marc/bin/META-INF/aop.xml
[AppClassLoader@535ff48b] info register aspect test.services.LoggingAspect
[AppClassLoader@535ff48b] debug weaving 'test.services.SearchService2'
[AppClassLoader@535ff48b] weaveinfo Join point
'method-call(java.util.List
test.services.SearchService2.get(java.lang.String,
test.services.SearchService2$Operator))' in Type
'test.services.SearchService2' (SearchService2.java:18) advised by
before advice from 'test.services.LoggingAspect'
(LoggingAspect.java:4)
[AppClassLoader@535ff48b] weaveinfo Join point
'method-call(java.util.List
test.services.SearchService2.get(java.lang.String,
test.services.SearchService2$Operator))' in Type
'test.services.SearchService2' (SearchService2.java:18) advised by
after advice from 'test.services.LoggingAspect' (LoggingAspect.java:9)
[AppClassLoader@535ff48b] debug weaving 'test.services.LoggingAspect'
[AppClassLoader@535ff48b] info processing reweavable type
test.services.LoggingAspect: test/services/LoggingAspect.java
[AppClassLoader@535ff48b] debug cannot weave
'org.aspectj.lang.NoAspectBoundException'
Before search for:foo op:null
test.services.SearchService2.get 2
After search for:foo op:null

The advice was OK (this was with the include="test.services.*" line).
 I changed the include line to:

<include within="test.services.SearchService2"/>

and that also worked.

When you say it doesn't work, what do you see - do you see the aspect
registration in the debug output, but just no weave infos for the
SearchService2 class?  Can you run it successfully the same as I have
run it?

cheers,
Andy

On 23 February 2012 07:14,  <marc.brette@xxxxxxx> wrote:
> Not much luck. The pointcut below work with
>
>         <include within="*"/>
>
> But not with
>
>         <include within="test.services.*"/>
>
>
>
>
>
> From: aspectj-users-bounces@xxxxxxxxxxx
> [mailto:aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Pasturel
> Sent: mercredi 22 février 2012 19:41
> To: aspectj-users@xxxxxxxxxxx
> Subject: Re: [aspectj-users] Load-time weaving issue
>
>
>
>
> have you tried with the pointcut definited as below ?
>
>    pointcut search(SearchService2 service, String terms,
> SearchService2.Operator operator) :
>
>      call(*  *..SearchService2.get(String, SearchService2.Operator))
>
>                                                                 &&
> target(service)
>
>                                                                 &&
> args(terms, operator);
>
>
> Le 22/02/2012 18:45, marc.brette@xxxxxxx a écrit :
>
> Hi,
>
> I try to use Load Time Weaving with a very simple program. It works except
> when I try to restrict the weaving to a class or a package.
>
> There is probably something obvious I missed but I tried most of the debug
> flags and it does not help.
>
> My example work with compile-time weaving.
>
>
>
> Aop.xml:
>
> <aspectj>
>
>
>
>     <aspects>
>
>         <aspect name="test.services.LoggingAspect"/>
>
>     </aspects>
>
>
>
>     <weaver options="-verbose -debug -showWeaveInfo">
>
>         <!--When I add this it does not work-->
>
>         <include within="test.services.*"/>
>
>         <!--<include within="test.services.SearchService2"/>   This does not
> work either -->
>
>         <!--<include within="*"/>  This does work -->
>
>     </weaver>
>
> </aspectj>
>
>
>
> Aspect:
>
> package test.services;
>
> public aspect LoggingAspect {
>
>
>
>     before(SearchService2 service, String term, SearchService2.Operator
> operator): search(service, term, operator) {
>
>         System.out.println("Before search for:" + term + " op:" + operator);
>
>         System.out.flush();
>
>     }
>
>
>
>     after(SearchService2 service, String term, SearchService2.Operator
> operator): search(service, term, operator) {
>
>         System.out.println("After search for:" + term + " op:" + operator);
>
>         System.out.flush();
>
>     }
>
>
>
>      pointcut search(SearchService2 service, String terms,
> SearchService2.Operator operator) :
>
>      call(* SearchService2.get(String, SearchService2.Operator))
>
>                                                                 &&
> target(service)
>
>                                                                 &&
> args(terms, operator);
>
>
>
> }
>
>
>
> Class to Weave:
>
> package test.services;
>
>
>
> import java.util.Arrays;
>
> import java.util.List;
>
>
>
> public class SearchService2 {
>
>
>
>     public enum Operator {
>
>         EQUALS,
>
>         CONTAINS
>
>     }
>
>     public List<String> get(String term, Operator operator) {
>
>         System.out.println("test.services.SearchService2.get 2");
>
>         return Arrays.asList(term + "1", term + "2");
>
>     }
>
> }
>
>
>
> Any help appreciated
>
> Best regards,
>
> Marc
>
>
>
>
>
>
> _______________________________________________
>
> aspectj-users mailing list
>
> aspectj-users@xxxxxxxxxxx
>
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>
>
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users

_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users



Back to the top