From 116e30c836b05df67d3bd515a5228ac6b36be30d Mon Sep 17 00:00:00 2001 From: robekras Date: Tue, 8 Nov 2005 19:02:40 +0000 Subject: [PATCH] 1) Interpret the local to remote path mappings as project relative path to server absolute path if Remote Sourcepath is empty. --- .../phpdt/internal/debug/core/PHPDBGProxy.java | 49 +++++- .../phpdt/internal/launching/PHPSourceLocator.java | 181 +++++++++++++------- 2 files changed, 160 insertions(+), 70 deletions(-) diff --git a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/PHPDBGProxy.java b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/PHPDBGProxy.java index 595d64d..e93a7f1 100644 --- a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/PHPDBGProxy.java +++ b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/PHPDBGProxy.java @@ -208,7 +208,11 @@ public class PHPDBGProxy { * */ private String MapPath (PHPLineBreakpoint phpLBP) { - IPath filename; + IPath filename; + IPath remotePath; + IPath newpath; + IPath localPath; + String local; if (remote) { filename = phpLBP.getMarker().getResource().getProjectRelativePath(); @@ -231,14 +235,43 @@ public class PHPDBGProxy { } } - if (pathtranslation && remote) { - if (remoteSourcePath.toString ().substring (0, 1).equals ("/")) { - path = path.replace ('/', '\\'); - } - else { - path = path.replace ('\\', '/'); + if (remoteSourcePath.isEmpty ()) { + if ((pathmap != null) && remote) { + java.util.Iterator iterator = pathmap.keySet().iterator(); + + while (iterator.hasNext ()) { + local = (String) iterator.next (); // Get the local/client side path of the mapping + remotePath = new Path ((String) pathmap.get (local)); // Get the remote/server side path of the mapping + localPath = new Path (local); // Get the remote/server side path of the mapping + + if (localPath.isPrefixOf (filename)) { // Starts the remote/server side file path with the remote/server side mapping path + // dann prefix abhängen und den remote path davorhägen + newpath = filename.removeFirstSegments (localPath.matchingFirstSegments (filename)); + newpath = remotePath.append (newpath); + path = newpath.toString (); + + if (path.substring (0, 1).equals ("/")) { + path = path.replace ('\\', '/'); + } + else { + path = path.replace ('/', '\\'); + } + + return path; + } + } } - } + } + else { + if (pathtranslation && remote) { + if (remoteSourcePath.toString ().substring (0, 1).equals ("/")) { + path = path.replace ('\\', '/'); + } + else { + path = path.replace ('/', '\\'); + } + } + } return path; } 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 index 7fb4da2..652a6c7 100644 --- 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 @@ -26,11 +26,11 @@ 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; + private String absoluteWorkingDirectory; + private Map pathMap = null; + private boolean remoteDebug; + private IPath remoteSourcePath; + private String projectName; public PHPSourceLocator() { @@ -39,6 +39,7 @@ public class PHPSourceLocator implements IPersistableSourceLocator, ISourcePrese public String getAbsoluteWorkingDirectory() { return absoluteWorkingDirectory; } + /** * @see org.eclipse.debug.core.model.IPersistableSourceLocator#getMemento() */ @@ -55,57 +56,103 @@ public class PHPSourceLocator implements IPersistableSourceLocator, ISourcePrese /** * @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 + 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) + * + * Return the client side source filename for the server side source file. + * E.g. when cross debugging, the server side filename could be /var/www/index.php + * on the client side it is either a Eclipse_PHP_projectname\index.php (when it is a linked file) + * + * + * @param stackFrame The stackframe for which we want the client side source file name + * @return The filename as it appears on the client side */ - 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(); + public Object getSourceElement (IStackFrame stackFrame) { + IPath projectPath; + IPath remotePath; + IPath path; + IPath localPath; + Iterator iterator; + String fileName; + String file; + String local; + + fileName = ((PHPStackFrame) stackFrame).getFileName (); // Get the filename as it is submitted by DBG + file = ""; + + if (remoteDebug) { // Is it a remote debugging session + path = new Path (fileName); // Create a IPath object for the server side filename + + if (!remoteSourcePath.isEmpty()) { + if (remoteSourcePath.isPrefixOf (path)) { // Is the server side filename with the remote source path + path = path.removeFirstSegments (remoteSourcePath.matchingFirstSegments (path)); // Remove the remote source path + file = path.toString (); // The filename without the remote source path + projectPath = (PHPeclipsePlugin.getWorkspace().getRoot().getProject(projectName).getLocation()); // Get the absolute project path + + return (projectPath.append (path)).toOSString (); // Return the filename as absolute client side path } - - if (pathMap == null) { - return fileName; + } + else { + if (pathMap == null) { // Do we have path mapping (e.g. for cross platform debugging) + return fileName; // No, then return the filename as it given by DBG (the full server side path) } - 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(); + + iterator = pathMap.keySet().iterator(); + + while (iterator.hasNext ()) { + local = (String) iterator.next (); // Get the local/client side path of the mapping + remotePath = new Path ((String) pathMap.get (local)); // Get the remote/server side path of the mapping + + if (remotePath.isPrefixOf (path)) { // Starts the remote/server side file path with the remote/server side mapping path + path = path.removeFirstSegments (remotePath.matchingFirstSegments (path)); // Remove the absolute path from filename + localPath = new Path (local); // Create new IPath object for the local/client side path + path = localPath.append (path); // Prepend the project relative path to filename + + projectPath = (PHPeclipsePlugin.getWorkspace().getRoot().getProject(projectName).getLocation()); // Get the absolute project path + + return (projectPath.append (path)).toOSString (); // Return the filename as absolute client side path } } - return fileName; - } else { - return fileName; + } + + if (pathMap == null) { // Do we have path mapping (e.g. for cross platform debugging) + return fileName; // No, then return the filename as it given by DBG (the full server side path) + } + + iterator = pathMap.keySet().iterator(); + + while (iterator.hasNext ()) { + local = (String) iterator.next (); // Get the local/client side path of the mapping + remotePath = new Path ((String) pathMap.get (local)); // Get the remote/server side path of the mapping + + if (remotePath.isPrefixOf (path)) { // Starts the remote/server side file path with the remote/server side mapping path + path = path.removeFirstSegments (remotePath.matchingFirstSegments (path)); // Remove the absolute path from filename + localPath = new Path (local); // Create new IPath object for the local/client side path + + return localPath.append (path).toOSString (); // Append the remote filename to the client side path (So we return the absolute path + // to the source file as the client side sees it. + } + } + + return fileName; + } else { + return fileName; } } @@ -118,19 +165,26 @@ public class PHPSourceLocator implements IPersistableSourceLocator, ISourcePrese /** * @see org.eclipse.debug.ui.ISourcePresentation#getEditorInput(Object) + * + * @param element The absolute local/client side file path */ - 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); - - + public IEditorInput getEditorInput (Object element) { + String filename; + IWorkbench workbench; + IWorkbenchWindow window; + IWorkbenchPage page; + IPath path; + IFile eclipseFile; + + filename = (String) element; + workbench = PlatformUI.getWorkbench (); + window = workbench.getWorkbenchWindows ()[0]; + page = window.getActivePage (); + path = new Path (filename); // Create an IPath object of the absolute local/client side file name // If the file exists in the workspace, open it - IFile eclipseFile = PHPeclipsePlugin.getWorkspace().getRoot().getFileForLocation(path); + eclipseFile = PHPeclipsePlugin.getWorkspace().getRoot().getFileForLocation (path); + // IFile eclipseFile = PHPeclipsePlugin.getWorkspace().getRoot().getFileForLocation(new Path(filename)); // if (eclipseFile == null) { // filename = this.getAbsoluteWorkingDirectory() + "/" + filename; @@ -139,15 +193,19 @@ public class PHPSourceLocator implements IPersistableSourceLocator, ISourcePrese // PHPeclipsePlugin.log(IStatus.INFO, "Could not find file \"" + element + "\"."); // return null; // } -// } else - if (eclipseFile == null || !eclipseFile.exists()) { +// } 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(); + + FileStorage storage = new FileStorage (path); + storage.setReadOnly (); + // IEditorRegistry registry = workbench.getEditorRegistry(); // IEditorDescriptor desc = registry.getDefaultEditor(filename); // if (desc == null) { @@ -155,8 +213,7 @@ public class PHPSourceLocator implements IPersistableSourceLocator, ISourcePrese // } return new ExternalEditorInput(storage); } - return new FileEditorInput(eclipseFile); + return new FileEditorInput (eclipseFile); } - } -- 1.7.1