mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 17:05:26 +02:00
bug 290631: Incorporate New Scanner Discovery from sd90 into the model
(in legacy mode)
This commit is contained in:
parent
86e15e9e9b
commit
90d34eab05
10 changed files with 1091 additions and 41 deletions
|
@ -114,6 +114,366 @@ public class LanguageSettingsListenersTests extends BaseTestCase {
|
|||
assertEquals(0, MockListenerRegisterer.getCount(EXTENSION_REGISTERER_PROVIDER_ID));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test events triggered for non-shared configuration owned provider.
|
||||
*/
|
||||
public void testListenerRegisterer_OneOwnedByCfg() throws Exception {
|
||||
// create project
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName());
|
||||
ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, true);
|
||||
|
||||
{
|
||||
// get project descriptions
|
||||
ICProjectDescription prjDescriptionWritable = CProjectDescriptionManager.getInstance().getProjectDescription(project, true);
|
||||
assertNotNull(prjDescriptionWritable);
|
||||
ICConfigurationDescription[] cfgDescriptions = prjDescriptionWritable.getConfigurations();
|
||||
assertEquals(1, cfgDescriptions.length);
|
||||
ICConfigurationDescription cfgDescription = cfgDescriptions[0];
|
||||
assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper);
|
||||
|
||||
// create a provider
|
||||
ILanguageSettingsProvider mockProvider = new MockListenerRegisterer(PROVIDER_1, PROVIDER_NAME_1);
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(mockProvider);
|
||||
((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers);
|
||||
List<ILanguageSettingsProvider> storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders();
|
||||
assertEquals(1, storedProviders.size());
|
||||
|
||||
// write to project description
|
||||
CoreModel.getDefault().setProjectDescription(project, prjDescriptionWritable);
|
||||
assertEquals(1, MockListenerRegisterer.getCount(PROVIDER_1));
|
||||
}
|
||||
{
|
||||
// close the project
|
||||
project.close(null);
|
||||
assertEquals(0, MockListenerRegisterer.getCount(PROVIDER_1));
|
||||
}
|
||||
{
|
||||
// reopen the project
|
||||
project.open(null);
|
||||
// initialize project description
|
||||
CProjectDescriptionManager.getInstance().getProjectDescription(project, false);
|
||||
assertEquals(1, MockListenerRegisterer.getCount(PROVIDER_1));
|
||||
// and delete
|
||||
project.delete(true, null);
|
||||
assertEquals(0, MockListenerRegisterer.getCount(PROVIDER_1));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test events triggered for non-shared configuration owned multiple providers.
|
||||
*/
|
||||
public void testListenerRegisterer_TwoOwnedByCfgs() throws Exception {
|
||||
// create project
|
||||
IProject project = ResourceHelper.createCDTProject(this.getName(), null, new String[] {
|
||||
"org.eclipse.cdt.core.tests.configuration.id.1",
|
||||
"org.eclipse.cdt.core.tests.configuration.id.2",
|
||||
});
|
||||
ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, true);
|
||||
|
||||
{
|
||||
// get project descriptions
|
||||
ICProjectDescription prjDescriptionWritable = CProjectDescriptionManager.getInstance().getProjectDescription(project, true);
|
||||
assertNotNull(prjDescriptionWritable);
|
||||
ICConfigurationDescription[] cfgDescriptions = prjDescriptionWritable.getConfigurations();
|
||||
assertEquals(2, cfgDescriptions.length);
|
||||
ICConfigurationDescription cfgDescription1 = cfgDescriptions[0];
|
||||
ICConfigurationDescription cfgDescription2 = cfgDescriptions[1];
|
||||
assertTrue(cfgDescription1 instanceof ILanguageSettingsProvidersKeeper);
|
||||
assertTrue(cfgDescription2 instanceof ILanguageSettingsProvidersKeeper);
|
||||
|
||||
{
|
||||
// create a provider 1
|
||||
ILanguageSettingsProvider mockProvider = new MockListenerRegisterer(PROVIDER_1, PROVIDER_NAME_1);
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(mockProvider);
|
||||
((ILanguageSettingsProvidersKeeper) cfgDescription1).setLanguageSettingProviders(providers);
|
||||
List<ILanguageSettingsProvider> storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription1).getLanguageSettingProviders();
|
||||
assertEquals(1, storedProviders.size());
|
||||
}
|
||||
{
|
||||
// create a provider 2
|
||||
ILanguageSettingsProvider mockProvider = new MockListenerRegisterer(PROVIDER_1, PROVIDER_NAME_1);
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(mockProvider);
|
||||
((ILanguageSettingsProvidersKeeper) cfgDescription2).setLanguageSettingProviders(providers);
|
||||
List<ILanguageSettingsProvider> storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription2).getLanguageSettingProviders();
|
||||
assertEquals(1, storedProviders.size());
|
||||
}
|
||||
|
||||
// write to project description
|
||||
CoreModel.getDefault().setProjectDescription(project, prjDescriptionWritable);
|
||||
assertEquals(2, MockListenerRegisterer.getCount(PROVIDER_1));
|
||||
}
|
||||
{
|
||||
// close the project
|
||||
project.close(null);
|
||||
assertEquals(0, MockListenerRegisterer.getCount(PROVIDER_1));
|
||||
}
|
||||
{
|
||||
// reopen the project
|
||||
project.open(null);
|
||||
// initialize project description
|
||||
CProjectDescriptionManager.getInstance().getProjectDescription(project, false);
|
||||
assertEquals(2, MockListenerRegisterer.getCount(PROVIDER_1));
|
||||
// and delete
|
||||
project.delete(true, null);
|
||||
assertEquals(0, MockListenerRegisterer.getCount(PROVIDER_1));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test events triggered for shared provider.
|
||||
*/
|
||||
public void testListenerRegisterer_OneGlobal() throws Exception {
|
||||
// create project
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName());
|
||||
ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, true);
|
||||
|
||||
{
|
||||
// get project descriptions
|
||||
ICProjectDescription prjDescriptionWritable = CProjectDescriptionManager.getInstance().getProjectDescription(project, true);
|
||||
assertNotNull(prjDescriptionWritable);
|
||||
ICConfigurationDescription[] cfgDescriptions = prjDescriptionWritable.getConfigurations();
|
||||
assertEquals(1, cfgDescriptions.length);
|
||||
ICConfigurationDescription cfgDescription = cfgDescriptions[0];
|
||||
assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper);
|
||||
|
||||
// add global provider
|
||||
ILanguageSettingsProvider workspaceProvider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_REGISTERER_PROVIDER_ID);
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(workspaceProvider);
|
||||
((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers);
|
||||
List<ILanguageSettingsProvider> storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders();
|
||||
assertEquals(1, storedProviders.size());
|
||||
|
||||
// write to project description
|
||||
CoreModel.getDefault().setProjectDescription(project, prjDescriptionWritable);
|
||||
assertEquals(1, MockListenerRegisterer.getCount(EXTENSION_REGISTERER_PROVIDER_ID));
|
||||
}
|
||||
{
|
||||
// close the project
|
||||
project.close(null);
|
||||
assertEquals(0, MockListenerRegisterer.getCount(EXTENSION_REGISTERER_PROVIDER_ID));
|
||||
}
|
||||
{
|
||||
// reopen the project
|
||||
project.open(null);
|
||||
// initialize project description
|
||||
CProjectDescriptionManager.getInstance().getProjectDescription(project, false);
|
||||
assertEquals(1, MockListenerRegisterer.getCount(EXTENSION_REGISTERER_PROVIDER_ID));
|
||||
// and delete
|
||||
project.delete(true, null);
|
||||
assertEquals(0, MockListenerRegisterer.getCount(EXTENSION_REGISTERER_PROVIDER_ID));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test events triggered for multiple shared providers.
|
||||
*/
|
||||
public void testListenerRegisterer_TwoGlobal() throws Exception {
|
||||
// create project
|
||||
IProject project = ResourceHelper.createCDTProject(this.getName(), null, new String[] {
|
||||
"org.eclipse.cdt.core.tests.configuration.id.1",
|
||||
"org.eclipse.cdt.core.tests.configuration.id.2",
|
||||
});
|
||||
ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, true);
|
||||
|
||||
{
|
||||
// retrieve global provider
|
||||
ILanguageSettingsProvider workspaceProvider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_REGISTERER_PROVIDER_ID);
|
||||
// get project descriptions
|
||||
ICProjectDescription prjDescriptionWritable = CProjectDescriptionManager.getInstance().getProjectDescription(project, true);
|
||||
assertNotNull(prjDescriptionWritable);
|
||||
ICConfigurationDescription[] cfgDescriptions = prjDescriptionWritable.getConfigurations();
|
||||
assertEquals(2, cfgDescriptions.length);
|
||||
ICConfigurationDescription cfgDescription1 = cfgDescriptions[0];
|
||||
ICConfigurationDescription cfgDescription2 = cfgDescriptions[1];
|
||||
assertTrue(cfgDescription1 instanceof ILanguageSettingsProvidersKeeper);
|
||||
assertTrue(cfgDescription2 instanceof ILanguageSettingsProvidersKeeper);
|
||||
|
||||
{
|
||||
// add global provider to configuration 1
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(workspaceProvider);
|
||||
((ILanguageSettingsProvidersKeeper) cfgDescription1).setLanguageSettingProviders(providers);
|
||||
List<ILanguageSettingsProvider> storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription1).getLanguageSettingProviders();
|
||||
assertEquals(1, storedProviders.size());
|
||||
}
|
||||
{
|
||||
// add global provider to configuration 2
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(workspaceProvider);
|
||||
((ILanguageSettingsProvidersKeeper) cfgDescription2).setLanguageSettingProviders(providers);
|
||||
List<ILanguageSettingsProvider> storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription2).getLanguageSettingProviders();
|
||||
assertEquals(1, storedProviders.size());
|
||||
}
|
||||
// write to project description
|
||||
CoreModel.getDefault().setProjectDescription(project, prjDescriptionWritable);
|
||||
assertEquals(1, MockListenerRegisterer.getCount(EXTENSION_REGISTERER_PROVIDER_ID));
|
||||
}
|
||||
{
|
||||
// close the project
|
||||
project.close(null);
|
||||
assertEquals(0, MockListenerRegisterer.getCount(EXTENSION_REGISTERER_PROVIDER_ID));
|
||||
}
|
||||
{
|
||||
// reopen the project
|
||||
project.open(null);
|
||||
// initialize project description
|
||||
CProjectDescriptionManager.getInstance().getProjectDescription(project, false);
|
||||
assertEquals(1, MockListenerRegisterer.getCount(EXTENSION_REGISTERER_PROVIDER_ID));
|
||||
// and delete
|
||||
project.delete(true, null);
|
||||
assertEquals(0, MockListenerRegisterer.getCount(EXTENSION_REGISTERER_PROVIDER_ID));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test events triggered for shared provider when the provider removed from the list.
|
||||
*/
|
||||
public void testListenerRegisterer_TwoGlobalMinusOne() throws Exception {
|
||||
// create project
|
||||
IProject project = ResourceHelper.createCDTProject(this.getName(), null, new String[] {
|
||||
"org.eclipse.cdt.core.tests.configuration.id.1",
|
||||
"org.eclipse.cdt.core.tests.configuration.id.2",
|
||||
});
|
||||
ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, true);
|
||||
|
||||
{
|
||||
// retrieve workspace provider
|
||||
ILanguageSettingsProvider workspaceProvider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_REGISTERER_PROVIDER_ID);
|
||||
// get project descriptions
|
||||
ICProjectDescription prjDescriptionWritable = CProjectDescriptionManager.getInstance().getProjectDescription(project, true);
|
||||
assertNotNull(prjDescriptionWritable);
|
||||
ICConfigurationDescription[] cfgDescriptions = prjDescriptionWritable.getConfigurations();
|
||||
assertEquals(2, cfgDescriptions.length);
|
||||
ICConfigurationDescription cfgDescription1 = cfgDescriptions[0];
|
||||
ICConfigurationDescription cfgDescription2 = cfgDescriptions[1];
|
||||
assertTrue(cfgDescription1 instanceof ILanguageSettingsProvidersKeeper);
|
||||
assertTrue(cfgDescription2 instanceof ILanguageSettingsProvidersKeeper);
|
||||
|
||||
{
|
||||
// add global provider to configuration 1
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(workspaceProvider);
|
||||
((ILanguageSettingsProvidersKeeper) cfgDescription1).setLanguageSettingProviders(providers);
|
||||
List<ILanguageSettingsProvider> storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription1).getLanguageSettingProviders();
|
||||
assertEquals(1, storedProviders.size());
|
||||
}
|
||||
{
|
||||
// add global provider to configuration 2
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(workspaceProvider);
|
||||
((ILanguageSettingsProvidersKeeper) cfgDescription2).setLanguageSettingProviders(providers);
|
||||
List<ILanguageSettingsProvider> storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription2).getLanguageSettingProviders();
|
||||
assertEquals(1, storedProviders.size());
|
||||
}
|
||||
// write to project description
|
||||
CoreModel.getDefault().setProjectDescription(project, prjDescriptionWritable);
|
||||
assertEquals(1, MockListenerRegisterer.getCount(EXTENSION_REGISTERER_PROVIDER_ID));
|
||||
}
|
||||
{
|
||||
// retrieve workspace provider
|
||||
ILanguageSettingsProvider workspaceProvider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_REGISTERER_PROVIDER_ID);
|
||||
// get project descriptions
|
||||
ICProjectDescription prjDescriptionWritable = CProjectDescriptionManager.getInstance().getProjectDescription(project, true);
|
||||
assertNotNull(prjDescriptionWritable);
|
||||
ICConfigurationDescription[] cfgDescriptions = prjDescriptionWritable.getConfigurations();
|
||||
assertEquals(2, cfgDescriptions.length);
|
||||
ICConfigurationDescription cfgDescription1 = cfgDescriptions[0];
|
||||
ICConfigurationDescription cfgDescription2 = cfgDescriptions[1];
|
||||
assertTrue(cfgDescription1 instanceof ILanguageSettingsProvidersKeeper);
|
||||
assertTrue(cfgDescription2 instanceof ILanguageSettingsProvidersKeeper);
|
||||
|
||||
{
|
||||
// remove global provider from configuration 1
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
((ILanguageSettingsProvidersKeeper) cfgDescription1).setLanguageSettingProviders(providers);
|
||||
List<ILanguageSettingsProvider> storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription1).getLanguageSettingProviders();
|
||||
assertEquals(0, storedProviders.size());
|
||||
}
|
||||
// write to project description
|
||||
CoreModel.getDefault().setProjectDescription(project, prjDescriptionWritable);
|
||||
assertEquals(1, MockListenerRegisterer.getCount(EXTENSION_REGISTERER_PROVIDER_ID));
|
||||
}
|
||||
{
|
||||
// close the project
|
||||
project.close(null);
|
||||
assertEquals(0, MockListenerRegisterer.getCount(EXTENSION_REGISTERER_PROVIDER_ID));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test events triggered for shared provider define in multiple projects.
|
||||
*/
|
||||
public void testListenerRegisterer_GlobalProviderTwoProjects() throws Exception {
|
||||
// create project 1
|
||||
IProject project_1 = ResourceHelper.createCDTProjectWithConfig(this.getName() + ".1");
|
||||
ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project_1, true);
|
||||
{
|
||||
// get project descriptions
|
||||
ICProjectDescription prjDescriptionWritable = CProjectDescriptionManager.getInstance().getProjectDescription(project_1, true);
|
||||
assertNotNull(prjDescriptionWritable);
|
||||
ICConfigurationDescription[] cfgDescriptions = prjDescriptionWritable.getConfigurations();
|
||||
assertEquals(1, cfgDescriptions.length);
|
||||
ICConfigurationDescription cfgDescription = cfgDescriptions[0];
|
||||
assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper);
|
||||
|
||||
// add global provider
|
||||
ILanguageSettingsProvider workspaceProvider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_REGISTERER_PROVIDER_ID);
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(workspaceProvider);
|
||||
((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers);
|
||||
List<ILanguageSettingsProvider> storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders();
|
||||
assertEquals(1, storedProviders.size());
|
||||
|
||||
// write to project description
|
||||
CoreModel.getDefault().setProjectDescription(project_1, prjDescriptionWritable);
|
||||
assertEquals(1, MockListenerRegisterer.getCount(EXTENSION_REGISTERER_PROVIDER_ID));
|
||||
}
|
||||
|
||||
// create project 2
|
||||
IProject project_2 = ResourceHelper.createCDTProjectWithConfig(this.getName() + ".2");
|
||||
ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project_2, true);
|
||||
{
|
||||
// get project descriptions
|
||||
ICProjectDescription prjDescriptionWritable = CProjectDescriptionManager.getInstance().getProjectDescription(project_2, true);
|
||||
assertNotNull(prjDescriptionWritable);
|
||||
ICConfigurationDescription[] cfgDescriptions = prjDescriptionWritable.getConfigurations();
|
||||
assertEquals(1, cfgDescriptions.length);
|
||||
ICConfigurationDescription cfgDescription = cfgDescriptions[0];
|
||||
assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper);
|
||||
|
||||
// add global provider
|
||||
ILanguageSettingsProvider workspaceProvider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_REGISTERER_PROVIDER_ID);
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(workspaceProvider);
|
||||
((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers);
|
||||
List<ILanguageSettingsProvider> storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders();
|
||||
assertEquals(1, storedProviders.size());
|
||||
|
||||
// write to project description
|
||||
CoreModel.getDefault().setProjectDescription(project_2, prjDescriptionWritable);
|
||||
assertEquals(1, MockListenerRegisterer.getCount(EXTENSION_REGISTERER_PROVIDER_ID));
|
||||
}
|
||||
|
||||
{
|
||||
// close project 1
|
||||
project_1.close(null);
|
||||
assertEquals(1, MockListenerRegisterer.getCount(EXTENSION_REGISTERER_PROVIDER_ID));
|
||||
}
|
||||
{
|
||||
// close project 2
|
||||
project_2.close(null);
|
||||
assertEquals(0, MockListenerRegisterer.getCount(EXTENSION_REGISTERER_PROVIDER_ID));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test events triggered for shared global providers not included in any configuration.
|
||||
*/
|
||||
|
@ -143,12 +503,73 @@ public class LanguageSettingsListenersTests extends BaseTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test events triggered for shared global provider replacing another one in global list.
|
||||
*/
|
||||
public void testListenerRegisterer_GlobalProviderAddRemoveOutsideTheProject() throws Exception {
|
||||
// create project
|
||||
ILanguageSettingsProvider workspaceProvider = LanguageSettingsManager.getWorkspaceProvider(PROVIDER_CUSTOM_GLOBAL);
|
||||
|
||||
// the global custom provider has not been added yet
|
||||
ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(workspaceProvider);
|
||||
assertNull(rawProvider);
|
||||
assertEquals(0, MockListenerRegisterer.getCount(PROVIDER_CUSTOM_GLOBAL));
|
||||
|
||||
// prepare project
|
||||
List<ILanguageSettingsProvider> workspaceProvidersOriginal = LanguageSettingsManager.getWorkspaceProviders();
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName());
|
||||
ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, true);
|
||||
{
|
||||
// get project descriptions
|
||||
ICProjectDescription prjDescriptionWritable = CProjectDescriptionManager.getInstance().getProjectDescription(project, true);
|
||||
assertNotNull(prjDescriptionWritable);
|
||||
ICConfigurationDescription[] cfgDescriptions = prjDescriptionWritable.getConfigurations();
|
||||
assertEquals(1, cfgDescriptions.length);
|
||||
ICConfigurationDescription cfgDescription = cfgDescriptions[0];
|
||||
assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper);
|
||||
|
||||
// add global provider
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(workspaceProvider);
|
||||
((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers);
|
||||
List<ILanguageSettingsProvider> storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders();
|
||||
assertEquals(1, storedProviders.size());
|
||||
|
||||
// write to project description
|
||||
CoreModel.getDefault().setProjectDescription(project, prjDescriptionWritable);
|
||||
// the global custom provider has not been added yet
|
||||
assertEquals(0, MockListenerRegisterer.getCount(PROVIDER_CUSTOM_GLOBAL));
|
||||
}
|
||||
|
||||
{
|
||||
// add global provider
|
||||
ILanguageSettingsProvider provider = new MockListenerRegisterer(PROVIDER_CUSTOM_GLOBAL, PROVIDER_CUSTOM_GLOBAL_NAME);
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(provider);
|
||||
LanguageSettingsManager.setWorkspaceProviders(providers);
|
||||
assertEquals(1, MockListenerRegisterer.getCount(PROVIDER_CUSTOM_GLOBAL));
|
||||
}
|
||||
{
|
||||
// remove global provider
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>(workspaceProvidersOriginal);
|
||||
LanguageSettingsManager.setWorkspaceProviders(providers);
|
||||
assertEquals(0, MockListenerRegisterer.getCount(PROVIDER_CUSTOM_GLOBAL));
|
||||
}
|
||||
|
||||
{
|
||||
// close project
|
||||
project.close(null);
|
||||
assertEquals(0, MockListenerRegisterer.getCount(PROVIDER_CUSTOM_GLOBAL));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test events triggered when empty provider added and the resulting list of entries does not change.
|
||||
*/
|
||||
public void testNotification_cfgProvider_AddEmptyProvider() throws Exception {
|
||||
// create project
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName());
|
||||
ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, true);
|
||||
// First clear default providers
|
||||
{
|
||||
// get project descriptions
|
||||
|
@ -201,12 +622,81 @@ public class LanguageSettingsListenersTests extends BaseTestCase {
|
|||
assertEquals(null, mockLseListener.getLastEvent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test events triggered where non-empty provider added.
|
||||
*/
|
||||
public void testNotification_cfgProvider_AddNonEmptyProvider() throws Exception {
|
||||
// create project
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName());
|
||||
ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, true);
|
||||
// First clear default providers
|
||||
{
|
||||
// get project descriptions
|
||||
ICProjectDescription prjDescriptionWritable = CProjectDescriptionManager.getInstance().getProjectDescription(project, true);
|
||||
assertNotNull(prjDescriptionWritable);
|
||||
ICConfigurationDescription[] cfgDescriptions = prjDescriptionWritable.getConfigurations();
|
||||
assertEquals(1, cfgDescriptions.length);
|
||||
ICConfigurationDescription cfgDescription = cfgDescriptions[0];
|
||||
assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper);
|
||||
|
||||
// clear providers
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers);
|
||||
List<ILanguageSettingsProvider> storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders();
|
||||
assertEquals(0, storedProviders.size());
|
||||
|
||||
// write to project description
|
||||
CoreModel.getDefault().setProjectDescription(project, prjDescriptionWritable);
|
||||
}
|
||||
|
||||
// register mock listener to inspect the notifications
|
||||
LanguageSettingsManager.registerLanguageSettingsChangeListener(mockLseListener);
|
||||
assertEquals(0, mockLseListener.getCount());
|
||||
assertEquals(null, mockLseListener.getLastEvent());
|
||||
|
||||
// Add non-empty provider
|
||||
{
|
||||
// get project descriptions
|
||||
ICProjectDescription prjDescriptionWritable = CProjectDescriptionManager.getInstance().getProjectDescription(project, true);
|
||||
assertNotNull(prjDescriptionWritable);
|
||||
ICConfigurationDescription[] cfgDescriptions = prjDescriptionWritable.getConfigurations();
|
||||
assertEquals(1, cfgDescriptions.length);
|
||||
ICConfigurationDescription cfgDescription = cfgDescriptions[0];
|
||||
String cfgDescriptionId = cfgDescription.getId();
|
||||
assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper);
|
||||
|
||||
// create a provider and add entries
|
||||
MockLanguageSettingsEditableProvider mockProvider = new MockLanguageSettingsEditableProvider(PROVIDER_1, PROVIDER_NAME_1);
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries.add(SAMPLE_LSE);
|
||||
mockProvider.setSettingEntries(cfgDescription, project, null, entries);
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(mockProvider);
|
||||
((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers);
|
||||
List<ILanguageSettingsProvider> storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders();
|
||||
assertEquals(1, storedProviders.size());
|
||||
|
||||
// write to project description
|
||||
CoreModel.getDefault().setProjectDescription(project, prjDescriptionWritable);
|
||||
|
||||
// inspect notifications
|
||||
assertEquals(1, mockLseListener.getCount());
|
||||
ILanguageSettingsChangeEvent event = mockLseListener.getLastEvent();
|
||||
assertNotNull(event);
|
||||
|
||||
assertEquals(project.getName(), event.getProjectName());
|
||||
assertEquals(1, event.getConfigurationDescriptionIds().length);
|
||||
assertEquals(cfgDescriptionId, event.getConfigurationDescriptionIds()[0]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test events triggered during serialization.
|
||||
*/
|
||||
public void testNotification_cfgProvider_SerializeEntries() throws Exception {
|
||||
// create project
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName());
|
||||
ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, true);
|
||||
|
||||
// add the mock provider
|
||||
{
|
||||
|
@ -276,6 +766,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase {
|
|||
public void testNotification_cfgProvider_SerializeEntriesConcurrent() throws Exception {
|
||||
// create project
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName());
|
||||
ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, true);
|
||||
|
||||
// add the mock provider
|
||||
{
|
||||
|
@ -379,6 +870,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase {
|
|||
public void testNotification_globalProvider_AddEmptyProvider() throws Exception {
|
||||
// create project
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName());
|
||||
ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, true);
|
||||
// First clear default providers
|
||||
{
|
||||
// get project descriptions
|
||||
|
@ -438,12 +930,89 @@ public class LanguageSettingsListenersTests extends BaseTestCase {
|
|||
assertEquals(null, mockLseListener.getLastEvent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test events triggered during adding global non-empty provider.
|
||||
*/
|
||||
public void testNotification_globalProvider_AddNonEmptyProvider() throws Exception {
|
||||
// create project
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName());
|
||||
ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, true);
|
||||
// First clear default providers
|
||||
{
|
||||
// get project descriptions
|
||||
ICProjectDescription prjDescriptionWritable = CProjectDescriptionManager.getInstance().getProjectDescription(project, true);
|
||||
assertNotNull(prjDescriptionWritable);
|
||||
ICConfigurationDescription[] cfgDescriptions = prjDescriptionWritable.getConfigurations();
|
||||
assertEquals(1, cfgDescriptions.length);
|
||||
ICConfigurationDescription cfgDescription = cfgDescriptions[0];
|
||||
assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper);
|
||||
|
||||
// clear providers
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers);
|
||||
List<ILanguageSettingsProvider> storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders();
|
||||
assertEquals(0, storedProviders.size());
|
||||
|
||||
// write to project description
|
||||
CoreModel.getDefault().setProjectDescription(project, prjDescriptionWritable);
|
||||
}
|
||||
|
||||
// register mock listener to inspect the notifications
|
||||
LanguageSettingsManager.registerLanguageSettingsChangeListener(mockLseListener);
|
||||
assertEquals(0, mockLseListener.getCount());
|
||||
assertEquals(null, mockLseListener.getLastEvent());
|
||||
|
||||
// Add non-empty provider
|
||||
{
|
||||
// get project descriptions
|
||||
ICProjectDescription prjDescriptionWritable = CProjectDescriptionManager.getInstance().getProjectDescription(project, true);
|
||||
assertNotNull(prjDescriptionWritable);
|
||||
ICConfigurationDescription[] cfgDescriptions = prjDescriptionWritable.getConfigurations();
|
||||
assertEquals(1, cfgDescriptions.length);
|
||||
ICConfigurationDescription cfgDescription = cfgDescriptions[0];
|
||||
assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper);
|
||||
|
||||
String cfgDescriptionId = cfgDescription.getId();
|
||||
|
||||
// retrieve a global provider
|
||||
ILanguageSettingsProvider wspProvider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_EDITABLE_PROVIDER_ID);
|
||||
assertNotNull(wspProvider);
|
||||
ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(wspProvider);
|
||||
assertTrue(rawProvider instanceof MockLanguageSettingsEditableProvider);
|
||||
((MockLanguageSettingsEditableProvider) rawProvider).clear();
|
||||
// add entries
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries.add(SAMPLE_LSE);
|
||||
((MockLanguageSettingsEditableProvider) rawProvider).setSettingEntries(cfgDescription, project, null, entries);
|
||||
assertEquals(SAMPLE_LSE, wspProvider.getSettingEntries(cfgDescription, project, null).get(0));
|
||||
// add the provider to cfgDescription
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(wspProvider);
|
||||
((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers);
|
||||
List<ILanguageSettingsProvider> storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders();
|
||||
assertEquals(1, storedProviders.size());
|
||||
|
||||
// write to project description
|
||||
CoreModel.getDefault().setProjectDescription(project, prjDescriptionWritable);
|
||||
|
||||
// inspect notifications
|
||||
assertEquals(1, mockLseListener.getCount());
|
||||
ILanguageSettingsChangeEvent event = mockLseListener.getLastEvent();
|
||||
assertNotNull(event);
|
||||
|
||||
assertEquals(project.getName(), event.getProjectName());
|
||||
assertEquals(1, event.getConfigurationDescriptionIds().length);
|
||||
assertEquals(cfgDescriptionId, event.getConfigurationDescriptionIds()[0]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test events triggered during serialization of global shared providers.
|
||||
*/
|
||||
public void testNotification_globalProvider_SerializeEntries() throws Exception {
|
||||
// create project
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName());
|
||||
ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, true);
|
||||
|
||||
// register mock listener to inspect the notifications
|
||||
LanguageSettingsManager.registerLanguageSettingsChangeListener(mockLseListener);
|
||||
|
|
|
@ -649,6 +649,59 @@ public class LanguageSettingsManagerTests extends BaseTestCase {
|
|||
assertEquals(3, includes.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test ability to serialize providers for a configuration.
|
||||
*/
|
||||
public void testConfigurationDescription_SerializeProviders() throws Exception {
|
||||
// Create model project and accompanied descriptions
|
||||
String projectName = getName();
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(projectName);
|
||||
ICProjectDescription prjDescriptionWritable = CProjectDescriptionManager.getInstance().getProjectDescription(project, true);
|
||||
|
||||
ICConfigurationDescription[] cfgDescriptions = prjDescriptionWritable.getConfigurations();
|
||||
ICConfigurationDescription cfgDescription = cfgDescriptions[0];
|
||||
assertTrue(cfgDescription instanceof CConfigurationDescription);
|
||||
|
||||
ILanguageSettingsProvider workspaceProvider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_BASE_PROVIDER_ID);
|
||||
assertNotNull(workspaceProvider);
|
||||
{
|
||||
// ensure no test provider is set yet
|
||||
List<ILanguageSettingsProvider> providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders();
|
||||
assertEquals(0, providers.size());
|
||||
}
|
||||
{
|
||||
// set test provider
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(workspaceProvider);
|
||||
((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers);
|
||||
}
|
||||
{
|
||||
// check that test provider got there
|
||||
List<ILanguageSettingsProvider> providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders();
|
||||
assertEquals(workspaceProvider, providers.get(0));
|
||||
}
|
||||
|
||||
{
|
||||
// serialize
|
||||
CProjectDescriptionManager.getInstance().setProjectDescription(project, prjDescriptionWritable);
|
||||
// close and reopen the project
|
||||
project.close(null);
|
||||
project.open(null);
|
||||
}
|
||||
|
||||
{
|
||||
// check that test provider got loaded
|
||||
ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false);
|
||||
ICConfigurationDescription[] loadedCfgDescriptions = prjDescription.getConfigurations();
|
||||
ICConfigurationDescription loadedCfgDescription = loadedCfgDescriptions[0];
|
||||
assertTrue(cfgDescription instanceof CConfigurationDescription);
|
||||
|
||||
List<ILanguageSettingsProvider> loadedProviders = ((ILanguageSettingsProvidersKeeper) loadedCfgDescription).getLanguageSettingProviders();
|
||||
assertTrue(LanguageSettingsManager.isWorkspaceProvider(loadedProviders.get(0)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test a workspace provider basics.
|
||||
*/
|
||||
|
|
|
@ -1026,6 +1026,148 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test serialization of real project.
|
||||
*/
|
||||
public void testProjectPersistence_RealProject() throws Exception {
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName());
|
||||
String xmlStorageFileLocation;
|
||||
String xmlOutOfTheWay;
|
||||
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries.add(new CIncludePathEntry("path0", 0));
|
||||
|
||||
{
|
||||
// get project descriptions
|
||||
ICProjectDescription prjDescriptionWritable = CProjectDescriptionManager.getInstance().getProjectDescription(project, true);
|
||||
assertNotNull(prjDescriptionWritable);
|
||||
ICConfigurationDescription[] cfgDescriptions = prjDescriptionWritable.getConfigurations();
|
||||
assertEquals(1, cfgDescriptions.length);
|
||||
ICConfigurationDescription cfgDescriptionWritable = cfgDescriptions[0];
|
||||
assertNotNull(cfgDescriptionWritable);
|
||||
assertTrue(cfgDescriptionWritable instanceof ILanguageSettingsProvidersKeeper);
|
||||
|
||||
// create a provider
|
||||
LanguageSettingsSerializableProvider mockProvider = new LanguageSettingsSerializableProvider(PROVIDER_0, PROVIDER_NAME_0);
|
||||
LanguageSettingsManager.setStoringEntriesInProjectArea(mockProvider, true);
|
||||
mockProvider.setSettingEntries(cfgDescriptionWritable, null, null, entries);
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(mockProvider);
|
||||
((ILanguageSettingsProvidersKeeper) cfgDescriptionWritable).setLanguageSettingProviders(providers);
|
||||
List<ILanguageSettingsProvider> storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescriptionWritable).getLanguageSettingProviders();
|
||||
assertEquals(1, storedProviders.size());
|
||||
|
||||
// write to project description
|
||||
CProjectDescriptionManager.getInstance().setProjectDescription(project, prjDescriptionWritable);
|
||||
IFile xmlStorageFile = project.getFile(LANGUAGE_SETTINGS_PROJECT_XML);
|
||||
assertTrue(xmlStorageFile.exists());
|
||||
xmlStorageFileLocation = xmlStorageFile.getLocation().toOSString();
|
||||
}
|
||||
{
|
||||
ICConfigurationDescription cfgDescription = getFirstConfigurationDescription(project);
|
||||
assertNotNull(cfgDescription);
|
||||
assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper);
|
||||
|
||||
List<ILanguageSettingsProvider> providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders();
|
||||
assertEquals(1, providers.size());
|
||||
ILanguageSettingsProvider provider = providers.get(0);
|
||||
assertTrue(provider instanceof LanguageSettingsSerializableProvider);
|
||||
assertEquals(PROVIDER_0, provider.getId());
|
||||
assertEquals(PROVIDER_NAME_0, provider.getName());
|
||||
|
||||
List<ICLanguageSettingEntry> actual = provider.getSettingEntries(cfgDescription, null, null);
|
||||
assertEquals(entries.get(0), actual.get(0));
|
||||
assertEquals(entries.size(), actual.size());
|
||||
}
|
||||
{
|
||||
// Move storage out of the way
|
||||
java.io.File xmlFile = new java.io.File(xmlStorageFileLocation);
|
||||
xmlOutOfTheWay = xmlStorageFileLocation+".out-of-the-way";
|
||||
java.io.File xmlFileOut = new java.io.File(xmlOutOfTheWay);
|
||||
xmlFile.renameTo(xmlFileOut);
|
||||
assertFalse(xmlFile.exists());
|
||||
assertTrue(xmlFileOut.exists());
|
||||
}
|
||||
{
|
||||
// Should not pollute workspace area with file with no meaningful data
|
||||
String xmlWspStorageFileLocation = getStoreLocationInWorkspaceArea(project.getName()+'.'+LANGUAGE_SETTINGS_WORKSPACE_XML);
|
||||
java.io.File xmlStorageFileWsp = new java.io.File(xmlWspStorageFileLocation);
|
||||
assertFalse(xmlStorageFileWsp.exists());
|
||||
}
|
||||
|
||||
{
|
||||
// clear configuration
|
||||
ICProjectDescription prjDescriptionWritable = CProjectDescriptionManager.getInstance().getProjectDescription(project, true);
|
||||
ICConfigurationDescription[] cfgDescriptions = prjDescriptionWritable.getConfigurations();
|
||||
assertEquals(1, cfgDescriptions.length);
|
||||
ICConfigurationDescription cfgDescriptionWritable = cfgDescriptions[0];
|
||||
assertNotNull(cfgDescriptionWritable);
|
||||
assertTrue(cfgDescriptionWritable instanceof ILanguageSettingsProvidersKeeper);
|
||||
|
||||
((ILanguageSettingsProvidersKeeper) cfgDescriptionWritable).setLanguageSettingProviders(new ArrayList<ILanguageSettingsProvider>());
|
||||
CProjectDescriptionManager.getInstance().setProjectDescription(project, prjDescriptionWritable);
|
||||
List<ILanguageSettingsProvider> providers = ((ILanguageSettingsProvidersKeeper) cfgDescriptionWritable).getLanguageSettingProviders();
|
||||
assertEquals(0, providers.size());
|
||||
}
|
||||
{
|
||||
// re-check if it really took it
|
||||
ICConfigurationDescription cfgDescription = getFirstConfigurationDescription(project);
|
||||
assertNotNull(cfgDescription);
|
||||
assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper);
|
||||
|
||||
List<ILanguageSettingsProvider> providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders();
|
||||
assertEquals(0, providers.size());
|
||||
}
|
||||
{
|
||||
// close the project
|
||||
project.close(null);
|
||||
}
|
||||
{
|
||||
// open to double-check the data is not kept in some other kind of cache
|
||||
project.open(null);
|
||||
ICConfigurationDescription cfgDescription = getFirstConfigurationDescription(project);
|
||||
assertNotNull(cfgDescription);
|
||||
assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper);
|
||||
|
||||
List<ILanguageSettingsProvider> providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders();
|
||||
assertEquals(0, providers.size());
|
||||
// and close
|
||||
project.close(null);
|
||||
}
|
||||
|
||||
{
|
||||
// Move storage back
|
||||
java.io.File xmlFile = new java.io.File(xmlStorageFileLocation);
|
||||
xmlFile.delete();
|
||||
assertFalse("File "+xmlFile+ " still exist", xmlFile.exists());
|
||||
java.io.File xmlFileOut = new java.io.File(xmlOutOfTheWay);
|
||||
xmlFileOut.renameTo(xmlFile);
|
||||
assertTrue("File "+xmlFile+ " does not exist", xmlFile.exists());
|
||||
assertFalse("File "+xmlFileOut+ " still exist", xmlFileOut.exists());
|
||||
}
|
||||
|
||||
{
|
||||
// Remove project from internal cache
|
||||
CProjectDescriptionManager.getInstance().projectClosedRemove(project);
|
||||
// open project and check if providers are loaded
|
||||
project.open(null);
|
||||
ICConfigurationDescription cfgDescription = getFirstConfigurationDescription(project);
|
||||
assertNotNull(cfgDescription);
|
||||
assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper);
|
||||
|
||||
List<ILanguageSettingsProvider> providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders();
|
||||
assertEquals(1, providers.size());
|
||||
ILanguageSettingsProvider loadedProvider = providers.get(0);
|
||||
assertTrue(loadedProvider instanceof LanguageSettingsSerializableProvider);
|
||||
assertEquals(PROVIDER_0, loadedProvider.getId());
|
||||
assertEquals(PROVIDER_NAME_0, loadedProvider.getName());
|
||||
|
||||
List<ICLanguageSettingEntry> actual = loadedProvider.getSettingEntries(cfgDescription, null, null);
|
||||
assertEquals(entries.get(0), actual.get(0));
|
||||
assertEquals(entries.size(), actual.size());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case when the storage is split between project and workspace area.
|
||||
*/
|
||||
|
@ -1087,6 +1229,8 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* TODO: refactor with ErrorParserManager
|
||||
*
|
||||
* @param store - name of the store
|
||||
* @return location of the store in the plug-in state area
|
||||
*/
|
||||
|
@ -1095,6 +1239,171 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase {
|
|||
return location.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test split storage in a real project.
|
||||
*/
|
||||
public void testProjectPersistence_RealProjectSplitStorage() throws Exception {
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName());
|
||||
String xmlStorageFileLocation;
|
||||
String xmlOutOfTheWay;
|
||||
String xmlWspStorageFileLocation;
|
||||
String xmlWspOutOfTheWay;
|
||||
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries.add(new CIncludePathEntry("path0", 0));
|
||||
|
||||
{
|
||||
// get project descriptions
|
||||
ICProjectDescription prjDescriptionWritable = CProjectDescriptionManager.getInstance().getProjectDescription(project, true);
|
||||
assertNotNull(prjDescriptionWritable);
|
||||
ICConfigurationDescription[] cfgDescriptions = prjDescriptionWritable.getConfigurations();
|
||||
assertEquals(1, cfgDescriptions.length);
|
||||
ICConfigurationDescription cfgDescriptionWritable = cfgDescriptions[0];
|
||||
assertNotNull(cfgDescriptionWritable);
|
||||
assertTrue(cfgDescriptionWritable instanceof ILanguageSettingsProvidersKeeper);
|
||||
|
||||
// create a provider
|
||||
LanguageSettingsSerializableProvider mockProvider = new LanguageSettingsSerializableProvider(PROVIDER_0, PROVIDER_NAME_0);
|
||||
LanguageSettingsManager.setStoringEntriesInProjectArea(mockProvider, false);
|
||||
mockProvider.setSettingEntries(cfgDescriptionWritable, null, null, entries);
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(mockProvider);
|
||||
((ILanguageSettingsProvidersKeeper) cfgDescriptionWritable).setLanguageSettingProviders(providers);
|
||||
List<ILanguageSettingsProvider> storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescriptionWritable).getLanguageSettingProviders();
|
||||
assertEquals(1, storedProviders.size());
|
||||
|
||||
// write to project description
|
||||
CProjectDescriptionManager.getInstance().setProjectDescription(project, prjDescriptionWritable);
|
||||
IFile xmlStorageFile = project.getFile(LANGUAGE_SETTINGS_PROJECT_XML);
|
||||
assertTrue(xmlStorageFile.exists());
|
||||
xmlStorageFileLocation = xmlStorageFile.getLocation().toOSString();
|
||||
// TODO - cleanup names
|
||||
xmlWspStorageFileLocation = getStoreLocationInWorkspaceArea(project.getName()+'.'+LANGUAGE_SETTINGS_WORKSPACE_XML);
|
||||
java.io.File xmlStorageFileWsp = new java.io.File(xmlWspStorageFileLocation);
|
||||
assertTrue(xmlStorageFileWsp.exists());
|
||||
}
|
||||
{
|
||||
ICConfigurationDescription cfgDescription = getFirstConfigurationDescription(project);
|
||||
assertNotNull(cfgDescription);
|
||||
assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper);
|
||||
|
||||
List<ILanguageSettingsProvider> providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders();
|
||||
assertEquals(1, providers.size());
|
||||
ILanguageSettingsProvider provider = providers.get(0);
|
||||
assertTrue(provider instanceof LanguageSettingsSerializableProvider);
|
||||
assertEquals(PROVIDER_0, provider.getId());
|
||||
assertEquals(PROVIDER_NAME_0, provider.getName());
|
||||
|
||||
List<ICLanguageSettingEntry> actual = provider.getSettingEntries(cfgDescription, null, null);
|
||||
assertEquals(entries.get(0), actual.get(0));
|
||||
assertEquals(entries.size(), actual.size());
|
||||
}
|
||||
// Move storages out of the way
|
||||
{
|
||||
java.io.File xmlFile = new java.io.File(xmlStorageFileLocation);
|
||||
xmlOutOfTheWay = xmlStorageFileLocation+".out-of-the-way";
|
||||
java.io.File xmlFileOut = new java.io.File(xmlOutOfTheWay);
|
||||
xmlFile.renameTo(xmlFileOut);
|
||||
assertFalse(xmlFile.exists());
|
||||
assertTrue(xmlFileOut.exists());
|
||||
}
|
||||
{
|
||||
// TODO - workspace file
|
||||
java.io.File xmlStorageFileWsp = new java.io.File(xmlWspStorageFileLocation);
|
||||
assertTrue(xmlStorageFileWsp.exists());
|
||||
xmlWspOutOfTheWay = xmlWspStorageFileLocation+".out-of-the-way";
|
||||
java.io.File xmlWspFileOut = new java.io.File(xmlWspOutOfTheWay);
|
||||
boolean result = xmlStorageFileWsp.renameTo(xmlWspFileOut);
|
||||
assertTrue(result);
|
||||
assertFalse(xmlStorageFileWsp.exists());
|
||||
assertTrue(xmlWspFileOut.exists());
|
||||
}
|
||||
|
||||
{
|
||||
// clear configuration
|
||||
ICProjectDescription prjDescriptionWritable = CProjectDescriptionManager.getInstance().getProjectDescription(project, true);
|
||||
ICConfigurationDescription[] cfgDescriptions = prjDescriptionWritable.getConfigurations();
|
||||
assertEquals(1, cfgDescriptions.length);
|
||||
ICConfigurationDescription cfgDescriptionWritable = cfgDescriptions[0];
|
||||
assertNotNull(cfgDescriptionWritable);
|
||||
assertTrue(cfgDescriptionWritable instanceof ILanguageSettingsProvidersKeeper);
|
||||
|
||||
((ILanguageSettingsProvidersKeeper) cfgDescriptionWritable).setLanguageSettingProviders(new ArrayList<ILanguageSettingsProvider>());
|
||||
CProjectDescriptionManager.getInstance().setProjectDescription(project, prjDescriptionWritable);
|
||||
List<ILanguageSettingsProvider> providers = ((ILanguageSettingsProvidersKeeper) cfgDescriptionWritable).getLanguageSettingProviders();
|
||||
assertEquals(0, providers.size());
|
||||
}
|
||||
{
|
||||
// re-check if it really took it
|
||||
ICConfigurationDescription cfgDescription = getFirstConfigurationDescription(project);
|
||||
assertNotNull(cfgDescription);
|
||||
assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper);
|
||||
|
||||
List<ILanguageSettingsProvider> providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders();
|
||||
assertEquals(0, providers.size());
|
||||
}
|
||||
{
|
||||
// close the project
|
||||
project.close(null);
|
||||
}
|
||||
{
|
||||
// open to double-check the data is not kept in some other kind of cache
|
||||
project.open(null);
|
||||
ICConfigurationDescription cfgDescription = getFirstConfigurationDescription(project);
|
||||
assertNotNull(cfgDescription);
|
||||
assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper);
|
||||
|
||||
List<ILanguageSettingsProvider> providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders();
|
||||
assertEquals(0, providers.size());
|
||||
// and close
|
||||
project.close(null);
|
||||
}
|
||||
|
||||
{
|
||||
// Move storage back
|
||||
java.io.File xmlFile = new java.io.File(xmlStorageFileLocation);
|
||||
xmlFile.delete();
|
||||
assertFalse("File "+xmlFile+ " still exist", xmlFile.exists());
|
||||
java.io.File xmlFileOut = new java.io.File(xmlOutOfTheWay);
|
||||
xmlFileOut.renameTo(xmlFile);
|
||||
assertTrue("File "+xmlFile+ " does not exist", xmlFile.exists());
|
||||
assertFalse("File "+xmlFileOut+ " still exist", xmlFileOut.exists());
|
||||
}
|
||||
|
||||
{
|
||||
// TODO
|
||||
// Move storage back
|
||||
java.io.File xmlWspFile = new java.io.File(xmlWspStorageFileLocation);
|
||||
xmlWspFile.delete();
|
||||
assertFalse("File "+xmlWspFile+ " still exist", xmlWspFile.exists());
|
||||
java.io.File xmlWspFileOut = new java.io.File(xmlWspOutOfTheWay);
|
||||
xmlWspFileOut.renameTo(xmlWspFile);
|
||||
assertTrue("File "+xmlWspFile+ " does not exist", xmlWspFile.exists());
|
||||
assertFalse("File "+xmlWspFileOut+ " still exist", xmlWspFileOut.exists());
|
||||
}
|
||||
|
||||
{
|
||||
// Remove project from internal cache
|
||||
CProjectDescriptionManager.getInstance().projectClosedRemove(project);
|
||||
// open project and check if providers are loaded
|
||||
project.open(null);
|
||||
ICConfigurationDescription cfgDescription = getFirstConfigurationDescription(project);
|
||||
assertNotNull(cfgDescription);
|
||||
assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper);
|
||||
|
||||
List<ILanguageSettingsProvider> providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders();
|
||||
assertEquals(1, providers.size());
|
||||
ILanguageSettingsProvider loadedProvider = providers.get(0);
|
||||
assertTrue(loadedProvider instanceof LanguageSettingsSerializableProvider);
|
||||
assertEquals(PROVIDER_0, loadedProvider.getId());
|
||||
assertEquals(PROVIDER_NAME_0, loadedProvider.getName());
|
||||
|
||||
List<ICLanguageSettingEntry> actual = loadedProvider.getSettingEntries(cfgDescription, null, null);
|
||||
assertEquals(entries.get(0), actual.get(0));
|
||||
assertEquals(entries.size(), actual.size());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test serialization of providers referring to global shared instance.
|
||||
*/
|
||||
|
|
|
@ -11,11 +11,13 @@
|
|||
|
||||
package org.eclipse.cdt.core.language.settings.providers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.internal.core.LocalProjectScope;
|
||||
import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsExtensionManager;
|
||||
import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.preferences.InstanceScope;
|
||||
import org.osgi.service.prefs.BackingStoreException;
|
||||
|
@ -81,19 +83,16 @@ public class ScannerDiscoveryLegacySupport {
|
|||
}
|
||||
|
||||
/**
|
||||
* @noreference This is internal helper method to support compatibility with previous versions
|
||||
* which is not intended to be referenced by clients.
|
||||
* Return list containing MBS and User provider. Used to initialize for unaware tool-chains (backward compatibility).
|
||||
*/
|
||||
public static boolean isMbsLanguageSettingsProviderOn(ICConfigurationDescription cfgDescription) {
|
||||
if (cfgDescription instanceof ILanguageSettingsProvidersKeeper) {
|
||||
List<ILanguageSettingsProvider> lsProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders();
|
||||
for (ILanguageSettingsProvider lsp : lsProviders) {
|
||||
if (MBS_LANGUAGE_SETTINGS_PROVIDER_ID.equals(lsp.getId())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
public static List<ILanguageSettingsProvider> getDefaultProvidersLegacy() {
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>(2);
|
||||
ILanguageSettingsProvider provider = LanguageSettingsExtensionManager.getExtensionProviderCopy((ScannerDiscoveryLegacySupport.USER_LANGUAGE_SETTINGS_PROVIDER_ID), false);
|
||||
if (provider != null) {
|
||||
providers.add(provider);
|
||||
}
|
||||
return false;
|
||||
providers.add(LanguageSettingsProvidersSerializer.getWorkspaceProvider(ScannerDiscoveryLegacySupport.MBS_LANGUAGE_SETTINGS_PROVIDER_ID));
|
||||
return providers;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.eclipse.cdt.core.CCorePlugin;
|
|||
import org.eclipse.cdt.core.cdtvariables.CdtVariableException;
|
||||
import org.eclipse.cdt.core.cdtvariables.ICdtVariable;
|
||||
import org.eclipse.cdt.core.cdtvariables.ICdtVariableManager;
|
||||
import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySupport;
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.CoreModelUtil;
|
||||
|
@ -63,6 +64,7 @@ import org.eclipse.cdt.internal.core.CharOperation;
|
|||
import org.eclipse.cdt.internal.core.cdtvariables.CoreVariableSubstitutor;
|
||||
import org.eclipse.cdt.internal.core.cdtvariables.DefaultVariableContextInfo;
|
||||
import org.eclipse.cdt.internal.core.cdtvariables.ICoreVariableContextInfo;
|
||||
import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer;
|
||||
import org.eclipse.cdt.internal.core.model.APathEntry;
|
||||
import org.eclipse.cdt.internal.core.model.CModelStatus;
|
||||
import org.eclipse.cdt.internal.core.model.PathEntry;
|
||||
|
@ -2046,6 +2048,16 @@ public class PathEntryTranslator {
|
|||
return false;
|
||||
}
|
||||
|
||||
IProject project = cfgDescription.getProjectDescription().getProject();
|
||||
if (ScannerDiscoveryLegacySupport.isLanguageSettingsProvidersFunctionalityEnabled(project)) {
|
||||
IResource rc = findResourceInWorkspace(project, rcData.getPath());
|
||||
for (CLanguageData lData : lDatas) {
|
||||
list.addAll(LanguageSettingsProvidersSerializer.getSettingEntriesByKind(cfgDescription, rc, lData.getLanguageId(), kind));
|
||||
}
|
||||
return list.size()>0;
|
||||
|
||||
}
|
||||
// Legacy logic
|
||||
boolean supported = false;
|
||||
for (CLanguageData lData : lDatas) {
|
||||
if (collectLanguageDataEntries(kind, lData, list))
|
||||
|
@ -2070,4 +2082,14 @@ public class PathEntryTranslator {
|
|||
PathEntryCollector cr = collectEntries(project, cfgDescription);
|
||||
return cr.getEntries(flags, cfgDescription);
|
||||
}
|
||||
|
||||
private static IResource findResourceInWorkspace(IProject project, IPath workspacePath) {
|
||||
IResource rc;
|
||||
if (project != null) {
|
||||
rc = project.findMember(workspacePath);
|
||||
} else {
|
||||
rc = ResourcesPlugin.getWorkspace().getRoot().findMember(workspacePath);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -259,9 +259,15 @@ public class LanguageSettingsProvidersSerializer {
|
|||
CCorePlugin.log(e);
|
||||
}
|
||||
if (specSettings != null) {
|
||||
LanguageSettingsDelta delta = specSettings.dropDelta();
|
||||
if (delta != null)
|
||||
deltaMap.put(cfgDescription.getId(), delta);
|
||||
String cfgId = cfgDescription.getId();
|
||||
if (ScannerDiscoveryLegacySupport.isLanguageSettingsProvidersFunctionalityEnabled(prjDescription.getProject())) {
|
||||
LanguageSettingsDelta delta = specSettings.dropDelta();
|
||||
if (delta != null) {
|
||||
deltaMap.put(cfgId, delta);
|
||||
}
|
||||
} else {
|
||||
deltaMap.remove(cfgId);
|
||||
}
|
||||
} else {
|
||||
IStatus ss = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "Internal error: Missing specSettings for " //$NON-NLS-1$
|
||||
+ cfgDescription.getClass().getSimpleName());
|
||||
|
@ -1051,10 +1057,7 @@ public class LanguageSettingsProvidersSerializer {
|
|||
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);
|
||||
((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(ScannerDiscoveryLegacySupport.getDefaultProvidersLegacy());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,14 +12,19 @@
|
|||
package org.eclipse.cdt.internal.core.language.settings.providers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.cdtvariables.CdtVariableException;
|
||||
import org.eclipse.cdt.core.cdtvariables.ICdtVariableManager;
|
||||
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsChangeEvent;
|
||||
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsChangeListener;
|
||||
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager;
|
||||
import org.eclipse.cdt.core.parser.ExtendedScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
|
@ -35,6 +40,7 @@ import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager;
|
|||
import org.eclipse.cdt.internal.core.settings.model.SettingsModelMessages;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
|
@ -49,11 +55,13 @@ import org.eclipse.osgi.util.NLS;
|
|||
* @see IScannerInfo#getIncludePaths()
|
||||
*
|
||||
*/
|
||||
public class LanguageSettingsScannerInfoProvider implements IScannerInfoProvider {
|
||||
public class LanguageSettingsScannerInfoProvider implements IScannerInfoProvider, ILanguageSettingsChangeListener {
|
||||
private static final String FRAMEWORK_PRIVATE_HEADERS_INCLUDE = "/__framework__.framework/PrivateHeaders/__header__"; //$NON-NLS-1$
|
||||
private static final String FRAMEWORK_HEADERS_INCLUDE = "/__framework__.framework/Headers/__header__"; //$NON-NLS-1$
|
||||
private static final ExtendedScannerInfo DUMMY_SCANNER_INFO = new ExtendedScannerInfo();
|
||||
|
||||
private Map<IResource, List<IScannerInfoChangeListener>> listenersMap = null;
|
||||
|
||||
@Override
|
||||
public ExtendedScannerInfo getScannerInformation(IResource rc) {
|
||||
IProject project = rc.getProject();
|
||||
|
@ -259,12 +267,70 @@ public class LanguageSettingsScannerInfoProvider implements IScannerInfoProvider
|
|||
|
||||
@Override
|
||||
public void subscribe(IResource resource, IScannerInfoChangeListener listener) {
|
||||
// Handled by ScannerInfoProviderProxy for the moment
|
||||
if (resource == null || listener == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (listenersMap == null) {
|
||||
listenersMap = Collections.synchronizedMap(new HashMap<IResource, List<IScannerInfoChangeListener>>());
|
||||
}
|
||||
|
||||
IProject project = resource.getProject();
|
||||
List<IScannerInfoChangeListener> list = listenersMap.get(project);
|
||||
if (list == null) {
|
||||
list = new Vector<IScannerInfoChangeListener>();
|
||||
listenersMap.put(project, list);
|
||||
}
|
||||
if (!list.contains(listener)) {
|
||||
list.add(listener);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsubscribe(IResource resource, IScannerInfoChangeListener listener) {
|
||||
// Handled by ScannerInfoProviderProxy for the moment
|
||||
if (resource == null || listener == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
IProject project = resource.getProject();
|
||||
if (listenersMap != null) {
|
||||
List<IScannerInfoChangeListener> list = listenersMap.get(project);
|
||||
if (list != null) {
|
||||
list.remove(listener);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleEvent(ILanguageSettingsChangeEvent event) {
|
||||
if (listenersMap == null || listenersMap.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(event.getProjectName());
|
||||
if (project != null) {
|
||||
ICProjectDescription prjDescription = CCorePlugin.getDefault().getProjectDescription(project);
|
||||
if (prjDescription != null) {
|
||||
ICConfigurationDescription indexedCfgDescription = prjDescription.getDefaultSettingConfiguration();
|
||||
String indexedCfgId = indexedCfgDescription.getId();
|
||||
|
||||
for (String cfgId : event.getConfigurationDescriptionIds()) {
|
||||
if (cfgId.equals(indexedCfgId)) {
|
||||
for (Entry<IResource, List<IScannerInfoChangeListener>> entry : listenersMap.entrySet()) {
|
||||
IResource rc = entry.getKey();
|
||||
List<IScannerInfoChangeListener> listeners = listenersMap.get(rc);
|
||||
if (listeners != null && !listeners.isEmpty()) {
|
||||
IScannerInfo info = getScannerInformation(rc);
|
||||
for (IScannerInfoChangeListener listener : listeners) {
|
||||
listener.changeNotification(rc, info);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,6 +42,7 @@ import org.eclipse.cdt.core.settings.model.extension.ICProjectConverter;
|
|||
import org.eclipse.cdt.core.settings.model.util.CDataUtil;
|
||||
import org.eclipse.cdt.internal.core.XmlUtil;
|
||||
import org.eclipse.cdt.internal.core.envvar.ContributedEnvironment;
|
||||
import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer;
|
||||
import org.eclipse.cdt.internal.core.settings.model.AbstractCProjectDescriptionStorage;
|
||||
import org.eclipse.cdt.internal.core.settings.model.CProjectDescription;
|
||||
import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager;
|
||||
|
@ -170,6 +171,7 @@ public class XmlProjectDescriptionStorage extends AbstractCProjectDescriptionSto
|
|||
}, null, IWorkspace.AVOID_UPDATE, null);
|
||||
// end Bug 249951 & Bug 310007
|
||||
serializingLock.acquire();
|
||||
LanguageSettingsProvidersSerializer.serializeLanguageSettings(fDes);
|
||||
projectModificaitonStamp = serialize(fDes.getProject(), ICProjectDescriptionStorageType.STORAGE_FILE_NAME, fElement);
|
||||
((ContributedEnvironment) CCorePlugin.getDefault().getBuildEnvironmentManager().getContributedEnvironment()).serialize(fDes);
|
||||
} finally {
|
||||
|
@ -364,6 +366,7 @@ public class XmlProjectDescriptionStorage extends AbstractCProjectDescriptionSto
|
|||
if (!overwriteIfExists && fProjectDescription.get() != null)
|
||||
return false;
|
||||
|
||||
ICProjectDescription oldDes = fProjectDescription.get();
|
||||
if (des != null) {
|
||||
if (project.exists() && project.isOpen()) {
|
||||
fProjectDescription = new SoftReference<ICProjectDescription>(des);
|
||||
|
@ -374,6 +377,8 @@ public class XmlProjectDescriptionStorage extends AbstractCProjectDescriptionSto
|
|||
} else {
|
||||
fProjectDescription = new SoftReference<ICProjectDescription>(null);
|
||||
}
|
||||
|
||||
LanguageSettingsProvidersSerializer.reRegisterListeners(oldDes, fProjectDescription.get());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -486,6 +491,8 @@ public class XmlProjectDescriptionStorage extends AbstractCProjectDescriptionSto
|
|||
try {
|
||||
setThreadLocalProjectDesc(des);
|
||||
des.loadDatas();
|
||||
|
||||
LanguageSettingsProvidersSerializer.loadLanguageSettings(des);
|
||||
des.doneLoading();
|
||||
} finally {
|
||||
setThreadLocalProjectDesc(null);
|
||||
|
|
|
@ -47,6 +47,7 @@ import org.eclipse.cdt.core.index.IIndexManager;
|
|||
import org.eclipse.cdt.core.index.IIndexerStateListener;
|
||||
import org.eclipse.cdt.core.index.IndexLocationFactory;
|
||||
import org.eclipse.cdt.core.index.IndexerSetupParticipant;
|
||||
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager;
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.ICContainer;
|
||||
|
@ -167,6 +168,7 @@ public class PDOMManager implements IWritableIndexManager, IListener {
|
|||
|
||||
private CModelListener fCModelListener= new CModelListener(this);
|
||||
private ILanguageMappingChangeListener fLanguageChangeListener = new LanguageMappingChangeListener(this);
|
||||
private LanguageSettingsChangeListener fLanguageSettingsChangeListener = new LanguageSettingsChangeListener(this);
|
||||
private final ICProjectDescriptionListener fProjectDescriptionListener;
|
||||
private final JobChangeListener fJobChangeListener;
|
||||
private final IPreferenceChangeListener fPreferenceChangeListener;
|
||||
|
@ -240,6 +242,7 @@ public class PDOMManager implements IWritableIndexManager, IListener {
|
|||
ResourcesPlugin.getWorkspace().addResourceChangeListener(fCModelListener, IResourceChangeEvent.POST_BUILD);
|
||||
model.addElementChangedListener(fCModelListener);
|
||||
LanguageManager.getInstance().registerLanguageChangeListener(fLanguageChangeListener);
|
||||
LanguageSettingsManager.registerLanguageSettingsChangeListener(fLanguageSettingsChangeListener);
|
||||
final int types= CProjectDescriptionEvent.DATA_APPLIED;
|
||||
CCorePlugin.getDefault().getProjectDescriptionManager().addCProjectDescriptionListener(fProjectDescriptionListener, types);
|
||||
|
||||
|
@ -260,6 +263,7 @@ public class PDOMManager implements IWritableIndexManager, IListener {
|
|||
final CoreModel model = CoreModel.getDefault();
|
||||
model.removeElementChangedListener(fCModelListener);
|
||||
ResourcesPlugin.getWorkspace().removeResourceChangeListener(fCModelListener);
|
||||
LanguageSettingsManager.unregisterLanguageSettingsChangeListener(fLanguageSettingsChangeListener);
|
||||
LanguageManager.getInstance().unregisterLanguageChangeListener(fLanguageChangeListener);
|
||||
PDOMIndexerJob jobToCancel= null;
|
||||
synchronized (fTaskQueue) {
|
||||
|
|
|
@ -28,6 +28,7 @@ import org.eclipse.cdt.core.cdtvariables.IUserVarSupplier;
|
|||
import org.eclipse.cdt.core.dom.IPDOMManager;
|
||||
import org.eclipse.cdt.core.envvar.IEnvironmentVariableManager;
|
||||
import org.eclipse.cdt.core.index.IIndexManager;
|
||||
import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySupport;
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
|
@ -50,6 +51,7 @@ import org.eclipse.cdt.internal.core.PositionTrackerManager;
|
|||
import org.eclipse.cdt.internal.core.cdtvariables.CdtVariableManager;
|
||||
import org.eclipse.cdt.internal.core.cdtvariables.UserVarSupplier;
|
||||
import org.eclipse.cdt.internal.core.envvar.EnvironmentVariableManager;
|
||||
import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsScannerInfoProvider;
|
||||
import org.eclipse.cdt.internal.core.model.CModelManager;
|
||||
import org.eclipse.cdt.internal.core.model.Util;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOMManager;
|
||||
|
@ -1025,28 +1027,17 @@ public class CCorePlugin extends Plugin {
|
|||
return provider;
|
||||
|
||||
// Next search the extension registry to see if a provider is registered with a build command
|
||||
IExtensionRegistry registry = Platform.getExtensionRegistry();
|
||||
IExtensionPoint point = registry.getExtensionPoint(SCANNER_INFO_PROVIDER2);
|
||||
if (point != null) {
|
||||
IExtension[] exts = point.getExtensions();
|
||||
for (IExtension ext : exts) {
|
||||
IConfigurationElement[] elems = ext.getConfigurationElements();
|
||||
for (IConfigurationElement elem : elems) {
|
||||
String builder = elem.getAttribute("builder"); //$NON-NLS-1$
|
||||
if (builder != null) {
|
||||
IProjectDescription desc = project.getDescription();
|
||||
ICommand[] commands = desc.getBuildSpec();
|
||||
for (ICommand command : commands)
|
||||
if (builder.equals(command.getBuilderName()))
|
||||
provider = (IScannerInfoProvider)elem.createExecutableExtension("class"); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
}
|
||||
provider = getExtensionScannerInfoProvider2(project);
|
||||
|
||||
// Regular usage is where Language Settings Providers are employed
|
||||
if (provider == null && ScannerDiscoveryLegacySupport.isLanguageSettingsProvidersFunctionalityEnabled(project)) {
|
||||
provider = new LanguageSettingsScannerInfoProvider();
|
||||
}
|
||||
|
||||
// Default to the proxy
|
||||
// Fall back to the MBS legacy
|
||||
if (provider == null)
|
||||
provider = fNewCProjectDescriptionManager.getScannerInfoProviderProxy(project);
|
||||
|
||||
project.setSessionProperty(scannerInfoProviderName, provider);
|
||||
} catch (CoreException e) {
|
||||
// Bug 313725: When project is being closed, don't report an error.
|
||||
|
@ -1059,6 +1050,33 @@ public class CCorePlugin extends Plugin {
|
|||
return provider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find {@link IScannerInfoProvider} registered as extension via extension point
|
||||
* org.eclipse.cdt.core.ScannerInfoProvider2.
|
||||
*/
|
||||
private IScannerInfoProvider getExtensionScannerInfoProvider2(IProject project) throws CoreException {
|
||||
IScannerInfoProvider provider = null;
|
||||
IExtensionRegistry registry = Platform.getExtensionRegistry();
|
||||
IExtensionPoint point = registry.getExtensionPoint(SCANNER_INFO_PROVIDER2);
|
||||
if (point != null) {
|
||||
IExtension[] exts = point.getExtensions();
|
||||
for (IExtension ext : exts) {
|
||||
IConfigurationElement[] elems = ext.getConfigurationElements();
|
||||
for (IConfigurationElement elem : elems) {
|
||||
String builder = elem.getAttribute("builder"); //$NON-NLS-1$
|
||||
if (builder != null) {
|
||||
IProjectDescription desc = project.getDescription();
|
||||
ICommand[] commands = desc.getBuildSpec();
|
||||
for (ICommand command : commands)
|
||||
if (builder.equals(command.getBuilderName()))
|
||||
provider = (IScannerInfoProvider)elem.createExecutableExtension("class"); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return provider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function, returning the content type for a filename
|
||||
* Same as: <pre>
|
||||
|
@ -1385,4 +1403,4 @@ public class CCorePlugin extends Plugin {
|
|||
return InstanceScope.INSTANCE.getNode(PLUGIN_ID)
|
||||
.getBoolean(CCorePreferenceConstants.SHOW_SOURCE_ROOTS_AT_TOP_LEVEL_OF_PROJECT, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue