1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Serialization of default providers

This commit is contained in:
Andrew Gvozdev 2012-01-23 17:42:11 -05:00
parent ded3f9e212
commit 2e2d1f833e
37 changed files with 974 additions and 278 deletions

View file

@ -188,7 +188,8 @@
class="org.eclipse.cdt.make.internal.core.scannerconfig.GCCBuildCommandParser" class="org.eclipse.cdt.make.internal.core.scannerconfig.GCCBuildCommandParser"
id="org.eclipse.cdt.make.core.build.command.parser.gcc" id="org.eclipse.cdt.make.core.build.command.parser.gcc"
name="CDT GCC Build Output Parser" name="CDT GCC Build Output Parser"
parameter="(gcc)|([gc]\+\+)"> parameter="(gcc)|([gc]\+\+)"
prefer-non-shared="true">
</provider> </provider>
</extension> </extension>

View file

@ -546,7 +546,6 @@
class="org.eclipse.cdt.make.core.scannerconfig.AbstractBuildCommandParser" class="org.eclipse.cdt.make.core.scannerconfig.AbstractBuildCommandParser"
icon="icons/obj16/log_obj.gif" icon="icons/obj16/log_obj.gif"
page="org.eclipse.cdt.make.internal.ui.preferences.GCCBuildCommandParserOptionPage" page="org.eclipse.cdt.make.internal.ui.preferences.GCCBuildCommandParserOptionPage"
shared="false"
ui-clear-entries="true" ui-clear-entries="true"
ui-edit-entries="false"> ui-edit-entries="false">
</class-association> </class-association>
@ -554,7 +553,6 @@
class="org.eclipse.cdt.make.core.scannerconfig.AbstractBuiltinSpecsDetector" class="org.eclipse.cdt.make.core.scannerconfig.AbstractBuiltinSpecsDetector"
icon="icons/obj16/inspect_system.gif" icon="icons/obj16/inspect_system.gif"
page="org.eclipse.cdt.make.internal.ui.scannerconfig.BuiltinSpecsDetectorOptionPage" page="org.eclipse.cdt.make.internal.ui.scannerconfig.BuiltinSpecsDetectorOptionPage"
shared="true"
ui-clear-entries="true" ui-clear-entries="true"
ui-edit-entries="false"> ui-edit-entries="false">
</class-association> </class-association>

View file

@ -4,7 +4,7 @@
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
@ -15,8 +15,8 @@ package org.eclipse.cdt.managedbuilder.tests.suite;
import junit.framework.Test; import junit.framework.Test;
import junit.framework.TestSuite; 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.CfgScannerConfigProfileManagerTests;
import org.eclipse.cdt.build.core.scannerconfig.tests.GCCBuiltinSpecsDetectorTest;
import org.eclipse.cdt.build.core.scannerconfig.tests.GCCSpecsConsoleParserTest; import org.eclipse.cdt.build.core.scannerconfig.tests.GCCSpecsConsoleParserTest;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMManager; import org.eclipse.cdt.core.dom.IPDOMManager;
@ -61,7 +61,9 @@ public class AllManagedBuildTests {
// build.core.scannerconfig.tests // build.core.scannerconfig.tests
suite.addTest(CfgScannerConfigProfileManagerTests.suite()); suite.addTest(CfgScannerConfigProfileManagerTests.suite());
suite.addTestSuite(GCCSpecsConsoleParserTest.class); suite.addTestSuite(GCCSpecsConsoleParserTest.class);
suite.addTestSuite(GCCBuiltinSpecsDetectorTest.class);
// language settings providers tests
suite.addTest(AllLanguageSettingsProvidersMBSTests.suite());
// managedbuilder.core.tests // managedbuilder.core.tests
suite.addTest(ManagedBuildDependencyLibsTests.suite()); suite.addTest(ManagedBuildDependencyLibsTests.suite());

View file

@ -11,8 +11,6 @@
package org.eclipse.cdt.build.core.scannerconfig.tests; package org.eclipse.cdt.build.core.scannerconfig.tests;
import org.eclipse.cdt.build.core.scannerconfig.tests.GCCBuiltinSpecsDetectorTest;
import junit.framework.TestSuite; import junit.framework.TestSuite;
public class AllLanguageSettingsProvidersMBSTests extends TestSuite { public class AllLanguageSettingsProvidersMBSTests extends TestSuite {
@ -24,6 +22,7 @@ public class AllLanguageSettingsProvidersMBSTests extends TestSuite {
public AllLanguageSettingsProvidersMBSTests() { public AllLanguageSettingsProvidersMBSTests() {
super(AllLanguageSettingsProvidersMBSTests.class.getName()); super(AllLanguageSettingsProvidersMBSTests.class.getName());
addTestSuite(LanguageSettingsProvidersMBSTest.class);
addTestSuite(GCCBuiltinSpecsDetectorTest.class); addTestSuite(GCCBuiltinSpecsDetectorTest.class);
} }
} }

View file

@ -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<ILanguageSettingsProvider> 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<ILanguageSettingsProvider>());
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<ILanguageSettingsProvider> 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());
}
}

View file

@ -15,6 +15,7 @@ Export-Package: org.eclipse.cdt.build.core.scannerconfig,
org.eclipse.cdt.managedbuilder.envvar, org.eclipse.cdt.managedbuilder.envvar,
org.eclipse.cdt.managedbuilder.internal.buildmodel;x-friends:="org.eclipse.cdt.managedbuilder.ui", 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.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.envvar;x-internal:=true,
org.eclipse.cdt.managedbuilder.internal.macros;x-friends:="org.eclipse.cdt.managedbuilder.ui", org.eclipse.cdt.managedbuilder.internal.macros;x-friends:="org.eclipse.cdt.managedbuilder.ui",
org.eclipse.cdt.managedbuilder.internal.scannerconfig;x-internal:=true, org.eclipse.cdt.managedbuilder.internal.scannerconfig;x-internal:=true,

View file

@ -172,8 +172,13 @@ public interface IConfiguration extends IBuildObject, IBuildObjectPropertiesCont
*/ */
public String[] getErrorParserList(); 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 * Projects have C or CC natures. Tools can specify a filter so they are not

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -26,6 +26,7 @@ import java.util.Vector;
import org.eclipse.cdt.build.core.scannerconfig.ICfgScannerConfigBuilderInfo2Set; import org.eclipse.cdt.build.core.scannerconfig.ICfgScannerConfigBuilderInfo2Set;
import org.eclipse.cdt.build.internal.core.scannerconfig.CfgDiscoveredPathManager.PathInfoCache; 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.ErrorParserManager;
import org.eclipse.cdt.core.settings.model.CIncludePathEntry; import org.eclipse.cdt.core.settings.model.CIncludePathEntry;
import org.eclipse.cdt.core.settings.model.CLibraryFileEntry; 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.resources.IResourceDelta;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.osgi.util.NLS; import org.eclipse.osgi.util.NLS;
import org.osgi.framework.Version; 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_STRING = ""; //$NON-NLS-1$
private static final String EMPTY_CFG_ID = "org.eclipse.cdt.build.core.emptycfg"; //$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 // Parent and children
private String parentId; private String parentId;
@ -105,7 +109,8 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild
private String cleanCommand; private String cleanCommand;
private String artifactExtension; private String artifactExtension;
private String errorParserIds; private String errorParserIds;
private String defaultLanguageSettingsProvidersIds; private String defaultLanguageSettingsProvidersAttribute;
private String[] defaultLanguageSettingsProvidersIds;
private String prebuildStep; private String prebuildStep;
private String postbuildStep; private String postbuildStep;
private String preannouncebuildStep; private String preannouncebuildStep;
@ -338,8 +343,8 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild
if (parentConfig != null) { if (parentConfig != null) {
name = parentConfig.getName(); name = parentConfig.getName();
// If this constructor is called to clone an existing // If this constructor is called to clone an existing
// configuration, the parent of the parent should be stored. // configuration, the parent of the parent should be stored.
// As of 2.1, there is still one single level of inheritance to // As of 2.1, there is still one single level of inheritance to
// worry about // worry about
parent = parentConfig.getParent() == null ? parentConfig : parentConfig.getParent(); parent = parentConfig.getParent() == null ? parentConfig : parentConfig.getParent();
@ -486,8 +491,8 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild
// if(!baseCfg.isExtensionConfig) // if(!baseCfg.isExtensionConfig)
// cloneChildren = true; // cloneChildren = true;
// If this constructor is called to clone an existing // If this constructor is called to clone an existing
// configuration, the parent of the cloning config should be stored. // configuration, the parent of the cloning config should be stored.
parent = baseCfg.isExtensionConfig || baseCfg.getParent() == null ? baseCfg : baseCfg.getParent(); parent = baseCfg.isExtensionConfig || baseCfg.getParent() == null ? baseCfg : baseCfg.getParent();
// Copy the remaining attributes // Copy the remaining attributes
@ -634,8 +639,8 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild
if(!cloneConfig.isExtensionConfig) if(!cloneConfig.isExtensionConfig)
cloneChildren = true; cloneChildren = true;
// If this constructor is called to clone an existing // If this constructor is called to clone an existing
// configuration, the parent of the cloning config should be stored. // configuration, the parent of the cloning config should be stored.
parent = cloneConfig.isExtensionConfig || cloneConfig.getParent() == null ? cloneConfig : cloneConfig.getParent(); parent = cloneConfig.isExtensionConfig || cloneConfig.getParent() == null ? cloneConfig : cloneConfig.getParent();
parentId = parent.getId(); parentId = parent.getId();
@ -786,7 +791,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild
errorParserIds = SafeStringInterner.safeIntern(element.getAttribute(ERROR_PARSERS)); errorParserIds = SafeStringInterner.safeIntern(element.getAttribute(ERROR_PARSERS));
// Get the initial/default language setttings providers IDs // 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 // Get the artifact extension
artifactExtension = SafeStringInterner.safeIntern(element.getAttribute(EXTENSION)); artifactExtension = SafeStringInterner.safeIntern(element.getAttribute(EXTENSION));
@ -1460,8 +1465,52 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild
return set; return set;
} }
private String getDefaultLanguageSettingsProvidersAttribute() {
if (defaultLanguageSettingsProvidersAttribute == null && parent instanceof Configuration) {
defaultLanguageSettingsProvidersAttribute = ((Configuration) parent).getDefaultLanguageSettingsProvidersAttribute();
}
return defaultLanguageSettingsProvidersAttribute;
}
@Override @Override
public String getDefaultLanguageSettingsProvidersIds() { public String[] getDefaultLanguageSettingsProvidersIds() {
defaultLanguageSettingsProvidersIds = null;
if (defaultLanguageSettingsProvidersIds == null) {
getDefaultLanguageSettingsProvidersAttribute();
if (defaultLanguageSettingsProvidersAttribute != null) {
List<String> ids = new ArrayList<String>();
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; return defaultLanguageSettingsProvidersIds;
} }

View file

@ -441,7 +441,7 @@ public class MultiConfiguration extends MultiItemsHolder implements
} }
@Override @Override
public String getDefaultLanguageSettingsProvidersIds() { public String[] getDefaultLanguageSettingsProvidersIds() {
ManagedBuilderCorePlugin.error("Default Language Settings Providers are not supported in multiconfiguration mode"); ManagedBuilderCorePlugin.error("Default Language Settings Providers are not supported in multiconfiguration mode");
return null; return null;
} }

