Script event hooks are cool
Grails has had the so called 'event hooks' for Gant scripts since 0.5. It basically is a way to tap into the Grails Gant scripts execution flow to customize build process, etc. It is elegantly implemented (as everything else in Grails) as a collection of closures in the Events.groovy script. The 'event closures' get called by Grails when the corresponding 'events' get generated in the Gant script e.g. a method 'event' is called with the event name as a parameter. So for example, event("StatusUpdate", [ "Status update event is called"]) would result in eventStatusUpdate { msg -> } closure defined in Events.groovy being called.
So, at work, for the typical Spring web applications we use Ant-based "common build" system originally created by the Spring guys. The common build uses ivy for the dependency resolution, so we have a custom ivyconf.xml which contains definitions for our local dependency repository, etc.
Grails has an ivy plugin, but when installing it for each web app, it puts the default ivyconf.xml into the root of the web app. So, I needed a way to 'tap' into the _Install.groovy script of the plugin to copy our local invyconf.xml. Sure enough the script 'statusUpdate' hook did the trick.
Here is the Events.groovy:
static final ESS_IVYCONF_FILE_LOCATION = "$userHome/.common-build/ntg/common-build"
eventStatusUpdate = { msg ->
if(msg ==~ /.*ivyconf.xml.*/) {
println "Copying ESS ivyconf.xml from common-build global directory ..."
Ant.copy(todir: "${basedir}", overwrite: true) {
fileset(dir: "$ESS_IVYCONF_FILE_LOCATION") {
include(name: "ivyconf.xml")
}
}
}
}
Later...

0 comments:
Post a Comment