|
28 | 28 | import java.nio.file.Paths; |
29 | 29 | import java.time.Duration; |
30 | 30 | import java.util.List; |
| 31 | +import java.util.Properties; |
31 | 32 | import java.util.logging.Level; |
32 | 33 | import java.util.logging.Logger; |
33 | 34 | import org.openqa.selenium.Beta; |
@@ -62,6 +63,7 @@ public class SeleniumManager { |
62 | 63 | private static final String CACHE_PATH_ENV = "SE_CACHE_PATH"; |
63 | 64 | private static final String BETA_PREFIX = "0."; |
64 | 65 | private static final String EXE = ".exe"; |
| 66 | + private static final String SE_ENV_PREFIX = "SE_"; |
65 | 67 |
|
66 | 68 | private static volatile SeleniumManager manager; |
67 | 69 | private final String managerPath = System.getenv("SE_MANAGER_PATH"); |
@@ -119,8 +121,21 @@ private static Result runCommand(Path binary, List<String> arguments) { |
119 | 121 | String output; |
120 | 122 | int code; |
121 | 123 | try { |
| 124 | + ExternalProcess.Builder processBuilder = ExternalProcess.builder(); |
| 125 | + |
| 126 | + Properties properties = System.getProperties(); |
| 127 | + for (String name : properties.stringPropertyNames()) { |
| 128 | + if (name.startsWith(SE_ENV_PREFIX)) { |
| 129 | + // read property with 'default' value due to concurrency |
| 130 | + String value = properties.getProperty(name, ""); |
| 131 | + if (!value.isEmpty()) { |
| 132 | + processBuilder.environment(name, value); |
| 133 | + } |
| 134 | + } |
| 135 | + } |
122 | 136 | ExternalProcess process = |
123 | | - ExternalProcess.builder().command(binary.toAbsolutePath().toString(), arguments).start(); |
| 137 | + processBuilder.command(binary.toAbsolutePath().toString(), arguments).start(); |
| 138 | + |
124 | 139 | if (!process.waitFor(Duration.ofHours(1))) { |
125 | 140 | LOG.warning("Selenium Manager did not exit, shutting it down"); |
126 | 141 | process.shutdown(); |
@@ -240,13 +255,13 @@ private Level getLogLevel() { |
240 | 255 | } |
241 | 256 |
|
242 | 257 | private Path getBinaryInCache(String binaryName) throws IOException { |
243 | | - String cachePath = DEFAULT_CACHE_PATH.replace(HOME, System.getProperty("user.home")); |
244 | 258 |
|
245 | | - // Look for cache path as env |
246 | | - String cachePathEnv = System.getenv(CACHE_PATH_ENV); |
247 | | - if (cachePathEnv != null) { |
248 | | - cachePath = cachePathEnv; |
249 | | - } |
| 259 | + // Look for cache path as system property or env |
| 260 | + String cachePath = System.getProperty(CACHE_PATH_ENV, ""); |
| 261 | + if (cachePath.isEmpty()) cachePath = System.getenv(CACHE_PATH_ENV); |
| 262 | + if (cachePath == null) cachePath = DEFAULT_CACHE_PATH; |
| 263 | + |
| 264 | + cachePath = cachePath.replace(HOME, System.getProperty("user.home")); |
250 | 265 |
|
251 | 266 | // If cache path is not writable, SM will be extracted to a temporal folder |
252 | 267 | Path cacheParent = Paths.get(cachePath); |
|
0 commit comments