001
014
015 package com.liferay.portal.kernel.util;
016
017 import java.io.File;
018
019
022 public class OSDetector {
023
024 public static String getBitmode() {
025 if (_bitMode != null) {
026 return _bitMode;
027 }
028
029 _bitMode = System.getProperty("sun.arch.data.model");
030
031 if (Validator.isNull(_bitMode)) {
032 _bitMode = System.getProperty("com.ibm.vm.bitmode");
033 }
034
035 if (Validator.isNull(_bitMode)) {
036 String arch = System.getProperty("os.arch");
037
038 arch = StringUtil.toLowerCase(arch);
039
040 if (arch.equals("amd64") || arch.equals("x86_64")) {
041 _bitMode = "64";
042 }
043 else if (arch.equals("i386") || arch.equals("i686") ||
044 arch.equals("x86")) {
045
046 _bitMode = "32";
047 }
048 }
049
050 return _bitMode;
051 }
052
053 public static boolean isAIX() {
054 if (_aix != null) {
055 return _aix.booleanValue();
056 }
057
058 String osName = System.getProperty("os.name");
059
060 osName = StringUtil.toLowerCase(osName);
061
062 if (osName.equals("aix")) {
063 _aix = Boolean.TRUE;
064 }
065 else {
066 _aix = Boolean.FALSE;
067 }
068
069 return _aix.booleanValue();
070 }
071
072 public static boolean isApple() {
073 if (_apple != null) {
074 return _apple.booleanValue();
075 }
076
077 String osName = System.getProperty("os.name");
078
079 osName = StringUtil.toLowerCase(osName);
080
081 if (osName.contains("darwin") || osName.contains("mac")) {
082 _apple = Boolean.TRUE;
083 }
084 else {
085 _apple = Boolean.FALSE;
086 }
087
088 return _apple.booleanValue();
089 }
090
091 public static boolean isLinux() {
092 if (_linux != null) {
093 return _linux.booleanValue();
094 }
095
096 String osName = System.getProperty("os.name");
097
098 osName = StringUtil.toLowerCase(osName);
099
100 if (osName.contains("linux")) {
101 _linux = Boolean.TRUE;
102 }
103 else {
104 _linux = Boolean.FALSE;
105 }
106
107 return _linux.booleanValue();
108 }
109
110 public static boolean isUnix() {
111 if (_unix != null) {
112 return _unix.booleanValue();
113 }
114
115 if (File.pathSeparator.equals(StringPool.COLON)) {
116 _unix = Boolean.TRUE;
117 }
118 else {
119 _unix = Boolean.FALSE;
120 }
121
122 return _unix.booleanValue();
123 }
124
125 public static boolean isWindows() {
126 if (_windows != null) {
127 return _windows.booleanValue();
128 }
129
130 if (File.pathSeparator.equals(StringPool.SEMICOLON)) {
131 _windows = Boolean.TRUE;
132 }
133 else {
134 _windows = Boolean.FALSE;
135 }
136
137 return _windows.booleanValue();
138 }
139
140 private static Boolean _aix;
141 private static Boolean _apple;
142 private static String _bitMode;
143 private static Boolean _linux;
144 private static Boolean _unix;
145 private static Boolean _windows;
146
147 }