Skip to content

Commit

Permalink
[java] Format Selenium Manager wrapper class in Java
Browse files Browse the repository at this point in the history
  • Loading branch information
bonigarcia committed Feb 15, 2023
1 parent 771c22c commit 60c9f4a
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions java/src/org/openqa/selenium/manager/SeleniumManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

/**
* This implementation is still in beta, and may change.
*
* <p>
* The Selenium-Manager binaries are distributed in a JAR file (org.openqa.selenium:selenium-manager) for
* the Java binding language. Since these binaries are compressed within these JAR, we need to serialize
* the proper binary for the current platform (Windows, macOS, or Linux) as an executable file. To
Expand All @@ -59,9 +59,9 @@ public class SeleniumManager {

private File binary;

/**
* Wrapper for the Selenium Manager binary.
*/
/**
* Wrapper for the Selenium Manager binary.
*/
private SeleniumManager() {
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
if (binary != null && binary.exists()) {
Expand All @@ -82,11 +82,12 @@ public static SeleniumManager getInstance() {
return manager;
}

/**
* Executes a process with the given arguments.
* @param command the file and arguments to execute.
* @return the standard output of the execution.
*/
/**
* Executes a process with the given arguments.
*
* @param command the file and arguments to execute.
* @return the standard output of the execution.
*/
private static String runCommand(String... command) {
String output = "";
int code = 0;
Expand All @@ -106,17 +107,18 @@ private static String runCommand(String... command) {
e.getClass().getSimpleName(), Arrays.toString(command), e.getMessage()));
}
if (code > 0) {
throw new WebDriverException("Unsuccessful command executed: " + Arrays.toString(command) +
"\n" + output);
throw new WebDriverException("Unsuccessful command executed: " + Arrays.toString(command) +
"\n" + output);
}

return output.replace(INFO, "").trim();
}

/**
* Determines the correct Selenium Manager binary to use.
* @return the path to the Selenium Manager binary.
*/
/**
* Determines the correct Selenium Manager binary to use.
*
* @return the path to the Selenium Manager binary.
*/
private synchronized File getBinary() {
if (binary == null) {
try {
Expand Down Expand Up @@ -145,11 +147,12 @@ private synchronized File getBinary() {
return binary;
}

/**
* Determines the location of the correct driver.
* @param driverName which driver the service needs.
* @return the location of the driver.
*/
/**
* Determines the location of the correct driver.
*
* @param driverName which driver the service needs.
* @return the location of the driver.
*/
public String getDriverPath(String driverName) {
if (!ImmutableList.of("geckodriver", "chromedriver", "msedgedriver", "IEDriverServer").contains(driverName)) {
throw new WebDriverException("Unable to locate driver with name: " + driverName);
Expand All @@ -158,7 +161,7 @@ public String getDriverPath(String driverName) {
String driverPath = null;
File binaryFile = getBinary();
if (binaryFile != null) {
driverPath = runCommand(binaryFile.getAbsolutePath(),
driverPath = runCommand(binaryFile.getAbsolutePath(),
"--driver", driverName.replaceAll(EXE, ""));
}
return driverPath;
Expand Down

0 comments on commit 60c9f4a

Please sign in to comment.