The problem is that java doesn't allow to find all classes having a
given annotation for ex. So you need to do complex classpath/
classloader voodoo magic to get that:
-
http://code.google.com/p/reflections/
-
http://bill.burkecentral.com/2008/01/14/scanning-java-annotations-at-runtim…
The pb is that this magic will not work if we want to distribute some
modules as frameworks (and not as applications) since we don't control
the classapth/classloader in that case.
So I see only 2 solutions:
1) we generate the components.xml from annotations at build time (btw
this is the approach followed by plexus, they have a maven plugin to
do this -
http://plexus.codehaus.org/plexus-maven-plugin/plugin-info.html)
. Pb is that this won't use our annotations so we'd need to implement
something similar (pain)
2) we create a META-INF/services/components.list file listing all
classes that are components (this can be genertaed too at build time
if need be) and our init code loads all these files and use
introspection to find annotations and register components dynamically.
Any other idea? WDYT?
Thanks
-Vincent
On Mar 26, 2009, at 11:21 AM, Vincent Massol wrote:
Hi devs,
I'm continuing on this topic since I really believe we need
annotations now. However I think it's best to have our own
annotations for injection.
One reason we need annotation (amongst other needs) is in order to
be able to create a xwiki uberjar for rendering modules for example.
With components.xml you cannot easily merge jars since you'd need to
merge components.xml so you'd need to write some xslt code for that.
Another reason is that we have to comment in the code things such as
"this field is injected automatically by the component manager". Of
course this comment is forgotten most of the time. It's much nicer
to have a @Inject annotation.
Last we need annotations if we want to be able to more easily
support different IOC frameworks since otherwise it means that for
each fwk we need to do again all components mappings in a static way.
Of course one basic need is evidently to reduce the number of config
lines we have to write and the errors associated with them.
I'm going to look into plexus annotations for a starter (+ guice) to
see how they do it and then I'll make a proposal for annotations.
Let me know what you think.
Thanks
-Vincent