public
Last active

build your project in the background while you can work on the next bug

  • Download Gist
build.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
#!/bin/bash
# Clones your existing repo and run the maven tests off this clone
# Tests are run on the the current branch at the time of cloning
#
# Note that you can work on the next bug while this is going on as
# tests are run off a cloned repo.
#
# $ build.sh
# runs 'maven clean install'
#
# $ build.sh test -pl module1,module2
# runs 'maven test -pl module1,module2'
#
# A notification is sent upon build completion if your OS supports it:
# - on Mac OS, install Growl and grownnotifier
# - on Linux, install send-notify
#
# Many thanks to David Gageot (http://blog.javabien.net) for the inspiration and optimization of this script.
#
# Released under the WTFPL license version 2 http://sam.zoy.org/wtfpl/
#
# Copyright (c) 2010 David Gageot
# Copyright (c) 2010-2011 Emmanuel Bernard
# Copyright (c) 2011 Sanne Grinovero
 
#the cloned repo will live in ../DIRECTORY_ROOT/REPO_DIRECTORY
DIRECTORY_ROOT="../privatebuild/"
 
#get the lastest part of the directory name
IFS="/"
SPLIT_DIR=(`pwd`)
SIZE=${#SPLIT_DIR[@]}
let LAST_INDEX=$SIZE-1
DIRECTORY_SUFFIX=${SPLIT_DIR[$LAST_INDEX]}
IFS=""
 
DIRECTORY="${DIRECTORY_ROOT}${DIRECTORY_SUFFIX}"
 
BRANCH=`git branch | grep "*" | awk '{print $NF}'`
 
#fresh clone
rm -Rf $DIRECTORY
git clone -slb "$BRANCH" . $DIRECTORY
cd $DIRECTORY
 
echo ""
echo "***** Working on branch $BRANCH *****"
echo ""
 
say() {
if [ `uname -s` == "Darwin" ]; then
# On Mac OS, notify via Growl
which -s growlnotify && growlnotify --name Maven --sticky --message "Maven - Branch $BRANCH - $RESULT"
fi
if [ `uname -s` == "Linux" ]; then
# On Linux, notify via notify-send
which notify-send && notify-send "Maven - branch $BRANCH" "$RESULT"
fi
}
 
if [ -e "pom.xml" ]; then
if [[ $# -eq 0 ]]; then
mvn clean install
else
mvn "$@"
fi
 
if [ $? -eq 0 ]; then
RESULT="Build SUCCESS"
echo $RESULT
say
else
RESULT="Build FAILURE"
echo $RESULT
say
exit $?
fi
fi

I like the growlnotify part :)

Adding this function to the script or even .bashrc allows you to call 'gmvn' instead of 'mvn' whenever you want.

function gmvn()
{
    mvn "$@";
    if [ $? -eq 0 ]; then
        growlnotify --name Maven --message "Build in `pwd` succeeded";
    else
        growlnotify --name Maven --message "Build in `pwd` failed";
    fi  
}

Cette syntaxe permet d'utiliser growlnotify s'il est disponible :
which -s growlnotify && growlnotify Maven -sm "Branch $BRANCH - $RESULT"

Thanks, applied the conditional call to growlnotifier.

I've adapted it to use send-notify on Linux: https://gist.github.com/789588
Thanks!

Thanks, contributed your change back.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.