forked from miho/JCSG
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathJavaCadBuildInfo.java
More file actions
199 lines (181 loc) · 3.94 KB
/
JavaCadBuildInfo.java
File metadata and controls
199 lines (181 loc) · 3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
package com.neuronrobotics.javacad;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
// TODO: Auto-generated Javadoc
/**
* The Class SDKBuildInfo.
*/
public class JavaCadBuildInfo {
/** The Constant NAME. */
private static final String NAME = "Neuron Robotics SDK "
+ getProtocolVersion() + "." + getSDKVersion() + "("
+ getBuildVersion() + ")";
/**
* Gets the version.
*
* @return the version
*/
public static String getVersion() {
String s = getTag("app.version");
if (s == null)
s = "0.0.0";
return s;
}
/**
* Gets the protocol version.
*
* @return the protocol version
*/
public static int getProtocolVersion() {
return getBuildInfo()[0];
}
/**
* Gets the SDK version.
*
* @return the SDK version
*/
public static int getSDKVersion() {
return getBuildInfo()[1];
}
/**
* Gets the builds the version.
*
* @return the builds the version
*/
public static int getBuildVersion() {
return getBuildInfo()[2];
}
/**
* Gets the builds the info.
*
* @return the builds the info
*/
public static int[] getBuildInfo() {
String s = getVersion();
String[] splits = s.split("[.]+");
if (splits.length == 1) {
return new int[]{0, 0, 0};
}
int[] rev = new int[3];
for (int i = 0; i < 3; i++) {
rev[i] = new Integer(splits[i]);
}
return rev;
}
/**
* Gets the tag.
*
* @param target the target
* @return the tag
*/
private static String getTag(String target) {
try {
String s = "";
InputStream is = getBuildPropertiesStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line;
try {
while (null != (line = br.readLine())) {
s += line + "\n";
}
} catch (IOException e) {
}
String[] splitAll = s.split("[\n]+");
for (int i = 0; i < splitAll.length; i++) {
if (splitAll[i].contains(target)) {
String[] split = splitAll[i].split("[=]+");
return split[1];
}
}
} catch (NullPointerException e) {
return null;
}
return null;
}
/**
* Gets the builds the date.
*
* @return the builds the date
*/
public static String getBuildDate() {
String s = "";
InputStream is = JavaCadBuildInfo.class
.getResourceAsStream("/META-INF/MANIFEST.MF");
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line;
try {
while (null != (line = br.readLine())) {
s += line + "\n";
}
} catch (IOException e) {
}
// com.neuronrobotics.sdk.common.Log.error("Manifest:\n"+s);
return "";
}
/**
* Gets the builds the properties stream.
*
* @return the builds the properties stream
*/
private static InputStream getBuildPropertiesStream() {
return JavaCadBuildInfo.class.getResourceAsStream("build.properties");
}
/**
* Gets the SDK version string.
*
* @return the SDK version string
*/
public static String getSDKVersionString() {
return NAME;
}
/**
* Checks if is o s64bit.
*
* @return true, if is o s64bit
*/
public static boolean isOS64bit() {
return (System.getProperty("os.arch").indexOf("x86_64") != -1);
}
/**
* Checks if is arm.
*
* @return true, if is arm
*/
public static boolean isARM() {
return (System.getProperty("os.arch").toLowerCase().indexOf("arm") != -1);
}
/**
* Checks if is linux.
*
* @return true, if is linux
*/
public static boolean isLinux() {
return (System.getProperty("os.name").toLowerCase().indexOf("linux") != -1);
}
/**
* Checks if is windows.
*
* @return true, if is windows
*/
public static boolean isWindows() {
return (System.getProperty("os.name").toLowerCase().indexOf("win") != -1);
}
/**
* Checks if is mac.
*
* @return true, if is mac
*/
public static boolean isMac() {
return (System.getProperty("os.name").toLowerCase().indexOf("mac") != -1);
}
/**
* Checks if is unix.
*
* @return true, if is unix
*/
public static boolean isUnix() {
return (isLinux() || isMac());
}
}