Skip to content

Commit

Permalink
Disable user plugin when the same artifact is a dev dependency in lei…
Browse files Browse the repository at this point in the history
…n.bat.
  • Loading branch information
mtyaka committed Jul 6, 2011
1 parent bd466d7 commit 5cb7656
Showing 1 changed file with 61 additions and 10 deletions.
71 changes: 61 additions & 10 deletions bin/lein.bat
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,15 @@ if "%ORIGINAL_PWD:~-1%x" == "\x" set "ORIGINAL_PWD=%ORIGINAL_PWD%\"
call :FIND_DIR_CONTAINING_UPWARDS project.clj
if "%DIR_CONTAINING%" neq "" cd "%DIR_CONTAINING%"

set LEIN_PLUGINS="
for %%j in (".\lib\dev\*.jar") do (
set LEIN_PLUGINS=!LEIN_PLUGINS!;%%~fj
)
set LEIN_PLUGINS=!LEIN_PLUGINS!"

set LEIN_USER_PLUGINS="
for %%j in ("%LEIN_HOME%\plugins\*.jar") do (
set LEIN_USER_PLUGINS=!LEIN_USER_PLUGINS!;%%~fj
set DEV_PLUGINS="
for %%j in (".\lib\dev\*.jar") do (
set DEV_PLUGINS=!DEV_PLUGINS!;%%~fj
)
set LEIN_USER_PLUGINS=!LEIN_USER_PLUGINS!"
set DEV_PLUGINS=!DEV_PLUGINS!"

set CLASSPATH="%CLASSPATH%";%LEIN_USER_PLUGINS%;%LEIN_PLUGINS%;test;src
call :BUILD_UNIQUE_USER_PLUGINS
set CLASSPATH="%CLASSPATH%";%DEV_PLUGINS%;%UNIQUE_USER_PLUGINS%;test;src

rem Apply context specific CLASSPATH entries
set CONTEXT_CP=""
Expand Down Expand Up @@ -81,6 +77,61 @@ set CLOJURE_JAR=%USERPROFILE%\.m2\repository\org\clojure\clojure\1.2.1\clojure-1
goto RUN


rem Builds a classpath fragment consisting of user plugins
rem which aren't already present as a dev dependency.
:BUILD_UNIQUE_USER_PLUGINS
call :BUILD_PLUGIN_SEARCH_STRING %DEV_PLUGINS%
set UNIQUE_USER_PLUGINS="
for %%j in ("%LEIN_HOME%\plugins\*.jar") do (
call :MAKE_SEARCH_TOKEN %%~nj
echo %PLUGIN_SEARCH_STRING%|findstr ;!SEARCH_TOKEN!; > NUL
if !ERRORLEVEL! == 1 (
set UNIQUE_USER_PLUGINS=!UNIQUE_USER_PLUGINS!;%%~fj
)
)
set UNIQUE_USER_PLUGINS=!UNIQUE_USER_PLUGINS!"
goto :EOF

rem Builds a search string to match against when ensuring
rem plugin uniqueness.
:BUILD_PLUGIN_SEARCH_STRING
for %%j in (".\lib\dev\*.jar") do (
call :MAKE_SEARCH_TOKEN %%~nj
set PLUGIN_SEARCH_STRING=!PLUGIN_SEARCH_STRING!;!SEARCH_TOKEN!
)
set PLUGIN_SEARCH_STRING=%PLUGIN_SEARCH_STRING%;
goto :EOF

rem Takes a jar filename and returns a reversed jar name without version.
rem Example: lein-multi-0.1.1.jar -> itlum-niel
:MAKE_SEARCH_TOKEN
call :REVERSE_STRING %1
call :STRIP_VERSION !RSTRING!
set SEARCH_TOKEN=!VERSIONLESS!
goto :EOF

rem Reverses a string.
:REVERSE_STRING
set NUM=0
set INPUTSTR=%1
set RSTRING=
:REVERSE_STRING_LOOP
call set TMPCHR=%%INPUTSTR:~%NUM%,1%%%
set /A NUM+=1
if not "x%TMPCHR%" == "x" (
set RSTRING=%TMPCHR%%RSTRING%
goto REVERSE_STRING_LOOP
)
goto :EOF

rem Takes a string and removes everything from the beginning up to
rem and including the first dash character.
:STRIP_VERSION
set INPUT=%1
for /F "delims=- tokens=1*" %%a in ("%INPUT%") do set VERSIONLESS=%%b
goto :EOF


:NO_LEIN_JAR
echo.
echo %LEIN_JAR% can not be found.
Expand Down

0 comments on commit 5cb7656

Please sign in to comment.