Ticket #23355: 23355.patch
File 23355.patch, 14.6 KB (added by , 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 57 57 import javax.swing.JLabel; 58 58 import javax.swing.JOptionPane; 59 59 import javax.swing.JPanel; 60 import javax.swing.JTextPane; 60 61 import javax.swing.KeyStroke; 61 62 import javax.swing.LookAndFeel; 62 63 import javax.swing.RepaintManager; … … 129 130 import org.openstreetmap.josm.gui.util.GuiHelper; 130 131 import org.openstreetmap.josm.gui.util.RedirectInputMap; 131 132 import org.openstreetmap.josm.gui.util.WindowGeometry; 133 import org.openstreetmap.josm.gui.widgets.TextContextualPopupMenu; 132 134 import org.openstreetmap.josm.gui.widgets.UrlLabel; 133 135 import org.openstreetmap.josm.io.CachedFile; 134 136 import org.openstreetmap.josm.io.CertificateAmendment; … … 405 407 // CHECKSTYLE.ON: LineLength 406 408 } 407 409 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 408 437 /** 409 438 * Called once at startup to initialize the main window content. 410 439 * 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 71 71 }), 72 72 new InitializationTask(tr("Starting file watcher"), FileWatcher.getDefaultInstance()::start), 73 73 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)), 75 76 new InitializationTask(tr("Building main menu"), application::initializeMainWindow), 76 77 new InitializationTask(tr("Updating user interface"), () -> { 77 78 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 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.tools; 3 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 4 6 import java.awt.GraphicsEnvironment; 5 7 import java.awt.Toolkit; 6 8 import java.awt.event.KeyEvent; … … 8 10 import java.io.File; 9 11 import java.io.IOException; 10 12 import java.io.InputStreamReader; 13 import java.lang.management.ManagementFactory; 11 14 import java.nio.charset.StandardCharsets; 12 15 import java.security.KeyStoreException; 13 16 import java.security.NoSuchAlgorithmException; 14 17 import java.security.cert.CertificateException; 15 18 import java.security.cert.X509Certificate; 16 19 import java.text.DateFormat; 20 import java.util.ArrayList; 17 21 import java.util.Collection; 18 22 import java.util.Collections; 19 23 import java.util.Date; … … 86 90 * OS, so we'll receive events from the system menu. 87 91 * @param javaCallback Java expiration callback, providing GUI feedback 88 92 * @param webStartCallback WebStart migration callback, providing GUI feedback 89 * @since 17679 (signature)93 * @since xxx 90 94 */ 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); 93 98 } 94 99 95 100 /** … … 286 291 void askMigrateWebStart(String url); 287 292 } 288 293 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 289 308 /** 290 309 * Checks if the running version of Java has expired, proposes to user to update it if needed. 291 310 * @param callback Java expiration callback … … 369 388 } 370 389 } 371 390 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 372 430 /** 373 431 * Called when interfacing with native OS functions. Currently only used with macOS. 374 432 * 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 68 68 } 69 69 70 70 @Override 71 public void startupHook(JavaExpirationCallback javaCallback, WebStartMigrationCallback webStartCallback) { 71 public void startupHook(JavaExpirationCallback javaCallback, WebStartMigrationCallback webStartCallback, 72 SanityCheckCallback sanityCheckCallback) { 72 73 // Here we register callbacks for the menu entries in the system menu and file opening through double-click 73 74 // https://openjdk.java.net/jeps/272 74 75 // https://bugs.openjdk.java.net/browse/JDK-8048731 … … 106 107 warnSoonToBeUnsupportedJava(javaCallback); 107 108 checkExpiredJava(javaCallback); 108 109 checkWebStartMigration(webStartCallback); 110 PlatformHook.super.startupHook(javaCallback, webStartCallback, sanityCheckCallback); 109 111 } 110 112 111 113 @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 63 63 } 64 64 65 65 @Override 66 public void startupHook(JavaExpirationCallback javaCallback, WebStartMigrationCallback webStartCallback) { 66 public void startupHook(JavaExpirationCallback javaCallback, WebStartMigrationCallback webStartCallback, 67 SanityCheckCallback sanityCheckCallback) { 67 68 checkWebStartMigration(webStartCallback); 69 PlatformHook.super.startupHook(javaCallback, webStartCallback, sanityCheckCallback); 68 70 } 69 71 70 72 @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 153 153 } 154 154 155 155 @Override 156 public void startupHook(JavaExpirationCallback javaCallback, WebStartMigrationCallback webStartCallback) { 156 public void startupHook(JavaExpirationCallback javaCallback, WebStartMigrationCallback webStartCallback, 157 SanityCheckCallback sanityCheckCallback) { 157 158 warnSoonToBeUnsupportedJava(javaCallback); 158 159 checkExpiredJava(javaCallback); 159 160 checkWebStartMigration(webStartCallback); 161 PlatformHook.super.startupHook(javaCallback, webStartCallback, sanityCheckCallback); 160 162 } 161 163 162 164 @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 34 34 */ 35 35 @Test 36 36 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")); 38 39 } 39 40 40 41 /** -
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 46 46 void testStartupHook() { 47 47 final PlatformHook.JavaExpirationCallback javaCallback = (a, b, c, d) -> System.out.println("java callback"); 48 48 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)); 50 51 } 51 52 52 53 /**