1 package com.bull.eclipse.jonas.utils; 2 3 7 8 9 import org.eclipse.core.runtime.CoreException; 10 import org.eclipse.debug.core.DebugPlugin; 11 import org.eclipse.debug.core.ILaunch; 12 import org.eclipse.debug.core.ILaunchConfigurationType; 13 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; 14 import org.eclipse.debug.core.ILaunchManager; 15 import org.eclipse.debug.core.Launch; 16 import org.eclipse.debug.core.model.ISourceLocator; 17 import org.eclipse.debug.ui.DebugUITools; 18 import org.eclipse.debug.ui.IDebugUIConstants; 19 import org.eclipse.jdt.launching.IVMInstall; 20 import org.eclipse.jdt.launching.IVMInstallType; 21 import org.eclipse.jdt.launching.IVMRunner; 22 import org.eclipse.jdt.launching.JavaRuntime; 23 import org.eclipse.jdt.launching.VMRunnerConfiguration; 24 25 import com.bull.eclipse.jonas.JonasLauncherPlugin; 26 27 28 29 30 36 37 public class VMLauncherUtility { 38 39 static public IVMInstall getVMInstall() { 40 IVMInstallType[] vmTypes = JavaRuntime.getVMInstallTypes(); 41 for (int i = 0; i < vmTypes.length; i++) { 42 IVMInstall[] vms = vmTypes[i].getVMInstalls(); 43 for (int j = 0; j < vms.length; j++) { 44 if(vms[j].getId().equals(JonasLauncherPlugin.getDefault().getJonasJRE())) { 45 return vms[j]; 46 } 47 } 48 } 49 return JavaRuntime.getDefaultVMInstall(); 50 } 51 52 53 static public void runVM(String label, String classToLaunch, String [] classpath, String [] bootClasspath, String [] vmArgs, String [] prgArgs, ISourceLocator sourceLocator, boolean debug, boolean showInDebugger) throws CoreException{ 54 runVM( label, classToLaunch, classpath, bootClasspath, vmArgs, prgArgs, sourceLocator, debug, showInDebugger, null ); 55 } 56 57 58 static public void runVM( String label, 59 String classToLaunch, 60 String [] classpath, 61 String [] bootClasspath, 62 String [] vmArgs, 63 String [] prgArgs, 64 ISourceLocator sourceLocator, 65 boolean debug, 66 boolean showInDebugger, 67 String workingDir 68 ) throws CoreException 69 { 70 IVMInstall vmInstall = getVMInstall(); 71 String mode = ""; 72 if (debug) 73 mode = ILaunchManager.DEBUG_MODE; 74 else 75 mode = ILaunchManager.RUN_MODE; 76 77 IVMRunner vmRunner = vmInstall.getVMRunner(mode); 78 79 ILaunchConfigurationType launchType = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationType("org.eclipse.jdt.launching.localJavaApplication"); 80 ILaunchConfigurationWorkingCopy config = launchType.newInstance(null, label); 81 config.setAttribute(IDebugUIConstants.ATTR_PRIVATE, true); 82 DebugUITools.setLaunchPerspective(launchType,"debug",IDebugUIConstants.PERSPECTIVE_DEFAULT); 83 DebugUITools.setLaunchPerspective(launchType,"run",IDebugUIConstants.PERSPECTIVE_DEFAULT); 84 config.setAttribute(IDebugUIConstants.ATTR_TARGET_DEBUG_PERSPECTIVE, IDebugUIConstants.PERSPECTIVE_DEFAULT); 85 config.setAttribute(IDebugUIConstants.ATTR_TARGET_RUN_PERSPECTIVE, IDebugUIConstants.PERSPECTIVE_DEFAULT); 86 88 Launch launch = new Launch(config, mode, sourceLocator); 89 90 config.doSave(); 91 92 if (vmRunner != null) { 93 VMRunnerConfiguration vmConfig = 94 new VMRunnerConfiguration(classToLaunch, classpath); 95 vmConfig.setVMArguments(vmArgs); 96 vmConfig.setProgramArguments(prgArgs); 97 98 if( workingDir!=null ) { vmConfig.setWorkingDirectory( workingDir ); } 99 100 if(bootClasspath.length == 0) { 101 vmConfig.setBootClassPath(null); } else { 103 vmConfig.setBootClassPath(bootClasspath); 104 } 105 106 107 vmRunner.run(vmConfig, launch, null); 108 109 } 110 111 if(showInDebugger) { 113 DebugPlugin.getDefault().getLaunchManager().addLaunch(launch); 114 } 115 116 } 117 118 119 122 static public void showInDebugger(ILaunch launch) throws CoreException { 123 DebugPlugin.getDefault().getLaunchManager().addLaunch(launch); 124 } 125 126 127 } 128 | Popular Tags |