Skip to content

Commit f34732e

Browse files
kool79diemol
authored andcommitted
[java][sm] Configure Selenium Manager environment from System Properties (SeleniumHQ#13858)
* [java][sm] Configure Selenium Manager environment from System Properties * Running format script --------- Co-authored-by: Diego Molina <[email protected]> Co-authored-by: Diego Molina <[email protected]>
1 parent c851871 commit f34732e

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

java/src/org/openqa/selenium/manager/SeleniumManager.java

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.nio.file.Paths;
2929
import java.time.Duration;
3030
import java.util.List;
31+
import java.util.Properties;
3132
import java.util.logging.Level;
3233
import java.util.logging.Logger;
3334
import org.openqa.selenium.Beta;
@@ -62,6 +63,7 @@ public class SeleniumManager {
6263
private static final String CACHE_PATH_ENV = "SE_CACHE_PATH";
6364
private static final String BETA_PREFIX = "0.";
6465
private static final String EXE = ".exe";
66+
private static final String SE_ENV_PREFIX = "SE_";
6567

6668
private static volatile SeleniumManager manager;
6769
private final String managerPath = System.getenv("SE_MANAGER_PATH");
@@ -119,8 +121,21 @@ private static Result runCommand(Path binary, List<String> arguments) {
119121
String output;
120122
int code;
121123
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+
}
122136
ExternalProcess process =
123-
ExternalProcess.builder().command(binary.toAbsolutePath().toString(), arguments).start();
137+
processBuilder.command(binary.toAbsolutePath().toString(), arguments).start();
138+
124139
if (!process.waitFor(Duration.ofHours(1))) {
125140
LOG.warning("Selenium Manager did not exit, shutting it down");
126141
process.shutdown();
@@ -240,13 +255,13 @@ private Level getLogLevel() {
240255
}
241256

242257
private Path getBinaryInCache(String binaryName) throws IOException {
243-
String cachePath = DEFAULT_CACHE_PATH.replace(HOME, System.getProperty("user.home"));
244258

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"));
250265

251266
// If cache path is not writable, SM will be extracted to a temporal folder
252267
Path cacheParent = Paths.get(cachePath);

0 commit comments

Comments
 (0)