grails/grails-core — pull request #414 by johnrengelman (2013-10-14 18:49:14+00:00)
Title: Support assigning 0 to http/https port for OS assigned port.

Enables support for assigning `server.port=0` and `server.port.https=0` and have the OS assign an available port. This is to facilitate testing on CI servers with multiple jobs, allowing Grails to bind to an available port.

Tested manually in the following scenarios:
`grails -Dserver.port=0 run-app`
`grails -Dserver.port.https=0 run-app -https`
`grails -Dserver.port=0 run-war`
`grails -Dserver.port.https=0 run-war -https`
`grails -Dserver.port=0 run-app` (with grails.project.fork.run=true)
`grails -Dserver.port.https=0 run-app -https` (with grails.project.fork.run=true)

Notes
1) Needed to move the Tomcat kill switch port to `server.port - 1` instead of `+ 1`. This is because when running both http and https as 0, they will typically be assigned sequential ports which causes the kill switch and https to use the same port.
2) Needed to add a new event in the test phase `testPhasePrepared`. This executes after Tomcat is initialized and will allow plugins (i.e. Geb) to get the actual server ports (instead of 0).

I was hoping that this could go into 2.2.5 since I think there will a number of people who won't be upgrading to 2.3 for a while. This patch should work fine in 2.3.x as well although the changes to the Tomcat plugin will need to be transferred to its repo.