diff --git a/java/src/org/openqa/selenium/support/events/BUILD.bazel b/java/src/org/openqa/selenium/support/events/BUILD.bazel index 0e5f92fbe2384..f5d99d373519f 100644 --- a/java/src/org/openqa/selenium/support/events/BUILD.bazel +++ b/java/src/org/openqa/selenium/support/events/BUILD.bazel @@ -1,4 +1,3 @@ -load("@rules_jvm_external//:defs.bzl", "artifact") load("//java:defs.bzl", "java_library") java_library( @@ -10,6 +9,5 @@ java_library( deps = [ "//java/src/org/openqa/selenium:core", "//java/src/org/openqa/selenium/support/decorators", - artifact("com.google.guava:guava"), ], ) diff --git a/java/src/org/openqa/selenium/support/events/EventFiringDecorator.java b/java/src/org/openqa/selenium/support/events/EventFiringDecorator.java index b9998ef9de231..b3ce8a46a4b69 100644 --- a/java/src/org/openqa/selenium/support/events/EventFiringDecorator.java +++ b/java/src/org/openqa/selenium/support/events/EventFiringDecorator.java @@ -17,7 +17,6 @@ package org.openqa.selenium.support.events; -import com.google.common.primitives.Primitives; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Arrays; @@ -316,7 +315,29 @@ private boolean parametersMatch(Method m, Object[] args) { return false; } for (int i = 0; i < params.length; i++) { - if (args[i] != null && !Primitives.wrap(params[i]).isAssignableFrom(args[i].getClass())) { + Class param = params[i]; + if (param.isPrimitive()) { + if (boolean.class.equals(param)) { + param = Boolean.class; + } else if (byte.class.equals(param)) { + param = Byte.class; + } else if (char.class.equals(param)) { + param = Character.class; + } else if (double.class.equals(param)) { + param = Double.class; + } else if (float.class.equals(param)) { + param = Float.class; + } else if (int.class.equals(param)) { + param = Integer.class; + } else if (long.class.equals(param)) { + param = Long.class; + } else if (short.class.equals(param)) { + param = Short.class; + } else if (void.class.equals(param)) { + param = Void.class; + } + } + if (args[i] != null && !param.isAssignableFrom(args[i].getClass())) { return false; } } diff --git a/java/src/org/openqa/selenium/support/locators/BUILD.bazel b/java/src/org/openqa/selenium/support/locators/BUILD.bazel index 76e4332a568d7..6a43703d981c0 100644 --- a/java/src/org/openqa/selenium/support/locators/BUILD.bazel +++ b/java/src/org/openqa/selenium/support/locators/BUILD.bazel @@ -1,4 +1,3 @@ -load("@rules_jvm_external//:defs.bzl", "artifact") load("//common:defs.bzl", "copy_file") load("//java:defs.bzl", "java_library") @@ -16,7 +15,6 @@ java_library( "//java:auto-service", "//java/src/org/openqa/selenium/json", "//java/src/org/openqa/selenium/remote", - artifact("com.google.guava:guava"), ], ) diff --git a/java/src/org/openqa/selenium/support/locators/RelativeLocator.java b/java/src/org/openqa/selenium/support/locators/RelativeLocator.java index aa2b9c8808132..4ad1f58b8d4c8 100644 --- a/java/src/org/openqa/selenium/support/locators/RelativeLocator.java +++ b/java/src/org/openqa/selenium/support/locators/RelativeLocator.java @@ -20,10 +20,10 @@ import static org.openqa.selenium.json.Json.MAP_TYPE; import static org.openqa.selenium.support.locators.RelativeLocatorScript.FIND_ELEMENTS; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.SearchContext; @@ -82,7 +82,7 @@ public static class RelativeBy extends By implements By.Remotable { private final List> filters; private RelativeBy(Object rootLocator) { - this(rootLocator, ImmutableList.of()); + this(rootLocator, List.of()); } private RelativeBy(Object rootLocator, List> filters) { @@ -100,7 +100,7 @@ private RelativeBy(Object rootLocator, List> filters) { } this.root = Require.nonNull("Root locator", rootLocator); - this.filters = ImmutableList.copyOf(Require.nonNull("Filters", filters)); + this.filters = List.copyOf(Require.nonNull("Filters", filters)); } public RelativeBy above(WebElement element) { @@ -178,11 +178,11 @@ private RelativeBy near(Object locator, int atMostDistanceInPixels) { return new RelativeBy( root, amend( - ImmutableMap.of( + Map.of( "kind", "near", "args", - ImmutableList.of(asAtomLocatorParameter(locator), atMostDistanceInPixels)))); + List.of(asAtomLocatorParameter(locator), atMostDistanceInPixels)))); } @Override @@ -200,24 +200,21 @@ private RelativeBy simpleDirection(String direction, Object locator) { Require.nonNull("Locator", locator); return new RelativeBy( - root, - amend( - ImmutableMap.of( - "kind", direction, "args", ImmutableList.of(asAtomLocatorParameter(locator))))); + root, amend(Map.of("kind", direction, "args", List.of(asAtomLocatorParameter(locator))))); } private List> amend(Map toAdd) { - return ImmutableList.>builder().addAll(filters).add(toAdd).build(); + return Stream.concat(filters.stream(), Stream.of(toAdd)) + .collect(Collectors.toUnmodifiableList()); } @Override public Parameters getRemoteParameters() { - return new Parameters("relative", ImmutableMap.of("root", root, "filters", filters)); + return new Parameters("relative", Map.of("root", root, "filters", filters)); } private Map toJson() { - return ImmutableMap.of( - "using", "relative", "value", ImmutableMap.of("root", root, "filters", filters)); + return Map.of("using", "relative", "value", Map.of("root", root, "filters", filters)); } } @@ -244,7 +241,7 @@ private static Object asAtomLocatorParameter(Object object) { "Expected JSON encoded form of locator to have a 'value' field: " + raw); } - return ImmutableMap.of((String) raw.get("using"), raw.get("value")); + return Map.of((String) raw.get("using"), raw.get("value")); } private static void assertLocatorCanBeSerialized(Object locator) { diff --git a/java/src/org/openqa/selenium/support/locators/RelativeLocatorScript.java b/java/src/org/openqa/selenium/support/locators/RelativeLocatorScript.java index d6137edd52541..9768e1d32ac0d 100644 --- a/java/src/org/openqa/selenium/support/locators/RelativeLocatorScript.java +++ b/java/src/org/openqa/selenium/support/locators/RelativeLocatorScript.java @@ -17,10 +17,9 @@ package org.openqa.selenium.support.locators; -import com.google.common.io.Resources; import java.io.IOException; +import java.io.InputStream; import java.io.UncheckedIOException; -import java.net.URL; import java.nio.charset.StandardCharsets; class RelativeLocatorScript { @@ -34,9 +33,11 @@ class RelativeLocatorScript { "/%s/%s", RelativeLocator.class.getPackage().getName().replace(".", "/"), "findElements.js"); - URL url = RelativeLocator.class.getResource(location); + String rawFunction; + try (InputStream stream = RelativeLocator.class.getResourceAsStream(location)) { + rawFunction = new String(stream.readAllBytes(), StandardCharsets.UTF_8); + } - String rawFunction = Resources.toString(url, StandardCharsets.UTF_8); FIND_ELEMENTS = String.format("/* findElements */return (%s).apply(null, arguments);", rawFunction); } catch (IOException e) { diff --git a/java/src/org/openqa/selenium/support/locators/RelativeLocatorServerSide.java b/java/src/org/openqa/selenium/support/locators/RelativeLocatorServerSide.java index 827fc2be33b16..6b58e457a716f 100644 --- a/java/src/org/openqa/selenium/support/locators/RelativeLocatorServerSide.java +++ b/java/src/org/openqa/selenium/support/locators/RelativeLocatorServerSide.java @@ -20,8 +20,8 @@ import static org.openqa.selenium.support.locators.RelativeLocatorScript.FIND_ELEMENTS; import com.google.auto.service.AutoService; -import com.google.common.collect.ImmutableMap; import java.util.List; +import java.util.Map; import org.openqa.selenium.By; import org.openqa.selenium.InvalidArgumentException; import org.openqa.selenium.JavascriptExecutor; @@ -64,8 +64,7 @@ public List findElements(SearchContext context) { @SuppressWarnings("unchecked") List elements = - (List) - js.executeScript(FIND_ELEMENTS, ImmutableMap.of("relative", converted)); + (List) js.executeScript(FIND_ELEMENTS, Map.of("relative", converted)); return elements; } diff --git a/java/src/org/openqa/selenium/support/ui/BUILD.bazel b/java/src/org/openqa/selenium/support/ui/BUILD.bazel index c6d6546630af9..3561037e59124 100644 --- a/java/src/org/openqa/selenium/support/ui/BUILD.bazel +++ b/java/src/org/openqa/selenium/support/ui/BUILD.bazel @@ -11,7 +11,6 @@ java_library( "//java/test/org/openqa/selenium/support:__subpackages__", ], deps = [ - artifact("com.google.guava:guava"), ], ) diff --git a/java/src/org/openqa/selenium/support/ui/FluentWait.java b/java/src/org/openqa/selenium/support/ui/FluentWait.java index 76619788de137..9442b22552988 100644 --- a/java/src/org/openqa/selenium/support/ui/FluentWait.java +++ b/java/src/org/openqa/selenium/support/ui/FluentWait.java @@ -18,7 +18,6 @@ package org.openqa.selenium.support.ui; import com.google.common.base.Throwables; -import com.google.common.collect.ImmutableList; import java.time.Clock; import java.time.Duration; import java.time.Instant; @@ -163,7 +162,7 @@ public FluentWait ignoreAll(Collection ignoring(Class exceptionType) { - return this.ignoreAll(ImmutableList.>of(exceptionType)); + return this.ignoreAll(List.>of(exceptionType)); } /** @@ -175,7 +174,7 @@ public FluentWait ignoring(Class exceptionType) { public FluentWait ignoring( Class firstType, Class secondType) { - return this.ignoreAll(ImmutableList.of(firstType, secondType)); + return this.ignoreAll(List.of(firstType, secondType)); } /**