├── .gitignore ├── .scalafmt.conf ├── .travis.yml ├── README.md ├── RELEASE_NOTES.md ├── build.sbt ├── project ├── build.properties └── plugins.sbt ├── sbt ├── scalafmt └── version.sbt /.gitignore: -------------------------------------------------------------------------------- 1 | # use glob syntax. 2 | syntax: glob 3 | *.ser 4 | *.class 5 | *~ 6 | *.bak 7 | #*.off 8 | *.old 9 | 10 | # eclipse conf file 11 | .settings 12 | .classpath 13 | .project 14 | .manager 15 | .scala_dependencies 16 | 17 | # idea 18 | .idea 19 | *.iml 20 | 21 | # building 22 | target 23 | build 24 | null 25 | tmp* 26 | dist 27 | test-output 28 | build.log 29 | 30 | # other scm 31 | .svn 32 | .CVS 33 | .hg* 34 | 35 | # switch to regexp syntax. 36 | # syntax: regexp 37 | # ^\.pc/ 38 | 39 | #SHITTY output not in target directory 40 | build.log 41 | 42 | #working dir 43 | target/* 44 | 45 | #intelliJ project 46 | *.iml 47 | *.ipr 48 | *.iws 49 | -------------------------------------------------------------------------------- /.scalafmt.conf: -------------------------------------------------------------------------------- 1 | maxColumn = 180 2 | style = defaultWithAlign 3 | optIn.breaksInsideChains = true 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | 3 | cache: 4 | directories: 5 | - $HOME/.ivy2/cache 6 | - $HOME/.sbt 7 | - $HOME/.coursier 8 | 9 | before_cache: 10 | # Cleanup the cached directories to avoid unnecessary cache updates 11 | - find $HOME/.ivy2/cache -name "ivydata-*.properties" -print -delete 12 | - find $HOME/.sbt -name "*.lock" -print -delete 13 | 14 | language: scala 15 | 16 | matrix: 17 | include: 18 | # Code forfmat test 19 | - env: PROJECT=code-format 20 | jdk: oraclejdk8 21 | script: ./scalafmt --test 22 | # Scala 2.12 + code coverage test 23 | - env: SCALA_VERSION=2.12.4 24 | jdk: oraclejdk8 25 | script: 26 | - ./sbt ++$SCALA_VERSION "; coverage; test; coverageReport" 27 | - ./sbt coverageAggregate && bash <(curl -s https://codecov.io/bash) 28 | - env: SCALA_VERSION=2.13.0-M2 29 | jdk: oraclejdk8 30 | script: ./sbt ++$SCALA_VERSION test 31 | - env: SCALA_VERSION=2.11.11 32 | jdk: oraclejdk8 33 | script: ./sbt ++$SCALA_VERSION test 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MessagePack for Scala 2 | [![Build Status](https://travis-ci.org/msgpack/msgpack-scala.svg?branch=master)](https://travis-ci.org/msgpack/msgpack-scala) 3 | 4 | - Message Pack specification: https://github.com/msgpack/msgpack/blob/master/spec.md 5 | 6 | ## Quick Start 7 | 8 | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.msgpack/msgpack-scala_2.12/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.msgpack/msgpack-scala_2.12/) 9 | 10 | ``` 11 | libraryDependencies += "org.msgpack" %% "msgpack-scala" % "(version)" 12 | ``` 13 | 14 | General usage is the same with msgpack-java. See this [example code (Java)](https://github.com/msgpack/msgpack-java/blob/develop/msgpack-core/src/test/java/org/msgpack/core/example/MessagePackExample.java). 15 | 16 | ## For MessagePack Developers 17 | 18 | ### Basic sbt commands 19 | Enter the sbt console: 20 | ``` 21 | $ ./sbt 22 | ``` 23 | 24 | Here is a list of sbt commands for daily development: 25 | ``` 26 | > ~compile # Compile source codes 27 | > ~test:compile # Compile both source and test codes 28 | > ~test # Run tests upon source code change 29 | > ~test-only *MessagePackTest # Run tests in the specified class 30 | > ~test-only *MessagePackTest -- -n prim # Run the test tagged as "prim" 31 | > project msgpack-scala # Focus on a specific project 32 | > package # Create a jar file in the target folder of each project 33 | > scalafmt # Reformat source codes 34 | > ; coverage; test; coverageReport; coverageAggregate; # Code coverage 35 | ``` 36 | 37 | ### Publishing 38 | 39 | ``` 40 | > publishLocal # Install to local .ivy2 repository 41 | > publish # Publishing a snapshot version to the Sonatype repository 42 | 43 | > release # Run the release procedure (set a new version, run tests, upload artifacts, then deploy to Sonatype) 44 | ``` 45 | 46 | For publishing to Maven central, msgpack-scala uses [sbt-sonatype](https://github.com/xerial/sbt-sonatype) plugin. Set Sonatype account information (user name and password) in the global sbt settings. To protect your password, never include this file in your project. 47 | 48 | ___$HOME/.sbt/(sbt-version)/sonatype.sbt___ 49 | 50 | ``` 51 | credentials += Credentials("Sonatype Nexus Repository Manager", 52 | "oss.sonatype.org", 53 | "(Sonatype user name)", 54 | "(Sonatype password)") 55 | ``` 56 | -------------------------------------------------------------------------------- /RELEASE_NOTES.md: -------------------------------------------------------------------------------- 1 | Release Notes 2 | === 3 | 4 | ## 0.8.13 5 | - A complete new release based on [msgpack-java 0.8.3](https://github.com/msgpack/msgpack-java) 6 | - Suppor Scala 2.11, 2.12, 2.13.0-M2 7 | - We will add Scala specific features in this repository (e.g., case class to msgpack conversion, etc.) 8 | - Use sbt-1.0.4 for building projects 9 | 10 | ## 0.6.11 11 | - An older version, which will no longer be maintained. The source code can be found in [0.6.x branch](https://github.com/msgpack/msgpack-scala/tree/0.6.x). 12 | -------------------------------------------------------------------------------- /build.sbt: -------------------------------------------------------------------------------- 1 | import ReleaseTransformations._ 2 | 3 | val SCALA_2_11 = "2.11.11" 4 | val SCALA_2_12 = "2.12.4" 5 | val SCALA_2_13 = "2.13.0-M2" 6 | 7 | val buildSettings = Seq[Setting[_]]( 8 | organization := "org.msgpack", 9 | organizationName := "MessagePack", 10 | organizationHomepage := Some(new URL("http://msgpack.org/")), 11 | description := "MessagePack for Scala", 12 | scalaVersion := SCALA_2_12, 13 | crossScalaVersions := Seq(SCALA_2_13, SCALA_2_12, SCALA_2_11), 14 | logBuffered in Test := false, 15 | licenses += ("Apache-2.0", url("https://www.apache.org/licenses/LICENSE-2.0.html")), 16 | homepage := Some(url("https://github.com/msgpack/msgpack-scala")), 17 | scmInfo := Some( 18 | ScmInfo( 19 | browseUrl = url("https://github.com/msgpack/msgpack-scala"), 20 | connection = "scm:git@github.com:msgpack/msgpack-scala.git" 21 | ) 22 | ), 23 | developers := List( 24 | Developer(id = "xerial", name = "Taro L. Saito", email = "leo@xerial.org", url = url("http://xerial.org/leo")), 25 | Developer(id = "takezoux2", name = "Yositeru Takeshita", email = "takezoux2@gmail.com", url = url("https://github.com/takezoux2")) 26 | ), 27 | // Use sonatype resolvers 28 | resolvers ++= Seq( 29 | Resolver.sonatypeRepo("releases"), 30 | Resolver.sonatypeRepo("snapshots") 31 | ), 32 | // JVM options for building 33 | scalacOptions ++= Seq("-encoding", "UTF-8", "-deprecation", "-unchecked", "-feature"), 34 | // Release settings 35 | publishTo := Some( 36 | if (isSnapshot.value) { 37 | Opts.resolver.sonatypeSnapshots 38 | } else { 39 | Opts.resolver.sonatypeStaging 40 | } 41 | ), 42 | releaseCrossBuild := true, 43 | releaseTagName := { (version in ThisBuild).value }, 44 | releaseProcess := Seq[ReleaseStep]( 45 | checkSnapshotDependencies, 46 | inquireVersions, 47 | runClean, 48 | runTest, 49 | setReleaseVersion, 50 | commitReleaseVersion, 51 | tagRelease, 52 | releaseStepCommand("publishSigned"), 53 | setNextVersion, 54 | commitNextVersion, 55 | releaseStepCommand("sonatypeReleaseAll"), 56 | pushChanges 57 | ) 58 | ) 59 | 60 | // Project settings 61 | lazy val root = Project(id = "msgpack-scala-root", base = file(".")) 62 | .settings( 63 | buildSettings, 64 | // Do not publish the root project 65 | publishArtifact := false, 66 | publish := {}, 67 | publishLocal := {} 68 | ).aggregate(msgpackScala) 69 | 70 | lazy val msgpackScala = Project(id = "msgpack-scala", base = file("msgpack-scala")) 71 | .settings( 72 | buildSettings, 73 | description := "MesasgePack for Scala", 74 | libraryDependencies ++= Seq( 75 | "org.msgpack" % "msgpack-core" % "0.8.13", 76 | "org.scalatest" %% "scalatest" % "3.0.4" % "test", 77 | "org.scalacheck" %% "scalacheck" % "1.13.5" % "test" 78 | ) 79 | ) 80 | -------------------------------------------------------------------------------- /project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version=1.0.4 2 | -------------------------------------------------------------------------------- /project/plugins.sbt: -------------------------------------------------------------------------------- 1 | addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.6") 2 | addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "2.0") 3 | addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.0") 4 | addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.0-RC12") 5 | addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.5.1") 6 | addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "1.3.0") 7 | addSbtPlugin("org.scala-native" % "sbt-crossproject" % "0.2.2") 8 | 9 | scalacOptions ++= Seq("-deprecation", "-feature") 10 | -------------------------------------------------------------------------------- /sbt: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # A more capable sbt runner, coincidentally also called sbt. 4 | # Author: Paul Phillips 5 | 6 | set -o pipefail 7 | 8 | declare -r sbt_release_version="0.13.16" 9 | declare -r sbt_unreleased_version="0.13.16" 10 | 11 | declare -r latest_213="2.13.0-M2" 12 | declare -r latest_212="2.12.4" 13 | declare -r latest_211="2.11.11" 14 | declare -r latest_210="2.10.6" 15 | declare -r latest_29="2.9.3" 16 | declare -r latest_28="2.8.2" 17 | 18 | declare -r buildProps="project/build.properties" 19 | 20 | declare -r sbt_launch_ivy_release_repo="http://repo.typesafe.com/typesafe/ivy-releases" 21 | declare -r sbt_launch_ivy_snapshot_repo="https://repo.scala-sbt.org/scalasbt/ivy-snapshots" 22 | declare -r sbt_launch_mvn_release_repo="http://repo.scala-sbt.org/scalasbt/maven-releases" 23 | declare -r sbt_launch_mvn_snapshot_repo="http://repo.scala-sbt.org/scalasbt/maven-snapshots" 24 | 25 | declare -r default_jvm_opts_common="-Xms512m -Xmx1536m -Xss2m" 26 | declare -r noshare_opts="-Dsbt.global.base=project/.sbtboot -Dsbt.boot.directory=project/.boot -Dsbt.ivy.home=project/.ivy" 27 | 28 | declare sbt_jar sbt_dir sbt_create sbt_version sbt_script sbt_new 29 | declare sbt_explicit_version 30 | declare verbose noshare batch trace_level 31 | declare debugUs 32 | 33 | declare java_cmd="java" 34 | declare sbt_launch_dir="$HOME/.sbt/launchers" 35 | declare sbt_launch_repo 36 | 37 | # pull -J and -D options to give to java. 38 | declare -a java_args scalac_args sbt_commands residual_args 39 | 40 | # args to jvm/sbt via files or environment variables 41 | declare -a extra_jvm_opts extra_sbt_opts 42 | 43 | echoerr () { echo >&2 "$@"; } 44 | vlog () { [[ -n "$verbose" ]] && echoerr "$@"; } 45 | die () { echo "Aborting: $@" ; exit 1; } 46 | 47 | setTrapExit () { 48 | # save stty and trap exit, to ensure echo is re-enabled if we are interrupted. 49 | export SBT_STTY="$(stty -g 2>/dev/null)" 50 | 51 | # restore stty settings (echo in particular) 52 | onSbtRunnerExit() { 53 | [ -t 0 ] || return 54 | vlog "" 55 | vlog "restoring stty: $SBT_STTY" 56 | stty "$SBT_STTY" 57 | } 58 | 59 | vlog "saving stty: $SBT_STTY" 60 | trap onSbtRunnerExit EXIT 61 | } 62 | 63 | # this seems to cover the bases on OSX, and someone will 64 | # have to tell me about the others. 65 | get_script_path () { 66 | local path="$1" 67 | [[ -L "$path" ]] || { echo "$path" ; return; } 68 | 69 | local target="$(readlink "$path")" 70 | if [[ "${target:0:1}" == "/" ]]; then 71 | echo "$target" 72 | else 73 | echo "${path%/*}/$target" 74 | fi 75 | } 76 | 77 | declare -r script_path="$(get_script_path "$BASH_SOURCE")" 78 | declare -r script_name="${script_path##*/}" 79 | 80 | init_default_option_file () { 81 | local overriding_var="${!1}" 82 | local default_file="$2" 83 | if [[ ! -r "$default_file" && "$overriding_var" =~ ^@(.*)$ ]]; then 84 | local envvar_file="${BASH_REMATCH[1]}" 85 | if [[ -r "$envvar_file" ]]; then 86 | default_file="$envvar_file" 87 | fi 88 | fi 89 | echo "$default_file" 90 | } 91 | 92 | declare sbt_opts_file="$(init_default_option_file SBT_OPTS .sbtopts)" 93 | declare jvm_opts_file="$(init_default_option_file JVM_OPTS .jvmopts)" 94 | 95 | build_props_sbt () { 96 | [[ -r "$buildProps" ]] && \ 97 | grep '^sbt\.version' "$buildProps" | tr '=\r' ' ' | awk '{ print $2; }' 98 | } 99 | 100 | update_build_props_sbt () { 101 | local ver="$1" 102 | local old="$(build_props_sbt)" 103 | 104 | [[ -r "$buildProps" ]] && [[ "$ver" != "$old" ]] && { 105 | perl -pi -e "s/^sbt\.version\b.*\$/sbt.version=${ver}/" "$buildProps" 106 | grep -q '^sbt.version[ =]' "$buildProps" || printf "\nsbt.version=%s\n" "$ver" >> "$buildProps" 107 | 108 | vlog "!!!" 109 | vlog "!!! Updated file $buildProps setting sbt.version to: $ver" 110 | vlog "!!! Previous value was: $old" 111 | vlog "!!!" 112 | } 113 | } 114 | 115 | set_sbt_version () { 116 | sbt_version="${sbt_explicit_version:-$(build_props_sbt)}" 117 | [[ -n "$sbt_version" ]] || sbt_version=$sbt_release_version 118 | export sbt_version 119 | } 120 | 121 | url_base () { 122 | local version="$1" 123 | 124 | case "$version" in 125 | 0.7.*) echo "http://simple-build-tool.googlecode.com" ;; 126 | 0.10.* ) echo "$sbt_launch_ivy_release_repo" ;; 127 | 0.11.[12]) echo "$sbt_launch_ivy_release_repo" ;; 128 | 0.*-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9][0-9][0-9]) # ie "*-yyyymmdd-hhMMss" 129 | echo "$sbt_launch_ivy_snapshot_repo" ;; 130 | 0.*) echo "$sbt_launch_ivy_release_repo" ;; 131 | *-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9][0-9][0-9]) # ie "*-yyyymmdd-hhMMss" 132 | echo "$sbt_launch_mvn_snapshot_repo" ;; 133 | *) echo "$sbt_launch_mvn_release_repo" ;; 134 | esac 135 | } 136 | 137 | make_url () { 138 | local version="$1" 139 | 140 | local base="${sbt_launch_repo:-$(url_base "$version")}" 141 | 142 | case "$version" in 143 | 0.7.*) echo "$base/files/sbt-launch-0.7.7.jar" ;; 144 | 0.10.* ) echo "$base/org.scala-tools.sbt/sbt-launch/$version/sbt-launch.jar" ;; 145 | 0.11.[12]) echo "$base/org.scala-tools.sbt/sbt-launch/$version/sbt-launch.jar" ;; 146 | 0.*) echo "$base/org.scala-sbt/sbt-launch/$version/sbt-launch.jar" ;; 147 | *) echo "$base/org/scala-sbt/sbt-launch/$version/sbt-launch.jar" ;; 148 | esac 149 | } 150 | 151 | addJava () { vlog "[addJava] arg = '$1'" ; java_args+=("$1"); } 152 | addSbt () { vlog "[addSbt] arg = '$1'" ; sbt_commands+=("$1"); } 153 | addScalac () { vlog "[addScalac] arg = '$1'" ; scalac_args+=("$1"); } 154 | addResidual () { vlog "[residual] arg = '$1'" ; residual_args+=("$1"); } 155 | 156 | addResolver () { addSbt "set resolvers += $1"; } 157 | addDebugger () { addJava "-Xdebug" ; addJava "-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=$1"; } 158 | setThisBuild () { 159 | vlog "[addBuild] args = '$@'" 160 | local key="$1" && shift 161 | addSbt "set $key in ThisBuild := $@" 162 | } 163 | setScalaVersion () { 164 | [[ "$1" == *"-SNAPSHOT" ]] && addResolver 'Resolver.sonatypeRepo("snapshots")' 165 | addSbt "++ $1" 166 | } 167 | setJavaHome () { 168 | java_cmd="$1/bin/java" 169 | setThisBuild javaHome "_root_.scala.Some(file(\"$1\"))" 170 | export JAVA_HOME="$1" 171 | export JDK_HOME="$1" 172 | export PATH="$JAVA_HOME/bin:$PATH" 173 | } 174 | 175 | getJavaVersion() { "$1" -version 2>&1 | grep -E -e '(java|openjdk) version' | awk '{ print $3 }' | tr -d \"; } 176 | 177 | checkJava() { 178 | # Warn if there is a Java version mismatch between PATH and JAVA_HOME/JDK_HOME 179 | 180 | [[ -n "$JAVA_HOME" && -e "$JAVA_HOME/bin/java" ]] && java="$JAVA_HOME/bin/java" 181 | [[ -n "$JDK_HOME" && -e "$JDK_HOME/lib/tools.jar" ]] && java="$JDK_HOME/bin/java" 182 | 183 | if [[ -n "$java" ]]; then 184 | pathJavaVersion=$(getJavaVersion java) 185 | homeJavaVersion=$(getJavaVersion "$java") 186 | if [[ "$pathJavaVersion" != "$homeJavaVersion" ]]; then 187 | echoerr "Warning: Java version mismatch between PATH and JAVA_HOME/JDK_HOME, sbt will use the one in PATH" 188 | echoerr " Either: fix your PATH, remove JAVA_HOME/JDK_HOME or use -java-home" 189 | echoerr " java version from PATH: $pathJavaVersion" 190 | echoerr " java version from JAVA_HOME/JDK_HOME: $homeJavaVersion" 191 | fi 192 | fi 193 | } 194 | 195 | java_version () { 196 | local version=$(getJavaVersion "$java_cmd") 197 | vlog "Detected Java version: $version" 198 | echo "${version:2:1}" 199 | } 200 | 201 | # MaxPermSize critical on pre-8 JVMs but incurs noisy warning on 8+ 202 | default_jvm_opts () { 203 | local v="$(java_version)" 204 | if [[ $v -ge 8 ]]; then 205 | echo "$default_jvm_opts_common" 206 | else 207 | echo "-XX:MaxPermSize=384m $default_jvm_opts_common" 208 | fi 209 | } 210 | 211 | build_props_scala () { 212 | if [[ -r "$buildProps" ]]; then 213 | versionLine="$(grep '^build.scala.versions' "$buildProps")" 214 | versionString="${versionLine##build.scala.versions=}" 215 | echo "${versionString%% .*}" 216 | fi 217 | } 218 | 219 | execRunner () { 220 | # print the arguments one to a line, quoting any containing spaces 221 | vlog "# Executing command line:" && { 222 | for arg; do 223 | if [[ -n "$arg" ]]; then 224 | if printf "%s\n" "$arg" | grep -q ' '; then 225 | printf >&2 "\"%s\"\n" "$arg" 226 | else 227 | printf >&2 "%s\n" "$arg" 228 | fi 229 | fi 230 | done 231 | vlog "" 232 | } 233 | 234 | setTrapExit 235 | 236 | if [[ -n "$batch" ]]; then 237 | "$@" < /dev/null 238 | else 239 | "$@" 240 | fi 241 | } 242 | 243 | jar_url () { make_url "$1"; } 244 | 245 | is_cygwin () [[ "$(uname -a)" == "CYGWIN"* ]] 246 | 247 | jar_file () { 248 | is_cygwin \ 249 | && echo "$(cygpath -w $sbt_launch_dir/"$1"/sbt-launch.jar)" \ 250 | || echo "$sbt_launch_dir/$1/sbt-launch.jar" 251 | } 252 | 253 | download_url () { 254 | local url="$1" 255 | local jar="$2" 256 | 257 | echoerr "Downloading sbt launcher for $sbt_version:" 258 | echoerr " From $url" 259 | echoerr " To $jar" 260 | 261 | mkdir -p "${jar%/*}" && { 262 | if which curl >/dev/null; then 263 | curl --fail --silent --location "$url" --output "$jar" 264 | elif which wget >/dev/null; then 265 | wget -q -O "$jar" "$url" 266 | fi 267 | } && [[ -r "$jar" ]] 268 | } 269 | 270 | acquire_sbt_jar () { 271 | { 272 | sbt_jar="$(jar_file "$sbt_version")" 273 | [[ -r "$sbt_jar" ]] 274 | } || { 275 | sbt_jar="$HOME/.ivy2/local/org.scala-sbt/sbt-launch/$sbt_version/jars/sbt-launch.jar" 276 | [[ -r "$sbt_jar" ]] 277 | } || { 278 | sbt_jar="$(jar_file "$sbt_version")" 279 | download_url "$(make_url "$sbt_version")" "$sbt_jar" 280 | } 281 | } 282 | 283 | usage () { 284 | set_sbt_version 285 | cat < display stack traces with a max of frames (default: -1, traces suppressed) 304 | -debug-inc enable debugging log for the incremental compiler 305 | -no-colors disable ANSI color codes 306 | -sbt-create start sbt even if current directory contains no sbt project 307 | -sbt-dir path to global settings/plugins directory (default: ~/.sbt/) 308 | -sbt-boot path to shared boot directory (default: ~/.sbt/boot in 0.11+) 309 | -ivy path to local Ivy repository (default: ~/.ivy2) 310 | -no-share use all local caches; no sharing 311 | -offline put sbt in offline mode 312 | -jvm-debug Turn on JVM debugging, open at the given port. 313 | -batch Disable interactive mode 314 | -prompt Set the sbt prompt; in expr, 's' is the State and 'e' is Extracted 315 | -script Run the specified file as a scala script 316 | 317 | # sbt version (default: sbt.version from $buildProps if present, otherwise $sbt_release_version) 318 | -sbt-force-latest force the use of the latest release of sbt: $sbt_release_version 319 | -sbt-version use the specified version of sbt (default: $sbt_release_version) 320 | -sbt-dev use the latest pre-release version of sbt: $sbt_unreleased_version 321 | -sbt-jar use the specified jar as the sbt launcher 322 | -sbt-launch-dir directory to hold sbt launchers (default: $sbt_launch_dir) 323 | -sbt-launch-repo repo url for downloading sbt launcher jar (default: $(url_base "$sbt_version")) 324 | 325 | # scala version (default: as chosen by sbt) 326 | -28 use $latest_28 327 | -29 use $latest_29 328 | -210 use $latest_210 329 | -211 use $latest_211 330 | -212 use $latest_212 331 | -213 use $latest_213 332 | -scala-home use the scala build at the specified directory 333 | -scala-version use the specified version of scala 334 | -binary-version use the specified scala version when searching for dependencies 335 | 336 | # java version (default: java from PATH, currently $(java -version 2>&1 | grep version)) 337 | -java-home alternate JAVA_HOME 338 | 339 | # passing options to the jvm - note it does NOT use JAVA_OPTS due to pollution 340 | # The default set is used if JVM_OPTS is unset and no -jvm-opts file is found 341 | $(default_jvm_opts) 342 | JVM_OPTS environment variable holding either the jvm args directly, or 343 | the reference to a file containing jvm args if given path is prepended by '@' (e.g. '@/etc/jvmopts') 344 | Note: "@"-file is overridden by local '.jvmopts' or '-jvm-opts' argument. 345 | -jvm-opts file containing jvm args (if not given, .jvmopts in project root is used if present) 346 | -Dkey=val pass -Dkey=val directly to the jvm 347 | -J-X pass option -X directly to the jvm (-J is stripped) 348 | 349 | # passing options to sbt, OR to this runner 350 | SBT_OPTS environment variable holding either the sbt args directly, or 351 | the reference to a file containing sbt args if given path is prepended by '@' (e.g. '@/etc/sbtopts') 352 | Note: "@"-file is overridden by local '.sbtopts' or '-sbt-opts' argument. 353 | -sbt-opts file containing sbt args (if not given, .sbtopts in project root is used if present) 354 | -S-X add -X to sbt's scalacOptions (-S is stripped) 355 | EOM 356 | } 357 | 358 | process_args () { 359 | require_arg () { 360 | local type="$1" 361 | local opt="$2" 362 | local arg="$3" 363 | 364 | if [[ -z "$arg" ]] || [[ "${arg:0:1}" == "-" ]]; then 365 | die "$opt requires <$type> argument" 366 | fi 367 | } 368 | while [[ $# -gt 0 ]]; do 369 | case "$1" in 370 | -h|-help) usage; exit 0 ;; 371 | -v) verbose=true && shift ;; 372 | -d) addSbt "--debug" && shift ;; 373 | -w) addSbt "--warn" && shift ;; 374 | -q) addSbt "--error" && shift ;; 375 | -x) debugUs=true && shift ;; 376 | -trace) require_arg integer "$1" "$2" && trace_level="$2" && shift 2 ;; 377 | -ivy) require_arg path "$1" "$2" && addJava "-Dsbt.ivy.home=$2" && shift 2 ;; 378 | -no-colors) addJava "-Dsbt.log.noformat=true" && shift ;; 379 | -no-share) noshare=true && shift ;; 380 | -sbt-boot) require_arg path "$1" "$2" && addJava "-Dsbt.boot.directory=$2" && shift 2 ;; 381 | -sbt-dir) require_arg path "$1" "$2" && sbt_dir="$2" && shift 2 ;; 382 | -debug-inc) addJava "-Dxsbt.inc.debug=true" && shift ;; 383 | -offline) addSbt "set offline in Global := true" && shift ;; 384 | -jvm-debug) require_arg port "$1" "$2" && addDebugger "$2" && shift 2 ;; 385 | -batch) batch=true && shift ;; 386 | -prompt) require_arg "expr" "$1" "$2" && setThisBuild shellPrompt "(s => { val e = Project.extract(s) ; $2 })" && shift 2 ;; 387 | -script) require_arg file "$1" "$2" && sbt_script="$2" && addJava "-Dsbt.main.class=sbt.ScriptMain" && shift 2 ;; 388 | 389 | -sbt-create) sbt_create=true && shift ;; 390 | -sbt-jar) require_arg path "$1" "$2" && sbt_jar="$2" && shift 2 ;; 391 | -sbt-version) require_arg version "$1" "$2" && sbt_explicit_version="$2" && shift 2 ;; 392 | -sbt-force-latest) sbt_explicit_version="$sbt_release_version" && shift ;; 393 | -sbt-dev) sbt_explicit_version="$sbt_unreleased_version" && shift ;; 394 | -sbt-launch-dir) require_arg path "$1" "$2" && sbt_launch_dir="$2" && shift 2 ;; 395 | -sbt-launch-repo) require_arg path "$1" "$2" && sbt_launch_repo="$2" && shift 2 ;; 396 | -scala-version) require_arg version "$1" "$2" && setScalaVersion "$2" && shift 2 ;; 397 | -binary-version) require_arg version "$1" "$2" && setThisBuild scalaBinaryVersion "\"$2\"" && shift 2 ;; 398 | -scala-home) require_arg path "$1" "$2" && setThisBuild scalaHome "_root_.scala.Some(file(\"$2\"))" && shift 2 ;; 399 | -java-home) require_arg path "$1" "$2" && setJavaHome "$2" && shift 2 ;; 400 | -sbt-opts) require_arg path "$1" "$2" && sbt_opts_file="$2" && shift 2 ;; 401 | -jvm-opts) require_arg path "$1" "$2" && jvm_opts_file="$2" && shift 2 ;; 402 | 403 | -D*) addJava "$1" && shift ;; 404 | -J*) addJava "${1:2}" && shift ;; 405 | -S*) addScalac "${1:2}" && shift ;; 406 | -28) setScalaVersion "$latest_28" && shift ;; 407 | -29) setScalaVersion "$latest_29" && shift ;; 408 | -210) setScalaVersion "$latest_210" && shift ;; 409 | -211) setScalaVersion "$latest_211" && shift ;; 410 | -212) setScalaVersion "$latest_212" && shift ;; 411 | -213) setScalaVersion "$latest_213" && shift ;; 412 | new) sbt_new=true && : ${sbt_explicit_version:=$sbt_release_version} && addResidual "$1" && shift ;; 413 | *) addResidual "$1" && shift ;; 414 | esac 415 | done 416 | } 417 | 418 | # process the direct command line arguments 419 | process_args "$@" 420 | 421 | # skip #-styled comments and blank lines 422 | readConfigFile() { 423 | local end=false 424 | until $end; do 425 | read || end=true 426 | [[ $REPLY =~ ^# ]] || [[ -z $REPLY ]] || echo "$REPLY" 427 | done < "$1" 428 | } 429 | 430 | # if there are file/environment sbt_opts, process again so we 431 | # can supply args to this runner 432 | if [[ -r "$sbt_opts_file" ]]; then 433 | vlog "Using sbt options defined in file $sbt_opts_file" 434 | while read opt; do extra_sbt_opts+=("$opt"); done < <(readConfigFile "$sbt_opts_file") 435 | elif [[ -n "$SBT_OPTS" && ! ("$SBT_OPTS" =~ ^@.*) ]]; then 436 | vlog "Using sbt options defined in variable \$SBT_OPTS" 437 | extra_sbt_opts=( $SBT_OPTS ) 438 | else 439 | vlog "No extra sbt options have been defined" 440 | fi 441 | 442 | [[ -n "${extra_sbt_opts[*]}" ]] && process_args "${extra_sbt_opts[@]}" 443 | 444 | # reset "$@" to the residual args 445 | set -- "${residual_args[@]}" 446 | argumentCount=$# 447 | 448 | # set sbt version 449 | set_sbt_version 450 | 451 | checkJava 452 | 453 | # only exists in 0.12+ 454 | setTraceLevel() { 455 | case "$sbt_version" in 456 | "0.7."* | "0.10."* | "0.11."* ) echoerr "Cannot set trace level in sbt version $sbt_version" ;; 457 | *) setThisBuild traceLevel $trace_level ;; 458 | esac 459 | } 460 | 461 | # set scalacOptions if we were given any -S opts 462 | [[ ${#scalac_args[@]} -eq 0 ]] || addSbt "set scalacOptions in ThisBuild += \"${scalac_args[@]}\"" 463 | 464 | # Update build.properties on disk to set explicit version - sbt gives us no choice 465 | [[ -n "$sbt_explicit_version" && -z "$sbt_new" ]] && update_build_props_sbt "$sbt_explicit_version" 466 | vlog "Detected sbt version $sbt_version" 467 | 468 | if [[ -n "$sbt_script" ]]; then 469 | residual_args=( $sbt_script ${residual_args[@]} ) 470 | else 471 | # no args - alert them there's stuff in here 472 | (( argumentCount > 0 )) || { 473 | vlog "Starting $script_name: invoke with -help for other options" 474 | residual_args=( shell ) 475 | } 476 | fi 477 | 478 | # verify this is an sbt dir, -create was given or user attempts to run a scala script 479 | [[ -r ./build.sbt || -d ./project || -n "$sbt_create" || -n "$sbt_script" || -n "$sbt_new" ]] || { 480 | cat <