Simplify handling of LEIN_JAVA_CMD to support parens in paths, such as with "Program Files (x86)"

This commit is contained in:
David Powell 2013-03-15 20:35:46 +00:00
parent 8df3d12ef8
commit f3059d4d25

View file

@ -66,10 +66,13 @@ if exist "%~dp0..\src\leiningen\version.clj" (
if not "x%DEBUG%" == "x" echo CLASSPATH=!CLASSPATH!
:: ##################################################
if "x!JAVA_CMD!" == "x" set JAVA_CMD=java
if "x!LEIN_JAVA_CMD!" == "x" set LEIN_JAVA_CMD=%JAVA_CMD%
rem ensure a single set of quotes around java commands
for /f "usebackq delims=" %%i in ('!JAVA_CMD!') do set JAVA_CMD="%%~i"
for /f "usebackq delims=" %%i in ('!LEIN_JAVA_CMD!') do set LEIN_JAVA_CMD="%%~i"
call :EnsureIsSet JAVA_CMD java
call :EnsureIsSet LEIN_JAVA_CMD %JAVA_CMD%
rem if "x%JAVA_CMD%" == "x" set JAVA_CMD="java"
if "x%JVM_OPTS%" == "x" set JVM_OPTS=%JAVA_OPTS%
goto RUN
@ -91,29 +94,6 @@ if NOT ERRORLEVEL 9009 (
goto EOF
:EnsureIsSet
rem parameters: Variable DefaultValue
rem Variable's value can be empty, if it is then it will be set to the DefaultValue(which is not modified/stripped)
rem it will strip all encountered double quotes from Variable and from Variable's value
rem this script will fail if Variable contains characters like >, <, |, & or even parentheses or even number of double quotes
rem the Variable's value will be surrounded by double quotes (no inner double quotes though, they're all stripped)
rem except in the case of DefaultValue which is set as it is
SETLOCAL
set _var=%~1
call set _result=%%%_var%%%
for /f "useback tokens=*" %%a in ('%_result%') do (
set _result=%%~a
set _result=%_result:"=%
)
( ENDLOCAL
if "x%_result%" == "x" (set %_var%=%2) ELSE (set %_var%="%_result%")
)
goto :eof
:NO_LEIN_JAR
echo.