Skip to content

Commit 4a1609c

Browse files
author
Brennon York
committed
finalizing working linux install for maven to local ./build/apache-maven folder
1 parent cbfcc68 commit 4a1609c

File tree

4 files changed

+71
-11
lines changed

4 files changed

+71
-11
lines changed

build/mvn

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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
5252
check_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
7597
case "$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"
119145
check_and_install_app "zinc"
120146
check_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
124153
if [ -z "`zinc -status`" ]; then
125-
zinc -start -port ${ZINC_PORT}
154+
${ZINC_BIN} -start -port ${ZINC_PORT}
126155
fi
127156

128157
# Determine the parameters pushed in from the command line and, if any are
129158
# present, use those within the maven
130159
if [ $# -gt 0 ]; then
131-
mvn "$@"
160+
${MVN_BIN} "$@"
132161
else
133-
mvn clean package -DskipTests
162+
${MVN_BIN} clean package -DskipTests
134163
fi

build/packages/mvn.sh

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,30 @@
11
#!/usr/bin/env bash
22

3+
# Determine the current working directory
4+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
5+
36
MVN_URL="http://apache.claz.org/maven/maven-3/3.2.3/binaries/apache-maven-3.2.3-bin.tar.gz"
7+
MVN_LOC="${DIR}/../apache-maven-3.2.3-bin.tar.gz"
48

59
install_mvn_for_linux() {
6-
echo
10+
local mvn_bin="${DIR}/../apache-maven-3.2.3/bin/mvn"
11+
12+
if [ ! -f "${mvn_bin}" ]; then
13+
# first check if we have curl installed and, if so, download Leiningen
14+
[ -n "`which curl 2>/dev/null`" ] && curl "${MVN_URL}" > "${MVN_LOC}"
15+
# if the `lein` file still doesn't exist, lets try `wget` and cross our fingers
16+
[ ! -f "${MVN_LOC}" ] && [ -n "`which wget 2>/dev/null`" ] && wget -O "${MVN_LOC}" "${MVN_URL}"
17+
# if both weren't successful, exit
18+
[ ! -f "${MVN_LOC}" ] && \
19+
echo "ERROR: Cannot find or download a version of Maven, please install manually and try again." && \
20+
exit 2
21+
cd "${DIR}/.." && tar -xzf "${MVN_LOC}"
22+
fi
23+
export MVN_BIN="${mvn_bin}"
724
}
825

926
install_mvn_for_osx() {
1027
brew install maven
28+
export MVN_BIN=`which mvn`
1129
}
1230

build/packages/scala.sh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
#!/usr/bin/env bash
22

3+
# Determine the current working directory
4+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
5+
36
SCALA_URL="http://downloads.typesafe.com/scala/2.11.4/scala-2.11.4.tgz"
7+
SCALA_LOC="${DIR}/../scala/scala-2.11.4.tgz"
48

59
install_scala_for_linux() {
6-
echo
10+
# first check if we have curl installed and, if so, download Leiningen
11+
[ -n "`which curl 2>/dev/null`" ] && curl "${SCALA_URL}" > "${SCALA_LOC}"
12+
# if the `lein` file still doesn't exist, lets try `wget` and cross our fingers
13+
[ ! -f "${SCALA_LOC}" ] && [ -n "`which wget 2>/dev/null`" ] && wget -O "${SCALA_LOC}" "${SCALA_URL}"
14+
# if both weren't successful, exit
15+
[ ! -f "${SCALA_LOC}" ] && \
16+
echo "ERROR: Cannot find or download a version of Scala, please install manually and try again." && \
17+
exit 2
718
}
819

920
install_scala_for_osx() {
1021
brew install scala
22+
export SCALA_BIN=`which scala`
1123
}

build/packages/zinc.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ install_zinc_for_linux() {
88

99
install_zinc_for_osx() {
1010
brew install zinc
11+
export ZINC_BIN=`which zinc`
1112
}

0 commit comments

Comments
 (0)