1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
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 String GITHUB_HOME = "/home/runner";
22  
23      static String LOCAL_REPOSITORY_PREFIX = GITHUB_HOME;
24  
25      static public boolean isGithubAction() {
26          String userHome = System.getProperty("user.home");
27          String localRepository = System.getProperty("localRepository");
28  
29          if (GITHUB_HOME.equals(userHome))
30              return true;
31  
32          if (localRepository != null && localRepository.startsWith(LOCAL_REPOSITORY_PREFIX))
33              return true;
34          
35          return false;
36      }
37  
38      static public boolean isWindows() {
39          return System.getProperty("os.name").indexOf("Windows") != -1;
40      }
41  
42      static public boolean isMac() {
43          return System.getProperty("os.name").indexOf("Mac") != -1;
44      }
45  
46      static public boolean isLinux() {
47          return System.getProperty("os.name").indexOf("Linux") != -1;
48      }
49  
50      static public boolean isRunningOnSlowJenkins() {
51          return System.getProperty(CoreTestConstants.SLOW_JENKINS) != null;
52      }
53  
54      static public String getLocalHostName() {
55          InetAddress localhostIA;
56          try {
57              localhostIA = InetAddress.getLocalHost();
58              return localhostIA.getHostName();
59          } catch (UnknownHostException e) {
60              return null;
61          }
62      }
63  
64      static public boolean isLocalHostNameInList(String[] hostList) {
65          String localHostName = getLocalHostName();
66          if (localHostName == null) {
67              return false;
68          }
69          for (String host : hostList) {
70              if (host.equalsIgnoreCase(localHostName)) {
71                  return true;
72              }
73          }
74          return false;
75      }
76  
77      public static String getPathToBash() {
78          if (EnvUtilForTests.isLinux()) {
79              return CoreTestConstants.BASH_PATH_ON_LINUX;
80          }
81          if (EnvUtilForTests.isLocalHostNameInList(new String[] { "hetz", "het" })) {
82              return CoreTestConstants.BASH_PATH_ON_CYGWIN;
83          }
84          return null;
85      }
86  }