docs/docs-core/src/main/java/com/sismics/util/EnvironmentUtil.java

115 lines
2.6 KiB
Java
Raw Normal View History

2013-07-27 18:33:20 +02:00
package com.sismics.util;
/**
* Environment properties utilities.
*
* @author jtremeaux
*/
public class EnvironmentUtil {
private static String OS = System.getProperty("os.name").toLowerCase();
2015-09-07 21:51:13 +02:00
private static String APPLICATION_MODE = System.getProperty("application.mode");
2013-07-27 18:33:20 +02:00
private static String WINDOWS_APPDATA = System.getenv("APPDATA");
private static String MAC_OS_USER_HOME = System.getProperty("user.home");
private static String DOCS_HOME = System.getProperty("docs.home");
/**
2015-09-07 21:51:13 +02:00
* In a web application context.
2013-07-27 18:33:20 +02:00
*/
2015-09-07 21:51:13 +02:00
private static boolean webappContext;
2013-07-27 18:33:20 +02:00
/**
* Returns true if running under Microsoft Windows.
*
* @return Running under Microsoft Windows
*/
public static boolean isWindows() {
2018-01-24 15:39:27 +01:00
return OS.contains("win");
2013-07-27 18:33:20 +02:00
}
/**
* Returns true if running under Mac OS.
*
* @return Running under Mac OS
*/
public static boolean isMacOs() {
2018-01-24 15:39:27 +01:00
return OS.contains("mac");
2013-07-27 18:33:20 +02:00
}
/**
* Returns true if running under UNIX.
*
* @return Running under UNIX
*/
public static boolean isUnix() {
2018-01-24 15:39:27 +01:00
return OS.contains("nix") || OS.contains("nux") || OS.contains("aix");
2013-07-27 18:33:20 +02:00
}
/**
* Returns true if we are in a unit testing environment.
*
* @return Unit testing environment
*/
public static boolean isUnitTest() {
2015-09-07 21:51:13 +02:00
return !webappContext || isDevMode();
2013-07-27 18:33:20 +02:00
}
2015-09-07 21:51:13 +02:00
/**
* Return true if we are in dev mode.
*
* @return Dev mode
*/
public static boolean isDevMode() {
return "dev".equalsIgnoreCase(APPLICATION_MODE);
}
2013-07-27 18:33:20 +02:00
/**
* Returns the MS Windows AppData directory of this user.
*
* @return AppData directory
*/
public static String getWindowsAppData() {
return WINDOWS_APPDATA;
}
/**
* Returns the Mac OS home directory of this user.
*
* @return Home directory
*/
public static String getMacOsUserHome() {
return MAC_OS_USER_HOME;
}
/**
* Returns the home directory of DOCS (e.g. /var/docs).
*
* @return Home directory
*/
public static String getDocsHome() {
return DOCS_HOME;
}
/**
2015-09-07 21:51:13 +02:00
* Getter of webappContext.
2013-07-27 18:33:20 +02:00
*
2015-09-07 21:51:13 +02:00
* @return webappContext
2013-07-27 18:33:20 +02:00
*/
2015-09-07 21:51:13 +02:00
public static boolean isWebappContext() {
return webappContext;
2013-07-27 18:33:20 +02:00
}
/**
2015-09-07 21:51:13 +02:00
* Setter of webappContext.
2013-07-27 18:33:20 +02:00
*
2015-09-07 21:51:13 +02:00
* @param webappContext webappContext
2013-07-27 18:33:20 +02:00
*/
2015-09-07 21:51:13 +02:00
public static void setWebappContext(boolean webappContext) {
EnvironmentUtil.webappContext = webappContext;
2013-07-27 18:33:20 +02:00
}
}