JavaCAD
JavaCadBuildInfo.java
Go to the documentation of this file.
1 package com.neuronrobotics.javacad;
2 
3 import java.io.BufferedReader;
4 import java.io.IOException;
5 import java.io.InputStream;
6 import java.io.InputStreamReader;
7 
8 // TODO: Auto-generated Javadoc
12 public class JavaCadBuildInfo {
14  private static final String NAME = "Neuron Robotics SDK "
15  + getProtocolVersion() + "." + getSDKVersion() + "("
16  + getBuildVersion() + ")";
17 
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 
35  public static int getProtocolVersion() {
36  return getBuildInfo()[0];
37  }
38 
44  public static int getSDKVersion() {
45  return getBuildInfo()[1];
46  }
47 
53  public static int getBuildVersion() {
54  return getBuildInfo()[2];
55  }
56 
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 
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 
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  // System.out.println("Manifest:\n"+s);
121  return "";
122  }
123 
129  private static InputStream getBuildPropertiesStream() {
130  return JavaCadBuildInfo.class.getResourceAsStream("build.properties");
131  }
132 
138  public static String getSDKVersionString() {
139  return NAME;
140  }
141 
147  public static boolean isOS64bit() {
148  return (System.getProperty("os.arch").indexOf("x86_64") != -1);
149  }
150 
156  public static boolean isARM() {
157  return (System.getProperty("os.arch").toLowerCase().indexOf("arm") != -1);
158  }
159 
165  public static boolean isLinux() {
166  return (System.getProperty("os.name").toLowerCase().indexOf("linux") != -1);
167  }
168 
174  public static boolean isWindows() {
175  return (System.getProperty("os.name").toLowerCase().indexOf("win") != -1);
176  }
177 
183  public static boolean isMac() {
184  return (System.getProperty("os.name").toLowerCase().indexOf("mac") != -1);
185  }
186 
192  public static boolean isUnix() {
193  return (isLinux() || isMac());
194  }
195 }