Skip to content

Commit

Permalink
Fix batch scripts for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumebort committed Feb 9, 2012
1 parent 53dc1b3 commit 31504ff
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
6 changes: 5 additions & 1 deletion framework/build.bat
@@ -1,6 +1,10 @@
@echo off

set PLAY_VERSION="2.0-RC1-SNAPSHOT"

if defined JPDA_PORT set DEBUG_PARAM="-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=%JPDA_PORT%"

set p=%~dp0
set p=%p:\=/%

java -Xms512M -Xmx1024M -Xss1M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256M -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9999 -Dfile.encoding=UTF8 -Dsbt.ivy.home="%~dp0..\repository" -Dplay.home="%~dp0." -Dsbt.boot.properties="file:///%p%sbt/sbt.boot.properties" -jar "%~dp0sbt\sbt-launch.jar" %*
java -Xms512M -Xmx1024M -Xss1M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256M %DEBUG_PARAM% -Dfile.encoding=UTF8 -Dplay.version="%PLAY_VERSION%" -Dsbt.ivy.home="%~dp0..\repository" -Dplay.home="%~dp0." -Dsbt.boot.properties="file:///%p%sbt/sbt.boot.properties" -jar "%~dp0sbt\sbt-launch.jar" %*
2 changes: 1 addition & 1 deletion framework/src/sbt-plugin/src/main/scala/PlayCommands.scala
Expand Up @@ -850,7 +850,7 @@ trait PlayCommands {
println(play.console.Console.logo)
println("""
|> Type "help play" or "license" for more information.
|> Type "exit" or use Ctrl+C to leave this console.
|> Type "exit" or use Ctrl+D to leave this console.
|""".stripMargin)

state.copy(
Expand Down
35 changes: 31 additions & 4 deletions play.bat
@@ -1,8 +1,11 @@
:begin
@echo off

setlocal

set p=%~dp0
set p=%p:\=/%
set buildScript=%~dp0framework\build.bat

if exist "conf\application.conf" goto existingApplication

Expand All @@ -12,19 +15,43 @@ java -Dsbt.ivy.home=%~dp0repository -Dplay.home=%~dp0framework -Dsbt.boot.proper
goto end

:existingApplication
if not "%1" == "clean" goto runCommand
if not "%1" == "clean-all" goto runCommand

:cleanCache
call %~dp0framework\cleanIvyCache.bat
if exist "target" rmdir /s /q target
if exist "tmp" rmdir /s /q tmp
if exist "logs" rmdir /s /q logs
if exist "project\target" rmdir /s /q project\target
if exist "project\project" rmdir /s /q project\project
if exist "dist" rmdir /s /q dist

shift
if "%1" == "" goto endWithMessage

:runCommand
if "%1" == "" goto enterConsole

call %~dp0framework\build.bat %*
if "%1" == "debug" goto setDebug
goto enterConsoleWithCommands

:setDebug
set JPDA_PORT=9999
shift

if "%1" == "" goto enterConsole

:enterConsoleWithCommands

call %buildScript% %1 %2 %3 %4 %5 %6 %7 %8 %9

This comment has been minimized.

Copy link
@kevinbosman

kevinbosman Feb 9, 2012

Contributor

Specifying Windows command line arguments by number removes any '=' signs between the parameters. This causes system property overrides to break, eg. -Dconfig.file=prod/application.conf becomes 2 separate arguments -Dconfig.file and prod/application.conf which is invalid. Rather use %* to append ALL remaining arguments as is, ie:

call %buildScript% %*

This comment has been minimized.

Copy link
@guillaumebort

guillaumebort Feb 10, 2012

Author Contributor

The problem is that shift doesn't work with %*. Enclosing the parameters with double quote should fix the problem, right?

This comment has been minimized.

Copy link
@kevinbosman

kevinbosman Feb 10, 2012

Contributor

Good point: I missed that.
However, double quoted params won't work because of the quotes in the comparisons eg. if "%1" == "clean-all" causes unexpected arguments.
What would work is a form of string replacement, since you know what needs to be removed from the beginning of the param string each time.

eg. Right at the top do

set buildParam=%*

Then whenever you do a shift, also do:

shift
set buildParam=%buildParam:*clean-all=%

and

shift
set buildParam=%buildParam:*debug=%

This removes everything up to and including the string after the *.
Then

call %buildScript% %buildParam%

It's not great, but it works.

goto end

:enterConsole

call %~dp0framework\build.bat play
call %buildScript% play
goto end

:endWithMessage
echo [info] Done!

:end
endlocal

0 comments on commit 31504ff

Please sign in to comment.