Skip to content

Commit

Permalink
Run format script
Browse files Browse the repository at this point in the history
  • Loading branch information
shs96c committed Aug 1, 2023
1 parent 22d946a commit 4b35528
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 70 deletions.
85 changes: 42 additions & 43 deletions java/src/org/openqa/selenium/manager/SeleniumManager.java
Expand Up @@ -16,15 +16,9 @@
// under the License.
package org.openqa.selenium.manager;

import org.openqa.selenium.Beta;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.Platform;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.json.Json;
import org.openqa.selenium.json.JsonException;
import org.openqa.selenium.manager.SeleniumManagerOutput.Result;
import org.openqa.selenium.os.CommandLine;
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
import static org.openqa.selenium.Platform.MAC;
import static org.openqa.selenium.Platform.WINDOWS;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -39,10 +33,15 @@
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
import static org.openqa.selenium.Platform.MAC;
import static org.openqa.selenium.Platform.WINDOWS;
import org.openqa.selenium.Beta;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.Platform;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.json.Json;
import org.openqa.selenium.json.JsonException;
import org.openqa.selenium.manager.SeleniumManagerOutput.Result;
import org.openqa.selenium.os.CommandLine;

/**
* This implementation is still in beta, and may change.
Expand Down Expand Up @@ -112,10 +111,11 @@ private static Result runCommand(Path binary, List<String> arguments) {
String output;
int code;
try {
CommandLine command = new CommandLine(binary.toAbsolutePath().toString(), arguments.toArray(new String[0]));
CommandLine command =
new CommandLine(binary.toAbsolutePath().toString(), arguments.toArray(new String[0]));
command.copyOutputTo(System.err);
command.executeAsync();
command.waitFor(10000); // A generous timeout
command.waitFor(10000); // A generous timeout
if (command.isRunning()) {
LOG.warning("Selenium Manager did not exit");
}
Expand Down Expand Up @@ -146,17 +146,11 @@ private static Result runCommand(Path binary, List<String> arguments) {
}
if (code != 0) {
throw new WebDriverException(
"Command failed with code: "
+ code
+ ", executed: "
+ arguments
+ "\n"
+ dump,
"Command failed with code: " + code + ", executed: " + arguments + "\n" + dump,
failedToParse);
} else if (failedToParse != null || jsonOutput == null) {
throw new WebDriverException(
"Failed to parse json output, executed: " + arguments + "\n" + dump,
failedToParse);
"Failed to parse json output, executed: " + arguments + "\n" + dump, failedToParse);
}
return jsonOutput.result;
}
Expand Down Expand Up @@ -198,27 +192,32 @@ private synchronized Path getBinary() {
}

private void deleteOnExit(Path tmpPath) {
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
Files.walkFileTree(
tmpPath,
new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
Files.delete(dir);
return FileVisitResult.CONTINUE;
}
Runtime.getRuntime()
.addShutdownHook(
new Thread(
() -> {
try {
Files.walkFileTree(
tmpPath,
new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc)
throws IOException {
Files.delete(dir);
return FileVisitResult.CONTINUE;
}

@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Files.delete(file);
return FileVisitResult.CONTINUE;
}
});
} catch (IOException e) {
// Do nothing. We're just tidying up.
}
}));
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
throws IOException {
Files.delete(file);
return FileVisitResult.CONTINUE;
}
});
} catch (IOException e) {
// Do nothing. We're just tidying up.
}
}));
}

/**
Expand Down
25 changes: 17 additions & 8 deletions java/src/org/openqa/selenium/manager/SeleniumManagerOutput.java
Expand Up @@ -18,7 +18,6 @@

import java.util.List;
import java.util.Objects;

import org.openqa.selenium.json.JsonInput;

public class SeleniumManagerOutput {
Expand Down Expand Up @@ -123,12 +122,19 @@ public void setBrowserPath(String browserPath) {

@Override
public String toString() {
return "Result{" +
"code=" + code +
", message='" + message + '\'' +
", driverPath='" + driverPath + '\'' +
", browserPath='" + browserPath + '\'' +
'}';
return "Result{"
+ "code="
+ code
+ ", message='"
+ message
+ '\''
+ ", driverPath='"
+ driverPath
+ '\''
+ ", browserPath='"
+ browserPath
+ '\''
+ '}';
}

@Override
Expand All @@ -137,7 +143,10 @@ public boolean equals(Object o) {
return false;
}
Result that = (Result) o;
return code == that.code && Objects.equals(message, that.message) && Objects.equals(driverPath, that.driverPath) && Objects.equals(browserPath, that.browserPath);
return code == that.code
&& Objects.equals(message, that.message)
&& Objects.equals(driverPath, that.driverPath)
&& Objects.equals(browserPath, that.browserPath);
}

@Override
Expand Down
Expand Up @@ -26,12 +26,9 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.ServiceLoader;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriverInfo;
import org.openqa.selenium.build.BazelBuild;
import org.openqa.selenium.build.DevMode;
import org.openqa.selenium.build.InProject;
Expand Down Expand Up @@ -87,14 +84,15 @@ public OutOfProcessSeleniumServer start(String mode, String... extraFlags) {
.map(entry -> "--jvm_flag=-D" + entry.getKey() + "=" + entry.getValue());

// Only use Selenium Manager if we're not running with pinned browsers.
boolean driverProvided = Stream.of(
GeckoDriverService.createDefaultService(),
EdgeDriverService.createDefaultService(),
ChromeDriverService.createDefaultService())
.map(DriverService::getDriverProperty)
.filter(Objects::nonNull)
.map(System::getProperty)
.anyMatch(Objects::nonNull);
boolean driverProvided =
Stream.of(
GeckoDriverService.createDefaultService(),
EdgeDriverService.createDefaultService(),
ChromeDriverService.createDefaultService())
.map(DriverService::getDriverProperty)
.filter(Objects::nonNull)
.map(System::getProperty)
.anyMatch(Objects::nonNull);

List<String> startupArgs = new ArrayList<>();
startupArgs.add(mode);
Expand All @@ -111,9 +109,8 @@ public OutOfProcessSeleniumServer start(String mode, String... extraFlags) {
Stream.concat(
javaFlags,
Stream.concat(
// If the driver is provided, we _don't_ want to use Selenium Manager
startupArgs.stream(),
Stream.of(extraFlags)))
// If the driver is provided, we _don't_ want to use Selenium Manager
startupArgs.stream(), Stream.of(extraFlags)))
.toArray(String[]::new));
if (Platform.getCurrent().is(Platform.WINDOWS)) {
File workingDir = findBinRoot(new File(".").getAbsoluteFile());
Expand Down Expand Up @@ -165,13 +162,10 @@ public void stop() {
private String buildServerAndClasspath() {
if (DevMode.isInDevMode()) {
Path serverJar =
InProject.locate(
"bazel-bin/java/src/org/openqa/selenium/grid/selenium_server");
InProject.locate("bazel-bin/java/src/org/openqa/selenium/grid/selenium_server");
if (serverJar == null) {
new BazelBuild().build("grid");
serverJar =
InProject.locate(
"bazel-bin/java/src/org/openqa/selenium/grid/selenium_server");
serverJar = InProject.locate("bazel-bin/java/src/org/openqa/selenium/grid/selenium_server");
}
if (serverJar != null) {
return serverJar.toAbsolutePath().toString();
Expand Down

0 comments on commit 4b35528

Please sign in to comment.