« Return to Thread: Extending the _Event system in Grails (Re: was something else I can't remember now)

Re: Extending the _Event system in Grails (Re: was something else I can't remember now)

by Graeme Rocher-3 :: Rate this Message:

Reply to Author | View in Thread

Hi Richard,

_Events.groovy is a script and hence like all other scripts it plays by the same rules in that you don't have access to sources from inside the script unless you explicitly compile and load them. You need to depend on compile() and classpath() and then use the classloader to explicitly load your classes:

myClass = classLoader.loadClass("MyClass")

The reason is this is because some events run before compilation happens. You can't have it both ways.

As for the missing CompileEnd event, in Grails 1.1 we removed the majority of hard coded events. Now Grails will fire an event whenever it encounters a target. So for:

target(name:"compile)

You will get CompileStart and CompileEnd events

Cheers

On Mon, Jun 22, 2009 at 3:46 AM, Richard Vowles <richard@...> wrote:
Ok, so since no-one responded to me about their ideal way to solve the problem I am going to propose a solution and if I don't get any "but nay!" comments, I'll go ahead and implement a patch and attach it to a JIRA.

My *suggestion* is this - extend the loadEventsHooks in GrailsBuildEventListener so that it looks for all scripts that *start* with _Events. It processes plain _Events as normal, and when an event is fired it checks to see if there are any _Event_That_Event_Name.groovy scripts anywhere, and if so, loads them in with loadEventScript.

I would have sworn there was an event ("CompileEnd") in the _GrailsCompile.groovy, but I can no-longer find it anywhere. It might be worthwhile to pepper more events around, but I think this is the biggie.

Thus if people need stuff to load after the compilation, they can create a script called _Events_Compile_End.groovy and that will load the extra event triggers into the namespace.

On Fri, Jun 19, 2009 at 11:53 AM, Luke Daley <ld@...> wrote:

Richard,

The chicken and egg problem with _Events and _Install really is a bug. Rather than workaround it, it would be great if someone actually fixed this at the source.

I think the same can be said for what you are planning for enhancing the test running infrastructure. That probably should go into core.

All of that said, I know that it is easier to workaround Grails issues in the plugin space (guilty myself) but if at all possible we should be fixing at the root.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

  http://xircles.codehaus.org/manage_email





--
---
Richard Vowles,
Talk to me about development in Grails, Groovy, Java and for the Blackberry
ph: +64275467747, linkedin, skype:rvowles
get 2Gb shared disk space in the cloud - Dropbox, its incredibly useful! - http://tinyurl.com/cmcceh
podcast: http://www.illegalargument.com



--
Graeme Rocher
Head of Grails Development
SpringSource - Weapons for the War on Java Complexity
http://www.springsource.com

 « Return to Thread: Extending the _Event system in Grails (Re: was something else I can't remember now)