-
-
Save dvdsmpsn/6123333 to your computer and use it in GitHub Desktop.
Maven with Notification Centre support - It's a work in progress.
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/bash | |
# | |
# USAGE: atlas-mvn <parameters and goals> | |
# | |
# Invoke maven with the supplied parameters and goals. | |
# | |
# When the build is complete, send a message to notification centre indicating if the build was successful, and | |
# the directory in which it was run (in case there are multiple builds running concurrently). If you invoked this | |
# script from either Terminal or iTerm2, clicking the notification should take you back to it. | |
# | |
# By using the 'project' as the group, any subsequent build notifications will replace the earlier ones for | |
# the same project, reducing notification centre clutter. | |
# Adapted from: https://github.com/geoffreywiseman/maven-notification-center | |
# Send a Notification to Notification Centre | |
function notify { | |
PROJECT=${PWD##*/} | |
SUBTITLE="in $PROJECT" | |
if [ $1 ]; then | |
TITLE="Build Successful" | |
MESSAGE="Build succeeded in $PROJECT; click to return." | |
else | |
TITLE="Build Failed" | |
MESSAGE="Build failed in $PROJECT; click to return." | |
fi | |
activate_term_program | |
terminal-notifier -title "$1" -subtitle "$SUBITLE" -message "$MESSAGE" -group $PROJECT $ACTIVATE | |
} | |
# Set the 'ACTIVATE' variable based on the terminal in which this is running | |
function activate_term_program { | |
if [ $TERM_PROGRAM = "Apple_Terminal" ]; then | |
ACTIVATE="-activate com.apple.Terminal" | |
elif [ $TERM_PROGRAM = "iTerm.app" ]; then | |
ACTIVATE="-activate com.googlecode.iterm2" | |
else | |
ACTIVATE="" | |
fi | |
} | |
# Print the header comment from this file, ducking the shebang line, and stopping a the first line that doesn't start with a hash | |
function print_header_comment { | |
awk '/^# / { print substr( $0, 3 ) }; $0 !~ /^#/ { exit }' $0 | |
} | |
# Print Usage or Execute | |
if [ $# == 0 ]; then | |
print_header_comment | |
else | |
# See: http://blank.jasonwhaley.com/2009/02/growl-maven-integration.html | |
/usr/local/Cellar/atlassian-plugin-sdk/4.2.2/libexec/apache-maven/bin/mvn.DIST $* | awk ' | |
{ | |
print; | |
if($0 ~ ".*BUILD ERROR.*") notify "Build failed : (" | |
if($0 ~ ".*BUILD SUCCESSFUL.*") notify "Build completed successfully : D" | |
if($0 ~ ".*CTRL-C.*") notify "localhost is now available : D" | |
} | |
END { | |
}' | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment