Changeset 8666 in josm for trunk/src/org
- Timestamp:
- 2015-08-17T02:14:59+02:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/RestartAction.java
r8471 r8666 11 11 import java.lang.management.ManagementFactory; 12 12 import java.util.ArrayList; 13 import java.util.Arrays; 14 import java.util.Collection; 13 15 import java.util.List; 14 16 … … 80 82 public static void restartJOSM() throws IOException { 81 83 if (isRestartSupported() && !Main.exitJosm(false, 0)) return; 84 final List<String> cmd; 82 85 try { 83 final List<String> cmd = new ArrayList<>();84 86 // special handling for OSX .app package 85 87 if (Main.isPlatformOsx() && System.getProperty("java.library.path").contains("/JOSM.app/Contents/MacOS")) { 86 cmd.add("/usr/bin/osascript"); 87 for (String line : RESTART_APPLE_SCRIPT.split("\n")) { 88 cmd.add("-e"); 89 cmd.add(line); 90 } 88 cmd = getAppleCommands(); 91 89 } else { 92 // java binary 93 final String java = System.getProperty("java.home") + File.separator + "bin" + File.separator + 94 (Main.isPlatformWindows() ? "java.exe" : "java"); 95 if (!new File(java).isFile()) { 96 throw new IOException("Unable to find suitable java runtime at "+java); 97 } 98 cmd.add(java); 99 // vm arguments 100 List<String> arguments = ManagementFactory.getRuntimeMXBean().getInputArguments(); 101 if (Main.isDebugEnabled()) { 102 Main.debug("VM arguments: "+arguments); 103 } 104 for (String arg : arguments) { 105 // When run from jp2launcher.exe, jnlpx.remove is true, while it is not when run from javaws 106 // Always set it to false to avoid error caused by a missing jnlp file on the second restart 107 arg = arg.replace("-Djnlpx.remove=true", "-Djnlpx.remove=false"); 108 // if it's the agent argument : we ignore it otherwise the 109 // address of the old application and the new one will be in conflict 110 if (!arg.contains("-agentlib")) { 111 cmd.add(arg); 112 } 113 } 114 // program main and program arguments (be careful a sun property. might not be supported by all JVM) 115 String[] mainCommand = System.getProperty("sun.java.command").split(" "); 116 // look for a .jar in all chunks to support paths with spaces (fix #9077) 117 StringBuilder sb = new StringBuilder(mainCommand[0]); 118 for (int i = 1; i < mainCommand.length && !mainCommand[i-1].endsWith(".jar"); i++) { 119 sb.append(' ').append(mainCommand[i]); 120 } 121 String jarPath = sb.toString(); 122 // program main is a jar 123 if (jarPath.endsWith(".jar")) { 124 // if it's a jar, add -jar mainJar 125 cmd.add("-jar"); 126 cmd.add(new File(jarPath).getPath()); 127 } else { 128 // else it's a .class, add the classpath and mainClass 129 cmd.add("-cp"); 130 cmd.add("\"" + System.getProperty("java.class.path") + "\""); 131 cmd.add(mainCommand[0]); 132 } 133 // if it's webstart add JNLP file. Use jnlpx.origFilenameArg instead of jnlp.application.href, 134 // because only this one is present when run from j2plauncher.exe (see #10795) 135 String jnlp = System.getProperty("jnlpx.origFilenameArg"); 136 if (jnlp != null) { 137 cmd.add(jnlp); 138 } 139 // finally add program arguments 140 cmd.addAll(Main.getCommandLineArgs()); 90 cmd = getCommands(); 141 91 } 142 92 Main.info("Restart "+cmd); … … 165 115 } 166 116 117 private static List<String> getAppleCommands() { 118 final List<String> cmd = new ArrayList<>(); 119 cmd.add("/usr/bin/osascript"); 120 for (String line : RESTART_APPLE_SCRIPT.split("\n")) { 121 cmd.add("-e"); 122 cmd.add(line); 123 } 124 return cmd; 125 } 126 127 private static List<String> getCommands() throws IOException { 128 final List<String> cmd = new ArrayList<>(); 129 // java binary 130 cmd.add(getJavaRuntime()); 131 // vm arguments 132 addVMArguments(cmd); 133 // Determine webstart JNLP file. Use jnlpx.origFilenameArg instead of jnlp.application.href, 134 // because only this one is present when run from j2plauncher.exe (see #10795) 135 final String jnlp = System.getProperty("jnlpx.origFilenameArg"); 136 // program main and program arguments (be careful a sun property. might not be supported by all JVM) 137 final String javaCommand = System.getProperty("sun.java.command"); 138 String[] mainCommand = javaCommand.split(" "); 139 if (javaCommand.endsWith(".jnlp") && jnlp == null) { 140 // see #11751 - jnlp on Linux 141 if (Main.isDebugEnabled()) { 142 Main.debug("Detected jnlp without jnlpx.origFilenameArg property set"); 143 } 144 cmd.addAll(Arrays.asList(mainCommand)); 145 } else { 146 // look for a .jar in all chunks to support paths with spaces (fix #9077) 147 StringBuilder sb = new StringBuilder(mainCommand[0]); 148 for (int i = 1; i < mainCommand.length && !mainCommand[i-1].endsWith(".jar"); i++) { 149 sb.append(' ').append(mainCommand[i]); 150 } 151 String jarPath = sb.toString(); 152 // program main is a jar 153 if (jarPath.endsWith(".jar")) { 154 // if it's a jar, add -jar mainJar 155 cmd.add("-jar"); 156 cmd.add(new File(jarPath).getPath()); 157 } else { 158 // else it's a .class, add the classpath and mainClass 159 cmd.add("-cp"); 160 cmd.add("\"" + System.getProperty("java.class.path") + "\""); 161 cmd.add(mainCommand[0]); 162 } 163 // add JNLP file. 164 if (jnlp != null) { 165 cmd.add(jnlp); 166 } 167 } 168 // finally add program arguments 169 cmd.addAll(Main.getCommandLineArgs()); 170 return cmd; 171 } 172 173 private static String getJavaRuntime() throws IOException { 174 final String java = System.getProperty("java.home") + File.separator + "bin" + File.separator + 175 (Main.isPlatformWindows() ? "java.exe" : "java"); 176 if (!new File(java).isFile()) { 177 throw new IOException("Unable to find suitable java runtime at "+java); 178 } 179 return java; 180 } 181 182 private static void addVMArguments(Collection<String> cmd) { 183 List<String> arguments = ManagementFactory.getRuntimeMXBean().getInputArguments(); 184 if (Main.isDebugEnabled()) { 185 Main.debug("VM arguments: "+arguments); 186 } 187 for (String arg : arguments) { 188 // When run from jp2launcher.exe, jnlpx.remove is true, while it is not when run from javaws 189 // Always set it to false to avoid error caused by a missing jnlp file on the second restart 190 arg = arg.replace("-Djnlpx.remove=true", "-Djnlpx.remove=false"); 191 // if it's the agent argument : we ignore it otherwise the 192 // address of the old application and the new one will be in conflict 193 if (!arg.contains("-agentlib")) { 194 cmd.add(arg); 195 } 196 } 197 } 198 167 199 /** 168 200 * Returns a new {@code ButtonSpec} instance that performs this action.
Note:
See TracChangeset
for help on using the changeset viewer.