Skip to content
This repository was archived by the owner on Aug 24, 2018. It is now read-only.

Commit de8dbfe

Browse files
committed
update sbt-extras
1 parent 1c39b09 commit de8dbfe

File tree

1 file changed

+37
-9
lines changed

1 file changed

+37
-9
lines changed

sbt

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
# todo - make this dynamic
77
declare -r sbt_release_version=0.12.4
8-
declare -r sbt_beta_version=0.13.0-RC1
8+
declare -r sbt_beta_version=0.13.0-RC4
99
declare -r sbt_snapshot_version=0.13.0-SNAPSHOT
1010

1111
declare sbt_jar sbt_dir sbt_create sbt_snapshot sbt_launch_dir
@@ -112,6 +112,18 @@ readarr () {
112112
done
113113
}
114114

115+
init_default_option_file () {
116+
local overriding_var=${!1}
117+
local default_file=$2
118+
if [[ ! -r "$default_file" && $overriding_var =~ ^@(.*)$ ]]; then
119+
local envvar_file=${BASH_REMATCH[1]}
120+
if [[ -r $envvar_file ]]; then
121+
default_file=$envvar_file
122+
fi
123+
fi
124+
echo $default_file
125+
}
126+
115127
declare -r default_jvm_opts="-Dfile.encoding=UTF8 -XX:MaxPermSize=256m -Xms512m -Xmx1g -XX:+CMSClassUnloadingEnabled -XX:+UseConcMarkSweepGC"
116128
declare -r noshare_opts="-Dsbt.global.base=project/.sbtboot -Dsbt.boot.directory=project/.boot -Dsbt.ivy.home=project/.ivy"
117129
declare -r latest_28="2.8.2"
@@ -124,8 +136,8 @@ declare -r script_name="$(basename $script_path)"
124136

125137
# some non-read-onlies set with defaults
126138
declare java_cmd=java
127-
declare sbt_opts_file=.sbtopts
128-
declare jvm_opts_file=.jvmopts
139+
declare sbt_opts_file=$(init_default_option_file SBT_OPTS .sbtopts)
140+
declare jvm_opts_file=$(init_default_option_file JVM_OPTS .jvmopts)
129141

130142
# pull -J and -D options to give to java.
131143
declare -a residual_args
@@ -298,13 +310,17 @@ Usage: $script_name [options]
298310
# passing options to the jvm - note it does NOT use JAVA_OPTS due to pollution
299311
# The default set is used if JVM_OPTS is unset and no -jvm-opts file is found
300312
<default> $default_jvm_opts
301-
JVM_OPTS environment variable holding jvm args
313+
JVM_OPTS environment variable holding either the jvm args directly, or
314+
the reference to a file containing jvm args if given path is prepended by '@' (e.g. '@/etc/jvmopts')
315+
Note: "@"-file is overridden by local '.jvmopts' or '-jvm-opts' argument.
302316
-jvm-opts <path> file containing jvm args (if not given, .jvmopts in project root is used if present)
303317
-Dkey=val pass -Dkey=val directly to the jvm
304318
-J-X pass option -X directly to the jvm (-J is stripped)
305319
306320
# passing options to sbt, OR to this runner
307-
SBT_OPTS environment variable holding sbt args
321+
SBT_OPTS environment variable holding either the sbt args directly, or
322+
the reference to a file containing sbt args if given path is prepended by '@' (e.g. '@/etc/sbtopts')
323+
Note: "@"-file is overridden by local '.sbtopts' or '-sbt-opts' argument.
308324
-sbt-opts <path> file containing sbt args (if not given, .sbtopts in project root is used if present)
309325
-S-X add -X to sbt's scalacOptions (-S is stripped)
310326
EOM
@@ -399,12 +415,21 @@ process_args ()
399415
# process the direct command line arguments
400416
process_args "$@"
401417

418+
# skip #-styled comments
419+
readConfigFile() {
420+
while read line; do echo ${line/\#*/} | grep -vE '^\s*$'; done < $1
421+
}
422+
402423
# if there are file/environment sbt_opts, process again so we
403424
# can supply args to this runner
404425
if [[ -r "$sbt_opts_file" ]]; then
405-
readarr extra_sbt_opts < "$sbt_opts_file"
406-
elif [[ -n "$SBT_OPTS" ]]; then
426+
vlog "Using sbt options defined in file $sbt_opts_file"
427+
readarr extra_sbt_opts < <(readConfigFile "$sbt_opts_file")
428+
elif [[ -n "$SBT_OPTS" && !($SBT_OPTS =~ ^@.*) ]]; then
429+
vlog "Using sbt options defined in variable \$SBT_OPTS"
407430
extra_sbt_opts=( $SBT_OPTS )
431+
else
432+
vlog "No extra sbt options have been defined"
408433
fi
409434

410435
[[ -n $extra_sbt_opts ]] && process_args "${extra_sbt_opts[@]}"
@@ -465,10 +490,13 @@ else
465490
fi
466491

467492
if [[ -r "$jvm_opts_file" ]]; then
468-
readarr extra_jvm_opts < "$jvm_opts_file"
469-
elif [[ -n "$JVM_OPTS" ]]; then
493+
vlog "Using jvm options defined in file $jvm_opts_file"
494+
readarr extra_jvm_opts < <(readConfigFile "$jvm_opts_file")
495+
elif [[ -n "$JVM_OPTS" && !($JVM_OPTS =~ ^@.*) ]]; then
496+
vlog "Using jvm options defined in \$JVM_OPTS variable"
470497
extra_jvm_opts=( $JVM_OPTS )
471498
else
499+
vlog "Using default jvm options"
472500
extra_jvm_opts=( $default_jvm_opts )
473501
fi
474502

0 commit comments

Comments
 (0)