9
9
10
10
@echo off
11
11
12
- if "%@@APP_ENV_NAME@@_HOME%"=="" set "@@APP_ENV_NAME@@_HOME=%~dp0\\.."
13
12
14
- set "APP_LIB_DIR=%@@APP_ENV_NAME@@_HOME%\lib\"
13
+ if "%@@APP_ENV_NAME@@_HOME%"=="" (
14
+ set "APP_HOME=%~dp0\\.."
15
+
16
+ rem Also set the old env name for backwards compatibility
17
+ set "@@APP_ENV_NAME@@_HOME=%~dp0\\.."
18
+ ) else (
19
+ set "APP_HOME=%@@APP_ENV_NAME@@_HOME%"
20
+ )
21
+
22
+ set "APP_LIB_DIR=%APP_HOME%\lib\"
15
23
16
24
rem Detect if we were double clicked, although theoretically A user could
17
25
rem manually run cmd /c
18
26
for %%x in (!cmdcmdline!) do if %%~x==/c set DOUBLECLICKED=1
19
27
20
28
rem FIRST we load the config file of extra options.
21
- set "CFG_FILE=%@@APP_ENV_NAME@@_HOME %\@@APP_ENV_NAME@@_config.txt"
29
+ set "CFG_FILE=%APP_HOME %\@@APP_ENV_NAME@@_config.txt"
22
30
set CFG_OPTS=
23
- if exist "%CFG_FILE%" (
24
- FOR /F "tokens=* eol=# usebackq delims=" %%i IN ("%CFG_FILE%") DO (
25
- set DO_NOT_REUSE_ME=%%i
26
- rem ZOMG (Part #2) WE use !! here to delay the expansion of
27
- rem CFG_OPTS, otherwise it remains "" for this loop.
28
- set CFG_OPTS=!CFG_OPTS! !DO_NOT_REUSE_ME!
29
- )
30
- )
31
+ call :parse_config "%CFG_FILE%" CFG_OPTS
31
32
32
33
rem We use the value of the JAVACMD environment variable if defined
33
34
set _JAVACMD=%JAVACMD%
@@ -79,55 +80,14 @@ rem "-J" is stripped, "-D" is left as is, and everything is appended to JAVA_OPT
79
80
set _JAVA_PARAMS=
80
81
set _APP_ARGS=
81
82
82
- :param_loop
83
- call set _PARAM1=%%1
84
- set "_TEST_PARAM=%~1"
85
-
86
- if ["!_PARAM1!"]==[""] goto param_afterloop
87
-
83
+ @@APP_DEFINES@@
88
84
89
- rem ignore arguments that do not start with '-'
90
- if "%_TEST_PARAM:~0,1%"=="-" goto param_java_check
91
- set _APP_ARGS=!_APP_ARGS! !_PARAM1!
92
- shift
93
- goto param_loop
85
+ rem if configuration files exist, prepend their contents to the script arguments so it can be processed by this runner
86
+ call :parse_config "%SCRIPT_CONF_FILE%" SCRIPT_CONF_ARGS
94
87
95
- :param_java_check
96
- if "!_TEST_PARAM:~0,2!"=="-J" (
97
- rem strip -J prefix
98
- set _JAVA_PARAMS=!_JAVA_PARAMS! !_TEST_PARAM:~2!
99
- shift
100
- goto param_loop
101
- )
102
-
103
- if "!_TEST_PARAM:~0,2!"=="-D" (
104
- rem test if this was double-quoted property "-Dprop=42"
105
- for /F "delims== tokens=1,*" %%G in ("!_TEST_PARAM!") DO (
106
- if not ["%%H"] == [""] (
107
- set _JAVA_PARAMS=!_JAVA_PARAMS! !_PARAM1!
108
- ) else if [%2] neq [] (
109
- rem it was a normal property: -Dprop=42 or -Drop="42"
110
- call set _PARAM1=%%1=%%2
111
- set _JAVA_PARAMS=!_JAVA_PARAMS! !_PARAM1!
112
- shift
113
- )
114
- )
115
- ) else (
116
- if "!_TEST_PARAM!"=="-main" (
117
- call set CUSTOM_MAIN_CLASS=%%2
118
- shift
119
- ) else (
120
- set _APP_ARGS=!_APP_ARGS! !_PARAM1!
121
- )
122
- )
123
- shift
124
- goto param_loop
125
- :param_afterloop
88
+ call :process_args %SCRIPT_CONF_ARGS% %%*
126
89
127
90
set _JAVA_OPTS=!_JAVA_OPTS! !_JAVA_PARAMS!
128
- :run
129
-
130
- @@APP_DEFINES@@
131
91
132
92
if defined CUSTOM_MAIN_CLASS (
133
93
set MAIN_CLASS=!CUSTOM_MAIN_CLASS!
@@ -140,7 +100,79 @@ rem Call the application and pass all arguments unchanged.
140
100
141
101
@endlocal
142
102
103
+ exit /B %ERRORLEVEL%
143
104
144
- :end
145
105
146
- exit /B %ERRORLEVEL%
106
+ rem Loads a configuration file full of default command line options for this script.
107
+ rem First argument is the path to the config file.
108
+ rem Second argument is the name of the environment variable to write to.
109
+ :parse_config
110
+ set _PARSE_FILE=%~1
111
+ set _PARSE_OUT=
112
+ if exist "%_PARSE_FILE%" (
113
+ FOR /F "tokens=* eol=# usebackq delims=" %%i IN ("%_PARSE_FILE%") DO (
114
+ set _PARSE_OUT=!_PARSE_OUT! %%i
115
+ )
116
+ )
117
+ set %2=!_PARSE_OUT!
118
+ exit /B 0
119
+
120
+
121
+ :add_java
122
+ set _JAVA_PARAMS=!_JAVA_PARAMS! %*
123
+ exit /B 0
124
+
125
+
126
+ :add_app
127
+ set _APP_ARGS=!_APP_ARGS! %*
128
+ exit /B 0
129
+
130
+
131
+ rem Processes incoming arguments and places them in appropriate global variables
132
+ :process_args
133
+ :param_loop
134
+ call set _PARAM1=%%1
135
+ set "_TEST_PARAM=%~1"
136
+
137
+ if ["!_PARAM1!"]==[""] goto param_afterloop
138
+
139
+
140
+ rem ignore arguments that do not start with '-'
141
+ if "%_TEST_PARAM:~0,1%"=="-" goto param_java_check
142
+ set _APP_ARGS=!_APP_ARGS! !_PARAM1!
143
+ shift
144
+ goto param_loop
145
+
146
+ :param_java_check
147
+ if "!_TEST_PARAM:~0,2!"=="-J" (
148
+ rem strip -J prefix
149
+ set _JAVA_PARAMS=!_JAVA_PARAMS! !_TEST_PARAM:~2!
150
+ shift
151
+ goto param_loop
152
+ )
153
+
154
+ if "!_TEST_PARAM:~0,2!"=="-D" (
155
+ rem test if this was double-quoted property "-Dprop=42"
156
+ for /F "delims== tokens=1,*" %%G in ("!_TEST_PARAM!") DO (
157
+ if not ["%%H"] == [""] (
158
+ set _JAVA_PARAMS=!_JAVA_PARAMS! !_PARAM1!
159
+ ) else if [%2] neq [] (
160
+ rem it was a normal property: -Dprop=42 or -Drop="42"
161
+ call set _PARAM1=%%1=%%2
162
+ set _JAVA_PARAMS=!_JAVA_PARAMS! !_PARAM1!
163
+ shift
164
+ )
165
+ )
166
+ ) else (
167
+ if "!_TEST_PARAM!"=="-main" (
168
+ call set CUSTOM_MAIN_CLASS=%%2
169
+ shift
170
+ ) else (
171
+ set _APP_ARGS=!_APP_ARGS! !_PARAM1!
172
+ )
173
+ )
174
+ shift
175
+ goto param_loop
176
+ :param_afterloop
177
+
178
+ exit /B 0
0 commit comments