View file

@ -1538,6 +1538,11 @@ public class ToolChain extends HoldsOptions implements IToolChain, IMatchKeyProv
@Override @Override
public String getDefaultLanguageSettingsProvidersIds() { public String getDefaultLanguageSettingsProvidersIds() {
if (defaultLanguageSettingsProvidersIds == null) {
if (superClass instanceof IToolChain) {
defaultLanguageSettingsProvidersIds = ((IToolChain) superClass).getDefaultLanguageSettingsProvidersIds();
}
}
return defaultLanguageSettingsProvidersIds; return defaultLanguageSettingsProvidersIds;
} }
@ -1577,7 +1582,7 @@ public class ToolChain extends HoldsOptions implements IToolChain, IMatchKeyProv
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
* @see org.eclipse.cdt.managedbuilder.core.IToolChain#getScannerConfigDiscoveryProfileId() * @see org.eclipse.cdt.managedbuilder.core.IToolChain#getScannerConfigDiscoveryProfileId()
*/ */
@Override @Override
@ -1597,7 +1602,7 @@ public class ToolChain extends HoldsOptions implements IToolChain, IMatchKeyProv
} }
return scannerConfigDiscoveryProfileId; return scannerConfigDiscoveryProfileId;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.managedbuilder.core.IToolChain#setScannerConfigDiscoveryProfileId(java.lang.String) * @see org.eclipse.cdt.managedbuilder.core.IToolChain#setScannerConfigDiscoveryProfileId(java.lang.String)
*/ */

View file

@ -19,6 +19,10 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import org.eclipse.cdt.build.internal.core.scannerconfig2.CfgScannerConfigInfoFactory2; 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.ILanguageDescriptor;
import org.eclipse.cdt.core.model.LanguageManager; import org.eclipse.cdt.core.model.LanguageManager;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
@ -532,28 +536,74 @@ public class ConfigurationDataProvider extends CConfigurationDataProvider implem
} }
@Override @Override
public CConfigurationData loadConfiguration(ICConfigurationDescription des, public CConfigurationData loadConfiguration(ICConfigurationDescription cfgDescription, IProgressMonitor monitor) throws CoreException {
IProgressMonitor monitor) if(cfgDescription.isPreferenceConfiguration())
throws CoreException { return loadPreferences(cfgDescription);
if(des.isPreferenceConfiguration())
return loadPreferences(des);
IManagedBuildInfo info = getBuildInfo(des); IManagedBuildInfo info = getBuildInfo(cfgDescription);
Configuration cfg = load(des, (ManagedProject)info.getManagedProject(), false); Configuration cfg = load(cfgDescription, (ManagedProject)info.getManagedProject(), false);
if(cfg != null){ if(cfg != null){
cfg.setConfigurationDescription(des); cfg.setConfigurationDescription(cfgDescription);
info.setValid(true); info.setValid(true);
setPersistedFlag(des); setPersistedFlag(cfgDescription);
cacheNaturesIdsUsedOnCache(des); cacheNaturesIdsUsedOnCache(cfgDescription);
// Update the ManagedBuildInfo in the ManagedBuildManager map. Doing this creates a barrier for subsequent // Update the ManagedBuildInfo in the ManagedBuildManager map. Doing this creates a barrier for subsequent
// ManagedBuildManager#getBuildInfo(...) see Bug 305146 for more // 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 cfg.getConfigurationData();
} }
return null; return null;
} }
private static List<ILanguageSettingsProvider> getDefaultLanguageSettingsProviders(IConfiguration cfg) {
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
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<ILanguageSettingsProvider> 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<ILanguageSettingsProvider> providers = getDefaultLanguageSettingsProviders(cfg);
((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers);
}
private boolean isPersistedCfg(ICConfigurationDescription cfgDes){ private boolean isPersistedCfg(ICConfigurationDescription cfgDes){
return cfgDes.getSessionProperty(CFG_PERSISTED_PROPERTY) != null; return cfgDes.getSessionProperty(CFG_PERSISTED_PROPERTY) != null;
} }

View file

@ -208,7 +208,7 @@ public class TestConfiguration implements IConfiguration {
} }
@Override @Override
public String getDefaultLanguageSettingsProvidersIds() { public String[] getDefaultLanguageSettingsProvidersIds() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }

View file

@ -653,7 +653,6 @@
<id-association <id-association
id="org.eclipse.cdt.managedbuilder.core.LanguageSettingsProvider" id="org.eclipse.cdt.managedbuilder.core.LanguageSettingsProvider"
icon="icons/obj16/mbs.gif" icon="icons/obj16/mbs.gif"
shared="true"
ui-clear-entries="false" ui-clear-entries="false"
ui-edit-entries="false"> ui-edit-entries="false">
</id-association> </id-association>

View file

@ -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.ICProjectDescriptionManager;
import org.eclipse.cdt.core.settings.model.extension.CConfigurationData; import org.eclipse.cdt.core.settings.model.extension.CConfigurationData;
import org.eclipse.cdt.core.templateengine.process.ProcessFailureException; 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.internal.ui.wizards.ICDTCommonProjectWizard;
import org.eclipse.cdt.managedbuilder.buildproperties.IBuildProperty; import org.eclipse.cdt.managedbuilder.buildproperties.IBuildProperty;
import org.eclipse.cdt.managedbuilder.buildproperties.IBuildPropertyValue; 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.Configuration;
import org.eclipse.cdt.managedbuilder.internal.core.ManagedBuildInfo; import org.eclipse.cdt.managedbuilder.internal.core.ManagedBuildInfo;
import org.eclipse.cdt.managedbuilder.internal.core.ManagedProject; 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.internal.ui.Messages;
import org.eclipse.cdt.managedbuilder.ui.properties.ManagedBuilderUIPlugin; import org.eclipse.cdt.managedbuilder.ui.properties.ManagedBuilderUIPlugin;
import org.eclipse.cdt.ui.newui.CDTPrefUtil; 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 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 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 = private static final String tooltip =
Messages.CWizardHandler_1 + Messages.CWizardHandler_1 +
Messages.CWizardHandler_2 + Messages.CWizardHandler_2 +
@ -613,12 +608,12 @@ public class MBSWizardHandler extends CWizardHandler {
ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, isTryingNewSD); ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, isTryingNewSD);
List<ILanguageSettingsProvider> providers; List<ILanguageSettingsProvider> providers;
if (isTryingNewSD) { if (isTryingNewSD) {
providers = MBSWizardHandler.getLanguageSettingsProviders(config); ConfigurationDataProvider.setDefaultLanguageSettingsProviders(config, cfgDes);
} else { } else {
providers = new ArrayList<ILanguageSettingsProvider>(); providers = new ArrayList<ILanguageSettingsProvider>();
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 { } else {
ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, false); ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, false);
} }
@ -866,93 +861,4 @@ public class MBSWizardHandler extends CWizardHandler {
return super.canFinish(); 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<ILanguageSettingsProvider> getLanguageSettingsProviders(IConfiguration cfg) {
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
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<String> 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<ILanguageSettingsProvider> providers, String id) {
for (ILanguageSettingsProvider provider : providers) {
if (provider.getId().equals(id)) {
return true;
}
}
return false;
}
} }

View file

@ -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.ManagedBuildInfo;
import org.eclipse.cdt.managedbuilder.internal.core.ManagedProject; import org.eclipse.cdt.managedbuilder.internal.core.ManagedProject;
import org.eclipse.cdt.managedbuilder.internal.core.ToolChain; 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.internal.ui.Messages;
import org.eclipse.cdt.managedbuilder.ui.properties.ManagedBuilderUIPlugin; import org.eclipse.cdt.managedbuilder.ui.properties.ManagedBuilderUIPlugin;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
@ -122,14 +123,13 @@ public class NewMakeProjFromExisting extends Wizard implements IImportWizard, IN
if (cfgDes instanceof ILanguageSettingsProvidersKeeper) { if (cfgDes instanceof ILanguageSettingsProvidersKeeper) {
ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, isTryingNewSD); ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, isTryingNewSD);
List<ILanguageSettingsProvider> providers;
if (isTryingNewSD) { if (isTryingNewSD) {
providers = MBSWizardHandler.getLanguageSettingsProviders(config); ConfigurationDataProvider.setDefaultLanguageSettingsProviders(config, cfgDes);
} else { } else {
providers = new ArrayList<ILanguageSettingsProvider>(); List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
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 { } else {
ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, false); ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, false);
} }

View file

