Skip to content

Commit

Permalink
Phoned in some tests. Updated the docs again.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulp committed Aug 25, 2011
1 parent 221a049 commit 01c75c8
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 53 deletions.
80 changes: 50 additions & 30 deletions README.md
@@ -1,14 +1,19 @@
sbt: the rebel cut
==================

An alternative script for running [sbt 0.10+](https://github.com/harrah/xsbt).
An alternative script for running [sbt](https://github.com/harrah/xsbt).
It works with sbt 0.7 projects as well as 0.10+. If you're in a directory
with an sbt project, you can just run it and it will use the right version
of sbt, including downloading sbt if necessary.

There's also a template project sbt coming together, but it's unfinished.
However the runner is quite useful already.

Here's a sample first run, which creates a new project using a snapshot
version of sbt, and runs the sbt "about" command.
Here's a sample use of the runner: it creates a new project using a
snapshot version of sbt as well as a snapshot version of scala, then
runs the sbt "about" command.

% sbt -debug -snapshot -create about
% sbt -d -sbt-snapshot -210 -sbt-create about
# Executing command line:
java
-Xss2m
Expand All @@ -22,29 +27,36 @@ version of sbt, and runs the sbt "about" command.
-jar
/r/sbt-extras/.lib/0.11.0-20110825-052147/sbt-launch.jar
"set logLevel in Global := Level.Debug"
"++ 2.10.0-SNAPSHOT"
"iflast shell"
about

Getting net.java.dev.jna jna 3.2.3 ...
:: retrieving :: org.scala-tools.sbt#boot-app
confs: [default]
1 artifacts copied, 0 already retrieved (838kB/15ms)
1 artifacts copied, 0 already retrieved (838kB/12ms)
Getting Scala 2.9.1.RC4 (for sbt)...
:: retrieving :: org.scala-tools.sbt#boot-scala
confs: [default]
4 artifacts copied, 0 already retrieved (19939kB/97ms)
4 artifacts copied, 0 already retrieved (19939kB/32ms)
Getting org.scala-tools.sbt sbt_2.9.1.RC4 0.11.0-20110825-052147 ...
:: retrieving :: org.scala-tools.sbt#boot-app
confs: [default]
38 artifacts copied, 0 already retrieved (6948kB/71ms)
[info] Set current project to default-06d8dd (in build file:/private/tmp/sbt-project/)
38 artifacts copied, 0 already retrieved (6948kB/45ms)
[info] Set current project to default-30ae78 (in build file:/private/var/folders/1w/zm_1vksn3y7gn127bkwt841w0000gn/T/abc.h9FdreF1/)
[info] Reapplying settings...
[info] Set current project to default-06d8dd (in build file:/private/tmp/sbt-project/)
[info] Set current project to default-30ae78 (in build file:/private/var/folders/1w/zm_1vksn3y7gn127bkwt841w0000gn/T/abc.h9FdreF1/)
Setting version to 2.10.0-SNAPSHOT
[info] Set current project to default-30ae78 (in build file:/private/var/folders/1w/zm_1vksn3y7gn127bkwt841w0000gn/T/abc.h9FdreF1/)
Getting Scala 2.10.0-SNAPSHOT ...
:: retrieving :: org.scala-tools.sbt#boot-scala
confs: [default]
4 artifacts copied, 0 already retrieved (20650kB/58ms)
[info] This is sbt 0.11.0-20110825-052147
[info] The current project is {file:/private/tmp/sbt-project/}default-06d8dd
[info] The current project is built against Scala 2.9.1.RC4
[info] The current project is {file:/private/var/folders/1w/zm_1vksn3y7gn127bkwt841w0000gn/T/abc.h9FdreF1/}default-30ae78
[info] The current project is built against Scala 2.10.0-SNAPSHOT
[info] sbt, sbt plugins, and build definitions are using Scala 2.9.1.RC4
[info] All logging output for this session is available at /var/folders/iO/iOpjflOpHzG8Mr1BL67D6k+++TI/-Tmp-/sbt75419762724938334.log
[info] All logging output for this session is available at /var/folders/1w/zm_1vksn3y7gn127bkwt841w0000gn/T/sbt8625229869994477318.log


Current -help output:
Expand All @@ -53,29 +65,37 @@ Current -help output:

Usage: sbt [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: ./.lib/<sbt version>/sbt-launch.jar)
-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)
-h | -help print this message
-v | -verbose this runner is chattier
-d | -debug set sbt log level to debug
-no-colors disable ANSI color codes
-sbt-create start sbt even if current directory contains no sbt project
-sbt-dir <path> path to global settings/plugins directory (default: ~/.sbt)
-sbt-boot <path> path to shared boot directory (default: none, no sharing)
-ivy <path> path to 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 2.8.1
-29 use 2.9.0-1
-29rc use 2.9.1.RC4
-210 use 2.10.0-SNAPSHOT
-scala-home <path> use the scala build at the specified directory
-scala-version <version> use the specified version of scala

# setting scala and sbt versions
-28 set scala version to 2.8.2.RC1
-29 set scala version to 2.9.1.RC4
-210 set scala version to 2.10.0-SNAPSHOT
-local <path> set scala version to local installation at path
-snapshot use a snapshot of sbt (otherwise, latest released version)
# java version (default: java from PATH, currently java version "1.6.0_26")
-java-home <path> alternate JAVA_HOME

# jvm options and output control
JAVA_OPTS environment variable, if unset uses "-Dfile.encoding=UTF8"
SBT_OPTS environment variable, if unset uses "-XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=512m -Xmx2g -Xss2m"
.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 exists in the sbt root, it is prepended to the runner args
-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.
8 changes: 4 additions & 4 deletions project/Build.scala
Expand Up @@ -84,9 +84,9 @@ class TemplateBuild(implicit sbtCreateConfig: SbtCreateConfig) extends Build {

lazy val testSettings = Seq(
libraryDependencies ++= Seq(
"org.specs2" %% "specs2" % "1.5",
"org.specs2" %% "specs2-scalaz-core" % "6.0.RC2" % "test"
)
"org.scala-tools.testing" % "specs_2.9.0-1" % "1.6.8" % "test"
),
libraryDependencies <+= (scalaVersion)(v => "org.scala-lang" % "scala-compiler" % v)
)

lazy val buildSettings = Seq(
Expand All @@ -105,7 +105,7 @@ class TemplateBuild(implicit sbtCreateConfig: SbtCreateConfig) extends Build {
aggregate = Nil,
dependencies = Nil,
delegates = Nil,
settings = Defaults.defaultSettings ++ buildSettings ++ Seq(
settings = Defaults.defaultSettings ++ buildSettings ++ testSettings ++ Seq(
commands += helpNames
)
)
Expand Down
38 changes: 19 additions & 19 deletions sbt
Expand Up @@ -17,7 +17,7 @@ declare sbt_version=$(
if [[ -f project/build.properties ]]; then
versionLine=$(grep ^sbt.version project/build.properties)
versionString=${versionLine##sbt.version=}
if [[ $versionString =~ ^[0-9]\.[0-9]\.[0-9]$ ]]; then
echo "$versionString"
fi
Expand All @@ -32,7 +32,7 @@ declare verbose=0
jar_url () {
local where=$1 # releases or snapshots
local ver=$2

if [[ $ver = 0.7* ]]; then
echo "http://simple-build-tool.googlecode.com/files/sbt-launch-$ver.jar"
else
Expand Down Expand Up @@ -63,7 +63,7 @@ set_sbt_jar () {
get_script_path () {
local path="$1"
[[ -L "$path" ]] || { echo "$path" ; return; }

local target=$(readlink "$path")
if [[ "${target:0:1}" == "/" ]]; then
echo "$target"
Expand All @@ -89,33 +89,33 @@ Usage: $script_name [options]
-h | -help print this message
-v | -verbose this runner is chattier
-debug set sbt log level to debug
-d | -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-create start sbt even if current directory contains no sbt project
-sbt-dir <path> path to global settings/plugins directory (default: ~/.sbt)
-sbt-boot <path> path to shared boot directory (default: none, no sharing)
-ivy <path> path to 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
# java version (default: java from PATH, currently $(java -version |& grep version))
-java-home <path> alternate 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 if this file is in the sbt root directory, its contents are arguments
.sbtopts if this file exists in the sbt root, it is prepended to the runner args
-Dkey=val pass -Dkey=val directly to the java runtime
-J-X pass option -X directly to the java runtime (-J is stripped)
Expand All @@ -141,7 +141,8 @@ process_args ()
while [ $# -gt 0 ]; do
case "$1" in
-h|-help) usage; exit 1 ;;
-v|-verbose) verbose=1 ; shift ;;
-v|-verbose) verbose=1; shift ;;
-d|-debug) debug=1; addSbt "set logLevel in Global := Level.Debug"; shift ;;

-ivy) addJava "-Dsbt.ivy.home=$2"; shift 2 ;;
-no-colors) addJava "-Dsbt.log.noformat=true"; shift ;;
Expand All @@ -152,7 +153,7 @@ process_args ()
-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-version) addSbt "++ $2"; shift 2 ;;
-scala-home) addSbt "set scalaHome in ThisBuild := Some(file(\"$2\"))"; shift 2 ;;
-java-home) java_cmd="$2/bin/java"; shift 2 ;;

