Skip to content

Commit

Permalink
[java] removed use of guava from browser packages
Browse files Browse the repository at this point in the history
  • Loading branch information
joerg1985 committed Oct 14, 2023
1 parent 2d89118 commit 42cc355
Show file tree
Hide file tree
Showing 22 changed files with 85 additions and 109 deletions.
2 changes: 0 additions & 2 deletions java/src/org/openqa/selenium/chrome/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
load("@rules_jvm_external//:defs.bzl", "artifact")
load("//java:defs.bzl", "java_export")
load("//java:version.bzl", "SE_VERSION")

Expand All @@ -18,6 +17,5 @@ java_export(
"//java/src/org/openqa/selenium/json",
"//java/src/org/openqa/selenium/manager",
"//java/src/org/openqa/selenium/remote",
artifact("com.google.guava:guava"),
],
)
11 changes: 6 additions & 5 deletions java/src/org/openqa/selenium/chrome/ChromeDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@

package org.openqa.selenium.chrome;

import com.google.common.collect.ImmutableMap;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.openqa.selenium.Beta;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebDriver;
Expand Down Expand Up @@ -116,10 +117,10 @@ public ChromeDriverCommandExecutor(DriverService service, ClientConfig clientCon
}

private static Map<String, CommandInfo> getExtraCommands() {
return ImmutableMap.<String, CommandInfo>builder()
.putAll(new AddHasCasting().getAdditionalCommands())
.putAll(new AddHasCdp().getAdditionalCommands())
.build();
return Stream.of(
new AddHasCasting().getAdditionalCommands(), new AddHasCdp().getAdditionalCommands())
.flatMap((m) -> m.entrySet().stream())
.collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue));
}
}
}
2 changes: 0 additions & 2 deletions java/src/org/openqa/selenium/chromium/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
load("@rules_jvm_external//:defs.bzl", "artifact")
load("//java:defs.bzl", "java_export")
load("//java:version.bzl", "SE_VERSION")

Expand All @@ -17,6 +16,5 @@ java_export(
"//java:auto-service",
"//java/src/org/openqa/selenium/json",
"//java/src/org/openqa/selenium/remote",
artifact("com.google.guava:guava"),
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@

package org.openqa.selenium.chromium;

import com.google.common.collect.ImmutableMap;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.openqa.selenium.remote.CommandInfo;
import org.openqa.selenium.remote.http.ClientConfig;
import org.openqa.selenium.remote.service.DriverCommandExecutor;
Expand All @@ -44,11 +45,12 @@ public ChromiumDriverCommandExecutor(
}

private static Map<String, CommandInfo> getExtraCommands(Map<String, CommandInfo> commands) {
return ImmutableMap.<String, CommandInfo>builder()
.putAll(commands)
.putAll(new AddHasNetworkConditions().getAdditionalCommands())
.putAll(new AddHasPermissions().getAdditionalCommands())
.putAll(new AddHasLaunchApp().getAdditionalCommands())
.build();
return Stream.of(
commands,
new AddHasNetworkConditions().getAdditionalCommands(),
new AddHasPermissions().getAdditionalCommands(),
new AddHasLaunchApp().getAdditionalCommands())
.flatMap((m) -> m.entrySet().stream())
.collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue));
}
}
20 changes: 9 additions & 11 deletions java/src/org/openqa/selenium/chromium/ChromiumDriverLogLevel.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.openqa.selenium.chromium;

import com.google.common.collect.ImmutableMap;
import java.util.Map;
import java.util.logging.Level;

