Skip to content

Commit

Permalink
update to Java 17 and JavaFX 20
Browse files Browse the repository at this point in the history
  • Loading branch information
cpesch committed Jul 12, 2023
1 parent 099d7d3 commit 66d5b3d
Show file tree
Hide file tree
Showing 16 changed files with 65 additions and 108 deletions.
3 changes: 1 addition & 2 deletions common-gui/src/main/java/slash/navigation/gui/OSXHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.util.logging.Logger;

import static slash.common.helpers.ExceptionHelper.getLocalizedMessage;
import static slash.common.system.Platform.isJava9OrLater;

/**
* Sets the dock icon for Mac OS X for RouteConverter.
Expand Down Expand Up @@ -82,7 +81,7 @@ private OSXHandler(String proxySignature, Object target, Method handler) {
private static void createProxy(OSXHandler adapter, String handlerClassName, String setMethodName) {
try {
initializeApplicationObject();
Class<?> handlerClass = Class.forName((isJava9OrLater() ? "java.awt.desktop." : "com.apple.eawt.") + handlerClassName);
Class<?> handlerClass = Class.forName("java.awt.desktop." + handlerClassName);
Method setHandlerMethod = application.getClass().getDeclaredMethod(setMethodName, handlerClass);
Object osxAdapterProxy = Proxy.newProxyInstance(OSXHandler.class.getClassLoader(), new Class<?>[]{handlerClass}, adapter);
setHandlerMethod.invoke(application, osxAdapterProxy);
Expand Down
15 changes: 3 additions & 12 deletions common/src/main/java/slash/common/io/Transfer.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import static java.lang.Double.isNaN;
import static java.lang.Integer.toHexString;
import static java.lang.Math.*;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.text.DateFormat.MEDIUM;
import static java.text.DateFormat.SHORT;
import static java.util.Calendar.*;
Expand Down Expand Up @@ -343,12 +344,7 @@ public static Integer[] toArray(int[] ints) {
}

public static String encodeUri(String uri) {
try {
return URLEncoder.encode(uri, UTF8_ENCODING);
} catch (UnsupportedEncodingException e) {
log.severe("Cannot encode uri " + uri + ": " + e);
return uri;
}
return URLEncoder.encode(uri, UTF_8);
}

public static String encodeUmlauts(String string) {
Expand All @@ -366,12 +362,7 @@ public static String encodeUriButKeepSlashes(String uri) {
}

public static String decodeUri(String uri) {
try {
return URLDecoder.decode(uri, UTF8_ENCODING);
} catch (UnsupportedEncodingException e) {
log.severe("Cannot decode uri " + uri + ": " + e);
return uri;
}
return URLDecoder.decode(uri, UTF_8);
}

private static final char URI_ESCAPE_CHAR = '%';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import java.net.URLConnection;

import static java.net.URLDecoder.decode;
import static slash.common.io.Transfer.UTF8_ENCODING;
import static java.nio.charset.StandardCharsets.UTF_8;

/**
* An {@link URLConnection} that reads URLs from the classpath.
Expand All @@ -46,11 +46,11 @@ public void connect() {
}

public InputStream getInputStream() throws IOException {
String file = decode(url.getFile(), UTF8_ENCODING);
String file = decode(url.getFile(), UTF_8);
InputStream result = classLoader.getResourceAsStream(file);
if (result == null) {
throw new MalformedURLException("Could not open InputStream for URL '" + url + "'");
}
return result;
}
}
}
18 changes: 0 additions & 18 deletions common/src/main/java/slash/common/system/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,11 @@ public static String getPlatform() {
System.getProperty("os.arch");
}

static boolean hasJavaFX(String vendor, String javaVersion) {
return vendor.contains("Oracle") &&
javaVersion.compareTo("1.7.0_40") >= 0 &&
!isJavaLaterThan(javaVersion, 11);
}

public static boolean hasJavaFX() {
return hasJavaFX(System.getProperty("java.vendor"), System.getProperty("java.version"));
}

static boolean isJavaLaterThan(String javaVersion, int version) {
String versionString = version < 9 ? "1." + version : Integer.toString(version);
return new Version(javaVersion).isLaterOrSameVersionThan(new Version(versionString));
}

public static boolean isJava9OrLater() {
return isJavaLaterThan(System.getProperty("java.version"), 9);
}

public static boolean isJava15OrLater() {
return isJavaLaterThan(System.getProperty("java.version"), 15);
}

public static String getJava() {
return System.getProperty("java.vendor") + " Java " + System.getProperty("java.version") + " (" + getBits() + "-bit)";
}
Expand Down
16 changes: 0 additions & 16 deletions common/src/test/java/slash/common/system/PlatformTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,4 @@ public void testIsJavaLaterThan() {
assertTrue(isJavaLaterThan("15", 15));
assertTrue(isJavaLaterThan("16", 15));
}

@Test
public void testHasJavaFX() {
assertFalse(hasJavaFX("Oracle", "1.7.0"));
assertTrue(hasJavaFX("Oracle", "1.8.0"));
assertFalse(hasJavaFX("OpenJDK", "1.8.0"));
assertTrue(hasJavaFX("Oracle", "9"));
assertFalse(hasJavaFX("OpenJDK", "9"));
assertTrue(hasJavaFX("Oracle", "10"));
assertFalse(hasJavaFX("OpenJDK", "10"));
assertTrue(hasJavaFX("Oracle", "10.0.1"));
assertFalse(hasJavaFX("OpenJDK", "10.0.1"));
assertFalse(hasJavaFX("Oracle", "11"));
assertFalse(hasJavaFX("Oracle", "11.0.1"));
assertFalse(hasJavaFX("Oracle", "12"));
}
}
11 changes: 6 additions & 5 deletions javafx8-mapview/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.sun</groupId>
<artifactId>javafx</artifactId>
<version>jdk8</version>
<classifier>stripped</classifier>
<scope>provided</scope>
<groupId>org.openjfx</groupId>
<artifactId>javafx-swing</artifactId>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-web</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
import java.awt.*;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Logger;
Expand Down
2 changes: 1 addition & 1 deletion mapsforge-mbtiles/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.41.2.2</version>
<version>3.42.0.0</version>
</dependency>
</dependencies>
</project>
4 changes: 2 additions & 2 deletions navigation-formats/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>${poi.version}</version>
<version>4.1.2</version>
<classifier>stripped</classifier>
<exclusions>
<exclusion>
Expand All @@ -144,7 +144,7 @@
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>3.1.0</version>
<version>5.1.1</version>
<classifier>stripped</classifier>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import java.util.Map;

import static java.net.URLEncoder.encode;
import static slash.common.io.Transfer.UTF8_ENCODING;
import static java.nio.charset.StandardCharsets.UTF_8;
import static slash.navigation.base.RouteCharacteristics.Route;

/**
Expand Down Expand Up @@ -143,22 +143,14 @@ private Map<String, List<String>> parseParameters(byte[] data, String encoding)
protected String decodeDescription(String description) {
if (description == null)
return "";
try {
return URLDecoder.decode(description, UTF8_ENCODING);
} catch (UnsupportedEncodingException e) {
return description;
}
return URLDecoder.decode(description, UTF_8);
}

protected String encodeDescription(String description) {
if (description == null)
return "";
try {
description = encode(description, UTF8_ENCODING);
description = description.replace("%2C", ",");
return description;
} catch (UnsupportedEncodingException e) {
return description;
}
description = encode(description, UTF_8);
description = description.replace("%2C", ",");
return description;
}
}
16 changes: 14 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
<skip.integration.tests>true</skip.integration.tests>
<itCoverageAgent />

<java.version>1.8</java.version>
<java.version>17</java.version>
<javafx.version>20.0.1</javafx.version>
<maven.version>[3.5.4,)</maven.version>

<alephformatter.version>0.1.1</alephformatter.version>
Expand All @@ -75,7 +76,7 @@
<jaxb-api.version>2.3.1</jaxb-api.version>
<jaxb-impl.version>2.3.1</jaxb-impl.version>
<mapsforge.version>0.19.0</mapsforge.version>
<poi.version>4.1.2</poi.version>
<poi.version>5.2.3</poi.version>
<slf4j.version>2.0.7</slf4j.version>
</properties>

Expand Down Expand Up @@ -400,6 +401,7 @@
</excludePackageNames>
<doclint>none</doclint>
<failOnError>false</failOnError>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
<reportSets>
<reportSet>
Expand Down Expand Up @@ -532,6 +534,16 @@
<version>1.2</version>
<classifier>stripped</classifier>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-swing</artifactId>
<version>${javafx.version}</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-web</artifactId>
<version>${javafx.version}</version>
</dependency>
<dependency>
<groupId>javax.help</groupId>
<artifactId>javahelp</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import static java.io.File.separator;
import static java.lang.String.format;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.apache.commons.io.IOUtils.copyLarge;
import static slash.common.io.Files.recursiveDelete;
import static slash.common.io.Files.removeExtension;
Expand Down Expand Up @@ -149,7 +151,7 @@ public Route createRoute(String description, File localFile) throws IOException

public Route createRoute(String description, String url) throws IOException {
File destination = new File(directory, encodeFileName(description));
try (PrintWriter writer = new PrintWriter(destination, UTF8_ENCODING)) {
try (PrintWriter writer = new PrintWriter(destination, UTF_8)) {
writer.println("[InternetShortcut]");
writer.println("URL=" + url);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
import static java.util.Arrays.asList;
import static javax.swing.JOptionPane.*;
import static slash.common.io.Transfer.trim;
import static slash.common.system.Platform.hasJavaFX;
import static slash.common.system.Platform.isWindows;
import static slash.common.system.Platform.*;
import static slash.navigation.converter.gui.helpers.ExternalPrograms.startBrowserForGoogleAPIKey;

/**
Expand All @@ -61,16 +60,31 @@ public String getEditionId() {
protected void checkJavaPrequisites() {
super.checkJavaPrequisites();

String currentVersion = System.getProperty("java.version");
if (!hasJavaFX()) {
showMessageDialog(null, "Java " + currentVersion + " does not support JavaFX. Please install a Java 8 from Oracle. Avoid OpenJDK.", "RouteConverter", ERROR_MESSAGE);
System.exit(8);
try {
Class.forName("javafx.embed.swing.JFXPanel");
}
catch (Exception e) {
showMessageDialog(null, "JavaFX Swing not found. Please install JavaFX 20 or later.", "RouteConverter", ERROR_MESSAGE);
System.exit(9);
}

try {
Class.forName("javafx.scene.web.WebView");
}
catch (Exception e) {
showMessageDialog(null, "JavaFX WebView not found. Please install JavaFX 20 or later.", "RouteConverter", ERROR_MESSAGE);
System.exit(10);
}

if (isWindows() && (currentVersion.equals("1.8.0_161") || currentVersion.equals("1.8.0_162") || currentVersion.equals("1.8.0_171") || currentVersion.equals("1.8.0_172"))) {
showMessageDialog(null, "Java " + currentVersion + " contains a fatal bug in JavaFX on Windows. Please install Java 8 Update 181 or later.", "RouteConverter", ERROR_MESSAGE);
String currentVersion = System.getProperty("javafx.runtime.version");
if (currentVersion == null) {
showMessageDialog(null, "JavaFX not found. Please install JavaFX 20 or later.", "RouteConverter", ERROR_MESSAGE);
System.exit(9);
}
if (!isCurrentAtLeastMinimumVersion(currentVersion, "20")) {
showMessageDialog(null, "JavaFX " + currentVersion + " is too old. Please install JavaFX 20 or later.", "RouteConverter", ERROR_MESSAGE);
System.exit(10);
}
}

protected void checkForGoogleMapsAPIKey() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,25 +220,10 @@ protected void startup() {

protected void checkJavaPrequisites() {
String currentVersion = System.getProperty("java.version");
if (!isCurrentAtLeastMinimumVersion(currentVersion, "1.7.0_40")) {
showMessageDialog(null, "Java " + currentVersion + " does not support JavaFX. Please install Java 8 or 10.", "RouteConverter", ERROR_MESSAGE);
System.exit(7);
}

if (!isCurrentAtLeastMinimumVersion(currentVersion, "1.8.0")) {
showMessageDialog(null, "Java " + currentVersion + " is too old for FIT and EclipseLink. Please install Java 8 or 11.", "RouteConverter", ERROR_MESSAGE);
if (!isCurrentAtLeastMinimumVersion(currentVersion, "17")) {
showMessageDialog(null, "Java " + currentVersion + " is too old for JavaFX 20. Please install Java 17 or later.", "RouteConverter", ERROR_MESSAGE);
System.exit(8);
}

if (isWindows() && (currentVersion.equals("1.8.0_161") || currentVersion.equals("1.8.0_162") || currentVersion.equals("1.8.0_171") || currentVersion.equals("1.8.0_172"))) {
showMessageDialog(null, "Java " + currentVersion + " contains a fatal bug in JavaFX on Windows. Please install Java 8 Update 181 or Java 11.", "RouteConverter", ERROR_MESSAGE);
System.exit(9);
}

if (isJava15OrLater()) {
showMessageDialog(null, "Java " + currentVersion + " contains breaking changes. Please install Java 8 or 11.", "RouteConverter", ERROR_MESSAGE);
System.exit(10);
}
}

protected abstract void checkForGoogleMapsAPIKey();
Expand Down Expand Up @@ -1123,7 +1108,7 @@ private void dividerChanged(int newValue) {
this.location = newValue;
getMapView().resize();
preferences.putInt(MAP_DIVIDER_LOCATION_PREFERENCE, newValue);
double newRatio = new Integer(newValue).doubleValue() / contentPane.getWidth();
double newRatio = Integer.valueOf(newValue).doubleValue() / contentPane.getWidth();
preferences.putDouble(MAP_DIVIDER_RATIO_PREFERENCE, newRatio);
log.fine("Changed map divider to " + newValue + " and ratio " + newRatio);
enableActions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import java.util.logging.Logger;

import static slash.common.helpers.ExceptionHelper.getLocalizedMessage;
import static slash.common.system.Platform.isJava9OrLater;
import static slash.navigation.gui.OSXHelper.OSXHandler.*;

/**
Expand Down Expand Up @@ -78,7 +77,7 @@ public void about(EventObject event) {

@SuppressWarnings("unchecked")
private List<File> extractFiles(EventObject eventObject) throws Exception {
Class<?> eventClass = Class.forName((isJava9OrLater() ? "java.awt.desktop." : "com.apple.eawt.AppEvent.") + "OpenFilesEvent");
Class<?> eventClass = Class.forName("java.awt.desktop." + "OpenFilesEvent");
Method getFilesMethod = eventClass.getMethod("getFiles");
Object result = getFilesMethod.invoke(eventObject);
return (List<File>)result;
Expand Down
Loading

0 comments on commit 66d5b3d

Please sign in to comment.