Skip to content

Commit 2990021

Browse files
committed
[grid] Replace Guava map,list and set with Java equivalent for Node
1 parent 55f02a9 commit 2990021

19 files changed

+178
-164
lines changed

java/src/org/openqa/selenium/grid/graphql/Grid.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717

1818
package org.openqa.selenium.grid.graphql;
1919

20-
import com.google.common.collect.ImmutableList;
2120
import java.net.URI;
2221
import java.util.ArrayList;
2322
import java.util.Collection;
23+
import java.util.Collections;
2424
import java.util.HashMap;
2525
import java.util.List;
2626
import java.util.Map;
@@ -68,7 +68,7 @@ public String getVersion() {
6868
}
6969

7070
public List<Node> getNodes() {
71-
ImmutableList.Builder<Node> toReturn = ImmutableList.builder();
71+
List<Node> toReturn = new ArrayList<>();
7272

7373
for (NodeStatus status : distributorStatus.getNodes()) {
7474
Map<Capabilities, Integer> stereotypes = new HashMap<>();
@@ -105,7 +105,7 @@ public List<Node> getNodes() {
105105
osInfo));
106106
}
107107

108-
return toReturn.build();
108+
return Collections.unmodifiableList(toReturn);
109109
}
110110

111111
public int getNodeCount() {

java/src/org/openqa/selenium/grid/node/CapabilityResponseEncoder.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919

2020
import static java.nio.charset.StandardCharsets.UTF_8;
2121

22-
import com.google.common.collect.ImmutableMap;
22+
import java.util.Collections;
23+
import java.util.HashMap;
2324
import java.util.Map;
2425
import java.util.function.BiFunction;
2526
import java.util.function.Function;
@@ -85,7 +86,7 @@ public byte[] apply(Session session, Map<String, Object> metadata) {
8586

8687
@Override
8788
public byte[] apply(Session session) {
88-
return apply(session, ImmutableMap.of());
89+
return apply(session, Map.of());
8990
}
9091

9192
/** Create a UTF-8 encoded response for a given dialect for use with the New Session command. */
@@ -108,14 +109,14 @@ private static byte[] encodeAsResponse(
108109

109110
private static Map<String, Object> encodeW3C(
110111
SessionId id, Capabilities capabilities, Map<String, Object> metadata) {
111-
return ImmutableMap.<String, Object>builder()
112-
.putAll(metadata)
113-
.put(
114-
"value",
115-
ImmutableMap.of(
116-
"sessionId", id,
117-
"capabilities", capabilities))
118-
.build();
112+
Map<String, Object> encodedResult = new HashMap<>(metadata);
113+
encodedResult.put(
114+
"value",
115+
Map.of(
116+
"sessionId", id,
117+
"capabilities", capabilities));
118+
119+
return Collections.unmodifiableMap(encodedResult);
119120
}
120121
}
121122
}

java/src/org/openqa/selenium/grid/node/CustomLocatorHandler.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
import static org.openqa.selenium.json.Json.MAP_TYPE;
2222

2323
import com.google.common.annotations.VisibleForTesting;
24-
import com.google.common.collect.ImmutableMap;
25-
import com.google.common.collect.ImmutableSet;
2624
import java.io.IOException;
2725
import java.io.UncheckedIOException;
2826
import java.util.Map;
@@ -72,7 +70,7 @@ class CustomLocatorHandler implements Routable {
7270
new UrlTemplate("/session/{sessionId}/element/{elementId}/elements");
7371
// These are derived from the w3c webdriver spec
7472
private static final Set<String> W3C_STRATEGIES =
75-
ImmutableSet.of("css selector", "link text", "partial link text", "tag name", "xpath");
73+
Set.of("css selector", "link text", "partial link text", "tag name", "xpath");
7674
private final HttpHandler toNode;
7775
private final Map<String, Function<Object, By>> extraLocators;
7876

@@ -119,9 +117,9 @@ public HttpResponse execute(HttpRequest req) throws UncheckedIOException {
119117
.setStatus(HTTP_BAD_REQUEST)
120118
.setContent(
121119
Contents.asJson(
122-
ImmutableMap.of(
120+
Map.of(
123121
"value",
124-
ImmutableMap.of(
122+
Map.of(
125123
"error", "invalid argument",
126124
"message", "Unable to determine element locating strategy",
127125
"stacktrace", ""))));
@@ -138,9 +136,9 @@ public HttpResponse execute(HttpRequest req) throws UncheckedIOException {
138136
.setStatus(HTTP_BAD_REQUEST)
139137
.setContent(
140138
Contents.asJson(
141-
ImmutableMap.of(
139+
Map.of(
142140
"value",
143-
ImmutableMap.of(
141+
Map.of(
144142
"error", "invalid argument",
145143
"message", "Unable to determine element locator arguments",
146144
"stacktrace", ""))));
@@ -224,7 +222,7 @@ public HttpResponse execute(HttpRequest req) throws UncheckedIOException {
224222
toReturn = context.findElement(by);
225223
}
226224

227-
return new HttpResponse().setContent(Contents.asJson(ImmutableMap.of("value", toReturn)));
225+
return new HttpResponse().setContent(Contents.asJson(Map.of("value", toReturn)));
228226
}
229227

230228
private static class NodeWrappingExecutor implements CommandExecutor {

java/src/org/openqa/selenium/grid/node/GetNodeSession.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
import static org.openqa.selenium.remote.http.Contents.asJson;
2121

22-
import com.google.common.collect.ImmutableMap;
2322
import java.io.UncheckedIOException;
23+
import java.util.Map;
2424
import org.openqa.selenium.grid.data.Session;
2525
import org.openqa.selenium.internal.Require;
2626
import org.openqa.selenium.remote.SessionId;
@@ -42,6 +42,6 @@ class GetNodeSession implements HttpHandler {
4242
public HttpResponse execute(HttpRequest req) throws UncheckedIOException {
4343
Session session = node.getSession(id);
4444

45-
return new HttpResponse().setContent(asJson(ImmutableMap.of("value", session)));
45+
return new HttpResponse().setContent(asJson(Map.of("value", session)));
4646
}
4747
}

java/src/org/openqa/selenium/grid/node/IsSessionOwner.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
import static org.openqa.selenium.remote.http.Contents.asJson;
2121

22-
import com.google.common.collect.ImmutableMap;
2322
import java.io.UncheckedIOException;
23+
import java.util.Map;
2424
import org.openqa.selenium.internal.Require;
2525
import org.openqa.selenium.remote.SessionId;
2626
import org.openqa.selenium.remote.http.HttpHandler;
@@ -39,6 +39,6 @@ class IsSessionOwner implements HttpHandler {
3939

4040
@Override
4141
public HttpResponse execute(HttpRequest req) throws UncheckedIOException {
42-
return new HttpResponse().setContent(asJson(ImmutableMap.of("value", node.isSessionOwner(id))));
42+
return new HttpResponse().setContent(asJson(Map.of("value", node.isSessionOwner(id))));
4343
}
4444
}

java/src/org/openqa/selenium/grid/node/NewNodeSession.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
import static org.openqa.selenium.remote.http.Contents.asJson;
2121
import static org.openqa.selenium.remote.http.Contents.string;
2222

23-
import com.google.common.collect.ImmutableMap;
2423
import java.io.UncheckedIOException;
2524
import java.util.HashMap;
25+
import java.util.Map;
2626
import org.openqa.selenium.WebDriverException;
2727
import org.openqa.selenium.grid.data.CreateSessionRequest;
2828
import org.openqa.selenium.grid.data.CreateSessionResponse;
@@ -58,7 +58,7 @@ public HttpResponse execute(HttpRequest req) throws UncheckedIOException {
5858
WebDriverException exception = result.left();
5959
response.put(
6060
"exception",
61-
ImmutableMap.of(
61+
Map.of(
6262
"error", exception.getClass(),
6363
"message", exception.getMessage()));
6464
}

java/src/org/openqa/selenium/grid/node/Node.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import static org.openqa.selenium.remote.http.Route.matching;
2626
import static org.openqa.selenium.remote.http.Route.post;
2727

28-
import com.google.common.collect.ImmutableMap;
2928
import java.io.IOException;
3029
import java.net.URI;
3130
import java.time.Duration;
@@ -125,7 +124,7 @@ public abstract class Node implements HasReadyState, Routable {
125124

126125
private static final Logger LOG = Logger.getLogger(Node.class.getName());
127126
private static final BuildInfo INFO = new BuildInfo();
128-
private static final ImmutableMap<String, String> OS_INFO = loadOsInfo();
127+
private static final Map<String, String> OS_INFO = loadOsInfo();
129128
protected final Tracer tracer;
130129
private final NodeId id;
131130
private final URI uri;
@@ -206,8 +205,8 @@ protected Node(
206205
get("/status").to(() -> new StatusHandler(this)).with(spanDecorator("node.status")));
207206
}
208207

209-
private static ImmutableMap<String, String> loadOsInfo() {
210-
return ImmutableMap.of(
208+
private static Map<String, String> loadOsInfo() {
209+
return Map.of(
211210
"arch", System.getProperty("os.arch"),
212211
"name", System.getProperty("os.name"),
213212
"version", System.getProperty("os.version"));
@@ -233,7 +232,7 @@ public String getNodeVersion() {
233232
return String.format("%s (revision %s)", INFO.getReleaseLabel(), INFO.getBuildRevision());
234233
}
235234

236-
public ImmutableMap<String, String> getOsInfo() {
235+
public Map<String, String> getOsInfo() {
237236
return OS_INFO;
238237
}
239238

java/src/org/openqa/selenium/grid/node/ProxyNodeWebsockets.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
import static org.openqa.selenium.internal.Debug.getDebugLogLevel;
2121
import static org.openqa.selenium.remote.http.HttpMethod.GET;
2222

23-
import com.google.common.collect.ImmutableSet;
2423
import java.net.URI;
2524
import java.net.URISyntaxException;
2625
import java.util.Objects;
2726
import java.util.Optional;
27+
import java.util.Set;
2828
import java.util.function.BiFunction;
2929
import java.util.function.Consumer;
3030
import java.util.logging.Level;
@@ -53,8 +53,8 @@ public class ProxyNodeWebsockets
5353
private static final UrlTemplate FWD_TEMPLATE = new UrlTemplate("/session/{sessionId}/se/fwd");
5454
private static final UrlTemplate VNC_TEMPLATE = new UrlTemplate("/session/{sessionId}/se/vnc");
5555
private static final Logger LOG = Logger.getLogger(ProxyNodeWebsockets.class.getName());
56-
private static final ImmutableSet<String> CDP_ENDPOINT_CAPS =
57-
ImmutableSet.of("goog:chromeOptions", "ms:edgeOptions");
56+
private static final Set<String> CDP_ENDPOINT_CAPS =
57+
Set.of("goog:chromeOptions", "ms:edgeOptions");
5858
private final HttpClient.Factory clientFactory;
5959
private final Node node;
6060
private final String gridSubPath;

java/src/org/openqa/selenium/grid/node/StatusHandler.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
import static org.openqa.selenium.remote.http.Contents.asJson;
2121

22-
import com.google.common.collect.ImmutableMap;
2322
import java.io.UncheckedIOException;
23+
import java.util.Map;
2424
import org.openqa.selenium.grid.data.NodeStatus;
2525
import org.openqa.selenium.internal.Require;
2626
import org.openqa.selenium.remote.http.HttpHandler;
@@ -39,10 +39,10 @@ class StatusHandler implements HttpHandler {
3939
public HttpResponse execute(HttpRequest req) throws UncheckedIOException {
4040
NodeStatus status = node.getStatus();
4141

42-
ImmutableMap<String, Object> report =
43-
ImmutableMap.of(
42+
Map<String, Object> report =
43+
Map.of(
4444
"value",
45-
ImmutableMap.of(
45+
Map.of(
4646
"ready",
4747
status.hasCapacity(),
4848
"message",

0 commit comments

Comments
 (0)