-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathcommon-shared
137 lines (120 loc) · 3.79 KB
/
common-shared
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/env bash
# Common options for both scala-cli and java based launchers
#/*--------------------------------------------------------------------------
# * Credits: This script is based on the script generated by sbt-pack.
# *--------------------------------------------------------------------------*/
# save terminal settings
saved_stty=$(stty -g 2>/dev/null)
# clear on error so we don't later try to restore them
if [[ ! $? ]]; then
saved_stty=""
fi
# restore stty settings (echo in particular)
function restoreSttySettings() {
stty $saved_stty
saved_stty=""
}
scala_exit_status=127
function onExit() {
[[ "$saved_stty" != "" ]] && restoreSttySettings
exit $scala_exit_status
}
# to reenable echo if we are interrupted before completing.
trap onExit INT TERM EXIT
unset cygwin mingw msys darwin
# COLUMNS is used together with command line option '-pageWidth'.
if command -v tput >/dev/null 2>&1; then
export COLUMNS="$(tput -Tdumb cols)"
fi
case "`uname`" in
CYGWIN*) cygwin=true
;;
MINGW*) mingw=true
;;
MSYS*) msys=true
;;
Darwin*) darwin=true
if [ -z "$JAVA_VERSION" ] ; then
JAVA_VERSION="CurrentJDK"
else
echo "Using Java version: $JAVA_VERSION" 1>&2
fi
if [ -z "$JAVA_HOME" ] ; then
JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/${JAVA_VERSION}/Home
fi
JAVACMD="`which java`"
;;
esac
unset CYGPATHCMD
if [[ ${cygwin-} || ${mingw-} || ${msys-} ]]; then
# cygpath is used by various windows shells: cygwin, git-sdk, gitbash, msys, etc.
CYGPATHCMD=`which cygpath 2>/dev/null`
case "$TERM" in
rxvt* | xterm* | cygwin*)
stty -icanon min 1 -echo
JAVA_OPTS="$JAVA_OPTS -Djline.terminal=unix"
;;
esac
fi
# Resolve JAVA_HOME from javac command path
if [ -z "$JAVA_HOME" ]; then
javaExecutable="`which javac`"
if [ -n "$javaExecutable" -a -f "$javaExecutable" -a ! "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
# readlink(1) is not available as standard on Solaris 10.
readLink=`which readlink`
if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
javaExecutable="`readlink -f \"$javaExecutable\"`"
javaHome="`dirname \"$javaExecutable\"`"
javaHome=`expr "$javaHome" : '\(.*\)/bin'`
JAVA_HOME="$javaHome"
export JAVA_HOME
fi
fi
fi
if [ -z "${JAVACMD-}" ] ; then
if [ -n "${JAVA_HOME-}" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
else
JAVACMD="`which java`"
fi
fi
if [ ! -x "$JAVACMD" ] ; then
echo "Error: JAVA_HOME is not defined correctly."
echo " We cannot execute $JAVACMD"
exit 1
fi
if [ -z "$JAVA_HOME" ] ; then
echo "Warning: JAVA_HOME environment variable is not set."
fi
CLASSPATH_SUFFIX=""
# Path separator used in EXTRA_CLASSPATH
PSEP=":"
PROG_HOME_URI="file://$PROG_HOME"
# translate paths to Windows-mixed format before running java
if [ -n "${CYGPATHCMD-}" ]; then
[ -n "${PROG_HOME-}" ] &&
PROG_HOME=`"$CYGPATHCMD" -am "$PROG_HOME"`
PROG_HOME_URI="file:///$PROG_HOME" # Add extra root dir prefix
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`"$CYGPATHCMD" -am "$JAVA_HOME"`
CLASSPATH_SUFFIX=";"
PSEP=";"
elif [[ ${mingw-} || ${msys-} ]]; then
# For Mingw / Msys, convert paths from UNIX format before anything is touched
[ -n "$PROG_HOME" ] &&
PROG_HOME="`(cd "$PROG_HOME"; pwd -W | sed 's|/|\\\\|g')`"
PROG_HOME_URI="file:///$PROG_HOME" # Add extra root dir prefix
[ -n "$JAVA_HOME" ] &&
JAVA_HOME="`(cd "$JAVA_HOME"; pwd -W | sed 's|/|\\\\|g')`"
CLASSPATH_SUFFIX=";"
PSEP=";"
fi
declare -a scala_args
addScala () {
scala_args+=("'$1'")
}