Expand All @@ -162,13 +163,12 @@ process_args ()
-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 ;;

*) args=("${args[@]}" "$1") ; shift ;;
esac
done
}

# if .sbtopts exists, prepend its contents so it can be processed by this runner
[[ -f "$sbt_opts" ]] && set -- $(cat $sbt_opts) "${@}"

Expand Down Expand Up @@ -200,7 +200,7 @@ EOM
echo " From $sbt_url"
echo " To $sbt_jar"

mkdir -p $(dirname "$sbt_jar") &&
mkdir -p $(dirname "$sbt_jar") &&
if which curl >/dev/null; then
curl --silent "$sbt_url" --output "$sbt_jar"
elif which wget >/dev/null; then
Expand Down
51 changes: 51 additions & 0 deletions src/test/scala/RunnerTest.scala
@@ -0,0 +1,51 @@
package org.improving

import scala.tools.nsc.io._
import org.specs._

object SbtRunnerTest extends Specification {
val scripts = {
import Predef._
List[String](
"""|sbt -sbt-create -sbt-snapshot -210
|sbt update
|sbt about
""",
"""|sbt -sbt-create -sbt-snapshot -29
|sbt update
|sbt version
""",
"""|sbt -sbt-create -sbt-version 0.7.7 -28
|sbt help
|sbt -h
"""
) map (_.trim.stripMargin.lines.toList)
}

val singles = """
sbt -v -d -no-colors update package
sbt -verbose -210 -debug -ivy /tmp update
""".trim.lines

import scala.sys.process._

def sbtProjectLines(lines: List[String]) = {
println("Running: " + lines.mkString(", "))

val dir = Directory.makeTemp("sbt-runner-test").jfile
val result = lines map (x => Process(x, dir)) reduceLeft (_ #&& _) ! ;

result == 0
}
def sbtProjectLine(line: String) =
sbtProjectLines(List("sbt -sbt-create version", line))

"Sbt Runner" should {
"deal with lots of different command lines" in {
singles foreach (x => sbtProjectLine(x) mustEqual true)
}
"handle various command sequences" in {
scripts foreach (xs => sbtProjectLines(xs) mustEqual true)
}
}
}

0 comments on commit 01c75c8

Please sign in to comment.