package net.sourceforge.phpdt.internal.launching; import java.io.File; import java.io.IOException; import java.util.Iterator; import net.sourceforge.phpdt.internal.core.JavaProject; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.Platform; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.model.IProcess; public class InterpreterRunner { public InterpreterRunner() { } public IProcess run(InterpreterRunnerConfiguration configuration, ILaunch launch, String[] env) { String commandLine = renderCommandLine(configuration); File workingDirectory = configuration.getAbsoluteWorkingDirectory(); Process nativePHPProcess = null; try { nativePHPProcess = configuration.getInterpreter().exec(commandLine, workingDirectory, env); } catch (IOException e) { throw new RuntimeException("Unable to execute interpreter: " + commandLine + workingDirectory); } IProcess process = DebugPlugin.newProcess(launch, nativePHPProcess, renderLabel(configuration)); process.setAttribute(PHPLaunchingPlugin.PLUGIN_ID + ".launcher.cmdline", commandLine); return process ; } protected String renderLabel(InterpreterRunnerConfiguration configuration) { StringBuffer buffer = new StringBuffer(); PHPInterpreter interpreter = configuration.getInterpreter(); buffer.append("PHP "); buffer.append(interpreter.getCommand()); buffer.append(" : "); buffer.append(configuration.getFileName()); return buffer.toString(); } protected String renderCommandLine(InterpreterRunnerConfiguration configuration) { PHPInterpreter interpreter = configuration.getInterpreter(); StringBuffer buffer = new StringBuffer(); buffer.append(this.getDebugCommandLineArgument()); // buffer.append(renderLoadPath(configuration)); buffer.append(" " + configuration.getInterpreterArguments()); // buffer.append(interpreter.endOfOptionsDelimeter); buffer.append(" " + osDependentPath(configuration.getAbsoluteFileName())); buffer.append(" " + configuration.getProgramArguments()); return buffer.toString(); } protected String renderLoadPath(InterpreterRunnerConfiguration configuration) { StringBuffer loadPath = new StringBuffer(); JavaProject project = configuration.getProject(); addToLoadPath(loadPath, project.getProject()); Iterator referencedProjects = project.getReferencedProjects().iterator(); while (referencedProjects.hasNext()) addToLoadPath(loadPath, (IProject) referencedProjects.next()); return loadPath.toString(); } protected void addToLoadPath(StringBuffer loadPath, IProject project) { loadPath.append(" -I " + osDependentPath(project.getLocation().toOSString())); } protected String osDependentPath(String aPath) { if (Platform.getOS().equals(Platform.OS_WIN32)) aPath = "\"" + aPath + "\""; return aPath; } protected String getDebugCommandLineArgument() { return "" ; } }