Changed a bunch of option names to be consistent with one another.

Added some more.
This commit is contained in:
Paul Phillips 2011-08-25 14:43:12 -07:00
parent 41311fcecd
commit 221a049cc0
1 changed files with 62 additions and 51 deletions

113
sbt
View File

@ -9,10 +9,11 @@ set -e
sbt_release_version=0.10.1
sbt_snapshot_version=0.11.0-20110825-052147
# Falses made true via command line options
useSnapshot=0
createProject=0
sbt_version=$(
# A bunch of falses and empties as defaults.
declare sbt_jar=
declare sbt_create=0
declare sbt_snapshot=0
declare sbt_version=$(
if [[ -f project/build.properties ]]; then
versionLine=$(grep ^sbt.version project/build.properties)
versionString=${versionLine##sbt.version=}
@ -22,7 +23,11 @@ sbt_version=$(
fi
fi
)
echo $sbt_version
declare scala_version=
declare java_cmd=java
declare java_home=
declare verbose=0
jar_url () {
local where=$1 # releases or snapshots
@ -41,7 +46,7 @@ jar_file () {
set_sbt_jar () {
if [[ -n "$sbt_version" ]]; then
sbt_url=$(jar_url releases $sbt_version)
elif (( $useSnapshot )); then
elif (( $sbt_snapshot )); then
sbt_version=$sbt_snapshot_version
sbt_url=$(jar_url snapshots $sbt_version)
else
@ -72,39 +77,47 @@ declare -r script_dir="$(dirname $script_path)"
declare -r script_name="$(basename $script_path)"
declare -r default_java_opts="-Dfile.encoding=UTF8"
declare -r default_sbt_opts="-XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=512m -Xmx2g -Xss2m"
declare -r sbt_opts_filename=".sbtopts"
declare -r latest_28="2.8.2.RC1"
declare -r latest_29="2.9.1.RC4"
declare -r sbt_opts=".sbtopts"
declare -r latest_28="2.8.1"
declare -r latest_29="2.9.0-1"
declare -r latest_29rc="2.9.1.RC4"
declare -r latest_210="2.10.0-SNAPSHOT"
usage () {
cat <<EOM
Usage: $script_name [options]
-help prints this message
-v | -verbose this runner is chattier
-debug set sbt log level to debug
-nocolors disable ANSI color codes
-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 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
-sbt-version use specified version of sbt
-snapshot use a snapshot of sbt (otherwise, latest released version)
-h | -help print this message
-v | -verbose this runner is chattier
-debug set sbt log level to debug
-no-colors disable ANSI color codes
-sbt-create start sbt even if location has no sbt project
-sbt-dir <path> location of global settings and plugins (default: ~/.sbt)
-sbt-boot <path> shared sbt boot directory (default: none, no sharing)
-ivy <path> local Ivy repository (default: ~/.ivy2)
# sbt version (default: from project/build.properties if there, else latest release)
-sbt-version <version> use the specified version of sbt
-sbt-jar <path> use the specified jar as the sbt launcher
-sbt-snapshot use a snapshot version of sbt
# scala version (default: latest release)
-28 use $latest_28
-29 use $latest_29
-29rc use $latest_29rc
-210 use $latest_210
-scala-home <path> use the scala build at the specified directory
-scala-version <version> use the specified version of scala
# java version (default: $(which java))
-java-home <path> use specified path as JAVA_HOME
# 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"
.sbtopts file in sbt root directory, if present contents passed to sbt
-Dkey=val pass -Dkey=val directly to the jvm
-J-X pass option -X directly to the jvm (-J is stripped)
.sbtopts if this file is in the sbt root directory, its contents are arguments
-Dkey=val pass -Dkey=val directly to the java runtime
-J-X pass option -X directly to the java runtime (-J is stripped)
In the case of duplicated or conflicting options, the order above
shows precedence: JAVA_OPTS lowest, command line options highest.
@ -115,8 +128,6 @@ EOM
declare -a args
declare -a java_args
declare -a sbt_commands
declare sbt_jar=
declare verbose=0
addJava () {
java_args=("${java_args[@]}" "$1")
@ -129,48 +140,47 @@ process_args ()
{
while [ $# -gt 0 ]; do
case "$1" in
-help) usage; exit 1 ;;
-h|-help) usage; exit 1 ;;
-v|-verbose) verbose=1 ; shift ;;
-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 ;;
-no-colors) addJava "-Dsbt.log.noformat=true"; shift ;;
-sbt-boot) addJava "-Dsbt.boot.directory=$2"; shift 2 ;;
-sbt-dir) addJava "-Dsbt.global.base=$2"; shift 2 ;;
-sbt-create) sbt_create=1; shift ;;
-sbt-snapshot) sbt_snapshot=1; shift ;;
-sbt-jar) sbt_jar="$2"; shift 2 ;;
-sbt-version) sbt_version="$2"; shift 2 ;;
-scala-version) scala_version="$2"; shift 2 ;;
-scala-home) addSbt "set scalaHome in ThisBuild := Some(file(\"$2\"))"; shift 2 ;;
-java-home) java_cmd="$2/bin/java"; shift 2 ;;
-D*) addJava "$1"; shift ;;
-J*) addJava "${1:2}"; shift ;;
-28) addSbt "++ $latest_28"; shift ;;
-29) addSbt "++ $latest_29"; shift ;;
-29rc) addSbt "++ $latest_29rc"; shift ;;
-210) addSbt "++ $latest_210"; shift ;;
-debug) addSbt "set logLevel in Global := Level.Debug"; debug=1; shift ;;
-local) addSbt "set scalaHome in ThisBuild := Some(file(\"$2\"))"; shift 2 ;;
-v|-verbose) verbose=1 ; shift ;;
-sbtjar) sbt_jar="$2"; shift 2 ;;
*) args=("${args[@]}" "$1") ; shift ;;
esac
done
}
# if .sbtopts exists, prepend its contents
[[ -f "$sbt_opts_filename" ]] && set -- $(cat $sbt_opts_filename) "${@}"
# if .sbtopts exists, prepend its contents so it can be processed by this runner
[[ -f "$sbt_opts" ]] && set -- $(cat $sbt_opts) "${@}"
# no args - alert them there's stuff in here
[[ $# -gt 0 ]] || {
echo "Starting $script_name: invoke with -help for other options"
}
[[ $# -gt 0 ]] || echo "Starting $script_name: invoke with -help for other options"
# process the unified options
# process the combined args, then reset "$@" to the residuals
process_args "$@"
# reset "$@" to the residual args
set -- "${args[@]}"
# verify this is an sbt dir or -create was given
[[ -f "build.sbt" ]] || [[ -d "project" ]] || (( $createProject )) || {
[[ -f build.sbt ]] || [[ -d project ]] || (( $sbt_create )) || {
cat <<EOM
$(pwd) doesn't appear to be an sbt project.
If you want to start sbt anyway, run:
@ -220,6 +230,7 @@ execRunner () {
"$@"
}
# since sbt 0.7 doesn't understand iflast
iflast-shell () {
if [[ $sbt_version = 0.7* ]]; then
echo "shell"
@ -229,7 +240,7 @@ iflast-shell () {
}
# run sbt
execRunner java \
execRunner "$java_cmd" \
${JAVA_OPTS:-$default_java_opts} \
${SBT_OPTS:-$default_sbt_opts} \
${java_args[@]} \