1 @if "%DEBUG%" == "" @echo off
2 @rem ##########################################################################
4 @rem Groovy JVM Bootstrap for Windowz ##
6 @rem ##########################################################################
12 @rem Set local scope for the variables with windows NT shell
13 if "%OS%"=="Windows_NT" setlocal
21 if exist "%USERPROFILE%/.groovy/preinit.bat" call "%USERPROFILE%/.groovy/preinit.bat"
23 @rem Determine the command interpreter to execute the "CD" later
24 set COMMAND_COM="cmd.exe"
25 if exist "%SystemRoot%\system32\cmd.exe" set COMMAND_COM="%SystemRoot%\system32\cmd.exe"
26 if exist "%SystemRoot%\command.com" set COMMAND_COM="%SystemRoot%\command.com"
28 @rem Use explicit find.exe to prevent cygwin and others find.exe from being used
29 set FIND_EXE="find.exe"
30 if exist "%SystemRoot%\system32\find.exe" set FIND_EXE="%SystemRoot%\system32\find.exe"
31 if exist "%SystemRoot%\command\find.exe" set FIND_EXE="%SystemRoot%\command\find.exe"
34 @rem Make sure we have a valid JAVA_HOME
35 if not "%JAVA_HOME%" == "" goto have_JAVA_HOME
36 for %%P in (%PATH%) do if exist %%P\..\bin\java.exe set JAVA_HOME=%%P\..
37 if not "%JAVA_HOME%" == "" goto valid_JAVA_HOME
39 if not ERRORLEVEL 1 goto default_JAVA_EXE
42 echo ERROR: Environment variable JAVA_HOME has not been set.
43 echo Attempting to find JAVA_HOME from PATH also failed.
47 @rem Remove trailing slash from JAVA_HOME if found
48 if "%JAVA_HOME:~-1%"=="\" SET JAVA_HOME=%JAVA_HOME:~0,-1%
50 @rem Validate JAVA_HOME
51 %COMMAND_COM% /C DIR "%JAVA_HOME%" 2>&1 | %FIND_EXE% /I /C "%JAVA_HOME%" >nul
52 if not errorlevel 1 goto valid_JAVA_HOME_DIR
55 echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
58 echo Please set the JAVA_HOME variable in your environment
59 echo to match the location of your Java installation.
64 goto check_GROOVY_HOME
67 set JAVA_EXE=%JAVA_HOME%\bin\java.exe
68 if exist "%JAVA_EXE%" goto valid_JAVA_HOME
71 echo ERROR: No java.exe found at: %JAVA_EXE%
75 if exist "%JAVA_HOME%\lib\tools.jar" set TOOLS_JAR=%JAVA_HOME%\lib\tools.jar
78 @rem Define GROOVY_HOME if not set
79 if "%GROOVY_HOME%" == "" set GROOVY_HOME=%DIRNAME%..
81 @rem Remove trailing slash from GROOVY_HOME if found
82 if "%GROOVY_HOME:~-1%"=="\" SET GROOVY_HOME=%GROOVY_HOME:~0,-1%
84 @rem classpath handling
87 if "x%~1" == "x-cp" set CP=%~2
88 if "x%~1" == "x-classpath" set CP=%~2
89 if "x%~1" == "x--classpath" set CP=%~2
90 if "x" == "x%CP%" goto init
96 @rem get name of script to launch with full path
97 set GROOVY_SCRIPT_NAME=%~f1
98 @rem Get command-line arguments, handling Windowz variants
99 if not "%OS%" == "Windows_NT" goto win9xME_args
100 if "%eval[2+2]" == "4" goto 4NT_args
103 @rem Slurp the command line arguments.
107 if "x%~1" == "x" goto execute
109 rem horrible roll your own arg processing inspired by jruby equivalent
111 rem escape minus (-d), quotes (-q), star (-s).
113 if not defined _ARGS goto execute
114 set _ARGS=%_ARGS:-=-d%
115 set _ARGS=%_ARGS:"=-q%
116 rem Windowz will try to match * with files so we escape it here
117 rem but it is also a meta char for env var string substitution
118 rem so it can't be first char here, hack just for common cases.
119 rem If in doubt use a space or bracket before * if using -e.
120 set _ARGS=%_ARGS: *= -s%
121 set _ARGS=%_ARGS:)*=)-s%
122 set _ARGS=%_ARGS:0*=0-s%
123 set _ARGS=%_ARGS:1*=1-s%
124 set _ARGS=%_ARGS:2*=2-s%
125 set _ARGS=%_ARGS:3*=3-s%
126 set _ARGS=%_ARGS:4*=4-s%
127 set _ARGS=%_ARGS:5*=5-s%
128 set _ARGS=%_ARGS:6*=6-s%
129 set _ARGS=%_ARGS:7*=7-s%
130 set _ARGS=%_ARGS:8*=8-s%
131 set _ARGS=%_ARGS:9*=9-s%
132 rem prequote all args for 'for' statement
136 rem split args by spaces into first and rest
137 for /f "tokens=1,*" %%i in (%_ARGS%) do call :get_arg "%%i" "%%j"
141 rem remove quotes around first arg
142 for %%i in (%1) do set _ARG=%%~i
143 rem set the remaining args
149 if "%_ARG%" == "" goto execute
151 if "x4" == "x%_SKIP%" goto skip_4
152 if "x3" == "x%_SKIP%" goto skip_3
153 if "x2" == "x%_SKIP%" goto skip_2
154 if "x1" == "x%_SKIP%" goto skip_1
156 rem now unescape -q, -s, -d
161 set CMD_LINE_ARGS=%CMD_LINE_ARGS% %_ARG%
163 goto win9xME_args_loop
168 goto win9xME_args_loop
173 goto win9xME_args_loop
178 goto win9xME_args_loop
183 goto win9xME_args_loop
186 @rem Get arguments from the 4NT Shell from JP Software
190 @rem Setup the command line
191 set STARTER_CLASSPATH=%GROOVY_HOME%\lib\@GROOVYJAR@
193 if exist "%USERPROFILE%/.groovy/init.bat" call "%USERPROFILE%/.groovy/init.bat"
195 @rem Setting a classpath using the -cp or -classpath option means not to use
196 @rem the global classpath. Groovy behaves then the same as the java
198 if "x" == "x%CP%" goto empty_cp
204 if "x" == "x%CLASSPATH%" goto after_cp
205 set CP=%CLASSPATH%;%CP%
208 set STARTER_MAIN_CLASS=org.codehaus.groovy.tools.GroovyStarter
209 set STARTER_CONF=%GROOVY_HOME%\conf\groovy-starter.conf
211 if "%JAVA_OPTS%" == "" set JAVA_OPTS="-Xmx128m"
212 set JAVA_OPTS=%JAVA_OPTS% -Dprogram.name="%PROGNAME%"
213 set JAVA_OPTS=%JAVA_OPTS% -Dgroovy.home="%GROOVY_HOME%"
214 if not "%TOOLS_JAR%" == "" set JAVA_OPTS=%JAVA_OPTS% -Dtools.jar="%TOOLS_JAR%"
215 set JAVA_OPTS=%JAVA_OPTS% -Dgroovy.starter.conf="%STARTER_CONF%"
216 set JAVA_OPTS=%JAVA_OPTS% -Dscript.name="%GROOVY_SCRIPT_NAME%"
218 if exist "%USERPROFILE%/.groovy/postinit.bat" call "%USERPROFILE%/.groovy/postinit.bat"
221 "%JAVA_EXE%" %JAVA_OPTS% -classpath "%STARTER_CLASSPATH%" %STARTER_MAIN_CLASS% --main %CLASS% --conf "%STARTER_CONF%" --classpath "%CP%" %CMD_LINE_ARGS%
224 @rem End local scope for the variables with windows NT shell
225 if "%OS%"=="Windows_NT" endlocal
227 @rem Optional pause the batch file
228 if "%GROOVY_BATCH_PAUSE%" == "on" pause