-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
startGroovy
308 lines (275 loc) · 13.4 KB
/
startGroovy
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
#!/usr/bin/env sh
# -*- mode:sh -*-
# ----------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.
# ----------------------------------------------------------------------------
##############################################################################
## ##
## Groovy JVM Bootstrap for UN*X ##
## ##
##############################################################################
PROGNAME="$(basename "$0")"
SCRIPT_PATH="$0"
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn ( ) {
echo "${PROGNAME}: $*"
}
die ( ) {
warn "$*"
exit 1
}
earlyInit ( ) {
return
}
lateInit ( ) {
return
}
GROOVY_STARTUP="$HOME/.groovy/startup"
if [ -r "$GROOVY_STARTUP" ] ; then
. "$GROOVY_STARTUP"
fi
earlyInit
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
linux=false
case "$(uname)" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
Linux* )
linux=true
;;
esac
if [ "$1" = "-cp" ] || [ "$1" = "-classpath" ] || [ "$1" = "--classpath" ] ; then
CP=$2
shift 2
fi
REPLACE_PREVIEW=
if [ "$1" = "-pr" ] || [ "$1" = "--enable-preview" ] ; then
JAVA_OPTS="$JAVA_OPTS --enable-preview -Dgroovy.preview.features=true"
# for now, also remember arg to pass through
REPLACE_PREVIEW="--enable-preview"
shift 1
fi
# Attempt to set JAVA_HOME if it's not already set.
if [ -z "$JAVA_HOME" ] ; then
if $darwin ; then
[ -z "$JAVA_HOME" ] && [ -f "/usr/libexec/java_home" ] && JAVA_HOME="$(/usr/libexec/java_home)"
[ -z "$JAVA_HOME" ] && [ -d "/Library/Java/Home" ] && JAVA_HOME="/Library/Java/Home"
[ -z "$JAVA_HOME" ] && [ -d "/System/Library/Frameworks/JavaVM.framework/Home" ] && JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Home"
else
javaExecutable="$(which javac)"
[ -z "$javaExecutable" ] || [ "$(expr "$javaExecutable" : '\([^ ]*\)')" = "no" ] && die "JAVA_HOME not set and cannot find javac to deduce location, please set JAVA_HOME."
# readlink(1) is not available as standard on Solaris 10.
readLink="$(which readlink)"
[ "$(expr "$readLink" : '\([^ ]*\)')" = "no" ] && die "JAVA_HOME not set and readlink not available, please set JAVA_HOME."
javaExecutable="$(readlink -f "$javaExecutable")"
javaHome="$(dirname "$javaExecutable")"
javaHome="$(expr "$javaHome" : '\(.*\)/bin')"
JAVA_HOME="$javaHome"
fi
export JAVA_HOME
fi
# GROOVY-9875: backspace does not work in the SecureCRT connecting Linux
if $linux ; then
export TERM=linux
fi
# For Cygwin, ensure paths are in UNIX format before anything is touched.
if $cygwin ; then
[ -n "$GROOVY_HOME" ] && GROOVY_HOME="$(cygpath --unix "$GROOVY_HOME")"
[ -n "$JAVACMD" ] && JAVACMD="$(cygpath --unix "$JAVACMD")"
[ -n "$JAVA_HOME" ] && JAVA_HOME="$(cygpath --unix "$JAVA_HOME")"
[ -n "$CP" ] && CP=$(cygpath --path --unix "$CP")
else
if [ -n "$GROOVY_HOME" ] && [ "$(expr "$GROOVY_HOME" : '\/$')" ] ; then
GROOVY_HOME="$(echo "$GROOVY_HOME" | sed -e 's/\/$//')"
fi
fi
# For MSYS, ensure paths are in appropriate format.
if $msys
then
[ -n "$JAVA_HOME" ] && JAVA_HOME="$(cd "$JAVA_HOME" ; pwd)"
fi
# Attempt to set GROOVY_HOME if it is not already set.
if [ -z "$GROOVY_HOME" ] || [ ! -d "$GROOVY_HOME" ] ; then
# Resolve links: $0 may be a link to groovy's home.
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls="$(ls -ld "$PRG")"
link="$(expr "$ls" : '.*-> \(.*\)$')"
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG="$(dirname "$PRG")""/$link"
fi
done
SAVED="$(pwd)"
cd "$(dirname "$PRG")/.."
GROOVY_HOME="$(pwd -P)"
cd "$SAVED"
fi
# Set the default Groovy config if no specific one is mentioned.
if [ -z "$GROOVY_CONF" ] ; then
GROOVY_CONF="$GROOVY_HOME/conf/groovy-starter.conf"
fi
STARTER_CLASSPATH="$GROOVY_HOME/lib/@GROOVYJAR@"
# Create the final classpath. Setting a classpath using the -cp or -classpath option means not to use the
# global classpath. Groovy behaves then the same as the java interpreter
if [ -n "$CP" ] ; then
CP="$CP":.
elif [ -n "$CLASSPATH" ] ; then
CP="$CLASSPATH":.
else
CP=.
fi
# Determine the Java command to use to start the JVM.
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="java"
fi
fi
if [ ! -x "$JAVACMD" ] ; then
die "JAVA_HOME is not defined correctly, can not execute: $JAVACMD"
fi
if [ -z "$JAVA_HOME" ] ; then
warn "JAVA_HOME environment variable is not set"
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" ] && [ "$darwin" = "false" ] && [ "$nonstop" = "false" ] ; then
# disable ulimit shellcheck warnings. while only ulimit -f is technicaly
# POSIX correct virtually every shell on every *nix supports these options
# shellcheck disable=SC2039
MAX_FD_LIMIT="$(ulimit -H -n)"
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" ] || [ "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
# shellcheck disable=SC2039
ulimit -n "$MAX_FD"
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query businessSystem maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# Setup Profiler
useprofiler=false
if [ "$PROFILER" != "" ] ; then
if [ -r "$PROFILER" ] ; then
. "$PROFILER"
useprofiler=true
else
die "Profiler file not found: $PROFILER"
fi
fi
# For Darwin, use classes.jar for TOOLS_JAR
TOOLS_JAR="$JAVA_HOME/lib/tools.jar"
#if $darwin; then
# TOOLS_JAR="/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Classes/classes.jar"
#fi
# For Darwin, add GROOVY_APP_NAME to the JAVA_OPTS as -Xdock:name
if "$darwin"; then
JAVA_OPTS="$JAVA_OPTS -Xdock:name=$GROOVY_APP_NAME -Xdock:icon=$GROOVY_HOME/lib/groovy.icns"
fi
# For Cygwin, switch paths to Windows format before running java
if "$cygwin"; then
GROOVY_HOME="$(cygpath --mixed "$GROOVY_HOME")"
JAVA_HOME="$(cygpath --mixed "$JAVA_HOME")"
GROOVY_CONF="$(cygpath --mixed "$GROOVY_CONF")"
CP="$(cygpath --path --mixed "$CP")"
TOOLS_JAR="$(cygpath --mixed "$TOOLS_JAR")"
STARTER_CLASSPATH="$(cygpath --path --mixed "$STARTER_CLASSPATH")"
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW="$(find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null)"
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GROOVY_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GROOVY_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
argsstr=''
for arg in "$@" ; do
CHECK="$(echo "$arg"|grep -E -c "$OURCYGPATTERN" -)"
if [ "$CHECK" -ne 0 ] ; then
patched="$(cygpath --path --ignore --mixed "$arg")"
else
patched="$arg"
fi
argsstr="$argsstr \"$patched\""
done
eval "set -- $argsstr"
fi
startGroovy ( ) {
JAVA_VERSION="$("$JAVACMD" -version 2>&1 | awk -F '"' '/version/ {print $2}' | cut -d "_" -f1)"
if [ "$(expr "$JAVA_VERSION" \> "1.8.0")" ]; then
[ "$GROOVY_TURN_OFF_JAVA_WARNINGS" = "true" ] && JAVA_OPTS="$JAVA_OPTS --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.annotation=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.lang.module=ALL-UNNAMED --add-opens=java.base/java.lang.ref=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.math=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.net.spi=ALL-UNNAMED --add-opens=java.base/java.nio=ALL-UNNAMED --add-opens=java.base/java.nio.channels=ALL-UNNAMED --add-opens=java.base/java.nio.channels.spi=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.nio.charset.spi=ALL-UNNAMED --add-opens=java.base/java.nio.file=ALL-UNNAMED --add-opens=java.base/java.nio.file.attribute=ALL-UNNAMED --add-opens=java.base/java.nio.file.spi=ALL-UNNAMED --add-opens=java.base/java.security=ALL-UNNAMED --add-opens=java.base/java.security.acl=ALL-UNNAMED --add-opens=java.base/java.security.cert=ALL-UNNAMED --add-opens=java.base/java.security.interfaces=ALL-UNNAMED --add-opens=java.base/java.security.spec=ALL-UNNAMED --add-opens=java.base/java.text=ALL-UNNAMED --add-opens=java.base/java.text.spi=ALL-UNNAMED --add-opens=java.base/java.time=ALL-UNNAMED --add-opens=java.base/java.time.chrono=ALL-UNNAMED --add-opens=java.base/java.time.format=ALL-UNNAMED --add-opens=java.base/java.time.temporal=ALL-UNNAMED --add-opens=java.base/java.time.zone=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.locks=ALL-UNNAMED --add-opens=java.base/java.util.function=ALL-UNNAMED --add-opens=java.base/java.util.jar=ALL-UNNAMED --add-opens=java.base/java.util.regex=ALL-UNNAMED --add-opens=java.base/java.util.spi=ALL-UNNAMED --add-opens=java.base/java.util.stream=ALL-UNNAMED --add-opens=java.base/java.util.zip=ALL-UNNAMED --add-opens=java.datatransfer/java.awt.datatransfer=ALL-UNNAMED --add-opens=java.desktop/java.applet=ALL-UNNAMED --add-opens=java.desktop/java.awt=ALL-UNNAMED --add-opens=java.desktop/java.awt.color=ALL-UNNAMED --add-opens=java.desktop/java.awt.desktop=ALL-UNNAMED --add-opens=java.desktop/java.awt.dnd=ALL-UNNAMED --add-opens=java.desktop/java.awt.dnd.peer=ALL-UNNAMED --add-opens=java.desktop/java.awt.event=ALL-UNNAMED --add-opens=java.desktop/java.awt.font=ALL-UNNAMED --add-opens=java.desktop/java.awt.geom=ALL-UNNAMED --add-opens=java.desktop/java.awt.im=ALL-UNNAMED --add-opens=java.desktop/java.awt.im.spi=ALL-UNNAMED --add-opens=java.desktop/java.awt.image=ALL-UNNAMED --add-opens=java.desktop/java.awt.image.renderable=ALL-UNNAMED --add-opens=java.desktop/java.awt.peer=ALL-UNNAMED --add-opens=java.desktop/java.awt.print=ALL-UNNAMED --add-opens=java.desktop/java.beans=ALL-UNNAMED --add-opens=java.desktop/java.beans.beancontext=ALL-UNNAMED --add-opens=java.instrument/java.lang.instrument=ALL-UNNAMED --add-opens=java.logging/java.util.logging=ALL-UNNAMED --add-opens=java.management/java.lang.management=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.rmi/java.rmi=ALL-UNNAMED --add-opens=java.rmi/java.rmi.activation=ALL-UNNAMED --add-opens=java.rmi/java.rmi.dgc=ALL-UNNAMED --add-opens=java.rmi/java.rmi.registry=ALL-UNNAMED --add-opens=java.rmi/java.rmi.server=ALL-UNNAMED --add-opens=java.sql/java.sql=ALL-UNNAMED --add-opens=java.desktop/javax.swing=ALL-UNNAMED --add-opens=java.desktop/javax.swing.border=ALL-UNNAMED --add-opens=java.desktop/javax.swing.text=ALL-UNNAMED --add-opens=java.desktop/javax.swing.text.html=ALL-UNNAMED --add-opens=java.desktop/sun.awt=ALL-UNNAMED --add-opens=java.desktop/sun.java2d=ALL-UNNAMED --add-opens=java.desktop/sun.font=ALL-UNNAMED"
# sun.awt.windows just on windows platforms
if [ $msys = 'true' ] || [ $cygwin = 'true' ]; then
[ "$GROOVY_TURN_OFF_JAVA_WARNINGS" = "true" ] && JAVA_OPTS="$JAVA_OPTS --add-opens=java.desktop/sun.awt.windows=ALL-UNNAMED"
fi
fi
CLASS="$1"
shift
# Start the Profiler or the JVM
if [ "$useprofiler" = true ] ; then
runProfiler
else
# shellcheck disable=SC2086
exec "$JAVACMD" $JAVA_OPTS \
-classpath "$STARTER_CLASSPATH" \
-Dscript.name="$SCRIPT_PATH" \
-Dprogram.name="$PROGNAME" \
-Dgroovy.starter.conf="$GROOVY_CONF" \
-Dgroovy.home="$GROOVY_HOME" \
-Dtools.jar="$TOOLS_JAR" \
"$STARTER_MAIN_CLASS" \
--main "$CLASS" \
--conf "$GROOVY_CONF" \
--classpath "$CP" $REPLACE_PREVIEW \
"$@"
fi
}
STARTER_MAIN_CLASS=org.codehaus.groovy.tools.GroovyStarter
lateInit