Skip to content

Commit 2868ca7

Browse files
committed
Add version check for Mac OSX
1 parent 2028779 commit 2868ca7

File tree

1 file changed

+43
-3
lines changed

1 file changed

+43
-3
lines changed

src/main/java/net/sourceforge/pmd/util/fxdesigner/DesignerStarter.java

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
package net.sourceforge.pmd.util.fxdesigner;
66

7+
import java.io.IOException;
8+
import java.io.InputStream;
9+
import java.util.Properties;
10+
711
import javax.swing.JOptionPane;
812

913
import org.apache.commons.lang3.SystemUtils;
@@ -23,6 +27,13 @@ public final class DesignerStarter {
2327
+ " Please install JavaFX on your system and try again." + System.lineSeparator()
2428
+ " See https://gluonhq.com/products/javafx/";
2529

30+
private static final String INCOMPATIBLE_JAVAFX =
31+
"You seem to be running an older version of JavaFX runtime." + System.lineSeparator()
32+
+ " Please install the latest JavaFX on your system and try again." + System.lineSeparator()
33+
+ " See https://gluonhq.com/products/javafx/";
34+
35+
private static final int MIN_JAVAFX_VERSION_ON_MAC_OSX = 14;
36+
2637
private static final int ERROR_EXIT = 1;
2738
private static final int OK = 0;
2839

@@ -71,17 +82,43 @@ public static void main(String[] args) {
7182

7283
readParameters(args);
7384

74-
setSystemProperties();
7585
launchGui(args);
7686
}
7787

7888
private static void setSystemProperties() {
7989
if (SystemUtils.IS_OS_LINUX) {
80-
// On Linux, JavaFX renders text poorly by default. These settings help to aleviate the problems.
90+
// On Linux, JavaFX renders text poorly by default. These settings help to alleviate the problems.
8191
System.setProperty("prism.text", "t2k");
8292
System.setProperty("prism.lcdtext", "true");
8393
}
8494
}
95+
96+
private static boolean isCompatibleJavaFxVersion() {
97+
if (SystemUtils.IS_OS_MAC_OSX) {
98+
final String javaFxVersion = getJavaFxVersion();
99+
if (javaFxVersion != null) {
100+
final int major = Integer.parseInt(javaFxVersion.split("\\.")[0]);
101+
if (major < MIN_JAVAFX_VERSION_ON_MAC_OSX) {
102+
// Prior to JavaFx 14, text on Mac OSX was garbled and unreadable
103+
return false;
104+
}
105+
}
106+
}
107+
108+
return true;
109+
}
110+
111+
private static String getJavaFxVersion() {
112+
try (InputStream is = DesignerStarter.class.getClassLoader().getResourceAsStream("javafx.properties")) {
113+
final Properties javaFxProperties = new Properties();
114+
javaFxProperties.load(is);
115+
return (String) javaFxProperties.get("javafx.version");
116+
} catch (IOException ignored) {
117+
// Can't determine the version
118+
}
119+
120+
return null;
121+
}
85122

86123
private static String getHelpText(JCommander jCommander) {
87124

@@ -105,9 +142,13 @@ private static String getHelpText(JCommander jCommander) {
105142

106143
@SuppressWarnings("PMD.AvoidCatchingThrowable")
107144
private static void launchGui(String[] args) {
145+
setSystemProperties();
146+
108147
String message = null;
109148
if (!isJavaFxAvailable()) {
110149
message = MISSING_JAVAFX;
150+
} else if (!isCompatibleJavaFxVersion()) {
151+
message = INCOMPATIBLE_JAVAFX;
111152
}
112153

113154
if (message != null) {
@@ -116,7 +157,6 @@ private static void launchGui(String[] args) {
116157
System.exit(ERROR_EXIT);
117158
}
118159

119-
120160
try {
121161
Application.launch(Designer.class, args);
122162
} catch (Throwable unrecoverable) {

0 commit comments

Comments
 (0)