Skip to content

Commit fb42e80

Browse files
committed
Add SystemUtils.getUserHomePath()
1 parent 421229b commit fb42e80

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

src/changes/changes.xml

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ The <action> type attribute can be add,update,fix,remove.
107107
<action type="add" dev="ggregory" due-to="Gary Gregory">Add SystemUtils.getJavaIoTmpDirPath().</action>
108108
<action type="add" dev="ggregory" due-to="Gary Gregory">Add SystemUtils.getJavaHomePath().</action>
109109
<action type="add" dev="ggregory" due-to="Gary Gregory">Add SystemUtils.getUserDirPath().</action>
110+
<action type="add" dev="ggregory" due-to="Gary Gregory">Add SystemUtils.getUserHomePath().</action>
110111
<!-- UPDATE -->
111112
<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>
112113
<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>

src/main/java/org/apache/commons/lang3/SystemUtils.java

+15
Original file line numberDiff line numberDiff line change
@@ -2190,6 +2190,21 @@ public static File getUserHome() {
21902190
return new File(SystemProperties.getUserHome());
21912191
}
21922192

2193+
/**
2194+
* Gets the current user home directory as a {@link Path}.
2195+
* <p>
2196+
* The result is based on the system property {@value SystemProperties#USER_HOME}.
2197+
* </p>
2198+
*
2199+
* @return a directory
2200+
* @throws SecurityException if a security manager exists and its {@code checkPropertyAccess} method doesn't allow access to the specified system property.
2201+
* @see SystemProperties#getUserHome()
2202+
* @since 3.18.0
2203+
*/
2204+
public static Path getUserHomePath() {
2205+
return Paths.get(SystemProperties.getUserHome());
2206+
}
2207+
21932208
/**
21942209
* Gets the current user name.
21952210
* <p>

src/test/java/org/apache/commons/lang3/SystemUtilsTest.java

+10
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,16 @@ public void testGetUserHome() {
342342
assertTrue(dir.exists());
343343
}
344344

345+
/**
346+
* Assumes no security manager exists.
347+
*/
348+
@Test
349+
public void testGetUserHomePath() {
350+
final Path dir = SystemUtils.getUserHomePath();
351+
assertNotNull(dir);
352+
assertTrue(Files.exists(dir));
353+
}
354+
345355
/**
346356
* Assumes no security manager exists.
347357
*/

0 commit comments

Comments
 (0)