Debian Codegraph @

src/bin/startGroovy

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 # -*- mode:sh -*-
2 # ----------------------------------------------------------------------------
3 # Licensed to the Apache Software Foundation (ASF) under one
4 # or more contributor license agreements. See the NOTICE file
5 # distributed with this work for additional information
6 # regarding copyright ownership. The ASF licenses this file
7 # to you under the Apache License, Version 2.0 (the
8 # "License"); you may not use this file except in compliance
9 # with the License. You may obtain a copy of the License at
10 #
11 # http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing,
14 # software distributed under the License is distributed on an
15 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 # KIND, either express or implied. See the License for the
17 # specific language governing permissions and limitations
18 # under the License.
19 # ----------------------------------------------------------------------------
20
21 ##############################################################################
22 ## ##
23 ## Groovy JVM Bootstrap for UN*X ##
24 ## ##
25 ##############################################################################
26
27 ##
28 ## $Revision$
29 ## $Date$
30 ##
31
32 PROGNAME=`basename "$0"`
33
34 #DIRNAME=`dirname "$0"`
35
36 SCRIPT_PATH="$0"
37
38 # Use the maximum available, or set MAX_FD != -1 to use that value.
39 MAX_FD="maximum"
40
41 warn ( ) {
42 echo "${PROGNAME}: $*"
43 }
44
45 die ( ) {
46 warn "$*"
47 exit 1
48 }
49
50 earlyInit ( ) {
51 return
52 }
53
54 lateInit ( ) {
55 return
56 }
57
58 GROOVY_STARTUP="$HOME/.groovy/startup"
59 if [ -r "$GROOVY_STARTUP" ] ; then
60 . "$GROOVY_STARTUP"
61 fi
62
63 earlyInit
64
65 # OS specific support (must be 'true' or 'false').
66 cygwin=false
67 msys=false
68 darwin=false
69 nonstop=false
70 case "`uname`" in
71 CYGWIN* )
72 cygwin=true
73 ;;
74 Darwin* )
75 darwin=true
76 ;;
77 MINGW* )
78 msys=true
79 ;;
80 NONSTOP* )
81 nonstop=true
82 ;;
83 esac
84
85 if [ "$1" = "-cp" -o "$1" = "-classpath" -o "$1" = "--classpath" ] ; then
86 CP=$2
87 shift 2
88 fi
89
90 # Attempt to set JAVA_HOME if it's not already set.
91 if [ -z "$JAVA_HOME" ] ; then
92 if $darwin ; then
93 [ -z "$JAVA_HOME" -a -f "/usr/libexec/java_home" ] && export JAVA_HOME=`/usr/libexec/java_home`
94 [ -z "$JAVA_HOME" -a -d "/Library/Java/Home" ] && export JAVA_HOME="/Library/Java/Home"
95 [ -z "$JAVA_HOME" -a -d "/System/Library/Frameworks/JavaVM.framework/Home" ] && export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Home"
96 else
97 javaExecutable="`which javac`"
98 [ -z "$javaExecutable" -o "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ] && die "JAVA_HOME not set and cannot find javac to deduce location, please set JAVA_HOME."
99 # readlink(1) is not available as standard on Solaris 10.
100 readLink=`which readlink`
101 [ `expr "$readLink" : '\([^ ]*\)'` = "no" ] && die "JAVA_HOME not set and readlink not available, please set JAVA_HOME."
102 javaExecutable="`readlink -f \"$javaExecutable\"`"
103 javaHome="`dirname \"$javaExecutable\"`"
104 javaHome=`expr "$javaHome" : '\(.*\)/bin'`
105 JAVA_HOME="$javaHome"
106 export JAVA_HOME
107
108 fi
109 fi
110
111 # For Cygwin, ensure paths are in UNIX format before anything is touched.
112 if $cygwin ; then
113 [ -n "$GROOVY_HOME" ] && GROOVY_HOME=`cygpath --unix "$GROOVY_HOME"`
114 [ -n "$JAVACMD" ] && JAVACMD=`cygpath --unix "$JAVACMD"`
115 [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
116 [ -n "$CP" ] && CP=`cygpath --path --unix "$CP"`
117 else
118 if [ -n "$GROOVY_HOME" -a "`expr "$GROOVY_HOME":'\/$'`" ] ; then
119 GROOVY_HOME=`echo $GROOVY_HOME | sed -e 's/\/$//'`
120 fi
121 fi
122
123 # For MSYS, ensure paths are in appropriate format.
124 if $msys
125 then
126 [ -n "$JAVA_HOME" ] && JAVA_HOME=`( cd "$JAVA_HOME" ; pwd )`
127 fi
128
129 # Attempt to set GROOVY_HOME if it is not already set.
130 if [ -z "$GROOVY_HOME" -o ! -d "$GROOVY_HOME" ] ; then
131 # Resolve links: $0 may be a link to groovy's home.
132 PRG="$0"
133 # Need this for relative symlinks.
134 while [ -h "$PRG" ] ; do
135 ls=`ls -ld "$PRG"`
136 link=`expr "$ls" : '.*-> \(.*\)$'`
137 if expr "$link" : '/.*' > /dev/null; then
138 PRG="$link"
139 else
140 PRG=`dirname "$PRG"`"/$link"
141 fi
142 done
143 SAVED="`pwd`"
144 cd "`dirname \"$PRG\"`/.."
145 GROOVY_HOME="`pwd -P`"
146 cd "$SAVED"
147 fi
148
149 # Set the default Groovy config if no specific one is mentioned.
150 if [ -z "$GROOVY_CONF" ] ; then
151 GROOVY_CONF="$GROOVY_HOME/conf/groovy-starter.conf"
152 fi
153 STARTER_CLASSPATH="$GROOVY_HOME/lib/@GROOVYJAR@"
154
155 # Create the final classpath. Setting a classpath using the -cp or -classpath option means not to use the
156 # global classpath. Groovy behaves then the same as the java interpreter
157 if [ -n "$CP" ] ; then
158 CP="$CP":.
159 elif [ -n "$CLASSPATH" ] ; then
160 CP="$CLASSPATH":.
161 else
162 CP=.
163 fi
164
165 # Determine the Java command to use to start the JVM.
166 if [ -z "$JAVACMD" ] ; then
167 if [ -n "$JAVA_HOME" ] ; then
168 if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
169 # IBM's JDK on AIX uses strange locations for the executables
170 JAVACMD="$JAVA_HOME/jre/sh/java"
171 else
172 JAVACMD="$JAVA_HOME/bin/java"
173 fi
174 else
175 JAVACMD="java"
176 fi
177 fi
178 if [ ! -x "$JAVACMD" ] ; then
179 die "JAVA_HOME is not defined correctly, can not execute: $JAVACMD"
180 fi
181 if [ -z "$JAVA_HOME" ] ; then
182 warn "JAVA_HOME environment variable is not set"
183 fi
184
185 # Increase the maximum file descriptors if we can.
186 if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
187 MAX_FD_LIMIT=`ulimit -H -n`
188 if [ $? -eq 0 ] ; then
189 if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
190 MAX_FD="$MAX_FD_LIMIT"
191 fi
192 ulimit -n $MAX_FD
193 if [ $? -ne 0 ] ; then
194 warn "Could not set maximum file descriptor limit: $MAX_FD"
195 fi
196 else
197 warn "Could not query businessSystem maximum file descriptor limit: $MAX_FD_LIMIT"
198 fi
199 fi
200
201 # Setup Profiler
202 useprofiler=false
203 if [ "$PROFILER" != "" ] ; then
204 if [ -r "$PROFILER" ] ; then
205 . $PROFILER
206 useprofiler=true
207 else
208 die "Profiler file not found: $PROFILER"
209 fi
210 fi
211
212 # For Darwin, use classes.jar for TOOLS_JAR
213 TOOLS_JAR="$JAVA_HOME/lib/tools.jar"
214 #if $darwin; then
215 # TOOLS_JAR="/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Classes/classes.jar"
216 #fi
217
218 # For Darwin, add GROOVY_APP_NAME to the JAVA_OPTS as -Xdock:name
219 if $darwin; then
220 JAVA_OPTS="$JAVA_OPTS -Xdock:name=$GROOVY_APP_NAME -Xdock:icon=$GROOVY_HOME/lib/groovy.icns"
221 fi
222
223 # For Cygwin, switch paths to Windows format before running java
224 if $cygwin ; then
225 GROOVY_HOME=`cygpath --mixed "$GROOVY_HOME"`
226 JAVA_HOME=`cygpath --mixed "$JAVA_HOME"`
227 GROOVY_CONF=`cygpath --mixed "$GROOVY_CONF"`
228 CP=`cygpath --path --mixed "$CP"`
229 TOOLS_JAR=`cygpath --mixed "$TOOLS_JAR"`
230 STARTER_CLASSPATH=`cygpath --path --mixed "$STARTER_CLASSPATH"`
231
232 # We build the pattern for arguments to be converted via cygpath
233 ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
234 SEP=""
235 for dir in $ROOTDIRSRAW ; do
236 ROOTDIRS="$ROOTDIRS$SEP$dir"
237 SEP="|"
238 done
239 OURCYGPATTERN="(^($ROOTDIRS))"
240 # Add a user-defined pattern to the cygpath arguments
241 if [ "$GROOVY_CYGPATTERN" != "" ] ; then
242 OURCYGPATTERN="$OURCYGPATTERN|($GROOVY_CYGPATTERN)"
243 fi
244 # Now convert the arguments - kludge to limit ourselves to /bin/sh
245 i=0
246 for arg in "$@" ; do
247 CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
248 if [ $CHECK -ne 0 ] ; then
249 patched=`cygpath --path --ignore --mixed "$arg"`
250 else
251 patched="$arg"
252 fi
253 if [ x"$BASH" = x ]; then
254 eval `echo args$i`="\"$arg\""
255 else
256 args[$i]="$patched"
257 fi
258 i=`expr $i + 1`
259 done
260
261 if [ x"$BASH" = x ]; then
262 case $i in
263 0) set -- ;;
264 1) set -- "$args0" ;;
265 2) set -- "$args0" "$args1" ;;
266 3) set -- "$args0" "$args1" "$args2" ;;
267 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
268 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
269 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
270 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
271 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
272 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
273 esac
274 else
275 set -- "${args[@]}"
276 fi
277 fi
278
279 startGroovy ( ) {
280 CLASS=$1
281 shift
282 # Start the Profiler or the JVM
283 if $useprofiler ; then
284 runProfiler
285 else
286 eval exec "\"\$JAVACMD\"" $JAVA_OPTS \
287 -classpath "\"\$STARTER_CLASSPATH\"" \
288 -Dscript.name="\"\$SCRIPT_PATH\"" \
289 -Dprogram.name="\"\$PROGNAME\"" \
290 -Dgroovy.starter.conf="\"\$GROOVY_CONF\"" \
291 -Dgroovy.home="\"\$GROOVY_HOME\"" \
292 -Dtools.jar="\"\$TOOLS_JAR\"" \
293 $STARTER_MAIN_CLASS \
294 --main $CLASS \
295 --conf "\"\$GROOVY_CONF\"" \
296 --classpath "\"\$CP\"" \
297 "\"\$@\""
298 fi
299 }
300
301 STARTER_MAIN_CLASS=org.codehaus.groovy.tools.GroovyStarter
302
303 lateInit