13eb2cc3a01be34768419bea32b7a3b5faec92cc
[phpeclipse.git] /
1 package net.sourceforge.phpdt.internal.launching;
2
3 import java.io.File;
4 import java.io.IOException;
5
6 import org.eclipse.core.boot.BootLoader;
7 import org.eclipse.debug.core.DebugPlugin;
8 import org.eclipse.debug.core.ILaunch;
9 import org.eclipse.debug.core.model.IProcess;
10
11 public class InterpreterRunner {
12
13         public InterpreterRunner() {
14         }
15
16         public IProcess run(InterpreterRunnerConfiguration configuration, ILaunch launch) {
17                 String commandLine = renderCommandLine(configuration);
18                 File workingDirectory = configuration.getAbsoluteWorkingDirectory();
19
20                 Process nativePHPProcess = null;
21                 try {
22                         nativePHPProcess = configuration.getInterpreter().exec(commandLine, workingDirectory);
23                 } catch (IOException e) {
24                         throw new RuntimeException("Unable to execute interpreter: " + commandLine + workingDirectory);
25                 }
26
27                 IProcess process = DebugPlugin.newProcess(launch, nativePHPProcess, renderLabel(configuration));
28                 process.setAttribute(PHPLaunchingPlugin.PLUGIN_ID + ".launcher.cmdline", commandLine);
29                 return process ;
30         }
31
32         protected String renderLabel(InterpreterRunnerConfiguration configuration) {
33                 StringBuffer buffer = new StringBuffer();
34
35                 PHPInterpreter interpreter = configuration.getInterpreter();
36                 buffer.append("PHP ");
37                 buffer.append(interpreter.getCommand());
38                 buffer.append(" : ");
39                 buffer.append(configuration.getFileName());
40
41                 return buffer.toString();
42         }
43
44         protected String renderCommandLine(InterpreterRunnerConfiguration configuration) {
45                 PHPInterpreter interpreter = configuration.getInterpreter();
46
47                 StringBuffer buffer = new StringBuffer();
48                 buffer.append(this.getDebugCommandLineArgument());
49         //      buffer.append(renderLoadPath(configuration));
50                 buffer.append(" " + configuration.getInterpreterArguments());
51         //      buffer.append(interpreter.endOfOptionsDelimeter);
52                 buffer.append(" " + osDependentPath(configuration.getAbsoluteFileName()));
53                 buffer.append(" " + configuration.getProgramArguments());
54
55                 return buffer.toString();
56         }
57
58 //      protected String renderLoadPath(InterpreterRunnerConfiguration configuration) {
59 //              StringBuffer loadPath = new StringBuffer();
60 //
61 //              PHPProject project = configuration.getProject();
62 //              addToLoadPath(loadPath, project.getProject());
63 //
64 //              Iterator referencedProjects = project.getReferencedProjects().iterator();
65 //              while (referencedProjects.hasNext())
66 //                      addToLoadPath(loadPath, (IProject) referencedProjects.next());
67 //
68 //              return loadPath.toString();
69 //      }
70
71 //      protected void addToLoadPath(StringBuffer loadPath, IProject project) {
72 //
73 //              loadPath.append(" -I " + osDependentPath(project.getLocation().toOSString()));
74 //      }
75
76         protected String osDependentPath(String aPath) {
77                 if (BootLoader.getOS().equals(BootLoader.OS_WIN32))
78                         aPath = "\"" + aPath + "\"";
79
80                 return aPath;
81         }
82         
83         protected String getDebugCommandLineArgument() {
84                 return "" ;     
85         }
86         
87 }