001/**
002 * Logback: the reliable, generic, fast and flexible logging framework.
003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
004 *
005 * This program and the accompanying materials are dual-licensed under
006 * either the terms of the Eclipse Public License v1.0 as published by
007 * the Eclipse Foundation
008 *
009 *   or (per the licensee's choosing)
010 *
011 * under the terms of the GNU Lesser General Public License version 2.1
012 * as published by the Free Software Foundation.
013 */
014package ch.qos.logback.core.testUtil;
015
016import java.net.InetAddress;
017import java.net.UnknownHostException;
018
019public class EnvUtilForTests {
020
021    static public boolean isWindows() {
022        return System.getProperty("os.name").indexOf("Windows") != -1;
023    }
024
025    static public boolean isMac() {
026        return System.getProperty("os.name").indexOf("Mac") != -1;
027    }
028
029    static public boolean isLinux() {
030        return System.getProperty("os.name").indexOf("Linux") != -1;
031    }
032
033    static public boolean isRunningOnSlowJenkins() {
034        return System.getProperty(CoreTestConstants.SLOW_JENKINS) != null;
035    }
036
037    static public String getLocalHostName() {
038        InetAddress localhostIA;
039        try {
040            localhostIA = InetAddress.getLocalHost();
041            return localhostIA.getHostName();
042        } catch (UnknownHostException e) {
043            return null;
044        }
045    }
046
047    static public boolean isLocalHostNameInList(String[] hostList) {
048        String localHostName = getLocalHostName();
049        if (localHostName == null) {
050            return false;
051        }
052        for (String host : hostList) {
053            if (host.equalsIgnoreCase(localHostName)) {
054                return true;
055            }
056        }
057        return false;
058    }
059
060    public static String getPathToBash() {
061        if (EnvUtilForTests.isLinux()) {
062            return CoreTestConstants.BASH_PATH_ON_LINUX;
063        }
064        if (EnvUtilForTests.isLocalHostNameInList(new String[] { "hetz", "het" })) {
065            return CoreTestConstants.BASH_PATH_ON_CYGWIN;
066        }
067        return null;
068    }
069}