Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] LTW and annotations

Hi Janos,
as the Spring documentation states, the
PathMatchingResourcePatternResolver is able to find something like
"*.xml" but only when it resolves to files or jar files (that is, the
base path can be translated to file:// or jar:file urls). Unfortunately
that is not always the case in an enterprise environment.

What AspectJ COULD do, is to create an annotation processor using Sun's
APT. That annotation processor could intercept the @Aspect annotation,
and generate the xml file on the fly also when sources are compiled
using the standard javac (and @AspectJ) and not only using ajc. In fact,
using the Filer (provided to the annotation processor, see
http://java.sun.com/j2se/1.5.0/docs/guide/apt/mirror/com/sun/mirror/apt/Filer.html
), it is possible to intercept the compiler work to create custom "text
file", and APT first chapter explicitly cites "creating deployment
descriptors".

That would avoid both problems : still compile with a standard 1.5
compiler, and have the aop.xml automatically generated.

Simone

P.S. I do have the same problem of static weaving as well, will probably
write about it today or tomorrow, cause that is causing me problems too.


Háber János wrote:
> Hi!
>
> Sry but I not agree. I not want to totally disable the aop.xml, is
> good, for weaving config.
> Maybe a possible solution: basePackage attribute to the <aspects> tag,
> if this attribute exists aspectj try to resolve all Aspects in this
> package and this subpackages.
>
> Maybe Spring PathMatchingResourcePatternResolver class may help. It's
> not impossible I think. 
>
> Janos
>
> Ps: I try the maven plugin (aspectj-maven-plugin 1.0) but I can't turn
> off the static weaving. (I want to using eclipse not command line
> apps, and automatically)
>
> ________________________________________
> From: aspectj-users-bounces@xxxxxxxxxxx
> [mailto:aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Ramnivas
> Laddad
> Sent: Thursday, October 02, 2008 8:12 PM
> To: aspectj-users@xxxxxxxxxxx
> Subject: Re: [aspectj-users] LTW and annotations
>
> I agree with Simone. There isn't a good way to effectively find out
> all aspects using some classpath scanning mechanism. Note, however,
> that there is an -outxml (or -outxmlfile <file>) option to 'ajc' that
> will create aop.xml with an entry for all aspects.
>
> -Ramnivas
>
> 2008/10/2 Simone Gianni <simoneg@xxxxxxxxxx>
> Hi Janos,
> unfortunately, at least AFAIK, there is no method in ClassLoader to
> find
> "all resources" in a package. The getResource (findResource,
> findResources etc..) only find resources if you already know the
> complete name of them (complete package). A number of tricks exists,
> like obtaining the path of the jar, then opening it as if it was a zip
> file, and scanning its content .. but they are not applicable in an
> "enterprise" like environment, where a hierarchy of classloaders may
> be
> in place and no direct access to jar files is possible (or even, there
> are no jar files at all). I also feel like this is a problem, but it's
> a
> ClassLoader problem in general, nothing AspectJ can easily fix.
>
> Anyway, exploring all possible classes for the presence of an
> annotation
> would be far too heavy. In even a simple web project there can be
> thousands of classes, scanning all of them so see which are aspects
> before even starting the "main" could require several seconds if not
> minutes.
>
> I can't think of any way to avoid the .xml file, maybe there is one,
> but
> without explicit support from the ClassLoader interface or some other
> java compiler internals (like a quick way to find all classes having a
> specific annotation, that would benefit quite a bit also JPA providers
> for example, which are also bound to XML based class listings in most
> cases) I think it's hard to do it in a reliable and standards
> compatible
> way. I don't think even a standard annotation processor could somehow
> ease this.
>
> Simone
>
> Háber János wrote:
>   
>> Hmm!
>>
>> Tanks.
>>
>> " but have no idea that it exists an aspect"?
>>
>> Maybe a solution: Spring solve this probelm with a very simply way.
>> Get the selected package (maybe in aspectj possible using <include>
>> for this) and get all file-s and directories with
>> classloader.getResource method. And if the selected class is an
>> @Aspect... load it...
>>
>>
>> Janos
>>
>>
>> -----Original Message-----
>> From: aspectj-users-bounces@xxxxxxxxxxx
>> [mailto:aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Simone
>>     
> Gianni
>   
>> Sent: Thursday, October 02, 2008 3:17 PM
>> To: aspectj-users@xxxxxxxxxxx
>> Subject: Re: [aspectj-users] LTW and annotations
>>
>> If I understand how LTW works correctly, the problem is in class
>> loading.
>>
>> Consider the situation where you have a bean with a doSomething
>> method,
>> and then have an advice that does something before that method.
>>
>> You application starts, it will load the bean with a new Bean(). At
>> this
>> point, the class loader loads the bean, but have no idea that it
>> exists
>> an aspect, so will not weave the bean. This is because, you never
>>     
> call
>   
>> (and have explicitly no way) to call "new MyAspect()".
>>
>> In fact, if you had such a way of instantiating aspects, another
>> situation could arise and cause problems. Suppose you have also a
>> tracing aspect, that will intercept all calls to all methods. If
>>     
> this
>   
>> tracing aspect gets loaded AFTER the bean has already been loaded,
>>     
> the
>   
>> class loader is not able anymore to modify the bean, because it has
>> already been loaded.
>>
>> (in reality, there are some ways to do class redefining in recent
>> classloaders, but that brings another lot of problems)
>>
>> So, yes, you have to define your aspects in the aop.xml file. Since
>> this
>> is tedious, the ajc compiler can perform this task for you. If you
>>     
> are
>   
>> using AJDT in Eclipse, there is an option for generating aop.xml on
>> the
>> fly under the AspectJ section of you settings. If you are compiling
>> from
>> command line using ajc, the -outxml option will generate it for you
>> (see
>> http://www.eclipse.org/aspectj/doc/released/devguide/ajc-ref.html ).
>> Also, the maven2 plugin for aspectj will generate the aop.xml file
>>     
> for
>   
>> you.
>>
>> Hope this helps,
>> Simone
>>
>>
>>
>> Háber János wrote:
>>
>>     
>>> Hi!
>>>
>>> I have a question. I want to write an application. I using
>>>       
> javaagent
>   
>>> vm option to LTW. But in this case what needed in aop.xml (aop.xml
>>> required in this case if I not want to set any special weaving
>>> options?)
>>> If I only write:
>>> <aspectj>
>>>     <weaver options="-verbose -showWeaveInfo"/>
>>> </aspectj>
>>>
>>> I get: "no aspects registered. Disabling weaver for class
>>>       
> loader..."
>   
>>> WTF? I need to set the aspects both aop.xml and annotation in java
>>> file? Why?
>>> If Yes, why? The classloader can't detect the annotations?
>>>
>>>
>>> Janos Haber
>>>
>>> _______________________________________________
>>> aspectj-users mailing list
>>> aspectj-users@xxxxxxxxxxx
>>> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>>>
>>>
>>>       
>>
>>     
>
>
> --
> Simone Gianni            CEO Semeru s.r.l.           Apache Committer
> MALE human being programming a computer   http://www.simonegianni.it/
>
> _______________________________________________
> 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
>   


-- 
Simone Gianni            CEO Semeru s.r.l.           Apache Committer
MALE human being programming a computer   http://www.simonegianni.it/



Back to the top