From 25964eb4c1e503cc31ee275014a5402b1731f05a Mon Sep 17 00:00:00 2001 From: Oleksandr Kulychok Date: Tue, 23 Apr 2024 02:52:44 +0300 Subject: [PATCH 1/2] [java][sm] Configure Selenium Manager environment from System Properties --- .../selenium/manager/SeleniumManager.java | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/java/src/org/openqa/selenium/manager/SeleniumManager.java b/java/src/org/openqa/selenium/manager/SeleniumManager.java index 75af5188e20ae..257007b09fc78 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,20 @@ 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 +254,15 @@ 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); From 28b36572856b91d428b9505ccc5ee6f21f38e9fc Mon Sep 17 00:00:00 2001 From: Diego Molina Date: Sat, 4 May 2024 13:57:53 +0000 Subject: [PATCH 2/2] Running format script --- .../openqa/selenium/manager/SeleniumManager.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/java/src/org/openqa/selenium/manager/SeleniumManager.java b/java/src/org/openqa/selenium/manager/SeleniumManager.java index 257007b09fc78..04daa88acb256 100644 --- a/java/src/org/openqa/selenium/manager/SeleniumManager.java +++ b/java/src/org/openqa/selenium/manager/SeleniumManager.java @@ -126,14 +126,15 @@ private static Result runCommand(Path binary, List arguments) { Properties properties = System.getProperties(); for (String name : properties.stringPropertyNames()) { if (name.startsWith(SE_ENV_PREFIX)) { - //read property with 'default' value due to concurrency + // read property with 'default' value due to concurrency String value = properties.getProperty(name, ""); - if (!value.isEmpty()) + if (!value.isEmpty()) { processBuilder.environment(name, value); + } } } ExternalProcess process = - processBuilder.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"); @@ -257,10 +258,8 @@ private Path getBinaryInCache(String binaryName) throws IOException { // 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; + if (cachePath.isEmpty()) cachePath = System.getenv(CACHE_PATH_ENV); + if (cachePath == null) cachePath = DEFAULT_CACHE_PATH; cachePath = cachePath.replace(HOME, System.getProperty("user.home"));