Added more options. Can choose to use an sbt snapshot with -snapshot.

Now by default it refuses to run sbt in a directory with no sign it is
an sbt directory; give -create to force it.
This commit is contained in:
Paul Phillips 2011-08-25 08:23:24 -07:00
parent c26f6a863c
commit ce1f6fb7c7
2 changed files with 74 additions and 29 deletions

2
.gitignore vendored
View File

@ -5,4 +5,4 @@ target
lib_managed
src_managed
/ext
.lib/sbt-launch.jar
.lib

101
sbt
View File

@ -5,9 +5,40 @@
set -e
jar_url () {
local where=$1 # releases or snapshots
local ver=$2
echo "http://typesafe.artifactoryonline.com/typesafe/ivy-$where/org.scala-tools.sbt/sbt-launch/$ver/sbt-launch.jar"
}
jar_file () {
echo "$script_dir/.lib/$1/sbt-launch.jar"
}
# todo - make this dynamic
launch_base=http://typesafe.artifactoryonline.com/typesafe/ivy-releases/org.scala-tools.sbt/sbt-launch
launch_url=$launch_base/0.10.1/sbt-launch.jar
sbt_release_version=0.10.1
sbt_release_url=$(jar_url releases $sbt_release_version)
sbt_release_jar=$(jar_file $sbt_release_version)
sbt_snapshot_version=0.11.0-20110825-052147
sbt_snapshot_url=$(jar_url snapshots $sbt_snapshot_version)
sbt_snapshot_jar=$(jar_file $sbt_snapshot_version)
# Falses made true via command line options
useSnapshot=0
createProject=0
set_sbt_jar () {
if (( $useSnapshot )); then
sbt_version=$sbt_snapshot_version
sbt_url=$sbt_snapshot_url
else
sbt_version=$sbt_release_version
sbt_url=$sbt_release_url
fi
sbt_jar="$script_dir/.lib/$sbt_version/sbt-launch.jar"
}
# this seems to cover the bases on OSX, and someone will
# have to tell me about the others.
@ -26,11 +57,10 @@ get_script_path () {
declare -r script_path=$(get_script_path "$BASH_SOURCE")
declare -r script_dir="$(dirname $script_path)"
declare -r script_name="$(basename $script_path)"
declare -r default_sbt_jar="$script_dir/.lib/sbt-launch.jar"
declare -r default_java_opts="-Dfile.encoding=UTF8"
declare -r default_sbt_opts="-XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=512m -Xmx2g -Xss2m"
declare -r latest_28="2.8.1"
declare -r latest_29="2.9.0-1"
declare -r latest_28="2.8.2.RC1"
declare -r latest_29="2.9.1.RC4"
declare -r latest_210="2.10.0-SNAPSHOT"
usage () {
@ -38,43 +68,38 @@ usage () {
Usage: $script_name [options]
-help prints this message
-nocolors disable ANSI color codes
-debug set sbt log level to debug
-v | -verbose this runner is chattier
-sbtjar <path> location of sbt launcher (default: $default_sbt_jar)
-debug set sbt log level to debug
-create start sbt even in a directory with no project
-sbtjar <path> location of sbt launcher (default: $(jar_file '<sbt version>'))
-sbtdir <path> location of global settings and plugins (default: ~/.sbt)
-ivy <path> local Ivy repository (default: ~/.ivy2)
-shared <path> shared sbt boot directory (default: none, no sharing)
# setting scala version
# setting scala and sbt versions
-28 set scala version to $latest_28
-29 set scala version to $latest_29
-210 set scala version to $latest_210
-local <path> set scala version to local installation at path
-snapshot use a snapshot of sbt (otherwise, latest released version)
# passing options to jvm
JAVA_OPTS environment variable # default: "$default_java_opts"
SBT_OPTS environment variable # default: "$default_sbt_opts"
# jvm options and output control
JAVA_OPTS environment variable, if unset uses "$default_java_opts"
SBT_OPTS environment variable, if unset uses "$default_sbt_opts"
-Dkey=val pass -Dkey=val directly to the jvm
-J-X pass option -X directly to the jvm (-J is stripped)
-nocolors disable ANSI color codes
The defaults given for JAVA_OPTS and SBT_OPTS are only used if the
corresponding variable is unset. In the case of a duplicated option,
SBT_OPTS takes precedence over JAVA_OPTS, and command line options
take precedence over both.
In the case of a duplicated option, SBT_OPTS takes precedence over
JAVA_OPTS, and command line options take precedence over both.
EOM
}
# no args - alert them there's stuff in here
[[ $# -gt 0 ]] || {
echo "Starting $script_name: invoke with -help for other options"
}
# pull -J and -D options to give to java.
declare -a args
declare -a java_args
declare -a sbt_commands
declare sbt_jar="$default_sbt_jar"
declare sbt_jar=
declare verbose=0
addJava () {
@ -91,7 +116,9 @@ while [ $# -gt 0 ]; do
-ivy) addJava "-Dsbt.ivy.home=$2"; shift 2 ;;
-shared) addJava "-Dsbt.boot.directory=$2"; shift 2 ;;
-sbtdir) addJava "-Dsbt.global.base=$2"; shift 2 ;;
-snapshot) useSnapshot=1; shift ;;
-nocolors) addJava "-Dsbt.log.noformat=true"; shift ;;
-create) createProject=1; shift ;;
-D*) addJava "$1"; shift ;;
-J*) addJava "${1:2}"; shift ;;
@ -111,18 +138,36 @@ done
# reset "$@" to the residual args
set -- "${args[@]}"
# verify this is an sbt dir or -create was given
[[ -f "build.sbt" ]] || [[ -d "project" ]] || (( $createProject )) || {
cat <<EOM
$(pwd) doesn't appear to be an sbt project.
If you want to start sbt anyway, run:
$0 -create
EOM
exit 1
}
# no args - alert them there's stuff in here
[[ $# -gt 0 ]] || {
echo "Starting $script_name: invoke with -help for other options"
}
# pick up completion if present; todo
[[ -f .sbt_completion.sh ]] && source .sbt_completion.sh
# no jar? download it.
[[ -f "$sbt_jar" ]] || set_sbt_jar
[[ -f "$sbt_jar" ]] || {
echo "Downloading sbt launcher, this should only take a moment..."
echo "Downloading sbt launcher $sbt_version, this should only take a moment..."
if which curl >/dev/null; then
curl "$launch_url" --output "$sbt_jar"
elif which wget >/dev/null; then
wget "$launch_url" > "$sbt_jar"
fi
mkdir -p $(dirname "$sbt_jar") &&
if which curl >/dev/null; then
curl --silent "$sbt_url" --output "$sbt_jar"
elif which wget >/dev/null; then
wget --quiet "$sbt_url" > "$sbt_jar"
fi
}
# still no jar? uh-oh.