Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions common/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ js_library(

http_archive(
name = "linux_beta_firefox",
url = "https://ftp.mozilla.org/pub/firefox/releases/147.0b8/linux-x86_64/en-US/firefox-147.0b8.tar.xz",
sha256 = "3ea7380cc380ab40845a02bc2c82ce6a47dbdc2e36ea970e489872fa4b058c30",
url = "https://ftp.mozilla.org/pub/firefox/releases/147.0b9/linux-x86_64/en-US/firefox-147.0b9.tar.xz",
sha256 = "1de4b07bcb1527f968d17ddfb95c38636806a2fcde3b4ce2b2ce8c69acf55647",
build_file_content = """
load("@aspect_rules_js//js:defs.bzl", "js_library")
package(default_visibility = ["//visibility:public"])
Expand All @@ -72,8 +72,8 @@ js_library(

dmg_archive(
name = "mac_beta_firefox",
url = "https://ftp.mozilla.org/pub/firefox/releases/147.0b8/mac/en-US/Firefox%20147.0b8.dmg",
sha256 = "4e9fcb29079a1f273aa9fe030d00eaedd2fad40f305ca01fa13f5dd37359b358",
url = "https://ftp.mozilla.org/pub/firefox/releases/147.0b9/mac/en-US/Firefox%20147.0b9.dmg",
sha256 = "ec968dfd927703653ac9598f45dc561a8de6721bb906f035b77daec4f6452f88",
build_file_content = """
load("@aspect_rules_js//js:defs.bzl", "js_library")
package(default_visibility = ["//visibility:public"])
Expand Down
2 changes: 1 addition & 1 deletion java/src/org/openqa/selenium/devtools/v141/v141Events.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected JavascriptException toJsException(ExceptionThrown event) {

JavascriptException exception = new JavascriptException(message);

if (!maybeTrace.isPresent()) {
if (maybeTrace.isEmpty()) {
StackTraceElement element =
new StackTraceElement(
"unknown", "unknown", details.getUrl().orElse("unknown"), details.getLineNumber());
Expand Down
2 changes: 1 addition & 1 deletion java/src/org/openqa/selenium/devtools/v142/v142Events.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected JavascriptException toJsException(ExceptionThrown event) {

JavascriptException exception = new JavascriptException(message);

if (!maybeTrace.isPresent()) {
if (maybeTrace.isEmpty()) {
StackTraceElement element =
new StackTraceElement(
"unknown", "unknown", details.getUrl().orElse("unknown"), details.getLineNumber());
Expand Down
2 changes: 1 addition & 1 deletion java/src/org/openqa/selenium/devtools/v143/v143Events.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected JavascriptException toJsException(ExceptionThrown event) {

JavascriptException exception = new JavascriptException(message);

if (!maybeTrace.isPresent()) {
if (maybeTrace.isEmpty()) {
StackTraceElement element =
new StackTraceElement(
"unknown", "unknown", details.getUrl().orElse("unknown"), details.getLineNumber());
Expand Down
7 changes: 3 additions & 4 deletions java/src/org/openqa/selenium/docker/ContainerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@

import static java.util.Collections.emptyList;

import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.openqa.selenium.Beta;
import org.openqa.selenium.internal.Multimap;
import org.openqa.selenium.internal.Require;

@Beta
Expand Down Expand Up @@ -146,7 +145,7 @@ public Image getImage() {
public static ContainerConfig image(Image image) {
return new ContainerConfig(
image,
HashMultimap.create(),
new Multimap<>(),
Map.of(),
Map.of(),
emptyList(),
Expand All @@ -163,7 +162,7 @@ public ContainerConfig map(Port containerPort, Port hostPort) {
String.format("Port protocols must match: %s -> %s", hostPort, containerPort));
}

Multimap<String, Map<String, Object>> updatedBindings = HashMultimap.create(portBindings);
Multimap<String, Map<String, Object>> updatedBindings = new Multimap<>(portBindings);
updatedBindings.put(
containerPort.getPort() + "/" + containerPort.getProtocol(),
Map.of("HostPort", String.valueOf(hostPort.getPort()), "HostIp", ""));
Expand Down
2 changes: 1 addition & 1 deletion java/src/org/openqa/selenium/docker/Docker.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private Optional<DockerProtocol> getDocker() {
}

synchronized (this) {
if (!dockerClient.isPresent()) {
if (dockerClient.isEmpty()) {
VersionCommand versionCommand = new VersionCommand(client);
dockerClient =
apiVersion != null
Expand Down
9 changes: 4 additions & 5 deletions java/src/org/openqa/selenium/docker/VersionCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

package org.openqa.selenium.docker;

import static org.openqa.selenium.internal.Maps.sequencedMapOf;
import static org.openqa.selenium.json.Json.MAP_TYPE;
import static org.openqa.selenium.remote.http.HttpMethod.GET;

import com.google.common.collect.ImmutableMap;
import java.io.UncheckedIOException;
import java.util.Map;
import java.util.Optional;
Expand All @@ -29,22 +29,21 @@
import org.openqa.selenium.internal.Require;
import org.openqa.selenium.json.Json;
import org.openqa.selenium.json.JsonException;
import org.openqa.selenium.remote.http.Contents;
import org.openqa.selenium.remote.http.HttpHandler;
import org.openqa.selenium.remote.http.HttpRequest;
import org.openqa.selenium.remote.http.HttpResponse;

class VersionCommand {

private static final Json JSON = new Json();
// Insertion order matters, and is preserved by ImmutableMap.
// Insertion order matters.
// Map Docker API versions to their implementations
// 1.48 is for Docker Engine v28+ with multi-platform and gateway priority support
// 1.44 is for Docker Engine v25+ with multi-network and modern features
// 1.40 is maintained for backward compatibility with legacy engines (Docker v19.03+)
// All use the same generic implementation with version-specific adapters
private static final Map<Version, Function<HttpHandler, DockerProtocol>> SUPPORTED_VERSIONS =
ImmutableMap.of(
sequencedMapOf(
new Version("1.48"), client -> new DockerClient(client, "1.48"),
new Version("1.44"), client -> new DockerClient(client, "1.44"),
new Version("1.40"), client -> new DockerClient(client, "1.40"));
Expand Down Expand Up @@ -91,7 +90,7 @@ public Optional<DockerProtocol> getDockerProtocol() {
return Optional.empty();
}

Map<String, Object> raw = JSON.toType(Contents.string(res), MAP_TYPE);
Map<String, Object> raw = JSON.toType(res.contentAsString(), MAP_TYPE);

Version maxVersion = new Version((String) raw.get("ApiVersion"));
Version minVersion = new Version((String) raw.get("MinAPIVersion"));
Expand Down
5 changes: 3 additions & 2 deletions java/src/org/openqa/selenium/grid/TemplateGridCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@

package org.openqa.selenium.grid;

import static org.openqa.selenium.internal.Sets.haveCommonElements;

import com.beust.jcommander.JCommander;
import com.beust.jcommander.ParameterDescription;
import com.beust.jcommander.ParameterException;
import com.beust.jcommander.internal.DefaultConsole;
import com.google.common.collect.Sets;
import java.io.PrintStream;
import java.util.LinkedHashSet;
import java.util.ServiceLoader;
Expand Down Expand Up @@ -53,7 +54,7 @@ public final Executable configure(PrintStream out, PrintStream err, String... ar
allFlags.add(configFlags);

StreamSupport.stream(ServiceLoader.load(HasRoles.class).spliterator(), false)
.filter(flags -> !Sets.intersection(getConfigurableRoles(), flags.getRoles()).isEmpty())
.filter(flags -> haveCommonElements(getConfigurableRoles(), flags.getRoles()))
.forEach(allFlags::add);

JCommander.Builder builder = JCommander.newBuilder().programName(getName());
Expand Down
1 change: 1 addition & 0 deletions java/src/org/openqa/selenium/grid/commands/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@ java_library(
"//java/src/org/openqa/selenium/remote",
artifact("com.beust:jcommander"),
artifact("com.google.guava:guava"),
artifact("org.jspecify:jspecify"),
],
)
18 changes: 14 additions & 4 deletions java/src/org/openqa/selenium/grid/commands/InfoCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,24 @@

package org.openqa.selenium.grid.commands;

import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Objects.requireNonNull;

import com.beust.jcommander.JCommander;
import com.beust.jcommander.ParameterException;
import com.beust.jcommander.internal.DefaultConsole;
import com.google.auto.service.AutoService;
import com.google.common.io.Resources;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.StringReader;
import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.Set;
import java.util.regex.Pattern;
import org.jspecify.annotations.NonNull;
import org.openqa.selenium.cli.CliCommand;
import org.openqa.selenium.cli.WrappedPrintWriter;
import org.openqa.selenium.grid.config.Role;
Expand Down Expand Up @@ -130,8 +133,7 @@ public Executable configure(PrintStream out, PrintStream err, String... args) {
}

private String readContent(String path) throws IOException {
String unformattedText =
Resources.toString(Resources.getResource(path), StandardCharsets.UTF_8);
String unformattedText = unformattedText(path);
StringBuilder formattedText = new StringBuilder();
try (BufferedReader reader = new BufferedReader(new StringReader(unformattedText))) {
boolean inCode = false;
Expand Down Expand Up @@ -161,4 +163,12 @@ private String readContent(String path) throws IOException {

return formattedText.toString();
}

@NonNull
private String unformattedText(String path) throws IOException {
try (InputStream in = getClass().getClassLoader().getResourceAsStream(path)) {
requireNonNull(in, () -> "Resource is not found in classpath: " + path);
return new String(in.readAllBytes(), UTF_8);
}
}
}
6 changes: 3 additions & 3 deletions java/src/org/openqa/selenium/grid/config/AnnotatedConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
package org.openqa.selenium.grid.config;

import static java.util.Collections.emptyMap;
import static java.util.Collections.unmodifiableSet;

import com.beust.jcommander.Parameter;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.primitives.Primitives;
import java.lang.reflect.Field;
import java.util.ArrayDeque;
Expand Down Expand Up @@ -180,12 +180,12 @@ public Optional<List<String>> getAll(String section, String option) {

@Override
public Set<String> getSectionNames() {
return ImmutableSortedSet.copyOf(config.keySet());
return unmodifiableSet(config.keySet());
}

@Override
public Set<String> getOptions(String section) {
Require.nonNull("Section name to get options for", section);
return ImmutableSortedSet.copyOf(config.getOrDefault(section, emptyMap()).keySet());
return unmodifiableSet(config.getOrDefault(section, emptyMap()).keySet());
}
}
7 changes: 3 additions & 4 deletions java/src/org/openqa/selenium/grid/config/CompoundConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@

package org.openqa.selenium.grid.config;

import static com.google.common.collect.ImmutableSortedSet.toImmutableSortedSet;
import static java.util.Comparator.naturalOrder;
import static java.util.stream.Collectors.toUnmodifiableList;
import static org.openqa.selenium.internal.Sets.toSortedSet;

import java.util.Collection;
import java.util.List;
Expand Down Expand Up @@ -60,7 +59,7 @@ public Set<String> getSectionNames() {
return allConfigs.stream()
.map(Config::getSectionNames)
.flatMap(Collection::stream)
.collect(toImmutableSortedSet(naturalOrder()));
.collect(toSortedSet());
}

@Override
Expand All @@ -70,6 +69,6 @@ public Set<String> getOptions(String section) {
return allConfigs.stream()
.map(config -> config.getOptions(section))
.flatMap(Collection::stream)
.collect(toImmutableSortedSet(naturalOrder()));
.collect(toSortedSet());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@

package org.openqa.selenium.grid.config;

import static java.util.Comparator.naturalOrder;
import static java.util.stream.Collectors.toUnmodifiableMap;
import static org.openqa.selenium.internal.Sets.toSortedSet;

import com.google.common.collect.ImmutableSortedSet;
import java.util.AbstractMap;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -75,7 +74,7 @@ public Set<String> getSectionNames() {
.filter(key -> key.indexOf(separator) > -1)
.map(key -> key.substring(0, key.indexOf(separator)))
.map(key -> key.toLowerCase(Locale.ENGLISH))
.collect(ImmutableSortedSet.toImmutableSortedSet(naturalOrder()));
.collect(toSortedSet());
}

@Override
Expand All @@ -89,6 +88,6 @@ public Set<String> getOptions(String section) {
.filter(key -> key.length() > actualPrefix.length() + 1)
.map(key -> key.substring(actualPrefix.length()))
.map(key -> key.toLowerCase(Locale.ENGLISH))
.collect(ImmutableSortedSet.toImmutableSortedSet(naturalOrder()));
.collect(toSortedSet());
}
}
2 changes: 1 addition & 1 deletion java/src/org/openqa/selenium/grid/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ default Optional<Boolean> getBool(String section, String option) {

default Optional<List<List<String>>> getArray(String section, String option) {
Optional<List<String>> flatConfigs = getAll(section, option);
if (!flatConfigs.isPresent()) {
if (flatConfigs.isEmpty()) {
return Optional.empty();
}

Expand Down
16 changes: 9 additions & 7 deletions java/src/org/openqa/selenium/grid/config/ConfigFlags.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@

package org.openqa.selenium.grid.config;

import static java.util.Collections.unmodifiableSet;
import static org.openqa.selenium.grid.config.StandardGridRoles.ALL_ROLES;

import com.beust.jcommander.Parameter;
import com.google.common.collect.ImmutableSortedSet;
import java.io.PrintStream;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.stream.Collectors;
import org.openqa.selenium.json.Json;

Expand Down Expand Up @@ -103,12 +104,13 @@ public boolean dumpConfigHelp(Config config, Set<Role> currentRoles, PrintStream
.collect(
Collectors.toMap(
DescribedOption::section,
ImmutableSortedSet::of,
(l, r) ->
ImmutableSortedSet.<DescribedOption>naturalOrder()
.addAll(l)
.addAll(r)
.build()));
Set::of,
(l, r) -> {
TreeSet<DescribedOption> set = new TreeSet<>();
set.addAll(l);
set.addAll(r);
return unmodifiableSet(set);
}));

StringBuilder demoToml = new StringBuilder();
demoToml.append("Configuration help for Toml config file").append("\n\n");
Expand Down
Loading
Loading