mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 10:16:03 +02:00
write project properties to the project pdom (fragment id)
This commit is contained in:
parent
00d0168452
commit
3fa2470a54
3 changed files with 101 additions and 0 deletions
|
@ -10,14 +10,20 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.pdom.tests;
|
package org.eclipse.cdt.internal.pdom.tests;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
import junit.framework.Test;
|
import junit.framework.Test;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.IPDOMManager;
|
import org.eclipse.cdt.core.dom.IPDOMManager;
|
||||||
|
import org.eclipse.cdt.core.index.IIndexLocationConverter;
|
||||||
|
import org.eclipse.cdt.core.index.ResourceContainerRelativeLocationConverter;
|
||||||
import org.eclipse.cdt.core.model.ICProject;
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
||||||
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
|
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
|
||||||
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.IWritableIndexFragment;
|
import org.eclipse.cdt.internal.core.index.IWritableIndexFragment;
|
||||||
|
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||||
import org.eclipse.cdt.internal.core.pdom.WritablePDOM;
|
import org.eclipse.cdt.internal.core.pdom.WritablePDOM;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||||
|
@ -59,4 +65,50 @@ public class PDOMBugsTest extends BaseTestCase {
|
||||||
pdom.releaseWriteLock(0);
|
pdom.releaseWriteLock(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testProjectPDOMProperties() throws Exception {
|
||||||
|
IWritableIndexFragment pdom = (IWritableIndexFragment) CCoreInternals.getPDOMManager().getPDOM(cproject);
|
||||||
|
pdom.acquireReadLock();
|
||||||
|
try {
|
||||||
|
String id= pdom.getProperty(IIndexFragment.PROPERTY_FRAGMENT_ID);
|
||||||
|
assertNotNull(id);
|
||||||
|
|
||||||
|
CCoreInternals.getPDOMManager().reindex(cproject);
|
||||||
|
|
||||||
|
String id2= pdom.getProperty(IIndexFragment.PROPERTY_FRAGMENT_ID);
|
||||||
|
assertNotNull(id2);
|
||||||
|
assertEquals(id, id2);
|
||||||
|
} finally {
|
||||||
|
pdom.releaseReadLock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testProjectPDOMPropertiesOnExport() throws Exception {
|
||||||
|
File tmp= new File(System.getProperty("java.io.tmpdir")+"/temp"+System.currentTimeMillis()+".pdom");
|
||||||
|
IIndexLocationConverter cvr= new ResourceContainerRelativeLocationConverter(cproject.getProject());
|
||||||
|
CCoreInternals.getPDOMManager().exportProjectPDOM(cproject, tmp, cvr);
|
||||||
|
|
||||||
|
IWritableIndexFragment pdom = new WritablePDOM(tmp, cvr);
|
||||||
|
pdom.acquireReadLock();
|
||||||
|
try {
|
||||||
|
String id= pdom.getProperty(IIndexFragment.PROPERTY_FRAGMENT_ID);
|
||||||
|
assertNotNull(id);
|
||||||
|
|
||||||
|
String id2= ((PDOM)CCoreInternals.getPDOMManager().getPDOM(cproject)).getProperty(IIndexFragment.PROPERTY_FRAGMENT_ID);
|
||||||
|
assertNotNull(id2);
|
||||||
|
assertFalse(id2.equals(id));
|
||||||
|
|
||||||
|
CCoreInternals.getPDOMManager().reindex(cproject);
|
||||||
|
|
||||||
|
String id3= pdom.getProperty(IIndexFragment.PROPERTY_FRAGMENT_ID);
|
||||||
|
assertNotNull(id3);
|
||||||
|
assertEquals(id,id3);
|
||||||
|
|
||||||
|
String id4= ((PDOM)CCoreInternals.getPDOMManager().getPDOM(cproject)).getProperty(IIndexFragment.PROPERTY_FRAGMENT_ID);
|
||||||
|
assertNotNull(id4);
|
||||||
|
assertFalse(id4.equals(id));
|
||||||
|
} finally {
|
||||||
|
pdom.releaseReadLock();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,7 @@ 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.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.IWritableIndex;
|
import org.eclipse.cdt.internal.core.index.IWritableIndex;
|
||||||
import org.eclipse.cdt.internal.core.index.IWritableIndexManager;
|
import org.eclipse.cdt.internal.core.index.IWritableIndexManager;
|
||||||
import org.eclipse.cdt.internal.core.index.IndexChangeEvent;
|
import org.eclipse.cdt.internal.core.index.IndexChangeEvent;
|
||||||
|
@ -195,7 +196,11 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen
|
||||||
storeDatabaseName(rproject, dbName);
|
storeDatabaseName(rproject, dbName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean newPDOM= !dbFile.exists();
|
||||||
pdom = new WritablePDOM(dbFile, new PDOMProjectIndexLocationConverter(rproject));
|
pdom = new WritablePDOM(dbFile, new PDOMProjectIndexLocationConverter(rproject));
|
||||||
|
if(newPDOM) {
|
||||||
|
writeProjectPDOMProperties(pdom, rproject);
|
||||||
|
}
|
||||||
pdom.addListener(this);
|
pdom.addListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -873,6 +878,11 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen
|
||||||
PDOMFile file = (PDOMFile) i.next();
|
PDOMFile file = (PDOMFile) i.next();
|
||||||
file.clear();
|
file.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ensure fragment id has a sensible value, in case callee's do not
|
||||||
|
// overwrite their own values
|
||||||
|
String oldId= pdom.getProperty(IIndexFragment.PROPERTY_FRAGMENT_ID);
|
||||||
|
newPDOM.setProperty(IIndexFragment.PROPERTY_FRAGMENT_ID, "exported."+oldId); //$NON-NLS-1$
|
||||||
} finally {
|
} finally {
|
||||||
newPDOM.releaseWriteLock();
|
newPDOM.releaseWriteLock();
|
||||||
}
|
}
|
||||||
|
@ -914,6 +924,7 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen
|
||||||
try {
|
try {
|
||||||
pdom.reloadFromFile(newFile);
|
pdom.reloadFromFile(newFile);
|
||||||
storeDatabaseName(project.getProject(), newName);
|
storeDatabaseName(project.getProject(), newName);
|
||||||
|
writeProjectPDOMProperties(pdom, project.getProject());
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
pdom.releaseWriteLock();
|
pdom.releaseWriteLock();
|
||||||
|
@ -926,4 +937,16 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen
|
||||||
operation.setOptions(options);
|
operation.setOptions(options);
|
||||||
operation.run(monitor);
|
operation.run(monitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write metadata appropriate for a project pdom
|
||||||
|
* @param pdom the pdom to write to
|
||||||
|
* @param project the project to write metadata about
|
||||||
|
* @throws CoreException
|
||||||
|
*/
|
||||||
|
public static void writeProjectPDOMProperties(WritablePDOM pdom, IProject project) throws CoreException {
|
||||||
|
String DELIM = "\0"; //$NON-NLS-1$
|
||||||
|
String id= CCorePlugin.PLUGIN_ID + ".pdom.project." + DELIM + project.getName() + DELIM; //$NON-NLS-1$
|
||||||
|
pdom.setProperty(IIndexFragment.PROPERTY_FRAGMENT_ID, id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,9 +20,12 @@ 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.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.WritablePDOM;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.osgi.util.NLS;
|
import org.eclipse.osgi.util.NLS;
|
||||||
|
@ -69,6 +72,29 @@ 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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue