assertion
[fedora-idea.git] / build / lib / gant / bin / startGroovy.bat
blob18f64becf31e21d7aa7f415e9308e5201f20d4d0
1 @if "%DEBUG%" == "" @echo off
3 @rem ##########################################################################
5 @rem                                                                         ##
7 @rem  Groovy JVM Bootstrap for Windowz                                       ##
9 @rem                                                                         ##
11 @rem ##########################################################################
15 @rem
17 @rem $Revision$ $Date$
19 @rem
23 @rem Set local scope for the variables with windows NT shell
25 if "%OS%"=="Windows_NT" setlocal
29 set DIRNAME=%~1
31 shift
35 set CLASS=%~1
37 shift
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"
65 :check_JAVA_HOME
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
75 java -version 2>NUL
77 if not ERRORLEVEL 1 goto default_JAVA_EXE
81 echo.
83 echo ERROR: Environment variable JAVA_HOME has not been set.
85 echo Attempting to find JAVA_HOME from PATH also failed.
87 goto common_error
91 :have_JAVA_HOME
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
107 echo.
109 echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
113 :common_error
115 echo Please set the JAVA_HOME variable in your environment
117 echo to match the location of your Java installation.
119 goto end
123 :default_JAVA_EXE
125 set JAVA_EXE=java.exe
127 goto check_GROOVY_HOME
131 :valid_JAVA_HOME_DIR
133 set JAVA_EXE=%JAVA_HOME%\bin\java.exe
135 if exist "%JAVA_EXE%" goto valid_JAVA_HOME
139 echo.
141 echo ERROR: No java.exe found at: %JAVA_EXE%
143 goto common_error
147 :valid_JAVA_HOME
149 if exist "%JAVA_HOME%\lib\tools.jar" set TOOLS_JAR=%JAVA_HOME%\lib\tools.jar
153 :check_GROOVY_HOME
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
169 set _SKIP=2
171 set CP=
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
181 set _SKIP=4
183 shift
185 shift
189 :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
203 :win9xME_args
205 @rem Slurp the command line arguments.
207 set CMD_LINE_ARGS=
211 :win9xME_args_slurp
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).
223 set _ARGS=%*
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
265 set _ARGS="%_ARGS%"
269 :win9xME_args_loop
271 rem split args by spaces into first and rest
273 for /f "tokens=1,*" %%i in (%_ARGS%) do call :get_arg "%%i" "%%j"
275 goto process_arg
279 :get_arg
281 rem remove quotes around first arg
283 for %%i in (%1) do set _ARG=%%~i
285 rem set the remaining args
287 set _ARGS=%2
289 rem return
291 goto :EOF
295 :process_arg
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
313 set _ARG=%_ARG:-q="%
315 set _ARG=%_ARG:-s=*%
317 set _ARG=%_ARG:-d=-%
321 set CMD_LINE_ARGS=%CMD_LINE_ARGS% %_ARG%
323 set _ARG=
325 goto win9xME_args_loop
329 :skip_4
331 set _ARG=
333 set _SKIP=3
335 goto win9xME_args_loop
339 :skip_3
341 set _ARG=
343 set _SKIP=2
345 goto win9xME_args_loop
349 :skip_2
351 set _ARG=
353 set _SKIP=1
355 goto win9xME_args_loop
359 :skip_1
361 set _ARG=
363 set _SKIP=0
365 goto win9xME_args_loop
369 :4NT_args
371 @rem Get arguments from the 4NT Shell from JP Software
373 set CMD_LINE_ARGS=%$
377 :execute
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
393 @rem interpreter
395 if "x" == "x%CP%" goto empty_cp
397 :non_empty_cp
399 set CP=%CP%;.
401 goto after_cp
403 :empty_cp
405 set CP=.
407 if "x" == "x%CLASSPATH%" goto after_cp
409 set CP=%CLASSPATH%;%CP%
411 :after_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"
439 @rem Execute Groovy
441 "%JAVA_EXE%" %JAVA_OPTS% -classpath "%STARTER_CLASSPATH%" %STARTER_MAIN_CLASS% --main %CLASS% --conf "%STARTER_CONF%" --classpath "%CP%" %CMD_LINE_ARGS%
445 :end
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
459 exit /B %ERRORLEVEL%