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

fix bug where PDOM content is preserved over deleting and creating a project of the same name

This commit is contained in:
Andrew Ferguson 2007-01-04 11:52:58 +00:00
parent 6bb1949ce9
commit 84147c9677
4 changed files with 97 additions and 23 deletions

View file

@ -7,10 +7,12 @@
*
* Contributors:
* Markus Schorn - initial API and implementation
* Andrew Ferguson (Symbian)
*******************************************************************************/
package org.eclipse.cdt.internal.index.tests;
import java.io.File;
import java.io.IOException;
import java.util.regex.Pattern;
@ -41,6 +43,8 @@ import org.eclipse.cdt.internal.core.CCoreInternals;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
@ -111,7 +115,6 @@ public class IndexBugsTests extends BaseTestCase {
String content = getContentsForTest(1)[0].toString();
String fileName = "bug162011.cpp";
String funcName = "function162011";
String nsName = "ns162011";
int indexOfDecl = content.indexOf(funcName);
int indexOfDef = content.indexOf(funcName, indexOfDecl+1);
@ -275,4 +278,62 @@ public class IndexBugsTests extends BaseTestCase {
}
}
// class A {}; class B {}; class C {};
public void testIndexContentOverProjectDelete() throws Exception {
waitForIndexer();
/* Check that when a project is deleted, its index contents do not
* appear in the initial index of a newly created project of the same name */
String pname = "deleteTest"+System.currentTimeMillis();
ICProject cproject = CProjectHelper.createCCProject(pname, "bin", IPDOMManager.ID_FAST_INDEXER);
IIndex index = CCorePlugin.getIndexManager().getIndex(cproject);
String content= getContentsForTest(1)[0].toString();
IFile file= TestSourceReader.createFile(cproject.getProject(), "content.cpp", content);
TestSourceReader.waitUntilFileIsIndexed(index, file, 8000);
CProjectHelper.delete(cproject);
cproject = CProjectHelper.createCCProject(pname, "bin", IPDOMManager.ID_FAST_INDEXER);
index = CCorePlugin.getIndexManager().getIndex(cproject);
index.acquireReadLock();
try {
IBinding[] bindings = index.findBindings(Pattern.compile(".*"), false, IndexFilter.ALL, new NullProgressMonitor());
assertEquals(0, bindings.length);
}
finally {
index.releaseReadLock();
CProjectHelper.delete(cproject);
}
}
// class A {}; class B {}; class C {}; class D {};
public void testIndexContentOverProjectMove() throws Exception {
waitForIndexer();
/* Check that the contents of an index is preserved over a project
* move operation */
ICProject cproject = CProjectHelper.createCCProject("moveTest", "bin", IPDOMManager.ID_FAST_INDEXER);
IIndex index = CCorePlugin.getIndexManager().getIndex(cproject);
String content= getContentsForTest(1)[0].toString();
IFile file= TestSourceReader.createFile(cproject.getProject(), "content.cpp", content);
TestSourceReader.waitUntilFileIsIndexed(index, file, 8000);
// move the project to a random new location
File newLocation = CProjectHelper.freshDir();
IProjectDescription description = cproject.getProject().getDescription();
description.setLocationURI(newLocation.toURI());
cproject.getProject().move(description, IResource.FORCE | IResource.SHALLOW, new NullProgressMonitor());
index = CCorePlugin.getIndexManager().getIndex(cproject);
index.acquireReadLock();
try {
IBinding[] bindings = index.findBindings(Pattern.compile(".*"), false, IndexFilter.ALL, new NullProgressMonitor());
assertEquals(4, bindings.length);
}
finally {
index.releaseReadLock();
CProjectHelper.delete(cproject);
}
}
}

View file

@ -53,8 +53,8 @@ public class IndexLocationTest extends BaseTestCase {
Bundle b = CTestPlugin.getDefault().getBundle();
StringBuffer[] testData = TestSourceReader.getContentsForTest(b, "parser", getClass(), getName(), 3);
movedLocation = freshDir();
externalHeader = new File(freshDir(),"external.h");
movedLocation = CProjectHelper.freshDir();
externalHeader = new File(CProjectHelper.freshDir(),"external.h");
IFile file1 = TestSourceReader.createFile(cproject.getProject(), "header.h", testData[0].toString());
createExternalFile(externalHeader, testData[1].toString());
@ -134,16 +134,4 @@ public class IndexLocationTest extends BaseTestCase {
new Path(nms3[0].getFile().getLocation().getFullPath())
);
}
private File freshDir() throws IOException {
File tempDir = new File(System.getProperty("java.io.tmpdir")).getCanonicalFile();
for(int i=0; i<Integer.MAX_VALUE; i++) {
File candidate = new File(tempDir, "__testData/"+i);
if(!candidate.exists()) {
candidate.mkdirs();
return candidate;
}
}
return null;
}
}

View file

@ -7,9 +7,11 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
* Andrew Ferguson (Symbian)
*******************************************************************************/
package org.eclipse.cdt.core.testplugin;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.zip.ZipFile;
@ -326,4 +328,20 @@ public class CProjectHelper {
}
}
/**
* Returns the location of a newly created directory in the systems temp. area.
* @return the location of a newly created directory in the systems temp. area
* @throws IOException
*/
public static File freshDir() throws IOException {
File tempDir = new File(System.getProperty("java.io.tmpdir")).getCanonicalFile();
for(int i=0; i<Integer.MAX_VALUE; i++) {
File candidate = new File(tempDir, "__testData/"+i);
if(!candidate.exists()) {
candidate.mkdirs();
return candidate;
}
}
return null;
}
}

View file

@ -8,6 +8,7 @@
* Contributors:
* QNX - Initial API and implementation
* Markus Schorn (Wind River Systems)
* Andrew Ferguson (Symbian)
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom;
@ -505,14 +506,20 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen
unregisterPreferenceListener(project);
}
public void deleteProject(ICProject project, IResourceDelta delta) {
// Project is about to be deleted. Stop all indexing tasks for it
IPDOMIndexer indexer = getIndexer(project, false);
if (indexer != null) {
stopIndexer(indexer);
}
unregisterPreferenceListener(project);
}
public void deleteProject(ICProject cproject, IResourceDelta delta) {
// Project is about to be deleted. Stop all indexing tasks for it
IPDOMIndexer indexer = getIndexer(cproject, false);
if (indexer != null) {
stopIndexer(indexer);
}
unregisterPreferenceListener(cproject);
// remove entry for project from PDOM map
synchronized (fProjectToPDOM) {
IProject project= cproject.getProject();
fProjectToPDOM.remove(project);
}
}
private void stopIndexer(IPDOMIndexer indexer) {
ICProject project= indexer.getProject();