Deal with spaces in JVM paths
authorMathieu Baudier <mbaudier@argeo.org>
Thu, 30 Jul 2009 13:17:02 +0000 (13:17 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Thu, 30 Jul 2009 13:17:02 +0000 (13:17 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@2837 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

eclipse/plugins/org.argeo.slc.ui.launch/META-INF/MANIFEST.MF
eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/osgi/SlcLaunchShortcut.java

index 1f4e7b59d6137cd95fdab5b0b0bfc1ab1603ee43..6ef3a9012fe213482661902d9ac074d8f770186a 100644 (file)
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
 Bundle-ManifestVersion: 2
 Bundle-Name: SLC UI Launch
 Bundle-SymbolicName: org.argeo.slc.ui.launch;singleton:=true
-Bundle-Version: 0.11.5.D20090730_1434
+Bundle-Version: 0.11.5.D20090730_1516
 Bundle-Activator: org.argeo.slc.ui.launch.SlcUiLaunchPlugin
 Require-Bundle: org.eclipse.ui,
  org.eclipse.core.runtime,
index 378749b4e0c12658d7ae357dcaa951be8ae043fe..88bd3589e62a40457855bec1e7e69821465512f1 100644 (file)
@@ -12,6 +12,7 @@ import org.eclipse.core.runtime.Assert;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.debug.core.ILaunchConfigurationType;
 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.jdt.internal.debug.ui.jres.VMInstallWizard;
 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
 import org.eclipse.jdt.launching.IVMInstall;
 import org.eclipse.jdt.launching.IVMInstall2;
@@ -98,52 +99,32 @@ public class SlcLaunchShortcut extends OSGiLaunchShortcut {
                        vmArgs.append(" -Xmx256m");
 
                        // Add locations of JVMs
-                       vmArgs.append(" -D" + VMS_PROPERTY_PREFIX + ".default="
-                                       + JavaRuntime.getDefaultVMInstall().getInstallLocation());
+                       addVmSysProperty(vmArgs, "default", JavaRuntime
+                                       .getDefaultVMInstall());
                        IVMInstallType[] vmTypes = JavaRuntime.getVMInstallTypes();
                        for (IVMInstallType vmType : vmTypes) {
-                               System.out.println("vmType: id=" + vmType.getId() + ", name="
-                                               + vmType.getName() + ", toString=" + vmType);
+                               // System.out.println("vmType: id=" + vmType.getId() + ", name="
+                               // + vmType.getName() + ", toString=" + vmType);
                                for (IVMInstall vmInstall : vmType.getVMInstalls()) {
-                                       printVm("", vmInstall);
+                                       // printVm("", vmInstall);
                                        // properties based on name
-                                       vmArgs.append(" -D" + VMS_PROPERTY_PREFIX + "."
-                                                       + vmInstall.getName() + "="
-                                                       + vmInstall.getInstallLocation());
+                                       addVmSysProperty(vmArgs, vmInstall.getName(), vmInstall);
                                        if (vmInstall instanceof IVMInstall2) {
                                                // properties based on version
                                                IVMInstall2 vmInstall2 = (IVMInstall2) vmInstall;
                                                String version = vmInstall2.getJavaVersion();
-                                               vmArgs.append(" -D" + VMS_PROPERTY_PREFIX + "."
-                                                               + version + "="
-                                                               + vmInstall.getInstallLocation());
+                                               addVmSysProperty(vmArgs, version, vmInstall);
 
                                                List<String> tokens = new ArrayList<String>();
                                                StringTokenizer st = new StringTokenizer(version, ".");
                                                while (st.hasMoreTokens())
                                                        tokens.add(st.nextToken());
                                                if (tokens.size() >= 2)
-                                                       vmArgs.append(" -D" + VMS_PROPERTY_PREFIX + "."
-                                                                       + tokens.get(0) + "." + tokens.get(1) + "="
-                                                                       + vmInstall.getInstallLocation());
-
+                                                       addVmSysProperty(vmArgs, tokens.get(0) + "."
+                                                                       + tokens.get(1), vmInstall);
                                        }
                                }
                        }
-                       // printVm("Default", JavaRuntime.getDefaultVMInstall());
-                       // IExecutionEnvironment[] execEnvs = JavaRuntime
-                       // .getExecutionEnvironmentsManager()
-                       // .getExecutionEnvironments();
-                       // for (IExecutionEnvironment execEnv : execEnvs) {
-                       // System.out.println("execEnv: id=" + execEnv.getId() + ", desc="
-                       // + execEnv.getDescription());
-                       // if (execEnv.getId().startsWith("J2SE")
-                       // || execEnv.getId().startsWith("Java")) {
-                       // IVMInstall vmInstall = execEnv.getDefaultVM();
-                       // printVm("", vmInstall);
-                       // }
-                       // }
-
                        configuration.setAttribute(
                                        IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, vmArgs
                                                        .toString());
@@ -168,7 +149,20 @@ public class SlcLaunchShortcut extends OSGiLaunchShortcut {
 
        }
 
-       private void printVm(String prefix, IVMInstall vmInstall) {
+       protected void addVmSysProperty(StringBuffer vmArgs, String suffix,
+                       IVMInstall vmInstall) {
+               addSysProperty(vmArgs, VMS_PROPERTY_PREFIX + "." + suffix, vmInstall
+                               .getInstallLocation().getPath());
+       }
+
+       protected void addSysProperty(StringBuffer vmArgs, String key, String value) {
+               String str = "-D" + key + "=" + value;
+               if (str.contains(" "))
+                       str = "\"" + str + "\"";
+               vmArgs.append(" " + str);
+       }
+
+       protected void printVm(String prefix, IVMInstall vmInstall) {
                System.out.println(prefix + " vmInstall: id=" + vmInstall.getId()
                                + ", name=" + vmInstall.getName() + ", installLocation="
                                + vmInstall.getInstallLocation() + ", toString=" + vmInstall);
@@ -177,6 +171,20 @@ public class SlcLaunchShortcut extends OSGiLaunchShortcut {
                        System.out.println("  vmInstall: javaVersion="
                                        + vmInstall2.getJavaVersion());
                }
+               // printVm("Default", JavaRuntime.getDefaultVMInstall());
+               // IExecutionEnvironment[] execEnvs = JavaRuntime
+               // .getExecutionEnvironmentsManager()
+               // .getExecutionEnvironments();
+               // for (IExecutionEnvironment execEnv : execEnvs) {
+               // System.out.println("execEnv: id=" + execEnv.getId() + ", desc="
+               // + execEnv.getDescription());
+               // if (execEnv.getId().startsWith("J2SE")
+               // || execEnv.getId().startsWith("Java")) {
+               // IVMInstall vmInstall = execEnv.getDefaultVM();
+               // printVm("", vmInstall);
+               // }
+               // }
+
        }
 
        protected String convertBundleList(List<String> bundlesToStart,