1 package net.sf.openrocket.startup;
3 import java.awt.GraphicsEnvironment;
5 import javax.swing.JOptionPane;
7 import net.sf.openrocket.logging.LogHelper;
9 public class VersionHelper {
11 private static final LogHelper log = Application.getLogger();
13 private static final int REQUIRED_MAJOR_VERSION = 1;
14 private static final int REQUIRED_MINOR_VERSION = 6;
16 // OpenJDK 1.6.0_0-b16 is known to work, 1.6.0_0-b12 does not
17 private static final String BAD_OPENJDK_VERSION = "^1.6.0_0-b([0-9]|1[1-5])$";
21 * Check that the JRE version is high enough.
23 static void checkVersion() {
25 String[] version = System.getProperty("java.specification.version", "").split("\\.");
27 String jreName = System.getProperty("java.vm.name", "(unknown)");
28 String jreVersion = System.getProperty("java.runtime.version", "(unknown)");
29 String jreVendor = System.getProperty("java.vendor", "(unknown)");
31 log.info("Running JRE " + jreName + " version " + jreVersion + " by " + jreVendor);
36 major = Integer.parseInt(version[0]);
37 minor = Integer.parseInt(version[1]);
39 if (major < REQUIRED_MAJOR_VERSION ||
40 (major == REQUIRED_MAJOR_VERSION && minor < REQUIRED_MINOR_VERSION)) {
41 error(new String[] { "Java SE version 6 is required to run OpenRocket.",
42 "You are currently running " + jreName + " version " +
43 jreVersion + " by " + jreVendor });
46 } catch (RuntimeException e) {
48 confirm(new String[] { "The Java version in use could not be detected.",
49 "OpenRocket requires at least Java SE 6.",
50 "Continue anyway?" });
57 * Check whether OpenJDK is being used, and if it is warn the user about
58 * problems and confirm whether to continue.
60 static void checkOpenJDK() {
62 if (System.getProperty("java.runtime.name", "").toLowerCase().indexOf("icedtea") >= 0 ||
63 System.getProperty("java.vm.name", "").toLowerCase().indexOf("openjdk") >= 0) {
65 String jreName = System.getProperty("java.vm.name", "(unknown)");
66 String jreVersion = System.getProperty("java.runtime.version", "(unknown)");
67 String jreVendor = System.getProperty("java.vendor", "(unknown)");
69 if (jreVersion.matches(BAD_OPENJDK_VERSION)) {
71 confirm(new String[] { "Old versions of OpenJDK are known to have problems " +
72 "running OpenRocket.",
74 "You are currently running " + jreName + " version " +
75 jreVersion + " by " + jreVendor,
76 "Do you want to continue?" });
83 /////////// Helper methods //////////
86 * Presents an error message to the user and exits the application.
88 * @param message an array of messages to present.
90 private static void error(String[] message) {
93 System.err.println("Error starting OpenRocket:");
95 for (int i = 0; i < message.length; i++) {
96 System.err.println(message[i]);
101 if (!GraphicsEnvironment.isHeadless()) {
103 JOptionPane.showMessageDialog(null, message, "Error starting OpenRocket",
104 JOptionPane.ERROR_MESSAGE);
113 * Presents the user with a message dialog and asks whether to continue.
114 * If the user does not select "Yes" the the application exits.
116 * @param message the message Strings to show.
118 private static void confirm(String[] message) {
120 if (!GraphicsEnvironment.isHeadless()) {
122 if (JOptionPane.showConfirmDialog(null, message, "Error starting OpenRocket",
123 JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) {