commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject [lang] [LANG-1297] SystemUtils.getHostName() API.
Date Wed, 14 Dec 2016 22:22:37 GMT
Repository: commons-lang
Updated Branches:
  refs/heads/master cdfb2aa1e -> bd5cc81ed


[LANG-1297] SystemUtils.getHostName() API.

Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/bd5cc81e
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/bd5cc81e
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/bd5cc81e

Branch: refs/heads/master
Commit: bd5cc81ed7f91865aee7a5a7febeb237220d0c5a
Parents: cdfb2aa
Author: Gary Gregory <ggregory@apache.org>
Authored: Wed Dec 14 14:22:34 2016 -0800
Committer: Gary Gregory <ggregory@apache.org>
Committed: Wed Dec 14 14:22:34 2016 -0800

----------------------------------------------------------------------
 src/changes/changes.xml                                   |  1 +
 src/main/java/org/apache/commons/lang3/SystemUtils.java   | 10 ++++++++++
 .../java/org/apache/commons/lang3/SystemUtilsTest.java    |  9 +++++++++
 3 files changed, 20 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-lang/blob/bd5cc81e/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 0d91422..12732d7 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -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-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-1297" type="update" dev="ggregory">Add SystemUtils.getHostName()
API.</action>
   </release>
 
   <release version="3.5" date="2016-10-13" description="New features including Java 9
detection">

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/bd5cc81e/src/main/java/org/apache/commons/lang3/SystemUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/SystemUtils.java b/src/main/java/org/apache/commons/lang3/SystemUtils.java
index e3eda9b..f850f65 100644
--- a/src/main/java/org/apache/commons/lang3/SystemUtils.java
+++ b/src/main/java/org/apache/commons/lang3/SystemUtils.java
@@ -1494,6 +1494,16 @@ public class SystemUtils {
     }
 
     /**
+     * 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>
      * Gets the Java IO temporary directory as a {@code File}.
      * </p>

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/bd5cc81e/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java b/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java
index af977e8..d10b2d9 100644
--- a/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java
@@ -58,6 +58,15 @@ public class SystemUtilsTest {
         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.
      */


Mime
View raw message