diff --git a/build/mvn b/build/mvn index 9e968e4fd5a98..b9f1b2a532a5c 100755 --- a/build/mvn +++ b/build/mvn @@ -1,7 +1,7 @@ #!/usr/bin/env bash # Determine the current working directory -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" # Called before any binaries are installed for any unknown operating system. # Current checks are as follows: @@ -50,16 +50,21 @@ prep_install_for_osx() { # forced installation, ## Arg1 - application name check_and_install_app() { + # create the local environment variable in uppercase + APP_BIN="`echo $1 | awk '{print toupper(\$0)}'`_BIN" + # some black magic to set the generated app variable (i.e. MVN_BIN) into the + # environment + eval "${APP_BIN}=`which $1 2>/dev/null`" if [ -z "`which $1 2>/dev/null`" ]; then # attempt to force install if flagged if [ -n "${FORCE_INSTALL}" ]; then - local resource="${DIR}/packages/$1.sh" + local resource="${_DIR}/packages/$1.sh" if [ -f "$resource" ]; then - source "${DIR}/packages/$1.sh" + source "${_DIR}/packages/$1.sh" prep_install_for_${_OSTYPE} install_$1_for_${_OSTYPE} else - echo "ERROR: Cannot find the $1.sh build file from within ${DIR}/packages." + echo "ERROR: Cannot find the $1.sh build file from within ${_DIR}/packages." echo " Ensure the file exists and is accesible." exit 1 fi @@ -71,6 +76,23 @@ check_and_install_app() { fi } +# Prints the help and usage for this script +print_help() { + echo "Spark Build Suite for Maven" && echo + echo "Usage: ./build/mvn -- " && echo + echo " Options:" + echo -e " -p=\t\tSets the port for a local Zinc instance" + echo -e " -f\t\t\tForces install of necessary packages" + echo -e " -h\t\t\tPrints this help message" && echo + echo " Maven Parameters:" + echo " All parameters after the double-dash (--) will be pushed to the Maven" + echo " call. If none are provided the default of 'clean package -DskipTests'" + echo " will be executed." && echo + echo " Examples:" + echo " ./build/mvn -f -- clean package" + echo " ./build/mvn -p=3031 -- clean" +} + # Set a cleaned OS type string based on the $OSTYPE bash variable case "$OSTYPE" in solaris*) @@ -102,6 +124,10 @@ while [ ! "$OPT" = "--" -a ! $# -eq 0 ]; do ZINC_PORT=${OPT/-p=/} shift ;; + -h) + print_help + exit 0 + ;; *) echo "Unknown option: $OPT" shift @@ -119,16 +145,19 @@ check_and_install_app "mvn" check_and_install_app "zinc" check_and_install_app "scala" -# Now that zinc is ensured to be installed, check its status and, if not -# running, start it +# Reset the current working directory +cd "${_DIR}/.." + +# Now that zinc is ensured to be installed, check its status and, if its +# not running, start it if [ -z "`zinc -status`" ]; then - zinc -start -port ${ZINC_PORT} + ${ZINC_BIN} -start -port ${ZINC_PORT} fi # Determine the parameters pushed in from the command line and, if any are # present, use those within the maven if [ $# -gt 0 ]; then - mvn "$@" + ${MVN_BIN} "$@" else - mvn clean package -DskipTests + ${MVN_BIN} clean package -DskipTests fi diff --git a/build/packages/mvn.sh b/build/packages/mvn.sh index 1a37853f86c1c..bbc1c0c5282e8 100644 --- a/build/packages/mvn.sh +++ b/build/packages/mvn.sh @@ -1,12 +1,30 @@ #!/usr/bin/env bash +# Determine the current working directory +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + MVN_URL="http://apache.claz.org/maven/maven-3/3.2.3/binaries/apache-maven-3.2.3-bin.tar.gz" +MVN_LOC="${DIR}/../apache-maven-3.2.3-bin.tar.gz" install_mvn_for_linux() { - echo + local mvn_bin="${DIR}/../apache-maven-3.2.3/bin/mvn" + + if [ ! -f "${mvn_bin}" ]; then + # first check if we have curl installed and, if so, download Leiningen + [ -n "`which curl 2>/dev/null`" ] && curl "${MVN_URL}" > "${MVN_LOC}" + # if the `lein` file still doesn't exist, lets try `wget` and cross our fingers + [ ! -f "${MVN_LOC}" ] && [ -n "`which wget 2>/dev/null`" ] && wget -O "${MVN_LOC}" "${MVN_URL}" + # if both weren't successful, exit + [ ! -f "${MVN_LOC}" ] && \ + echo "ERROR: Cannot find or download a version of Maven, please install manually and try again." && \ + exit 2 + cd "${DIR}/.." && tar -xzf "${MVN_LOC}" + fi + export MVN_BIN="${mvn_bin}" } install_mvn_for_osx() { brew install maven + export MVN_BIN=`which mvn` } diff --git a/build/packages/scala.sh b/build/packages/scala.sh index 1c25edf902a6d..28b1d2f578d1b 100644 --- a/build/packages/scala.sh +++ b/build/packages/scala.sh @@ -1,11 +1,23 @@ #!/usr/bin/env bash +# Determine the current working directory +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + SCALA_URL="http://downloads.typesafe.com/scala/2.11.4/scala-2.11.4.tgz" +SCALA_LOC="${DIR}/../scala/scala-2.11.4.tgz" install_scala_for_linux() { - echo + # first check if we have curl installed and, if so, download Leiningen + [ -n "`which curl 2>/dev/null`" ] && curl "${SCALA_URL}" > "${SCALA_LOC}" + # if the `lein` file still doesn't exist, lets try `wget` and cross our fingers + [ ! -f "${SCALA_LOC}" ] && [ -n "`which wget 2>/dev/null`" ] && wget -O "${SCALA_LOC}" "${SCALA_URL}" + # if both weren't successful, exit + [ ! -f "${SCALA_LOC}" ] && \ + echo "ERROR: Cannot find or download a version of Scala, please install manually and try again." && \ + exit 2 } install_scala_for_osx() { brew install scala + export SCALA_BIN=`which scala` } diff --git a/build/packages/zinc.sh b/build/packages/zinc.sh index 3d5e8ece9ca9d..807520aef82ef 100644 --- a/build/packages/zinc.sh +++ b/build/packages/zinc.sh @@ -8,4 +8,5 @@ install_zinc_for_linux() { install_zinc_for_osx() { brew install zinc + export ZINC_BIN=`which zinc` }