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:
parent
66b1d31a66
commit
952fdd89d6
3 changed files with 148 additions and 97 deletions
|
@ -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
|
2003-10-07 Mikhail Khodjaiants
|
||||||
All methods of 'IRuntimeOptions' should throw CDI exceptions in case of failure.
|
All methods of 'IRuntimeOptions' should throw CDI exceptions in case of failure.
|
||||||
* ICDIRuntimeOptions.java
|
* ICDIRuntimeOptions.java
|
||||||
|
|
|
@ -160,23 +160,14 @@ public class CDirectorySourceLocation implements IDirectorySourceLocation
|
||||||
File file = new File( name );
|
File file = new File( name );
|
||||||
if ( !file.isAbsolute() )
|
if ( !file.isAbsolute() )
|
||||||
return null;
|
return null;
|
||||||
String fileName;
|
IPath filePath = new Path( name );
|
||||||
try
|
|
||||||
{
|
|
||||||
fileName = file.getCanonicalPath();
|
|
||||||
}
|
|
||||||
catch( IOException e )
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
IPath filePath = new Path( fileName );
|
|
||||||
IPath path = getDirectory();
|
IPath path = getDirectory();
|
||||||
IPath association = getAssociation();
|
IPath association = getAssociation();
|
||||||
if ( path.isPrefixOf( filePath ) )
|
if ( isPrefix( path, filePath ) )
|
||||||
{
|
{
|
||||||
filePath = path.append( filePath.removeFirstSegments( path.segmentCount() ) );
|
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() ) );
|
filePath = path.append( filePath.removeFirstSegments( association.segmentCount() ) );
|
||||||
}
|
}
|
||||||
|
@ -184,6 +175,7 @@ public class CDirectorySourceLocation implements IDirectorySourceLocation
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try for a file in another workspace project
|
// Try for a file in another workspace project
|
||||||
IFile f = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation( filePath );
|
IFile f = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation( filePath );
|
||||||
if ( f != null && f.exists() )
|
if ( f != null && f.exists() )
|
||||||
|
@ -208,20 +200,14 @@ public class CDirectorySourceLocation implements IDirectorySourceLocation
|
||||||
File file = path.toFile();
|
File file = path.toFile();
|
||||||
if ( file.exists() )
|
if ( file.exists() )
|
||||||
{
|
{
|
||||||
try
|
path = new Path( file.getAbsolutePath() ); // can't use getCanonicalPath because of links
|
||||||
{
|
|
||||||
path = new Path( file.getCanonicalPath() );
|
|
||||||
IFile f = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation( path );
|
IFile f = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation( path );
|
||||||
if ( f != null )
|
if ( f != null && f.exists() )
|
||||||
{
|
{
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
return createExternalFileStorage( path );
|
return createExternalFileStorage( path );
|
||||||
}
|
}
|
||||||
catch( IOException e )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -359,4 +345,14 @@ public class CDirectorySourceLocation implements IDirectorySourceLocation
|
||||||
}
|
}
|
||||||
return false;
|
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 );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,8 @@ import java.io.StringReader;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
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.CDebugUtils;
|
||||||
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation;
|
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation;
|
||||||
import org.eclipse.cdt.debug.core.sourcelookup.IProjectSourceLocation;
|
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.IProject;
|
||||||
import org.eclipse.core.resources.IResource;
|
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.resources.ResourcesPlugin;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
|
@ -53,6 +54,8 @@ public class CProjectSourceLocation implements IProjectSourceLocation
|
||||||
*/
|
*/
|
||||||
private IProject fProject;
|
private IProject fProject;
|
||||||
|
|
||||||
|
private IResource[] fFolders;
|
||||||
|
|
||||||
private HashMap fCache = new HashMap( 20 );
|
private HashMap fCache = new HashMap( 20 );
|
||||||
|
|
||||||
private HashSet fNotFoundCache = new HashSet( 20 );
|
private HashSet fNotFoundCache = new HashSet( 20 );
|
||||||
|
@ -73,6 +76,7 @@ public class CProjectSourceLocation implements IProjectSourceLocation
|
||||||
{
|
{
|
||||||
setProject( project );
|
setProject( project );
|
||||||
fGenerated = true;
|
fGenerated = true;
|
||||||
|
initializeFolders();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -82,6 +86,7 @@ public class CProjectSourceLocation implements IProjectSourceLocation
|
||||||
{
|
{
|
||||||
setProject( project );
|
setProject( project );
|
||||||
fGenerated = generated;
|
fGenerated = generated;
|
||||||
|
initializeFolders();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
@ -147,84 +152,83 @@ public class CProjectSourceLocation implements IProjectSourceLocation
|
||||||
{
|
{
|
||||||
File file = new File( name );
|
File file = new File( name );
|
||||||
return ( file.isAbsolute() ) ? findFileByAbsolutePath( name ) :
|
return ( file.isAbsolute() ) ? findFileByAbsolutePath( name ) :
|
||||||
findFileByRelativePath( getProject(), name );
|
findFileByRelativePath( name );
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object findFileByAbsolutePath( String name )
|
private Object findFileByAbsolutePath( String name )
|
||||||
{
|
{
|
||||||
File file = new File( name );
|
File file = new File( name );
|
||||||
Object result = null;
|
Object result = null;
|
||||||
try
|
if ( file.isAbsolute() && file.exists() )
|
||||||
{
|
result = findFile( file );
|
||||||
if ( file.isAbsolute() )
|
|
||||||
result = findFile( getProject(), file.getCanonicalPath() );
|
|
||||||
}
|
|
||||||
catch( IOException e )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object findFileByRelativePath( IContainer container, String fileName )
|
private Object findFileByRelativePath( String fileName )
|
||||||
{
|
{
|
||||||
IPath rootPath = container.getLocation();
|
IResource[] folders = getFolders();
|
||||||
if ( rootPath == null )
|
LinkedList list = new LinkedList();
|
||||||
return null;
|
for ( int i = 0; i < folders.length; ++i )
|
||||||
IPath path = rootPath.append( fileName );
|
|
||||||
Object result = findFileByAbsolutePath( path.toOSString() );
|
|
||||||
if ( result == null )
|
|
||||||
{
|
{
|
||||||
try
|
if ( list.size() > 0 && !searchForDuplicateFileNames() )
|
||||||
{
|
|
||||||
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;
|
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 );
|
||||||
}
|
}
|
||||||
}
|
if ( list.size() == 1 || (list.size() > 0 && !searchForDuplicateFileNames()) )
|
||||||
}
|
return list.getFirst();
|
||||||
catch( CoreException e )
|
if ( list.size() > 0 )
|
||||||
{
|
return list;
|
||||||
// do nothing
|
return null;
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object findFile( IContainer container, String fileName )
|
private Object findFile( final File file )
|
||||||
{
|
{
|
||||||
|
if ( file != null )
|
||||||
|
{
|
||||||
|
final String name = file.getName();
|
||||||
|
IResource[] folders = getFolders();
|
||||||
|
final LinkedList list = new LinkedList();
|
||||||
|
for ( int i = 0; i < folders.length; ++i )
|
||||||
|
{
|
||||||
|
// 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
|
try
|
||||||
{
|
{
|
||||||
IResource[] members = container.members();
|
folders[i].accept(
|
||||||
for ( int i = 0; i < members.length; ++i )
|
new IResourceProxyVisitor()
|
||||||
{
|
{
|
||||||
if ( members[i] instanceof IFile )
|
public boolean visit( IResourceProxy proxy ) throws CoreException
|
||||||
{
|
{
|
||||||
if ( members[i].getLocation().toOSString().equals( fileName ) )
|
// use equalsIgnoreCase to make it work for Wondows
|
||||||
return members[i];
|
if ( proxy.getType() == IResource.FILE && proxy.getName().equalsIgnoreCase( name ) )
|
||||||
}
|
|
||||||
else if ( members[i] instanceof IFolder && fileName.startsWith( members[i].getLocation().toOSString() ) )
|
|
||||||
{
|
{
|
||||||
Object result = findFile( (IContainer)members[i], fileName );
|
IResource resource = proxy.requestResource();
|
||||||
if ( result != null )
|
File file1 = new File( resource.getLocation().toOSString() );
|
||||||
return result;
|
if ( file1.exists() && file1.equals( file ) )
|
||||||
|
list.addLast( resource );
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
IResource.NONE );
|
||||||
}
|
}
|
||||||
catch( CoreException e )
|
catch( CoreException e )
|
||||||
{
|
{
|
||||||
// do nothing
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if ( list.size() == 1 || (list.size() > 0 && !searchForDuplicateFileNames()) )
|
||||||
|
return list.getFirst();
|
||||||
|
if ( list.size() > 0 )
|
||||||
|
return list;
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -304,6 +308,7 @@ public class CProjectSourceLocation implements IProjectSourceLocation
|
||||||
if ( isGeneric == null || isGeneric.trim().length() == 0 )
|
if ( isGeneric == null || isGeneric.trim().length() == 0 )
|
||||||
isGeneric = Boolean.FALSE.toString();
|
isGeneric = Boolean.FALSE.toString();
|
||||||
setGenerated( isGeneric.equals( Boolean.TRUE.toString() ) );
|
setGenerated( isGeneric.equals( Boolean.TRUE.toString() ) );
|
||||||
|
initializeFolders();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
catch( ParserConfigurationException e )
|
catch( ParserConfigurationException e )
|
||||||
|
@ -357,8 +362,53 @@ public class CProjectSourceLocation implements IProjectSourceLocation
|
||||||
*/
|
*/
|
||||||
public boolean equals( Object obj )
|
public boolean equals( Object obj )
|
||||||
{
|
{
|
||||||
if ( obj instanceof IProjectSourceLocation )
|
if ( obj instanceof IProjectSourceLocation && getProject() != null )
|
||||||
return getProject().getName().equals( ((IProjectSourceLocation)obj).getProject().getName() );
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue