This repository has been archived by the owner on Jan 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
grailsw
executable file
·335 lines (287 loc) · 8.48 KB
/
grailsw
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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
##############################################################################
## ##
## Grails JVM Bootstrap for UN*X ##
## ##
##############################################################################
PROGNAME=`basename "$0"`
DIRNAME=`dirname "$0"`
# Use the maximum available, or set MAX_FD != -1 to use that
MAX_FD="maximum"
warn() {
echo "${PROGNAME}: $*"
}
die() {
warn "$*"
exit 1
}
earlyInit() {
return
}
lateInit() {
return
}
GROOVY_STARTUP=~/.groovy/startup
if [ -r "$GROOVY_STARTUP" ]; then
. "$GROOVY_STARTUP"
fi
earlyInit
# OS specific support (must be 'true' or 'false').
cygwin=false;
darwin=false;
case "`uname`" in
CYGWIN*)
cygwin=true
;;
Darwin*)
darwin=true
;;
esac
# Attempt to set JAVA_HOME if it's not already set
if [ -z "$JAVA_HOME" ]; then
# Set JAVA_HOME for Darwin
if $darwin; then
[ -z "$JAVA_HOME" -a -d "/Library/Java/Home" ] &&
export JAVA_HOME="/Library/Java/Home"
[ -z "$JAVA_HOME" -a -d "/System/Library/Frameworks/JavaVM.framework/Home" ] &&
export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Home"
fi
fi
# For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin ; then
[ -n "$GRAILS_HOME" ] &&
GRAILS_HOME=`cygpath --unix "$GRAILS_HOME"`
[ -n "$JAVACMD" ] &&
JAVACMD=`cygpath --unix "$JAVACMD"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
[ -n "$CP" ] &&
CP=`cygpath --path --unix "$CP"`
fi
# Remove possible trailing slash (after possible cygwin correction)
GRAILS_HOME=`echo $GRAILS_HOME | sed -e 's|/$||g'`
# Locate GRAILS_HOME if not it is not set
if [ -z "$GRAILS_HOME" -o ! -d "$GRAILS_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\"`/.."
GRAILS_HOME="`pwd -P`"
cd "$SAVED"
fi
# Warn the user if JAVA_HOME and/or GRAILS_HOME are not set.
if [ -z "$JAVA_HOME" ] ; then
die "JAVA_HOME environment variable is not set"
elif [ ! -d "$JAVA_HOME" ] ; then
die "JAVA_HOME is not a directory: $JAVA_HOME"
fi
if [ -z "$GRAILS_HOME" ] ; then
warn "GRAILS_HOME environment variable is not set"
fi
if [ ! -d "$GRAILS_HOME" ] ; then
die "GRAILS_HOME is not a directory: $GRAILS_HOME"
fi
# Use default groovy-conf config
if [ -z "$STARTER_CONF" ]; then
STARTER_CONF="$GRAILS_HOME/conf/groovy-starter.conf"
fi
STARTER_CLASSPATH="wrapper/grails-wrapper-runtime-2.1.1.jar:wrapper:."
# Allow access to Cocoa classes on OS X
if $darwin; then
STARTER_CLASSPATH="$STARTER_CLASSPATH:/System/Library/Java/Support"
fi
# 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"
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
# Increase the maximum file descriptors if we can
if [ "$cygwin" = "false" ]; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ "$MAX_FD_LIMIT" != "unlimited" ]; then
if [ $? -eq 0 ]; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ]; then
# use the businessSystem max
MAX_FD="$MAX_FD_LIMIT"
fi
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
fi
# Fix the cygwin agent issue
AGENT_GRAILS_HOME=$GRAILS_HOME
if $cygwin ; then
[ -n "$GRAILS_HOME" ] &&
AGENT_GRAILS_HOME=`cygpath --windows "$GRAILS_HOME"`
fi
if [ -z "$GRAILS_AGENT_CACHE_DIR" ]; then
GRAILS_AGENT_CACHE_DIR=~/.grails/@grails.version@/
fi
SPRINGLOADED_PARAMS="profile=grails;cacheDir=$GRAILS_AGENT_CACHE_DIR"
if [ ! -d "$GRAILS_AGENT_CACHE_DIR" ]; then
mkdir -p $GRAILS_AGENT_CACHE_DIR
fi
# Process JVM args
AGENT_STRING="-javaagent:wrapper/springloaded-core-1.0.6.jar -noverify -Dspringloaded=$SPRINGLOADED_PARAMS"
CMD_LINE_ARGS=""
DISABLE_RELOADING=false
while true; do
if [ "$1" = "-cp" ] || [ "$1" = "-classpath" ]; then
CP=$2
shift 2
break
fi
if [ "$1" = "-reloading" ]; then
AGENT=$AGENT_STRING
shift
break
fi
if [ "$1" = "-noreloading" ]; then
DISABLE_RELOADING=true
shift
break
fi
if [ "$1" = "-debug" ]; then
JAVA_OPTS="$JAVA_OPTS -Xdebug -Xnoagent -Dgrails.full.stacktrace=true -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"
shift
break
fi
if [ "$1" != -* ]; then
break
fi
CMD_LINE_ARGS="$CMD_LINE_ARGS $1"
shift
done
# Enable agent-based reloading for the 'run-app' command.
if ! $DISABLE_RELOADING; then
for a in "$@"; do
if [ "$a" = "run-app" ]; then
AGENT=$AGENT_STRING
fi
done
if [ $# = 0 ]; then
AGENT=$AGENT_STRING
fi
fi
ARGUMENTS="$CMD_LINE_ARGS $@"
# Setup Profiler
useprofiler=false
if [ "x$PROFILER" != "x" ]; 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
JAVA_OPTS="-Xdock:name=Grails -Xdock:icon=$GRAILS_HOME/media/icons/grails.icns $JAVA_OPTS"
# TOOLS_JAR="/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Classes/classes.jar"
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
GRAILS_HOME=`cygpath --path --mixed "$GRAILS_HOME"`
JAVA_HOME=`cygpath --path --mixed "$JAVA_HOME"`
STARTER_CONF=`cygpath --path --mixed "$STARTER_CONF"`
CP=`cygpath --path --mixed "$CP"`
TOOLS_JAR=`cygpath --path --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
ARGUMENTS=""
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
if [ $CHECK -ne 0 ] ; then
convArg=`cygpath --path --ignore --mixed "$arg"`
else
convArg=$arg
fi
ARGUMENTS="$ARGUMENTS $convArg"
done
fi
STARTER_MAIN_CLASS=org.grails.wrapper.GrailsWrapper
lateInit
startGrails() {
CLASS=$1
shift
if [ -n "$GRAILS_OPTS" ]
then
GRAILS_OPTS="$GRAILS_OPTS"
else
GRAILS_OPTS="-server -Xmx768M -Xms768M -XX:PermSize=256m -XX:MaxPermSize=256m -Dfile.encoding=UTF-8"
fi
JAVA_OPTS="$GRAILS_OPTS $JAVA_OPTS $AGENT"
# Start the Profiler or the JVM
if $useprofiler; then
runProfiler
else
if [ $# -eq 0 ] ; then # no argument given
exec "$JAVACMD" $JAVA_OPTS \
-classpath "$STARTER_CLASSPATH" \
-Dgrails.home="$GRAILS_HOME" \
-Dtools.jar="$TOOLS_JAR" \
$STARTER_MAIN_CLASS \
--main $CLASS \
--conf "$STARTER_CONF" \
--classpath "$CP"
else
exec "$JAVACMD" $JAVA_OPTS \
-classpath "$STARTER_CLASSPATH" \
-Dgrails.home="$GRAILS_HOME" \
-Dtools.jar="$TOOLS_JAR" \
$STARTER_MAIN_CLASS \
--main $CLASS \
--conf "$STARTER_CONF" \
--classpath "$CP" \
"${ARGUMENTS}"
fi
fi
}
startGrails $STARTER_MAIN_CLASS "$@"