1 package net.sourceforge.phpdt.internal.launching;
4 import java.io.IOException;
5 import java.util.Iterator;
7 import net.sourceforge.phpeclipse.resourcesview.PHPProject;
8 import org.eclipse.core.boot.BootLoader;
9 import org.eclipse.core.resources.IProject;
10 import org.eclipse.debug.core.DebugPlugin;
11 import org.eclipse.debug.core.ILaunch;
12 import org.eclipse.debug.core.model.IProcess;
14 public class InterpreterRunner {
16 public InterpreterRunner() {
19 public IProcess run(InterpreterRunnerConfiguration configuration, ILaunch launch) {
20 String commandLine = renderCommandLine(configuration);
21 File workingDirectory = configuration.getAbsoluteWorkingDirectory();
23 Process nativePHPProcess = null;
25 nativePHPProcess = configuration.getInterpreter().exec(commandLine, workingDirectory);
26 } catch (IOException e) {
27 throw new RuntimeException("Unable to execute interpreter: " + commandLine + workingDirectory);
30 IProcess process = DebugPlugin.getDefault().newProcess(launch, nativePHPProcess, renderLabel(configuration));
31 process.setAttribute(PHPLaunchingPlugin.PLUGIN_ID + ".launcher.cmdline", commandLine);
35 protected String renderLabel(InterpreterRunnerConfiguration configuration) {
36 StringBuffer buffer = new StringBuffer();
38 PHPInterpreter interpreter = configuration.getInterpreter();
39 buffer.append("PHP ");
40 buffer.append(interpreter.getCommand());
42 buffer.append(configuration.getFileName());
44 return buffer.toString();
47 protected String renderCommandLine(InterpreterRunnerConfiguration configuration) {
48 PHPInterpreter interpreter = configuration.getInterpreter();
50 StringBuffer buffer = new StringBuffer();
51 buffer.append(this.getDebugCommandLineArgument());
52 // buffer.append(renderLoadPath(configuration));
53 buffer.append(" " + configuration.getInterpreterArguments());
54 // buffer.append(interpreter.endOfOptionsDelimeter);
55 buffer.append(" " + osDependentPath(configuration.getAbsoluteFileName()));
56 buffer.append(" " + configuration.getProgramArguments());
58 return buffer.toString();
61 // protected String renderLoadPath(InterpreterRunnerConfiguration configuration) {
62 // StringBuffer loadPath = new StringBuffer();
64 // PHPProject project = configuration.getProject();
65 // addToLoadPath(loadPath, project.getProject());
67 // Iterator referencedProjects = project.getReferencedProjects().iterator();
68 // while (referencedProjects.hasNext())
69 // addToLoadPath(loadPath, (IProject) referencedProjects.next());
71 // return loadPath.toString();
74 // protected void addToLoadPath(StringBuffer loadPath, IProject project) {
76 // loadPath.append(" -I " + osDependentPath(project.getLocation().toOSString()));
79 protected String osDependentPath(String aPath) {
80 if (BootLoader.getOS().equals(BootLoader.OS_WIN32))
81 aPath = "\"" + aPath + "\"";
86 protected String getDebugCommandLineArgument() {