Ticket #23355: 23355.patch

File 23355.patch, 14.6 KB (added by taylor.smock, 20 months ago)
  • core/src/org/openstreetmap/josm/gui/MainApplication.java

    Subject: [PATCH] #23355
    ---
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    diff --git a/core/src/org/openstreetmap/josm/gui/MainApplication.java b/core/src/org/openstreetmap/josm/gui/MainApplication.java
    a b  
    5757import javax.swing.JLabel;
    5858import javax.swing.JOptionPane;
    5959import javax.swing.JPanel;
     60import javax.swing.JTextPane;
    6061import javax.swing.KeyStroke;
    6162import javax.swing.LookAndFeel;
    6263import javax.swing.RepaintManager;
     
    129130import org.openstreetmap.josm.gui.util.GuiHelper;
    130131import org.openstreetmap.josm.gui.util.RedirectInputMap;
    131132import org.openstreetmap.josm.gui.util.WindowGeometry;
     133import org.openstreetmap.josm.gui.widgets.TextContextualPopupMenu;
    132134import org.openstreetmap.josm.gui.widgets.UrlLabel;
    133135import org.openstreetmap.josm.io.CachedFile;
    134136import org.openstreetmap.josm.io.CertificateAmendment;
     
    405407        // CHECKSTYLE.ON: LineLength
    406408    }
    407409
     410    /**
     411     * Tells the user that a sanity check failed
     412     * @param title The title of the message to show
     413     * @param canContinue {@code true} if the failed sanity check(s) will not instantly kill JOSM when the user edits
     414     * @param message The message parts to show the user (as a list)
     415     */
     416    public static void sanityCheckFailed(String title, boolean canContinue, String... message) {
     417        final ExtendedDialog ed = new ExtendedDialog(mainFrame, title, tr("OK"), tr("Cancel"));
     418        // Check if the dialog has not already been permanently hidden by user
     419        if (!ed.toggleEnable("sanityCheckFailed").toggleCheckState() || !canContinue) {
     420            final String content = Arrays.stream(message).collect(Collectors.joining("</li><li>",
     421                    "<html><body><ul><li>", "</li></ul></body></html>"));
     422            final JTextPane textField = new JTextPane();
     423            textField.setContentType("text/html");
     424            textField.setText(content);
     425            TextContextualPopupMenu.enableMenuFor(textField, true);
     426            ed.setButtonIcons("ok", "cancel").setCancelButton(2);
     427            ed.setMinimumSize(new Dimension(480, 300));
     428            ed.setIcon(JOptionPane.WARNING_MESSAGE);
     429            ed.setContent(textField);
     430            ed.showDialog();
     431        }
     432        if (!canContinue) {
     433            Lifecycle.exitJosm(true, -1);
     434        }
     435    }
     436
    408437    /**
    409438     * Called once at startup to initialize the main window content.
    410439     * Should set {@link #menu} and {@link #mainPanel}
  • core/src/org/openstreetmap/josm/gui/MainInitialization.java

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    diff --git a/core/src/org/openstreetmap/josm/gui/MainInitialization.java b/core/src/org/openstreetmap/josm/gui/MainInitialization.java
    a b  
    7171            }),
    7272            new InitializationTask(tr("Starting file watcher"), FileWatcher.getDefaultInstance()::start),
    7373            new InitializationTask(tr("Executing platform startup hook"),
    74                     () -> PlatformManager.getPlatform().startupHook(MainApplication::askUpdateJava, MainApplication::askMigrateWebStart)),
     74                    () -> PlatformManager.getPlatform().startupHook(MainApplication::askUpdateJava,
     75                            MainApplication::askMigrateWebStart, MainApplication::sanityCheckFailed)),
    7576            new InitializationTask(tr("Building main menu"), application::initializeMainWindow),
    7677            new InitializationTask(tr("Updating user interface"), () -> {
    7778                UndoRedoHandler.getInstance().addCommandQueueListener(application.redoUndoListener);
  • core/src/org/openstreetmap/josm/tools/PlatformHook.java

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    diff --git a/core/src/org/openstreetmap/josm/tools/PlatformHook.java b/core/src/org/openstreetmap/josm/tools/PlatformHook.java
    a b  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.tools;
    33
     4import static org.openstreetmap.josm.tools.I18n.tr;
     5
    46import java.awt.GraphicsEnvironment;
    57import java.awt.Toolkit;
    68import java.awt.event.KeyEvent;
     
    810import java.io.File;
    911import java.io.IOException;
    1012import java.io.InputStreamReader;
     13import java.lang.management.ManagementFactory;
    1114import java.nio.charset.StandardCharsets;
    1215import java.security.KeyStoreException;
    1316import java.security.NoSuchAlgorithmException;
    1417import java.security.cert.CertificateException;
    1518import java.security.cert.X509Certificate;
    1619import java.text.DateFormat;
     20import java.util.ArrayList;
    1721import java.util.Collection;
    1822import java.util.Collections;
    1923import java.util.Date;
     
    8690      * OS, so we'll receive events from the system menu.
    8791      * @param javaCallback Java expiration callback, providing GUI feedback
    8892      * @param webStartCallback WebStart migration callback, providing GUI feedback
    89       * @since 17679 (signature)
     93      * @since xxx
    9094      */
    91     default void startupHook(JavaExpirationCallback javaCallback, WebStartMigrationCallback webStartCallback) {
    92         // Do nothing
     95    default void startupHook(JavaExpirationCallback javaCallback, WebStartMigrationCallback webStartCallback,
     96            SanityCheckCallback sanityCheckCallback) {
     97        startupSanityChecks(sanityCheckCallback);
    9398    }
    9499
    95100    /**
     
    286291        void askMigrateWebStart(String url);
    287292    }
    288293
     294    /**
     295     * Inform the user that a sanity check or checks failed
     296     */
     297    @FunctionalInterface
     298    interface SanityCheckCallback {
     299        /**
     300         * Tells the user that a sanity check failed
     301         * @param title The title of the message to show
     302         * @param canContinue {@code true} if the failed sanity check(s) will not instantly kill JOSM when the user edits
     303         * @param message The message parts to show the user (as a list)
     304         */
     305        void sanityCheckFailed(String title, boolean canContinue, String... message);
     306    }
     307
    289308    /**
    290309     * Checks if the running version of Java has expired, proposes to user to update it if needed.
    291310     * @param callback Java expiration callback
     
    369388        }
    370389    }
    371390
     391    default void startupSanityChecks(SanityCheckCallback sanityCheckCallback) {
     392        final String arch = System.getProperty("os.arch");
     393        final List<String> messages = new ArrayList<>();
     394        final String jvmArch = System.getProperty("sun.arch.data.model");
     395        boolean canContinue = true;
     396        if (!"x86".equals(arch) && "32".equals(jvmArch)) {
     397            messages.add(tr("Please use a 64 bit version of Java -- this will avoid out of memory errors"));
     398        }
     399        final String[] expectedJvmArguments = {
     400                "--add-exports=java.base/sun.security.action=ALL-UNNAMED",
     401                "--add-exports=java.desktop/com.sun.imageio.plugins.jpeg=ALL-UNNAMED",
     402                "--add-exports=java.desktop/com.sun.imageio.spi=ALL-UNNAMED"
     403
     404        };
     405        final List<String> vmArguments = ManagementFactory.getRuntimeMXBean().getInputArguments();
     406        for (String arg : expectedJvmArguments) {
     407            if (!vmArguments.contains(arg)) {
     408                messages.add(tr("Missing JVM Arguments: ''{0}''", arg));
     409            }
     410        }
     411        if (Utils.getJavaVersion() < 8) {
     412            canContinue = false;
     413            messages.add(tr("You must update Java to {0} in order to run this version of JOSM", 17));
     414            // Reset webstart/java update prompts
     415            Config.getPref().put("askUpdateWebStart", null);
     416            Config.getPref().put("askUpdateJava" + Utils.getJavaLatestVersion(), null);
     417            Config.getPref().put("askUpdateJavalatest", null);
     418        }
     419        if (!messages.isEmpty()) {
     420            if (canContinue) {
     421                sanityCheckCallback.sanityCheckFailed(tr("JOSM may work improperly"), true,
     422                        messages.toArray(new String[0]));
     423            } else {
     424                sanityCheckCallback.sanityCheckFailed(tr("JOSM will be unable to work properly and will exit"), false,
     425                        messages.toArray(new String[0]));
     426            }
     427        }
     428    }
     429
    372430    /**
    373431     * Called when interfacing with native OS functions. Currently only used with macOS.
    374432     * The callback must perform all GUI-related tasks associated to an OS request.
  • core/src/org/openstreetmap/josm/tools/PlatformHookOsx.java

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    diff --git a/core/src/org/openstreetmap/josm/tools/PlatformHookOsx.java b/core/src/org/openstreetmap/josm/tools/PlatformHookOsx.java
    a b  
    6868    }
    6969
    7070    @Override
    71     public void startupHook(JavaExpirationCallback javaCallback, WebStartMigrationCallback webStartCallback) {
     71    public void startupHook(JavaExpirationCallback javaCallback, WebStartMigrationCallback webStartCallback,
     72            SanityCheckCallback sanityCheckCallback) {
    7273        // Here we register callbacks for the menu entries in the system menu and file opening through double-click
    7374        // https://openjdk.java.net/jeps/272
    7475        // https://bugs.openjdk.java.net/browse/JDK-8048731
     
    106107        warnSoonToBeUnsupportedJava(javaCallback);
    107108        checkExpiredJava(javaCallback);
    108109        checkWebStartMigration(webStartCallback);
     110        PlatformHook.super.startupHook(javaCallback, webStartCallback, sanityCheckCallback);
    109111    }
    110112
    111113    @Override
  • core/src/org/openstreetmap/josm/tools/PlatformHookUnixoid.java

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    diff --git a/core/src/org/openstreetmap/josm/tools/PlatformHookUnixoid.java b/core/src/org/openstreetmap/josm/tools/PlatformHookUnixoid.java
    a b  
    6363    }
    6464
    6565    @Override
    66     public void startupHook(JavaExpirationCallback javaCallback, WebStartMigrationCallback webStartCallback) {
     66    public void startupHook(JavaExpirationCallback javaCallback, WebStartMigrationCallback webStartCallback,
     67            SanityCheckCallback sanityCheckCallback) {
    6768        checkWebStartMigration(webStartCallback);
     69        PlatformHook.super.startupHook(javaCallback, webStartCallback, sanityCheckCallback);
    6870    }
    6971
    7072    @Override
  • core/src/org/openstreetmap/josm/tools/PlatformHookWindows.java

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    diff --git a/core/src/org/openstreetmap/josm/tools/PlatformHookWindows.java b/core/src/org/openstreetmap/josm/tools/PlatformHookWindows.java
    a b  
    153153    }
    154154
    155155    @Override
    156     public void startupHook(JavaExpirationCallback javaCallback, WebStartMigrationCallback webStartCallback) {
     156    public void startupHook(JavaExpirationCallback javaCallback, WebStartMigrationCallback webStartCallback,
     157            SanityCheckCallback sanityCheckCallback) {
    157158        warnSoonToBeUnsupportedJava(javaCallback);
    158159        checkExpiredJava(javaCallback);
    159160        checkWebStartMigration(webStartCallback);
     161        PlatformHook.super.startupHook(javaCallback, webStartCallback, sanityCheckCallback);
    160162    }
    161163
    162164    @Override
  • core/test/unit/org/openstreetmap/josm/tools/PlatformHookOsxTest.java

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    diff --git a/core/test/unit/org/openstreetmap/josm/tools/PlatformHookOsxTest.java b/core/test/unit/org/openstreetmap/josm/tools/PlatformHookOsxTest.java
    a b  
    3434     */
    3535    @Test
    3636    void testStartupHook() {
    37         hook.startupHook((a, b, c, d) -> System.out.println("java callback"), u -> System.out.println("webstart callback"));
     37        hook.startupHook((a, b, c, d) -> System.out.println("java callback"), u -> System.out.println("webstart callback"),
     38                (a, b, c) -> System.out.println("sanity check callback"));
    3839    }
    3940
    4041    /**
  • core/test/unit/org/openstreetmap/josm/tools/PlatformHookWindowsTest.java

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    diff --git a/core/test/unit/org/openstreetmap/josm/tools/PlatformHookWindowsTest.java b/core/test/unit/org/openstreetmap/josm/tools/PlatformHookWindowsTest.java
    a b  
    4646    void testStartupHook() {
    4747        final PlatformHook.JavaExpirationCallback javaCallback = (a, b, c, d) -> System.out.println("java callback");
    4848        final PlatformHook.WebStartMigrationCallback webstartCallback = u -> System.out.println("webstart callback");
    49         assertDoesNotThrow(() -> hook.startupHook(javaCallback, webstartCallback));
     49        final PlatformHook.SanityCheckCallback sanityCheckCallback = (a, b, c) -> System.out.println("sanity check callback");
     50        assertDoesNotThrow(() -> hook.startupHook(javaCallback, webstartCallback, sanityCheckCallback));
    5051    }
    5152
    5253    /**