mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-18 14:35:23 +02:00
Bug 343538 - Index not updated when complete folder deleted
This commit is contained in:
parent
a5750c313d
commit
c3d3296b60
3 changed files with 109 additions and 36 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2006, 2010 Wind River Systems, Inc. and others.
|
* Copyright (c) 2006, 2011 Wind River Systems, Inc. and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -17,6 +17,8 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import junit.framework.TestSuite;
|
import junit.framework.TestSuite;
|
||||||
|
@ -89,10 +91,18 @@ import org.eclipse.core.resources.IFolder;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.IProjectDescription;
|
import org.eclipse.core.resources.IProjectDescription;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
|
import org.eclipse.core.resources.IResourceVisitor;
|
||||||
|
import org.eclipse.core.resources.IWorkspace;
|
||||||
|
import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
|
import org.eclipse.core.resources.WorkspaceJob;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
|
import org.eclipse.core.runtime.Status;
|
||||||
|
import org.eclipse.core.runtime.jobs.Job;
|
||||||
|
|
||||||
public class IndexBugsTests extends BaseTestCase {
|
public class IndexBugsTests extends BaseTestCase {
|
||||||
private static final int INDEX_WAIT_TIME = 8000;
|
private static final int INDEX_WAIT_TIME = 8000;
|
||||||
|
@ -2317,4 +2327,77 @@ public class IndexBugsTests extends BaseTestCase {
|
||||||
|
|
||||||
assertTrue(offset1 != offset2);
|
assertTrue(offset1 != offset2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testUpdateOnFolderRemove_343538() throws Exception {
|
||||||
|
IIndexBinding[] r;
|
||||||
|
|
||||||
|
final IProject prj = fCProject.getProject();
|
||||||
|
final IFolder root= prj.getFolder("root");
|
||||||
|
root.create(true, false, null);
|
||||||
|
assertTrue(root.exists());
|
||||||
|
IFolder child1 = root.getFolder("child1");
|
||||||
|
child1.create(true, false, null);
|
||||||
|
assertTrue(child1.exists());
|
||||||
|
IFolder child2 = root.getFolder("child2");
|
||||||
|
child2.create(true, false, null);
|
||||||
|
assertTrue(child2.exists());
|
||||||
|
|
||||||
|
TestSourceReader.createFile(child1, "a.c", "void bug343538() {}");
|
||||||
|
TestSourceReader.createFile(child2, "b.c", "void bug343538();");
|
||||||
|
waitForIndexer(fCProject);
|
||||||
|
|
||||||
|
final IIndex index= CCorePlugin.getIndexManager().getIndex(fCProject);
|
||||||
|
index.acquireReadLock();
|
||||||
|
try {
|
||||||
|
r = index.findBindings("bug343538".toCharArray(), IndexFilter.ALL, null);
|
||||||
|
assertEquals(1, r.length);
|
||||||
|
IIndexName[] names = index.findNames(r[0], IIndex.FIND_DECLARATIONS_DEFINITIONS);
|
||||||
|
assertEquals(2, names.length);
|
||||||
|
} finally {
|
||||||
|
index.releaseReadLock();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Collect files and folders
|
||||||
|
final Set<IFile> files = new HashSet<IFile>();
|
||||||
|
final Set<IFolder> folders = new HashSet<IFolder>();
|
||||||
|
folders.add(root);
|
||||||
|
root.accept(new IResourceVisitor() {
|
||||||
|
public boolean visit(final IResource resource) throws CoreException {
|
||||||
|
if (resource instanceof IFile) {
|
||||||
|
files.add((IFile) resource);
|
||||||
|
} else if (resource instanceof IFolder) {
|
||||||
|
folders.add((IFolder) resource);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Job job = new WorkspaceJob("Delete folder") {
|
||||||
|
@Override
|
||||||
|
public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
|
||||||
|
IWorkspace ws = ResourcesPlugin.getWorkspace();
|
||||||
|
ws.delete(files.toArray(new IResource[files.size()]), IResource.FORCE, null);
|
||||||
|
ws.delete(folders.toArray(new IResource[folders.size()]), IResource.FORCE, null);
|
||||||
|
return Status.OK_STATUS;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
job.schedule();
|
||||||
|
job.join();
|
||||||
|
Thread.sleep(1000);
|
||||||
|
waitForIndexer(fCProject);
|
||||||
|
|
||||||
|
index.acquireReadLock();
|
||||||
|
try {
|
||||||
|
r = index.findBindings("bug343538".toCharArray(), IndexFilter.ALL, null);
|
||||||
|
if (r.length == 1) {
|
||||||
|
IIndexName[] names = index.findNames(r[0], IIndex.FIND_DECLARATIONS_DEFINITIONS);
|
||||||
|
assertEquals(0, names.length);
|
||||||
|
} else {
|
||||||
|
assertEquals(0, r.length);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
index.releaseReadLock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2002, 2010 IBM Corporation and others.
|
* Copyright (c) 2002, 2011 IBM Corporation and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -423,8 +423,6 @@ final class DeltaProcessor {
|
||||||
* relevant <code>CModel</code>s.
|
* relevant <code>CModel</code>s.
|
||||||
*/
|
*/
|
||||||
public ICElementDelta[] processResourceDelta(IResourceDelta changes) {
|
public ICElementDelta[] processResourceDelta(IResourceDelta changes) {
|
||||||
|
|
||||||
try {
|
|
||||||
ICElement root = CModelManager.getDefault().getCModel();
|
ICElement root = CModelManager.getDefault().getCModel();
|
||||||
// get the workspace delta, and start processing there.
|
// get the workspace delta, and start processing there.
|
||||||
IResourceDelta[] deltas = changes.getAffectedChildren();
|
IResourceDelta[] deltas = changes.getAffectedChildren();
|
||||||
|
@ -440,8 +438,6 @@ final class DeltaProcessor {
|
||||||
// release deltas
|
// release deltas
|
||||||
fCurrentDelta= null;
|
fCurrentDelta= null;
|
||||||
return filteredDeltas;
|
return filteredDeltas;
|
||||||
} finally {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -457,10 +453,7 @@ final class DeltaProcessor {
|
||||||
IResource resource = delta.getResource();
|
IResource resource = delta.getResource();
|
||||||
ICElement current = createElement(resource);
|
ICElement current = createElement(resource);
|
||||||
updateChildren = updateCurrentDeltaAndIndex(current, delta);
|
updateChildren = updateCurrentDeltaAndIndex(current, delta);
|
||||||
if (current == null) {
|
if (current == null || current instanceof ICContainer) {
|
||||||
if (parent != null)
|
|
||||||
nonCResourcesChanged(parent, delta);
|
|
||||||
} else if (current instanceof ISourceRoot) {
|
|
||||||
if (parent != null)
|
if (parent != null)
|
||||||
nonCResourcesChanged(parent, delta);
|
nonCResourcesChanged(parent, delta);
|
||||||
} else if (current instanceof ICProject) {
|
} else if (current instanceof ICProject) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2007, 2010 Wind River Systems, Inc. and others.
|
* Copyright (c) 2007, 2011 Wind River Systems, Inc. and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -51,11 +51,11 @@ public class DeltaAnalyzer {
|
||||||
}
|
}
|
||||||
|
|
||||||
final ICElement element = delta.getElement();
|
final ICElement element = delta.getElement();
|
||||||
handled.add(element.getResource());
|
|
||||||
switch (element.getElementType()) {
|
switch (element.getElementType()) {
|
||||||
case ICElement.C_UNIT:
|
case ICElement.C_UNIT:
|
||||||
ITranslationUnit tu = (ITranslationUnit)element;
|
ITranslationUnit tu = (ITranslationUnit)element;
|
||||||
if (!tu.isWorkingCopy()) {
|
if (!tu.isWorkingCopy()) {
|
||||||
|
handled.add(element.getResource());
|
||||||
switch (delta.getKind()) {
|
switch (delta.getKind()) {
|
||||||
case ICElementDelta.CHANGED:
|
case ICElementDelta.CHANGED:
|
||||||
if ((flags & ICElementDelta.F_CONTENT) != 0) {
|
if ((flags & ICElementDelta.F_CONTENT) != 0) {
|
||||||
|
@ -74,22 +74,21 @@ public class DeltaAnalyzer {
|
||||||
case ICElement.C_CCONTAINER:
|
case ICElement.C_CCONTAINER:
|
||||||
ICContainer folder= (ICContainer) element;
|
ICContainer folder= (ICContainer) element;
|
||||||
if (delta.getKind() == ICElementDelta.ADDED) {
|
if (delta.getKind() == ICElementDelta.ADDED) {
|
||||||
|
handled.add(element.getResource());
|
||||||
collectSources(folder, fChanged);
|
collectSources(folder, fChanged);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sSuppressPotentialTUs) {
|
if (!sSuppressPotentialTUs) {
|
||||||
// If the cmodel delta does not have children, also look at the children of the
|
// Always look at the children of the resource delta (bug 343538)
|
||||||
// resource delta.
|
|
||||||
final boolean checkChildren = !hasChildren;
|
|
||||||
final IResourceDelta[] rDeltas= delta.getResourceDeltas();
|
final IResourceDelta[] rDeltas= delta.getResourceDeltas();
|
||||||
processResourceDelta(rDeltas, element, handled, checkChildren);
|
processResourceDelta(rDeltas, element, handled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void processResourceDelta(final IResourceDelta[] rDeltas, final ICElement element,
|
public void processResourceDelta(final IResourceDelta[] rDeltas, final ICElement element,
|
||||||
Set<IResource> handled, boolean checkChildren) {
|
Set<IResource> handled) {
|
||||||
if (rDeltas != null) {
|
if (rDeltas != null) {
|
||||||
for (IResourceDelta rd: rDeltas) {
|
for (IResourceDelta rd: rDeltas) {
|
||||||
final int rdkind = rd.getKind();
|
final int rdkind = rd.getKind();
|
||||||
|
@ -108,9 +107,7 @@ public class DeltaAnalyzer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (rdkind == IResourceDelta.CHANGED && checkChildren) {
|
processResourceDelta(rd.getAffectedChildren(IResourceDelta.CHANGED | IResourceDelta.REMOVED), element, handled);
|
||||||
processResourceDelta(rd.getAffectedChildren(), element, handled, checkChildren);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue