Skip to content

Commit b2a7fbf

Browse files
committed
add sbt
1 parent dd638b5 commit b2a7fbf

7 files changed

+359
-0
lines changed

.gitignore

+17
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,20 @@ target/
1515
*.asc
1616
*.gpg
1717
/bin/
18+
19+
*.class
20+
*.log
21+
*.pyc
22+
sbt/*.jar
23+
24+
# sbt specific
25+
.cache/
26+
.history/
27+
.lib/
28+
dist/*
29+
target/
30+
lib_managed/
31+
src_managed/
32+
project/boot/
33+
project/plugins/project/
34+

build.sbt

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Your sbt build file. Guides on how to write one can be found at
2+
// http://www.scala-sbt.org/0.13/docs/index.html
3+
4+
scalaVersion := "2.10.4"
5+
6+
sparkVersion := "1.4.0"
7+
8+
spName := "RedisLabs/spark-redis"
9+
10+
description := "A library for reading and writing data from and to Redis with Apache Spark, for Spark SQL and DataFrames."
11+
12+
// Don't forget to set the version
13+
version := "0.1.0"
14+
15+
homepage := Some(url("https://github.com/RedisLabs/spark-redis"))
16+
17+
// All Spark Packages need a license
18+
licenses := Seq("BSD 3-Clause" -> url("http://opensource.org/licenses/BSD-3-Clause"))
19+
20+
organization := "com.redislabs"
21+
22+
organizationName := "Redis Labs, Inc."
23+
24+
organizationHomepage := Some(url("https://redislabs.com"))
25+
26+
// Add Spark components this package depends on, e.g, "mllib", ....
27+
// sparkComponents ++= Seq("sql", "mllib")
28+
29+
// uncomment and change the value below to change the directory where your zip artifact will be created
30+
// spDistDirectory := target.value
31+
32+
// add any Spark Package dependencies using spDependencies.
33+
// e.g. spDependencies += "databricks/spark-avro:0.1"
34+
35+
credentials += Credentials(Path.userHome / ".ivy2" / ".sbtcredentials") // A file containing credentials

build/sbt

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#!/usr/bin/env bash
2+
3+
# When creating new tests for Spark SQL Hive, the HADOOP_CLASSPATH must contain the hive jars so
4+
# that we can run Hive to generate the golden answer. This is not required for normal development
5+
# or testing.
6+
for i in $HIVE_HOME/lib/*
7+
do HADOOP_CLASSPATH=$HADOOP_CLASSPATH:$i
8+
done
9+
export HADOOP_CLASSPATH
10+
11+
realpath () {
12+
(
13+
TARGET_FILE=$1
14+
15+
cd $(dirname $TARGET_FILE)
16+
TARGET_FILE=$(basename $TARGET_FILE)
17+
18+
COUNT=0
19+
while [ -L "$TARGET_FILE" -a $COUNT -lt 100 ]
20+
do
21+
TARGET_FILE=$(readlink $TARGET_FILE)
22+
cd $(dirname $TARGET_FILE)
23+
TARGET_FILE=$(basename $TARGET_FILE)
24+
COUNT=$(($COUNT + 1))
25+
done
26+
27+
echo $(pwd -P)/$TARGET_FILE
28+
)
29+
}
30+
31+
. $(dirname $(realpath $0))/sbt-launch-lib.bash
32+
33+
34+
declare -r noshare_opts="-Dsbt.global.base=project/.sbtboot -Dsbt.boot.directory=project/.boot -Dsbt.ivy.home=project/.ivy"
35+
declare -r sbt_opts_file=".sbtopts"
36+
declare -r etc_sbt_opts_file="/etc/sbt/sbtopts"
37+
38+
usage() {
39+
cat <<EOM
40+
Usage: $script_name [options]
41+
-h | -help print this message
42+
-v | -verbose this runner is chattier
43+
-d | -debug set sbt log level to debug
44+
-no-colors disable ANSI color codes
45+
-sbt-create start sbt even if current directory contains no sbt project
46+
-sbt-dir <path> path to global settings/plugins directory (default: ~/.sbt)
47+
-sbt-boot <path> path to shared boot directory (default: ~/.sbt/boot in 0.11 series)
48+
-ivy <path> path to local Ivy repository (default: ~/.ivy2)
49+
-mem <integer> set memory options (default: $sbt_mem, which is $(get_mem_opts $sbt_mem))
50+
-no-share use all local caches; no sharing
51+
-no-global uses global caches, but does not use global ~/.sbt directory.
52+
-jvm-debug <port> Turn on JVM debugging, open at the given port.
53+
-batch Disable interactive mode
54+
# sbt version (default: from project/build.properties if present, else latest release)
55+
-sbt-version <version> use the specified version of sbt
56+
-sbt-jar <path> use the specified jar as the sbt launcher
57+
-sbt-rc use an RC version of sbt
58+
-sbt-snapshot use a snapshot version of sbt
59+
# java version (default: java from PATH, currently $(java -version 2>&1 | grep version))
60+
-java-home <path> alternate JAVA_HOME
61+
# jvm options and output control
62+
JAVA_OPTS environment variable, if unset uses "$java_opts"
63+
SBT_OPTS environment variable, if unset uses "$default_sbt_opts"
64+
.sbtopts if this file exists in the current directory, it is
65+
prepended to the runner args
66+
/etc/sbt/sbtopts if this file exists, it is prepended to the runner args
67+
-Dkey=val pass -Dkey=val directly to the java runtime
68+
-J-X pass option -X directly to the java runtime
69+
(-J is stripped)
70+
-S-X add -X to sbt's scalacOptions (-J is stripped)
71+
-PmavenProfiles Enable a maven profile for the build.
72+
In the case of duplicated or conflicting options, the order above
73+
shows precedence: JAVA_OPTS lowest, command line options highest.
74+
EOM
75+
}
76+
77+
process_my_args () {
78+
while [[ $# -gt 0 ]]; do
79+
case "$1" in
80+
-no-colors) addJava "-Dsbt.log.noformat=true" && shift ;;
81+
-no-share) addJava "$noshare_opts" && shift ;;
82+
-no-global) addJava "-Dsbt.global.base=$(pwd)/project/.sbtboot" && shift ;;
83+
-sbt-boot) require_arg path "$1" "$2" && addJava "-Dsbt.boot.directory=$2" && shift 2 ;;
84+
-sbt-dir) require_arg path "$1" "$2" && addJava "-Dsbt.global.base=$2" && shift 2 ;;
85+
-debug-inc) addJava "-Dxsbt.inc.debug=true" && shift ;;
86+
-batch) exec </dev/null && shift ;;
87+
88+
-sbt-create) sbt_create=true && shift ;;
89+
90+
*) addResidual "$1" && shift ;;
91+
esac
92+
done
93+
94+
# Now, ensure sbt version is used.
95+
[[ "${sbt_version}XXX" != "XXX" ]] && addJava "-Dsbt.version=$sbt_version"
96+
}
97+
98+
loadConfigFile() {
99+
cat "$1" | sed '/^\#/d'
100+
}
101+
102+
# if sbtopts files exist, prepend their contents to $@ so it can be processed by this runner
103+
[[ -f "$etc_sbt_opts_file" ]] && set -- $(loadConfigFile "$etc_sbt_opts_file") "$@"
104+
[[ -f "$sbt_opts_file" ]] && set -- $(loadConfigFile "$sbt_opts_file") "$@"
105+
106+
run "$@"

build/sbt-launch-0.13.6.jar

1.16 MB
Binary file not shown.

build/sbt-launch-lib.bash

+195
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
#!/usr/bin/env bash
2+
#
3+
4+
# A library to simplify using the SBT launcher from other packages.
5+
# Note: This should be used by tools like giter8/conscript etc.
6+
7+
# TODO - Should we merge the main SBT script with this library?
8+
9+
if test -z "$HOME"; then
10+
declare -r script_dir="$(dirname $script_path)"
11+
else
12+
declare -r script_dir="$HOME/.sbt"
13+
fi
14+
15+
declare -a residual_args
16+
declare -a java_args
17+
declare -a scalac_args
18+
declare -a sbt_commands
19+
declare -a maven_profiles
20+
21+
if test -x "$JAVA_HOME/bin/java"; then
22+
echo -e "Using $JAVA_HOME as default JAVA_HOME."
23+
echo "Note, this will be overridden by -java-home if it is set."
24+
declare java_cmd="$JAVA_HOME/bin/java"
25+
else
26+
declare java_cmd=java
27+
fi
28+
29+
echoerr () {
30+
echo 1>&2 "$@"
31+
}
32+
vlog () {
33+
[[ $verbose || $debug ]] && echoerr "$@"
34+
}
35+
dlog () {
36+
[[ $debug ]] && echoerr "$@"
37+
}
38+
39+
acquire_sbt_jar () {
40+
SBT_VERSION=`awk -F "=" '/sbt\\.version/ {print $2}' ./project/build.properties`
41+
URL1=https://dl.bintray.com/typesafe/ivy-releases/org.scala-sbt/sbt-launch/${SBT_VERSION}/sbt-launch.jar
42+
JAR=build/sbt-launch-${SBT_VERSION}.jar
43+
44+
sbt_jar=$JAR
45+
46+
if [[ ! -f "$sbt_jar" ]]; then
47+
# Download sbt launch jar if it hasn't been downloaded yet
48+
if [ ! -f ${JAR} ]; then
49+
# Download
50+
printf "Attempting to fetch sbt\n"
51+
JAR_DL=${JAR}.part
52+
if hash curl 2>/dev/null; then
53+
curl --fail --location --silent ${URL1} > "${JAR_DL}" &&\
54+
mv "${JAR_DL}" "${JAR}"
55+
elif hash wget 2>/dev/null; then
56+
wget --quiet ${URL1} -O "${JAR_DL}" &&\
57+
mv "${JAR_DL}" "${JAR}"
58+
else
59+
printf "You do not have curl or wget installed, please install sbt manually from http://www.scala-sbt.org/\n"
60+
exit -1
61+
fi
62+
fi
63+
if [ ! -f ${JAR} ]; then
64+
# We failed to download
65+
printf "Our attempt to download sbt locally to ${JAR} failed. Please install sbt manually from http://www.scala-sbt.org/\n"
66+
exit -1
67+
fi
68+
printf "Launching sbt from ${JAR}\n"
69+
fi
70+
}
71+
72+
execRunner () {
73+
# print the arguments one to a line, quoting any containing spaces
74+
[[ $verbose || $debug ]] && echo "# Executing command line:" && {
75+
for arg; do
76+
if printf "%s\n" "$arg" | grep -q ' '; then
77+
printf "\"%s\"\n" "$arg"
78+
else
79+
printf "%s\n" "$arg"
80+
fi
81+
done
82+
echo ""
83+
}
84+
85+
exec "$@"
86+
}
87+
88+
addJava () {
89+
dlog "[addJava] arg = '$1'"
90+
java_args=( "${java_args[@]}" "$1" )
91+
}
92+
93+
enableProfile () {
94+
dlog "[enableProfile] arg = '$1'"
95+
maven_profiles=( "${maven_profiles[@]}" "$1" )
96+
export SBT_MAVEN_PROFILES="${maven_profiles[@]}"
97+
}
98+
99+
addSbt () {
100+
dlog "[addSbt] arg = '$1'"
101+
sbt_commands=( "${sbt_commands[@]}" "$1" )
102+
}
103+
addResidual () {
104+
dlog "[residual] arg = '$1'"
105+
residual_args=( "${residual_args[@]}" "$1" )
106+
}
107+
addDebugger () {
108+
addJava "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=$1"
109+
}
110+
111+
# a ham-fisted attempt to move some memory settings in concert
112+
# so they need not be dicked around with individually.
113+
get_mem_opts () {
114+
local mem=${1:-2048}
115+
local perm=$(( $mem / 4 ))
116+
(( $perm > 256 )) || perm=256
117+
(( $perm < 4096 )) || perm=4096
118+
local codecache=$(( $perm / 2 ))
119+
120+
echo "-Xms${mem}m -Xmx${mem}m -XX:MaxPermSize=${perm}m -XX:ReservedCodeCacheSize=${codecache}m"
121+
}
122+
123+
require_arg () {
124+
local type="$1"
125+
local opt="$2"
126+
local arg="$3"
127+
if [[ -z "$arg" ]] || [[ "${arg:0:1}" == "-" ]]; then
128+
die "$opt requires <$type> argument"
129+
fi
130+
}
131+
132+
is_function_defined() {
133+
declare -f "$1" > /dev/null
134+
}
135+
136+
process_args () {
137+
while [[ $# -gt 0 ]]; do
138+
case "$1" in
139+
-h|-help) usage; exit 1 ;;
140+
-v|-verbose) verbose=1 && shift ;;
141+
-d|-debug) debug=1 && shift ;;
142+
143+
-ivy) require_arg path "$1" "$2" && addJava "-Dsbt.ivy.home=$2" && shift 2 ;;
144+
-mem) require_arg integer "$1" "$2" && sbt_mem="$2" && shift 2 ;;
145+
-jvm-debug) require_arg port "$1" "$2" && addDebugger $2 && shift 2 ;;
146+
-batch) exec </dev/null && shift ;;
147+
148+
-sbt-jar) require_arg path "$1" "$2" && sbt_jar="$2" && shift 2 ;;
149+
-sbt-version) require_arg version "$1" "$2" && sbt_version="$2" && shift 2 ;;
150+
-java-home) require_arg path "$1" "$2" && java_cmd="$2/bin/java" && export JAVA_HOME=$2 && shift 2 ;;
151+
152+
-D*) addJava "$1" && shift ;;
153+
-J*) addJava "${1:2}" && shift ;;
154+
-P*) enableProfile "$1" && shift ;;
155+
*) addResidual "$1" && shift ;;
156+
esac
157+
done
158+
159+
is_function_defined process_my_args && {
160+
myargs=("${residual_args[@]}")
161+
residual_args=()
162+
process_my_args "${myargs[@]}"
163+
}
164+
}
165+
166+
run() {
167+
# no jar? download it.
168+
[[ -f "$sbt_jar" ]] || acquire_sbt_jar "$sbt_version" || {
169+
# still no jar? uh-oh.
170+
echo "Download failed. Obtain the sbt-launch.jar manually and place it at $sbt_jar"
171+
exit 1
172+
}
173+
174+
# process the combined args, then reset "$@" to the residuals
175+
process_args "$@"
176+
set -- "${residual_args[@]}"
177+
argumentCount=$#
178+
179+
# run sbt
180+
execRunner "$java_cmd" \
181+
${SBT_OPTS:-$default_sbt_opts} \
182+
$(get_mem_opts $sbt_mem) \
183+
${java_opts} \
184+
${java_args[@]} \
185+
-jar "$sbt_jar" \
186+
"${sbt_commands[@]}" \
187+
"${residual_args[@]}"
188+
}
189+
190+
runAlternateBoot() {
191+
local bootpropsfile="$1"
192+
shift
193+
addJava "-Dsbt.boot.properties=$bootpropsfile"
194+
run $@
195+
}

project/build.properties

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// This file should only contain the version of sbt to use.
2+
sbt.version=0.13.6

project/plugins.sbt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// You may use this file to add plugin dependencies for sbt.
2+
addSbtPlugin("org.spark-packages" % "sbt-spark-package" % "0.2.3")
3+
4+
resolvers += "bintray-spark-packages" at "https://dl.bintray.com/spark-packages/maven/"

0 commit comments

Comments
 (0)