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