From 6b053aa52a6981a8c8a37a411f5659204e05ff74 Mon Sep 17 00:00:00 2001 From: Andrew Ferguson Date: Tue, 8 May 2007 15:24:42 +0000 Subject: [PATCH] 178856: use the default settings configuration for index fragments via CIndex extension point --- .../index/provider/test/DummyProvider1.java | 17 ++- .../index/tests/IndexProviderManagerTest.java | 93 +++++++++++++- .../settings/model/ICProjectDescription.java | 13 ++ .../cdt/internal/core/index/IndexFactory.java | 115 +++++++++--------- 4 files changed, 173 insertions(+), 65 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/index/provider/test/DummyProvider1.java b/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/index/provider/test/DummyProvider1.java index d457a680d08..199ef8f94a5 100644 --- a/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/index/provider/test/DummyProvider1.java +++ b/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/index/provider/test/DummyProvider1.java @@ -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; } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexProviderManagerTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexProviderManagerTest.java index 6a01313f59f..2f614597567 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexProviderManagerTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexProviderManagerTest.java @@ -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 { diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICProjectDescription.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICProjectDescription.java index 8f6a30f865c..0d528c0c914 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICProjectDescription.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICProjectDescription.java @@ -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); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexFactory.java index 6a4bd09ddf6..e2b3249ab8c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexFactory.java @@ -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 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