|
| 1 | +@REM activator launcher script |
| 2 | +@REM |
| 3 | +@REM Envioronment: |
| 4 | +@REM JAVA_HOME - location of a JDK home dir (optional if java on path) |
| 5 | +@REM CFG_OPTS - JVM options (optional) |
| 6 | +@REM Configuration: |
| 7 | +@REM activatorconfig.txt found in the ACTIVATOR_HOME or ACTIVATOR_HOME/ACTIVATOR_VERSION |
| 8 | +@setlocal enabledelayedexpansion |
| 9 | + |
| 10 | +@echo off |
| 11 | + |
| 12 | +set "var1=%~1" |
| 13 | +if defined var1 ( |
| 14 | + if "%var1%"=="help" ( |
| 15 | + echo. |
| 16 | + echo Usage activator [options] [command] |
| 17 | + echo. |
| 18 | + echo Commands: |
| 19 | + echo ui Start the Activator UI |
| 20 | + echo new [name] [template-id] Create a new project with [name] using template [template-id] |
| 21 | + echo list-templates Print all available template names |
| 22 | + echo help Print this message |
| 23 | + echo. |
| 24 | + echo Options: |
| 25 | + echo -jvm-debug [port] Turn on JVM debugging, open at the given port. Defaults to 9999 if no port given. |
| 26 | + echo. |
| 27 | + echo Environment variables ^(read from context^): |
| 28 | + echo JAVA_OPTS Environment variable, if unset uses "" |
| 29 | + echo SBT_OPTS Environment variable, if unset uses "" |
| 30 | + echo ACTIVATOR_OPTS Environment variable, if unset uses "" |
| 31 | + echo. |
| 32 | + goto :end |
| 33 | + ) |
| 34 | +) |
| 35 | + |
| 36 | +if "%ACTIVATOR_HOME%"=="" ( |
| 37 | + set "ACTIVATOR_HOME=%~dp0" |
| 38 | + @REM remove trailing "\" from path |
| 39 | + set ACTIVATOR_HOME=!ACTIVATOR_HOME:~0,-1! |
| 40 | +) |
| 41 | + |
| 42 | +set ERROR_CODE=0 |
| 43 | +set APP_VERSION=1.2.12 |
| 44 | +set ACTIVATOR_LAUNCH_JAR=activator-launch-%APP_VERSION%.jar |
| 45 | + |
| 46 | +rem Detect if we were double clicked, although theoretically A user could |
| 47 | +rem manually run cmd /c |
| 48 | +for %%x in (%cmdcmdline%) do if %%~x==/c set DOUBLECLICKED=1 |
| 49 | + |
| 50 | +rem FIRST we load a config file of extra options (if there is one) |
| 51 | +set "CFG_FILE_HOME=%UserProfile%\.activator\activatorconfig.txt" |
| 52 | +set "CFG_FILE_VERSION=%UserProfile%\.activator\%APP_VERSION%\activatorconfig.txt" |
| 53 | +set CFG_OPTS= |
| 54 | +if exist %CFG_FILE_VERSION% ( |
| 55 | + FOR /F "tokens=* eol=# usebackq delims=" %%i IN ("%CFG_FILE_VERSION%") DO ( |
| 56 | + set DO_NOT_REUSE_ME=%%i |
| 57 | + rem ZOMG (Part #2) WE use !! here to delay the expansion of |
| 58 | + rem CFG_OPTS, otherwise it remains "" for this loop. |
| 59 | + set CFG_OPTS=!CFG_OPTS! !DO_NOT_REUSE_ME! |
| 60 | + ) |
| 61 | +) |
| 62 | +if "%CFG_OPTS%"=="" ( |
| 63 | + if exist %CFG_FILE_HOME% ( |
| 64 | + FOR /F "tokens=* eol=# usebackq delims=" %%i IN ("%CFG_FILE_HOME%") DO ( |
| 65 | + set DO_NOT_REUSE_ME=%%i |
| 66 | + rem ZOMG (Part #2) WE use !! here to delay the expansion of |
| 67 | + rem CFG_OPTS, otherwise it remains "" for this loop. |
| 68 | + set CFG_OPTS=!CFG_OPTS! !DO_NOT_REUSE_ME! |
| 69 | + ) |
| 70 | + ) |
| 71 | +) |
| 72 | + |
| 73 | +rem We use the value of the JAVACMD environment variable if defined |
| 74 | +set _JAVACMD=%JAVACMD% |
| 75 | + |
| 76 | +if "%_JAVACMD%"=="" ( |
| 77 | + if not "%JAVA_HOME%"=="" ( |
| 78 | + if exist "%JAVA_HOME%\bin\java.exe" set "_JAVACMD=%JAVA_HOME%\bin\java.exe" |
| 79 | + |
| 80 | + rem if there is a java home set we make sure it is the first picked up when invoking 'java' |
| 81 | + SET "PATH=%JAVA_HOME%\bin;%PATH%" |
| 82 | + ) |
| 83 | +) |
| 84 | + |
| 85 | +if "%_JAVACMD%"=="" set _JAVACMD=java |
| 86 | + |
| 87 | +rem Detect if this java is ok to use. |
| 88 | +for /F %%j in ('"%_JAVACMD%" -version 2^>^&1') do ( |
| 89 | + if %%~j==Java set JAVAINSTALLED=1 |
| 90 | +) |
| 91 | + |
| 92 | +rem Detect the same thing about javac |
| 93 | +if "%_JAVACCMD%"=="" ( |
| 94 | + if not "%JAVA_HOME%"=="" ( |
| 95 | + if exist "%JAVA_HOME%\bin\javac.exe" set "_JAVACCMD=%JAVA_HOME%\bin\javac.exe" |
| 96 | + ) |
| 97 | +) |
| 98 | +if "%_JAVACCMD%"=="" set _JAVACCMD=javac |
| 99 | +for /F %%j in ('"%_JAVACCMD%" -version 2^>^&1') do ( |
| 100 | + if %%~j==javac set JAVACINSTALLED=1 |
| 101 | +) |
| 102 | + |
| 103 | +rem BAT has no logical or, so we do it OLD SCHOOL! Oppan Redmond Style |
| 104 | +set JAVAOK=true |
| 105 | +if not defined JAVAINSTALLED set JAVAOK=false |
| 106 | +if not defined JAVACINSTALLED set JAVAOK=false |
| 107 | + |
| 108 | +if "%JAVAOK%"=="false" ( |
| 109 | + echo. |
| 110 | + echo A Java JDK is not installed or can't be found. |
| 111 | + if not "%JAVA_HOME%"=="" ( |
| 112 | + echo JAVA_HOME = "%JAVA_HOME%" |
| 113 | + ) |
| 114 | + echo. |
| 115 | + echo Please go to |
| 116 | + echo http://www.oracle.com/technetwork/java/javase/downloads/index.html |
| 117 | + echo and download a valid Java JDK and install before running Activator. |
| 118 | + echo. |
| 119 | + echo If you think this message is in error, please check |
| 120 | + echo your environment variables to see if "java.exe" and "javac.exe" are |
| 121 | + echo available via JAVA_HOME or PATH. |
| 122 | + echo. |
| 123 | + if defined DOUBLECLICKED pause |
| 124 | + exit /B 1 |
| 125 | +) |
| 126 | + |
| 127 | +rem Check what Java version is being used to determine what memory options to use |
| 128 | +for /f "tokens=3" %%g in ('java -version 2^>^&1 ^| findstr /i "version"') do ( |
| 129 | + set JAVA_VERSION=%%g |
| 130 | +) |
| 131 | + |
| 132 | +rem Strips away the " characters |
| 133 | +set JAVA_VERSION=%JAVA_VERSION:"=% |
| 134 | + |
| 135 | +rem TODO Check if there are existing mem settings in JAVA_OPTS/CFG_OPTS and use those instead of the below |
| 136 | +for /f "delims=. tokens=1-3" %%v in ("%JAVA_VERSION%") do ( |
| 137 | + set MAJOR=%%v |
| 138 | + set MINOR=%%w |
| 139 | + set BUILD=%%x |
| 140 | + |
| 141 | + set META_SIZE=-XX:MetaspaceSize=64M -XX:MaxMetaspaceSize=256M |
| 142 | + if "!MINOR!" LSS "8" ( |
| 143 | + set META_SIZE=-XX:PermSize=64M -XX:MaxPermSize=256M |
| 144 | + ) |
| 145 | + |
| 146 | + set MEM_OPTS=!META_SIZE! |
| 147 | + ) |
| 148 | + |
| 149 | +rem We use the value of the JAVA_OPTS environment variable if defined, rather than the config. |
| 150 | +set _JAVA_OPTS=%JAVA_OPTS% |
| 151 | +if "%_JAVA_OPTS%"=="" set _JAVA_OPTS=%CFG_OPTS% |
| 152 | + |
| 153 | +set DEBUG_OPTS= |
| 154 | + |
| 155 | +rem Loop through the arguments, building remaining args in args variable |
| 156 | +set args= |
| 157 | +:argsloop |
| 158 | +if not "%~1"=="" ( |
| 159 | + rem Checks if the argument contains "-D" and if true, adds argument 1 with 2 and puts an equal sign between them. |
| 160 | + rem This is done since batch considers "=" to be a delimiter so we need to circumvent this behavior with a small hack. |
| 161 | + set arg1=%~1 |
| 162 | + if "!arg1:~0,2!"=="-D" ( |
| 163 | + set "args=%args% "%~1"="%~2"" |
| 164 | + shift |
| 165 | + shift |
| 166 | + goto argsloop |
| 167 | + ) |
| 168 | + |
| 169 | + if "%~1"=="-jvm-debug" ( |
| 170 | + if not "%~2"=="" ( |
| 171 | + rem This piece of magic somehow checks that an argument is a number |
| 172 | + for /F "delims=0123456789" %%i in ("%~2") do ( |
| 173 | + set var="%%i" |
| 174 | + ) |
| 175 | + if defined var ( |
| 176 | + rem Not a number, assume no argument given and default to 9999 |
| 177 | + set JPDA_PORT=9999 |
| 178 | + ) else ( |
| 179 | + rem Port was given, shift arguments |
| 180 | + set JPDA_PORT=%~2 |
| 181 | + shift |
| 182 | + ) |
| 183 | + ) else ( |
| 184 | + set JPDA_PORT=9999 |
| 185 | + ) |
| 186 | + shift |
| 187 | + |
| 188 | + set DEBUG_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=!JPDA_PORT! |
| 189 | + goto argsloop |
| 190 | + ) |
| 191 | + rem else |
| 192 | + set "args=%args% "%~1"" |
| 193 | + shift |
| 194 | + goto argsloop |
| 195 | +) |
| 196 | + |
| 197 | +:run |
| 198 | + |
| 199 | +if "!args!"=="" ( |
| 200 | + if defined DOUBLECLICKED ( |
| 201 | + set CMDS="ui" |
| 202 | + ) else set CMDS=!args! |
| 203 | +) else set CMDS=!args! |
| 204 | + |
| 205 | +rem We add a / in front, so we get file:///C: instead of file://C: |
| 206 | +rem Java considers the later a UNC path. |
| 207 | +rem We also attempt a solid effort at making it URI friendly. |
| 208 | +rem We don't even bother with UNC paths. |
| 209 | +set JAVA_FRIENDLY_HOME_1=/!ACTIVATOR_HOME:\=/! |
| 210 | +set JAVA_FRIENDLY_HOME=/!JAVA_FRIENDLY_HOME_1: =%%20! |
| 211 | + |
| 212 | +rem Checks if the command contains spaces to know if it should be wrapped in quotes or not |
| 213 | +set NON_SPACED_CMD=%_JAVACMD: =% |
| 214 | +if "%_JAVACMD%"=="%NON_SPACED_CMD%" %_JAVACMD% %DEBUG_OPTS% %MEM_OPTS% %ACTIVATOR_OPTS% %SBT_OPTS% %_JAVA_OPTS% "-Dactivator.home=%JAVA_FRIENDLY_HOME%" -jar "%ACTIVATOR_HOME%\%ACTIVATOR_LAUNCH_JAR%" %CMDS% |
| 215 | +if NOT "%_JAVACMD%"=="%NON_SPACED_CMD%" "%_JAVACMD%" %DEBUG_OPTS% %MEM_OPTS% %ACTIVATOR_OPTS% %SBT_OPTS% %_JAVA_OPTS% "-Dactivator.home=%JAVA_FRIENDLY_HOME%" -jar "%ACTIVATOR_HOME%\%ACTIVATOR_LAUNCH_JAR%" %CMDS% |
| 216 | + |
| 217 | +if ERRORLEVEL 1 goto error |
| 218 | +goto end |
| 219 | + |
| 220 | +:error |
| 221 | +set ERROR_CODE=1 |
| 222 | + |
| 223 | +:end |
| 224 | + |
| 225 | +@endlocal |
| 226 | + |
| 227 | +exit /B %ERROR_CODE% |
0 commit comments