Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Annotations weaving into a jar

Hi,

Thanks again for your help.

I have modified the pointcut signature to 
* getTable(..)
which now weaves my annotations.

Yet there is still a problem - which is the same that made my first
annotation declaration fail.
The method getTable for JCO.ParameterList is inherited from the class
that it extends. So the annotation is woven, but only into the
superclass, not into JCO.ParamterList (I see that in the -showWeaveInfo
output).
I have tried capturing the execution of this method, but it fails (no
match for the pointcut). Indeed, getTable is always called from objects
that are instances of JCO.ParameterList in my application.

Is it normal ? Is there a problem with declaring annotations for
inherited methods ?

My pointcut for testing the annotations is a basic call(@AccessControl *
*(..))

Once again, thanks.

Laurent

PS: I only receive a mail with a broken URL from this mailing list, and
have to get the answers from the on-line archive, which is why my replys
are a bit screwed.


Message: 1
Date: Fri, 17 Jun 2005 19:46:03 +0100
From: Andrew Clement <CLEMAS@xxxxxxxxxx>
Subject: Re: [aspectj-users] Annotations weaving into a jar
To: aspectj-users@xxxxxxxxxxx
Message-ID:
	
<OFEE063FDA.26A95EAC-ON80257023.0066617C-80257023.006718B8@xxxxxxxxxx>
Content-Type: text/plain; charset="us-ascii"

An HTML attachment was scrubbed...
URL:
http://eclipse.org/pipermail/aspectj-users/attachments/20050617/48cbbe2e
/attachment.html

Hi,

Yes, retention policy of CLASS is fine if you want to just match on
them, which is all you need from your example.

If you wanted to extract annotations as context, for example:

before(ColoredAnnotation ca): call(* *(..)) && @annotation(ca) {
  System.err.println("Method call colored:"+ca.value());
}

then you would need them to have RUNTIME retention.

In my query:
> "I presume you are passing the code for the 'JCO.Table' code into the
>  compiler so that it can be woven?"

By 'code' I meant the class files for JCO.Table.  

Your command line:

ajc -cp "src;lib/aspectjrt.jar;lib/jco.jar" -d bin -1.5 -showWeaveInfo
   -injars lib/jco.jar src/foo/AccessControl.java
   src/foo/AnnotateAccessControl.aj

looks fine (although -injars is deprecated in favour of -inpath).

We should ignore the advice not matching and just look
at why the declare @method isn't doing what you want.

public aspect AnnotateAccessControl {
 declare @method : JCO.Table JCO.ParameterList.getTable(..):
         @AccessControl; //database request
}

Have you tried variations of the method signature?  What about:

JCO.Table getTable(..)

or even

* getTable(..)

or even (!)

* *(..)

just to try and see if you get any weaving messages output?

Andy.





"Sesques, Laurent" <laurent.sesques@xxxxxxx>
Sent by: aspectj-users-bounces@xxxxxxxxxxx

17/06/2005 14:58
Please respond to
aspectj-users@xxxxxxxxxxx

	
To
	<aspectj-users@xxxxxxxxxxx>
cc
	
Subject
	Re: [aspectj-users] Annotations weaving into a jar

	




Hi,

Thanks for your answer.

The retention policy of the annotation @AccessControl is CLASS. My
understanding is that I do not need RUNTIME, is that correct ?

I've also made an example of annotation weaving which works similarly as
yours as a test. Now I am trying binary weaving, and this is what fails.

I am not sure I correctly understand this question:
"I presume you are passing the code for the 'JCO.Table' code into the
compiler so that it can be woven?"
Do you refer to the source code or bytecode? My understanding was that
thanks to bytecode weaving, you do not need the source code for weaving.
The sure thing is I do not have the source code for the classes in this
jar file.
So to weave my annotating aspect, I give the '-injars lib/jco.jar'
option to ajc.
To make it clear, here is the command:
ajc -cp "src;lib/aspectjrt.jar;lib/jco.jar" -d bin -1.5 -showWeaveInfo
-injars lib/jco.jar src/foo/AccessControl.java
src/foo/AnnotateAccessControl.aj

The -showWeaveInfo did not show anything, since the annotation is not
woven (sorry I had not made this explicit in my original post, but for
me it was clear).

Thanks again for your help,
Laurent






Hi,

I presume you are passing the code for the 'JCO.Table' code into the
compiler so that it can be woven?  Try compiling with '-showWeaveInfo'
to check if the declare @method is adding the annotation to what you
expect.

What is the retention policy for the AccessControl annotation?

Here is my example that works:

import java.lang.annotation.*;

@interface Blue {}

public class A {
 public void m() {}

 public static void main(String[]argv) {
   new A().m();
 }
}

aspect Y {
 declare @method: void A.m(..) : @Blue;

 before(): within(A) && call(@Blue * *(..)) {
   System.err.println(thisJoinPoint);
 }
}

C:\aspectj1.5.0-dev>ajc -1.5 A.aj -showWeaveInfo
'public void A.m()' (A.aj:6) is annotated with @Blue method annotation
from 'Y' (A.aj:14)
Type 'A' (A.aj:9) advised by before advice from 'Y' (A.aj:16)

C:\aspectj1.5.0-dev>java A
call(void A.m())

My example isn't binary weaving of course (with inpath) but it should
work the same...

Andy.



"Sesques, Laurent" <laurent.sesques@xxxxxxx>
Sent by: aspectj-users-bounces@xxxxxxxxxxx

15/06/2005 15:43
Please respond to
aspectj-users@xxxxxxxxxxx

               
To
                <aspectj-users@xxxxxxxxxxx>
cc
               
Subject
                [aspectj-users] Annotations weaving into a jar

               




Hello,

I am encountering problems trying to use annotations with AspectJ.
I have a jar library which provides me with all the tools I need to
connect to a back-end.
For access control purposes, I want to protect the calls performed with
this tool according to information concerning the current user.

I have this annotating aspect:

public aspect AnnotateAccessControl {
               declare @method : JCO.Table
JCO.ParameterList.getTable(..):
@AccessControl; //database request
}

And this advice testing the catching of the methods annotated like
above:

before(): within(CallingClass) && call( @AccessControl *
*.getTable(..)){
               System.out.println("This should be controlled!");
}

I use AspectJ Compiler DEVELOPMENT built on Friday Jun 3, 2005 at
12:16:27 GMT

I use the -injars option for the compilation.

Here is the output of the compilation:

C:\Project\src\foo\AccessControl.aj:15 [warning] advice defined in
foo.AccessControl has not been applied [Xlint:adviceDidNotMatch]

Then at runtime, as expected due to the compilator's message, nothing is
caught. (running on Sun's JVM 1.5.0_02)

Is there something I did wrong ?

Thanks in advance,
Laurent
_______________________________________________
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


End of aspectj-users Digest, Vol 4, Issue 16
********************************************



Back to the top