1 11 package org.eclipse.jdt.launching; 12 13 14 import java.io.File ; 15 import java.util.HashMap ; 16 import java.util.Map ; 17 18 import org.eclipse.core.runtime.CoreException; 19 import org.eclipse.core.runtime.IStatus; 20 import org.eclipse.core.runtime.Status; 21 import org.eclipse.debug.core.DebugPlugin; 22 import org.eclipse.debug.core.ILaunch; 23 import org.eclipse.debug.core.model.IProcess; 24 import org.eclipse.jdt.internal.launching.LaunchingMessages; 25 26 34 public abstract class AbstractVMRunner implements IVMRunner { 35 36 46 protected void abort(String message, Throwable exception, int code) throws CoreException { 47 throw new CoreException(new Status(IStatus.ERROR, getPluginIdentifier(), code, message, exception)); 48 } 49 50 56 protected abstract String getPluginIdentifier(); 57 58 61 protected Process exec(String [] cmdLine, File workingDirectory) throws CoreException { 62 return DebugPlugin.exec(cmdLine, workingDirectory); 63 } 64 65 69 protected Process exec(String [] cmdLine, File workingDirectory, String [] envp) throws CoreException { 70 return DebugPlugin.exec(cmdLine, workingDirectory, envp); 71 } 72 73 79 protected String getCmdLineAsString(String [] cmdLine) { 80 StringBuffer buff= new StringBuffer (); 81 for (int i = 0, numStrings= cmdLine.length; i < numStrings; i++) { 82 buff.append(cmdLine[i]); 83 buff.append(' '); 84 } 85 return buff.toString().trim(); 86 } 87 88 93 protected Map getDefaultProcessMap() { 94 Map map = new HashMap (); 95 map.put(IProcess.ATTR_PROCESS_TYPE, IJavaLaunchConfigurationConstants.ID_JAVA_PROCESS_TYPE); 96 return map; 97 } 98 99 109 protected IProcess newProcess(ILaunch launch, Process p, String label, Map attributes) throws CoreException { 110 IProcess process= DebugPlugin.newProcess(launch, p, label, attributes); 111 if (process == null) { 112 p.destroy(); 113 abort(LaunchingMessages.AbstractVMRunner_0, null, IJavaLaunchConfigurationConstants.ERR_INTERNAL_ERROR); 114 } 115 return process; 116 } 117 118 128 protected String [] combineVmArgs(VMRunnerConfiguration configuration, IVMInstall vmInstall) { 129 String [] launchVMArgs= configuration.getVMArguments(); 130 String [] vmVMArgs = vmInstall.getVMArguments(); 131 if (vmVMArgs == null || vmVMArgs.length == 0) { 132 return launchVMArgs; 133 } 134 String [] allVMArgs = new String [launchVMArgs.length + vmVMArgs.length]; 135 System.arraycopy(launchVMArgs, 0, allVMArgs, 0, launchVMArgs.length); 136 System.arraycopy(vmVMArgs, 0, allVMArgs, launchVMArgs.length, vmVMArgs.length); 137 return allVMArgs; 138 } 139 } 140 | Popular Tags |