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 421229b42f79a41d1eb7f4e9d9f1dabef56270d3 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Fri Feb 28 16:50:37 2025 -0500 Add SystemUtils.getUserDirPath() --- src/changes/changes.xml | 1 + src/main/java/org/apache/commons/lang3/SystemUtils.java | 15 +++++++++++++++ .../java/org/apache/commons/lang3/SystemUtilsTest.java | 10 ++++++++++ 3 files changed, 26 insertions(+) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index c8c6f656a..45936ca04 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -106,6 +106,7 @@ The <action> type attribute can be add,update,fix,remove. <action type="add" dev="ggregory" due-to="Gary Gregory">Add the @FunctionalInterface annotation to org.apache.commons.lang3.concurrent.Computable.</action> <action type="add" dev="ggregory" due-to="Gary Gregory">Add SystemUtils.getJavaIoTmpDirPath().</action> <action type="add" dev="ggregory" due-to="Gary Gregory">Add SystemUtils.getJavaHomePath().</action> + <action type="add" dev="ggregory" due-to="Gary Gregory">Add SystemUtils.getUserDirPath().</action> <!-- UPDATE --> <action type="update" dev="ggregory" due-to="Gary Gregory, Dependabot">Bump org.apache.commons:commons-parent from 73 to 81 #1267, #1277, #1283, #1288, #1302.</action> <action type="update" dev="ggregory" due-to="Gary Gregory, Dependabot">[site] Bump org.codehaus.mojo:taglist-maven-plugin from 3.1.0 to 3.2.1 #1300.</action> diff --git a/src/main/java/org/apache/commons/lang3/SystemUtils.java b/src/main/java/org/apache/commons/lang3/SystemUtils.java index 23a6559db..937ef080f 100644 --- a/src/main/java/org/apache/commons/lang3/SystemUtils.java +++ b/src/main/java/org/apache/commons/lang3/SystemUtils.java @@ -2160,6 +2160,21 @@ public static File getUserDir() { return new File(SystemProperties.getUserDir()); } + /** + * Gets the current user directory as a {@link Path}. + * <p> + * The result is based on the system property {@value SystemProperties#USER_DIR}. + * </p> + * + * @return a directory + * @throws SecurityException if a security manager exists and its {@code checkPropertyAccess} method doesn't allow access to the specified system property. + * @see SystemProperties#getUserDir() + * @since 3.18.0 + */ + public static Path getUserDirPath() { + return Paths.get(SystemProperties.getUserDir()); + } + /** * Gets the current user home directory as a {@link File}. * <p> diff --git a/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java b/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java index a9ce53b29..bf63ea21f 100644 --- a/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java @@ -322,6 +322,16 @@ public void testGetUserDir() { assertTrue(dir.exists()); } + /** + * Assumes no security manager exists. + */ + @Test + public void testGetUserDirPath() { + final Path dir = SystemUtils.getUserDirPath(); + assertNotNull(dir); + assertTrue(Files.exists(dir)); + } + /** * Assumes no security manager exists. */