Showing posts with label Maven. Show all posts
Showing posts with label Maven. Show all posts

Wednesday, June 19, 2013

Maven / Ant Alerts in OS X

The Case of the Forgotten Builds (Mac Edition)

You can see my previous post on Maven / Ant Alerts in Ubuntu for the Linux version

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.

growlnotify To the Rescue!

Growl, a popular notifications app for OS X has a nice command line utility called growlnotify. Download an install it from that link and then with a short bash function and a few aliases we can have nice notifications for any command line we want!

The OS X Terminal as of 10.7 also responds to the "bel" escape character if it is in the background. For each bel that occurs while the Terminal is in the background a numeric badge appears and the counter it shows increments. The Terminal app icon also bounces a few times.

The combination of Growl and the Terminal bel provide a nice notification system that your command is done.

1. Install Growl and growlnotify

2. Edit ~/.bash_aliases:

cmdstatus()
{
    CMD=$1
    shift
 
    $CMD $@
    RETCODE=$?
    BUILD_DIR=${PWD##*/}
    BUILD_CMD=`basename $CMD`
    if [ $RETCODE -eq 0 ]
    then
        printf '\a'
        growlnotify -s -d $BUILD_CMD -n $BUILD_CMD -m "$BUILD_DIR: $BUILD_CMD successful
$(date)"
    else
        printf '\a\a'
        growlnotify -s -d $BUILD_CMD -n $BUILD_CMD -m "$BUILD_DIR: $BUILD_CMD failed
$(date)"
    fi
    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.





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:

cmdstatus()
{
    CMD=$1
    shift

    $CMD $@
    RETCODE=$?
    BUILD_DIR=${PWD##*/}
    BUILD_CMD=`basename $CMD`
    if [ $RETCODE -eq 0 ]
    then
        notify-send -c $BUILD_CMD -i emblem-default -t 3600000 "$BUILD_DIR: $BUILD_CMD successful" "$(date)"
    else
        notify-send -c $BUILD_CMD -i emblem-important -t 3600000 "$BUILD_DIR: $BUILD_CMD failed" "$(date)"
    fi
    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.


Tuesday, January 15, 2008

Using Ant with a Maven project

I recently had to take a Maven 2 WAR project and make it buildable on a system that did not have Maven available. Not being one to duplicate configuration I put together an Ant build script that, when Maven is available, can be used to pull the dependencies into the project file structure in an organized fashion and write out properties about the maven project for use by the script.

Currently the script provides support for doing the equivalent of 'mvn clean package' on a simple Maven managed WAR project.



As you can see at the end of the script it depends on Ant Contrib and Maven Ant Tasks.