11#! /usr/bin/env bash
22
33# Determine the current working directory
4- DIR =" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd ) "
4+ _DIR =" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd ) "
55
66# Called before any binaries are installed for any unknown operating system.
77# Current checks are as follows:
@@ -50,16 +50,21 @@ prep_install_for_osx() {
5050# forced installation,
5151# # Arg1 - application name
5252check_and_install_app () {
53+ # create the local environment variable in uppercase
54+ APP_BIN=" ` echo $1 | awk ' {print toupper(\$0)}' ` _BIN"
55+ # some black magic to set the generated app variable (i.e. MVN_BIN) into the
56+ # environment
57+ eval " ${APP_BIN} =` which $1 2> /dev/null` "
5358 if [ -z " ` which $1 2> /dev/null` " ]; then
5459 # attempt to force install if flagged
5560 if [ -n " ${FORCE_INSTALL} " ]; then
56- local resource=" ${DIR } /packages/$1 .sh"
61+ local resource=" ${_DIR } /packages/$1 .sh"
5762 if [ -f " $resource " ]; then
58- source " ${DIR } /packages/$1 .sh"
63+ source " ${_DIR } /packages/$1 .sh"
5964 prep_install_for_${_OSTYPE}
6065 install_$1 _for_${_OSTYPE}
6166 else
62- echo " ERROR: Cannot find the $1 .sh build file from within ${DIR } /packages."
67+ echo " ERROR: Cannot find the $1 .sh build file from within ${_DIR } /packages."
6368 echo " Ensure the file exists and is accesible."
6469 exit 1
6570 fi
@@ -71,6 +76,23 @@ check_and_install_app() {
7176 fi
7277}
7378
79+ # Prints the help and usage for this script
80+ print_help () {
81+ echo " Spark Build Suite for Maven" && echo
82+ echo " Usage: ./build/mvn <options> -- <mvn-parameters>" && echo
83+ echo " Options:"
84+ echo -e " -p=<port>\t\tSets the port for a local Zinc instance"
85+ echo -e " -f\t\t\tForces install of necessary packages"
86+ echo -e " -h\t\t\tPrints this help message" && echo
87+ echo " Maven Parameters:"
88+ echo " All parameters after the double-dash (--) will be pushed to the Maven"
89+ echo " call. If none are provided the default of 'clean package -DskipTests'"
90+ echo " will be executed." && echo
91+ echo " Examples:"
92+ echo " ./build/mvn -f -- clean package"
93+ echo " ./build/mvn -p=3031 -- clean"
94+ }
95+
7496# Set a cleaned OS type string based on the $OSTYPE bash variable
7597case " $OSTYPE " in
7698 solaris* )
@@ -102,6 +124,10 @@ while [ ! "$OPT" = "--" -a ! $# -eq 0 ]; do
102124 ZINC_PORT=${OPT/ -p=/ }
103125 shift
104126 ;;
127+ -h)
128+ print_help
129+ exit 0
130+ ;;
105131 * )
106132 echo " Unknown option: $OPT "
107133 shift
@@ -119,16 +145,19 @@ check_and_install_app "mvn"
119145check_and_install_app " zinc"
120146check_and_install_app " scala"
121147
122- # Now that zinc is ensured to be installed, check its status and, if not
123- # running, start it
148+ # Reset the current working directory
149+ cd " ${_DIR} /.."
150+
151+ # Now that zinc is ensured to be installed, check its status and, if its
152+ # not running, start it
124153if [ -z " ` zinc -status` " ]; then
125- zinc -start -port ${ZINC_PORT}
154+ ${ZINC_BIN} -start -port ${ZINC_PORT}
126155fi
127156
128157# Determine the parameters pushed in from the command line and, if any are
129158# present, use those within the maven
130159if [ $# -gt 0 ]; then
131- mvn " $@ "
160+ ${MVN_BIN} " $@ "
132161else
133- mvn clean package -DskipTests
162+ ${MVN_BIN} clean package -DskipTests
134163fi
0 commit comments