Debian Codegraph @

src/com/bulenkov/iconloader/util/SystemInfo.java

raw symbols SCIP
1 /*
2 * Copyright 2000-2014 JetBrains s.r.o.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package com.bulenkov.iconloader.util;
18
19 /**
20 * @author Konstantin Bulenkov
21 */
22 @SuppressWarnings({"HardCodedStringLiteral", "UtilityClassWithoutPrivateConstructor", "UnusedDeclaration"})
23 public class SystemInfo {
24 public static final String OS_NAME = System.getProperty("os.name");
25 public static final String OS_VERSION = System.getProperty("os.version").toLowerCase();
26 public static final String JAVA_VERSION = System.getProperty("java.version");
27 public static final String JAVA_RUNTIME_VERSION = System.getProperty("java.runtime.version");
28
29 protected static final String _OS_NAME = OS_NAME.toLowerCase();
30 public static final boolean isWindows = _OS_NAME.startsWith("windows");
31 public static final boolean isOS2 = _OS_NAME.startsWith("os/2") || _OS_NAME.startsWith("os2");
32 public static final boolean isMac = _OS_NAME.startsWith("mac");
33 public static final boolean isLinux = _OS_NAME.startsWith("linux");
34 public static final boolean isUnix = !isWindows && !isOS2;
35
36 public static final boolean isFileSystemCaseSensitive = isUnix && !isMac;
37 public static final boolean isMacOSLion = isLion();
38
39 public static final boolean isAppleJvm = isAppleJvm();
40 public static final boolean isOracleJvm = isOracleJvm();
41 public static final boolean isSunJvm = isSunJvm();
42 public static final boolean isJetbrainsJvm = isJetbrainsJvm();
43
44 public static boolean isOsVersionAtLeast(String version) {
45 return compareVersionNumbers(OS_VERSION, version) >= 0;
46 }
47
48
49 private static boolean isTiger() {
50 return isMac &&
51 !OS_VERSION.startsWith("10.0") &&
52 !OS_VERSION.startsWith("10.1") &&
53 !OS_VERSION.startsWith("10.2") &&
54 !OS_VERSION.startsWith("10.3");
55 }
56
57 private static boolean isLeopard() {
58 return isMac && isTiger() && !OS_VERSION.startsWith("10.4");
59 }
60
61 private static boolean isSnowLeopard() {
62 return isMac && isLeopard() && !OS_VERSION.startsWith("10.5");
63 }
64
65 private static boolean isLion() {
66 return isMac && isSnowLeopard() && !OS_VERSION.startsWith("10.6");
67 }
68
69 private static boolean isMountainLion() {
70 return isMac && isLion() && !OS_VERSION.startsWith("10.7");
71 }
72
73 public static int compareVersionNumbers(String v1, String v2) {
74 if (v1 == null && v2 == null) {
75 return 0;
76 }
77 if (v1 == null) {
78 return -1;
79 }
80 if (v2 == null) {
81 return 1;
82 }
83
84 String[] part1 = v1.split("[\\.\\_\\-]");
85 String[] part2 = v2.split("[\\.\\_\\-]");
86
87 int idx = 0;
88 for (; idx < part1.length && idx < part2.length; idx++) {
89 String p1 = part1[idx];
90 String p2 = part2[idx];
91
92 int cmp;
93 if (p1.matches("\\d+") && p2.matches("\\d+")) {
94 cmp = new Integer(p1).compareTo(new Integer(p2));
95 } else {
96 cmp = part1[idx].compareTo(part2[idx]);
97 }
98 if (cmp != 0) return cmp;
99 }
100
101 if (part1.length == part2.length) {
102 return 0;
103 } else if (part1.length > idx) {
104 return 1;
105 } else {
106 return -1;
107 }
108 }
109
110 public static boolean isJavaVersionAtLeast(String v) {
111 return StringUtil.compareVersionNumbers(JAVA_RUNTIME_VERSION, v) >= 0;
112 }
113
114 private static boolean isOracleJvm() {
115 final String vendor = getJavaVmVendor();
116 return vendor != null && StringUtil.containsIgnoreCase(vendor, "Oracle");
117 }
118
119 private static boolean isSunJvm() {
120 final String vendor = getJavaVmVendor();
121 return vendor != null && StringUtil.containsIgnoreCase(vendor, "Sun") && StringUtil.containsIgnoreCase(vendor, "Microsystems");
122 }
123
124 private static boolean isAppleJvm() {
125 final String vendor = getJavaVmVendor();
126 return vendor != null && StringUtil.containsIgnoreCase(vendor, "Apple");
127 }
128
129 public static String getJavaVmVendor() {
130 return System.getProperty("java.vm.vendor");
131 }
132
133 private static boolean isJetbrainsJvm() {
134 final String vendor = System.getProperty("java.vendor");
135 return vendor != null && StringUtil.containsIgnoreCase(vendor, "jetbrains");
136 }
137 }