001/* 002 * Logback: the reliable, generic, fast and flexible logging framework. 003 * Copyright (C) 1999-2022, 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 String GITHUB_HOME = "/home/runner"; 022 023 static String LOCAL_REPOSITORY_PREFIX = GITHUB_HOME; 024 025 static public boolean isGithubAction() { 026 String userHome = System.getProperty("user.home"); 027 String localRepository = System.getProperty("localRepository"); 028 029 if (GITHUB_HOME.equals(userHome)) 030 return true; 031 032 if (localRepository != null && localRepository.startsWith(LOCAL_REPOSITORY_PREFIX)) 033 return true; 034 035 return false; 036 } 037 038 static public boolean isWindows() { 039 return System.getProperty("os.name").indexOf("Windows") != -1; 040 } 041 042 static public boolean isMac() { 043 return System.getProperty("os.name").indexOf("Mac") != -1; 044 } 045 046 static public boolean isLinux() { 047 return System.getProperty("os.name").indexOf("Linux") != -1; 048 } 049 050 static public boolean isRunningOnSlowJenkins() { 051 return System.getProperty(CoreTestConstants.SLOW_JENKINS) != null; 052 } 053 054 static public String getLocalHostName() { 055 InetAddress localhostIA; 056 try { 057 localhostIA = InetAddress.getLocalHost(); 058 return localhostIA.getHostName(); 059 } catch (UnknownHostException e) { 060 return null; 061 } 062 } 063 064 static public boolean isLocalHostNameInList(String[] hostList) { 065 String localHostName = getLocalHostName(); 066 if (localHostName == null) { 067 return false; 068 } 069 for (String host : hostList) { 070 if (host.equalsIgnoreCase(localHostName)) { 071 return true; 072 } 073 } 074 return false; 075 } 076 077 public static String getPathToBash() { 078 if (EnvUtilForTests.isLinux()) { 079 return CoreTestConstants.BASH_PATH_ON_LINUX; 080 } 081 if (EnvUtilForTests.isLocalHostNameInList(new String[] { "hetz", "het" })) { 082 return CoreTestConstants.BASH_PATH_ON_CYGWIN; 083 } 084 return null; 085 } 086}