203a5b4db54286b0bf89c2f75106b8d9a245c67c
[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 **********************************************************************/
12 package net.sourceforge.phpdt.internal.launching;
13
14 import java.util.Iterator;
15
16 import org.eclipse.core.resources.IProject;
17 import org.eclipse.debug.core.ILaunch;
18 import org.eclipse.debug.core.model.IProcess;
19 import org.eclipse.core.runtime.IPath;
20 import org.eclipse.core.runtime.Path;
21 import net.sourceforge.phpdt.internal.debug.core.model.PHPDebugTarget;
22 import net.sourceforge.phpdt.internal.debug.core.Environment;
23 import net.sourceforge.phpdt.internal.debug.core.PHPDBGProxy;
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                 PHPDBGProxy newPHPDBGProxy= new PHPDBGProxy();
31                 newPHPDBGProxy.start();
32                 env= setEnvironmentVariables(newPHPDBGProxy.getPort(), configuration.getAbsoluteFileName());
33                 
34                 IProcess process = super.run(configuration, launch, env);
35                 PHPDebugTarget debugTarget = new PHPDebugTarget(launch, process);
36                 newPHPDBGProxy.setDebugTarget(debugTarget);
37                 launch.addDebugTarget(debugTarget);
38
39                 return process;
40         }
41
42         protected String[] setEnvironmentVariables(int listenPort, String AbsoluteFileName) {
43                 IPath FilePath= new Path(AbsoluteFileName);
44                 String OSFilePath= FilePath.toOSString();
45                 String DBGSessID;
46                 String env[]= new String[18];
47
48                 DBGSessID = "DBGSESSID=0753972710000018@clienthost:" + listenPort;
49
50                 env[0]= "HTTP_COOKIE=" + DBGSessID;
51                 env[1]= "REDIRECT_QUERY_STRING=";
52                 env[2]= "REDIRECT_STATUS=200";
53                 env[3]= "REDIRECT_URL=" + OSFilePath;
54                 env[4]= "SERVER_SOFTWARE=DBG / 2.1";
55                 env[5]= "SERVER_NAME=localhost";
56                 env[6]= "SERVER_ADDR=127.0.0.1";
57                 env[7]= "SERVER_PORT=80";
58                 env[8]= "REMOTE_ADDR=127.0.0.1";
59                 env[9]= "SCRIPT_FILENAME=c:\\php\\php.exe";
60                 env[10]= "GATEWAY_INTERFACE=CGI / 1.1";
61                 env[11]= "SERVER_PROTOCOL=HTTP / 1.1";
62                 env[12]= "REQUEST_METHOD=GET";
63                 env[13]= "QUERY_STRING=";
64                 env[14]= "REQUEST_URI=" + OSFilePath;
65                 env[15]= "PATH_INFO=" + OSFilePath;
66                 env[16]= "PATH_TRANSLATED=" + OSFilePath;
67                 env[17]= "SystemRoot=" + Environment.getenv("SystemRoot");
68
69                 return env;
70         }
71
72         protected String getDebugCommandLineArgument() {
73                 return "";
74         }
75
76         protected String renderLoadPath(InterpreterRunnerConfiguration configuration) {
77                 StringBuffer loadPath = new StringBuffer();
78
79                 PHPProject project = configuration.getProject();
80                 addToLoadPath(loadPath, project.getProject());
81
82                 Iterator referencedProjects = project.getReferencedProjects().iterator();
83                 while (referencedProjects.hasNext())
84                         addToLoadPath(loadPath, (IProject) referencedProjects.next());
85
86                 return loadPath.toString();
87         }
88 }