mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-09-08 11:03:28 +02:00
Testcases for 167551, use index on project import.
This commit is contained in:
parent
4ba1f45c11
commit
e7450163c8
10 changed files with 509 additions and 29 deletions
|
@ -0,0 +1,30 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2007 Wind River Systems, Inc. and others.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Markus Schorn - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
package org.eclipse.cdt.internal.index.tests;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.dom.IPDOMIndexerTask;
|
||||||
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
|
import org.eclipse.cdt.internal.core.pdom.indexer.AbstractPDOMIndexer;
|
||||||
|
|
||||||
|
public class FakeIndexer extends AbstractPDOMIndexer {
|
||||||
|
static final String ID = "org.eclipse.cdt.core.tests.FakeIndexer";
|
||||||
|
|
||||||
|
public IPDOMIndexerTask createTask(ITranslationUnit[] added,
|
||||||
|
ITranslationUnit[] changed, ITranslationUnit[] removed) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getID() {
|
||||||
|
return ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2006 Wind River Systems, Inc. and others.
|
* Copyright (c) 2006, 2007 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
|
||||||
|
@ -27,6 +27,7 @@ public class IndexTests extends TestSuite {
|
||||||
suite.addTest(IndexIncludeTest.suite());
|
suite.addTest(IndexIncludeTest.suite());
|
||||||
suite.addTest(IndexBugsTests.suite());
|
suite.addTest(IndexBugsTests.suite());
|
||||||
suite.addTest(EnclosingNamesTest.suite());
|
suite.addTest(EnclosingNamesTest.suite());
|
||||||
|
suite.addTest(TeamSharedIndexTest.suite());
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,355 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2007 Wind River Systems, Inc. and others.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Markus Schorn - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
package org.eclipse.cdt.internal.index.tests;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
|
||||||
|
import junit.framework.TestSuite;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
|
import org.eclipse.cdt.core.dom.IPDOMManager;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||||
|
import org.eclipse.cdt.core.index.IIndex;
|
||||||
|
import org.eclipse.cdt.core.index.IndexFilter;
|
||||||
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
|
import org.eclipse.cdt.core.model.ElementChangedEvent;
|
||||||
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
|
import org.eclipse.cdt.core.model.IElementChangedListener;
|
||||||
|
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
||||||
|
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
|
||||||
|
import org.eclipse.cdt.internal.core.pdom.PDOMManager;
|
||||||
|
import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences;
|
||||||
|
import org.eclipse.core.resources.IProject;
|
||||||
|
import org.eclipse.core.resources.IProjectDescription;
|
||||||
|
import org.eclipse.core.resources.IWorkspace;
|
||||||
|
import org.eclipse.core.resources.IWorkspaceRunnable;
|
||||||
|
import org.eclipse.core.resources.ProjectScope;
|
||||||
|
import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
|
||||||
|
|
||||||
|
public class TeamSharedIndexTest extends IndexTestBase {
|
||||||
|
|
||||||
|
private static final int INDEXER_WAIT_TIME = 8000;
|
||||||
|
|
||||||
|
public static TestSuite suite() {
|
||||||
|
return suite(TeamSharedIndexTest.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Collection fProjects= new LinkedList();
|
||||||
|
private static final PDOMManager fPDOMManager = (PDOMManager) CCorePlugin.getPDOMManager();
|
||||||
|
|
||||||
|
public TeamSharedIndexTest(String name) {
|
||||||
|
super(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
fProjects.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void tearDown() throws Exception {
|
||||||
|
for (Iterator iterator = fProjects.iterator(); iterator.hasNext();) {
|
||||||
|
ICProject project = (ICProject) iterator.next();
|
||||||
|
CProjectHelper.delete(project);
|
||||||
|
}
|
||||||
|
super.tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerProject(ICProject prj) {
|
||||||
|
fProjects.add(prj);
|
||||||
|
}
|
||||||
|
private void unregisterProject(ICProject prj) {
|
||||||
|
fProjects.remove(prj);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ICProject createProject(String name) throws CoreException {
|
||||||
|
ICProject project= CProjectHelper.createCCProject(name, null, IPDOMManager.ID_NO_INDEXER);
|
||||||
|
registerProject(project);
|
||||||
|
TestSourceReader.createFile(project.getProject(), "a.cpp", "int a;");
|
||||||
|
TestSourceReader.createFile(project.getProject(), "b.cpp", "int b;");
|
||||||
|
TestSourceReader.createFile(project.getProject(), "c.cpp", "int c;");
|
||||||
|
fPDOMManager.setIndexerId(project, IPDOMManager.ID_FAST_INDEXER);
|
||||||
|
assertTrue(fPDOMManager.joinIndexer(INDEXER_WAIT_TIME, NPM));
|
||||||
|
return project;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ICProject recreateProject(final String prjName) throws Exception {
|
||||||
|
final boolean[] changed= {false};
|
||||||
|
CoreModel.getDefault().addElementChangedListener(new IElementChangedListener() {
|
||||||
|
public void elementChanged(ElementChangedEvent event) {
|
||||||
|
synchronized (changed) {
|
||||||
|
changed[0]= true;
|
||||||
|
}
|
||||||
|
changed.notifyAll();
|
||||||
|
}});
|
||||||
|
final IWorkspace workspace = ResourcesPlugin.getWorkspace();
|
||||||
|
final IProject prjHandle= workspace.getRoot().getProject(prjName);
|
||||||
|
workspace.run(new IWorkspaceRunnable() {
|
||||||
|
public void run(IProgressMonitor monitor) throws CoreException {
|
||||||
|
IProjectDescription desc= IDEWorkbenchPlugin.getPluginWorkspace().newProjectDescription(prjName);
|
||||||
|
prjHandle.create(desc, NPM);
|
||||||
|
prjHandle.open(0, NPM);
|
||||||
|
}
|
||||||
|
}, null);
|
||||||
|
synchronized(changed) {
|
||||||
|
if (!changed[0]) {
|
||||||
|
changed.wait(INDEXER_WAIT_TIME);
|
||||||
|
assertTrue(changed[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fPDOMManager.joinIndexer(INDEXER_WAIT_TIME, NPM);
|
||||||
|
return CoreModel.getDefault().create(workspace.getRoot().getProject(prjName));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkVariable(ICProject prj, String var, int expectedCount)
|
||||||
|
throws CoreException, InterruptedException {
|
||||||
|
IIndex index= fPDOMManager.getIndex(prj);
|
||||||
|
index.acquireReadLock();
|
||||||
|
try {
|
||||||
|
IBinding[] binding= index.findBindings(var.toCharArray(), IndexFilter.ALL, NPM);
|
||||||
|
int count= 0;
|
||||||
|
assertTrue(binding.length < 2);
|
||||||
|
if (binding.length == 1) {
|
||||||
|
assertTrue(binding[0] instanceof IVariable);
|
||||||
|
count= index.findNames(binding[0], IIndex.FIND_ALL_OCCURENCES).length;
|
||||||
|
}
|
||||||
|
assertEquals(var, expectedCount, count);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
index.releaseReadLock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testDefaultExport() throws Exception {
|
||||||
|
String prjName= "__testDefaultExport__";
|
||||||
|
ICProject prj= createProject(prjName);
|
||||||
|
String loc= IndexerPreferences.getIndexImportLocation(prj.getProject());
|
||||||
|
checkVariable(prj, "a", 1);
|
||||||
|
checkVariable(prj, "b", 1);
|
||||||
|
checkVariable(prj, "c", 1);
|
||||||
|
|
||||||
|
// export the project.
|
||||||
|
fPDOMManager.export(prj, loc, 0, NPM);
|
||||||
|
|
||||||
|
// set indexer to the fake one.
|
||||||
|
fPDOMManager.setIndexerId(prj, FakeIndexer.ID);
|
||||||
|
IndexerPreferences.setScope(prj.getProject(), IndexerPreferences.SCOPE_PROJECT_SHARED);
|
||||||
|
new ProjectScope(prj.getProject()).getNode(CCorePlugin.PLUGIN_ID).flush();
|
||||||
|
fPDOMManager.joinIndexer(INDEXER_WAIT_TIME, NPM);
|
||||||
|
checkVariable(prj, "a", 0);
|
||||||
|
checkVariable(prj, "b", 0);
|
||||||
|
checkVariable(prj, "c", 0);
|
||||||
|
|
||||||
|
// delete project
|
||||||
|
prj.getProject().delete(false, true, NPM);
|
||||||
|
unregisterProject(prj);
|
||||||
|
|
||||||
|
// import project
|
||||||
|
prj = recreateProject(prjName);
|
||||||
|
assertEquals(FakeIndexer.ID, fPDOMManager.getIndexerId(prj));
|
||||||
|
|
||||||
|
registerProject(prj);
|
||||||
|
checkVariable(prj, "a", 1);
|
||||||
|
checkVariable(prj, "b", 1);
|
||||||
|
checkVariable(prj, "c", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testExportWithFileChange() throws Exception {
|
||||||
|
String prjName= "__testExportWithChange__";
|
||||||
|
ICProject prj= createProject(prjName);
|
||||||
|
String loc= IndexerPreferences.getIndexImportLocation(prj.getProject());
|
||||||
|
checkVariable(prj, "a", 1);
|
||||||
|
checkVariable(prj, "b", 1);
|
||||||
|
checkVariable(prj, "c", 1);
|
||||||
|
|
||||||
|
// export the project.
|
||||||
|
IndexerPreferences.setScope(prj.getProject(), IndexerPreferences.SCOPE_PROJECT_SHARED);
|
||||||
|
new ProjectScope(prj.getProject()).getNode(CCorePlugin.PLUGIN_ID).flush();
|
||||||
|
fPDOMManager.export(prj, loc, 0, NPM);
|
||||||
|
fPDOMManager.joinIndexer(INDEXER_WAIT_TIME, NPM);
|
||||||
|
|
||||||
|
// change file
|
||||||
|
prj.getProject().getFile("a.cpp").setContents(new ByteArrayInputStream("int d;".getBytes()), true, false, NPM);
|
||||||
|
prj.getProject().delete(false, true, NPM);
|
||||||
|
unregisterProject(prj);
|
||||||
|
|
||||||
|
// import project
|
||||||
|
prj = recreateProject(prjName);
|
||||||
|
registerProject(prj);
|
||||||
|
checkVariable(prj, "a", 0);
|
||||||
|
checkVariable(prj, "b", 1);
|
||||||
|
checkVariable(prj, "c", 1);
|
||||||
|
checkVariable(prj, "d", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testExportWithFileChangeFake() throws Exception {
|
||||||
|
String prjName= "__testExportWithChangeFake__";
|
||||||
|
ICProject prj= createProject(prjName);
|
||||||
|
String loc= IndexerPreferences.getIndexImportLocation(prj.getProject());
|
||||||
|
checkVariable(prj, "a", 1);
|
||||||
|
checkVariable(prj, "b", 1);
|
||||||
|
checkVariable(prj, "c", 1);
|
||||||
|
|
||||||
|
// export the project.
|
||||||
|
fPDOMManager.export(prj, loc, 0, NPM);
|
||||||
|
fPDOMManager.joinIndexer(INDEXER_WAIT_TIME, NPM);
|
||||||
|
|
||||||
|
// set indexer to the fake one.
|
||||||
|
fPDOMManager.setIndexerId(prj, FakeIndexer.ID);
|
||||||
|
IndexerPreferences.setScope(prj.getProject(), IndexerPreferences.SCOPE_PROJECT_SHARED);
|
||||||
|
new ProjectScope(prj.getProject()).getNode(CCorePlugin.PLUGIN_ID).flush();
|
||||||
|
checkVariable(prj, "a", 0);
|
||||||
|
checkVariable(prj, "b", 0);
|
||||||
|
checkVariable(prj, "c", 0);
|
||||||
|
|
||||||
|
// change file
|
||||||
|
prj.getProject().getFile("a.cpp").setContents(new ByteArrayInputStream("int d;".getBytes()), true, false, NPM);
|
||||||
|
prj.getProject().delete(false, true, NPM);
|
||||||
|
unregisterProject(prj);
|
||||||
|
|
||||||
|
// import project
|
||||||
|
prj = recreateProject(prjName);
|
||||||
|
registerProject(prj);
|
||||||
|
checkVariable(prj, "a", 1);
|
||||||
|
checkVariable(prj, "b", 1);
|
||||||
|
checkVariable(prj, "c", 1);
|
||||||
|
checkVariable(prj, "d", 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testExportWithAddition() throws Exception {
|
||||||
|
String prjName= "__testExportWithAddition__";
|
||||||
|
ICProject prj= createProject(prjName);
|
||||||
|
String loc= IndexerPreferences.getIndexImportLocation(prj.getProject());
|
||||||
|
checkVariable(prj, "a", 1);
|
||||||
|
checkVariable(prj, "b", 1);
|
||||||
|
checkVariable(prj, "c", 1);
|
||||||
|
|
||||||
|
// export the project.
|
||||||
|
IndexerPreferences.setScope(prj.getProject(), IndexerPreferences.SCOPE_PROJECT_SHARED);
|
||||||
|
new ProjectScope(prj.getProject()).getNode(CCorePlugin.PLUGIN_ID).flush();
|
||||||
|
fPDOMManager.export(prj, loc, 0, NPM);
|
||||||
|
fPDOMManager.joinIndexer(INDEXER_WAIT_TIME, NPM);
|
||||||
|
|
||||||
|
// add file
|
||||||
|
TestSourceReader.createFile(prj.getProject(), "d.cpp", "int d;");
|
||||||
|
prj.getProject().delete(false, true, NPM);
|
||||||
|
unregisterProject(prj);
|
||||||
|
|
||||||
|
// import project
|
||||||
|
prj = recreateProject(prjName);
|
||||||
|
registerProject(prj);
|
||||||
|
checkVariable(prj, "a", 1);
|
||||||
|
checkVariable(prj, "b", 1);
|
||||||
|
checkVariable(prj, "c", 1);
|
||||||
|
checkVariable(prj, "d", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testExportWithAdditionFake() throws Exception {
|
||||||
|
String prjName= "__testExportWithAdditionFake__";
|
||||||
|
ICProject prj= createProject(prjName);
|
||||||
|
String loc= IndexerPreferences.getIndexImportLocation(prj.getProject());
|
||||||
|
checkVariable(prj, "a", 1);
|
||||||
|
checkVariable(prj, "b", 1);
|
||||||
|
checkVariable(prj, "c", 1);
|
||||||
|
|
||||||
|
// export the project.
|
||||||
|
fPDOMManager.export(prj, loc, 0, NPM);
|
||||||
|
fPDOMManager.joinIndexer(INDEXER_WAIT_TIME, NPM);
|
||||||
|
|
||||||
|
// set indexer to the fake one.
|
||||||
|
fPDOMManager.setIndexerId(prj, FakeIndexer.ID);
|
||||||
|
IndexerPreferences.setScope(prj.getProject(), IndexerPreferences.SCOPE_PROJECT_SHARED);
|
||||||
|
new ProjectScope(prj.getProject()).getNode(CCorePlugin.PLUGIN_ID).flush();
|
||||||
|
checkVariable(prj, "a", 0);
|
||||||
|
checkVariable(prj, "b", 0);
|
||||||
|
checkVariable(prj, "c", 0);
|
||||||
|
|
||||||
|
// add file
|
||||||
|
TestSourceReader.createFile(prj.getProject(), "d.cpp", "int d;");
|
||||||
|
prj.getProject().delete(false, true, NPM);
|
||||||
|
unregisterProject(prj);
|
||||||
|
|
||||||
|
// import project
|
||||||
|
prj = recreateProject(prjName);
|
||||||
|
registerProject(prj);
|
||||||
|
checkVariable(prj, "a", 1);
|
||||||
|
checkVariable(prj, "b", 1);
|
||||||
|
checkVariable(prj, "c", 1);
|
||||||
|
checkVariable(prj, "d", 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testExportWithRemoval() throws Exception {
|
||||||
|
String prjName= "__testExportWithRemoval__";
|
||||||
|
ICProject prj= createProject(prjName);
|
||||||
|
String loc= IndexerPreferences.getIndexImportLocation(prj.getProject());
|
||||||
|
checkVariable(prj, "a", 1);
|
||||||
|
checkVariable(prj, "b", 1);
|
||||||
|
checkVariable(prj, "c", 1);
|
||||||
|
|
||||||
|
// export the project.
|
||||||
|
IndexerPreferences.setScope(prj.getProject(), IndexerPreferences.SCOPE_PROJECT_SHARED);
|
||||||
|
new ProjectScope(prj.getProject()).getNode(CCorePlugin.PLUGIN_ID).flush();
|
||||||
|
fPDOMManager.export(prj, loc, 0, NPM);
|
||||||
|
fPDOMManager.joinIndexer(INDEXER_WAIT_TIME, NPM);
|
||||||
|
|
||||||
|
// delete file
|
||||||
|
prj.getProject().getFile("a.cpp").delete(true, NPM);
|
||||||
|
prj.getProject().delete(false, true, NPM);
|
||||||
|
unregisterProject(prj);
|
||||||
|
|
||||||
|
// import project
|
||||||
|
prj = recreateProject(prjName);
|
||||||
|
registerProject(prj);
|
||||||
|
checkVariable(prj, "a", 0);
|
||||||
|
checkVariable(prj, "b", 1);
|
||||||
|
checkVariable(prj, "c", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testExportWithRemovalFake() throws Exception {
|
||||||
|
String prjName= "__testExportWithRemovalFake__";
|
||||||
|
ICProject prj= createProject(prjName);
|
||||||
|
String loc= IndexerPreferences.getIndexImportLocation(prj.getProject());
|
||||||
|
checkVariable(prj, "a", 1);
|
||||||
|
checkVariable(prj, "b", 1);
|
||||||
|
checkVariable(prj, "c", 1);
|
||||||
|
|
||||||
|
// export the project.
|
||||||
|
fPDOMManager.export(prj, loc, 0, NPM);
|
||||||
|
fPDOMManager.joinIndexer(INDEXER_WAIT_TIME, NPM);
|
||||||
|
|
||||||
|
// set indexer to the fake one.
|
||||||
|
fPDOMManager.setIndexerId(prj, FakeIndexer.ID);
|
||||||
|
IndexerPreferences.setScope(prj.getProject(), IndexerPreferences.SCOPE_PROJECT_SHARED);
|
||||||
|
new ProjectScope(prj.getProject()).getNode(CCorePlugin.PLUGIN_ID).flush();
|
||||||
|
checkVariable(prj, "a", 0);
|
||||||
|
checkVariable(prj, "b", 0);
|
||||||
|
checkVariable(prj, "c", 0);
|
||||||
|
|
||||||
|
// delete file
|
||||||
|
prj.getProject().getFile("a.cpp").delete(true, NPM);
|
||||||
|
prj.getProject().delete(false, true, NPM);
|
||||||
|
unregisterProject(prj);
|
||||||
|
|
||||||
|
// import project
|
||||||
|
prj = recreateProject(prjName);
|
||||||
|
registerProject(prj);
|
||||||
|
checkVariable(prj, "a", 0);
|
||||||
|
checkVariable(prj, "b", 1);
|
||||||
|
checkVariable(prj, "c", 1);
|
||||||
|
}
|
||||||
|
}
|
|
@ -19,5 +19,13 @@
|
||||||
</run>
|
</run>
|
||||||
</cextension>
|
</cextension>
|
||||||
</extension>
|
</extension>
|
||||||
|
<extension
|
||||||
|
id="FakeIndexer"
|
||||||
|
name="FakeIndexer"
|
||||||
|
point="org.eclipse.cdt.core.CIndexer">
|
||||||
|
<run
|
||||||
|
class="org.eclipse.cdt.internal.index.tests.FakeIndexer">
|
||||||
|
</run>
|
||||||
|
</extension>
|
||||||
|
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2006 Wind River Systems, Inc. and others.
|
* Copyright (c) 2006, 2007 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
|
||||||
|
@ -74,6 +74,9 @@ public class BaseTestCase extends TestCase {
|
||||||
if (name.startsWith("test") || (prefix != null && !name.startsWith(prefix))) {
|
if (name.startsWith("test") || (prefix != null && !name.startsWith(prefix))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (name.equals("tearDown") || name.equals("setUp")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (Modifier.isPublic(m.getModifiers())) {
|
if (Modifier.isPublic(m.getModifiers())) {
|
||||||
Class[] parameters= m.getParameterTypes();
|
Class[] parameters= m.getParameterTypes();
|
||||||
Class returnType= m.getReturnType();
|
Class returnType= m.getReturnType();
|
||||||
|
|
|
@ -40,7 +40,6 @@ import org.eclipse.cdt.core.model.CoreModel;
|
||||||
import org.eclipse.cdt.core.model.ICElementDelta;
|
import org.eclipse.cdt.core.model.ICElementDelta;
|
||||||
import org.eclipse.cdt.core.model.ICProject;
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
import org.eclipse.cdt.core.model.IElementChangedListener;
|
import org.eclipse.cdt.core.model.IElementChangedListener;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
|
||||||
import org.eclipse.cdt.internal.core.CCoreInternals;
|
import org.eclipse.cdt.internal.core.CCoreInternals;
|
||||||
import org.eclipse.cdt.internal.core.index.IIndexFragment;
|
import org.eclipse.cdt.internal.core.index.IIndexFragment;
|
||||||
import org.eclipse.cdt.internal.core.index.IWritableIndex;
|
import org.eclipse.cdt.internal.core.index.IWritableIndex;
|
||||||
|
@ -54,6 +53,7 @@ import org.eclipse.cdt.internal.core.pdom.dom.PDOMProjectIndexLocationConverter;
|
||||||
import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences;
|
import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences;
|
||||||
import org.eclipse.cdt.internal.core.pdom.indexer.PDOMRebuildTask;
|
import org.eclipse.cdt.internal.core.pdom.indexer.PDOMRebuildTask;
|
||||||
import org.eclipse.cdt.internal.core.pdom.indexer.PDOMResourceDeltaTask;
|
import org.eclipse.cdt.internal.core.pdom.indexer.PDOMResourceDeltaTask;
|
||||||
|
import org.eclipse.cdt.internal.core.pdom.indexer.PDOMUpdateTask;
|
||||||
import org.eclipse.cdt.internal.core.pdom.indexer.nulli.PDOMNullIndexer;
|
import org.eclipse.cdt.internal.core.pdom.indexer.nulli.PDOMNullIndexer;
|
||||||
import org.eclipse.core.resources.IFolder;
|
import org.eclipse.core.resources.IFolder;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
|
@ -112,7 +112,6 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen
|
||||||
|
|
||||||
private static final ISchedulingRule NOTIFICATION_SCHEDULING_RULE = new PerInstanceSchedulingRule();
|
private static final ISchedulingRule NOTIFICATION_SCHEDULING_RULE = new PerInstanceSchedulingRule();
|
||||||
private static final ISchedulingRule INDEXER_SCHEDULING_RULE = new PerInstanceSchedulingRule();
|
private static final ISchedulingRule INDEXER_SCHEDULING_RULE = new PerInstanceSchedulingRule();
|
||||||
private static final ITranslationUnit[] NO_TUS = new ITranslationUnit[0];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Protects indexerJob, currentTask and taskQueue.
|
* Protects indexerJob, currentTask and taskQueue.
|
||||||
|
@ -362,18 +361,13 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen
|
||||||
|
|
||||||
registerIndexer(project, indexer);
|
registerIndexer(project, indexer);
|
||||||
IPDOMIndexerTask task= null;
|
IPDOMIndexerTask task= null;
|
||||||
if (!operation.wasSuccessful()) {
|
if (operation.wasSuccessful()) {
|
||||||
task= new PDOMRebuildTask(indexer);
|
task= new PDOMUpdateTask(indexer);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ITranslationUnit[] tus= operation.getTranslationUnitsToUpdate();
|
task= new PDOMRebuildTask(indexer);
|
||||||
if (tus.length > 0) {
|
|
||||||
task= indexer.createTask(NO_TUS, tus, NO_TUS);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (task != null) {
|
|
||||||
enqueue(task);
|
|
||||||
}
|
}
|
||||||
|
enqueue(task);
|
||||||
}
|
}
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
CCorePlugin.log(e);
|
CCorePlugin.log(e);
|
||||||
|
@ -712,7 +706,6 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen
|
||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
Job.getJobManager().join(this, monitor);
|
Job.getJobManager().join(this, monitor);
|
||||||
assert Job.getJobManager().find(this).length == 0;
|
|
||||||
return true;
|
return true;
|
||||||
} catch (OperationCanceledException e1) {
|
} catch (OperationCanceledException e1) {
|
||||||
} catch (InterruptedException e1) {
|
} catch (InterruptedException e1) {
|
||||||
|
|
|
@ -77,7 +77,6 @@ public class TeamPDOMImportOperation implements IWorkspaceRunnable {
|
||||||
|
|
||||||
private ICProject fProject;
|
private ICProject fProject;
|
||||||
private boolean fSuccess;
|
private boolean fSuccess;
|
||||||
private ITranslationUnit[] fTranslationUnitsToUpdate= new ITranslationUnit[0];
|
|
||||||
private boolean fShowActivity;
|
private boolean fShowActivity;
|
||||||
|
|
||||||
public TeamPDOMImportOperation(ICProject project) {
|
public TeamPDOMImportOperation(ICProject project) {
|
||||||
|
@ -123,11 +122,6 @@ public class TeamPDOMImportOperation implements IWorkspaceRunnable {
|
||||||
return fSuccess;
|
return fSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ITranslationUnit[] getTranslationUnitsToUpdate() {
|
|
||||||
return fTranslationUnitsToUpdate;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private File getImportLocation() throws CoreException {
|
private File getImportLocation() throws CoreException {
|
||||||
IProject project= fProject.getProject();
|
IProject project= fProject.getProject();
|
||||||
String locationString= IndexerPreferences.getIndexImportLocation(project);
|
String locationString= IndexerPreferences.getIndexImportLocation(project);
|
||||||
|
@ -242,15 +236,14 @@ public class TeamPDOMImportOperation implements IWorkspaceRunnable {
|
||||||
filesToCheck.add(new FileAndChecksum(tu, checksum));
|
filesToCheck.add(new FileAndChecksum(tu, checksum));
|
||||||
i.remove();
|
i.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteFiles(pdom, 1, filesToDelete, filesToCheck, monitor);
|
|
||||||
try {
|
try {
|
||||||
fTranslationUnitsToUpdate= checkFiles(checksums, filesToCheck, monitor);
|
removeOutdatedFiles(checksums, filesToCheck, monitor);
|
||||||
}
|
}
|
||||||
catch (NoSuchAlgorithmException e) {
|
catch (NoSuchAlgorithmException e) {
|
||||||
CCorePlugin.log(e);
|
CCorePlugin.log(e);
|
||||||
}
|
}
|
||||||
|
deleteFiles(pdom, 1, filesToDelete, filesToCheck, monitor);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
pdom.releaseReadLock();
|
pdom.releaseReadLock();
|
||||||
|
@ -292,8 +285,7 @@ public class TeamPDOMImportOperation implements IWorkspaceRunnable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ITranslationUnit[] checkFiles(Map checksums, List filesToCheck, IProgressMonitor monitor) throws NoSuchAlgorithmException {
|
private void removeOutdatedFiles(Map checksums, List filesToCheck, IProgressMonitor monitor) throws NoSuchAlgorithmException {
|
||||||
List result= new ArrayList();
|
|
||||||
MessageDigest md= Checksums.getAlgorithm(checksums);
|
MessageDigest md= Checksums.getAlgorithm(checksums);
|
||||||
for (Iterator i = filesToCheck.iterator(); i.hasNext();) {
|
for (Iterator i = filesToCheck.iterator(); i.hasNext();) {
|
||||||
checkMonitor(monitor);
|
checkMonitor(monitor);
|
||||||
|
@ -306,7 +298,7 @@ public class TeamPDOMImportOperation implements IWorkspaceRunnable {
|
||||||
try {
|
try {
|
||||||
byte[] checksum= Checksums.computeChecksum(md, location.toFile());
|
byte[] checksum= Checksums.computeChecksum(md, location.toFile());
|
||||||
if (!Arrays.equals(checksum, cs.fChecksum)) {
|
if (!Arrays.equals(checksum, cs.fChecksum)) {
|
||||||
result.add(tu);
|
i.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
|
@ -315,6 +307,5 @@ public class TeamPDOMImportOperation implements IWorkspaceRunnable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (ITranslationUnit[]) result.toArray(new ITranslationUnit[result.size()]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,7 +97,10 @@ public class IndexerPreferences {
|
||||||
if (makeCopy) {
|
if (makeCopy) {
|
||||||
Preferences[] prefs= getPreferences(project, scope);
|
Preferences[] prefs= getPreferences(project, scope);
|
||||||
if (prefs[0].get(KEY_INDEXER_ID, null) == null) {
|
if (prefs[0].get(KEY_INDEXER_ID, null) == null) {
|
||||||
Properties props= getProperties(project, SCOPE_INSTANCE);
|
Preferences ppp= getLocalPreferences(project);
|
||||||
|
int oldScope= ppp.getInt(KEY_INDEXER_PREFS_SCOPE, SCOPE_INSTANCE);
|
||||||
|
|
||||||
|
Properties props= getProperties(project, oldScope);
|
||||||
setProperties(prefs[0], props);
|
setProperties(prefs[0], props);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,11 +36,17 @@ public class PDOMRebuildTask implements IPDOMIndexerTask {
|
||||||
|
|
||||||
private final IPDOMIndexer fIndexer;
|
private final IPDOMIndexer fIndexer;
|
||||||
private final IndexerProgress fProgress;
|
private final IndexerProgress fProgress;
|
||||||
|
private final boolean fCheckTimestamps;
|
||||||
private volatile IPDOMIndexerTask fDelegate;
|
private volatile IPDOMIndexerTask fDelegate;
|
||||||
|
|
||||||
public PDOMRebuildTask(IPDOMIndexer indexer) {
|
public PDOMRebuildTask(IPDOMIndexer indexer) {
|
||||||
|
this(indexer, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PDOMRebuildTask(IPDOMIndexer indexer, boolean checkTimestamps) {
|
||||||
fIndexer= indexer;
|
fIndexer= indexer;
|
||||||
fProgress= createProgress();
|
fProgress= createProgress();
|
||||||
|
fCheckTimestamps= checkTimestamps;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IndexerProgress createProgress() {
|
private IndexerProgress createProgress() {
|
||||||
|
@ -117,6 +123,9 @@ public class PDOMRebuildTask implements IPDOMIndexerTask {
|
||||||
project.accept(collector);
|
project.accept(collector);
|
||||||
ITranslationUnit[] tus= (ITranslationUnit[]) list.toArray(new ITranslationUnit[list.size()]);
|
ITranslationUnit[] tus= (ITranslationUnit[]) list.toArray(new ITranslationUnit[list.size()]);
|
||||||
fDelegate= fIndexer.createTask(tus, NO_TUS, NO_TUS);
|
fDelegate= fIndexer.createTask(tus, NO_TUS, NO_TUS);
|
||||||
|
if (fDelegate instanceof PDOMIndexerTask) {
|
||||||
|
((PDOMIndexerTask) fDelegate).setCheckTimestamps(fCheckTimestamps);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,87 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2007 Wind River Systems, Inc. and others.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Markus Schorn - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
package org.eclipse.cdt.internal.core.pdom.indexer;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
|
import org.eclipse.cdt.core.dom.IPDOMIndexer;
|
||||||
|
import org.eclipse.cdt.core.dom.IPDOMIndexerTask;
|
||||||
|
import org.eclipse.cdt.core.dom.IPDOMManager;
|
||||||
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
|
import org.eclipse.cdt.internal.core.pdom.IndexerProgress;
|
||||||
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
import org.eclipse.osgi.util.NLS;
|
||||||
|
|
||||||
|
public class PDOMUpdateTask implements IPDOMIndexerTask {
|
||||||
|
protected static final String TRUE= String.valueOf(true);
|
||||||
|
protected static final ITranslationUnit[] NO_TUS = new ITranslationUnit[0];
|
||||||
|
|
||||||
|
private final IPDOMIndexer fIndexer;
|
||||||
|
private final IndexerProgress fProgress;
|
||||||
|
private volatile IPDOMIndexerTask fDelegate;
|
||||||
|
|
||||||
|
public PDOMUpdateTask(IPDOMIndexer indexer) {
|
||||||
|
fIndexer= indexer;
|
||||||
|
fProgress= createProgress();
|
||||||
|
}
|
||||||
|
|
||||||
|
private IndexerProgress createProgress() {
|
||||||
|
IndexerProgress progress= new IndexerProgress();
|
||||||
|
progress.fTimeEstimate= 1000;
|
||||||
|
return progress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IPDOMIndexer getIndexer() {
|
||||||
|
return fIndexer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run(IProgressMonitor monitor) {
|
||||||
|
monitor.subTask(NLS.bind(Messages.PDOMIndexerTask_collectingFilesTask,
|
||||||
|
fIndexer.getProject().getElementName()));
|
||||||
|
|
||||||
|
ICProject project= fIndexer.getProject();
|
||||||
|
if (project.getProject().isOpen()) {
|
||||||
|
try {
|
||||||
|
if (!IPDOMManager.ID_NO_INDEXER.equals(fIndexer.getID())) {
|
||||||
|
createDelegate(project, monitor);
|
||||||
|
}
|
||||||
|
} catch (CoreException e) {
|
||||||
|
CCorePlugin.log(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fDelegate != null) {
|
||||||
|
fDelegate.run(monitor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized void createDelegate(ICProject project, IProgressMonitor monitor) throws CoreException {
|
||||||
|
boolean allFiles= TRUE.equals(fIndexer.getProperty(IndexerPreferences.KEY_INDEX_ALL_FILES));
|
||||||
|
List list= new ArrayList();
|
||||||
|
TranslationUnitCollector collector= new TranslationUnitCollector(list, allFiles, monitor);
|
||||||
|
project.accept(collector);
|
||||||
|
ITranslationUnit[] tus= (ITranslationUnit[]) list.toArray(new ITranslationUnit[list.size()]);
|
||||||
|
fDelegate= fIndexer.createTask(tus, NO_TUS, NO_TUS);
|
||||||
|
if (fDelegate instanceof PDOMIndexerTask) {
|
||||||
|
((PDOMIndexerTask) fDelegate).setCheckTimestamps(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public synchronized IndexerProgress getProgressInformation() {
|
||||||
|
return fDelegate != null ? fDelegate.getProgressInformation() : fProgress;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue