1 /***********************************************************************************************************************************
2 * Copyright (c) 2000, 2002 IBM Corp. and others. All rights reserved. This program and the accompanying materials are made
3 * available under the terms of the Common Public License v1.0 which accompanies this distribution, and is available at
4 * http://www.eclipse.org/legal/cpl-v10.html
6 * Contributors: IBM Corporation - Initial implementation Vicente Fernando - www.alfersoft.com.ar Christian Perkonig - remote Debug
7 **********************************************************************************************************************************/
8 package net.sourceforge.phpdt.internal.launching;
10 import java.util.Iterator;
12 import net.sourceforge.phpdt.internal.core.JavaProject;
13 import net.sourceforge.phpdt.internal.debug.core.PHPDBGProxy;
14 import net.sourceforge.phpdt.internal.debug.core.model.PHPDebugTarget;
15 import net.sourceforge.phpeclipse.ui.editor.BrowserUtil;
17 import org.eclipse.core.resources.IFile;
18 import org.eclipse.core.resources.IProject;
19 import org.eclipse.debug.core.ILaunch;
20 import org.eclipse.debug.core.model.IProcess;
21 import org.eclipse.swt.widgets.Display;
23 //import net.sourceforge.phpeclipse.resourcesview.PHPProject;
25 public class DebuggerRunner extends InterpreterRunner {
27 public IProcess run(InterpreterRunnerConfiguration configuration, ILaunch launch) {
30 PHPDBGProxy newPHPDBGProxy = new PHPDBGProxy(configuration.useRemoteDebugger(), configuration.getRemoteSourcePath(),
31 configuration.usePathTranslation(),configuration.getPathMap());
34 IProcess process = null;
35 PHPDebugTarget debugTarget = new PHPDebugTarget(launch, process);
36 newPHPDBGProxy.setDebugTarget(debugTarget);
37 newPHPDBGProxy.start();
38 if (configuration.useRemoteDebugger()) {
39 // listener for remote debuger is started
40 if (configuration.useDBGSessionInBrowser()) {
41 activateDBGSESSIDPreview(configuration,newPHPDBGProxy.getPort());
44 setEnvironmentVariables(configuration, newPHPDBGProxy.getPort());
45 // env=configuration.getEnvironment();
46 process = super.run(configuration, launch);
47 debugTarget.setProcess(process);
49 launch.addDebugTarget(debugTarget);
55 * Open the browser in the UI thread with the current debugger URL
57 * @param configuration
60 protected static void activateDBGSESSIDPreview(final InterpreterRunnerConfiguration configuration, final int port) {
61 Display.getDefault().asyncExec(new Runnable() {
63 String fileName = configuration.getFileName();
64 JavaProject jproject = configuration.getProject();
65 IProject project = jproject.getProject();
66 IFile file = project.getFile(fileName);
67 BrowserUtil.showPreview(file, true, "?DBGSESSID=1@clienthost:"+port);
71 protected void setEnvironmentVariables(InterpreterRunnerConfiguration configuration, int listenPort) {
73 String env[] = new String[18];
74 long id = Math.round(Math.random() * 100000);
76 DBGSessID = "DBGSESSID=" + id + "@clienthost:" + listenPort;
77 configuration.addEnvironmentValue("HTTP_COOKIE", DBGSessID, false);
79 * configuration.addEnvironmentValue("REDIRECT_URL",OSFilePath,true);
80 * configuration.addEnvironmentValue("REQUEST_URI",OSFilePath,true);
81 * configuration.addEnvironmentValue("PATH_INFO",OSFilePath,true);
82 * configuration.addEnvironmentValue("PATH_TRANSLATED",OSFilePath,true);
83 * configuration.addEnvironmentValue("SCRIPT_FILENAME",interpreter,true);
84 * configuration.addEnvironmentValue("SERVER_PROTOCOL","HTTP / 1.1",true);
87 * env[0]= "HTTP_COOKIE=" + DBGSessID; env[1]= "REDIRECT_QUERY_STRING="; env[2]= "REDIRECT_STATUS=200"; env[3]= "REDIRECT_URL=" +
88 * OSFilePath; env[4]= "SERVER_SOFTWARE=DBG / 2.1"; env[5]= "SERVER_NAME=localhost"; env[6]= "SERVER_ADDR=127.0.0.1"; env[7]=
89 * "SERVER_PORT=80"; env[8]= "REMOTE_ADDR=127.0.0.1"; env[9]= "SCRIPT_FILENAME=" + interpreter; env[10]= "GATEWAY_INTERFACE=CGI /
90 * 1.1"; env[11]= "SERVER_PROTOCOL=HTTP / 1.1"; env[12]= "REQUEST_METHOD=GET"; env[13]= "QUERY_STRING=test=1"; env[14]=
91 * "REQUEST_URI=" + OSFilePath; env[15]= "PATH_INFO=" + OSFilePath; env[16]= "PATH_TRANSLATED=" + OSFilePath; env[17]=
92 * "SystemRoot=" + Environment.getenv("SystemRoot");
97 protected String getDebugCommandLineArgument() {
101 protected String renderLoadPath(InterpreterRunnerConfiguration configuration) {
102 StringBuffer loadPath = new StringBuffer();
104 JavaProject project = configuration.getProject();
105 addToLoadPath(loadPath, project.getProject());
107 Iterator referencedProjects = project.getReferencedProjects().iterator();
108 while (referencedProjects.hasNext())
109 addToLoadPath(loadPath, (IProject) referencedProjects.next());
111 return loadPath.toString();