Skip to content

Instantly share code, notes, and snippets.

@nobeans
Created May 31, 2012 04:46
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nobeans/2841103 to your computer and use it in GitHub Desktop.
Save nobeans/2841103 to your computer and use it in GitHub Desktop.
My Grails' Events.groovy
// Variables
def grailsHome = grailsSettings.grailsHome
def baseDir = buildSettings.baseDir.absolutePath
def testReportsDir = grailsSettings.testReportsDir
def failedTests = [:]
// Helper methods
def growlnotify = { priority, title, message, openTarget = null ->
def cmd = [
System.properties["user.home"] + "/.grails/scripts/growlAndOpen.sh",
grailsHome,
priority,
title,
openTarget ?: 'NO_TARGET',
message,
]
cmd.execute()
}
def debug = growlnotify.curry(-2, "Debug")
def info = growlnotify.curry(0)
def warn = growlnotify.curry(1)
def error = growlnotify.curry(2)
// Event handlers
eventStatusFinal = { msg ->
// Skip if test phase
if (grailsEnv == "test") return
// If you click too earlier, the server which hasn't be ready yet might return 503.
def urls = (msg =~ /^Server running. Browse to (http:.*)$/).collect { matched, url -> url }
if (urls) {
info 'Server running', "${msg}\nClick here to open the url", urls.first()
} else {
info 'Status', msg
}
}
eventStatusError = { msg ->
error 'Error', msg
}
eventExiting = { code ->
error 'Exit', "Return code: ${code}"
}
eventTestFailure = { name, failure, isError ->
warn "Test failure", "${name}: ${failure}"
failedTests[name] = failure
}
eventTestPhasesEnd = {
def file = "${testReportsDir}/html/index.html"
if (failedTests) {
error "${failedTests.size()} tests failed", "Click here to open the report", file
} else {
info "All tests passed", "Click here to open the report", file
}
}
#!/bin/sh
GRAILS_HOME=$1
shift
PRIORITY=$1
shift
TITLE=$1
shift
OPEN_TARGET=$1
shift
MESSAGE=$*
/usr/local/bin/growlnotify \
-n Grails \
--image $GRAILS_HOME/media/icons/favicon48.png \
-p $PRIORITY \
-t "$TITLE" \
-m "$MESSAGE" \
-w
if [ $? -eq 2 ] && [ "$OPEN_TARGET" != "NO_TARGET" ]; then
/usr/bin/open "$OPEN_TARGET"
fi
@nobeans
Copy link
Author

nobeans commented Jun 1, 2012

How to use:

  • Copy them to $HOME/.grails/scripts
  • Give +x permission to growlAndOpen.sh
  • Enjoy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment