1 /**********************************************************************
2 Copyright (c) 2000, 2002 IBM Corp. and others.
3 All rights reserved. This program and the accompanying materials
4 are made available under the terms of the Common Public License v1.0
5 which accompanies this distribution, and is available at
6 http://www.eclipse.org/legal/cpl-v10.html
9 IBM Corporation - Initial implementation
10 Vicente Fernando - www.alfersoft.com.ar
11 Christian Perkonig - remote Debug
12 **********************************************************************/
13 package net.sourceforge.phpdt.internal.launching;
15 import java.util.Iterator;
17 import net.sourceforge.phpdt.internal.core.JavaProject;
18 import net.sourceforge.phpdt.internal.debug.core.Environment;
19 import net.sourceforge.phpdt.internal.debug.core.PHPDBGProxy;
20 import net.sourceforge.phpdt.internal.debug.core.model.PHPDebugTarget;
22 import org.eclipse.core.resources.IProject;
23 import org.eclipse.core.runtime.IPath;
24 import org.eclipse.core.runtime.Path;
25 import org.eclipse.debug.core.ILaunch;
26 import org.eclipse.debug.core.model.IProcess;
27 //import net.sourceforge.phpeclipse.resourcesview.PHPProject;
29 public class DebuggerRunner extends InterpreterRunner {
31 public IProcess run(InterpreterRunnerConfiguration configuration, ILaunch launch) {
34 PHPDBGProxy newPHPDBGProxy= new PHPDBGProxy(configuration.useRemoteDebugger(),
35 configuration.getRemoteSourcePath());
39 IProcess process =null;
40 PHPDebugTarget debugTarget = new PHPDebugTarget(launch, process);
41 newPHPDBGProxy.setDebugTarget(debugTarget);
42 newPHPDBGProxy.start();
43 if (configuration.useRemoteDebugger())
45 // listener for remote debuger is started
50 env= setEnvironmentVariables(newPHPDBGProxy.getPort(), configuration.getAbsoluteFileName(), configuration.getInterpreter().getCommand());
51 for(int i= 0; i < env.length; i++) {
52 pos= env[i].indexOf("=");
54 name= env[i].substring(0, pos);
55 value= env[i].substring(pos + 1);
60 Environment.setenv(name, value);
62 // now enviroment settings is made with Environment class
63 // because if new parameters are passed by array, doesn't inherit system vars
64 process = super.run(configuration, launch, null);
65 debugTarget.setProcess(process);
67 launch.addDebugTarget(debugTarget);
72 protected String[] setEnvironmentVariables(int listenPort, String AbsoluteFileName, String interpreter) {
73 IPath FilePath= new Path(AbsoluteFileName);
74 String OSFilePath= FilePath.toOSString();
76 String env[]= new String[18];
78 DBGSessID = "DBGSESSID=0753972710000018@clienthost:" + listenPort;
80 env[0]= "HTTP_COOKIE=" + DBGSessID;
81 env[1]= "REDIRECT_QUERY_STRING=";
82 env[2]= "REDIRECT_STATUS=200";
83 env[3]= "REDIRECT_URL=" + OSFilePath;
84 env[4]= "SERVER_SOFTWARE=DBG / 2.1";
85 env[5]= "SERVER_NAME=localhost";
86 env[6]= "SERVER_ADDR=127.0.0.1";
87 env[7]= "SERVER_PORT=80";
88 env[8]= "REMOTE_ADDR=127.0.0.1";
89 env[9]= "SCRIPT_FILENAME=" + interpreter;
90 env[10]= "GATEWAY_INTERFACE=CGI / 1.1";
91 env[11]= "SERVER_PROTOCOL=HTTP / 1.1";
92 env[12]= "REQUEST_METHOD=GET";
93 env[13]= "QUERY_STRING=";
94 env[14]= "REQUEST_URI=" + OSFilePath;
95 env[15]= "PATH_INFO=" + OSFilePath;
96 env[16]= "PATH_TRANSLATED=" + OSFilePath;
97 env[17]= "SystemRoot=" + Environment.getenv("SystemRoot");
102 protected String getDebugCommandLineArgument() {
106 protected String renderLoadPath(InterpreterRunnerConfiguration configuration) {
107 StringBuffer loadPath = new StringBuffer();
109 JavaProject project = configuration.getProject();
110 addToLoadPath(loadPath, project.getProject());
112 Iterator referencedProjects = project.getReferencedProjects().iterator();
113 while (referencedProjects.hasNext())
114 addToLoadPath(loadPath, (IProject) referencedProjects.next());
116 return loadPath.toString();