1 @if "%DEBUG%" == "" @echo off
3 @rem ##########################################################################
7 @rem Groovy JVM Bootstrap for Windowz ##
11 @rem ##########################################################################
17 @rem $Revision$ $Date$
23 @rem Set local scope for the variables with windows NT shell
25 if "%OS%"=="Windows_NT" setlocal
41 if exist "%USERPROFILE%\.groovy\preinit.bat" call "%USERPROFILE%\.groovy\preinit.bat"
45 @rem Determine the command interpreter to execute the "CD" later
47 set COMMAND_COM="cmd.exe"
49 if exist "%SystemRoot%\system32\cmd.exe" set COMMAND_COM="%SystemRoot%\system32\cmd.exe"
51 if exist "%SystemRoot%\command.com" set COMMAND_COM="%SystemRoot%\command.com"
55 @rem Use explicit find.exe to prevent cygwin and others find.exe from being used
57 set FIND_EXE="find.exe"
59 if exist "%SystemRoot%\system32\find.exe" set FIND_EXE="%SystemRoot%\system32\find.exe"
61 if exist "%SystemRoot%\command\find.exe" set FIND_EXE="%SystemRoot%\command\find.exe"
67 @rem Make sure we have a valid JAVA_HOME
69 if not "%JAVA_HOME%" == "" goto have_JAVA_HOME
71 for %%P in (%PATH%) do if exist %%P\..\bin\java.exe set JAVA_HOME=%%P\..
73 if not "%JAVA_HOME%" == "" goto valid_JAVA_HOME
77 if not ERRORLEVEL 1 goto default_JAVA_EXE
83 echo ERROR: Environment variable JAVA_HOME has not been set.
85 echo Attempting to find JAVA_HOME from PATH also failed.
93 @rem Remove trailing slash from JAVA_HOME if found
95 if "%JAVA_HOME:~-1%"=="\" SET JAVA_HOME=%JAVA_HOME:~0,-1%
99 @rem Validate JAVA_HOME
101 %COMMAND_COM% /C DIR "%JAVA_HOME%" 2>&1 | %FIND_EXE% /I /C "%JAVA_HOME%" >nul
103 if not errorlevel 1 goto valid_JAVA_HOME_DIR
109 echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
115 echo Please set the JAVA_HOME variable in your environment
117 echo to match the location of your Java installation.
125 set JAVA_EXE=java.exe
127 goto check_GROOVY_HOME
133 set JAVA_EXE=%JAVA_HOME%\bin\java.exe
135 if exist "%JAVA_EXE%" goto valid_JAVA_HOME
141 echo ERROR: No java.exe found at: %JAVA_EXE%
149 if exist "%JAVA_HOME%\lib\tools.jar" set TOOLS_JAR=%JAVA_HOME%\lib\tools.jar
155 @rem Define GROOVY_HOME if not set
157 if "%GROOVY_HOME%" == "" set GROOVY_HOME=%DIRNAME%..
161 @rem Remove trailing slash from GROOVY_HOME if found
163 if "%GROOVY_HOME:~-1%"=="\" SET GROOVY_HOME=%GROOVY_HOME:~0,-1%
167 @rem classpath handling
173 if "x%~1" == "x-cp" set CP=%~2
175 if "x%~1" == "x-classpath" set CP=%~2
177 if "x%~1" == "x--classpath" set CP=%~2
179 if "x" == "x%CP%" goto init
191 @rem get name of script to launch with full path
193 set GROOVY_SCRIPT_NAME=%~f1
195 @rem Get command-line arguments, handling Windowz variants
197 if not "%OS%" == "Windows_NT" goto win9xME_args
199 if "%eval[2+2]" == "4" goto 4NT_args
205 @rem Slurp the command line arguments.
213 if "x%~1" == "x" goto execute
217 rem horrible roll your own arg processing inspired by jruby equivalent
221 rem escape minus (-d), quotes (-q), star (-s).
225 if not defined _ARGS goto execute
227 set _ARGS=%_ARGS:-=-d%
229 set _ARGS=%_ARGS:"=-q%
231 rem Windowz will try to match * with files so we escape it here
233 rem but it is also a meta char for env var string substitution
235 rem so it can't be first char here, hack just for common cases.
237 rem If in doubt use a space or bracket before * if using -e.
239 set _ARGS=%_ARGS: *= -s%
241 set _ARGS=%_ARGS:)*=)-s%
243 set _ARGS=%_ARGS:0*=0-s%
245 set _ARGS=%_ARGS:1*=1-s%
247 set _ARGS=%_ARGS:2*=2-s%
249 set _ARGS=%_ARGS:3*=3-s%
251 set _ARGS=%_ARGS:4*=4-s%
253 set _ARGS=%_ARGS:5*=5-s%
255 set _ARGS=%_ARGS:6*=6-s%
257 set _ARGS=%_ARGS:7*=7-s%
259 set _ARGS=%_ARGS:8*=8-s%
261 set _ARGS=%_ARGS:9*=9-s%
263 rem prequote all args for 'for' statement
271 rem split args by spaces into first and rest
273 for /f "tokens=1,*" %%i in (%_ARGS%) do call :get_arg "%%i" "%%j"
281 rem remove quotes around first arg
283 for %%i in (%1) do set _ARG=%%~i
285 rem set the remaining args
297 if "%_ARG%" == "" goto execute
301 if "x4" == "x%_SKIP%" goto skip_4
303 if "x3" == "x%_SKIP%" goto skip_3
305 if "x2" == "x%_SKIP%" goto skip_2
307 if "x1" == "x%_SKIP%" goto skip_1
311 rem now unescape -q, -s, -d
321 set CMD_LINE_ARGS=%CMD_LINE_ARGS% %_ARG%
325 goto win9xME_args_loop
335 goto win9xME_args_loop
345 goto win9xME_args_loop
355 goto win9xME_args_loop
365 goto win9xME_args_loop
371 @rem Get arguments from the 4NT Shell from JP Software
379 @rem Setup the command line
381 set STARTER_CLASSPATH=%GROOVY_HOME%\lib\groovy-all-1.6.4.jar;%STARTER_CLASSPATH%
385 if exist "%USERPROFILE%\.groovy\init.bat" call "%USERPROFILE%\.groovy\init.bat"
389 @rem Setting a classpath using the -cp or -classpath option means not to use
391 @rem the global classpath. Groovy behaves then the same as the java
395 if "x" == "x%CP%" goto empty_cp
407 if "x" == "x%CLASSPATH%" goto after_cp
409 set CP=%CLASSPATH%;%CP%
415 set STARTER_MAIN_CLASS=org.codehaus.groovy.tools.GroovyStarter
417 if "%STARTER_CONF%" == "" set STARTER_CONF=%GROOVY_HOME%\conf\groovy-starter.conf
421 if "%JAVA_OPTS%" == "" set JAVA_OPTS="-Xmx512m"
423 set JAVA_OPTS=%JAVA_OPTS% -Dprogram.name="%PROGNAME%"
425 set JAVA_OPTS=%JAVA_OPTS% -Dgroovy.home="%GROOVY_HOME%"
427 if not "%TOOLS_JAR%" == "" set JAVA_OPTS=%JAVA_OPTS% -Dtools.jar="%TOOLS_JAR%"
429 set JAVA_OPTS=%JAVA_OPTS% -Dgroovy.starter.conf="%STARTER_CONF%"
431 set JAVA_OPTS=%JAVA_OPTS% -Dscript.name="%GROOVY_SCRIPT_NAME%"
435 if exist "%USERPROFILE%\.groovy\postinit.bat" call "%USERPROFILE%\.groovy\postinit.bat"
441 "%JAVA_EXE%" %JAVA_OPTS% -classpath "%STARTER_CLASSPATH%" %STARTER_MAIN_CLASS% --main %CLASS% --conf "%STARTER_CONF%" --classpath "%CP%" %CMD_LINE_ARGS%
447 @rem End local scope for the variables with windows NT shell
449 if "%OS%"=="Windows_NT" endlocal
453 @rem Optional pause the batch file
455 if "%GROOVY_BATCH_PAUSE%" == "on" pause