1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 10:16:03 +02:00

Fix for 178995, handling of PDOMProperties

This commit is contained in:
Markus Schorn 2007-03-28 11:04:13 +00:00
parent ea99f62e2f
commit bb895064cf
4 changed files with 27 additions and 33 deletions

View file

@ -25,6 +25,7 @@ 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.IWritableIndexFragment; import org.eclipse.cdt.internal.core.index.IWritableIndexFragment;
import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.PDOMManager;
import org.eclipse.cdt.internal.core.pdom.WritablePDOM; import org.eclipse.cdt.internal.core.pdom.WritablePDOM;
import org.eclipse.cdt.internal.core.pdom.db.ChunkCache; import org.eclipse.cdt.internal.core.pdom.db.ChunkCache;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
@ -91,7 +92,8 @@ public class PDOMBugsTest extends BaseTestCase {
File tmp= new File(System.getProperty("java.io.tmpdir")+"/temp"+System.currentTimeMillis()+".pdom"); File tmp= new File(System.getProperty("java.io.tmpdir")+"/temp"+System.currentTimeMillis()+".pdom");
IIndexLocationConverter cvr= new ResourceContainerRelativeLocationConverter(cproject.getProject()); IIndexLocationConverter cvr= new ResourceContainerRelativeLocationConverter(cproject.getProject());
CCoreInternals.getPDOMManager().exportProjectPDOM(cproject, tmp, cvr); final PDOMManager pdomManager = CCoreInternals.getPDOMManager();
pdomManager.exportProjectPDOM(cproject, tmp, cvr);
IWritableIndexFragment pdom = new WritablePDOM(tmp, cvr, new ChunkCache()); IWritableIndexFragment pdom = new WritablePDOM(tmp, cvr, new ChunkCache());
pdom.acquireReadLock(); pdom.acquireReadLock();
@ -99,19 +101,20 @@ public class PDOMBugsTest extends BaseTestCase {
String id= pdom.getProperty(IIndexFragment.PROPERTY_FRAGMENT_ID); String id= pdom.getProperty(IIndexFragment.PROPERTY_FRAGMENT_ID);
assertNotNull("Exported pdom ID is null", id); assertNotNull("Exported pdom ID is null", id);
String id2= ((PDOM)CCoreInternals.getPDOMManager().getPDOM(cproject)).getProperty(IIndexFragment.PROPERTY_FRAGMENT_ID); String id2= ((PDOM)pdomManager.getPDOM(cproject)).getProperty(IIndexFragment.PROPERTY_FRAGMENT_ID);
assertNotNull("Project pdom ID is null", id2); assertNotNull("Project pdom ID is null", id2);
assertFalse("Project pdom ID equals export PDOM id", id2.equals(id)); assertFalse("Project pdom ID equals export PDOM id", id2.equals(id));
CCoreInternals.getPDOMManager().reindex(cproject); pdomManager.reindex(cproject);
assertTrue(pdomManager.joinIndexer(4000, new NullProgressMonitor()));
String id3= pdom.getProperty(IIndexFragment.PROPERTY_FRAGMENT_ID); String id3= pdom.getProperty(IIndexFragment.PROPERTY_FRAGMENT_ID);
assertNotNull("Reindexed project pdom ID is null", id3); assertNotNull("Exported pdom ID is null after project reindex", id3);
assertEquals("Reindexex project pdom ID equals exported pdom ID", id, id3); assertEquals("Exported pdom ID hasChanged during reindex", id, id3);
String id4= ((PDOM)CCoreInternals.getPDOMManager().getPDOM(cproject)).getProperty(IIndexFragment.PROPERTY_FRAGMENT_ID); String id4= ((PDOM)pdomManager.getPDOM(cproject)).getProperty(IIndexFragment.PROPERTY_FRAGMENT_ID);
assertNotNull("Exported pdom ID is null after project reindex", id4); assertNotNull("Reindexed project pdom ID is null", id4);
assertFalse("Exported pdom ID equals project pdom ID after reindex", id4.equals(id)); assertFalse("Reindexex project pdom ID equals exported pdom ID", id4.equals(id));
} finally { } finally {
pdom.releaseReadLock(); pdom.releaseReadLock();
} }

