|
19 | 19 | public class StableConfigParser {
|
20 | 20 | private static final Logger log = LoggerFactory.getLogger(StableConfigParser.class);
|
21 | 21 |
|
| 22 | + private static final String ENVIRONMENT_VARIABLES_PREFIX = "environment_variables['"; |
| 23 | + private static final String PROCESS_ARGUMENTS_PREFIX = "process_arguments['"; |
| 24 | + private static final String UNDEFINED_VALUE = "UNDEFINED"; |
| 25 | + |
22 | 26 | /**
|
23 | 27 | * Parses a configuration file and returns a stable configuration object.
|
24 | 28 | *
|
@@ -230,37 +234,39 @@ static String processTemplate(String content) throws IOException {
|
230 | 234 | }
|
231 | 235 |
|
232 | 236 | private static String processTemplateVar(String templateVar) throws IOException {
|
233 |
| - if (templateVar.startsWith("environment_variables['") && templateVar.endsWith("']")) { |
| 237 | + if (templateVar.startsWith(ENVIRONMENT_VARIABLES_PREFIX) && templateVar.endsWith("']")) { |
234 | 238 | String envVar =
|
235 | 239 | templateVar
|
236 |
| - .substring("environment_variables['".length(), templateVar.length() - 2) |
| 240 | + .substring(ENVIRONMENT_VARIABLES_PREFIX.length(), templateVar.length() - 2) |
237 | 241 | .trim();
|
238 | 242 | if (envVar.isEmpty()) {
|
239 | 243 | throw new IOException("Empty environment variable name in template");
|
240 | 244 | }
|
241 | 245 | String value = System.getenv(envVar.toUpperCase());
|
242 | 246 | if (value == null || value.isEmpty()) {
|
243 |
| - return "UNDEFINED"; |
| 247 | + return UNDEFINED_VALUE; |
244 | 248 | }
|
245 | 249 | return value;
|
246 |
| - } else if (templateVar.startsWith("process_arguments['") && templateVar.endsWith("']")) { |
| 250 | + } else if (templateVar.startsWith(PROCESS_ARGUMENTS_PREFIX) && templateVar.endsWith("']")) { |
247 | 251 | String processArg =
|
248 |
| - templateVar.substring("process_arguments['".length(), templateVar.length() - 2).trim(); |
| 252 | + templateVar.substring(PROCESS_ARGUMENTS_PREFIX.length(), templateVar.length() - 2).trim(); |
249 | 253 | if (processArg.isEmpty()) {
|
250 | 254 | throw new IOException("Empty process argument in template");
|
251 | 255 | }
|
252 | 256 | if (!processArg.startsWith("-D")) {
|
253 | 257 | log.warn(
|
254 |
| - "Ignoring unsupported process_arguments entry in template variable, '{}'. Only system properties specified with the '-D' prefix are supported.", |
| 258 | + "Ignoring unsupported process_arguments entry in template variable, '{}'." |
| 259 | + + " Only system properties specified with the '-D' prefix are supported.", |
255 | 260 | processArg);
|
256 |
| - return "UNDEFINED"; |
| 261 | + return UNDEFINED_VALUE; |
257 | 262 | }
|
258 | 263 | String value = System.getProperty(processArg.substring(2));
|
259 | 264 | if (value == null || value.isEmpty()) {
|
260 |
| - return "UNDEFINED"; |
| 265 | + return UNDEFINED_VALUE; |
261 | 266 | }
|
262 | 267 | return value;
|
| 268 | + } else { |
| 269 | + return UNDEFINED_VALUE; |
263 | 270 | }
|
264 |
| - return "UNDEFINED"; |
265 | 271 | }
|
266 | 272 | }
|
0 commit comments