Expand All @@ -35,16 +34,15 @@ public enum ChromiumDriverLogLevel {
OFF;

private static final Map<Level, ChromiumDriverLogLevel> logLevelToChromeLevelMap =
new ImmutableMap.Builder<Level, ChromiumDriverLogLevel>()
.put(Level.ALL, ALL)
.put(Level.FINEST, DEBUG)
.put(Level.FINER, DEBUG)
.put(Level.FINE, DEBUG)
.put(Level.INFO, INFO)
.put(Level.WARNING, WARNING)
.put(Level.SEVERE, SEVERE)
.put(Level.OFF, OFF)
.build();
Map.of(
Level.ALL, ALL,
Level.FINEST, DEBUG,
Level.FINER, DEBUG,
Level.FINE, DEBUG,
Level.INFO, INFO,
Level.WARNING, WARNING,
Level.SEVERE, SEVERE,
Level.OFF, OFF);

@Override
public String toString() {
Expand Down
3 changes: 1 addition & 2 deletions java/src/org/openqa/selenium/edge/AddHasCasting.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static org.openqa.selenium.remote.Browser.EDGE;

import com.google.auto.service.AutoService;
import com.google.common.collect.ImmutableMap;
import java.util.Map;
import java.util.function.Predicate;
import org.openqa.selenium.Capabilities;
Expand All @@ -34,7 +33,7 @@
public class AddHasCasting extends org.openqa.selenium.chromium.AddHasCasting {

private static final Map<String, CommandInfo> COMMANDS =
ImmutableMap.of(
Map.of(
GET_CAST_SINKS, new CommandInfo("session/:sessionId/ms/cast/get_sinks", HttpMethod.GET),
SET_CAST_SINK_TO_USE,
new CommandInfo("session/:sessionId/ms/cast/set_sink_to_use", HttpMethod.POST),
Expand Down
4 changes: 1 addition & 3 deletions java/src/org/openqa/selenium/edge/AddHasCdp.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static org.openqa.selenium.remote.Browser.EDGE;

import com.google.auto.service.AutoService;
import com.google.common.collect.ImmutableMap;
import java.util.Map;
import java.util.function.Predicate;
import org.openqa.selenium.Capabilities;
Expand All @@ -34,8 +33,7 @@
public class AddHasCdp extends org.openqa.selenium.chromium.AddHasCdp {

private static final Map<String, CommandInfo> COMMANDS =
ImmutableMap.of(
EXECUTE_CDP, new CommandInfo("session/:sessionId/ms/cdp/execute", HttpMethod.POST));
Map.of(EXECUTE_CDP, new CommandInfo("session/:sessionId/ms/cdp/execute", HttpMethod.POST));

@Override
public Map<String, CommandInfo> getAdditionalCommands() {
Expand Down
2 changes: 0 additions & 2 deletions java/src/org/openqa/selenium/edge/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
load("@rules_jvm_external//:defs.bzl", "artifact")
load("//java:defs.bzl", "java_export")
load("//java:version.bzl", "SE_VERSION")

Expand All @@ -19,6 +18,5 @@ java_export(
"//java/src/org/openqa/selenium/chromium",
"//java/src/org/openqa/selenium/manager",
"//java/src/org/openqa/selenium/remote",
artifact("com.google.guava:guava"),
],
)
11 changes: 6 additions & 5 deletions java/src/org/openqa/selenium/edge/EdgeDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
// under the License.
package org.openqa.selenium.edge;

import com.google.common.collect.ImmutableMap;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.openqa.selenium.Beta;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chromium.ChromiumDriver;
Expand Down Expand Up @@ -88,10 +89,10 @@ public EdgeDriverCommandExecutor(DriverService service, ClientConfig clientConfi
}

private static Map<String, CommandInfo> getExtraCommands() {
return ImmutableMap.<String, CommandInfo>builder()
.putAll(new AddHasCasting().getAdditionalCommands())
.putAll(new AddHasCdp().getAdditionalCommands())
.build();
return Stream.of(
new AddHasCasting().getAdditionalCommands(), new AddHasCdp().getAdditionalCommands())
.flatMap((m) -> m.entrySet().stream())
.collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue));
}
}
}
12 changes: 2 additions & 10 deletions java/src/org/openqa/selenium/edge/EdgeDriverService.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

package org.openqa.selenium.edge;

import static java.util.Collections.unmodifiableList;
import static java.util.Collections.unmodifiableMap;
import static org.openqa.selenium.edge.EdgeOptions.WEBVIEW2_BROWSER_NAME;
import static org.openqa.selenium.remote.Browser.EDGE;

Expand All @@ -28,7 +26,6 @@
import java.io.OutputStream;
import java.time.Duration;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.openqa.selenium.Capabilities;
Expand Down Expand Up @@ -101,12 +98,7 @@ public EdgeDriverService(
List<String> args,
Map<String, String> environment)
throws IOException {
super(
executable,
port,
timeout,
unmodifiableList(new ArrayList<>(args)),
unmodifiableMap(new HashMap<>(environment)));
super(executable, port, timeout, List.copyOf(args), Map.copyOf(environment));
}

public String getDriverName() {
Expand Down Expand Up @@ -316,7 +308,7 @@ protected List<String> createArgs() {
args.add("--disable-build-check");
}

return unmodifiableList(args);
return List.copyOf(args);
}

@Override
Expand Down
5 changes: 2 additions & 3 deletions java/src/org/openqa/selenium/firefox/AddHasContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static org.openqa.selenium.remote.Browser.FIREFOX;

import com.google.auto.service.AutoService;
import com.google.common.collect.ImmutableMap;
import java.util.Map;
import java.util.function.Predicate;
import org.openqa.selenium.Capabilities;
Expand All @@ -39,7 +38,7 @@ public class AddHasContext implements AugmenterProvider<HasContext>, AdditionalH
public static final String GET_CONTEXT = "getContext";

private static final Map<String, CommandInfo> COMMANDS =
ImmutableMap.of(
Map.of(
SET_CONTEXT, new CommandInfo("/session/:sessionId/moz/context", HttpMethod.POST),
GET_CONTEXT, new CommandInfo("/session/:sessionId/moz/context", HttpMethod.GET));

Expand All @@ -65,7 +64,7 @@ public HasContext getImplementation(Capabilities capabilities, ExecuteMethod exe
public void setContext(FirefoxCommandContext context) {
Require.nonNull("Firefox Command Context", context);

executeMethod.execute(SET_CONTEXT, ImmutableMap.of("context", context));
executeMethod.execute(SET_CONTEXT, Map.of("context", context));
}

@Override
Expand Down
7 changes: 3 additions & 4 deletions java/src/org/openqa/selenium/firefox/AddHasExtensions.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static org.openqa.selenium.remote.Browser.FIREFOX;

import com.google.auto.service.AutoService;
import com.google.common.collect.ImmutableMap;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.FileVisitResult;
Expand Down Expand Up @@ -51,7 +50,7 @@ public class AddHasExtensions implements AugmenterProvider<HasExtensions>, Addit
public static final String UNINSTALL_EXTENSION = "uninstallExtension";

private static final Map<String, CommandInfo> COMMANDS =
ImmutableMap.of(
Map.of(
INSTALL_EXTENSION,
new CommandInfo("/session/:sessionId/moz/addon/install", HttpMethod.POST),
UNINSTALL_EXTENSION,
Expand Down Expand Up @@ -98,7 +97,7 @@ public String installExtension(Path path, Boolean temporary) {

return (String)
executeMethod.execute(
INSTALL_EXTENSION, ImmutableMap.of("addon", encoded, "temporary", temporary));
INSTALL_EXTENSION, Map.of("addon", encoded, "temporary", temporary));
}

private Path zipDirectory(Path path) throws IOException {
Expand All @@ -124,7 +123,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
public void uninstallExtension(String extensionId) {
Require.nonNull("Extension ID", extensionId);

executeMethod.execute(UNINSTALL_EXTENSION, ImmutableMap.of("id", extensionId));
executeMethod.execute(UNINSTALL_EXTENSION, Map.of("id", extensionId));
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static org.openqa.selenium.remote.Browser.FIREFOX;

import com.google.auto.service.AutoService;
import com.google.common.collect.ImmutableMap;
import java.util.Map;
import java.util.function.Predicate;
import org.openqa.selenium.Capabilities;
Expand All @@ -40,7 +39,7 @@ public class AddHasFullPageScreenshot<X>
public static final String FULL_PAGE_SCREENSHOT = "fullPageScreenshot";

private static final Map<String, CommandInfo> COMMANDS =
ImmutableMap.of(
Map.of(
FULL_PAGE_SCREENSHOT,
new CommandInfo("/session/:sessionId/moz/screenshot/full", HttpMethod.GET));

Expand Down
2 changes: 0 additions & 2 deletions java/src/org/openqa/selenium/firefox/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
load("@rules_jvm_external//:defs.bzl", "artifact")
load("//java:defs.bzl", "java_export")
load("//java:version.bzl", "SE_VERSION")

Expand All @@ -15,6 +14,5 @@ java_export(
"//java/src/org/openqa/selenium/json",
"//java/src/org/openqa/selenium/manager",
"//java/src/org/openqa/selenium/remote",
artifact("com.google.guava:guava"),
],
)
15 changes: 9 additions & 6 deletions java/src/org/openqa/selenium/firefox/ClasspathExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@

package org.openqa.selenium.firefox;

import com.google.common.io.Resources;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.io.FileHandler;

Expand Down Expand Up @@ -52,10 +51,14 @@ public void writeTo(File extensionsDir) throws IOException {
}
}

URL resourceUrl = Resources.getResource(loadResourcesUsing, loadFrom);

try (OutputStream stream = new FileOutputStream(extractedXpi)) {
Resources.copy(resourceUrl, stream);
try (InputStream resource = loadResourcesUsing.getResourceAsStream(loadFrom)) {
if (resource == null) {
throw new IllegalArgumentException(
"missing resource '" + loadFrom + "' in " + loadResourcesUsing.getName());
}
try (OutputStream stream = new FileOutputStream(extractedXpi)) {
resource.transferTo(stream);
}
}
new FileExtension(extractedXpi).writeTo(extensionsDir);
}
Expand Down
14 changes: 8 additions & 6 deletions java/src/org/openqa/selenium/firefox/FirefoxDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@

import static org.openqa.selenium.remote.CapabilityType.PROXY;

import com.google.common.collect.ImmutableMap;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.util.Map;
import java.util.Optional;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.openqa.selenium.Beta;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.ImmutableCapabilities;
Expand Down Expand Up @@ -416,11 +417,12 @@ public FirefoxDriverCommandExecutor(DriverService service, ClientConfig clientCo
}

private static Map<String, CommandInfo> getExtraCommands() {
return ImmutableMap.<String, CommandInfo>builder()
.putAll(new AddHasContext().getAdditionalCommands())
.putAll(new AddHasExtensions().getAdditionalCommands())
.putAll(new AddHasFullPageScreenshot().getAdditionalCommands())
.build();
return Stream.of(
new AddHasContext().getAdditionalCommands(),
new AddHasExtensions().getAdditionalCommands(),
new AddHasFullPageScreenshot<>().getAdditionalCommands())
.flatMap((m) -> m.entrySet().stream())
.collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue));
}
}
}
Loading

0 comments on commit 42cc355

Please sign in to comment.