inital plugin from webtools project
[phpeclipse.git] / net.sourceforge.phpeclipse.launching / src / net / sourceforge / phpdt / internal / launching / DebuggerRunner.java
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
7
8 Contributors:
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;
14
15 import java.util.Iterator;
16
17 import net.sourceforge.phpdt.internal.core.JavaProject;
18 import net.sourceforge.phpdt.internal.debug.core.PHPDBGProxy;
19 import net.sourceforge.phpdt.internal.debug.core.model.PHPDebugTarget;
20
21 import org.eclipse.core.resources.IProject;
22 import org.eclipse.debug.core.ILaunch;
23 import org.eclipse.debug.core.model.IProcess;
24 //import net.sourceforge.phpeclipse.resourcesview.PHPProject;
25
26 public class DebuggerRunner extends InterpreterRunner {
27
28         public IProcess run(InterpreterRunnerConfiguration configuration, ILaunch launch) {
29                 String[] env;
30                 String name, value;
31                 PHPDBGProxy newPHPDBGProxy= new PHPDBGProxy(configuration.useRemoteDebugger(),
32                                                             configuration.getRemoteSourcePath());
33                 int pos;
34
35
36                 IProcess process =null;
37                 PHPDebugTarget debugTarget = new PHPDebugTarget(launch, process);
38                 newPHPDBGProxy.setDebugTarget(debugTarget);             
39                 newPHPDBGProxy.start();                         
40                 if (configuration.useRemoteDebugger())
41                 {
42                         // listener for remote debuger is started 
43                 }
44                 else
45                 {
46                         setEnvironmentVariables(configuration,newPHPDBGProxy.getPort());
47 //                      env=configuration.getEnvironment();
48                         process = super.run(configuration, launch);
49                         debugTarget.setProcess(process);
50                 }       
51                 launch.addDebugTarget(debugTarget);
52
53                 return process;
54         }
55         
56         protected void setEnvironmentVariables(InterpreterRunnerConfiguration configuration,int listenPort) {
57                 String DBGSessID;
58                 String env[]= new String[18];
59                 long id = Math.round(Math.random()*100000);
60                 
61
62                 DBGSessID = "DBGSESSID="+id+"@clienthost:" + listenPort;
63                 configuration.addEnvironmentValue("HTTP_COOKIE",DBGSessID,false);
64 /*              configuration.addEnvironmentValue("REDIRECT_URL",OSFilePath,true);
65                 configuration.addEnvironmentValue("REQUEST_URI",OSFilePath,true);
66                 configuration.addEnvironmentValue("PATH_INFO",OSFilePath,true);
67                 configuration.addEnvironmentValue("PATH_TRANSLATED",OSFilePath,true);
68                 configuration.addEnvironmentValue("SCRIPT_FILENAME",interpreter,true);
69                 configuration.addEnvironmentValue("SERVER_PROTOCOL","HTTP / 1.1",true);
70 */
71 /*              
72                 env[0]= "HTTP_COOKIE=" + DBGSessID;
73                 env[1]= "REDIRECT_QUERY_STRING=";
74                 env[2]= "REDIRECT_STATUS=200";
75                 env[3]= "REDIRECT_URL=" + OSFilePath;
76                 env[4]= "SERVER_SOFTWARE=DBG / 2.1";
77                 env[5]= "SERVER_NAME=localhost";
78                 env[6]= "SERVER_ADDR=127.0.0.1";
79                 env[7]= "SERVER_PORT=80";
80                 env[8]= "REMOTE_ADDR=127.0.0.1";
81                 env[9]= "SCRIPT_FILENAME=" + interpreter;
82                 env[10]= "GATEWAY_INTERFACE=CGI / 1.1";
83                 env[11]= "SERVER_PROTOCOL=HTTP / 1.1";
84                 env[12]= "REQUEST_METHOD=GET";
85                 env[13]= "QUERY_STRING=test=1";
86                 env[14]= "REQUEST_URI=" + OSFilePath;
87                 env[15]= "PATH_INFO=" + OSFilePath;
88                 env[16]= "PATH_TRANSLATED=" + OSFilePath;
89                 env[17]= "SystemRoot=" + Environment.getenv("SystemRoot");
90 */
91         //      return env;
92         }
93
94         protected String getDebugCommandLineArgument() {
95                 return "";
96         }
97
98         protected String renderLoadPath(InterpreterRunnerConfiguration configuration) {
99                 StringBuffer loadPath = new StringBuffer();
100
101                 JavaProject project = configuration.getProject();
102                 addToLoadPath(loadPath, project.getProject());
103
104                 Iterator referencedProjects = project.getReferencedProjects().iterator();
105                 while (referencedProjects.hasNext())
106                         addToLoadPath(loadPath, (IProject) referencedProjects.next());
107
108                 return loadPath.toString();
109         }
110 }