3 ##############################################################################
5 ## Groovy JVM Bootstrap for UN*X ##
7 ##############################################################################
14 PROGNAME=`basename "$0"`
16 #DIRNAME=`dirname "$0"`
20 # Use the maximum available, or set MAX_FD != -1 to use that value.
24 echo "${PROGNAME}: $*"
40 GROOVY_STARTUP="$HOME/.groovy/startup"
41 if [ -r "$GROOVY_STARTUP" ] ; then
47 # OS specific support (must be 'true' or 'false').
63 if [ "$1" = "-cp" -o "$1" = "-classpath" ] ; then
68 # Attempt to set JAVA_HOME if it's not already set.
69 if [ -z "$JAVA_HOME" ] ; then
71 [ -z "$JAVA_HOME" -a -d "/Library/Java/Home" ] && export JAVA_HOME="/Library/Java/Home"
72 [ -z "$JAVA_HOME" -a -d "/System/Library/Frameworks/JavaVM.framework/Home" ] && export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Home"
74 javaExecutable="`which javac`"
75 [ -z "$javaExecutable" -o "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ] && die "JAVA_HOME not set and cannot find javac to deduce location, please set JAVA_HOME."
76 # readlink(1) is not available as standard on Solaris 10.
77 readLink=`which readlink`
78 [ `expr "$readLink" : '\([^ ]*\)'` = "no" ] && die "JAVA_HOME not set and readlink not available, please set JAVA_HOME."
79 javaExecutable="`readlink -f \"$javaExecutable\"`"
80 javaHome="`dirname \"$javaExecutable\"`"
81 javaHome=`expr "$javaHome" : '\(.*\)/bin'`
88 # For Cygwin, ensure paths are in UNIX format before anything is touched.
90 [ -n "$GROOVY_HOME" ] && GROOVY_HOME=`cygpath --unix "$GROOVY_HOME"`
91 [ -n "$JAVACMD" ] && JAVACMD=`cygpath --unix "$JAVACMD"`
92 [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
93 [ -n "$CP" ] && CP=`cygpath --path --unix "$CP"`
95 if [ -n "$GROOVY_HOME" -a `expr "$GROOVY_HOME":'\/$'` ] ; then
96 GROOVY_HOME=`echo $GROOVY_HOME | sed -e 's/\/$//'`
100 # Attempt to set GROOVY_HOME if it is not already set.
101 if [ -z "$GROOVY_HOME" -o ! -d "$GROOVY_HOME" ] ; then
102 # Resolve links: $0 may be a link to groovy's home.
104 # Need this for relative symlinks.
105 while [ -h "$PRG" ] ; do
107 link=`expr "$ls" : '.*-> \(.*\)$'`
108 if expr "$link" : '/.*' > /dev/null; then
111 PRG=`dirname "$PRG"`"/$link"
115 cd "`dirname \"$PRG\"`/.."
116 GROOVY_HOME="`pwd -P`"
120 # Set the default Groovy config if no specific one is mentioned.
121 if [ -z "$GROOVY_CONF" ] ; then
122 GROOVY_CONF="$GROOVY_HOME/conf/groovy-starter.conf"
124 STARTER_CLASSPATH="$GROOVY_HOME/lib/@GROOVYJAR@"
126 # Create the final classpath. Setting a classpath using the -cp or -classpath option means not to use the
127 # global classpath. Groovy behaves then the same as the java interpreter
128 if [ -n "$CP" ] ; then
130 elif [ -n "$CLASSPATH" ] ; then
136 # Determine the Java command to use to start the JVM.
137 if [ -z "$JAVACMD" ] ; then
138 if [ -n "$JAVA_HOME" ] ; then
139 if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
140 # IBM's JDK on AIX uses strange locations for the executables
141 JAVACMD="$JAVA_HOME/jre/sh/java"
143 JAVACMD="$JAVA_HOME/bin/java"
149 if [ ! -x "$JAVACMD" ] ; then
150 die "JAVA_HOME is not defined correctly, can not execute: $JAVACMD"
152 if [ -z "$JAVA_HOME" ] ; then
153 warn "JAVA_HOME environment variable is not set"
156 # Increase the maximum file descriptors if we can.
157 if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
158 MAX_FD_LIMIT=`ulimit -H -n`
159 if [ $? -eq 0 ] ; then
160 if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
161 MAX_FD="$MAX_FD_LIMIT"
164 if [ $? -ne 0 ] ; then
165 warn "Could not set maximum file descriptor limit: $MAX_FD"
168 warn "Could not query businessSystem maximum file descriptor limit: $MAX_FD_LIMIT"
174 if [ "$PROFILER" != "" ] ; then
175 if [ -r "$PROFILER" ] ; then
179 die "Profiler file not found: $PROFILER"
183 # For Darwin, use classes.jar for TOOLS_JAR
184 TOOLS_JAR="$JAVA_HOME/lib/tools.jar"
186 # TOOLS_JAR="/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Classes/classes.jar"
189 # For Darwin, add GROOVY_APP_NAME to the JAVA_OPTS as -Xdock:name
191 JAVA_OPTS="$JAVA_OPTS -Xdock:name=$GROOVY_APP_NAME"
192 # we may also want to set -Xdock:image
195 # For Cygwin, switch paths to Windows format before running java
197 GROOVY_HOME=`cygpath --path --mixed "$GROOVY_HOME"`
198 JAVA_HOME=`cygpath --path --mixed "$JAVA_HOME"`
199 GROOVY_CONF=`cygpath --path --mixed "$GROOVY_CONF"`
200 CP=`cygpath --path --mixed "$CP"`
201 TOOLS_JAR=`cygpath --path --mixed "$TOOLS_JAR"`
202 STARTER_CLASSPATH=`cygpath --path --mixed "$STARTER_CLASSPATH"`
204 # We build the pattern for arguments to be converted via cygpath
205 ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
207 for dir in $ROOTDIRSRAW ; do
208 ROOTDIRS="$ROOTDIRS$SEP$dir"
211 OURCYGPATTERN="(^($ROOTDIRS))"
212 # Add a user-defined pattern to the cygpath arguments
213 if [ "$GROOVY_CYGPATTERN" != "" ] ; then
214 OURCYGPATTERN="$OURCYGPATTERN|($GROOVY_CYGPATTERN)"
216 # Now convert the arguments - kludge to limit ourselves to /bin/sh
219 CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
220 if [ $CHECK -ne 0 ] ; then
221 eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
223 eval `echo args$i`="\"$arg\""
229 1) set -- "$args0" ;;
230 2) set -- "$args0" "$args1" ;;
231 3) set -- "$args0" "$args1" "$args2" ;;
232 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
233 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
234 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
235 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
236 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
237 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
245 # Start the Profiler or the JVM
246 if $useprofiler ; then
249 exec "$JAVACMD" $JAVA_OPTS \
250 -classpath "$STARTER_CLASSPATH" \
251 -Dscript.name="$SCRIPT_PATH" \
252 -Dprogram.name="$PROGNAME" \
253 -Dgroovy.starter.conf="$GROOVY_CONF" \
254 -Dgroovy.home="$GROOVY_HOME" \
255 -Dtools.jar="$TOOLS_JAR" \
256 $STARTER_MAIN_CLASS \
258 --conf "$GROOVY_CONF" \
264 STARTER_MAIN_CLASS=org.codehaus.groovy.tools.GroovyStarter