Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updated version of SBT Rebel cut

  • Loading branch information...
commit 5f66711cdae68a5768ad9c395121c91cf6974472 1 parent fbf90c6
@bwmcadams bwmcadams authored
Showing with 122 additions and 109 deletions.
  1. +122 −109 sbt
View
231 sbt
@@ -3,6 +3,62 @@
# A more capable sbt runner, coincidentally also called sbt.
# Author: Paul Phillips <paulp@typesafe.com>
+# todo - make this dynamic
+declare -r sbt_release_version=0.11.3
+declare -r sbt_snapshot_version=0.13.0-SNAPSHOT
+
+unset sbt_jar sbt_dir sbt_create sbt_snapshot sbt_launch_dir
+unset scala_version java_home sbt_explicit_version
+unset verbose debug quiet
+
+build_props_sbt () {
+ if [[ -f project/build.properties ]]; then
+ versionLine=$(grep ^sbt.version project/build.properties)
+ versionString=${versionLine##sbt.version=}
+ echo "$versionString"
+ fi
+}
+
+update_build_props_sbt () {
+ local ver="$1"
+ local old=$(build_props_sbt)
+
+ if [[ $ver == $old ]]; then
+ return
+ elif [[ -f project/build.properties ]]; then
+ perl -pi -e "s/^sbt\.version=.*\$/sbt.version=${ver}/" project/build.properties
+ grep -q '^sbt.version=' project/build.properties || echo "sbt.version=${ver}" >> project/build.properties
+
+ echo !!!
+ echo !!! Updated file project/build.properties setting sbt.version to: $ver
+ echo !!! Previous value was: $old
+ echo !!!
+ fi
+}
+
+sbt_version () {
+ if [[ -n $sbt_explicit_version ]]; then
+ echo $sbt_explicit_version
+ else
+ local v=$(build_props_sbt)
+ if [[ -n $v ]]; then
+ echo $v
+ else
+ echo $sbt_release_version
+ fi
+ fi
+}
+
+echoerr () {
+ echo 1>&2 "$@"
+}
+vlog () {
+ [[ $verbose || $debug ]] && echoerr "$@"
+}
+dlog () {
+ [[ $debug ]] && echoerr "$@"
+}
+
# this seems to cover the bases on OSX, and someone will
# have to tell me about the others.
get_script_path () {
@@ -13,7 +69,7 @@ get_script_path () {
if [[ "${target:0:1}" == "/" ]]; then
echo "$target"
else
- echo "$path/$target"
+ echo "$(dirname $path)/$target"
fi
}
@@ -34,12 +90,13 @@ die() {
exit 1
}
-# todo - make this dynamic
-declare -r sbt_release_version=0.11.2
-unset sbt_rc_version
-# declare -r sbt_rc_version=
-declare -r sbt_snapshot_version=0.11.3-SNAPSHOT
-declare -r sbt_snapshot_baseurl="http://typesafe.artifactoryonline.com/typesafe/ivy-snapshots/org.scala-tools.sbt/sbt-launch/"
+make_url () {
+ groupid="$1"
+ category="$2"
+ version="$3"
+
+ echo "http://typesafe.artifactoryonline.com/typesafe/ivy-$category/$groupid/sbt-launch/$version/sbt-launch.jar"
+}
declare -r default_jvm_opts="-Dfile.encoding=UTF8"
declare -r default_sbt_opts="-XX:+CMSClassUnloadingEnabled"
@@ -55,27 +112,17 @@ declare -r script_path=$(get_script_path "$BASH_SOURCE")
declare -r script_dir="$(dirname $script_path)"
declare -r script_name="$(basename $script_path)"
+# some non-read-onlies set with defaults
declare java_cmd=java
+declare sbt_launch_dir="$script_dir/.lib"
declare sbt_mem=$default_sbt_mem
-unset sbt_jar sbt_dir sbt_create sbt_version sbt_snapshot
-unset scala_version
-unset java_home
-unset verbose debug quiet
-
# pull -J and -D options to give to java.
declare -a residual_args
declare -a java_args
declare -a scalac_args
declare -a sbt_commands
-build_props_sbt () {
- if [[ -f project/build.properties ]]; then
- versionLine=$(grep ^sbt.version project/build.properties)
- versionString=${versionLine##sbt.version=}
- echo "$versionString"
- fi
-}
build_props_scala () {
if [[ -f project/build.properties ]]; then
versionLine=$(grep ^build.scala.versions project/build.properties)
@@ -84,13 +131,6 @@ build_props_scala () {
fi
}
-isSnapshot () {
- [[ "$sbt_version" = *-SNAPSHOT* ]]
-}
-isRC () {
- [[ "$sbt_version" = *-RC* ]]
-}
-
execRunner () {
# print the arguments one to a line, quoting any containing spaces
[[ $verbose || $debug ]] && echo "# Executing command line:" && {
@@ -107,84 +147,67 @@ execRunner () {
exec "$@"
}
-echoerr () {
- echo 1>&2 "$@"
-}
-vlog () {
- [[ $verbose || $debug ]] && echoerr "$@"
-}
-dlog () {
- [[ $debug ]] && echoerr "$@"
-}
-
-sbtjar_07_url () {
- echo "http://simple-build-tool.googlecode.com/files/sbt-launch-${1}.jar"
-}
-sbtjar_release_url () {
- echo "http://typesafe.artifactoryonline.com/typesafe/ivy-releases/org.scala-tools.sbt/sbt-launch/$sbt_version/sbt-launch.jar"
-}
-sbtjar_snapshot_url () {
- local ver="$sbt_version"
- if [[ "$sbt_version" = *-SNAPSHOT ]]; then
- ver=$(sbt_snapshot_actual_version -SNAPSHOT)
- echoerr "sbt snapshot is $ver"
- elif [[ "$sbt_version" = *-SNAPSHOT ]]; then
- ver=$(sbt_snapshot_actual_version -RC)
- echoerr "sbt rc is $ver"
- fi
-
- echo "${sbt_snapshot_baseurl}${ver}/sbt-launch.jar"
-}
-jar_url () {
- case $sbt_version in
- 0.7.4*) sbtjar_07_url 0.7.4 ;;
- 0.7.5*) sbtjar_07_url 0.7.5 ;;
- 0.7.7*) sbtjar_07_url 0.7.7 ;;
- 0.7.*) sbtjar_07_url 0.7.7 ;;
- *-SNAPSHOT*) sbtjar_snapshot_url ;;
- *-RC*) sbtjar_snapshot_url ;;
- *) sbtjar_release_url ;;
+sbt_groupid () {
+ case $(sbt_version) in
+ 0.7.*) echo org.scala-tools.sbt ;;
+ 0.10.*) echo org.scala-tools.sbt ;;
+ 0.11.[12]) echo org.scala-tools.sbt ;;
+ *) echo org.scala-sbt ;;
esac
}
-jar_file () {
- echo "$script_dir/.lib/$1/sbt-launch.jar"
-}
-
sbt_artifactory_list () {
- local type="$1" # -RC or -SNAPSHOT
- local version=${sbt_version%-SNAPSHOT}
+ local version0=$(sbt_version)
+ local version=${version0%-SNAPSHOT}
+ local url="http://typesafe.artifactoryonline.com/typesafe/ivy-snapshots/$(sbt_groupid)/sbt-launch/"
+ dlog "Looking for snapshot list at: $url "
- curl -s --list-only "$sbt_snapshot_baseurl" | \
+ curl -s --list-only "$url" | \
grep -F $version | \
perl -e 'print reverse <>' | \
perl -pe 's#^<a href="([^"/]+).*#$1#;'
}
-# argument is e.g. 0.11.0-SNAPSHOT
+make_release_url () {
+ make_url $(sbt_groupid) releases $(sbt_version)
+}
+
+# argument is e.g. 0.13.0-SNAPSHOT
# finds the actual version (with the build id) at artifactory
-sbt_snapshot_actual_version () {
- for ver in $(sbt_artifactory_list "$1"); do
- local url="$sbt_snapshot_baseurl$ver/sbt-launch.jar"
+make_snapshot_url () {
+ for ver in $(sbt_artifactory_list); do
+ local url=$(make_url $(sbt_groupid) snapshots $ver)
dlog "Testing $url"
curl -s --head "$url" >/dev/null
dlog "curl returned: $?"
- echo "$ver"
+ echo "$url"
return
done
}
+jar_url () {
+ case $(sbt_version) in
+ 0.7.*) echo "http://simple-build-tool.googlecode.com/files/sbt-launch-0.7.7.jar" ;;
+ *-SNAPSHOT) make_snapshot_url ;;
+ *) make_release_url ;;
+ esac
+}
+
+jar_file () {
+ echo "$sbt_launch_dir/$1/sbt-launch.jar"
+}
+
download_url () {
local url="$1"
local jar="$2"
- echo "Downloading sbt launcher $sbt_version:"
+ echo "Downloading sbt launcher $(sbt_version):"
echo " From $url"
echo " To $jar"
mkdir -p $(dirname "$jar") && {
if which curl >/dev/null; then
- curl --silent "$url" --output "$jar"
+ curl --fail --silent "$url" --output "$jar"
elif which wget >/dev/null; then
wget --quiet -O "$jar" "$url"
fi
@@ -192,19 +215,12 @@ download_url () {
}
acquire_sbt_jar () {
- if [[ $sbt_snapshot ]]; then
- sbt_version=$sbt_snapshot_version
- elif [[ ! $sbt_version ]]; then
- sbt_version=$sbt_release_version
- fi
-
sbt_url="$(jar_url)"
- sbt_jar="$(jar_file $sbt_version)"
+ sbt_jar="$(jar_file $(sbt_version))"
[[ -f "$sbt_jar" ]] || download_url "$sbt_url" "$sbt_jar"
}
-
usage () {
cat <<EOM
Usage: $script_name [options]
@@ -218,19 +234,22 @@ Usage: $script_name [options]
-sbt-dir <path> path to global settings/plugins directory (default: ~/.sbt/<version>)
-sbt-boot <path> path to shared boot directory (default: ~/.sbt/boot in 0.11 series)
-ivy <path> path to local Ivy repository (default: ~/.ivy2)
- -mem <integer> set memory options (default: $sbt_mem, which is $(get_mem_opts $sbt_mem))
+ -mem <integer> set memory options (default: $sbt_mem, which is
+ $(get_mem_opts $sbt_mem) )
-no-share use all local caches; no sharing
-offline put sbt in offline mode
-jvm-debug <port> Turn on JVM debugging, open at the given port.
-batch Disable interactive mode
# sbt version (default: from project/build.properties if present, else latest release)
- -sbt-version <version> use the specified version of sbt
+ !!! The only way to accomplish this pre-0.12.0 if there is a build.properties file which
+ !!! contains an sbt.version property is to update the file on disk. That's what this does.
+ -sbt-version <version> use the specified version of sbt
-sbt-jar <path> use the specified jar as the sbt launcher
- -sbt-rc use an RC version of sbt
-sbt-snapshot use a snapshot version of sbt
+ -sbt-launch-dir <path> directory to hold sbt launchers (default: $sbt_launch_dir)
- # scala version (default: latest release)
+ # scala version (default: as chosen by sbt)
-28 use $latest_28
-29 use $latest_29
-210 use $latest_210
@@ -273,10 +292,6 @@ addResidual () {
addResolver () {
addSbt "set resolvers in ThisBuild += $1"
}
-unset addedSnapshotRepo
-addSnapshotRepo () {
- [[ -n "$addedSnapshotRepo" ]] || addResolver "ScalaToolsSnapshots" && addedSnapshotRepo=true
-}
addDebugger () {
addJava "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=$1"
}
@@ -304,7 +319,6 @@ process_args ()
-v|-verbose) verbose=1 && shift ;;
-d|-debug) debug=1 && shift ;;
-q|-quiet) quiet=1 && shift ;;
- # -u|-upgrade) addSbt 'set sbt.version 0.7.7' ; addSbt reload && shift ;;
-ivy) require_arg path "$1" "$2" && addJava "-Dsbt.ivy.home=$2" && shift 2 ;;
-mem) require_arg integer "$1" "$2" && sbt_mem="$2" && shift 2 ;;
@@ -318,11 +332,11 @@ process_args ()
-batch) exec </dev/null && shift ;;
-sbt-create) sbt_create=true && shift ;;
- -sbt-rc) [[ -n "$sbt_rc_version" ]] || die "no sbt RC candidate defined."; sbt_version=$sbt_rc_version && shift ;;
- -sbt-snapshot) addSnapshotRepo ; sbt_version=$sbt_snapshot_version && shift ;;
+ -sbt-snapshot) sbt_explicit_version=$sbt_snapshot_version && shift ;;
-sbt-jar) require_arg path "$1" "$2" && sbt_jar="$2" && shift 2 ;;
- -sbt-version) require_arg version "$1" "$2" && sbt_version="$2" && shift 2 ;;
- -scala-version) require_arg version "$1" "$2" && addSbt "++ $2" && shift 2 ;;
+ -sbt-version) require_arg version "$1" "$2" && sbt_explicit_version="$2" && shift 2 ;;
+-sbt-launch-dir) require_arg path "$1" "$2" && sbt_launch_dir="$2" && shift 2 ;;
+ -scala-version) require_arg version "$1" "$2" && addSbt "set scalaVersion := \"$2\"" && shift 2 ;;
-scala-home) require_arg path "$1" "$2" && addSbt "set scalaHome in ThisBuild := Some(file(\"$2\"))" && shift 2 ;;
-java-home) require_arg path "$1" "$2" && java_cmd="$2/bin/java" && shift 2 ;;
@@ -331,21 +345,21 @@ process_args ()
-S*) addScalac "${1:2}" && shift ;;
-28) addSbt "++ $latest_28" && shift ;;
-29) addSbt "++ $latest_29" && shift ;;
- -210) addSnapshotRepo ; addSbt "++ $latest_210" && shift ;;
+ -210) addSbt "++ $latest_210" && shift ;;
*) addResidual "$1" && shift ;;
esac
done
[[ $debug ]] && {
- case "$sbt_version" in
- 0.7*) addSbt "debug" ;;
+ case $(sbt_version) in
+ 0.7.*) addSbt "debug" ;;
*) addSbt "set logLevel in Global := Level.Debug" ;;
esac
}
[[ $quiet ]] && {
- case "$sbt_version" in
- 0.7*) ;;
+ case $(sbt_version) in
+ 0.7.*) ;;
*) addSbt "set logLevel in Global := Level.Error" ;;
esac
}
@@ -369,12 +383,11 @@ argumentCount=$#
# set scalacOptions if we were given any -S opts
[[ ${#scalac_args[@]} -eq 0 ]] || addSbt "set scalacOptions in ThisBuild += \"${scalac_args[@]}\""
-# figure out the version
-[[ "$sbt_version" ]] || sbt_version=$(build_props_sbt)
-[[ "$sbt_version" = *-SNAPSHOT* || "$sbt_version" = *-RC* ]] && sbt_snapshot=1
-[[ -n "$sbt_version" ]] && echo "Detected sbt version $sbt_version"
+# Update build.properties no disk to set explicit version - sbt gives us no choice
+[[ -n "$sbt_explicit_version" ]] && update_build_props_sbt "$sbt_explicit_version"
+echo "Detected sbt version $(sbt_version)"
-[[ -n "$scala_version" ]] && echo "Detected scala version $scala_version"
+[[ -n "$scala_version" ]] && echo "Overriding scala version to $scala_version"
# no args - alert them there's stuff in here
(( $argumentCount > 0 )) || echo "Starting $script_name: invoke with -help for other options"
@@ -401,7 +414,7 @@ EOM
}
[[ -n "$sbt_dir" ]] || {
- sbt_dir=~/.sbt/$sbt_version
+ sbt_dir=~/.sbt/$(sbt_version)
addJava "-Dsbt.global.base=$sbt_dir"
echo "Using $sbt_dir as sbt dir, -sbt-dir to override."
}
Please sign in to comment.
Something went wrong with that request. Please try again.