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 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


Back to the top