Changeset 17390 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2020-12-06T16:56:46+01:00 (4 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/RestartAction.java
r16643 r17390 14 14 import java.util.Arrays; 15 15 import java.util.Collection; 16 import java.util.Collections; 16 17 import java.util.List; 17 18 … … 35 36 public class RestartAction extends JosmAction { 36 37 38 private static final String APPLE_OSASCRIPT = "/usr/bin/osascript"; 39 37 40 // AppleScript to restart OS X package 38 41 private static final String RESTART_APPLE_SCRIPT = … … 44 47 + "tell application \"JOSM\" to activate"; 45 48 49 // Make sure we're able to retrieve restart commands before initiating shutdown (#13784) 50 private static final List<String> cmd = determineRestartCommands(); 51 46 52 /** 47 53 * Constructs a new {@code RestartAction}. … … 60 66 @Override 61 67 public void actionPerformed(ActionEvent e) { 62 try { 63 restartJOSM(); 64 } catch (IOException ex) { 65 Logging.error(ex); 66 } 68 restartJOSM(); 67 69 } 68 70 … … 73 75 */ 74 76 public static boolean isRestartSupported() { 75 return getSystemProperty("sun.java.command") != null;77 return !cmd.isEmpty(); 76 78 } 77 79 78 80 /** 79 81 * Restarts the current Java application. 80 * @throws IOException in case of any I/O error 81 */ 82 public static void restartJOSM() throws IOException { 82 */ 83 public static void restartJOSM() { 83 84 // If JOSM has been started with property 'josm.restart=true' this means 84 85 // it is executed by a start script that can handle restart. … … 89 90 } 90 91 91 if (isRestartSupported() && !MainApplication.exitJosm(false, 0, SaveLayersDialog.Reason.RESTART)) return; 92 final List<String> cmd; 93 // special handling for OSX .app package 94 if (PlatformManager.isPlatformOsx() && getSystemProperty("java.library.path").contains("/JOSM.app/Contents/MacOS")) { 95 cmd = getAppleCommands(); 96 } else { 97 cmd = getCommands(); 92 // Log every related environmentvariable for debug purpose 93 if (isDebugSimulation()) { 94 logEnvironment(); 98 95 } 99 96 Logging.info("Restart "+cmd); 100 if ( Logging.isDebugEnabled() && Config.getPref().getBoolean("restart.debug.simulation")) {97 if (isDebugSimulation()) { 101 98 Logging.debug("Restart cancelled to get debug info"); 102 99 return; 103 100 } 101 102 // Initiate shutdown 103 if (isRestartSupported() && !MainApplication.exitJosm(false, 0, SaveLayersDialog.Reason.RESTART)) 104 return; 105 104 106 // execute the command in a shutdown hook, to be sure that all the 105 107 // resources have been disposed before restarting the application … … 118 120 } 119 121 120 private static List<String> getAppleCommands() { 122 private static boolean isDebugSimulation() { 123 return Logging.isDebugEnabled() && Config.getPref().getBoolean("restart.debug.simulation"); 124 } 125 126 private static void logEnvironment() { 127 logEnvironmentVariable("java.home"); 128 logEnvironmentVariable("java.class.path"); 129 logEnvironmentVariable("java.library.path"); 130 logEnvironmentVariable("jnlpx.origFilenameArg"); 131 logEnvironmentVariable("sun.java.command"); 132 } 133 134 private static void logEnvironmentVariable(String var) { 135 Logging.debug("{0}: {1}", var, getSystemProperty(var)); 136 } 137 138 private static boolean isExecutableFile(File f) { 139 return f.isFile() && f.canExecute(); 140 } 141 142 private static List<String> determineRestartCommands() { 143 try { 144 // special handling for OSX .app package 145 if (PlatformManager.isPlatformOsx() && getSystemProperty("java.library.path").contains("/JOSM.app/Contents/MacOS")) { 146 return getAppleCommands(); 147 } else { 148 return getCommands(); 149 } 150 } catch (IOException e) { 151 Logging.error(e); 152 return Collections.emptyList(); 153 } 154 } 155 156 private static List<String> getAppleCommands() throws IOException { 157 if (!isExecutableFile(new File(APPLE_OSASCRIPT))) { 158 throw new IOException("Unable to find suitable osascript at " + APPLE_OSASCRIPT); 159 } 121 160 final List<String> cmd = new ArrayList<>(); 122 cmd.add( "/usr/bin/osascript");161 cmd.add(APPLE_OSASCRIPT); 123 162 for (String line : RESTART_APPLE_SCRIPT.split("\n", -1)) { 124 163 cmd.add("-e"); … … 178 217 final String java = getSystemProperty("java.home") + File.separator + "bin" + File.separator + 179 218 (PlatformManager.isPlatformWindows() ? "java.exe" : "java"); 180 if (! new File(java).isFile()) {219 if (!isExecutableFile(new File(java))) { 181 220 throw new IOException("Unable to find suitable java runtime at "+java); 182 221 } -
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r17379 r17390 1232 1232 Logging.info(tr("Detected no useable IPv6 network, preferring IPv4 over IPv6 after next restart.")); 1233 1233 Config.getPref().putBoolean("validated.ipv6", hasv6); // be sure it is stored before the restart! 1234 try { 1235 RestartAction.restartJOSM(); 1236 } catch (IOException e) { 1237 Logging.error(e); 1238 } 1234 RestartAction.restartJOSM(); 1239 1235 } 1240 1236 Config.getPref().putBoolean("validated.ipv6", hasv6); -
trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java
r16975 r17390 617 617 Config.getPref().putList("plugins", new ArrayList<>(plugins)); 618 618 // restart 619 try { 620 RestartAction.restartJOSM(); 621 } catch (IOException e) { 622 Logging.error(e); 623 } 619 RestartAction.restartJOSM(); 624 620 } else { 625 621 Logging.warn("No plugin downloaded, restart canceled");
Note:
See TracChangeset
for help on using the changeset viewer.