1 11 package org.eclipse.pde.internal.ui.launcher; 12 13 import java.util.ArrayList ; 14 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.debug.core.ILaunchConfiguration; 17 import org.eclipse.jdt.launching.IVMInstall; 18 import org.eclipse.jdt.launching.IVMInstallType; 19 import org.eclipse.jdt.launching.JavaRuntime; 20 import org.eclipse.jdt.launching.environments.IExecutionEnvironment; 21 import org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager; 22 import org.eclipse.osgi.util.NLS; 23 import org.eclipse.pde.internal.ui.PDEUIMessages; 24 import org.eclipse.pde.ui.launcher.IPDELauncherConstants; 25 26 public class VMHelper { 27 28 public static IVMInstall[] getAllVMInstances() { 29 ArrayList res = new ArrayList (); 30 IVMInstallType[] types = JavaRuntime.getVMInstallTypes(); 31 for (int i = 0; i < types.length; i++) { 32 IVMInstall[] installs = types[i].getVMInstalls(); 33 for (int k = 0; k < installs.length; k++) { 34 res.add(installs[k]); 35 } 36 } 37 return (IVMInstall[]) res.toArray(new IVMInstall[res.size()]); 38 } 39 40 public static String [] getVMInstallNames() { 41 IVMInstall[] installs = getAllVMInstances(); 42 String [] names = new String [installs.length]; 43 for (int i = 0; i < installs.length; i++) { 44 names[i] = installs[i].getName(); 45 } 46 return names; 47 } 48 49 public static String getDefaultVMInstallName() { 50 IVMInstall install = JavaRuntime.getDefaultVMInstall(); 51 if (install != null) 52 return install.getName(); 53 return null; 54 } 55 56 public static String getDefaultVMInstallLocation() { 57 IVMInstall install = JavaRuntime.getDefaultVMInstall(); 58 if (install != null) 59 return install.getInstallLocation().getAbsolutePath(); 60 return null; 61 } 62 63 public static IVMInstall getVMInstall(ILaunchConfiguration configuration) throws CoreException { 64 String vm = configuration.getAttribute(IPDELauncherConstants.VMINSTALL, (String ) null); 65 return getVMInstall(vm); 66 } 67 68 69 public static IVMInstall getVMInstall(String name) { 70 if (name != null) { 71 IVMInstall[] installs = getAllVMInstances(); 72 for (int i = 0; i < installs.length; i++) { 73 if (installs[i].getName().equals(name)) 74 return installs[i]; 75 } 76 } 77 return JavaRuntime.getDefaultVMInstall(); 78 } 79 80 public static IVMInstall createLauncher( 81 ILaunchConfiguration configuration) 82 throws CoreException { 83 String vm = configuration.getAttribute(IPDELauncherConstants.VMINSTALL, (String ) null); 84 IVMInstall launcher = getVMInstall(vm); 85 if (launcher == null) 86 throw new CoreException( 87 LauncherUtils.createErrorStatus(NLS.bind(PDEUIMessages.WorkbenchLauncherConfigurationDelegate_noJRE, vm))); 88 89 if (!launcher.getInstallLocation().exists()) 90 throw new CoreException( 91 LauncherUtils.createErrorStatus(PDEUIMessages.WorkbenchLauncherConfigurationDelegate_jrePathNotFound)); 92 93 return launcher; 94 } 95 96 public static IExecutionEnvironment[] getExecutionEnvironments() { 97 IExecutionEnvironmentsManager manager = 98 JavaRuntime.getExecutionEnvironmentsManager(); 99 return manager.getExecutionEnvironments(); 100 } 101 102 } 103 | Popular Tags |