@ -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.ManagedBuildInfo;
import org.eclipse.cdt.managedbuilder.internal.core.ManagedProject; import org.eclipse.cdt.managedbuilder.internal.core.ManagedProject;
import org.eclipse.cdt.managedbuilder.internal.core.ToolChain; 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.internal.ui.Messages;
import org.eclipse.cdt.ui.wizards.CDTMainWizardPage; import org.eclipse.cdt.ui.wizards.CDTMainWizardPage;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
@ -120,14 +121,13 @@ public class STDWizardHandler extends MBSWizardHandler {
} }
ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, isTryingNewSD); ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, isTryingNewSD);
List<ILanguageSettingsProvider> providers;
if (isTryingNewSD) { if (isTryingNewSD) {
providers = MBSWizardHandler.getLanguageSettingsProviders(cfg); ConfigurationDataProvider.setDefaultLanguageSettingsProviders(cfg, cfgDes);
} else { } else {
providers = new ArrayList<ILanguageSettingsProvider>(); List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
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 { } else {
ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, false); ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, false);
} }
@ -136,7 +136,10 @@ public class STDWizardHandler extends MBSWizardHandler {
} }
mngr.setProjectDescription(project, des); mngr.setProjectDescription(project, des);
} }
public boolean canCreateWithoutToolchain() { return true; }
public boolean canCreateWithoutToolchain() {
return true;
}
@Override @Override
public void convertProject(IProject proj, IProgressMonitor monitor) throws CoreException { public void convertProject(IProject proj, IProgressMonitor monitor) throws CoreException {

View file

@ -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.ICLanguageSettingEntry;
import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.core.settings.model.ICSettingEntry;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase; 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.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.resources.ResourcesPlugin;
@ -356,6 +357,7 @@ public class LanguageSettingsExtensionsTests extends BaseTestCase {
ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(providerExt); ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(providerExt);
assertTrue(rawProvider instanceof LanguageSettingsSerializableProvider); assertTrue(rawProvider instanceof LanguageSettingsSerializableProvider);
assertTrue(LanguageSettingsManager.isEqualExtensionProvider(rawProvider, true)); assertTrue(LanguageSettingsManager.isEqualExtensionProvider(rawProvider, true));
assertEquals(true, LanguageSettingsExtensionManager.isPreferShared(EXTENSION_SERIALIZABLE_PROVIDER_ID));
} }
// Editable providers are retrieved by copy // Editable providers are retrieved by copy
@ -365,6 +367,7 @@ public class LanguageSettingsExtensionsTests extends BaseTestCase {
assertFalse(LanguageSettingsManager.isWorkspaceProvider(providerExt)); assertFalse(LanguageSettingsManager.isWorkspaceProvider(providerExt));
assertTrue(providerExt instanceof ILanguageSettingsEditableProvider); assertTrue(providerExt instanceof ILanguageSettingsEditableProvider);
assertTrue(LanguageSettingsManager.isEqualExtensionProvider(providerExt, true)); assertTrue(LanguageSettingsManager.isEqualExtensionProvider(providerExt, true));
assertEquals(LanguageSettingsExtensionManager.isPreferShared(EXTENSION_EDITABLE_PROVIDER_ID), false);
// test that different copies are not same // test that different copies are not same
ILanguageSettingsProvider providerExt2 = LanguageSettingsManager.getExtensionProviderCopy(EXTENSION_EDITABLE_PROVIDER_ID, true); ILanguageSettingsProvider providerExt2 = LanguageSettingsManager.getExtensionProviderCopy(EXTENSION_EDITABLE_PROVIDER_ID, true);

View file

@ -60,6 +60,8 @@ public class LanguageSettingsManagerTests extends BaseTestCase {
class MockConfigurationDescription extends CModelMock.DummyCConfigurationDescription implements ILanguageSettingsProvidersKeeper { class MockConfigurationDescription extends CModelMock.DummyCConfigurationDescription implements ILanguageSettingsProvidersKeeper {
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>(); List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
String[] defaultProvidersIds = null;
public MockConfigurationDescription(String id) { public MockConfigurationDescription(String id) {
super(id); super(id);
} }
@ -73,6 +75,16 @@ public class LanguageSettingsManagerTests extends BaseTestCase {
public List<ILanguageSettingsProvider> getLanguageSettingProviders() { public List<ILanguageSettingsProvider> getLanguageSettingProviders() {
return providers; return providers;
} }
@Override
public void setDefaultLanguageSettingsProvidersIds(String[] ids) {
defaultProvidersIds = ids;
}
@Override
public String[] getDefaultLanguageSettingsProvidersIds() {
return defaultProvidersIds;
}
} }
private class MockProvider extends AbstractExecutableExtensionBase implements ILanguageSettingsProvider { 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 { public void testConfigurationDescription_Providers() throws Exception {
MockConfigurationDescription cfgDescription = new MockConfigurationDescription(CFG_ID); MockConfigurationDescription cfgDescription = new MockConfigurationDescription(CFG_ID);
@ -146,6 +158,13 @@ public class LanguageSettingsManagerTests extends BaseTestCase {
assertEquals(provider2, actual.get(1)); assertEquals(provider2, actual.get(1));
assertEquals(providers.size(), actual.size()); assertEquals(providers.size(), actual.size());
assertNotSame(actual, providers); assertNotSame(actual, providers);
// set default providers
String[] defaultProviders = { PROVIDER_0, PROVIDER_1 };
cfgDescription.setDefaultLanguageSettingsProvidersIds(defaultProviders);
// get default providers
assertEquals(defaultProviders, cfgDescription.getDefaultLanguageSettingsProvidersIds());
} }
/** /**

View file

@ -12,6 +12,7 @@
package org.eclipse.cdt.core.language.settings.providers; package org.eclipse.cdt.core.language.settings.providers;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import junit.framework.TestSuite; 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_ID = LanguageSettingsExtensionsTests.EXTENSION_BASE_PROVIDER_ID;
private static final String EXTENSION_BASE_PROVIDER_NAME = LanguageSettingsExtensionsTests.EXTENSION_BASE_PROVIDER_NAME; 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_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 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 ICLanguageSettingEntry EXTENSION_SERIALIZABLE_PROVIDER_ENTRY = LanguageSettingsExtensionsTests.EXTENSION_SERIALIZABLE_PROVIDER_ENTRY;
private static final String LANGUAGE_SETTINGS_PROJECT_XML = ".settings/language.settings.xml"; public 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_WORKSPACE_XML = "language.settings.xml";
private static final String CFG_ID = "test.configuration.id.0"; 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 CFG_ID_2 = "test.configuration.id.2";
private static final String PROVIDER_0 = "test.provider.0.id"; 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_2 = "test.provider.2.id";
private static final String PROVIDER_NAME_0 = "test.provider.0.name"; 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 PROVIDER_NAME_2 = "test.provider.2.name";
private static final String ATTR_PARAMETER = "parameter"; private static final String ATTR_PARAMETER = "parameter";
private static final String CUSTOM_PARAMETER = "custom parameter"; private static final String CUSTOM_PARAMETER = "custom parameter";
private static final String ELEM_TEST = "test"; 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(); private static CoreModel coreModel = CoreModel.getDefault();
@ -77,6 +83,15 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase {
public List<ILanguageSettingsProvider> getLanguageSettingProviders() { public List<ILanguageSettingsProvider> getLanguageSettingProviders() {
return providers; return providers;
} }
@Override
public void setDefaultLanguageSettingsProvidersIds(String[] ids) {
}
@Override
public String[] getDefaultLanguageSettingsProvidersIds() {
return null;
}
} }
class MockProjectDescription extends CModelMock.DummyCProjectDescription { class MockProjectDescription extends CModelMock.DummyCProjectDescription {
ICConfigurationDescription[] cfgDescriptions; ICConfigurationDescription[] cfgDescriptions;
@ -215,7 +230,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase {
assertNotNull(cfgDescription); assertNotNull(cfgDescription);
assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper);
// try to write to it // try to write to it providers
try { try {
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>(); List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers);
@ -223,6 +238,14 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase {
} catch (WriteAccessException e) { } catch (WriteAccessException e) {
// exception is expected // 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<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>(); List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
@ -238,8 +261,8 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase {
assertNotNull(cfgDescription); assertNotNull(cfgDescription);
assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper);
// create a provider // create a provider and write to cfgDescription
LanguageSettingsSerializableProvider mockProvider = new MockLanguageSettingsEditableProvider(PROVIDER_0, PROVIDER_NAME_0); LanguageSettingsSerializableProvider mockProvider = new MockLanguageSettingsEditableProvider(PROVIDER_1, PROVIDER_NAME_1);
LanguageSettingsManager.setStoringEntriesInProjectArea(mockProvider, true); LanguageSettingsManager.setStoringEntriesInProjectArea(mockProvider, true);
mockProvider.setSettingEntries(cfgDescription, null, null, entries); mockProvider.setSettingEntries(cfgDescription, null, null, entries);
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>(); List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
@ -248,6 +271,9 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase {
List<ILanguageSettingsProvider> storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); List<ILanguageSettingsProvider> storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders();
assertEquals(1, storedProviders.size()); 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 // apply new project description to the project model
coreModel.setProjectDescription(project, writableProjDescription); coreModel.setProjectDescription(project, writableProjDescription);
} }
@ -261,16 +287,21 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase {
assertNotNull(cfgDescription); assertNotNull(cfgDescription);
assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper);
// double-check providers
List<ILanguageSettingsProvider> providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); List<ILanguageSettingsProvider> providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders();
assertEquals(1, providers.size()); assertEquals(1, providers.size());
ILanguageSettingsProvider loadedProvider = providers.get(0); ILanguageSettingsProvider loadedProvider = providers.get(0);
assertTrue(loadedProvider instanceof MockLanguageSettingsEditableProvider); assertTrue(loadedProvider instanceof MockLanguageSettingsEditableProvider);
assertEquals(PROVIDER_0, loadedProvider.getId()); assertEquals(PROVIDER_1, loadedProvider.getId());
assertEquals(PROVIDER_NAME_0, loadedProvider.getName()); assertEquals(PROVIDER_NAME_1, loadedProvider.getName());
// double-check provider's setting entries
List<ICLanguageSettingEntry> actual = loadedProvider.getSettingEntries(cfgDescription, null, null); List<ICLanguageSettingEntry> actual = loadedProvider.getSettingEntries(cfgDescription, null, null);
assertEquals(entries.get(0), actual.get(0)); assertEquals(entries.get(0), actual.get(0));
assertEquals(entries.size(), actual.size()); 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 // get writable project descriptions
@ -282,16 +313,21 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase {
assertNotNull(cfgDescription); assertNotNull(cfgDescription);
assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper);
// check providers
List<ILanguageSettingsProvider> providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); List<ILanguageSettingsProvider> providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders();
assertEquals(1, providers.size()); assertEquals(1, providers.size());
ILanguageSettingsProvider loadedProvider = providers.get(0); ILanguageSettingsProvider loadedProvider = providers.get(0);
assertTrue(loadedProvider instanceof MockLanguageSettingsEditableProvider); assertTrue(loadedProvider instanceof MockLanguageSettingsEditableProvider);
assertEquals(PROVIDER_0, loadedProvider.getId()); assertEquals(PROVIDER_1, loadedProvider.getId());
assertEquals(PROVIDER_NAME_0, loadedProvider.getName()); assertEquals(PROVIDER_NAME_1, loadedProvider.getName());
// check provider's setting entries
List<ICLanguageSettingEntry> actual = loadedProvider.getSettingEntries(cfgDescription, null, null); List<ICLanguageSettingEntry> actual = loadedProvider.getSettingEntries(cfgDescription, null, null);
assertEquals(entries.get(0), actual.get(0)); assertEquals(entries.get(0), actual.get(0));
assertEquals(entries.size(), actual.size()); 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 * @param store - name of the store
* @return location of the store in the plug-in state area * @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); IPath location = CCorePlugin.getDefault().getStateLocation().append(store);
return location.toString(); 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<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
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<ILanguageSettingsProvider> 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<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
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<ILanguageSettingsProvider> 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<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
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());
}
} }

View file

@ -192,7 +192,8 @@
</extension> </extension>
<extension <extension
point="org.eclipse.cdt.core.LanguageSettingsProvider"> point="org.eclipse.cdt.core.LanguageSettingsProvider">
<!-- uncomment to test message about missing class in the log <!-- uncomment to test message about missing class in the log -->
<!--
<provider <provider
class="org.eclipse.cdt.core.language.settings.providers.MissingClass" class="org.eclipse.cdt.core.language.settings.providers.MissingClass"
id="org.eclipse.cdt.core.tests.missing.language.settings.provider" id="org.eclipse.cdt.core.tests.missing.language.settings.provider"
@ -265,7 +266,8 @@
<provider <provider
class="org.eclipse.cdt.core.language.settings.providers.MockLanguageSettingsEditableProvider" class="org.eclipse.cdt.core.language.settings.providers.MockLanguageSettingsEditableProvider"
id="org.eclipse.cdt.core.tests.custom.editable.language.settings.provider" id="org.eclipse.cdt.core.tests.custom.editable.language.settings.provider"
name="Test Plugin Mock Editable Language Settings Provider"> name="Test Plugin Mock Editable Language Settings Provider"
prefer-non-shared="true">
<entry <entry
kind="macro" kind="macro"
name="MACRO" name="MACRO"

View file

@ -15,11 +15,14 @@ package org.eclipse.cdt.core.testplugin;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
@ -66,7 +69,7 @@ import org.eclipse.core.runtime.jobs.Job;
public class ResourceHelper { public class ResourceHelper {
private final static IProgressMonitor NULL_MONITOR = new NullProgressMonitor(); private final static IProgressMonitor NULL_MONITOR = new NullProgressMonitor();
private static final int MAX_RETRY= 5; private static final int MAX_RETRY= 5;
private final static Set<String> externalFilesCreated = new HashSet<String>(); private final static Set<String> externalFilesCreated = new HashSet<String>();
private final static Set<IResource> resourcesCreated = new HashSet<IResource>(); private final static Set<IResource> resourcesCreated = new HashSet<IResource>();
@ -190,7 +193,7 @@ public class ResourceHelper {
/** /**
* Create a plain Eclipse project. * Create a plain Eclipse project.
* *
* @param projectName * @param projectName
* @return the project handle * @return the project handle
* @throws CoreException if project could not be created * @throws CoreException if project could not be created
@ -202,17 +205,17 @@ public class ResourceHelper {
project.create(NULL_MONITOR); project.create(NULL_MONITOR);
else else
project.refreshLocal(IResource.DEPTH_INFINITE, null); project.refreshLocal(IResource.DEPTH_INFINITE, null);
if (!project.isOpen()) if (!project.isOpen())
project.open(NULL_MONITOR); project.open(NULL_MONITOR);
resourcesCreated.add(project); resourcesCreated.add(project);
return project; return project;
} }
/** /**
* Delete project by name. * Delete project by name.
* *
* @param projectName * @param projectName
* @throws CoreException * @throws CoreException
*/ */
@ -222,20 +225,20 @@ public class ResourceHelper {
if (project.exists()) if (project.exists())
delete(project); delete(project);
} }
/** /**
* Delete given project with content. * Delete given project with content.
* *
* @param project * @param project
* @throws CoreException * @throws CoreException
*/ */
public static void delete(final IProject project) throws CoreException { public static void delete(final IProject project) throws CoreException {
delete(project, true); delete(project, true);
} }
/** /**
* Delete project. * Delete project.
* *
* @param project * @param project
* @param deleteContent whether to delete project content * @param deleteContent whether to delete project content
* @throws CoreException * @throws CoreException
@ -252,7 +255,7 @@ public class ResourceHelper {
try { try {
Thread.sleep(1000); // sleep a second Thread.sleep(1000); // sleep a second
} catch (InterruptedException e) { } catch (InterruptedException e) {
} }
} }
} }
} }
@ -297,7 +300,7 @@ public class ResourceHelper {
* can include relative path as a part of the name but the the path * can include relative path as a part of the name but the the path
* has to be present on disk. * has to be present on disk.
* The intention of the method is to create files which do not belong to any project. * The intention of the method is to create files which do not belong to any project.
* *
* @param name - filename. * @param name - filename.
* @return full path of the created file. * @return full path of the created file.
* *
@ -375,7 +378,7 @@ public class ResourceHelper {
public static IPath createTemporaryFolder() throws CoreException, IOException { public static IPath createTemporaryFolder() throws CoreException, IOException {
return ResourceHelper.createWorkspaceFolder("tmp/"+System.currentTimeMillis()+'.'+UUID.randomUUID()); return ResourceHelper.createWorkspaceFolder("tmp/"+System.currentTimeMillis()+'.'+UUID.randomUUID());
} }
/** /**
* Creates new eclipse file-link from project root to file system file. The filename * Creates new eclipse file-link from project root to file system file. The filename
* can include relative path as a part of the name but the the path * can include relative path as a part of the name but the the path
@ -514,7 +517,7 @@ public class ResourceHelper {
* Checks if symbolic links are supported on the system. * Checks if symbolic links are supported on the system.
* Used in particular by method {@link #createSymbolicLink(IPath, IPath)} * Used in particular by method {@link #createSymbolicLink(IPath, IPath)}
* and other flavors to create symbolic links. * and other flavors to create symbolic links.
* *
* Note that Windows links .lnk are not supported here. * Note that Windows links .lnk are not supported here.
* @return {@code true} if symbolic links are suppoted, {@code false} otherwise. * @return {@code true} if symbolic links are suppoted, {@code false} otherwise.
*/ */
@ -675,6 +678,42 @@ public class ResourceHelper {
return windowsPath.trim(); return windowsPath.trim();
} }
/**
* Get contents of file on file-system.
*
* @param fullPath - full path to the file on the file-system.
* @return contents of the file.
* @throws IOException on IO problem.
*/
public static String getContents(IPath fullPath) throws IOException {
FileInputStream stream = new FileInputStream(fullPath.toFile());
try {
// Avoid using java.nio.channels.FileChannel,
// see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4715154
Reader reader = new BufferedReader(new InputStreamReader(stream, Charset.defaultCharset()));
StringBuilder builder = new StringBuilder();
char[] buffer = new char[8192];
int read;
while ((read = reader.read(buffer, 0, buffer.length)) > 0) {
builder.append(buffer, 0, read);
}
return builder.toString();
} finally {
stream.close();
}
}
/**
* Get contents of file on file-system.
*
* @param fullPath - full path to the file on the file-system.
* @return contents of the file.
* @throws IOException on IO problem.
*/
public static String getContents(String fullPath) throws IOException {
return getContents(new Path(fullPath));
}
/** /**
* Clean-up any files created as part of a unit test. * Clean-up any files created as part of a unit test.
* This method removes *all* Workspace IResources and any external * This method removes *all* Workspace IResources and any external

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2011, 2011 Andrew Gvozdev and others. * Copyright (c) 2011, 2012 Andrew Gvozdev and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -47,4 +47,23 @@ public interface ILanguageSettingsProvidersKeeper {
*/ */
public List<ILanguageSettingsProvider> getLanguageSettingProviders(); public List<ILanguageSettingsProvider> getLanguageSettingProviders();
/**
* Sets the list of IDs of default language settings providers.
* <br><br>
* The method is intended to be used by MBS to set the list from tool-chain definition.
* The default list from the tool-chain is used, for example, while resetting
* configuration providers to default in UI.
*
* @param ids - default provider IDs specified in the tool-chain.
*/
public void setDefaultLanguageSettingsProvidersIds(String[] ids);
/**
* Retrieve the list of IDs of default language settings providers.
* Normally the list would come from the tool-chain definition.
*
* @return default provider IDs or {@code null} if default providers are not defined.
*/
public String[] getDefaultLanguageSettingsProvidersIds();
} }

View file

@ -57,12 +57,13 @@ public class LanguageSettingsManager {
return LanguageSettingsProvidersSerializer.getSettingEntriesUpResourceTree(provider, cfgDescription, rc, languageId); return LanguageSettingsProvidersSerializer.getSettingEntriesUpResourceTree(provider, cfgDescription, rc, languageId);
} }
/** /**
* Get Language Settings Provider from the list of workspace providers, * Get Language Settings Provider from the list of workspace providers,
* see {@link #getWorkspaceProviders()}. * see {@link #getWorkspaceProviders()}.
* *
* @param id - id of provider to find. * @param id - id of provider to find.
* @return the provider or {@code null} if provider is not defined. * @return the workspace provider. If workspace provider is not defined
* a new instance is created and returned.
*/ */
public static ILanguageSettingsProvider getWorkspaceProvider(String id) { public static ILanguageSettingsProvider getWorkspaceProvider(String id) {
return LanguageSettingsProvidersSerializer.getWorkspaceProvider(id); return LanguageSettingsProvidersSerializer.getWorkspaceProvider(id);
@ -174,7 +175,7 @@ public class LanguageSettingsManager {
* @return - {@code true} if the provider matches the extension or {@code false} otherwise. * @return - {@code true} if the provider matches the extension or {@code false} otherwise.
*/ */
public static boolean isEqualExtensionProvider(ILanguageSettingsProvider provider, boolean deep) { public static boolean isEqualExtensionProvider(ILanguageSettingsProvider provider, boolean deep) {
return LanguageSettingsExtensionManager.isEqualsExtensionProvider(provider, deep); return LanguageSettingsExtensionManager.isEqualExtensionProvider(provider, deep);
} }
/** /**
@ -278,6 +279,21 @@ public class LanguageSettingsManager {
LanguageSettingsProvidersSerializer.unregisterLanguageSettingsChangeListener(listener); LanguageSettingsProvidersSerializer.unregisterLanguageSettingsChangeListener(listener);
} }
/**
* Tells if the provider is meant to be shared between projects in workspace
* or belong to a specific configuration. This attribute is defined in
* {@code org.eclipse.cdt.core.LanguageSettingsProvider} extension point.
* <br>Note that only {@link ILanguageSettingsEditableProvider} can be owned by
* a configuration.
*
* @param id - ID of the provider to inquire.
* @return {@code true} if the provider is designed to be shared,
* {@code false} if configuration-owned.
*/
public static boolean isPreferShared(String id) {
return LanguageSettingsExtensionManager.isPreferShared(id);
}
/** /**
* Tells if language settings entries of the provider are persisted with the project * Tells if language settings entries of the provider are persisted with the project
* (under .settings/ folder) or in workspace area. Persistence in the project area lets * (under .settings/ folder) or in workspace area. Persistence in the project area lets

View file

@ -306,9 +306,9 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr
if (!key.equals(ATTR_ID) && !key.equals(ATTR_NAME) && !key.equals(ATTR_CLASS)) { if (!key.equals(ATTR_ID) && !key.equals(ATTR_NAME) && !key.equals(ATTR_CLASS)) {
String value = attr.getNodeValue(); String value = attr.getNodeValue();
properties.put(key, value); properties.put(key, value);
}
} }
} }
}
this.setId(providerId); this.setId(providerId);
this.setName(providerName); this.setName(providerName);

View file

@ -33,8 +33,10 @@ import org.osgi.service.prefs.Preferences;
* @since 5.4 * @since 5.4
*/ */
public class ScannerDiscoveryLegacySupport { public class ScannerDiscoveryLegacySupport {
/** Name of MBS language settings provider (from org.eclipse.cdt.managedbuilder.core) */ /** ID of User language settings provider (from org.eclipse.cdt.ui) */
public static final String MBS_LANGUAGE_SETTINGS_PROVIDER = "org.eclipse.cdt.managedbuilder.core.LanguageSettingsProvider"; //$NON-NLS-1$ public static final String USER_LANGUAGE_SETTINGS_PROVIDER_ID = "org.eclipse.cdt.ui.user.LanguageSettingsProvider"; //$NON-NLS-1$
/** ID of MBS language settings provider (from org.eclipse.cdt.managedbuilder.core) */
public static final String MBS_LANGUAGE_SETTINGS_PROVIDER_ID = "org.eclipse.cdt.managedbuilder.core.LanguageSettingsProvider"; //$NON-NLS-1$
private static String USE_LANGUAGE_SETTINGS_PROVIDERS_PREFERENCE = "enabled"; //$NON-NLS-1$ private static String USE_LANGUAGE_SETTINGS_PROVIDERS_PREFERENCE = "enabled"; //$NON-NLS-1$
// the default needs to be "false" for legacy projects to be open with old SD enabled for MBS provider // the default needs to be "false" for legacy projects to be open with old SD enabled for MBS provider
@ -91,7 +93,7 @@ public class ScannerDiscoveryLegacySupport {
if (cfgDescription instanceof ILanguageSettingsProvidersKeeper) { if (cfgDescription instanceof ILanguageSettingsProvidersKeeper) {
List<ILanguageSettingsProvider> lsProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); List<ILanguageSettingsProvider> lsProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders();
for (ILanguageSettingsProvider lsp : lsProviders) { for (ILanguageSettingsProvider lsp : lsProviders) {
if (MBS_LANGUAGE_SETTINGS_PROVIDER.equals(lsp.getId())) { if (MBS_LANGUAGE_SETTINGS_PROVIDER_ID.equals(lsp.getId())) {
return true; return true;
} }
} }

View file

@ -49,6 +49,7 @@ public class LanguageSettingsExtensionManager {
static final String ATTR_ID = "id"; //$NON-NLS-1$ static final String ATTR_ID = "id"; //$NON-NLS-1$
static final String ATTR_NAME = "name"; //$NON-NLS-1$ static final String ATTR_NAME = "name"; //$NON-NLS-1$
static final String ATTR_CLASS = "class"; //$NON-NLS-1$ static final String ATTR_CLASS = "class"; //$NON-NLS-1$
static final String ATTR_PREFER_NON_SHARED = "prefer-non-shared"; //$NON-NLS-1$
static final String ELEM_PROVIDER = "provider"; //$NON-NLS-1$ static final String ELEM_PROVIDER = "provider"; //$NON-NLS-1$
static final String ELEM_LANGUAGE_SCOPE = "language-scope"; //$NON-NLS-1$ static final String ELEM_LANGUAGE_SCOPE = "language-scope"; //$NON-NLS-1$
@ -359,7 +360,7 @@ public class LanguageSettingsExtensionManager {
* Shallow equality is applicable only for {@link ILanguageSettingsEditableProvider}. * Shallow equality is applicable only for {@link ILanguageSettingsEditableProvider}.
* @return - {@code true} if the provider matches the extension or {@code false} otherwise. * @return - {@code true} if the provider matches the extension or {@code false} otherwise.
*/ */
public static boolean isEqualsExtensionProvider(ILanguageSettingsProvider provider, boolean deep) { public static boolean isEqualExtensionProvider(ILanguageSettingsProvider provider, boolean deep) {
String id = provider.getId(); String id = provider.getId();
if (deep || !(provider instanceof ILanguageSettingsEditableProvider)) { if (deep || !(provider instanceof ILanguageSettingsEditableProvider)) {
ILanguageSettingsProvider extensionProvider = fExtensionProviders.get(id); ILanguageSettingsProvider extensionProvider = fExtensionProviders.get(id);
@ -372,4 +373,22 @@ public class LanguageSettingsExtensionManager {
} }
} }
/**
* Tells if the provider is meant to be shared between projects in workspace
* or belong to a specific configuration. This attribute is defined in
* {@code org.eclipse.cdt.core.LanguageSettingsProvider} extension point.
* <br>Note that only {@link ILanguageSettingsEditableProvider} can be owned by
* a configuration.
*
* @param id - ID of the provider to inquire.
* @return {@code true} if the provider is designed to be shared,
* {@code false} if configuration-owned.
*/
public static boolean isPreferShared(String id) {
ILanguageSettingsProvider provider = fExtensionProviders.get(id);
if (provider instanceof LanguageSettingsBaseProvider && provider instanceof ILanguageSettingsEditableProvider) {
return ! ((LanguageSettingsBaseProvider) provider).getPropertyBool(ATTR_PREFER_NON_SHARED);
}
return true;
}
} }

View file

@ -34,6 +34,7 @@ import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.core.settings.model.ICSettingEntry;
import org.eclipse.cdt.core.settings.model.ICStorageElement;
import org.eclipse.cdt.internal.core.XmlUtil; import org.eclipse.cdt.internal.core.XmlUtil;
import org.eclipse.cdt.internal.core.settings.model.CConfigurationSpecSettings; import org.eclipse.cdt.internal.core.settings.model.CConfigurationSpecSettings;
import org.eclipse.cdt.internal.core.settings.model.IInternalCCfgInfo; import org.eclipse.cdt.internal.core.settings.model.IInternalCCfgInfo;
@ -73,9 +74,9 @@ public class LanguageSettingsProvidersSerializer {
public static final String ELEM_LANGUAGE_SCOPE = LanguageSettingsExtensionManager.ELEM_LANGUAGE_SCOPE; public static final String ELEM_LANGUAGE_SCOPE = LanguageSettingsExtensionManager.ELEM_LANGUAGE_SCOPE;
private static final String PREFERENCE_WORSPACE_PROVIDERS_SET = "language.settings.providers.workspace.prefs.toggle"; //$NON-NLS-1$ private static final String PREFERENCE_WORSPACE_PROVIDERS_SET = "language.settings.providers.workspace.prefs.toggle"; //$NON-NLS-1$
private static final String CPROJECT_STORAGE_MODULE = "org.eclipse.cdt.core.LanguageSettingsProviders"; //$NON-NLS-1$
private static final String STORAGE_WORKSPACE_LANGUAGE_SETTINGS = "language.settings.xml"; //$NON-NLS-1$ private static final String STORAGE_WORKSPACE_LANGUAGE_SETTINGS = "language.settings.xml"; //$NON-NLS-1$
private static final String SETTINGS_FOLDER_NAME = ".settings/"; //$NON-NLS-1$ private static final String STORAGE_PROJECT_PATH = ".settings/language.settings.xml"; //$NON-NLS-1$
private static final String STORAGE_PROJECT_LANGUAGE_SETTINGS = "language.settings.xml"; //$NON-NLS-1$
private static final String ELEM_PLUGIN = "plugin"; //$NON-NLS-1$ private static final String ELEM_PLUGIN = "plugin"; //$NON-NLS-1$
private static final String ELEM_EXTENSION = "extension"; //$NON-NLS-1$ private static final String ELEM_EXTENSION = "extension"; //$NON-NLS-1$
@ -85,6 +86,12 @@ public class LanguageSettingsProvidersSerializer {
private static final String ELEM_PROVIDER_REFERENCE = "provider-reference"; //$NON-NLS-1$ private static final String ELEM_PROVIDER_REFERENCE = "provider-reference"; //$NON-NLS-1$
private static final String ATTR_STORE_ENTRIES_WITH_PROJECT = "store-entries-with-project"; //$NON-NLS-1$ private static final String ATTR_STORE_ENTRIES_WITH_PROJECT = "store-entries-with-project"; //$NON-NLS-1$
// those are for readability of xml only
private static final String ATTR_REF = "ref"; //$NON-NLS-1$
private static final String VALUE_REF_SHARED_PROVIDER = "shared-provider"; //$NON-NLS-1$
private static final String ATTR_COPY_OF = "copy-of"; //$NON-NLS-1$
private static final String VALUE_COPY_OF_EXTENSION = "extension"; //$NON-NLS-1$
/** Cache of true (raw) workspace providers */ /** Cache of true (raw) workspace providers */
private static Map<String, ILanguageSettingsProvider> rawGlobalWorkspaceProviders = new HashMap<String, ILanguageSettingsProvider>(); private static Map<String, ILanguageSettingsProvider> rawGlobalWorkspaceProviders = new HashMap<String, ILanguageSettingsProvider>();
/** Cache of workspace providers wrappers */ /** Cache of workspace providers wrappers */
@ -301,13 +308,8 @@ public class LanguageSettingsProvidersSerializer {
* @param store - name of the store. * @param store - name of the store.
* @return location of the store in the plug-in state area. * @return location of the store in the plug-in state area.
*/ */
private static IFile getStoreInProjectArea(IProject project) throws CoreException { private static IFile getStoreInProjectArea(IProject project) {
IFolder folder = project.getFolder(SETTINGS_FOLDER_NAME); return project.getFile(STORAGE_PROJECT_PATH);
if (!folder.exists()) {
folder.create(true, true, null);
}
IFile storage = folder.getFile(STORAGE_PROJECT_LANGUAGE_SETTINGS);
return storage;
} }
/** /**
@ -465,7 +467,9 @@ public class LanguageSettingsProvidersSerializer {
List<LanguageSettingsSerializableProvider> serializableWorkspaceProviders = new ArrayList<LanguageSettingsSerializableProvider>(); List<LanguageSettingsSerializableProvider> serializableWorkspaceProviders = new ArrayList<LanguageSettingsSerializableProvider>();
for (ILanguageSettingsProvider provider : rawGlobalWorkspaceProviders.values()) { for (ILanguageSettingsProvider provider : rawGlobalWorkspaceProviders.values()) {
if (provider instanceof LanguageSettingsSerializableProvider) { if (provider instanceof LanguageSettingsSerializableProvider) {
serializableWorkspaceProviders.add((LanguageSettingsSerializableProvider)provider); if (!LanguageSettingsManager.isEqualExtensionProvider(provider, true)) {
serializableWorkspaceProviders.add((LanguageSettingsSerializableProvider)provider);
}
} }
} }
try { try {
@ -487,9 +491,7 @@ public class LanguageSettingsProvidersSerializer {
new String[] {ATTR_EXTENSION_POINT, PROVIDER_EXTENSION_POINT_ID}); new String[] {ATTR_EXTENSION_POINT, PROVIDER_EXTENSION_POINT_ID});
for (LanguageSettingsSerializableProvider provider : serializableWorkspaceProviders) { for (LanguageSettingsSerializableProvider provider : serializableWorkspaceProviders) {
if (!LanguageSettingsManager.isEqualExtensionProvider(provider, true)) { provider.serialize(elementExtension);
provider.serialize(elementExtension);
}
} }
try { try {
@ -567,6 +569,7 @@ public class LanguageSettingsProvidersSerializer {
if (!(cfgDescription instanceof ILanguageSettingsProvidersKeeper)) if (!(cfgDescription instanceof ILanguageSettingsProvidersKeeper))
continue; continue;
// no lazy initialization as we may need to save 0 providers when it is different from default
Element elementConfiguration = XmlUtil.appendElement(projectElementPrjStore, ELEM_CONFIGURATION, new String[] { Element elementConfiguration = XmlUtil.appendElement(projectElementPrjStore, ELEM_CONFIGURATION, new String[] {
ATTR_ID, cfgDescription.getId(), ATTR_ID, cfgDescription.getId(),
ATTR_NAME, cfgDescription.getName(), ATTR_NAME, cfgDescription.getName(),
@ -574,27 +577,60 @@ public class LanguageSettingsProvidersSerializer {
Element elementConfigurationWsp = null; Element elementConfigurationWsp = null;
List<ILanguageSettingsProvider> providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); List<ILanguageSettingsProvider> providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders();
if (providers.size()>0) { if (providers.size() > 0) {
Element elementExtension = XmlUtil.appendElement(elementConfiguration, ELEM_EXTENSION, new String[] { Element elementExtension = null;
ATTR_EXTENSION_POINT, PROVIDER_EXTENSION_POINT_ID});
Element elementExtensionWsp = null; Element elementExtensionWsp = null;
for (ILanguageSettingsProvider provider : providers) { for (ILanguageSettingsProvider provider : providers) {
if (isWorkspaceProvider(provider)) { if (isWorkspaceProvider(provider)) {
if (elementExtension == null) {
elementExtension = XmlUtil.appendElement(elementConfiguration, ELEM_EXTENSION, new String[] {
ATTR_EXTENSION_POINT, PROVIDER_EXTENSION_POINT_ID});
}
// Element elementProviderReference = // Element elementProviderReference =
XmlUtil.appendElement(elementExtension, ELEM_PROVIDER_REFERENCE, new String[] { XmlUtil.appendElement(elementExtension, ELEM_PROVIDER_REFERENCE, new String[] {
ATTR_ID, provider.getId()}); ATTR_ID, provider.getId(),
ATTR_REF, VALUE_REF_SHARED_PROVIDER,
});
continue; continue;
} }
if (provider instanceof LanguageSettingsSerializableProvider) { if (!(provider instanceof LanguageSettingsSerializableProvider)) {
if (elementExtension == null) {
elementExtension = XmlUtil.appendElement(elementConfiguration, ELEM_EXTENSION, new String[] {
ATTR_EXTENSION_POINT, PROVIDER_EXTENSION_POINT_ID});
}
// Element elementProvider =
XmlUtil.appendElement(elementExtension, ELEM_PROVIDER, new String[] {
ATTR_ID, provider.getId(),
ATTR_NAME, provider.getName(),
ATTR_CLASS, provider.getClass().getCanonicalName(),
});
} else if (LanguageSettingsManager.isEqualExtensionProvider(provider, true)) {
if (elementExtension == null) {
elementExtension = XmlUtil.appendElement(elementConfiguration, ELEM_EXTENSION, new String[] {
ATTR_EXTENSION_POINT, PROVIDER_EXTENSION_POINT_ID});
}
// Element elementProvider =
XmlUtil.appendElement(elementExtension, ELEM_PROVIDER, new String[] {
ATTR_ID, provider.getId(),
ATTR_COPY_OF, VALUE_COPY_OF_EXTENSION,
});
} else {
try { try {
LanguageSettingsSerializableProvider lss = (LanguageSettingsSerializableProvider) provider; LanguageSettingsSerializableProvider lss = (LanguageSettingsSerializableProvider) provider;
boolean isWspStorageAvailable = (projectElementWspStore != null) && (projectElementPrjStore != projectElementWspStore); boolean isWspStorageAvailable = (projectElementWspStore != null) && (projectElementPrjStore != projectElementWspStore);
if (isStoringEntriesInProjectArea(lss) || !isWspStorageAvailable) { if (isStoringEntriesInProjectArea(lss) || !isWspStorageAvailable) {
if (elementExtension == null) {
elementExtension = XmlUtil.appendElement(elementConfiguration, ELEM_EXTENSION, new String[] {
ATTR_EXTENSION_POINT, PROVIDER_EXTENSION_POINT_ID});
}
lss.serialize(elementExtension); lss.serialize(elementExtension);
} else { } else {
// lazy initialization of wsp storage elements - to avoid serialization of no-data file if (elementExtension == null) {
elementExtension = XmlUtil.appendElement(elementConfiguration, ELEM_EXTENSION, new String[] {
ATTR_EXTENSION_POINT, PROVIDER_EXTENSION_POINT_ID});
}
if (elementExtensionWsp == null) { if (elementExtensionWsp == null) {
if (elementConfigurationWsp == null) { if (elementConfigurationWsp == null) {
elementConfigurationWsp = XmlUtil.appendElement(projectElementWspStore, ELEM_CONFIGURATION, new String[] { elementConfigurationWsp = XmlUtil.appendElement(projectElementWspStore, ELEM_CONFIGURATION, new String[] {
@ -606,7 +642,7 @@ public class LanguageSettingsProvidersSerializer {
ATTR_EXTENSION_POINT, PROVIDER_EXTENSION_POINT_ID}); ATTR_EXTENSION_POINT, PROVIDER_EXTENSION_POINT_ID});
} }
Element elementProviderWsp = XmlUtil.appendElement(elementExtensionWsp, ELEM_PROVIDER, new String[] { Element elementProviderWsp = XmlUtil.appendElement(elementExtensionWsp, ELEM_PROVIDER, new String[] {
ATTR_ID, provider.getId()}); ATTR_ID, provider.getId() }); // no attributes kept in workspace storage
// split storage // split storage
lss.serializeAttributes(elementExtension); lss.serializeAttributes(elementExtension);
@ -616,19 +652,59 @@ public class LanguageSettingsProvidersSerializer {
// protect from any exceptions from implementers // protect from any exceptions from implementers
CCorePlugin.log("Exception trying serialize provider "+provider.getId(), e); //$NON-NLS-1$ CCorePlugin.log("Exception trying serialize provider "+provider.getId(), e); //$NON-NLS-1$
} }
} else {
// Element elementProvider =
XmlUtil.appendElement(elementExtension, ELEM_PROVIDER, new String[] {
ATTR_ID, provider.getId(),
ATTR_NAME, provider.getName(),
ATTR_CLASS, provider.getClass().getCanonicalName(),
});
} }
} }
} }
} }
} }
/**
* Check if all the language settings providers in the project match defaults.
*/
private static boolean isEqualToDefaultProviders(ICProjectDescription prjDescription) {
ICConfigurationDescription[] cfgDescriptions = prjDescription.getConfigurations();
for (ICConfigurationDescription cfgDescription : cfgDescriptions) {
if (!(cfgDescription instanceof ILanguageSettingsProvidersKeeper)) {
continue;
}
String[] defaultIds = ((ILanguageSettingsProvidersKeeper) cfgDescription).getDefaultLanguageSettingsProvidersIds();
if (defaultIds == null) {
defaultIds = new String[0];
}
// check size
List<ILanguageSettingsProvider> providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders();
if (providers.size() != defaultIds.length) {
return false;
}
// check ids
for (int i = 0; i < defaultIds.length; i++) {
ILanguageSettingsProvider provider = providers.get(i);
if (!provider.getId().equals(defaultIds[i])) {
return false;
}
}
// check equality (most expensive, so check last)
for (ILanguageSettingsProvider provider : providers) {
if (LanguageSettingsManager.isPreferShared(provider.getId())) {
if (!isWorkspaceProvider(provider)) {
return false;
}
} else {
if (!LanguageSettingsManager.isEqualExtensionProvider(provider, true)) {
return false;
}
}
}
}
return true;
}
/** /**
* Save language settings providers of a project to persistent storage. * Save language settings providers of a project to persistent storage.
* *
@ -640,6 +716,14 @@ public class LanguageSettingsProvidersSerializer {
// AG FIXME - temporary log to remove before CDT Juno release // AG FIXME - temporary log to remove before CDT Juno release
LanguageSettingsLogger.logWarning("LanguageSettingsProvidersSerializer.serializeLanguageSettings() for " + project); LanguageSettingsLogger.logWarning("LanguageSettingsProvidersSerializer.serializeLanguageSettings() for " + project);
try {
// Using side effect of adding the module to the storage
prjDescription.getStorage(CPROJECT_STORAGE_MODULE, true);
} catch (CoreException e) {
CCorePlugin.log("Internal error while trying to serialize language settings", e); //$NON-NLS-1$
}
try { try {
// The storage could be split in two, one for provider properties, another one for entries, // The storage could be split in two, one for provider properties, another one for entries,
// depending on provider flag // depending on provider flag
@ -651,19 +735,33 @@ public class LanguageSettingsProvidersSerializer {
Document docStoreWsp = XmlUtil.newDocument(); Document docStoreWsp = XmlUtil.newDocument();
Element projectElementStoreWsp = XmlUtil.appendElement(docStoreWsp, ELEM_PROJECT); Element projectElementStoreWsp = XmlUtil.appendElement(docStoreWsp, ELEM_PROJECT);
// The project store should not be absent. Currently absent store means legacy project, not 0 providers.
IFile fileStorePrj = getStoreInProjectArea(project);
URI uriStoreWsp = getStoreInWorkspaceArea(project.getName()+'.'+STORAGE_WORKSPACE_LANGUAGE_SETTINGS); URI uriStoreWsp = getStoreInWorkspaceArea(project.getName()+'.'+STORAGE_WORKSPACE_LANGUAGE_SETTINGS);
LanguageSettingsChangeEvent event = null; LanguageSettingsChangeEvent event = null;
try { try {
serializingLock.acquire();
// Note that need for serialization may exist even if LS *entries* event delta is empty, // Note that need for serialization may exist even if LS *entries* event delta is empty,
// as set of providers or their properties may differ // as set of providers or their properties may differ
serializeLanguageSettingsInternal(projectElementStorePrj, projectElementStoreWsp, prjDescription);
XmlUtil.serializeXml(docStorePrj, fileStorePrj); serializingLock.acquire();
if (!isEqualToDefaultProviders(prjDescription)) {
serializeLanguageSettingsInternal(projectElementStorePrj, projectElementStoreWsp, prjDescription);
}
// Absent store means default providers as specified in the toolchain
IFile fileStorePrj = getStoreInProjectArea(project);
boolean isProjectStoreEmpty = projectElementStorePrj.getChildNodes().getLength() == 0;
if (isProjectStoreEmpty) {
if (fileStorePrj.exists()) {
fileStorePrj.delete(true, null);
}
} else {
IContainer folder = fileStorePrj.getParent();
if (folder instanceof IFolder && !folder.exists()) {
((IFolder) folder).create(true, true, null);
}
XmlUtil.serializeXml(docStorePrj, fileStorePrj);
}
// project-specific location in workspace area // project-specific location in workspace area
boolean isWorkspaceStoreEmpty = projectElementStoreWsp.getChildNodes().getLength() == 0; boolean isWorkspaceStoreEmpty = projectElementStoreWsp.getChildNodes().getLength() == 0;
@ -733,11 +831,25 @@ public class LanguageSettingsProvidersSerializer {
String providerId = XmlUtil.determineAttributeValue(providerNode, ATTR_ID); String providerId = XmlUtil.determineAttributeValue(providerNode, ATTR_ID);
provider = getWorkspaceProvider(providerId); provider = getWorkspaceProvider(providerId);
} else if (isElementWithName(providerNode, ELEM_PROVIDER)) { } else if (isElementWithName(providerNode, ELEM_PROVIDER)) {
provider = loadProvider(providerNode); String providerClass = XmlUtil.determineAttributeValue(providerNode, ATTR_CLASS);
if (provider instanceof LanguageSettingsSerializableProvider) { if (providerClass == null || providerClass.isEmpty()) {
LanguageSettingsSerializableProvider lss = (LanguageSettingsSerializableProvider) provider; // provider is copied from extension if "class" is not supplied
if (!isStoringEntriesInProjectArea(lss) && projectElementWsp != null) { String providerId = XmlUtil.determineAttributeValue(providerNode, ATTR_ID);
loadProviderEntries(lss, cfgId, projectElementWsp); provider = LanguageSettingsManager.getExtensionProviderCopy(providerId, true);
if (provider == null) {
String msg = "Internal Error trying to copy extension provider id=" + providerId; //$NON-NLS-1$
CCorePlugin.log(new Status(IStatus.WARNING, CCorePlugin.PLUGIN_ID, msg, new Exception(msg)));
provider = LanguageSettingsManager.getWorkspaceProvider(providerId);
}
} else {
provider = loadProvider(providerNode);
if (provider instanceof LanguageSettingsSerializableProvider) {
LanguageSettingsSerializableProvider lss = (LanguageSettingsSerializableProvider) provider;
if (!isStoringEntriesInProjectArea(lss) && projectElementWsp != null) {
loadProviderEntries(lss, cfgId, projectElementWsp);
}
} }
} }
} }
@ -748,14 +860,22 @@ public class LanguageSettingsProvidersSerializer {
} }
ICConfigurationDescription cfgDescription = prjDescription.getConfigurationById(cfgId); ICConfigurationDescription cfgDescription = prjDescription.getConfigurationById(cfgId);
if (cfgDescription instanceof ILanguageSettingsProvidersKeeper) { setProvidersWithoutNotification(cfgDescription, providers);
((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); }
if (cfgDescription instanceof IInternalCCfgInfo) { }
try {
((IInternalCCfgInfo) cfgDescription).getSpecSettings().dropDelta(); /**
} catch (CoreException e) { * Set providers into configuration description avoiding triggering an event.
CCorePlugin.log(e); */
} private static void setProvidersWithoutNotification(ICConfigurationDescription cfgDescription, List<ILanguageSettingsProvider> providers) {
if (cfgDescription instanceof ILanguageSettingsProvidersKeeper) {
((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers);
if (cfgDescription instanceof IInternalCCfgInfo) {
try {
// swallow delta
((IInternalCCfgInfo) cfgDescription).getSpecSettings().dropDelta();
} catch (CoreException e) {
CCorePlugin.log(e);
} }
} }
} }
@ -837,11 +957,11 @@ public class LanguageSettingsProvidersSerializer {
*/ */
public static void loadLanguageSettings(ICProjectDescription prjDescription) { public static void loadLanguageSettings(ICProjectDescription prjDescription) {
IProject project = prjDescription.getProject(); IProject project = prjDescription.getProject();
IFile storeInPrjArea = project.getFile(SETTINGS_FOLDER_NAME + STORAGE_PROJECT_LANGUAGE_SETTINGS); IFile storeInPrjArea = getStoreInProjectArea(project);
try { try {
Job currentJob = Job.getJobManager().currentJob(); Job currentJob = Job.getJobManager().currentJob();
ISchedulingRule currentRule = (currentJob != null) ? currentJob.getRule() : null; ISchedulingRule currentRule = (currentJob != null) ? currentJob.getRule() : null;
if (currentRule == null || currentRule.contains(storeInPrjArea)) { if ((currentRule == null || currentRule.contains(storeInPrjArea)) && !ResourcesPlugin.getWorkspace().isTreeLocked()) {
storeInPrjArea.refreshLocal(IResource.DEPTH_ZERO, null); storeInPrjArea.refreshLocal(IResource.DEPTH_ZERO, null);
} }
} catch (Throwable e) { } catch (Throwable e) {
@ -874,14 +994,43 @@ public class LanguageSettingsProvidersSerializer {
} }
} else { } else {
// Already existing legacy projects // Storage in project area does not exist
ICConfigurationDescription[] cfgDescriptions = prjDescription.getConfigurations(); ICStorageElement storageElement = null;
for (ICConfigurationDescription cfgDescription : cfgDescriptions) { try {
if (cfgDescription instanceof ILanguageSettingsProvidersKeeper) { storageElement = prjDescription.getStorage(CPROJECT_STORAGE_MODULE, false);
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>(2); } catch (CoreException e) {
ILanguageSettingsProvider providerMBS = getWorkspaceProvider(ScannerDiscoveryLegacySupport.MBS_LANGUAGE_SETTINGS_PROVIDER); String msg = "Internal error while trying to load language settings"; //$NON-NLS-1$
providers.add(providerMBS); CCorePlugin.log(msg, e);
((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); }
if (storageElement != null) {
// set default providers defined in the tool-chain
for (ICConfigurationDescription cfgDescription : prjDescription.getConfigurations()) {
String[] ids = ((ILanguageSettingsProvidersKeeper) cfgDescription).getDefaultLanguageSettingsProvidersIds();
if (ids != null) {
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>(ids.length);
for (String id : ids) {
if (LanguageSettingsExtensionManager.isPreferShared(id)) {
providers.add(LanguageSettingsManager.getWorkspaceProvider(id));
} else {
providers.add(LanguageSettingsManager.getExtensionProviderCopy(id, true));
}
}
((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers);
}
}
} else {
// Older existing legacy projects unaware of Language Settings Providers and their persistence store
ICConfigurationDescription[] cfgDescriptions = prjDescription.getConfigurations();
for (ICConfigurationDescription cfgDescription : cfgDescriptions) {
if (cfgDescription instanceof ILanguageSettingsProvidersKeeper) {
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>(2);
providers.add(LanguageSettingsExtensionManager.getExtensionProviderCopy((ScannerDiscoveryLegacySupport.USER_LANGUAGE_SETTINGS_PROVIDER_ID), true));
providers.add(getWorkspaceProvider(ScannerDiscoveryLegacySupport.MBS_LANGUAGE_SETTINGS_PROVIDER_ID));
((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers);
}
} }
} }
@ -893,7 +1042,8 @@ public class LanguageSettingsProvidersSerializer {
* see {@link #getWorkspaceProviders()}. * see {@link #getWorkspaceProviders()}.
* *
* @param id - ID of provider to find. * @param id - ID of provider to find.
* @return the provider or {@code null} if provider is not defined. * @return the workspace provider. If provider is not defined - still workspace
* provider wrapper is created and returned.
*/ */
public static ILanguageSettingsProvider getWorkspaceProvider(String id) { public static ILanguageSettingsProvider getWorkspaceProvider(String id) {
ILanguageSettingsProvider provider = globalWorkspaceProviders.get(id); ILanguageSettingsProvider provider = globalWorkspaceProviders.get(id);

View file

@ -832,8 +832,7 @@ public class CConfigurationDescription extends CDataProxyContainer
@Override @Override
public void setLanguageSettingProviders(List<ILanguageSettingsProvider> providers) { public void setLanguageSettingProviders(List<ILanguageSettingsProvider> providers) {
try { try {
CConfigurationSpecSettings specSettings = getSpecSettings(); getSpecSettings().setLanguageSettingProviders(providers);
specSettings.setLanguageSettingProviders(providers);
} catch (CoreException e) { } catch (CoreException e) {
CCorePlugin.log(e); CCorePlugin.log(e);
} }
@ -848,4 +847,23 @@ public class CConfigurationDescription extends CDataProxyContainer
} }
return null; return null;
} }
@Override
public void setDefaultLanguageSettingsProvidersIds(String[] ids) {
try {
getSpecSettings().setDefaultLanguageSettingsProvidersIds(ids);
} catch (CoreException e) {
CCorePlugin.log(e);
}
}
@Override
public String[] getDefaultLanguageSettingsProvidersIds() {
try {
return getSpecSettings().getDefaultLanguageSettingsProvidersIds();
} catch (CoreException e) {
CCorePlugin.log(e);
}
return null;
}
} }

View file

@ -628,4 +628,16 @@ public class CConfigurationDescriptionCache extends CDefaultConfigurationData
public List<ILanguageSettingsProvider> getLanguageSettingProviders() { public List<ILanguageSettingsProvider> getLanguageSettingProviders() {
return fSpecSettings.getLanguageSettingProviders(); return fSpecSettings.getLanguageSettingProviders();
} }
@Override
public void setDefaultLanguageSettingsProvidersIds(String[] ids) {
if(!fInitializing)
throw ExceptionFactory.createIsReadOnlyException();
fSpecSettings.setDefaultLanguageSettingsProvidersIds(ids);
}
@Override
public String[] getDefaultLanguageSettingsProvidersIds() {
return fSpecSettings.getDefaultLanguageSettingsProvidersIds();
}
} }

View file

@ -25,6 +25,7 @@ import java.util.Set;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsBroadcastingProvider; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsBroadcastingProvider;
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; 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.LanguageSettingsManager;
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsStorage; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsStorage;
import org.eclipse.cdt.core.settings.model.CExternalSetting; import org.eclipse.cdt.core.settings.model.CExternalSetting;
@ -57,7 +58,7 @@ import org.eclipse.core.runtime.QualifiedName;
* This corresponds to the <cconfiguration id="....> elements within * This corresponds to the <cconfiguration id="....> elements within
* the org.eclipse.cdt.core.settings storageModule in the project xml file * the org.eclipse.cdt.core.settings storageModule in the project xml file
*/ */
public class CConfigurationSpecSettings implements ICSettingsStorage{ public class CConfigurationSpecSettings implements ICSettingsStorage, ILanguageSettingsProvidersKeeper {
static final String BUILD_SYSTEM_ID = "buildSystemId"; //$NON-NLS-1$ static final String BUILD_SYSTEM_ID = "buildSystemId"; //$NON-NLS-1$
// private final static String ELEMENT_REFERENCES = "references"; //$NON-NLS-1$ // private final static String ELEMENT_REFERENCES = "references"; //$NON-NLS-1$
private static final String PROJECT_EXTENSION_ATTR_POINT = "point"; //$NON-NLS-1$ private static final String PROJECT_EXTENSION_ATTR_POINT = "point"; //$NON-NLS-1$
@ -98,6 +99,7 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{
private List<ILanguageSettingsProvider> fLanguageSettingsProviders = new ArrayList<ILanguageSettingsProvider>(0); private List<ILanguageSettingsProvider> fLanguageSettingsProviders = new ArrayList<ILanguageSettingsProvider>(0);
private LinkedHashMap<String /*provider*/, LanguageSettingsStorage> lspPersistedState = new LinkedHashMap<String, LanguageSettingsStorage>(); private LinkedHashMap<String /*provider*/, LanguageSettingsStorage> lspPersistedState = new LinkedHashMap<String, LanguageSettingsStorage>();
private String[] defaultLanguageSettingsProvidersIds = null;
private class DeltaSet { private class DeltaSet {
@ -202,6 +204,11 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{
CCorePlugin.log("Not able to clone language settings storage:" + e); //$NON-NLS-1$ CCorePlugin.log("Not able to clone language settings storage:" + e); //$NON-NLS-1$
} }
} }
if (base.defaultLanguageSettingsProvidersIds != null) {
defaultLanguageSettingsProvidersIds = base.defaultLanguageSettingsProvidersIds.clone();
} else {
defaultLanguageSettingsProvidersIds = null;
}
} }
// private void copyRefInfos(Map infosMap){ // private void copyRefInfos(Map infosMap){
@ -1007,6 +1014,7 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{
* *
* @param providers - list of providers to keep in the specs. * @param providers - list of providers to keep in the specs.
*/ */
@Override
public void setLanguageSettingProviders(List<ILanguageSettingsProvider> providers) { public void setLanguageSettingProviders(List<ILanguageSettingsProvider> providers) {
fLanguageSettingsProviders = new ArrayList<ILanguageSettingsProvider>(0); fLanguageSettingsProviders = new ArrayList<ILanguageSettingsProvider>(0);
Set<String> ids = new HashSet<String>(); Set<String> ids = new HashSet<String>();
@ -1025,10 +1033,21 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{
fIsModified = true; fIsModified = true;
} }
@Override
public List<ILanguageSettingsProvider> getLanguageSettingProviders() { public List<ILanguageSettingsProvider> getLanguageSettingProviders() {
return Collections.unmodifiableList(fLanguageSettingsProviders); return Collections.unmodifiableList(fLanguageSettingsProviders);
} }
@Override
public void setDefaultLanguageSettingsProvidersIds(String[] ids) {
defaultLanguageSettingsProvidersIds = ids;
}
@Override
public String[] getDefaultLanguageSettingsProvidersIds() {
return defaultLanguageSettingsProvidersIds;
}
/** /**
* Returns delta and updates last persisted state to the new state. * Returns delta and updates last persisted state to the new state.
* That implies that the delta needs to be used to fire an event of it will * That implies that the delta needs to be used to fire an event of it will

View file

@ -172,9 +172,9 @@ public class XmlProjectDescriptionStorage extends AbstractCProjectDescriptionSto
}, null, IWorkspace.AVOID_UPDATE, null); }, null, IWorkspace.AVOID_UPDATE, null);
// end Bug 249951 & Bug 310007 // end Bug 249951 & Bug 310007
serializingLock.acquire(); serializingLock.acquire();
LanguageSettingsManager.serializeLanguageSettings(fDes);
projectModificaitonStamp = serialize(fDes.getProject(), ICProjectDescriptionStorageType.STORAGE_FILE_NAME, fElement); projectModificaitonStamp = serialize(fDes.getProject(), ICProjectDescriptionStorageType.STORAGE_FILE_NAME, fElement);
((ContributedEnvironment) CCorePlugin.getDefault().getBuildEnvironmentManager().getContributedEnvironment()).serialize(fDes); ((ContributedEnvironment) CCorePlugin.getDefault().getBuildEnvironmentManager().getContributedEnvironment()).serialize(fDes);
LanguageSettingsManager.serializeLanguageSettings(fDes);
} finally { } finally {
serializingLock.release(); serializingLock.release();
Job.getJobManager().removeJobChangeListener(notifyJobCanceller); Job.getJobManager().removeJobChangeListener(notifyJobCanceller);

View file

@ -94,6 +94,14 @@ Default constructor (constructor without arguments) of this class must be public
</documentation> </documentation>
</annotation> </annotation>
</attribute> </attribute>
<attribute name="prefer-non-shared" type="boolean" use="default" value="false">
<annotation>
<documentation>
A flag indicating that the provider should be owned by a configuration rather than be global in workspace and shared between projects (when the choice has not been indicated yet by other means). This preference is consulted in order to initially set the &quot;shared&quot; attribute, for example when a user adds a provider from the list of extension providers.
The value &quot;true&quot; of this attribute is meaningful only for providers capable of being non-shared, i.e. providers extending ILanguageSettingsEditableProvider.
</documentation>
</annotation>
</attribute>
</complexType> </complexType>
</element> </element>

View file

@ -4306,14 +4306,14 @@
<provider <provider
class="org.eclipse.cdt.core.language.settings.providers.LanguageSettingsGenericProvider" class="org.eclipse.cdt.core.language.settings.providers.LanguageSettingsGenericProvider"
id="org.eclipse.cdt.ui.user.LanguageSettingsProvider" id="org.eclipse.cdt.ui.user.LanguageSettingsProvider"
name="CDT User Setting Entries"> name="CDT User Setting Entries"
prefer-non-shared="true">
</provider> </provider>
</extension> </extension>
<extension point="org.eclipse.cdt.ui.LanguageSettingsProviderAssociation"> <extension point="org.eclipse.cdt.ui.LanguageSettingsProviderAssociation">
<id-association <id-association
id="org.eclipse.cdt.ui.user.LanguageSettingsProvider" id="org.eclipse.cdt.ui.user.LanguageSettingsProvider"
icon="icons/obj16/person-me.gif" icon="icons/obj16/person-me.gif"
shared="false"
ui-clear-entries="true" ui-clear-entries="true"
ui-edit-entries="true"> ui-edit-entries="true">
</id-association> </id-association>

View file

@ -77,13 +77,6 @@
</appInfo> </appInfo>
</annotation> </annotation>
</attribute> </attribute>
<attribute name="shared" type="boolean">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="ui-edit-entries" type="boolean"> <attribute name="ui-edit-entries" type="boolean">
<annotation> <annotation>
<documentation> <documentation>
@ -133,13 +126,6 @@
</appInfo> </appInfo>
</annotation> </annotation>
</attribute> </attribute>
<attribute name="shared" type="boolean">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="ui-clear-entries" type="boolean"> <attribute name="ui-clear-entries" type="boolean">
<annotation> <annotation>
<documentation> <documentation>

View file

@ -29,7 +29,6 @@ public class LanguageSettingsProviderAssociationManager {
private static final String ATTR_CLASS = "class"; //$NON-NLS-1$ private static final String ATTR_CLASS = "class"; //$NON-NLS-1$
private static final String ATTR_ICON = "icon"; //$NON-NLS-1$ private static final String ATTR_ICON = "icon"; //$NON-NLS-1$
private static final String ATTR_PAGE = "page"; //$NON-NLS-1$ private static final String ATTR_PAGE = "page"; //$NON-NLS-1$
private static final String ATTR_SHARED = "shared"; //$NON-NLS-1$
private static final String ATTR_UI_CLEAR_ENTRIES = "ui-clear-entries"; //$NON-NLS-1$ private static final String ATTR_UI_CLEAR_ENTRIES = "ui-clear-entries"; //$NON-NLS-1$
private static final String ATTR_UI_EDIT_ENTRIES = "ui-edit-entries"; //$NON-NLS-1$ private static final String ATTR_UI_EDIT_ENTRIES = "ui-edit-entries"; //$NON-NLS-1$
@ -71,7 +70,6 @@ public class LanguageSettingsProviderAssociationManager {
Map<String, String> properties = new HashMap<String, String>(); Map<String, String> properties = new HashMap<String, String>();
sensiblePut(properties, ATTR_PAGE, cfgEl.getAttribute(ATTR_PAGE)); sensiblePut(properties, ATTR_PAGE, cfgEl.getAttribute(ATTR_PAGE));
sensiblePut(properties, ATTR_SHARED, cfgEl.getAttribute(ATTR_SHARED));
sensiblePut(properties, ATTR_UI_CLEAR_ENTRIES, cfgEl.getAttribute(ATTR_UI_CLEAR_ENTRIES)); sensiblePut(properties, ATTR_UI_CLEAR_ENTRIES, cfgEl.getAttribute(ATTR_UI_CLEAR_ENTRIES));
sensiblePut(properties, ATTR_UI_EDIT_ENTRIES, cfgEl.getAttribute(ATTR_UI_EDIT_ENTRIES)); sensiblePut(properties, ATTR_UI_EDIT_ENTRIES, cfgEl.getAttribute(ATTR_UI_EDIT_ENTRIES));
fAssociationsById.put(id, properties); fAssociationsById.put(id, properties);
@ -86,7 +84,6 @@ public class LanguageSettingsProviderAssociationManager {
Map<String, String> properties = new HashMap<String, String>(); Map<String, String> properties = new HashMap<String, String>();
sensiblePut(properties, ATTR_PAGE, cfgEl.getAttribute(ATTR_PAGE)); sensiblePut(properties, ATTR_PAGE, cfgEl.getAttribute(ATTR_PAGE));
sensiblePut(properties, ATTR_SHARED, cfgEl.getAttribute(ATTR_SHARED));
sensiblePut(properties, ATTR_UI_CLEAR_ENTRIES, cfgEl.getAttribute(ATTR_UI_CLEAR_ENTRIES)); sensiblePut(properties, ATTR_UI_CLEAR_ENTRIES, cfgEl.getAttribute(ATTR_UI_CLEAR_ENTRIES));
sensiblePut(properties, ATTR_UI_EDIT_ENTRIES, cfgEl.getAttribute(ATTR_UI_EDIT_ENTRIES)); sensiblePut(properties, ATTR_UI_EDIT_ENTRIES, cfgEl.getAttribute(ATTR_UI_EDIT_ENTRIES));
fAssociationsByClass.put(className, properties); fAssociationsByClass.put(className, properties);
@ -304,16 +301,6 @@ public class LanguageSettingsProviderAssociationManager {
return false; return false;
} }
/**
* Returns TODO for id or closest superclass.
* @param provider TODO
* @return TODO
*/
public static boolean shouldBeShared(ILanguageSettingsProvider provider) {
return getBooleanAttribute(provider, ATTR_SHARED);
}
/** /**
* Returns TODO for id or closest superclass. * Returns TODO for id or closest superclass.
* @param provider TODO * @param provider TODO

View file

@ -315,9 +315,9 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab {
tableProviders.setSelection(pos); tableProviders.setSelection(pos);
if (event.getChecked() && LanguageSettingsManager.isWorkspaceProvider(provider)) { if (event.getChecked() && LanguageSettingsManager.isWorkspaceProvider(provider)) {
ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); if (!LanguageSettingsManager.isPreferShared(provider.getId())) {
if (!LanguageSettingsProviderAssociationManager.shouldBeShared(rawProvider)) { // Switch to non-shared provider instance
// Switch to local provider instance ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider);
if (rawProvider instanceof ILanguageSettingsEditableProvider) { if (rawProvider instanceof ILanguageSettingsEditableProvider) {
ILanguageSettingsEditableProvider newProvider = LanguageSettingsManager.getProviderCopy((ILanguageSettingsEditableProvider) rawProvider, false); ILanguageSettingsEditableProvider newProvider = LanguageSettingsManager.getProviderCopy((ILanguageSettingsEditableProvider) rawProvider, false);
if (newProvider != null) { if (newProvider != null) {

View file

@ -90,7 +90,8 @@
class="org.eclipse.cdt.make.internal.core.scannerconfig.GCCBuildCommandParser" class="org.eclipse.cdt.make.internal.core.scannerconfig.GCCBuildCommandParser"
id="org.eclipse.cdt.managedbuilder.xlc.core.xlc.build.command.parser" id="org.eclipse.cdt.managedbuilder.xlc.core.xlc.build.command.parser"
name="%XlcBuildCommandParserName" name="%XlcBuildCommandParserName"
parameter="xl[cC]"> parameter="xl[cC]"
prefer-non-shared="true">
</provider> </provider>
</extension> </extension>