diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/FakeIndexer.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/FakeIndexer.java new file mode 100644 index 00000000000..4aa6ca7c7e6 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/FakeIndexer.java @@ -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; + } + +} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexTests.java index 3bb8fddfe24..cb9086e6eb5 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexTests.java @@ -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 * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -27,6 +27,7 @@ public class IndexTests extends TestSuite { suite.addTest(IndexIncludeTest.suite()); suite.addTest(IndexBugsTests.suite()); suite.addTest(EnclosingNamesTest.suite()); + suite.addTest(TeamSharedIndexTest.suite()); return suite; } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/TeamSharedIndexTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/TeamSharedIndexTest.java new file mode 100644 index 00000000000..40f615e55b3 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/TeamSharedIndexTest.java @@ -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); + } +} diff --git a/core/org.eclipse.cdt.core.tests/plugin.xml b/core/org.eclipse.cdt.core.tests/plugin.xml index 01861baac28..e1fc57e4e7c 100644 --- a/core/org.eclipse.cdt.core.tests/plugin.xml +++ b/core/org.eclipse.cdt.core.tests/plugin.xml @@ -19,5 +19,13 @@ + + + + diff --git a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/BaseTestCase.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/BaseTestCase.java index a4fbdcaece7..625f8e1fae4 100644 --- a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/BaseTestCase.java +++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/BaseTestCase.java @@ -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 * are made available under the terms of the Eclipse Public License v1.0 * 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))) { return; } + if (name.equals("tearDown") || name.equals("setUp")) { + return; + } if (Modifier.isPublic(m.getModifiers())) { Class[] parameters= m.getParameterTypes(); Class returnType= m.getReturnType(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java index 3e09e95f43e..533d5a274ec 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java @@ -40,7 +40,6 @@ import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.ICElementDelta; import org.eclipse.cdt.core.model.ICProject; 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.index.IIndexFragment; 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.PDOMRebuildTask; 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.core.resources.IFolder; 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 INDEXER_SCHEDULING_RULE = new PerInstanceSchedulingRule(); - private static final ITranslationUnit[] NO_TUS = new ITranslationUnit[0]; /** * Protects indexerJob, currentTask and taskQueue. @@ -362,18 +361,13 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen registerIndexer(project, indexer); IPDOMIndexerTask task= null; - if (!operation.wasSuccessful()) { - task= new PDOMRebuildTask(indexer); + if (operation.wasSuccessful()) { + task= new PDOMUpdateTask(indexer); } else { - ITranslationUnit[] tus= operation.getTranslationUnitsToUpdate(); - if (tus.length > 0) { - task= indexer.createTask(NO_TUS, tus, NO_TUS); - } - } - if (task != null) { - enqueue(task); + task= new PDOMRebuildTask(indexer); } + enqueue(task); } } catch (CoreException e) { CCorePlugin.log(e); @@ -712,7 +706,6 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen try { try { Job.getJobManager().join(this, monitor); - assert Job.getJobManager().find(this).length == 0; return true; } catch (OperationCanceledException e1) { } catch (InterruptedException e1) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/TeamPDOMImportOperation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/TeamPDOMImportOperation.java index dec56d12a8b..30c23587965 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/TeamPDOMImportOperation.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/TeamPDOMImportOperation.java @@ -77,7 +77,6 @@ public class TeamPDOMImportOperation implements IWorkspaceRunnable { private ICProject fProject; private boolean fSuccess; - private ITranslationUnit[] fTranslationUnitsToUpdate= new ITranslationUnit[0]; private boolean fShowActivity; public TeamPDOMImportOperation(ICProject project) { @@ -123,11 +122,6 @@ public class TeamPDOMImportOperation implements IWorkspaceRunnable { return fSuccess; } - public ITranslationUnit[] getTranslationUnitsToUpdate() { - return fTranslationUnitsToUpdate; - } - - private File getImportLocation() throws CoreException { IProject project= fProject.getProject(); String locationString= IndexerPreferences.getIndexImportLocation(project); @@ -242,15 +236,14 @@ public class TeamPDOMImportOperation implements IWorkspaceRunnable { filesToCheck.add(new FileAndChecksum(tu, checksum)); i.remove(); } - } - - deleteFiles(pdom, 1, filesToDelete, filesToCheck, monitor); + } try { - fTranslationUnitsToUpdate= checkFiles(checksums, filesToCheck, monitor); + removeOutdatedFiles(checksums, filesToCheck, monitor); } catch (NoSuchAlgorithmException e) { CCorePlugin.log(e); } + deleteFiles(pdom, 1, filesToDelete, filesToCheck, monitor); } finally { pdom.releaseReadLock(); @@ -292,8 +285,7 @@ public class TeamPDOMImportOperation implements IWorkspaceRunnable { } } - private ITranslationUnit[] checkFiles(Map checksums, List filesToCheck, IProgressMonitor monitor) throws NoSuchAlgorithmException { - List result= new ArrayList(); + private void removeOutdatedFiles(Map checksums, List filesToCheck, IProgressMonitor monitor) throws NoSuchAlgorithmException { MessageDigest md= Checksums.getAlgorithm(checksums); for (Iterator i = filesToCheck.iterator(); i.hasNext();) { checkMonitor(monitor); @@ -306,7 +298,7 @@ public class TeamPDOMImportOperation implements IWorkspaceRunnable { try { byte[] checksum= Checksums.computeChecksum(md, location.toFile()); if (!Arrays.equals(checksum, cs.fChecksum)) { - result.add(tu); + i.remove(); } } catch (IOException e) { @@ -315,6 +307,5 @@ public class TeamPDOMImportOperation implements IWorkspaceRunnable { } } } - return (ITranslationUnit[]) result.toArray(new ITranslationUnit[result.size()]); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/IndexerPreferences.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/IndexerPreferences.java index 3ac5368dc3e..df61e784f26 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/IndexerPreferences.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/IndexerPreferences.java @@ -97,7 +97,10 @@ public class IndexerPreferences { if (makeCopy) { Preferences[] prefs= getPreferences(project, scope); 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); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMRebuildTask.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMRebuildTask.java index df115a190cb..a973910188b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMRebuildTask.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMRebuildTask.java @@ -36,11 +36,17 @@ public class PDOMRebuildTask implements IPDOMIndexerTask { private final IPDOMIndexer fIndexer; private final IndexerProgress fProgress; + private final boolean fCheckTimestamps; private volatile IPDOMIndexerTask fDelegate; public PDOMRebuildTask(IPDOMIndexer indexer) { + this(indexer, false); + } + + public PDOMRebuildTask(IPDOMIndexer indexer, boolean checkTimestamps) { fIndexer= indexer; fProgress= createProgress(); + fCheckTimestamps= checkTimestamps; } private IndexerProgress createProgress() { @@ -117,6 +123,9 @@ public class PDOMRebuildTask implements IPDOMIndexerTask { 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(fCheckTimestamps); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMUpdateTask.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMUpdateTask.java new file mode 100644 index 00000000000..c62a31cdd66 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMUpdateTask.java @@ -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; + } +}