1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-30 21:55:31 +02:00

178856: use the default settings configuration for index fragments via CIndex extension point

This commit is contained in:
Andrew Ferguson 2007-05-08 15:24:42 +00:00
parent 15a448bf76
commit 6b053aa52a
4 changed files with 173 additions and 65 deletions

View file

@ -25,18 +25,29 @@ import org.eclipse.core.runtime.CoreException;
* project lifecycles.
*/
public class DummyProvider1 implements IReadOnlyPDOMProvider {
static List trace = Collections.synchronizedList(new ArrayList());
static List prjTrace= Collections.synchronizedList(new ArrayList());
static List cfgTrace= Collections.synchronizedList(new ArrayList());
public static void reset() {
prjTrace.clear();
cfgTrace.clear();
}
public static List getProjectsTrace() {
return trace;
return prjTrace;
}
public static List getCfgsTrace() {
return cfgTrace;
}
public IPDOMDescriptor[] getDescriptors(ICConfigurationDescription config) {
cfgTrace.add(config);
return new IPDOMDescriptor[0];
}
public boolean providesFor(ICProject project) throws CoreException {
trace.add(project);
prjTrace.add(project);
return true;
}
}

View file

@ -39,6 +39,7 @@ import org.eclipse.cdt.core.settings.model.ICFileDescription;
import org.eclipse.cdt.core.settings.model.ICFolderDescription;
import org.eclipse.cdt.core.settings.model.ICLanguageSetting;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionPreferences;
import org.eclipse.cdt.core.settings.model.ICResourceDescription;
import org.eclipse.cdt.core.settings.model.ICSettingContainer;
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
@ -48,6 +49,7 @@ import org.eclipse.cdt.core.settings.model.ICStorageElement;
import org.eclipse.cdt.core.settings.model.ICTargetPlatformSetting;
import org.eclipse.cdt.core.settings.model.WriteAccessException;
import org.eclipse.cdt.core.settings.model.extension.CConfigurationData;
import org.eclipse.cdt.core.settings.model.extension.impl.CDefaultConfigurationData;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.internal.core.index.IIndexFragment;
import org.eclipse.cdt.internal.core.index.provider.IIndexFragmentProvider;
@ -65,6 +67,8 @@ import org.eclipse.core.runtime.QualifiedName;
* Example usage and test for IIndexProvider
*/
public class IndexProviderManagerTest extends IndexTestBase {
final CCorePlugin core= CCorePlugin.getDefault();
public IndexProviderManagerTest() {
super("IndexProviderManagerTest");
}
@ -74,7 +78,7 @@ public class IndexProviderManagerTest extends IndexTestBase {
}
public void testProvider_SimpleLifeCycle() throws Exception {
DummyProvider1.getProjectsTrace().clear();
DummyProvider1.reset();
List cprojects = new ArrayList(), expectedTrace = new ArrayList();
try {
for(int i=0; i<3; i++) {
@ -98,7 +102,7 @@ public class IndexProviderManagerTest extends IndexTestBase {
}
public void testProvider_OverDeleteAndAdd() throws Exception {
DummyProvider1.getProjectsTrace().clear();
DummyProvider1.reset();
List expectedTrace = new ArrayList();
ICProject cproject = null;
try {
@ -121,7 +125,7 @@ public class IndexProviderManagerTest extends IndexTestBase {
}
public void testProvider_OverMove() throws Exception {
DummyProvider1.getProjectsTrace().clear();
DummyProvider1.reset();
List cprojects = new ArrayList();
List expectedTrace = new ArrayList();
@ -151,7 +155,68 @@ public class IndexProviderManagerTest extends IndexTestBase {
}
}
}
public void testIndexFactoryConfigurationUsage() throws Exception {
IIndex index;
ICProject cproject= CProjectHelper.createCCProject("IndexFactoryConfigurationUsageTest", IPDOMManager.ID_NO_INDEXER);
IProject project= cproject.getProject();
ICProjectDescription pd= core.getProjectDescription(project);
ICConfigurationDescription cfg1= newCfg(pd, "project", "config1");
ICConfigurationDescription cfg2= newCfg(pd, "project", "config2");
core.setProjectDescription(project, pd);
index= CCorePlugin.getIndexManager().getIndex(cproject);
CCorePlugin.getIndexManager().joinIndexer(8000, NPM);
try {
DummyProvider1.reset();
changeConfigRelations(project, ICProjectDescriptionPreferences.CONFIGS_LINK_SETTINGS_AND_ACTIVE);
assertEquals(0, DummyProvider1.getProjectsTrace().size());
assertEquals(0, DummyProvider1.getCfgsTrace().size());
changeActiveConfiguration(project, cfg1);
DummyProvider1.reset();
index= CCorePlugin.getIndexManager().getIndex(cproject);
assertEquals(0, DummyProvider1.getProjectsTrace().size());
assertEquals(1, DummyProvider1.getCfgsTrace().size());
assertEquals("project.config1", ((ICConfigurationDescription)DummyProvider1.getCfgsTrace().get(0)).getId());
changeActiveConfiguration(project, cfg2);
DummyProvider1.reset();
index= CCorePlugin.getIndexManager().getIndex(cproject);
assertEquals(0, DummyProvider1.getProjectsTrace().size());
assertEquals(1, DummyProvider1.getCfgsTrace().size());
assertEquals("project.config2", ((ICConfigurationDescription)DummyProvider1.getCfgsTrace().get(0)).getId());
DummyProvider1.reset();
changeConfigRelations(project, ICProjectDescriptionPreferences.CONFIGS_INDEPENDENT);
assertEquals(0, DummyProvider1.getProjectsTrace().size());
assertEquals(0, DummyProvider1.getCfgsTrace().size());
changeActiveConfiguration(project, cfg1);
DummyProvider1.reset();
index= CCorePlugin.getIndexManager().getIndex(cproject);
assertEquals(0, DummyProvider1.getProjectsTrace().size());
assertEquals(1, DummyProvider1.getCfgsTrace().size());
// should still be config2, as the change in active configuration does not matter
assertEquals("project.config2", ((ICConfigurationDescription)DummyProvider1.getCfgsTrace().get(0)).getId());
changeActiveConfiguration(project, cfg2);
DummyProvider1.reset();
index= CCorePlugin.getIndexManager().getIndex(cproject);
assertEquals(0, DummyProvider1.getProjectsTrace().size());
assertEquals(1, DummyProvider1.getCfgsTrace().size());
// there should be no change from the previous state (also config2)
assertEquals("project.config2", ((ICConfigurationDescription)DummyProvider1.getCfgsTrace().get(0)).getId());
} finally {
if (cproject != null) {
cproject.getProject().delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, new NullProgressMonitor());
}
}
}
public void testGetProvidedFragments() throws Exception {
ICProject cproject= CProjectHelper.createCProject("IndexProviderManagerTest", "bin", IPDOMManager.ID_NO_INDEXER);
@ -258,6 +323,26 @@ public class IndexProviderManagerTest extends IndexTestBase {
}
}
}
private ICConfigurationDescription newCfg(ICProjectDescription des, String project, String config) throws CoreException {
CDefaultConfigurationData data= new CDefaultConfigurationData(project+"."+config, project+" "+config+" name", null);
data.initEmptyData();
return des.createConfiguration(CCorePlugin.DEFAULT_PROVIDER_ID, data);
}
private void changeActiveConfiguration(IProject project, ICConfigurationDescription cfg) throws CoreException {
ICProjectDescription pd= core.getProjectDescription(project);
pd.setActiveConfiguration(pd.getConfigurationById(cfg.getId()));
core.setProjectDescription(project, pd);
CCorePlugin.getIndexManager().joinIndexer(8000, NPM);
}
private void changeConfigRelations(IProject project, int option) throws CoreException {
ICProjectDescription pd= core.getProjectDescription(project);
pd.setConfigurationRelations(option);
core.setProjectDescription(project, pd);
CCorePlugin.getIndexManager().joinIndexer(8000, NPM);
}
}
class MockStateIndexProvider implements IIndexProvider {

View file

@ -145,7 +145,20 @@ public interface ICProjectDescription extends ICSettingContainer,
*/
void setSessionProperty(QualifiedName name, Object value);
/**
* Returns the default setting ICConfigurationDescription. This is the configuration
* used by the CDT editor and views.
*
* @see ICProjectDescriptionPreferences#setConfigurationRelations(int)
* @return
*/
ICConfigurationDescription getDefaultSettingConfiguration();
/**
* Sets the default setting ICConfigurationDescription. This is the configuration
* used by the CDT editor and views.
*
* @param cfg
*/
void setDefaultSettingConfiguration(ICConfigurationDescription cfg);
}

View file

@ -58,7 +58,6 @@ public class IndexFactory {
boolean addDependent= (options & ADD_DEPENDENT) != 0;
boolean skipProvided= (options & SKIP_PROVIDED) != 0;
IndexProviderManager m = CCoreInternals.getPDOMManager().getIndexProviderManager();
HashMap map= new HashMap();
Collection selectedProjects= getProjects(projects, addDependencies, addDependent, map, new Integer(1));
@ -70,14 +69,7 @@ public class IndexFactory {
safeAddFragment(fragments, pdom);
if(!skipProvided) {
ICProjectDescription pd= CoreModel.getDefault().getProjectDescription(cproject.getProject(), false);
if(pd!=null) {
ICConfigurationDescription activeCfg= pd.getActiveConfiguration();
IIndexFragment[] pFragments= m.getProvidedIndexFragments(activeCfg);
for(int i=0; i<pFragments.length; i++) {
safeAddFragment(fragments, pFragments[i]);
}
}
safeAddProvidedFragments(cproject, fragments);
}
}
}
@ -96,15 +88,9 @@ public class IndexFactory {
ICProject cproject = (ICProject) iter.next();
IWritableIndexFragment pdom= (IWritableIndexFragment) fPDOMManager.getPDOM(cproject);
safeAddFragment(fragments, pdom);
if(!skipProvided) {
ICProjectDescription pd= CoreModel.getDefault().getProjectDescription(cproject.getProject(), false);
if(pd!=null) {
ICConfigurationDescription activeCfg= pd.getActiveConfiguration();
IIndexFragment[] pFragments= m.getProvidedIndexFragments(activeCfg);
for(int i=0; i<pFragments.length; i++) {
safeAddFragment(fragments, pFragments[i]);
}
}
safeAddProvidedFragments(cproject, fragments);
}
}
}
@ -113,6 +99,38 @@ public class IndexFactory {
return new CIndex((IIndexFragment[]) pdoms.toArray(new IIndexFragment[pdoms.size()]), primaryFragmentCount);
}
public IWritableIndex getWritableIndex(ICProject project) throws CoreException {
Collection selectedProjects= Collections.singleton(project);
Map readOnlyFrag= new LinkedHashMap();
Map fragments= new LinkedHashMap();
for (Iterator iter = selectedProjects.iterator(); iter.hasNext(); ) {
ICProject cproject = (ICProject) iter.next();
IWritableIndexFragment pdom= (IWritableIndexFragment) fPDOMManager.getPDOM(cproject);
if (pdom != null) {
safeAddFragment(fragments, pdom);
safeAddProvidedFragments(cproject, readOnlyFrag);
}
}
selectedProjects= getProjects(new ICProject[] {project}, true, false, new HashMap(), new Integer(1));
selectedProjects.remove(project);
for (Iterator iter = selectedProjects.iterator(); iter.hasNext(); ) {
ICProject cproject = (ICProject) iter.next();
safeAddFragment(readOnlyFrag, (IIndexFragment) fPDOMManager.getPDOM(cproject));
}
if (fragments.isEmpty()) {
throw new CoreException(CCorePlugin.createStatus(
MessageFormat.format(Messages.IndexFactory_errorNoSuchPDOM0, new Object[]{project.getElementName()})));
}
Collection pdoms= fragments.values();
Collection roPdoms= readOnlyFrag.values();
return new WritableCIndex((IWritableIndexFragment[]) pdoms.toArray(new IWritableIndexFragment[pdoms.size()]),
(IIndexFragment[]) roPdoms.toArray(new IIndexFragment[roPdoms.size()]) );
}
private Collection getProjects(ICProject[] projects, boolean addDependencies, boolean addDependent, HashMap map, Integer markWith) {
List projectsToSearch= new ArrayList();
@ -172,47 +190,6 @@ public class IndexFactory {
}
}
}
public IWritableIndex getWritableIndex(ICProject project) throws CoreException {
IndexProviderManager m = CCoreInternals.getPDOMManager().getIndexProviderManager();
Collection selectedProjects= Collections.singleton(project);
Map readOnlyFrag= new LinkedHashMap();
Map fragments= new LinkedHashMap();
for (Iterator iter = selectedProjects.iterator(); iter.hasNext(); ) {
ICProject p = (ICProject) iter.next();
IWritableIndexFragment pdom= (IWritableIndexFragment) fPDOMManager.getPDOM(p);
if (pdom != null) {
safeAddFragment(fragments, pdom);
ICProjectDescription pd= CoreModel.getDefault().getProjectDescription(p.getProject(), false);
if(pd!=null) {
ICConfigurationDescription activeCfg= pd.getActiveConfiguration();
IIndexFragment[] pFragments= m.getProvidedIndexFragments(activeCfg);
for(int i=0; i<pFragments.length; i++) {
safeAddFragment(readOnlyFrag, pFragments[i]);
}
}
}
}
selectedProjects= getProjects(new ICProject[] {project}, true, false, new HashMap(), new Integer(1));
selectedProjects.remove(project);
for (Iterator iter = selectedProjects.iterator(); iter.hasNext(); ) {
ICProject cproject = (ICProject) iter.next();
safeAddFragment(readOnlyFrag, (IIndexFragment) fPDOMManager.getPDOM(cproject));
}
if (fragments.isEmpty()) {
throw new CoreException(CCorePlugin.createStatus(
MessageFormat.format(Messages.IndexFactory_errorNoSuchPDOM0, new Object[]{project.getElementName()})));
}
Collection pdoms= fragments.values();
Collection roPdoms= readOnlyFrag.values();
return new WritableCIndex((IWritableIndexFragment[]) pdoms.toArray(new IWritableIndexFragment[pdoms.size()]),
(IIndexFragment[]) roPdoms.toArray(new IIndexFragment[roPdoms.size()]) );
}
/**
* Add an entry for the specified fragment. This copes with problems occuring when reading
@ -238,4 +215,26 @@ public class IndexFactory {
}
}
}
/**
* Adds ID -> IIndexFragment entries to the specified Map, for fragments provided under the
* CIndex extension point for the specified ICProject
* @param cproject
* @param fragments
*/
private void safeAddProvidedFragments(ICProject cproject, Map fragments) {
ICProjectDescription pd= CoreModel.getDefault().getProjectDescription(cproject.getProject(), false);
if(pd!=null) {
IndexProviderManager ipm = CCoreInternals.getPDOMManager().getIndexProviderManager();
ICConfigurationDescription cfg= pd.getDefaultSettingConfiguration();
try {
IIndexFragment[] pFragments= ipm.getProvidedIndexFragments(cfg);
for(int i=0; i<pFragments.length; i++) {
safeAddFragment(fragments, pFragments[i]);
}
} catch(CoreException ce) {
CCorePlugin.log(ce);
}
}
}
}