create changelog entry
[debian/openrocket] / core / src / net / sf / openrocket / util / BuildProperties.java
1 package net.sf.openrocket.util;\r
2 \r
3 import java.io.IOException;\r
4 import java.io.InputStream;\r
5 import java.util.MissingResourceException;\r
6 import java.util.Properties;\r
7 \r
8 public class BuildProperties {\r
9 \r
10         private static final Properties PROPERTIES;\r
11         private static final String BUILD_VERSION;\r
12         private static final String BUILD_SOURCE;\r
13         private static final boolean DEFAULT_CHECK_UPDATES;\r
14         \r
15         /**\r
16          * Return the OpenRocket version number.\r
17          */\r
18         public static String getVersion() {\r
19                 return BUILD_VERSION;\r
20         }\r
21         \r
22         /**\r
23          * Return the OpenRocket build source (e.g. "default" or "Debian")\r
24          */\r
25         public static String getBuildSource() {\r
26                 return BUILD_SOURCE;\r
27         }\r
28         \r
29         public static boolean getDefaultCheckUpdates() {\r
30                 return DEFAULT_CHECK_UPDATES;\r
31         }\r
32         \r
33         static {\r
34                 try {\r
35                         InputStream is = BuildProperties.class.getClassLoader().getResourceAsStream("build.properties");\r
36                         if (is == null) {\r
37                                 throw new MissingResourceException(\r
38                                                 "build.properties not found, distribution built wrong" +\r
39                                                                 "   classpath:" + System.getProperty("java.class.path"),\r
40                                                 "build.properties", "build.version");\r
41                         }\r
42                         \r
43                         PROPERTIES = new Properties();\r
44                         PROPERTIES.load(is);\r
45                         is.close();\r
46                         \r
47                         String version = PROPERTIES.getProperty("build.version");\r
48                         if (version == null) {\r
49                                 throw new MissingResourceException(\r
50                                                 "build.version not found in property file",\r
51                                                 "build.properties", "build.version");\r
52                         }\r
53                         BUILD_VERSION = version.trim();\r
54                         \r
55                         BUILD_SOURCE = PROPERTIES.getProperty("build.source");\r
56                         if (BUILD_SOURCE == null) {\r
57                                 throw new MissingResourceException(\r
58                                                 "build.source not found in property file",\r
59                                                 "build.properties", "build.source");\r
60                         }\r
61                         \r
62                         String value = PROPERTIES.getProperty("build.checkupdates");\r
63                         if (value != null)\r
64                                 DEFAULT_CHECK_UPDATES = Boolean.parseBoolean(value);\r
65                         else\r
66                                 DEFAULT_CHECK_UPDATES = true;\r
67                         \r
68                 } catch (IOException e) {\r
69                         throw new MissingResourceException(\r
70                                         "Error reading build.properties",\r
71                                         "build.properties", "build.version");\r
72                 }\r
73         }\r
74 \r
75 }\r