View file

@ -73,4 +73,10 @@ public interface IWritableIndex extends IIndex {
* Returns cache misses since last reset of counters. * Returns cache misses since last reset of counters.
*/ */
long getCacheMisses(); long getCacheMisses();
/**
* Returns the primary writable fragment, or <code>null</code> if there is
* no writable fragment.
*/
IWritableIndexFragment getPrimaryWritableFragment();
} }

View file

@ -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
@ -128,4 +128,8 @@ public class WritableCIndex extends CIndex implements IWritableIndex {
fWritableFragments[i].releaseWriteLock(establishReadlockCount); fWritableFragments[i].releaseWriteLock(establishReadlockCount);
} }
} }
public IWritableIndexFragment getPrimaryWritableFragment() {
return fWritableFragments.length > 0 ? fWritableFragments[0] : null;
}
} }

View file

@ -20,8 +20,8 @@ import org.eclipse.cdt.core.dom.IPDOMIndexerTask;
import org.eclipse.cdt.core.dom.IPDOMManager; import org.eclipse.cdt.core.dom.IPDOMManager;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.core.CCoreInternals;
import org.eclipse.cdt.internal.core.index.IWritableIndex; import org.eclipse.cdt.internal.core.index.IWritableIndex;
import org.eclipse.cdt.internal.core.index.IWritableIndexFragment;
import org.eclipse.cdt.internal.core.index.IWritableIndexManager; import org.eclipse.cdt.internal.core.index.IWritableIndexManager;
import org.eclipse.cdt.internal.core.pdom.IndexerProgress; import org.eclipse.cdt.internal.core.pdom.IndexerProgress;
import org.eclipse.cdt.internal.core.pdom.PDOMManager; import org.eclipse.cdt.internal.core.pdom.PDOMManager;
@ -78,38 +78,19 @@ public class PDOMRebuildTask implements IPDOMIndexerTask {
if (fDelegate != null) { if (fDelegate != null) {
fDelegate.run(monitor); fDelegate.run(monitor);
writeProjectProperties(project);
} }
} }
/**
* Writes project metadata to the pdom
* @see PDOMManager#writeProjectPDOMProperties(WritablePDOM, org.eclipse.core.resources.IProject)
* @param project the project to write project metadata about
*/
private void writeProjectProperties(ICProject project) {
try {
PDOMManager mgr= CCoreInternals.getPDOMManager();
WritablePDOM projectPDOM= (WritablePDOM) mgr.getPDOM(project);
projectPDOM.acquireWriteLock();
try {
PDOMManager.writeProjectPDOMProperties(projectPDOM, project.getProject());
} finally {
projectPDOM.releaseWriteLock();
}
} catch(CoreException ce) {
CCorePlugin.log(ce);
} catch(InterruptedException ie) {
// no-op
}
}
private void clearIndex(ICProject project) throws CoreException, InterruptedException { private void clearIndex(ICProject project) throws CoreException, InterruptedException {
IWritableIndex index= ((IWritableIndexManager) CCorePlugin.getIndexManager()).getWritableIndex(project); IWritableIndex index= ((IWritableIndexManager) CCorePlugin.getIndexManager()).getWritableIndex(project);
// First clear the pdom // First clear the pdom
index.acquireWriteLock(0); index.acquireWriteLock(0);
try { try {
index.clear(); index.clear();
IWritableIndexFragment wf= index.getPrimaryWritableFragment();
if (wf instanceof WritablePDOM) {
PDOMManager.writeProjectPDOMProperties((WritablePDOM) wf, project.getProject());
}
} }
finally { finally {
index.releaseWriteLock(0); index.releaseWriteLock(0);