Hey Dominic, great to hear that you got everything working and thanks for sharing your findings. Much appreciated.
Cheers, -Martin > > Martin; > > Thank you for your reply. First off: I solved my issue, and AspectJ is now > working as expected. I'll walk through the issues. > > Yes, I am using Equinox weaving. > > Because Eclipse 4 RCP is OSGi based, OSGi issues and conventions must be > addressed. > > The first breakthrough I had was when I modified my pointcut to use execution > instead of call. > i.e. pointcut mypointcut: execution(* *.myMethod()); > > That gave me aspect oriented behavior, though my before: aspect ran after the > method. > > I started looking more closely at the difference between execution and call, > and I found that call gets weaved around the call, i.e. in the class / method > one higher than the "target" method in the stack. > > This means that I need to import the AspectJ bundles into the bundles which > use the annotated methods, rather than the bundles which contain the > annotated methods. > > I then identified (through Internet research) a more subtle difference > between execution and call: namely that call is weaved against the declared > type, rather than the object type. OSGi encourages programming to > interfaces, so all code that uses a service from a different bundle declares > the variable as the interface type. When I tried to annotate the concrete > implementation method, AspectJ didn't do anything. It's necessary to > annotate the interface's method declaration. > > Retrieving the parameter from the custom annotation was a brief struggle as > well, but that too fell to Internet research. > > At the end of the day, it all works, and is quite slick. Aspect Oriented > Programming and AspectJ saved me from adding a layer, and passing around a > session object, to an already complex system in order to apply authorization. > > For anyone that is interested here is a basic version of the aspect I created: > Public aspect MyAspect > { > pointcut mypointcut(MyAnnotation a): call(@MyAnnotation * *()) && > @annotation(a); > > before(MyAnnotation a) throws MyException: mypointcut(a) > { > ...Aspect / advice code... > } > } > > I apologize for the length. > > Thank you, > > Dominic L. Hilsbos, MBA, CSDA > Director - Information Technology > Perform Air International Inc. > > > -----Original Message----- > From: aspectj-users-boun...@eclipse.org > [mailto:aspectj-users-boun...@eclipse.org] On Behalf Of Martin Lippert > Sent: Thursday, February 18, 2016 5:57 AM > To: aspectj-users@eclipse.org > Subject: Re: [aspectj-users] AspectJ and Eclipse RCP > > Hey Dominic, > > I guess you are using the Equinox weaving feature to weave your aspects into > your RCP application, right? > Or is this limited to the scope of the bundle that the aspect lives in? > > Maybe you can point me to a sample project that reproduces this behavior. > Would love to take a more detailed look. > > Cheers, > -Martin > > > >> >> Users; >> >> I'm trying to use AspectJ with an Eclipse RCP program. I want to use >> aspects for the normal things, i.e. authorization and logging. >> >> My failures seem to fall into 2 broad types: crash and burn or don't do >> anything. >> >> My first try aspect looks like this: >> >> Public aspect MyAspect >> { >> pointcut mypointcut: call(* *.myMethod()); >> >> before(): mypointcut() >> { >> System.out.println("Hello Aspect oriented programming"); >> } >> } >> >> I have extensive logging turned on, but am not really sure what I'm looking >> for. >> I get this: info register aspect <MyAspect> I also get this: info >> weaving bundle '<my bundle>' with a bunch of stuff in between. >> I even get: debug weaving '<MyService>' >> >> MyService registers with OSGi Declarative Services, and is injected into the >> RCP object, but when I call myMethod on MyService the aspect isn't called. >> >> On the other hand, when I set up an aspect like this: >> Public aspect MyAspect >> { >> pointcut mypointcut: call(* *.myMethod()); >> >> before(): mypointcut() >> { >> System.out.println("Hello Aspect oriented programming"); >> } >> } >> >> The RCP code freaks out, and doesn't run. >> >> All the debug type output from AspectJ suggests that the AspectJ runtime is >> loaded and running. >> >> BTW, where I eventually plan to go with this is to tie it to a Runtime >> Annotation, as follows: >> Public aspect MyAspect >> { >> pointcut mypointcut: call(@MyAnnotation * *()); >> >> before(): mypointcut() >> { >> System.out.println("Hello Aspect oriented programming"); >> } >> } >> >> But this too generates no aspect output. >> >> Any thoughts? >> >> Thank you, >> >> Dominic L. Hilsbos, MBA, CSDA >> Director - Information Technology >> Perform Air International Inc. >> >> >> _______________________________________________ >> aspectj-users mailing list >> aspectj-users@eclipse.org >> To change your delivery options, retrieve your password, or >> unsubscribe from this list, visit >> https://dev.eclipse.org/mailman/listinfo/aspectj-users > > _______________________________________________ > aspectj-users mailing list > aspectj-users@eclipse.org > To change your delivery options, retrieve your password, or unsubscribe from > this list, visit https://dev.eclipse.org/mailman/listinfo/aspectj-users > _______________________________________________ > aspectj-users mailing list > aspectj-users@eclipse.org > To change your delivery options, retrieve your password, or unsubscribe from > this list, visit > https://dev.eclipse.org/mailman/listinfo/aspectj-users _______________________________________________ aspectj-users mailing list aspectj-users@eclipse.org To change your delivery options, retrieve your password, or unsubscribe from this list, visit https://dev.eclipse.org/mailman/listinfo/aspectj-users