From 2e2d1f833e5bb6be4fa2089ed5a1e6dfbe74c7a3 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Mon, 23 Jan 2012 17:42:11 -0500 Subject: [PATCH] Serialization of default providers --- build/org.eclipse.cdt.make.core/plugin.xml | 3 +- build/org.eclipse.cdt.make.ui/plugin.xml | 2 - .../tests/suite/AllManagedBuildTests.java | 8 +- .../AllLanguageSettingsProvidersMBSTests.java | 3 +- .../LanguageSettingsProvidersMBSTest.java | 173 ++++++++++++ .../META-INF/MANIFEST.MF | 1 + .../managedbuilder/core/IConfiguration.java | 9 +- .../internal/core/Configuration.java | 69 ++++- .../internal/core/MultiConfiguration.java | 2 +- .../internal/core/ToolChain.java | 9 +- .../ConfigurationDataProvider.java | 72 ++++- .../ui/tests/util/TestConfiguration.java | 2 +- .../plugin.xml | 1 - .../ui/wizards/MBSWizardHandler.java | 102 +------ .../ui/wizards/NewMakeProjFromExisting.java | 10 +- .../ui/wizards/STDWizardHandler.java | 15 +- .../LanguageSettingsExtensionsTests.java | 3 + .../LanguageSettingsManagerTests.java | 21 +- ...nguageSettingsPersistenceProjectTests.java | 229 ++++++++++++++- core/org.eclipse.cdt.core.tests/plugin.xml | 6 +- .../cdt/core/testplugin/ResourceHelper.java | 67 ++++- .../ILanguageSettingsProvidersKeeper.java | 21 +- .../providers/LanguageSettingsManager.java | 22 +- .../LanguageSettingsSerializableProvider.java | 2 +- .../ScannerDiscoveryLegacySupport.java | 8 +- .../LanguageSettingsExtensionManager.java | 21 +- .../LanguageSettingsProvidersSerializer.java | 266 ++++++++++++++---- .../model/CConfigurationDescription.java | 22 +- .../model/CConfigurationDescriptionCache.java | 12 + .../model/CConfigurationSpecSettings.java | 21 +- .../xml/XmlProjectDescriptionStorage.java | 2 +- .../schema/LanguageSettingsProvider.exsd | 8 + core/org.eclipse.cdt.ui/plugin.xml | 4 +- .../LanguageSettingsProviderAssociation.exsd | 14 - ...ageSettingsProviderAssociationManager.java | 13 - .../LanguageSettingsProviderTab.java | 6 +- .../plugin.xml | 3 +- 37 files changed, 974 insertions(+), 278 deletions(-) create mode 100644 build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/LanguageSettingsProvidersMBSTest.java diff --git a/build/org.eclipse.cdt.make.core/plugin.xml b/build/org.eclipse.cdt.make.core/plugin.xml index ecdb0eb306f..9082042153d 100644 --- a/build/org.eclipse.cdt.make.core/plugin.xml +++ b/build/org.eclipse.cdt.make.core/plugin.xml @@ -188,7 +188,8 @@ class="org.eclipse.cdt.make.internal.core.scannerconfig.GCCBuildCommandParser" id="org.eclipse.cdt.make.core.build.command.parser.gcc" name="CDT GCC Build Output Parser" - parameter="(gcc)|([gc]\+\+)"> + parameter="(gcc)|([gc]\+\+)" + prefer-non-shared="true"> diff --git a/build/org.eclipse.cdt.make.ui/plugin.xml b/build/org.eclipse.cdt.make.ui/plugin.xml index 198ae158db7..df3f6cc3161 100644 --- a/build/org.eclipse.cdt.make.ui/plugin.xml +++ b/build/org.eclipse.cdt.make.ui/plugin.xml @@ -546,7 +546,6 @@ class="org.eclipse.cdt.make.core.scannerconfig.AbstractBuildCommandParser" icon="icons/obj16/log_obj.gif" page="org.eclipse.cdt.make.internal.ui.preferences.GCCBuildCommandParserOptionPage" - shared="false" ui-clear-entries="true" ui-edit-entries="false"> @@ -554,7 +553,6 @@ class="org.eclipse.cdt.make.core.scannerconfig.AbstractBuiltinSpecsDetector" icon="icons/obj16/inspect_system.gif" page="org.eclipse.cdt.make.internal.ui.scannerconfig.BuiltinSpecsDetectorOptionPage" - shared="true" ui-clear-entries="true" ui-edit-entries="false"> diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/tests/suite/AllManagedBuildTests.java b/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/tests/suite/AllManagedBuildTests.java index 72153c409f0..d777ca64be8 100644 --- a/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/tests/suite/AllManagedBuildTests.java +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/tests/suite/AllManagedBuildTests.java @@ -4,7 +4,7 @@ * 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: * IBM - Initial API and implementation * Markus Schorn (Wind River Systems) @@ -15,8 +15,8 @@ package org.eclipse.cdt.managedbuilder.tests.suite; import junit.framework.Test; import junit.framework.TestSuite; +import org.eclipse.cdt.build.core.scannerconfig.tests.AllLanguageSettingsProvidersMBSTests; import org.eclipse.cdt.build.core.scannerconfig.tests.CfgScannerConfigProfileManagerTests; -import org.eclipse.cdt.build.core.scannerconfig.tests.GCCBuiltinSpecsDetectorTest; import org.eclipse.cdt.build.core.scannerconfig.tests.GCCSpecsConsoleParserTest; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.IPDOMManager; @@ -61,7 +61,9 @@ public class AllManagedBuildTests { // build.core.scannerconfig.tests suite.addTest(CfgScannerConfigProfileManagerTests.suite()); suite.addTestSuite(GCCSpecsConsoleParserTest.class); - suite.addTestSuite(GCCBuiltinSpecsDetectorTest.class); + + // language settings providers tests + suite.addTest(AllLanguageSettingsProvidersMBSTests.suite()); // managedbuilder.core.tests suite.addTest(ManagedBuildDependencyLibsTests.suite()); diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/AllLanguageSettingsProvidersMBSTests.java b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/AllLanguageSettingsProvidersMBSTests.java index c521b01d261..943ce675ad9 100644 --- a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/AllLanguageSettingsProvidersMBSTests.java +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/AllLanguageSettingsProvidersMBSTests.java @@ -11,8 +11,6 @@ package org.eclipse.cdt.build.core.scannerconfig.tests; -import org.eclipse.cdt.build.core.scannerconfig.tests.GCCBuiltinSpecsDetectorTest; - import junit.framework.TestSuite; public class AllLanguageSettingsProvidersMBSTests extends TestSuite { @@ -24,6 +22,7 @@ public class AllLanguageSettingsProvidersMBSTests extends TestSuite { public AllLanguageSettingsProvidersMBSTests() { super(AllLanguageSettingsProvidersMBSTests.class.getName()); + addTestSuite(LanguageSettingsProvidersMBSTest.class); addTestSuite(GCCBuiltinSpecsDetectorTest.class); } } diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/LanguageSettingsProvidersMBSTest.java b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/LanguageSettingsProvidersMBSTest.java new file mode 100644 index 00000000000..40e95796671 --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/LanguageSettingsProvidersMBSTest.java @@ -0,0 +1,173 @@ +/******************************************************************************* + * Copyright (c) 2010, 2012 Andrew Gvozdev 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: + * Andrew Gvozdev - Initial API and implementation + *******************************************************************************/ + package org.eclipse.cdt.build.core.scannerconfig.tests; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvidersKeeper; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsPersistenceProjectTests; +import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySupport; +import org.eclipse.cdt.core.model.CoreModel; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICProjectDescription; +import org.eclipse.cdt.core.testplugin.util.BaseTestCase; +import org.eclipse.cdt.managedbuilder.core.IConfiguration; +import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; +import org.eclipse.cdt.managedbuilder.internal.dataprovider.ConfigurationDataProvider; +import org.eclipse.cdt.managedbuilder.testplugin.ManagedBuildTestHelper; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; + +public class LanguageSettingsProvidersMBSTest extends BaseTestCase { + private static final String MBS_LANGUAGE_SETTINGS_PROVIDER_ID = ScannerDiscoveryLegacySupport.MBS_LANGUAGE_SETTINGS_PROVIDER_ID; + private static final String USER_LANGUAGE_SETTINGS_PROVIDER_ID = ScannerDiscoveryLegacySupport.USER_LANGUAGE_SETTINGS_PROVIDER_ID; + private static final String GCC_SPECS_DETECTOR_ID = "org.eclipse.cdt.managedbuilder.core.gcc.specs.detector"; + private static final String PROJECT_TYPE_EXECUTABLE_GNU = "cdt.managedbuild.target.gnu.exe"; + private static final String LANGUAGE_SETTINGS_PROJECT_XML = LanguageSettingsPersistenceProjectTests.LANGUAGE_SETTINGS_PROJECT_XML; + private static final String LANGUAGE_SETTINGS_WORKSPACE_XML = LanguageSettingsPersistenceProjectTests.LANGUAGE_SETTINGS_WORKSPACE_XML; + + @Override + protected void setUp() throws Exception { + super.setUp(); + } + + @Override + protected void tearDown() throws Exception { + ManagedBuildTestHelper.removeProject(this.getName()); + super.tearDown(); + } + + /** + * New Project Wizards do all these things + */ + private static IProject imitateNewProjectWizard(String name, String projectTypeId) throws CoreException { + IProject project = ManagedBuildTestHelper.createProject(name, projectTypeId); + ManagedBuildTestHelper.addManagedBuildNature(project); + + ICProjectDescription prjDescription = CoreModel.getDefault().getProjectDescription(project, true); + assertNotNull(prjDescription); + ICConfigurationDescription[] cfgDescriptions = prjDescription.getConfigurations(); + for (ICConfigurationDescription cfgDescription : cfgDescriptions) { + assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); + + ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, true); + IConfiguration cfg = ManagedBuildManager.getConfigurationForDescription(cfgDescription); + ConfigurationDataProvider.setDefaultLanguageSettingsProviders(cfg, cfgDescription); + + assertTrue(((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders().size() > 0); + } + + CoreModel.getDefault().setProjectDescription(project, prjDescription); + + return project; + } + + /** + */ + public void testGnuToolchainProviders() throws Exception { + IProject project = imitateNewProjectWizard(this.getName(), PROJECT_TYPE_EXECUTABLE_GNU); + + ICProjectDescription prjDescription = CoreModel.getDefault().getProjectDescription(project, false); + assertNotNull(prjDescription); + ICConfigurationDescription[] cfgDescriptions = prjDescription.getConfigurations(); + for (ICConfigurationDescription cfgDescription : cfgDescriptions) { + assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); + + List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); + { + ILanguageSettingsProvider provider = providers.get(0); + String id = provider.getId(); + assertEquals(USER_LANGUAGE_SETTINGS_PROVIDER_ID, id); + assertEquals(false, LanguageSettingsManager.isPreferShared(id)); + assertEquals(false, LanguageSettingsManager.isWorkspaceProvider(provider)); + } + { + ILanguageSettingsProvider provider = providers.get(1); + String id = provider.getId(); + assertEquals(MBS_LANGUAGE_SETTINGS_PROVIDER_ID, id); + assertEquals(true, LanguageSettingsManager.isPreferShared(id)); + assertEquals(true, LanguageSettingsManager.isWorkspaceProvider(provider)); + } + { + ILanguageSettingsProvider provider = providers.get(2); + String id = provider.getId(); + assertEquals(GCC_SPECS_DETECTOR_ID, id); + assertEquals(true, LanguageSettingsManager.isPreferShared(id)); + assertEquals(true, LanguageSettingsManager.isWorkspaceProvider(provider)); + } + assertEquals(3, providers.size()); + } + } + + /** + */ + public void testProjectPersistence_NoProviders() throws Exception { + IProject project = imitateNewProjectWizard(this.getName(), PROJECT_TYPE_EXECUTABLE_GNU); + + ICProjectDescription prjDescription = CoreModel.getDefault().getProjectDescription(project, true); + assertNotNull(prjDescription); + ICConfigurationDescription[] cfgDescriptions = prjDescription.getConfigurations(); + for (ICConfigurationDescription cfgDescription : cfgDescriptions) { + assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); + + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(new ArrayList()); + assertTrue(((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders().size() == 0); + } + + CoreModel.getDefault().setProjectDescription(project, prjDescription); + + IFile xmlStorageFile = project.getFile(LANGUAGE_SETTINGS_PROJECT_XML); + assertEquals(true, xmlStorageFile.exists()); + + String xmlPrjWspStorageFileLocation = LanguageSettingsPersistenceProjectTests.getStoreLocationInWorkspaceArea(project.getName()+'.'+LANGUAGE_SETTINGS_WORKSPACE_XML); + java.io.File xmlStorageFilePrjWsp = new java.io.File(xmlPrjWspStorageFileLocation); + assertEquals(false, xmlStorageFilePrjWsp.exists()); + + } + + /** + */ + public void testProjectPersistence_Defaults() throws Exception { + IProject project = imitateNewProjectWizard(this.getName(), PROJECT_TYPE_EXECUTABLE_GNU); + + ICProjectDescription prjDescription = CoreModel.getDefault().getProjectDescription(project, false); + assertNotNull(prjDescription); + ICConfigurationDescription[] cfgDescriptions = prjDescription.getConfigurations(); + for (ICConfigurationDescription cfgDescription : cfgDescriptions) { + assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); + + String[] defaultIds = ((ILanguageSettingsProvidersKeeper) cfgDescription).getDefaultLanguageSettingsProvidersIds(); + List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); + assertEquals(defaultIds.length, providers.size()); + for (int i = 0; i < defaultIds.length; i++) { + assertEquals(providers.get(i).getId(), defaultIds[i]); + } + assertTrue(defaultIds.length > 0); + } + + IFile xmlStorageFile = project.getFile(LANGUAGE_SETTINGS_PROJECT_XML); + assertEquals(false, xmlStorageFile.exists()); + assertEquals(false, xmlStorageFile.getParent().exists()); // .settings folder + + String xmlPrjWspStorageFileLocation = LanguageSettingsPersistenceProjectTests.getStoreLocationInWorkspaceArea(project.getName()+'.'+LANGUAGE_SETTINGS_WORKSPACE_XML); + java.io.File xmlStorageFilePrjWsp = new java.io.File(xmlPrjWspStorageFileLocation); + assertEquals(false, xmlStorageFilePrjWsp.exists()); + } + +} diff --git a/build/org.eclipse.cdt.managedbuilder.core/META-INF/MANIFEST.MF b/build/org.eclipse.cdt.managedbuilder.core/META-INF/MANIFEST.MF index 363db3a759e..13c80711101 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/META-INF/MANIFEST.MF +++ b/build/org.eclipse.cdt.managedbuilder.core/META-INF/MANIFEST.MF @@ -15,6 +15,7 @@ Export-Package: org.eclipse.cdt.build.core.scannerconfig, org.eclipse.cdt.managedbuilder.envvar, org.eclipse.cdt.managedbuilder.internal.buildmodel;x-friends:="org.eclipse.cdt.managedbuilder.ui", org.eclipse.cdt.managedbuilder.internal.core;x-friends:="org.eclipse.cdt.managedbuilder.ui", + org.eclipse.cdt.managedbuilder.internal.dataprovider;x-internal:=true, org.eclipse.cdt.managedbuilder.internal.envvar;x-internal:=true, org.eclipse.cdt.managedbuilder.internal.macros;x-friends:="org.eclipse.cdt.managedbuilder.ui", org.eclipse.cdt.managedbuilder.internal.scannerconfig;x-internal:=true, diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IConfiguration.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IConfiguration.java index b6227d36b36..8aba30dbfe9 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IConfiguration.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IConfiguration.java @@ -172,8 +172,13 @@ public interface IConfiguration extends IBuildObject, IBuildObjectPropertiesCont */ public String[] getErrorParserList(); - /** @since 8.1 */ - public String getDefaultLanguageSettingsProvidersIds(); + /** + * Returns default language settings providers IDs specified for the configuration. + * @return default language settings providers IDs. + * + * @since 8.1 + */ + public String[] getDefaultLanguageSettingsProvidersIds(); /** * Projects have C or CC natures. Tools can specify a filter so they are not diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java index c9316856981..7c2bb2ef3e0 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2011 IBM Corporation and others. + * Copyright (c) 2003, 2012 IBM Corporation 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 @@ -26,6 +26,7 @@ import java.util.Vector; import org.eclipse.cdt.build.core.scannerconfig.ICfgScannerConfigBuilderInfo2Set; import org.eclipse.cdt.build.internal.core.scannerconfig.CfgDiscoveredPathManager.PathInfoCache; +import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.ErrorParserManager; import org.eclipse.cdt.core.settings.model.CIncludePathEntry; import org.eclipse.cdt.core.settings.model.CLibraryFileEntry; @@ -86,8 +87,10 @@ import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResourceDelta; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; import org.eclipse.osgi.util.NLS; import org.osgi.framework.Version; @@ -95,6 +98,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild private static final String EMPTY_STRING = ""; //$NON-NLS-1$ private static final String EMPTY_CFG_ID = "org.eclipse.cdt.build.core.emptycfg"; //$NON-NLS-1$ + private static final String LANGUAGE_SETTINGS_PROVIDER_DELIMITER = ";"; //$NON-NLS-1$ // Parent and children private String parentId; @@ -105,7 +109,8 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild private String cleanCommand; private String artifactExtension; private String errorParserIds; - private String defaultLanguageSettingsProvidersIds; + private String defaultLanguageSettingsProvidersAttribute; + private String[] defaultLanguageSettingsProvidersIds; private String prebuildStep; private String postbuildStep; private String preannouncebuildStep; @@ -338,8 +343,8 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild if (parentConfig != null) { name = parentConfig.getName(); - // If this constructor is called to clone an existing - // configuration, the parent of the parent should be stored. + // If this constructor is called to clone an existing + // configuration, the parent of the parent should be stored. // As of 2.1, there is still one single level of inheritance to // worry about parent = parentConfig.getParent() == null ? parentConfig : parentConfig.getParent(); @@ -486,8 +491,8 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild // if(!baseCfg.isExtensionConfig) // cloneChildren = true; - // If this constructor is called to clone an existing - // configuration, the parent of the cloning config should be stored. + // If this constructor is called to clone an existing + // configuration, the parent of the cloning config should be stored. parent = baseCfg.isExtensionConfig || baseCfg.getParent() == null ? baseCfg : baseCfg.getParent(); // Copy the remaining attributes @@ -634,8 +639,8 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild if(!cloneConfig.isExtensionConfig) cloneChildren = true; - // If this constructor is called to clone an existing - // configuration, the parent of the cloning config should be stored. + // If this constructor is called to clone an existing + // configuration, the parent of the cloning config should be stored. parent = cloneConfig.isExtensionConfig || cloneConfig.getParent() == null ? cloneConfig : cloneConfig.getParent(); parentId = parent.getId(); @@ -786,7 +791,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild errorParserIds = SafeStringInterner.safeIntern(element.getAttribute(ERROR_PARSERS)); // Get the initial/default language setttings providers IDs - defaultLanguageSettingsProvidersIds = SafeStringInterner.safeIntern(element.getAttribute(LANGUAGE_SETTINGS_PROVIDERS)); + defaultLanguageSettingsProvidersAttribute = SafeStringInterner.safeIntern(element.getAttribute(LANGUAGE_SETTINGS_PROVIDERS)); // Get the artifact extension artifactExtension = SafeStringInterner.safeIntern(element.getAttribute(EXTENSION)); @@ -1460,8 +1465,52 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild return set; } + private String getDefaultLanguageSettingsProvidersAttribute() { + if (defaultLanguageSettingsProvidersAttribute == null && parent instanceof Configuration) { + defaultLanguageSettingsProvidersAttribute = ((Configuration) parent).getDefaultLanguageSettingsProvidersAttribute(); + } + + return defaultLanguageSettingsProvidersAttribute; + } + @Override - public String getDefaultLanguageSettingsProvidersIds() { + public String[] getDefaultLanguageSettingsProvidersIds() { + defaultLanguageSettingsProvidersIds = null; + if (defaultLanguageSettingsProvidersIds == null) { + getDefaultLanguageSettingsProvidersAttribute(); + if (defaultLanguageSettingsProvidersAttribute != null) { + List ids = new ArrayList(); + String[] defaultIds = defaultLanguageSettingsProvidersAttribute.split(LANGUAGE_SETTINGS_PROVIDER_DELIMITER); + for (String id : defaultIds) { + if (id != null && !id.isEmpty()) { + if (id.startsWith("-")) { + id = id.substring(1); + ids.remove(id); + } else if (!ids.contains(id)){ + if (id.contains("${Toolchain}")) { + IToolChain toolchain = getToolChain(); + if (toolchain != null) { + String toolchainProvidersIds = toolchain.getDefaultLanguageSettingsProvidersIds(); + if (toolchainProvidersIds != null) { + ids.addAll(Arrays.asList(toolchainProvidersIds.split(LANGUAGE_SETTINGS_PROVIDER_DELIMITER))); + } else { + String message = "Invalid use of ${Toolchain} tag, toolchain does not specify language settings providers. cfg=" + getId(); + ManagedBuilderCorePlugin.log(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, IStatus.ERROR, message, new Exception())); + } + } + } else { + ids.add(id); + } + } + } + + } + defaultLanguageSettingsProvidersIds = ids.toArray(new String[ids.size()]); + } else if (parent != null) { + defaultLanguageSettingsProvidersIds = parent.getDefaultLanguageSettingsProvidersIds(); + } + } + return defaultLanguageSettingsProvidersIds; } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/MultiConfiguration.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/MultiConfiguration.java index df67d68d2b4..3ce6f992212 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/MultiConfiguration.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/MultiConfiguration.java @@ -441,7 +441,7 @@ public class MultiConfiguration extends MultiItemsHolder implements } @Override - public String getDefaultLanguageSettingsProvidersIds() { + public String[] getDefaultLanguageSettingsProvidersIds() { ManagedBuilderCorePlugin.error("Default Language Settings Providers are not supported in multiconfiguration mode"); return null; } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolChain.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolChain.java index 83fddb4c70c..7bcbd388135 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolChain.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolChain.java @@ -1538,6 +1538,11 @@ public class ToolChain extends HoldsOptions implements IToolChain, IMatchKeyProv @Override public String getDefaultLanguageSettingsProvidersIds() { + if (defaultLanguageSettingsProvidersIds == null) { + if (superClass instanceof IToolChain) { + defaultLanguageSettingsProvidersIds = ((IToolChain) superClass).getDefaultLanguageSettingsProvidersIds(); + } + } return defaultLanguageSettingsProvidersIds; } @@ -1577,7 +1582,7 @@ public class ToolChain extends HoldsOptions implements IToolChain, IMatchKeyProv /* * (non-Javadoc) - * + * * @see org.eclipse.cdt.managedbuilder.core.IToolChain#getScannerConfigDiscoveryProfileId() */ @Override @@ -1597,7 +1602,7 @@ public class ToolChain extends HoldsOptions implements IToolChain, IMatchKeyProv } return scannerConfigDiscoveryProfileId; } - + /* (non-Javadoc) * @see org.eclipse.cdt.managedbuilder.core.IToolChain#setScannerConfigDiscoveryProfileId(java.lang.String) */ diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/dataprovider/ConfigurationDataProvider.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/dataprovider/ConfigurationDataProvider.java index 97d11966389..72657a9471a 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/dataprovider/ConfigurationDataProvider.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/dataprovider/ConfigurationDataProvider.java @@ -19,6 +19,10 @@ import java.util.Map; import java.util.Set; import org.eclipse.cdt.build.internal.core.scannerconfig2.CfgScannerConfigInfoFactory2; +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvidersKeeper; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; +import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySupport; import org.eclipse.cdt.core.model.ILanguageDescriptor; import org.eclipse.cdt.core.model.LanguageManager; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; @@ -532,28 +536,74 @@ public class ConfigurationDataProvider extends CConfigurationDataProvider implem } @Override - public CConfigurationData loadConfiguration(ICConfigurationDescription des, - IProgressMonitor monitor) - throws CoreException { - if(des.isPreferenceConfiguration()) - return loadPreferences(des); + public CConfigurationData loadConfiguration(ICConfigurationDescription cfgDescription, IProgressMonitor monitor) throws CoreException { + if(cfgDescription.isPreferenceConfiguration()) + return loadPreferences(cfgDescription); - IManagedBuildInfo info = getBuildInfo(des); - Configuration cfg = load(des, (ManagedProject)info.getManagedProject(), false); + IManagedBuildInfo info = getBuildInfo(cfgDescription); + Configuration cfg = load(cfgDescription, (ManagedProject)info.getManagedProject(), false); if(cfg != null){ - cfg.setConfigurationDescription(des); + cfg.setConfigurationDescription(cfgDescription); info.setValid(true); - setPersistedFlag(des); - cacheNaturesIdsUsedOnCache(des); + setPersistedFlag(cfgDescription); + cacheNaturesIdsUsedOnCache(cfgDescription); // Update the ManagedBuildInfo in the ManagedBuildManager map. Doing this creates a barrier for subsequent // ManagedBuildManager#getBuildInfo(...) see Bug 305146 for more - ManagedBuildManager.setLoaddedBuildInfo(des.getProjectDescription().getProject(), info); + ManagedBuildManager.setLoaddedBuildInfo(cfgDescription.getProjectDescription().getProject(), info); + setDefaultLanguageSettingsProvidersIds(cfg, cfgDescription); return cfg.getConfigurationData(); } return null; } + private static List getDefaultLanguageSettingsProviders(IConfiguration cfg) { + List providers = new ArrayList(); + String[] ids = cfg.getDefaultLanguageSettingsProvidersIds(); + if (ids != null) { + for (String id : ids) { + ILanguageSettingsProvider provider = null; + if (!LanguageSettingsManager.isPreferShared(id)) { + provider = LanguageSettingsManager.getExtensionProviderCopy(id, false); + } + if (provider == null) { + provider = LanguageSettingsManager.getWorkspaceProvider(id); + } + providers.add(provider); + } + } + + if (providers.isEmpty()) { + // Add MBS and User provider for unsuspecting toolchains (backward compatibility) + ILanguageSettingsProvider userProvider = LanguageSettingsManager.getExtensionProviderCopy(ScannerDiscoveryLegacySupport.USER_LANGUAGE_SETTINGS_PROVIDER_ID, true); + ILanguageSettingsProvider mbsProvider = LanguageSettingsManager.getWorkspaceProvider(ScannerDiscoveryLegacySupport.MBS_LANGUAGE_SETTINGS_PROVIDER_ID); + providers.add(userProvider); + providers.add(mbsProvider); + } + + return providers; + } + + private static void setDefaultLanguageSettingsProvidersIds(IConfiguration cfg, ICConfigurationDescription cfgDescription) { + if (cfgDescription instanceof ILanguageSettingsProvidersKeeper) { + List providers = getDefaultLanguageSettingsProviders(cfg); + String[] ids = new String[providers.size()]; + for (int i = 0; i < ids.length; i++) { + ILanguageSettingsProvider provider = providers.get(i); + ids[i] = provider.getId(); + } + ((ILanguageSettingsProvidersKeeper) cfgDescription).setDefaultLanguageSettingsProvidersIds(ids); + } + + } + + public static void setDefaultLanguageSettingsProviders(IConfiguration cfg, ICConfigurationDescription cfgDescription) { + setDefaultLanguageSettingsProvidersIds(cfg, cfgDescription); + List providers = getDefaultLanguageSettingsProviders(cfg); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); + } + + private boolean isPersistedCfg(ICConfigurationDescription cfgDes){ return cfgDes.getSessionProperty(CFG_PERSISTED_PROPERTY) != null; } diff --git a/build/org.eclipse.cdt.managedbuilder.ui.tests/src/org/eclipse/cdt/managedbuilder/ui/tests/util/TestConfiguration.java b/build/org.eclipse.cdt.managedbuilder.ui.tests/src/org/eclipse/cdt/managedbuilder/ui/tests/util/TestConfiguration.java index 038df9d297a..f09d0f26b2c 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui.tests/src/org/eclipse/cdt/managedbuilder/ui/tests/util/TestConfiguration.java +++ b/build/org.eclipse.cdt.managedbuilder.ui.tests/src/org/eclipse/cdt/managedbuilder/ui/tests/util/TestConfiguration.java @@ -208,7 +208,7 @@ public class TestConfiguration implements IConfiguration { } @Override - public String getDefaultLanguageSettingsProvidersIds() { + public String[] getDefaultLanguageSettingsProvidersIds() { // TODO Auto-generated method stub return null; } diff --git a/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml b/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml index 0d557ef995e..b82b03c7a7e 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml +++ b/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml @@ -653,7 +653,6 @@ diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/MBSWizardHandler.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/MBSWizardHandler.java index 2968615327e..832ce2bc40b 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/MBSWizardHandler.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/MBSWizardHandler.java @@ -33,7 +33,6 @@ import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager; import org.eclipse.cdt.core.settings.model.extension.CConfigurationData; import org.eclipse.cdt.core.templateengine.process.ProcessFailureException; -import org.eclipse.cdt.internal.ui.language.settings.providers.LanguageSettingsProviderAssociationManager; import org.eclipse.cdt.internal.ui.wizards.ICDTCommonProjectWizard; import org.eclipse.cdt.managedbuilder.buildproperties.IBuildProperty; import org.eclipse.cdt.managedbuilder.buildproperties.IBuildPropertyValue; @@ -46,6 +45,7 @@ import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; import org.eclipse.cdt.managedbuilder.internal.core.Configuration; import org.eclipse.cdt.managedbuilder.internal.core.ManagedBuildInfo; import org.eclipse.cdt.managedbuilder.internal.core.ManagedProject; +import org.eclipse.cdt.managedbuilder.internal.dataprovider.ConfigurationDataProvider; import org.eclipse.cdt.managedbuilder.internal.ui.Messages; import org.eclipse.cdt.managedbuilder.ui.properties.ManagedBuilderUIPlugin; import org.eclipse.cdt.ui.newui.CDTPrefUtil; @@ -93,11 +93,6 @@ public class MBSWizardHandler extends CWizardHandler { private static final String PROPERTY = "org.eclipse.cdt.build.core.buildType"; //$NON-NLS-1$ private static final String PROP_VAL = PROPERTY + ".debug"; //$NON-NLS-1$ - private static final String UI_USER_LANGUAGE_SETTINGS_PROVIDER = "org.eclipse.cdt.ui.user.LanguageSettingsProvider"; - /** @since 8.1 */ - public static final String MBS_LANGUAGE_SETTINGS_PROVIDER = "org.eclipse.cdt.managedbuilder.core.LanguageSettingsProvider"; - private static final String LANGUAGE_SETTINGS_PROVIDER_DELIMITER = ";"; - private static final String tooltip = Messages.CWizardHandler_1 + Messages.CWizardHandler_2 + @@ -613,12 +608,12 @@ public class MBSWizardHandler extends CWizardHandler { ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, isTryingNewSD); List providers; if (isTryingNewSD) { - providers = MBSWizardHandler.getLanguageSettingsProviders(config); + ConfigurationDataProvider.setDefaultLanguageSettingsProviders(config, cfgDes); } else { providers = new ArrayList(); - providers.add(LanguageSettingsManager.getWorkspaceProvider(MBSWizardHandler.MBS_LANGUAGE_SETTINGS_PROVIDER)); + providers.add(LanguageSettingsManager.getWorkspaceProvider(ScannerDiscoveryLegacySupport.MBS_LANGUAGE_SETTINGS_PROVIDER_ID)); + ((ILanguageSettingsProvidersKeeper) cfgDes).setLanguageSettingProviders(providers); } - ((ILanguageSettingsProvidersKeeper) cfgDes).setLanguageSettingProviders(providers); } else { ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, false); } @@ -866,93 +861,4 @@ public class MBSWizardHandler extends CWizardHandler { return super.canFinish(); } - private static String getLanguageSettingsProvidersStr(IToolChain toolchain) { - for (;toolchain!=null;toolchain=toolchain.getSuperClass()) { - String providersIdsStr = toolchain.getDefaultLanguageSettingsProvidersIds(); - if (providersIdsStr!=null) { - return providersIdsStr; - } - } - return ""; - } - - private static String getLanguageSettingsProvidersStr(IConfiguration cfg) { - for (;cfg!=null;cfg=cfg.getParent()) { - String providersIdsStr = cfg.getDefaultLanguageSettingsProvidersIds(); - if (providersIdsStr!=null) { - return providersIdsStr; - } - } - return ""; - } - - /** - * @since 8.1 - */ - public static List getLanguageSettingsProviders(IConfiguration cfg) { - List providers = new ArrayList(); - - String providersIdsStr = getLanguageSettingsProvidersStr(cfg); - if (providersIdsStr!=null) { - if (providersIdsStr.contains("${Toolchain}")) { - IToolChain toolchain = cfg.getToolChain(); - String toolchainProvidersIds = getLanguageSettingsProvidersStr(toolchain); - if (toolchainProvidersIds==null) { - toolchainProvidersIds=""; - } - providersIdsStr = providersIdsStr.replaceAll("\\$\\{Toolchain\\}", toolchainProvidersIds); - } - List providersIds = Arrays.asList(providersIdsStr.split(LANGUAGE_SETTINGS_PROVIDER_DELIMITER)); - for (String id : providersIds) { - id = id.trim(); - ILanguageSettingsProvider provider = null; - if (id.startsWith("-")) { - id = id.substring(1); - for (ILanguageSettingsProvider pr : providers) { - if (pr.getId().equals(id)) { - providers.remove(pr); - // Has to break as the collection is invalidated - // TODO: remove all elements or better use unique list - break; - } - } - } else if (id.length()>0) { - ILanguageSettingsProvider providerExt = LanguageSettingsManager.getExtensionProviderCopy(id, false); - if (providerExt == null || LanguageSettingsProviderAssociationManager.shouldBeShared(providerExt)) { - provider = LanguageSettingsManager.getWorkspaceProvider(id); - } else { - provider = providerExt; - } - } - if (provider!=null) { - providers.add(provider); - } - } - } - - - if (providers.isEmpty()) { - // Add MBS provider for unsuspecting toolchains (backward compatibility) - ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(MBS_LANGUAGE_SETTINGS_PROVIDER); - providers.add(provider); - } - - if (!isProviderThere(providers, UI_USER_LANGUAGE_SETTINGS_PROVIDER)) { - ILanguageSettingsProvider provider = LanguageSettingsManager.getExtensionProviderCopy(UI_USER_LANGUAGE_SETTINGS_PROVIDER, true); - providers.add(0, provider); - } - - return providers; - } - - private static boolean isProviderThere(List providers, String id) { - for (ILanguageSettingsProvider provider : providers) { - if (provider.getId().equals(id)) { - return true; - } - } - return false; - } - - } diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/NewMakeProjFromExisting.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/NewMakeProjFromExisting.java index cf44315d0c6..f94ad593132 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/NewMakeProjFromExisting.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/NewMakeProjFromExisting.java @@ -32,6 +32,7 @@ import org.eclipse.cdt.managedbuilder.internal.core.Configuration; import org.eclipse.cdt.managedbuilder.internal.core.ManagedBuildInfo; import org.eclipse.cdt.managedbuilder.internal.core.ManagedProject; import org.eclipse.cdt.managedbuilder.internal.core.ToolChain; +import org.eclipse.cdt.managedbuilder.internal.dataprovider.ConfigurationDataProvider; import org.eclipse.cdt.managedbuilder.internal.ui.Messages; import org.eclipse.cdt.managedbuilder.ui.properties.ManagedBuilderUIPlugin; import org.eclipse.core.resources.IProject; @@ -122,14 +123,13 @@ public class NewMakeProjFromExisting extends Wizard implements IImportWizard, IN if (cfgDes instanceof ILanguageSettingsProvidersKeeper) { ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, isTryingNewSD); - List providers; if (isTryingNewSD) { - providers = MBSWizardHandler.getLanguageSettingsProviders(config); + ConfigurationDataProvider.setDefaultLanguageSettingsProviders(config, cfgDes); } else { - providers = new ArrayList(); - providers.add(LanguageSettingsManager.getWorkspaceProvider(MBSWizardHandler.MBS_LANGUAGE_SETTINGS_PROVIDER)); + List providers = new ArrayList(); + providers.add(LanguageSettingsManager.getWorkspaceProvider(ScannerDiscoveryLegacySupport.MBS_LANGUAGE_SETTINGS_PROVIDER_ID)); + ((ILanguageSettingsProvidersKeeper) cfgDes).setLanguageSettingProviders(providers); } - ((ILanguageSettingsProvidersKeeper) cfgDes).setLanguageSettingProviders(providers); } else { ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, false); } diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/STDWizardHandler.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/STDWizardHandler.java index 5232b3a0d7b..d9d2049db7c 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/STDWizardHandler.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/STDWizardHandler.java @@ -31,6 +31,7 @@ import org.eclipse.cdt.managedbuilder.internal.core.Configuration; import org.eclipse.cdt.managedbuilder.internal.core.ManagedBuildInfo; import org.eclipse.cdt.managedbuilder.internal.core.ManagedProject; import org.eclipse.cdt.managedbuilder.internal.core.ToolChain; +import org.eclipse.cdt.managedbuilder.internal.dataprovider.ConfigurationDataProvider; import org.eclipse.cdt.managedbuilder.internal.ui.Messages; import org.eclipse.cdt.ui.wizards.CDTMainWizardPage; import org.eclipse.core.resources.IProject; @@ -120,14 +121,13 @@ public class STDWizardHandler extends MBSWizardHandler { } ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, isTryingNewSD); - List providers; if (isTryingNewSD) { - providers = MBSWizardHandler.getLanguageSettingsProviders(cfg); + ConfigurationDataProvider.setDefaultLanguageSettingsProviders(cfg, cfgDes); } else { - providers = new ArrayList(); - providers.add(LanguageSettingsManager.getWorkspaceProvider(MBSWizardHandler.MBS_LANGUAGE_SETTINGS_PROVIDER)); + List providers = new ArrayList(); + providers.add(LanguageSettingsManager.getWorkspaceProvider(ScannerDiscoveryLegacySupport.MBS_LANGUAGE_SETTINGS_PROVIDER_ID)); + ((ILanguageSettingsProvidersKeeper) cfgDes).setLanguageSettingProviders(providers); } - ((ILanguageSettingsProvidersKeeper) cfgDes).setLanguageSettingProviders(providers); } else { ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, false); } @@ -136,7 +136,10 @@ public class STDWizardHandler extends MBSWizardHandler { } mngr.setProjectDescription(project, des); } - public boolean canCreateWithoutToolchain() { return true; } + + public boolean canCreateWithoutToolchain() { + return true; + } @Override public void convertProject(IProject proj, IProgressMonitor monitor) throws CoreException { diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java index e3d52720616..f3efdacf527 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java @@ -27,6 +27,7 @@ import org.eclipse.cdt.core.settings.model.CMacroFileEntry; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.core.testplugin.util.BaseTestCase; +import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsExtensionManager; import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.ResourcesPlugin; @@ -356,6 +357,7 @@ public class LanguageSettingsExtensionsTests extends BaseTestCase { ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(providerExt); assertTrue(rawProvider instanceof LanguageSettingsSerializableProvider); assertTrue(LanguageSettingsManager.isEqualExtensionProvider(rawProvider, true)); + assertEquals(true, LanguageSettingsExtensionManager.isPreferShared(EXTENSION_SERIALIZABLE_PROVIDER_ID)); } // Editable providers are retrieved by copy @@ -365,6 +367,7 @@ public class LanguageSettingsExtensionsTests extends BaseTestCase { assertFalse(LanguageSettingsManager.isWorkspaceProvider(providerExt)); assertTrue(providerExt instanceof ILanguageSettingsEditableProvider); assertTrue(LanguageSettingsManager.isEqualExtensionProvider(providerExt, true)); + assertEquals(LanguageSettingsExtensionManager.isPreferShared(EXTENSION_EDITABLE_PROVIDER_ID), false); // test that different copies are not same ILanguageSettingsProvider providerExt2 = LanguageSettingsManager.getExtensionProviderCopy(EXTENSION_EDITABLE_PROVIDER_ID, true); diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java index 66855fae87a..37ab92f213c 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java @@ -60,6 +60,8 @@ public class LanguageSettingsManagerTests extends BaseTestCase { class MockConfigurationDescription extends CModelMock.DummyCConfigurationDescription implements ILanguageSettingsProvidersKeeper { List providers = new ArrayList(); + String[] defaultProvidersIds = null; + public MockConfigurationDescription(String id) { super(id); } @@ -73,6 +75,16 @@ public class LanguageSettingsManagerTests extends BaseTestCase { public List getLanguageSettingProviders() { return providers; } + + @Override + public void setDefaultLanguageSettingsProvidersIds(String[] ids) { + defaultProvidersIds = ids; + } + + @Override + public String[] getDefaultLanguageSettingsProvidersIds() { + return defaultProvidersIds; + } } private class MockProvider extends AbstractExecutableExtensionBase implements ILanguageSettingsProvider { @@ -127,7 +139,7 @@ public class LanguageSettingsManagerTests extends BaseTestCase { } /** - * Test ICConfigurationDescription API (getters and setters). + * Test ILanguageSettingsProvidersKeeper API (getters and setters). */ public void testConfigurationDescription_Providers() throws Exception { MockConfigurationDescription cfgDescription = new MockConfigurationDescription(CFG_ID); @@ -146,6 +158,13 @@ public class LanguageSettingsManagerTests extends BaseTestCase { assertEquals(provider2, actual.get(1)); assertEquals(providers.size(), actual.size()); assertNotSame(actual, providers); + + // set default providers + String[] defaultProviders = { PROVIDER_0, PROVIDER_1 }; + cfgDescription.setDefaultLanguageSettingsProvidersIds(defaultProviders); + + // get default providers + assertEquals(defaultProviders, cfgDescription.getDefaultLanguageSettingsProvidersIds()); } /** diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java index 44c65c77c25..3cf74ffaab2 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java @@ -12,6 +12,7 @@ package org.eclipse.cdt.core.language.settings.providers; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import junit.framework.TestSuite; @@ -44,21 +45,26 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { private static final String EXTENSION_BASE_PROVIDER_ID = LanguageSettingsExtensionsTests.EXTENSION_BASE_PROVIDER_ID; private static final String EXTENSION_BASE_PROVIDER_NAME = LanguageSettingsExtensionsTests.EXTENSION_BASE_PROVIDER_NAME; private static final String EXTENSION_SERIALIZABLE_PROVIDER_ID = LanguageSettingsExtensionsTests.EXTENSION_SERIALIZABLE_PROVIDER_ID; + private static final String EXTENSION_EDITABLE_PROVIDER_ID = LanguageSettingsExtensionsTests.EXTENSION_EDITABLE_PROVIDER_ID; private static final String EXTENSION_USER_PROVIDER_ID = LanguageSettingsExtensionsTests.EXTENSION_USER_PROVIDER_ID; private static final ICLanguageSettingEntry EXTENSION_SERIALIZABLE_PROVIDER_ENTRY = LanguageSettingsExtensionsTests.EXTENSION_SERIALIZABLE_PROVIDER_ENTRY; - private static final String LANGUAGE_SETTINGS_PROJECT_XML = ".settings/language.settings.xml"; - private static final String LANGUAGE_SETTINGS_WORKSPACE_XML = "language.settings.xml"; + public static final String LANGUAGE_SETTINGS_PROJECT_XML = ".settings/language.settings.xml"; + public static final String LANGUAGE_SETTINGS_WORKSPACE_XML = "language.settings.xml"; private static final String CFG_ID = "test.configuration.id.0"; private static final String CFG_ID_2 = "test.configuration.id.2"; private static final String PROVIDER_0 = "test.provider.0.id"; + private static final String PROVIDER_1 = "test.provider.1.id"; private static final String PROVIDER_2 = "test.provider.2.id"; private static final String PROVIDER_NAME_0 = "test.provider.0.name"; + private static final String PROVIDER_NAME_1 = "test.provider.1.name"; private static final String PROVIDER_NAME_2 = "test.provider.2.name"; private static final String ATTR_PARAMETER = "parameter"; private static final String CUSTOM_PARAMETER = "custom parameter"; private static final String ELEM_TEST = "test"; + private static final String ELEM_PROVIDER = "provider "; // keep space for more reliable comparison + private static final String ELEM_PROVIDER_REFERENCE = "provider-reference"; private static CoreModel coreModel = CoreModel.getDefault(); @@ -77,6 +83,15 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { public List getLanguageSettingProviders() { return providers; } + + @Override + public void setDefaultLanguageSettingsProvidersIds(String[] ids) { + } + + @Override + public String[] getDefaultLanguageSettingsProvidersIds() { + return null; + } } class MockProjectDescription extends CModelMock.DummyCProjectDescription { ICConfigurationDescription[] cfgDescriptions; @@ -215,7 +230,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { assertNotNull(cfgDescription); assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); - // try to write to it + // try to write to it providers try { List providers = new ArrayList(); ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); @@ -223,6 +238,14 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { } catch (WriteAccessException e) { // exception is expected } + + // try to write to it default providers ids + try { + ((ILanguageSettingsProvidersKeeper) cfgDescription).setDefaultLanguageSettingsProvidersIds(new String[] { PROVIDER_0 }); + fail("WriteAccessException was expected but it was not throw."); + } catch (WriteAccessException e) { + // exception is expected + } } List entries = new ArrayList(); @@ -238,8 +261,8 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { assertNotNull(cfgDescription); assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); - // create a provider - LanguageSettingsSerializableProvider mockProvider = new MockLanguageSettingsEditableProvider(PROVIDER_0, PROVIDER_NAME_0); + // create a provider and write to cfgDescription + LanguageSettingsSerializableProvider mockProvider = new MockLanguageSettingsEditableProvider(PROVIDER_1, PROVIDER_NAME_1); LanguageSettingsManager.setStoringEntriesInProjectArea(mockProvider, true); mockProvider.setSettingEntries(cfgDescription, null, null, entries); List providers = new ArrayList(); @@ -248,6 +271,9 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { List storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); assertEquals(1, storedProviders.size()); + // write to cfgDescription default providers ids + ((ILanguageSettingsProvidersKeeper) cfgDescription).setDefaultLanguageSettingsProvidersIds(new String[] { PROVIDER_0 }); + // apply new project description to the project model coreModel.setProjectDescription(project, writableProjDescription); } @@ -261,16 +287,21 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { assertNotNull(cfgDescription); assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); + // double-check providers List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); assertEquals(1, providers.size()); ILanguageSettingsProvider loadedProvider = providers.get(0); assertTrue(loadedProvider instanceof MockLanguageSettingsEditableProvider); - assertEquals(PROVIDER_0, loadedProvider.getId()); - assertEquals(PROVIDER_NAME_0, loadedProvider.getName()); - + assertEquals(PROVIDER_1, loadedProvider.getId()); + assertEquals(PROVIDER_NAME_1, loadedProvider.getName()); + // double-check provider's setting entries List actual = loadedProvider.getSettingEntries(cfgDescription, null, null); assertEquals(entries.get(0), actual.get(0)); assertEquals(entries.size(), actual.size()); + + // double-check default providers ids + String[] actualDefaultProvidersIds = ((ILanguageSettingsProvidersKeeper) cfgDescription).getDefaultLanguageSettingsProvidersIds(); + assertTrue(Arrays.equals(new String[] { PROVIDER_0 }, actualDefaultProvidersIds)); } { // get writable project descriptions @@ -282,16 +313,21 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { assertNotNull(cfgDescription); assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); + // check providers List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); assertEquals(1, providers.size()); ILanguageSettingsProvider loadedProvider = providers.get(0); assertTrue(loadedProvider instanceof MockLanguageSettingsEditableProvider); - assertEquals(PROVIDER_0, loadedProvider.getId()); - assertEquals(PROVIDER_NAME_0, loadedProvider.getName()); - + assertEquals(PROVIDER_1, loadedProvider.getId()); + assertEquals(PROVIDER_NAME_1, loadedProvider.getName()); + // check provider's setting entries List actual = loadedProvider.getSettingEntries(cfgDescription, null, null); assertEquals(entries.get(0), actual.get(0)); assertEquals(entries.size(), actual.size()); + + // check default providers ids + String[] actualDefaultProvidersIds = ((ILanguageSettingsProvidersKeeper) cfgDescription).getDefaultLanguageSettingsProvidersIds(); + assertTrue(Arrays.equals(new String[] { PROVIDER_0 }, actualDefaultProvidersIds)); } } @@ -1188,7 +1224,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { * @param store - name of the store * @return location of the store in the plug-in state area */ - private static String getStoreLocationInWorkspaceArea(String store) { + public static String getStoreLocationInWorkspaceArea(String store) { IPath location = CCorePlugin.getDefault().getStateLocation().append(store); return location.toString(); } @@ -1358,5 +1394,174 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { } } + /** + */ + public void testProjectPersistence_ProviderExtensionReferenceDOM() throws Exception { + Document doc = XmlUtil.newDocument(); + Element storageElement = XmlUtil.appendElement(doc, ELEM_TEST); + + ILanguageSettingsProvider providerExt = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_BASE_PROVIDER_ID); + assertNotNull(providerExt); + + { + // create a provider + MockProjectDescription mockPrjDescription = new MockProjectDescription(new MockConfigurationDescription(CFG_ID)); + + ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations(); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); + + + ArrayList providers = new ArrayList(); + providers.add(providerExt); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); + + // prepare DOM storage + LanguageSettingsProvidersSerializer.serializeLanguageSettingsInternal(storageElement, null, mockPrjDescription); + + String xml = XmlUtil.toString(doc); + assertTrue(xml.contains(ELEM_PROVIDER_REFERENCE)); + assertTrue(xml.contains(EXTENSION_BASE_PROVIDER_ID)); + assertTrue(xml.contains(LanguageSettingsProvidersSerializer.ATTR_ID)); + assertFalse(xml.contains(LanguageSettingsProvidersSerializer.ATTR_CLASS)); + } + { + // re-load and check language settings of the newly loaded provider + MockProjectDescription mockPrjDescription = new MockProjectDescription(new MockConfigurationDescription(CFG_ID)); + LanguageSettingsProvidersSerializer.loadLanguageSettingsInternal(storageElement, null, mockPrjDescription); + + ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations(); + assertNotNull(cfgDescriptions); + assertEquals(1, cfgDescriptions.length); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); + + List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); + assertNotNull(providers); + assertEquals(1, providers.size()); + ILanguageSettingsProvider provider = providers.get(0); + assertEquals(providerExt, provider); + } + } + + /** + */ + public void testProjectPersistence_ProviderExtensionCopyDOM() throws Exception { + Document doc = XmlUtil.newDocument(); + Element storageElement = XmlUtil.appendElement(doc, ELEM_TEST); + + ILanguageSettingsProvider providerExt = LanguageSettingsManager.getExtensionProviderCopy(EXTENSION_EDITABLE_PROVIDER_ID, true); + assertNotNull(providerExt); + + { + // create a provider + MockProjectDescription mockPrjDescription = new MockProjectDescription(new MockConfigurationDescription(CFG_ID)); + + ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations(); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); + + + ArrayList providers = new ArrayList(); + providers.add(providerExt); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); + + // prepare DOM storage + LanguageSettingsProvidersSerializer.serializeLanguageSettingsInternal(storageElement, null, mockPrjDescription); + + String xml = XmlUtil.toString(doc); + assertTrue(xml.contains(ELEM_PROVIDER)); + assertTrue(xml.contains(EXTENSION_EDITABLE_PROVIDER_ID)); + assertTrue(xml.contains(LanguageSettingsProvidersSerializer.ATTR_ID)); + assertFalse(xml.contains(LanguageSettingsProvidersSerializer.ATTR_CLASS)); + } + { + // re-load and check language settings of the newly loaded provider + MockProjectDescription mockPrjDescription = new MockProjectDescription(new MockConfigurationDescription(CFG_ID)); + LanguageSettingsProvidersSerializer.loadLanguageSettingsInternal(storageElement, null, mockPrjDescription); + + ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations(); + assertNotNull(cfgDescriptions); + assertEquals(1, cfgDescriptions.length); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); + + List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); + assertNotNull(providers); + assertEquals(1, providers.size()); + ILanguageSettingsProvider provider = providers.get(0); + assertEquals(providerExt, provider); + } + } + + /** + */ + public void testProjectPersistence_Defaults() throws Exception { + // AG TODO - create and check real MBS projects with some providers + IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName()); + IFile xmlStorageFile = project.getFile(LANGUAGE_SETTINGS_PROJECT_XML); + assertFalse(xmlStorageFile.exists()); + + String xmlPrjWspStorageFileLocation = getStoreLocationInWorkspaceArea(project.getName()+'.'+LANGUAGE_SETTINGS_WORKSPACE_XML); + java.io.File xmlStorageFilePrjWsp = new java.io.File(xmlPrjWspStorageFileLocation); + assertFalse(xmlStorageFilePrjWsp.exists()); + } + + /** + */ + public void testWorkspacePersistence_ProviderExtensionCopy() throws Exception { + List entries = new ArrayList(); + List providers = new ArrayList(); + entries.add(new CIncludePathEntry("path0", 0)); + { + // get extension provider + ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_EDITABLE_PROVIDER_ID); + LanguageSettingsSerializableProvider rawProvider = (LanguageSettingsSerializableProvider) LanguageSettingsManager.getRawProvider(provider); + assertNotNull(rawProvider); + assertEquals(EXTENSION_EDITABLE_PROVIDER_ID, rawProvider.getId()); + + // add non-modified provider to the list + providers.add(provider); + } + { + // get another extension provider + ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_SERIALIZABLE_PROVIDER_ID); + LanguageSettingsSerializableProvider rawProvider = (LanguageSettingsSerializableProvider) LanguageSettingsManager.getRawProvider(provider); + assertNotNull(rawProvider); + assertEquals(EXTENSION_SERIALIZABLE_PROVIDER_ID, rawProvider.getId()); + // modify it and add it to the list + rawProvider.setSettingEntries(null, null, null, entries); + providers.add(rawProvider); + + // set and serialize language settings of workspace providers + LanguageSettingsManager.setWorkspaceProviders(providers); + LanguageSettingsManager.serializeLanguageSettingsWorkspace(); + } + { + String xmlWspStorageFileLocation = getStoreLocationInWorkspaceArea(LANGUAGE_SETTINGS_WORKSPACE_XML); + String xml = ResourceHelper.getContents(xmlWspStorageFileLocation); + // provider matching extension is not saved (extensions added automatically during loading providers) + assertFalse(xml.contains(EXTENSION_EDITABLE_PROVIDER_ID)); + // provider that differs is saved + assertTrue(xml.contains(EXTENSION_SERIALIZABLE_PROVIDER_ID)); + } + } + + /** + */ + public void testWorkspacePersistence_Defaults() throws Exception { + // reset and serialize workspace providers + LanguageSettingsManager.setWorkspaceProviders(null); + LanguageSettingsManager.serializeLanguageSettingsWorkspace(); + + // check that XML file is not created + String xmlWspStorageFileLocation = getStoreLocationInWorkspaceArea(LANGUAGE_SETTINGS_WORKSPACE_XML); + java.io.File xmlStorageFileWsp = new java.io.File(xmlWspStorageFileLocation); + assertFalse(xmlStorageFileWsp.exists()); + } } diff --git a/core/org.eclipse.cdt.core.tests/plugin.xml b/core/org.eclipse.cdt.core.tests/plugin.xml index c8588c34993..ad800c1705b 100644 --- a/core/org.eclipse.cdt.core.tests/plugin.xml +++ b/core/org.eclipse.cdt.core.tests/plugin.xml @@ -192,7 +192,8 @@ - +