Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Aspectj only works on annotations when they are in the same project? (using OSGI)

Yes, proxying could be getting in the way and you may need to adjust
your pointcut to cope with an invocation via a proxy (particularly if
the proxy is actually invoking the code via reflection - using AspectJ
with reflective invocation needs special consideration).

Andy

On 14 July 2010 08:02, Kashtan, Daniel <Daniel.Kashtan@xxxxxxx> wrote:
> Hey Andy,
>
> Sorry about the last confusing email. I was able to figure out what was causing me to have problems with using aspects inside the bundle where the aspect was defined. The ant build just has to have the inpath set correctly. I was having trouble because of some stale copy compilation business that I took care of.
>
> Also, I was able to get rid of javac in my ant build and just use iajc, so less clutter :) Thanks for pointing out that I just had to get rid of those useless @override annotations.
>
> I am still not able to get the call pointcut to work. It still works as execution. My inpath for that bundle touches every source file in that bundle, so does this mean that the call to that function has to be coming from outside the bundle? When I run through the debugger, the function is getting called from within the same bundle, but in the stack trace, there is some funky proxy stuff going on in-between where the function is called and where it finally executes the method. Could this be messing up aspectJ? Let me know what you think.
> ________________________________________
> From: aspectj-users-bounces@xxxxxxxxxxx [aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Andy Clement [andrew.clement@xxxxxxxxx]
> Sent: Tuesday, July 13, 2010 10:49 AM
> To: aspectj-users@xxxxxxxxxxx
> Subject: Re: [aspectj-users] Aspectj only works on annotations when they are    in the same project? (using OSGI)
>
> On 13 July 2010 06:16, Kashtan, Daniel <Daniel.Kashtan@xxxxxxx> wrote:
>> You mentioned that Joinpoints in undo_1.0.0.jar will not be woven. I agreed with that, but tried to see if they would anyways, and I am able to get advice to get called even if the annotation I am using in on a method in the undo jar. I am confused by this, does it have something to do with the way execution works?
>
> i don't quite understand what you mean.  If you want to weave what is
> in undo_1.0.0.jar it needs to be on the inpath.  If you have it on the
> aspectpath we only discover aspects on it and use it to resolve type
> references.  Any AspectJ pointcut will attempt to match against code
> it sees - either source or code from inpath.
>
>>
>> compile:
>>     [iajc] error at public void commit()
>>     [iajc]             ^^^^^^
>>     [iajc] /home/djkasht/workspaceBlueprint/bp/bp-trunk/bundles/Undo/src/undo/UndoServiceImp.java:44:0::0 The method commit() of type UndoServiceImp must override a superclass method
>>     [iajc] error at public void start(BundleContext context) throws Exception
>>     [iajc]             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>>     [iajc] /home/djkasht/workspaceBlueprint/bp/bp-trunk/bundles/Undo/src/undo/UndoServiceImp.java:88:0::0 The method start(BundleContext) of type UndoServiceImp must override a superclass method
>>     [iajc] error at public void stop(BundleContext arg0) throws Exception
>
> I think you'll find that you are using @Override on a method that
> implements an interface - so you aren't really overriding.  This is
> the eclipse compiler behaving a little different to javac.
>
>> Here is what my merged iajc ant call looks like:
>>
>>          <!--<javac srcdir="src" destdir="${bin.dir}" debug="true" source="1.5" target="1.5">
>>                        <classpath refid="classpath" />
>>                </javac>-->
>>                <iajc srcdir="src" sourceRoots="src/undo/aspect" destdir="${bin.dir}" debug="true" source="1.5">
>>                        <classpath>
>>                                <pathelement path="classpath" />
>>                                <pathelement location="${blueprint.home}/lib/aspectjrt.jar" />
>>                                <pathelement location="${bin.dir}" />
>>                        </classpath>
>>                        <classpath refid="classpath" />
>>                </iajc>
>
> I see - you have used sourceroots to weave your undo jar - I thought
> you would use inpath if you wanted to do that (as you'd already built
> that jar).  Yes, execution will weave into undo if you pass it on
> sourceroots - as I mentioned above pointcuts will be matched against
> all code on the inpath or passed in as source.
>
> Andy
>
>
>>
>> ________________________________________
>> From: aspectj-users-bounces@xxxxxxxxxxx [aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Andy Clement [andrew.clement@xxxxxxxxx]
>> Sent: Monday, July 12, 2010 3:55 PM
>> To: aspectj-users@xxxxxxxxxxx
>> Subject: Re: [aspectj-users] Aspectj only works on annotations when they are    in the same project? (using OSGI)
>>
>> If your call joinpoints are in 'src' for the bundle, then yes they
>> should be candidates for weaving.  Joinpoints in undo_1.0.0.jar will
>> not be woven (but I think you realise that).
>>
>> You could merge your steps together and see if that makes any
>> difference.  Pass the source to iajc rather than performing that
>> earlier javac step.
>>
>> Andy
>>
>> On 12 July 2010 11:48, Kashtan, Daniel <Daniel.Kashtan@xxxxxxx> wrote:
>>> My call joinpoints should be in the code being passed to for weaving. The method I annotated is called by a function in a different package, but the same bundle. I believe I tell IAJC to compile everything in ${bin.dir} to ${woven.bin.dir}. When I say everything, it should compile everything in the bundle (all the packages). Here is my javac and iajc ant build code below. I am unsure about if this is the problem, but it sure seems to be the only thing possible.
>>>
>>>                <javac srcdir="src" destdir="${bin.dir}" debug="true" source="1.5" target="1.5">
>>>                        <classpath refid="classpath" />
>>>                </javac>
>>>                <mkdir dir="${woven.bin.dir}" />
>>>                <iajc inpath="${bin.dir}" destdir="${woven.bin.dir}" aspectPath="${blueprint.home}/plugins/undo_1.0.0.jar" debug="true" source="1.5">
>>>                        <classpath refid="classpath" />
>>>                </iajc>
>>> ________________________________________
>>> From: aspectj-users-bounces@xxxxxxxxxxx [aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Andy Clement [andrew.clement@xxxxxxxxx]
>>> Sent: Monday, July 12, 2010 2:05 PM
>>> To: aspectj-users@xxxxxxxxxxx
>>> Subject: Re: [aspectj-users] Aspectj only works on annotations when they are    in the same project? (using OSGI)
>>>
>>> Are you sure your call join points were in the code being passed to
>>> AspectJ for weaving?  If your call joinpoints were not but your
>>> execution joinpoints were, that would cause what you are seeing.
>>>
>>> Andy
>>>
>>> On 12 July 2010 10:56, Kashtan, Daniel <Daniel.Kashtan@xxxxxxx> wrote:
>>>> I finally got my adivce to intercept an annotated method join point. I am not sure exactly what did it. When I changed it from call to execution it worked. I had tried this before, but had no success. I made a lot of changes to my ant build files, so it must have been a combination of things that straightened out the problem. Can anyone elaborate on why execution would make it work when call would not? It is a little anti-climatic to not fully understand why things went right.
>>>>
>>>> Also, here is my final advice code:
>>>>
>>>>        after() : execution(@Test * *(..))
>>>>        {
>>>>                System.out.println("COMMIT!");
>>>>        }
>>>> ________________________________________
>>>> From: aspectj-users-bounces@xxxxxxxxxxx [aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Kashtan, Daniel [Daniel.Kashtan@xxxxxxx]
>>>> Sent: Monday, July 12, 2010 9:54 AM
>>>> To: aspectj-users@xxxxxxxxxxx
>>>> Subject: RE: [aspectj-users] Aspectj only works on annotations when they are    in the same project? (using OSGI)
>>>>
>>>> I added source="1.5" to both of the iajc ant calls I make, but nothing changed.
>>>>
>>>> I went through the steps of the project you detailed and I was able to build it all and get the same output at the end. This is a great proof of concept for confidence.
>>>>
>>>> Any other suggestions on what I could try? I am still not able to get it to work in my project. I'll let you know what I did if I figure it out first :)
>>>> ________________________________________
>>>> From: aspectj-users-bounces@xxxxxxxxxxx [aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Andy Clement [andrew.clement@xxxxxxxxx]
>>>> Sent: Friday, July 09, 2010 5:33 PM
>>>> To: aspectj-users@xxxxxxxxxxx
>>>> Subject: Re: [aspectj-users] Aspectj only works on annotations when they are    in the same project? (using OSGI)
>>>>
>>>> And that Test annotation has runtime retention does it?
>>>>
>>>>> Also, is what I am trying to do possible?
>>>>> I've gotten an aspect to work that intercepts system.out.println in other bundles, but this annotation based one is killing me :(
>>>>
>>>> You haven't said anything that makes me believe it isn't possible, but
>>>> I can't quite put my finger on what you are not quite doing.  What if
>>>> you ignore Ant and do something far simpler:
>>>>
>>>> one/Test.java  ---
>>>> import java.lang.annotation.*;
>>>>
>>>> @Retention(RetentionPolicy.RUNTIME)
>>>> public @interface Test {}
>>>> ---
>>>>
>>>> one/Azpect.java ---
>>>> public aspect Azpect {
>>>>  before(): call(@Test * *(..)) {}
>>>> }
>>>> ---
>>>>
>>>> two/Code.java ---
>>>> public class Code {
>>>>  @Test
>>>>  public void m() {}
>>>>
>>>>  public void n() {}
>>>>
>>>>  public void foo() {
>>>>    m();
>>>>    n();
>>>>    m();
>>>>  }
>>>> }
>>>> ---
>>>>
>>>> Now to build it:
>>>> 1) build the aspect and annotation (your project 'A')
>>>> cd one
>>>> ajc *.java -1.5 -outjar azpect.jar
>>>>
>>>> 2) build the code (your project 'B')
>>>> cd ..\two
>>>> ajc Code.java -classpath
>>>> "..\one\azpect.jar;n:\aspectj169-dev\lib\aspectjrt.jar" -1.5
>>>>
>>>> 3) weave the code
>>>> cd ..\three
>>>> ajc -inpath ..\two -aspectpath ..\one\azpect.jar -showWeaveInfo -1.5 -d .
>>>> Join point 'method-call(void Code.m())' in Type 'Code' (Code.java:8)
>>>> advised by before advice from 'Azpect' (azpect.jar!Azpect.class:2(from
>>>> Azpect.java))
>>>> Join point 'method-call(void Code.m())' in Type 'Code' (Code.java:10)
>>>> advised by before advice from 'Azpect' (azpect.jar!Azpect.class:2(from
>>>> Azpect.java))
>>>>
>>>> So the two calls to m() were advised.
>>>>
>>>> Now we just have to work out why whatever you are doing is different
>>>> to that.  Have you tried specifying source="1.5" in your iajc task?
>>>>
>>>> Andy
>>>>
>>>> On 9 July 2010 13:56, Kashtan, Daniel <Daniel.Kashtan@xxxxxxx> wrote:
>>>>> As I test my code more and more, it seems that I can get aspects working across bundles, but I can't with annotations, and I can't get the annotations to trigger interception even in the same bundle as the aspect.
>>>>>
>>>>> The top one will work, but the one below it won't, despite the function pullData() having the annotation above it. There must be something causing aspectj to not recognise that annotation :(
>>>>>
>>>>>        after() : call(* pullData(..))
>>>>>        {
>>>>>                System.out.println("COMMIT!@");
>>>>>        }
>>>>>
>>>>>        after() : call(@Test * *(..))
>>>>>        {
>>>>>                System.out.println("COMMIT!");
>>>>>        }
>>>>> ________________________________________
>>>>> From: aspectj-users-bounces@xxxxxxxxxxx [aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Kashtan, Daniel [Daniel.Kashtan@xxxxxxx]
>>>>> Sent: Friday, July 09, 2010 3:04 PM
>>>>> To: aspectj-users@xxxxxxxxxxx
>>>>> Subject: RE: [aspectj-users] Aspectj only works on annotations when they are    in the same project? (using OSGI)
>>>>>
>>>>> I changed my build so that my woven code is put in a separate folder, which my build step now uses. I still can't get my aspect to work though, but this seems like a good idea anyways.
>>>>>
>>>>> (answer to you last paragraph)
>>>>> A is on the classpath of B. I am able to get B to see my annotation without any trouble. I am not sure what an eclipse builder step is, so I believe I am not using one. I am doing everything from the command line and just using eclipse as an editor. Here is where my iajc ant call lives:
>>>>>
>>>>>       <target name="compile">
>>>>>                <mkdir dir="${bin.dir}" />
>>>>>                <javac srcdir="src" destdir="${bin.dir}" debug="true">
>>>>>                        <classpath refid="classpath" />
>>>>>                </javac>
>>>>>                <mkdir dir="${woven.bin.dir}" />
>>>>>                <iajc inpath="${bin.dir}" destdir="${woven.bin.dir}" aspectPath="${blueprint.home}/plugins/undo_1.0.0.jar" debug="true">
>>>>>                        <classpath refid="classpath" />
>>>>>                </iajc>
>>>>>                <copy todir="${woven.bin.dir}">
>>>>>                        <fileset dir="src" excludes="**/*Test.java" />
>>>>>                </copy>
>>>>>        </target>
>>>>>
>>>>>
>>>>> Also, is what I am trying to do possible? I've gotten an aspect to work that intercepts system.out.println in other bundles, but this annotation based one is killing me :(
>>>>> ________________________________________
>>>>> From: aspectj-users-bounces@xxxxxxxxxxx [aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Andy Clement [andrew.clement@xxxxxxxxx]
>>>>> Sent: Friday, July 09, 2010 2:36 PM
>>>>> To: aspectj-users@xxxxxxxxxxx
>>>>> Subject: Re: [aspectj-users] Aspectj only works on annotations when they are    in the same project? (using OSGI)
>>>>>
>>>>> i'd be very cautious about specifying the output folder to be the same
>>>>> as the input folder:  inpath="${bin.dir}" destdir="${bin.dir}"
>>>>>
>>>>> it isn't like aspectj pre-loads all the code ready to do a weave, you
>>>>> might get very strange results with that.  how about:
>>>>> inpath="${bin.dir}" destdir="${woven.bin.dir}"
>>>>>
>>>>> I presume, although your annotation is in bundle A that you are using
>>>>> it in bundle B?  I got that impression.  If that is the case, how is
>>>>> the code in B compiling unless A is on the classpath?  You aren't
>>>>> using an Ant step defined as an eclipse builder step are you?  The
>>>>> iajc is something that is running later?
>>>>>
>>>>> Andy
>>>>>
>>>>> On 9 July 2010 09:55, Kashtan, Daniel <Daniel.Kashtan@xxxxxxx> wrote:
>>>>>> I hope I can explain everything correctly.
>>>>>>
>>>>>> I have my aspect in bundle A. My join points are in bundle B. My annotation is in bundle A, but I am not even sure if this matters at all. My ant compilation for bundle B has an aspect path dependency I believe, I use this iajc tag:
>>>>>>
>>>>>> <iajc inpath="${bin.dir}" destdir="${bin.dir}" aspectPath="${blueprint.home}/plugins/undo_1.0.0.jar" debug="true">
>>>>>>        <classpath refid="classpath" />
>>>>>> </iajc>
>>>>>>
>>>>>> I have another aspectj function in my .aj file in bundle A. This one works, which is why I think the usage of annotations is somehow causing the problem.
>>>>>>
>>>>>>        void around() : call(void java.io.PrintStream.println(String))
>>>>>>        && !within(HelloAspect){
>>>>>>                System.out.println("Hi from HelloAspect ;-)");
>>>>>>        }
>>>>>>
>>>>>> ________________________________________
>>>>>> From: aspectj-users-bounces@xxxxxxxxxxx [aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Andy Clement [andrew.clement@xxxxxxxxx]
>>>>>> Sent: Friday, July 09, 2010 11:55 AM
>>>>>> To: aspectj-users@xxxxxxxxxxx
>>>>>> Subject: Re: [aspectj-users] Aspectj only works on annotations when they are    in the same project? (using OSGI)
>>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> How does your code containing the join points compile if you don't
>>>>>> have the annotation in the same project that is using it?  Do you have
>>>>>> a classpath dependency (maybe an aspectpath dependency) from the join
>>>>>> point containing project to the aspectj project?  I would need to know
>>>>>> how the annotation is being used in the code-to-be-woven and what
>>>>>> relationships you have between the projects.
>>>>>>
>>>>>> Andy
>>>>>>
>>>>>> On 9 July 2010 07:19, Kashtan, Daniel <Daniel.Kashtan@xxxxxxx> wrote:
>>>>>>> Hey all,
>>>>>>>
>>>>>>> I am using compile-time-weaving and OSGI. I cannot figure out why, but my aspects don't work unless my annotation file is in the same project where my join points are. Basically, I have gotten the aspect below to work if my aspect is in one project, and my annotation and java code with join points are in another. I'd like to move my annotation file into the same project as the one with the aspect, but my aspects will stop working then :(
>>>>>>>
>>>>>>> I am using aspect code like this:
>>>>>>>
>>>>>>>        after() : call(@CommitingFunction * *(..))
>>>>>>>        {
>>>>>>>                System.out.println("Commit clicked");
>>>>>>>        }
>>>>>>>
>>>>>>> My annotation is simply just this:
>>>>>>>
>>>>>>> @Retention(RetentionPolicy.RUNTIME)
>>>>>>> public @interface CommitingFunction
>>>>>>> {
>>>>>>>
>>>>>>> }
>>>>>>>
>>>>>>> This e-mail and any files transmitted with it may be proprietary and are intended solely for the use of the individual or entity to whom they are addressed. If you have received this e-mail in error please notify the sender.
>>>>>>> Please note that any views or opinions presented in this e-mail are solely those of the author and do not necessarily represent those of ITT Corporation. The recipient should check this e-mail and any attachments for the presence of viruses. ITT accepts no liability for any damage caused by any virus transmitted by this e-mail.
>>>>>>> _______________________________________________
>>>>>>> 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
>>>>> _______________________________________________
>>>>> 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
>>>> _______________________________________________
>>>> 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
>> _______________________________________________
>> 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