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:42 UTC

(commons-lang) branch master updated (e8944ba1b -> 9384d0fb5)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git


    from e8944ba1b Bump actions/upload-artifact from 4.3.2 to 4.3.3 (#1207)
     new f2cacb473 Add org.apache.commons.lang3.SystemProperties.getUserName(Supplier<String>)
     new 9384d0fb5 Add org.apache.commons.lang3.SystemProperties.getLineSeparator(Supplier<String>)

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/changes/changes.xml                            | 26 ++++++++-------
 .../org/apache/commons/lang3/SystemProperties.java | 38 +++++++++++++++++++---
 .../apache/commons/lang3/SystemPropertiesTest.java |  8 +++++
 3 files changed, 55 insertions(+), 17 deletions(-)


(commons-lang) 01/02: Add org.apache.commons.lang3.SystemProperties.getUserName(Supplier)

Posted by gg...@apache.org.
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&lt;String&gt;).</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


(commons-lang) 02/02: Add org.apache.commons.lang3.SystemProperties.getLineSeparator(Supplier)

Posted by gg...@apache.org.
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 9384d0fb583c7a26f5eed8b6f586dc8e24f0dc49
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed May 1 09:02:36 2024 -0400

    Add org.apache.commons.lang3.SystemProperties.getLineSeparator(Supplier<String>)
---
 src/changes/changes.xml                            |  1 +
 .../org/apache/commons/lang3/SystemProperties.java | 24 +++++++++++++++++-----
 .../apache/commons/lang3/SystemPropertiesTest.java |  4 ++++
 3 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 0595e2ee2..cdd3a0cd0 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -61,6 +61,7 @@ The <action> type attribute can be add,update,fix,remove.
     <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&lt;String&gt;).</action>
+    <action                   type="add" dev="ggregory" due-to="Gary Gregory">Add org.apache.commons.lang3.SystemProperties.getLineSeparator(Supplier&lt;String&gt;).</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 45217fd11..11164fda5 100644
--- a/src/main/java/org/apache/commons/lang3/SystemProperties.java
+++ b/src/main/java/org/apache/commons/lang3/SystemProperties.java
@@ -680,6 +680,20 @@ public final class SystemProperties {
         return getProperty(LINE_SEPARATOR);
     }
 
+    /**
+     * 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 defaultIfAbsent 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 getLineSeparator(final Supplier<String> defaultIfAbsent) {
+        return getProperty(LINE_SEPARATOR, defaultIfAbsent);
+    }
+
     /**
      * Gets the current value for the property named {@code key} as a {@code long}.
      *
@@ -762,22 +776,22 @@ public final class SystemProperties {
      * </p>
      *
      * @param property        the system property name.
-     * @param defaultValue get this Supplier when the property is empty or throws SecurityException.
+     * @param defaultIfAbsent get this Supplier when the property is empty or throws SecurityException.
      * @return the system property value or {@code null} if a security problem occurs
      */
-    static String getProperty(final String property, final Supplier<String> defaultValue) {
+    static String getProperty(final String property, final Supplier<String> defaultIfAbsent) {
         try {
             if (StringUtils.isEmpty(property)) {
-                return defaultValue.get();
+                return defaultIfAbsent.get();
             }
             final String value = System.getProperty(property);
-            return StringUtils.getIfEmpty(value, defaultValue);
+            return StringUtils.getIfEmpty(value, defaultIfAbsent);
         } catch (final SecurityException ignore) {
             // We are not allowed to look at this property.
             //
             // System.err.println("Caught a SecurityException reading the system property '" + property
             // + "'; the SystemUtils property value will default to null.");
-            return defaultValue.get();
+            return defaultIfAbsent.get();
         }
     }
 
diff --git a/src/test/java/org/apache/commons/lang3/SystemPropertiesTest.java b/src/test/java/org/apache/commons/lang3/SystemPropertiesTest.java
index 0dde1a85b..b1ce892ef 100644
--- a/src/test/java/org/apache/commons/lang3/SystemPropertiesTest.java
+++ b/src/test/java/org/apache/commons/lang3/SystemPropertiesTest.java
@@ -242,6 +242,10 @@ public class SystemPropertiesTest {
     @Test
     public void testGetLineSeparator() {
         assertNotNull(SystemProperties.getLineSeparator());
+        assertNotNull(SystemProperties.getLineSeparator(() -> ""));
+        assertNotNull(SystemProperties.getLineSeparator(() -> "\n"));
+        assertNotNull(SystemProperties.getLineSeparator(() -> null));
+        assertNotNull(SystemProperties.getLineSeparator(null));
     }
 
     @Test