Skip to content

Commit ecfa9c4

Browse files
sbabcocdiemol
andauthored
[java] Use new 'getArray' method to extract driver configurations (#12716)
Use new 'getArray' method; fix formatting Co-authored-by: Diego Molina <[email protected]>
1 parent 5cfaef5 commit ecfa9c4

File tree

1 file changed

+34
-35
lines changed

1 file changed

+34
-35
lines changed

java/src/org/openqa/selenium/grid/node/config/NodeOptions.java

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -349,51 +349,50 @@ private void addDriverConfigs(
349349

350350
// get all driver configuration settings
351351
config
352-
.getAll(NODE_SECTION, "driver-configuration")
353-
// if settings exist
352+
.getArray(NODE_SECTION, "driver-configuration")
353+
// if configurations exist
354354
.ifPresent(
355355
drivers -> {
356-
Map<String, String> configMap = new HashMap<>();
357356
List<Map<String, String>> configList = new ArrayList<>();
358357

359-
// iterate over driver settings
360-
for (String setting : drivers) {
361-
// split this setting into key/value pair
362-
String[] values = setting.split("=", 2);
363-
// if format is invalid
364-
if (values.length != 2) {
365-
throw new ConfigException(
366-
"Driver setting '"
367-
+ setting
368-
+ "' does not adhere to the required 'key=value' format!");
369-
}
370-
// if this is a record separator
371-
if (values[0].equals(Config.DELIM_KEY)) {
372-
// if config lacks settings
373-
if (configMap.isEmpty()) {
374-
throw new ConfigException("Found config delimiter with no preceding settings!");
375-
}
376-
377-
// if config lacks 'display-name' setting
378-
if (!configMap.containsKey("display-name")) {
379-
throw new ConfigException(
380-
"Found config with no 'display-name' setting! " + configMap);
381-
}
358+
// iterate over driver configurations
359+
for (List<String> driver : drivers) {
360+
Map<String, String> configMap = new HashMap<>();
382361

383-
// if config lacks 'stereotype' setting
384-
if (!configMap.containsKey("stereotype")) {
362+
// iterate over driver settings
363+
for (String setting : driver) {
364+
// split this setting into key/value pair
365+
String[] values = setting.split("=", 2);
366+
// if format is invalid
367+
if (values.length != 2) {
385368
throw new ConfigException(
386-
"Found config with no 'stereotype' setting! " + configMap);
369+
"Driver setting '"
370+
+ setting
371+
+ "' does not adhere to the required 'key=value' format!");
387372
}
388-
389-
// add config to list
390-
configList.add(configMap);
391-
// prepare for next config
392-
configMap = new HashMap<>();
393-
} else {
394373
// add setting to config
395374
configMap.put(values[0], unquote(values[1]));
396375
}
376+
377+
// if config lacks settings
378+
if (configMap.isEmpty()) {
379+
throw new ConfigException("Found config delimiter with no preceding settings!");
380+
}
381+
382+
// if config lacks 'display-name' setting
383+
if (!configMap.containsKey("display-name")) {
384+
throw new ConfigException(
385+
"Found config with no 'display-name' setting! " + configMap);
386+
}
387+
388+
// if config lacks 'stereotype' setting
389+
if (!configMap.containsKey("stereotype")) {
390+
throw new ConfigException(
391+
"Found config with no 'stereotype' setting! " + configMap);
392+
}
393+
394+
// add config to list
395+
configList.add(configMap);
397396
}
398397

399398
// if no configs were found

0 commit comments

Comments
 (0)