public void testFindFilesByLocation() throws Exception { fProject.create(new NullProgressMonitor()); fProject.open(new NullProgressMonitor()); createFolder(fProject, "folder1"); createFolder(fProject, "folder2"); IFile file = createFile(fProject, "abc.h"); createFile(fProject, "folder1/abc.h"); createFile(fProject, "folder2/abC.h"); URI uri = file.getLocationURI(); IPath path = file.getLocation(); IFile[] files = ResourceLookup.findFilesForLocationURI(uri); assertEquals(1, files.length); files = ResourceLookup.findFilesForLocation(path); assertEquals(1, files.length); if (new File("a").equals(new File("A"))) { URI upperCase = new URI(uri.getScheme(), uri.getSchemeSpecificPart().toUpperCase(), uri.getFragment()); IPath upperCasePath = new Path(path.toString().toUpperCase()); files = ResourceLookup.findFilesForLocationURI(upperCase); assertEquals(1, files.length); files = ResourceLookup.findFilesForLocation(upperCasePath); assertEquals(1, files.length); } }
/** Returns whether the given URI points within the workspace. */ private static boolean isWorkspaceFile(URI uri) { for (IFile file : ResourceLookup.findFilesForLocationURI(uri)) { if (file.exists()) { return true; } } return false; }
public void testResourceDelta() throws CoreException { IProject[] prjs = new IProject[] {fProject}; fProject.create(new NullProgressMonitor()); fProject.open(new NullProgressMonitor()); IFile[] files = ResourceLookup.findFilesByName(new Path("abc.h"), prjs, true); assertEquals(0, files.length); IFolder f1 = createFolder(fProject, "folder1"); createFolder(fProject, "folder2"); IFile f2 = createFile(fProject, "abc.h"); files = ResourceLookup.findFilesByName(new Path("abc.h"), prjs, true); assertEquals(1, files.length); createFile(fProject, "folder1/abc.h"); files = ResourceLookup.findFilesByName(new Path("abc.h"), prjs, true); assertEquals(2, files.length); createFile(fProject, "folder2/abC.h"); files = ResourceLookup.findFilesByName(new Path("abc.h"), prjs, true); assertEquals(3, files.length); f1.delete(true, new NullProgressMonitor()); files = ResourceLookup.findFilesByName(new Path("abc.h"), prjs, true); assertEquals(2, files.length); f2.delete(true, new NullProgressMonitor()); files = ResourceLookup.findFilesByName(new Path("abc.h"), prjs, true); assertEquals(1, files.length); }
public void testLinkedResourceFiles() throws Exception { IProject[] prjs = new IProject[] {fProject}; fProject.create(new NullProgressMonitor()); fProject.open(new NullProgressMonitor()); createFolder(fProject, "folder1"); File f = createTempFile("extern", ".h"); IPath location = Path.fromOSString(f.getAbsolutePath()); IFile file1 = fProject.getFile("linked1"); IFile file2 = fProject.getFile("linked2.h"); file1.createLink(location, 0, new NullProgressMonitor()); file2.createLink(location, 0, new NullProgressMonitor()); IFile[] files = ResourceLookup.findFilesForLocation(location); assertEquals(2, files.length); files = ResourceLookup.findFilesByName(new Path(location.lastSegment()), prjs, false); assertEquals(2, files.length); files = ResourceLookup.findFilesByName(new Path("linked2.h"), prjs, false); assertEquals(0, files.length); }
public void testCollected() throws CoreException { IProject[] prjs = new IProject[] {fProject}; fProject.create(new NullProgressMonitor()); fProject.open(new NullProgressMonitor()); createFolder(fProject, "folder1"); createFolder(fProject, "folder2"); createFile(fProject, "abc.h"); IFile[] files = ResourceLookup.findFilesByName(new Path("abc.h"), prjs, true); assertEquals(1, files.length); ResourceLookup.simulateNodeMapCollection(); createFile(fProject, "folder1/abc.h"); createFile(fProject, "folder2/abC.h"); files = ResourceLookup.findFilesByName(new Path("abc.h"), prjs, true); assertEquals(3, files.length); ResourceLookup.simulateNodeMapCollection(); files = ResourceLookup.findFilesByName(new Path("abc.h"), prjs, true); assertEquals(3, files.length); }
public void testNameLookup() throws CoreException { IProject[] prjs = new IProject[] {fProject}; fProject.create(new NullProgressMonitor()); fProject.open(new NullProgressMonitor()); createFolder(fProject, "folder1"); createFolder(fProject, "folder2"); createFile(fProject, "abc.h"); createFile(fProject, "folder1/abc.h"); createFile(fProject, "folder2/abC.h"); IFile[] files = ResourceLookup.findFilesByName(new Path("abc.h"), prjs, false); assertEquals(2, files.length); files = ResourceLookup.findFilesByName(new Path("bla/../abc.h"), prjs, false); assertEquals(2, files.length); files = ResourceLookup.findFilesByName(new Path("../abc.h"), prjs, false); assertEquals(2, files.length); files = ResourceLookup.findFilesByName(new Path("../../abc.h"), prjs, false); assertEquals(2, files.length); files = ResourceLookup.findFilesByName(new Path("abc.h"), prjs, true); assertEquals(3, files.length); files = ResourceLookup.findFilesByName(new Path("folder1/abc.h"), prjs, false); assertEquals(1, files.length); files = ResourceLookup.findFilesByName(new Path("folder1/abC.h"), prjs, false); assertEquals(0, files.length); files = ResourceLookup.findFilesByName(new Path("fOlder1/abc.h"), prjs, false); assertEquals(0, files.length); files = ResourceLookup.findFilesByName(new Path("folder1/abc.h"), prjs, true); assertEquals(1, files.length); files = ResourceLookup.findFilesByName(new Path("folder1/abC.h"), prjs, true); assertEquals(1, files.length); files = ResourceLookup.findFilesByName(new Path("fOlder1/abc.h"), prjs, true); assertEquals(1, files.length); files = ResourceLookup.findFilesByName(new Path("bla/../abc.h"), prjs, true); assertEquals(3, files.length); }