BowlerKernel
BowlerKernelBuildInfo.java
Go to the documentation of this file.
1 package com.neuronrobotics.bowlerkernel;
2 
3 import java.io.BufferedReader;
4 import java.io.IOException;
5 import java.io.InputStream;
6 import java.io.InputStreamReader;
7 
11 public class BowlerKernelBuildInfo {
12 
16  private static final String NAME = "CommonWealthRobotics SDK "
17  + getProtocolVersion() + "." + getSDKVersion() + "("
18  + getBuildVersion() + ")";
19 
25  public static String getVersion() {
26  String s = getTag("app.version");
27  if (s == null) {
28  s = "0.0.0";
29  }
30  return s;
31  }
32 
38  public static int getProtocolVersion() {
39  return getBuildInfo()[0];
40  }
41 
47  public static int getSDKVersion() {
48  return getBuildInfo()[1];
49  }
50 
56  public static int getBuildVersion() {
57  return getBuildInfo()[2];
58  }
59 
65  public static int[] getBuildInfo() {
66  String s = getVersion();
67  String[] splits = s.split("[.]+");
68  int[] rev = new int[3];
69  for (int i = 0; i < 3; i++) {
70  rev[i] = new Integer(splits[i]);
71  }
72  return rev;
73  }
74 
81  private static String getTag(String target) {
82  try {
83  String s = "";
84  InputStream is = getBuildPropertiesStream();
85  BufferedReader br = new BufferedReader(new InputStreamReader(is));
86  String line;
87  try {
88  while (null != (line = br.readLine())) {
89  s += line + "\n";
90  }
91  } catch (IOException e) {
92  }
93  String[] splitAll = s.split("[\n]+");
94  for (int i = 0; i < splitAll.length; i++) {
95  if (splitAll[i].contains(target)) {
96  String[] split = splitAll[i].split("[=]+");
97  return split[1];
98  }
99  }
100  } catch (NullPointerException e) {
101  return null;
102  }
103  return null;
104  }
105 
111  public static String getBuildDate() {
112  String s = "";
113  InputStream is = BowlerKernelBuildInfo.class
114  .getResourceAsStream("/META-INF/MANIFEST.MF");
115  BufferedReader br = new BufferedReader(new InputStreamReader(is));
116  String line;
117  try {
118  while (null != (line = br.readLine())) {
119  s += line + "\n";
120  }
121  } catch (IOException e) {
122  }
123  // System.out.println("Manifest:\n"+s);
124  return "";
125  }
126 
132  private static InputStream getBuildPropertiesStream() {
133  return BowlerKernelBuildInfo.class.getResourceAsStream("build.properties");
134  }
135 
141  public static String getSDKVersionString() {
142  return NAME;
143  }
144 
150  public static boolean isOS64bit() {
151  return (System.getProperty("os.arch").indexOf("x86_64") != -1);
152  }
153 
159  public static boolean isARM() {
160  return (System.getProperty("os.arch").toLowerCase().indexOf("arm") != -1);
161  }
162 
168  public static boolean isLinux() {
169  return (System.getProperty("os.name").toLowerCase().indexOf("linux") != -1);
170  }
171 
177  public static boolean isWindows() {
178  return (System.getProperty("os.name").toLowerCase().indexOf("win") != -1);
179  }
180 
186  public static boolean isMac() {
187  return (System.getProperty("os.name").toLowerCase().indexOf("mac") != -1);
188  }
189 
195  public static boolean isUnix() {
196  return (isLinux() || isMac());
197  }
198 }