Monday, June 17, 2013

Maven / Ant Alerts in Ubuntu

The Case of the Forgotten Builds

There are a few projects I work with that have long builds. I have a bad habit of alt-tabbing away from the build and promptly forgetting that I even started it only to come back 15 minutes later and not remembering if/when/why I built the project. What I need is a way for these tools to get my attention when they are done.

libnotify To the Rescue!

So Ubuntu and its variants have a built in notification system that we can build on. By installing the libnotify-bin package we can use this system from the command line. With a short bash function and a few aliases we can have nice notifications for any command line we want!

1. Install libnotify-bin:

sudo apt-get install libnotify-bin

2. Edit ~/.bash_aliases:


    $CMD $@
    BUILD_CMD=`basename $CMD`
    if [ $RETCODE -eq 0 ]
        notify-send -c $BUILD_CMD -i emblem-default -t 3600000 "$BUILD_DIR: $BUILD_CMD successful" "$(date)"
        notify-send -c $BUILD_CMD -i emblem-important -t 3600000 "$BUILD_DIR: $BUILD_CMD failed" "$(date)"
    return $RETCODE
alias ant="cmdstatus ant"
alias mvn="cmdstatus mvn"

3. Restart Your Terminal

Now you get nice success/failure messages out of your ant and mvn commands. The original commands return code is correctly preserved and this cmdstatus wrapper can be easily added to any other command you want via a simple alias line.

1 comment:

Tim Levett said...

Nice feature! I shall install it tomorrow when I am in the office.