I've managed to hack something up around this - basically it uses JDT to
parse the necessary Singletons, and then walks through the PreDestroy
and PostContruct methods looking for method invocations. Its pretty
basic at the moment, it does a complete search on every build, rather
than building incrementally. It does work recursively, and will visit
other classes (if you make a call like new MyOtherClass().someMethod()
in the PreDestroy/PostConstruct method for example), so its potentially
a long running operation. It will mark incorrect / missing uses of
@DependsOn as errors.
I've checked it in, but left it to be switched off by default. I'm
planning to add quick fix and incremental build support soon too.
Any comments are welcome. I'm also happy to have a go at providing this
in IntelliJ if that would be useful to anyone.
Jon
David Blevins wrote:
On Aug 7, 2008, at 9:11 AM, Karan Malhi wrote:
I think OPENEJB-516 (https://issues.apache.org/jira/browse/OPENEJB-516)
can be closed, as the plugin will now add the javaee-api and
openejb-client
JARs to the classpath of projects associated with its runtime - does
anyone
have any thoughts on this?
I also think OPENEJB-525 (
https://issues.apache.org/jira/browse/OPENEJB-525) can be closed as the
plugin is now built with Maven.
Yes, these issues should be closed.
Also, I think David just implemented the DependsOn functionality.
What do
you think about generating a dependency graph in eclipse? i.e the plugin
could scrape through the EJB's / descriptors and generate this graph
(which
could possibly also be modified).
Along those lines what would be really cool is if the tool could add
the @DependsOn automatically for a user.
A singleton needs a @DependsOn declaration only when referring to
(invoking) another singleton in either its @PostConstruct or
@PreDestroy method. I don't know if it's possible, but if there was
some way spot that and add the @DependsOn for them, that'd be really
cool.
As an example, the bean has this:
@Singleton
@Startup
public class RedBean {
@EJB(beanName="BlueBean")
private BlueLocal blue
@PostConstruct
public void startup() {
}
}
and all is fine, but when they add this to the @PostConstruct method...
@PostConstruct
public void startup() {
blue.doSomeWork();
}
At that point you need to add the @DependsOn like so:
@Singleton
@Startup
@DependsOn("BlueBean")
public class RedBean {
...
}
Don't know if that's possible, but would be cool.
-David