This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-lang.git
commit 4721b0f9c2e850a1a3305172872e383ff91b9fc1 Author: Gary Gregory <[email protected]> AuthorDate: Mon Dec 2 08:32:59 2024 -0500 Rename internal method to avoid possible confusion with System.getenv() They don't do the same thing --- .../apache/commons/lang3/RuntimeEnvironment.java | 52 +++++++++++----------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/RuntimeEnvironment.java b/src/main/java/org/apache/commons/lang3/RuntimeEnvironment.java index 294c54dff..8f1cfb5ac 100644 --- a/src/main/java/org/apache/commons/lang3/RuntimeEnvironment.java +++ b/src/main/java/org/apache/commons/lang3/RuntimeEnvironment.java @@ -34,31 +34,6 @@ public class RuntimeEnvironment { return Files.exists(Paths.get(path)); } - /** - * Tests whether the /proc/N/environ file at the given path string contains a specific line prefix. - * - * @param envVarFile The path to a /proc/N/environ file. - * @param key The env var key to find. - * @return value The env var value or null - */ - private static String getenv(final String envVarFile, final String key) { - try { - final byte[] bytes = Files.readAllBytes(Paths.get(envVarFile)); - final String content = new String(bytes, Charset.defaultCharset()); - // Split by null byte character - final String[] lines = content.split("\u0000"); - final String prefix = key + "="; - return Arrays.stream(lines) - .filter(line -> line.startsWith(prefix)) - .map(line -> line.split("=", 2)) - .map(keyValue -> keyValue[1]) - .findFirst() - .orElse(null); - } catch (final IOException e) { - return null; - } - } - /** * Tests whether we are running in a container like Docker or Podman. * @@ -83,13 +58,38 @@ public class RuntimeEnvironment { /run/.containerenv is used by PodMan. */ - final String value = getenv(dirPrefix + "/proc/1/environ", "container"); + final String value = readFile(dirPrefix + "/proc/1/environ", "container"); if (value != null) { return !value.isEmpty(); } return fileExists(dirPrefix + "/.dockerenv") || fileExists(dirPrefix + "/run/.containerenv"); } + /** + * Tests whether the /proc/N/environ file at the given path string contains a specific line prefix. + * + * @param envVarFile The path to a /proc/N/environ file. + * @param key The env var key to find. + * @return value The env var value or null. + */ + private static String readFile(final String envVarFile, final String key) { + try { + final byte[] bytes = Files.readAllBytes(Paths.get(envVarFile)); + final String content = new String(bytes, Charset.defaultCharset()); + // Split by null byte character + final String[] lines = content.split("\u0000"); + final String prefix = key + "="; + return Arrays.stream(lines) + .filter(line -> line.startsWith(prefix)) + .map(line -> line.split("=", 2)) + .map(keyValue -> keyValue[1]) + .findFirst() + .orElse(null); + } catch (final IOException e) { + return null; + } + } + /** * Constructs a new instance. *
