diff --git a/java/src/org/openqa/selenium/manager/SeleniumManager.java b/java/src/org/openqa/selenium/manager/SeleniumManager.java index 75af5188e20ae..04daa88acb256 100644 --- a/java/src/org/openqa/selenium/manager/SeleniumManager.java +++ b/java/src/org/openqa/selenium/manager/SeleniumManager.java @@ -28,6 +28,7 @@ import java.nio.file.Paths; import java.time.Duration; import java.util.List; +import java.util.Properties; import java.util.logging.Level; import java.util.logging.Logger; import org.openqa.selenium.Beta; @@ -62,6 +63,7 @@ public class SeleniumManager { private static final String CACHE_PATH_ENV = "SE_CACHE_PATH"; private static final String BETA_PREFIX = "0."; private static final String EXE = ".exe"; + private static final String SE_ENV_PREFIX = "SE_"; private static volatile SeleniumManager manager; private final String managerPath = System.getenv("SE_MANAGER_PATH"); @@ -119,8 +121,21 @@ private static Result runCommand(Path binary, List arguments) { String output; int code; try { + ExternalProcess.Builder processBuilder = ExternalProcess.builder(); + + Properties properties = System.getProperties(); + for (String name : properties.stringPropertyNames()) { + if (name.startsWith(SE_ENV_PREFIX)) { + // read property with 'default' value due to concurrency + String value = properties.getProperty(name, ""); + if (!value.isEmpty()) { + processBuilder.environment(name, value); + } + } + } ExternalProcess process = - ExternalProcess.builder().command(binary.toAbsolutePath().toString(), arguments).start(); + processBuilder.command(binary.toAbsolutePath().toString(), arguments).start(); + if (!process.waitFor(Duration.ofHours(1))) { LOG.warning("Selenium Manager did not exit, shutting it down"); process.shutdown(); @@ -240,13 +255,13 @@ private Level getLogLevel() { } private Path getBinaryInCache(String binaryName) throws IOException { - String cachePath = DEFAULT_CACHE_PATH.replace(HOME, System.getProperty("user.home")); - // Look for cache path as env - String cachePathEnv = System.getenv(CACHE_PATH_ENV); - if (cachePathEnv != null) { - cachePath = cachePathEnv; - } + // Look for cache path as system property or env + String cachePath = System.getProperty(CACHE_PATH_ENV, ""); + if (cachePath.isEmpty()) cachePath = System.getenv(CACHE_PATH_ENV); + if (cachePath == null) cachePath = DEFAULT_CACHE_PATH; + + cachePath = cachePath.replace(HOME, System.getProperty("user.home")); // If cache path is not writable, SM will be extracted to a temporal folder Path cacheParent = Paths.get(cachePath);