Skip to content

Commit

Permalink
Simplify handling of LEIN_JAVA_CMD to support parens in paths, such a…
Browse files Browse the repository at this point in the history
…s with "Program Files (x86)"
  • Loading branch information
djpowell committed Mar 15, 2013
1 parent 8df3d12 commit f3059d4
Showing 1 changed file with 6 additions and 26 deletions.
32 changes: 6 additions & 26 deletions bin/lein.bat
Expand Up @@ -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

Expand All @@ -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.
Expand Down

0 comments on commit f3059d4

Please sign in to comment.