This commit is contained in:
Tony Tam 2014-02-19 12:15:50 -08:00
parent d72578e492
commit 5a4af29f0e
2 changed files with 92 additions and 40 deletions

View File

@ -7,7 +7,7 @@ name := "swagger-codegen"
version := "2.0.13" version := "2.0.13"
scalaVersion := "2.10.0" scalaVersion := "2.10.1"
crossVersion := CrossVersion.full crossVersion := CrossVersion.full
@ -22,7 +22,7 @@ libraryDependencies ++= Seq(
"io.backchat.inflector" %% "scala-inflector" % "1.3.5", "io.backchat.inflector" %% "scala-inflector" % "1.3.5",
"commons-io" % "commons-io" % "2.3", "commons-io" % "commons-io" % "2.3",
"ch.qos.logback" % "logback-classic" % "1.0.13" % "provided", "ch.qos.logback" % "logback-classic" % "1.0.13" % "provided",
"org.rogach" %% "scallop" % "0.9.4", "org.rogach" %% "scallop" % "0.8.1",
"junit" % "junit" % "4.11" % "test", "junit" % "junit" % "4.11" % "test",
"org.scalatest" %% "scalatest" % "1.9.1" % "test" "org.scalatest" %% "scalatest" % "1.9.1" % "test"
) )

128
sbt
View File

