1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Fix for bug 43372: changed the source lookup procedures to avoid the usage of 'getCanonicalPath'.

This commit is contained in:
Mikhail Khodjaiants 2003-10-14 02:10:34 +00:00
parent 66b1d31a66
commit 952fdd89d6
3 changed files with 148 additions and 97 deletions

View file

@ -1,3 +1,8 @@
2003-10-13 Mikhail Khodjaiants
Fix for bug 43372: changed the source lookup procedures to avoid the usage of 'getCanonicalPath'.
* CDirectorySourceLocation.java
* CProjectSourceLocation.java
2003-10-07 Mikhail Khodjaiants
All methods of 'IRuntimeOptions' should throw CDI exceptions in case of failure.
* ICDIRuntimeOptions.java

View file

@ -160,23 +160,14 @@ public class CDirectorySourceLocation implements IDirectorySourceLocation
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 filePath = new Path( name );
IPath path = getDirectory();
IPath association = getAssociation();
if ( path.isPrefixOf( filePath ) )
if ( isPrefix( path, filePath ) )
{
filePath = path.append( filePath.removeFirstSegments( path.segmentCount() ) );
}
else if ( association != null && association.isPrefixOf( filePath ) )
else if ( association != null && isPrefix( association, filePath ) )
{
filePath = path.append( filePath.removeFirstSegments( association.segmentCount() ) );
}
@ -184,6 +175,7 @@ public class CDirectorySourceLocation implements IDirectorySourceLocation
{
return null;
}
// Try for a file in another workspace project
IFile f = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation( filePath );
if ( f != null && f.exists() )
@ -208,19 +200,13 @@ public class CDirectorySourceLocation implements IDirectorySourceLocation
File file = path.toFile();
if ( file.exists() )
{
try
{
path = new Path( file.getCanonicalPath() );
IFile f = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation( path );
if ( f != null )
{
return f;
}
return createExternalFileStorage( path );
}
catch( IOException e )
path = new Path( file.getAbsolutePath() ); // can't use getCanonicalPath because of links
IFile f = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation( path );
if ( f != null && f.exists() )
{
return f;
}
return createExternalFileStorage( path );
}
}
return null;
@ -359,4 +345,14 @@ public class CDirectorySourceLocation implements IDirectorySourceLocation
}
return false;
}
private boolean isPrefix( IPath prefix, IPath path )
{
int segCount = prefix.segmentCount();
if ( segCount >= path.segmentCount() )
return false;
String prefixString = prefix.toOSString();
String pathString = path.removeLastSegments( path.segmentCount() - segCount ).toOSString();
return prefixString.equalsIgnoreCase( pathString );
}
}

View file

