Merge pull request #1202 from SiboVG/issue-1176
[fixes #1176] Add JRE version checking at startup
This commit is contained in:
commit
c2a61c84db
@ -21,6 +21,9 @@ public final class Application {
|
||||
|
||||
private static Injector injector;
|
||||
|
||||
// Supported Java Runtime Environment versions in which OR is allowed to run (e.g. '11' for Java 11)
|
||||
public static int[] SUPPORTED_JRE_VERSIONS = {11};
|
||||
|
||||
/**
|
||||
* Return whether to use additional safety code checks.
|
||||
*/
|
||||
|
@ -5,7 +5,10 @@ import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.File;
|
||||
import java.io.PrintStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.Timer;
|
||||
import javax.swing.ToolTipManager;
|
||||
@ -61,6 +64,11 @@ public class SwingStartup {
|
||||
initializeLogging();
|
||||
log.info("Starting up OpenRocket version {}", BuildProperties.getVersion());
|
||||
|
||||
// Check JRE version
|
||||
if (!checkJREVersion()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check that we're not running headless
|
||||
log.info("Checking for graphics head");
|
||||
checkHead();
|
||||
@ -85,6 +93,44 @@ public class SwingStartup {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the Java Runtime Engine version is supported.
|
||||
*
|
||||
* @return true if the JRE is supported, false if not
|
||||
*/
|
||||
private static boolean checkJREVersion() {
|
||||
String JREVersion = System.getProperty("java.version");
|
||||
if (JREVersion != null) {
|
||||
try {
|
||||
// We're only interested in the big decimal part of the JRE version
|
||||
int version = Integer.parseInt(JREVersion.split("\\.")[0]);
|
||||
if (IntStream.of(Application.SUPPORTED_JRE_VERSIONS).noneMatch(c -> c == version)) {
|
||||
String title = "Unsupported Java version";
|
||||
String message1 = "Unsupported Java version: %s";
|
||||
String message2 = "Supported version(s): %s";
|
||||
String message3 = "Please change the Java Runtime Environment version or install OpenRocket using a packaged installer.";
|
||||
|
||||
StringBuilder message = new StringBuilder();
|
||||
message.append(String.format(message1, JREVersion));
|
||||
message.append("\n");
|
||||
String[] supported = Arrays.stream(Application.SUPPORTED_JRE_VERSIONS)
|
||||
.mapToObj(String::valueOf)
|
||||
.toArray(String[]::new);
|
||||
message.append(String.format(message2, String.join(", ", supported)));
|
||||
message.append("\n\n");
|
||||
message.append(message3);
|
||||
|
||||
JOptionPane.showMessageDialog(null, message.toString(),
|
||||
title, JOptionPane.ERROR_MESSAGE);
|
||||
return false;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
log.warn("Malformed JRE version - " + JREVersion);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set proper system properties if openrocket.debug is defined.
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user