Skip to content

Commit

Permalink
[java] Use new 'getArray' method to extract driver configurations (#1…
Browse files Browse the repository at this point in the history
…2716)

Use new 'getArray' method; fix formatting

Co-authored-by: Diego Molina <[email protected]>
  • Loading branch information
sbabcoc and diemol authored Oct 7, 2023
1 parent 5cfaef5 commit ecfa9c4
Showing 1 changed file with 34 additions and 35 deletions.
69 changes: 34 additions & 35 deletions java/src/org/openqa/selenium/grid/node/config/NodeOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -349,51 +349,50 @@ private void addDriverConfigs(

// get all driver configuration settings
config
.getAll(NODE_SECTION, "driver-configuration")
// if settings exist
.getArray(NODE_SECTION, "driver-configuration")
// if configurations exist
.ifPresent(
drivers -> {
Map<String, String> configMap = new HashMap<>();
List<Map<String, String>> configList = new ArrayList<>();

// iterate over driver settings
for (String setting : drivers) {
// split this setting into key/value pair
String[] values = setting.split("=", 2);
// if format is invalid
if (values.length != 2) {
throw new ConfigException(
"Driver setting '"
+ setting
+ "' does not adhere to the required 'key=value' format!");
}
// if this is a record separator
if (values[0].equals(Config.DELIM_KEY)) {
// if config lacks settings
if (configMap.isEmpty()) {
throw new ConfigException("Found config delimiter with no preceding settings!");
}

// if config lacks 'display-name' setting
if (!configMap.containsKey("display-name")) {
throw new ConfigException(
"Found config with no 'display-name' setting! " + configMap);
}
// iterate over driver configurations
for (List<String> driver : drivers) {
Map<String, String> configMap = new HashMap<>();

// if config lacks 'stereotype' setting
if (!configMap.containsKey("stereotype")) {
// iterate over driver settings
for (String setting : driver) {
// split this setting into key/value pair
String[] values = setting.split("=", 2);
// if format is invalid
if (values.length != 2) {
throw new ConfigException(
"Found config with no 'stereotype' setting! " + configMap);
"Driver setting '"
+ setting
+ "' does not adhere to the required 'key=value' format!");
}

// add config to list
configList.add(configMap);
// prepare for next config
configMap = new HashMap<>();
} else {
// add setting to config
configMap.put(values[0], unquote(values[1]));
}

// if config lacks settings
if (configMap.isEmpty()) {
throw new ConfigException("Found config delimiter with no preceding settings!");
}

// if config lacks 'display-name' setting
if (!configMap.containsKey("display-name")) {
throw new ConfigException(
"Found config with no 'display-name' setting! " + configMap);
}

// if config lacks 'stereotype' setting
if (!configMap.containsKey("stereotype")) {
throw new ConfigException(
"Found config with no 'stereotype' setting! " + configMap);
}

// add config to list
configList.add(configMap);
}

// if no configs were found
Expand Down

0 comments on commit ecfa9c4

Please sign in to comment.