|
From: <caw...@us...> - 2007-07-11 15:24:20
|
Revision: 2744
http://svn.sourceforge.net/rubyeclipse/?rev=2744&view=rev
Author: cawilliams
Date: 2007-07-11 08:24:15 -0700 (Wed, 11 Jul 2007)
Log Message:
-----------
fix #5158 - Debugger doesn't open file of breakpoint reached
Modified Paths:
--------------
trunk/org.rubypeople.rdt.debug.ui/src/org/rubypeople/rdt/internal/debug/ui/RubySourceLocator.java
trunk/org.rubypeople.rdt.debug.ui.tests/src/org/rubypeople/rdt/internal/debug/ui/TC_RubySourceLocator.java
Modified: trunk/org.rubypeople.rdt.debug.ui/src/org/rubypeople/rdt/internal/debug/ui/RubySourceLocator.java
===================================================================
--- trunk/org.rubypeople.rdt.debug.ui/src/org/rubypeople/rdt/internal/debug/ui/RubySourceLocator.java 2007-07-10 21:27:04 UTC (rev 2743)
+++ trunk/org.rubypeople.rdt.debug.ui/src/org/rubypeople/rdt/internal/debug/ui/RubySourceLocator.java 2007-07-11 15:24:15 UTC (rev 2744)
@@ -25,9 +25,10 @@
* Window>Preferences>Java>Templates. To enable and disable the creation of
* type comments go to Window>Preferences>Java>Code Generation.
*/
-public class RubySourceLocator implements IPersistableSourceLocator, ISourcePresentation { // ISourcePresentation
- // {
+public class RubySourceLocator implements IPersistableSourceLocator, ISourcePresentation {
+
private String absoluteWorkingDirectory;
+ private String projectName;
public RubySourceLocator() {
@@ -54,6 +55,7 @@
*/
public void initializeDefaults(ILaunchConfiguration configuration) throws CoreException {
this.absoluteWorkingDirectory = configuration.getAttribute(IRubyLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, ""); //$NON-NLS-1$
+ this.projectName = configuration.getAttribute(IRubyLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); //$NON-NLS-1$
}
/**
@@ -104,6 +106,9 @@
private IFile workspaceFile;
public SourceElement(String aFilename, RubySourceLocator pSourceLocator) {
filename = aFilename;
+ if (filename.startsWith("./")) {
+ filename = "/" + pSourceLocator.projectName + filename.substring(1);
+ }
workspaceFile = RdtDebugCorePlugin.getWorkspace().getRoot().getFileForLocation(new Path(filename));
if (workspaceFile == null) {
try {
Modified: trunk/org.rubypeople.rdt.debug.ui.tests/src/org/rubypeople/rdt/internal/debug/ui/TC_RubySourceLocator.java
===================================================================
--- trunk/org.rubypeople.rdt.debug.ui.tests/src/org/rubypeople/rdt/internal/debug/ui/TC_RubySourceLocator.java 2007-07-10 21:27:04 UTC (rev 2743)
+++ trunk/org.rubypeople.rdt.debug.ui.tests/src/org/rubypeople/rdt/internal/debug/ui/TC_RubySourceLocator.java 2007-07-11 15:24:15 UTC (rev 2744)
@@ -10,7 +10,9 @@
import org.eclipse.core.internal.resources.Project;
import org.eclipse.core.internal.resources.Workspace;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -20,7 +22,9 @@
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.actions.CreateFileAction;
import org.rubypeople.rdt.internal.debug.core.model.RubyStackFrame;
import org.rubypeople.rdt.internal.debug.ui.RdtDebugUiPlugin;
import org.rubypeople.rdt.internal.debug.ui.RubySourceLocator;
@@ -35,90 +39,110 @@
}
public void testWorkspaceInternalFile() throws Exception {
-
- Workspace workspace = (Workspace) RdtDebugUiPlugin.getWorkspace() ;
- // Create a project called 'SourceLocatorTest'
- Project p = new TestProject("/SourceLocatorTest", workspace) ; //$NON-NLS-1$
+ createProject("SourceLocatorTest") ; //$NON-NLS-1$
+ createEmptyFile("/SourceLocatorTest/test.rb"); //$NON-NLS-1$
- p.create(null) ;
- p.open(null) ;
- IPath filePath = new Path("/SourceLocatorTest/test.rb") ; //$NON-NLS-1$
- IFile file =RdtDebugUiPlugin.getWorkspace().getRoot().getFile(filePath) ;
- file.create(new ByteArrayInputStream(new byte[0]) ,true, null) ;
-
// using slashes for the workspace internal path is platform independent
- String fullPath = workspace.getRoot().getLocation().toOSString() + File.separator + "SourceLocatorTest/test.rb" ; //$NON-NLS-1$
+ String fullPath = getWorkspaceRoot().getLocation().toOSString() + File.separator + "SourceLocatorTest/test.rb"; //$NON-NLS-1$
- RubySourceLocator sourceLocator = new RubySourceLocator() ;
- RubyStackFrame rubyStackFrame = new RubyStackFrame(null,fullPath, 5, 1) ;
- Object sourceElement = sourceLocator.getSourceElement(rubyStackFrame) ;
- IEditorInput input = sourceLocator.getEditorInput(sourceElement) ;
- assertNotNull(input) ;
- assertTrue(input.exists()) ;
- PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, sourceLocator.getEditorId(input, sourceElement)) ;
-
+ RubyStackFrame rubyStackFrame = new RubyStackFrame(null,fullPath, 5, 1);
+ assertCanOpen(rubyStackFrame);
}
- public void testWorkspaceExternalFile() throws Exception {
-
+ public void testWorkspaceExternalFile() throws Exception {
// external File
File tmpFile = File.createTempFile("rubyfile", null) ; //$NON-NLS-1$
RubyStackFrame rubyStackFrame = new RubyStackFrame(null,tmpFile.getAbsolutePath(), 5, 1) ;
- RubySourceLocator sourceLocator = new RubySourceLocator() ;
- Object sourceElement = sourceLocator.getSourceElement(rubyStackFrame) ;
- IEditorInput input = sourceLocator.getEditorInput(sourceElement) ;
- assertNotNull(input) ;
- assertTrue(input.exists()) ;
+ assertCanOpen(rubyStackFrame);
- PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, sourceLocator.getEditorId(input, sourceElement)) ;
-
- // set Working Directory to a project location
- Workspace workspace = (Workspace) RdtDebugUiPlugin.getWorkspace() ;
- Project p = new TestProject("/WorkingDirIsProject", workspace) ; //$NON-NLS-1$
- p.create(null) ;
- p.open(null) ;
- sourceLocator.initializeDefaults(new LaunchConfiguration(workspace.getRoot().getLocation().toOSString() + File.separator + "WorkingDirIsProject")) ;
+ // set Working Directory to a project location
+ createProject("WorkingDirIsProject"); //$NON-NLS-1$
+ RubySourceLocator sourceLocator = new RubySourceLocator();
+ sourceLocator.initializeDefaults(new LaunchConfiguration(getWorkspaceRoot().getLocation().toOSString() + File.separator + "WorkingDirIsProject"));
+ assertCanOpen(sourceLocator, rubyStackFrame);
- sourceElement = sourceLocator.getSourceElement(rubyStackFrame) ;
- input = sourceLocator.getEditorInput(sourceElement) ;
- assertNotNull(input) ;
- assertTrue(input.exists()) ;
-
- PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, sourceLocator.getEditorId(input, sourceElement)) ;
-
// An External file which is relative to the working directory
// If an external file is found within an include path, ruby seems always to deliver an
// absolte file path. But if the file found relative to the working directory, ruby
// shows a relative path
- String workspacePath = workspace.getRoot().getLocation().toOSString() ;
- File externalFile = new File(workspacePath + File.separator + "externalRelativeRubyFile.rb") ;
- assertTrue(externalFile.createNewFile()) ;
+ String workspacePath = getWorkspaceRoot().getLocation().toOSString();
+ File externalFile = new File(workspacePath + File.separator + "externalRelativeRubyFile.rb");
+ assertTrue(externalFile.createNewFile());
// current directory = working dir = workspacePath/WorkingDirIsProject
- rubyStackFrame = new RubyStackFrame(null,"../externalRelativeRubyFile.rb", 5, 1) ;
-
- sourceElement = sourceLocator.getSourceElement(rubyStackFrame) ;
- input = sourceLocator.getEditorInput(sourceElement) ;
- assertNotNull(input) ;
- assertTrue(input.exists()) ;
-
- PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, sourceLocator.getEditorId(input, sourceElement)) ;
-
-
-
+ rubyStackFrame = new RubyStackFrame(null,"../externalRelativeRubyFile.rb", 5, 1);
+ assertCanOpen(sourceLocator, rubyStackFrame);
}
public void testNotExistingFile() throws Exception {
- RubyStackFrame rubyStackFrame = new RubyStackFrame(null,"/tmp/nonexistingtestfile", 5, 1) ; //$NON-NLS-1$
+ RubyStackFrame rubyStackFrame = new RubyStackFrame(null,"/tmp/nonexistingtestfile", 5, 1); //$NON-NLS-1$
+ assertCantOpen(rubyStackFrame);
+ }
+
+ /**
+ * http://aptana.com/trac/ticket/5158
+ * @throws Exception
+ */
+ public void testTracTicket5158() throws Exception {
+ final String projectName = "BugTest"; //$NON-NLS-1$
+ createProject(projectName);
+ createFolder("/" + projectName + "/script"); //$NON-NLS-1$ //$NON-NLS-2$
+ createFolder("/" + projectName + "/config"); //$NON-NLS-1$ //$NON-NLS-2$
+ createFolder("/" + projectName + "/app"); //$NON-NLS-1$ //$NON-NLS-2$
+ createFolder("/" + projectName + "/app/models"); //$NON-NLS-1$ //$NON-NLS-2$
+ createEmptyFile("/" + projectName + "/app/models/arsupport.rb"); //$NON-NLS-1$ //$NON-NLS-2$
- RubySourceLocator sourceLocator = new RubySourceLocator() ;
- Object sourceElement = sourceLocator.getSourceElement(rubyStackFrame) ;
- IEditorInput input = sourceLocator.getEditorInput(sourceElement) ;
- assertNull(input) ;
+ // using slashes for the workspace internal path is platform independent
+ String fullPath = "./script/../config/../app/models/arsupport.rb"; //$NON-NLS-1$
+ RubyStackFrame rubyStackFrame = new RubyStackFrame(null,fullPath, 5, 1);
+ RubySourceLocator sourceLocator = new RubySourceLocator();
+ sourceLocator.initializeDefaults(new LaunchConfiguration(projectName));
+ assertCanOpen(sourceLocator, rubyStackFrame);
}
+ private void assertCanOpen(RubyStackFrame rubyStackFrame) throws PartInitException {
+ assertCanOpen(new RubySourceLocator(), rubyStackFrame);
+ }
+
+ private void assertCanOpen(RubySourceLocator sourceLocator, RubyStackFrame rubyStackFrame) throws PartInitException {
+ Object sourceElement = sourceLocator.getSourceElement(rubyStackFrame);
+ IEditorInput input = sourceLocator.getEditorInput(sourceElement);
+ assertNotNull(input);
+ assertTrue(input.exists());
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, sourceLocator.getEditorId(input, sourceElement));
+ }
+
+ private void assertCantOpen(RubyStackFrame rubyStackFrame) {
+ RubySourceLocator sourceLocator = new RubySourceLocator();
+ Object sourceElement = sourceLocator.getSourceElement(rubyStackFrame);
+ IEditorInput input = sourceLocator.getEditorInput(sourceElement);
+ assertNull(input);
+ }
+ private IFile createEmptyFile(String path) throws CoreException {
+ IFile file = getWorkspaceRoot().getFile(new Path(path));
+ file.create(new ByteArrayInputStream(new byte[0]), true, null);
+ return file;
+ }
+
+ private IWorkspaceRoot getWorkspaceRoot() {
+ return RdtDebugUiPlugin.getWorkspace().getRoot();
+ }
+
+ private Project createProject(String name) throws CoreException {
+ Workspace workspace = (Workspace) RdtDebugUiPlugin.getWorkspace();
+ Project p = new TestProject("/" + name, workspace); //$NON-NLS-1$
+ p.create(null);
+ p.open(null);
+ return p;
+ }
+
+ private IFolder createFolder(String path) throws CoreException {
+ IFolder folder = getWorkspaceRoot().getFolder(new Path(path));
+ folder.create(true, true, null);
+ return folder;
+ }
public class TestProject extends Project {
public TestProject(String aName, Workspace aWorkspace) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|