BowlerKernel
StudioBuildInfo.java
Go to the documentation of this file.
1 package com.neuronrobotics.bowlerstudio.assets;
2 
3 import java.io.BufferedReader;
4 import java.io.IOException;
5 import java.io.InputStream;
6 import java.io.InputStreamReader;
7 
8 import com.neuronrobotics.bowlerstudio.BowlerKernel;
9 
10 public class StudioBuildInfo {
11 
12  private static Class baseBuildInfoClass = BowlerKernel.class;
13 
14  public static String getVersion() {
15  String s = getTag("app.version");
16 
17  if (s == null) {
18  s="0.0.0";
19  }
20  return s;
21  }
22 
23  public static int getProtocolVersion() {
24  return getBuildInfo()[0];
25  }
26 
27  public static int getSDKVersion() {
28  return getBuildInfo()[1];
29  }
30 
31  public static int getBuildVersion() {
32  return getBuildInfo()[2];
33  }
34 
35  public static int[] getBuildInfo() {
36  try {
37  String s = getVersion();
38  String[] splits = s.split("[.]+");
39  int[] rev = new int[3];
40  for (int i = 0; i < 3; i++) {
41  rev[i] = new Integer(splits[i]);
42  }
43  return rev;
44  } catch (NumberFormatException e) {
45  return new int[]{0, 0, 0};
46  }
47 
48  }
49 
50  private static String getTag(String target) {
51  try {
52  StringBuilder s = new StringBuilder();
53  InputStream is = getBuildPropertiesStream();
54  BufferedReader br = new BufferedReader(new InputStreamReader(is));
55 
56  String line;
57  try {
58  while (null != (line = br.readLine())) {
59  s.append(line).append("\n");
60  }
61  } catch (IOException ignored) {
62  }
63 
64  String[] splitAll = s.toString().split("[\n]+");
65  for (String aSplitAll : splitAll) {
66  if (aSplitAll.contains(target)) {
67  String[] split = aSplitAll.split("[=]+");
68  return split[1];
69  }
70  }
71  } catch (NullPointerException e) {
72  return null;
73  }
74  return null;
75  }
76 
77  public static String getBuildDate() {
78  String s = "";
79  InputStream is = StudioBuildInfo.class
80  .getResourceAsStream("/META-INF/MANIFEST.MF");
81  BufferedReader br = new BufferedReader(new InputStreamReader(is));
82  String line;
83  try {
84  while (null != (line = br.readLine())) {
85  s += line + "\n";
86  }
87  } catch (IOException ignored) {
88  }
89  // System.out.println("Manifest:\n"+s);
90  return "";
91  }
92 
93  private static InputStream getBuildPropertiesStream() {
94  return baseBuildInfoClass.getResourceAsStream("build.properties");
95  }
96 
97  public static String getSDKVersionString() {
98  return getName();
99  }
100 
101  public static boolean isOS64bit() {
102  return (System.getProperty("os.arch").contains("64"));
103  }
104 
105  public static boolean isARM() {
106  return (System.getProperty("os.arch").toLowerCase().contains("arm"));
107  }
108 
109  public static boolean isLinux() {
110  return (System.getProperty("os.name").toLowerCase().contains("linux"));
111  }
112 
113  public static boolean isWindows() {
114  return (System.getProperty("os.name").toLowerCase().contains("win"));
115  }
116 
117  public static boolean isMac() {
118  return (System.getProperty("os.name").toLowerCase().contains("mac"));
119  }
120 
121  public static boolean isUnix() {
122  return (isLinux() || isMac());
123  }
124 
125  public static Class getBaseBuildInfoClass() {
126  return baseBuildInfoClass;
127  }
128 
129  public static void setBaseBuildInfoClass(Class c) {
130  baseBuildInfoClass = c;
131  }
132 
133  public static String getName() {
134  return "Bowler Studio "
135  + getProtocolVersion() + "." + getSDKVersion() + "("
136  + getBuildVersion() + ")";
137  }
138 }