Skip to content

Instantly share code, notes, and snippets.

@George1
Created February 24, 2010 21:24
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save George1/313862 to your computer and use it in GitHub Desktop.
Save George1/313862 to your computer and use it in GitHub Desktop.
Automatically selects version of Grails to run based either on context, environment variable, or command line argument.
@ECHO OFF
REM
REM Automatic Grails Version Selector v1.0
REM
REM Description:
REM Automatically selects version of Grails to run based either
REM on context, environment variable, or command line argument.
REM
REM Copyright © 2010, Componentix (http://www.componentix.com/)
REM Copyright © 2010, Yuri Sakhno (George1). All rights reserved.
REM
REM License:
REM You are granted the permission to use this script free of charge with
REM your projects, modify it, distribute it or your modified copies by any
REM means available to you as long as this whole comment is included in
REM the file you distribute.
REM You are not required to include attribution either to Componentix, or
REM to the author (Yuri Sakhno) in the projects that you build using this
REM script.
REM
REM THIS SCRIPT IS DISTRIBUTED "AS IS". THERE IS NO WARRANTY OF ANY KIND,
REM EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
REM MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
REM IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
REM CLAIM, DAMAGES, LOSSES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
REM CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
REM WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
REM
IF "%GRAILS_PREFIX%q" == "q" (
ECHO You must define environment variable GRAILS_PREFIX before running Automatic Grails Version Selector
EXIT /B -5
)
:setupArgs
IF "q%1" == "q" (
GOTO :doneStart
)
SET VER_PARAM=%1
IF "%VER_PARAM:~0,5%" == "-ver:" (
IF "%VER_PARAM:~5%q" == "q" (
ECHO "Version override argument -ver must specify version number after the colon"
EXIT /B -2
)
SET VERSION_OVERRIDE=%VER_PARAM:~5%
SHIFT
GOTO :setupArgs
)
SET CMD_LINE_ARGS=%CMD_LINE_ARGS% %1
SHIFT
GOTO :setupArgs
:doneStart
IF EXIST .\application.properties (
CALL :WithApplicationPropertiesProc
) ELSE (
CALL :NoApplicationPropertiesProc
)
EXIT /B %ERRORLEVEL%
:NoApplicationPropertiesProc
IF NOT "%VERSION_OVERRIDE%q" == "q" (
SET GRAILS_VERSION=%VERSION_OVERRIDE%
)
IF "%GRAILS_VERSION%q" == "q" (
ECHO You must define environment variable GRAILS_VERSION to specify the default version of Grails to use
EXIT /B -5
)
SET GRAILS_HOME=%GRAILS_PREFIX%%GRAILS_VERSION%
IF NOT EXIST %GRAILS_HOME%\. (
ECHO Grails home directory for default version does not exist: %GRAILS_HOME%
ECHO Make sure you have downloaded and installed the version of Grails required: %GRAILS_VERSION%
EXIT /B -1
)
CALL :CallGrailsProc
EXIT /B 0
:WithApplicationPropertiesProc
IF "%VERSION_OVERRIDE%q" == "q" (
FOR /F "eol=# tokens=1,2 delims==" %%i IN (application.properties) DO (
IF "%%i" == "app.grails.version" (
SET GRAILS_VERSION=%%j
)
)
SET PLACE=file application.properties
) ELSE (
SET GRAILS_VERSION=%VERSION_OVERRIDE%
SET PLACE=command line argument -ver
)
IF "%GRAILS_VERSION%q" == "q" (
ECHO Grails version is not defined in %PLACE%
EXIT /B -4
)
SET GRAILS_HOME=%GRAILS_PREFIX%%GRAILS_VERSION%
IF NOT EXIST %GRAILS_HOME%\. (
ECHO Grails home directory for this project does not exist: %GRAILS_HOME%
ECHO The current project might have updated to a newer Grails version.
ECHO Make sure you have downloaded and installed the version of Grails required: %GRAILS_VERSION%
EXIT /B -1
)
CALL :CallGrailsProc
EXIT /B 0
:CallGrailsProc
SET PATH=%GRAILS_HOME%\bin
CALL %GRAILS_HOME%\bin\grails.bat %CMD_LINE_ARGS%
EXIT /B
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment