]> git.gag.com Git - debian/openrocket/blob - src/net/sf/openrocket/startup/VersionHelper.java
preset component framework
[debian/openrocket] / src / net / sf / openrocket / startup / VersionHelper.java
1 package net.sf.openrocket.startup;
2
3 import net.sf.openrocket.logging.LogHelper;
4
5 public class VersionHelper {
6         
7         private static final LogHelper log = Application.getLogger();
8         
9         private static final int REQUIRED_MAJOR_VERSION = 1;
10         private static final int REQUIRED_MINOR_VERSION = 6;
11         
12         // OpenJDK 1.6.0_0-b16 is known to work, 1.6.0_0-b12 does not
13         private static final String BAD_OPENJDK_VERSION = "^1.6.0_0-b([0-9]|1[1-5])$";
14         
15         
16         /**
17          * Check that the JRE version is high enough.
18          */
19         static void checkVersion() {
20                 
21                 String[] version = System.getProperty("java.specification.version", "").split("\\.");
22                 
23                 String jreName = System.getProperty("java.vm.name", "(unknown)");
24                 String jreVersion = System.getProperty("java.runtime.version", "(unknown)");
25                 String jreVendor = System.getProperty("java.vendor", "(unknown)");
26                 
27                 log.info("Running JRE " + jreName + " version " + jreVersion + " by " + jreVendor);
28                 
29                 int major, minor;
30                 
31                 try {
32                         major = Integer.parseInt(version[0]);
33                         minor = Integer.parseInt(version[1]);
34                         
35                         if (major < REQUIRED_MAJOR_VERSION ||
36                                         (major == REQUIRED_MAJOR_VERSION && minor < REQUIRED_MINOR_VERSION)) {
37                                 Startup.error(new String[] { "Java SE version 6 is required to run OpenRocket.",
38                                                 "You are currently running " + jreName + " version " +
39                                                                 jreVersion + " by " + jreVendor });
40                         }
41                         
42                 } catch (RuntimeException e) {
43                         
44                         Startup.confirm(new String[] { "The Java version in use could not be detected.",
45                                         "OpenRocket requires at least Java SE 6.",
46                                         "Continue anyway?" });
47                         
48                 }
49                 
50         }
51         
52         /**
53          * Check whether OpenJDK is being used, and if it is warn the user about
54          * problems and confirm whether to continue.
55          */
56         static void checkOpenJDK() {
57                 
58                 if (System.getProperty("java.runtime.name", "").toLowerCase().indexOf("icedtea") >= 0 ||
59                                 System.getProperty("java.vm.name", "").toLowerCase().indexOf("openjdk") >= 0) {
60                         
61                         String jreName = System.getProperty("java.vm.name", "(unknown)");
62                         String jreVersion = System.getProperty("java.runtime.version", "(unknown)");
63                         String jreVendor = System.getProperty("java.vendor", "(unknown)");
64                         
65                         if (jreVersion.matches(BAD_OPENJDK_VERSION)) {
66                                 
67                                 Startup.confirm(new String[] { "Old versions of OpenJDK are known to have problems " +
68                                                 "running OpenRocket.",
69                                                 " ",
70                                                 "You are currently running " + jreName + " version " +
71                                                                 jreVersion + " by " + jreVendor,
72                                                 "Do you want to continue?" });
73                         }
74                 }
75         }
76         
77 }