Skip to content

Commit e8c0435

Browse files
Delta456pujagani
andauthored
[grid] TomlConfig: migrate TOML library to tomlj/tomlj (SeleniumHQ#14470)
Co-authored-by: Puja Jagani <[email protected]>
1 parent c120f60 commit e8c0435

File tree

10 files changed

+83
-39
lines changed

10 files changed

+83
-39
lines changed

MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ maven.install(
199199
"io.opentelemetry:opentelemetry-sdk-testing:1.43.0",
200200
"io.opentelemetry:opentelemetry-sdk-trace:1.43.0",
201201
"io.opentelemetry.semconv:opentelemetry-semconv:1.25.0-alpha",
202-
"io.ous:jtoml:2.0.0",
203202
"it.ozimov:embedded-redis:0.7.3",
204203
"net.bytebuddy:byte-buddy:1.15.10",
205204
"org.htmlunit:htmlunit-core-js:4.5.0",
@@ -221,6 +220,7 @@ maven.install(
221220
"org.redisson:redisson:3.37.0",
222221
"org.slf4j:slf4j-api:2.0.16",
223222
"org.slf4j:slf4j-jdk14:2.0.16",
223+
"org.tomlj:tomlj:1.1.1",
224224
"org.zeromq:jeromq:0.6.0",
225225
],
226226
excluded_artifacts = [

java/maven_install.json

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"__AUTOGENERATED_FILE_DO_NOT_MODIFY_THIS_FILE_MANUALLY": "THERE_IS_NO_DATA_ONLY_ZUUL",
3-
"__INPUT_ARTIFACTS_HASH": 707988571,
4-
"__RESOLVED_ARTIFACTS_HASH": -1165730169,
3+
"__INPUT_ARTIFACTS_HASH": -1685742929,
4+
"__RESOLVED_ARTIFACTS_HASH": -1218025727,
55
"conflict_resolution": {
66
"com.google.code.gson:gson:2.8.9": "com.google.code.gson:gson:2.11.0",
77
"com.google.errorprone:error_prone_annotations:2.3.2": "com.google.errorprone:error_prone_annotations:2.28.0",
@@ -444,13 +444,6 @@
444444
},
445445
"version": "1.43.0"
446446
},
447-
"io.ous:jtoml": {
448-
"shasums": {
449-
"jar": "3cabdae2244c999addebb8c31ae452fbdc874b4f26a163539954b8eeb5d6acc6",
450-
"sources": "f479f2acdf7a362dc86a5c9310ddaec7b34a87f0a8a6f46dde41c1069b2a2138"
451-
},
452-
"version": "2.0.0"
453-
},
454447
"io.projectreactor:reactor-core": {
455448
"shasums": {
456449
"jar": "44f055fbd033b6c976c53fb2e04b59027e79fb2312c37d2eaa54c77ea1ea80fe",
@@ -514,6 +507,13 @@
514507
},
515508
"version": "12.4"
516509
},
510+
"org.antlr:antlr4-runtime": {
511+
"shasums": {
512+
"jar": "e06c6553c1ccc14d36052ec4b0fc6f13b808cf957b5b1dc3f61bf401996ada59",
513+
"sources": "6fa0efb711a152842ecda1d41ceab94fb2049f833e00e360e161ac0e7a3819fe"
514+
},
515+
"version": "4.11.1"
516+
},
517517
"org.apache.bcel:bcel": {
518518
"shasums": {
519519
"jar": "a119a4420350dea669acfd84120ecc7e5742dcabcc82b0b9f9755dc692335aa2",
@@ -801,6 +801,13 @@
801801
},
802802
"version": "1.7.21"
803803
},
804+
"org.tomlj:tomlj": {
805+
"shasums": {
806+
"jar": "383b7c66966c42ee4913ec977a7b6573631866bddc5318ec4a6215b688dd0d6c",
807+
"sources": "533276104d58ebc92ce049c59a129717ce7daf0e9340969256fdb61f4f06f717"
808+
},
809+
"version": "1.1.1"
810+
},
804811
"org.xmlresolver:xmlresolver": {
805812
"shasums": {
806813
"data": "173904bdbd783ba0fac92c5bcc05da5d09f0ce7eed24346666ea0a239461f9b4",
@@ -1159,6 +1166,10 @@
11591166
"org.slf4j:slf4j-simple": [
11601167
"org.slf4j:slf4j-api"
11611168
],
1169+
"org.tomlj:tomlj": [
1170+
"org.antlr:antlr4-runtime",
1171+
"org.checkerframework:checker-qual"
1172+
],
11621173
"org.xmlresolver:xmlresolver": [
11631174
"org.apache.httpcomponents.client5:httpclient5",
11641175
"org.apache.httpcomponents.core5:httpcore5"
@@ -1786,10 +1797,6 @@
17861797
"io.opentelemetry.sdk.trace.internal.data",
17871798
"io.opentelemetry.sdk.trace.samplers"
17881799
],
1789-
"io.ous:jtoml": [
1790-
"io.ous.jtoml",
1791-
"io.ous.jtoml.impl"
1792-
],
17931800
"io.projectreactor:reactor-core": [
17941801
"reactor.adapter",
17951802
"reactor.core",
@@ -2014,6 +2021,15 @@
20142021
"net.sf.saxon.xpath",
20152022
"net.sf.saxon.z"
20162023
],
2024+
"org.antlr:antlr4-runtime": [
2025+
"org.antlr.v4.runtime",
2026+
"org.antlr.v4.runtime.atn",
2027+
"org.antlr.v4.runtime.dfa",
2028+
"org.antlr.v4.runtime.misc",
2029+
"org.antlr.v4.runtime.tree",
2030+
"org.antlr.v4.runtime.tree.pattern",
2031+
"org.antlr.v4.runtime.tree.xpath"
2032+
],
20172033
"org.apache.bcel:bcel": [
20182034
"org.apache.bcel",
20192035
"org.apache.bcel.classfile",
@@ -2898,6 +2914,10 @@
28982914
"org.slf4j:slf4j-simple": [
28992915
"org.slf4j.impl"
29002916
],
2917+
"org.tomlj:tomlj": [
2918+
"org.tomlj",
2919+
"org.tomlj.internal"
2920+
],
29012921
"org.xmlresolver:xmlresolver": [
29022922
"org.xmlresolver",
29032923
"org.xmlresolver.cache",
@@ -3095,8 +3115,6 @@
30953115
"io.opentelemetry:opentelemetry-sdk-trace",
30963116
"io.opentelemetry:opentelemetry-sdk-trace:jar:sources",
30973117
"io.opentelemetry:opentelemetry-sdk:jar:sources",
3098-
"io.ous:jtoml",
3099-
"io.ous:jtoml:jar:sources",
31003118
"io.projectreactor:reactor-core",
31013119
"io.projectreactor:reactor-core:jar:sources",
31023120
"io.reactivex.rxjava3:rxjava",
@@ -3115,6 +3133,8 @@
31153133
"net.bytebuddy:byte-buddy:jar:sources",
31163134
"net.sf.saxon:Saxon-HE",
31173135
"net.sf.saxon:Saxon-HE:jar:sources",
3136+
"org.antlr:antlr4-runtime",
3137+
"org.antlr:antlr4-runtime:jar:sources",
31183138
"org.apache.bcel:bcel",
31193139
"org.apache.bcel:bcel:jar:sources",
31203140
"org.apache.commons:commons-exec",
@@ -3197,6 +3217,8 @@
31973217
"org.slf4j:slf4j-jdk14:jar:sources",
31983218
"org.slf4j:slf4j-simple",
31993219
"org.slf4j:slf4j-simple:jar:sources",
3220+
"org.tomlj:tomlj",
3221+
"org.tomlj:tomlj:jar:sources",
32003222
"org.xmlresolver:xmlresolver",
32013223
"org.xmlresolver:xmlresolver:jar:data",
32023224
"org.xmlresolver:xmlresolver:jar:sources",

java/src/org/openqa/selenium/grid/config/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ java_library(
2121
"//java/src/org/openqa/selenium/json",
2222
artifact("com.beust:jcommander"),
2323
artifact("com.google.guava:guava"),
24-
artifact("io.ous:jtoml"),
24+
artifact("org.tomlj:tomlj"),
2525
],
2626
)

java/src/org/openqa/selenium/grid/config/TomlConfig.java

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@
1919

2020
import com.google.common.collect.ImmutableList;
2121
import com.google.common.collect.ImmutableSortedSet;
22-
import io.ous.jtoml.JToml;
23-
import io.ous.jtoml.ParseException;
24-
import io.ous.jtoml.Toml;
25-
import io.ous.jtoml.TomlTable;
2622
import java.io.IOException;
2723
import java.io.Reader;
2824
import java.nio.file.Files;
@@ -31,18 +27,31 @@
3127
import java.util.List;
3228
import java.util.Optional;
3329
import java.util.Set;
30+
import java.util.stream.Collectors;
3431
import org.openqa.selenium.internal.Require;
32+
import org.tomlj.Toml;
33+
import org.tomlj.TomlArray;
34+
import org.tomlj.TomlParseError;
35+
import org.tomlj.TomlParseResult;
36+
import org.tomlj.TomlTable;
3537

3638
public class TomlConfig implements Config {
3739

38-
private final Toml toml;
40+
private final TomlParseResult toml;
3941

4042
public TomlConfig(Reader reader) {
4143
try {
42-
toml = JToml.parse(reader);
44+
toml = Toml.parse(reader);
45+
46+
if (toml.hasErrors()) {
47+
String error =
48+
toml.errors().stream().map(TomlParseError::toString).collect(Collectors.joining("\n"));
49+
50+
throw new ConfigException(error);
51+
}
4352
} catch (IOException e) {
4453
throw new ConfigException("Unable to read TOML.", e);
45-
} catch (ParseException e) {
54+
} catch (TomlParseError e) {
4655
throw new ConfigException(
4756
e.getCause()
4857
+ "\n Validate the config using https://www.toml-lint.com/. "
@@ -65,7 +74,7 @@ public Optional<List<String>> getAll(String section, String option) {
6574
Require.nonNull("Section to read", section);
6675
Require.nonNull("Option to read", option);
6776

68-
if (!toml.containsKey(section)) {
77+
if (!toml.contains(section)) {
6978
return Optional.empty();
7079
}
7180

@@ -74,21 +83,28 @@ public Optional<List<String>> getAll(String section, String option) {
7483
throw new ConfigException(String.format("Section %s is not a section! %s", section, raw));
7584
}
7685

77-
TomlTable table = toml.getTomlTable(section);
86+
TomlTable table = toml.getTable(section);
87+
Object value = null;
88+
if (table != null) {
89+
value = table.get(option);
90+
}
7891

79-
Object value = table.getOrDefault(option, null);
8092
if (value == null) {
8193
return Optional.empty();
8294
}
8395

96+
if (value instanceof TomlArray) {
97+
value = ((TomlArray) value).toList();
98+
}
99+
84100
if (value instanceof Collection) {
85101
Collection<?> collection = (Collection<?>) value;
86102
// Case when an array of tables is used as config
87103
// https://toml.io/en/v1.0.0-rc.3#array-of-tables
88-
if (collection.stream().anyMatch(item -> item instanceof TomlTable)) {
104+
if (collection.stream().anyMatch(TomlTable.class::isInstance)) {
89105
return Optional.of(
90106
collection.stream()
91-
.map(item -> (TomlTable) item)
107+
.map(TomlTable.class::cast)
92108
.map(TomlTable::toMap)
93109
.map(this::toEntryList)
94110
.flatMap(Collection::stream)
@@ -106,7 +122,7 @@ public Optional<List<String>> getAll(String section, String option) {
106122
return Optional.of(toEntryList(((TomlTable) value).toMap()));
107123
}
108124

109-
return Optional.of(ImmutableList.of(String.valueOf(value)));
125+
return Optional.of(List.of(String.valueOf(value)));
110126
}
111127

112128
@Override

java/test/org/openqa/selenium/grid/config/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ java_test_suite(
1111
"//java/src/org/openqa/selenium/json",
1212
artifact("com.beust:jcommander"),
1313
artifact("com.google.guava:guava"),
14-
artifact("io.ous:jtoml"),
1514
artifact("org.junit.jupiter:junit-jupiter-api"),
1615
artifact("org.assertj:assertj-core"),
1716
] + JUNIT5_DEPS,

java/test/org/openqa/selenium/grid/config/TomlConfigTest.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.openqa.selenium.grid.config;
1919

2020
import static org.assertj.core.api.Assertions.assertThat;
21+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
2122

2223
import java.io.StringReader;
2324
import java.util.Arrays;
@@ -30,18 +31,24 @@ class TomlConfigTest {
3031

3132
@Test
3233
void shouldUseATableAsASection() {
33-
String raw = "[cheeses]\nselected=brie";
34+
String raw = "[cheeses]\nselected=\"brie\"";
3435
Config config = new TomlConfig(new StringReader(raw));
35-
3636
assertThat(config.get("cheeses", "selected")).isEqualTo(Optional.of("brie"));
3737
}
3838

39+
@Test
40+
void shouldCheckForErrorsAndThrow() {
41+
String raw = "[cheeses]\nselected=brie";
42+
assertThatThrownBy(() -> new TomlConfig(new StringReader(raw)))
43+
.isInstanceOf(ConfigException.class);
44+
}
45+
3946
@Test
4047
void shouldContainConfigFromArrayOfTables() {
4148
String[] rawConfig =
4249
new String[] {
4350
"[cheeses]",
44-
"default = manchego",
51+
"default = \"manchego\"",
4552
"[[cheeses.type]]",
4653
"name = \"soft cheese\"",
4754
"default = \"brie\"",
@@ -104,7 +111,7 @@ void ensureCanReadListOfLists() {
104111
String[] rawConfig =
105112
new String[] {
106113
"[cheeses]",
107-
"default = manchego",
114+
"default = \"manchego\"",
108115
"[[cheeses.type]]",
109116
"name = \"soft cheese\"",
110117
"default = \"brie\"",

java/test/org/openqa/selenium/grid/router/DistributedCdpTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void ensureBasicFunctionality() {
6868
"[node]\n"
6969
+ "selenium-manager = false\n"
7070
+ "driver-implementation = "
71-
+ browser.displayName())));
71+
+ String.format("\"%s\"", browser.displayName()))));
7272

7373
Server<?> server =
7474
new NettyServer(

java/test/org/openqa/selenium/grid/router/RemoteWebDriverBiDiTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void setup() {
7777
"[node]\n"
7878
+ "selenium-manager = false\n"
7979
+ "driver-implementation = "
80-
+ browser.displayName())));
80+
+ String.format("\"%s\"", browser.displayName()))));
8181

8282
driver = new RemoteWebDriver(deployment.getServer().getUrl(), browser.getCapabilities());
8383
driver = new Augmenter().augment(driver);

java/test/org/openqa/selenium/grid/router/RemoteWebDriverDownloadTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void setupServers() {
8484
+ "selenium-manager = true\n"
8585
+ "enable-managed-downloads = true\n"
8686
+ "driver-implementation = "
87-
+ browser.displayName())));
87+
+ String.format("\"%s\"", browser.displayName()))));
8888
tearDowns.add(deployment);
8989

9090
server = deployment.getServer();

java/test/org/openqa/selenium/grid/router/StressTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void setupServers() {
7373
new StringReader(
7474
"[node]\n"
7575
+ "driver-implementation = "
76-
+ browser.displayName()
76+
+ String.format("\"%s\"", browser.displayName())
7777
+ "\n"
7878
+ "session-timeout = 11"
7979
+ "\n"

0 commit comments

Comments
 (0)