mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Violette Roche-Montane
07.15.2014 73302adac1b5e9aa946418ca776df8be9613ced4
opendj-cli/src/main/java/com/forgerock/opendj/cli/Utils.java
@@ -32,6 +32,8 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.StringTokenizer;
import org.forgerock.i18n.LocalizableMessage;
@@ -44,11 +46,6 @@
    static public final String LINE_SEPARATOR = System.getProperty("line.separator");
    /**
     * The name of a command-line script used to launch a tool.
     */
    public static final String PROPERTY_SCRIPT_NAME = "com.forgerock.opendj.ldap.tools.scriptName";
    /**
     * The column at which to wrap long lines of output in the command-line
     * tools.
     */
@@ -346,6 +343,28 @@
        }
    }
    /**
     * Returns the default host name.
     *
     * @return The default host name or empty string if the host name cannot be resolved.
     */
    public static String getDefaultHostName() {
        try {
            return InetAddress.getLocalHost().getHostName();
        } catch (UnknownHostException e) {
            // Fails.
        }
        String host = System.getenv("COMPUTERNAME"); // Windows.
        if (host != null) {
            return host;
        }
        host = System.getenv("HOSTNAME"); // Unix.
        if (host != null) {
            return host;
        }
        return "";
    }
    // Prevent instantiation.
    private Utils() {
        // Do nothing.