@ -4,23 +4,32 @@
# Author: Paul Phillips <paulp@typesafe.com> # Author: Paul Phillips <paulp@typesafe.com>
# todo - make this dynamic # todo - make this dynamic
declare -r sbt_release_version=0.12.2 declare -r sbt_release_version=0.12.4
declare -r sbt_beta_version=0.13.0-RC4
declare -r sbt_snapshot_version=0.13.0-SNAPSHOT declare -r sbt_snapshot_version=0.13.0-SNAPSHOT
declare sbt_jar sbt_dir sbt_create sbt_snapshot sbt_launch_dir declare sbt_jar sbt_dir sbt_create sbt_snapshot sbt_launch_dir
declare scala_version java_home sbt_explicit_version declare scala_version java_home sbt_explicit_version
declare verbose debug quiet noshare batch trace_level log_level declare verbose debug quiet noshare batch trace_level log_level
declare sbt_saved_stty
echoerr () { [[ -z $quiet ]] && echo "$@" >&2; }
vlog () { [[ -n "$verbose$debug" ]] && echoerr "$@"; }
dlog () { [[ -n $debug ]] && echoerr "$@"; }
# we'd like these set before we get around to properly processing arguments
for arg in "$@"; do for arg in "$@"; do
case $arg in case $arg in
-q|-quiet) quiet=true ;; -q|-quiet) quiet=true ;;
*) ;; -d|-debug) debug=true ;;
-v|-verbose) verbose=true ;;
*) ;;
esac esac
done done
build_props_sbt () { build_props_sbt () {
if [[ -r project/build.properties ]]; then if [[ -r project/build.properties ]]; then
versionLine=$(grep ^sbt.version project/build.properties) versionLine=$(grep ^sbt.version project/build.properties | tr -d '\r')
versionString=${versionLine##sbt.version=} versionString=${versionLine##sbt.version=}
echo "$versionString" echo "$versionString"
fi fi
@ -36,10 +45,10 @@ update_build_props_sbt () {
perl -pi -e "s/^sbt\.version=.*\$/sbt.version=${ver}/" project/build.properties 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 grep -q '^sbt.version=' project/build.properties || echo "sbt.version=${ver}" >> project/build.properties
echo !!! echoerr !!!
echo !!! Updated file project/build.properties setting sbt.version to: $ver echoerr !!! Updated file project/build.properties setting sbt.version to: $ver
echo !!! Previous value was: $old echoerr !!! Previous value was: $old
echo !!! echoerr !!!
fi fi
} }
@ -56,16 +65,20 @@ sbt_version () {
fi fi
} }
echoerr () { # restore stty settings (echo in particular)
[[ -z $quiet ]] && echo "$@" >&2 onSbtRunnerExit() {
} [[ -n $sbt_saved_stty ]] || return
vlog () { dlog ""
[[ $verbose || $debug ]] && echoerr "$@" dlog "restoring stty: $sbt_saved_stty"
} stty $sbt_saved_stty
dlog () { unset sbt_saved_stty
[[ $debug ]] && echoerr "$@"
} }
# save stty and trap exit, to ensure echo is reenabled if we are interrupted.
trap onSbtRunnerExit EXIT
sbt_saved_stty=$(stty -g 2>/dev/null)
dlog "Saved stty: $sbt_saved_stty"
# this seems to cover the bases on OSX, and someone will # this seems to cover the bases on OSX, and someone will
# have to tell me about the others. # have to tell me about the others.
get_script_path () { get_script_path () {
@ -93,6 +106,24 @@ make_url () {
echo "http://typesafe.artifactoryonline.com/typesafe/ivy-$category/$groupid/sbt-launch/$version/sbt-launch.jar" echo "http://typesafe.artifactoryonline.com/typesafe/ivy-$category/$groupid/sbt-launch/$version/sbt-launch.jar"
} }
readarr () {
while read ; do
eval "$1+=(\"$REPLY\")"
done
}
init_default_option_file () {
local overriding_var=${!1}
local default_file=$2
if [[ ! -r "$default_file" && $overriding_var =~ ^@(.*)$ ]]; then
local envvar_file=${BASH_REMATCH[1]}
if [[ -r $envvar_file ]]; then
default_file=$envvar_file
fi
fi
echo $default_file
}
declare -r default_jvm_opts="-Dfile.encoding=UTF8 -XX:MaxPermSize=256m -Xms512m -Xmx1g -XX:+CMSClassUnloadingEnabled -XX:+UseConcMarkSweepGC" declare -r default_jvm_opts="-Dfile.encoding=UTF8 -XX:MaxPermSize=256m -Xms512m -Xmx1g -XX:+CMSClassUnloadingEnabled -XX:+UseConcMarkSweepGC"
declare -r noshare_opts="-Dsbt.global.base=project/.sbtboot -Dsbt.boot.directory=project/.boot -Dsbt.ivy.home=project/.ivy" declare -r noshare_opts="-Dsbt.global.base=project/.sbtboot -Dsbt.boot.directory=project/.boot -Dsbt.ivy.home=project/.ivy"
declare -r latest_28="2.8.2" declare -r latest_28="2.8.2"
@ -105,11 +136,8 @@ declare -r script_name="$(basename $script_path)"
# some non-read-onlies set with defaults # some non-read-onlies set with defaults
declare java_cmd=java declare java_cmd=java
declare sbt_launch_dir="$script_dir/.lib" declare sbt_opts_file=$(init_default_option_file SBT_OPTS .sbtopts)
declare sbt_universal_launcher="$script_dir/lib/sbt-launch.jar" declare jvm_opts_file=$(init_default_option_file JVM_OPTS .jvmopts)
declare sbt_jar=$sbt_universal_launcher
declare sbt_opts_file=.sbtopts
declare jvm_opts_file=.jvmopts
# pull -J and -D options to give to java. # pull -J and -D options to give to java.
declare -a residual_args declare -a residual_args
@ -123,8 +151,10 @@ declare -a extra_jvm_opts extra_sbt_opts
# if set, use JAVA_HOME over java found in path # if set, use JAVA_HOME over java found in path
[[ -e "$JAVA_HOME/bin/java" ]] && java_cmd="$JAVA_HOME/bin/java" [[ -e "$JAVA_HOME/bin/java" ]] && java_cmd="$JAVA_HOME/bin/java"
# use ~/.sbt/launch to store sbt jars if script_dir is not writable # directory to store sbt launchers
[[ -w "$sbt_launch_dir" ]] || sbt_launch_dir="$HOME/.sbt/launch" declare sbt_launch_dir="$HOME/.sbt/launchers"
[[ -d "$sbt_launch_dir" ]] || mkdir -p "$sbt_launch_dir"
[[ -w "$sbt_launch_dir" ]] || sbt_launch_dir="$(mktemp -d -t sbt_extras_launchers)"
build_props_scala () { build_props_scala () {
if [[ -r project/build.properties ]]; then if [[ -r project/build.properties ]]; then
@ -156,7 +186,7 @@ execRunner () {
# I'm sure there's some way to get our hands on the pid and wait for it # I'm sure there's some way to get our hands on the pid and wait for it
# but it exceeds my present level of ambition. # but it exceeds my present level of ambition.
else else
exec "$@" { "$@"; }
fi fi
} }
@ -207,7 +237,10 @@ jar_url () {
} }
jar_file () { jar_file () {
echo "$sbt_launch_dir/$1/sbt-launch.jar" case $1 in
0.13.*) echo "$sbt_launch_dir/$1/sbt-launch.jar" ;;
*) echo "$sbt_launch_dir/$sbt_release_version/sbt-launch.jar" ;;
esac
} }
download_url () { download_url () {
@ -257,9 +290,10 @@ Usage: $script_name [options]
# sbt version (default: from project/build.properties if present, else latest release) # sbt version (default: from project/build.properties if present, else latest release)
!!! The only way to accomplish this pre-0.12.0 if there is a build.properties file which !!! 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. !!! 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-version <version> use the specified version of sbt (default: $sbt_release_version)
-sbt-jar <path> use the specified jar as the sbt launcher -sbt-jar <path> use the specified jar as the sbt launcher
-sbt-snapshot use a snapshot version of sbt -sbt-beta use a beta version of sbt (currently: $sbt_beta_version)
-sbt-snapshot use a snapshot version of sbt (currently: $sbt_snapshot_version)
-sbt-launch-dir <path> directory to hold sbt launchers (default: $sbt_launch_dir) -sbt-launch-dir <path> directory to hold sbt launchers (default: $sbt_launch_dir)
# scala version (default: as chosen by sbt) # scala version (default: as chosen by sbt)
@ -270,19 +304,23 @@ Usage: $script_name [options]
-scala-version <version> use the specified version of scala -scala-version <version> use the specified version of scala
-binary-version <version> use the specified scala version when searching for dependencies -binary-version <version> use the specified scala version when searching for dependencies
# java version (default: java from PATH, currently $(java -version |& grep version)) # java version (default: java from PATH, currently $(java -version 2>&1 | grep version))
-java-home <path> alternate JAVA_HOME -java-home <path> alternate JAVA_HOME
# passing options to the jvm - note it does NOT use JAVA_OPTS due to pollution # passing options to the jvm - note it does NOT use JAVA_OPTS due to pollution
# The default set is used if JVM_OPTS is unset and no -jvm-opts file is found # The default set is used if JVM_OPTS is unset and no -jvm-opts file is found
<default> $default_jvm_opts <default> $default_jvm_opts
JVM_OPTS environment variable holding jvm args JVM_OPTS environment variable holding either the jvm args directly, or
the reference to a file containing jvm args if given path is prepended by '@' (e.g. '@/etc/jvmopts')
Note: "@"-file is overridden by local '.jvmopts' or '-jvm-opts' argument.
-jvm-opts <path> file containing jvm args (if not given, .jvmopts in project root is used if present) -jvm-opts <path> file containing jvm args (if not given, .jvmopts in project root is used if present)
-Dkey=val pass -Dkey=val directly to the jvm -Dkey=val pass -Dkey=val directly to the jvm
-J-X pass option -X directly to the jvm (-J is stripped) -J-X pass option -X directly to the jvm (-J is stripped)
# passing options to sbt, OR to this runner # passing options to sbt, OR to this runner
SBT_OPTS environment variable holding sbt args SBT_OPTS environment variable holding either the sbt args directly, or
the reference to a file containing sbt args if given path is prepended by '@' (e.g. '@/etc/sbtopts')
Note: "@"-file is overridden by local '.sbtopts' or '-sbt-opts' argument.
-sbt-opts <path> file containing sbt args (if not given, .sbtopts in project root is used if present) -sbt-opts <path> file containing sbt args (if not given, .sbtopts in project root is used if present)
-S-X add -X to sbt's scalacOptions (-S is stripped) -S-X add -X to sbt's scalacOptions (-S is stripped)
EOM EOM
@ -308,7 +346,8 @@ addResolver () {
addSbt "set resolvers in ThisBuild += $1" addSbt "set resolvers in ThisBuild += $1"
} }
addDebugger () { addDebugger () {
addJava "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=$1" addJava "-Xdebug"
addJava "-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=$1"
} }
setScalaVersion () { setScalaVersion () {
addSbt "set scalaVersion in ThisBuild := \"$1\"" addSbt "set scalaVersion in ThisBuild := \"$1\""
@ -349,6 +388,7 @@ process_args ()
-sbt-create) sbt_create=true && shift ;; -sbt-create) sbt_create=true && shift ;;
-sbt-snapshot) sbt_explicit_version=$sbt_snapshot_version && shift ;; -sbt-snapshot) sbt_explicit_version=$sbt_snapshot_version && shift ;;
-sbt-beta) sbt_explicit_version=$sbt_beta_version && shift ;;
-sbt-jar) require_arg path "$1" "$2" && sbt_jar="$2" && shift 2 ;; -sbt-jar) require_arg path "$1" "$2" && sbt_jar="$2" && shift 2 ;;
-sbt-version) require_arg version "$1" "$2" && sbt_explicit_version="$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 ;; -sbt-launch-dir) require_arg path "$1" "$2" && sbt_launch_dir="$2" && shift 2 ;;
@ -375,12 +415,21 @@ process_args ()
# process the direct command line arguments # process the direct command line arguments
process_args "$@" process_args "$@"
# skip #-styled comments
readConfigFile() {
while read line; do echo ${line/\#*/} | grep -vE '^\s*$'; done < $1
}
# if there are file/environment sbt_opts, process again so we # if there are file/environment sbt_opts, process again so we
# can supply args to this runner # can supply args to this runner
if [[ -r "$sbt_opts_file" ]]; then if [[ -r "$sbt_opts_file" ]]; then
readarray -t extra_sbt_opts < "$sbt_opts_file" vlog "Using sbt options defined in file $sbt_opts_file"
elif [[ -n "$SBT_OPTS" ]]; then readarr extra_sbt_opts < <(readConfigFile "$sbt_opts_file")
elif [[ -n "$SBT_OPTS" && !($SBT_OPTS =~ ^@.*) ]]; then
vlog "Using sbt options defined in variable \$SBT_OPTS"
extra_sbt_opts=( $SBT_OPTS ) extra_sbt_opts=( $SBT_OPTS )
else
vlog "No extra sbt options have been defined"
fi fi
[[ -n $extra_sbt_opts ]] && process_args "${extra_sbt_opts[@]}" [[ -n $extra_sbt_opts ]] && process_args "${extra_sbt_opts[@]}"
@ -402,12 +451,12 @@ setTraceLevel() {
# Update build.properties no disk to set explicit version - sbt gives us no choice # 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" [[ -n "$sbt_explicit_version" ]] && update_build_props_sbt "$sbt_explicit_version"
echoerr "Detected sbt version $(sbt_version)" vlog "Detected sbt version $(sbt_version)"
[[ -n "$scala_version" ]] && echo "Overriding scala version to $scala_version" [[ -n "$scala_version" ]] && echoerr "Overriding scala version to $scala_version"
# no args - alert them there's stuff in here # no args - alert them there's stuff in here
(( $argumentCount > 0 )) || echo "Starting $script_name: invoke with -help for other options" (( $argumentCount > 0 )) || vlog "Starting $script_name: invoke with -help for other options"
# verify this is an sbt dir or -create was given # verify this is an sbt dir or -create was given
[[ -r ./build.sbt || -d ./project || -n "$sbt_create" ]] || { [[ -r ./build.sbt || -d ./project || -n "$sbt_create" ]] || {
@ -441,10 +490,13 @@ else
fi fi
if [[ -r "$jvm_opts_file" ]]; then if [[ -r "$jvm_opts_file" ]]; then
readarray -t extra_jvm_opts < "$jvm_opts_file" vlog "Using jvm options defined in file $jvm_opts_file"
elif [[ -n "$JVM_OPTS" ]]; then readarr extra_jvm_opts < <(readConfigFile "$jvm_opts_file")
elif [[ -n "$JVM_OPTS" && !($JVM_OPTS =~ ^@.*) ]]; then
vlog "Using jvm options defined in \$JVM_OPTS variable"
extra_jvm_opts=( $JVM_OPTS ) extra_jvm_opts=( $JVM_OPTS )
else else
vlog "Using default jvm options"
extra_jvm_opts=( $default_jvm_opts ) extra_jvm_opts=( $default_jvm_opts )
fi fi