Ticket #18925: 18925.3.patch

File 18925.3.patch, 5.9 KB (added by taylor.smock, 4 years ago)

Java 11+

  • src/org/openstreetmap/josm/plugins/javafx/JavaFxPlugin.java

     
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.javafx;
     3import static org.openstreetmap.josm.tools.I18n.tr;
    34
    45import java.io.File;
    56import java.io.IOException;
     
    1415import java.nio.file.StandardCopyOption;
    1516import java.nio.file.attribute.BasicFileAttributes;
    1617import java.security.CodeSource;
     18import java.util.Arrays;
     19import java.util.Collections;
    1720import java.util.Enumeration;
    1821import java.util.List;
    1922import java.util.Objects;
     
    2124import java.util.zip.ZipFile;
    2225
    2326import org.openstreetmap.josm.data.Preferences;
     27import org.openstreetmap.josm.gui.MainApplication;
    2428import org.openstreetmap.josm.io.audio.AudioPlayer;
    2529import org.openstreetmap.josm.plugins.DynamicURLClassLoader;
    2630import org.openstreetmap.josm.plugins.Plugin;
     31import org.openstreetmap.josm.plugins.PluginHandler;
    2732import org.openstreetmap.josm.plugins.PluginInformation;
    2833import org.openstreetmap.josm.plugins.javafx.io.audio.JavaFxMediaPlayer;
    2934import org.openstreetmap.josm.tools.Logging;
     35import org.openstreetmap.josm.tools.Utils;
    3036
     37
    3138/**
    3239 * OpenJFX plugin brings OpenJFX (JavaFX) to other plugins.
    3340 */
    3441abstract class JavaFxPlugin extends Plugin {
    3542
     43    Exception e;
    3644    /**
    3745     * Constructs a new {@code OpenJfxPlugin}.
    3846     * @param info plugin info
    3947     * @param ext native libraries extension
    40      * @param orderedNativeLibraries native librarires that must be loaded in this order
     48     * @param orderedNativeLibraries native libraries that must be loaded in this order
    4149     */
    4250    protected JavaFxPlugin(PluginInformation info, String ext, List<String> orderedNativeLibraries) {
    4351        super(info);
     52        boolean isJavaFx = Utils.getSystemProperty("javafx.runtime.version") != null || Arrays.asList("Oracle Corporation").contains(Utils.getSystemProperty("java.vendor"));
     53        if (!isJavaFx && Utils.getJavaVersion() >= 10) {
     54            extractNativeLibs(ext);
     55            loadNativeLibs(ext, orderedNativeLibraries);
     56        } else if (!isJavaFx) {
     57            Logging.error("JavaFX is not available");
     58            StringBuilder message = new StringBuilder(tr("JavaFX is not available."));
     59            String os = Utils.getSystemProperty("os.name").toLowerCase();
     60            if (Arrays.asList("windows", "mac os").contains(os)) {
     61                message.append(tr(" Please install OpenJFX through your package manager."));
     62            } else {
     63                message.append(tr(" Please update to Java 11+."));
     64            }
     65            if (PluginHandler.confirmDisablePlugin(MainApplication.getMainFrame(), message.toString(), info.getName())) {
     66                PluginHandler.removePlugins(Collections.singletonList(info));
     67            }
     68            return;
     69        }
    4470        AudioPlayer.setSoundPlayerClass(JavaFxMediaPlayer.class);
    45         extractNativeLibs(ext);
    46         loadNativeLibs(ext, orderedNativeLibraries);
    4771    }
    4872
    4973    private static void extractNativeLibs(String ext) {
  • src/org/openstreetmap/josm/plugins/javafx/JavaFxPluginOsx.java

     
    33
    44import java.util.Arrays;
    55
     6import javax.swing.UnsupportedLookAndFeelException;
     7
    68import org.openstreetmap.josm.plugins.PluginInformation;
    79
    810/**
     
    1315    /**
    1416     * Constructs a new {@code JavaFxPluginOsx}.
    1517     * @param info plugin info
     18     * @throws UnsupportedLookAndFeelException if JavaFX is not available (< Java 10)
    1619     */
    17     public JavaFxPluginOsx(PluginInformation info) {
     20    public JavaFxPluginOsx(PluginInformation info) throws UnsupportedLookAndFeelException {
    1821        super(info, ".dylib", Arrays.asList());
    1922    }
    2023}
  • src/org/openstreetmap/josm/plugins/javafx/JavaFxPluginUnixoid.java

     
    33
    44import java.util.Arrays;
    55
     6import javax.swing.UnsupportedLookAndFeelException;
     7
    68import org.openstreetmap.josm.plugins.PluginInformation;
    79
    810/**
     
    1315    /**
    1416     * Constructs a new {@code JavaFxPluginUnixoid}.
    1517     * @param info plugin info
     18     * @throws UnsupportedLookAndFeelException if JavaFX is not available (< Java 10)
    1619     */
    17     public JavaFxPluginUnixoid(PluginInformation info) {
     20    public JavaFxPluginUnixoid(PluginInformation info) throws UnsupportedLookAndFeelException {
    1821        super(info, ".so", Arrays.asList());
    1922    }
    2023}
  • src/org/openstreetmap/josm/plugins/javafx/JavaFxPluginWindows.java

     
    33
    44import java.util.Arrays;
    55
     6import javax.swing.UnsupportedLookAndFeelException;
     7
    68import org.openstreetmap.josm.plugins.PluginInformation;
    79
    810/**
     
    1315    /**
    1416     * Constructs a new {@code JavaFxPluginWindows}.
    1517     * @param info plugin info
     18     * @throws UnsupportedLookAndFeelException if JavaFX is not available (< Java 10)
    1619     */
    17     public JavaFxPluginWindows(PluginInformation info) {
     20    public JavaFxPluginWindows(PluginInformation info) throws UnsupportedLookAndFeelException {
    1821        super(info, ".dll", Arrays.asList("fxplugins.dll"));
    1922    }
    2023}