1 package net.sf.openrocket.startup;
3 import java.awt.GraphicsEnvironment;
4 import java.util.Locale;
6 import javax.swing.JOptionPane;
8 import net.sf.openrocket.logging.LogHelper;
10 public class VersionHelper {
12 private static final LogHelper log = Application.getLogger();
14 private static final int REQUIRED_MAJOR_VERSION = 1;
15 private static final int REQUIRED_MINOR_VERSION = 6;
17 // OpenJDK 1.6.0_0-b16 is known to work, 1.6.0_0-b12 does not
18 private static final String BAD_OPENJDK_VERSION = "^1.6.0_0-b([0-9]|1[1-5])$";
22 * Check that the JRE version is high enough.
24 static void checkVersion() {
26 String[] version = System.getProperty("java.specification.version", "").split("\\.");
28 String jreName = System.getProperty("java.vm.name", "(unknown)");
29 String jreVersion = System.getProperty("java.runtime.version", "(unknown)");
30 String jreVendor = System.getProperty("java.vendor", "(unknown)");
32 log.info("Running JRE " + jreName + " version " + jreVersion + " by " + jreVendor);
37 major = Integer.parseInt(version[0]);
38 minor = Integer.parseInt(version[1]);
40 if (major < REQUIRED_MAJOR_VERSION ||
41 (major == REQUIRED_MAJOR_VERSION && minor < REQUIRED_MINOR_VERSION)) {
42 error(new String[] { "Java SE version 6 is required to run OpenRocket.",
43 "You are currently running " + jreName + " version " +
44 jreVersion + " by " + jreVendor });
47 } catch (RuntimeException e) {
49 confirm(new String[] { "The Java version in use could not be detected.",
50 "OpenRocket requires at least Java SE 6.",
51 "Continue anyway?" });
58 * Check whether OpenJDK is being used, and if it is warn the user about
59 * problems and confirm whether to continue.
61 static void checkOpenJDK() {
63 if (System.getProperty("java.runtime.name", "").toLowerCase(Locale.ENGLISH).indexOf("icedtea") >= 0 ||
64 System.getProperty("java.vm.name", "").toLowerCase(Locale.ENGLISH).indexOf("openjdk") >= 0) {
66 String jreName = System.getProperty("java.vm.name", "(unknown)");
67 String jreVersion = System.getProperty("java.runtime.version", "(unknown)");
68 String jreVendor = System.getProperty("java.vendor", "(unknown)");
70 if (jreVersion.matches(BAD_OPENJDK_VERSION)) {
72 confirm(new String[] { "Old versions of OpenJDK are known to have problems " +
73 "running OpenRocket.",
75 "You are currently running " + jreName + " version " +
76 jreVersion + " by " + jreVendor,
77 "Do you want to continue?" });
84 /////////// Helper methods //////////
87 * Presents an error message to the user and exits the application.
89 * @param message an array of messages to present.
91 private static void error(String[] message) {
94 System.err.println("Error starting OpenRocket:");
96 for (int i = 0; i < message.length; i++) {
97 System.err.println(message[i]);
102 if (!GraphicsEnvironment.isHeadless()) {
104 JOptionPane.showMessageDialog(null, message, "Error starting OpenRocket",
105 JOptionPane.ERROR_MESSAGE);
114 * Presents the user with a message dialog and asks whether to continue.
115 * If the user does not select "Yes" the the application exits.
117 * @param message the message Strings to show.
119 private static void confirm(String[] message) {
121 if (!GraphicsEnvironment.isHeadless()) {
123 if (JOptionPane.showConfirmDialog(null, message, "Error starting OpenRocket",
124 JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) {