From e58606a5d1958411baa9c362879b7e9405089cfa Mon Sep 17 00:00:00 2001 From: stefanbjarni Date: Wed, 25 May 2005 21:45:54 +0000 Subject: [PATCH] Debugger now steps through embedded PHP in HTML files. Fixed a bug that prevented the debugger from popping up the right line in a PHP editor. Mods: debug.ui plugin: PHPSourceLocator.java: Moved this file to the launching plugin launching: PHPSourceLocator.java: Moved this file from the debug.ui plugin PHPLaunchConfigurationDelegate.java: Added the getLaunch method. This puts the PHP source locator into the launch, which let's the debugger client find lines in PHP source. plugin.xml: PHP debugger now associated with .htm and .html files, so it's possible to step through embedded PHP code in HTML files. Tested: PHPeclipse CVS HEAD on Windows, against Xampp on local host. --- .../phpdt/internal/debug/ui/PHPSourceLocator.java | 163 -------------------- net.sourceforge.phpeclipse.launching/plugin.xml | 9 + .../launching/PHPLaunchConfigurationDelegate.java | 64 +++++--- .../phpdt/internal/launching/PHPSourceLocator.java | 162 +++++++++++++++++++ 4 files changed, 210 insertions(+), 188 deletions(-) delete mode 100644 net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/PHPSourceLocator.java create mode 100644 net.sourceforge.phpeclipse.launching/src/net/sourceforge/phpdt/internal/launching/PHPSourceLocator.java diff --git a/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/PHPSourceLocator.java b/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/PHPSourceLocator.java deleted file mode 100644 index 8dfbfdd..0000000 --- a/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/PHPSourceLocator.java +++ /dev/null @@ -1,163 +0,0 @@ -package net.sourceforge.phpdt.internal.debug.ui; - -import java.util.Iterator; -import java.util.Map; - -import net.sourceforge.phpdt.internal.debug.core.model.PHPStackFrame; -import net.sourceforge.phpdt.internal.launching.PHPLaunchConfigurationAttribute; -import net.sourceforge.phpeclipse.PHPeclipsePlugin; -import net.sourceforge.phpeclipse.builder.ExternalEditorInput; -import net.sourceforge.phpeclipse.builder.FileStorage; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; -import org.eclipse.debug.core.ILaunchConfiguration; -import org.eclipse.debug.core.model.IPersistableSourceLocator; -import org.eclipse.debug.core.model.IStackFrame; -import org.eclipse.debug.ui.ISourcePresentation; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.part.FileEditorInput; - -public class PHPSourceLocator implements IPersistableSourceLocator, ISourcePresentation { - private String absoluteWorkingDirectory; - private Map pathMap = null; - private boolean remoteDebug; - private IPath remoteSourcePath; - private String projectName; - - public PHPSourceLocator() { - - } - - public String getAbsoluteWorkingDirectory() { - return absoluteWorkingDirectory; - } - /** - * @see org.eclipse.debug.core.model.IPersistableSourceLocator#getMemento() - */ - public String getMemento() throws CoreException { - return null; - } - - /** - * @see org.eclipse.debug.core.model.IPersistableSourceLocator#initializeFromMemento(String) - */ - public void initializeFromMemento(String memento) throws CoreException { - } - - /** - * @see org.eclipse.debug.core.model.IPersistableSourceLocator#initializeDefaults(ILaunchConfiguration) - */ - public void initializeDefaults(ILaunchConfiguration configuration) throws CoreException { - this.absoluteWorkingDirectory = configuration.getAttribute(PHPLaunchConfigurationAttribute.WORKING_DIRECTORY, ""); - this.remoteDebug=configuration.getAttribute(PHPLaunchConfigurationAttribute.REMOTE_DEBUG,false); - this.pathMap = configuration.getAttribute(PHPLaunchConfigurationAttribute.FILE_MAP, (Map)null); - this.projectName =configuration.getAttribute(PHPLaunchConfigurationAttribute.PROJECT_NAME, ""); - - if (Platform.getOS().equals(Platform.OS_WIN32)) - this.remoteSourcePath= new Path((configuration.getAttribute(PHPLaunchConfigurationAttribute.REMOTE_PATH, "")).toLowerCase()); - else - this.remoteSourcePath= new Path(configuration.getAttribute(PHPLaunchConfigurationAttribute.REMOTE_PATH, "")); - -// system.os.name - - } - - /** - * @see org.eclipse.debug.core.model.ISourceLocator#getSourceElement(IStackFrame) - */ - public Object getSourceElement(IStackFrame stackFrame) { - - String fileName=((PHPStackFrame) stackFrame).getFileName(); - String file=""; - - if (remoteDebug) - { - IPath path = new Path(fileName); - if (remoteSourcePath.isPrefixOf(path)) - { - IPath projectPath; - path=path.removeFirstSegments(remoteSourcePath.matchingFirstSegments(path)); - file=path.toString(); - projectPath=(PHPeclipsePlugin.getWorkspace().getRoot().getProject(projectName).getLocation()); - return (projectPath.append(path)).toOSString(); - } - - if (pathMap == null) { - return fileName; - } - Iterator iterator = pathMap.keySet().iterator(); - while (iterator.hasNext()) { - String local = (String) iterator.next(); - IPath remotePath = new Path((String) pathMap.get(local)); - if (remotePath.isPrefixOf(path)) { - path=path.removeFirstSegments(remotePath.matchingFirstSegments(path)); - IPath localPath= new Path(local); - return localPath.append(path).toOSString(); - } - } - return fileName; - } else { - return fileName; - } - } - - /** - * @see org.eclipse.debug.ui.ISourcePresentation#getEditorId(IEditorInput, Object) - */ - public String getEditorId(IEditorInput input, Object element) { - return PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor((String) element).getId(); - } - - /** - * @see org.eclipse.debug.ui.ISourcePresentation#getEditorInput(Object) - */ - public IEditorInput getEditorInput(Object element) { - - String filename = (String) element; - IWorkbench workbench = PlatformUI.getWorkbench(); - IWorkbenchWindow window = workbench.getWorkbenchWindows()[0]; - IWorkbenchPage page = window.getActivePage(); - IPath path = new Path(filename); - - - - // If the file exists in the workspace, open it - IFile eclipseFile = PHPeclipsePlugin.getWorkspace().getRoot().getFileForLocation(path); - // IFile eclipseFile = PHPeclipsePlugin.getWorkspace().getRoot().getFileForLocation(new Path(filename)); -// if (eclipseFile == null) { -// filename = this.getAbsoluteWorkingDirectory() + "/" + filename; -// eclipseFile = PHPeclipsePlugin.getWorkspace().getRoot().getFileForLocation(new Path(filename)); -// if (eclipseFile == null) { -// PHPeclipsePlugin.log(IStatus.INFO, "Could not find file \"" + element + "\"."); -// return null; -// } -// } else - if (eclipseFile == null || !eclipseFile.exists()) { - // Otherwise open the stream directly - if (page == null) { - PHPeclipsePlugin.log(IStatus.INFO, "Could not find file \"" + element + "\"."); - return null; - } - FileStorage storage = new FileStorage(path); - storage.setReadOnly(); - // IEditorRegistry registry = workbench.getEditorRegistry(); - // IEditorDescriptor desc = registry.getDefaultEditor(filename); - // if (desc == null) { - // desc = registry.getDefaultEditor(); - // } - return new ExternalEditorInput(storage); - } - return new FileEditorInput(eclipseFile); - - } - -} diff --git a/net.sourceforge.phpeclipse.launching/plugin.xml b/net.sourceforge.phpeclipse.launching/plugin.xml index ca346bd..4836ae5 100644 --- a/net.sourceforge.phpeclipse.launching/plugin.xml +++ b/net.sourceforge.phpeclipse.launching/plugin.xml @@ -23,6 +23,7 @@ + @@ -49,6 +50,14 @@ default="true" extension="php5"> + + + + diff --git a/net.sourceforge.phpeclipse.launching/src/net/sourceforge/phpdt/internal/launching/PHPLaunchConfigurationDelegate.java b/net.sourceforge.phpeclipse.launching/src/net/sourceforge/phpdt/internal/launching/PHPLaunchConfigurationDelegate.java index 434dd50..6324404 100644 --- a/net.sourceforge.phpeclipse.launching/src/net/sourceforge/phpdt/internal/launching/PHPLaunchConfigurationDelegate.java +++ b/net.sourceforge.phpeclipse.launching/src/net/sourceforge/phpdt/internal/launching/PHPLaunchConfigurationDelegate.java @@ -1,19 +1,16 @@ /********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. and others. -All rights reserved. This program and the accompanying materials -are made available under the terms of the Common Public License v1.0 -which accompanies this distribution, and is available at -http://www.eclipse.org/legal/cpl-v10.html - -Contributors: - IBM Corporation - Initial implementation - Vicente Fernando - www.alfersoft.com.ar -**********************************************************************/ + Copyright (c) 2000, 2002 IBM Corp. and others. + All rights reserved. This program and the accompanying materials + are made available under the terms of the Common Public License v1.0 + which accompanies this distribution, and is available at + http://www.eclipse.org/legal/cpl-v10.html + + Contributors: + IBM Corporation - Initial implementation + Vicente Fernando - www.alfersoft.com.ar + **********************************************************************/ package net.sourceforge.phpdt.internal.launching; -//import java.io.OutputStream; - - import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; @@ -21,28 +18,45 @@ import org.eclipse.core.runtime.Status; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchManager; +import org.eclipse.debug.core.Launch; import org.eclipse.debug.core.model.ILaunchConfigurationDelegate; import org.eclipse.debug.core.model.LaunchConfigurationDelegate; -//import org.eclipse.debug.core.model.ILaunchConfigurationDelegate; - public class PHPLaunchConfigurationDelegate extends LaunchConfigurationDelegate { - protected static final InterpreterRunner interpreterRunner = new InterpreterRunner(); - protected static final DebuggerRunner debuggerRunner = new DebuggerRunner(); + + protected static final InterpreterRunner interpreterRunner; + protected static final DebuggerRunner debuggerRunner; + + static { + interpreterRunner = new InterpreterRunner(); + debuggerRunner = new DebuggerRunner(); + } -/* public PHPLaunchConfigurationDelegate() { - super(); + /** (non-Javadoc) + * @see org.eclipse.debug.core.model.ILaunchConfigurationDelegate2#getLaunch(org.eclipse.debug.core.ILaunchConfiguration, java.lang.String) + */ + public ILaunch getLaunch(ILaunchConfiguration configuration, String mode) + throws CoreException { + return new Launch(configuration, mode, new PHPSourceLocator()); } -*/ + /** * @see ILaunchConfigurationDelegate#launch(ILaunchConfiguration, String, ILaunch, IProgressMonitor) */ - public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException { - if (PHPRuntime.getDefault().getSelectedInterpreter() == null) - throw new CoreException(new Status(IStatus.ERROR, PHPLaunchingPlugin.PLUGIN_ID, IStatus.OK, "You must define an interpreter before running PHP.", null)); + public void + launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException { + if (PHPRuntime.getDefault().getSelectedInterpreter() == null) { + String pid = PHPLaunchingPlugin.PLUGIN_ID; + String msg = "You must define an interpreter before running PHP."; + IStatus s = new Status(IStatus.ERROR, pid, IStatus.OK, msg, null); + throw new CoreException(s); + } - InterpreterRunnerConfiguration conf=new InterpreterRunnerConfiguration(configuration); - conf.setEnvironment(DebugPlugin.getDefault().getLaunchManager().getEnvironment(configuration)); + InterpreterRunnerConfiguration conf = new + InterpreterRunnerConfiguration(configuration); + ILaunchManager m = DebugPlugin.getDefault().getLaunchManager(); + conf.setEnvironment(m.getEnvironment(configuration)); if (mode.equals("debug")) { debuggerRunner.run(conf, launch); } else { diff --git a/net.sourceforge.phpeclipse.launching/src/net/sourceforge/phpdt/internal/launching/PHPSourceLocator.java b/net.sourceforge.phpeclipse.launching/src/net/sourceforge/phpdt/internal/launching/PHPSourceLocator.java new file mode 100644 index 0000000..7fb4da2 --- /dev/null +++ b/net.sourceforge.phpeclipse.launching/src/net/sourceforge/phpdt/internal/launching/PHPSourceLocator.java @@ -0,0 +1,162 @@ +package net.sourceforge.phpdt.internal.launching; + +import java.util.Iterator; +import java.util.Map; + +import net.sourceforge.phpdt.internal.debug.core.model.PHPStackFrame; +import net.sourceforge.phpeclipse.PHPeclipsePlugin; +import net.sourceforge.phpeclipse.builder.ExternalEditorInput; +import net.sourceforge.phpeclipse.builder.FileStorage; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.model.IPersistableSourceLocator; +import org.eclipse.debug.core.model.IStackFrame; +import org.eclipse.debug.ui.ISourcePresentation; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.part.FileEditorInput; + +public class PHPSourceLocator implements IPersistableSourceLocator, ISourcePresentation { + private String absoluteWorkingDirectory; + private Map pathMap = null; + private boolean remoteDebug; + private IPath remoteSourcePath; + private String projectName; + + public PHPSourceLocator() { + + } + + public String getAbsoluteWorkingDirectory() { + return absoluteWorkingDirectory; + } + /** + * @see org.eclipse.debug.core.model.IPersistableSourceLocator#getMemento() + */ + public String getMemento() throws CoreException { + return null; + } + + /** + * @see org.eclipse.debug.core.model.IPersistableSourceLocator#initializeFromMemento(String) + */ + public void initializeFromMemento(String memento) throws CoreException { + } + + /** + * @see org.eclipse.debug.core.model.IPersistableSourceLocator#initializeDefaults(ILaunchConfiguration) + */ + public void initializeDefaults(ILaunchConfiguration configuration) throws CoreException { + this.absoluteWorkingDirectory = configuration.getAttribute(PHPLaunchConfigurationAttribute.WORKING_DIRECTORY, ""); + this.remoteDebug=configuration.getAttribute(PHPLaunchConfigurationAttribute.REMOTE_DEBUG,false); + this.pathMap = configuration.getAttribute(PHPLaunchConfigurationAttribute.FILE_MAP, (Map)null); + this.projectName =configuration.getAttribute(PHPLaunchConfigurationAttribute.PROJECT_NAME, ""); + + if (Platform.getOS().equals(Platform.OS_WIN32)) + this.remoteSourcePath= new Path((configuration.getAttribute(PHPLaunchConfigurationAttribute.REMOTE_PATH, "")).toLowerCase()); + else + this.remoteSourcePath= new Path(configuration.getAttribute(PHPLaunchConfigurationAttribute.REMOTE_PATH, "")); + +// system.os.name + + } + + /** + * @see org.eclipse.debug.core.model.ISourceLocator#getSourceElement(IStackFrame) + */ + public Object getSourceElement(IStackFrame stackFrame) { + + String fileName=((PHPStackFrame) stackFrame).getFileName(); + String file=""; + + if (remoteDebug) + { + IPath path = new Path(fileName); + if (remoteSourcePath.isPrefixOf(path)) + { + IPath projectPath; + path=path.removeFirstSegments(remoteSourcePath.matchingFirstSegments(path)); + file=path.toString(); + projectPath=(PHPeclipsePlugin.getWorkspace().getRoot().getProject(projectName).getLocation()); + return (projectPath.append(path)).toOSString(); + } + + if (pathMap == null) { + return fileName; + } + Iterator iterator = pathMap.keySet().iterator(); + while (iterator.hasNext()) { + String local = (String) iterator.next(); + IPath remotePath = new Path((String) pathMap.get(local)); + if (remotePath.isPrefixOf(path)) { + path=path.removeFirstSegments(remotePath.matchingFirstSegments(path)); + IPath localPath= new Path(local); + return localPath.append(path).toOSString(); + } + } + return fileName; + } else { + return fileName; + } + } + + /** + * @see org.eclipse.debug.ui.ISourcePresentation#getEditorId(IEditorInput, Object) + */ + public String getEditorId(IEditorInput input, Object element) { + return PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor((String) element).getId(); + } + + /** + * @see org.eclipse.debug.ui.ISourcePresentation#getEditorInput(Object) + */ + public IEditorInput getEditorInput(Object element) { + + String filename = (String) element; + IWorkbench workbench = PlatformUI.getWorkbench(); + IWorkbenchWindow window = workbench.getWorkbenchWindows()[0]; + IWorkbenchPage page = window.getActivePage(); + IPath path = new Path(filename); + + + + // If the file exists in the workspace, open it + IFile eclipseFile = PHPeclipsePlugin.getWorkspace().getRoot().getFileForLocation(path); + // IFile eclipseFile = PHPeclipsePlugin.getWorkspace().getRoot().getFileForLocation(new Path(filename)); +// if (eclipseFile == null) { +// filename = this.getAbsoluteWorkingDirectory() + "/" + filename; +// eclipseFile = PHPeclipsePlugin.getWorkspace().getRoot().getFileForLocation(new Path(filename)); +// if (eclipseFile == null) { +// PHPeclipsePlugin.log(IStatus.INFO, "Could not find file \"" + element + "\"."); +// return null; +// } +// } else + if (eclipseFile == null || !eclipseFile.exists()) { + // Otherwise open the stream directly + if (page == null) { + PHPeclipsePlugin.log(IStatus.INFO, "Could not find file \"" + element + "\"."); + return null; + } + FileStorage storage = new FileStorage(path); + storage.setReadOnly(); + // IEditorRegistry registry = workbench.getEditorRegistry(); + // IEditorDescriptor desc = registry.getDefaultEditor(filename); + // if (desc == null) { + // desc = registry.getDefaultEditor(); + // } + return new ExternalEditorInput(storage); + } + return new FileEditorInput(eclipseFile); + + } + +} -- 1.7.1