@ -11,6 +11,8 @@ import java.io.StringReader;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@ -21,11 +23,10 @@ import org.eclipse.cdt.debug.core.CDebugCorePlugin;
import org.eclipse.cdt.debug.core.CDebugUtils;
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation;
import org.eclipse.cdt.debug.core.sourcelookup.IProjectSourceLocation;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceProxy;
import org.eclipse.core.resources.IResourceProxyVisitor;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
@ -53,6 +54,8 @@ public class CProjectSourceLocation implements IProjectSourceLocation
*/
private IProject fProject;
private IResource[] fFolders;
private HashMap fCache = new HashMap( 20 );
private HashSet fNotFoundCache = new HashSet( 20 );
@ -73,6 +76,7 @@ public class CProjectSourceLocation implements IProjectSourceLocation
{
setProject( project );
fGenerated = true;
initializeFolders();
}
/**
@ -82,6 +86,7 @@ public class CProjectSourceLocation implements IProjectSourceLocation
{
setProject( project );
fGenerated = generated;
initializeFolders();
}
/* (non-Javadoc)
@ -147,84 +152,83 @@ public class CProjectSourceLocation implements IProjectSourceLocation
{
File file = new File( name );
return ( file.isAbsolute() ) ? findFileByAbsolutePath( name ) :
findFileByRelativePath( getProject(), name );
findFileByRelativePath( name );
}
private Object findFileByAbsolutePath( String name )
{
File file = new File( name );
Object result = null;
try
{
if ( file.isAbsolute() )
result = findFile( getProject(), file.getCanonicalPath() );
}
catch( IOException e )
{
}
if ( file.isAbsolute() && file.exists() )
result = findFile( file );
return result;
}
private Object findFileByRelativePath( IContainer container, String fileName )
private Object findFileByRelativePath( String fileName )
{
IPath rootPath = container.getLocation();
if ( rootPath == null )
return null;
IPath path = rootPath.append( fileName );
Object result = findFileByAbsolutePath( path.toOSString() );
if ( result == null )
IResource[] folders = getFolders();
LinkedList list = new LinkedList();
for ( int i = 0; i < folders.length; ++i )
{
try
{
IResource[] members = container.members();
for ( int i = 0; i < members.length; ++i )
{
if ( members[i] instanceof IFolder )
{
path = members[i].getLocation().append( fileName );
result = findFileByAbsolutePath( path.toOSString() );
if ( result == null )
{
result = findFileByRelativePath( (IFolder)members[i], fileName );
}
if ( result != null )
break;
}
}
}
catch( CoreException e )
{
// do nothing
}
if ( list.size() > 0 && !searchForDuplicateFileNames() )
break;
IPath path = folders[i].getLocation().append( fileName );
Object result = findFile( new File( path.toOSString() ) );
if ( result instanceof List )
list.addAll( (List)result );
else if ( result != null )
list.add( result );
}
return result;
if ( list.size() == 1 || (list.size() > 0 && !searchForDuplicateFileNames()) )
return list.getFirst();
if ( list.size() > 0 )
return list;
return null;
}
private Object findFile( IContainer container, String fileName )
private Object findFile( final File file )
{
try
if ( file != null )
{
IResource[] members = container.members();
for ( int i = 0; i < members.length; ++i )
final String name = file.getName();
IResource[] folders = getFolders();
final LinkedList list = new LinkedList();
for ( int i = 0; i < folders.length; ++i )
{
if ( members[i] instanceof IFile )
// The workspace resources are case-sensitive, so we can not just
// append the file name to the folder name and check if the result exists.
if ( list.size() > 0 && !searchForDuplicateFileNames() )
break;
try
{
if ( members[i].getLocation().toOSString().equals( fileName ) )
return members[i];
folders[i].accept(
new IResourceProxyVisitor()
{
public boolean visit( IResourceProxy proxy ) throws CoreException
{
// use equalsIgnoreCase to make it work for Wondows
if ( proxy.getType() == IResource.FILE && proxy.getName().equalsIgnoreCase( name ) )
{
IResource resource = proxy.requestResource();
File file1 = new File( resource.getLocation().toOSString() );
if ( file1.exists() && file1.equals( file ) )
list.addLast( resource );
return false;
}
return true;
}
},
IResource.NONE );
}
else if ( members[i] instanceof IFolder && fileName.startsWith( members[i].getLocation().toOSString() ) )
catch( CoreException e )
{
Object result = findFile( (IContainer)members[i], fileName );
if ( result != null )
return result;
}
}
if ( list.size() == 1 || (list.size() > 0 && !searchForDuplicateFileNames()) )
return list.getFirst();
if ( list.size() > 0 )
return list;
}
catch( CoreException e )
{
// do nothing
}
return null;
}
@ -304,6 +308,7 @@ public class CProjectSourceLocation implements IProjectSourceLocation
if ( isGeneric == null || isGeneric.trim().length() == 0 )
isGeneric = Boolean.FALSE.toString();
setGenerated( isGeneric.equals( Boolean.TRUE.toString() ) );
initializeFolders();
return;
}
catch( ParserConfigurationException e )
@ -357,8 +362,53 @@ public class CProjectSourceLocation implements IProjectSourceLocation
*/
public boolean equals( Object obj )
{
if ( obj instanceof IProjectSourceLocation )
return getProject().getName().equals( ((IProjectSourceLocation)obj).getProject().getName() );
if ( obj instanceof IProjectSourceLocation && getProject() != null )
return getProject().equals( ((IProjectSourceLocation)obj).getProject() );
return false;
}
private void initializeFolders()
{
final LinkedList list = new LinkedList();
if ( getProject() != null )
{
list.add( getProject() );
try
{
getProject().accept(
new IResourceProxyVisitor()
{
public boolean visit( IResourceProxy proxy ) throws CoreException
{
switch( proxy.getType() )
{
case IResource.FILE:
return false;
case IResource.FOLDER:
list.addLast( proxy.requestResource() );
return true;
}
return true;
}
},
IResource.NONE );
}
catch( CoreException e )
{
}
}
fFolders = (IResource[])list.toArray( new IResource[list.size()] );
}
protected IResource[] getFolders()
{
return fFolders;
}
protected boolean searchForDuplicateFileNames()
{
// for now
return false;
}
}