[LANG-1297] SystemUtils.getHostName() API.
This commit is contained in:
parent
cdfb2aa1e1
commit
bd5cc81ed7
|
@ -72,6 +72,7 @@ The <action> type attribute can be add,update,fix,remove.
|
||||||
<action issue="LANG-1277" type="update" dev="pschumacher" due-to="yufcuy">StringUtils#getLevenshteinDistance reduce memory consumption</action>
|
<action issue="LANG-1277" type="update" dev="pschumacher" due-to="yufcuy">StringUtils#getLevenshteinDistance reduce memory consumption</action>
|
||||||
<action issue="LANG-1279" type="update" dev="ggregory">Update Java requirement from Java 6 to 7.</action>
|
<action issue="LANG-1279" type="update" dev="ggregory">Update Java requirement from Java 6 to 7.</action>
|
||||||
<action issue="LANG-1143" type="update" dev="pschumacher" due-to="sebb">StringUtils should use toXxxxCase(int) rather than toXxxxCase(char)</action>
|
<action issue="LANG-1143" type="update" dev="pschumacher" due-to="sebb">StringUtils should use toXxxxCase(int) rather than toXxxxCase(char)</action>
|
||||||
|
<action issue="LANG-1297" type="update" dev="ggregory">Add SystemUtils.getHostName() API.</action>
|
||||||
</release>
|
</release>
|
||||||
|
|
||||||
<release version="3.5" date="2016-10-13" description="New features including Java 9 detection">
|
<release version="3.5" date="2016-10-13" description="New features including Java 9 detection">
|
||||||
|
|
|
@ -1493,6 +1493,16 @@ public class SystemUtils {
|
||||||
return new File(System.getProperty(JAVA_HOME_KEY));
|
return new File(System.getProperty(JAVA_HOME_KEY));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the host name.
|
||||||
|
*
|
||||||
|
* @return the host name.
|
||||||
|
* @since 3.6
|
||||||
|
*/
|
||||||
|
public static String getHostName() {
|
||||||
|
return SystemUtils.IS_OS_WINDOWS ? System.getenv("COMPUTERNAME") : System.getenv("HOSTNAME");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* Gets the Java IO temporary directory as a {@code File}.
|
* Gets the Java IO temporary directory as a {@code File}.
|
||||||
|
|
|
@ -58,6 +58,15 @@ public class SystemUtilsTest {
|
||||||
assertFalse(Modifier.isFinal(SystemUtils.class.getModifiers()));
|
assertFalse(Modifier.isFinal(SystemUtils.class.getModifiers()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetHostName() {
|
||||||
|
final String hostName = SystemUtils.getHostName();
|
||||||
|
Assert.assertNotNull(hostName);
|
||||||
|
Assert.assertFalse(hostName.isEmpty());
|
||||||
|
String expected = SystemUtils.IS_OS_WINDOWS ? System.getenv("COMPUTERNAME") : System.getenv("HOSTNAME");
|
||||||
|
Assert.assertEquals(expected, hostName);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assumes no security manager exists.
|
* Assumes no security manager exists.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue