From 93129aabdcb21d71316a39cb3ff346886118802d Mon Sep 17 00:00:00 2001 From: Mikhail Khodjaiants Date: Tue, 16 Sep 2003 18:40:02 +0000 Subject: [PATCH] Fix for PR 38468: Error in files location. Use the 'getCanonicalPath' method of the 'File' class to obtain the file name. --- debug/org.eclipse.cdt.debug.core/ChangeLog | 7 ++++ .../CDirectorySourceLocation.java | 33 +++++++++++++++---- .../sourcelookup/CProjectSourceLocation.java | 14 ++++++-- .../core/sourcelookup/CSourceLocator.java | 24 +++++++++----- 4 files changed, 60 insertions(+), 18 deletions(-) diff --git a/debug/org.eclipse.cdt.debug.core/ChangeLog b/debug/org.eclipse.cdt.debug.core/ChangeLog index 6193bec5975..2017c056eb4 100644 --- a/debug/org.eclipse.cdt.debug.core/ChangeLog +++ b/debug/org.eclipse.cdt.debug.core/ChangeLog @@ -1,3 +1,10 @@ +2003-16-10 Mikhail Khodjaiants + Fix for PR 38468: Error in files location. + Use the 'getCanonicalPath' method of the 'File' class to obtain the file name. + * CDirectorySourceLocation.java + * CProjectSourceLocation.java + * CSourceLocator.java + 2003-15-10 Mikhail Khodjaiants Fix for PR 43101: Breakpoint exception when source doesn't exist. The 'fireBreakpointChanged' method of 'BreakpointManager' is used to notify diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CDirectorySourceLocation.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CDirectorySourceLocation.java index 306852367b4..99108e17a71 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CDirectorySourceLocation.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CDirectorySourceLocation.java @@ -145,8 +145,20 @@ public class CDirectorySourceLocation implements IDirectorySourceLocation return fAssociation; } - private Object findFileByAbsolutePath( String fileName ) + private Object findFileByAbsolutePath( String name ) { + File file = new File( name ); + if ( !file.isAbsolute() ) + return null; + String fileName; + try + { + fileName = file.getCanonicalPath(); + } + catch( IOException e ) + { + return null; + } IPath filePath = new Path( fileName ); IPath path = getDirectory(); IPath association = getAssociation(); @@ -169,7 +181,7 @@ public class CDirectorySourceLocation implements IDirectorySourceLocation return f; } - File file = filePath.toFile(); + file = filePath.toFile(); if ( file.exists() ) { return createExternalFileStorage( filePath ); @@ -186,12 +198,19 @@ public class CDirectorySourceLocation implements IDirectorySourceLocation File file = path.toFile(); if ( file.exists() ) { - IFile f = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation( path ); - if ( f != null ) + try { - return f; - } - return createExternalFileStorage( path ); + path = new Path( file.getCanonicalPath() ); + IFile f = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation( path ); + if ( f != null ) + { + return f; + } + return createExternalFileStorage( path ); + } + catch( IOException e ) + { + } } } return null; diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CProjectSourceLocation.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CProjectSourceLocation.java index ea7c8ce3003..c731a387c56 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CProjectSourceLocation.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CProjectSourceLocation.java @@ -30,7 +30,6 @@ import org.eclipse.core.resources.ResourcesPlugin; 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.Status; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -153,8 +152,17 @@ public class CProjectSourceLocation implements IProjectSourceLocation private Object findFileByAbsolutePath( String name ) { - IPath path = new Path( name ); - return findFile( getProject(), path.toOSString() ); + File file = new File( name ); + Object result = null; + try + { + if ( file.isAbsolute() ) + result = findFile( getProject(), file.getCanonicalPath() ); + } + catch( IOException e ) + { + } + return result; } private Object findFileByRelativePath( IContainer container, String fileName ) diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLocator.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLocator.java index 7d30ea04991..7f9e30dde75 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLocator.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLocator.java @@ -6,6 +6,7 @@ package org.eclipse.cdt.debug.internal.core.sourcelookup; +import java.io.File; import java.io.IOException; import java.io.StringReader; import java.text.MessageFormat; @@ -249,16 +250,23 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato private Object findFileByAbsolutePath( String fileName ) { - Path path = new Path( fileName ); - if ( path.isAbsolute() && path.toFile().exists() ) + File file = new File( fileName ); + if ( file.isAbsolute() && file.exists() ) { - // Try for a file in another workspace project - IFile f = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation( path ); - if ( f != null && f.exists() ) + try { - return f; - } - return new FileStorage( path ); + Path path = new Path( file.getCanonicalPath() ); + // Try for a file in another workspace project + IFile f = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation( path ); + if ( f != null && f.exists() ) + { + return f; + } + return new FileStorage( path ); + } + catch( IOException e ) + { + } } return null; }