Created
May 31, 2012 04:46
-
-
Save nobeans/2841103 to your computer and use it in GitHub Desktop.
My Grails' Events.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to use: