Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
build your project in the background while you can work on the next bug
#!/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
@hferentschik

This comment has been minimized.

Copy link

commented Jan 20, 2011

I like the growlnotify part :)

@hferentschik

This comment has been minimized.

Copy link

commented Jan 20, 2011

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  
}
@dgageot

This comment has been minimized.

Copy link

commented Jan 20, 2011

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

@emmanuelbernard

This comment has been minimized.

Copy link
Owner Author

commented Jan 20, 2011

Thanks, applied the conditional call to growlnotifier.

@Sanne

This comment has been minimized.

Copy link

commented Jan 21, 2011

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

@emmanuelbernard

This comment has been minimized.

Copy link
Owner Author

commented Jan 21, 2011

Thanks, contributed your change back.

@guillaumerose

This comment has been minimized.

Copy link

commented Mar 11, 2019

If it can help someone: https://gist.github.com/guillaumerose/b6110d8424b7a0796cd3389217f4e832

This version adds colors and is dedicated to push after success.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.