Changeset 7487 in josm for trunk/src


Ignore:
Timestamp:
2014-09-03T21:57:20+02:00 (10 years ago)
Author:
Don-vip
Message:

see #10455 - fix restart of OS X package + file icons

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/RestartAction.java

    r7335 r7487  
    1212import java.util.ArrayList;
    1313import java.util.Arrays;
    14 import java.util.Collections;
    1514import java.util.List;
    1615
     
    2726 */
    2827public class RestartAction extends JosmAction {
     28
     29    // AppleScript to restart OS X package
     30    private static final String RESTART_APPLE_SCRIPT =
     31              "tell application \"System Events\"\n"
     32            + "repeat until not (exists process \"JOSM\")\n"
     33            + "delay 0.2\n"
     34            + "end repeat\n"
     35            + "end tell\n"
     36            + "tell application \"JOSM\" to activate";
    2937
    3038    /**
     
    7381        if (isRestartSupported() && !Main.exitJosm(false, 0)) return;
    7482        try {
    75             // java binary
    76             final String java = System.getProperty("java.home") + File.separator + "bin" + File.separator +
    77                     (Main.isPlatformWindows() ? "java.exe" : "java");
    78             if (!new File(java).isFile()) {
    79                 throw new IOException("Unable to find suitable java runtime at "+java);
     83            final List<String> cmd = new ArrayList<>();
     84            // special handling for OSX .app package
     85            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                }
     91            } 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                for (String arg : ManagementFactory.getRuntimeMXBean().getInputArguments()) {
     101                    // if it's the agent argument : we ignore it otherwise the
     102                    // address of the old application and the new one will be in conflict
     103                    if (!arg.contains("-agentlib")) {
     104                        cmd.add(arg);
     105                    }
     106                }
     107                // program main and program arguments (be careful a sun property. might not be supported by all JVM)
     108                String[] mainCommand = System.getProperty("sun.java.command").split(" ");
     109                // look for a .jar in all chunks to support paths with spaces (fix #9077)
     110                String jarPath = mainCommand[0];
     111                for (int i = 1; i < mainCommand.length && !jarPath.endsWith(".jar"); i++) {
     112                    jarPath += " " + mainCommand[i];
     113                }
     114                // program main is a jar
     115                if (jarPath.endsWith(".jar")) {
     116                    // if it's a jar, add -jar mainJar
     117                    cmd.add("-jar");
     118                    cmd.add(new File(jarPath).getPath());
     119                } else {
     120                    // else it's a .class, add the classpath and mainClass
     121                    cmd.add("-cp");
     122                    cmd.add("\"" + System.getProperty("java.class.path") + "\"");
     123                    cmd.add(mainCommand[0]);
     124                }
     125                // if it's webstart add JNLP file
     126                String jnlp = System.getProperty("jnlp.application.href");
     127                if (jnlp != null) {
     128                    cmd.add(jnlp);
     129                }
     130                // finally add program arguments
     131                cmd.addAll(Arrays.asList(Main.commandLineArgs));
    80132            }
    81             final List<String> cmd = new ArrayList<>(Collections.singleton(java));
    82             // vm arguments
    83             for (String arg : ManagementFactory.getRuntimeMXBean().getInputArguments()) {
    84                 // if it's the agent argument : we ignore it otherwise the
    85                 // address of the old application and the new one will be in conflict
    86                 if (!arg.contains("-agentlib")) {
    87                     cmd.add(arg);
    88                 }
    89             }
    90             // program main and program arguments (be careful a sun property. might not be supported by all JVM)
    91             String[] mainCommand = System.getProperty("sun.java.command").split(" ");
    92             // look for a .jar in all chunks to support paths with spaces (fix #9077)
    93             String jarPath = mainCommand[0];
    94             for (int i = 1; i < mainCommand.length && !jarPath.endsWith(".jar"); i++) {
    95                 jarPath += " " + mainCommand[i];
    96             }
    97             // program main is a jar
    98             if (jarPath.endsWith(".jar")) {
    99                 // if it's a jar, add -jar mainJar
    100                 cmd.add("-jar");
    101                 cmd.add(new File(jarPath).getPath());
    102             } else {
    103                 // else it's a .class, add the classpath and mainClass
    104                 cmd.add("-cp");
    105                 cmd.add("\"" + System.getProperty("java.class.path") + "\"");
    106                 cmd.add(mainCommand[0]);
    107             }
    108             // if it's webstart add JNLP file
    109             String jnlp = System.getProperty("jnlp.application.href");
    110             if (jnlp != null) {
    111                 cmd.add(jnlp);
    112             }
    113             // finally add program arguments
    114             cmd.addAll(Arrays.asList(Main.commandLineArgs));
    115133            Main.info("Restart "+cmd);
    116134            // execute the command in a shutdown hook, to be sure that all the
Note: See TracChangeset for help on using the changeset viewer.