Skip to content

Commit

Permalink
[java] Moving code that finds Firefox binary from WindowsUtils to Fir…
Browse files Browse the repository at this point in the history
…efoxBinary
  • Loading branch information
barancev committed Nov 2, 2018
1 parent 530eca5 commit 1911c51
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 160 deletions.
41 changes: 37 additions & 4 deletions java/client/src/org/openqa/selenium/firefox/FirefoxBinary.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import static org.openqa.selenium.Platform.MAC;
import static org.openqa.selenium.Platform.UNIX;
import static org.openqa.selenium.Platform.WINDOWS;
import static org.openqa.selenium.os.WindowsUtils.getPathsInProgramFiles;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
Expand All @@ -49,7 +48,9 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class FirefoxBinary {
Expand Down Expand Up @@ -400,9 +401,10 @@ private static Stream<Executable> locateFirefoxBinariesFromPlatform() {

Platform current = Platform.getCurrent();
if (current.is(WINDOWS)) {
executables.addAll(Stream.of(getPathsInProgramFiles("Mozilla Firefox\\firefox.exe"),
getPathsInProgramFiles("Firefox Developer Edition\\firefox.exe"),
getPathsInProgramFiles("Nightly\\firefox.exe"))
executables.addAll(Stream.of("Mozilla Firefox\\firefox.exe",
"Firefox Developer Edition\\firefox.exe",
"Nightly\\firefox.exe")
.map(FirefoxBinary::getPathsInProgramFiles)
.flatMap(List::stream)
.map(File::new).filter(File::exists)
.map(Executable::new).collect(toList()));
Expand Down Expand Up @@ -454,4 +456,35 @@ private static Stream<Executable> locateFirefoxBinariesFromPlatform() {
return executables.build().stream();
}

private static List<String> getPathsInProgramFiles(final String childPath) {
return Stream.of(getProgramFilesPath(), getProgramFiles86Path())
.map(parent -> new File(parent, childPath).getAbsolutePath())
.collect(Collectors.toList());
}

/**
* Returns the path to the Windows Program Files. On non-English versions, this is not necessarily
* "C:\Program Files".
*
* @return the path to the Windows Program Files
*/
private static String getProgramFilesPath() {
return getEnvVarPath("ProgramFiles", "C:\\Program Files").replace(" (x86)", "");
}

private static String getProgramFiles86Path() {
return getEnvVarPath("ProgramFiles(x86)", "C:\\Program Files (x86)");
}

private static String getEnvVarPath(final String envVar, final String defaultValue) {
return getEnvVarIgnoreCase(envVar)
.map(File::new).filter(File::exists).map(File::getAbsolutePath)
.orElseGet(() -> new File(defaultValue).getAbsolutePath());
}

private static Optional<String> getEnvVarIgnoreCase(String var) {
return System.getenv().entrySet().stream()
.filter(e -> e.getKey().equalsIgnoreCase(var))
.findFirst().map(Map.Entry::getValue);
}
}
114 changes: 0 additions & 114 deletions java/client/src/org/openqa/selenium/os/WindowsUtils.java

This file was deleted.

2 changes: 0 additions & 2 deletions java/client/test/org/openqa/selenium/SmallTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.openqa.selenium.net.NetworkUtilsTest;
import org.openqa.selenium.net.UrlCheckerTest;
import org.openqa.selenium.os.CommandLineTest;
import org.openqa.selenium.os.WindowsUtilsUnitTest;
import org.openqa.selenium.testing.drivers.IgnoreComparatorUnitTest;

@RunWith(Suite.class)
Expand Down Expand Up @@ -59,7 +58,6 @@
TemporaryFilesystemTest.class,
UrlCheckerTest.class,
WebDriverExceptionTest.class,
WindowsUtilsUnitTest.class,
ZipTest.class,

org.openqa.selenium.support.SmallTests.class,
Expand Down
40 changes: 0 additions & 40 deletions java/client/test/org/openqa/selenium/os/WindowsUtilsUnitTest.java

This file was deleted.

0 comments on commit 1911c51

Please sign in to comment.