diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..1df4c3a3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,19 @@ +.lib +*~ +*.class +*.log + +# sbt specific +dist/* +target/ +lib_managed/ +src_managed/ +project/boot/ +project/plugins/project/ + +# Scala-IDE specific +.scala_dependencies +.idea* + +src/sbt-test/*/*/bin/.lib + diff --git a/project/Build.scala b/project/Build.scala new file mode 100755 index 00000000..e68b9a02 --- /dev/null +++ b/project/Build.scala @@ -0,0 +1,113 @@ +/* + * Copyright 2012 Taro L. Saito + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package xerial.sbt + +import java.io.File +import sbt._ +import Keys._ +import sbt.ScriptedPlugin._ +import sbtrelease.ReleasePlugin._ + +object SonatypeBuild extends Build { + + val SCALA_VERSION = "2.10.3" + + def releaseResolver(v: String): Resolver = { + val profile = System.getProperty("xerial.profile", "default") + profile match { + case "default" => { + val nexus = "https://oss.sonatype.org/" + if (v.trim.endsWith("SNAPSHOT")) + "snapshots" at nexus + "content/repositories/snapshots" + else + "releases" at nexus + "service/local/staging/deploy/maven2" + } + case p => { + sys.error("unknown xerial.profile:%s".format(p)) + } + } + } + + lazy val buildSettings = Defaults.defaultSettings ++ releaseSettings ++ scriptedSettings ++ Seq[Setting[_]]( + organization := "org.xerial.sbt", + organizationName := "Xerial project", + organizationHomepage := Some(new URL("http://xerial.org/")), + description := "A sbt plugin for automating staging processes in Sonatype", + scalaVersion := SCALA_VERSION, + publishMavenStyle := true, + publishArtifact in Test := false, + publishTo <<= version { (v) => Some(releaseResolver(v)) }, + pomIncludeRepository := { + _ => false + }, + sbtPlugin := true, + parallelExecution := true, + crossPaths := false, + scalacOptions ++= Seq("-encoding", "UTF-8", "-deprecation", "-unchecked", "-target:jvm-1.6"), + scriptedBufferLog := false, + scriptedLaunchOpts ++= { + import scala.collection.JavaConverters._ + management.ManagementFactory.getRuntimeMXBean().getInputArguments().asScala.filter(a => Seq("-Xmx","-Xms").contains(a) || a.startsWith("-XX")).toSeq + }, + pomExtra := { + http://xerial.org/ + + + + Apache 2 + http://www.apache.org/licenses/LICENSE-2.0.txt + + + + scm:git:github.com/xerial/sbt-sonatype.git + scm:git:git@github.com:xerial/sbt-sonatype.git + github.com/xerial/sbt-sonatype.git + + + + leo + Taro L. Saito + http://xerial.org/leo + + + } + ) + + + // Project modules + lazy val sbtSonatype = Project( + id = "sbt-sonatype", + base = file("."), + settings = buildSettings ++ Seq( + libraryDependencies ++= Seq( + //"io.spray" % "spray-client" % "1.2.0", + //"com.typesafe.akka" %% "akka-actor" % "2.2.3", + "org.apache.httpcomponents" % "httpclient" % "4.2.6", + "org.scalatest" % "scalatest_2.10" % "2.0" % "test" + ) + ) + ) + +} + + + + + + + + diff --git a/project/build.properties b/project/build.properties new file mode 100755 index 00000000..37b489cb --- /dev/null +++ b/project/build.properties @@ -0,0 +1 @@ +sbt.version=0.13.1 diff --git a/project/plugins.sbt b/project/plugins.sbt new file mode 100755 index 00000000..0a4e7866 --- /dev/null +++ b/project/plugins.sbt @@ -0,0 +1,8 @@ + +addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.5.1") + +addSbtPlugin("com.github.gseitz" % "sbt-release" % "0.7.1") + +addSbtPlugin("com.mojolly.scalate" % "xsbt-scalate-generator" % "0.4.2") + +libraryDependencies <+= sbtVersion("org.scala-sbt" % "scripted-plugin" % _) diff --git a/sbt b/sbt new file mode 100755 index 00000000..8e23b37f --- /dev/null +++ b/sbt @@ -0,0 +1,437 @@ +#!/usr/bin/env bash +# +# A more capable sbt runner, coincidentally also called sbt. +# Author: Paul Phillips + +# this seems to cover the bases on OSX, and someone will +# have to tell me about the others. +get_script_path () { + local path="$1" + [[ -L "$path" ]] || { echo "$path" ; return; } + + local target=$(readlink "$path") + if [[ "${target:0:1}" == "/" ]]; then + echo "$target" + else + echo "$path/$target" + fi +} + +# a ham-fisted attempt to move some memory settings in concert +# so they need not be dicked around with individually. +get_mem_opts () { + local mem=${1:-1536} + local perm=$(( $mem / 4 )) + (( $perm > 256 )) || perm=256 + (( $perm < 1024 )) || perm=1024 + local codecache=$(( $perm / 2 )) + + echo "-Xms512m -Xmx${mem}m -XX:MaxPermSize=${perm}m" +} + +die() { + echo "Aborting: $@" + exit 1 +} + +# todo - make this dynamic +declare -r sbt_release_version=0.13.0 +unset sbt_rc_version +declare -r sbt_rc_version=0.13.0 +declare -r sbt_snapshot_version=0.13.0-SNAPSHOT +declare -r sbt_snapshot_baseurl="http://typesafe.artifactoryonline.com/typesafe/ivy-snapshots/org.scala-sbt/sbt-launch/" + +declare default_jvm_opts="-Dfile.encoding=UTF8" +declare -r default_sbt_opts="-XX:+CMSClassUnloadingEnabled -XX:ReservedCodeCacheSize=128m" +declare -r default_sbt_mem=1536 +declare -r noshare_opts="-Dsbt.global.base=project/.sbtboot -Dsbt.boot.directory=project/.boot -Dsbt.ivy.home=project/.ivy" +declare -r sbt_opts_file=".sbtopts" +declare -r jvm_opts_file=".jvmopts" +declare -r latest_28="2.8.2" +declare -r latest_29="2.9.2" +declare -r latest_210="2.10.2" + +declare -r script_path=$(get_script_path "$BASH_SOURCE") + + +declare -r script_dir="$(dirname $script_path)" +declare -r script_name="$(basename $script_path)" + +declare java_cmd=java +declare sbt_mem=$default_sbt_mem + +unset sbt_jar sbt_dir sbt_tmpdir 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) + versionString=${versionLine##build.scala.versions=} + echo ${versionString%% .*} + 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:" && { + for arg; do + if printf "%s\n" "$arg" | grep -q ' '; then + printf "\"%s\"\n" "$arg" + else + printf "%s\n" "$arg" + fi + done + echo "" + } + + 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-sbt/sbt-launch/$sbt_version/sbt-launch.jar" +} +sbtjar_snapshot_url () { + local ver="$sbt_version" + echoerr "sbt version: $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_release_url ;; + *) sbtjar_release_url ;; + 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} + + curl -s --list-only "$sbt_snapshot_baseurl" | \ + grep -F $version | \ + perl -e 'print reverse <>' | \ + perl -pe 's#^/dev/null + dlog "curl returned: $?" + echo "$ver" + return + done +} + +download_url () { + local url="$1" + local jar="$2" + + 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" + elif which wget >/dev/null; then + wget --quiet -O "$jar" "$url" + fi + } && [[ -f "$jar" ]] +} + +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)" + + [[ -f "$sbt_jar" ]] || download_url "$sbt_url" "$sbt_jar" +} + + +usage () { + cat < path to global settings/plugins directory (default: ~/.sbt/) + -sbt-boot path to shared boot directory (default: ~/.sbt/boot in 0.11 series) + -ivy path to local Ivy repository (default: ~/.ivy2) + -mem 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 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 use the specified version of sbt + -sbt-jar use the specified jar as the sbt launcher + -sbt-rc use an RC version of sbt + -sbt-snapshot use a snapshot version of sbt + + # scala version (default: latest release) + -28 use $latest_28 + -29 use $latest_29 + -210 use $latest_210 + -scala-home use the scala build at the specified directory + -scala-version use the specified version of scala + + # java version (default: java from PATH, currently $(java -version |& grep version)) + -java-home alternate JAVA_HOME + + # jvm options and output control + JAVA_OPTS environment variable holding jvm args, if unset uses "$default_jvm_opts" + SBT_OPTS environment variable holding jvm args, if unset uses "$default_sbt_opts" + .jvmopts if file is in sbt root, it is prepended to the args given to the jvm + .sbtopts if file is in sbt root, it is prepended to the args given to **sbt** + -Dkey=val pass -Dkey=val directly to the jvm + -J-X pass option -X directly to the jvm (-J is stripped) + -S-X add -X to sbt's scalacOptions (-J is stripped) + +In the case of duplicated or conflicting options, the order above +shows precedence: JAVA_OPTS lowest, command line options highest. +EOM +} + +addJava () { + dlog "[addJava] arg = '$1'" + java_args=( "${java_args[@]}" "$1" ) +} +addSbt () { + dlog "[addSbt] arg = '$1'" + sbt_commands=( "${sbt_commands[@]}" "$1" ) +} +addScalac () { + dlog "[addScalac] arg = '$1'" + scalac_args=( "${scalac_args[@]}" "$1" ) +} +addResidual () { + dlog "[residual] arg = '$1'" + residual_args=( "${residual_args[@]}" "$1" ) +} +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" +} +get_jvm_opts () { + # echo "${JAVA_OPTS:-$default_jvm_opts}" + # echo "${SBT_OPTS:-$default_sbt_opts}" + + [[ -f "$jvm_opts_file" ]] && cat "$jvm_opts_file" +} + +process_args () +{ + require_arg () { + local type="$1" + local opt="$2" + local arg="$3" + + if [[ -z "$arg" ]] || [[ "${arg:0:1}" == "-" ]]; then + die "$opt requires <$type> argument" + fi + } + while [[ $# -gt 0 ]]; do + case "$1" in + -h|-help) usage; exit 1 ;; + -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 ;; + -no-colors) addJava "-Dsbt.log.noformat=true" && shift ;; + -no-share) addJava "$noshare_opts" && shift ;; + -sbt-boot) require_arg path "$1" "$2" && addJava "-Dsbt.boot.directory=$2" && shift 2 ;; + -sbt-dir) require_arg path "$1" "$2" && sbt_dir="$2" && shift 2 ;; + -debug-inc) addJava "-Dxsbt.inc.debug=true" && shift ;; + -offline) addSbt "set offline := true" && shift ;; + -jvm-debug) require_arg port "$1" "$2" && addDebugger $2 && shift 2 ;; + -batch) exec 0 )) || echo "Starting $script_name: invoke with -help for other options" + +# verify this is an sbt dir or -create was given +[[ -f ./build.sbt || -d ./project || -n "$sbt_create" ]] || { + cat < d} + if(credt.isEmpty) { + s.log.error(s"No credential is found for ${credentialHost.value}") + false + } + + val user = credt.get.userName + val passwd = credt.get.passwd + + val client = new DefaultHttpClient() + try { + client.getCredentialsProvider.setCredentials( + new AuthScope(credt.get.host, AuthScope.ANY_PORT), + new UsernamePasswordCredentials(user, passwd) + ) + + val req = new HttpGet(s"${repo}/staging/profile_repositories") + req.addHeader("Content-Type", "application/xml") + val response = client.execute(req) + s.log.info(s"Status line: ${response.getStatusLine}") + val entity = response.getEntity + val len = entity.getContentLength + val b = new ByteArrayOutputStream() + entity.writeTo(b) + val content = b.toString("UTF-8") + s.log.info(content) + response.toString + } + finally + client.getConnectionManager.shutdown() + }, + close := { + true + }, + promote := { + true + } + ) + + private def repoBase(url:String) = if(url.endsWith("/")) url.dropRight(1) else url + +} + diff --git a/src/sbt-test/sbt-sonatype/example/build.sbt b/src/sbt-test/sbt-sonatype/example/build.sbt new file mode 100644 index 00000000..a7dfd0be --- /dev/null +++ b/src/sbt-test/sbt-sonatype/example/build.sbt @@ -0,0 +1 @@ +import SonatypeKeys._ organization := "org.xerial" sonatypeSettings \ No newline at end of file diff --git a/src/sbt-test/sbt-sonatype/example/project/plugins.sbt b/src/sbt-test/sbt-sonatype/example/project/plugins.sbt new file mode 100644 index 00000000..884e6b02 --- /dev/null +++ b/src/sbt-test/sbt-sonatype/example/project/plugins.sbt @@ -0,0 +1,2 @@ +addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "0.1-SNAPSHOT") + diff --git a/src/sbt-test/sbt-sonatype/example/sbt b/src/sbt-test/sbt-sonatype/example/sbt new file mode 100755 index 00000000..c1c80507 --- /dev/null +++ b/src/sbt-test/sbt-sonatype/example/sbt @@ -0,0 +1,437 @@ +#!/usr/bin/env bash +# +# A more capable sbt runner, coincidentally also called sbt. +# Author: Paul Phillips + +# this seems to cover the bases on OSX, and someone will +# have to tell me about the others. +get_script_path () { + local path="$1" + [[ -L "$path" ]] || { echo "$path" ; return; } + + local target=$(readlink "$path") + if [[ "${target:0:1}" == "/" ]]; then + echo "$target" + else + echo "$path/$target" + fi +} + +# a ham-fisted attempt to move some memory settings in concert +# so they need not be dicked around with individually. +get_mem_opts () { + local mem=${1:-1536} + local perm=$(( $mem / 4 )) + (( $perm > 256 )) || perm=256 + (( $perm < 1024 )) || perm=1024 + local codecache=$(( $perm / 2 )) + + echo "-Xms512m -Xmx${mem}m -XX:MaxPermSize=${perm}m" +} + +die() { + echo "Aborting: $@" + exit 1 +} + +# todo - make this dynamic +declare -r sbt_release_version=0.13.1 +unset sbt_rc_version +declare -r sbt_rc_version=0.13.1 +declare -r sbt_snapshot_version=0.13.1-SNAPSHOT +declare -r sbt_snapshot_baseurl="http://typesafe.artifactoryonline.com/typesafe/ivy-snapshots/org.scala-sbt/sbt-launch/" + +declare default_jvm_opts="-Dfile.encoding=UTF8" +declare -r default_sbt_opts="-XX:+CMSClassUnloadingEnabled -XX:ReservedCodeCacheSize=128m" +declare -r default_sbt_mem=1536 +declare -r noshare_opts="-Dsbt.global.base=project/.sbtboot -Dsbt.boot.directory=project/.boot -Dsbt.ivy.home=project/.ivy" +declare -r sbt_opts_file=".sbtopts" +declare -r jvm_opts_file=".jvmopts" +declare -r latest_28="2.8.2" +declare -r latest_29="2.9.2" +declare -r latest_210="2.10.3" + +declare -r script_path=$(get_script_path "$BASH_SOURCE") + + +declare -r script_dir="$(dirname $script_path)" +declare -r script_name="$(basename $script_path)" + +declare java_cmd=java +declare sbt_mem=$default_sbt_mem + +unset sbt_jar sbt_dir sbt_tmpdir 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) + versionString=${versionLine##build.scala.versions=} + echo ${versionString%% .*} + 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:" && { + for arg; do + if printf "%s\n" "$arg" | grep -q ' '; then + printf "\"%s\"\n" "$arg" + else + printf "%s\n" "$arg" + fi + done + echo "" + } + + 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-sbt/sbt-launch/$sbt_version/sbt-launch.jar" +} +sbtjar_snapshot_url () { + local ver="$sbt_version" + echoerr "sbt version: $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_release_url ;; + *) sbtjar_release_url ;; + 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} + + curl -s --list-only "$sbt_snapshot_baseurl" | \ + grep -F $version | \ + perl -e 'print reverse <>' | \ + perl -pe 's#^/dev/null + dlog "curl returned: $?" + echo "$ver" + return + done +} + +download_url () { + local url="$1" + local jar="$2" + + 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" + elif which wget >/dev/null; then + wget --quiet -O "$jar" "$url" + fi + } && [[ -f "$jar" ]] +} + +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)" + + [[ -f "$sbt_jar" ]] || download_url "$sbt_url" "$sbt_jar" +} + + +usage () { + cat < path to global settings/plugins directory (default: ~/.sbt/) + -sbt-boot path to shared boot directory (default: ~/.sbt/boot in 0.11 series) + -ivy path to local Ivy repository (default: ~/.ivy2) + -mem 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 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 use the specified version of sbt + -sbt-jar use the specified jar as the sbt launcher + -sbt-rc use an RC version of sbt + -sbt-snapshot use a snapshot version of sbt + + # scala version (default: latest release) + -28 use $latest_28 + -29 use $latest_29 + -210 use $latest_210 + -scala-home use the scala build at the specified directory + -scala-version use the specified version of scala + + # java version (default: java from PATH, currently $(java -version |& grep version)) + -java-home alternate JAVA_HOME + + # jvm options and output control + JAVA_OPTS environment variable holding jvm args, if unset uses "$default_jvm_opts" + SBT_OPTS environment variable holding jvm args, if unset uses "$default_sbt_opts" + .jvmopts if file is in sbt root, it is prepended to the args given to the jvm + .sbtopts if file is in sbt root, it is prepended to the args given to **sbt** + -Dkey=val pass -Dkey=val directly to the jvm + -J-X pass option -X directly to the jvm (-J is stripped) + -S-X add -X to sbt's scalacOptions (-J is stripped) + +In the case of duplicated or conflicting options, the order above +shows precedence: JAVA_OPTS lowest, command line options highest. +EOM +} + +addJava () { + dlog "[addJava] arg = '$1'" + java_args=( "${java_args[@]}" "$1" ) +} +addSbt () { + dlog "[addSbt] arg = '$1'" + sbt_commands=( "${sbt_commands[@]}" "$1" ) +} +addScalac () { + dlog "[addScalac] arg = '$1'" + scalac_args=( "${scalac_args[@]}" "$1" ) +} +addResidual () { + dlog "[residual] arg = '$1'" + residual_args=( "${residual_args[@]}" "$1" ) +} +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" +} +get_jvm_opts () { + # echo "${JAVA_OPTS:-$default_jvm_opts}" + # echo "${SBT_OPTS:-$default_sbt_opts}" + + [[ -f "$jvm_opts_file" ]] && cat "$jvm_opts_file" +} + +process_args () +{ + require_arg () { + local type="$1" + local opt="$2" + local arg="$3" + + if [[ -z "$arg" ]] || [[ "${arg:0:1}" == "-" ]]; then + die "$opt requires <$type> argument" + fi + } + while [[ $# -gt 0 ]]; do + case "$1" in + -h|-help) usage; exit 1 ;; + -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 ;; + -no-colors) addJava "-Dsbt.log.noformat=true" && shift ;; + -no-share) addJava "$noshare_opts" && shift ;; + -sbt-boot) require_arg path "$1" "$2" && addJava "-Dsbt.boot.directory=$2" && shift 2 ;; + -sbt-dir) require_arg path "$1" "$2" && sbt_dir="$2" && shift 2 ;; + -debug-inc) addJava "-Dxsbt.inc.debug=true" && shift ;; + -offline) addSbt "set offline := true" && shift ;; + -jvm-debug) require_arg port "$1" "$2" && addDebugger $2 && shift 2 ;; + -batch) exec 0 )) || echo "Starting $script_name: invoke with -help for other options" + +# verify this is an sbt dir or -create was given +[[ -f ./build.sbt || -d ./project || -n "$sbt_create" ]] || { + cat <