View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package ch.qos.logback.core.testUtil;
15  
16  import java.net.InetAddress;
17  import java.net.UnknownHostException;
18  
19  public class EnvUtilForTests {
20  
21      static public boolean isWindows() {
22          return System.getProperty("os.name").indexOf("Windows") != -1;
23      }
24  
25      static public boolean isMac() {
26          return System.getProperty("os.name").indexOf("Mac") != -1;
27      }
28  
29      static public boolean isLinux() {
30          return System.getProperty("os.name").indexOf("Linux") != -1;
31      }
32  
33      static public boolean isRunningOnSlowJenkins() {
34          return System.getProperty(CoreTestConstants.SLOW_JENKINS) != null;
35      }
36  
37      static public String getLocalHostName() {
38          InetAddress localhostIA;
39          try {
40              localhostIA = InetAddress.getLocalHost();
41              return localhostIA.getHostName();
42          } catch (UnknownHostException e) {
43              return null;
44          }
45      }
46  
47      static public boolean isLocalHostNameInList(String[] hostList) {
48          String localHostName = getLocalHostName();
49          if (localHostName == null) {
50              return false;
51          }
52          for (String host : hostList) {
53              if (host.equalsIgnoreCase(localHostName)) {
54                  return true;
55              }
56          }
57          return false;
58      }
59  
60      public static String getPathToBash() {
61          if (EnvUtilForTests.isLinux()) {
62              return CoreTestConstants.BASH_PATH_ON_LINUX;
63          }
64          if (EnvUtilForTests.isLocalHostNameInList(new String[] { "hetz", "het" })) {
65              return CoreTestConstants.BASH_PATH_ON_CYGWIN;
66          }
67          return null;
68      }
69  }