You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2024/05/01 13:02:43 UTC
(commons-lang) 01/02: Add org.apache.commons.lang3.SystemProperties.getUserName(Supplier)
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 f2cacb4732f1d4aeae03faced4ee922d592f7e9d
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed May 1 09:02:17 2024 -0400
Add org.apache.commons.lang3.SystemProperties.getUserName(Supplier<String>)
---
src/changes/changes.xml | 25 +++++++++++-----------
.../org/apache/commons/lang3/SystemProperties.java | 14 ++++++++++++
.../apache/commons/lang3/SystemPropertiesTest.java | 4 ++++
3 files changed, 31 insertions(+), 12 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 730e50a54..0595e2ee2 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -48,18 +48,19 @@ The <action> type attribute can be add,update,fix,remove.
<release version="3.15.0" date="202Y-MM-DD" description="New features and bug fixes (Java 8 or above).">
<!-- ADD -->
<action issue="LANG-1724" type="add" dev="ggregory" due-to="Gary Gregory, Dennis Baerten">Customize text pattern in DiffResult#toString().</action>
- <action issue="LANG-1724" type="add" dev="ggregory" due-to="Gary Gregory">Add DiffBuilder.Builder.</action>
- <action issue="LANG-1724" type="add" dev="ggregory" due-to="Gary Gregory">Add DiffBuilder.builder().</action>
- <action issue="LANG-1724" type="add" dev="ggregory" due-to="Gary Gregory">Add ReflectionDiffBuilder.Builder.</action>
- <action issue="LANG-1724" type="add" dev="ggregory" due-to="Gary Gregory">Add ReflectionDiffBuilder.builder().</action>
- <action issue="LANG-1702" type="add" dev="ggregory" due-to="Elliotte Rusty Harold">Add test in TypeUtilsTest #1151.</action>
- <action issue="LANG-1724" type="add" dev="ggregory" due-to="Gary Gregory">Add Streams.failableStream(T), non-varargs variant.</action>
- <action issue="LANG-1724" type="add" dev="ggregory" due-to="Gary Gregory">Add Streams.nonNull(T), non-varargs variant.</action>
- <action issue="LANG-1724" type="add" dev="ggregory" due-to="Gary Gregory">Add ArrayUtils.nullTo(T[], T[]).</action>
- <action issue="LANG-1724" type="add" dev="ggregory" due-to="Gary Gregory">Add T ArrayUtils.arraycopy(T, int, T, int, int) fluent style.</action>
- <action issue="LANG-1724" type="add" dev="ggregory" due-to="Gary Gregory">Add T ArrayUtils.arraycopy(T, int, int, int, Function) fluent style.</action>
- <action issue="LANG-1724" type="add" dev="ggregory" due-to="Gary Gregory">Add SystemUtils.IS_JAVA_22.</action>
- <action issue="LANG-1724" type="add" dev="ggregory" due-to="Gary Gregory">Add JavaVersion.JAVA_22.</action>
+ <action type="add" dev="ggregory" due-to="Gary Gregory">Add DiffBuilder.Builder.</action>
+ <action type="add" dev="ggregory" due-to="Gary Gregory">Add DiffBuilder.builder().</action>
+ <action type="add" dev="ggregory" due-to="Gary Gregory">Add ReflectionDiffBuilder.Builder.</action>
+ <action type="add" dev="ggregory" due-to="Gary Gregory">Add ReflectionDiffBuilder.builder().</action>
+ <action type="add" dev="ggregory" due-to="Elliotte Rusty Harold">Add test in TypeUtilsTest #1151.</action>
+ <action type="add" dev="ggregory" due-to="Gary Gregory">Add Streams.failableStream(T), non-varargs variant.</action>
+ <action type="add" dev="ggregory" due-to="Gary Gregory">Add Streams.nonNull(T), non-varargs variant.</action>
+ <action type="add" dev="ggregory" due-to="Gary Gregory">Add ArrayUtils.nullTo(T[], T[]).</action>
+ <action type="add" dev="ggregory" due-to="Gary Gregory">Add T ArrayUtils.arraycopy(T, int, T, int, int) fluent style.</action>
+ <action type="add" dev="ggregory" due-to="Gary Gregory">Add T ArrayUtils.arraycopy(T, int, int, int, Function) fluent style.</action>
+ <action type="add" dev="ggregory" due-to="Gary Gregory">Add SystemUtils.IS_JAVA_22.</action>
+ <action type="add" dev="ggregory" due-to="Gary Gregory">Add JavaVersion.JAVA_22.</action>
+ <action type="add" dev="ggregory" due-to="Gary Gregory">Add org.apache.commons.lang3.SystemProperties.getUserName(Supplier<String>).</action>
<!-- FIX -->
<action type="fix" dev="ggregory" due-to="Miklós Karakó, Gary Gregory">Improve Javadoc in ExceptionUtils #1136.</action>
<action type="fix" dev="ggregory" due-to="Saiharshith Karuneegar Ramesh, Gary Gregory">Fixed two non-deterministic tests in EnumUtilsTest.java #1131.</action>
diff --git a/src/main/java/org/apache/commons/lang3/SystemProperties.java b/src/main/java/org/apache/commons/lang3/SystemProperties.java
index 7358779a2..45217fd11 100644
--- a/src/main/java/org/apache/commons/lang3/SystemProperties.java
+++ b/src/main/java/org/apache/commons/lang3/SystemProperties.java
@@ -841,6 +841,20 @@ public final class SystemProperties {
return getProperty(USER_NAME);
}
+ /**
+ * Gets the current value from the system properties map.
+ * <p>
+ * Returns {@code null} if the property cannot be read due to a {@link SecurityException}.
+ * </p>
+ *
+ * @param defaultValue get this Supplier when the property is empty or throws SecurityException.
+ * @return the current value from the system properties map.
+ * @since 3.15.0
+ */
+ public static String getUserName(final Supplier<String> defaultValue) {
+ return getProperty(USER_NAME, defaultValue);
+ }
+
/**
* Gets the current value from the system properties map.
* <p>
diff --git a/src/test/java/org/apache/commons/lang3/SystemPropertiesTest.java b/src/test/java/org/apache/commons/lang3/SystemPropertiesTest.java
index e6cd94bc5..0dde1a85b 100644
--- a/src/test/java/org/apache/commons/lang3/SystemPropertiesTest.java
+++ b/src/test/java/org/apache/commons/lang3/SystemPropertiesTest.java
@@ -303,6 +303,10 @@ public class SystemPropertiesTest {
@Test
public void testGetUserName() {
assertNotNull(SystemProperties.getUserName());
+ assertNotNull(SystemProperties.getUserName(() -> ""));
+ assertNotNull(SystemProperties.getUserName(() -> "User"));
+ assertNotNull(SystemProperties.getUserName(() -> null));
+ assertNotNull(SystemProperties.getUserName(null));
}
@Test