4.3 Hooking into Events - Reference Documentation
Authors: Andres Almiray
Version: 1.2.0
4.3 Hooking into Events
Griffon provides the ability to hook into scripting events. These are events triggered during execution of Griffon target and plugin scripts.The mechanism is deliberately simple and loosely specified. The list of possible events is not fixed in any way, so it is possible to hook into events triggered by plugin scripts, for which there is no equivalent event in the core target scripts.Defining event handlers
Event handlers are defined in scripts called_Events.groovy
. Griffon searches for these scripts in the following locations:
USER_HOME/.griffon/scripts
- user-specific event handlersPROJECT_HOME/scripts
- application-specific event handlersPLUGINS_HOME/*/scripts
- plugin-specific event handlers
_Events.groovy
file.Event handlers are blocks defined in _Events.groovy
, with a name beginning with "event". The following example can be put in your /scripts directory to demonstrate the feature:eventCreatedArtefact = { type, name ->
println "Created $type $name"
}eventStatusUpdate = { msg ->
println msg
}eventStatusFinal = { msg ->
println msg
}
eventCreatedArtefact
, eventStatusUpdate
, eventStatusFinal
. Griffon provides some standard events, which are documented in the command line reference guide. For example the compile command fires the following events:
CompileStart
- Called when compilation starts, passing the kind of compile - source or testsCompileEnd
- Called when compilation is finished, passing the kind of compile - source or tests
Triggering events
To trigger an event simply call the event() closure:event("StatusFinal", ["Super duper plugin action complete!"])
Common Events
Below is a table of some of the common events that can be leveraged:Event | Parameters | Description |
---|---|---|
StatusUpdate | message | Passed a string indicating current script status/progress |
StatusError | message | Passed a string indicating an error message from the current script |
StatusFinal | message | Passed a string indicating the final script status message, i.e. when completing a target, even if the target does not exit the scripting environment |
CreatedArtefact | artefactType,artefactName | Called when a create-xxxx script has completed and created an artifact |
CreatedFile | fileName | Called whenever a project source filed is created, not including files constantly managed by Griffon |
Exiting | returnCode | Called when the scripting environment is about to exit cleanly |
PluginInstalled | pluginName | Called after a plugin has been installed |
CompileSourcesStart | kind | Called when compilation starts |
CompileSourcesEnd | kind | Called when compilation is finished |
DocStart | kind | Called when documentation generation is about to start - javadoc or groovydoc |
DocEnd | kind | Called when documentation generation has ended - javadoc or groovydoc |