Skip to content

Commit ef017e6

Browse files
author
Brennon York
committed
removed OS complexities, setup generic install_app call, removed extra file complexities, removed help, removed forced install (defaults now), removed double-dash from cli
1 parent 07bf018 commit ef017e6

File tree

1 file changed

+64
-143
lines changed

1 file changed

+64
-143
lines changed

build/mvn

Lines changed: 64 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,69 @@
33
# Determine the current working directory
44
_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
55

6-
# Called before any binaries are installed for any unknown operating system.
7-
# Current checks are as follows:
8-
# - NA
9-
prep_install_for_unknown() {
10-
echo "ERROR: Forced installation is not available at this time for an"
11-
echo "Operating System of type $OSTYPE"
12-
exit 1
13-
}
14-
15-
# Called before any binaries are installed for the Solaris operating system.
16-
# Current checks are as follows:
17-
# - NA
18-
prep_install_for_solaris() {
19-
echo "ERROR: Forced installation is not available at this time for"
20-
echo "Solaris-based systems."
21-
exit 1
6+
# Installs any application tarball given a URL, the expected tarball name,
7+
# and, optionally, a checkable binary path to determine if the binary has
8+
# already been installed
9+
## Arg1 - URL
10+
## Arg2 - Tarball Name
11+
## Arg3 - Checkable Binary
12+
install_app() {
13+
local remote_tarball="$1/$2"
14+
local local_tarball="${_DIR}/$2"
15+
local binary="${_DIR}/$3"
16+
if [ -z "$3" -o ! -f "$binary" ]; then
17+
# check if we already have the tarball
18+
# check if we have curl installed
19+
# download application
20+
[ ! -f "${local_tarball}" ] && [ -n "`which curl 2>/dev/null`" ] && \
21+
curl "${remote_tarball}" > "${local_tarball}"
22+
# if the file still doesn't exist, lets try `wget` and cross our fingers
23+
[ ! -f "${local_tarball}" ] && [ -n "`which wget 2>/dev/null`" ] && \
24+
wget -O "${local_tarball}" "${remote_tarball}"
25+
# if both were unsuccessful, exit
26+
[ ! -f "${local_tarball}" ] && \
27+
echo -n "ERROR: Cannot download $2 with cURL or wget; " && \
28+
echo "please install manually and try again." && \
29+
exit 2
30+
cd "${_DIR}" && tar -xzf "$2"
31+
rm -rf "$local_tarball"
32+
fi
2233
}
2334

24-
# Called before any binaries are installed for the BSD operating system.
25-
# Current checks are as follows:
26-
# - NA
27-
prep_install_for_bsd() {
28-
echo "ERROR: Forced installation is not available at this time for BSD-based systems."
29-
exit 1
35+
install_mvn() {
36+
install_app \
37+
"http://apache.claz.org/maven/maven-3/3.2.3/binaries" \
38+
"apache-maven-3.2.3-bin.tar.gz" \
39+
"apache-maven-3.2.3/bin/mvn"
40+
MVN_BIN="${_DIR}/apache-maven-3.2.3/bin/mvn"
3041
}
3142

32-
# Called before any binaries are installed for the Linux operating system.
33-
# Current checks are as follows:
34-
# - NA
35-
prep_install_for_linux() {
36-
echo -n ""
43+
install_zinc() {
44+
ZINC_INSTALL_FLAG=1
45+
install_app \
46+
"http://downloads.typesafe.com/zinc/0.3.5.3" \
47+
"zinc-0.3.5.3.tgz" \
48+
"zinc-0.3.5.3/bin/zinc"
49+
ZINC_BIN="${_DIR}/zinc-0.3.5.3/bin/zinc"
3750
}
3851

39-
# Called before any binaries are installed for the OSX operating system.
40-
# Current checks are as follows:
41-
# - 'brew' must be installed
42-
prep_install_for_osx() {
43-
[ -z "`which brew 2>/dev/null`" ] && \
44-
echo "ERROR: Must have 'brew' installed for forced installation on OSX." && \
45-
echo " - You can download 'brew' at: http://brew.sh/" && \
52+
install_scala() {
53+
[ -z "`which python 2>/dev/null`" ] && \
54+
echo "ERROR: Found no `python` package; please install one and try again." && \
4655
exit 1
56+
# determine the Scala version used in Spark
57+
local scala_version=`python -c "
58+
from xml.dom import minidom
59+
print(minidom.parse('${_DIR}/../pom.xml').getElementsByTagName('scala.version')[0].firstChild.data)"`
60+
local scala_bin="${_DIR}/scala-${scala_version}/bin/scala"
61+
62+
install_app \
63+
"http://downloads.typesafe.com/scala/${scala_version}" \
64+
"scala-${scala_version}.tgz" \
65+
"scala-${scala_version}/bin/scala"
66+
67+
SCALA_COMPILER="$(cd "$(dirname ${scala_bin})/../lib" && pwd)/scala-compiler.jar"
68+
SCALA_LIBRARY="$(cd "$(dirname ${scala_bin})/../lib" && pwd)/scala-library.jar"
4769
}
4870

4971
# Determines if a given application is already installed. If not, will attempt
@@ -54,141 +76,40 @@ prep_install_for_osx() {
5476
# - Current supported operating systems are Linux, Solaris, BSD, and OSX
5577
## Arg1 - application name
5678
check_and_install_app() {
57-
local resource="${_DIR}/packages/$1.sh"
5879
# create the local environment variable in uppercase
5980
local app_bin="`echo $1 | awk '{print toupper(\$0)}'`_BIN"
6081
# some black magic to set the generated app variable (i.e. MVN_BIN) into the
6182
# environment
6283
eval "${app_bin}=`which $1 2>/dev/null`"
6384

6485
if [ -z "`which $1 2>/dev/null`" ]; then
65-
# attempt to force install if flagged
66-
if [ -n "${FORCE_INSTALL}" ]; then
67-
# Check and source the package build file if present, else error out
68-
if [ -f "$resource" ]; then
69-
source "${_DIR}/packages/$1.sh"
70-
prep_install_for_${_OSTYPE}
71-
install_$1_for_${_OSTYPE}
72-
else
73-
echo "ERROR: Cannot find the $1.sh build file from within ${_DIR}/packages."
74-
echo " Ensure the file exists and is accesible."
75-
exit 1
76-
fi
77-
else
78-
echo "ERROR: $1 isn't installed; please install or automatically force install (-f)."
79-
exit 2
80-
fi
86+
install_$1
8187
fi
8288
}
8389

84-
check_and_download_scala() {
85-
# Using Python's minidom model, parse the pom.xml and retrieve the Scala version
86-
local scala_version=`python -c "
87-
from xml.dom import minidom
88-
print(minidom.parse('pom.xml').getElementsByTagName('scala.version')[0].firstChild.data)"`
89-
local scala_url="http://downloads.typesafe.com/scala/${scala_version}/scala-${scala_version}.tgz"
90-
local scala_loc="${_DIR}/scala-${scala_version}.tgz"
91-
local scala_bin="${_DIR}/scala-${scala_version}/bin/scala"
92-
93-
if [ ! -f "${scala_bin}" ]; then
94-
# check if we already have the tarball; check if we have curl installed; download `scala`
95-
[ ! -f "${scala_loc}" ] && [ -n "`which curl 2>/dev/null`" ] && curl "${scala_url}" > "${scala_loc}"
96-
# if the `scala` file still doesn't exist, lets try `wget` and cross our fingers
97-
[ ! -f "${scala_loc}" ] && [ -n "`which wget 2>/dev/null`" ] && wget -O "${scala_loc}" "${scala_url}"
98-
# if both were unsuccessful, exit
99-
[ ! -f "${scala_loc}" ] && \
100-
echo "ERROR: Cannot find or download a version of Scala, please install manually and try again." && \
101-
exit 2
102-
cd "${_DIR}" && tar -xzf "${scala_loc}"
103-
rm -rf "${scala_loc}"
104-
fi
105-
SCALA_COMPILER="$(cd "$(dirname ${scala_bin})/../lib" && pwd)/scala-compiler.jar"
106-
SCALA_LIBRARY="$(cd "$(dirname ${scala_bin})/../lib" && pwd)/scala-library.jar"
107-
}
108-
109-
# Prints the help and usage for this script
110-
print_help() {
111-
echo "Spark Build Suite for Maven" && echo
112-
echo "Usage: build/mvn <options> -- <mvn-parameters>" && echo
113-
echo " Options:"
114-
echo -e " -p=<port>\t\tSets the port for a local Zinc instance"
115-
echo -e " -f\t\t\tForces install of necessary packages"
116-
echo -e " -h\t\t\tPrints this help message" && echo
117-
echo " Maven Parameters:"
118-
echo " All parameters after the double-dash (--) will be pushed to the Maven"
119-
echo " call. If none are provided the default of 'clean package -DskipTests'"
120-
echo " will be executed." && echo
121-
echo " Examples:"
122-
echo " build/mvn -f -- clean package"
123-
echo " build/mvn -p=3031 -- clean"
124-
}
125-
126-
# Set a cleaned OS type string based on the $OSTYPE bash variable
127-
case "$OSTYPE" in
128-
solaris*)
129-
_OSTYPE="solaris"
130-
;;
131-
darwin*)
132-
_OSTYPE="osx"
133-
;;
134-
linux*)
135-
_OSTYPE="linux"
136-
;;
137-
bsd*)
138-
_OSTYPE="bsd"
139-
;;
140-
*)
141-
_OSTYPE="unknown"
142-
;;
143-
esac
144-
145-
# Here we build our own CLI event loop with the '--' as the stop
146-
OPT="$1"
147-
while [ ! "$OPT" = "--" -a ! $# -eq 0 ]; do
148-
case $OPT in
149-
-f)
150-
FORCE_INSTALL=1
151-
shift
152-
;;
153-
-p=*)
154-
ZINC_PORT=${OPT/-p=/}
155-
shift
156-
;;
157-
-h)
158-
print_help
159-
exit 0
160-
;;
161-
*)
162-
shift
163-
;;
164-
esac
165-
OPT="$1"
166-
done
167-
shift
168-
169-
# Setup healthy defaults for the Zinc port if none were provided
90+
# Setup healthy defaults for the Zinc port if none were provided from
91+
# the environment
17092
ZINC_PORT=${ZINC_PORT:-"3030"}
17193

17294
# Check and install all applications necessary to build Spark
17395
check_and_install_app "mvn"
17496
check_and_install_app "zinc"
17597

17698
# Check and download the proper version of Scala for the build
177-
check_and_download_scala
99+
install_scala
178100

179101
# Reset the current working directory
180102
cd "${_DIR}/.."
181103

182104
# Now that zinc is ensured to be installed, check its status and, if its
183105
# not running, start it
184-
if [ -n "`${ZINC_BIN} -status`" ]; then
106+
if [ -n "${ZINC_INSTALL_FLAG}" -o -z "`${ZINC_BIN} -status`" ]; then
185107
${ZINC_BIN} -shutdown
108+
${ZINC_BIN} -start -port ${ZINC_PORT} \
109+
-scala-compiler "${SCALA_COMPILER}" \
110+
-scala-library "${SCALA_LIBRARY}"
186111
fi
187112

188-
${ZINC_BIN} -start -port ${ZINC_PORT} \
189-
-scala-compiler "${SCALA_COMPILER}" \
190-
-scala-library "${SCALA_LIBRARY}"
191-
192113
# Determine the parameters pushed in from the command line and, if any are
193114
# present, use those within the maven
194115
if [ $# -gt 0 ]; then

0 commit comments

Comments
 (0)