From fbc67e72a2bb7fed8343cccbccdbbe7e06f534e9 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Thu, 7 Jul 2011 12:29:41 -0400 Subject: [PATCH 001/120] Initial commit of new Scanner Discovery for CDT - bug 290631. See prior history on GitHub https://github.com/angvoz/SD80/, branch sd80 --- .../plugin.xml | 14 + .../make/scannerdiscovery/AllSD80Tests.java | 26 + .../GCCBuildCommandParserTest.java | 1904 +++++++++++++++++ .../ScannerDiscoveryTests.java | 4 +- build/org.eclipse.cdt.make.core/plugin.xml | 9 + .../AbstractBuildCommandParser.java | 130 ++ ...AbstractLanguageSettingsOutputScanner.java | 821 +++++++ .../scannerconfig/GCCBuildCommandParser.java | 72 + .../ILanguageSettingsBuildOutputScanner.java | 29 + ...ILanguageSettingsBuiltinSpecsDetector.java | 28 + .../ILanguageSettingsOutputScanner.java | 35 + .../icons/obj16/inspect_system.gif | Bin 0 -> 553 bytes .../icons/obj16/log_obj.gif | Bin 0 -> 335 bytes .../icons/obj16/search.gif | Bin 0 -> 347 bytes .../org.eclipse.cdt.make.ui/plugin.properties | 3 + build/org.eclipse.cdt.make.ui/plugin.xml | 31 + .../GCCBuildCommandParserOptionPage.java | 370 ++++ .../ScannerDiscoveryConsole.java | 39 + .../tests/suite/AllManagedBuildTests.java | 2 + .../scannerconfig/tests/AllSD80Tests.java | 29 + .../tests/GCCBuiltinSpecsDetectorTest.java | 659 ++++++ .../plugin.xml | 28 + .../schema/buildDefinitions.exsd | 45 +- .../CfgScannerConfigProfileManager.java | 36 + .../core/ExternalBuildRunner.java | 89 +- .../managedbuilder/core/IConfiguration.java | 3 + .../cdt/managedbuilder/core/IToolChain.java | 9 + .../core/InternalBuildRunner.java | 66 +- .../core/ManagedBuildManager.java | 145 ++ .../internal/core/CommonBuilder.java | 3 + .../internal/core/Configuration.java | 8 + .../internal/core/MultiConfiguration.java | 5 + .../internal/core/ToolChain.java | 8 + .../AbstractBuiltinSpecsDetector.java | 508 +++++ .../GCCBuiltinSpecsDetector.java | 135 ++ .../MBSLanguageSettingsProvider.java | 113 + .../plugin.xml | 25 +- .../ui/tests/util/TestConfiguration.java | 5 + .../ui/tests/util/TestToolchain.java | 9 +- .../icons/obj16/mbs.gif | Bin 0 -> 380 bytes .../icons/obj16/search.gif | Bin 0 -> 347 bytes .../plugin.properties | 1 + .../plugin.xml | 11 + .../managedbuilder/internal/ui/Messages.java | 2 + .../internal/ui/Messages.properties | 1 + .../BuiltinSpecsDetectorOptionPage.java | 325 +++ .../ui/preferences/PropertyPageDefsTab.java | 11 +- .../ui/preferences/WizardDefaultsTab.java | 8 + .../ui/wizards/MBSWizardHandler.java | 35 +- .../ui/wizards/NewMakeProjFromExisting.java | 35 +- .../wizards/NewMakeProjFromExistingPage.java | 23 + .../ui/wizards/STDWizardHandler.java | 42 +- .../ram/MemoryEFSExtensionProvider.java | 33 + .../AllLanguageSettingsProvidersTests.java | 32 + .../LanguageSettingsExtensionsTests.java | 324 +++ .../LanguageSettingsManagerTests.java | 781 +++++++ ...nguageSettingsPersistenceProjectTests.java | 839 ++++++++ ...guageSettingsScannerInfoProviderTests.java | 893 ++++++++ .../LanguageSettingsSerializableTests.java | 1146 ++++++++++ .../MockLanguageSettingsBaseProvider.java | 19 + .../MockLanguageSettingsEditableProvider.java | 30 + .../MockLanguageSettingsProvider.java | 28 + ...kLanguageSettingsSerializableProvider.java | 25 + .../cdt/core/model/tests/AllCoreTests.java | 3 + .../index/tests/IndexProviderManagerTest.java | 7 + core/org.eclipse.cdt.core.tests/plugin.xml | 157 ++ .../cdt/core/testplugin/CModelMock.java | 416 ++++ .../org.eclipse.cdt.core/META-INF/MANIFEST.MF | 2 + .../providers/ILanguageSettingsProvider.java | 65 + .../LanguageSettingsBaseProvider.java | 175 ++ .../providers/LanguageSettingsManager.java | 204 ++ .../LanguageSettingsManager_TBD.java | 99 + .../LanguageSettingsSerializable.java | 504 +++++ .../LanguageSettingsSerializableEditable.java | 28 + .../model/ACExclusionFilterEntry.java | 3 +- .../cdt/core/settings/model/ACPathEntry.java | 8 +- .../model/ICConfigurationDescription.java | 27 + .../core/settings/model/ICSettingEntry.java | 15 + .../ILanguageSettingsEditableProvider.java | 34 + .../LanguageSettingEntriesSerializer.java | 20 +- .../model/util/PathEntryTranslator.java | 48 +- .../LanguageSettingsExtensionManager.java | 517 +++++ .../providers/LanguageSettingsLogger.java | 79 + .../LanguageSettingsProvidersSerializer.java | 456 ++++ .../LanguageSettingsScannerInfoProvider.java | 325 +++ .../model/CConfigurationDescription.java | 19 + .../model/CConfigurationDescriptionCache.java | 34 + .../model/CConfigurationSpecSettings.java | 42 +- .../model/DescriptionScannerInfoProvider.java | 4 + .../model/MultiConfigDescription.java | 13 + .../model/ScannerInfoProviderProxy.java | 11 + .../model/SettingsModelMessages.properties | 6 +- .../xml/XmlProjectDescriptionStorage.java | 4 + core/org.eclipse.cdt.core/plugin.properties | 1 + core/org.eclipse.cdt.core/plugin.xml | 5 +- .../schema/LanguageSettingsProvider.exsd | 264 +++ .../core/AbstractExecutableExtensionBase.java | 83 + .../src/org/eclipse/cdt/core/CCorePlugin.java | 2 +- .../eclipse/cdt/core/ErrorParserManager.java | 2 +- .../org/eclipse/cdt/core/ICConsoleParser.java | 25 + .../cdt/core/resources/ScannerProvider.java | 9 + .../internal/core/ConsoleOutputSniffer.java | 30 +- core/org.eclipse.cdt.ui/META-INF/MANIFEST.MF | 1 + .../icons/obj16/filesyst.gif | Bin 310 -> 144 bytes .../icons/obj16/frameworks.gif | Bin 0 -> 904 bytes .../icons/obj16/ls_entries.gif | Bin 0 -> 386 bytes .../icons/obj16/ls_entries_provider.gif | Bin 0 -> 371 bytes .../icons/obj16/provider_ls_obj.gif | Bin 0 -> 186 bytes .../org.eclipse.cdt.ui/icons/obj16/search.gif | Bin 0 -> 347 bytes .../icons/ovr16/cfg_ovr.gif | Bin 0 -> 155 bytes .../icons/ovr16/edited_ov.gif | Bin 0 -> 167 bytes .../icons/ovr16/empty_ovr.png | Bin 0 -> 335 bytes .../icons/ovr16/global_ovr.gif | Bin 0 -> 271 bytes .../icons/ovr16/import_co.gif | Bin 0 -> 68 bytes .../icons/ovr16/link_ovr.gif | Bin 0 -> 169 bytes .../icons/ovr16/lock_ovr.gif | Bin 0 -> 115 bytes .../icons/ovr16/overlay-has-context.gif | Bin 0 -> 162 bytes .../icons/ovr16/project_co.gif | Bin 0 -> 112 bytes core/org.eclipse.cdt.ui/plugin.properties | 8 +- core/org.eclipse.cdt.ui/plugin.xml | 43 + .../LanguageSettingsProviderAssociation.exsd | 155 ++ .../eclipse/cdt/internal/ui/ImageCombo.java | 1471 +++++++++++++ ...ractLanguageSettingProviderOptionPage.java | 13 + .../providers/LanguageSettingEntryDialog.java | 644 ++++++ .../providers/LanguageSettingsEntriesTab.java | 1128 ++++++++++ .../LanguageSettingsProviderAssociation.java | 246 +++ .../LanguageSettingsProviderTab.java | 1059 +++++++++ ...anguageSettingsProvidersLabelProvider.java | 118 + .../Page_LanguageSettingsProviders.java | 41 + .../UserLanguageSettingsProvider.java | 47 + .../ui/newui/LanguageSettingsImages.java | 195 ++ .../cdt/internal/ui/newui/Messages.java | 11 + .../cdt/internal/ui/newui/Messages.properties | 11 + .../internal/ui/newui/StatusMessageLine.java | 81 + .../viewsupport/ProblemsLabelDecorator.java | 4 +- .../org/eclipse/cdt/ui/CDTSharedImages.java | 18 + .../cdt/ui/newui/AbstractCPropertyTab.java | 7 + .../cdt/ui/newui/AbstractLangsListTab.java | 109 +- .../org/eclipse/cdt/ui/newui/CDTPrefUtil.java | 2 + .../cdt/ui/wizards/CDTMainWizardPage.java | 19 + .../plugin.xml | 20 +- .../xlc/core/XlcBuiltinSpecsDetector.java | 97 + 142 files changed, 19260 insertions(+), 123 deletions(-) create mode 100644 build/org.eclipse.cdt.make.core.tests/plugin.xml create mode 100644 build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/AllSD80Tests.java create mode 100644 build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java create mode 100644 build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java create mode 100644 build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java create mode 100644 build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/GCCBuildCommandParser.java create mode 100644 build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/ILanguageSettingsBuildOutputScanner.java create mode 100644 build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/ILanguageSettingsBuiltinSpecsDetector.java create mode 100644 build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/ILanguageSettingsOutputScanner.java create mode 100644 build/org.eclipse.cdt.make.ui/icons/obj16/inspect_system.gif create mode 100644 build/org.eclipse.cdt.make.ui/icons/obj16/log_obj.gif create mode 100644 build/org.eclipse.cdt.make.ui/icons/obj16/search.gif create mode 100644 build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/preferences/GCCBuildCommandParserOptionPage.java create mode 100644 build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/scannerconfig/ScannerDiscoveryConsole.java create mode 100644 build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/AllSD80Tests.java create mode 100644 build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/GCCBuiltinSpecsDetectorTest.java create mode 100644 build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/AbstractBuiltinSpecsDetector.java create mode 100644 build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/GCCBuiltinSpecsDetector.java create mode 100644 build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/MBSLanguageSettingsProvider.java create mode 100644 build/org.eclipse.cdt.managedbuilder.ui/icons/obj16/mbs.gif create mode 100644 build/org.eclipse.cdt.managedbuilder.ui/icons/obj16/search.gif create mode 100644 build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/preferences/BuiltinSpecsDetectorOptionPage.java create mode 100644 core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/tests/filesystem/ram/MemoryEFSExtensionProvider.java create mode 100644 core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/AllLanguageSettingsProvidersTests.java create mode 100644 core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java create mode 100644 core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java create mode 100644 core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java create mode 100644 core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsScannerInfoProviderTests.java create mode 100644 core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java create mode 100644 core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockLanguageSettingsBaseProvider.java create mode 100644 core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockLanguageSettingsEditableProvider.java create mode 100644 core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockLanguageSettingsProvider.java create mode 100644 core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockLanguageSettingsSerializableProvider.java create mode 100644 core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/CModelMock.java create mode 100644 core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsProvider.java create mode 100644 core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsBaseProvider.java create mode 100644 core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java create mode 100644 core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager_TBD.java create mode 100644 core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java create mode 100644 core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableEditable.java create mode 100644 core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ILanguageSettingsEditableProvider.java create mode 100644 core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java create mode 100644 core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsLogger.java create mode 100644 core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java create mode 100644 core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsScannerInfoProvider.java create mode 100644 core/org.eclipse.cdt.core/schema/LanguageSettingsProvider.exsd create mode 100644 core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/AbstractExecutableExtensionBase.java create mode 100644 core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICConsoleParser.java create mode 100644 core/org.eclipse.cdt.ui/icons/obj16/frameworks.gif create mode 100644 core/org.eclipse.cdt.ui/icons/obj16/ls_entries.gif create mode 100644 core/org.eclipse.cdt.ui/icons/obj16/ls_entries_provider.gif create mode 100644 core/org.eclipse.cdt.ui/icons/obj16/provider_ls_obj.gif create mode 100644 core/org.eclipse.cdt.ui/icons/obj16/search.gif create mode 100644 core/org.eclipse.cdt.ui/icons/ovr16/cfg_ovr.gif create mode 100644 core/org.eclipse.cdt.ui/icons/ovr16/edited_ov.gif create mode 100644 core/org.eclipse.cdt.ui/icons/ovr16/empty_ovr.png create mode 100644 core/org.eclipse.cdt.ui/icons/ovr16/global_ovr.gif create mode 100644 core/org.eclipse.cdt.ui/icons/ovr16/import_co.gif create mode 100644 core/org.eclipse.cdt.ui/icons/ovr16/link_ovr.gif create mode 100644 core/org.eclipse.cdt.ui/icons/ovr16/lock_ovr.gif create mode 100644 core/org.eclipse.cdt.ui/icons/ovr16/overlay-has-context.gif create mode 100644 core/org.eclipse.cdt.ui/icons/ovr16/project_co.gif create mode 100644 core/org.eclipse.cdt.ui/schema/LanguageSettingsProviderAssociation.exsd create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/ImageCombo.java create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/AbstractLanguageSettingProviderOptionPage.java create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingEntryDialog.java create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderAssociation.java create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProvidersLabelProvider.java create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/Page_LanguageSettingsProviders.java create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/UserLanguageSettingsProvider.java create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/LanguageSettingsImages.java create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/StatusMessageLine.java create mode 100644 xlc/org.eclipse.cdt.managedbuilder.xlc.core/src/org/eclipse/cdt/managedbuilder/xlc/core/XlcBuiltinSpecsDetector.java diff --git a/build/org.eclipse.cdt.make.core.tests/plugin.xml b/build/org.eclipse.cdt.make.core.tests/plugin.xml new file mode 100644 index 00000000000..f0a7adef70f --- /dev/null +++ b/build/org.eclipse.cdt.make.core.tests/plugin.xml @@ -0,0 +1,14 @@ + + + + + + + + diff --git a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/AllSD80Tests.java b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/AllSD80Tests.java new file mode 100644 index 00000000000..f4b900a04c7 --- /dev/null +++ b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/AllSD80Tests.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2010, 2011 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.make.scannerdiscovery; + +import junit.framework.TestSuite; + +public class AllSD80Tests extends TestSuite { + + public static TestSuite suite() { + return new AllSD80Tests(); + } + + public AllSD80Tests() { + super(AllSD80Tests.class.getName()); + + addTestSuite(GCCBuildCommandParserTest.class); + } +} diff --git a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java new file mode 100644 index 00000000000..1f71546aaca --- /dev/null +++ b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java @@ -0,0 +1,1904 @@ +/******************************************************************************* + * Copyright (c) 2009, 2011 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.make.scannerdiscovery; + +import java.net.URI; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import junit.framework.TestCase; + +import org.eclipse.cdt.core.ErrorParserManager; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; +import org.eclipse.cdt.core.model.CoreModel; +import org.eclipse.cdt.core.settings.model.CIncludeFileEntry; +import org.eclipse.cdt.core.settings.model.CIncludePathEntry; +import org.eclipse.cdt.core.settings.model.CLibraryFileEntry; +import org.eclipse.cdt.core.settings.model.CLibraryPathEntry; +import org.eclipse.cdt.core.settings.model.CMacroEntry; +import org.eclipse.cdt.core.settings.model.CMacroFileEntry; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICLanguageSetting; +import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; +import org.eclipse.cdt.core.settings.model.ICProjectDescription; +import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager; +import org.eclipse.cdt.core.settings.model.ICSettingEntry; +import org.eclipse.cdt.core.testplugin.ResourceHelper; +import org.eclipse.cdt.internal.core.XmlUtil; +import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager; +import org.eclipse.cdt.make.core.scannerconfig.AbstractBuildCommandParser; +import org.eclipse.cdt.make.core.scannerconfig.GCCBuildCommandParser; +import org.eclipse.cdt.make.core.scannerconfig.ILanguageSettingsBuildOutputScanner; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.content.IContentType; +import org.eclipse.core.runtime.content.IContentTypeManager; +import org.eclipse.core.runtime.content.IContentTypeSettings; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +public class GCCBuildCommandParserTest extends TestCase { + // ID of the parser taken from the extension point + private static final String GCC_BUILD_COMMAND_PARSER_EXT = "org.eclipse.cdt.make.core.build.command.parser.gcc"; //$NON-NLS-1$ + + private static final String ELEM_TEST = "test"; + private static final String LANG_CPP = "org.eclipse.cdt.core.g++"; + + // those attributes must match that in AbstractBuiltinSpecsDetector + private static final String ATTR_EXPAND_RELATIVE_PATHS = "expand-relative-paths"; //$NON-NLS-1$ + + private class MockBuildCommandParser extends AbstractBuildCommandParser implements Cloneable { + @Override + protected AbstractOptionParser[] getOptionParsers() { + return new AbstractOptionParser[] {}; + } + @Override + public MockBuildCommandParser cloneShallow() throws CloneNotSupportedException { + return (MockBuildCommandParser) super.cloneShallow(); + } + @Override + public MockBuildCommandParser clone() throws CloneNotSupportedException { + return (MockBuildCommandParser) super.clone(); + } + } + + @Override + protected void setUp() throws Exception { + } + + @Override + protected void tearDown() throws Exception { + ResourceHelper.cleanUp(); + } + + private ICConfigurationDescription[] getConfigurationDescriptions(IProject project) { + CoreModel coreModel = CoreModel.getDefault(); + ICProjectDescriptionManager mngr = coreModel.getProjectDescriptionManager(); + // project description + ICProjectDescription projectDescription = mngr.getProjectDescription(project); + assertNotNull(projectDescription); + assertEquals(1, projectDescription.getConfigurations().length); + // configuration description + ICConfigurationDescription[] cfgDescriptions = projectDescription.getConfigurations(); + return cfgDescriptions; + } + + /** + * Sets build working directory for DefaultSettingConfiguration being tested. + */ + private void setBuilderCWD(IProject project, IPath buildCWD) throws CoreException { + CProjectDescriptionManager manager = CProjectDescriptionManager.getInstance(); + { + ICProjectDescription prjDescription = manager.getProjectDescription(project, true); + assertNotNull(prjDescription); + ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); + assertNotNull(cfgDescription); + + cfgDescription.getBuildSetting().setBuilderCWD(buildCWD); + manager.setProjectDescription(project, prjDescription); + // doublecheck builderCWD + IPath actualBuildCWD = cfgDescription.getBuildSetting().getBuilderCWD(); + assertEquals(buildCWD, actualBuildCWD); + } + { + // triplecheck builderCWD for different project/configuration descriptions + ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false); + assertNotNull(prjDescription); + ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); + assertNotNull(cfgDescription); + + } + } + + private void setReference(IProject project, final IProject projectReferenced) throws CoreException { + { + CoreModel coreModel = CoreModel.getDefault(); + ICProjectDescriptionManager mngr = coreModel.getProjectDescriptionManager(); + // project description + ICProjectDescription projectDescription = mngr.getProjectDescription(project); + assertNotNull(projectDescription); + assertEquals(1, projectDescription.getConfigurations().length); + // configuration description + ICConfigurationDescription[] cfgDescriptions = projectDescription.getConfigurations(); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + final ICConfigurationDescription cfgDescriptionReferenced = getConfigurationDescriptions(projectReferenced)[0]; + cfgDescription.setReferenceInfo(new HashMap() {{ put(projectReferenced.getName(), cfgDescriptionReferenced.getId()); }}); + coreModel.setProjectDescription(project, projectDescription); + } + + { + // doublecheck that it's set as expected + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + Map refs = cfgDescription.getReferenceInfo(); + assertEquals(1, refs.size()); + Set referencedProjectsNames = new LinkedHashSet(refs.keySet()); + assertEquals(projectReferenced.getName(), referencedProjectsNames.toArray()[0]); + } + + } + + + public void testAbstractBuildCommandParser_CloneAndEquals() throws Exception { + // create instance to compare to + MockBuildCommandParser parser = new MockBuildCommandParser(); + assertEquals(true, parser.isResolvingPaths()); + + // check clone after initialization + MockBuildCommandParser clone0 = parser.clone(); + assertTrue(parser.equals(clone0)); + + // configure provider + parser.setResolvingPaths(false); + assertFalse(parser.equals(clone0)); + + // check another clone after configuring + { + MockBuildCommandParser clone = parser.clone(); + assertTrue(parser.equals(clone)); + } + + // check 'expand relative paths' flag + { + MockBuildCommandParser clone = parser.clone(); + boolean expandRelativePaths = clone.isResolvingPaths(); + clone.setResolvingPaths( ! expandRelativePaths ); + assertFalse(parser.equals(clone)); + } + + // check cloneShallow() + { + MockBuildCommandParser parser2 = parser.clone(); + MockBuildCommandParser clone = parser2.cloneShallow(); + assertTrue(parser2.equals(clone)); + } + + } + + public void testAbstractBuildCommandParser_Serialize() throws Exception { + { + // create empty XML + Document doc = XmlUtil.newDocument(); + Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST); + + // load it to new provider + MockBuildCommandParser parser = new MockBuildCommandParser(); + parser.load(rootElement); + assertEquals(true, parser.isResolvingPaths()); + } + + Element elementProvider; + { + // define mock parser + MockBuildCommandParser parser = new MockBuildCommandParser(); + assertEquals(true, parser.isResolvingPaths()); + + // redefine the settings + parser.setResolvingPaths(false); + assertEquals(false, parser.isResolvingPaths()); + + // serialize in XML + Document doc = XmlUtil.newDocument(); + Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST); + elementProvider = parser.serialize(rootElement); + String xmlString = XmlUtil.toString(doc); + + assertTrue(xmlString.contains(ATTR_EXPAND_RELATIVE_PATHS)); + } + { + // create another instance of the provider + MockBuildCommandParser parser = new MockBuildCommandParser(); + assertEquals(true, parser.isResolvingPaths()); + + // load element + parser.load(elementProvider); + assertEquals(false, parser.isResolvingPaths()); + } + } + + public void testAbstractBuildCommandParser_Nulls() throws Exception { + MockBuildCommandParser parser = new MockBuildCommandParser(); + parser.startup(null); + parser.processLine(null); + parser.shutdown(); + + List entries = parser.getSettingEntries(null, null, null); + assertNull(entries); + } + + public void testAbstractBuildCommandParser_Basic() throws Exception { + // Create model project and accompanied descriptions + String projectName = getName(); + IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + final IFile file=ResourceHelper.createFile(project, "file.cpp"); + + // create test class + ILanguageSettingsBuildOutputScanner parser = new MockBuildCommandParser() { + @Override + public boolean processLine(String line, ErrorParserManager epm) { + // pretending that we parsed the line + currentResource = file; + List entries = new ArrayList(); + ICLanguageSettingEntry entry = new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN); + entries.add(entry); + setSettingEntries(entries); + return true; + } + }; + // parse line + parser.startup(cfgDescription); + parser.processLine("gcc -DMACRO=VALUE file.cpp"); + parser.shutdown(); + + // sanity check that it does not return same values for all inputs + List noentries = parser.getSettingEntries(null, null, null); + assertNull(noentries); + + // check populated entries + ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); + String languageId = ls.getLanguageId(); + + List entries = parser.getSettingEntries(cfgDescription, file, languageId); + CMacroEntry expected = new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN); + assertEquals(expected, entries.get(0)); + } + +// public void testGCCBuildCommandParser_Nulls() throws Exception { +// GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); +// parser.startup(null); +// parser.processLine(null); +// parser.shutdown(); +// +// List entries = parser.getSettingEntries(null, null, null); +// assertNull(entries); +// } + + /** + */ + public void testOneEntry() throws Exception { + // Create model project and accompanied descriptions + String projectName = getName(); + IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + IFile file=ResourceHelper.createFile(project, "file.cpp"); + ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); + String languageId = ls.getLanguageId(); + + // create GCCBuildCommandParser + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + + // parse line + parser.startup(cfgDescription); + parser.processLine("gcc -I/path0 file.cpp"); + parser.shutdown(); + + // check populated entries + List entries = parser.getSettingEntries(cfgDescription, file, languageId); + { + IPath path = new Path("/path0").setDevice(project.getLocation().getDevice()); + CIncludePathEntry expected = new CIncludePathEntry(path, 0); + CIncludePathEntry entry = (CIncludePathEntry)entries.get(0); + assertEquals(expected.getName(), entry.getName()); + assertEquals(expected.getValue(), entry.getValue()); + assertEquals(expected.getKind(), entry.getKind()); + assertEquals(expected.getFlags(), entry.getFlags()); + assertEquals(expected, entry); + } + } + + /** + */ + public void testGccFlavors() throws Exception { + // Create model project and accompanied descriptions + String projectName = getName(); + IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + IFile file1=ResourceHelper.createFile(project, "file1.cpp"); + IFile file2=ResourceHelper.createFile(project, "file2.cpp"); + IFile file3=ResourceHelper.createFile(project, "file3.cpp"); + IFile file4=ResourceHelper.createFile(project, "file4.cpp"); + IFile file5=ResourceHelper.createFile(project, "file5.cpp"); + ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file1.getProjectRelativePath(), true); + String languageId = ls.getLanguageId(); + + // create GCCBuildCommandParser + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + + // parse line + parser.startup(cfgDescription); + parser.processLine("gcc -I/path0 file1.cpp"); + parser.processLine("gcc-4.2 -I/path0 file2.cpp"); + parser.processLine("g++ -I/path0 file3.cpp"); + parser.processLine("c++ -I/path0 file4.cpp"); + parser.processLine("\"gcc\" -I/path0 file5.cpp"); + parser.shutdown(); + + // check populated entries + IPath path0 = new Path("/path0").setDevice(project.getLocation().getDevice()); + { + List entries = parser.getSettingEntries(cfgDescription, file1, languageId); + assertEquals(new CIncludePathEntry(path0, 0), entries.get(0)); + } + { + List entries = parser.getSettingEntries(cfgDescription, file2, languageId); + assertEquals(new CIncludePathEntry(path0, 0), entries.get(0)); + } + { + List entries = parser.getSettingEntries(cfgDescription, file3, languageId); + assertEquals(new CIncludePathEntry(path0, 0), entries.get(0)); + } + { + List entries = parser.getSettingEntries(cfgDescription, file4, languageId); + assertEquals(new CIncludePathEntry(path0, 0), entries.get(0)); + } + { + List entries = parser.getSettingEntries(cfgDescription, file5, languageId); + assertEquals(new CIncludePathEntry(path0, 0), entries.get(0)); + } + } + + /** + */ + public void testCIncludePathEntry() throws Exception { + // Create model project and accompanied descriptions + String projectName = getName(); + IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + IFile file=ResourceHelper.createFile(project, "file.cpp"); + ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); + String languageId = ls.getLanguageId(); + + // create GCCBuildCommandParser + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + + // parse line + parser.startup(cfgDescription); + parser.processLine("gcc" + // regular + + " -I/path0 " + // space after -I + + " -I /path1 " + // unknown option, should be ignored + + " -? " + // double-quoted path with spaces + + " -I\"/path with spaces\"" + // single-quoted path with spaces + + " -I'/path with spaces2'" + // second single-quoted and space after -I + + " -I '/path with spaces3'" + + " file.cpp"); + parser.shutdown(); + + // check populated entries + List entries = parser.getSettingEntries(cfgDescription, file, languageId); + { + IPath path = new Path("/path0").setDevice(project.getLocation().getDevice()); + CIncludePathEntry expected = new CIncludePathEntry(path, 0); + CIncludePathEntry entry = (CIncludePathEntry)entries.get(0); + assertEquals(expected.getName(), entry.getName()); + assertEquals(expected.getValue(), entry.getValue()); + assertEquals(expected.getKind(), entry.getKind()); + assertEquals(expected.getFlags(), entry.getFlags()); + assertEquals(expected, entry); + } + { + IPath path = new Path("/path1").setDevice(project.getLocation().getDevice()); + CIncludePathEntry expected = new CIncludePathEntry(path, 0); + CIncludePathEntry entry = (CIncludePathEntry)entries.get(1); + assertEquals(expected, entry); + } + { + IPath path = new Path("/path with spaces").setDevice(project.getLocation().getDevice()); + CIncludePathEntry expected = new CIncludePathEntry(path, 0); + CIncludePathEntry entry = (CIncludePathEntry)entries.get(2); + assertEquals(expected, entry); + } + { + IPath path = new Path("/path with spaces2").setDevice(project.getLocation().getDevice()); + CIncludePathEntry expected = new CIncludePathEntry(path, 0); + CIncludePathEntry entry = (CIncludePathEntry)entries.get(3); + assertEquals(expected, entry); + } + { + IPath path = new Path("/path with spaces3").setDevice(project.getLocation().getDevice()); + CIncludePathEntry expected = new CIncludePathEntry(path, 0); + CIncludePathEntry entry = (CIncludePathEntry)entries.get(4); + assertEquals(expected, entry); + } + } + + /** + */ + public void testCMacroEntry() throws Exception { + // Create model project and accompanied descriptions + String projectName = getName(); + IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + IFile file=ResourceHelper.createFile(project, "file.cpp"); + ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); + String languageId = ls.getLanguageId(); + + // create GCCBuildCommandParser + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + + // parse line + parser.startup(cfgDescription); + parser.processLine("gcc " + + " -DMACRO0" + + " -DMACRO1=value" + + " -DMACRO2=\"value with spaces\"" + + " -DMACRO3='value with spaces'" + + " -DMACRO4='\"quoted value\"'" + + " -D'MACRO5=\"quoted value\"'" + + " -DMACRO6=\\\"escape-quoted value\\\"" + + " -DMACRO7=\"'single-quoted value'\"" + + " file.cpp"); + parser.shutdown(); + + // check populated entries + List entries = parser.getSettingEntries(cfgDescription, file, languageId); + { + CMacroEntry expected = new CMacroEntry("MACRO0", "", 0); + CMacroEntry entry = (CMacroEntry)entries.get(0); + assertEquals(expected.getName(), entry.getName()); + assertEquals(expected.getValue(), entry.getValue()); + assertEquals(expected.getKind(), entry.getKind()); + assertEquals(expected.getFlags(), entry.getFlags()); + assertEquals(expected, entry); + } + { + CMacroEntry expected = new CMacroEntry("MACRO1", "value", 0); + CMacroEntry entry = (CMacroEntry)entries.get(1); + assertEquals(expected, entry); + } + { + CMacroEntry expected = new CMacroEntry("MACRO2", "value with spaces", 0); + CMacroEntry entry = (CMacroEntry)entries.get(2); + assertEquals(expected, entry); + } + { + CMacroEntry expected = new CMacroEntry("MACRO3", "value with spaces", 0); + CMacroEntry entry = (CMacroEntry)entries.get(3); + assertEquals(expected, entry); + } + { + CMacroEntry expected = new CMacroEntry("MACRO4", "\"quoted value\"", 0); + CMacroEntry entry = (CMacroEntry)entries.get(4); + assertEquals(expected, entry); + } + { + CMacroEntry expected = new CMacroEntry("MACRO5", "\"quoted value\"", 0); + CMacroEntry entry = (CMacroEntry)entries.get(5); + assertEquals(expected, entry); + } + { + CMacroEntry expected = new CMacroEntry("MACRO6", "\"escape-quoted value\"", 0); + CMacroEntry entry = (CMacroEntry)entries.get(6); + assertEquals(expected, entry); + } + { + CMacroEntry expected = new CMacroEntry("MACRO7", "'single-quoted value'", 0); + CMacroEntry entry = (CMacroEntry)entries.get(7); + assertEquals(expected, entry); + } + } + + /** + */ + public void testCMacroEntry_undef() throws Exception { + // Create model project and accompanied descriptions + String projectName = getName(); + IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + IFile file=ResourceHelper.createFile(project, "file.cpp"); + ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); + String languageId = ls.getLanguageId(); + + // create GCCBuildCommandParser + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + + // parse line + parser.startup(cfgDescription); + parser.processLine("gcc " + + " -UMACRO" + + " file.cpp"); + parser.shutdown(); + + // check populated entries + List entries = parser.getSettingEntries(cfgDescription, file, languageId); + { + assertEquals(new CMacroEntry("MACRO", null, ICSettingEntry.UNDEFINED), entries.get(0)); + } + } + + /** + */ + public void testCIncludeFileEntry() throws Exception { + // Create model project and accompanied descriptions + String projectName = getName(); + IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + IFile file=ResourceHelper.createFile(project, "file.cpp"); + ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); + String languageId = ls.getLanguageId(); + + // create GCCBuildCommandParser + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + + // parse line + parser.startup(cfgDescription); + parser.processLine("gcc " + + " -include /include.file1" + + " -include '/include.file with spaces'" + + " -include ../../include.file2" + + " -include include.file3" + + " -include ../../include-file-with-dashes" + + " file.cpp"); + parser.shutdown(); + + // check populated entries + List entries = parser.getSettingEntries(cfgDescription, file, languageId); + { + IPath incFile = new Path("/include.file1").setDevice(project.getLocation().getDevice()); + CIncludeFileEntry expected = new CIncludeFileEntry(incFile, 0); + CIncludeFileEntry entry = (CIncludeFileEntry)entries.get(0); + assertEquals(expected.getName(), entry.getName()); + assertEquals(expected.getValue(), entry.getValue()); + assertEquals(expected.getKind(), entry.getKind()); + assertEquals(expected.getFlags(), entry.getFlags()); + assertEquals(expected, entry); + } + + { + IPath incFile = new Path("/include.file with spaces").setDevice(project.getLocation().getDevice()); + assertEquals(new CIncludeFileEntry(incFile, 0), entries.get(1)); + } + { + assertEquals(new CIncludeFileEntry(project.getLocation().removeLastSegments(2).append("include.file2"), 0), entries.get(2)); + assertEquals(new CIncludeFileEntry(project.getFullPath().append("include.file3"), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(3)); + assertEquals(new CIncludeFileEntry(project.getLocation().removeLastSegments(2).append("include-file-with-dashes"), 0), entries.get(4)); + } + } + + /** + */ + public void testCMacroFileEntry() throws Exception { + // Create model project and accompanied descriptions + String projectName = getName(); + IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + IFile file=ResourceHelper.createFile(project, "file.cpp"); + ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); + String languageId = ls.getLanguageId(); + + // create GCCBuildCommandParser + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + + // parse line + parser.startup(cfgDescription); + parser.processLine("gcc -macros macro.file file.cpp"); + parser.processLine("gcc " + + " -macros /macro.file" + + " -macros '/macro.file with spaces'" + + " file.cpp"); + parser.shutdown(); + + // check populated entries + List entries = parser.getSettingEntries(cfgDescription, file, languageId); + { + IPath path = new Path("/macro.file").setDevice(project.getLocation().getDevice()); + CMacroFileEntry expected = new CMacroFileEntry(path, 0); + CMacroFileEntry entry = (CMacroFileEntry)entries.get(0); + assertEquals(expected.getName(), entry.getName()); + assertEquals(expected.getValue(), entry.getValue()); + assertEquals(expected.getKind(), entry.getKind()); + assertEquals(expected.getFlags(), entry.getFlags()); + assertEquals(expected, entry); + } + { + IPath path = new Path("/macro.file with spaces").setDevice(project.getLocation().getDevice()); + CMacroFileEntry expected = new CMacroFileEntry(path, 0); + CMacroFileEntry entry = (CMacroFileEntry)entries.get(1); + assertEquals(expected, entry); + } + } + + /** + */ + public void testCLibraryPathEntry() throws Exception { + // Create model project and accompanied descriptions + String projectName = getName(); + IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + IFile file=ResourceHelper.createFile(project, "file.cpp"); + ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); + String languageId = ls.getLanguageId(); + + // create GCCBuildCommandParser + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + + // parse line + parser.startup(cfgDescription); + parser.processLine("gcc " + + " -L/path0" + + " -L'/path with spaces'" + + " file.cpp"); + parser.shutdown(); + + // check populated entries + List entries = parser.getSettingEntries(cfgDescription, file, languageId); + { + IPath path = new Path("/path0").setDevice(project.getLocation().getDevice()); + CLibraryPathEntry expected = new CLibraryPathEntry(path, 0); + CLibraryPathEntry entry = (CLibraryPathEntry)entries.get(0); + assertEquals(expected.getName(), entry.getName()); + assertEquals(expected.getValue(), entry.getValue()); + assertEquals(expected.getKind(), entry.getKind()); + assertEquals(expected.getFlags(), entry.getFlags()); + assertEquals(expected, entry); + } + { + IPath path = new Path("/path with spaces").setDevice(project.getLocation().getDevice()); + CLibraryPathEntry expected = new CLibraryPathEntry(path, 0); + CLibraryPathEntry entry = (CLibraryPathEntry)entries.get(1); + assertEquals(expected, entry); + } + } + + /** + */ + public void testCLibraryFileEntry() throws Exception { + // Create model project and accompanied descriptions + String projectName = getName(); + IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + IFile file=ResourceHelper.createFile(project, "file.cpp"); + ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); + String languageId = ls.getLanguageId(); + + // create GCCBuildCommandParser + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + + // parse line + parser.startup(cfgDescription); + parser.processLine("gcc -ldomain file.cpp"); + parser.shutdown(); + + // check populated entries + List entries = parser.getSettingEntries(cfgDescription, file, languageId); + CLibraryFileEntry expected = new CLibraryFileEntry("libdomain.a", 0); + CLibraryFileEntry entry = (CLibraryFileEntry) entries.get(0); + assertEquals(expected.getName(), entry.getName()); + assertEquals(expected.getValue(), entry.getValue()); + assertEquals(expected.getKind(), entry.getKind()); + assertEquals(expected.getFlags(), entry.getFlags()); + assertEquals(expected, entry); + } + + /** + */ + public void testMixedSettingEntries() throws Exception { + // Create model project and accompanied descriptions + String projectName = getName(); + IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + IFile file=ResourceHelper.createFile(project, "file.cpp"); + ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); + String languageId = ls.getLanguageId(); + + // create GCCBuildCommandParser + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + + // parse line + parser.startup(cfgDescription); + parser.processLine("gcc" + + " -I/path0 " + + " -DMACRO1=value" + + " -v" + + " -ldomain" + + " -E" + + " -I /path1 " + + " -DMACRO2=\"value with spaces\"" + + " -I\"/path with spaces\"" + + " -o file.exe" + + " -L/usr/lib" + + " file.cpp" + + " -mtune=pentiumpro" + ); + parser.shutdown(); + + // check populated entries + List entries = parser.getSettingEntries(cfgDescription, file, languageId); +// + " -I/path0 " + { + IPath path = new Path("/path0").setDevice(project.getLocation().getDevice()); + CIncludePathEntry expected = new CIncludePathEntry(path, 0); + assertEquals(expected, entries.get(0)); + } +// + " -DMACRO1=value" + { + CMacroEntry expected = new CMacroEntry("MACRO1", "value", 0); + assertEquals(expected, entries.get(1)); + } +// + " -ldomain" + { + CLibraryFileEntry expected = new CLibraryFileEntry("libdomain.a", 0); + assertEquals(expected, entries.get(2)); + } +// + " -I /path1 " + { + IPath path = new Path("/path1").setDevice(project.getLocation().getDevice()); + CIncludePathEntry expected = new CIncludePathEntry(path, 0); + assertEquals(expected, entries.get(3)); + } +// + " -DMACRO2=\"value with spaces\"" + { + CMacroEntry expected = new CMacroEntry("MACRO2", "value with spaces", 0); + assertEquals(expected, entries.get(4)); + } +// + " -I\"/path with spaces\"" + { + IPath path = new Path("/path with spaces").setDevice(project.getLocation().getDevice()); + CIncludePathEntry expected = new CIncludePathEntry(path, 0); + assertEquals(expected, entries.get(5)); + } +// + " -L/usr/lib" + { + IPath path = new Path("/usr/lib").setDevice(project.getLocation().getDevice()); + CLibraryPathEntry expected = new CLibraryPathEntry(path, 0); + assertEquals(expected, entries.get(6)); + } + + assertEquals(7, entries.size()); + } + + /** + */ + public void testFileMissing() throws Exception { + // Create model project and accompanied descriptions + String projectName = getName(); + IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + // create GCCBuildCommandParser + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + + // parse line + parser.startup(cfgDescription); + parser.processLine("gcc -I/path0 missing.cpp"); + parser.shutdown(); + + // check entries + assertTrue(parser.isEmpty()); + } + + /** + */ + public void testFileAbsolutePath() throws Exception { + // Create model project and accompanied descriptions + String projectName = getName(); + IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); + IFile file=ResourceHelper.createFile(project, "file.cpp"); + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); + String languageId = ls.getLanguageId(); + + // create GCCBuildCommandParser + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + + // parse line + parser.startup(cfgDescription); + parser.processLine("gcc " + + "-I/path0 " + + "-I. " + + file.getLocation().toOSString()); + parser.shutdown(); + + // check entries + IPath path0 = new Path("/path0").setDevice(project.getLocation().getDevice()); + { + List entries = parser.getSettingEntries(cfgDescription, file, languageId); + assertEquals(new CIncludePathEntry(path0, 0), entries.get(0)); + assertEquals(new CIncludePathEntry(project.getFullPath(), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(1)); + } + } + + /** + */ + public void testFileAbsolutePath_NoProject() throws Exception { + // Create model project and accompanied descriptions + String projectName = getName(); + IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); + IFile file=ResourceHelper.createFile(project, "file.cpp"); + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); + String languageId = ls.getLanguageId(); + + // create GCCBuildCommandParser + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + + // parse line + parser.startup(null); + parser.processLine("gcc " + + "-I/path0 " + + "-I. " + + file.getLocation().toOSString()); + parser.shutdown(); + + // check entries + IPath path0 = new Path("/path0").setDevice(project.getLocation().getDevice()); + { + List entries = parser.getSettingEntries(null, file, languageId); + assertEquals(new CIncludePathEntry(path0, 0), entries.get(0)); + assertEquals(new CIncludePathEntry(file.getParent().getFullPath(), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(1)); + } + } + + /** + */ + public void testFileWithSpaces() throws Exception { + // Create model project and accompanied descriptions + String projectName = getName(); + IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + IFile file1=ResourceHelper.createFile(project, "file with spaces 1.cpp"); + IFile file2=ResourceHelper.createFile(project, "file with spaces 2.cpp"); + IFile file3=ResourceHelper.createFile(project, "file with spaces 3.cpp"); + IFile file4=ResourceHelper.createFile(project, "file with spaces 4.cpp"); + ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file1.getProjectRelativePath(), true); + String languageId = ls.getLanguageId(); + + // create GCCBuildCommandParser + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + + // parse line + parser.startup(cfgDescription); + parser.processLine("gcc -I/path0 'file with spaces 1.cpp'"); + parser.processLine("gcc -I/path0 \"file with spaces 2.cpp\""); + parser.processLine("gcc -I/path0 'file with spaces 3.cpp'\n"); + parser.processLine("gcc -I/path0 'file with spaces 4.cpp'\r\n"); + parser.shutdown(); + + // check populated entries + IPath path0 = new Path("/path0").setDevice(project.getLocation().getDevice()); + { + // in single quotes + List entries = parser.getSettingEntries(cfgDescription, file1, languageId); + CIncludePathEntry expected = new CIncludePathEntry(path0, 0); + assertEquals(expected, entries.get(0)); + } + { + // in double quotes + List entries = parser.getSettingEntries(cfgDescription, file2, languageId); + CIncludePathEntry expected = new CIncludePathEntry(path0, 0); + assertEquals(expected, entries.get(0)); + } + { + // Unix EOL + List entries = parser.getSettingEntries(cfgDescription, file3, languageId); + CIncludePathEntry expected = new CIncludePathEntry(path0, 0); + assertEquals(expected, entries.get(0)); + } + { + // Windows EOL + List entries = parser.getSettingEntries(cfgDescription, file4, languageId); + CIncludePathEntry expected = new CIncludePathEntry(path0, 0); + assertEquals(expected, entries.get(0)); + } + } + + /** + */ + public void testEndOfLine() throws Exception { + // Create model project and accompanied descriptions + String projectName = getName(); + IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + IFile file0=ResourceHelper.createFile(project, "file0.cpp"); + IFile file1=ResourceHelper.createFile(project, "file1.cpp"); + IFile file2=ResourceHelper.createFile(project, "file2.cpp"); + ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file0.getProjectRelativePath(), true); + String languageId = ls.getLanguageId(); + + // create GCCBuildCommandParser + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + + // parse line + parser.startup(cfgDescription); + parser.processLine("gcc -I/path0 file0.cpp"); + parser.processLine("gcc -I/path0 file1.cpp\n"); + parser.processLine("gcc -I/path0 file2.cpp\r\n"); + parser.shutdown(); + + // check populated entries + IPath path0 = new Path("/path0").setDevice(project.getLocation().getDevice()); + { + List entries = parser.getSettingEntries(cfgDescription, file0, languageId); + CIncludePathEntry expected = new CIncludePathEntry(path0, 0); + CIncludePathEntry entry = (CIncludePathEntry)entries.get(0); + assertEquals(expected, entry); + } + { + List entries = parser.getSettingEntries(cfgDescription, file1, languageId); + CIncludePathEntry expected = new CIncludePathEntry(path0, 0); + CIncludePathEntry entry = (CIncludePathEntry)entries.get(0); + assertEquals(expected, entry); + } + { + List entries = parser.getSettingEntries(cfgDescription, file2, languageId); + CIncludePathEntry expected = new CIncludePathEntry(path0, 0); + CIncludePathEntry entry = (CIncludePathEntry)entries.get(0); + assertEquals(expected, entry); + } + } + + /** + */ + public void testPathEntry_DriveLetter() throws Exception { + // do not test on non-windows systems where drive letters are not supported + if (! Platform.getOS().equals(Platform.OS_WIN32)) + return; + + // Create model project and accompanied descriptions + String projectName = getName(); + IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + IFile file=ResourceHelper.createFile(project, "file.cpp"); + ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); + String languageId = ls.getLanguageId(); + + // create GCCBuildCommandParser + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + parser.setResolvingPaths(true); + + // parse line + parser.startup(cfgDescription); + parser.processLine("gcc " + + " -IC:\\path" + + " file.cpp"); + parser.shutdown(); + + // check populated entries + IPath path0 = new Path("C:\\path").setDevice(project.getLocation().getDevice()); + { + List entries = parser.getSettingEntries(cfgDescription, file, languageId); + CIncludePathEntry expected = new CIncludePathEntry(path0, 0); + assertEquals(expected, entries.get(0)); + } + } + + /** + */ + public void testPathEntry_ExpandRelativePath() throws Exception { + // Create model project and accompanied descriptions + String projectName = getName(); + IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + IFile file=ResourceHelper.createFile(project, "file.cpp"); + IFolder folder=ResourceHelper.createFolder(project, "Folder"); + IFolder folderComposite=ResourceHelper.createFolder(project, "Folder-Icomposite"); + ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); + String languageId = ls.getLanguageId(); + + // create GCCBuildCommandParser + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + parser.setResolvingPaths(true); + + // parse line + parser.startup(cfgDescription); + parser.processLine("gcc " + + " -I." + + " -I.." + + " -IFolder" + + " -IFolder-Icomposite" // to test case when "-I" is a part of folder name + + " file.cpp"); + parser.shutdown(); + + // check populated entries + List entries = parser.getSettingEntries(cfgDescription, file, languageId); + { + // check that relative paths are relative to CWD which is the location of the project + assertEquals(new CIncludePathEntry(project.getFullPath(), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(0)); + assertEquals(new CIncludePathEntry(project.getLocation().removeLastSegments(1), 0), entries.get(1)); + assertEquals(new CIncludePathEntry(folder.getFullPath(), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(2)); + assertEquals(new CIncludePathEntry(folderComposite.getFullPath(), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(3)); + } + } + + /** + */ + public void testPathEntry_DoNotExpandRelativePath() throws Exception { + // Create model project and accompanied descriptions + String projectName = getName(); + IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + IFile file=ResourceHelper.createFile(project, "file.cpp"); + @SuppressWarnings("unused") + IFolder folder=ResourceHelper.createFolder(project, "Folder"); + ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); + String languageId = ls.getLanguageId(); + + // create GCCBuildCommandParser with expandRelativePaths=false + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + parser.setResolvingPaths(false); + + // parse line + parser.startup(cfgDescription); + parser.processLine("gcc " + + " -I." + + " -I.." + + " -IFolder" + + " file.cpp"); + parser.shutdown(); + + // check populated entries + List entries = parser.getSettingEntries(cfgDescription, file, languageId); + { + assertEquals(new CIncludePathEntry(".", 0), entries.get(0)); + assertEquals(new CIncludePathEntry("..", 0), entries.get(1)); + assertEquals(new CIncludePathEntry("Folder", 0), entries.get(2)); + } + } + + /** + */ + public void testPathEntry_DuplicatePath() throws Exception { + // Create model project and accompanied descriptions + String projectName = getName(); + IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + IFile file=ResourceHelper.createFile(project, "file.cpp"); + IFolder folder=ResourceHelper.createFolder(project, "Folder"); + ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); + String languageId = ls.getLanguageId(); + + // create GCCBuildCommandParser + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + parser.setResolvingPaths(true); + + // parse line + parser.startup(cfgDescription); + parser.processLine("gcc " + + " -IFolder" + + " -IFolder" + + " file.cpp"); + parser.shutdown(); + + // check populated entries + List entries = parser.getSettingEntries(cfgDescription, file, languageId); + { + assertEquals(new CIncludePathEntry(folder.getFullPath(), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(0)); + assertEquals(1, entries.size()); + } + } + + /** + */ + public void testPathEntry_FollowCWD() throws Exception { + // Create model project and accompanied descriptions + String projectName = getName(); + IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + IFolder buildDir=ResourceHelper.createFolder(project, "BuildDir"); + IFolder folder=ResourceHelper.createFolder(project, "BuildDir/Folder"); + IFile file=ResourceHelper.createFile(project, "BuildDir/file.cpp"); + @SuppressWarnings("unused") + IFile fakeFile=ResourceHelper.createFile(project, "file.cpp"); + ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); + String languageId = ls.getLanguageId(); + + // create GCCBuildCommandParser + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + ErrorParserManager epm = new ErrorParserManager(project, null); + epm.pushDirectoryURI(buildDir.getLocationURI()); + + // parse line + parser.startup(cfgDescription); + parser.processLine("gcc " + + " -I." + + " -I.." + + " -I../../.." + + " -IFolder" + + " -IMissingFolder" + + " file.cpp", + epm); + parser.shutdown(); + + // check populated entries + List entries = parser.getSettingEntries(cfgDescription, file, languageId); + { + assertEquals(new CIncludePathEntry(buildDir.getFullPath(), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(0)); + assertEquals(new CIncludePathEntry(buildDir.getFullPath().removeLastSegments(1), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(1)); + assertEquals(new CIncludePathEntry(buildDir.getLocation().removeLastSegments(3), 0), entries.get(2)); + assertEquals(new CIncludePathEntry(folder.getFullPath(), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(3)); + assertEquals(new CIncludePathEntry(buildDir.getFullPath().append("MissingFolder"), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(4)); + } + } + + /** + */ + public void testPathEntry_GuessCWD() throws Exception { + // Create model project and accompanied descriptions + String projectName = getName(); + IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + IFolder folder=ResourceHelper.createFolder(project, "BuildDir/Folder"); + IFile file=ResourceHelper.createFile(project, "BuildDir/file.cpp"); + ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); + String languageId = ls.getLanguageId(); + + // create GCCBuildCommandParser + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + + ErrorParserManager epm = new ErrorParserManager(project, null); + + // parse line + parser.startup(cfgDescription); + parser.processLine("gcc " + + " -IFolder" + + " file.cpp", + epm); + parser.shutdown(); + + // check populated entries + List entries = parser.getSettingEntries(cfgDescription, file, languageId); + assertEquals(new CIncludePathEntry(folder.getFullPath(), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(0)); + } + + /** + */ + public void testPathEntry_NonExistentCWD_Workspace() throws Exception { + // Create model project and accompanied descriptions + String projectName = getName(); + IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + IFolder buildDir=project.getFolder("Missing/Folder"); + IFile file=ResourceHelper.createFile(project, "file.cpp"); + ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); + String languageId = ls.getLanguageId(); + + // create GCCBuildCommandParser + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + + ErrorParserManager epm = new ErrorParserManager(project, null); + epm.pushDirectoryURI(buildDir.getLocationURI()); + + // parse line + parser.startup(cfgDescription); + parser.processLine("gcc " + + " -I." + + " -I.." + + " -IFolder" + + " ../file.cpp", + epm); + parser.shutdown(); + + // check populated entries + List entries = parser.getSettingEntries(cfgDescription, file, languageId); + { + assertEquals(new CIncludePathEntry(buildDir.getFullPath(), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(0)); + assertEquals(new CIncludePathEntry(buildDir.getFullPath().removeLastSegments(1), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(1)); + assertEquals(new CIncludePathEntry(buildDir.getFullPath().append("Folder"), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(2)); + } + } + + /** + */ + public void testPathEntry_NonExistentCWD_Filesystem() throws Exception { + // Create model project and accompanied descriptions + String projectName = getName(); + IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + IFile file=ResourceHelper.createFile(project, "file.cpp"); + ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); + String languageId = ls.getLanguageId(); + + // create GCCBuildCommandParser + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + + ErrorParserManager epm = new ErrorParserManager(project, null); + URI uriBuildDir = new URI("file:/non-existing/path"); + epm.pushDirectoryURI(uriBuildDir); + + // parse line + parser.startup(cfgDescription); + parser.processLine("gcc " + + " -I." + + " -I.." + + " -IFolder" + + " ../file.cpp", + epm); + parser.shutdown(); + + // check populated entries + List entries = parser.getSettingEntries(cfgDescription, file, languageId); + { + IPath buildPath = new Path(uriBuildDir.getPath()).setDevice(project.getLocation().getDevice()); + assertEquals(new CIncludePathEntry(buildPath, 0), entries.get(0)); + assertEquals(new CIncludePathEntry(buildPath.removeLastSegments(1), 0), entries.get(1)); + assertEquals(new CIncludePathEntry(buildPath.append("Folder"), 0), entries.get(2)); + } + } + + /** + */ + public void testPathEntry_MappedRemoteFolder() throws Exception { + // Create model project and accompanied descriptions + String projectName = getName(); + IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + IFolder buildDir=ResourceHelper.createFolder(project, "Local/BuildDir"); + IFolder folder=ResourceHelper.createFolder(project, "Local/BuildDir/Folder"); + IFolder folder2=ResourceHelper.createFolder(project, "Local/BuildDir/Folder2"); + IFile file=ResourceHelper.createFile(project, "Local/BuildDir/file.cpp"); + ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); + String languageId = ls.getLanguageId(); + + // create GCCBuildCommandParser + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + + ErrorParserManager epm = new ErrorParserManager(project, null); + URI uriBuildDir = new URI("file:/BuildDir"); + epm.pushDirectoryURI(uriBuildDir); + + // parse line + parser.startup(cfgDescription); + parser.processLine("gcc " + + " -I." + + " -I/BuildDir/Folder" + + " -I../BuildDir/Folder2" + + " -I/BuildDir/MissingFolder" + + " -I../BuildDir/MissingFolder2" + + " /BuildDir/file.cpp", + epm); + parser.shutdown(); + + // check populated entries + List entries = parser.getSettingEntries(cfgDescription, file, languageId); + { + assertEquals(new CIncludePathEntry(buildDir.getFullPath(), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(0)); + assertEquals(new CIncludePathEntry(folder.getFullPath(), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(1)); + assertEquals(new CIncludePathEntry(folder2.getFullPath(), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(2)); + assertEquals(new CIncludePathEntry(buildDir.getFullPath().append("MissingFolder"), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(3)); + assertEquals(new CIncludePathEntry(buildDir.getFullPath().append("MissingFolder2"), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(4)); + } + } + + /** + */ + public void testPathEntry_MappedFolderInProject() throws Exception { + // Create model project and accompanied descriptions + String projectName = getName(); + IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + IFile file=ResourceHelper.createFile(project, "BuildDir/file.cpp"); + IFolder mappedFolder=ResourceHelper.createFolder(project, "Mapped/Folder"); + IFolder folder=ResourceHelper.createFolder(project, "Mapped/Folder/Subfolder"); + @SuppressWarnings("unused") + IFolder ambiguousFolder1=ResourceHelper.createFolder(project, "One/Ambiguous/Folder"); + @SuppressWarnings("unused") + IFolder ambiguousFolder2=ResourceHelper.createFolder(project, "Another/Ambiguous/Folder"); + + ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); + String languageId = ls.getLanguageId(); + + // create GCCBuildCommandParser + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + ErrorParserManager epm = new ErrorParserManager(project, null); + + // parse line + parser.startup(cfgDescription); + parser.processLine("gcc " + + " -I/Folder/Subfolder" + + " -I/Mapped/Folder" + + " -I/Ambiguous/Folder" + + " -I/Missing/Folder" + + " file.cpp", + epm); + parser.shutdown(); + + // check populated entries + List entries = parser.getSettingEntries(cfgDescription, file, languageId); + { + assertEquals(new CIncludePathEntry(folder.getFullPath(), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(0)); + assertEquals(new CIncludePathEntry(mappedFolder.getFullPath(), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(1)); + } + { + IPath path = new Path("/Ambiguous/Folder").setDevice(file.getLocation().getDevice()); + assertEquals(new CIncludePathEntry(path, 0), entries.get(2)); + } + { + IPath path = new Path("/Missing/Folder").setDevice(file.getLocation().getDevice()); + assertEquals(new CIncludePathEntry(path, 0), entries.get(3)); + } + } + + /** + */ + public void testPathEntry_MappedFolderInAnotherProject() throws Exception { + // Create model project and accompanied descriptions + String projectName = getName(); + IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + // create files and folders + IFile file=ResourceHelper.createFile(project, "file.cpp"); + // another project + IProject anotherProject = ResourceHelper.createCDTProjectWithConfig(projectName+"-another"); + IFolder folder=ResourceHelper.createFolder(anotherProject, "Mapped/Folder/Subfolder"); + @SuppressWarnings("unused") + IFolder ambiguousFolder1=ResourceHelper.createFolder(anotherProject, "One/Ambiguous/Folder"); + @SuppressWarnings("unused") + IFolder ambiguousFolder2=ResourceHelper.createFolder(anotherProject, "Another/Ambiguous/Folder"); + + + ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); + String languageId = ls.getLanguageId(); + + // create GCCBuildCommandParser + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + ErrorParserManager epm = new ErrorParserManager(project, null); + + // parse line + parser.startup(cfgDescription); + parser.processLine("gcc " + + " -I/Folder/Subfolder" + + " -I/Ambiguous/Folder" + + " -I/Missing/Folder" + + " file.cpp", + epm); + parser.shutdown(); + + // check populated entries + List entries = parser.getSettingEntries(cfgDescription, file, languageId); + { + assertEquals(new CIncludePathEntry(folder.getFullPath(), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(0)); + } + { + IPath path = new Path("/Ambiguous/Folder").setDevice(file.getLocation().getDevice()); + assertEquals(new CIncludePathEntry(path, 0), entries.get(1)); + } + { + IPath path = new Path("/Missing/Folder").setDevice(file.getLocation().getDevice()); + assertEquals(new CIncludePathEntry(path, 0), entries.get(2)); + } + } + + /** + */ + public void testPathEntry_MappedFolderInReferencedProject() throws Exception { + // Create model project and accompanied descriptions + String projectName = getName(); + + // create main project + IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); + IFile file=ResourceHelper.createFile(project, "file.cpp"); + + // create another project (non-referenced) + IProject anotherProject = ResourceHelper.createCDTProjectWithConfig(projectName+"-another"); + @SuppressWarnings("unused") + IFolder folderInAnotherProject=ResourceHelper.createFolder(anotherProject, "Mapped/Folder/Subfolder"); + + // create referenced project + IProject referencedProject = ResourceHelper.createCDTProjectWithConfig(projectName+"-referenced"); + IFolder folderInReferencedProject=ResourceHelper.createFolder(referencedProject, "Mapped/Folder/Subfolder"); + @SuppressWarnings("unused") + IFolder ambiguousFolder1=ResourceHelper.createFolder(referencedProject, "One/Ambiguous/Folder"); + @SuppressWarnings("unused") + IFolder ambiguousFolder2=ResourceHelper.createFolder(referencedProject, "Another/Ambiguous/Folder"); + + setReference(project, referencedProject); + + // get cfgDescription and language to work with + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); + String languageId = ls.getLanguageId(); + + // create GCCBuildCommandParser + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + ErrorParserManager epm = new ErrorParserManager(project, null); + + // parse line + parser.startup(cfgDescription); + parser.processLine("gcc " + + " -I/Folder/Subfolder" + + " -I/Ambiguous/Folder" + + " file.cpp", + epm); + parser.shutdown(); + + // check populated entries + List entries = parser.getSettingEntries(cfgDescription, file, languageId); + { + assertEquals(new CIncludePathEntry(folderInReferencedProject.getFullPath(), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(0)); + + IPath path = new Path("/Ambiguous/Folder").setDevice(file.getLocation().getDevice()); + assertEquals(new CIncludePathEntry(path, 0), entries.get(1)); + } + } + + /** + */ + public void testPathEntry_NavigateSymbolicLinkUpAbsolute() throws Exception { + // do not test on systems where symbolic links are not supported + if (!ResourceHelper.isSymbolicLinkSupported()) + return; + + // Create model project and accompanied descriptions + String projectName = getName(); + IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + String languageId = LANG_CPP; + IFile file=ResourceHelper.createFile(project, "file.cpp"); + + // create link on the filesystem + IPath dir1 = ResourceHelper.createTemporaryFolder(); + IPath dir2 = dir1.removeLastSegments(1); + IPath linkPath = dir1.append("linked"); + ResourceHelper.createSymbolicLink(linkPath, dir2); + + // create GCCBuildCommandParser + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + ErrorParserManager epm = new ErrorParserManager(project, null); + + // parse line + parser.startup(cfgDescription); + // "../" should navigate along filesystem path, not along the link itself + parser.processLine("gcc -I"+linkPath.toString()+"/.."+" file.cpp", epm); + parser.shutdown(); + + // check populated entries + { + List entries = parser.getSettingEntries(cfgDescription, file, languageId); + CIncludePathEntry expected = new CIncludePathEntry(dir2.removeLastSegments(1), 0); + assertEquals(expected, entries.get(0)); + } + } + + /** + */ + public void testPathEntry_NavigateSymbolicLinkUpRelative() throws Exception { + // do not test on systems where symbolic links are not supported + if (!ResourceHelper.isSymbolicLinkSupported()) + return; + + // Create model project and accompanied descriptions + String projectName = getName(); + IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + String languageId = LANG_CPP; + IFile file=ResourceHelper.createFile(project, "file.cpp"); + + // create link + IFolder folder = ResourceHelper.createFolder(project, "folder"); + IFolder subfolder = ResourceHelper.createFolder(project, "folder/subfolder"); + IPath linkPath = project.getLocation().append("linked"); + ResourceHelper.createSymbolicLink(linkPath, subfolder.getLocation()); + + // create GCCBuildCommandParser + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + ErrorParserManager epm = new ErrorParserManager(project, null); + + // parse line + parser.startup(cfgDescription); + // "../" should navigate along filesystem path, not along the link itself + parser.processLine("gcc -Ilinked/.."+" file.cpp", epm); + parser.shutdown(); + + // check populated entries + { + List entries = parser.getSettingEntries(cfgDescription, file, languageId); + CIncludePathEntry expected = new CIncludePathEntry(folder.getFullPath(), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED); + assertEquals(expected, entries.get(0)); + } + } + + /** + */ + public void testPathEntry_BuildDirDefinedByConfiguration_RelativePath() throws Exception { + // Create model project and accompanied descriptions + String projectName = getName(); + IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); + // Create resources trying to confuse the parser + @SuppressWarnings("unused") + IFile fileInProjectRoot=ResourceHelper.createFile(project, "file.cpp"); + @SuppressWarnings("unused") + IFolder includeDirInProjectRoot=ResourceHelper.createFolder(project, "include"); + // Create resources meant to be found + IFolder buildDir=ResourceHelper.createFolder(project, "BuildDir"); + IFile file=ResourceHelper.createFile(project, "BuildDir/file.cpp"); + IFolder includeDir=ResourceHelper.createFolder(project, "BuildDir/include"); + // Change build dir + setBuilderCWD(project, buildDir.getLocation()); + + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); + String languageId = ls.getLanguageId(); + + // create GCCBuildCommandParser + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + + // parse line + parser.startup(cfgDescription); + parser.processLine("gcc " + + " -I." + + " -Iinclude" + + " file.cpp"); + parser.shutdown(); + + // check populated entries + List entries = parser.getSettingEntries(cfgDescription, file, languageId); + { + assertEquals(new CIncludePathEntry(buildDir.getFullPath(), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(0)); + assertEquals(new CIncludePathEntry(includeDir.getFullPath(), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(1)); + } + } + + /** + */ + public void testPathEntry_BuildDirDefinedByConfiguration_AbsolutePath() throws Exception { + // Create model project and accompanied descriptions + String projectName = getName(); + IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); + // Create resources trying to confuse the parser + @SuppressWarnings("unused") + IFile fileInProjectRoot=ResourceHelper.createFile(project, "file.cpp"); + @SuppressWarnings("unused") + IFolder includeDirInProjectRoot=ResourceHelper.createFolder(project, "include"); + // Create resources meant to be found + IFolder buildDir=ResourceHelper.createFolder(project, "BuildDir"); + IFile file=ResourceHelper.createFile(project, "BuildDir/file.cpp"); + IFolder includeDir=ResourceHelper.createFolder(project, "BuildDir/include"); + // Change build dir + setBuilderCWD(project, buildDir.getLocation()); + + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); + String languageId = ls.getLanguageId(); + + // create GCCBuildCommandParser + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + + // parse line + parser.startup(cfgDescription); + parser.processLine("gcc " + + " -I." + + " -Iinclude" + + " " + file.getLocation().toOSString() + ); + parser.shutdown(); + + // check populated entries + List entries = parser.getSettingEntries(cfgDescription, file, languageId); + { + assertEquals(new CIncludePathEntry(buildDir.getFullPath(), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(0)); + assertEquals(new CIncludePathEntry(includeDir.getFullPath(), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(1)); + } + + } + + public void testContentType_None() throws Exception { + MockBuildCommandParser parser = new MockBuildCommandParser() { + @Override + protected String parseForResourceName(String line) { + return "file.wrong-content-type"; + } + }; + parser.startup(null); + parser.processLine("gcc file.wrong-content-type"); + parser.shutdown(); + + List entries = parser.getSettingEntries(null, null, null); + assertNull(entries); + } + + /** + */ + public void testContentType_Mismatch() throws Exception { + // Create model project and accompanied descriptions + String projectName = getName(); + IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + ResourceHelper.createFile(project, "file.c"); + + // create GCCBuildCommandParser + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + // restrict the parser's language scope to C++ only + parser.setLanguageScope(new ArrayList() {{add(LANG_CPP);}}); + + // parse line + parser.startup(cfgDescription); + parser.processLine("gcc -I/path0 file.c"); + parser.shutdown(); + + assertTrue(parser.isEmpty()); + } + + /** + */ + public void testContentType_FileExtensions() throws Exception { + // Create model project and accompanied descriptions + String projectName = getName(); + IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + String languageId = LANG_CPP; + // add custom extension to C++ content type + IContentTypeManager manager = Platform.getContentTypeManager(); + IContentType contentType = manager.findContentTypeFor("file.cpp"); + contentType.addFileSpec("x++", IContentTypeSettings.FILE_EXTENSION_SPEC); + + IFile file=ResourceHelper.createFile(project, "file.x++"); + IContentType contentTypeX = manager.findContentTypeFor("file.x++"); + assertEquals(contentType, contentTypeX); + + // create GCCBuildCommandParser + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + + // parse line + parser.startup(cfgDescription); + parser.processLine("gcc -I/path0 file.x++"); + parser.shutdown(); + + // check populated entries + IPath path0 = new Path("/path0").setDevice(project.getLocation().getDevice()); + { + List entries = parser.getSettingEntries(cfgDescription, file, languageId); + CIncludePathEntry expected = new CIncludePathEntry(path0, 0); + assertEquals(expected, entries.get(0)); + } + } + + /** + */ + public void testUpperCase() throws Exception { + // Create model project and accompanied descriptions + String projectName = getName(); + IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + String languageId = LANG_CPP; + + IFile file=ResourceHelper.createFile(project, "file.cpp"); + + // create GCCBuildCommandParser + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + ErrorParserManager epm = new ErrorParserManager(project, null); + + // parse line + parser.startup(cfgDescription); + parser.processLine("gcc -I/path0 FILE.CPP", epm); + parser.shutdown(); + + // check populated entries + IPath path0 = new Path("/path0").setDevice(project.getLocation().getDevice()); + { + List entries = parser.getSettingEntries(cfgDescription, file, languageId); + CIncludePathEntry expected = new CIncludePathEntry(path0, 0); + assertEquals(expected, entries.get(0)); + } + } + + /** + */ + public void testBoostBjam() throws Exception { + // Create model project and accompanied descriptions + String projectName = getName(); + IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + IFile file=ResourceHelper.createFile(project, "libs/python/src/numeric.cpp"); + ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); + String languageId = ls.getLanguageId(); + + // create GCCBuildCommandParser + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + + // parse line + parser.startup(cfgDescription); + // "g++" -ftemplate-depth-128 -O0 -fno-inline -Wall -g -mthreads -DBOOST_ALL_NO_LIB=1 -DBOOST_PYTHON_SOURCE -DBOOST_PYTHON_STATIC_LIB -I"." -I"/Python25/Include" -c -o "bin.v2/libs/python/build/gcc-mingw-3.4.5/debug/link-static/threading-multi/numeric.o" "libs/python/src/numeric.cpp" + parser.processLine(" \"g++\"" + + " -ftemplate-depth-128 -O0 -fno-inline -Wall -g -mthreads" + + " -DBOOST_ALL_NO_LIB=1" + + " -DBOOST_PYTHON_SOURCE" + + " -DBOOST_PYTHON_STATIC_LIB" + + " -I\".\"" + + " -I\"/Python1025/Include\"" + + " -c -o \"bin.v2/libs/python/build/gcc-mingw-3.4.5/debug/link-static/threading-multi/numeric.o\"" + + " libs/python/src/numeric.cpp"); + parser.shutdown(); + + // check populated entries + { + List entries = parser.getSettingEntries(cfgDescription, file, languageId); + assertEquals(new CMacroEntry("BOOST_ALL_NO_LIB", "1", 0), entries.get(0)); + assertEquals(new CMacroEntry("BOOST_PYTHON_SOURCE", "", 0), entries.get(1)); + assertEquals(new CMacroEntry("BOOST_PYTHON_STATIC_LIB", "", 0), entries.get(2)); + assertEquals(new CIncludePathEntry(project.getFullPath(), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(3)); + assertEquals(new CIncludePathEntry(new Path("/Python1025/Include").setDevice(project.getLocation().getDevice()), 0), entries.get(4)); + assertEquals(5, entries.size()); + } + } + + /** + */ + public void testPathEntry_Efs() throws Exception { + // Create model project and accompanied descriptions + String projectName = getName(); + IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + // create folder structure + @SuppressWarnings("unused") + IFolder buildDir=ResourceHelper.createEfsFolder(project, "BuildDir", new URI("mem:/EfsProject/BuildDir")); + IFolder folder=ResourceHelper.createEfsFolder(project, "BuildDir/Folder", new URI("mem:/EfsProject/BuildDir/Folder")); + IFile file=ResourceHelper.createEfsFile(project, "BuildDir/file.cpp", new URI("mem:/EfsProject/BuildDir/file.cpp")); + ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); + String languageId = ls.getLanguageId(); + + // create GCCBuildCommandParser + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + ErrorParserManager epm = new ErrorParserManager(project, null); + + // parse line + parser.startup(cfgDescription); + parser.processLine("gcc " + + " -IFolder" + + " -I/Absolute/Folder" + + " file.cpp", + epm); + parser.shutdown(); + + // check populated entries + List entries = parser.getSettingEntries(cfgDescription, file, languageId); + { + String device = project.getLocation().getDevice(); + assertEquals(new CIncludePathEntry(folder.getFullPath(), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(0)); + assertEquals(new CIncludePathEntry(new Path("/Absolute/Folder").setDevice(device), 0), entries.get(1)); + } + } + + /** + */ + public void testPathEntry_EfsMappedFolder() throws Exception { + // Create model project and accompanied descriptions + String projectName = getName(); + IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + // create folder structure + @SuppressWarnings("unused") + IFolder buildDir=ResourceHelper.createEfsFolder(project, "BuildDir", new URI("mem:/MappedEfsProject/BuildDir")); + @SuppressWarnings("unused") + IFolder folder=ResourceHelper.createEfsFolder(project, "BuildDir/Folder", new URI("mem:/MappedEfsProject/BuildDir/Folder")); + IFile file=ResourceHelper.createEfsFile(project, "BuildDir/file.cpp", new URI("mem:/MappedEfsProject/BuildDir/file.cpp")); + ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); + String languageId = ls.getLanguageId(); + + // create GCCBuildCommandParser + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + ErrorParserManager epm = new ErrorParserManager(project, null); + + // parse line + parser.startup(cfgDescription); + parser.processLine("gcc " + + " -I/BeingMappedFrom/Folder" // mapped to local folder in EFSExtensionProvider extension point + + " file.cpp", + epm); + parser.shutdown(); + + // check populated entries + List entries = parser.getSettingEntries(cfgDescription, file, languageId); + { + String device = project.getLocation().getDevice(); + assertEquals(new CIncludePathEntry(new Path("/LocallyMappedTo/Folder").setDevice(device), 0), entries.get(0)); + } + } + +} diff --git a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/ScannerDiscoveryTests.java b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/ScannerDiscoveryTests.java index 973802190a0..75eed421b16 100644 --- a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/ScannerDiscoveryTests.java +++ b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/ScannerDiscoveryTests.java @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright (c) 2007, 2009 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2009 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: - * Markus Schorn - initial API and implementation + * Andrew Gvozdev - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.make.scannerdiscovery; diff --git a/build/org.eclipse.cdt.make.core/plugin.xml b/build/org.eclipse.cdt.make.core/plugin.xml index 03f6d45a78a..d9ac29dfc6d 100644 --- a/build/org.eclipse.cdt.make.core/plugin.xml +++ b/build/org.eclipse.cdt.make.core/plugin.xml @@ -182,5 +182,14 @@ class="org.eclipse.cdt.make.internal.core.dataprovider.MakeConfigurationDataProvider" /> + + + + diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java new file mode 100644 index 00000000000..e6a9d2de807 --- /dev/null +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java @@ -0,0 +1,130 @@ +/******************************************************************************* + * Copyright (c) 2009, 2011 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.make.core.scannerconfig; + +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.eclipse.cdt.core.ErrorParserManager; +import org.eclipse.cdt.core.IErrorParser2; +import org.eclipse.cdt.core.IMarkerGenerator; +import org.eclipse.cdt.core.errorparsers.RegexErrorParser; +import org.eclipse.cdt.core.errorparsers.RegexErrorPattern; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; + +public abstract class AbstractBuildCommandParser extends AbstractLanguageSettingsOutputScanner implements + ILanguageSettingsBuildOutputScanner { + + private static final Pattern OPTIONS_PATTERN = Pattern.compile("-[^\\s\"']*(\\s*((\".*?\")|('.*?')|([^-\\s][^\\s]+)))?"); //$NON-NLS-1$ + private static final int OPTION_GROUP = 0; + + /** + * Note: design patterns to keep file group the same and matching {@link #FILE_GROUP} + */ + @SuppressWarnings("nls") + private static final String[] PATTERN_TEMPLATES = { + "\\s*\"?${COMPILER_PATTERN}\"?.*\\s" + "()([^'\"\\s]*\\.${EXTENSIONS_PATTERN})(\\s.*)?[\r\n]*", // compiling unquoted file + "\\s*\"?${COMPILER_PATTERN}\"?.*\\s" + "(['\"])(.*\\.${EXTENSIONS_PATTERN})\\${COMPILER_GROUPS+1}(\\s.*)?[\r\n]*" // compiling quoted file + }; + private static final int FILE_GROUP = 2; + + + @SuppressWarnings("nls") + private String getCompilerCommandPattern() { + String parameter = getCustomParameter(); + return "(" + parameter + ")"; + } + + private int adjustFileGroup() { + return countGroups(getCompilerCommandPattern()) + FILE_GROUP; + } + + private String makePattern(String template) { + @SuppressWarnings("nls") + String pattern = template + .replace("${COMPILER_PATTERN}", getCompilerCommandPattern()) + .replace("${EXTENSIONS_PATTERN}", getPatternFileExtensions()) + .replace("${COMPILER_GROUPS+1}", new Integer(countGroups(getCompilerCommandPattern()) + 1).toString()); + return pattern; + } + + @Override + protected String parseForResourceName(String line) { + if (line==null) { + return null; + } + + for (String template : PATTERN_TEMPLATES) { + String pattern = makePattern(template); + Matcher fileMatcher = Pattern.compile(pattern).matcher(line); + if (fileMatcher.matches()) { + int fileGroup = adjustFileGroup(); + String sourceFileName = fileMatcher.group(fileGroup); + return sourceFileName; + } + } + return null; + } + + @Override + protected List parseForOptions(String line) { + if (line==null || currentResource==null) { + return null; + } + + List options = new ArrayList(); + Matcher optionMatcher = OPTIONS_PATTERN.matcher(line); + while (optionMatcher.find()) { + String option = optionMatcher.group(OPTION_GROUP); + if (option!=null) { + options.add(option); + } + } + return options; + } + + // This is redundant but let us keep it here to navigate in java code easier + @Override + public boolean processLine(String line, ErrorParserManager epm) { + return super.processLine(line, epm); + } + + /** + * Trivial Error Parser which allows highlighting of output lines matching the patterns + * of this parser. Intended for better troubleshooting experience. + * Implementers are supposed to add the error parser as an extension. Initialize with + * build command parser extension ID. + */ + protected static abstract class AbstractBuildCommandPatternHighlighter extends RegexErrorParser implements IErrorParser2 { + public AbstractBuildCommandPatternHighlighter(String buildCommandParserPluginExtension) { + init(buildCommandParserPluginExtension); + } + + protected void init(String buildCommandParserId) { + AbstractBuildCommandParser buildCommandParser = (AbstractBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(buildCommandParserId); + for (String template : PATTERN_TEMPLATES) { + String pattern = buildCommandParser.makePattern(template); + String fileExpr = "$"+buildCommandParser.adjustFileGroup(); //$NON-NLS-1$ + String descExpr = "$0"; //$NON-NLS-1$ + addPattern(new RegexErrorPattern(pattern, fileExpr, null, descExpr, null, IMarkerGenerator.SEVERITY_WARNING, true)); + } + } + + public int getProcessLineBehaviour() { + return KEEP_LONGLINES; + } + } + + +} diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java new file mode 100644 index 00000000000..4f30aaba5f5 --- /dev/null +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java @@ -0,0 +1,821 @@ +/******************************************************************************* + * Copyright (c) 2009, 2011 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.make.core.scannerconfig; + +import java.io.File; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.eclipse.cdt.core.ErrorParserManager; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable; +import org.eclipse.cdt.core.model.ILanguage; +import org.eclipse.cdt.core.model.LanguageManager; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; +import org.eclipse.cdt.core.settings.model.ICSettingEntry; +import org.eclipse.cdt.core.settings.model.util.CDataUtil; +import org.eclipse.cdt.internal.core.XmlUtil; +import org.eclipse.cdt.make.core.MakeCorePlugin; +import org.eclipse.cdt.utils.EFSExtensionManager; +import org.eclipse.core.filesystem.EFS; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.content.IContentType; +import org.eclipse.core.runtime.content.IContentTypeManager; +import org.w3c.dom.Element; + +public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSettingsSerializable implements + ILanguageSettingsOutputScanner { + + protected static final String ATTR_EXPAND_RELATIVE_PATHS = "expand-relative-paths"; //$NON-NLS-1$ + + protected ICConfigurationDescription currentCfgDescription = null; + protected IProject currentProject = null; + protected IResource currentResource = null; + protected String currentLanguageId = null; + + protected ErrorParserManager errorParserManager = null; + protected String parsedResourceName = null; + protected boolean isResolvingPaths = true; + + protected static abstract class AbstractOptionParser { + protected final Pattern pattern; + protected final String patternStr; + protected String nameExpression; + protected String valueExpression; + protected int extraFlag = 0; + protected int kind = 0; + private String parsedName; + private String parsedValue; + + public AbstractOptionParser(int kind, String pattern, String nameExpression, String valueExpression, int extraFlag) { + this.kind = kind; + this.patternStr = pattern; + this.nameExpression = nameExpression; + this.valueExpression = valueExpression; + this.extraFlag = extraFlag; + + this.pattern = Pattern.compile(pattern); + } + + public ICLanguageSettingEntry createEntry(String name, String value, int flag) { + return (ICLanguageSettingEntry) CDataUtil.createEntry(kind, name, value, null, flag | extraFlag); + } + + /** + * TODO: explain + */ + protected String extractOption(String input) { + @SuppressWarnings("nls") + String option = input.replaceFirst("(" + patternStr + ").*", "$1"); + return option; + } + + protected String parseStr(Matcher matcher, String str) { + if (str != null) + return matcher.replaceAll(str); + return null; + } + + protected boolean isPathKind() { + return kind == ICSettingEntry.INCLUDE_PATH || kind == ICSettingEntry.INCLUDE_FILE + || kind == ICSettingEntry.MACRO_FILE || kind == ICSettingEntry.LIBRARY_PATH; + } + + public boolean parseOption(String option) { + String opt = extractOption(option); + Matcher matcher = pattern.matcher(opt); + boolean isMatch = matcher.matches(); + if (isMatch) { + parsedName = parseStr(matcher, nameExpression); + parsedValue = parseStr(matcher, valueExpression); + } + return isMatch; + } + + } + + protected static class IncludePathOptionParser extends AbstractOptionParser { + public IncludePathOptionParser(String pattern, String nameExpression) { + super(ICLanguageSettingEntry.INCLUDE_PATH, pattern, nameExpression, nameExpression, 0); + } + public IncludePathOptionParser(String pattern, String nameExpression, int extraFlag) { + super(ICLanguageSettingEntry.INCLUDE_PATH, pattern, nameExpression, nameExpression, extraFlag); + } + } + + protected static class IncludeFileOptionParser extends AbstractOptionParser { + public IncludeFileOptionParser(String pattern, String nameExpression) { + super(ICLanguageSettingEntry.INCLUDE_FILE, pattern, nameExpression, nameExpression, 0); + } + public IncludeFileOptionParser(String pattern, String nameExpression, int extraFlag) { + super(ICLanguageSettingEntry.INCLUDE_FILE, pattern, nameExpression, nameExpression, extraFlag); + } + } + + protected static class MacroOptionParser extends AbstractOptionParser { + public MacroOptionParser(String pattern, String nameExpression, String valueExpression) { + super(ICLanguageSettingEntry.MACRO, pattern, nameExpression, valueExpression, 0); + } + public MacroOptionParser(String pattern, String nameExpression, String valueExpression, int extraFlag) { + super(ICLanguageSettingEntry.MACRO, pattern, nameExpression, valueExpression, extraFlag); + } + public MacroOptionParser(String pattern, String nameExpression, int extraFlag) { + super(ICLanguageSettingEntry.MACRO, pattern, nameExpression, null, extraFlag); + } + } + + protected static class MacroFileOptionParser extends AbstractOptionParser { + public MacroFileOptionParser(String pattern, String nameExpression) { + super(ICLanguageSettingEntry.MACRO_FILE, pattern, nameExpression, nameExpression, 0); + } + public MacroFileOptionParser(String pattern, String nameExpression, int extraFlag) { + super(ICLanguageSettingEntry.MACRO_FILE, pattern, nameExpression, nameExpression, extraFlag); + } + } + + protected static class LibraryPathOptionParser extends AbstractOptionParser { + public LibraryPathOptionParser(String pattern, String nameExpression) { + super(ICLanguageSettingEntry.LIBRARY_PATH, pattern, nameExpression, nameExpression, 0); + } + public LibraryPathOptionParser(String pattern, String nameExpression, int extraFlag) { + super(ICLanguageSettingEntry.LIBRARY_PATH, pattern, nameExpression, nameExpression, extraFlag); + } + } + + protected static class LibraryFileOptionParser extends AbstractOptionParser { + public LibraryFileOptionParser(String pattern, String nameExpression) { + super(ICLanguageSettingEntry.LIBRARY_FILE, pattern, nameExpression, nameExpression, 0); + } + public LibraryFileOptionParser(String pattern, String nameExpression, int extraFlag) { + super(ICLanguageSettingEntry.LIBRARY_FILE, pattern, nameExpression, nameExpression, extraFlag); + } + } + + /** + * Parse the line returning the resource name as appears in the output. + * This is the resource where {@link ICLanguageSettingEntry} list is being added. + * + * @param line - one input line from the output stripped from end of line characters. + * @return the resource name as appears in the output or {@code null}. + * Note that {@code null} can have different semantics and can mean "no resource found" + * or "applicable to any resource". By default "no resource found" is used in this + * abstract class but extenders can handle otherwise. + */ + protected abstract String parseForResourceName(String line); + + /** + * Parse the line returning the list of substrings to be treated each as input to + * the option parsers. It is assumed that each substring presents one + * {@link ICLanguageSettingEntry} (for example compiler options {@code -I/path} or + * {@code -DMACRO=1}. + * + * @param line - one input line from the output stripped from end of line characters. + * @return list of substrings representing language settings entries. + */ + protected abstract List parseForOptions(String line); + + /** + * @return array of option parsers defining how to parse a string to + * {@link ICLanguageSettingEntry}. + * See {@link AbstractOptionParser} and its specific extenders. + */ + protected abstract AbstractOptionParser[] getOptionParsers(); + + public boolean isResolvingPaths() { + return isResolvingPaths; + } + + public void setResolvingPaths(boolean resolvePaths) { + this.isResolvingPaths = resolvePaths; + } + + + public void startup(ICConfigurationDescription cfgDescription) throws CoreException { + currentCfgDescription = cfgDescription; + currentProject = cfgDescription != null ? cfgDescription.getProjectDescription().getProject() : null; + } + + public boolean processLine(String line) { + return processLine(line, null); + } + + public void shutdown() { + } + + public boolean processLine(String line, ErrorParserManager epm) { + errorParserManager = epm; + parsedResourceName = parseForResourceName(line); + + currentLanguageId = determineLanguage(parsedResourceName); + if (!isLanguageInScope(currentLanguageId)) + return false; + + currentResource = findResource(parsedResourceName); + + /** + * Where source tree starts if mapped. This kind of mapping is useful for example in cases when + * the absolute path to the source file on the remote system is simulated inside a project in the + * workspace. + */ + URI mappedRootURI = null; + URI buildDirURI = null; + + if (isResolvingPaths) { + if (currentResource!=null) { + mappedRootURI = getMappedRootURI(currentResource, parsedResourceName); + } + buildDirURI = getBuildDirURI(mappedRootURI); + } + + List entries = new ArrayList(); + + List options = parseForOptions(line); + if (options!=null) { + for (String option : options) { + for (AbstractOptionParser optionParser : getOptionParsers()) { + try { + if (optionParser.parseOption(option)) { + ICLanguageSettingEntry entry = null; + if (isResolvingPaths && optionParser.isPathKind()) { + URI baseURI = new Path(optionParser.parsedName).isAbsolute() ? mappedRootURI : buildDirURI; + entry = createResolvedPathEntry(optionParser, optionParser.parsedName, 0, baseURI); + } else { + entry = optionParser.createEntry(optionParser.parsedName, optionParser.parsedValue, 0); + } + + if (entry != null && !entries.contains(entry)) { + entries.add(entry); + break; + } + } + } catch (Throwable e) { + // protect from rogue parsers extending this class + MakeCorePlugin.log(e); + } + } + } + if (entries.size() > 0) { + setSettingEntries(entries); + } else { + setSettingEntries(null); + } + } + return false; + } + + protected void setSettingEntries(List entries) { + setSettingEntries(currentCfgDescription, currentResource, currentLanguageId, entries); + + // TODO - for debugging only, eventually remove + IStatus status = new Status(IStatus.INFO, MakeCorePlugin.PLUGIN_ID, getClass().getSimpleName() + + " collected " + (entries!=null ? ("" + entries.size()) : "null") + " entries for " + currentResource); + MakeCorePlugin.log(status); + } + + protected String determineLanguage(String parsedResourceName) { + if (parsedResourceName==null) + return null; + + String fileName = new Path(parsedResourceName).lastSegment().toString(); + IContentTypeManager manager = Platform.getContentTypeManager(); + IContentType contentType = manager.findContentTypeFor(fileName); + if (contentType==null) + return null; + + ILanguage lang = LanguageManager.getInstance().getLanguage(contentType); + if (lang==null) + return null; + + return lang.getId(); + } + + protected boolean isLanguageInScope(String languageId) { + List languageIds = getLanguageScope(); + return languageIds == null || languageIds.contains(languageId); + } + + protected String getPatternFileExtensions() { + IContentTypeManager manager = Platform.getContentTypeManager(); + + Set fileExts = new HashSet(); + + IContentType contentTypeCpp = manager.getContentType("org.eclipse.cdt.core.cxxSource"); //$NON-NLS-1$ + fileExts.addAll(Arrays.asList(contentTypeCpp.getFileSpecs(IContentType.FILE_EXTENSION_SPEC))); + + IContentType contentTypeC = manager.getContentType("org.eclipse.cdt.core.cSource"); //$NON-NLS-1$ + fileExts.addAll(Arrays.asList(contentTypeC.getFileSpecs(IContentType.FILE_EXTENSION_SPEC))); + + String pattern = expressionLogicalOr(fileExts); + + return pattern; + } + + private ICLanguageSettingEntry createResolvedPathEntry(AbstractOptionParser optionParser, + String parsedPath, int flag, URI baseURI) { + + ICLanguageSettingEntry entry; + String resolvedPath = null; + + URI uri = determineURI(parsedPath, baseURI); + IResource rc = null; + if (uri != null && uri.isAbsolute()) { + rc = findResourceForLocationURI(uri, optionParser.kind, currentProject); + } + if (rc != null) { + IPath path = rc.getFullPath(); + resolvedPath = path.toString(); + flag = flag | ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED; + } else { + IPath path = getFilesystemLocation(uri); + if (path != null && new File(path.toString()).exists()) { + resolvedPath = path.toString(); + } + if (resolvedPath == null) { + Set referencedProjectsNames = new LinkedHashSet(); + if (currentCfgDescription!=null) { + Map refs = currentCfgDescription.getReferenceInfo(); + referencedProjectsNames.addAll(refs.keySet()); + } + IResource resource = resolveResourceInWorkspace(parsedPath, currentProject, referencedProjectsNames); + if (resource != null) { + path = resource.getFullPath(); + resolvedPath = path.toString(); + flag = flag | ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED; + } + } + if (resolvedPath==null && path!=null) { + resolvedPath = path.toString(); + } + } + + if (resolvedPath==null) { + resolvedPath = parsedPath; + } + + entry = optionParser.createEntry(resolvedPath, resolvedPath, flag); + return entry; + } + + private IResource findResource(String parsedResourceName) { + if (parsedResourceName==null) + return null; + + IResource sourceFile = null; + + // try ErrorParserManager + if (errorParserManager != null) { + sourceFile = errorParserManager.findFileName(parsedResourceName); + } + // try to find absolute path in the workspace + if (sourceFile == null && new Path(parsedResourceName).isAbsolute()) { + URI uri = org.eclipse.core.filesystem.URIUtil.toURI(parsedResourceName); + sourceFile = findFileForLocationURI(uri, currentProject); + } + // try path relative to build dir from configuration + if (sourceFile == null && currentCfgDescription != null) { + IPath builderCWD = currentCfgDescription.getBuildSetting().getBuilderCWD(); + if (builderCWD!=null) { + IPath path = builderCWD.append(parsedResourceName); + URI uri = org.eclipse.core.filesystem.URIUtil.toURI(path); + sourceFile = findFileForLocationURI(uri, currentProject); + } + } + // try path relative to the project + if (sourceFile == null && currentProject != null) { + sourceFile = currentProject.findMember(parsedResourceName); + } + return sourceFile; + } + + private URI getBuildDirURI(URI mappedRootURI) { + URI buildDirURI = null; + + URI cwdURI = null; + if (currentResource!=null && parsedResourceName!=null && !new Path(parsedResourceName).isAbsolute()) { + cwdURI = findBaseLocationURI(currentResource.getLocationURI(), parsedResourceName); + } + if (cwdURI == null && errorParserManager != null) { + cwdURI = errorParserManager.getWorkingDirectoryURI(); + } + + String cwdPath = cwdURI != null ? EFSExtensionManager.getDefault().getPathFromURI(cwdURI) : null; + if (cwdPath != null && mappedRootURI != null) { + buildDirURI = EFSExtensionManager.getDefault().append(mappedRootURI, cwdPath); + } else { + buildDirURI = cwdURI; + } + + if (buildDirURI == null && currentCfgDescription != null) { + IPath builderCWD = currentCfgDescription.getBuildSetting().getBuilderCWD(); + buildDirURI = org.eclipse.core.filesystem.URIUtil.toURI(builderCWD); + } + + if (buildDirURI == null && currentProject != null) { + buildDirURI = currentProject.getLocationURI(); + } + + if (buildDirURI == null && currentResource != null) { + IContainer container; + if (currentResource instanceof IContainer) { + container = (IContainer) currentResource; + } else { + container = currentResource.getParent(); + } + buildDirURI = container.getLocationURI(); + } + return buildDirURI; + } + + /** + * Determine URI appending to baseURI when possible. + * + * @param pathStr - path to the resource, can be absolute or relative + * @param baseURI - base {@link URI} where path to the resource is rooted + * @return {@link URI} of the resource + */ + private static URI determineURI(String pathStr, URI baseURI) { + URI uri = null; + + if (baseURI==null) { + if (new Path(pathStr).isAbsolute()) { + uri = resolvePathFromBaseLocation(pathStr, Path.ROOT); + } + } else if (baseURI.getScheme().equals(EFS.SCHEME_FILE)) { + // location on the local filesystem + IPath baseLocation = org.eclipse.core.filesystem.URIUtil.toPath(baseURI); + // careful not to use Path here but 'pathStr' as String as we want to properly navigate symlinks + uri = resolvePathFromBaseLocation(pathStr, baseLocation); + } else { + // use canonicalized path here, in particular replace all '\' with '/' for Windows paths + Path path = new Path(pathStr); + uri = EFSExtensionManager.getDefault().append(baseURI, path.toString()); + } + + if (uri == null) { + // if everything fails just wrap string to URI + uri = org.eclipse.core.filesystem.URIUtil.toURI(pathStr); + } + return uri; + } + + private static IResource resolveResourceInWorkspace(String parsedName, IProject preferredProject, Set referencedProjectsNames) { + IPath path = new Path(parsedName); + if (path.equals(new Path(".")) || path.equals(new Path(".."))) { //$NON-NLS-1$ //$NON-NLS-2$ + return null; + } + + // prefer current project + if (preferredProject!=null) { + List result = findPathInFolder(path, preferredProject); + int size = result.size(); + if (size==1) { // found the one + return result.get(0); + } else if (size>1) { // ambiguous + return null; + } + } + + IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); + + // then prefer referenced projects + if (referencedProjectsNames.size() > 0) { + IResource rc = null; + for (String prjName : referencedProjectsNames) { + IProject prj = root.getProject(prjName); + if (prj.isOpen()) { + List result = findPathInFolder(path, prj); + int size = result.size(); + if (size==1 && rc==null) { + rc = result.get(0); + } else if (size > 0) { + // ambiguous + rc = null; + break; + } + } + } + if (rc!=null) { + return rc; + } + } + + // then check all other projects in workspace + IProject[] projects = root.getProjects(); + if (projects.length > 0) { + IResource rc = null; + for (IProject prj : projects) { + if (!prj.equals(preferredProject) && !referencedProjectsNames.contains(prj.getName()) && prj.isOpen()) { + List result = findPathInFolder(path, prj); + int size = result.size(); + if (size==1 && rc==null) { + rc = result.get(0); + } else if (size > 0) { + // ambiguous + rc = null; + break; + } + } + } + if (rc!=null) { + return rc; + } + } + + // not found or ambiguous + return null; + } + + private static List findPathInFolder(IPath path, IContainer folder) { + List paths = new ArrayList(); + IResource resource = folder.findMember(path); + if (resource != null) { + paths.add(resource); + } + + try { + for (IResource res : folder.members()) { + if (res instanceof IContainer) { + paths.addAll(findPathInFolder(path, (IContainer) res)); + } + } + } catch (CoreException e) { + // ignore + } + + return paths; + } + + private static IResource findFileForLocationURI(URI uri, IProject preferredProject) { + IResource sourceFile; + IResource result = null; + IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); + IResource[] resources = root.findFilesForLocationURI(uri); + if (resources.length > 0) { + result = resources[0]; + if (preferredProject!=null) { + for (IResource rc : resources) { + if (rc.getProject().equals(preferredProject)) { + result = rc; + break; + } + } + } + } + sourceFile = result; + return sourceFile; + } + + private static URI findBaseLocationURI(URI fileURI, String relativeFileName) { + URI cwdURI = null; + String path = fileURI.getPath(); + + String[] segments = relativeFileName.split("[/\\\\]"); //$NON-NLS-1$ + + // start removing segments from the end of the path + for (int i = segments.length - 1; i >= 0; i--) { + String lastSegment = segments[i]; + if (lastSegment.length() > 0 && !lastSegment.equals(".")) { //$NON-NLS-1$ + if (lastSegment.equals("..")) { //$NON-NLS-1$ + // navigating ".." in the other direction is ambiguous, bailing out + return null; + } else { + if (path.endsWith("/" + lastSegment)) { //$NON-NLS-1$ + int pos = path.lastIndexOf(lastSegment); + path = path.substring(0, pos); + continue; + } else { + // ouch, relativeFileName does not match fileURI, bailing out + return null; + } + } + } + } + + try { + cwdURI = new URI(fileURI.getScheme(), fileURI.getUserInfo(), fileURI.getHost(), + fileURI.getPort(), path, fileURI.getQuery(), fileURI.getFragment()); + } catch (URISyntaxException e) { + // It should be valid URI here or something is wrong + MakeCorePlugin.log(e); + } + + return cwdURI; + } + + /** + * In case when absolute path is mapped to the source tree in a project + * this function will try to figure mapping and return "mapped root", + * i.e URI where the root path would be mapped. The mapped root will be + * used to prepend to other "absolute" paths where appropriate. + * + * @param sourceFile - a resource referred by parsed path + * @param parsedResourceName - path as appears in the output + * @return mapped path as URI + */ + private static URI getMappedRootURI(IResource sourceFile, String parsedResourceName) { + URI fileURI = sourceFile.getLocationURI(); + String mappedRoot = "/"; //$NON-NLS-1$ + + if (parsedResourceName!=null) { + IPath parsedSrcPath = new Path(parsedResourceName); + if (parsedSrcPath.isAbsolute()) { + IPath absPath = sourceFile.getLocation(); + int absSegmentsCount = absPath.segmentCount(); + int relSegmentsCount = parsedSrcPath.segmentCount(); + if (absSegmentsCount >= relSegmentsCount) { + IPath ending = absPath.removeFirstSegments(absSegmentsCount - relSegmentsCount); + ending = ending.setDevice(parsedSrcPath.getDevice()).makeAbsolute(); + if (ending.equals(parsedSrcPath.makeAbsolute())) { + mappedRoot = absPath.removeLastSegments(relSegmentsCount).toString(); + } + } + } + } + URI uri = EFSExtensionManager.getDefault().createNewURIFromPath(fileURI, mappedRoot); + return uri; + } + + /** + * The manipulations here are done to resolve "../" navigation for symbolic links where "link/.." cannot + * be collapsed as it must follow the real filesystem path. {@link java.io.File#getCanonicalPath()} deals + * with that correctly but {@link Path} or {@link URI} try to normalize the path which would be incorrect + * here. + */ + private static URI resolvePathFromBaseLocation(String name, IPath baseLocation) { + String pathName = name; + if (baseLocation != null && !baseLocation.isEmpty()) { + String device = new Path(pathName).getDevice(); + if (device != null && device.length() > 0) { + pathName = pathName.substring(device.length()); + } + pathName = pathName.replace(File.separatorChar, '/'); + + baseLocation = baseLocation.addTrailingSeparator(); + if (pathName.startsWith("/")) { //$NON-NLS-1$ + pathName = pathName.substring(1); + } + pathName = baseLocation.toString() + pathName; + } + + try { + File file = new File(pathName); + file = file.getCanonicalFile(); + return file.toURI(); + } catch (IOException e) { + // if error just leave it as is + } + + URI uri = org.eclipse.core.filesystem.URIUtil.toURI(pathName); + return uri; + } + + private static IResource findResourceForLocationURI(URI uri, int kind, IProject preferredProject) { + if (uri==null) + return null; + + IResource resource = null; + + switch (kind) { + case ICSettingEntry.INCLUDE_PATH: + case ICSettingEntry.LIBRARY_PATH: + resource = findContainerForLocationURI(uri, preferredProject); + break; + case ICSettingEntry.INCLUDE_FILE: + case ICSettingEntry.MACRO_FILE: + resource = findFileForLocationURI(uri, preferredProject); + break; + } + + return resource; + } + + private static IResource findContainerForLocationURI(URI uri, IProject preferredProject) { + IResource resource = null; + IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); + IResource[] resources = root.findContainersForLocationURI(uri); + if (resources.length > 0) { + for (IResource rc : resources) { + if ((rc instanceof IProject || rc instanceof IFolder)) { // treat IWorkspaceRoot as non-workspace path + IProject prj = rc instanceof IProject ? (IProject)rc : rc.getProject(); + if (prj.equals(preferredProject)) { + resource = rc; + break; + } + if (resource==null) { + resource=rc; // to be deterministic the first qualified resource has preference + } + } + } + } + return resource; + } + + private static IPath getFilesystemLocation(URI uri) { + if (uri==null) + return null; + + // EFSExtensionManager mapping + String pathStr = EFSExtensionManager.getDefault().getMappedPath(uri); + uri = org.eclipse.core.filesystem.URIUtil.toURI(pathStr); + + try { + File file = new java.io.File(uri); + String canonicalPathStr = file.getCanonicalPath(); + return new Path(canonicalPathStr); + } catch (Exception e) { + MakeCorePlugin.log(e); + } + return null; + } + + @SuppressWarnings("nls") + private static String expressionLogicalOr(Set fileExts) { + String pattern = "("; + for (String ext : fileExts) { + if (pattern.length() != 1) + pattern += "|"; + pattern += "(" + Pattern.quote(ext) + ")"; + ext = ext.toUpperCase(); + if (!fileExts.contains(ext)) { + pattern += "|(" + Pattern.quote(ext) + ")"; + } + } + pattern += ")"; + return pattern; + } + + protected static int countGroups(String str) { + @SuppressWarnings("nls") + int count = str.replaceAll("[^\\(]", "").length(); + return count; + } + + @Override + public Element serialize(Element parentElement) { + Element elementProvider = super.serialize(parentElement); + elementProvider.setAttribute(ATTR_EXPAND_RELATIVE_PATHS, Boolean.toString(isResolvingPaths)); + return elementProvider; + } + + @Override + public void load(Element providerNode) { + super.load(providerNode); + + String expandRelativePathsValue = XmlUtil.determineAttributeValue(providerNode, ATTR_EXPAND_RELATIVE_PATHS); + if (expandRelativePathsValue!=null) + isResolvingPaths = Boolean.parseBoolean(expandRelativePathsValue); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + (isResolvingPaths ? 1231 : 1237); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + AbstractLanguageSettingsOutputScanner other = (AbstractLanguageSettingsOutputScanner) obj; + if (isResolvingPaths != other.isResolvingPaths) + return false; + return true; + } + +} diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/GCCBuildCommandParser.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/GCCBuildCommandParser.java new file mode 100644 index 00000000000..1594c0b1898 --- /dev/null +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/GCCBuildCommandParser.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright (c) 2009, 2011 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.make.core.scannerconfig; + + +import org.eclipse.cdt.core.errorparsers.RegexErrorPattern; +import org.eclipse.cdt.core.settings.model.ICSettingEntry; +import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider; + +public class GCCBuildCommandParser extends AbstractBuildCommandParser implements + ILanguageSettingsEditableProvider { + @SuppressWarnings("nls") + static final AbstractOptionParser[] optionParsers = { + new IncludePathOptionParser("-I\\s*([\"'])(.*)\\1", "$2"), + new IncludePathOptionParser("-I\\s*([^\\s\"']*)", "$1"), + new IncludeFileOptionParser("-include\\s*([\"'])(.*)\\1", "$2"), + new IncludeFileOptionParser("-include\\s*([^\\s\"']*)", "$1"), + new MacroOptionParser("-D\\s*([\"'])([^=]*)(=(.*))?\\1", "$2", "$4"), + new MacroOptionParser("-D\\s*([^\\s=\"']*)=(\\\\([\"']))(.*?)\\2", "$1", "$3$4$3"), + new MacroOptionParser("-D\\s*([^\\s=\"']*)=([\"'])(.*?)\\2", "$1", "$3"), + new MacroOptionParser("-D\\s*([^\\s=\"']*)(=([^\\s\"']*))?", "$1", "$3"), + new MacroOptionParser("-U\\s*([^\\s=\"']*)", "$1", ICSettingEntry.UNDEFINED), + new MacroFileOptionParser("-macros\\s*([\"'])(.*)\\1", "$2"), + new MacroFileOptionParser("-macros\\s*([^\\s\"']*)", "$1"), + new LibraryPathOptionParser("-L\\s*([\"'])(.*)\\1", "$2"), + new LibraryPathOptionParser("-L\\s*([^\\s\"']*)", "$1"), + new LibraryFileOptionParser("-l\\s*([^\\s\"']*)", "lib$1.a"), }; + + @Override + protected AbstractOptionParser[] getOptionParsers() { + return optionParsers; + } + + @Override + public GCCBuildCommandParser cloneShallow() throws CloneNotSupportedException { + return (GCCBuildCommandParser) super.cloneShallow(); + } + + @Override + public GCCBuildCommandParser clone() throws CloneNotSupportedException { + return (GCCBuildCommandParser) super.clone(); + } + + public static class GCCBuildCommandPatternHighlighter extends AbstractBuildCommandParser.AbstractBuildCommandPatternHighlighter { + // ID of the parser taken from the extension point + private static final String GCC_BUILD_COMMAND_PARSER_EXT = "org.eclipse.cdt.make.core.build.command.parser.gcc"; //$NON-NLS-1$ + + public GCCBuildCommandPatternHighlighter() { + super(GCC_BUILD_COMMAND_PARSER_EXT); + } + + @Override + public Object clone() throws CloneNotSupportedException { + GCCBuildCommandPatternHighlighter that = new GCCBuildCommandPatternHighlighter(); + that.setId(getId()); + that.setName(getName()); + for (RegexErrorPattern pattern : getPatterns()) { + that.addPattern((RegexErrorPattern)pattern.clone()); + } + return that; + } + } + +} diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/ILanguageSettingsBuildOutputScanner.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/ILanguageSettingsBuildOutputScanner.java new file mode 100644 index 00000000000..51615891c53 --- /dev/null +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/ILanguageSettingsBuildOutputScanner.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2011, 2011 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.make.core.scannerconfig; + +import org.eclipse.cdt.core.ErrorParserManager; +import org.eclipse.cdt.core.IErrorParser; +import org.eclipse.cdt.internal.core.ConsoleOutputSniffer; + +/** + * Note: IErrorParser interface is used here to work around {@link ConsoleOutputSniffer} having + * no access from CDT core to build packages. + */ +public interface ILanguageSettingsBuildOutputScanner extends ILanguageSettingsOutputScanner, IErrorParser { + + /** + * This method is expected to populate this.settingEntries with specific values + * parsed from supplied lines. + */ + public boolean processLine(String line, ErrorParserManager epm); +} diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/ILanguageSettingsBuiltinSpecsDetector.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/ILanguageSettingsBuiltinSpecsDetector.java new file mode 100644 index 00000000000..e094fb18dc6 --- /dev/null +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/ILanguageSettingsBuiltinSpecsDetector.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2011, 2011 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.make.core.scannerconfig; + +import java.io.IOException; +import java.util.List; + +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; + +public interface ILanguageSettingsBuiltinSpecsDetector extends ILanguageSettingsProvider { + public List getLanguageScope(); + public void run(IProject project, String languageId, IPath workingDirectory, String[] env, IProgressMonitor monitor) throws CoreException, IOException; + public void run(ICConfigurationDescription cfgDescription, String languageId, IPath workingDirectory, String[] env, IProgressMonitor monitor) throws CoreException, IOException; +} diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/ILanguageSettingsOutputScanner.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/ILanguageSettingsOutputScanner.java new file mode 100644 index 00000000000..642322f2d36 --- /dev/null +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/ILanguageSettingsOutputScanner.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2009, 2009 Andrew Gvozdev (Quoin Inc.) 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 (Quoin Inc.) - initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.make.core.scannerconfig; + +import java.util.List; + +import org.eclipse.cdt.core.ICConsoleParser; +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; + +/** + * TODO: Is this interface superfluous? + */ +public interface ILanguageSettingsOutputScanner extends ILanguageSettingsProvider, ICConsoleParser { + + // Inherited from ICConsoleParser + public void startup(ICConfigurationDescription cfgDescription) throws CoreException; + public boolean processLine(String line); + public void shutdown(); + + // Inherited from ICLanguageSettingsProvider + public List getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId); +} diff --git a/build/org.eclipse.cdt.make.ui/icons/obj16/inspect_system.gif b/build/org.eclipse.cdt.make.ui/icons/obj16/inspect_system.gif new file mode 100644 index 0000000000000000000000000000000000000000..d68100a748898719a2c9a143ac0d6763ebde2f5e GIT binary patch literal 553 zcmZ?wbhEHb6krfwIOf9;Vr7!!r&8(f(3F=qCo81AAgiM=v!gJpt1zRzxUjRNps~HJ zu4DSF_J%nf^=-XV+WKeD=_{EuwXb*Dl9|(H&YxK{XJ*Zu8Pg`sTDWXp{+@X@3l>ga zv#4O{lBpY)mo8eddC{t^TUXa^TGP30P5qiR3)ZilyL#QqEt_Vo-?DfAj)_}$Y}vf? z;I=(ScJDv1fB&u{2iN}DXLIoIiDO5$A3ApO%!y4GPOZIo>D;9&*REbYclr9Qn>TO$ zxfgT)?uA?T9^AeE@X_NZ&z?Pd@#4k%cdtKv`t;??m+xObfByRQ&%Zg}zJLGo>&x%o zzyJOF_kR!r#h)yU3=H)QIt)MniW3L+wubtq=9bnbHCnQMuxbn?E#L3)ZDx;_@r#aum z$dP4>x0jP>o2@27^AWxvl)hmM=8bB*YIHYRDTl@iK87YGY** L`SDqVgTWdAt^i(L literal 0 HcmV?d00001 diff --git a/build/org.eclipse.cdt.make.ui/icons/obj16/log_obj.gif b/build/org.eclipse.cdt.make.ui/icons/obj16/log_obj.gif new file mode 100644 index 0000000000000000000000000000000000000000..aebeab820d82ab024a82b9e03c4b284b4e2f0a48 GIT binary patch literal 335 zcmZ?wbhEHb6krfwSgOR(F=0i+i~}=fOq?}q!o1nN9SaUDn%A{#Vf%_jZL1fztX7DfgJdj=f_AOQKvfi362{8SH}s5+07 zrH6COgguw2x~z?Io{*wEIZ}k_&Ibjny>aTEr_;~oSudJ+_LwvS!;`ib{Dm)n{})e5 z3(Lq1DJf$J70Ogl=qT%p%#@QWnL2|fP()_#ym{*RNf? z`oQk}`*!YKK6~ljZF_cZ+HvgAv6IJ69zSyY;J$;WPMkV&@Th0*!vFtI{{R2)-9{Q{xYzi!ojzd!Hm)rnuOPWpOf;{Cn#PZn9eTp#{=Q|#Kl_?H9)`m^Y_v_E|osjQ0xhPeU?V7 zFYefq7px@erW32aOhZI~o1e+F);Uj8NSKj>%P7ZHO;TK&kDY#h literal 0 HcmV?d00001 diff --git a/build/org.eclipse.cdt.make.ui/plugin.properties b/build/org.eclipse.cdt.make.ui/plugin.properties index 21b341f00ec..4db795b46c4 100644 --- a/build/org.eclipse.cdt.make.ui/plugin.properties +++ b/build/org.eclipse.cdt.make.ui/plugin.properties @@ -44,6 +44,9 @@ PreferenceBuildSettings.name=Settings ErrorParsersTab.name=Error Parsers ErrorParsersTab.tooltip=Error Parsers scan build output and report errors in Problems view +LanguageSettingsProvidersTab.name=Discovery +LanguageSettingsProvidersTab.tooltip=Language settings providers + PreferenceMakeProject.name=New Make Projects PreferenceMake.name=Make Targets PreferenceMakefileEditor.name=Makefile Editor diff --git a/build/org.eclipse.cdt.make.ui/plugin.xml b/build/org.eclipse.cdt.make.ui/plugin.xml index 002d57859e9..c9c87cb44f6 100644 --- a/build/org.eclipse.cdt.make.ui/plugin.xml +++ b/build/org.eclipse.cdt.make.ui/plugin.xml @@ -470,6 +470,14 @@ tooltip="%ErrorParsersTab.tooltip" weight="020"> + + + + + + + + + + + + + + diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/preferences/GCCBuildCommandParserOptionPage.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/preferences/GCCBuildCommandParserOptionPage.java new file mode 100644 index 00000000000..d5bf8f74541 --- /dev/null +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/preferences/GCCBuildCommandParserOptionPage.java @@ -0,0 +1,370 @@ +/******************************************************************************* + * Copyright (c) 2009, 2010 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.make.internal.ui.preferences; + +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; +import org.eclipse.cdt.internal.ui.language.settings.providers.AbstractLanguageSettingProviderOptionPage; +import org.eclipse.cdt.internal.ui.newui.StatusMessageLine; +import org.eclipse.cdt.make.core.scannerconfig.AbstractBuildCommandParser; +import org.eclipse.cdt.utils.ui.controls.ControlFactory; +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; + +/** + * Options page for TODO + * + */ +public final class GCCBuildCommandParserOptionPage extends AbstractLanguageSettingProviderOptionPage { + private boolean fEditable; + + private Text inputCommand; + + private StatusMessageLine fStatusLine; + private Button runOnceRadioButton; + private Button runEveryBuildRadioButton; + private Button expandRelativePathCheckBox; + private Button applyToProjectCheckBox; + + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) + */ + @Override + public void createControl(Composite parent) { +// Composite optionsPageComposite = new Composite(composite, SWT.NULL); + fEditable = parent.isEnabled(); + + final Composite composite = new Composite(parent, SWT.NONE); + { + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + layout.marginWidth = 1; + layout.marginHeight = 1; + layout.marginRight = 1; + composite.setLayout(layout); + composite.setLayoutData(new GridData(GridData.FILL_BOTH)); + Dialog.applyDialogFont(composite); + + GridData gd = new GridData(GridData.FILL_HORIZONTAL); + gd.horizontalSpan = 2; + composite.setLayoutData(gd); + } + + +// Group groupRun = new Group(composite, SWT.SHADOW_ETCHED_IN); +//// groupRun.setText("Language Settings Provider Options"); +// +// GridLayout gridLayoutRun = new GridLayout(); +//// GridLayout gridLayoutRun = new GridLayout(2, true); +//// gridLayoutRun.makeColumnsEqualWidth = false; +//// gridLayoutRun.marginRight = -10; +//// gridLayoutRun.marginLeft = -4; +// groupRun.setLayout(gridLayoutRun); +//// GridData gdRun = new GridData(GridData.FILL_HORIZONTAL); +//// gdRun.horizontalSpan = 2; +//// groupRun.setLayoutData(gdRun); + + AbstractBuildCommandParser provider = getRawProvider(); +// { +// runOnceRadioButton = new Button(groupRun, SWT.RADIO); +// runOnceRadioButton.setText("Run only once"); //$NON-NLS-1$ +// // b1.setToolTipText(UIMessages.getString("EnvironmentTab.3")); //$NON-NLS-1$ +// GridData gd = new GridData(GridData.FILL_HORIZONTAL); +// gd.horizontalSpan = 3; +// runOnceRadioButton.setLayoutData(gd); +// runOnceRadioButton.setSelection(provider.isRunOnce()); +// runOnceRadioButton.setEnabled(fEditable); +// runOnceRadioButton.addSelectionListener(new SelectionAdapter() { +// @Override +// public void widgetSelected(SelectionEvent evt) { +// boolean runOnceEnabled = runOnceRadioButton.getSelection(); +// if (runOnceEnabled) { +// AbstractBuildCommandParser provider = getRawProvider(); +// if (runOnceEnabled != provider.isRunOnce()) { +// AbstractBuildCommandParser selectedProvider = getWorkingCopy(providerId); +// selectedProvider.setRunOnce(runOnceEnabled); +// providerTab.refreshItem(selectedProvider); +// } +// } +// } +// +// }); +// } +// { +// runEveryBuildRadioButton = new Button(groupRun, SWT.RADIO); +// runEveryBuildRadioButton.setText("Activate on every build"); //$NON-NLS-1$ +// runEveryBuildRadioButton.setSelection(!provider.isRunOnce()); +// runEveryBuildRadioButton.setEnabled(fEditable); +// GridData gd = new GridData(GridData.FILL_HORIZONTAL); +// gd.horizontalSpan = 3; +// runEveryBuildRadioButton.setLayoutData(gd); +// runEveryBuildRadioButton.addSelectionListener(new SelectionAdapter() { +// @Override +// public void widgetSelected(SelectionEvent evt) { +// boolean runEveryBuildEnabled = runEveryBuildRadioButton.getSelection(); +// if (runEveryBuildEnabled) { +// AbstractBuildCommandParser provider = getRawProvider(); +// if (runEveryBuildEnabled != !provider.isRunOnce()) { +// AbstractBuildCommandParser selectedProvider = getWorkingCopy(providerId); +// selectedProvider.setRunOnce(!runEveryBuildEnabled); +// providerTab.refreshItem(selectedProvider); +// } +// } +// } +// }); +// } + + // Compiler specs command + { + Label label = ControlFactory.createLabel(composite, "Compiler command pattern:"); + GridData gd = new GridData(); + gd.horizontalSpan = 1; + label.setLayoutData(gd); + label.setEnabled(fEditable); + } + + { + inputCommand = ControlFactory.createTextField(composite, SWT.SINGLE | SWT.BORDER); + String customParameter = provider.getCustomParameter(); + inputCommand.setText(customParameter!=null ? customParameter : ""); + + GridData gd = new GridData(); + gd.horizontalSpan = 1; + gd.grabExcessHorizontalSpace = true; + gd.horizontalAlignment = SWT.FILL; + inputCommand.setLayoutData(gd); + inputCommand.setEnabled(fEditable); + + inputCommand.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + String text = inputCommand.getText(); + AbstractBuildCommandParser provider = getRawProvider(); + if (!text.equals(provider.getCustomParameter())) { + AbstractBuildCommandParser selectedProvider = getWorkingCopy(providerId); + selectedProvider.setCustomParameter(text); + providerTab.refreshItem(selectedProvider); + } + } + }); + } + +// { +// Button button = ControlFactory.createPushButton(composite, "Browse..."); +// button.setEnabled(fEditable); +// button.addSelectionListener(new SelectionAdapter() { +// +// @Override +// public void widgetSelected(SelectionEvent evt) { +//// handleAddr2LineButtonSelected(); +// //updateLaunchConfigurationDialog(); +// } +// +// }); +// +// } + +// { +// final Button button = new Button(composite, SWT.PUSH); +// button.setFont(parent.getFont()); +// String text = fProvider.isEmpty() ? "Run Now (TODO)" : "Clear"; +// button.setText(text); +//// button.addSelectionListener(this); +// GridData data = new GridData(); +// data.horizontalSpan = 2; +//// data.horizontalAlignment = GridData.BEGINNING; +//// data.widthHint = 60; +// button.setLayoutData(data); +// // TODO +// button.setEnabled(fEditable && !fProvider.isEmpty()); +// +// button.addSelectionListener(new SelectionAdapter() { +// +// @Override +// public void widgetSelected(SelectionEvent evt) { +// if (fProvider.isEmpty()) { +// // TODO +// } else { +// fProvider.clear(); +// } +// // TODO +// button.setEnabled(fEditable && !fProvider.isEmpty()); +// String text = fProvider.isEmpty() ? "Run Now (TODO)" : "Clear"; +// button.setText(text); +// button.pack(); +// } +// +// }); +// +// } + +// // Compiler specs command +// { +// Label label = ControlFactory.createLabel(composite, "Parsing rules:"); +// GridData gd = new GridData(); +// gd.horizontalSpan = 2; +// label.setLayoutData(gd); +//// Label newLabel = new Label(composite, SWT.NONE); +////// ((GridData) newLabel.getLayoutData()).horizontalSpan = 1; +//// newLabel.setText("Command to get compiler specs:"); +// } + + +// createPatternsTable(group, composite); + + + + + + + + +// Group group = new Group(parent, SWT.SHADOW_ETCHED_IN); +// group.setText(DialogsMessages.RegexErrorParserOptionPage_Title); +// +// GridLayout gridLayout = new GridLayout(2, true); +// gridLayout.makeColumnsEqualWidth = false; +// gridLayout.marginRight = -10; +// gridLayout.marginLeft = -4; +// group.setLayout(gridLayout); +// group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); +// +// Composite composite = new Composite(group, SWT.NONE); +// GridLayout layout = new GridLayout(); +// layout.numColumns = 2; +// layout.marginWidth = 1; +// layout.marginHeight = 1; +// layout.marginRight = 1; +// composite.setLayout(layout); +// composite.setLayoutData(new GridData(GridData.FILL_BOTH)); +// Dialog.applyDialogFont(composite); +// +// if (!fEditable) +// createLinkToPreferences(composite); +// +// createPatternsTable(group, composite); +// +// if (fEditable) { +// createButtons(composite); +// } + + { + expandRelativePathCheckBox = new Button(composite, SWT.CHECK); + expandRelativePathCheckBox.setText("Use heuristics to resolve paths"); + GridData gd = new GridData(GridData.FILL_HORIZONTAL); + gd.horizontalSpan = 2; + expandRelativePathCheckBox.setLayoutData(gd); + + expandRelativePathCheckBox.setSelection(provider.isResolvingPaths()); + expandRelativePathCheckBox.setEnabled(fEditable); + expandRelativePathCheckBox.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + boolean enabled = expandRelativePathCheckBox.getSelection(); + AbstractBuildCommandParser provider = getRawProvider(); + if (enabled != provider.isResolvingPaths()) { + AbstractBuildCommandParser selectedProvider = getWorkingCopy(providerId); + selectedProvider.setResolvingPaths(enabled); + providerTab.refreshItem(selectedProvider); + } + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + widgetSelected(e); + } + + }); + + } + + { + applyToProjectCheckBox = new Button(composite, SWT.CHECK); + applyToProjectCheckBox.setText("Apply discovered settings on project level"); + GridData gd = new GridData(GridData.FILL_HORIZONTAL); + gd.horizontalSpan = 2; + applyToProjectCheckBox.setLayoutData(gd); + +// applyToProjectCheckBox.setSelection(provider.isExpandRelativePaths()); +// applyToProjectCheckBox.setEnabled(fEditable); + applyToProjectCheckBox.setSelection(false); + applyToProjectCheckBox.setEnabled(false); + applyToProjectCheckBox.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + boolean enabled = applyToProjectCheckBox.getSelection(); + AbstractBuildCommandParser provider = getRawProvider(); + if (enabled != provider.isResolvingPaths()) { + AbstractBuildCommandParser selectedProvider = getWorkingCopy(providerId); + selectedProvider.setResolvingPaths(enabled); + providerTab.refreshItem(selectedProvider); + } + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + widgetSelected(e); + } + + }); + + } + +// // Status line +// if (fEditable) { +// fStatusLine = new StatusMessageLine(composite, SWT.LEFT, 2); +// IStatus status = new Status(IStatus.WARNING, CUIPlugin.PLUGIN_ID, "Note that currently not all options are persisted (FIXME)"); +// fStatusLine.setErrorStatus(status); +// } + + setControl(composite); + } + + private AbstractBuildCommandParser getRawProvider() { + ILanguageSettingsProvider provider = LanguageSettingsManager.getRawProvider(providerTab.getProvider(providerId)); + Assert.isTrue(provider instanceof AbstractBuildCommandParser); + return (AbstractBuildCommandParser) provider; + } + + private AbstractBuildCommandParser getWorkingCopy(String providerId) { + ILanguageSettingsProvider provider = providerTab.getWorkingCopy(providerId); + Assert.isTrue(provider instanceof AbstractBuildCommandParser); + return (AbstractBuildCommandParser) provider; + } + + @Override + public void performApply(IProgressMonitor monitor) throws CoreException { + // handled by LanguageSettingsProviderTab + } + + @Override + public void performDefaults() { + // handled by LanguageSettingsProviderTab + } + +} diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/scannerconfig/ScannerDiscoveryConsole.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/scannerconfig/ScannerDiscoveryConsole.java new file mode 100644 index 00000000000..e5590d9fd43 --- /dev/null +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/scannerconfig/ScannerDiscoveryConsole.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2010, 2011 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.make.internal.ui.scannerconfig; + +import java.net.URL; + +import org.eclipse.cdt.internal.ui.buildconsole.CBuildConsole; +import org.eclipse.cdt.internal.ui.language.settings.providers.LanguageSettingsProviderAssociation; + +public class ScannerDiscoveryConsole extends CBuildConsole { + + /** + * {@inheritDoc} + * @param consoleId - a console ID is expected here which then is used as menu context ID. + * @param defaultIconUrl - if {@code LanguageSettingsProviderAssociation} extension point + * defines URL by provider id, {@code defaultIconUrl} will be ignored and the URL from the extension + * point will be used. If not, supplied {@code defaultIconUrl} will be used. + */ + @Override + public void init(String consoleId, String name, URL defaultIconUrl) { + URL iconUrl = LanguageSettingsProviderAssociation.getImageUrl(consoleId); + if (iconUrl==null) { + iconUrl = defaultIconUrl; + } + + super.init(consoleId, name, iconUrl); + } + + +} diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/tests/suite/AllManagedBuildTests.java b/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/tests/suite/AllManagedBuildTests.java index 65fdaadca1d..6ea149057a4 100644 --- a/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/tests/suite/AllManagedBuildTests.java +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/tests/suite/AllManagedBuildTests.java @@ -16,6 +16,7 @@ import junit.framework.Test; import junit.framework.TestSuite; import org.eclipse.cdt.build.core.scannerconfig.tests.CfgScannerConfigProfileManagerTests; +import org.eclipse.cdt.build.core.scannerconfig.tests.GCCBuiltinSpecsDetectorTest; import org.eclipse.cdt.build.core.scannerconfig.tests.GCCSpecsConsoleParserTest; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.IPDOMManager; @@ -59,6 +60,7 @@ public class AllManagedBuildTests { // build.core.scannerconfig.tests suite.addTest(CfgScannerConfigProfileManagerTests.suite()); suite.addTestSuite(GCCSpecsConsoleParserTest.class); + suite.addTestSuite(GCCBuiltinSpecsDetectorTest.class); // managedbuilder.core.tests suite.addTest(ManagedBuildCoreTests20.suite()); diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/AllSD80Tests.java b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/AllSD80Tests.java new file mode 100644 index 00000000000..d339b469792 --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/AllSD80Tests.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2010, 2011 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 org.eclipse.cdt.build.core.scannerconfig.tests.GCCBuiltinSpecsDetectorTest; + +import junit.framework.TestSuite; + +public class AllSD80Tests extends TestSuite { + + public static TestSuite suite() { + return new AllSD80Tests(); + } + + public AllSD80Tests() { + super(AllSD80Tests.class.getName()); + + addTestSuite(GCCBuiltinSpecsDetectorTest.class); + } +} diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/GCCBuiltinSpecsDetectorTest.java b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/GCCBuiltinSpecsDetectorTest.java new file mode 100644 index 00000000000..5e5ff994266 --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/GCCBuiltinSpecsDetectorTest.java @@ -0,0 +1,659 @@ +/******************************************************************************* + * Copyright (c) 2009 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.io.IOException; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.List; + +import junit.framework.TestCase; + +import org.eclipse.cdt.core.model.CoreModel; +import org.eclipse.cdt.core.settings.model.CIncludeFileEntry; +import org.eclipse.cdt.core.settings.model.CIncludePathEntry; +import org.eclipse.cdt.core.settings.model.CLibraryFileEntry; +import org.eclipse.cdt.core.settings.model.CLibraryPathEntry; +import org.eclipse.cdt.core.settings.model.CMacroEntry; +import org.eclipse.cdt.core.settings.model.CMacroFileEntry; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; +import org.eclipse.cdt.core.settings.model.ICProjectDescription; +import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager; +import org.eclipse.cdt.core.settings.model.ICSettingEntry; +import org.eclipse.cdt.core.testplugin.ResourceHelper; +import org.eclipse.cdt.internal.core.XmlUtil; +import org.eclipse.cdt.managedbuilder.internal.scannerconfig.AbstractBuiltinSpecsDetector; +import org.eclipse.cdt.managedbuilder.internal.scannerconfig.GCCBuiltinSpecsDetector; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +public class GCCBuiltinSpecsDetectorTest extends TestCase { + private static final String PROVIDER_ID = "provider.id"; + private static final String PROVIDER_NAME = "provider name"; + private static final String LANGUAGE_ID = "language.test.id"; + private static final String LANGUAGE_ID_C = "org.eclipse.cdt.core.gcc"; + private static final String LANGUAGE_ID_CPP = "org.eclipse.cdt.core.g++"; + private static final String CUSTOM_PARAMETER = "customParameter"; + private static final String ELEM_TEST = "test"; + + // those attributes must match that in AbstractBuiltinSpecsDetector + private static final String ATTR_CONSOLE = "console"; //$NON-NLS-1$ + private static final String ATTR_RUN_ONCE = "run-once"; //$NON-NLS-1$ + + private class MockBuiltinSpecsDetector extends AbstractBuiltinSpecsDetector { + @Override + protected String getToolchainId() { + return null; + } + @Override + protected List parseForOptions(String line) { + return null; + } + @Override + protected AbstractOptionParser[] getOptionParsers() { + return null; + } + } + + @Override + protected void setUp() throws Exception { + } + + @Override + protected void tearDown() throws Exception { + ResourceHelper.cleanUp(); + } + + private ICConfigurationDescription[] getConfigurationDescriptions(IProject project) { + CoreModel coreModel = CoreModel.getDefault(); + ICProjectDescriptionManager mngr = coreModel.getProjectDescriptionManager(); + // project description + ICProjectDescription projectDescription = mngr.getProjectDescription(project); + assertNotNull(projectDescription); + assertEquals(1, projectDescription.getConfigurations().length); + // configuration description + ICConfigurationDescription[] cfgDescriptions = projectDescription.getConfigurations(); + return cfgDescriptions; + } + + public void testAbstractBuiltinSpecsDetector_GettersSetters() throws Exception { + // define mock detector + MockBuiltinSpecsDetector detector = new MockBuiltinSpecsDetector(); + + detector.configureProvider(PROVIDER_ID, PROVIDER_NAME, null, null, null); + assertEquals(PROVIDER_ID, detector.getId()); + assertEquals(PROVIDER_NAME, detector.getName()); + assertEquals(null, detector.getLanguageScope()); + assertEquals(null, detector.getSettingEntries(null, null, null)); + assertEquals(null, detector.getCustomParameter()); + + List languages = new ArrayList(); + languages.add(LANGUAGE_ID); + List entries = new ArrayList(); + ICLanguageSettingEntry entry = new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); + entries.add(entry); + + detector.configureProvider(PROVIDER_ID, PROVIDER_NAME, languages, entries, CUSTOM_PARAMETER); + assertEquals(PROVIDER_ID, detector.getId()); + assertEquals(PROVIDER_NAME, detector.getName()); + assertEquals(languages, detector.getLanguageScope()); + assertEquals(entries, detector.getSettingEntries(null, null, null)); + assertEquals(CUSTOM_PARAMETER, detector.getCustomParameter()); + + assertEquals(true, detector.isRunOnce()); + detector.setRunOnce(false); + assertEquals(false, detector.isRunOnce()); + } + + public void testAbstractBuiltinSpecsDetector_CloneAndEquals() throws Exception { + // define mock detector + class MockDetectorCloneable extends MockBuiltinSpecsDetector implements Cloneable { + @Override + public MockDetectorCloneable clone() throws CloneNotSupportedException { + return (MockDetectorCloneable) super.clone(); + } + @Override + public MockDetectorCloneable cloneShallow() throws CloneNotSupportedException { + return (MockDetectorCloneable) super.cloneShallow(); + } + } + + // create instance to compare to + MockDetectorCloneable detector = new MockDetectorCloneable(); + + List languages = new ArrayList(); + languages.add(LANGUAGE_ID); + List entries = new ArrayList(); + ICLanguageSettingEntry entry = new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); + entries.add(entry); + + // check clone after initialization + MockDetectorCloneable clone0 = detector.clone(); + assertTrue(detector.equals(clone0)); + + // configure provider + detector.configureProvider(PROVIDER_ID, PROVIDER_NAME, languages, entries, CUSTOM_PARAMETER); + assertEquals(true, detector.isRunOnce()); + detector.setRunOnce(false); + assertFalse(detector.equals(clone0)); + + // check another clone after configuring + { + MockDetectorCloneable clone = detector.clone(); + assertTrue(detector.equals(clone)); + } + + // check custom parameter + { + MockDetectorCloneable clone = detector.clone(); + clone.setCustomParameter("changed"); + assertFalse(detector.equals(clone)); + } + + // check language scope + { + MockDetectorCloneable clone = detector.clone(); + clone.setLanguageScope(null); + assertFalse(detector.equals(clone)); + } + + // check 'run once' flag + { + MockDetectorCloneable clone = detector.clone(); + boolean runOnce = clone.isRunOnce(); + clone.setRunOnce( ! runOnce ); + assertFalse(detector.equals(clone)); + } + + // check console flag + { + MockDetectorCloneable clone = detector.clone(); + boolean isConsoleEnabled = clone.isConsoleEnabled(); + clone.setConsoleEnabled( ! isConsoleEnabled ); + assertFalse(detector.equals(clone)); + } + + // check entries + { + MockDetectorCloneable clone = detector.clone(); + clone.setSettingEntries(null, null, null, null); + assertFalse(detector.equals(clone)); + } + + // check cloneShallow() + { + MockDetectorCloneable detector2 = detector.clone(); + MockDetectorCloneable clone = detector2.cloneShallow(); + assertFalse(detector2.equals(clone)); + detector2.setSettingEntries(null, null, null, null); + assertTrue(detector2.equals(clone)); + } + + } + + /** + */ + public void testAbstractBuiltinSpecsDetector_Serialize() throws Exception { + { + // create empty XML + Document doc = XmlUtil.newDocument(); + Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST); + + // load it to new provider + MockBuiltinSpecsDetector detector = new MockBuiltinSpecsDetector(); + detector.load(rootElement); + assertEquals(true, detector.isRunOnce()); + assertEquals(false, detector.isConsoleEnabled()); + } + + Element elementProvider; + { + // define mock detector + MockBuiltinSpecsDetector detector = new MockBuiltinSpecsDetector(); + assertEquals(true, detector.isRunOnce()); + assertEquals(false, detector.isConsoleEnabled()); + + // redefine the settings + detector.setRunOnce(false); + assertEquals(false, detector.isRunOnce()); + detector.setConsoleEnabled(true); + assertEquals(true, detector.isConsoleEnabled()); + + // serialize in XML + Document doc = XmlUtil.newDocument(); + Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST); + elementProvider = detector.serialize(rootElement); + String xmlString = XmlUtil.toString(doc); + + assertTrue(xmlString.contains(ATTR_RUN_ONCE)); + assertTrue(xmlString.contains(ATTR_CONSOLE)); + } + { + // create another instance of the provider + MockBuiltinSpecsDetector detector = new MockBuiltinSpecsDetector(); + assertEquals(true, detector.isRunOnce()); + assertEquals(false, detector.isConsoleEnabled()); + + // load element + detector.load(elementProvider); + assertEquals(false, detector.isRunOnce()); + assertEquals(true, detector.isConsoleEnabled()); + } + } + + + + public void testAbstractBuiltinSpecsDetector_Nulls() throws Exception { + { + // test AbstractBuiltinSpecsDetector.run(...); + MockBuiltinSpecsDetector detector = new MockBuiltinSpecsDetector(); + detector.run((IProject)null, null, null, null, null); + // Do not test with (ICConfigurationDescription)null as it is not allowed + } + + { + // test AbstractBuiltinSpecsDetector.processLine(...) flow + MockBuiltinSpecsDetector detector = new MockBuiltinSpecsDetector(); + detector.startup(null); + detector.processLine(null); + detector.shutdown(); + } + + } + + public void testAbstractBuiltinSpecsDetector_RunConfiguration() throws Exception { + // Create model project and accompanied descriptions + String projectName = getName(); + IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); + + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + AbstractBuiltinSpecsDetector detector = new GCCBuiltinSpecsDetector() { + @Override + protected boolean runProgram(String command, String[] env, IPath workingDirectory, IProgressMonitor monitor, + OutputStream consoleOut, OutputStream consoleErr) throws CoreException, IOException { + printLine(consoleOut, "#define MACRO VALUE"); + consoleOut.close(); + consoleErr.close(); + return true; + } + }; + + detector.setLanguageScope(new ArrayList() {{add(LANGUAGE_ID);}}); + + detector.run(cfgDescription, LANGUAGE_ID, null, null, null); + assertFalse(detector.isEmpty()); + + List noentries = detector.getSettingEntries(null, null, null); + assertNull(noentries); + + List entries = detector.getSettingEntries(cfgDescription, null, LANGUAGE_ID); + ICLanguageSettingEntry expected = new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); + assertEquals(expected, entries.get(0)); + } + + public void testAbstractBuiltinSpecsDetector_RunProject() throws Exception { + // Create model project and accompanied descriptions + String projectName = getName(); + IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); + + AbstractBuiltinSpecsDetector detector = new GCCBuiltinSpecsDetector() { + @Override + protected boolean runProgram(String command, String[] env, IPath workingDirectory, IProgressMonitor monitor, + OutputStream consoleOut, OutputStream consoleErr) throws CoreException, IOException { + printLine(consoleOut, "#define MACRO VALUE"); + consoleOut.close(); + consoleErr.close(); + return true; + } + }; + + detector.setLanguageScope(new ArrayList() {{add(LANGUAGE_ID);}}); + + detector.run(project, LANGUAGE_ID, null, null, null); + assertFalse(detector.isEmpty()); + + List entries = detector.getSettingEntries(null, null, LANGUAGE_ID); + ICLanguageSettingEntry expected = new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); + assertEquals(expected, entries.get(0)); + } + + public void testAbstractBuiltinSpecsDetector_RunOnce() throws Exception { + // Create model project and accompanied descriptions + String projectName = getName(); + IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + // Define mock detector which collects number of entries equal to count + AbstractBuiltinSpecsDetector detector = new MockBuiltinSpecsDetector() { + int count=0; + @Override + public boolean processLine(String line) { + count++; + for (int i=0;i entries = detector.getSettingEntries(null, null, LANGUAGE_ID_C); + assertEquals(1, entries.size()); + } + + // run second time + detector.run(project, LANGUAGE_ID_C, null, null, null); + { + List entries = detector.getSettingEntries(null, null, LANGUAGE_ID_C); + assertEquals(2, entries.size()); + } + + // set to run once + detector.setRunOnce(true); + assertEquals(true, detector.isRunOnce()); + assertFalse(detector.isEmpty()); + + detector.run(project, LANGUAGE_ID_C, null, null, null); + { + // should not collect when provider is not empty + List entries = detector.getSettingEntries(null, null, LANGUAGE_ID_C); + assertEquals(2, entries.size()); + } + + detector.run(cfgDescription, LANGUAGE_ID_C, null, null, null); + { + // should not collect when provider is not empty + List entries = detector.getSettingEntries(null, null, LANGUAGE_ID_C); + assertEquals(2, entries.size()); + } + } + + public void testAbstractBuiltinSpecsDetector_GroupSettings() throws Exception { + // define benchmarks + final CIncludePathEntry includePath_1 = new CIncludePathEntry("/include/path_1", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); + final CIncludePathEntry includePath_2 = new CIncludePathEntry("/include/path_2", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); + final CIncludeFileEntry includeFile_1 = new CIncludeFileEntry(new Path("/include.file1"), ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); + final CIncludeFileEntry includeFile_2 = new CIncludeFileEntry(new Path("/include.file2"), ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); + final CMacroEntry macro_1 = new CMacroEntry("MACRO_1", "", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); + final CMacroEntry macro_2 = new CMacroEntry("MACRO_2", "", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY |ICSettingEntry.UNDEFINED); + final CMacroFileEntry macroFile_1 = new CMacroFileEntry(new Path("/macro.file1"), ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); + final CMacroFileEntry macroFile_2 = new CMacroFileEntry(new Path("/macro.file2"), ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); + final CLibraryPathEntry libraryPath_1 = new CLibraryPathEntry(new Path("/lib/path_1"), ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); + final CLibraryPathEntry libraryPath_2 = new CLibraryPathEntry(new Path("/lib/path_2"), ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); + final CLibraryFileEntry libraryFile_1 = new CLibraryFileEntry("lib_1.a", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); + final CLibraryFileEntry libraryFile_2 = new CLibraryFileEntry("lib_2.a", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); + + // Define mock detector adding unorganized entries + AbstractBuiltinSpecsDetector detector = new MockBuiltinSpecsDetector() { + @Override + public boolean processLine(String line) { + detectedSettingEntries.add(libraryFile_1); + detectedSettingEntries.add(libraryPath_1); + detectedSettingEntries.add(macroFile_1); + detectedSettingEntries.add(macro_1); + detectedSettingEntries.add(includeFile_1); + detectedSettingEntries.add(includePath_1); + + detectedSettingEntries.add(includePath_2); + detectedSettingEntries.add(includeFile_2); + detectedSettingEntries.add(macro_2); + detectedSettingEntries.add(macroFile_2); + detectedSettingEntries.add(libraryPath_2); + detectedSettingEntries.add(libraryFile_2); + return true; + } + }; + + // run specs detector + detector.startup(null); + detector.processLine(""); + detector.shutdown(); + + + // compare benchmarks, expected well-sorted + List entries = detector.getSettingEntries(null, null, null); + + int i=0; + assertEquals(includePath_1, entries.get(i++)); + assertEquals(includePath_2, entries.get(i++)); + assertEquals(includeFile_1, entries.get(i++)); + assertEquals(includeFile_2, entries.get(i++)); + assertEquals(macro_1, entries.get(i++)); + assertEquals(macro_2, entries.get(i++)); + assertEquals(macroFile_1, entries.get(i++)); + assertEquals(macroFile_2, entries.get(i++)); + assertEquals(libraryPath_1, entries.get(i++)); + assertEquals(libraryPath_2, entries.get(i++)); + assertEquals(libraryFile_1, entries.get(i++)); + assertEquals(libraryFile_2, entries.get(i++)); + + assertEquals(12, entries.size()); + } + + public void testGCCBuiltinSpecsDetector_Macro_NoValue() throws Exception { + AbstractBuiltinSpecsDetector detector = new GCCBuiltinSpecsDetector(); + + detector.startup(null); + detector.processLine("#define MACRO"); + detector.shutdown(); + + List entries = detector.getSettingEntries(null, null, null); + ICLanguageSettingEntry expected = new CMacroEntry("MACRO", null, ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); + assertEquals(expected, entries.get(0)); + } + + public void testGCCBuiltinSpecsDetector_ResolvedCommand() throws Exception { + class MockGCCBuiltinSpecsDetector extends GCCBuiltinSpecsDetector { + @Override + public String resolveCommand(String languageId) throws CoreException { + return super.resolveCommand(languageId); + } + } + { + MockGCCBuiltinSpecsDetector detector = new MockGCCBuiltinSpecsDetector(); + detector.setLanguageScope(new ArrayList() {{add(LANGUAGE_ID_C);}}); + detector.setCustomParameter("${COMMAND} -E -P -v -dD ${INPUTS}"); + + String resolvedCommand = detector.resolveCommand(LANGUAGE_ID_C); + assertTrue(resolvedCommand.startsWith("gcc -E -P -v -dD ")); + assertTrue(resolvedCommand.endsWith("spec.c")); + detector.shutdown(); + } + { + MockGCCBuiltinSpecsDetector detector = new MockGCCBuiltinSpecsDetector(); + detector.setLanguageScope(new ArrayList() {{add(LANGUAGE_ID_C);}}); + detector.setCustomParameter("${COMMAND} -E -P -v -dD file.${EXT}"); + + String resolvedCommand = detector.resolveCommand(LANGUAGE_ID_C); + assertTrue(resolvedCommand.startsWith("gcc -E -P -v -dD ")); + assertTrue(resolvedCommand.endsWith("file.c")); + detector.shutdown(); + } + } + + public void testGCCBuiltinSpecsDetector_Macro_NoArgs() throws Exception { + AbstractBuiltinSpecsDetector detector = new GCCBuiltinSpecsDetector(); + + detector.startup(null); + detector.processLine("#define MACRO VALUE"); + detector.shutdown(); + + List entries = detector.getSettingEntries(null, null, null); + ICLanguageSettingEntry expected = new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); + assertEquals(expected, entries.get(0)); + } + + public void testGCCBuiltinSpecsDetector_Macro_Const() throws Exception { + AbstractBuiltinSpecsDetector detector = new GCCBuiltinSpecsDetector(); + + detector.startup(null); + detector.processLine("#define MACRO (3)"); + detector.shutdown(); + + List entries = detector.getSettingEntries(null, null, null); + ICLanguageSettingEntry expected = new CMacroEntry("MACRO", "(3)", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); + assertEquals(expected, entries.get(0)); + } + + public void testGCCBuiltinSpecsDetector_Macro_EmptyArgList() throws Exception { + AbstractBuiltinSpecsDetector detector = new GCCBuiltinSpecsDetector(); + + detector.startup(null); + detector.processLine("#define MACRO() VALUE"); + detector.shutdown(); + + List entries = detector.getSettingEntries(null, null, null); + ICLanguageSettingEntry expected = new CMacroEntry("MACRO()", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); + assertEquals(expected, entries.get(0)); + } + + public void testGCCBuiltinSpecsDetector_Macro_ParamUnused() throws Exception { + AbstractBuiltinSpecsDetector detector = new GCCBuiltinSpecsDetector(); + + detector.startup(null); + detector.processLine("#define MACRO(X) VALUE"); + detector.shutdown(); + + List entries = detector.getSettingEntries(null, null, null); + ICLanguageSettingEntry expected = new CMacroEntry("MACRO(X)", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); + assertEquals(expected, entries.get(0)); + } + + public void testGCCBuiltinSpecsDetector_Macro_ParamSpace() throws Exception { + AbstractBuiltinSpecsDetector detector = new GCCBuiltinSpecsDetector(); + + detector.startup(null); + detector.processLine("#define MACRO(P1, P2) VALUE(P1, P2)"); + detector.shutdown(); + + List entries = detector.getSettingEntries(null, null, null); + ICLanguageSettingEntry expected = new CMacroEntry("MACRO(P1, P2)", "VALUE(P1, P2)", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); + assertEquals(expected, entries.get(0)); + } + + public void testGCCBuiltinSpecsDetector_Macro_ArgsNoValue() throws Exception { + AbstractBuiltinSpecsDetector detector = new GCCBuiltinSpecsDetector(); + + detector.startup(null); + detector.processLine("#define MACRO(P1, P2) "); + detector.shutdown(); + + List entries = detector.getSettingEntries(null, null, null); + ICLanguageSettingEntry expected = new CMacroEntry("MACRO(P1, P2)", null, ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); + assertEquals(expected, entries.get(0)); + } + + public void testGCCBuiltinSpecsDetector_Includes() throws Exception { + // Create model project and folders to test + String projectName = getName(); + IProject project = ResourceHelper.createCDTProject(projectName); + IPath tmpPath = ResourceHelper.createTemporaryFolder(); + ResourceHelper.createFolder(project, "/misplaced/include1"); + ResourceHelper.createFolder(project, "/local/include"); + ResourceHelper.createFolder(project, "/usr/include"); + ResourceHelper.createFolder(project, "/usr/include2"); + ResourceHelper.createFolder(project, "/misplaced/include2"); + ResourceHelper.createFolder(project, "/System/Library/Frameworks"); + ResourceHelper.createFolder(project, "/Library/Frameworks"); + ResourceHelper.createFolder(project, "/misplaced/include3"); + String loc = tmpPath.toString(); + + GCCBuiltinSpecsDetector detector = new GCCBuiltinSpecsDetector(); + detector.startup(null); + + detector.processLine(" "+loc+"/misplaced/include1"); + detector.processLine("#include \"...\" search starts here:"); + detector.processLine(" "+loc+"/local/include"); + detector.processLine("#include <...> search starts here:"); + detector.processLine(" "+loc+"/usr/include"); + detector.processLine(" "+loc+"/usr/include/../include2"); + detector.processLine(" "+loc+"/missing/folder"); + detector.processLine(" "+loc+"/Library/Frameworks (framework directory)"); + detector.processLine("End of search list."); + detector.processLine(" "+loc+"/misplaced/include2"); + detector.processLine("Framework search starts here:"); + detector.processLine(" "+loc+"/System/Library/Frameworks"); + detector.processLine("End of search list."); + detector.processLine(" "+loc+"/misplaced/include3"); + detector.shutdown(); + + List entries = detector.getSettingEntries(null, null, null); + assertEquals(new CIncludePathEntry(loc+"/local/include", ICSettingEntry.LOCAL | ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), + entries.get(0)); + assertEquals(new CIncludePathEntry(loc+"/usr/include", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), + entries.get(1)); + assertEquals(new CIncludePathEntry(loc+"/usr/include2", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), + entries.get(2)); + assertEquals(new CIncludePathEntry(loc+"/missing/folder", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), + entries.get(3)); + assertEquals(new CIncludePathEntry(loc+"/Library/Frameworks", ICSettingEntry.FRAMEWORKS_MAC | ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), + entries.get(4)); + assertEquals(new CIncludePathEntry(loc+"/System/Library/Frameworks", ICSettingEntry.FRAMEWORKS_MAC | ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), + entries.get(5)); + assertEquals(6, entries.size()); + } + + public void testGCCBuiltinSpecsDetector_Includes_SymbolicLinkUp() throws Exception { + // do not test on systems where symbolic links are not supported + if (!ResourceHelper.isSymbolicLinkSupported()) + return; + + // Create model project and folders to test + String projectName = getName(); + @SuppressWarnings("unused") + IProject project = ResourceHelper.createCDTProject(projectName); + // create link on the filesystem + IPath dir1 = ResourceHelper.createTemporaryFolder(); + IPath dir2 = dir1.removeLastSegments(1); + IPath linkPath = dir1.append("linked"); + ResourceHelper.createSymbolicLink(linkPath, dir2); + + AbstractBuiltinSpecsDetector detector = new GCCBuiltinSpecsDetector(); + + detector.startup(null); + detector.processLine("#include <...> search starts here:"); + detector.processLine(" "+linkPath.toString()+"/.."); + detector.processLine("End of search list."); + detector.shutdown(); + + // check populated entries + List entries = detector.getSettingEntries(null, null, null); + CIncludePathEntry expected = new CIncludePathEntry(dir2.removeLastSegments(1), ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); + assertEquals(expected, entries.get(0)); + assertEquals(1, entries.size()); + } + +} diff --git a/build/org.eclipse.cdt.managedbuilder.core/plugin.xml b/build/org.eclipse.cdt.managedbuilder.core/plugin.xml index 532aee8a5f0..fa816ec68e8 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/plugin.xml +++ b/build/org.eclipse.cdt.managedbuilder.core/plugin.xml @@ -308,6 +308,7 @@ @@ -597,6 +598,25 @@ + + + + + + + + + + + + + + diff --git a/build/org.eclipse.cdt.managedbuilder.core/schema/buildDefinitions.exsd b/build/org.eclipse.cdt.managedbuilder.core/schema/buildDefinitions.exsd index 83e75654f87..842d0059706 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/schema/buildDefinitions.exsd +++ b/build/org.eclipse.cdt.managedbuilder.core/schema/buildDefinitions.exsd @@ -263,7 +263,16 @@ Specifying this attribute is fully equivalent to specifying the "org.eclips - The semi-colon separated list of the default error parsers to be used with this configuration. The list is ordered with the first error parser on the list invoked first, the second error parser second, and so on. The list may contain the error parsers defined by CDT and/or other installed error parser extensions. The list of error parsers to be used may be changed by the user on a per-configuration basis. When specified, this overrides the tool-chain errorParsers attribute. + The semi-colon separated list of the default error parsers to be used with this configuration. The list is ordered with the first error parser on the list invoked first, the second error parser second, and so on. The list may contain the error parsers defined by CDT and/or other installed error parser extensions. The list of error parsers to be used may be changed by the user on a per-configuration basis. When specified, this overrides the tool-chain errorParsers attribute. + + + + + + + Semicolon-separated list of providers ID implementing ILanguageSettingProvider interface. +This field could be amended with toolchain-level providers list by using ${Toolchain} keyword. Provider ID can be prefixed with "*", in this case shared instance of the provider defined on workspace level is used. Also provider ID can be prefixed with "-" which will cause id to be removed from the preceeding list including providers defined with ${Toolchain} keyword. +If this field is not specified, "*org.eclipse.cdt.managedbuilder.core.LanguageSettingsProvider" (MBS Language Settings Provider) is used by default. @@ -405,7 +414,15 @@ Specifying this attribute is fully equivalent to specifying the "org.eclips - The semi-colon separated list of the default error parsers to be used with this tool-chain. The list is ordered with the first error parser on the list invoked first, the second error parser second, and so on. The list may contain the error parsers defined by CDT and/or other installed error parser extensions. When specified, this overrides the tool errorParsers attributes of the tool children of the tool-chain and the builder child of the tool-chain. + The semi-colon separated list of the default error parsers to be used with this tool-chain. The list is ordered with the first error parser on the list invoked first, the second error parser second, and so on. The list may contain the error parsers defined by CDT and/or other installed error parser extensions. When specified, this overrides the tool errorParsers attributes of the tool children of the tool-chain and the builder child of the tool-chain. + + + + + + + Semicolon-separated list of providers ID implementing ILanguageSettingProvider interface. Provider ID can be prefixed with "*", in this case shared instance of the provider defined on workspace level is used. +This list could be adjusted on configuration level in the corresponding attribute. @@ -732,14 +749,14 @@ The pathConverter of a toolchain applies for all tools of the toolchain except i - Specifies whether this Tool represents a user-define custom build step. The default is false. When True, the default value of the commandLinePattern attribute changes to “$(command)”. + Specifies whether this Tool represents a user-define custom build step. The default is false. When True, the default value of the commandLinePattern attribute changes to “$(command)�. - Specifies a string that is written to the build output prior to each invocation of the tool. The default value is “Invoking tool-name (tool-id)…” + Specifies a string that is written to the build output prior to each invocation of the tool. The default value is “Invoking tool-name (tool-id)…� @@ -1066,7 +1083,7 @@ Overrides language id specified with the languageId attribute. - The id of the input type that is used in determining the build “rules” for the output type and for the default name of the output file. The default is the input type with primaryInput == true. + The id of the input type that is used in determining the build “rules� for the output type and for the default name of the output file. The default is the input type with primaryInput == true. @@ -1080,7 +1097,7 @@ Overrides language id specified with the languageId attribute. - Some tools produce files with a special prefix that must be specified. For example, a librarian on POSIX systems expects the output to be libtarget.a, so 'lib' would be the prefix. The default is to use the Tool “outputPrefix” attribute if primaryOutput is True, otherwise the default is an empty string. This attribute supports MBS configuration context macros. + Some tools produce files with a special prefix that must be specified. For example, a librarian on POSIX systems expects the output to be libtarget.a, so 'lib' would be the prefix. The default is to use the Tool “outputPrefix� attribute if primaryOutput is True, otherwise the default is an empty string. This attribute supports MBS configuration context macros. @@ -2016,11 +2033,11 @@ If the "buildPathResolver" attribute is specified, the "pathDelim Represents the applicability type for this enablement. Can contain the following values: -UI_VISIBILITY – the given enablement expression specifies whether the option is to be visible in UI, -UI_ENABLEMENT – the given enablement expression specifies the enable state of the controls that represent the option in UI, -CMD_USAGE – the given enablement expression specifies whether the option is to be used in command line +UI_VISIBILITY – the given enablement expression specifies whether the option is to be visible in UI, +UI_ENABLEMENT – the given enablement expression specifies the enable state of the controls that represent the option in UI, +CMD_USAGE – the given enablement expression specifies whether the option is to be used in command line CONTAINER_ATTRIBUTE - the given enablement expressions specifies thecontainer attribute value -ALL – this value means the combination of all the above values. +ALL – this value means the combination of all the above values. Several types could be specified simultaneously using the "|" as a delimiter, e.g.: type="UI_VISIBILITY|CMD_USAGE" @@ -2154,7 +2171,7 @@ Default value is true. - Specifies the expected value. If the current option value matches the value specified in this attribute, the checkOption element is treated as true, otherwise – as false. + Specifies the expected value. If the current option value matches the value specified in this attribute, the checkOption element is treated as true, otherwise – as false. The expected value could be specified either as a string that may contain build macros or as a regular expression. During the comparison, the build macros are resolved and the option value is checked to match the resulting string or regular expression. The way the expected value is specified and treated depends on the value of the isRegex attribute @@ -2169,14 +2186,14 @@ The expected value could be specified either as a string that may contain build - The id of the option which is to be compared with the option specified with the “optionId” attribute. The default is the id of the option that holds this expression. If the “value” attribute is specified, both the “otherOptionId” and the “otherHolderId” attributes are ignored. When searching for the option to be checked, MBS will examine all the options the holder contains along with all superclasses of each option to find the option with the specified id. + The id of the option which is to be compared with the option specified with the “optionId� attribute. The default is the id of the option that holds this expression. If the “value� attribute is specified, both the “otherOptionId� and the “otherHolderId� attributes are ignored. When searching for the option to be checked, MBS will examine all the options the holder contains along with all superclasses of each option to find the option with the specified id. - The option holder id that holds the option specified with the “otherOptionId” attribute. The default is the id of the holder that holds the container of this expression. If the “value” attribute is specified, both the “otherOptionId” and the “otherHolderId” attributes are ingnored. When searching for the needed holder, MBS will examine all the holders the current configuration contains along with all superclasses of each holder in order to find the holder with the specified id. + The option holder id that holds the option specified with the “otherOptionId� attribute. The default is the id of the holder that holds the container of this expression. If the “value� attribute is specified, both the “otherOptionId� and the “otherHolderId� attributes are ingnored. When searching for the needed holder, MBS will examine all the holders the current configuration contains along with all superclasses of each holder in order to find the holder with the specified id. @@ -2200,7 +2217,7 @@ The expected value could be specified either as a string that may contain build - Specifies the expected value. If the current string specified in the “string” attribute matches the value specified in this attribute, the checkString element is treated as true, otherwise – as false. + Specifies the expected value. If the current string specified in the “string� attribute matches the value specified in this attribute, the checkString element is treated as true, otherwise – as false. The expected value could be specified either as a string that might contain the build macros or as a regular expression. The way the value is specified and treated depends on the value of the isRegex attribute. diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/build/internal/core/scannerconfig2/CfgScannerConfigProfileManager.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/build/internal/core/scannerconfig2/CfgScannerConfigProfileManager.java index bef0ef6047f..632659b2a55 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/build/internal/core/scannerconfig2/CfgScannerConfigProfileManager.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/build/internal/core/scannerconfig2/CfgScannerConfigProfileManager.java @@ -10,8 +10,14 @@ *******************************************************************************/ package org.eclipse.cdt.build.internal.core.scannerconfig2; +import java.util.Collection; +import java.util.Map; + import org.eclipse.cdt.build.core.scannerconfig.CfgInfoContext; import org.eclipse.cdt.build.core.scannerconfig.ICfgScannerConfigBuilderInfo2Set; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICProjectDescription; +import org.eclipse.cdt.make.core.scannerconfig.IScannerConfigBuilderInfo2; import org.eclipse.cdt.make.core.scannerconfig.InfoContext; import org.eclipse.cdt.make.core.scannerconfig.ScannerConfigScope; import org.eclipse.cdt.make.internal.core.scannerconfig2.ScannerConfigProfile; @@ -44,4 +50,34 @@ public class CfgScannerConfigProfileManager { return new CfgInfoContext(cfg).toInfoContext(); return new InfoContext(project); } + + public static boolean disableScannerDiscovery(IConfiguration cfg) { + boolean isChanged = false; + + ICfgScannerConfigBuilderInfo2Set info2set = getCfgScannerConfigBuildInfo(cfg); + Map infoMap = info2set.getInfoMap(); + Collection infos = infoMap.values(); + for (IScannerConfigBuilderInfo2 info2 : infos) { + isChanged = isChanged || info2.isAutoDiscoveryEnabled(); + info2.setAutoDiscoveryEnabled(false); + } + return isChanged; + } + + public static boolean disableScannerDiscovery(ICProjectDescription prjDescription) { + boolean isChanged = false; + + ICConfigurationDescription[] cfgDescs = prjDescription.getConfigurations(); + if (cfgDescs!=null) { + for (ICConfigurationDescription cfgDesc : cfgDescs) { + IConfiguration cfg = ManagedBuildManager.getConfigurationForDescription(cfgDesc); + boolean changed=CfgScannerConfigProfileManager.disableScannerDiscovery(cfg); + if (changed) { + isChanged = true; + } + + } + } + return isChanged; + } } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ExternalBuildRunner.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ExternalBuildRunner.java index 42940a74288..171046d3e2c 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ExternalBuildRunner.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ExternalBuildRunner.java @@ -25,15 +25,23 @@ import org.eclipse.cdt.build.core.scannerconfig.ICfgScannerConfigBuilderInfo2Set import org.eclipse.cdt.build.internal.core.scannerconfig2.CfgScannerConfigProfileManager; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.ErrorParserManager; +import org.eclipse.cdt.core.ICConsoleParser; import org.eclipse.cdt.core.ICommandLauncher; +import org.eclipse.cdt.core.IConsoleParser; import org.eclipse.cdt.core.IMarkerGenerator; import org.eclipse.cdt.core.envvar.IEnvironmentVariable; import org.eclipse.cdt.core.envvar.IEnvironmentVariableManager; +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager_TBD; import org.eclipse.cdt.core.model.ICModelMarker; import org.eclipse.cdt.core.resources.IConsole; import org.eclipse.cdt.core.resources.RefreshScopeManager; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.internal.core.ConsoleOutputSniffer; +import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer; +import org.eclipse.cdt.make.core.scannerconfig.ILanguageSettingsBuiltinSpecsDetector; import org.eclipse.cdt.make.core.scannerconfig.IScannerConfigBuilderInfo2; import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector; import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoConsoleParser; @@ -114,6 +122,23 @@ public class ExternalBuildRunner extends AbstractBuildRunner { break; } + URI workingDirectoryURI = ManagedBuildManager.getBuildLocationURI(configuration, builder); + final String pathFromURI = EFSExtensionManager.getDefault().getPathFromURI(workingDirectoryURI); + if(pathFromURI == null) { + throw new CoreException(new Status(IStatus.ERROR, ManagedBuilderCorePlugin.PLUGIN_ID, ManagedMakeMessages.getString("ManagedMakeBuilder.message.error"), null)); //$NON-NLS-1$ + } + + IPath workingDirectory = new Path(pathFromURI); + + // Set the environment + Map envMap = getEnvironment(builder); + String[] env = getEnvStrings(envMap); + + ICConfigurationDescription cfgDescription = ManagedBuildManager.getDescriptionForConfiguration(configuration); + if (kind!=IncrementalProjectBuilder.CLEAN_BUILD) { + ManagedBuildManager.runBuiltinSpecsDetectors(cfgDescription, workingDirectory, env, monitor); + } + consoleHeader[1] = configuration.getName(); consoleHeader[2] = project.getName(); buf.append(NEWLINE); @@ -135,14 +160,6 @@ public class ExternalBuildRunner extends AbstractBuildRunner { if (markers != null) workspace.deleteMarkers(markers); - URI workingDirectoryURI = ManagedBuildManager.getBuildLocationURI(configuration, builder); - final String pathFromURI = EFSExtensionManager.getDefault().getPathFromURI(workingDirectoryURI); - if(pathFromURI == null) { - throw new CoreException(new Status(IStatus.ERROR, ManagedBuilderCorePlugin.PLUGIN_ID, ManagedMakeMessages.getString("ManagedMakeBuilder.message.error"), null)); //$NON-NLS-1$ - } - - IPath workingDirectory = new Path(pathFromURI); - String[] targets = getTargets(kind, builder); if (targets.length != 0 && targets[targets.length - 1].equals(builder.getCleanBuildTarget())) isClean = true; @@ -153,9 +170,6 @@ public class ExternalBuildRunner extends AbstractBuildRunner { // Print the command for visual interaction. launcher.showCommand(true); - // Set the environment - Map envMap = getEnvironment(builder); - String[] env = getEnvStrings(envMap); String[] buildArguments = targets; String[] newArgs = CommandLineUtil.argumentsToArray(builder.getBuildArguments()); @@ -175,9 +189,15 @@ public class ExternalBuildRunner extends AbstractBuildRunner { OutputStream stderr = streamMon; // Sniff console output for scanner info - ConsoleOutputSniffer sniffer = createBuildOutputSniffer(stdout, stderr, project, configuration, workingDirectory, markerGenerator, null); - OutputStream consoleOut = (sniffer == null ? stdout : sniffer.getOutputStream()); - OutputStream consoleErr = (sniffer == null ? stderr : sniffer.getErrorStream()); + OutputStream consoleOut = stdout; + OutputStream consoleErr = stderr; + if (kind!=IncrementalProjectBuilder.CLEAN_BUILD) { + ConsoleOutputSniffer sniffer = createBuildOutputSniffer(stdout, stderr, project, configuration, workingDirectory, markerGenerator, null, epm); + if (sniffer!=null) { + consoleOut = sniffer.getOutputStream(); + consoleErr = sniffer.getErrorStream(); + } + } Process p = launcher.execute(buildCommand, buildArguments, env, workingDirectory, monitor); if (p != null) { try { @@ -193,6 +213,14 @@ public class ExternalBuildRunner extends AbstractBuildRunner { errMsg = launcher.getErrorMessage(); monitor.subTask(ManagedMakeMessages.getResourceString("MakeBuilder.Updating_project")); //$NON-NLS-1$ + // AG: FIXME +// try { +// LanguageSettingsManager.serialize(cfgDescription); +// } catch (CoreException e) { +// // TODO Auto-generated catch block +// e.printStackTrace(); +// } + try { // Do not allow the cancel of the refresh, since the builder is external // to Eclipse, files may have been created/modified and we will be out-of-sync. @@ -245,6 +273,11 @@ public class ExternalBuildRunner extends AbstractBuildRunner { consoleOut.close(); consoleErr.close(); cos.close(); + if (kind!=IncrementalProjectBuilder.CLEAN_BUILD) { + LanguageSettingsManager_TBD.serializeWorkspaceProviders(); + ICProjectDescription prjDescription = CCorePlugin.getDefault().getProjectDescription(project, false); + LanguageSettingsProvidersSerializer.serializeLanguageSettings(prjDescription); + } } } catch (Exception e) { ManagedBuilderCorePlugin.log(e); @@ -337,10 +370,11 @@ public class ExternalBuildRunner extends AbstractBuildRunner { IConfiguration cfg, IPath workingDirectory, IMarkerGenerator markerGenerator, - IScannerInfoCollector collector){ + IScannerInfoCollector collector, + ErrorParserManager epm){ ICfgScannerConfigBuilderInfo2Set container = CfgScannerConfigProfileManager.getCfgScannerConfigBuildInfo(cfg); Map map = container.getInfoMap(); - List clParserList = new ArrayList(); + List clParserList = new ArrayList(); if(container.isPerRcTypeDiscovery()){ for (IResourceInfo rcInfo : cfg.getResourceInfos()) { @@ -370,9 +404,25 @@ public class ExternalBuildRunner extends AbstractBuildRunner { contributeToConsoleParserList(project, map, new CfgInfoContext(cfg), workingDirectory, markerGenerator, collector, clParserList); } + ICConfigurationDescription cfgDescription = ManagedBuildManager.getDescriptionForConfiguration(cfg); + List lsProviders = cfgDescription.getLanguageSettingProviders(); + for (ILanguageSettingsProvider lsProvider : lsProviders) { + ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(lsProvider); + if (rawProvider instanceof ICConsoleParser && !(rawProvider instanceof ILanguageSettingsBuiltinSpecsDetector)) { + ICConsoleParser consoleParser = (ICConsoleParser) rawProvider; + try { + consoleParser.startup(cfgDescription); + clParserList.add(consoleParser); + } catch (CoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + if(clParserList.size() != 0){ - return new ConsoleOutputSniffer(outputStream, errorStream, - clParserList.toArray(new IScannerInfoConsoleParser[clParserList.size()])); + IConsoleParser[] parsers = clParserList.toArray(new IConsoleParser[clParserList.size()]); + return new ConsoleOutputSniffer(outputStream, errorStream, parsers, epm); } return null; @@ -385,7 +435,7 @@ public class ExternalBuildRunner extends AbstractBuildRunner { IPath workingDirectory, IMarkerGenerator markerGenerator, IScannerInfoCollector collector, - List parserList){ + List parserList){ IScannerConfigBuilderInfo2 info = map.get(context); InfoContext ic = context.toInfoContext(); boolean added = false; @@ -416,5 +466,4 @@ public class ExternalBuildRunner extends AbstractBuildRunner { return added; } - } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IConfiguration.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IConfiguration.java index 8b7f0499dce..3ab54cf1ec7 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IConfiguration.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IConfiguration.java @@ -46,6 +46,7 @@ public interface IConfiguration extends IBuildObject, IBuildObjectPropertiesCont // Schema element names public static final String CONFIGURATION_ELEMENT_NAME = "configuration"; //$NON-NLS-1$ public static final String ERROR_PARSERS = "errorParsers"; //$NON-NLS-1$ + public static final String LANGUAGE_SETTINGS_PROVIDERS = "languageSettingsProviders"; public static final String EXTENSION = "artifactExtension"; //$NON-NLS-1$ public static final String PARENT = "parent"; //$NON-NLS-1$ @@ -170,6 +171,8 @@ public interface IConfiguration extends IBuildObject, IBuildObjectPropertiesCont */ public String[] getErrorParserList(); + public String getDefaultLanguageSettingsProvidersIds(); + /** * Projects have C or CC natures. Tools can specify a filter so they are not * misapplied to a project. This method allows the caller to retrieve a list diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IToolChain.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IToolChain.java index 57cba447fca..34a1a4331b7 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IToolChain.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IToolChain.java @@ -53,6 +53,8 @@ public interface IToolChain extends IBuildObject, IHoldsOptions { // The attribute name for the scanner info collector public static final String SCANNER_CONFIG_PROFILE_ID = "scannerConfigDiscoveryProfileId"; //$NON-NLS-1$ + public static final String LANGUAGE_SETTINGS_PROVIDERS = "languageSettingsProviders"; + /** * Returns the configuration that is the parent of this tool-chain. * @@ -261,6 +263,13 @@ public interface IToolChain extends IBuildObject, IHoldsOptions { */ public void setErrorParserIds(String ids); + /** + * Returns the default language settings providers IDs. + * + * @return the default language settings providers IDs separated by semicolon or {@code null} if none. + */ + public String getDefaultLanguageSettingsProvidersIds(); + /** * Returns the scanner config discovery profile id or null if none. * diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/InternalBuildRunner.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/InternalBuildRunner.java index b8f525e1a1b..933d9750483 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/InternalBuildRunner.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/InternalBuildRunner.java @@ -13,14 +13,26 @@ package org.eclipse.cdt.managedbuilder.core; import java.io.IOException; import java.io.OutputStream; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.ConsoleOutputStream; import org.eclipse.cdt.core.ErrorParserManager; import org.eclipse.cdt.core.IMarkerGenerator; +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager_TBD; import org.eclipse.cdt.core.model.ICModelMarker; import org.eclipse.cdt.core.resources.IConsole; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICProjectDescription; +import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer; +import org.eclipse.cdt.make.core.scannerconfig.ILanguageSettingsBuildOutputScanner; import org.eclipse.cdt.managedbuilder.buildmodel.BuildDescriptionManager; import org.eclipse.cdt.managedbuilder.buildmodel.IBuildDescription; +import org.eclipse.cdt.managedbuilder.internal.buildmodel.BuildDescription; import org.eclipse.cdt.managedbuilder.internal.buildmodel.BuildStateManager; import org.eclipse.cdt.managedbuilder.internal.buildmodel.DescriptionBuilder; import org.eclipse.cdt.managedbuilder.internal.buildmodel.IBuildModelBuilder; @@ -35,6 +47,7 @@ import org.eclipse.core.resources.IResourceDelta; import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.IncrementalProjectBuilder; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; @@ -61,6 +74,21 @@ public class InternalBuildRunner extends AbstractBuildRunner { private static final String NOTHING_BUILT = "ManagedMakeBuilder.message.no.build"; //$NON-NLS-1$ private static final String BUILD_ERROR = "ManagedMakeBuilder.message.error"; //$NON-NLS-1$ + + // TODO: same function is present in CommandBuilder and BuildProcessManager + private String[] mapToStringArray(Map map){ + if(map == null) + return null; + + List list = new ArrayList(); + + for (Entry entry : map.entrySet()) { + list.add(entry.getKey() + '=' + entry.getValue()); + } + + return list.toArray(new String[list.size()]); + } + @Override public boolean invokeBuild(int kind, IProject project, IConfiguration configuration, IBuilder builder, IConsole console, IMarkerGenerator markerGenerator, @@ -96,6 +124,16 @@ public class InternalBuildRunner extends AbstractBuildRunner { // Get a build console for the project StringBuffer buf = new StringBuffer(); + + IBuildDescription des = BuildDescriptionManager.createBuildDescription(configuration, cBS, delta, flags); + + IPath workingDirectory = des.getDefaultBuildDirLocation(); + String[] env = null; + if (des instanceof BuildDescription) { + Map envMap = ((BuildDescription)des).getEnvironment(); + env = mapToStringArray(envMap); + } + consoleOutStream = console.getOutputStream(); String[] consoleHeader = new String[3]; if(buildIncrementaly) @@ -119,11 +157,28 @@ public class InternalBuildRunner extends AbstractBuildRunner { buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$ buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$ } + + if (kind!=IncrementalProjectBuilder.CLEAN_BUILD) { + ICConfigurationDescription cfgDescription = ManagedBuildManager.getDescriptionForConfiguration(configuration); + ManagedBuildManager.runBuiltinSpecsDetectors(cfgDescription, workingDirectory, env, monitor); + + List providers = cfgDescription.getLanguageSettingProviders(); + for (ILanguageSettingsProvider provider : providers) { + if (provider instanceof ILanguageSettingsBuildOutputScanner) { + buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$ + String msg = ManagedMakeMessages.getFormattedString("BOP Language Settings Provider [{0}] is not supported by Internal Builder.", provider.getName()); + buf.append("**** "+msg+" ****"); + buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$ + buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$ + + ManagedBuilderCorePlugin.error(msg); + } + } + } + consoleOutStream.write(buf.toString().getBytes()); consoleOutStream.flush(); - IBuildDescription des = BuildDescriptionManager.createBuildDescription(configuration, cBS, delta, flags); - DescriptionBuilder dBuilder = null; if (!isParallel) dBuilder = new DescriptionBuilder(des, buildIncrementaly, resumeOnErr, cBS); @@ -193,6 +248,12 @@ public class InternalBuildRunner extends AbstractBuildRunner { consoleOutStream.flush(); epmOutputStream.close(); epmOutputStream = null; + if (kind!=IncrementalProjectBuilder.CLEAN_BUILD) { + LanguageSettingsManager_TBD.serializeWorkspaceProviders(); + ICProjectDescription prjDescription = CCorePlugin.getDefault().getProjectDescription(project, false); + LanguageSettingsProvidersSerializer.serializeLanguageSettings(prjDescription); + } + // Generate any error markers that the build has discovered monitor.subTask(ManagedMakeMessages .getResourceString(MARKERS)); @@ -240,5 +301,4 @@ public class InternalBuildRunner extends AbstractBuildRunner { } return false; } - } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java index 6d8981d5bcc..296753806cd 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java @@ -49,17 +49,27 @@ import javax.xml.transform.stream.StreamResult; import org.eclipse.cdt.core.AbstractCExtension; import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.index.IIndexManager; +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager_TBD; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModelUtil; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.parser.IScannerInfo; import org.eclipse.cdt.core.parser.IScannerInfoChangeListener; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICFolderDescription; +import org.eclipse.cdt.core.settings.model.ICLanguageSetting; import org.eclipse.cdt.core.settings.model.ICMultiConfigDescription; import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager; import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.core.settings.model.XmlStorageUtil; import org.eclipse.cdt.core.settings.model.extension.CConfigurationData; +import org.eclipse.cdt.make.core.MakeCorePlugin; +import org.eclipse.cdt.make.core.scannerconfig.ILanguageSettingsBuiltinSpecsDetector; import org.eclipse.cdt.managedbuilder.buildproperties.IBuildProperty; import org.eclipse.cdt.managedbuilder.buildproperties.IBuildPropertyManager; import org.eclipse.cdt.managedbuilder.envvar.IEnvironmentBuildPathsChangeListener; @@ -149,6 +159,7 @@ import org.w3c.dom.ProcessingInstruction; */ public class ManagedBuildManager extends AbstractCExtension { + public static final String MBS_LANGUAGE_SETTINGS_PROVIDER = "org.eclipse.cdt.managedbuilder.core.LanguageSettingsProvider"; // private static final QualifiedName buildInfoProperty = new QualifiedName(ManagedBuilderCorePlugin.getUniqueIdentifier(), "managedBuildInfo"); //$NON-NLS-1$ private static final String ROOT_NODE_NAME = "ManagedProjectBuildInfo"; //$NON-NLS-1$ public static final String SETTINGS_FILE_NAME = ".cdtbuild"; //$NON-NLS-1$ @@ -4714,4 +4725,138 @@ public class ManagedBuildManager extends AbstractCExtension { return true; // no target platform - nothing to check. } + 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 ""; + } + + public static List getLanguageSettingsProviders(IConfiguration cfg) { + List providers = new ArrayList(); + + String providersIdsStr = getLanguageSettingsProvidersStr(cfg); + if (providersIdsStr!=null) { + if (providersIdsStr.contains("${Toolchain}")) { + IToolChain toolchain = cfg.getToolChain(); + String toolchainProvidersIds = getLanguageSettingsProvidersStr(toolchain); + if (toolchainProvidersIds==null) { + toolchainProvidersIds=""; + } + providersIdsStr = providersIdsStr.replaceAll("\\$\\{Toolchain\\}", toolchainProvidersIds); + } + List providersIds = Arrays.asList(providersIdsStr.split(String.valueOf(LanguageSettingsManager_TBD.PROVIDER_DELIMITER))); + for (String id : providersIds) { + id = id.trim(); + ILanguageSettingsProvider provider = null; + if (id.startsWith("*")) { + id = id.substring(1); + provider = LanguageSettingsManager.getWorkspaceProvider(id); + } else 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){ + provider = LanguageSettingsManager.getExtensionProviderCopy(id); + } + 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, LanguageSettingsManager_TBD.PROVIDER_UI_USER)) { + ILanguageSettingsProvider provider = LanguageSettingsManager.getExtensionProviderCopy(LanguageSettingsManager_TBD.PROVIDER_UI_USER); + providers.add(0, provider); + } + + return providers; + } + + private static boolean isProviderThere(List providers, String id) { + for (ILanguageSettingsProvider provider : providers) { + if (provider.getId().equals(id)) { + return true; + } + } + return false; + } + + /** + * TODO - better home? + */ + static public void runBuiltinSpecsDetectors(ICConfigurationDescription cfgDescription, IPath workingDirectory, + String[] env, IProgressMonitor monitor) { + IProject project = cfgDescription.getProjectDescription().getProject(); + ICFolderDescription rootFolderDescription = cfgDescription.getRootFolderDescription(); + List languageIds = new ArrayList(); + for (ICLanguageSetting languageSetting : rootFolderDescription.getLanguageSettings()) { + String id = languageSetting.getLanguageId(); + if (id!=null) { + languageIds.add(id); + } + } + + for (ILanguageSettingsProvider provider : cfgDescription.getLanguageSettingProviders()) { + ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); + if (rawProvider instanceof ILanguageSettingsBuiltinSpecsDetector) { + ILanguageSettingsBuiltinSpecsDetector detector = (ILanguageSettingsBuiltinSpecsDetector)rawProvider; + boolean isWorkspaceProvider = LanguageSettingsManager.isWorkspaceProvider(provider); + for (String languageId : languageIds) { + if (detector.getLanguageScope()==null || detector.getLanguageScope().contains(languageId)) { + try { + if (isWorkspaceProvider) { + detector.run(project, languageId, workingDirectory, env, monitor); + } else { + detector.run(cfgDescription, languageId, workingDirectory, env, monitor); + } + // detector.shutdown() is called from ConsoleOutputSniffer + } catch (Throwable e) { + IStatus status = new Status(IStatus.ERROR, MakeCorePlugin.PLUGIN_ID, "Internal error in BuiltinSpecsDetector "+detector.getId(), e); + MakeCorePlugin.log(status); + } + } + } + } + } + + + // AG: FIXME +// LanguageSettingsManager.serialize(cfgDescription); + // AG: FIXME - rather send event that ls settings changed + ICProject icProject = CoreModel.getDefault().create(project); + ICElement[] tuSelection = new ICElement[] {icProject}; + try { + CCorePlugin.getIndexManager().update(tuSelection, IIndexManager.UPDATE_ALL | IIndexManager.UPDATE_EXTERNAL_FILES_FOR_PROJECT); + } catch (CoreException e) { + IStatus status = new Status(IStatus.ERROR, ManagedBuilderCorePlugin.PLUGIN_ID, "Error updating CDT index", e); + ManagedBuilderCorePlugin.log(status); + } + } + } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/CommonBuilder.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/CommonBuilder.java index 3167b768e3e..06bf6f49a73 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/CommonBuilder.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/CommonBuilder.java @@ -26,6 +26,8 @@ import java.util.Set; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.ConsoleOutputStream; import org.eclipse.cdt.core.ProblemMarkerInfo; +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager_TBD; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.resources.ACBuilder; import org.eclipse.cdt.core.resources.IConsole; @@ -145,6 +147,7 @@ public class CommonBuilder extends ACBuilder { private final IConfiguration fCfg; private final IBuilder fBuilder; private IConsole fConsole; + CfgBuildInfo(IBuilder builder, boolean isForegound){ this.fBuilder = builder; this.fCfg = builder.getParent().getParent(); diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java index ef84a29dc1e..a2093855a1c 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java @@ -105,6 +105,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild private String cleanCommand; private String artifactExtension; private String errorParserIds; + private String defaultLanguageSettingsProvidersIds; private String prebuildStep; private String postbuildStep; private String preannouncebuildStep; @@ -784,6 +785,9 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild // Get the semicolon separated list of IDs of the error parsers errorParserIds = SafeStringInterner.safeIntern(element.getAttribute(ERROR_PARSERS)); + // Get the initial/default language setttings providers IDs + defaultLanguageSettingsProvidersIds = SafeStringInterner.safeIntern(element.getAttribute(LANGUAGE_SETTINGS_PROVIDERS)); + // Get the artifact extension artifactExtension = SafeStringInterner.safeIntern(element.getAttribute(EXTENSION)); @@ -1425,6 +1429,10 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild return set; } + public String getDefaultLanguageSettingsProvidersIds() { + return defaultLanguageSettingsProvidersIds; + } + /* (non-Javadoc) * @see org.eclipse.cdt.managedbuilder.core.IConfiguration#setArtifactExtension(java.lang.String) */ diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/MultiConfiguration.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/MultiConfiguration.java index d9834448cad..a2bfbc22137 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/MultiConfiguration.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/MultiConfiguration.java @@ -403,6 +403,11 @@ public class MultiConfiguration extends MultiItemsHolder implements return s; } + public String getDefaultLanguageSettingsProvidersIds() { + ManagedBuilderCorePlugin.error("Default Language Settings Providers are not supported in multiconfiguration mode"); + return null; + } + /* (non-Javadoc) * @see org.eclipse.cdt.managedbuilder.core.IConfiguration#getFilteredTools() */ diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolChain.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolChain.java index 6dd49708b6f..fb0bca68433 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolChain.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolChain.java @@ -85,6 +85,7 @@ public class ToolChain extends HoldsOptions implements IToolChain, IMatchKeyProv private String targetToolIds; private String secondaryOutputIds; private Boolean isAbstract; + private String defaultLanguageSettingsProvidersIds; private String scannerConfigDiscoveryProfileId; private String versionsSupported; private String convertToId; @@ -554,6 +555,9 @@ public class ToolChain extends HoldsOptions implements IToolChain, IMatchKeyProv // Get the target tool id targetToolIds = SafeStringInterner.safeIntern(element.getAttribute(TARGET_TOOL)); + // Get the initial/default language setttings providers IDs + defaultLanguageSettingsProvidersIds = element.getAttribute(LANGUAGE_SETTINGS_PROVIDERS); + // Get the scanner config discovery profile id scannerConfigDiscoveryProfileId = SafeStringInterner.safeIntern(element.getAttribute(SCANNER_CONFIG_PROFILE_ID)); String tmp = element.getAttribute(RESOURCE_TYPE_BASED_DISCOVERY); @@ -1501,6 +1505,10 @@ public class ToolChain extends HoldsOptions implements IToolChain, IMatchKeyProv setDirty(true); } + public String getDefaultLanguageSettingsProvidersIds() { + return defaultLanguageSettingsProvidersIds; + } + /* (non-Javadoc) * @see org.eclipse.cdt.managedbuilder.core.IToolChain#getScannerConfigDiscoveryProfileId() */ diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/AbstractBuiltinSpecsDetector.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/AbstractBuiltinSpecsDetector.java new file mode 100644 index 00000000000..4b0a3ac816e --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/AbstractBuiltinSpecsDetector.java @@ -0,0 +1,508 @@ +/******************************************************************************* + * Copyright (c) 2009, 2011 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.managedbuilder.internal.scannerconfig; + +import java.io.IOException; +import java.io.OutputStream; +import java.net.URL; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.CommandLauncher; +import org.eclipse.cdt.core.ErrorParserManager; +import org.eclipse.cdt.core.ICommandLauncher; +import org.eclipse.cdt.core.IConsoleParser; +import org.eclipse.cdt.core.model.ILanguageDescriptor; +import org.eclipse.cdt.core.model.LanguageManager; +import org.eclipse.cdt.core.resources.IConsole; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; +import org.eclipse.cdt.internal.core.ConsoleOutputSniffer; +import org.eclipse.cdt.internal.core.XmlUtil; +import org.eclipse.cdt.make.core.MakeCorePlugin; +import org.eclipse.cdt.make.core.scannerconfig.AbstractLanguageSettingsOutputScanner; +import org.eclipse.cdt.make.core.scannerconfig.ILanguageSettingsBuiltinSpecsDetector; +import org.eclipse.cdt.make.internal.core.MakeMessages; +import org.eclipse.cdt.make.internal.core.StreamMonitor; +import org.eclipse.cdt.make.internal.core.scannerconfig2.SCMarkerGenerator; +import org.eclipse.cdt.managedbuilder.core.IInputType; +import org.eclipse.cdt.managedbuilder.core.ITool; +import org.eclipse.cdt.managedbuilder.core.IToolChain; +import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; +import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin; +import org.eclipse.cdt.utils.CommandLineUtil; +import org.eclipse.cdt.utils.PathUtil; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.SubProgressMonitor; +import org.w3c.dom.Element; + +public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSettingsOutputScanner implements ILanguageSettingsBuiltinSpecsDetector { + private static final String NEWLINE = System.getProperty("line.separator", "\n"); //$NON-NLS-1$ //$NON-NLS-2$ + private static final String PLUGIN_CDT_MAKE_UI_ID = "org.eclipse.cdt.make.ui"; //$NON-NLS-1$ + private static final String GMAKE_ERROR_PARSER_ID = "org.eclipse.cdt.core.GmakeErrorParser"; //$NON-NLS-1$ + private static final String PATH_ENV = "PATH"; //$NON-NLS-1$ + private static final String ATTR_RUN_ONCE = "run-once"; //$NON-NLS-1$ + private static final String ATTR_CONSOLE = "console"; //$NON-NLS-1$ + + protected static final String COMPILER_MACRO = "${COMMAND}"; //$NON-NLS-1$ + protected static final String SPEC_FILE_MACRO = "${INPUTS}"; //$NON-NLS-1$ + protected static final String SPEC_EXT_MACRO = "${EXT}"; //$NON-NLS-1$ + protected static final String SPEC_FILE_BASE = "spec."; //$NON-NLS-1$ + + private String currentCommandResolved = null; + protected List detectedSettingEntries = null; + + private boolean runOnce = true; + private boolean isConsoleEnabled = false; + protected java.io.File specFile = null; + protected boolean preserveSpecFile = false; + + /** + * TODO + */ + protected abstract String getToolchainId(); + + @Override + public void configureProvider(String id, String name, List languages, List entries, String customParameter) { + super.configureProvider(id, name, languages, entries, customParameter); + + runOnce = true; + } + + public void setRunOnce(boolean once) { + runOnce = once; + } + + public boolean isRunOnce() { + return runOnce; + } + + public void setConsoleEnabled(boolean enable) { + isConsoleEnabled = enable; + } + + public boolean isConsoleEnabled() { + return isConsoleEnabled; + } + + protected String resolveCommand(String languageId) throws CoreException { + String cmd = getCustomParameter(); + + if (cmd!=null && (cmd.contains(COMPILER_MACRO) || cmd.contains(SPEC_FILE_MACRO) || cmd.contains(SPEC_EXT_MACRO))) { + String toolchainId = getToolchainId(); + ITool tool = getTool(toolchainId, languageId); + if (tool==null) { + IStatus status = new Status(IStatus.ERROR, ManagedBuilderCorePlugin.PLUGIN_ID, "Provider "+getId() + +" unable to find the compiler tool for language " + languageId + + "in toolchain " + toolchainId); + throw new CoreException(status); + } + + if (cmd.contains(COMPILER_MACRO)) { + String compiler = getCompilerCommand(tool); + cmd = cmd.replace(COMPILER_MACRO, compiler); + } + if (cmd.contains(SPEC_FILE_MACRO)) { + String specFileName = getSpecFile(languageId, tool); + cmd = cmd.replace(SPEC_FILE_MACRO, specFileName); + } + if (cmd.contains(SPEC_EXT_MACRO)) { + String specFileExt = getSpecExt(languageId, tool); + cmd = cmd.replace(SPEC_EXT_MACRO, specFileExt); + } + } + return cmd; + } + + /** + * TODO + */ + @Override + protected String parseForResourceName(String line) { + // This works as if workspace-wide + return null; + } + + @Override + protected String determineLanguage(String parsedResourceName) { + // language id is supposed to be set by run(), just return it + return currentLanguageId; + } + + @Override + public void startup(ICConfigurationDescription cfgDescription) throws CoreException { + // for workspace provider cfgDescription is used to figure out the current project for build console + currentCfgDescription = cfgDescription; + if (cfgDescription!=null) { + currentProject = cfgDescription.getProjectDescription().getProject(); + } + + detectedSettingEntries = new ArrayList(); + currentCommandResolved = customParameter; + + specFile = null; + + currentCommandResolved = resolveCommand(currentLanguageId); + } + + @Override + public void shutdown() { + if (detectedSettingEntries!=null && detectedSettingEntries.size()>0) { + groupEntries(detectedSettingEntries); + setSettingEntries(currentCfgDescription, currentResource, currentLanguageId, detectedSettingEntries); + + IStatus status = new Status(IStatus.INFO, MakeCorePlugin.PLUGIN_ID, getClass().getSimpleName() + + " collected " + detectedSettingEntries.size() + " entries" + " for language " + currentLanguageId); + ManagedBuilderCorePlugin.log(status); + } + detectedSettingEntries = null; + + if (specFile!=null && !preserveSpecFile) { + specFile.delete(); + specFile = null; + } + + currentCommandResolved = null; + } + + protected void groupEntries(List inputEntries) { + Map> groupedEntries = new HashMap>(); + int kindMax = 0; + for (ICLanguageSettingEntry entry : inputEntries) { + int kind = entry.getKind(); + if (kind>kindMax) { + kindMax = kind; + } + + List entries = groupedEntries.get(kind); + if (entries==null) { + entries = new ArrayList(); + groupedEntries.put(kind, entries); + } + entries.add(entry); + } + + inputEntries.clear(); + + for (int kind=1;kind<=kindMax;kind++) { + List entries = groupedEntries.get(kind); + if (entries!=null) { + inputEntries.addAll(entries); + } + } + } + + public void run(IProject project, String languageId, IPath workingDirectory, String[] env, + IProgressMonitor monitor) throws CoreException, IOException { + if (isRunOnce() && !isEmpty()) { + return; + } + + currentProject = project; + currentLanguageId = languageId; + startup(null); + + run(workingDirectory, env, monitor); + } + + public void run(ICConfigurationDescription cfgDescription, String languageId, IPath workingDirectory, + String[] env, IProgressMonitor monitor) throws CoreException, IOException { + Assert.isNotNull(cfgDescription); + + if (isRunOnce() && !isEmpty()) { + return; + } + + currentLanguageId = languageId; + startup(cfgDescription); + + run(workingDirectory, env, monitor); + } + + + /** + * TODO: test case for this function + */ + private void run(IPath workingDirectory, String[] env, IProgressMonitor monitor) + throws CoreException, IOException { + + IConsole console; + if (isConsoleEnabled) { + console = startProviderConsole(); + } else { + // that looks in extension points registry and won't find the id + console = CCorePlugin.getDefault().getConsole(MakeCorePlugin.PLUGIN_ID + ".console.hidden"); //$NON-NLS-1$ + } + console.start(currentProject); + OutputStream cos = console.getOutputStream(); + + ErrorParserManager epm = null; + if (currentProject!=null) { + epm = new ErrorParserManager(currentProject, new SCMarkerGenerator(), new String[] {GMAKE_ERROR_PARSER_ID}); + epm.setOutputStream(cos); + } + + if (monitor==null) { + monitor = new NullProgressMonitor(); + } + StreamMonitor streamMon = new StreamMonitor(new SubProgressMonitor(monitor, 70), epm, 100); + OutputStream stdout = streamMon; + OutputStream stderr = streamMon; + + String msg = "Running scanner discovery: " + getName(); + monitor.subTask(msg); + printLine(stdout, "**** " + msg + " ****" + NEWLINE); + + ConsoleOutputSniffer sniffer = new ConsoleOutputSniffer(stdout, stderr, new IConsoleParser[] { this }); + OutputStream consoleOut = sniffer.getOutputStream(); + OutputStream consoleErr = sniffer.getErrorStream(); + + boolean isSuccess = false; + try { + isSuccess = runProgram(currentCommandResolved, env, workingDirectory, monitor, consoleOut, consoleErr); + } catch (Exception e) { + ManagedBuilderCorePlugin.log(e); + } + if (!isSuccess) { + try { + consoleOut.close(); + } catch (IOException e) { + ManagedBuilderCorePlugin.log(e); + } + try { + consoleErr.close(); + } catch (IOException e) { + ManagedBuilderCorePlugin.log(e); + } + } + } + + protected boolean runProgram(String command, String[] env, IPath workingDirectory, IProgressMonitor monitor, + OutputStream consoleOut, OutputStream consoleErr) throws CoreException, IOException { + + if (command==null || command.trim().length()==0) { + return false; + } + + String errMsg = null; + ICommandLauncher launcher = new CommandLauncher(); + + launcher.setProject(currentProject); + + // Print the command for visual interaction. + launcher.showCommand(true); + + String[] cmdArray = CommandLineUtil.argumentsToArray(command); + IPath program = new Path(cmdArray[0]); + String[] args = new String[0]; + if (cmdArray.length>1) { + args = new String[cmdArray.length-1]; + System.arraycopy(cmdArray, 1, args, 0, args.length); + } + + Process p = launcher.execute(program, args, env, workingDirectory, monitor); + + if (p != null) { + // Before launching give visual cues via the monitor + monitor.subTask("Invoking command " + command); + if (launcher.waitAndRead(consoleOut, consoleErr, new SubProgressMonitor(monitor, 0)) + != ICommandLauncher.OK) { + errMsg = launcher.getErrorMessage(); + } + } else { + errMsg = launcher.getErrorMessage(); + } + if (errMsg!=null) { + String errorPrefix = MakeMessages.getString("ExternalScannerInfoProvider.Error_Prefix"); //$NON-NLS-1$ + + String msg = MakeMessages.getFormattedString("ExternalScannerInfoProvider.Provider_Error", command); + printLine(consoleErr, errorPrefix + msg + NEWLINE); + + // Launching failed, trying to figure out possible cause + String envPath = getEnvVar(env, PATH_ENV); + if (!program.isAbsolute() && PathUtil.findProgramLocation(program.toString(), envPath) == null) { + printLine(consoleErr, errMsg); + msg = MakeMessages.getFormattedString("ExternalScannerInfoProvider.Working_Directory", workingDirectory); //$NON-NLS-1$ + msg = MakeMessages.getFormattedString("ExternalScannerInfoProvider.Program_Not_In_Path", program); //$NON-NLS-1$ + printLine(consoleErr, errorPrefix + msg + NEWLINE); + printLine(consoleErr, PATH_ENV + "=[" + envPath + "]" + NEWLINE); //$NON-NLS-1$ //$NON-NLS-2$ + } else { + printLine(consoleErr, errorPrefix + errMsg); + msg = MakeMessages.getFormattedString("ExternalScannerInfoProvider.Working_Directory", workingDirectory); //$NON-NLS-1$ + printLine(consoleErr, PATH_ENV + "=[" + envPath + "]" + NEWLINE); //$NON-NLS-1$ //$NON-NLS-2$ + } + return false; + } + + return true; + } + + /** + * TODO + */ + @Override + protected void setSettingEntries(List entries) { + // Builtin specs detectors collect entries not per line but for the whole output + if (entries!=null) + detectedSettingEntries.addAll(entries); + } + + private IConsole startProviderConsole() { + ILanguageDescriptor ld = LanguageManager.getInstance().getLanguageDescriptor(currentLanguageId); + + String consoleId = MakeCorePlugin.PLUGIN_ID + '.' + getId() + '.' + currentLanguageId; + String consoleName = getName() + ", " + ld.getName(); + URL defaultIcon = Platform.getBundle(PLUGIN_CDT_MAKE_UI_ID).getEntry("icons/obj16/inspect_system.gif"); + + IConsole console = CCorePlugin.getDefault().getConsole("org.eclipse.cdt.make.internal.ui.scannerconfig.ScannerDiscoveryConsole", consoleId, consoleName, defaultIcon); + return console; + } + + private String getEnvVar(String[] envStrings, String envVar) { + String envPath = null; + if (envStrings!=null) { + String varPrefix = envVar+'='; + for (String envStr : envStrings) { + if (envStr.startsWith(varPrefix)) { + envPath = envStr.substring(varPrefix.length()); + break; + } + } + } else { + envPath = System.getenv(envVar); + } + return envPath; + } + + private ITool getTool(String toolchainId, String languageId) { + IToolChain toolchain = ManagedBuildManager.getExtensionToolChain(toolchainId); + if (toolchain != null) { + ITool[] tools = toolchain.getTools(); + for (ITool tool : tools) { + IInputType[] inputTypes = tool.getInputTypes(); + for (IInputType inType : inputTypes) { + String lang = inType.getLanguageId(tool); + if (languageId.equals(lang)) + return tool; + } + } + } + ManagedBuilderCorePlugin.error("Unable to find tool in toolchain="+toolchainId+" for language="+languageId); + return null; + } + + private String getCompilerCommand(ITool tool) { + String compiler = tool.getToolCommand(); + if (compiler.length()==0) { + String msg = "Unable to find compiler command in toolchain="+getToolchainId(); + ManagedBuilderCorePlugin.error(msg); + } + return compiler; + } + + private String getSpecFile(String languageId, ITool tool) { + String ext = getSpecExt(languageId, tool); + + String specFileName = SPEC_FILE_BASE + ext; + IPath workingLocation = MakeCorePlugin.getWorkingDirectory(); + IPath fileLocation = workingLocation.append(specFileName); + + specFile = new java.io.File(fileLocation.toOSString()); + // will preserve spec file if it was already there otherwise will delete upon finishing + preserveSpecFile = specFile.exists(); + if (!preserveSpecFile) { + try { + specFile.createNewFile(); + } catch (IOException e) { + ManagedBuilderCorePlugin.log(e); + } + } + + return fileLocation.toString(); + } + + private String getSpecExt(String languageId, ITool tool) { + String ext = ""; + String[] srcFileExtensions = tool.getAllInputExtensions(); + if (srcFileExtensions!=null && srcFileExtensions.length>0) { + ext = srcFileExtensions[0]; + } + if (ext.length()==0) { + ManagedBuilderCorePlugin.error("Unable to find file extension for language "+languageId); + } + return ext; + } + + protected void printLine(OutputStream stream, String msg) throws IOException { + stream.write((msg + NEWLINE).getBytes()); + stream.flush(); + } + + @Override + public Element serialize(Element parentElement) { + Element elementProvider = super.serialize(parentElement); + elementProvider.setAttribute(ATTR_RUN_ONCE, Boolean.toString(runOnce)); + elementProvider.setAttribute(ATTR_CONSOLE, Boolean.toString(isConsoleEnabled)); + return elementProvider; + } + + @Override + public void load(Element providerNode) { + super.load(providerNode); + + String runOnceValue = XmlUtil.determineAttributeValue(providerNode, ATTR_RUN_ONCE); + if (runOnceValue!=null) + runOnce = Boolean.parseBoolean(runOnceValue); + + String consoleValue = XmlUtil.determineAttributeValue(providerNode, ATTR_CONSOLE); + if (consoleValue!=null) + isConsoleEnabled = Boolean.parseBoolean(consoleValue); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + (runOnce ? 1231 : 1237); + result = prime * result + (isConsoleEnabled ? 1231 : 1237); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (!(obj instanceof AbstractBuiltinSpecsDetector)) + return false; + AbstractBuiltinSpecsDetector other = (AbstractBuiltinSpecsDetector) obj; + if (runOnce != other.runOnce) + return false; + if (isConsoleEnabled != other.isConsoleEnabled) + return false; + return true; + } +} diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/GCCBuiltinSpecsDetector.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/GCCBuiltinSpecsDetector.java new file mode 100644 index 00000000000..d5fee24780e --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/GCCBuiltinSpecsDetector.java @@ -0,0 +1,135 @@ +/******************************************************************************* + * Copyright (c) 2009, 2011 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.managedbuilder.internal.scannerconfig; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICSettingEntry; +import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider; +import org.eclipse.core.runtime.CoreException; + +/** + * Class to detect built-in compiler settings. Note that currently this class is hardwired + * to GCC toolchain {@code cdt.managedbuild.toolchain.gnu.base}. + * + */ +public class GCCBuiltinSpecsDetector extends AbstractBuiltinSpecsDetector implements ILanguageSettingsEditableProvider { + // must match the toolchain definition in org.eclipse.cdt.managedbuilder.core.buildDefinitions extension point + private static final String GCC_TOOLCHAIN_ID = "cdt.managedbuild.toolchain.gnu.base"; //$NON-NLS-1$ + + private enum State {NONE, EXPECTING_LOCAL_INCLUDE, EXPECTING_SYSTEM_INCLUDE, EXPECTING_FRAMEWORKS} + State state = State.NONE; + + @SuppressWarnings("nls") + static final AbstractOptionParser[] optionParsers = { + new IncludePathOptionParser("#include \"(\\S.*)\"", "$1", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY | ICSettingEntry.LOCAL), + new IncludePathOptionParser("#include <(\\S.*)>", "$1", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), + new IncludePathOptionParser("#framework <(\\S.*)>", "$1", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY | ICSettingEntry.FRAMEWORKS_MAC), + new MacroOptionParser("#define (\\S*\\(.*?\\)) *(.*)", "$1", "$2", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), + new MacroOptionParser("#define (\\S*) *(.*)", "$1", "$2", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), + }; + + @Override + protected String getToolchainId() { + return GCC_TOOLCHAIN_ID; + } + + @Override + protected AbstractOptionParser[] getOptionParsers() { + return optionParsers; + } + + private List makeList(final String line) { + return new ArrayList() {{ add(line); }}; + } + + @Override + protected List parseForOptions(String line) { + line = line.trim(); + + // contribution of -dD option + if (line.startsWith("#define")) { + return makeList(line); + } + + /** + +Framework search starts here: + /System/Library/Frameworks + /Library/Frameworks +End of framework search list. + + */ + + // contribution of includes + if (line.equals("#include \"...\" search starts here:")) { + state = State.EXPECTING_LOCAL_INCLUDE; + } else if (line.equals("#include <...> search starts here:")) { + state = State.EXPECTING_SYSTEM_INCLUDE; + } else if (line.startsWith("End of search list.")) { + state = State.NONE; + } else if (line.equals("Framework search starts here:")) { + state = State.EXPECTING_FRAMEWORKS; + } else if (line.startsWith("End of framework search list.")) { + state = State.NONE; + } else if (state==State.EXPECTING_LOCAL_INCLUDE) { + // making that up for the parser to figure out + line = "#include \""+line+"\""; + return makeList(line); + } else { + String frameworkIndicator = "(framework directory)"; + if (state==State.EXPECTING_SYSTEM_INCLUDE) { + // making that up for the parser to figure out + if (line.contains(frameworkIndicator)) { + line = "#framework <"+line.replace(frameworkIndicator, "").trim()+">"; + } else { + line = "#include <"+line+">"; + } + return makeList(line); + } else if (state==State.EXPECTING_FRAMEWORKS) { + // making that up for the parser to figure out + line = "#framework <"+line.replace(frameworkIndicator, "").trim()+">"; + return makeList(line); + } + } + + return null; + } + + @Override + public void startup(ICConfigurationDescription cfgDescription) throws CoreException { + super.startup(cfgDescription); + + state = State.NONE; + } + + @Override + public void shutdown() { + state = State.NONE; + + super.shutdown(); + } + + @Override + public GCCBuiltinSpecsDetector cloneShallow() throws CloneNotSupportedException { + return (GCCBuiltinSpecsDetector) super.cloneShallow(); + } + + @Override + public GCCBuiltinSpecsDetector clone() throws CloneNotSupportedException { + return (GCCBuiltinSpecsDetector) super.clone(); + } + + +} diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/MBSLanguageSettingsProvider.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/MBSLanguageSettingsProvider.java new file mode 100644 index 00000000000..ebddb38e568 --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/MBSLanguageSettingsProvider.java @@ -0,0 +1,113 @@ +/******************************************************************************* + * Copyright (c) 2009, 2009 Andrew Gvozdev (Quoin Inc.) 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 (Quoin Inc.) - initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.managedbuilder.internal.scannerconfig; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.cdt.core.AbstractExecutableExtensionBase; +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICFileDescription; +import org.eclipse.cdt.core.settings.model.ICFolderDescription; +import org.eclipse.cdt.core.settings.model.ICLanguageSetting; +import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; +import org.eclipse.cdt.core.settings.model.ICResourceDescription; +import org.eclipse.cdt.core.settings.model.ICSettingBase; +import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.IPath; + +//public class MBSLanguageSettingsProvider extends AbstractExecutableExtensionBase implements ILanguageSettingsEditableProvider { +public class MBSLanguageSettingsProvider extends AbstractExecutableExtensionBase implements ILanguageSettingsProvider { + + public List getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) { + + IPath projectPath = rc.getProjectRelativePath(); + ICResourceDescription rcDescription = cfgDescription.getResourceDescription(projectPath, false); + + List list = new ArrayList(); + for (ICLanguageSetting languageSetting : getLanguageSettings(rcDescription)) { + if (languageSetting!=null) { + String id = languageSetting.getLanguageId(); + if (id!=null && id.equals(languageId)) { + int kindsBits = languageSetting.getSupportedEntryKinds(); + for (int kind=1;kind<=kindsBits;kind<<=1) { + if ((kindsBits & kind) != 0) { + list.addAll(languageSetting.getSettingEntriesList(kind)); + } + } + } else { +// System.err.println("languageSetting id=null: name=" + languageSetting.getName()); + } + } else { + System.err.println("languageSetting=null: rcDescription=" + rcDescription.getName()); + } + } + return list; + } + + private ICLanguageSetting[] getLanguageSettings(ICResourceDescription rcDescription) { + ICLanguageSetting[] array = null; + switch (rcDescription.getType()) { + case ICSettingBase.SETTING_PROJECT: + case ICSettingBase.SETTING_CONFIGURATION: + case ICSettingBase.SETTING_FOLDER: + ICFolderDescription foDes = (ICFolderDescription)rcDescription; + array = foDes.getLanguageSettings(); + break; + case ICSettingBase.SETTING_FILE: + ICFileDescription fiDes = (ICFileDescription)rcDescription; + ICLanguageSetting ls = fiDes.getLanguageSetting(); + if (ls!=null) { + array = new ICLanguageSetting[] { ls }; + } + } + if (array==null) { + array = new ICLanguageSetting[0]; + } + return array; + } + + public void setSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId, + List entries) { + +// lang.setSettingEntries(kind, entries); + IPath projectPath = rc.getProjectRelativePath(); + ICResourceDescription rcDescription = cfgDescription.getResourceDescription(projectPath, false); + + for (ICLanguageSetting languageSetting : getLanguageSettings(rcDescription)) { + if (languageSetting!=null) { + String id = languageSetting.getLanguageId(); + if (id!=null && id.equals(languageId)) { + int kindsBits = languageSetting.getSupportedEntryKinds(); + for (int kind=1;kind<=kindsBits;kind<<=1) { + if ((kindsBits & kind) != 0) { + List list = new ArrayList(entries.size()); + for (ICLanguageSettingEntry entry : entries) { + if (entry.getKind()==kind) { + list.add(entry); + } + } + languageSetting.setSettingEntries(kind, list); + } + } + } else { +// System.err.println("languageSetting id=null: name=" + languageSetting.getName()); + } + } else { + System.err.println("languageSetting=null: rcDescription=" + rcDescription.getName()); + } + } + } + +} diff --git a/build/org.eclipse.cdt.managedbuilder.gnu.ui/plugin.xml b/build/org.eclipse.cdt.managedbuilder.gnu.ui/plugin.xml index f26ee076aae..77ada67aea3 100644 --- a/build/org.eclipse.cdt.managedbuilder.gnu.ui/plugin.xml +++ b/build/org.eclipse.cdt.managedbuilder.gnu.ui/plugin.xml @@ -1665,10 +1665,11 @@ + osList="linux,hpux,aix,qnx" + targetTool="cdt.managedbuild.tool.gnu.c.linker;cdt.managedbuild.tool.gnu.cpp.linker;cdt.managedbuild.tool.gnu.archiver"> @@ -1802,6 +1804,7 @@ configurationEnvironmentSupplier="org.eclipse.cdt.managedbuilder.gnu.mingw.MingwEnvironmentVariableSupplier" id="cdt.managedbuild.toolchain.gnu.mingw.base" isToolChainSupported="org.eclipse.cdt.managedbuilder.gnu.mingw.MingwIsToolChainSupported" + languageSettingsProviders="org.eclipse.cdt.make.core.build.command.parser.gcc;*org.eclipse.cdt.managedbuilder.core.gcc.specs.detector" name="%ToolChainName.MinGW" osList="win32" targetTool="cdt.managedbuild.tool.gnu.cpp.linker.mingw.base;cdt.managedbuild.tool.gnu.c.linker.mingw.base;cdt.managedbuild.tool.gnu.archiver"> @@ -2043,9 +2046,9 @@ + id="cdt.managedbuild.config.gnu.base" + languageSettingsProviders="org.eclipse.cdt.ui.user.LanguageSettingsProvider;org.eclipse.cdt.managedbuilder.core.LanguageSettingsProvider;${Toolchain};-org.eclipse.cdt.make.core.build.command.parser.gcc"> + cleanCommand="rm -rf" + id="cdt.managedbuild.config.gnu.cygwin.base" + languageSettingsProviders="org.eclipse.cdt.ui.user.LanguageSettingsProvider;org.eclipse.cdt.managedbuilder.core.LanguageSettingsProvider;${Toolchain};-org.eclipse.cdt.make.core.build.command.parser.gcc"> + cleanCommand="rm -rf" + id="cdt.managedbuild.config.gnu.mingw.base" + languageSettingsProviders="org.eclipse.cdt.ui.user.LanguageSettingsProvider;org.eclipse.cdt.managedbuilder.core.LanguageSettingsProvider;${Toolchain};-org.eclipse.cdt.make.core.build.command.parser.gcc"> 6OU;p2od-v(ryHCI0eg5_C^Y2eze}DS+``eE{|Nqbb z|Nr>^-yi;y3lx8{FfuUMGw3h?0mx4bY%>qcFYwTj>UV1w@+?_1@3g#9gNBhqgn+X| z04rDPLM7*Y3S1LzU07IPl0A11n=G3mo1k#K#M)^p%BpP4Dr)Q^Y!V_2{Pr@7HPkiO`uQ0o gjx#thaci<^7Tce=e9B3th+W3%^0B=>ZjKDr0Hf`~-v9sr literal 0 HcmV?d00001 diff --git a/build/org.eclipse.cdt.managedbuilder.ui/icons/obj16/search.gif b/build/org.eclipse.cdt.managedbuilder.ui/icons/obj16/search.gif new file mode 100644 index 0000000000000000000000000000000000000000..d540a01f4d9eeb9d2951f30cee165c7370e9fc6a GIT binary patch literal 347 zcmZ?wbhEHb6krfwxXQq=Vd*RNf? z`oQk}`*!YKK6~ljZF_cZ+HvgAv6IJ69zSyY;J$;WPMkV&@Th0*!vFtI{{R2)-9{Q{xYzi!ojzd!Hm)rnuOPWpOf;{Cn#PZn9eTp#{=Q|#Kl_?H9)`m^Y_v_E|osjQ0xhPeU?V7 zFYefq7px@erW32aOhZI~o1e+F);Uj8NSKj>%P7ZHO;TK&kDY#h literal 0 HcmV?d00001 diff --git a/build/org.eclipse.cdt.managedbuilder.ui/plugin.properties b/build/org.eclipse.cdt.managedbuilder.ui/plugin.properties index f511362e8b3..fce07128cfd 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/plugin.properties +++ b/build/org.eclipse.cdt.managedbuilder.ui/plugin.properties @@ -92,6 +92,7 @@ Source.location=Source Location Output.location=Output Location Binary.parsers=Binary Parsers Error.parsers=Error Parsers +Language.settings.providers=Discovery Data.hierarchy=Data Hierarchy Preferred.toolchains=Preferred Toolchains Wizard.defaults=Wizard Defaults diff --git a/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml b/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml index 94449d3aaf7..6db04757aef 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml +++ b/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml @@ -648,5 +648,16 @@ + + + + + + diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/Messages.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/Messages.java index 7d4180d427f..e445ffb8dc3 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/Messages.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/Messages.java @@ -210,6 +210,8 @@ public class Messages extends NLS { public static String PropertyPageDefsTab_8; public static String PropertyPageDefsTab_9; public static String PropertyPageDefsTab_showIncludeFileTab; + public static String PropertyPageDefsTab_showProvidersTab; + public static String RefreshPolicyExceptionDialog_addButtonLabel; public static String RefreshPolicyExceptionDialog_addDialogLabel; public static String RefreshPolicyExceptionDialog_AddExceptionInfoDialog_message; public static String RefreshPolicyExceptionDialog_AddExceptionInfoDialog_title; diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/Messages.properties b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/Messages.properties index 9b176b659e6..5185ed82802 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/Messages.properties +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/Messages.properties @@ -272,6 +272,7 @@ PropertyPageDefsTab_7=Show disc. page names if they are unique. Else show profil PropertyPageDefsTab_8=Always show names + profile IDs PropertyPageDefsTab_9=Always show profile IDs only PropertyPageDefsTab_showIncludeFileTab=Display "Include Files" tab +PropertyPageDefsTab_showProvidersTab=Display new experimental Scanner Discovery Providers tabs ProjectConvert_convertersList=Converters List AbstractPrefPage_0=\ Preference settings will be applied to new projects \n only when there were no toolchains selected. diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/preferences/BuiltinSpecsDetectorOptionPage.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/preferences/BuiltinSpecsDetectorOptionPage.java new file mode 100644 index 00000000000..12885afab20 --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/preferences/BuiltinSpecsDetectorOptionPage.java @@ -0,0 +1,325 @@ +/******************************************************************************* + * Copyright (c) 2009, 2010 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.managedbuilder.ui.preferences; + +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; +import org.eclipse.cdt.internal.ui.language.settings.providers.AbstractLanguageSettingProviderOptionPage; +import org.eclipse.cdt.internal.ui.newui.StatusMessageLine; +import org.eclipse.cdt.managedbuilder.internal.scannerconfig.AbstractBuiltinSpecsDetector; +import org.eclipse.cdt.utils.ui.controls.ControlFactory; +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; + +/** + * Options page for TODO + * + */ +public final class BuiltinSpecsDetectorOptionPage extends AbstractLanguageSettingProviderOptionPage { + private boolean fEditable; + + private Text inputCommand; + + private StatusMessageLine fStatusLine; + private Button runOnceRadioButton; + private Button runEveryBuildRadioButton; + private Button allocateConsoleCheckBox; + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) + */ + @Override + public void createControl(Composite parent) { +// Composite optionsPageComposite = new Composite(composite, SWT.NULL); + fEditable = parent.isEnabled(); + + final Composite composite = new Composite(parent, SWT.NONE); + { + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + layout.marginWidth = 1; + layout.marginHeight = 1; + layout.marginRight = 1; + composite.setLayout(layout); + composite.setLayoutData(new GridData(GridData.FILL_BOTH)); + Dialog.applyDialogFont(composite); + + GridData gd = new GridData(GridData.FILL_HORIZONTAL); + gd.horizontalSpan = 2; + composite.setLayoutData(gd); + } + + + Group groupRun = new Group(composite, SWT.SHADOW_ETCHED_IN); +// groupRun.setText("Language Settings Provider Options"); + + GridLayout gridLayoutRun = new GridLayout(); +// GridLayout gridLayoutRun = new GridLayout(2, true); +// gridLayoutRun.makeColumnsEqualWidth = false; +// gridLayoutRun.marginRight = -10; +// gridLayoutRun.marginLeft = -4; + groupRun.setLayout(gridLayoutRun); +// GridData gdRun = new GridData(GridData.FILL_HORIZONTAL); +// gdRun.horizontalSpan = 2; +// groupRun.setLayoutData(gdRun); + + AbstractBuiltinSpecsDetector provider = getRawProvider(); + { + runOnceRadioButton = new Button(groupRun, SWT.RADIO); + runOnceRadioButton.setText("Run only once"); //$NON-NLS-1$ + // b1.setToolTipText(UIMessages.getString("EnvironmentTab.3")); //$NON-NLS-1$ + GridData gd = new GridData(GridData.FILL_HORIZONTAL); + gd.horizontalSpan = 3; + runOnceRadioButton.setLayoutData(gd); + runOnceRadioButton.setSelection(provider.isRunOnce()); + runOnceRadioButton.setEnabled(fEditable); + runOnceRadioButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent evt) { + boolean runOnceEnabled = runOnceRadioButton.getSelection(); + if (runOnceEnabled) { + AbstractBuiltinSpecsDetector provider = getRawProvider(); + if (runOnceEnabled != provider.isRunOnce()) { + AbstractBuiltinSpecsDetector selectedProvider = getWorkingCopy(providerId); + selectedProvider.setRunOnce(runOnceEnabled); + providerTab.refreshItem(selectedProvider); + } + } + } + + }); + } + { + runEveryBuildRadioButton = new Button(groupRun, SWT.RADIO); + runEveryBuildRadioButton.setText("Activate on every build"); //$NON-NLS-1$ + runEveryBuildRadioButton.setSelection(!provider.isRunOnce()); + runEveryBuildRadioButton.setEnabled(fEditable); + GridData gd = new GridData(GridData.FILL_HORIZONTAL); + gd.horizontalSpan = 3; + runEveryBuildRadioButton.setLayoutData(gd); + runEveryBuildRadioButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent evt) { + boolean runEveryBuildEnabled = runEveryBuildRadioButton.getSelection(); + if (runEveryBuildEnabled) { + AbstractBuiltinSpecsDetector provider = getRawProvider(); + if (runEveryBuildEnabled != !provider.isRunOnce()) { + AbstractBuiltinSpecsDetector selectedProvider = getWorkingCopy(providerId); + selectedProvider.setRunOnce(!runEveryBuildEnabled); + providerTab.refreshItem(selectedProvider); + } + } + } + }); + } + + // Compiler specs command + { + Label label = ControlFactory.createLabel(composite, "Command to get compiler specs:"); + GridData gd = new GridData(); + gd.horizontalSpan = 2; + label.setLayoutData(gd); + label.setEnabled(fEditable); + } + + { + inputCommand = ControlFactory.createTextField(composite, SWT.SINGLE | SWT.BORDER); + String customParameter = provider.getCustomParameter(); + inputCommand.setText(customParameter!=null ? customParameter : ""); + inputCommand.setEnabled(fEditable); + inputCommand.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + String text = inputCommand.getText(); + AbstractBuiltinSpecsDetector provider = getRawProvider(); + if (!text.equals(provider.getCustomParameter())) { + AbstractBuiltinSpecsDetector selectedProvider = getWorkingCopy(providerId); + selectedProvider.setCustomParameter(text); + providerTab.refreshItem(selectedProvider); + } + } + }); + } + + { + Button button = ControlFactory.createPushButton(composite, "Browse..."); + button.setEnabled(fEditable); + button.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent evt) { +// handleAddr2LineButtonSelected(); + //updateLaunchConfigurationDialog(); + } + + }); + + } + +// { +// final Button button = new Button(composite, SWT.PUSH); +// button.setFont(parent.getFont()); +// String text = fProvider.isEmpty() ? "Run Now (TODO)" : "Clear"; +// button.setText(text); +//// button.addSelectionListener(this); +// GridData data = new GridData(); +// data.horizontalSpan = 2; +//// data.horizontalAlignment = GridData.BEGINNING; +//// data.widthHint = 60; +// button.setLayoutData(data); +// // TODO +// button.setEnabled(fEditable && !fProvider.isEmpty()); +// +// button.addSelectionListener(new SelectionAdapter() { +// +// @Override +// public void widgetSelected(SelectionEvent evt) { +// if (fProvider.isEmpty()) { +// // TODO +// } else { +// fProvider.clear(); +// } +// // TODO +// button.setEnabled(fEditable && !fProvider.isEmpty()); +// String text = fProvider.isEmpty() ? "Run Now (TODO)" : "Clear"; +// button.setText(text); +// button.pack(); +// } +// +// }); +// +// } + +// // Compiler specs command +// { +// Label label = ControlFactory.createLabel(composite, "Parsing rules:"); +// GridData gd = new GridData(); +// gd.horizontalSpan = 2; +// label.setLayoutData(gd); +//// Label newLabel = new Label(composite, SWT.NONE); +////// ((GridData) newLabel.getLayoutData()).horizontalSpan = 1; +//// newLabel.setText("Command to get compiler specs:"); +// } + + +// createPatternsTable(group, composite); + + + + + + + + +// Group group = new Group(parent, SWT.SHADOW_ETCHED_IN); +// group.setText(DialogsMessages.RegexErrorParserOptionPage_Title); +// +// GridLayout gridLayout = new GridLayout(2, true); +// gridLayout.makeColumnsEqualWidth = false; +// gridLayout.marginRight = -10; +// gridLayout.marginLeft = -4; +// group.setLayout(gridLayout); +// group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); +// +// Composite composite = new Composite(group, SWT.NONE); +// GridLayout layout = new GridLayout(); +// layout.numColumns = 2; +// layout.marginWidth = 1; +// layout.marginHeight = 1; +// layout.marginRight = 1; +// composite.setLayout(layout); +// composite.setLayoutData(new GridData(GridData.FILL_BOTH)); +// Dialog.applyDialogFont(composite); +// +// if (!fEditable) +// createLinkToPreferences(composite); +// +// createPatternsTable(group, composite); +// +// if (fEditable) { +// createButtons(composite); +// } + + { + allocateConsoleCheckBox = new Button(composite, SWT.CHECK); + allocateConsoleCheckBox.setText("Allocate console in the Console View"); + allocateConsoleCheckBox.setSelection(provider.isConsoleEnabled()); + allocateConsoleCheckBox.setEnabled(fEditable); + allocateConsoleCheckBox.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + boolean enabled = allocateConsoleCheckBox.getSelection(); + AbstractBuiltinSpecsDetector provider = getRawProvider(); + if (enabled != provider.isConsoleEnabled()) { + AbstractBuiltinSpecsDetector selectedProvider = getWorkingCopy(providerId); + selectedProvider.setConsoleEnabled(enabled); + providerTab.refreshItem(selectedProvider); + } + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + widgetSelected(e); + } + + }); + + } + +// // Status line +// if (fEditable) { +// fStatusLine = new StatusMessageLine(composite, SWT.LEFT, 2); +// IStatus status = new Status(IStatus.WARNING, CUIPlugin.PLUGIN_ID, "Note that currently not all options are persisted (FIXME)"); +// fStatusLine.setErrorStatus(status); +// } + + setControl(composite); + } + + private AbstractBuiltinSpecsDetector getRawProvider() { + ILanguageSettingsProvider provider = LanguageSettingsManager.getRawProvider(providerTab.getProvider(providerId)); + Assert.isTrue(provider instanceof AbstractBuiltinSpecsDetector); + return (AbstractBuiltinSpecsDetector) provider; + } + + private AbstractBuiltinSpecsDetector getWorkingCopy(String providerId) { + ILanguageSettingsProvider provider = providerTab.getWorkingCopy(providerId); + Assert.isTrue(provider instanceof AbstractBuiltinSpecsDetector); + return (AbstractBuiltinSpecsDetector) provider; + } + + @Override + public void performApply(IProgressMonitor monitor) throws CoreException { + // handled by LanguageSettingsProviderTab + } + + @Override + public void performDefaults() { + // handled by LanguageSettingsProviderTab + } + +} diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/preferences/PropertyPageDefsTab.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/preferences/PropertyPageDefsTab.java index 458f7e517a1..245dde59395 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/preferences/PropertyPageDefsTab.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/preferences/PropertyPageDefsTab.java @@ -12,9 +12,9 @@ package org.eclipse.cdt.managedbuilder.ui.preferences; import org.eclipse.cdt.core.settings.model.ICResourceDescription; +import org.eclipse.cdt.managedbuilder.internal.ui.Messages; import org.eclipse.cdt.ui.newui.AbstractCPropertyTab; import org.eclipse.cdt.ui.newui.CDTPrefUtil; -import org.eclipse.cdt.managedbuilder.internal.ui.Messages; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.layout.GridData; @@ -38,6 +38,7 @@ public class PropertyPageDefsTab extends AbstractCPropertyTab { private Button show_mng; private Button show_tool; private Button show_exp; + private Button show_providers_tab; // temporary checkbox for scanner discovery Providers tab private Button show_tipbox; private Button b_0; @@ -74,6 +75,11 @@ public class PropertyPageDefsTab extends AbstractCPropertyTab { show_exp.setText(Messages.PropertyPageDefsTab_10); show_exp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + show_providers_tab = new Button(usercomp, SWT.CHECK); + show_providers_tab.setText(Messages.PropertyPageDefsTab_showProvidersTab + ", " //$NON-NLS-1$ + + org.eclipse.cdt.internal.ui.newui.Messages.CDTMainWizardPage_TrySD90); + show_providers_tab.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + show_tipbox = new Button(usercomp, SWT.CHECK); show_tipbox.setText(Messages.PropertyPageDefsTab_16); show_tipbox.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); @@ -117,6 +123,7 @@ public class PropertyPageDefsTab extends AbstractCPropertyTab { show_mng.setSelection(!CDTPrefUtil.getBool(CDTPrefUtil.KEY_NOMNG)); show_tool.setSelection(!CDTPrefUtil.getBool(CDTPrefUtil.KEY_NOTOOLM)); show_exp.setSelection(CDTPrefUtil.getBool(CDTPrefUtil.KEY_EXPORT)); + show_providers_tab.setSelection(!CDTPrefUtil.getBool(CDTPrefUtil.KEY_NO_SHOW_PROVIDERS)); show_tipbox.setSelection(CDTPrefUtil.getBool(CDTPrefUtil.KEY_TIPBOX)); switch (CDTPrefUtil.getInt(CDTPrefUtil.KEY_DISC_NAMES)) { @@ -140,6 +147,7 @@ public class PropertyPageDefsTab extends AbstractCPropertyTab { CDTPrefUtil.setBool(CDTPrefUtil.KEY_NOMNG, !show_mng.getSelection()); CDTPrefUtil.setBool(CDTPrefUtil.KEY_NOTOOLM, !show_tool.getSelection()); CDTPrefUtil.setBool(CDTPrefUtil.KEY_EXPORT, show_exp.getSelection()); + CDTPrefUtil.setBool(CDTPrefUtil.KEY_NO_SHOW_PROVIDERS, !show_providers_tab.getSelection()); CDTPrefUtil.setBool(CDTPrefUtil.KEY_TIPBOX, show_tipbox.getSelection()); int x = 0; if (b_1.getSelection()) x = 1; @@ -160,6 +168,7 @@ public class PropertyPageDefsTab extends AbstractCPropertyTab { show_mng.setSelection(true); show_tool.setSelection(true); show_exp.setSelection(false); + show_providers_tab.setSelection(false); show_tipbox.setSelection(false); b_0.setSelection(true); b_1.setSelection(false); diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/preferences/WizardDefaultsTab.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/preferences/WizardDefaultsTab.java index 636382cc660..03b4f0a8f1f 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/preferences/WizardDefaultsTab.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/preferences/WizardDefaultsTab.java @@ -30,6 +30,7 @@ public class WizardDefaultsTab extends AbstractCPropertyTab { private Button show_sup; private Button show_oth; + private Button checkBoxTryNewSD; @Override public void createControls(Composite parent) { @@ -44,20 +45,27 @@ public class WizardDefaultsTab extends AbstractCPropertyTab { show_oth.setText(Messages.WizardDefaultsTab_1); show_oth.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + checkBoxTryNewSD = new Button(usercomp, SWT.CHECK); + checkBoxTryNewSD.setText(org.eclipse.cdt.internal.ui.newui.Messages.CDTMainWizardPage_TrySD90); + checkBoxTryNewSD.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + show_sup.setSelection(!CDTPrefUtil.getBool(CDTPrefUtil.KEY_NOSUPP)); show_oth.setSelection(CDTPrefUtil.getBool(CDTPrefUtil.KEY_OTHERS)); + checkBoxTryNewSD.setSelection(CDTPrefUtil.getBool(CDTPrefUtil.KEY_NEWSD)); } @Override protected void performOK() { CDTPrefUtil.setBool(CDTPrefUtil.KEY_NOSUPP, !show_sup.getSelection()); CDTPrefUtil.setBool(CDTPrefUtil.KEY_OTHERS, show_oth.getSelection()); + CDTPrefUtil.setBool(CDTPrefUtil.KEY_NEWSD, checkBoxTryNewSD.getSelection()); } @Override protected void performDefaults() { show_sup.setSelection(true); show_oth.setSelection(false); + checkBoxTryNewSD.setSelection(true); } @Override diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/MBSWizardHandler.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/MBSWizardHandler.java index 14fa0ce258b..ef874834d15 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/MBSWizardHandler.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/MBSWizardHandler.java @@ -23,6 +23,9 @@ import java.util.SortedMap; import java.util.TreeMap; import java.util.TreeSet; +import org.eclipse.cdt.build.internal.core.scannerconfig2.CfgScannerConfigProfileManager; +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICProjectDescription; @@ -41,8 +44,8 @@ import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; import org.eclipse.cdt.managedbuilder.internal.core.Configuration; import org.eclipse.cdt.managedbuilder.internal.core.ManagedBuildInfo; import org.eclipse.cdt.managedbuilder.internal.core.ManagedProject; -import org.eclipse.cdt.managedbuilder.ui.properties.ManagedBuilderUIPlugin; import org.eclipse.cdt.managedbuilder.internal.ui.Messages; +import org.eclipse.cdt.managedbuilder.ui.properties.ManagedBuilderUIPlugin; import org.eclipse.cdt.ui.newui.CDTPrefUtil; import org.eclipse.cdt.ui.templateengine.IWizardDataPage; import org.eclipse.cdt.ui.templateengine.Template; @@ -549,6 +552,13 @@ public class MBSWizardHandler extends CWizardHandler { } private void setProjectDescription(IProject project, boolean defaults, boolean onFinish, IProgressMonitor monitor) throws CoreException { + boolean isTryingNewSD = false; + IWizardPage page = getStartingPage(); + if (page instanceof CDTMainWizardPage) { + CDTMainWizardPage mainWizardPage = (CDTMainWizardPage)page; + isTryingNewSD = mainWizardPage.isTryingNewSD(); + } + ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager(); ICProjectDescription des = mngr.createProjectDescription(project, false, !onFinish); ManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project); @@ -594,9 +604,32 @@ public class MBSWizardHandler extends CWizardHandler { cfgDebug = cfgDes; if (cfgFirst == null) // select at least first configuration cfgFirst = cfgDes; + + if (isTryingNewSD) { + CfgScannerConfigProfileManager.disableScannerDiscovery(config); + + List providers = ManagedBuildManager.getLanguageSettingsProviders(config); + cfgDes.setLanguageSettingProviders(providers); + } else { + ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(ManagedBuildManager.MBS_LANGUAGE_SETTINGS_PROVIDER); + List providers = new ArrayList(); + providers.add(provider); + cfgDes.setLanguageSettingProviders(providers); + } + monitor.worked(work); } mngr.setProjectDescription(project, des); + + // FIXME if scanner discovery is empty it is "fixed" deeply inside setProjectDescription(), taking the easy road here for the moment + if (isTryingNewSD) { + des = mngr.getProjectDescription(project); + boolean isChanged = CfgScannerConfigProfileManager.disableScannerDiscovery(des); + + if (isChanged) { + mngr.setProjectDescription(project, des); + } + } } @Override diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/NewMakeProjFromExisting.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/NewMakeProjFromExisting.java index 3e5767ffabb..666a8dce04f 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/NewMakeProjFromExisting.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/NewMakeProjFromExisting.java @@ -11,10 +11,16 @@ package org.eclipse.cdt.managedbuilder.ui.wizards; import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.List; +import org.eclipse.cdt.build.internal.core.scannerconfig2.CfgScannerConfigProfileManager; import org.eclipse.cdt.core.CCProjectNature; import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; 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.settings.model.ICProjectDescriptionManager; import org.eclipse.cdt.core.settings.model.extension.CConfigurationData; @@ -68,6 +74,7 @@ public class NewMakeProjFromExisting extends Wizard implements IImportWizard, IN final String locationStr = page.getLocation(); final boolean isCPP = page.isCPP(); final IToolChain toolChain = page.getToolChain(); + final boolean isTryingNewSD = page.isTryingNewSD(); IRunnableWithProgress op = new WorkspaceModifyOperation() { @Override @@ -109,13 +116,39 @@ public class NewMakeProjFromExisting extends Wizard implements IImportWizard, IN IBuilder builder = config.getEditableBuilder(); builder.setManagedBuildOn(false); CConfigurationData data = config.getConfigurationData(); - projDesc.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID, data); + ICConfigurationDescription cfgDes = projDesc.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID, data); + + if (isTryingNewSD) { + CfgScannerConfigProfileManager.disableScannerDiscovery(config); + + List providers = ManagedBuildManager.getLanguageSettingsProviders(config); + cfgDes.setLanguageSettingProviders(providers); + } else { + ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(ManagedBuildManager.MBS_LANGUAGE_SETTINGS_PROVIDER); + List providers = new ArrayList(); + providers.add(provider); + cfgDes.setLanguageSettingProviders(providers); + } + + monitor.worked(1); pdMgr.setProjectDescription(project, projDesc); + + // FIXME if scanner discovery is empty it is "fixed" deeply inside setProjectDescription(), taking the easy road here for the moment + if (isTryingNewSD) { + ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager(); + ICProjectDescription des = mngr.getProjectDescription(project); + boolean isChanged = CfgScannerConfigProfileManager.disableScannerDiscovery(des); + + if (isChanged) { + mngr.setProjectDescription(project, des); + } + } } catch (Throwable e) { ManagedBuilderUIPlugin.log(e); } + monitor.done(); } }; diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/NewMakeProjFromExistingPage.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/NewMakeProjFromExistingPage.java index 31e61531fff..0b584fe8aa4 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/NewMakeProjFromExistingPage.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/NewMakeProjFromExistingPage.java @@ -19,6 +19,8 @@ import java.util.Map; import org.eclipse.cdt.managedbuilder.core.IToolChain; import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; import org.eclipse.cdt.managedbuilder.internal.ui.Messages; +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.cdt.ui.newui.CDTPrefUtil; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.ResourcesPlugin; @@ -52,6 +54,9 @@ public class NewMakeProjFromExistingPage extends WizardPage { List tcList; Map tcMap = new HashMap(); + private Button checkBoxTryNewSD; + + protected NewMakeProjFromExistingPage() { super(Messages.NewMakeProjFromExistingPage_0); setTitle(Messages.NewMakeProjFromExistingPage_1); @@ -71,6 +76,21 @@ public class NewMakeProjFromExistingPage extends WizardPage { addLanguageSelector(comp); addToolchainSelector(comp); + checkBoxTryNewSD = new Button(comp, SWT.CHECK); + checkBoxTryNewSD.setText(org.eclipse.cdt.internal.ui.newui.Messages.CDTMainWizardPage_TrySD90); + GridData gd = new GridData(GridData.FILL_HORIZONTAL); + gd.horizontalSpan = 2; + checkBoxTryNewSD.setLayoutData(gd); + + + // restore settings from preferences + boolean isTryNewSD = true; + boolean contains = CUIPlugin.getDefault().getPreferenceStore().contains(CDTPrefUtil.KEY_NEWSD); + if (contains) { + isTryNewSD = CDTPrefUtil.getBool(CDTPrefUtil.KEY_NEWSD); + } + checkBoxTryNewSD.setSelection(isTryNewSD); + setControl(comp); } @@ -208,4 +228,7 @@ public class NewMakeProjFromExistingPage extends WizardPage { return selection.length != 0 ? tcMap.get(selection[0]) : null; } + public boolean isTryingNewSD() { + return checkBoxTryNewSD.getSelection(); + } } diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/STDWizardHandler.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/STDWizardHandler.java index b5128f0ef2e..83951ab46c9 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/STDWizardHandler.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/STDWizardHandler.java @@ -11,7 +11,14 @@ *******************************************************************************/ package org.eclipse.cdt.managedbuilder.ui.wizards; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.cdt.build.internal.core.scannerconfig2.CfgScannerConfigProfileManager; +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; 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.settings.model.ICProjectDescriptionManager; import org.eclipse.cdt.core.settings.model.extension.CConfigurationData; @@ -24,10 +31,12 @@ import org.eclipse.cdt.managedbuilder.internal.core.ManagedBuildInfo; import org.eclipse.cdt.managedbuilder.internal.core.ManagedProject; import org.eclipse.cdt.managedbuilder.internal.core.ToolChain; import org.eclipse.cdt.managedbuilder.internal.ui.Messages; +import org.eclipse.cdt.ui.wizards.CDTMainWizardPage; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jface.wizard.IWizard; +import org.eclipse.jface.wizard.IWizardPage; import org.eclipse.swt.widgets.Composite; /** @@ -71,6 +80,14 @@ public class STDWizardHandler extends MBSWizardHandler { private void setProjectDescription(IProject project, boolean defaults, boolean onFinish, IProgressMonitor monitor) throws CoreException { + + boolean isTryingNewSD = false; + IWizardPage page = getStartingPage(); + if (page instanceof CDTMainWizardPage) { + CDTMainWizardPage mainWizardPage = (CDTMainWizardPage)page; + isTryingNewSD = mainWizardPage.isTryingNewSD(); + } + ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager(); ICProjectDescription des = mngr.createProjectDescription(project, false, !onFinish); ManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project); @@ -99,10 +116,33 @@ public class STDWizardHandler extends MBSWizardHandler { } cfg.setArtifactName(mProj.getDefaultArtifactName()); CConfigurationData data = cfg.getConfigurationData(); - des.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID, data); + ICConfigurationDescription cfgDes = des.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID, data); + + if (isTryingNewSD) { + CfgScannerConfigProfileManager.disableScannerDiscovery(cfg); + + List providers = ManagedBuildManager.getLanguageSettingsProviders(cfg); + cfgDes.setLanguageSettingProviders(providers); + } else { + ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(ManagedBuildManager.MBS_LANGUAGE_SETTINGS_PROVIDER); + List providers = new ArrayList(); + providers.add(provider); + cfgDes.setLanguageSettingProviders(providers); + } + monitor.worked(work); } mngr.setProjectDescription(project, des); + + // FIXME if scanner discovery is empty it is "fixed" deeply inside setProjectDescription(), taking the easy road here for the moment + if (isTryingNewSD) { + des = mngr.getProjectDescription(project); + boolean isChanged = CfgScannerConfigProfileManager.disableScannerDiscovery(des); + + if (isChanged) { + mngr.setProjectDescription(project, des); + } + } } public boolean canCreateWithoutToolchain() { return true; } diff --git a/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/tests/filesystem/ram/MemoryEFSExtensionProvider.java b/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/tests/filesystem/ram/MemoryEFSExtensionProvider.java new file mode 100644 index 00000000000..279f507aae8 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/tests/filesystem/ram/MemoryEFSExtensionProvider.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2010, 2011 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.core.internal.tests.filesystem.ram; + +import java.net.URI; + +import org.eclipse.cdt.core.EFSExtensionProvider; + +/** + * Test stub to test EFSExtensionProvider mappings. + * + */ +public class MemoryEFSExtensionProvider extends EFSExtensionProvider { + + public String getMappedPath(URI locationURI) { + + String path = locationURI.getPath(); + if (path.contains("/BeingMappedFrom/Folder")) { + return path.replaceFirst("/BeingMappedFrom/Folder", "/LocallyMappedTo/Folder"); + } + + return super.getMappedPath(locationURI); + } + +} diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/AllLanguageSettingsProvidersTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/AllLanguageSettingsProvidersTests.java new file mode 100644 index 00000000000..fb9b5be8379 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/AllLanguageSettingsProvidersTests.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2010, 2011 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.core.language.settings.providers; + +import junit.framework.Test; +import junit.framework.TestSuite; + + +public class AllLanguageSettingsProvidersTests { + public static void main(String[] args) { + junit.textui.TestRunner.run(suite()); + } + + public static Test suite() { + TestSuite suite = new TestSuite(AllLanguageSettingsProvidersTests.class.getName()); + + suite.addTest(LanguageSettingsExtensionsTests.suite()); + suite.addTest(LanguageSettingsManagerTests.suite()); + suite.addTest(LanguageSettingsSerializableTests.suite()); + suite.addTest(LanguageSettingsPersistenceProjectTests.suite()); + suite.addTest(LanguageSettingsScannerInfoProviderTests.suite()); + return suite; + } +} diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java new file mode 100644 index 00000000000..3a95102a247 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java @@ -0,0 +1,324 @@ +/******************************************************************************* + * Copyright (c) 2009, 2010 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.core.language.settings.providers; + +import java.util.ArrayList; +import java.util.List; + +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.eclipse.cdt.core.settings.model.CIncludeFileEntry; +import org.eclipse.cdt.core.settings.model.CIncludePathEntry; +import org.eclipse.cdt.core.settings.model.CLibraryFileEntry; +import org.eclipse.cdt.core.settings.model.CLibraryPathEntry; +import org.eclipse.cdt.core.settings.model.CMacroEntry; +import org.eclipse.cdt.core.settings.model.CMacroFileEntry; +import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; +import org.eclipse.cdt.core.settings.model.ICSettingEntry; +import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider; +import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsExtensionManager; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.Path; + +/** + * Test cases testing LanguageSettingsProvider functionality + */ +public class LanguageSettingsExtensionsTests extends TestCase { + // These should match corresponding entries defined in plugin.xml + private static final String EXTENSION_BASE_PROVIDER_ID = "org.eclipse.cdt.core.tests.language.settings.base.provider"; + private static final String EXTENSION_BASE_PROVIDER_NAME = "Test Plugin Language Settings Base Provider"; + private static final String EXTENSION_BASE_PROVIDER_LANG_ID = "org.eclipse.cdt.core.tests.language.id"; + private static final String EXTENSION_BASE_PROVIDER_PARAMETER = "custom parameter"; + private static final String EXTENSION_CUSTOM_PROVIDER_ID = "org.eclipse.cdt.core.tests.custom.language.settings.provider"; + private static final String EXTENSION_CUSTOM_PROVIDER_NAME = "Test Plugin Language Settings Provider"; + private static final String EXTENSION_BASE_SUBCLASS_PROVIDER_ID = "org.eclipse.cdt.core.tests.language.settings.base.provider.subclass"; + private static final String EXTENSION_BASE_SUBCLASS_PROVIDER_PARAMETER = "custom parameter subclass"; + private static final String EXTENSION_SERIALIZABLE_PROVIDER_ID = "org.eclipse.cdt.core.tests.custom.serializable.language.settings.provider"; + private static final String EXTENSION_EDITABLE_PROVIDER_ID = "org.eclipse.cdt.core.tests.custom.editable.language.settings.provider"; + + // These are made up + private static final String PROVIDER_0 = "test.provider.0.id"; + private static final String PROVIDER_NAME_0 = "test.provider.0.name"; + private static final String LANG_ID = "test.lang.id"; + private static final IFile FILE_0 = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("/project/path0")); + + /** + * Constructor. + * @param name - name of the test. + */ + public LanguageSettingsExtensionsTests(String name) { + super(name); + + } + + @Override + protected void setUp() throws Exception { + } + + @Override + protected void tearDown() throws Exception { + } + + /** + * @return - new TestSuite. + */ + public static TestSuite suite() { + return new TestSuite(LanguageSettingsExtensionsTests.class); + } + + /** + * main function of the class. + * + * @param args - arguments + */ + public static void main(String[] args) { + junit.textui.TestRunner.run(suite()); + } + + /** + * Check that regular ICLanguageSettingsProvider extension defined in plugin.xml is accessible. + */ + public void testExtension() throws Exception { + { + List providers = LanguageSettingsManager.getWorkspaceProviders(); + List ids = new ArrayList(); + for (ILanguageSettingsProvider provider : providers) { + ids.add(provider.getId()); + } + assertTrue("extension " + EXTENSION_BASE_PROVIDER_ID + " not found", ids.contains(EXTENSION_BASE_PROVIDER_ID)); + } + + { + // test provider not in the list + ILanguageSettingsProvider providerExt = LanguageSettingsManager.getExtensionProviderCopy("missing.povider"); + assertTrue(LanguageSettingsManager.isWorkspaceProvider(providerExt)); + ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(providerExt); + assertNull(rawProvider); + } + + // get test plugin extension provider + ILanguageSettingsProvider providerExt = LanguageSettingsManager.getExtensionProviderCopy(EXTENSION_BASE_PROVIDER_ID); + assertTrue(LanguageSettingsManager.isWorkspaceProvider(providerExt)); + + // get raw extension provider + ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(providerExt); + assertTrue(rawProvider instanceof LanguageSettingsBaseProvider); + LanguageSettingsBaseProvider provider = (LanguageSettingsBaseProvider)rawProvider; + assertEquals(EXTENSION_BASE_PROVIDER_ID, provider.getId()); + assertEquals(EXTENSION_BASE_PROVIDER_NAME, provider.getName()); + assertEquals(EXTENSION_BASE_PROVIDER_PARAMETER, provider.getCustomParameter()); + + // attempt to get entries for wrong language + assertNull(provider.getSettingEntries(null, FILE_0, LANG_ID)); + + // benchmarks matching extension point definition + List entriesExt = new ArrayList(); + entriesExt.add(new CIncludePathEntry("/usr/include/", + ICSettingEntry.BUILTIN + | ICSettingEntry.LOCAL + | ICSettingEntry.RESOLVED + | ICSettingEntry.VALUE_WORKSPACE_PATH + | ICSettingEntry.UNDEFINED + )); + entriesExt.add(new CMacroEntry("TEST_DEFINE", "100", 0)); + entriesExt.add(new CIncludeFileEntry("/include/file.inc", 0)); + entriesExt.add(new CLibraryPathEntry("/usr/lib/", 0)); + entriesExt.add(new CLibraryFileEntry("libdomain.a", 0)); + entriesExt.add(new CMacroFileEntry("/macro/file.mac", 0)); + + // retrieve entries from extension point + List actual = provider.getSettingEntries(null, FILE_0, EXTENSION_BASE_PROVIDER_LANG_ID); + for (int i=0;i actual = provider.getSettingEntries(null, FILE_0, LANG_ID); + for (int i=0;i languages = new ArrayList(2); + languages.add("bogus.language.id"); + languages.add(LANG_ID); + + // add default provider + LanguageSettingsBaseProvider provider = new LanguageSettingsBaseProvider( + PROVIDER_0, PROVIDER_NAME_0, languages, entries); + + { + // attempt to get entries for wrong language + List actual = provider.getSettingEntries(null, FILE_0, "wrong.lang.id"); + assertNull(actual); + } + + { + // retrieve the entries + List actual = provider.getSettingEntries(null, FILE_0, LANG_ID); + assertEquals(entries.get(0), actual.get(0)); + assertNotSame(entries, actual); + // retrieve languages + List actualLanguageIds = provider.getLanguageScope(); + for (String languageId: languages) { + assertTrue(actualLanguageIds.contains(languageId)); + } + assertEquals(languages.size(), actualLanguageIds.size()); + } + } + + /** + * TODO + */ + public void testSerializableProvider() throws Exception { + // get test plugin extension for serializable provider + ILanguageSettingsProvider providerExt = LanguageSettingsManager.getExtensionProviderCopy(EXTENSION_SERIALIZABLE_PROVIDER_ID); + assertTrue(LanguageSettingsManager.isWorkspaceProvider(providerExt)); + + // get raw extension provider + ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(providerExt); + assertTrue(rawProvider instanceof LanguageSettingsSerializable); + LanguageSettingsSerializable provider = (LanguageSettingsSerializable) rawProvider; + + assertEquals(null, provider.getLanguageScope()); + assertEquals("", provider.getCustomParameter()); + + List expected = new ArrayList(); + expected.add(new CMacroEntry("MACRO", "value", 0)); + assertEquals(expected, provider.getSettingEntries(null, null, null)); + } + + /** + * TODO + */ + public void testEditableProvider() throws Exception { + // Non-editable providers cannot be copied so they are singletons + { + // get test plugin extension for serializable provider + ILanguageSettingsProvider providerExt = LanguageSettingsManager.getExtensionProviderCopy(EXTENSION_SERIALIZABLE_PROVIDER_ID); + assertTrue(LanguageSettingsManager.isWorkspaceProvider(providerExt)); + + // get raw extension provider + ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(providerExt); + assertTrue(rawProvider instanceof LanguageSettingsSerializable); + assertTrue(LanguageSettingsExtensionManager.equalsExtensionProvider(rawProvider)); + + // compare with workspace provider + ILanguageSettingsProvider providerWsp = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_SERIALIZABLE_PROVIDER_ID); + ILanguageSettingsProvider providerWspRaw = LanguageSettingsManager.getRawProvider(providerWsp); + assertSame(rawProvider, providerWspRaw); + } + + // Editable providers are retrieved by copy + { + ILanguageSettingsProvider providerExt = LanguageSettingsManager.getExtensionProviderCopy(EXTENSION_EDITABLE_PROVIDER_ID); + assertFalse(LanguageSettingsManager.isWorkspaceProvider(providerExt)); + assertTrue(providerExt instanceof ILanguageSettingsEditableProvider); + assertTrue(LanguageSettingsExtensionManager.equalsExtensionProvider(providerExt)); + + ILanguageSettingsProvider providerExt2 = LanguageSettingsManager.getExtensionProviderCopy(EXTENSION_EDITABLE_PROVIDER_ID); + assertNotSame(providerExt, providerExt2); + assertEquals(providerExt, providerExt2); + + ILanguageSettingsProvider providerWsp = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_EDITABLE_PROVIDER_ID); + ILanguageSettingsProvider providerWspRaw = LanguageSettingsManager.getRawProvider(providerWsp); + assertNotSame(providerExt, providerWspRaw); + assertEquals(providerExt, providerWspRaw); + assertTrue(LanguageSettingsExtensionManager.equalsExtensionProvider(providerWspRaw)); + } + + // Test shallow copy + { + ILanguageSettingsProvider provider = LanguageSettingsManager.getExtensionProviderCopy(EXTENSION_EDITABLE_PROVIDER_ID); + assertNotNull(provider); + assertTrue(provider instanceof ILanguageSettingsEditableProvider); + + ILanguageSettingsProvider providerShallow = LanguageSettingsExtensionManager.getExtensionProviderShallow(EXTENSION_EDITABLE_PROVIDER_ID); + assertNotNull(providerShallow); + assertTrue(providerShallow instanceof ILanguageSettingsEditableProvider); + assertFalse(provider.equals(providerShallow)); + + assertFalse(LanguageSettingsExtensionManager.equalsExtensionProvider(providerShallow)); + assertTrue(LanguageSettingsExtensionManager.equalsExtensionProviderShallow((ILanguageSettingsEditableProvider) providerShallow)); + + } + } + +// /** +// * LanguageSettingsBaseProvider is not allowed to be configured twice. +// */ +// public void testBaseProviderConfigure() throws Exception { +// // create LanguageSettingsBaseProvider +// LanguageSettingsBaseProvider provider = new LanguageSettingsBaseProvider(); +// List entries = new ArrayList(); +// entries.add(new CIncludePathEntry("/usr/include/", 0)); +// // configure it +// provider.configureProvider("id", "name", null, entries, null); +// +// try { +// // attempt to configure it twice should fail +// provider.configureProvider("id", "name", null, entries, null); +// fail("LanguageSettingsBaseProvider is not allowed to be configured twice"); +// } catch (UnsupportedOperationException e) { +// } +// } + +} diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java new file mode 100644 index 00000000000..066ac866a66 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java @@ -0,0 +1,781 @@ +/******************************************************************************* + * Copyright (c) 2009, 2010 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.core.language.settings.providers; + +import java.util.ArrayList; +import java.util.List; + +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.eclipse.cdt.core.AbstractExecutableExtensionBase; +import org.eclipse.cdt.core.model.CoreModel; +import org.eclipse.cdt.core.settings.model.CIncludePathEntry; +import org.eclipse.cdt.core.settings.model.CMacroEntry; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; +import org.eclipse.cdt.core.settings.model.ICProjectDescription; +import org.eclipse.cdt.core.settings.model.ICSettingEntry; +import org.eclipse.cdt.core.testplugin.CModelMock; +import org.eclipse.cdt.core.testplugin.ResourceHelper; +import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsExtensionManager; +import org.eclipse.cdt.internal.core.settings.model.CConfigurationDescription; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.Path; + +/** + * Test cases testing LanguageSettingsProvider functionality + */ +public class LanguageSettingsManagerTests extends TestCase { + // Should match id of extension point defined in plugin.xml + private static final String EXTENSION_BASE_PROVIDER_ID = "org.eclipse.cdt.core.tests.language.settings.base.provider"; + private static final String EXTENSION_EDITABLE_PROVIDER_ID = "org.eclipse.cdt.core.tests.custom.editable.language.settings.provider"; + private static final String EXTENSION_EDITABLE_PROVIDER_NAME = "Test Plugin Editable Language Settings Provider"; + + private static final IFile FILE_0 = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("/project/path0")); + private static final String CFG_ID = "test.configuration.id"; + private static final String LANG_ID = "test.lang.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_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"; + + class MockConfigurationDescription extends CModelMock.DummyCConfigurationDescription { + List providers = new ArrayList(); + public MockConfigurationDescription(String id) { + super(id); + } + + @Override + public void setLanguageSettingProviders(List providers) { + this.providers = new ArrayList(providers); + } + + @Override + public List getLanguageSettingProviders() { + return providers; + } + } + + private class MockProvider extends AbstractExecutableExtensionBase implements ILanguageSettingsProvider { + private List entries; + + public MockProvider(String id, String name, List entries) { + super(id, name); + this.entries = entries; + } + + public List getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) { + return entries; + } + } + + + /** + * Constructor. + * @param name - name of the test. + */ + public LanguageSettingsManagerTests(String name) { + super(name); + + } + + @Override + protected void setUp() throws Exception { + } + + @Override + protected void tearDown() throws Exception { + LanguageSettingsManager.setWorkspaceProviders(null); + ResourceHelper.cleanUp(); + } + + /** + * @return - new TestSuite. + */ + public static TestSuite suite() { + return new TestSuite(LanguageSettingsManagerTests.class); + } + + /** + * main function of the class. + * + * @param args - arguments + */ + public static void main(String[] args) { + junit.textui.TestRunner.run(suite()); + } + + /** + * Test ICConfigurationDescription API (getters and setters). + */ + public void testConfigurationDescription_Providers() throws Exception { + ICConfigurationDescription cfgDescription = new MockConfigurationDescription(CFG_ID); + + // set providers + ILanguageSettingsProvider provider1 = new MockProvider(PROVIDER_1, PROVIDER_NAME_1, null); + ILanguageSettingsProvider provider2 = new MockProvider(PROVIDER_2, PROVIDER_NAME_2, null); + List providers = new ArrayList(); + providers.add(provider1); + providers.add(provider2); + cfgDescription.setLanguageSettingProviders(providers); + + // get providers + List actual = cfgDescription.getLanguageSettingProviders(); + assertEquals(provider1, actual.get(0)); + assertEquals(provider2, actual.get(1)); + assertEquals(providers.size(), actual.size()); + assertNotSame(actual, providers); + } + + /** + * Test to ensure uniqueness of ids for providers kept in configuration description. + */ + public void testConfigurationDescription_ProvidersUniqueId() throws Exception { + // Create model project and accompanied descriptions + String projectName = getName(); + IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); + ICProjectDescription writableProjDescription = CoreModel.getDefault().getProjectDescription(project, true); + + ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + assertTrue(cfgDescription instanceof CConfigurationDescription); + + // attempt to add duplicate providers + MockProvider dupe1 = new MockProvider(PROVIDER_0, PROVIDER_NAME_1, null); + MockProvider dupe2 = new MockProvider(PROVIDER_0, PROVIDER_NAME_2, null); + + List providers = new ArrayList(); + providers.add(dupe1); + providers.add(dupe2); + + try { + cfgDescription.setLanguageSettingProviders(providers); + fail("cfgDescription.setLanguageSettingProviders() should not accept duplicate providers"); + } catch (Exception e) { + // Exception is welcome here + } + } + + /** + * Test various cases of ill-defined providers. + */ + public void testRudeProviders() throws Exception { + ICConfigurationDescription cfgDescription = new MockConfigurationDescription(CFG_ID); + // set impolite provider returning null by getSettingEntries() + ILanguageSettingsProvider providerNull = new MockProvider(PROVIDER_1, PROVIDER_NAME_1, null); + { + List providers = new ArrayList(); + providers.add(providerNull); + cfgDescription.setLanguageSettingProviders(providers); + } + + // use provider returning null, no exception should be recorded + { + List actual = LanguageSettingsManager + .getSettingEntriesUpResourceTree(providerNull, cfgDescription, FILE_0, LANG_ID); + assertNotNull(actual); + assertEquals(0, actual.size()); + } + { + List actual = LanguageSettingsManager + .getSettingEntriesByKind(cfgDescription, FILE_0, LANG_ID, 0); + assertNotNull(actual); + assertEquals(0, actual.size()); + } + + // set impolite provider returning null in getSettingEntries() array + ILanguageSettingsProvider providerNull_2 = new MockProvider(PROVIDER_2, PROVIDER_NAME_2, + new ArrayList() { + { // init via static initializer + add(null); + } + }); + + { + List providers = new ArrayList(); + providers.add(providerNull); + cfgDescription.setLanguageSettingProviders(providers); + } + + // use provider returning null as item in array + { + List actual = LanguageSettingsManager + .getSettingEntriesUpResourceTree(providerNull_2, cfgDescription, FILE_0, LANG_ID); + assertNotNull(actual); + assertEquals(1, actual.size()); + } + { + List actual = LanguageSettingsManager + .getSettingEntriesByKind(cfgDescription, FILE_0, LANG_ID, 0); + assertNotNull(actual); + assertEquals(0, actual.size()); + } + + // use careless provider causing an exception + { + ILanguageSettingsProvider providerNPE = new MockProvider(PROVIDER_1, PROVIDER_NAME_1, null) { + public List getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) { + throw new NullPointerException("Can you handle me?"); + } + }; + try { + List actual = LanguageSettingsManager + .getSettingEntriesUpResourceTree(providerNPE, null, null, LANG_ID); + assertNotNull(actual); + assertEquals(0, actual.size()); + } catch (Throwable e) { + fail("Exceptions are expected to be swallowed (after logging) but got " + e); + } + } + } + + /** + * Test simple use case. + */ + public void testProvider_Basic() throws Exception { + final ICConfigurationDescription modelCfgDescription = new MockConfigurationDescription(CFG_ID); + + final List entries = new ArrayList(); + entries.add(new CIncludePathEntry("path0", 0)); + + List providers = new ArrayList(); + // define provider returning entries when configuration id matches and null otherwise + ILanguageSettingsProvider providerYes = new MockProvider(PROVIDER_0, PROVIDER_NAME_0, null) { + @Override + public List getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) { + if (cfgDescription.getId().equals(modelCfgDescription.getId())) { + return entries; + } + return null; + } + + }; + providers.add(providerYes); + // define provider returning null when configuration id matches and some entries otherwise + ILanguageSettingsProvider providerNo = new MockProvider(PROVIDER_1, PROVIDER_NAME_1, null) { + @Override + public List getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) { + if (cfgDescription.getId().equals(modelCfgDescription.getId())) { + return null; + } + return entries; + } + + }; + providers.add(providerNo); + modelCfgDescription.setLanguageSettingProviders(providers); + + { + // retrieve the entries with provider returning the given list + List actual = LanguageSettingsManager + .getSettingEntriesUpResourceTree(providerYes, modelCfgDescription, FILE_0, LANG_ID); + assertEquals(entries.get(0), actual.get(0)); + assertEquals(entries.size(), actual.size()); + } + + { + // retrieve the entries with provider returning empty list + List actual = LanguageSettingsManager + .getSettingEntriesUpResourceTree(providerNo, modelCfgDescription, FILE_0, LANG_ID); + assertEquals(0, actual.size()); + } + } + + /** + * Test regular functionality with a few providers. + */ + public void testProvider_Regular() throws Exception { + ICConfigurationDescription cfgDescription = new MockConfigurationDescription(CFG_ID); + + // create couple of providers + List entries1 = new ArrayList(); + entries1.add(new CIncludePathEntry("value1", 1)); + entries1.add(new CIncludePathEntry("value2", 2)); + + List entries2 = new ArrayList(); + entries2.add(new CIncludePathEntry("value1", 1)); + entries2.add(new CIncludePathEntry("value2", 2)); + entries2.add(new CIncludePathEntry("value3", 2)); + + ILanguageSettingsProvider provider1 = new MockProvider(PROVIDER_1, PROVIDER_NAME_1, entries1); + ILanguageSettingsProvider provider2 = new MockProvider(PROVIDER_2, PROVIDER_NAME_2, entries2); + List providers = new ArrayList(); + providers.add(provider1); + providers.add(provider2); + cfgDescription.setLanguageSettingProviders(providers); + + { + // retrieve the entries for provider-1 + List actual = LanguageSettingsManager + .getSettingEntriesUpResourceTree(provider1, cfgDescription, FILE_0, LANG_ID); + assertNotSame(entries1, actual); + + ICLanguageSettingEntry[] entriesArray = entries1.toArray(new ICLanguageSettingEntry[0]); + ICLanguageSettingEntry[] actualArray = actual.toArray(new ICLanguageSettingEntry[0]); + for (int i=0;i entries = new ArrayList(); + entries.add(new CIncludePathEntry("path0", 0)); + List providers = new ArrayList(); + ILanguageSettingsProvider provider = new MockProvider(PROVIDER_0, PROVIDER_NAME_0, null) { + @Override + public List getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) { + if (rc.equals(parentFolder)) { + return entries; + } + if (rc.equals(emptySettingsPath)) { + return new ArrayList(0); + } + return null; + } + + }; + providers.add(provider); + cfgDescription.setLanguageSettingProviders(providers); + + { + // retrieve entries for a derived resource (in a subfolder) + IFile derived = ResourceHelper.createFile(project, "/ParentFolder/Subfolder/resource"); + List actual = LanguageSettingsManager + .getSettingEntriesUpResourceTree(provider, cfgDescription, derived, LANG_ID); + // taken from parent folder + assertEquals(entries.get(0),actual.get(0)); + assertEquals(entries.size(), actual.size()); + } + + { + // retrieve entries for not related resource + IFile notRelated = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("/AnotherFolder/Subfolder/resource")); + List actual = LanguageSettingsManager + .getSettingEntriesUpResourceTree(provider, cfgDescription, notRelated, LANG_ID); + assertEquals(0, actual.size()); + } + + { + // test distinction between no settings and empty settings + List actual = LanguageSettingsManager + .getSettingEntriesUpResourceTree(provider, cfgDescription, emptySettingsPath, LANG_ID); + // NOT taken from parent folder + assertEquals(0, actual.size()); + } + } + + /** + */ + public void testProvider_DefaultEntries() throws Exception { + // Create model project and accompanied descriptions + String projectName = getName(); + IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); + ICProjectDescription prjDescription = CoreModel.getDefault().getProjectDescription(project); + ICConfigurationDescription[] cfgDescriptions = prjDescription.getConfigurations(); + + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + assertTrue(cfgDescription instanceof CConfigurationDescription); + + final IFolder parentFolder = ResourceHelper.createFolder(project, "/ParentFolder/"); + assertNotNull(parentFolder); + final IFile emptySettingsPath = ResourceHelper.createFile(project, "/ParentFolder/Subfolder/empty"); + assertNotNull(emptySettingsPath); + + // store the entries as default entries + final List entries = new ArrayList(); + entries.add(new CIncludePathEntry("path0", 0)); + List providers = new ArrayList(); + ILanguageSettingsProvider provider = new MockProvider(PROVIDER_0, PROVIDER_NAME_0, null) { + @Override + public List getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) { + if (cfgDescription==null && rc==null) { + return entries; + } + return null; + } + + }; + providers.add(provider); + cfgDescription.setLanguageSettingProviders(providers); + + { + // retrieve entries for a resource + IFile derived = ResourceHelper.createFile(project, "/ParentFolder/Subfolder/resource"); + List actual = LanguageSettingsManager + .getSettingEntriesUpResourceTree(provider, cfgDescription, derived, LANG_ID); + // default entries given + assertEquals(entries.get(0),actual.get(0)); + assertEquals(entries.size(), actual.size()); + } + } + + /** + * Test ability to get entries by kind. + */ + public void testEntriesByKind_Regular() throws Exception { + ICConfigurationDescription cfgDescription = new MockConfigurationDescription(CFG_ID); + + // contribute the entries + List entries = new ArrayList(); + entries.add(new CIncludePathEntry("path0", 0)); + entries.add(new CMacroEntry("MACRO0", "value0",0)); + entries.add(new CIncludePathEntry("path1", 0)); + entries.add(new CMacroEntry("MACRO1", "value1",0)); + entries.add(new CIncludePathEntry("path2", 0)); + + ILanguageSettingsProvider provider0 = new MockProvider(PROVIDER_0, PROVIDER_NAME_0, entries); + List providers = new ArrayList(); + providers.add(provider0); + cfgDescription.setLanguageSettingProviders(providers); + + // retrieve entries by kind + List includes = LanguageSettingsManager + .getSettingEntriesByKind(cfgDescription, FILE_0, LANG_ID, ICSettingEntry.INCLUDE_PATH); + assertEquals(new CIncludePathEntry("path0", 0),includes.get(0)); + assertEquals(new CIncludePathEntry("path1", 0),includes.get(1)); + assertEquals(new CIncludePathEntry("path2", 0),includes.get(2)); + assertEquals(3, includes.size()); + + List macros = LanguageSettingsManager + .getSettingEntriesByKind(cfgDescription, FILE_0, LANG_ID, ICSettingEntry.MACRO); + assertEquals(new CMacroEntry("MACRO0", "value0",0), macros.get(0)); + assertEquals(new CMacroEntry("MACRO1", "value1",0), macros.get(1)); + assertEquals(2, macros.size()); + } + + /** + * Test how conflicting entries are resolved. + */ + public void testEntriesByKind_ConflictingEntries() throws Exception { + ICConfigurationDescription cfgDescription = new MockConfigurationDescription(CFG_ID); + + // contribute the entries + List entries = new ArrayList(); + entries.add(new CIncludePathEntry("path", ICSettingEntry.BUILTIN)); + entries.add(new CIncludePathEntry("path", ICSettingEntry.UNDEFINED)); + entries.add(new CIncludePathEntry("path", 0)); + + ILanguageSettingsProvider provider0 = new MockProvider(PROVIDER_0, PROVIDER_NAME_0, entries); + List providers = new ArrayList(); + providers.add(provider0); + cfgDescription.setLanguageSettingProviders(providers); + + // retrieve entries by kind, only first entry should be returned + List includes = LanguageSettingsManager + .getSettingEntriesByKind(cfgDescription, FILE_0, LANG_ID, ICSettingEntry.INCLUDE_PATH); + assertEquals(1, includes.size()); + assertEquals(entries.get(0),includes.get(0)); + } + + /** + * Check handling of {@link ICSettingEntry#UNDEFINED} flag. + */ + public void testEntriesByKind_Undefined() throws Exception { + ICConfigurationDescription cfgDescription = new MockConfigurationDescription(CFG_ID); + + // contribute the entries + List entries = new ArrayList(); + entries.add(new CIncludePathEntry("path", ICSettingEntry.UNDEFINED)); + entries.add(new CIncludePathEntry("path", 0)); + + ILanguageSettingsProvider provider0 = new MockProvider(PROVIDER_0, PROVIDER_NAME_0, entries); + List providers = new ArrayList(); + providers.add(provider0); + cfgDescription.setLanguageSettingProviders(providers); + + // retrieve entries by kind, no entries should be returned + List includes = LanguageSettingsManager + .getSettingEntriesByKind(cfgDescription, FILE_0, LANG_ID, ICSettingEntry.INCLUDE_PATH); + assertEquals(0, includes.size()); + } + + /** + * Check handling of local vs. system entries, see {@link ICSettingEntry#LOCAL} flag. + */ + public void testEntriesByKind_LocalAndSystem() throws Exception { + ICConfigurationDescription cfgDescription = new MockConfigurationDescription(CFG_ID); + + // contribute the entries + List entries = new ArrayList(); + CIncludePathEntry localIncludeEntry = new CIncludePathEntry("path-local", ICSettingEntry.LOCAL); + CIncludePathEntry systemIncludeEntry = new CIncludePathEntry("path-system", 0); + entries.add(localIncludeEntry); + entries.add(systemIncludeEntry); + + ILanguageSettingsProvider provider0 = new MockProvider(PROVIDER_0, PROVIDER_NAME_0, entries); + List providers = new ArrayList(); + providers.add(provider0); + cfgDescription.setLanguageSettingProviders(providers); + + { + // retrieve local entries + List includes = LanguageSettingsExtensionManager + .getLocalSettingEntriesByKind(cfgDescription, FILE_0, LANG_ID, ICSettingEntry.INCLUDE_PATH); + assertEquals(localIncludeEntry, includes.get(0)); + assertEquals(1, includes.size()); + } + + { + // retrieve system entries + List includes = LanguageSettingsExtensionManager + .getSystemSettingEntriesByKind(cfgDescription, FILE_0, LANG_ID, ICSettingEntry.INCLUDE_PATH); + assertEquals(systemIncludeEntry, includes.get(0)); + assertEquals(1, includes.size()); + } + + { + // retrieve both local and system + List includes = LanguageSettingsExtensionManager + .getSettingEntriesByKind(cfgDescription, FILE_0, LANG_ID, ICSettingEntry.INCLUDE_PATH); + assertEquals(entries.get(0), includes.get(0)); + assertEquals(entries.get(1), includes.get(1)); + assertEquals(2, includes.size()); + } + } + + /** + * Test conflicting entries contributed by different providers. + */ + public void testEntriesByKind_ConflictingProviders() throws Exception { + ICConfigurationDescription cfgDescription = new MockConfigurationDescription(CFG_ID); + + // contribute the entries + List providers = new ArrayList(); + + // contribute the higher ranked entries + List entriesHigh = new ArrayList(); + entriesHigh.add(new CIncludePathEntry("path0", ICSettingEntry.RESOLVED)); + entriesHigh.add(new CIncludePathEntry("path1", 0)); + entriesHigh.add(new CIncludePathEntry("path2", ICSettingEntry.UNDEFINED)); + ILanguageSettingsProvider highRankProvider = new MockProvider(PROVIDER_2, PROVIDER_NAME_2, entriesHigh); + providers.add(highRankProvider); + + // contribute the lower ranked entries + List entriesLow = new ArrayList(); + entriesLow.add(new CIncludePathEntry("path0", ICSettingEntry.BUILTIN)); + entriesLow.add(new CIncludePathEntry("path1", ICSettingEntry.UNDEFINED)); + entriesLow.add(new CIncludePathEntry("path2", 0)); + entriesLow.add(new CIncludePathEntry("path3", 0)); + ILanguageSettingsProvider lowRankProvider = new MockProvider(PROVIDER_1, PROVIDER_NAME_1, entriesLow); + providers.add(lowRankProvider); + + cfgDescription.setLanguageSettingProviders(providers); + + // retrieve entries by kind + List includes = LanguageSettingsManager + .getSettingEntriesByKind(cfgDescription, FILE_0, LANG_ID, ICSettingEntry.INCLUDE_PATH); + // path0 is taken from higher priority provider + assertEquals(entriesHigh.get(0),includes.get(0)); + // path1 disablement by lower priority provider is ignored + assertEquals(entriesHigh.get(1),includes.get(1)); + // path2 is removed because of DISABLED flag of high priority provider + // path3 gets there from low priority provider + assertEquals(entriesLow.get(3),includes.get(2)); + 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 writableProjDescription = CoreModel.getDefault().getProjectDescription(project, true); + + ICConfigurationDescription[] cfgDescriptions = writableProjDescription.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 providers = cfgDescription.getLanguageSettingProviders(); + assertEquals(0, providers.size()); + } + { + // set test provider + List providers = new ArrayList(); + providers.add(workspaceProvider); + cfgDescription.setLanguageSettingProviders(providers); + } + { + // check that test provider got there + List providers = cfgDescription.getLanguageSettingProviders(); + assertEquals(workspaceProvider, providers.get(0)); + } + + { + // serialize + CoreModel.getDefault().setProjectDescription(project, writableProjDescription); + // close and reopen the project + project.close(null); + project.open(null); + } + + { + // check that test provider got loaded + ICProjectDescription prjDescription = CoreModel.getDefault().getProjectDescription(project); + ICConfigurationDescription[] loadedCfgDescriptions = prjDescription.getConfigurations(); + ICConfigurationDescription loadedCfgDescription = loadedCfgDescriptions[0]; + assertTrue(cfgDescription instanceof CConfigurationDescription); + + List loadedProviders = loadedCfgDescription.getLanguageSettingProviders(); + assertTrue(LanguageSettingsManager.isWorkspaceProvider(loadedProviders.get(0))); + } + + } + + /** + * Test a workspace provider basics. + */ + public void testWorkspaceProvider_Basic() throws Exception { + // get workspace provider + ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_EDITABLE_PROVIDER_ID); + assertEquals(EXTENSION_EDITABLE_PROVIDER_ID, provider.getId()); + assertEquals(EXTENSION_EDITABLE_PROVIDER_NAME, provider.getName()); + + // get raw provider + ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); + assertEquals(EXTENSION_EDITABLE_PROVIDER_ID, rawProvider.getId()); + assertEquals(EXTENSION_EDITABLE_PROVIDER_NAME, rawProvider.getName()); + assertTrue(rawProvider instanceof LanguageSettingsSerializable); + // assert they are not the same object + assertNotSame(provider, rawProvider); + + { + // make sure entries are the same + List entries = provider.getSettingEntries(null, null, null); + assertEquals(1, entries.size()); // defined in the extension + List rawEntries = rawProvider.getSettingEntries(null, null, null); + assertEquals(entries, rawEntries); + } + + { + // set new entries to the raw provider + List newEntries = new ArrayList(); + newEntries.add(new CIncludePathEntry("path0", 0)); + newEntries.add(new CIncludePathEntry("path1", 0)); + ((LanguageSettingsSerializable)rawProvider).setSettingEntries(null, null, null, newEntries); + + // check that the workspace provider gets them too + List newRawEntries = rawProvider.getSettingEntries(null, null, null); + assertEquals(newEntries, newRawEntries); + assertEquals(2, newEntries.size()); + } + } + + /** + * Test workspace providers equality. + */ + public void testWorkspaceProvider_Equals() throws Exception { + ILanguageSettingsProvider providerA = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_EDITABLE_PROVIDER_ID); + ILanguageSettingsProvider providerB = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_EDITABLE_PROVIDER_ID); + assertEquals(providerA, providerB); + } + + /** + * Test ability to replace underlying raw provider. + */ + public void testWorkspaceProvider_ReplaceRawProvider() throws Exception { + // get sample workspace provider + ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_EDITABLE_PROVIDER_ID); + { + // check on its entries + List entries = provider.getSettingEntries(null, null, null); + assertEquals(1, entries.size()); // defined in the extension + } + + // define new entries for the raw provider + List newEntries = new ArrayList(); + newEntries.add(new CIncludePathEntry("path0", 0)); + newEntries.add(new CIncludePathEntry("path1", 0)); + newEntries.add(new CIncludePathEntry("path2", 0)); + + { + // replace raw provider + List providers = new ArrayList(); + LanguageSettingsSerializable newRawProvider = new LanguageSettingsSerializable(EXTENSION_EDITABLE_PROVIDER_ID, PROVIDER_NAME_0); + newRawProvider.setSettingEntries(null, null, null, newEntries); + providers.add(newRawProvider); + LanguageSettingsManager.setWorkspaceProviders(providers); + } + + { + // check that provider provides the new entries + List entries = provider.getSettingEntries(null, null, null); + assertEquals(newEntries.size(), entries.size()); + assertEquals(newEntries, entries); + } + } + + /** + * Test ability to be called with workspace provider as well (NOOP). + */ + public void testWorkspaceProvider_ReplaceWithWorkspaceProvider() throws Exception { + // get sample workspace provider + ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_EDITABLE_PROVIDER_ID); + ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); + assertNotSame(provider, rawProvider); + + // attempt to "replace" with workspace provider (which is a wrapper around raw provider), should be NOOP + List providers = new ArrayList(); + providers.add(provider); + LanguageSettingsManager.setWorkspaceProviders(providers); + ILanguageSettingsProvider newRawProvider = LanguageSettingsManager.getRawProvider(provider); + assertSame(rawProvider, newRawProvider); + + // check for no side effect + assertSame(provider, providers.get(0)); + } +} diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java new file mode 100644 index 00000000000..ef7a1544b84 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java @@ -0,0 +1,839 @@ +/******************************************************************************* + * Copyright (c) 2009 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.core.language.settings.providers; + +import java.util.ArrayList; +import java.util.List; + +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.eclipse.cdt.core.model.CoreModel; +import org.eclipse.cdt.core.settings.model.CIncludePathEntry; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; +import org.eclipse.cdt.core.settings.model.ICProjectDescription; +import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager; +import org.eclipse.cdt.core.testplugin.CModelMock; +import org.eclipse.cdt.core.testplugin.ResourceHelper; +import org.eclipse.cdt.internal.core.XmlUtil; +import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer; +import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +/** + * Test cases testing LanguageSettingsProvider functionality + */ +public class LanguageSettingsPersistenceProjectTests extends TestCase { + // Should match id of extension point defined in plugin.xml + private static final String EXTENSION_PROVIDER_ID = "org.eclipse.cdt.core.tests.language.settings.base.provider.subclass"; + private static final String EXTENSION_PROVIDER_NAME = "Test Plugin Base Provider Subclass"; + private static final String EXTENSION_SERIALIZABLE_PROVIDER_ID = "org.eclipse.cdt.core.tests.custom.serializable.language.settings.provider"; + + private static final String CFG_ID = "test.configuration.id.0"; + private static final String CFG_ID_2 = "test.configuration.id.2"; + private static final String PROVIDER_0 = "test.provider.0.id"; + private static final String PROVIDER_2 = "test.provider.2.id"; + private static final String PROVIDER_NAME_0 = "test.provider.0.name"; + private static final String PROVIDER_NAME_2 = "test.provider.2.name"; + private static final String PROVIDER_ID_WSP = "test.provider.workspace.id"; + private static final String PROVIDER_NAME_WSP = "test.provider.workspace.name"; + private static final String CUSTOM_PARAMETER = "custom parameter"; + private static final String ELEM_TEST = "test"; + + private static CoreModel coreModel = CoreModel.getDefault(); + + class MockConfigurationDescription extends CModelMock.DummyCConfigurationDescription { + List providers; + public MockConfigurationDescription(String id) { + super(id); + } + + @Override + public void setLanguageSettingProviders(List providers) { + this.providers = new ArrayList(providers); + } + + @Override + public List getLanguageSettingProviders() { + return providers; + } + } + class MockProjectDescription extends CModelMock.DummyCProjectDescription { + ICConfigurationDescription[] cfgDescriptions; + + public MockProjectDescription(ICConfigurationDescription[] cfgDescriptions) { + this.cfgDescriptions = cfgDescriptions; + } + + public MockProjectDescription(ICConfigurationDescription cfgDescription) { + this.cfgDescriptions = new ICConfigurationDescription[] { cfgDescription }; + } + + @Override + public ICConfigurationDescription[] getConfigurations() { + return cfgDescriptions; + + } + + @Override + public ICConfigurationDescription getConfigurationById(String id) { + for (ICConfigurationDescription cfgDescription : cfgDescriptions) { + if (cfgDescription.getId().equals(id)) + return cfgDescription; + } + return null; + } + } + + private class MockProvider extends LanguageSettingsSerializable { + public MockProvider(String id, String name) { + super(id, name); + } + } + + + /** + * Constructor. + * @param name - name of the test. + */ + public LanguageSettingsPersistenceProjectTests(String name) { + super(name); + + } + + @Override + protected void setUp() throws Exception { + } + + @Override + protected void tearDown() throws Exception { + LanguageSettingsManager.setWorkspaceProviders(null); + ResourceHelper.cleanUp(); + } + + /** + * @return - new TestSuite. + */ + public static TestSuite suite() { + return new TestSuite(LanguageSettingsPersistenceProjectTests.class); + } + + /** + * main function of the class. + * + * @param args - arguments + */ + public static void main(String[] args) { + junit.textui.TestRunner.run(suite()); + } + + private ICConfigurationDescription[] getConfigurationDescriptions(IProject project) { + ICProjectDescriptionManager mngr = coreModel.getProjectDescriptionManager(); + // project description + ICProjectDescription projectDescription = mngr.getProjectDescription(project); + assertNotNull(projectDescription); + assertEquals(1, projectDescription.getConfigurations().length); + // configuration description + ICConfigurationDescription[] cfgDescriptions = projectDescription.getConfigurations(); + assertNotNull(cfgDescriptions); + return cfgDescriptions; + } + + private ICConfigurationDescription getFirstConfigurationDescription(IProject project) { + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); + + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + assertNotNull(cfgDescription); + + return cfgDescription; + } + + /** + */ + public void testWorkspacePersistence_ModifiedExtensionProvider() throws Exception { + List entries = new ArrayList(); + entries.add(new CIncludePathEntry("path0", 0)); + + { + // get the raw extension provider + ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_SERIALIZABLE_PROVIDER_ID); + LanguageSettingsSerializable extProvider = (LanguageSettingsSerializable) LanguageSettingsManager.getRawProvider(provider); + assertNotNull(extProvider); + assertEquals(EXTENSION_SERIALIZABLE_PROVIDER_ID, extProvider.getId()); + + // add entries + extProvider.setSettingEntries(null, null, null, entries); + List actual = extProvider.getSettingEntries(null, null, null); + assertEquals(entries.get(0), actual.get(0)); + assertEquals(entries.size(), actual.size()); + + // serialize language settings of workspace providers + LanguageSettingsProvidersSerializer.serializeLanguageSettingsWorkspace(); + + // clear the provider + extProvider.setSettingEntries(null, null, null, null); + } + + { + // doublecheck it's clean + ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_SERIALIZABLE_PROVIDER_ID); + List actual = provider.getSettingEntries(null, null, null); + assertNull(actual); + } + { + // re-load and check language settings of the provider + LanguageSettingsProvidersSerializer.loadLanguageSettingsWorkspace(); + + ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_SERIALIZABLE_PROVIDER_ID); + assertEquals(EXTENSION_SERIALIZABLE_PROVIDER_ID, provider.getId()); + List actual = provider.getSettingEntries(null, null, null); + assertEquals(entries.get(0), actual.get(0)); + assertEquals(entries.size(), actual.size()); + } + } + + /** + */ + public void testWorkspacePersistence_GlobalProvider() throws Exception { + { + // get the raw extension provider + ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_SERIALIZABLE_PROVIDER_ID); + LanguageSettingsSerializable rawProvider = (LanguageSettingsSerializable) LanguageSettingsManager.getRawProvider(provider); + assertNotNull(rawProvider); + assertEquals(EXTENSION_SERIALIZABLE_PROVIDER_ID, rawProvider.getId()); + + // customize provider + rawProvider.setCustomParameter(CUSTOM_PARAMETER); + assertEquals(CUSTOM_PARAMETER, rawProvider.getCustomParameter()); + } + { + // save workspace provider (as opposed to raw provider) + List providers = new ArrayList(); + ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_SERIALIZABLE_PROVIDER_ID); + providers.add(provider); + LanguageSettingsManager.setWorkspaceProviders(providers); + } + { + // check that it has not cleared + ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_SERIALIZABLE_PROVIDER_ID); + LanguageSettingsSerializable rawProvider = (LanguageSettingsSerializable) LanguageSettingsManager.getRawProvider(provider); + assertEquals(CUSTOM_PARAMETER, rawProvider.getCustomParameter()); + } + } + + /** + */ + public void testWorkspacePersistence_ShadowedExtensionProvider() throws Exception { + { + // get the raw extension provider + ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_PROVIDER_ID); + ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); + // confirm its type and name + assertTrue(rawProvider instanceof LanguageSettingsBaseProvider); + assertEquals(EXTENSION_PROVIDER_ID, rawProvider.getId()); + assertEquals(EXTENSION_PROVIDER_NAME, rawProvider.getName()); + } + { + // replace extension provider + ILanguageSettingsProvider provider = new MockLanguageSettingsSerializableProvider(EXTENSION_PROVIDER_ID, PROVIDER_NAME_0); + List providers = new ArrayList(); + providers.add(provider); + // note that this will also serialize workspace providers + LanguageSettingsManager.setWorkspaceProviders(providers); + } + { + // doublecheck it's in the list + ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_PROVIDER_ID); + ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); + assertTrue(rawProvider instanceof MockLanguageSettingsSerializableProvider); + assertEquals(EXTENSION_PROVIDER_ID, rawProvider.getId()); + assertEquals(PROVIDER_NAME_0, rawProvider.getName()); + } + + { + // re-load to check serialization + LanguageSettingsProvidersSerializer.loadLanguageSettingsWorkspace(); + + ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_PROVIDER_ID); + ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); + assertTrue(rawProvider instanceof MockLanguageSettingsSerializableProvider); + assertEquals(EXTENSION_PROVIDER_ID, rawProvider.getId()); + assertEquals(PROVIDER_NAME_0, rawProvider.getName()); + } + + { + // reset workspace providers, that will also serialize + LanguageSettingsManager.setWorkspaceProviders(null); + } + { + // doublecheck original one is in the list + ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_PROVIDER_ID); + ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); + assertTrue(rawProvider instanceof LanguageSettingsBaseProvider); + assertEquals(EXTENSION_PROVIDER_ID, rawProvider.getId()); + assertEquals(EXTENSION_PROVIDER_NAME, rawProvider.getName()); + } + { + // re-load to check serialization + LanguageSettingsProvidersSerializer.loadLanguageSettingsWorkspace(); + + ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_PROVIDER_ID); + ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); + assertTrue(rawProvider instanceof LanguageSettingsBaseProvider); + assertEquals(EXTENSION_PROVIDER_ID, rawProvider.getId()); + assertEquals(EXTENSION_PROVIDER_NAME, rawProvider.getName()); + } + } + + /** + */ + public void testProjectPersistence_SerializableProviderDOM() throws Exception { + Element rootElement = null; + + List entries = new ArrayList(); + entries.add(new CIncludePathEntry("path0", 0)); + + { + // create a provider + MockProjectDescription mockPrjDescription = new MockProjectDescription(new MockConfigurationDescription(CFG_ID)); + + ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations(); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + assertNotNull(cfgDescription); + + LanguageSettingsSerializable serializableProvider = new LanguageSettingsSerializable(PROVIDER_0, PROVIDER_NAME_0); + serializableProvider.setSettingEntries(null, null, null, entries); + + ArrayList providers = new ArrayList(); + providers.add(serializableProvider); + cfgDescription.setLanguageSettingProviders(providers); + + // prepare DOM storage + Document doc = XmlUtil.newDocument(); + rootElement = XmlUtil.appendElement(doc, ELEM_TEST); + // serialize language settings to the DOM + LanguageSettingsProvidersSerializer.serializeLanguageSettings(rootElement, mockPrjDescription); + } + { + // re-load and check language settings of the newly loaded provider + MockProjectDescription mockPrjDescription = new MockProjectDescription(new MockConfigurationDescription(CFG_ID)); + LanguageSettingsProvidersSerializer.loadLanguageSettings(rootElement, mockPrjDescription); + + ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations(); + assertNotNull(cfgDescriptions); + assertEquals(1, cfgDescriptions.length); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + assertNotNull(cfgDescription); + + List providers = cfgDescription.getLanguageSettingProviders(); + assertNotNull(providers); + assertEquals(1, providers.size()); + ILanguageSettingsProvider provider = providers.get(0); + assertTrue(provider instanceof LanguageSettingsSerializable); + + List actual = provider.getSettingEntries(null, null, null); + assertEquals(entries.get(0), actual.get(0)); + assertEquals(entries.size(), actual.size()); + } + } + + /** + */ + public void testProjectPersistence_TwoConfigurationsDOM() throws Exception { + Element rootElement = null; + + List entries = new ArrayList(); + entries.add(new CIncludePathEntry("path0", 0)); + List entries2 = new ArrayList(); + entries2.add(new CIncludePathEntry("path2", 0)); + + { + // create a project description with 2 configuration descriptions + MockProjectDescription mockPrjDescription = new MockProjectDescription( + new MockConfigurationDescription[] { + new MockConfigurationDescription(CFG_ID), + new MockConfigurationDescription(CFG_ID_2), + }); + { + ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations(); + assertNotNull(cfgDescriptions); + assertEquals(2, cfgDescriptions.length); + { + // populate configuration 1 with provider + ICConfigurationDescription cfgDescription1 = cfgDescriptions[0]; + assertNotNull(cfgDescription1); + assertEquals(CFG_ID, cfgDescription1.getId()); + LanguageSettingsSerializable provider1 = new LanguageSettingsSerializable(PROVIDER_0, PROVIDER_NAME_0); + provider1.setSettingEntries(null, null, null, entries); + ArrayList providers = new ArrayList(); + providers.add(provider1); + cfgDescription1.setLanguageSettingProviders(providers); + } + { + // populate configuration 2 with provider + ICConfigurationDescription cfgDescription2 = cfgDescriptions[1]; + assertNotNull(cfgDescription2); + assertEquals(CFG_ID_2, cfgDescription2.getId()); + LanguageSettingsSerializable provider2 = new LanguageSettingsSerializable(PROVIDER_0, PROVIDER_NAME_0); + provider2.setSettingEntries(null, null, null, entries2); + ArrayList providers = new ArrayList(); + providers.add(provider2); + cfgDescription2.setLanguageSettingProviders(providers); + } + } + + { + // doublecheck both configuration descriptions + ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations(); + assertNotNull(cfgDescriptions); + assertEquals(2, cfgDescriptions.length); + { + // doublecheck configuration 1 + ICConfigurationDescription cfgDescription1 = cfgDescriptions[0]; + assertNotNull(cfgDescription1); + List providers = cfgDescription1.getLanguageSettingProviders(); + assertNotNull(providers); + assertEquals(1, providers.size()); + ILanguageSettingsProvider provider = providers.get(0); + assertNotNull(provider); + List actual = provider.getSettingEntries(null, null, null); + assertEquals(entries.get(0), actual.get(0)); + assertEquals(entries.size(), actual.size()); + } + { + // doublecheck configuration 2 + ICConfigurationDescription cfgDescription2 = cfgDescriptions[1]; + assertNotNull(cfgDescription2); + List providers = cfgDescription2.getLanguageSettingProviders(); + assertNotNull(providers); + assertEquals(1, providers.size()); + ILanguageSettingsProvider provider = providers.get(0); + assertNotNull(provider); + List actual2 = provider.getSettingEntries(null, null, null); + assertEquals(entries2.get(0), actual2.get(0)); + assertEquals(entries2.size(), actual2.size()); + } + } + + // prepare DOM storage + Document doc = XmlUtil.newDocument(); + rootElement = XmlUtil.appendElement(doc, ELEM_TEST); + // serialize language settings to the DOM + LanguageSettingsProvidersSerializer.serializeLanguageSettings(rootElement, mockPrjDescription); + } + { + // re-create a project description and re-load language settings for each configuration + MockProjectDescription mockPrjDescription = new MockProjectDescription( + new MockConfigurationDescription[] { + new MockConfigurationDescription(CFG_ID), + new MockConfigurationDescription(CFG_ID_2), + }); + // load + LanguageSettingsProvidersSerializer.loadLanguageSettings(rootElement, mockPrjDescription); + + ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations(); + assertNotNull(cfgDescriptions); + assertEquals(2, cfgDescriptions.length); + { + // check configuration 1 + ICConfigurationDescription cfgDescription1 = cfgDescriptions[0]; + assertNotNull(cfgDescription1); + List providers = cfgDescription1.getLanguageSettingProviders(); + assertNotNull(providers); + assertEquals(1, providers.size()); + ILanguageSettingsProvider provider = providers.get(0); + assertNotNull(provider); + List actual = provider.getSettingEntries(null, null, null); + assertEquals(entries.get(0), actual.get(0)); + assertEquals(entries.size(), actual.size()); + } + { + // check configuration 2 + ICConfigurationDescription cfgDescription2 = cfgDescriptions[1]; + assertNotNull(cfgDescription2); + List providers = cfgDescription2.getLanguageSettingProviders(); + assertNotNull(providers); + assertEquals(1, providers.size()); + ILanguageSettingsProvider provider = providers.get(0); + assertNotNull(provider); + List actual2 = provider.getSettingEntries(null, null, null); + assertEquals(entries2.get(0), actual2.get(0)); + assertEquals(entries2.size(), actual2.size()); + } + } + } + + /** + */ + public void testProjectPersistence_SubclassedSerializableProviderDOM() throws Exception { + Element rootElement = null; + + List entries = new ArrayList(); + entries.add(new CIncludePathEntry("path0", 0)); + + { + // create a provider + MockProjectDescription mockPrjDescription = new MockProjectDescription(new MockConfigurationDescription(CFG_ID)); + + ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations(); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + assertNotNull(cfgDescription); + + LanguageSettingsSerializable serializableProvider = new MockLanguageSettingsSerializableProvider(PROVIDER_0, PROVIDER_NAME_0); + serializableProvider.setSettingEntries(null, null, null, entries); + + ArrayList providers = new ArrayList(); + providers.add(serializableProvider); + cfgDescription.setLanguageSettingProviders(providers); + + // prepare DOM storage + Document doc = XmlUtil.newDocument(); + rootElement = XmlUtil.appendElement(doc, ELEM_TEST); + // serialize language settings to the DOM + LanguageSettingsProvidersSerializer.serializeLanguageSettings(rootElement, mockPrjDescription); + } + { + // re-load and check language settings of the newly loaded provider + MockProjectDescription mockPrjDescription = new MockProjectDescription(new MockConfigurationDescription(CFG_ID)); + LanguageSettingsProvidersSerializer.loadLanguageSettings(rootElement, mockPrjDescription); + + ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations(); + assertNotNull(cfgDescriptions); + assertEquals(1, cfgDescriptions.length); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + assertNotNull(cfgDescription); + + List providers = cfgDescription.getLanguageSettingProviders(); + assertNotNull(providers); + assertEquals(1, providers.size()); + ILanguageSettingsProvider provider = providers.get(0); + assertTrue(provider instanceof MockLanguageSettingsSerializableProvider); + + List actual = provider.getSettingEntries(null, null, null); + assertEquals(entries.get(0), actual.get(0)); + assertEquals(entries.size(), actual.size()); + } + } + + /** + */ + public void testProjectPersistence_ReferenceExtensionProviderDOM() throws Exception { + Element rootElement = null; + + // provider of other type (not LanguageSettingsSerializable) defined as an extension + ILanguageSettingsProvider providerExt = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_PROVIDER_ID); + + { + // create cfg description + MockProjectDescription mockPrjDescription = new MockProjectDescription(new MockConfigurationDescription(CFG_ID)); + ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations(); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + assertNotNull(cfgDescription); + + // populate with provider defined as extension + List providers = new ArrayList(); + providers.add(providerExt); + cfgDescription.setLanguageSettingProviders(providers); + + // prepare DOM storage + Document doc = XmlUtil.newDocument(); + rootElement = XmlUtil.appendElement(doc, ELEM_TEST); + // serialize language settings to the DOM + LanguageSettingsProvidersSerializer.serializeLanguageSettings(rootElement, mockPrjDescription); + } + { + // re-load + MockProjectDescription mockPrjDescription = new MockProjectDescription(new MockConfigurationDescription(CFG_ID)); + LanguageSettingsProvidersSerializer.loadLanguageSettings(rootElement, mockPrjDescription); + + ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations(); + assertNotNull(cfgDescriptions); + assertEquals(1, cfgDescriptions.length); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + assertNotNull(cfgDescription); + + // and check the newly loaded provider which should be workspace provider + List providers = cfgDescription.getLanguageSettingProviders(); + assertNotNull(providers); + assertEquals(1, providers.size()); + ILanguageSettingsProvider provider = providers.get(0); + assertNotNull(provider); + assertTrue(LanguageSettingsManager.isWorkspaceProvider(provider)); + } + } + + /** + */ + public void testProjectPersistence_OverrideExtensionProviderDOM() throws Exception { + Element rootElement = null; + + // provider set on workspace level overriding an extension + String idExt = EXTENSION_PROVIDER_ID; + ILanguageSettingsProvider providerExt = LanguageSettingsManager.getWorkspaceProvider(idExt); + assertNotNull(providerExt); + { + // create cfg description + MockProjectDescription mockPrjDescription = new MockProjectDescription(new MockConfigurationDescription(CFG_ID)); + ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations(); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + assertNotNull(cfgDescription); + + // populate with provider overriding the extension (must be SerializableLanguageSettingsProvider or a class from another extension) + ILanguageSettingsProvider providerOverride = new MockLanguageSettingsSerializableProvider(idExt, PROVIDER_NAME_0); + List providers = new ArrayList(); + providers.add(providerOverride); + cfgDescription.setLanguageSettingProviders(providers); + + + // prepare DOM storage + Document doc = XmlUtil.newDocument(); + rootElement = XmlUtil.appendElement(doc, ELEM_TEST); + // serialize language settings to the DOM + LanguageSettingsProvidersSerializer.serializeLanguageSettings(rootElement, mockPrjDescription); + } + { + // re-load + MockProjectDescription mockPrjDescription = new MockProjectDescription(new MockConfigurationDescription(CFG_ID)); + LanguageSettingsProvidersSerializer.loadLanguageSettings(rootElement, mockPrjDescription); + + ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations(); + assertNotNull(cfgDescriptions); + assertEquals(1, cfgDescriptions.length); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + assertNotNull(cfgDescription); + + // check the newly loaded provider + List providers = cfgDescription.getLanguageSettingProviders(); + assertNotNull(providers); + assertEquals(1, providers.size()); + ILanguageSettingsProvider provider = providers.get(0); + assertNotNull(provider); + assertTrue(provider instanceof MockLanguageSettingsSerializableProvider); + assertEquals(idExt, provider.getId()); + assertEquals(PROVIDER_NAME_0, provider.getName()); + } + } + + + /** + */ + public void testProjectPersistence_MixedProvidersDOM() throws Exception { + Element rootElement = null; + + List entries_31 = new ArrayList(); + entries_31.add(new CIncludePathEntry("path0", 0)); + + List entries_32 = new ArrayList(); + entries_32.add(new CIncludePathEntry("path2", 0)); + + ILanguageSettingsProvider providerExt; + ILanguageSettingsProvider providerWsp; + { + // Define providers a bunch + MockProjectDescription mockPrjDescription = new MockProjectDescription(new MockConfigurationDescription(CFG_ID)); + { + ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations(); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + assertNotNull(cfgDescription); + + // 1. Provider reference to extension from plugin.xml + providerExt = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_PROVIDER_ID); + + // 2. TODO Provider reference to provider defined in the project + + // 3. Providers defined in a configuration + // 3.1 + LanguageSettingsSerializable mockProvider1 = new LanguageSettingsSerializable(PROVIDER_0, PROVIDER_NAME_0); + mockProvider1.setSettingEntries(null, null, null, entries_31); + // 3.2 + LanguageSettingsSerializable mockProvider2 = new MockLanguageSettingsSerializableProvider(PROVIDER_2, PROVIDER_NAME_2); + mockProvider2.setSettingEntries(null, null, null, entries_32); + + ArrayList providers = new ArrayList(); + providers.add(providerExt); + providers.add(mockProvider1); + providers.add(mockProvider2); + cfgDescription.setLanguageSettingProviders(providers); + } + + // prepare DOM storage + Document doc = XmlUtil.newDocument(); + rootElement = XmlUtil.appendElement(doc, ELEM_TEST); + // serialize language settings to the DOM + LanguageSettingsProvidersSerializer.serializeLanguageSettings(rootElement, mockPrjDescription); + XmlUtil.toString(doc); + } + { + // re-load and check language settings of the newly loaded provider + MockProjectDescription mockPrjDescription = new MockProjectDescription(new MockConfigurationDescription(CFG_ID)); + LanguageSettingsProvidersSerializer.loadLanguageSettings(rootElement, mockPrjDescription); + + ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations(); + assertNotNull(cfgDescriptions); + assertEquals(1, cfgDescriptions.length); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + List providers = cfgDescription.getLanguageSettingProviders(); + assertNotNull(providers); + // 1. Provider reference to extension from plugin.xml + ILanguageSettingsProvider provider0 = providers.get(0); + assertTrue(LanguageSettingsManager.isWorkspaceProvider(provider0)); + + // 2. TODO Provider reference to provider defined in the project + + // 3. Providers defined in a configuration + // 3.1 + { + ILanguageSettingsProvider provider1 = providers.get(1); + assertTrue(provider1 instanceof LanguageSettingsSerializable); + List actual = provider1.getSettingEntries(null, null, null); + assertEquals(entries_31.get(0), actual.get(0)); + assertEquals(entries_31.size(), actual.size()); + } + // 3.2 + { + ILanguageSettingsProvider provider2 = providers.get(2); + assertTrue(provider2 instanceof MockLanguageSettingsSerializableProvider); + List actual = provider2.getSettingEntries(null, null, null); + assertEquals(entries_32.get(0), actual.get(0)); + assertEquals(entries_32.size(), actual.size()); + } + assertEquals(3, providers.size()); + } + } + + /** + */ + public void testProjectPersistence_RealProject() throws Exception { + IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName()); + String xmlStorageFileLocation; + String xmlOutOfTheWay; + + List entries = new ArrayList(); + entries.add(new CIncludePathEntry("path0", 0)); + + { + // get project descriptions + ICProjectDescription writableProjDescription = coreModel.getProjectDescription(project); + assertNotNull(writableProjDescription); + ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); + assertEquals(1, cfgDescriptions.length); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + // create a provider + LanguageSettingsSerializable mockProvider = new LanguageSettingsSerializable(PROVIDER_0, PROVIDER_NAME_0); + mockProvider.setSettingEntries(cfgDescription, null, null, entries); + List providers = new ArrayList(); + providers.add(mockProvider); + cfgDescription.setLanguageSettingProviders(providers); + List storedProviders = cfgDescription.getLanguageSettingProviders(); + assertEquals(1, storedProviders.size()); + + // write to project description + coreModel.setProjectDescription(project, writableProjDescription); + IFile xmlStorageFile = project.getFile(".settings/language.settings.xml"); + assertTrue(xmlStorageFile.exists()); + xmlStorageFileLocation = xmlStorageFile.getLocation().toOSString(); + } + { + coreModel.getProjectDescription(project); + ICConfigurationDescription cfgDescription = getFirstConfigurationDescription(project); + List providers = cfgDescription.getLanguageSettingProviders(); + assertEquals(1, providers.size()); + ILanguageSettingsProvider provider = providers.get(0); + assertTrue(provider instanceof LanguageSettingsSerializable); + assertEquals(PROVIDER_0, provider.getId()); + assertEquals(PROVIDER_NAME_0, provider.getName()); + + List 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()); + } + + { + // clear configuration + ICProjectDescription writableProjDescription = coreModel.getProjectDescription(project); + ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); + assertEquals(1, cfgDescriptions.length); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + assertNotNull(cfgDescription); + + cfgDescription.setLanguageSettingProviders(new ArrayList()); + coreModel.setProjectDescription(project, writableProjDescription); + List providers = cfgDescription.getLanguageSettingProviders(); + assertEquals(0, providers.size()); + } + { + // re-check if it really took it + ICConfigurationDescription cfgDescription = getFirstConfigurationDescription(project); + List providers = 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); + List providers = 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); + List providers = cfgDescription.getLanguageSettingProviders(); + assertEquals(1, providers.size()); + ILanguageSettingsProvider loadedProvider = providers.get(0); + assertTrue(loadedProvider instanceof LanguageSettingsSerializable); + assertEquals(PROVIDER_0, loadedProvider.getId()); + assertEquals(PROVIDER_NAME_0, loadedProvider.getName()); + + List actual = loadedProvider.getSettingEntries(cfgDescription, null, null); + assertEquals(entries.get(0), actual.get(0)); + assertEquals(entries.size(), actual.size()); + } + } + + +} diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsScannerInfoProviderTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsScannerInfoProviderTests.java new file mode 100644 index 00000000000..5615a97bd41 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsScannerInfoProviderTests.java @@ -0,0 +1,893 @@ +/******************************************************************************* + * Copyright (c) 2009, 2010 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.core.language.settings.providers; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.eclipse.cdt.core.model.ILanguage; +import org.eclipse.cdt.core.model.LanguageManager; +import org.eclipse.cdt.core.parser.ExtendedScannerInfo; +import org.eclipse.cdt.core.settings.model.CIncludeFileEntry; +import org.eclipse.cdt.core.settings.model.CIncludePathEntry; +import org.eclipse.cdt.core.settings.model.CMacroEntry; +import org.eclipse.cdt.core.settings.model.CMacroFileEntry; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICFolderDescription; +import org.eclipse.cdt.core.settings.model.ICLanguageSetting; +import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; +import org.eclipse.cdt.core.settings.model.ICProjectDescription; +import org.eclipse.cdt.core.settings.model.ICSettingEntry; +import org.eclipse.cdt.core.testplugin.ResourceHelper; +import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsScannerInfoProvider; +import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; + +/** + * Test cases testing LanguageSettingsProvider functionality + */ +public class LanguageSettingsScannerInfoProviderTests extends TestCase { + private static final IFile FAKE_FILE = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("/project/path0")); + private static final String PROVIDER_ID = "test.provider.id"; + private static final String PROVIDER_ID_2 = "test.provider.id.2"; + private static final String PROVIDER_NAME = "test.provider.name"; + + private class MockProvider extends LanguageSettingsBaseProvider implements ILanguageSettingsProvider { + private final List entries; + + public MockProvider(String id, String name, List entries) { + super(id, name); + this.entries = entries; + } + + @Override + public List getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) { + return entries; + } + } + + /** + * Constructor. + * @param name - name of the test. + */ + public LanguageSettingsScannerInfoProviderTests(String name) { + super(name); + + } + + @Override + protected void setUp() throws Exception { + } + + @Override + protected void tearDown() throws Exception { + ResourceHelper.cleanUp(); + } + + /** + * @return - new TestSuite. + */ + public static TestSuite suite() { + return new TestSuite(LanguageSettingsScannerInfoProviderTests.class); + } + + /** + * main function of the class. + * + * @param args - arguments + */ + public static void main(String[] args) { + junit.textui.TestRunner.run(suite()); + } + + /** + * Sets build working directory for DefaultSettingConfiguration being tested. + */ + private void setBuilderCWD(IProject project, IPath buildCWD) throws CoreException { + CProjectDescriptionManager manager = CProjectDescriptionManager.getInstance(); + { + ICProjectDescription prjDescription = manager.getProjectDescription(project, true); + assertNotNull(prjDescription); + ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); + assertNotNull(cfgDescription); + + cfgDescription.getBuildSetting().setBuilderCWD(buildCWD); + manager.setProjectDescription(project, prjDescription); + // doublecheck builderCWD + IPath actualBuildCWD = cfgDescription.getBuildSetting().getBuilderCWD(); + assertEquals(buildCWD, actualBuildCWD); + } + { + // triplecheck builderCWD for different project/configuration descriptions + ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false); + assertNotNull(prjDescription); + ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); + assertNotNull(cfgDescription); + + } + } + + /** + * Test cases when some objects are null. + */ + public void testNulls() throws Exception { + { + // Handle project==null + IResource root = ResourcesPlugin.getWorkspace().getRoot(); + assertNull(root.getProject()); + + LanguageSettingsScannerInfoProvider scannerInfoProvider = new LanguageSettingsScannerInfoProvider(); + ExtendedScannerInfo info = scannerInfoProvider.getScannerInformation(root); + assertEquals(0, info.getIncludePaths().length); + assertEquals(0, info.getDefinedSymbols().size()); + assertEquals(0, info.getIncludeFiles().length); + assertEquals(0, info.getMacroFiles().length); + assertEquals(0, info.getLocalIncludePath().length); + } + + { + // Handle prjDescription==null + IProject project = FAKE_FILE.getProject(); + ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false); + assertNull(prjDescription); + + LanguageSettingsScannerInfoProvider scannerInfoProvider = new LanguageSettingsScannerInfoProvider(); + ExtendedScannerInfo info = scannerInfoProvider.getScannerInformation(FAKE_FILE); + assertEquals(0, info.getIncludePaths().length); + assertEquals(0, info.getDefinedSymbols().size()); + assertEquals(0, info.getIncludeFiles().length); + assertEquals(0, info.getMacroFiles().length); + assertEquals(0, info.getLocalIncludePath().length); + } + + { + // Handle language==null + LanguageSettingsScannerInfoProvider scannerInfoProvider = new LanguageSettingsScannerInfoProvider(); + IProject project = ResourceHelper.createCDTProjectWithConfig(getName()); + IFile file = ResourceHelper.createFile(project, "file"); + + ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false); + assertNotNull(prjDescription); + ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); + assertNotNull(cfgDescription); + ILanguage language = LanguageManager.getInstance().getLanguageForFile(file, cfgDescription); + assertNull(language); + + ExtendedScannerInfo info = scannerInfoProvider.getScannerInformation(file); + assertEquals(0, info.getIncludePaths().length); + assertEquals(0, info.getDefinedSymbols().size()); + assertEquals(0, info.getIncludeFiles().length); + assertEquals(0, info.getMacroFiles().length); + assertEquals(0, info.getLocalIncludePath().length); + } + } + + /** + * Test empty scanner info. + */ + public void testEmpty() throws Exception { + LanguageSettingsScannerInfoProvider scannerInfoProvider = new LanguageSettingsScannerInfoProvider(); + IProject project = ResourceHelper.createCDTProjectWithConfig(getName()); + IFile file = ResourceHelper.createFile(project, "file.c"); + + // confirm that language==null + ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false); + assertNotNull(prjDescription); + ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); + assertNotNull(cfgDescription); + ILanguage language = LanguageManager.getInstance().getLanguageForFile(file, cfgDescription); + assertNotNull(language); + + // test that the info is empty + ExtendedScannerInfo info = scannerInfoProvider.getScannerInformation(file); + assertEquals(0, info.getIncludePaths().length); + assertEquals(0, info.getDefinedSymbols().size()); + assertEquals(0, info.getIncludeFiles().length); + assertEquals(0, info.getMacroFiles().length); + assertEquals(0, info.getLocalIncludePath().length); + } + + /** + * Test regular cases. + */ + public void testRegular() throws Exception { + // create a project + IProject project = ResourceHelper.createCDTProjectWithConfig(getName()); + ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false); + assertNotNull(prjDescription); + ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); + assertNotNull(cfgDescription); + + // sample file + IFile file = ResourceHelper.createFile(project, "file.c"); + + // sanity test of language + ILanguage language = LanguageManager.getInstance().getLanguageForFile(file, cfgDescription); + assertNotNull(language); + + // contribute the entries + IFolder includeFolder = ResourceHelper.createFolder(project, "/include-path"); + IFolder includeLocalFolder = ResourceHelper.createFolder(project, "/local-include-path"); + IFile macroFile = ResourceHelper.createFile(project, "macro-file"); + IFile includeFile = ResourceHelper.createFile(project, "include-file"); + + CIncludePathEntry includePathEntry = new CIncludePathEntry(includeFolder, 0); + CIncludePathEntry includeLocalPathEntry = new CIncludePathEntry(includeLocalFolder, ICSettingEntry.LOCAL); // #include "..." + CMacroEntry macroEntry = new CMacroEntry("MACRO", "value",0); + CIncludeFileEntry includeFileEntry = new CIncludeFileEntry(includeFile, 0); + CMacroFileEntry macroFileEntry = new CMacroFileEntry(macroFile, 0); + + List entries = new ArrayList(); + entries.add(includePathEntry); + entries.add(includeLocalPathEntry); + entries.add(macroEntry); + entries.add(includeFileEntry); + entries.add(macroFileEntry); + + // add provider to the configuration + ILanguageSettingsProvider provider = new MockProvider(PROVIDER_ID, PROVIDER_NAME, entries); + List providers = new ArrayList(); + providers.add(provider); + cfgDescription.setLanguageSettingProviders(providers); + + // test that the scannerInfoProvider gets the entries + LanguageSettingsScannerInfoProvider scannerInfoProvider = new LanguageSettingsScannerInfoProvider(); + ExtendedScannerInfo info = scannerInfoProvider.getScannerInformation(file); + String[] actualIncludePaths = info.getIncludePaths(); + Map actualDefinedSymbols = info.getDefinedSymbols(); + String[] actualIncludeFiles = info.getIncludeFiles(); + String[] actualMacroFiles = info.getMacroFiles(); + String[] actualLocalIncludePath = info.getLocalIncludePath(); + // include paths + assertEquals(includeFolder.getLocation(), new Path(actualIncludePaths[0])); + assertEquals(1, actualIncludePaths.length); + // macros + assertEquals(macroEntry.getValue(), actualDefinedSymbols.get(macroEntry.getName())); + assertEquals(1, actualDefinedSymbols.size()); + // include file + assertEquals(includeFile.getLocation(), new Path(actualIncludeFiles[0])); + assertEquals(1, actualIncludeFiles.length); + // macro file + assertEquals(macroFile.getLocation(), new Path(actualMacroFiles[0])); + assertEquals(1, actualMacroFiles.length); + // local include files + assertEquals(includeLocalFolder.getLocation(), new Path(actualLocalIncludePath[0])); + assertEquals(1, actualLocalIncludePath.length); + } + + /** + * Test "local" flag (#include "..."). + */ + public void testLocal() throws Exception { + // create a project + IProject project = ResourceHelper.createCDTProjectWithConfig(getName()); + ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false); + assertNotNull(prjDescription); + ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); + assertNotNull(cfgDescription); + + // sample file + IFile file = ResourceHelper.createFile(project, "file.c"); + + // contribute the entries + IFolder incFolder = ResourceHelper.createFolder(project, "include"); + IFolder incFolder2 = ResourceHelper.createFolder(project, "include2"); + CIncludePathEntry includePathEntry = new CIncludePathEntry(incFolder, 0); + CIncludePathEntry includeLocalPathEntry = new CIncludePathEntry(incFolder, ICSettingEntry.LOCAL); // #include "..." + CIncludePathEntry includeLocalPathEntry2 = new CIncludePathEntry(incFolder2, ICSettingEntry.LOCAL); // #include "..." + CIncludePathEntry includePathEntry2 = new CIncludePathEntry(incFolder2, 0); + + List entries = new ArrayList(); + entries.add(includePathEntry); + entries.add(includeLocalPathEntry); + // reverse order for incPath2 + entries.add(includeLocalPathEntry2); + entries.add(includePathEntry2); + + // add provider to the configuration + ILanguageSettingsProvider provider = new MockProvider(PROVIDER_ID, PROVIDER_NAME, entries); + List providers = new ArrayList(); + providers.add(provider); + cfgDescription.setLanguageSettingProviders(providers); + + // test that the scannerInfoProvider gets the entries + LanguageSettingsScannerInfoProvider scannerInfoProvider = new LanguageSettingsScannerInfoProvider(); + ExtendedScannerInfo info = scannerInfoProvider.getScannerInformation(file); + String[] actualIncludePaths = info.getIncludePaths(); + String[] actualLocalIncludePath = info.getLocalIncludePath(); + // include paths + assertEquals(incFolder.getLocation(), new Path(actualIncludePaths[0])); + assertEquals(incFolder2.getLocation(), new Path(actualIncludePaths[1])); + assertEquals(2, actualIncludePaths.length); + // local include files + assertEquals(incFolder.getLocation(), new Path(actualLocalIncludePath[0])); + assertEquals(incFolder2.getLocation(), new Path(actualLocalIncludePath[1])); + assertEquals(2, actualLocalIncludePath.length); + } + + /** + * Test Mac frameworks. + */ + public void testFramework() throws Exception { + // create a project + IProject project = ResourceHelper.createCDTProjectWithConfig(getName()); + ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false); + assertNotNull(prjDescription); + ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); + assertNotNull(cfgDescription); + + // sample file + IFile file = ResourceHelper.createFile(project, "file.c"); + + // contribute the entries + IFolder frameworkFolder = ResourceHelper.createFolder(project, "Fmwk"); + CIncludePathEntry frameworkPathEntry = new CIncludePathEntry(frameworkFolder, ICSettingEntry.FRAMEWORKS_MAC); + + List entries = new ArrayList(); + entries.add(frameworkPathEntry); + + // add provider to the configuration + ILanguageSettingsProvider provider = new MockProvider(PROVIDER_ID, PROVIDER_NAME, entries); + List providers = new ArrayList(); + providers.add(provider); + cfgDescription.setLanguageSettingProviders(providers); + + // test that the scannerInfoProvider gets the entries + LanguageSettingsScannerInfoProvider scannerInfoProvider = new LanguageSettingsScannerInfoProvider(); + ExtendedScannerInfo info = scannerInfoProvider.getScannerInformation(file); + String[] actualIncludePaths = info.getIncludePaths(); + // include paths + assertEquals(frameworkFolder.getLocation().append("/__framework__.framework/Headers/__header__"), + new Path(actualIncludePaths[0])); + assertEquals(frameworkFolder.getLocation().append("/__framework__.framework/PrivateHeaders/__header__"), + new Path(actualIncludePaths[1])); + assertEquals(2, actualIncludePaths.length); + } + + /** + * Test duplicate entries. + */ + public void testDuplicate() throws Exception { + // create a project + IProject project = ResourceHelper.createCDTProjectWithConfig(getName()); + ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false); + assertNotNull(prjDescription); + ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); + assertNotNull(cfgDescription); + + // sample file + IFile file = ResourceHelper.createFile(project, "file.c"); + + // contribute the entries + IFolder incFolder = ResourceHelper.createFolder(project, "include"); + CIncludePathEntry includePathEntry = new CIncludePathEntry(incFolder, 0); + CIncludePathEntry includeLocalPathEntry = new CIncludePathEntry(incFolder, ICSettingEntry.LOCAL); // #include "..." + CIncludePathEntry includePathEntry2 = new CIncludePathEntry(incFolder, 0); + CIncludePathEntry includeLocalPathEntry2 = new CIncludePathEntry(incFolder, ICSettingEntry.LOCAL); // #include "..." + + List entries = new ArrayList(); + entries.add(includePathEntry); + entries.add(includeLocalPathEntry); + entries.add(includePathEntry2); + entries.add(includeLocalPathEntry2); + + // add provider to the configuration + ILanguageSettingsProvider provider = new MockProvider(PROVIDER_ID, PROVIDER_NAME, entries); + List providers = new ArrayList(); + providers.add(provider); + cfgDescription.setLanguageSettingProviders(providers); + + // test that the scannerInfoProvider gets the entries + LanguageSettingsScannerInfoProvider scannerInfoProvider = new LanguageSettingsScannerInfoProvider(); + ExtendedScannerInfo info = scannerInfoProvider.getScannerInformation(file); + String[] actualIncludePaths = info.getIncludePaths(); + String[] actualLocalIncludePath = info.getLocalIncludePath(); + // include paths + assertEquals(incFolder.getLocation(), new Path(actualIncludePaths[0])); + assertEquals(1, actualIncludePaths.length); + // local include files + assertEquals(incFolder.getLocation(), new Path(actualLocalIncludePath[0])); + assertEquals(1, actualLocalIncludePath.length); + } + + /** + * Test include path managed by eclipse as a workspace path. + */ + public void testWorkspacePath() throws Exception { + // create a project + IProject project = ResourceHelper.createCDTProjectWithConfig(getName()); + ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false); + assertNotNull(prjDescription); + ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); + assertNotNull(cfgDescription); + + // create sample file + IFile file = ResourceHelper.createFile(project, "file.c"); + // eclipse-managed folder in workspace + IFolder incWorkspace_1 = ResourceHelper.createFolder(project, "include_1"); + IPath incWorkspaceLocation_1 = incWorkspace_1.getLocation(); + IFolder incWorkspace_2 = ResourceHelper.createFolder(project, "include_2"); + IPath incWorkspacePath_2 = incWorkspace_2.getFullPath(); + IPath incWorkspaceLocation_2 = incWorkspace_2.getLocation(); + IFolder incWorkspace_3 = ResourceHelper.createFolder(project, "include_3"); + // "relative" should make no difference for VALUE_WORKSPACE_PATH + IPath incWorkspaceRelativePath_3 = incWorkspace_3.getFullPath().makeRelative(); + IPath incWorkspaceLocation_3 = incWorkspace_3.getLocation(); + // folder defined by absolute path on the filesystem + IPath incFilesystem = ResourceHelper.createWorkspaceFolder("includeFilesystem"); + + // contribute the entries + CIncludePathEntry incWorkspaceEntry_1 = new CIncludePathEntry(incWorkspace_1, 0); + CIncludePathEntry incWorkspaceEntry_2 = new CIncludePathEntry(incWorkspacePath_2, ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED); + CIncludePathEntry incWorkspaceEntry_3 = new CIncludePathEntry(incWorkspaceRelativePath_3, ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED); + CIncludePathEntry incFilesystemEntry = new CIncludePathEntry(incFilesystem, 0); + + List entries = new ArrayList(); + entries.add(incWorkspaceEntry_1); + entries.add(incWorkspaceEntry_2); + entries.add(incWorkspaceEntry_3); + entries.add(incFilesystemEntry); + + // add provider to the configuration + ILanguageSettingsProvider provider = new MockProvider(PROVIDER_ID, PROVIDER_NAME, entries); + List providers = new ArrayList(); + providers.add(provider); + cfgDescription.setLanguageSettingProviders(providers); + + // test the entries received from the scannerInfoProvider + LanguageSettingsScannerInfoProvider scannerInfoProvider = new LanguageSettingsScannerInfoProvider(); + ExtendedScannerInfo info = scannerInfoProvider.getScannerInformation(file); + String[] actualIncludePaths = info.getIncludePaths(); + + assertEquals(incWorkspaceLocation_1, new Path(actualIncludePaths[0])); + assertEquals(incWorkspaceLocation_2, new Path(actualIncludePaths[1])); + assertEquals(incWorkspaceLocation_3, new Path(actualIncludePaths[2])); + assertEquals(incFilesystem, new Path(actualIncludePaths[3])); + assertEquals(4, actualIncludePaths.length); + + } + + /** + * Confirm that device letter is prepended on filesystems that support that. + */ + public void testFilesystemPathNoDriveLetter() throws Exception { + // create a project + IProject project = ResourceHelper.createCDTProjectWithConfig(getName()); + // change drive on build working directory + String buildCwdDevice = project.getLocation().getDevice(); + +// // Test manually with a device which is different from project location device (path should exist) +// IPath buildCWD = new Path("D:/build/path"); +// String buildCwdDevice = buildCWD.getDevice(); + + // get project/configuration descriptions + ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false); + assertNotNull(prjDescription); + ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); + assertNotNull(cfgDescription); + + // create sample file + IFile file = ResourceHelper.createFile(project, "file.c"); + + // contribute the entries + // no-drive-letter folder defined by absolute path on the filesystem + IPath incFilesystem = ResourceHelper.createWorkspaceFolder("includeFilesystem").setDevice(null); + CIncludePathEntry incFilesystemEntry = new CIncludePathEntry(incFilesystem, 0); + List entries = new ArrayList(); + entries.add(incFilesystemEntry); + + // add provider to the configuration + ILanguageSettingsProvider provider = new MockProvider(PROVIDER_ID, PROVIDER_NAME, entries); + List providers = new ArrayList(); + providers.add(provider); + cfgDescription.setLanguageSettingProviders(providers); + + // test the entries received from the scannerInfoProvider + LanguageSettingsScannerInfoProvider scannerInfoProvider = new LanguageSettingsScannerInfoProvider(); + ExtendedScannerInfo info = scannerInfoProvider.getScannerInformation(file); + String[] actualIncludePaths = info.getIncludePaths(); + + IPath expectedInclude = incFilesystem.setDevice(buildCwdDevice); + assertEquals(expectedInclude, new Path(actualIncludePaths[0])); + assertEquals(1, actualIncludePaths.length); + } + + /** + * Test relative paths. + */ + public void testRelativePath() throws Exception { + // create a project + String prjName = getName(); + IProject project = ResourceHelper.createCDTProjectWithConfig(prjName); + String relativePath = "include"; + IFolder buildFolder = ResourceHelper.createFolder(project, "buildDir"); + IFolder relativeFolder = ResourceHelper.createFolder(project, "buildDir/"+relativePath); + IFolder relativeFolderProjName = ResourceHelper.createFolder(project, "buildDir/"+prjName); + String markedResolved = "-MarkedResolved"; + IFolder relativeFolderProjNameResolved = ResourceHelper.createFolder(project, "buildDir/" + prjName+markedResolved); + IPath buildCWD=buildFolder.getLocation(); + setBuilderCWD(project, buildCWD); + + // get project/configuration descriptions + ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false); + assertNotNull(prjDescription); + ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); + assertNotNull(cfgDescription); + + // create sample file + IFile file = ResourceHelper.createFile(project, "file.c"); + + // contribute the entries + CIncludePathEntry incRelativeEntry = new CIncludePathEntry(new Path(relativePath), 0); + CIncludePathEntry incProjNameEntry = new CIncludePathEntry(new Path("${ProjName}"), 0); + CIncludePathEntry incProjNameMarkedResolvedEntry = new CIncludePathEntry(new Path("${ProjName}"+markedResolved), ICSettingEntry.RESOLVED); + List entries = new ArrayList(); + entries.add(incRelativeEntry); + entries.add(incProjNameEntry); + entries.add(incProjNameMarkedResolvedEntry); + + // add provider to the configuration + ILanguageSettingsProvider provider = new MockProvider(PROVIDER_ID, PROVIDER_NAME, entries); + List providers = new ArrayList(); + providers.add(provider); + cfgDescription.setLanguageSettingProviders(providers); + + // test the entries received from the scannerInfoProvider + LanguageSettingsScannerInfoProvider scannerInfoProvider = new LanguageSettingsScannerInfoProvider(); + ExtendedScannerInfo info = scannerInfoProvider.getScannerInformation(file); + String[] actualIncludePaths = info.getIncludePaths(); + + // pair of entries, one from build dir another relative path + assertEquals(relativeFolder.getLocation(), new Path(actualIncludePaths[0])); + assertEquals(new Path(relativePath), new Path(actualIncludePaths[1])); + + // pair of entries, one resolved from build dir another expanded relative path + assertEquals(relativeFolderProjName.getLocation(), new Path(actualIncludePaths[2])); + assertEquals(new Path(prjName), new Path(actualIncludePaths[3])); + + // if marked RESOLVED only that path stays + assertEquals(new Path("${ProjName}"+markedResolved), new Path(actualIncludePaths[4])); + + assertEquals(5, actualIncludePaths.length); + } + + /** + * Test relative paths - some combinations of dot paths. + */ + public void testRelativePathWithDots() throws Exception { + // create a project + IProject project = ResourceHelper.createCDTProjectWithConfig(getName()); + // set build CWD + IFolder buildFolder = ResourceHelper.createFolder(project, "buildDir"); + IPath buildCWD=buildFolder.getLocation(); + setBuilderCWD(project, buildCWD); + + // define a few variations of paths + String relativePath_dot = "."; + String relativePath_dot_slash = "./"; + String relativePath_dot_slash_path = "./include"; + IFolder relativeFolder_dot_slash_path = ResourceHelper.createFolder(project, "buildDir/include"); + String relativePath_dotdot = ".."; + String relativePath_dotdot_slash = "../"; + String relativePath_dotdot_slash_path = "../include"; + IFolder relativeFolder_dotdot_slash_path = ResourceHelper.createFolder(project, "include"); + String locationPath_dotdot_path = buildCWD.toString()+"/../include2"; + IFolder incFolder_dotdot_slash_path = ResourceHelper.createFolder(project, "include2"); // "/ProjPath/buildDir/../include2" + + // get project/configuration descriptions + ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false); + assertNotNull(prjDescription); + ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); + assertNotNull(cfgDescription); + + // create sample file + IFile file = ResourceHelper.createFile(project, "file.c"); + + // contribute the entries + CIncludePathEntry incRelativeEntry_dot = new CIncludePathEntry(new Path(relativePath_dot), 0); + CIncludePathEntry incRelativeEntry_dot_slash_path = new CIncludePathEntry(new Path(relativePath_dot_slash_path), 0); + CIncludePathEntry incRelativeEntry_dotdot = new CIncludePathEntry(new Path(relativePath_dotdot), 0); + CIncludePathEntry incRelativeEntry_dotdot_slash_path = new CIncludePathEntry(new Path(relativePath_dotdot_slash_path), 0); + CIncludePathEntry incEntry_dotdot_path = new CIncludePathEntry(locationPath_dotdot_path, 0); + // use LOCAL flag not to clash with plain dot entries + CIncludePathEntry incRelativeEntry_dotdot_slash = new CIncludePathEntry(new Path(relativePath_dotdot_slash), ICSettingEntry.LOCAL); + CIncludePathEntry incRelativeEntry_dot_slash = new CIncludePathEntry(new Path(relativePath_dot_slash), ICSettingEntry.LOCAL); + + List entries = new ArrayList(); + entries.add(incRelativeEntry_dot); + entries.add(incRelativeEntry_dot_slash); + entries.add(incRelativeEntry_dot_slash_path); + entries.add(incRelativeEntry_dotdot); + entries.add(incRelativeEntry_dotdot_slash); + entries.add(incRelativeEntry_dotdot_slash_path); + entries.add(incEntry_dotdot_path); + + // add provider to the configuration + ILanguageSettingsProvider provider = new MockProvider(PROVIDER_ID, PROVIDER_NAME, entries); + List providers = new ArrayList(); + providers.add(provider); + cfgDescription.setLanguageSettingProviders(providers); + + // test the entries received from the scannerInfoProvider + LanguageSettingsScannerInfoProvider scannerInfoProvider = new LanguageSettingsScannerInfoProvider(); + ExtendedScannerInfo info = scannerInfoProvider.getScannerInformation(file); + String[] actualIncludePaths = info.getIncludePaths(); + String[] actualLocalIncludePaths = info.getLocalIncludePath(); + + IPath expectedLocation_dot = buildFolder.getLocation(); + IPath expectedLocation_dot_slash = buildFolder.getLocation(); + IPath expectedLocation_dot_slash_path = relativeFolder_dot_slash_path.getLocation(); + IPath expectedLocation_dotdot = project.getLocation(); + IPath expectedLocation_dotdot_slash = project.getLocation(); + IPath expectedLocation_dotdot_slash_path = relativeFolder_dotdot_slash_path.getLocation(); + + assertEquals(expectedLocation_dot, new Path(actualIncludePaths[0])); + assertEquals(".", actualIncludePaths[1]); + assertEquals(expectedLocation_dot_slash_path, new Path(actualIncludePaths[2])); + assertEquals(new Path(relativePath_dot_slash_path), new Path(actualIncludePaths[3])); + + assertEquals(expectedLocation_dotdot, new Path(actualIncludePaths[4])); + assertEquals("..", actualIncludePaths[5]); + assertEquals(expectedLocation_dotdot_slash_path, new Path(actualIncludePaths[6])); + assertEquals(new Path(relativePath_dotdot_slash_path), new Path(actualIncludePaths[7])); + assertTrue(actualIncludePaths[7].startsWith("..")); + assertEquals(new Path(locationPath_dotdot_path), new Path(actualIncludePaths[8])); + assertTrue(actualIncludePaths[8].contains("..")); + assertEquals(9, actualIncludePaths.length); + + assertEquals(expectedLocation_dot_slash, new Path(actualLocalIncludePaths[0])); + assertEquals(new Path(relativePath_dot_slash), new Path(actualLocalIncludePaths[1])); + assertTrue(actualLocalIncludePaths[1].startsWith(".")); + assertEquals(expectedLocation_dotdot_slash, new Path(actualLocalIncludePaths[2])); + assertEquals(new Path(relativePath_dotdot_slash), new Path(actualLocalIncludePaths[3])); + assertTrue(actualLocalIncludePaths[3].startsWith("..")); + assertEquals(4, actualLocalIncludePaths.length); + } + + /** + * Test if build/environment variables are expanded + */ + public void testEnvironmentVars() throws Exception { + // create a project + IProject project = ResourceHelper.createCDTProjectWithConfig(getName()); + IFolder folder = ResourceHelper.createFolder(project, "Folder"); + String envPathStr = "${ProjDirPath}/Folder"; + + // get project/configuration descriptions + ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false); + assertNotNull(prjDescription); + ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); + assertNotNull(cfgDescription); + + // create sample file + IFile file = ResourceHelper.createFile(project, "file.c"); + + // contribute the entries + CIncludePathEntry incRelativeEntry = new CIncludePathEntry(envPathStr, 0); + List entries = new ArrayList(); + entries.add(incRelativeEntry); + + // add provider to the configuration + ILanguageSettingsProvider provider = new MockProvider(PROVIDER_ID, PROVIDER_NAME, entries); + List providers = new ArrayList(); + providers.add(provider); + cfgDescription.setLanguageSettingProviders(providers); + + // test the entries received from the scannerInfoProvider + LanguageSettingsScannerInfoProvider scannerInfoProvider = new LanguageSettingsScannerInfoProvider(); + ExtendedScannerInfo info = scannerInfoProvider.getScannerInformation(file); + String[] actualIncludePaths = info.getIncludePaths(); + + IPath expectedLocation = folder.getLocation(); + assertEquals(expectedLocation, new Path(actualIncludePaths[0])); + assertEquals(1, actualIncludePaths.length); + } + + /** + * Test from parent folder's entries. + */ + public void testParentFolder() throws Exception { + class MockProviderForResource extends LanguageSettingsBaseProvider implements ILanguageSettingsProvider { + private IResource rc; + private final List entries; + + public MockProviderForResource(IResource rc, List entries) { + this.rc = rc; + this.entries = entries; + } + + @Override + public List getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) { + if (this.rc.equals(rc)) + return entries; + return null; + } + } + + // create a project + IProject project = ResourceHelper.createCDTProjectWithConfig(getName()); + ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false); + assertNotNull(prjDescription); + ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); + assertNotNull(cfgDescription); + + // sample file + IFolder parentFolder = ResourceHelper.createFolder(project, "ParentFolder"); + IFile file = ResourceHelper.createFile(project, "ParentFolder/file.c"); + + // contribute the entries + IFolder incFolder = ResourceHelper.createFolder(project, "include"); + CIncludePathEntry includePathEntry = new CIncludePathEntry(incFolder, 0); + + List entries = new ArrayList(); + entries.add(includePathEntry); + + // add provider for parent folder + ILanguageSettingsProvider provider = new MockProviderForResource(parentFolder, entries); + assertNull(provider.getSettingEntries(cfgDescription, file, null)); + assertEquals(includePathEntry, provider.getSettingEntries(cfgDescription, parentFolder, null).get(0)); + + List providers = new ArrayList(); + providers.add(provider); + cfgDescription.setLanguageSettingProviders(providers); + + // test that the scannerInfoProvider gets the entries for + LanguageSettingsScannerInfoProvider scannerInfoProvider = new LanguageSettingsScannerInfoProvider(); + ExtendedScannerInfo info = scannerInfoProvider.getScannerInformation(file); + String[] actualIncludePaths = info.getIncludePaths(); + // include paths + assertEquals(incFolder.getLocation(), new Path(actualIncludePaths[0])); + assertEquals(1, actualIncludePaths.length); + } + + /** + * Test resolved paths. + */ + public void testResolvedPath() throws Exception { + // create a project + IProject project = ResourceHelper.createCDTProjectWithConfig(getName()); + IFolder folder = ResourceHelper.createFolder(project, "Folder"); + String envPathStr = "${ProjDirPath}/Folder"; + + // get project/configuration descriptions + ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false); + assertNotNull(prjDescription); + ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); + assertNotNull(cfgDescription); + + // create sample file + IFile file = ResourceHelper.createFile(project, "file.c"); + + // contribute the entries + CIncludePathEntry incRelativeEntry = new CIncludePathEntry(envPathStr, ICSettingEntry.RESOLVED); + List entries = new ArrayList(); + entries.add(incRelativeEntry); + + // add provider to the configuration + ILanguageSettingsProvider provider = new MockProvider(PROVIDER_ID, PROVIDER_NAME, entries); + List providers = new ArrayList(); + providers.add(provider); + cfgDescription.setLanguageSettingProviders(providers); + + // test the entries received from the scannerInfoProvider + LanguageSettingsScannerInfoProvider scannerInfoProvider = new LanguageSettingsScannerInfoProvider(); + ExtendedScannerInfo info = scannerInfoProvider.getScannerInformation(file); + String[] actualIncludePaths = info.getIncludePaths(); + + // test that RESOLVED entries are not modified + IPath expectedLocation = new Path(envPathStr); + assertEquals(expectedLocation, new Path(actualIncludePaths[0])); + assertEquals(1, actualIncludePaths.length); + } + + private List getLanguages(IFolder folder, ICConfigurationDescription cfgDescription) { + // Get first 2 languages + IPath rcPath = folder.getProjectRelativePath(); + ICFolderDescription rcDes = (ICFolderDescription) cfgDescription.getResourceDescription(rcPath, false); + ICLanguageSetting[] langSettings = rcDes.getLanguageSettings(); + assertNotNull(langSettings); + + List languageIds = new ArrayList(); + for (ICLanguageSetting ls : langSettings) { + String langId = ls.getLanguageId(); + if (langId!=null && !languageIds.contains(langId)) { + languageIds.add(langId); + } + } + return languageIds; + } + + /** + * Test composition of 2 languages. + */ + public void testResourceLanguages() throws Exception { + class MockProviderLang extends LanguageSettingsBaseProvider implements ILanguageSettingsProvider { + private final String langId; + private final List entries; + + public MockProviderLang(String id, String name, String langId, List entries) { + super(id, name); + this.langId = langId; + this.entries = entries; + } + + @Override + public List getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) { + if (langId==null || langId.equals(languageId)) + return entries; + return new ArrayList(); + } + } + + // create a project + IProject project = ResourceHelper.createCDTProjectWithConfig(getName()); + IFolder folder = ResourceHelper.createFolder(project, "Folder"); + + IFolder incFolderA = ResourceHelper.createFolder(project, "includeA"); + IFolder incFolderB = ResourceHelper.createFolder(project, "includeB"); + IFolder incFolderC = ResourceHelper.createFolder(project, "includeC"); + + // get project/configuration descriptions + ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false); + assertNotNull(prjDescription); + ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); + assertNotNull(cfgDescription); + + // find 2 languages applicable to the folder + List languageIds = getLanguages(folder, cfgDescription); + assertTrue(languageIds.size() >= 2); + String langId1 = languageIds.get(0); + String langId2 = languageIds.get(1); + + // define overlapping entries + CIncludePathEntry incEntryA = new CIncludePathEntry(incFolderA, 0); + CIncludePathEntry incEntryB = new CIncludePathEntry(incFolderB, 0); + CIncludePathEntry incEntryC = new CIncludePathEntry(incFolderC, 0); + List entries1 = new ArrayList(); + entries1.add(incEntryA); + entries1.add(incEntryB); + List entries2 = new ArrayList(); + entries2.add(incEntryC); + entries2.add(incEntryB); + + // add providers to the configuration + ILanguageSettingsProvider provider1 = new MockProviderLang(PROVIDER_ID, PROVIDER_NAME, langId1, entries1); + ILanguageSettingsProvider provider2 = new MockProviderLang(PROVIDER_ID_2, PROVIDER_NAME, langId2, entries2); + List providers = new ArrayList(); + providers.add(provider1); + providers.add(provider2); + cfgDescription.setLanguageSettingProviders(providers); + + // test the entries received from the scannerInfoProvider + LanguageSettingsScannerInfoProvider scannerInfoProvider = new LanguageSettingsScannerInfoProvider(); + ExtendedScannerInfo info = scannerInfoProvider.getScannerInformation(folder); + String[] actualIncludePaths = info.getIncludePaths(); + + // Test that the result is the union of entries + assertEquals(incFolderA.getLocation(), new Path(actualIncludePaths[0])); + assertEquals(incFolderB.getLocation(), new Path(actualIncludePaths[1])); + assertEquals(incFolderC.getLocation(), new Path(actualIncludePaths[2])); + assertEquals(3, actualIncludePaths.length); + } + +} diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java new file mode 100644 index 00000000000..0cde8b59f0a --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java @@ -0,0 +1,1146 @@ +/******************************************************************************* + * Copyright (c) 2009 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.core.language.settings.providers; + +import java.util.ArrayList; +import java.util.List; + +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.eclipse.cdt.core.settings.model.CIncludeFileEntry; +import org.eclipse.cdt.core.settings.model.CIncludePathEntry; +import org.eclipse.cdt.core.settings.model.CLibraryFileEntry; +import org.eclipse.cdt.core.settings.model.CLibraryPathEntry; +import org.eclipse.cdt.core.settings.model.CMacroEntry; +import org.eclipse.cdt.core.settings.model.CMacroFileEntry; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; +import org.eclipse.cdt.core.testplugin.CModelMock; +import org.eclipse.cdt.core.testplugin.ResourceHelper; +import org.eclipse.cdt.internal.core.XmlUtil; +import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.Path; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +/** + * Test cases testing LanguageSettingsProvider functionality + */ +public class LanguageSettingsSerializableTests extends TestCase { + // Should match id of extension point defined in plugin.xml + private static final String EXTENSION_SERIALIZABLE_PROVIDER_ID = "org.eclipse.cdt.core.tests.custom.serializable.language.settings.provider"; + + private static final String CFG_ID = "test.configuration.id"; + private static final String CFG_ID_1 = "test.configuration.id.1"; + private static final String CFG_ID_2 = "test.configuration.id.2"; + private static final ICConfigurationDescription MOCK_CFG = new CModelMock.DummyCConfigurationDescription(CFG_ID); + private static final IResource MOCK_RC = ResourcesPlugin.getWorkspace().getRoot(); + private static final String LANG_ID = "test.lang.id"; + private static final String LANG_ID_1 = "test.lang.id.1"; + private static final String LANG_ID_2 = "test.lang.id.2"; + private static final String PROVIDER_NULL = "test.provider.null.id"; + private static final String PROVIDER_1 = "test.provider.1.id"; + private static final String PROVIDER_2 = "test.provider.2.id"; + private static final String PROVIDER_NAME_NULL = "test.provider.null.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 CUSTOM_PARAMETER = "custom.parameter"; + + private static final String ELEM_TEST = "test"; + + /** + * Constructor. + * @param name - name of the test. + */ + public LanguageSettingsSerializableTests(String name) { + super(name); + + } + + @Override + protected void setUp() throws Exception { + } + + @Override + protected void tearDown() throws Exception { + ResourceHelper.cleanUp(); + } + + /** + * @return - new TestSuite. + */ + public static TestSuite suite() { + return new TestSuite(LanguageSettingsSerializableTests.class); + } + + /** + * main function of the class. + * + * @param args - arguments + */ + public static void main(String[] args) { + junit.textui.TestRunner.run(suite()); + } + + /** + */ + public void testProvider() throws Exception { + // benchmark data + List entries = new ArrayList(); + entries.add(new CIncludePathEntry("path0", 0)); + List languages = new ArrayList(); + languages.add(LANG_ID); + + // create a provider + LanguageSettingsSerializable mockProvider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + // test isEmpty() + assertTrue(mockProvider.isEmpty()); + + // test setters and getters + mockProvider.setId(PROVIDER_2); + assertEquals(PROVIDER_2, mockProvider.getId()); + mockProvider.setName(PROVIDER_NAME_2); + assertEquals(PROVIDER_NAME_2, mockProvider.getName()); + mockProvider.setCustomParameter(CUSTOM_PARAMETER); + assertEquals(CUSTOM_PARAMETER, mockProvider.getCustomParameter()); + mockProvider.setLanguageScope(languages); + assertEquals(languages, mockProvider.getLanguageScope()); + mockProvider.setLanguageScope(null); + assertEquals(null, mockProvider.getLanguageScope()); + + mockProvider.setSettingEntries(null, MOCK_RC, LANG_ID, entries); + List actual = mockProvider.getSettingEntries(null, MOCK_RC, LANG_ID); + assertEquals(entries.get(0), actual.get(0)); + assertEquals(entries.size(), actual.size()); + assertFalse(mockProvider.isEmpty()); + + // test clear() + mockProvider.clear(); + assertTrue(mockProvider.isEmpty()); + } + + /** + */ + public void testNoProviders() throws Exception { + // serialize language settings of user defined providers (on workspace level) + LanguageSettingsProvidersSerializer.serializeLanguageSettingsWorkspace(); + LanguageSettingsProvidersSerializer.loadLanguageSettingsWorkspace(); + + // test passes if no exception was thrown + } + + /** + */ + public void testEmptyProvider() throws Exception { + Element elementProvider; + { + // create null provider + LanguageSettingsSerializable providerNull = new LanguageSettingsSerializable(PROVIDER_NULL, PROVIDER_NAME_NULL); + assertNull(providerNull.getSettingEntries(null, null, null)); + // set and get null entries + providerNull.setSettingEntries(null, null, null, null); + assertNull(providerNull.getSettingEntries(null, null, null)); + + Document doc = XmlUtil.newDocument(); + Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST); + elementProvider = providerNull.serialize(rootElement); + String xmlString = XmlUtil.toString(doc); + assertTrue(xmlString.contains(PROVIDER_NULL)); + } + { + // re-load and check language settings of the newly loaded provider + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(elementProvider); + assertEquals(PROVIDER_NULL, provider.getId()); + List actual = provider.getSettingEntries(null, null, null); + assertNull(actual); + } + } + + /** + */ + public void testCustomParameter() throws Exception { + Element elementProvider; + { + // create provider with custom parameter + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + provider.setCustomParameter(CUSTOM_PARAMETER); + assertEquals(CUSTOM_PARAMETER, provider.getCustomParameter()); + + Document doc = XmlUtil.newDocument(); + Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST); + elementProvider = provider.serialize(rootElement); + String xmlString = XmlUtil.toString(doc); + assertTrue(xmlString.contains(CUSTOM_PARAMETER)); + } + { + // re-load and check custom parameter of the newly loaded provider + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(elementProvider); + assertEquals(CUSTOM_PARAMETER, provider.getCustomParameter()); + } + } + + /** + */ + public void testLanguages() throws Exception { + List expectedLanguageIds = new ArrayList(); + expectedLanguageIds.add(LANG_ID); + expectedLanguageIds.add(LANG_ID_1); + + Element elementProvider; + { + // create provider with custom language scope + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + provider.setLanguageScope(expectedLanguageIds); + List actualIds = provider.getLanguageScope(); + assertEquals(LANG_ID, actualIds.get(0)); + assertEquals(LANG_ID_1, actualIds.get(1)); + assertEquals(2, actualIds.size()); + + Document doc = XmlUtil.newDocument(); + Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST); + elementProvider = provider.serialize(rootElement); + String xmlString = XmlUtil.toString(doc); + assertTrue(xmlString.contains(LANG_ID)); + assertTrue(xmlString.contains(LANG_ID_1)); + } + { + // re-load and check language settings of the newly loaded provider + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(elementProvider); + List actualIds = provider.getLanguageScope(); + assertEquals(expectedLanguageIds.get(0), actualIds.get(0)); + assertEquals(expectedLanguageIds.get(1), actualIds.get(1)); + assertEquals(expectedLanguageIds.size(), actualIds.size()); + } + } + + /** + */ + public void testLanguageScope() throws Exception { + // benchmark entries + List entries = new ArrayList(); + entries.add(new CIncludePathEntry("path0", 0)); + + // define the scope + List expectedLanguageIds = new ArrayList(); + expectedLanguageIds.add(LANG_ID); + expectedLanguageIds.add(LANG_ID_1); + + Element elementProvider; + { + // create provider with no scope by default + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + // set entries for the whole language scope (now langId=null) + provider.setSettingEntries(null, null, null, entries); + { + // doublecheck for language scope itself + List actual = provider.getSettingEntries(null, null, null); + assertEquals(entries, actual); + } + { + // doublecheck for any language + List actual = provider.getSettingEntries(null, null, LANG_ID_2); + assertEquals(entries, actual); + } + + // set the scope + provider.setLanguageScope(expectedLanguageIds); + List actualIds = provider.getLanguageScope(); + assertEquals(LANG_ID, actualIds.get(0)); + assertEquals(LANG_ID_1, actualIds.get(1)); + assertEquals(2, actualIds.size()); + + { + // check for language scope itself + List actual = provider.getSettingEntries(null, null, null); + assertEquals(entries, actual); + } + { + // check for language in the language scope + List actual = provider.getSettingEntries(null, null, LANG_ID); + assertEquals(entries, actual); + } + { + // check for language not in scope + List actual = provider.getSettingEntries(null, null, LANG_ID_2); + assertNull(actual); + } + + Document doc = XmlUtil.newDocument(); + Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST); + elementProvider = provider.serialize(rootElement); + String xmlString = XmlUtil.toString(doc); + assertTrue(xmlString.contains(LANG_ID)); + assertTrue(xmlString.contains(LANG_ID_1)); + } + { + // re-load and check language settings of the newly loaded provider + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(elementProvider); + List actualIds = provider.getLanguageScope(); + assertEquals(expectedLanguageIds.get(0), actualIds.get(0)); + assertEquals(expectedLanguageIds.get(1), actualIds.get(1)); + assertEquals(expectedLanguageIds.size(), actualIds.size()); + + { + // check for language scope itself + List actual = provider.getSettingEntries(null, null, null); + assertEquals(entries, actual); + } + { + // check for language in the language scope + List actual = provider.getSettingEntries(null, null, LANG_ID); + assertEquals(entries, actual); + } + { + // check for language not in scope + List actual = provider.getSettingEntries(null, null, LANG_ID_2); + assertNull(actual); + } + } + } + + /** + */ + public void testNullConfiguration() throws Exception { + // provider/configuration/language/resource/settingEntry + Element elementProvider; + List entries = new ArrayList(); + entries.add(new CIncludePathEntry("path0", 0)); + { + // create a provider and serialize its settings + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + provider.setSettingEntries(null, MOCK_RC, LANG_ID, entries); + + Document doc = XmlUtil.newDocument(); + Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST); + elementProvider = provider.serialize(rootElement); + + // verify that "configuration" element is collapsed and not saved in XML + String xmlString = XmlUtil.toString(doc); + assertFalse(xmlString.contains(" actual = provider.getSettingEntries(null, MOCK_RC, LANG_ID); + assertEquals(entries.get(0), actual.get(0)); + } + } + + /** + */ + public void testNullLanguage() throws Exception { + // provider/configuration/language/resource/settingEntry + Element elementProvider; + List entries = new ArrayList(); + entries.add(new CIncludePathEntry("path0", 0)); + { + // create a provider and serialize its settings + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + provider.setSettingEntries(MOCK_CFG, MOCK_RC, null, entries); + + Document doc = XmlUtil.newDocument(); + Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST); + elementProvider = provider.serialize(rootElement); + + // verify that "language" element is collapsed and not saved in XML + String xmlString = XmlUtil.toString(doc); + assertFalse(xmlString.contains(" actual = provider.getSettingEntries(MOCK_CFG, MOCK_RC, null); + assertEquals(entries.get(0), actual.get(0)); + } + } + + + /** + */ + public void testNullLanguageScope() throws Exception { + // define benchmark entries + List entriesNullLanguage = new ArrayList(); + entriesNullLanguage.add(new CIncludePathEntry("path_null", 0)); + List entriesLanguage = new ArrayList(); + entriesLanguage.add(new CIncludePathEntry("path", 0)); + + Element elementProvider; + + { + // create a provider + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + assertEquals(null, provider.getLanguageScope()); + + // add null language + provider.setSettingEntries(null, MOCK_RC, null, entriesNullLanguage); + assertEquals(null, provider.getLanguageScope()); + { + // getter by null language + List actual = provider.getSettingEntries(null, MOCK_RC, null); + assertEquals(entriesNullLanguage.get(0), actual.get(0)); + assertEquals(entriesNullLanguage.size(), actual.size()); + } + { + // getter by any language - should return same entries as null + List actual = provider.getSettingEntries(null, MOCK_RC, LANG_ID); + assertEquals(entriesNullLanguage.get(0), actual.get(0)); + assertEquals(entriesNullLanguage.size(), actual.size()); + } + + // add non-null language + provider.setSettingEntries(MOCK_CFG, MOCK_RC, LANG_ID, entriesLanguage); + assertNull(provider.getLanguageScope()); + { + // getter by null language + List actual = provider.getSettingEntries(null, MOCK_RC, null); + assertEquals(entriesNullLanguage.get(0), actual.get(0)); + assertEquals(entriesNullLanguage.size(), actual.size()); + } + { + // getter by the language + List actual = provider.getSettingEntries(null, MOCK_RC, LANG_ID); + assertEquals(entriesLanguage.get(0), actual.get(0)); + assertEquals(entriesLanguage.size(), actual.size()); + } + + // provider/configuration/language/resource/settingEntry + Document doc = XmlUtil.newDocument(); + Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST); + elementProvider = provider.serialize(rootElement); + + // verify that "language" element is saved in XML + String xmlString = XmlUtil.toString(doc); + assertTrue(xmlString.contains(" actual = provider.getSettingEntries(null, MOCK_RC, null); + assertEquals(entriesNullLanguage.get(0), actual.get(0)); + assertEquals(entriesNullLanguage.size(), actual.size()); + } + { + // getter by the language + List actual = provider.getSettingEntries(null, MOCK_RC, LANG_ID); + assertEquals(entriesLanguage.get(0), actual.get(0)); + assertEquals(entriesLanguage.size(), actual.size()); + } + } + } + + /** + */ + public void testNullResource() throws Exception { + // provider/configuration/language/resource/settingEntry + Element elementProvider; + List entries = new ArrayList(); + entries.add(new CIncludePathEntry("path0", 0)); + { + // create a provider and serialize its settings + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + provider.setSettingEntries(MOCK_CFG, null, LANG_ID, entries); + + Document doc = XmlUtil.newDocument(); + Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST); + elementProvider = provider.serialize(rootElement); + + // verify that "resource" element is collapsed and not saved in XML + String xmlString = XmlUtil.toString(doc); + assertFalse(xmlString.contains(" actual = provider.getSettingEntries(MOCK_CFG, null, LANG_ID); + assertEquals(entries.get(0), actual.get(0)); + } + } + + /** + */ + public void testNullConfigurationLanguage() throws Exception { + // provider/configuration/language/resource/settingEntry + Element elementProvider; + List entries = new ArrayList(); + entries.add(new CIncludePathEntry("path0", 0)); + { + // create a provider and serialize its settings + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + provider.setSettingEntries(null, MOCK_RC, null, entries); + + Document doc = XmlUtil.newDocument(); + Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST); + elementProvider = provider.serialize(rootElement); + + // verify that element is collapsed and not saved in XML + String xmlString = XmlUtil.toString(doc); + assertFalse(xmlString.contains(" actual = provider.getSettingEntries(null, MOCK_RC, null); + assertEquals(entries.get(0), actual.get(0)); + } + } + + /** + */ + public void testNullConfigurationResource() throws Exception { + // provider/configuration/language/resource/settingEntry + Element elementProvider; + List entries = new ArrayList(); + entries.add(new CIncludePathEntry("path0", 0)); + { + // create a provider and serialize its settings + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + provider.setSettingEntries(null, null, LANG_ID, entries); + + Document doc = XmlUtil.newDocument(); + Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST); + elementProvider = provider.serialize(rootElement); + + // verify that element is collapsed and not saved in XML + String xmlString = XmlUtil.toString(doc); + assertFalse(xmlString.contains(" actual = provider.getSettingEntries(null, null, LANG_ID); + assertEquals(entries.get(0), actual.get(0)); + } + } + + /** + */ + public void testNullLanguageResource() throws Exception { + // provider/configuration/language/resource/settingEntry + Element elementProvider; + List entries = new ArrayList(); + entries.add(new CIncludePathEntry("path0", 0)); + { + // create a provider and serialize its settings + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + provider.setSettingEntries(MOCK_CFG, null, null, entries); + + Document doc = XmlUtil.newDocument(); + Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST); + elementProvider = provider.serialize(rootElement); + + // verify that element is collapsed and not saved in XML + String xmlString = XmlUtil.toString(doc); + assertFalse(xmlString.contains(" actual = provider.getSettingEntries(MOCK_CFG, null, null); + assertEquals(entries.get(0), actual.get(0)); + } + } + + /** + */ + public void testNullConfigurationLanguageResourceFlag() throws Exception { + // provider/configuration/language/resource/settingEntry + Element elementProvider; + List entries = new ArrayList(); + int flag = 0; + entries.add(new CIncludePathEntry("path0", flag)); + { + // create a provider and serialize its settings + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + provider.setSettingEntries(null, null, null, entries); + + Document doc = XmlUtil.newDocument(); + Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST); + elementProvider = provider.serialize(rootElement); + + // verify that element is collapsed and not saved in XML + String xmlString = XmlUtil.toString(doc); + assertFalse(xmlString.contains(" actual = provider.getSettingEntries(null, null, null); + assertEquals(entries.get(0), actual.get(0)); + } + } + + /** + */ + public void testCIncludePathEntry() throws Exception { + Element elementProvider; + List entries = new ArrayList(); + entries.add(new CIncludePathEntry("path0", 1)); + { + // create a provider and serialize its settings + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + provider.setSettingEntries(null, null, null, entries); + + Document doc = XmlUtil.newDocument(); + Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST); + elementProvider = provider.serialize(rootElement); + } + { + // re-load and check language settings of the newly loaded provider + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(elementProvider); + assertEquals(PROVIDER_1, provider.getId()); + + List actual = provider.getSettingEntries(null, null, null); + ICLanguageSettingEntry entry = actual.get(0); + assertTrue(entry instanceof CIncludePathEntry); + + CIncludePathEntry includePathEntry = (CIncludePathEntry)entry; + assertEquals(entries.get(0).getName(), includePathEntry.getName()); + assertEquals(entries.get(0).getValue(), includePathEntry.getValue()); + assertEquals(entries.get(0).getKind(), includePathEntry.getKind()); + assertEquals(entries.get(0).getFlags(), includePathEntry.getFlags()); + assertEquals(entries.get(0), includePathEntry); + } + } + + /** + */ + public void testCIncludeFileEntry() throws Exception { + Element elementProvider; + List entries = new ArrayList(); + entries.add(new CIncludeFileEntry("name", 1)); + { + // create a provider and serialize its settings + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + provider.setSettingEntries(null, null, null, entries); + + Document doc = XmlUtil.newDocument(); + Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST); + elementProvider = provider.serialize(rootElement); + } + { + // re-load and check language settings of the newly loaded provider + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(elementProvider); + assertEquals(PROVIDER_1, provider.getId()); + + List actual = provider.getSettingEntries(null, null, null); + ICLanguageSettingEntry entry = actual.get(0); + assertTrue(entry instanceof CIncludeFileEntry); + CIncludeFileEntry includeFileEntry = (CIncludeFileEntry)entry; + assertEquals(entries.get(0).getName(), includeFileEntry.getName()); + assertEquals(entries.get(0).getValue(), includeFileEntry.getValue()); + assertEquals(entries.get(0).getKind(), includeFileEntry.getKind()); + assertEquals(entries.get(0).getFlags(), includeFileEntry.getFlags()); + assertEquals(entries.get(0), includeFileEntry); + } + } + + /** + */ + public void testCMacroEntry() throws Exception { + Element elementProvider; + List entries = new ArrayList(); + entries.add(new CMacroEntry("MACRO0", "value0",1)); + { + // create a provider and serialize its settings + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + provider.setSettingEntries(null, null, null, entries); + + Document doc = XmlUtil.newDocument(); + Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST); + elementProvider = provider.serialize(rootElement); + } + { + // re-load and check language settings of the newly loaded provider + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(elementProvider); + assertEquals(PROVIDER_1, provider.getId()); + + List actual = provider.getSettingEntries(null, null, null); + ICLanguageSettingEntry entry = actual.get(0); + assertTrue(entry instanceof CMacroEntry); + CMacroEntry macroEntry = (CMacroEntry)entry; + assertEquals(entries.get(0).getName(), macroEntry.getName()); + assertEquals(entries.get(0).getValue(), macroEntry.getValue()); + assertEquals(entries.get(0).getKind(), macroEntry.getKind()); + assertEquals(entries.get(0).getFlags(), macroEntry.getFlags()); + assertEquals(entries.get(0), macroEntry); + } + } + + /** + */ + public void testCMacroFileEntry() throws Exception { + Element elementProvider; + List entries = new ArrayList(); + entries.add(new CMacroFileEntry("name", 1)); + { + // create a provider and serialize its settings + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + provider.setSettingEntries(null, null, null, entries); + + Document doc = XmlUtil.newDocument(); + Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST); + elementProvider = provider.serialize(rootElement); + } + { + // re-load and check language settings of the newly loaded provider + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(elementProvider); + assertEquals(PROVIDER_1, provider.getId()); + + List actual = provider.getSettingEntries(null, null, null); + ICLanguageSettingEntry entry = actual.get(0); + assertTrue(entry instanceof CMacroFileEntry); + CMacroFileEntry macroFileEntry = (CMacroFileEntry)entry; + assertEquals(entries.get(0).getName(), macroFileEntry.getName()); + assertEquals(entries.get(0).getValue(), macroFileEntry.getValue()); + assertEquals(entries.get(0).getKind(), macroFileEntry.getKind()); + assertEquals(entries.get(0).getFlags(), macroFileEntry.getFlags()); + assertEquals(entries.get(0), macroFileEntry); + } + } + + /** + */ + public void testCLibraryPathEntry() throws Exception { + Element elementProvider; + List entries = new ArrayList(); + entries.add(new CLibraryPathEntry("name", 1)); + { + // create a provider and serialize its settings + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + provider.setSettingEntries(null, null, null, entries); + + Document doc = XmlUtil.newDocument(); + Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST); + elementProvider = provider.serialize(rootElement); + } + { + // re-load and check language settings of the newly loaded provider + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(elementProvider); + assertEquals(PROVIDER_1, provider.getId()); + + List actual = provider.getSettingEntries(null, null, null); + ICLanguageSettingEntry entry = actual.get(0); + assertTrue(entry instanceof CLibraryPathEntry); + CLibraryPathEntry libraryPathEntry = (CLibraryPathEntry)entry; + assertEquals(entries.get(0).getName(), libraryPathEntry.getName()); + assertEquals(entries.get(0).getValue(), libraryPathEntry.getValue()); + assertEquals(entries.get(0).getKind(), libraryPathEntry.getKind()); + assertEquals(entries.get(0).getFlags(), libraryPathEntry.getFlags()); + assertEquals(entries.get(0), libraryPathEntry); + } + } + + /** + */ + public void testCLibraryFileEntry() throws Exception { + Element elementProvider; + List entries = new ArrayList(); + entries.add(new CLibraryFileEntry("name", 1)); + { + // create a provider and serialize its settings + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + provider.setSettingEntries(null, null, null, entries); + + Document doc = XmlUtil.newDocument(); + Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST); + elementProvider = provider.serialize(rootElement); + } + { + // re-load and check language settings of the newly loaded provider + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(elementProvider); + assertEquals(PROVIDER_1, provider.getId()); + + List actual = provider.getSettingEntries(null, null, null); + ICLanguageSettingEntry entry = actual.get(0); + assertTrue(entry instanceof CLibraryFileEntry); + CLibraryFileEntry libraryFileEntry = (CLibraryFileEntry)entry; + assertEquals(entries.get(0).getName(), libraryFileEntry.getName()); + assertEquals(entries.get(0).getValue(), libraryFileEntry.getValue()); + assertEquals(entries.get(0).getKind(), libraryFileEntry.getKind()); + assertEquals(entries.get(0).getFlags(), libraryFileEntry.getFlags()); + assertEquals(entries.get(0), libraryFileEntry); + } + } + + /** + */ + public void testMixedSettingEntries() throws Exception { + Element elementProvider; + List entries = new ArrayList(); + entries.add(new CMacroEntry("MACRO0", "value0",1)); + entries.add(new CIncludePathEntry("path0", 1)); + entries.add(new CIncludePathEntry("path1", 1)); + { + // create a provider and serialize its settings + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + provider.setSettingEntries(null, null, null, entries); + + Document doc = XmlUtil.newDocument(); + Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST); + elementProvider = provider.serialize(rootElement); + } + { + // re-load and check language settings of the newly loaded provider + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(elementProvider); + assertEquals(PROVIDER_1, provider.getId()); + + List actual = provider.getSettingEntries(null, null, null); + assertEquals(entries.get(0), actual.get(0)); + assertEquals(entries.get(1), actual.get(1)); + assertEquals(entries.get(2), actual.get(2)); + assertEquals(entries.size(), actual.size()); + } + } + + /** + */ + public void testLanguageAndNull() throws Exception { + Element elementProvider = null; + + List entries = new ArrayList(); + entries.add(new CIncludePathEntry("path0", 0)); + List entries2 = new ArrayList(); + entries2.add(new CIncludePathEntry("path2", 0)); + + { + // create a provider + LanguageSettingsSerializable mockProvider = null; + mockProvider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + mockProvider.setSettingEntries(null, null, null, entries); + mockProvider.setSettingEntries(null, null, LANG_ID, entries2); + + // serialize language settings to DOM + Document doc = XmlUtil.newDocument(); + Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST); + elementProvider = mockProvider.serialize(rootElement); + } + { + // re-load and check language settings of the newly loaded provider + LanguageSettingsSerializable loadedProvider = new LanguageSettingsSerializable(elementProvider); + + List actual = loadedProvider.getSettingEntries(null, null, null); + assertEquals(entries.get(0), actual.get(0)); + assertEquals(entries.size(), actual.size()); + + List actual2 = loadedProvider.getSettingEntries(null, null, LANG_ID); + assertEquals(entries2.get(0), actual2.get(0)); + assertEquals(entries2.size(), actual2.size()); + } + } + + /** + */ + public void testTwoLanguages() throws Exception { + Element elementProvider = null; + + List entries = new ArrayList(); + entries.add(new CIncludePathEntry("path0", 0)); + List entries2 = new ArrayList(); + entries2.add(new CIncludePathEntry("path2", 0)); + + { + // create a provider + LanguageSettingsSerializable mockProvider = null; + mockProvider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + mockProvider.setSettingEntries(null, null, LANG_ID_1, entries); + mockProvider.setSettingEntries(null, null, LANG_ID_2, entries2); + + // serialize language settings to DOM + Document doc = XmlUtil.newDocument(); + Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST); + elementProvider = mockProvider.serialize(rootElement); + String xml = XmlUtil.toString(elementProvider.getOwnerDocument()); +// fail(xml); // for debugging + } + { + // re-load and check language settings of the newly loaded provider + LanguageSettingsSerializable loadedProvider = new LanguageSettingsSerializable(elementProvider); + + List actual = loadedProvider.getSettingEntries(null, null, LANG_ID_1); + assertEquals(entries.get(0), actual.get(0)); + assertEquals(entries.size(), actual.size()); + + List actual2 = loadedProvider.getSettingEntries(null, null, LANG_ID_2); + assertEquals(entries2.get(0), actual2.get(0)); + assertEquals(entries2.size(), actual2.size()); + } + } + + /** + */ + public void testTwoResources() throws Exception { + // Create resources + IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName()); + IFile rc1 = ResourceHelper.createFile(project, "rc1"); + assertNotNull(rc1); + IFile rc2 = ResourceHelper.createFile(project, "rc2"); + assertNotNull(rc2); + assertFalse(rc1.getFullPath().equals(rc2.getFullPath())); + + Element elementProvider = null; + + List entries = new ArrayList(); + entries.add(new CIncludePathEntry("path0", 0)); + List entries2 = new ArrayList(); + entries2.add(new CIncludePathEntry("path2", 0)); + + { + // create a provider + LanguageSettingsSerializable mockProvider = null; + mockProvider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + mockProvider.setSettingEntries(null, rc1, null, entries); + mockProvider.setSettingEntries(null, rc2, null, entries2); + + // serialize language settings to DOM + Document doc = XmlUtil.newDocument(); + Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST); + elementProvider = mockProvider.serialize(rootElement); + String xml = XmlUtil.toString(elementProvider.getOwnerDocument()); +// fail(xml); // for debugging + } + { + // re-load and check language settings of the newly loaded provider + LanguageSettingsSerializable loadedProvider = new LanguageSettingsSerializable(elementProvider); + + List actual = loadedProvider.getSettingEntries(null, rc1, null); + assertEquals(entries.get(0), actual.get(0)); + assertEquals(entries.size(), actual.size()); + + List actual2 = loadedProvider.getSettingEntries(null, rc2, null); + assertEquals(entries2.get(0), actual2.get(0)); + assertEquals(entries2.size(), actual2.size()); + } + } + + /** + */ + public void testParentFolder() throws Exception { + // Create model project and accompanied descriptions + IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName()); + + // Create resources + IFolder parentFolder = ResourceHelper.createFolder(project, "/ParentFolder/"); + assertNotNull(parentFolder); + IFile emptySettingsPath = ResourceHelper.createFile(project, "/ParentFolder/Subfolder/empty"); + assertNotNull(emptySettingsPath); + + // Create provider + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + + // store the entries in parent folder + List entries = new ArrayList(); + entries.add(new CIncludePathEntry("path0", 0)); + provider.setSettingEntries(null, parentFolder, LANG_ID, entries); + provider.setSettingEntries(null, emptySettingsPath, LANG_ID, new ArrayList()); + + { + // retrieve entries for a parent folder itself + List actual = provider.getSettingEntries(null, parentFolder, LANG_ID); + assertEquals(entries,actual); + assertEquals(entries.size(), actual.size()); + } + + { + // retrieve entries for a derived resource (in a subfolder) + IFile derived = ResourceHelper.createFile(project, "/ParentFolder/Subfolder/resource"); + List actual = provider.getSettingEntries(null, derived, LANG_ID); + // NOT taken from parent folder + assertEquals(null,actual); + } + + { + // retrieve entries for not related resource + IFile notRelated = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("/AnotherFolder/Subfolder/resource")); + List actual = provider.getSettingEntries(null, notRelated, LANG_ID); + assertEquals(null,actual); + } + + { + // test distinction between no settings and empty settings + List actual = provider.getSettingEntries(null, emptySettingsPath, LANG_ID); + // NOT taken from parent folder and not null + assertEquals(0, actual.size()); + } + } + + /** + */ + public void testEquals() throws Exception { + List sampleEntries_1 = new ArrayList(); + sampleEntries_1.add(new CMacroEntry("MACRO0", "value0",1)); + sampleEntries_1.add(new CIncludePathEntry("path0", 1)); + sampleEntries_1.add(new CIncludePathEntry("path1", 1)); + + List sampleEntries_2 = new ArrayList(); + sampleEntries_2.add(new CIncludePathEntry("path0", 1)); + + List sampleLanguages = new ArrayList(); + sampleLanguages.add(LANG_ID); + + // create a model provider + LanguageSettingsSerializable provider1 = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + provider1.setLanguageScope(sampleLanguages); + provider1.setCustomParameter(CUSTOM_PARAMETER); + provider1.setSettingEntries(MOCK_CFG, MOCK_RC, LANG_ID, sampleEntries_1); + provider1.setSettingEntries(null, null, LANG_ID, sampleEntries_2); + + { + // create another provider with the same data + LanguageSettingsSerializable provider2 = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + assertFalse(provider1.equals(provider2)); + assertFalse(provider1.hashCode()==provider2.hashCode()); + + provider2.setSettingEntries(MOCK_CFG, MOCK_RC, LANG_ID, sampleEntries_1); + assertFalse(provider1.equals(provider2)); + assertFalse(provider1.hashCode()==provider2.hashCode()); + + provider2.setSettingEntries(null, null, LANG_ID, sampleEntries_2); + assertFalse(provider1.equals(provider2)); + assertFalse(provider1.hashCode()==provider2.hashCode()); + + provider2.setLanguageScope(sampleLanguages); + assertFalse(provider1.equals(provider2)); + assertFalse(provider1.hashCode()==provider2.hashCode()); + + provider2.setCustomParameter(CUSTOM_PARAMETER); + assertTrue(provider1.equals(provider2)); + assertTrue(provider1.hashCode()==provider2.hashCode()); + + // check different ID + provider2.setId(PROVIDER_2); + assertFalse(provider1.equals(provider2)); + assertFalse(provider1.hashCode()==provider2.hashCode()); + } + + { + // check that subclasses are not equal + LanguageSettingsSerializable providerSub1 = new LanguageSettingsSerializable() {}; + LanguageSettingsSerializable providerSub2 = new LanguageSettingsSerializable() {}; + assertFalse(providerSub1.equals(providerSub2)); + assertFalse(providerSub1.hashCode()==providerSub2.hashCode()); + } + } + + /** + */ + public void testClone() throws Exception { + // define sample data + List sampleEntries_1 = new ArrayList(); + sampleEntries_1.add(new CMacroEntry("MACRO0", "value0",1)); + sampleEntries_1.add(new CIncludePathEntry("path0", 1)); + sampleEntries_1.add(new CIncludePathEntry("path1", 1)); + + List sampleEntries_2 = new ArrayList(); + sampleEntries_2.add(new CIncludePathEntry("path0", 1)); + + List sampleLanguages = new ArrayList(); + sampleLanguages.add(LANG_ID); + + // create a model provider + class LanguageSettingsSerializableMock extends LanguageSettingsSerializable implements Cloneable { + public LanguageSettingsSerializableMock(String id, String name) { + super(id, name); + } + @Override + public LanguageSettingsSerializableMock clone() throws CloneNotSupportedException { + return (LanguageSettingsSerializableMock) super.clone(); + } + + } + LanguageSettingsSerializableMock provider1 = new LanguageSettingsSerializableMock(PROVIDER_1, PROVIDER_NAME_1); + provider1.setLanguageScope(sampleLanguages); + provider1.setCustomParameter(CUSTOM_PARAMETER); + provider1.setSettingEntries(MOCK_CFG, MOCK_RC, LANG_ID, sampleEntries_1); + provider1.setSettingEntries(null, null, LANG_ID, sampleEntries_2); + + // clone provider + LanguageSettingsSerializableMock providerClone = provider1.clone(); + assertNotSame(provider1, providerClone); + assertTrue(provider1.equals(providerClone)); + assertTrue(provider1.getClass()==providerClone.getClass()); + assertEquals(provider1.getCustomParameter(), providerClone.getCustomParameter()); + assertEquals(provider1.getLanguageScope().get(0), providerClone.getLanguageScope().get(0)); + + List actual1 = providerClone.getSettingEntries(MOCK_CFG, MOCK_RC, LANG_ID); + assertNotSame(sampleEntries_1, actual1); + assertEquals(sampleEntries_1.get(0), actual1.get(0)); + assertEquals(sampleEntries_1.get(1), actual1.get(1)); + assertEquals(sampleEntries_1.get(2), actual1.get(2)); + assertEquals(sampleEntries_1.size(), actual1.size()); + + List actual2 = providerClone.getSettingEntries(null, null, LANG_ID); + assertNotSame(sampleEntries_2, actual2); + assertEquals(sampleEntries_2.get(0), actual2.get(0)); + assertEquals(sampleEntries_2.size(), actual2.size()); + } + + /** + */ + public void testCloneShallow() throws Exception { + // define sample data + List sampleLanguages = new ArrayList(); + sampleLanguages.add(LANG_ID); + + // create a model provider + class LanguageSettingsSerializableMock extends LanguageSettingsSerializable implements Cloneable { + public LanguageSettingsSerializableMock(String id, String name) { + super(id, name); + } + @Override + public LanguageSettingsSerializableMock cloneShallow() throws CloneNotSupportedException { + return (LanguageSettingsSerializableMock) super.cloneShallow(); + } + + } + LanguageSettingsSerializableMock provider1 = new LanguageSettingsSerializableMock(PROVIDER_1, PROVIDER_NAME_1); + provider1.setLanguageScope(sampleLanguages); + provider1.setCustomParameter(CUSTOM_PARAMETER); + + List entries = new ArrayList(); + entries.add(new CIncludePathEntry("path", 1)); + provider1.setSettingEntries(null, null, null, entries); + + // clone provider + LanguageSettingsSerializableMock providerClone = provider1.cloneShallow(); + assertNotSame(provider1, providerClone); + assertFalse(provider1.equals(providerClone)); + assertTrue(provider1.getClass()==providerClone.getClass()); + assertEquals(provider1.getCustomParameter(), providerClone.getCustomParameter()); + assertEquals(provider1.getLanguageScope().get(0), providerClone.getLanguageScope().get(0)); + + List actual = providerClone.getSettingEntries(null, null, null); + assertNull(actual); + } +} + + diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockLanguageSettingsBaseProvider.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockLanguageSettingsBaseProvider.java new file mode 100644 index 00000000000..afae2a4cb50 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockLanguageSettingsBaseProvider.java @@ -0,0 +1,19 @@ +/******************************************************************************* + * Copyright (c) 2009, 2009 Andrew Gvozdev (Quoin Inc.) 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 (Quoin Inc.) - initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.core.language.settings.providers; + +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsBaseProvider; + + +public class MockLanguageSettingsBaseProvider extends LanguageSettingsBaseProvider { + +} diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockLanguageSettingsEditableProvider.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockLanguageSettingsEditableProvider.java new file mode 100644 index 00000000000..bdb11b3d7e7 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockLanguageSettingsEditableProvider.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2009, 2011 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.core.language.settings.providers; + +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable; +import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider; + + +public class MockLanguageSettingsEditableProvider extends LanguageSettingsSerializable implements ILanguageSettingsEditableProvider { + public MockLanguageSettingsEditableProvider() { + super(); + } + + public MockLanguageSettingsEditableProvider cloneShallow() throws CloneNotSupportedException { + return (MockLanguageSettingsEditableProvider) super.cloneShallow(); + } + + public MockLanguageSettingsEditableProvider clone() throws CloneNotSupportedException { + return (MockLanguageSettingsEditableProvider) super.clone(); + } +} diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockLanguageSettingsProvider.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockLanguageSettingsProvider.java new file mode 100644 index 00000000000..96024c7db45 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockLanguageSettingsProvider.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2009, 2009 Andrew Gvozdev (Quoin Inc.) 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 (Quoin Inc.) - initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.core.language.settings.providers; + +import java.util.List; + +import org.eclipse.cdt.core.AbstractExecutableExtensionBase; +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; +import org.eclipse.core.resources.IResource; + +public class MockLanguageSettingsProvider extends AbstractExecutableExtensionBase + implements ILanguageSettingsProvider { + + public List getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) { + return null; + } +} diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockLanguageSettingsSerializableProvider.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockLanguageSettingsSerializableProvider.java new file mode 100644 index 00000000000..276a3400b93 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockLanguageSettingsSerializableProvider.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2009, 2009 Andrew Gvozdev (Quoin Inc.) 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 (Quoin Inc.) - initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.core.language.settings.providers; + +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable; + + +public class MockLanguageSettingsSerializableProvider extends LanguageSettingsSerializable { + public MockLanguageSettingsSerializableProvider() { + super(); + } + + public MockLanguageSettingsSerializableProvider(String id, String name) { + super(id, name); + } +} diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/AllCoreTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/AllCoreTests.java index b6738d6a07d..7544599c04b 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/AllCoreTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/AllCoreTests.java @@ -14,6 +14,7 @@ package org.eclipse.cdt.core.model.tests; import junit.framework.Test; import junit.framework.TestSuite; +import org.eclipse.cdt.core.language.settings.providers.AllLanguageSettingsProvidersTests; import org.eclipse.cdt.core.settings.model.AllCProjectDescriptionTests; import org.eclipse.cdt.core.settings.model.PathSettingsContainerTests; @@ -60,6 +61,8 @@ public class AllCoreTests { suite.addTest(AsmModelBuilderTest.suite()); suite.addTest(CModelBuilderBugsTest.suite()); suite.addTest(Bug311189.suite()); + + suite.addTest(AllLanguageSettingsProvidersTests.suite()); return suite; } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexProviderManagerTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexProviderManagerTest.java index c4cb84e7459..de9df4893f5 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexProviderManagerTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexProviderManagerTest.java @@ -25,6 +25,7 @@ import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.index.provider.IIndexProvider; import org.eclipse.cdt.core.internal.index.provider.test.DummyProviderTraces; import org.eclipse.cdt.core.internal.index.provider.test.Providers; +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.parser.util.ArrayUtil; @@ -704,6 +705,12 @@ class MockConfig implements ICConfigurationDescription { } public void setReadOnly(boolean readOnly, boolean keepModify) {} + + public void setLanguageSettingProviders(List providers) {} + + public List getLanguageSettingProviders() { + return null; + } } /* diff --git a/core/org.eclipse.cdt.core.tests/plugin.xml b/core/org.eclipse.cdt.core.tests/plugin.xml index 4e9b99437e5..4c4418fc9fe 100644 --- a/core/org.eclipse.cdt.core.tests/plugin.xml +++ b/core/org.eclipse.cdt.core.tests/plugin.xml @@ -159,6 +159,13 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + getReferenceInfo() { + return null; + } + + public void setReferenceInfo(Map refs) throws WriteAccessException { + } + + public ICExternalSetting[] getExternalSettings() { + return null; + } + + public ICExternalSetting createExternalSetting(String[] languageIDs, + String[] contentTypeIds, String[] extensions, + ICSettingEntry[] entries) throws WriteAccessException { + return null; + } + + public void removeExternalSetting(ICExternalSetting setting) throws WriteAccessException { + } + + public void removeExternalSettings() throws WriteAccessException { + } + + public ICBuildSetting getBuildSetting() { + return null; + } + + public ICdtVariablesContributor getBuildVariablesContributor() { + return null; + } + + public Object getSessionProperty(QualifiedName name) { + return null; + } + + public void setSessionProperty(QualifiedName name, Object value) { + } + + public void setName(String name) throws WriteAccessException { + } + + public ICConfigExtensionReference[] get(String extensionPointID) { + return null; + } + + public ICConfigExtensionReference create(String extensionPoint, String extension) throws CoreException { + return null; + } + + public void remove(ICConfigExtensionReference ext) throws CoreException { + } + + public void remove(String extensionPoint) throws CoreException { + } + + public boolean isPreferenceConfiguration() { + return false; + } + + public ICLanguageSetting getLanguageSettingForFile(IPath path, boolean ignoreExludeStatus) { + return null; + } + + public void setExternalSettingsProviderIds(String[] ids) { + } + + public String[] getExternalSettingsProviderIds() { + return null; + } + + public void updateExternalSettingsProviders(String[] ids) throws WriteAccessException { + } + + public CConfigurationStatus getConfigurationStatus() { + return null; + } + + public void setLanguageSettingProviders(List providers) { + } + + public List getLanguageSettingProviders() { + return null; + } + + } +} diff --git a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF index 238adb9b4f9..0949e2d8844 100644 --- a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF +++ b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF @@ -27,6 +27,7 @@ Export-Package: org.eclipse.cdt.core, org.eclipse.cdt.core.index.export, org.eclipse.cdt.core.index.provider, org.eclipse.cdt.core.language, + org.eclipse.cdt.core.language.settings.providers, org.eclipse.cdt.core.model, org.eclipse.cdt.core.model.util, org.eclipse.cdt.core.parser, @@ -66,6 +67,7 @@ Export-Package: org.eclipse.cdt.core, org.eclipse.cdt.internal.core.index.provider;x-internal:=true, org.eclipse.cdt.internal.core.indexer;x-internal:=true, org.eclipse.cdt.internal.core.language;x-friends:="org.eclipse.cdt.ui", + org.eclipse.cdt.internal.core.language.settings.providers;x-internal:=true, org.eclipse.cdt.internal.core.model;x-friends:="org.eclipse.cdt.ui,org.eclipse.cdt.debug.core,org.eclipse.cdt.debug.ui", org.eclipse.cdt.internal.core.model.ext;x-friends:="org.eclipse.cdt.ui", org.eclipse.cdt.internal.core.parser;x-internal:=true, diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsProvider.java new file mode 100644 index 00000000000..e8a30f39a24 --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsProvider.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2009, 2010 Andrew Gvozdev (Quoin Inc.) 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 (Quoin Inc.) - initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.core.language.settings.providers; + +import java.util.List; + +import org.eclipse.cdt.core.model.LanguageManager; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; +import org.eclipse.cdt.core.settings.model.ICSettingEntry; +import org.eclipse.core.resources.IResource; + +/** + * Base interface to provide list of {@link ICLanguageSettingEntry}. + * This interface is used to deliver additions to compiler options such as + * include paths (-I) or preprocessor defines (-D) and others (see + * {@link ICSettingEntry#INCLUDE_PATH} and other kinds). + * + * To define a provider like that use extension point + * {@code org.eclipse.cdt.core.LanguageSettingsProvider} and implement this + * interface. CDT provides a few general use implementations such as + * {@link LanguageSettingsBaseProvider} which could be used out of the box or + * extended. See extension point schema description LanguageSettingsProvider.exsd + * for more details. + * + * @since 6.0 + */ +public interface ILanguageSettingsProvider { + /** + * Id is used to keep track of the providers internally. Use unique id + * to represent the provider. + * + * @return Id of the provider. + */ + public String getId(); + + /** + * Name is used to present the provider to the end user in UI. + * + * @return name of the provider. + */ + public String getName(); + + /** + * Returns the list of setting entries for the given configuration description, + * resource and language. + * + * @param cfgDescription - configuration description. + * @param rc - resource such as file or folder. + * @param languageId - language id + * (see {@link LanguageManager#getLanguageForFile(org.eclipse.core.resources.IFile, ICConfigurationDescription)}). + * + * @return the list of setting entries or {@code null} if no settings defined. + */ + public List getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId); +} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsBaseProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsBaseProvider.java new file mode 100644 index 00000000000..a97bb4ce46c --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsBaseProvider.java @@ -0,0 +1,175 @@ +/******************************************************************************* + * Copyright (c) 2009, 2010 Andrew Gvozdev (Quoin Inc.) 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 (Quoin Inc.) - initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.core.language.settings.providers; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.eclipse.cdt.core.AbstractExecutableExtensionBase; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; +import org.eclipse.cdt.internal.core.settings.model.SettingsModelMessages; +import org.eclipse.core.resources.IResource; + +/** + * {@code LanguageSettingsBaseProvider} is a basic implementation of {@link ILanguageSettingsProvider} + * defined in {@code org.eclipse.cdt.core.LanguageSettingsProvider} extension point. + * + * This implementation supports "static" list of entries for languages specified in + * the extension point. + * + * @since 6.0 + */ +public class LanguageSettingsBaseProvider extends AbstractExecutableExtensionBase implements ILanguageSettingsProvider { + /** Language scope, i.e. list of languages the entries will be provided for. */ + protected List languageScope = null; + + /** Custom parameter. Intended for providers extending this class. */ + protected String customParameter = null; + + /** List of entries defined by this provider. */ + private List entries = null; + + /** + * Default constructor. + */ + public LanguageSettingsBaseProvider() { + } + + /** + * Constructor. Creates an "empty" provider. + * + * @param id - id of the provider. + * @param name - name of the provider to be presented to a user. + */ + public LanguageSettingsBaseProvider(String id, String name) { + super(id, name); + } + + /** + * Constructor. + * + * @param id - id of the provider. + * @param name - name of the provider to be presented to a user. + * @param languages - list of languages the {@code entries} provided for. + * {@code languages} can be {@code null}, in this case the {@code entries} + * are provided for any language. + * @param entries - the list of language settings entries this provider provides. + * If {@code null} is passed, the provider creates an empty list. + */ + public LanguageSettingsBaseProvider(String id, String name, List languages, List entries) { + super(id, name); + this.languageScope = languages!=null ? new ArrayList(languages) : null; + this.entries = cloneList(entries); + } + + /** + * Constructor. + * + * @param id - id of the provider. + * @param name - name of the provider to be presented to a user. + * @param languages - list of languages the {@code entries} provided for. + * {@code languages} can be {@code null}, in this case the {@code entries} + * are provided for any language. + * @param entries - the list of language settings entries this provider provides. + * If {@code null} is passed, the provider creates an empty list. + * @param customParameter - a custom parameter as the means to customize + * providers extending this class. + */ + public LanguageSettingsBaseProvider(String id, String name, List languages, List entries, String customParameter) { + super(id, name); + this.languageScope = languages!=null ? new ArrayList(languages) : null; + this.entries = cloneList(entries); + this.customParameter = customParameter; + } + + /** + * A method to configure the provider. The initialization of provider from + * the extension point is done in 2 steps. First, the class is created as + * an executable extension using the default provider. Then this method is + * used to configure the provider. + * + * FIXME It is not allowed to reconfigure the provider. + * + * @param id - id of the provider. + * @param name - name of the provider to be presented to a user. + * @param languages - list of languages the {@code entries} provided for. + * {@code languages} can be {@code null}, in this case the {@code entries} + * are provided for any language. + * @param entries - the list of language settings entries this provider provides. + * If {@code null} is passed, the provider creates an empty list. + * @param customParameter - a custom parameter as the means to customize + * providers extending this class from extension definition in {@code plugin.xml}. + * + * FIXME @throws UnsupportedOperationException if an attempt to reconfigure provider is made. + */ + public void configureProvider(String id, String name, List languages, List entries, String customParameter) { +// if (this.entries!=null) +// throw new UnsupportedOperationException(SettingsModelMessages.getString("LanguageSettingsBaseProvider.CanBeConfiguredOnlyOnce")); //$NON-NLS-1$ + + setId(id); + setName(name); + this.languageScope = languages!=null ? new ArrayList(languages) : null; + this.entries = cloneList(entries); + this.customParameter = customParameter; + } + + /** + * {@inheritDoc} + * @param cfgDescription - configuration description. + * @param rc - resource such as file or folder. + * @param languageId - language id. If {@code null}, then entries defined for + * the language scope are returned. See {@link #getLanguageScope()} + */ + public List getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) { + if (languageScope==null) { + if (entries==null) + return null; + return Collections.unmodifiableList(entries); + } + for (String lang : languageScope) { + if (lang.equals(languageId)) { + if (entries==null) + return null; + return Collections.unmodifiableList(entries); + } + } + return null; + } + + /** + * @return the list of languages this provider provides for. + * If {@code null}, the provider provides for any language. + */ + public List getLanguageScope() { + if (languageScope==null) + return null; + return Collections.unmodifiableList(languageScope); + } + + /** + * @return the custom parameter defined in the extension in {@code plugin.xml}. + */ + public String getCustomParameter() { + return customParameter; + } + + /** + * @param entries + * @return copy of the list of the entries. + */ + private List cloneList(List entries) { + return entries!=null ? new ArrayList(entries) : null; + } + +} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java new file mode 100644 index 00000000000..b837908fe1f --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java @@ -0,0 +1,204 @@ +/******************************************************************************* + * Copyright (c) 2009, 2010 Andrew Gvozdev (Quoin Inc.) 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 (Quoin Inc.) - initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.core.language.settings.providers; + +import java.util.List; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; +import org.eclipse.cdt.core.settings.model.ICSettingEntry; +import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider; +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.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.preferences.InstanceScope; +import org.osgi.service.prefs.BackingStoreException; +import org.osgi.service.prefs.Preferences; + +/** + * A collection of utility methods to manage language settings providers. + * See {@link ILanguageSettingsProvider}. + * + * @since 6.0 + */ +public class LanguageSettingsManager { + /** @noreference This field is temporary and not intended to be referenced by clients. */ + public static String USE_LANGUAGE_SETTINGS_PROVIDERS_PREFERENCE = "enabled"; //$NON-NLS-1$ + public static boolean USE_LANGUAGE_SETTINGS_PROVIDERS_DEFAULT = true; + + private static final String PREFERENCES_QUALIFIER = CCorePlugin.PLUGIN_ID; + private static final String LANGUAGE_SETTINGS_PROVIDERS_NODE = "languageSettingsProviders"; //$NON-NLS-1$ + + /** + * Returns the list of setting entries of the given provider + * for the given configuration description, resource and language. + * This method reaches to the parent folder of the resource recursively + * in case the resource does not define the entries for the given provider. + * + * @param provider - language settings provider. + * @param cfgDescription - configuration description. + * @param rc - resource such as file or folder. + * @param languageId - language id. + * + * @return the list of setting entries. Never returns {@code null} + * although individual providers return {@code null} if no settings defined. + */ + public static List getSettingEntriesUpResourceTree(ILanguageSettingsProvider provider, ICConfigurationDescription cfgDescription, IResource rc, String languageId) { + return LanguageSettingsExtensionManager.getSettingEntriesUpResourceTree(provider, cfgDescription, rc, languageId); + } + + /** + * Returns the list of setting entries of a certain kind (such as include paths) + * for the given configuration description, resource and language. This is a + * combined list for all providers taking into account settings of parent folder + * if settings for the given resource are not defined. + * + * @param cfgDescription - configuration description. + * @param rc - resource such as file or folder. + * @param languageId - language id. + * @param kind - kind of language settings entries, such as + * {@link ICSettingEntry#INCLUDE_PATH} etc. This is a binary flag + * and it is possible to specify composite kind. + * Use {@link ICSettingEntry#ALL} to get all kinds. + * + * @return the list of setting entries. + */ + // FIXME: get rid of callers PathEntryTranslator and DescriptionScannerInfoProvider + public static List getSettingEntriesByKind(ICConfigurationDescription cfgDescription, IResource rc, String languageId, int kind) { + return LanguageSettingsExtensionManager.getSettingEntriesByKind(cfgDescription, rc, languageId, kind); + } + + /** + * Get Language Settings Provider defined in the workspace. That includes user-defined + * providers and after that providers defined as extensions via + * {@code org.eclipse.cdt.core.LanguageSettingsProvider} extension point. + * That returns actual object, any modifications will affect any configuration + * referring to the provider. + * + * @param id - id of provider to find. + * @return the provider or {@code null} if provider is not defined. + */ + public static ILanguageSettingsProvider getWorkspaceProvider(String id) { + return LanguageSettingsProvidersSerializer.getWorkspaceProvider(id); + } + + /** + * @return a list of language settings providers defined on workspace level. + * That includes user-defined providers and after that providers defined as + * extensions via {@code org.eclipse.cdt.core.LanguageSettingsProvider} + * extension point. + */ + public static List getWorkspaceProviders() { + return LanguageSettingsProvidersSerializer.getWorkspaceProviders(); + } + + /** + * Checks if the provider is defined on the workspace level. + * + * @param provider - provider to check. + * @return {@code true} if the given provider is workspace provider, {@code false} otherwise. + */ + public static boolean isWorkspaceProvider(ILanguageSettingsProvider provider) { + return LanguageSettingsProvidersSerializer.isWorkspaceProvider(provider); + } + + /** + * TODO - helper method for often used chunk of code + * @param provider + * @return ILanguageSettingsProvider + */ + public static ILanguageSettingsProvider getRawProvider(ILanguageSettingsProvider provider) { + if (LanguageSettingsManager.isWorkspaceProvider(provider)){ + provider = LanguageSettingsProvidersSerializer.getRawWorkspaceProvider(provider.getId()); + } + return provider; + } + + + /** + * Set and store in workspace area user defined providers. + * + * @param providers - array of user defined workspace providers. + * Note that those providers will shadow extension providers with the same ID. + * All not shadowed extension providers will be added to the list to be present + * as workspace providers. {@code null} is equivalent to passing an empty array + * and so will reset workspace providers to match extension providers. + * @throws CoreException in case of problems (such as problems with persistence). + */ + public static void setWorkspaceProviders(List providers) throws CoreException { + LanguageSettingsProvidersSerializer.setWorkspaceProviders(providers); + } + + /** + * Get Language Settings Provider defined via + * {@code org.eclipse.cdt.core.LanguageSettingsProvider} extension point. + * + * @param id - ID of provider to find. + * @return the copy of the provider if possible (i.e. for {@link ILanguageSettingsEditableProvider}) + * or workspace provider if provider is not copyable. + */ + public static ILanguageSettingsProvider getExtensionProviderCopy(String id) { + ILanguageSettingsProvider provider = null; + try { + provider = LanguageSettingsExtensionManager.getExtensionProviderClone(id); + } catch (CloneNotSupportedException e) { + // from here falls to get workspace provider + } + if (provider==null) + provider = LanguageSettingsManager.getWorkspaceProvider(id); + + return provider; + } + + private static Preferences getPreferences(IProject project) { + if (project == null) + return InstanceScope.INSTANCE.getNode(PREFERENCES_QUALIFIER).node(LANGUAGE_SETTINGS_PROVIDERS_NODE); + else + return new LocalProjectScope(project).getNode(PREFERENCES_QUALIFIER).node(LANGUAGE_SETTINGS_PROVIDERS_NODE); + } + + /** + * Checks if Language Settings functionality is enabled for given project. + * + * @param project - project to check the preference + * @return {@code true} if functionality is enabled + * + * @noreference This method is temporary and not intended to be referenced by clients. + */ + public static boolean isLanguageSettingsProvidersEnabled(IProject project) { + Preferences pref = LanguageSettingsManager.getPreferences(project); + return pref.getBoolean(LanguageSettingsManager.USE_LANGUAGE_SETTINGS_PROVIDERS_PREFERENCE, LanguageSettingsManager.USE_LANGUAGE_SETTINGS_PROVIDERS_DEFAULT); + } + + /** + * Enable/disable Language Settings functionality for the given project. + * + * @param project + * @param value {@code true} to enable or {@code false} to disable the functionality. + * + * @noreference This method is temporary and not intended to be referenced by clients. + */ + public static void setLanguageSettingsProvidersEnabled(IProject project, boolean value) { + Preferences pref = LanguageSettingsManager.getPreferences(project); + pref.putBoolean(LanguageSettingsManager.USE_LANGUAGE_SETTINGS_PROVIDERS_PREFERENCE, value); + try { + pref.flush(); + } catch (BackingStoreException e) { + CCorePlugin.log(e); + } + } + +} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager_TBD.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager_TBD.java new file mode 100644 index 00000000000..b92da74a593 --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager_TBD.java @@ -0,0 +1,99 @@ +/******************************************************************************* + * Copyright (c) 2009, 2009 Andrew Gvozdev (Quoin Inc.) 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 (Quoin Inc.) - initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.core.language.settings.providers; + +import java.util.List; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICFileDescription; +import org.eclipse.cdt.core.settings.model.ICFolderDescription; +import org.eclipse.cdt.core.settings.model.ICLanguageSetting; +import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; +import org.eclipse.cdt.core.settings.model.ICResourceDescription; +import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider; +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.resources.IResource; +import org.eclipse.core.runtime.CoreException; + +/** + * TODO + * This layer of language settings in TODO + * + * Duplicate entries are filtered where only first entry is preserved. + * + */ +public class LanguageSettingsManager_TBD { + public static final String PROVIDER_UNKNOWN = "org.eclipse.cdt.projectmodel.4.0.0"; + public static final String PROVIDER_UI_USER = "org.eclipse.cdt.ui.user.LanguageSettingsProvider"; + public static final char PROVIDER_DELIMITER = LanguageSettingsProvidersSerializer.PROVIDER_DELIMITER; + + private static ICLanguageSetting[] getLanguageIds(ICResourceDescription rcDescription) { + if (rcDescription instanceof ICFileDescription) { + ICFileDescription fileDescription = (ICFileDescription)rcDescription; + return new ICLanguageSetting[] {fileDescription.getLanguageSetting()}; + } else if (rcDescription instanceof ICFolderDescription) { + ICFolderDescription folderDescription = (ICFolderDescription)rcDescription; + return folderDescription.getLanguageSettings(); + } + + return null; + } + + public static boolean isCustomizedResource(ICConfigurationDescription cfgDescription, IResource rc) { + if (rc instanceof IProject) + return false; + + for (ILanguageSettingsProvider provider: cfgDescription.getLanguageSettingProviders()) { + // FIXME +// if (!LanguageSettingsManager.isWorkspaceProvider(provider)) { + if (provider instanceof ILanguageSettingsEditableProvider || provider instanceof LanguageSettingsSerializable) { + ICResourceDescription rcDescription = cfgDescription.getResourceDescription(rc.getProjectRelativePath(), false); + for (ICLanguageSetting languageSetting : getLanguageIds(rcDescription)) { + String languageId = languageSetting.getLanguageId(); + if (languageId!=null) { + List list = provider.getSettingEntries(cfgDescription, rc, languageId); + if (list!=null) { + List listDefault = provider.getSettingEntries(null, null, languageId); + if (!list.equals(listDefault)) + return true; + } + } + } + } + } + + return false; + } + + @Deprecated // Shouldn't be API + public static void serializeWorkspaceProviders() throws CoreException { + LanguageSettingsProvidersSerializer.serializeLanguageSettingsWorkspace(); + } + + public static boolean isReconfigured(ILanguageSettingsProvider provider) { + if (provider instanceof ILanguageSettingsEditableProvider) { + try { + return ! LanguageSettingsExtensionManager.equalsExtensionProviderShallow((ILanguageSettingsEditableProvider) provider); + } catch (Exception e) { + CCorePlugin.log("Internal Error: cannot clone provider "+provider.getId(), e); + } + } + return false; + } + + public static boolean isEqualExtensionProvider(ILanguageSettingsProvider provider) { + return LanguageSettingsExtensionManager.equalsExtensionProvider(provider); + } +} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java new file mode 100644 index 00000000000..709a84e67d6 --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java @@ -0,0 +1,504 @@ +/******************************************************************************* + * Copyright (c) 2009, 2010 Andrew Gvozdev (Quoin Inc.) 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 (Quoin Inc.) - initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.core.language.settings.providers; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import org.eclipse.cdt.core.settings.model.CIncludeFileEntry; +import org.eclipse.cdt.core.settings.model.CIncludePathEntry; +import org.eclipse.cdt.core.settings.model.CLibraryFileEntry; +import org.eclipse.cdt.core.settings.model.CLibraryPathEntry; +import org.eclipse.cdt.core.settings.model.CMacroEntry; +import org.eclipse.cdt.core.settings.model.CMacroFileEntry; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; +import org.eclipse.cdt.core.settings.model.ICSettingEntry; +import org.eclipse.cdt.core.settings.model.util.LanguageSettingEntriesSerializer; +import org.eclipse.cdt.internal.core.XmlUtil; +import org.eclipse.core.resources.IResource; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + + +public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { + public static final String ELEM_PROVIDER = "provider"; //$NON-NLS-1$ + private static final String ATTR_ID = "id"; //$NON-NLS-1$ + + private static final String ELEM_LANGUAGE_SCOPE = "language-scope"; //$NON-NLS-1$ + private static final String ELEM_LANGUAGE = "language"; //$NON-NLS-1$ + private static final String ELEM_RESOURCE = "resource"; //$NON-NLS-1$ + private static final String ATTR_PROJECT_PATH = "project-relative-path"; //$NON-NLS-1$ + + private static final String ELEM_ENTRY = "entry"; //$NON-NLS-1$ + private static final String ATTR_KIND = "kind"; //$NON-NLS-1$ + private static final String ATTR_NAME = "name"; //$NON-NLS-1$ + private static final String ATTR_CLASS = "class"; //$NON-NLS-1$ + private static final String ATTR_PARAMETER = "parameter"; //$NON-NLS-1$ + private static final String ATTR_VALUE = "value"; //$NON-NLS-1$ + + private static final String ELEM_FLAG = "flag"; //$NON-NLS-1$ + + + private Map>> fStorage = new HashMap>>(); + + public LanguageSettingsSerializable() { + super(); + } + + public LanguageSettingsSerializable(String id, String name) { + super(id, name); + } + + public LanguageSettingsSerializable(Element elementProvider) { + super(); + load(elementProvider); + } + + @Override + public void configureProvider(String id, String name, List languages, List entries, String customParameter) { + // do not pass entries to super, keep them in local storage + super.configureProvider(id, name, languages, null, customParameter); + + fStorage.clear(); + + if (entries!=null) { + // note that these entries are intended to be retrieved by LanguageSettingsManager.getSettingEntriesUpResourceTree() + // when the whole resource hierarchy has been traversed up + setSettingEntries(null, null, null, entries); + } + } + + /** + * @return {@code true} if the provider does not keep any settings yet or {@code false} if there are some. + */ + public boolean isEmpty() { + return fStorage.isEmpty(); + } + + /** + * Set the language scope of the provider. + * + * @param languages - the list of languages this provider provides for. + * If {@code null}, the provider provides for any language. + * + * @see #getLanguageScope() + */ + public void setLanguageScope(List languages) { + if (languages==null) + this.languageScope = null; + else + this.languageScope = new ArrayList(languages); + } + + public void setCustomParameter(String customParameter) { + this.customParameter = customParameter; + } + + public void clear() { + fStorage.clear(); + } + + // TODO: look for refactoring this method + private void setSettingEntriesInternal(String rcProjectPath, String languageId, List entries) { + if (entries!=null) { + Map> langMap = fStorage.get(languageId); + if (langMap==null) { + langMap = new HashMap>(); + fStorage.put(languageId, langMap); + } + langMap.put(rcProjectPath, entries); + } else { + // do not keep nulls in the tables + Map> langMap = fStorage.get(languageId); + if (langMap!=null) { + langMap.remove(rcProjectPath); + if (langMap.size()==0) { + fStorage.remove(languageId); + } + } + } + } + + /** + * Sets language settings entries for the provider. + * Note that the entries are not persisted at that point. To persist use TODO + * + * @param cfgDescription - configuration description. + * @param rc - resource such as file or folder. + * @param languageId - language id. If {@code null}, then entries are considered to be defined for + * the language scope. See {@link #getLanguageScope()} + * @param entries - language settings entries to set. + */ + public void setSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId, List entries) { + String rcProjectPath = rc!=null ? rc.getProjectRelativePath().toString() : null; + setSettingEntriesInternal(rcProjectPath, languageId, entries); + } + + /** + * {@inheritDoc} + */ + @Override + public List getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) { + Map> langMap = fStorage.get(languageId); + if (langMap!=null) { + String rcProjectPath = rc!=null ? rc.getProjectRelativePath().toString() : null; + List entries = langMap.get(rcProjectPath); + if (entries!=null) + return Collections.unmodifiableList(entries); + } + + if (languageId!=null && (languageScope==null || languageScope.contains(languageId))) { + List entries = getSettingEntries(cfgDescription, rc, null); + return entries; + } + + return null; + } + + /* + + + + + + + + + */ + // provider/configuration/language/resource/entry + public Element serialize(Element parentElement) { + Element elementProvider = XmlUtil.appendElement(parentElement, ELEM_PROVIDER, new String[] { + ATTR_ID, getId(), + ATTR_NAME, getName(), + ATTR_CLASS, getClass().getCanonicalName(), + ATTR_PARAMETER, getCustomParameter(), + }); + + if (languageScope!=null) { + for (String langId : languageScope) { + XmlUtil.appendElement(elementProvider, ELEM_LANGUAGE_SCOPE, new String[] {ATTR_ID, langId}); + } + } + for (Entry>> entryLang : fStorage.entrySet()) { + serializeLanguage(elementProvider, entryLang); + } + return elementProvider; + } + + private void serializeLanguage(Element parentElement, Entry>> entryLang) { + String langId = entryLang.getKey(); + if (langId!=null) { + Element elementLanguage = XmlUtil.appendElement(parentElement, ELEM_LANGUAGE, new String[] {ATTR_ID, langId}); + parentElement = elementLanguage; + } + for (Entry> entryRc : entryLang.getValue().entrySet()) { + serializeResource(parentElement, entryRc); + } + } + + private void serializeResource(Element parentElement, Entry> entryRc) { + String rcProjectPath = entryRc.getKey(); + if (rcProjectPath!=null) { + Element elementRc = XmlUtil.appendElement(parentElement, ELEM_RESOURCE, new String[] {ATTR_PROJECT_PATH, rcProjectPath}); + parentElement = elementRc; + } + serializeSettingEntries(parentElement, entryRc.getValue()); + } + + private void serializeSettingEntries(Element parentElement, List settingEntries) { + for (ICLanguageSettingEntry entry : settingEntries) { + Element elementSettingEntry = XmlUtil.appendElement(parentElement, ELEM_ENTRY, new String[] { + ATTR_KIND, LanguageSettingEntriesSerializer.kindToString(entry.getKind()), + ATTR_NAME, entry.getName(), + }); + switch(entry.getKind()) { + case ICSettingEntry.MACRO: + elementSettingEntry.setAttribute(ATTR_VALUE, entry.getValue()); + break; +// case ICLanguageSettingEntry.LIBRARY_FILE: + // TODO: sourceAttachment fields need to be covered +// break; + } + int flags = entry.getFlags(); + if (flags!=0) { + // Element elementFlag = + XmlUtil.appendElement(elementSettingEntry, ELEM_FLAG, new String[] { + ATTR_VALUE, LanguageSettingEntriesSerializer.composeFlagsString(entry.getFlags()) + }); + } + } + } + + private ICLanguageSettingEntry loadSettingEntry(Node parentElement) { + String settingKind = XmlUtil.determineAttributeValue(parentElement, ATTR_KIND); + String settingName = XmlUtil.determineAttributeValue(parentElement, ATTR_NAME); + + NodeList flagNodes = parentElement.getChildNodes(); + int flags = 0; + for (int i=0;i settings = new ArrayList(); + NodeList nodes = providerNode.getChildNodes(); + for (int i=0;i0) { + setSettingEntriesInternal(null, null, settings); + } + } + } + + private void loadLanguageScopeElement(Node parentNode) { + if (languageScope==null) { + languageScope = new ArrayList(); + } + String id = XmlUtil.determineAttributeValue(parentNode, ATTR_ID); + languageScope.add(id); + + } + + private void loadLanguageElement(Node parentNode, String cfgId) { + String langId = XmlUtil.determineAttributeValue(parentNode, ATTR_ID); + if (langId.length()==0) { + langId=null; + } + + List settings = new ArrayList(); + NodeList nodes = parentNode.getChildNodes(); + for (int i=0;i0) { + setSettingEntriesInternal(null, langId, settings); + } + } + + private void loadResourceElement(Node parentNode, String cfgId, String langId) { + String rcProjectPath = XmlUtil.determineAttributeValue(parentNode, ATTR_PROJECT_PATH); + + List settings = new ArrayList(); + NodeList nodes = parentNode.getChildNodes(); + for (int i=0;i0) { + setSettingEntriesInternal(rcProjectPath, langId, settings); + } + } + + private Map>> cloneStorage() { + Map>> storageClone = new HashMap>>(); +// Set>>>> entrySetCfg = fStorage.entrySet(); +// for (Entry>>> entryCfg : entrySetCfg) { +// String cfgDescriptionId = entryCfg.getKey(); +// Map>> mapLang = entryCfg.getValue(); +// Map>> mapLangClone = new HashMap>>(); + Set>>> entrySetLang = fStorage.entrySet(); + for (Entry>> entryLang : entrySetLang) { + String langId = entryLang.getKey(); + Map> mapRc = entryLang.getValue(); + Map> mapRcClone = new HashMap>(); + Set>> entrySetRc = mapRc.entrySet(); + for (Entry> entryRc : entrySetRc) { + String rcProjectPath = entryRc.getKey(); + List lsEntries = entryRc.getValue(); + List lsEntriesClone = new ArrayList(lsEntries); + mapRcClone.put(rcProjectPath, lsEntriesClone); + } +// mapLangClone.put(langId, mapRcClone); + storageClone.put(langId, mapRcClone); + } +// } + return storageClone; + } + + protected LanguageSettingsSerializable cloneShallow() throws CloneNotSupportedException { + LanguageSettingsSerializable clone = (LanguageSettingsSerializable)super.clone(); + if (languageScope!=null) + clone.languageScope = new ArrayList(languageScope); + + clone.fStorage = new HashMap>>(); + return clone; + } + + /* (non-Javadoc) + * @see java.lang.Object#clone() + */ + @Override + protected LanguageSettingsSerializable clone() throws CloneNotSupportedException { + LanguageSettingsSerializable clone = cloneShallow(); + clone.fStorage = cloneStorage(); + return clone; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((getId() == null) ? 0 : getId().hashCode()); + result = prime * result + ((getName() == null) ? 0 : getName().hashCode()); + result = prime * result + ((languageScope == null) ? 0 : languageScope.hashCode()); + result = prime * result + ((customParameter == null) ? 0 : customParameter.hashCode()); + result = prime * result + ((fStorage == null) ? 0 : fStorage.hashCode()); + result = prime * result + getClass().hashCode(); + return result; + } + + /** + * @return {@code true} if the objects are equal, {@code false } otherwise. + * + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + LanguageSettingsSerializable other = (LanguageSettingsSerializable) obj; + + String id = getId(); + String otherId = other.getId(); + if (id == null) { + if (otherId != null) + return false; + } else if (!id.equals(otherId)) + return false; + + String name = getName(); + String otherName = other.getName(); + if (name == null) { + if (otherName != null) + return false; + } else if (!name.equals(otherName)) + return false; + + if (languageScope == null) { + if (other.languageScope != null) + return false; + } else if (!languageScope.equals(other.languageScope)) + return false; + + if (customParameter == null) { + if (other.customParameter != null) + return false; + } else if (!customParameter.equals(other.customParameter)) + return false; + + if (fStorage == null) { + if (other.fStorage != null) + return false; + } else if (!fStorage.equals(other.fStorage)) + return false; + return true; + } +} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableEditable.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableEditable.java new file mode 100644 index 00000000000..1a0fe61a846 --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableEditable.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2009, 2011 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.core.language.settings.providers; + +// TODO: move ILanguageSettingsEditableProvider here +import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider; + +public class LanguageSettingsSerializableEditable extends LanguageSettingsSerializable implements ILanguageSettingsEditableProvider { + @Override + public LanguageSettingsSerializableEditable clone() throws CloneNotSupportedException { + return (LanguageSettingsSerializableEditable) super.clone(); + } + + @Override + public LanguageSettingsSerializableEditable cloneShallow() throws CloneNotSupportedException { + return (LanguageSettingsSerializableEditable) super.cloneShallow(); + } + +} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ACExclusionFilterEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ACExclusionFilterEntry.java index 061696b7136..fc103cb66e4 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ACExclusionFilterEntry.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ACExclusionFilterEntry.java @@ -36,8 +36,9 @@ public abstract class ACExclusionFilterEntry extends ACPathEntry implements ICEx this.exclusionPatterns = exclusionPatterns != null ? (IPath[])exclusionPatterns.clone() : new IPath[0]; } + /** @since 5.3 */ @Override - protected final boolean isFile() { + public final boolean isFile() { return false; } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ACPathEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ACPathEntry.java index 363b4d6a9a1..a7d0557d3e8 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ACPathEntry.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ACPathEntry.java @@ -15,8 +15,7 @@ import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; -public abstract class ACPathEntry extends ACSettingEntry - implements ICPathEntry { +public abstract class ACPathEntry extends ACSettingEntry implements ICPathEntry { // IPath fFullPath; // IPath fLocation; // private IPath fPath; @@ -67,7 +66,10 @@ public abstract class ACPathEntry extends ACSettingEntry return null; } - protected abstract boolean isFile(); + /** + * @since 5.3 + */ + public abstract boolean isFile(); public IPath getLocation() { if(!isValueWorkspacePath()) diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICConfigurationDescription.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICConfigurationDescription.java index 6e54e180496..e58bc9ad55a 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICConfigurationDescription.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICConfigurationDescription.java @@ -10,9 +10,11 @@ *******************************************************************************/ package org.eclipse.cdt.core.settings.model; +import java.util.List; import java.util.Map; import org.eclipse.cdt.core.cdtvariables.ICdtVariablesContributor; +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.settings.model.extension.CConfigurationData; import org.eclipse.cdt.core.settings.model.extension.CConfigurationDataProvider; @@ -386,4 +388,29 @@ public interface ICConfigurationDescription extends ICSettingContainer, ICSettin void updateExternalSettingsProviders(String[] ids) throws WriteAccessException; CConfigurationStatus getConfigurationStatus(); + + /** + * Sets the list of language settings providers. Language settings providers are + * used to supply language settings {@link ICLanguageSettingEntry} such as include paths + * or preprocessor macros. + * + * @param providers the list of providers to assign to the configuration description. + * + * @since 6.0 + */ + public void setLanguageSettingProviders(List providers); + + /** + * Returns the list of language settings providers. Language settings providers are + * used to supply language settings {@link ICLanguageSettingEntry} such as include paths + * or preprocessor macros. + * + * @return the list of providers to assign to the configuration description. This + * returns immutable list. Use {@link #setLanguageSettingProviders(List)} to change. + * This method does not return {@code null}. + * + * @since 6.0 + */ + public List getLanguageSettingProviders(); + } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICSettingEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICSettingEntry.java index 3adc824a568..4cef66d3750 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICSettingEntry.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICSettingEntry.java @@ -46,6 +46,21 @@ public interface ICSettingEntry { */ int RESOLVED = 1 << 4; + /** + * Flag {@code UNDEFINED} indicates that the entry should not be defined. + * It's main purpose to provide the means to negate entries defined elsewhere. + * + * @since 6.0 + */ + int UNDEFINED = 1 << 5; + + /** + * Flag {@code FRAMEWORKS_MAC} applies for path entries. Such a path entry will be treated + * in a special way to imitate resolving paths by Apple's version of gcc, see bug 69529. + * . + */ + int FRAMEWORKS_MAC = 1 << 6; + int INCLUDE_PATH = 1; int INCLUDE_FILE = 1 << 1; int MACRO = 1 << 2; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ILanguageSettingsEditableProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ILanguageSettingsEditableProvider.java new file mode 100644 index 00000000000..7b15e893d76 --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ILanguageSettingsEditableProvider.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2009, 2009 Andrew Gvozdev (Quoin Inc.) 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 (Quoin Inc.) - initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.core.settings.model; + +import java.util.List; + +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable; +import org.eclipse.core.resources.IResource; + +/** + * This interface is used in UI to identify classes allowing user to modify settings externally + * contrary to some subclasses of {@link LanguageSettingsSerializable} managing + * their settings themselves and not providing such option to the user. + * + */ +public interface ILanguageSettingsEditableProvider extends ILanguageSettingsProvider, Cloneable { + + public void setSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId, List entries); + public boolean isEmpty(); + public void clear(); + + public ILanguageSettingsEditableProvider cloneShallow() throws CloneNotSupportedException; + public ILanguageSettingsEditableProvider clone() throws CloneNotSupportedException; +} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/LanguageSettingEntriesSerializer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/LanguageSettingEntriesSerializer.java index a889fa9f68f..7047e40fd55 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/LanguageSettingEntriesSerializer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/LanguageSettingEntriesSerializer.java @@ -59,6 +59,8 @@ public class LanguageSettingEntriesSerializer { public static final String LOCAL = "LOCAL"; //$NON-NLS-1$ public static final String VALUE_WORKSPACE_PATH = "VALUE_WORKSPACE_PATH"; //$NON-NLS-1$ public static final String RESOLVED = "RESOLVED"; //$NON-NLS-1$ + private static final String UNDEFINED = "UNDEFINED"; //$NON-NLS-1$ + private static final String FRAMEWORK = "FRAMEWORK"; //$NON-NLS-1$ public static final String FLAGS_SEPARATOR = "|"; //$NON-NLS-1$ @@ -280,10 +282,22 @@ public class LanguageSettingEntriesSerializer { buf.append(RESOLVED); } + if((flags & ICLanguageSettingEntry.UNDEFINED) != 0){ + if(buf.length() != 0) + buf.append(FLAGS_SEPARATOR); + + buf.append(UNDEFINED); + } + if((flags & ICLanguageSettingEntry.FRAMEWORKS_MAC) != 0){ + if(buf.length() != 0) + buf.append(FLAGS_SEPARATOR); + + buf.append(FRAMEWORK); + } return buf.toString(); } - private static int composeFlags(String flagsString){ + public static int composeFlags(String flagsString){ if(flagsString == null || flagsString.length() == 0) return 0; @@ -302,6 +316,10 @@ public class LanguageSettingEntriesSerializer { flags |= ICLanguageSettingEntry.VALUE_WORKSPACE_PATH; if(RESOLVED.equals(f)) flags |= ICLanguageSettingEntry.RESOLVED; + if(UNDEFINED.equals(f)) + flags |= ICLanguageSettingEntry.UNDEFINED; + if(FRAMEWORK.equals(f)) + flags |= ICLanguageSettingEntry.FRAMEWORKS_MAC; } return flags; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/PathEntryTranslator.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/PathEntryTranslator.java index f399fdbbdde..e7a41760ebb 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/PathEntryTranslator.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/PathEntryTranslator.java @@ -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.LanguageSettingsManager; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModelUtil; @@ -68,6 +69,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.LanguageSettingsLogger; import org.eclipse.cdt.internal.core.model.APathEntry; import org.eclipse.cdt.internal.core.model.CModelStatus; import org.eclipse.cdt.internal.core.model.PathEntry; @@ -2002,7 +2004,7 @@ public class PathEntryTranslator { } } - public static PathEntryCollector collectEntries(IProject project, ICConfigurationDescription des) { + public static PathEntryCollector collectEntries(IProject project, final ICConfigurationDescription des) { CConfigurationData data = getCfgData(des); ReferenceSettingsInfo refInfo = new ReferenceSettingsInfo(des); @@ -2036,10 +2038,12 @@ public class PathEntryTranslator { public boolean visit(PathSettingsContainer container) { CResourceData data = (CResourceData)container.getValue(); if (data != null) { + AG_log(des, kinds, data); // AG FIXME REMOVEME + PathEntryCollector child = cr.createChild(container.getPath()); for (int kind : kinds) { List list = new ArrayList(); - if (collectResourceDataEntries(kind, data, list)) { + if (collectResourceDataEntries(des, kind, data, list)) { ICLanguageSettingEntry[] entries = list.toArray(new ICLanguageSettingEntry[list.size()]); child.setEntries(kind, entries, exportedSettings); } @@ -2047,11 +2051,28 @@ public class PathEntryTranslator { } return true; } + + // AG FIXME REMOVEME + private void AG_log(final ICConfigurationDescription des, final int[] kinds, CResourceData data) { + String kindsStr=""; + for (int kind : kinds) { + String kstr = LanguageSettingEntriesSerializer.kindToString(kind); + if (kindsStr.length()==0) { + kindsStr = kstr; + } else { + kindsStr += "|" + kstr; + } + } + final IProject prj = des.getProjectDescription().getProject(); + String log_msg = "path="+prj+"/"+data.getPath()+", kind=["+kindsStr+"]"+" (PathEntryTranslator.collectEntries())"; + LanguageSettingsLogger.logInfo(log_msg); + } + }); return cr; } - private static boolean collectResourceDataEntries(int kind, CResourceData data, List list) { + private static boolean collectResourceDataEntries(ICConfigurationDescription des, int kind, CResourceData data, List list) { CLanguageData[] lDatas = null; if (data instanceof CFolderData) { lDatas = ((CFolderData)data).getLanguageDatas(); @@ -2068,6 +2089,17 @@ public class PathEntryTranslator { return false; } + + IProject project = des.getProjectDescription().getProject(); + if (LanguageSettingsManager.isLanguageSettingsProvidersEnabled(project)) { + IResource rc = getResource(project, data.getPath()); + for (CLanguageData lData : lDatas) { + list.addAll(LanguageSettingsManager.getSettingEntriesByKind(des, rc, lData.getLanguageId(), kind)); + } + return list.size()>0; + + } + // Legacy logic boolean supported = false; for (CLanguageData lData : lDatas) { if (collectLanguageDataEntries(kind, lData, list)) @@ -2092,4 +2124,14 @@ public class PathEntryTranslator { PathEntryCollector cr = collectEntries(project, cfg); return cr.getEntries(flags, cfg); } + + private static IResource getResource(IProject project, IPath workspacePath) { + IResource rc; + if (project!=null) { + rc = project.findMember(workspacePath); + } else { + rc = ResourcesPlugin.getWorkspace().getRoot().findMember(workspacePath); + } + return rc; + } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java new file mode 100644 index 00000000000..d595114bea7 --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java @@ -0,0 +1,517 @@ +/******************************************************************************* + * Copyright (c) 2009, 2010 Andrew Gvozdev (Quoin Inc.) 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 (Quoin Inc.) - initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.internal.core.language.settings.providers; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Set; +import java.util.TreeSet; + +import org.eclipse.cdt.core.AbstractExecutableExtensionBase; +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsBaseProvider; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; +import org.eclipse.cdt.core.settings.model.ICSettingEntry; +import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider; +import org.eclipse.cdt.core.settings.model.util.CDataUtil; +import org.eclipse.cdt.core.settings.model.util.LanguageSettingEntriesSerializer; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtension; +import org.eclipse.core.runtime.IExtensionPoint; +import org.eclipse.core.runtime.IExtensionRegistry; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; + +/** + * Class {@code LanguageSettingsExtensionManager} manages {@link ILanguageSettingsProvider} extensions + */ +public class LanguageSettingsExtensionManager { + /** Name of the extension point for contributing language settings */ + final static String PROVIDER_EXTENSION_FULL_ID = "org.eclipse.cdt.core.LanguageSettingsProvider"; //$NON-NLS-1$ + final static String PROVIDER_EXTENSION_SIMPLE_ID = "LanguageSettingsProvider"; //$NON-NLS-1$ + + static final String ELEM_PROVIDER = "provider"; //$NON-NLS-1$ + static final String ATTR_CLASS = "class"; //$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_PARAMETER = "parameter"; //$NON-NLS-1$ + + static final String ELEM_LANGUAGE_SCOPE = "language-scope"; //$NON-NLS-1$ + + static final String ELEM_ENTRY = "entry"; //$NON-NLS-1$ + static final String ELEM_FLAG = "flag"; //$NON-NLS-1$ + static final String ATTR_KIND = "kind"; //$NON-NLS-1$ + static final String ATTR_VALUE = "value"; //$NON-NLS-1$ + + /** + * Extension providers loaded once. If the provider is editable (read cloneable) + * external callers get copy rather than real instance. + */ + private static final LinkedHashMap fExtensionProviders = new LinkedHashMap(); + + /** + * Providers loaded initially via static initializer. + */ + static { + try { + loadProviderExtensions(); + } catch (Throwable e) { + CCorePlugin.log("Error loading language settings providers extensions", e); //$NON-NLS-1$ + } finally { + } + } + + /** + * Load language settings providers contributed via the extension point. + */ + synchronized private static void loadProviderExtensions() { + // sort by name - for the providers taken from platform extensions + Set sortedProviders = new TreeSet( + new Comparator() { + public int compare(ILanguageSettingsProvider pr1, ILanguageSettingsProvider pr2) { + return pr1.getName().compareTo(pr2.getName()); + } + } + ); + + loadProviderExtensions(Platform.getExtensionRegistry(), sortedProviders); + + fExtensionProviders.clear(); + for (ILanguageSettingsProvider provider : sortedProviders) { + fExtensionProviders.put(provider.getId(), provider); + } + } + + /** + * Load contributed extensions from extension registry. + * + * @param registry - extension registry + * @param providers - resulting set of providers + */ + private static void loadProviderExtensions(IExtensionRegistry registry, Set providers) { + providers.clear(); + IExtensionPoint extension = registry.getExtensionPoint(CCorePlugin.PLUGIN_ID, PROVIDER_EXTENSION_SIMPLE_ID); + if (extension != null) { + IExtension[] extensions = extension.getExtensions(); + for (IExtension ext : extensions) { + for (IConfigurationElement cfgEl : ext.getConfigurationElements()) { + ILanguageSettingsProvider provider = null; + String id=null; + try { + if (cfgEl.getName().equals(ELEM_PROVIDER)) { + id = determineAttributeValue(cfgEl, ATTR_ID); + provider = createExecutableExtension(cfgEl); + configureExecutableProvider(provider, cfgEl); + providers.add(provider); + } + } catch (Throwable e) { + CCorePlugin.log("Cannot load LanguageSettingsProvider extension id=" + id, e); //$NON-NLS-1$ + } + } + } + } + } + + + private static String determineAttributeValue(IConfigurationElement ce, String attr) { + String value = ce.getAttribute(attr); + return value!=null ? value : ""; //$NON-NLS-1$ + } + + /** + * Creates empty non-configured provider as executable extension from extension point definition. + * If "class" attribute is empty {@link LanguageSettingsBaseProvider} is created. + * + * @param ce - configuration element with provider definition + * @return new non-configured provider + * @throws CoreException in case of failure + */ + private static ILanguageSettingsProvider createExecutableExtension(IConfigurationElement ce) throws CoreException { + String ceClass = ce.getAttribute(ATTR_CLASS); + ILanguageSettingsProvider provider = null; + if (ceClass==null || ceClass.trim().length()==0 || ceClass.equals(LanguageSettingsBaseProvider.class.getCanonicalName())) { + provider = new LanguageSettingsBaseProvider(); + } else { + provider = (ILanguageSettingsProvider)ce.createExecutableExtension(ATTR_CLASS); + } + + return provider; + } + + + /** + * Configure language settings provider with parameters defined in XML metadata. + * + * @param provider - empty non-configured provider. + * @param ce - configuration element from registry representing XML. + */ + private static void configureExecutableProvider(ILanguageSettingsProvider provider, IConfigurationElement ce) { + String ceId = determineAttributeValue(ce, ATTR_ID); + String ceName = determineAttributeValue(ce, ATTR_NAME); + String ceParameter = determineAttributeValue(ce, ATTR_PARAMETER); + List languages = null; + List entries = null; + + for (IConfigurationElement ceLang : ce.getChildren(ELEM_LANGUAGE_SCOPE)) { + String langId = determineAttributeValue(ceLang, ATTR_ID); + if (langId.trim().length()>0) { + if (languages==null) { + languages = new ArrayList(); + } + languages.add(langId); + } + } + + for (IConfigurationElement ceEntry : ce.getChildren(ELEM_ENTRY)) { + try { + int entryKind = LanguageSettingEntriesSerializer.stringToKind(determineAttributeValue(ceEntry, ATTR_KIND)); + String entryName = determineAttributeValue(ceEntry, ATTR_NAME); + String entryValue = determineAttributeValue(ceEntry, ATTR_VALUE); + + int flags = 0; + for (IConfigurationElement ceFlags : ceEntry.getChildren(ELEM_FLAG)) { + int bitFlag = LanguageSettingEntriesSerializer.composeFlags(determineAttributeValue(ceFlags, ATTR_VALUE)); + flags |= bitFlag; + } + + ICLanguageSettingEntry entry = (ICLanguageSettingEntry) CDataUtil.createEntry( + entryKind, entryName, entryValue, null, flags); + + if (entries == null) + entries = new ArrayList(); + entries.add(entry); + + } catch (Exception e) { + CCorePlugin.log("Error creating language settings entry ", e); //$NON-NLS-1$ + } + } + + if (provider instanceof LanguageSettingsBaseProvider) { + ((LanguageSettingsBaseProvider) provider).configureProvider(ceId, ceName, languages, entries, ceParameter); + } else if (provider instanceof AbstractExecutableExtensionBase) { + ((AbstractExecutableExtensionBase) provider).setId(ceId); + ((AbstractExecutableExtensionBase) provider).setName(ceName); + } + } + + /** + * Creates empty non-configured provider from extension point definition. The method will + * inspect extension registry for extension point "org.eclipse.cdt.core.LanguageSettingsProvider" + * to determine bundle and instantiate the class. + * ID and name of provider are assigned from first extension point encountered. + * + * @param className - full qualified class name of provider. + * @param registry - extension registry + * @return new non-configured provider + */ + private static ILanguageSettingsProvider createProviderCarcass(String className, IExtensionRegistry registry) { + if (className==null || className.length()==0) { + return new LanguageSettingsBaseProvider(); + } + + try { + IExtensionPoint extension = registry.getExtensionPoint(CCorePlugin.PLUGIN_ID, PROVIDER_EXTENSION_SIMPLE_ID); + if (extension != null) { + IExtension[] extensions = extension.getExtensions(); + for (IExtension ext : extensions) { + for (IConfigurationElement cfgEl : ext.getConfigurationElements()) { + if (cfgEl.getName().equals(ELEM_PROVIDER) && className.equals(cfgEl.getAttribute(ATTR_CLASS))) { + ILanguageSettingsProvider provider = createExecutableExtension(cfgEl); + if (provider instanceof AbstractExecutableExtensionBase) { + String ceId = determineAttributeValue(cfgEl, ATTR_ID); + String ceName = determineAttributeValue(cfgEl, ATTR_NAME); + ((AbstractExecutableExtensionBase) provider).setId(ceId); + ((AbstractExecutableExtensionBase) provider).setName(ceName); + } + return provider; + } + } + } + } + } catch (Exception e) { + CCorePlugin.log("Error creating language settings provider.", e); //$NON-NLS-1$ + } + return null; + } + + /** + * Create an instance of language settings provider of given class name. + * + * @param className - class name to instantiate. + * @return new instance of language settings provider. + */ + /*package*/ static ILanguageSettingsProvider getProviderInstance(String className) { + if (className==null || className.equals(LanguageSettingsSerializable.class.getName())) { + return new LanguageSettingsSerializable(); + } + + ILanguageSettingsProvider provider = createProviderCarcass(className, Platform.getExtensionRegistry()); + if (provider==null) { + IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "Not able to load provider class=" + className); + CCorePlugin.log(new CoreException(status)); + } + return provider; + } + + /** + * Get Language Settings Provider defined via + * {@code org.eclipse.cdt.core.LanguageSettingsProvider} extension point. + * + * @param id - ID of provider to find. + * @return the clone of the provider or {@code null} if provider is not defined. + * @throws CloneNotSupportedException if the provider is not cloneable + */ + public static ILanguageSettingsProvider getExtensionProviderClone(String id) throws CloneNotSupportedException { + ILanguageSettingsProvider provider = fExtensionProviders.get(id); + if (provider!=null) { + if (!(provider instanceof ILanguageSettingsEditableProvider)) + throw new CloneNotSupportedException("Not able to clone provider " + provider.getClass()); + + provider = ((ILanguageSettingsEditableProvider) provider).clone(); + } + return provider; + } + + /** + * TODO + * + * @param id + * @return + */ + public static ILanguageSettingsProvider getExtensionProviderShallow(String id) { + ILanguageSettingsProvider provider = fExtensionProviders.get(id); + if (provider instanceof ILanguageSettingsEditableProvider) { + try { + return ((ILanguageSettingsEditableProvider) provider).cloneShallow(); + } catch (CloneNotSupportedException e) { + IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "Not able to clone provider " + provider.getClass()); + CCorePlugin.log(new CoreException(status)); + return null; + } + } + return provider; + } + + /** + * @return list of providers contributed by all extensions. Preferable copy but if not possible + * will return raw provider. + */ + /*package*/ static List getExtensionProvidersInternal() { + ArrayList list = new ArrayList(fExtensionProviders.size()); + for (String id : fExtensionProviders.keySet()) { + ILanguageSettingsProvider extensionProvider = null; + try { + extensionProvider = getExtensionProviderClone(id); + } catch (CloneNotSupportedException e) { + // from here falls to get raw extension provider + } + if (extensionProvider==null) + extensionProvider = fExtensionProviders.get(id); + + if (extensionProvider!=null) + list.add(extensionProvider); + } + return list; + } + + private static List safeGetSettingEntries(ILanguageSettingsProvider provider, + ICConfigurationDescription cfgDescription, IResource rc, String languageId) { + + try { + return provider.getSettingEntries(cfgDescription, rc, languageId); + } catch (Throwable e) { + String cfgId = cfgDescription!=null ? cfgDescription.getId() : null; + String msg = "Exception in provider "+provider.getId()+": getSettingEntries("+cfgId+", "+rc+", "+languageId+")"; + CCorePlugin.log(msg, e); + // return empty array to prevent climbing up the resource tree + return new ArrayList(0); + } + } + + /** + * Returns the list of setting entries of the given provider + * for the given configuration description, resource and language. + * This method reaches to the parent folder of the resource recursively + * in case the resource does not define the entries for the given provider. + * + * @param provider - language settings provider. + * @param cfgDescription - configuration description. + * @param rc - resource such as file or folder. + * @param languageId - language id. + * + * @return the list of setting entries. Never returns {@code null} + * although individual providers mandated to return {@code null} if no settings defined. + */ + public static List getSettingEntriesUpResourceTree(ILanguageSettingsProvider provider, ICConfigurationDescription cfgDescription, IResource rc, String languageId) { + Assert.isTrue( !(rc instanceof IWorkspaceRoot) ); + if (provider!=null) { + List entries = safeGetSettingEntries(provider, cfgDescription, rc, languageId); + if (entries!=null) { + return new ArrayList(entries); + } + if (rc!=null) { + IResource parentFolder = (rc instanceof IProject) ? null : rc.getParent(); + if (parentFolder!=null) { + return getSettingEntriesUpResourceTree(provider, cfgDescription, parentFolder, languageId); + } + // if out of parent resources - get default entries for the applicable language scope + entries = safeGetSettingEntries(provider, null, null, languageId); + if (entries!=null) { + return new ArrayList(entries); + } + } + } + + return new ArrayList(0); + } + + private static boolean checkBit(int flags, int bit) { + return (flags & bit) == bit; + } + + /** + * Returns the list of setting entries of a certain kind (such as include paths) + * for the given configuration description, resource and language. This is a + * combined list for all providers taking into account settings of parent folder + * if settings for the given resource are not defined. + * + * @param cfgDescription - configuration description. + * @param rc - resource such as file or folder. + * @param languageId - language id. + * @param kind - kind of language settings entries, such as + * {@link ICSettingEntry#INCLUDE_PATH} etc. This is a binary flag + * and it is possible to specify composite kind. + * Use {@link ICSettingEntry#ALL} to get all kinds. + * @param checkLocality - specifies if parameter {@code isLocal} should be considered. + * @param isLocal - {@code true} if "local" entries should be provided and + * {@code false} for "system" entries. This makes sense for include paths where + * [#include "..."] is "local" and [#include <...>] is system. + * + * @return the list of setting entries found. + */ + private static List getSettingEntriesByKind(ICConfigurationDescription cfgDescription, + IResource rc, String languageId, int kind, boolean checkLocality, boolean isLocal) { + + List entries = new ArrayList(); + List alreadyAdded = new ArrayList(); + + List providers = cfgDescription.getLanguageSettingProviders(); + for (ILanguageSettingsProvider provider: providers) { + List providerEntries = getSettingEntriesUpResourceTree(provider, cfgDescription, rc, languageId); + for (ICLanguageSettingEntry entry : providerEntries) { + if (entry!=null) { + String entryName = entry.getName(); + boolean isRightKind = (entry.getKind() & kind) != 0; + // Only first entry is considered + // Entry flagged as "UNDEFINED" prevents adding entry with the same name down the line + if (isRightKind && !alreadyAdded.contains(entryName)) { + int flags = entry.getFlags(); + boolean isRightLocal = !checkLocality || (checkBit(flags, ICSettingEntry.LOCAL) == isLocal); + if (isRightLocal) { + if (!checkBit(flags, ICSettingEntry.UNDEFINED)) { + entries.add(entry); + } + alreadyAdded.add(entryName); + } + } + } + } + } + + return entries; + } + + /** + * Returns the list of setting entries of a certain kind (such as include paths) + * for the given configuration description, resource and language. This is a + * combined list for all providers taking into account settings of parent folder + * if settings for the given resource are not defined. For include paths both + * local (#include "...") and system (#include <...>) entries are returned. + * + * @param cfgDescription - configuration description. + * @param rc - resource such as file or folder. + * @param languageId - language id. + * @param kind - kind of language settings entries, such as + * {@link ICSettingEntry#INCLUDE_PATH} etc. This is a binary flag + * and it is possible to specify composite kind. + * Use {@link ICSettingEntry#ALL} to get all kinds. + * + * @return the list of setting entries. + */ + public static List getSettingEntriesByKind(ICConfigurationDescription cfgDescription, IResource rc, String languageId, int kind) { + return getSettingEntriesByKind(cfgDescription, rc, languageId, kind, /* checkLocality */ false, /* isLocal */ false); + } + + /** + * Returns the list of "system" (such as [#include <...>]) setting entries of a certain kind + * for the given configuration description, resource and language. This is a + * combined list for all providers taking into account settings of parent folder + * if settings for the given resource are not defined. + * + * @param cfgDescription - configuration description. + * @param rc - resource such as file or folder. + * @param languageId - language id. + * @param kind - kind of language settings entries, such as + * {@link ICSettingEntry#INCLUDE_PATH} etc. This is a binary flag + * and it is possible to specify composite kind. + * Use {@link ICSettingEntry#ALL} to get all kinds. + * + * @return the list of setting entries. + */ + public static List getSystemSettingEntriesByKind(ICConfigurationDescription cfgDescription, IResource rc, String languageId, int kind) { + return getSettingEntriesByKind(cfgDescription, rc, languageId, kind, /* checkLocality */ true, /* isLocal */ false); + } + + /** + * Returns the list of "local" (such as [#include "..."]) setting entries of a certain kind + * for the given configuration description, resource and language. This is a + * combined list for all providers taking into account settings of parent folder + * if settings for the given resource are not defined. + * + * @param cfgDescription - configuration description. + * @param rc - resource such as file or folder. + * @param languageId - language id. + * @param kind - kind of language settings entries, such as + * {@link ICSettingEntry#INCLUDE_PATH} etc. This is a binary flag + * and it is possible to specify composite kind. + * Use {@link ICSettingEntry#ALL} to get all kinds. + * + * @return the list of setting entries. + */ + public static List getLocalSettingEntriesByKind(ICConfigurationDescription cfgDescription, IResource rc, String languageId, int kind) { + return getSettingEntriesByKind(cfgDescription, rc, languageId, kind, /* checkLocality */ true, /* isLocal */ true); + } + + public static boolean equalsExtensionProviderShallow(ILanguageSettingsEditableProvider provider) throws CloneNotSupportedException { + String id = provider.getId(); + ILanguageSettingsProvider extensionProviderShallow = getExtensionProviderShallow(id); + return provider.cloneShallow().equals(extensionProviderShallow); + } + + public static boolean equalsExtensionProvider(ILanguageSettingsProvider provider) { + String id = provider.getId(); + ILanguageSettingsProvider extensionProvider = fExtensionProviders.get(id); + return provider.equals(extensionProvider); + } + +} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsLogger.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsLogger.java new file mode 100644 index 00000000000..7483b4100bf --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsLogger.java @@ -0,0 +1,79 @@ +package org.eclipse.cdt.internal.core.language.settings.providers; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; + +@Deprecated +public class LanguageSettingsLogger { + + /** + * + */ + private static final boolean ENABLED = false; + + // AG FIXME + /** + * @param msg + * @noreference This method is not intended to be referenced by clients. + */ + @Deprecated + public static void logInfo(String msg) { + if (ENABLED) { + Exception e = new Exception(msg); + IStatus status = new Status(IStatus.INFO, CCorePlugin.PLUGIN_ID, msg, e); + CCorePlugin.log(status); + } + } + + // AG FIXME + /** + * @param msg + * @noreference This method is not intended to be referenced by clients. + */ + @Deprecated + public static void logWarning(String msg) { + if (ENABLED) { + Exception e = new Exception(msg); + IStatus status = new Status(IStatus.WARNING, CCorePlugin.PLUGIN_ID, msg, e); + CCorePlugin.log(status); + } + } + + // AG FIXME + /** + * @param msg + * @noreference This method is not intended to be referenced by clients. + */ + @Deprecated + public static void logError(String msg) { + if (ENABLED) { + Exception e = new Exception(msg); + IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, msg, e); + CCorePlugin.log(status); + } + } + + // AG FIXME + /** + * @param rc + * @param who - pass "this" (calling class instance) here + * @noreference This method is not intended to be referenced by clients. + */ + @Deprecated + public static void logScannerInfoProvider(IResource rc, Object who) { + if (ENABLED) { + String msg = "rc="+rc+" <-- "+who.getClass().getSimpleName(); + if (rc instanceof IFile) { + LanguageSettingsLogger.logInfo(msg); + } else if (rc instanceof IProject) { + LanguageSettingsLogger.logWarning(msg); + } else { + LanguageSettingsLogger.logError(msg); + } + } + } +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java new file mode 100644 index 00000000000..6868b13c53d --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java @@ -0,0 +1,456 @@ +package org.eclipse.cdt.internal.core.language.settings.providers; + +import java.net.URI; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; +import org.eclipse.cdt.core.settings.model.ICProjectDescription; +import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider; +import org.eclipse.cdt.internal.core.XmlUtil; +import org.eclipse.core.filesystem.URIUtil; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +public class LanguageSettingsProvidersSerializer { + + 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_LANGUAGE_SETTINGS = "language.settings.xml"; //$NON-NLS-1$ + public static final char PROVIDER_DELIMITER = ';'; + private static final String MBS_LANGUAGE_SETTINGS_PROVIDER = "org.eclipse.cdt.managedbuilder.core.LanguageSettingsProvider"; + private static final String ELEM_PLUGIN = "plugin"; //$NON-NLS-1$ + private static final String ELEM_EXTENSION = "extension"; //$NON-NLS-1$ + private static final String ATTR_POINT = "point"; //$NON-NLS-1$ + private static final String ELEM_PROJECT = "project"; //$NON-NLS-1$ + private static final String ELEM_CONFIGURATION = "configuration"; //$NON-NLS-1$ + private static final String ELEM_PROVIDER_REFERENCE = "provider-reference"; //$NON-NLS-1$ + /** Cache of globally available providers to be consumed by calling clients */ + private static Map rawGlobalWorkspaceProviders = new HashMap(); + private static Object serializingLock = new Object(); + + private static class LanguageSettingsWorkspaceProvider implements ILanguageSettingsProvider { + private String providerId; + + public LanguageSettingsWorkspaceProvider(String id) { + Assert.isNotNull(id); + Assert.isTrue(id.length()>0); + providerId = id; + } + + public String getId() { + return providerId; + } + + public String getName() { + ILanguageSettingsProvider rawProvider = getRawProvider(); + String name = rawProvider!=null ? rawProvider.getName() : null; + return name; + } + + public List getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) { + ILanguageSettingsProvider rawProvider = getRawProvider(); + List entries = rawProvider!=null ? rawProvider.getSettingEntries(cfgDescription, rc, languageId) : null; + return entries; + } + + /** + * Do not cache the "raw" provider as workspace provider can be changed at any time. + */ + private ILanguageSettingsProvider getRawProvider() { + return LanguageSettingsProvidersSerializer.getRawWorkspaceProvider(providerId); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof LanguageSettingsWorkspaceProvider) { + LanguageSettingsWorkspaceProvider that = (LanguageSettingsWorkspaceProvider) obj; + return providerId.equals(that.providerId); + } + return false; + } + /** + * Method toString() for debugging purposes. + */ + @SuppressWarnings("nls") + @Override + public String toString() { + return "id="+getId()+", name="+getName(); + } + } + + + /** static initializer */ + static { + try { + loadLanguageSettingsWorkspace(); + } catch (Throwable e) { + CCorePlugin.log("Error loading workspace language settings providers", e); //$NON-NLS-1$ + } finally { + } + } + + /** + * Set and store in workspace area user defined providers. + * + * @param providers - array of user defined providers + * @throws CoreException in case of problems + */ + public static void setWorkspaceProviders(List providers) throws CoreException { + setWorkspaceProvidersInternal(providers); + serializeLanguageSettingsWorkspace(); + } + + /** + * Internal method to set user defined providers in memory. + * + * @param providers - list of user defined providers. If {@code null} + * is passed user defined providers are cleared. + */ + private static void setWorkspaceProvidersInternal(List providers) { + Map rawWorkspaceProviders = new HashMap(); + List extensionProviders = new ArrayList(LanguageSettingsExtensionManager.getExtensionProvidersInternal()); + for (ILanguageSettingsProvider rawExtensionProvider : extensionProviders) { + if (rawExtensionProvider!=null) { + rawWorkspaceProviders.put(rawExtensionProvider.getId(), rawExtensionProvider); + } + } + + if (providers!=null) { + List rawProviders = new ArrayList(); + for (ILanguageSettingsProvider provider : providers) { + if (isWorkspaceProvider(provider)) { + provider = rawGlobalWorkspaceProviders.get(provider.getId()); + } + if (provider!=null) { + rawProviders.add(provider); + } + } + for (ILanguageSettingsProvider provider : rawProviders) { + rawWorkspaceProviders.put(provider.getId(), provider); + } + } + + rawGlobalWorkspaceProviders = rawWorkspaceProviders; + } + + /** + * TODO: refactor with ErrorParserManager + * + * @param store - name of the store + * @return location of the store in the plug-in state area + */ + private static URI getStoreLocation(String store) { + IPath location = CCorePlugin.getDefault().getStateLocation().append(store); + URI uri = URIUtil.toURI(location); + return uri; + } + + public static void serializeLanguageSettingsWorkspace() throws CoreException { + URI uriLocation = getStoreLocation(STORAGE_WORKSPACE_LANGUAGE_SETTINGS); + List serializableExtensionProviders = new ArrayList(); + for (ILanguageSettingsProvider provider : rawGlobalWorkspaceProviders.values()) { + if (provider instanceof LanguageSettingsSerializable) { + // serialize all editable providers which are different from corresponding extension + // and serialize all serializable ones that are not editable (those are singletons and we don't know whether they changed) + if (!(provider instanceof ILanguageSettingsEditableProvider) || !LanguageSettingsExtensionManager.equalsExtensionProvider(provider)) { + serializableExtensionProviders.add((LanguageSettingsSerializable)provider); + } + } + } + try { + if (serializableExtensionProviders.isEmpty()) { + java.io.File file = new java.io.File(uriLocation); + synchronized (serializingLock) { + file.delete(); + } + return; + } + + Document doc = XmlUtil.newDocument(); + Element rootElement = XmlUtil.appendElement(doc, ELEM_PLUGIN); + Element elementExtension = XmlUtil.appendElement(rootElement, ELEM_EXTENSION, new String[] {ATTR_POINT, LanguageSettingsExtensionManager.PROVIDER_EXTENSION_FULL_ID}); + + for (LanguageSettingsSerializable provider : serializableExtensionProviders) { + provider.serialize(elementExtension); + } + + synchronized (serializingLock) { + XmlUtil.serializeXml(doc, uriLocation); + } + + } catch (Exception e) { + CCorePlugin.log("Internal error while trying to serialize language settings", e); //$NON-NLS-1$ + IStatus s = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "Internal error while trying to serialize language settings", e); + throw new CoreException(s); + } + } + + public static void loadLanguageSettingsWorkspace() throws CoreException { + List providers = null; + + URI uriLocation = getStoreLocation(STORAGE_WORKSPACE_LANGUAGE_SETTINGS); + + Document doc = null; + try { + synchronized (serializingLock) { + doc = XmlUtil.loadXml(uriLocation); + } + } catch (Exception e) { + CCorePlugin.log("Can't load preferences from file "+uriLocation, e); //$NON-NLS-1$ + } + + if (doc!=null) { + Element rootElement = doc.getDocumentElement(); + NodeList providerNodes = rootElement.getElementsByTagName(LanguageSettingsSerializable.ELEM_PROVIDER); + + List userDefinedProvidersIds = new ArrayList(); + for (int i=0;i(); + + if (!LanguageSettingsExtensionManager.equalsExtensionProvider(provider)) { + providers.add(provider); + } + } + } + } + setWorkspaceProvidersInternal(providers); + } + + public static void serializeLanguageSettings(Element parentElement, ICProjectDescription prjDescription) throws CoreException { + ICConfigurationDescription[] cfgDescriptions = prjDescription.getConfigurations(); + for (ICConfigurationDescription cfgDescription : cfgDescriptions) { + Element elementConfiguration = XmlUtil.appendElement(parentElement, ELEM_CONFIGURATION, new String[] { + LanguageSettingsExtensionManager.ATTR_ID, cfgDescription.getId(), + LanguageSettingsExtensionManager.ATTR_NAME, cfgDescription.getName(), + }); + List providers = cfgDescription.getLanguageSettingProviders(); + if (providers.size()>0) { + Element elementExtension = XmlUtil.appendElement(elementConfiguration, ELEM_EXTENSION, new String[] { + ATTR_POINT, LanguageSettingsExtensionManager.PROVIDER_EXTENSION_FULL_ID}); + for (ILanguageSettingsProvider provider : providers) { + if (isWorkspaceProvider(provider)) { + // Element elementProviderReference = + XmlUtil.appendElement(elementExtension, ELEM_PROVIDER_REFERENCE, new String[] { + LanguageSettingsExtensionManager.ATTR_ID, provider.getId()}); + continue; + } + if (provider instanceof LanguageSettingsSerializable) { + ((LanguageSettingsSerializable) provider).serialize(elementExtension); + } else { + // Element elementProvider = + XmlUtil.appendElement(elementExtension, LanguageSettingsExtensionManager.ELEM_PROVIDER, new String[] { + LanguageSettingsExtensionManager.ATTR_ID, provider.getId(), + LanguageSettingsExtensionManager.ATTR_NAME, provider.getName(), + LanguageSettingsExtensionManager.ATTR_CLASS, provider.getClass().getCanonicalName(), + }); + } + } + } + } + } + + private static IFile getStorage(IProject project) throws CoreException { + IFolder folder = project.getFolder(SETTINGS_FOLDER_NAME); + if (!folder.exists()) { + folder.create(true, true, null); + } + IFile storage = folder.getFile(STORAGE_PROJECT_LANGUAGE_SETTINGS); + return storage; + } + + public static void serializeLanguageSettings(ICProjectDescription prjDescription) throws CoreException { + IProject project = prjDescription.getProject(); + try { + Document doc = XmlUtil.newDocument(); + Element rootElement = XmlUtil.appendElement(doc, ELEM_PROJECT); + serializeLanguageSettings(rootElement, prjDescription); + + IFile file = getStorage(project); + synchronized (serializingLock){ + XmlUtil.serializeXml(doc, file); + } + + } catch (Exception e) { + IStatus s = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "Internal error while trying to serialize language settings", e); + CCorePlugin.log(s); + throw new CoreException(s); + } + } + + public static void loadLanguageSettings(Element parentElement, ICProjectDescription prjDescription) { + /* + + + + + + + + + */ + NodeList configurationNodes = parentElement.getChildNodes(); + for (int ic=0;ic providers = new ArrayList(); + String cfgId = XmlUtil.determineAttributeValue(cfgNode, LanguageSettingsExtensionManager.ATTR_ID); + @SuppressWarnings("unused") + String cfgName = XmlUtil.determineAttributeValue(cfgNode, LanguageSettingsExtensionManager.ATTR_NAME); + + NodeList extensionAndReferenceNodes = cfgNode.getChildNodes(); + for (int ie=0;ie + loadLanguageSettings(rootElement, prjDescription); + } catch (Exception e) { + CCorePlugin.log("Can't load preferences from file "+file.getLocation(), e); //$NON-NLS-1$ + } + + if (doc!=null) { + } + + } else { + // Already existing legacy projects + ICConfigurationDescription[] cfgDescriptions = prjDescription.getConfigurations(); + for (ICConfigurationDescription cfgDescription : cfgDescriptions) { + if (cfgDescription!=null) { + List providers = new ArrayList(2); + ILanguageSettingsProvider userProvider = getWorkspaceProvider(MBS_LANGUAGE_SETTINGS_PROVIDER); + providers.add(userProvider); + cfgDescription.setLanguageSettingProviders(providers); + } + } + + } + } + + /** + * FIXME Get Language Settings Provider defined in the workspace. That includes user-defined + * providers and after that providers defined as extensions via + * {@code org.eclipse.cdt.core.LanguageSettingsProvider} extension point. + * That returns actual object, any modifications will affect any configuration + * referring to the provider. + * + * @param id - ID of provider to find. + * @return the provider or {@code null} if provider is not defined. + */ + public static ILanguageSettingsProvider getWorkspaceProvider(String id) { + return new LanguageSettingsWorkspaceProvider(id); + } + + public static ILanguageSettingsProvider getRawWorkspaceProvider(String id) { + return rawGlobalWorkspaceProviders.get(id); + } + + /** + * TODO + * @return ordered set of providers defined in the workspace which include contributed through extension + user defined ones + * + */ + public static List getWorkspaceProviders() { + ArrayList workspaceProviders = new ArrayList(); + for (ILanguageSettingsProvider rawProvider : rawGlobalWorkspaceProviders.values()) { + workspaceProviders.add(new LanguageSettingsWorkspaceProvider(rawProvider.getId())); + } + return workspaceProviders; + } + + /** + * Checks if the provider is defined on the workspace level. + * + * @param provider - provider to check. + * @return {@code true} if the given provider is workspace provider, {@code false} otherwise. + * + */ + public static boolean isWorkspaceProvider(ILanguageSettingsProvider provider) { + return provider instanceof LanguageSettingsWorkspaceProvider; + } +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsScannerInfoProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsScannerInfoProvider.java new file mode 100644 index 00000000000..0b6f4b8a1c5 --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsScannerInfoProvider.java @@ -0,0 +1,325 @@ +/******************************************************************************* + * Copyright (c) 2010, 2010 Andrew Gvozdev (Quoin Inc.) 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 (Quoin Inc.) - initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.internal.core.language.settings.providers; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; + +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.model.ILanguage; +import org.eclipse.cdt.core.model.LanguageManager; +import org.eclipse.cdt.core.parser.ExtendedScannerInfo; +import org.eclipse.cdt.core.parser.IScannerInfoChangeListener; +import org.eclipse.cdt.core.parser.IScannerInfoProvider; +import org.eclipse.cdt.core.settings.model.ACPathEntry; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICFolderDescription; +import org.eclipse.cdt.core.settings.model.ICLanguageSetting; +import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; +import org.eclipse.cdt.core.settings.model.ICLanguageSettingPathEntry; +import org.eclipse.cdt.core.settings.model.ICMacroEntry; +import org.eclipse.cdt.core.settings.model.ICProjectDescription; +import org.eclipse.cdt.core.settings.model.ICSettingEntry; +import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager; +import org.eclipse.cdt.internal.core.settings.model.SettingsModelMessages; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Status; +import org.eclipse.osgi.util.NLS; + +/** + * Implementation of {@link IScannerInfoProvider} backed by the list of + * language settings providers of "default settings configuration" + * (see {@link ICProjectDescription#getDefaultSettingConfiguration()}). + * + */ +public class LanguageSettingsScannerInfoProvider implements IScannerInfoProvider { + private static final ExtendedScannerInfo DUMMY_SCANNER_INFO = new ExtendedScannerInfo(); + + public ExtendedScannerInfo getScannerInformation(IResource rc) { + // AG FIXME + LanguageSettingsLogger.logScannerInfoProvider(rc, this); + + IProject project = rc.getProject(); + if (project==null) + return DUMMY_SCANNER_INFO; + + ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false); + if (prjDescription==null) + return DUMMY_SCANNER_INFO; + + ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); + if (cfgDescription==null) + return DUMMY_SCANNER_INFO; + + List languageIds = getLanguageIds(cfgDescription, rc); + if (languageIds==null || languageIds.size()==0) { + return DUMMY_SCANNER_INFO; + } + + LinkedHashSet includePathEntries = new LinkedHashSet(); + LinkedHashSet includePathLocalEntries = new LinkedHashSet(); + LinkedHashSet includeFileEntries = new LinkedHashSet(); + LinkedHashSet macroFileEntries = new LinkedHashSet(); + LinkedHashSet macroEntries = new LinkedHashSet(); + + for (String langId : languageIds) { + List incSys = LanguageSettingsExtensionManager.getSystemSettingEntriesByKind(cfgDescription, rc, langId, + ICSettingEntry.INCLUDE_PATH); + includePathEntries.addAll(incSys); + + List incLocal = LanguageSettingsExtensionManager.getLocalSettingEntriesByKind(cfgDescription, rc, langId, + ICSettingEntry.INCLUDE_PATH); + includePathLocalEntries.addAll(incLocal); + + List incFiles = LanguageSettingsExtensionManager.getSettingEntriesByKind(cfgDescription, rc, langId, + ICSettingEntry.INCLUDE_FILE); + includeFileEntries.addAll(incFiles); + + List macroFiles = LanguageSettingsExtensionManager.getSettingEntriesByKind(cfgDescription, rc, langId, + ICSettingEntry.MACRO_FILE); + macroFileEntries.addAll(macroFiles); + + List macros = LanguageSettingsExtensionManager.getSettingEntriesByKind(cfgDescription, rc, langId, + ICSettingEntry.MACRO); + macroEntries.addAll(macros); + } + + String[] includePaths = convertToLocations(includePathEntries, cfgDescription); + String[] includePathsLocal = convertToLocations(includePathLocalEntries, cfgDescription); + String[] includeFiles = convertToLocations(includeFileEntries, cfgDescription); + String[] macroFiles = convertToLocations(macroFileEntries, cfgDescription); + + Map definedMacros = new HashMap(); + for (ICLanguageSettingEntry entry : macroEntries) { + ICMacroEntry macroEntry = (ICMacroEntry)entry; + String name = macroEntry.getName(); + String value = macroEntry.getValue(); + definedMacros.put(name, value); + } + + return new ExtendedScannerInfo(definedMacros, includePaths, macroFiles, includeFiles, includePathsLocal); + } + + private List getLanguageIds(ICConfigurationDescription cfgDescription, IResource resource) { + List languageIds = null; + if (resource instanceof IFile) { + String langId = getLanguageIdForFile(cfgDescription, resource); + if (langId!=null) { + languageIds = new ArrayList(1); + languageIds.add(langId); + } + } else if (resource instanceof IContainer) { // IResource can be either IFile or IContainer + languageIds = getLanguageIdsForFolder(cfgDescription, (IContainer) resource); + } + if (languageIds==null || languageIds.size()==0) { + String msg = NLS.bind(SettingsModelMessages.getString("LanguageSettingsScannerInfoProvider.UnableToDetermineLanguage"), resource.toString()); //$NON-NLS-1$ + CCorePlugin.log(new CoreException(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, msg))); + } + return languageIds; + } + + private String getLanguageIdForFile(ICConfigurationDescription cfgDescription, IResource resource) { + // For files using LanguageManager + try { + ILanguage language = LanguageManager.getInstance().getLanguageForFile((IFile) resource, cfgDescription); + if (language!=null) { + return language.getId(); + } + } catch (CoreException e) { + CCorePlugin.log(e); + } + return null; + } + + private List getLanguageIdsForFolder(ICConfigurationDescription cfgDescription, IContainer resource) { + // Using MBS for folders. That will take language ID from input type of applicable tools in the toolchain. + List languageIds = new ArrayList(); + + ICFolderDescription rcDes = null; + ICLanguageSetting[] langSettings = null; + if (resource.getType() == IResource.FOLDER) { // but not IResource.PROJECT + IPath rcPath = resource.getProjectRelativePath(); + rcDes = (ICFolderDescription) cfgDescription.getResourceDescription(rcPath, false); + langSettings = rcDes.getLanguageSettings(); + } + if (langSettings==null || langSettings.length==0) { + // not found or IResource.PROJECT + ICFolderDescription rootDes = cfgDescription.getRootFolderDescription(); + langSettings = rootDes.getLanguageSettings(); + } + + if (langSettings!=null) { + for (ICLanguageSetting ls : langSettings) { + String langId = ls.getLanguageId(); + if (langId!=null && !languageIds.contains(langId)) { + languageIds.add(langId); + } + } + } + + return languageIds; + } + + private IPath expandVariables(IPath path, ICConfigurationDescription cfgDescription) { + ICdtVariableManager varManager = CCorePlugin.getDefault().getCdtVariableManager(); + String pathStr = path.toString(); + try { + pathStr = varManager.resolveValue(pathStr, "", null, cfgDescription); //$NON-NLS-1$ + } catch (CdtVariableException e) { + // Swallow exceptions but also log them + CCorePlugin.log(e); + } + IPath resolvedLoc = new Path(pathStr); + return resolvedLoc; + } + + /** + * Get build working directory for the provided configuration. Returns + * project location if none defined. + */ + private static IPath getBuildCWD(ICConfigurationDescription cfgDescription) { + IPath buildCWD = cfgDescription.getBuildSetting().getBuilderCWD(); + if (buildCWD==null) { + IProject project = cfgDescription.getProjectDescription().getProject(); + buildCWD = project.getLocation(); + } else { + ICdtVariableManager mngr = CCorePlugin.getDefault().getCdtVariableManager(); + try { + // FIXME IPath buildCWD can hold variables i.e. ${workspace_loc:/path} + String buildPathString = buildCWD.toString(); + buildPathString = mngr.resolveValue(buildPathString, "", null, cfgDescription); + buildCWD = new Path(buildPathString); + } catch (CdtVariableException e) { + CCorePlugin.log(e); + } + + } + buildCWD = buildCWD.addTrailingSeparator(); + return buildCWD; + } + + /** + * Resolve location to file system location in a configuration context. + * Resolving includes replacing build/environment variables with values, making relative path absolute etc. + * + * @param location - location to resolve. If relative, it is taken to be rooted in build working directory. + * @param cfgDescription - the configuration context. + * @return resolved file system location. + */ + private static String resolveEntry(String location, ICConfigurationDescription cfgDescription) { + // Substitute build/environment variables + ICdtVariableManager varManager = CCorePlugin.getDefault().getCdtVariableManager(); + try { + location = varManager.resolveValue(location, "", null, cfgDescription); //$NON-NLS-1$ + } catch (CdtVariableException e) { + // Swallow exceptions but also log them + CCorePlugin.log(e); + } + // use OS file separators (i.e. '\' on Windows) + if (java.io.File.separatorChar != '/') { + location = location.replace('/', java.io.File.separatorChar); + } + + // note that we avoid using org.eclipse.core.runtime.Path for manipulations being careful + // to preserve "../" segments and not let collapsing them which is not correct for symbolic links. + Path locPath = new Path(location); + if (locPath.isAbsolute() && locPath.getDevice()==null) { + // prepend device (C:) for Windows + IPath buildCWD = getBuildCWD(cfgDescription); + String device = buildCWD.getDevice(); + if (device!=null) + location = device + location; + } + if (!locPath.isAbsolute()) { + // consider relative path to be from build working directory + IPath buildCWD = getBuildCWD(cfgDescription); + location = buildCWD.toOSString() + locPath; + } + return location; + } + + /** + * Convert the path entries to absolute file system locations represented as String array. + * Resolve the entries which are not resolved. + * + * @param entriesPath - language settings path entries. + * @param cfgDescription - configuration description for resolving entries. + * @return array of the locations. + */ + private String[] convertToLocations(LinkedHashSet entriesPath, ICConfigurationDescription cfgDescription){ + List locations = new ArrayList(entriesPath.size()); + for (ICLanguageSettingEntry entry : entriesPath) { + ACPathEntry entryPath = (ACPathEntry)entry; + if (entryPath.isValueWorkspacePath()) { + IPath loc = entryPath.getLocation(); + if (loc!=null) { + if (checkBit(entryPath.getFlags(), ICSettingEntry.FRAMEWORKS_MAC)) { + locations.add(loc.append("/__framework__.framework/Headers/__header__").toOSString()); + locations.add(loc.append("/__framework__.framework/PrivateHeaders/__header__").toOSString()); + } else { + locations.add(loc.toOSString()); + } + } + } else { + String locStr = entryPath.getName(); + if (entryPath.isResolved()) { + locations.add(locStr); + } else { + locStr = resolveEntry(locStr, cfgDescription); + if (locStr!=null) { + if (checkBit(entryPath.getFlags(), ICSettingEntry.FRAMEWORKS_MAC)) { + locations.add(locStr+"/__framework__.framework/Headers/__header__"); + locations.add(locStr+"/__framework__.framework/PrivateHeaders/__header__"); + } else { + locations.add(locStr); + // add relative paths again for indexer to resolve from source file location + IPath unresolvedPath = entryPath.getLocation(); + if (!unresolvedPath.isAbsolute()) { + IPath expandedPath = expandVariables(unresolvedPath, cfgDescription); + if (!expandedPath.isAbsolute()) { + locations.add(expandedPath.toOSString()); + } + } + } + } + } + } + } + + return locations.toArray(new String[locations.size()]); + } + + private static boolean checkBit(int flags, int bit) { + return (flags & bit) == bit; + } + + public void subscribe(IResource resource, IScannerInfoChangeListener listener) { + // Handled by ScannerInfoProviderProxy for the moment + } + + public void unsubscribe(IResource resource, IScannerInfoChangeListener listener) { + // Handled by ScannerInfoProviderProxy for the moment + } + +} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationDescription.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationDescription.java index 0edac50159b..8b359afaf4c 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationDescription.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationDescription.java @@ -18,6 +18,7 @@ import java.util.Map; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.cdtvariables.ICdtVariablesContributor; +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.settings.model.CConfigurationStatus; import org.eclipse.cdt.core.settings.model.ICBuildSetting; import org.eclipse.cdt.core.settings.model.ICConfigExtensionReference; @@ -765,4 +766,22 @@ public class CConfigurationDescription extends CDataProxyContainer implements IC CConfigurationStatus status = data.getStatus(); return status != null ? status : CConfigurationStatus.CFG_STATUS_OK; } + + public void setLanguageSettingProviders(List providers) { + try { + CConfigurationSpecSettings specSettings = getSpecSettings(); + specSettings.setLanguageSettingProviders(providers); + } catch (CoreException e) { + CCorePlugin.log(e); + } +} + + public List getLanguageSettingProviders() { + try { + return getSpecSettings().getLanguageSettingProviders(); + } catch (CoreException e) { + CCorePlugin.log(e); + } + return null; + } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationDescriptionCache.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationDescriptionCache.java index 95f54d667c7..0c64dbc3ce3 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationDescriptionCache.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationDescriptionCache.java @@ -16,6 +16,7 @@ import java.util.Map; import org.eclipse.cdt.core.cdtvariables.ICdtVariable; import org.eclipse.cdt.core.cdtvariables.ICdtVariablesContributor; +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.settings.model.CConfigurationStatus; import org.eclipse.cdt.core.settings.model.ICBuildSetting; import org.eclipse.cdt.core.settings.model.ICConfigExtensionReference; @@ -53,6 +54,28 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.QualifiedName; +/** + * CConfigurationDescriptionCache is a proxy class for serialization of configuration description data. + * + * An inspection of the scenario where user changes project properties and saves it yields + * following sequence of events: + * - Initialization: + * - After eclipse started a project is being opened. A new CConfigurationDescriptionCache is created + * with CConfigurationDescriptionCache(ICStorageElement storage, CProjectDescription parent) constructor. + * - Any clients needed ICConfigurationDescription get CConfigurationDescription using constructor + * CConfigurationDescription(CConfigurationData data, String buildSystemId, ICDataProxyContainer cr) + * where the CConfigurationDescriptionCache is passed as data. The reference to cache is kept in field fCfgCache. + * - fCfgCache is used to getSpecSettings() CConfigurationSpecSettings, after that fCfgCache is set to null. + * - User enters project properties/settings: + * - another CConfigurationDescription (settings configuration) created using the same constructor setting fCfgCache + * to the CConfigurationDescriptionCache. + * - User changes settings (in the settings configuration CConfigurationDescription) and saves it: + * - new CConfigurationDescriptionCache is created from the CConfigurationDescription via constructor + * CConfigurationDescriptionCache(ICConfigurationDescription baseDescription, ...) where + * baseDescription is saved as fBaseDescription. + * - CConfigurationDescriptionCache.applyData(...) is used to persist the data. at that point + * reference fBaseDescription gets set to null. + */ public class CConfigurationDescriptionCache extends CDefaultConfigurationData implements ICConfigurationDescription, IInternalCCfgInfo, ICachedData { private CProjectDescription fParent; @@ -535,4 +558,15 @@ public class CConfigurationDescriptionCache extends CDefaultConfigurationData return status != null ? status : CConfigurationStatus.CFG_STATUS_OK; } + public void setLanguageSettingProviders(List providers) { +// FIXME? - not sure +// if(!fInitializing) +// throw ExceptionFactory.createIsReadOnlyException(); + + fSpecSettings.setLanguageSettingProviders(providers); + } + + public List getLanguageSettingProviders() { + return fSpecSettings.getLanguageSettingProviders(); + } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationSpecSettings.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationSpecSettings.java index ae5a488764f..63dd2cac673 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationSpecSettings.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationSpecSettings.java @@ -11,15 +11,19 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.settings.model; +import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; -import java.util.Set; import java.util.Map.Entry; +import java.util.Set; import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.settings.model.CExternalSetting; import org.eclipse.cdt.core.settings.model.ICBuildSetting; import org.eclipse.cdt.core.settings.model.ICConfigExtensionReference; @@ -37,9 +41,11 @@ import org.eclipse.cdt.internal.core.COwner; import org.eclipse.cdt.internal.core.COwnerConfiguration; import org.eclipse.cdt.internal.core.cdtvariables.StorableCdtVariables; import org.eclipse.cdt.internal.core.envvar.EnvironmentVariableManager; +import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer; import org.eclipse.cdt.utils.envvar.StorableEnvironment; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.QualifiedName; +import org.eclipse.osgi.util.NLS; /** * CConfigurationSpecSettings impelements ICSettingsStorage @@ -87,6 +93,8 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ // private CConfigBasedDescriptor fDescriptor; // private Map fExternalSettingsProviderMap; + private List fLanguageSettingsProviders = new ArrayList(0); + private class DeltaSet { public Set extSet; public Set idSet; @@ -179,6 +187,8 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ fOwner = base.fOwner; copyExtensionInfo(base); + + fLanguageSettingsProviders = new ArrayList(base.getLanguageSettingProviders()); } // private void copyRefInfos(Map infosMap){ @@ -971,4 +981,34 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ public void updateExternalSettingsProviders(String[] ids){ ExtensionContainerFactory.updateReferencedProviderIds(fCfg, ids); } + + /** + * Adds list of {@link ILanguageSettingsProvider} to the specs. + * Note that only unique IDs are accepted. + * + * @param providers - list of providers to keep in the specs. + */ + public void setLanguageSettingProviders(List providers) { + fLanguageSettingsProviders.clear(); + Set ids = new HashSet(); + for (ILanguageSettingsProvider provider : providers) { + String id = provider.getId(); + if (provider==LanguageSettingsProvidersSerializer.getRawWorkspaceProvider(id)) { + String msg = "Error: Attempt to add to the configuration raw global provider " + id; + throw new IllegalArgumentException(msg); + } + if (!ids.contains(id)) { + fLanguageSettingsProviders.add(provider); + ids.add(id); + } else { + String msg = NLS.bind(SettingsModelMessages.getString("CConfigurationSpecSettings.MustHaveUniqueID"), id); //$NON-NLS-1$ + throw new IllegalArgumentException(msg); + } + } + fIsModified = true; + } + + public List getLanguageSettingProviders() { + return Collections.unmodifiableList(fLanguageSettingsProviders); + } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/DescriptionScannerInfoProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/DescriptionScannerInfoProvider.java index 1951c3aa5cc..f7d7e7008b3 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/DescriptionScannerInfoProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/DescriptionScannerInfoProvider.java @@ -34,6 +34,7 @@ import org.eclipse.cdt.core.settings.model.ICProjectDescriptionListener; import org.eclipse.cdt.core.settings.model.ICResourceDescription; import org.eclipse.cdt.core.settings.model.ICSettingBase; import org.eclipse.cdt.core.settings.model.ICSettingEntry; +import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsLogger; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IWorkspaceRoot; @@ -74,6 +75,9 @@ public class DescriptionScannerInfoProvider implements IScannerInfoProvider, ICP } public IScannerInfo getScannerInformation(IResource resource) { + // AG FIXME + LanguageSettingsLogger.logScannerInfoProvider(resource, this); + if(!fInited) updateProjCfgInfo(CProjectDescriptionManager.getInstance().getProjectDescription(fProject, false)); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/MultiConfigDescription.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/MultiConfigDescription.java index a6838481d1c..bff75bff4b8 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/MultiConfigDescription.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/MultiConfigDescription.java @@ -14,9 +14,11 @@ package org.eclipse.cdt.internal.core.settings.model; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.List; import java.util.Map; import org.eclipse.cdt.core.cdtvariables.ICdtVariablesContributor; +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.settings.model.CConfigurationStatus; import org.eclipse.cdt.core.settings.model.ICBuildSetting; import org.eclipse.cdt.core.settings.model.ICConfigExtensionReference; @@ -581,4 +583,15 @@ public class MultiConfigDescription extends MultiItemsHolder implements fCfgs[i].removeStorage(id); } + public void setLanguageSettingProviders(List providers) { + if (DEBUG) + System.out.println("Bad multi access: MultiConfigDescription.setLanguageSettingProviders()"); //$NON-NLS-1$ + } + + public List getLanguageSettingProviders() { + if (DEBUG) + System.out.println("Bad multi access: MultiConfigDescription.getLanguageSettingProviders()"); //$NON-NLS-1$ + return null; + } + } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/ScannerInfoProviderProxy.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/ScannerInfoProviderProxy.java index 89e13e57c98..64cf620e576 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/ScannerInfoProviderProxy.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/ScannerInfoProviderProxy.java @@ -16,13 +16,19 @@ import java.util.List; import java.util.Map; import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; import org.eclipse.cdt.core.parser.IScannerInfo; import org.eclipse.cdt.core.parser.IScannerInfoChangeListener; import org.eclipse.cdt.core.parser.IScannerInfoProvider; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsScannerInfoProvider; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; +/** + * TODO fProvider is going to be deprecated in favor of {@link LanguageSettingsScannerInfoProvider}. + * + */ public class ScannerInfoProviderProxy extends AbstractCExtensionProxy implements IScannerInfoProvider, IScannerInfoChangeListener{ private Map> listeners; private IScannerInfoProvider fProvider; @@ -33,6 +39,11 @@ public class ScannerInfoProviderProxy extends AbstractCExtensionProxy implements } public IScannerInfo getScannerInformation(IResource resource) { + if (LanguageSettingsManager.isLanguageSettingsProvidersEnabled(getProject())) { + LanguageSettingsScannerInfoProvider lsProvider = new LanguageSettingsScannerInfoProvider(); + return lsProvider.getScannerInformation(resource); + } + // Legacy logic providerRequested(); return fProvider.getScannerInformation(resource); } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/SettingsModelMessages.properties b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/SettingsModelMessages.properties index a37c844b3f2..09dd9fd56cb 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/SettingsModelMessages.properties +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/SettingsModelMessages.properties @@ -15,8 +15,9 @@ CConfigurationDescription.0=data was not created CConfigurationDescription.1=expected proxy of type ICFileDescription, but was CConfigurationDescription.2=data was not created CConfigurationDescription.3=expected proxy of type ICFolderDescription, but was -CConfigurationStatus.1=configurations settings invalid CConfigurationDescriptionCache.0=description is read only +CConfigurationSpecSettings.MustHaveUniqueID=Language Settings Providers must have unique ID. Duplicate ID={0} +CConfigurationStatus.1=configurations settings invalid CProjectConverterDesciptor.0=illegal provider implementation CProjectConverterDesciptor.1=no provider defined CProjectDescriptionManager.1=required build system is not installed @@ -49,5 +50,8 @@ CExternalSettingsManager.3=writable ref info is requested for the read only conf CfgExportSettingContainerFactory.2=invalid id: project name not specified ExtensionContainerFactory.4=invalid setting provider class specified ExtensionContainerFactory.5=provider element not specified +LanguageSettingsBaseProvider.CanBeConfiguredOnlyOnce=LanguageSettingsBaseProvider can be configured only once +LanguageSettingsScannerInfoProvider.UnableToDetermineLanguage=Error getting ScannerInfo: Unable to determine language for resource {0} SettingsContext.0=no project associated with the context SettingsContext.1=can not accept the not-context project description + diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/xml/XmlProjectDescriptionStorage.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/xml/XmlProjectDescriptionStorage.java index a7ef3579cca..f48a2d6d2bf 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/xml/XmlProjectDescriptionStorage.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/xml/XmlProjectDescriptionStorage.java @@ -34,6 +34,7 @@ import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager_TBD; import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager; import org.eclipse.cdt.core.settings.model.ICSettingsStorage; @@ -42,6 +43,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 +172,7 @@ public class XmlProjectDescriptionStorage extends AbstractCProjectDescriptionSto serializingLock.acquire(); projectModificaitonStamp = serialize(fDes.getProject(), ICProjectDescriptionStorageType.STORAGE_FILE_NAME, fElement); ((ContributedEnvironment) CCorePlugin.getDefault().getBuildEnvironmentManager().getContributedEnvironment()).serialize(fDes); + LanguageSettingsProvidersSerializer.serializeLanguageSettings(fDes); } finally { serializingLock.release(); Job.getJobManager().removeJobChangeListener(notifyJobCanceller); @@ -481,6 +484,7 @@ public class XmlProjectDescriptionStorage extends AbstractCProjectDescriptionSto // Update the modification stamp projectModificaitonStamp = getModificationStamp(project.getFile(ICProjectDescriptionStorageType.STORAGE_FILE_NAME)); CProjectDescription des = new CProjectDescription(project, new XmlStorage(storage), storage, true, false); + LanguageSettingsProvidersSerializer.loadLanguageSettings(des); try { setThreadLocalProjectDesc(des); des.loadDatas(); diff --git a/core/org.eclipse.cdt.core/plugin.properties b/core/org.eclipse.cdt.core/plugin.properties index e791b820771..892f8ccb2ec 100644 --- a/core/org.eclipse.cdt.core/plugin.properties +++ b/core/org.eclipse.cdt.core/plugin.properties @@ -26,6 +26,7 @@ ErrorParser.name=Error Parser BinaryParser.name=Binary Parser PathEntryStore.name=Path Entry Store ScannerInfoProvider.name=Scanner Information Provider +LanguageSettingsProvider.name=Language Settings Provider CIndexer.name= C/C++ Indexer language.name= CDT Language diff --git a/core/org.eclipse.cdt.core/plugin.xml b/core/org.eclipse.cdt.core/plugin.xml index 3cb166b1acb..c8167c62bf1 100644 --- a/core/org.eclipse.cdt.core/plugin.xml +++ b/core/org.eclipse.cdt.core/plugin.xml @@ -638,8 +638,9 @@ - - + + + + + + + + + + + This extension point is used to contribute a new Language Settings Provider. A Language Settings Provider is used to get additions to compiler options such as include paths (-I) or preprocessor defines (-D) and others into the project model. + + + + + + + + + + + + + + + + + + + + + + + + ID of the extension point, not used + + + + + + + Name of the extension point, not used + + + + + + + + + + + + + The definition of a language settings provider. + + + + + + + + + + + A fully qualified name of the Java class that implements <samp>org.eclipse.cdt.core.settings.model.ILanguageSettingsProvider</samp> interface. If empty, <samp>org.eclipse.cdt.core.language.settings.providers.LanguageSettingsBaseProvider</samp> is used by default which provides basic functionality defined by this extension point. +If there is a need to configure a provider, attribute parameter could be used in a class extending <samp>LanguageSettingsBaseProvider</samp>. + + + + + + + + + + Unique ID of the provider + + + + + + + Name of the provider. This name will be presented to a user in UI. + + + + + + + A custom parameter to initialize provider. Used to deliver command for GCCBuiltinSpecsDetector as an example. + + + + + + + + + + The definition of language scope. Includes the list of language ID this provider is applicable to. If a language scope is not present, the provider will provide for any language. + + + + + + + ID of the language for which this provider provides the entries. As an example, those are languages contributed by CDT (see extension org.eclipse.cdt.core.language): +<p>- "<samp>org.eclipse.cdt.core.gcc</samp>" for C,</p> +<p>- "<samp>org.eclipse.cdt.core.g++</samp>" for C++.</p> + + + + + + + + + + The Language Settings Entries used to provide additions to compiler options such as include paths (-I) or preprocessor defines (-D) and others into the project model. + + + + + + + + + + Kind of language settings entry which maps to compiler options. For example, following mapping is used for gcc options: + +<br><samp>"-I"</samp> : includePath +<br>"<samp>-D</samp>" : macro +<br>"<samp>-include</samp>" : includeFile +<br>"<samp>-L</samp>" : libraryPath +<br>"<samp>-l</samp>" : libraryFile +<br>"<samp>-imacros</samp>" : macroFile + + + + + + + + + + + + + + + + + + + + + + + "name" attribute maps to path for the entries representing a path to a folder or file and to name for <samp>macro</samp> kind representing name-value pair. For example: +<br>"<samp>/usr/include/</samp>" +<br>"<samp>MACRO</samp>" (for <samp>#define MACRO value</samp>) +<br>Note that relative paths are treated as rooted in build working directory (when applicable). + + + + + + + "value" attribute is used for <samp>macro</samp> kind representing name-value pair only. It is not used for the entries representing a path. For example: +<br>"<samp>value</samp>" (for <samp>#define MACRO value</samp>) + + + + + + + + + + Combination of flags for the entry. + + + + + + + A value of the flag. Corresponds to <samp>ICSettingEntry</samp> flags, see JavaDoc there for more details. Here is an excerpt from the Javadoc for the flags intended to be used with this extension point (the others might be not supported): + <br>- <samp>BUILTIN</samp> : Indicates settings built in a tool (compiler) itself. That kind of settings are not passed as options to a compiler but indexer or other clients might need them. + <br>- <samp>LOCAL</samp> : Applicable for <samp>includePath</samp> only which could be local (#include "...") or system (#include <...>). If an <samp>includePath</samp> is not marked as <samp>LOCAL</samp> it is treated as system. + <br>- <samp>RESOLVED</samp> : Indicates that the entries do not need to be resolved such as expansion of environment variables, normalizing the path against build working directory etc. + <br>- <samp>VALUE_WORKSPACE_PATH</samp> : is used to indicate that the entry is a resource managed by eclipse in the workspace. The path is rooted in the workspace root. + <br>- <samp>UNDEFINED</samp> : indicates that the entry should not be defined, corresponds to <samp>-U</samp> option of gcc compiler. If this flag is defined it will negate entries with the same name (and kind) for all providers down the list. + + + + + + + + + + + + + + + + + + + + + + + + + + CDT 9.0 + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + Plug-ins that want to extend this extension point must implement <samp>org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider</samp> interface. +<br/> +For those cases where contributed settings entries (representing the compiler options) are not changed dynamically it is sufficient to configure existing class LanguageSettingsBaseProvider which is provided by default. +<br/> + + + + + + + + + [Enter information about supplied implementation of this extension point.] + + + + + + + + + Copyright (c) 2009, 2010 Andrew Gvozdev (Quoin Inc.) 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 + + + + diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/AbstractExecutableExtensionBase.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/AbstractExecutableExtensionBase.java new file mode 100644 index 00000000000..d56988056f6 --- /dev/null +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/AbstractExecutableExtensionBase.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * Copyright (c) 2009, 2010 Andrew Gvozdev (Quoin Inc.) 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 (Quoin Inc.) - initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.core; + +/** + * Helper abstract class serving as a base for creating a frame of executable class + * defined as an extension in plugin.xml. + * + */ +public abstract class AbstractExecutableExtensionBase { + private String fId; + private String fName; + + /** + * Default constructor will initialize with the name of the class + * using reflection mechanism. + */ + public AbstractExecutableExtensionBase() { + fName = this.getClass().getSimpleName(); + fId = this.getClass().getCanonicalName(); + } + + /** + * Constructor to initialize with ID and name of the extension. + * + * @param id - ID of the extension. + * @param name - name of the extension. + */ + public AbstractExecutableExtensionBase(String id, String name) { + fName = name; + fId = id; + } + + /** + * Set extension ID. + * + * @param id of extension + */ + public void setId(String id) { + fId = id; + } + + /** + * Set extension name. + * + * @param name of extension + */ + public void setName(String name) { + fName = name; + } + + /** + * @return id of extension + */ + public String getId() { + return fId; + } + + /** + * @return name of extension + */ + public String getName() { + return fName; + } + + /** + * Method toString() for debugging purposes. + */ + @SuppressWarnings("nls") + @Override + public String toString() { + return "id="+fId+", name="+fName; + } +} diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java index e39749b1a02..08d5bd5b470 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java @@ -526,7 +526,7 @@ public class CCorePlugin extends Plugin { * * @return CDT console adapter. */ - private IConsole getConsole(String extConsoleId, String contextId, String name, URL iconUrl) { + public IConsole getConsole(String extConsoleId, String contextId, String name, URL iconUrl) { try { IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(CCorePlugin.PLUGIN_ID, "CBuildConsole"); //$NON-NLS-1$ if (extensionPoint != null) { diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ErrorParserManager.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ErrorParserManager.java index aa5fe227db2..f1d0fa7e9a5 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ErrorParserManager.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ErrorParserManager.java @@ -697,7 +697,7 @@ outer: * @return URI * @since 5.1 */ - private URI toURI(IPath path) { + public URI toURI(IPath path) { // try { URI baseURI = getWorkingDirectoryURI(); String uriString = path.toString(); diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICConsoleParser.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICConsoleParser.java new file mode 100644 index 00000000000..44b216124bc --- /dev/null +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICConsoleParser.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2009, 2011 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.core; + +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.core.runtime.CoreException; + +/** + * TODO - this interface assumes configuration description. CDT project + * can be without configurations, in that case IProject should be passed + * to startup somehow. Perhaps another interface "IPConsoleParser" could + * be created when needed? + */ +public interface ICConsoleParser extends IConsoleParser { + public void startup(ICConfigurationDescription cfgDescription) throws CoreException; +} diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/ScannerProvider.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/ScannerProvider.java index 68dca092569..b349cb6b9e0 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/ScannerProvider.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/ScannerProvider.java @@ -29,8 +29,10 @@ import org.eclipse.cdt.core.model.IMacroFileEntry; import org.eclipse.cdt.core.parser.IScannerInfo; import org.eclipse.cdt.core.parser.IScannerInfoChangeListener; import org.eclipse.cdt.core.parser.IScannerInfoProvider; +import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsLogger; import org.eclipse.cdt.internal.core.model.PathEntryManager; import org.eclipse.cdt.internal.core.settings.model.ScannerInfoProviderProxy; +import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IPath; @@ -95,6 +97,13 @@ public class ScannerProvider extends AbstractCExtension implements IScannerInfoP * @see org.eclipse.cdt.core.parser.IScannerInfoProvider#getScannerInformation(org.eclipse.core.resources.IResource) */ public IScannerInfo getScannerInformation(IResource resource) { + // AG FIXME + if (resource instanceof IFile) { + LanguageSettingsLogger.logInfo("rc="+resource+" (ScannerProvider.getScannerInformation())"); + } else { + LanguageSettingsLogger.logWarning("rc="+resource+" (ScannerProvider.getScannerInformation())"); + } + IPath resPath = resource.getFullPath(); try { diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/ConsoleOutputSniffer.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/ConsoleOutputSniffer.java index aa357dd991a..bf81b071c09 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/ConsoleOutputSniffer.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/ConsoleOutputSniffer.java @@ -13,7 +13,10 @@ package org.eclipse.cdt.internal.core; import java.io.IOException; import java.io.OutputStream; +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.ErrorParserManager; import org.eclipse.cdt.core.IConsoleParser; +import org.eclipse.cdt.core.IErrorParser; /** @@ -127,6 +130,8 @@ public class ConsoleOutputSniffer { private OutputStream consoleErrorStream; private IConsoleParser[] parsers; + private ErrorParserManager errorParserManager = null; + public ConsoleOutputSniffer(IConsoleParser[] parsers) { this.parsers = parsers; } @@ -137,6 +142,11 @@ public class ConsoleOutputSniffer { this.consoleErrorStream = errorStream; } + public ConsoleOutputSniffer(OutputStream outputStream, OutputStream errorStream, IConsoleParser[] parsers, ErrorParserManager epm) { + this(outputStream, errorStream, parsers); + this.errorParserManager = epm; + } + /** * Returns an output stream that will be sniffed. * This stream should be hooked up so the command @@ -166,7 +176,13 @@ public class ConsoleOutputSniffer { public synchronized void closeConsoleOutputStream() throws IOException { if (nOpens > 0 && --nOpens == 0) { for (int i = 0; i < parsers.length; ++i) { + try { parsers[i].shutdown(); + } catch (Throwable e) { + // Report exception if any but let all the parsers chance to shutdown. + CCorePlugin.log(e); + } finally { + } } } } @@ -177,8 +193,18 @@ public class ConsoleOutputSniffer { * @param line */ private synchronized void processLine(String line) { - for (int i = 0; i < parsers.length; ++i) { - parsers[i].processLine(line); + for (IConsoleParser parser : parsers) { + try { + if (parser instanceof IErrorParser) { + // IErrorParser interface is used here only to pass ErrorParserManager + // which keeps track of CWD and provides useful methods for locating files + ((IErrorParser)parser).processLine(line, errorParserManager); + } else { + parser.processLine(line); + } + } catch (Throwable e) { + CCorePlugin.log(e); + } } } diff --git a/core/org.eclipse.cdt.ui/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.ui/META-INF/MANIFEST.MF index 643438de4c3..27dff622aef 100644 --- a/core/org.eclipse.cdt.ui/META-INF/MANIFEST.MF +++ b/core/org.eclipse.cdt.ui/META-INF/MANIFEST.MF @@ -29,6 +29,7 @@ Export-Package: org.eclipse.cdt.internal.corext;x-internal:=true, org.eclipse.cdt.internal.ui.includebrowser;x-internal:=true, org.eclipse.cdt.internal.ui.indexview;x-internal:=true, org.eclipse.cdt.internal.ui.language;x-internal:=true, + org.eclipse.cdt.internal.ui.language.settings.providers;x-internal:=true, org.eclipse.cdt.internal.ui.navigator;x-internal:=true, org.eclipse.cdt.internal.ui.newui;x-internal:=true, org.eclipse.cdt.internal.ui.preferences;x-internal:=true, diff --git a/core/org.eclipse.cdt.ui/icons/obj16/filesyst.gif b/core/org.eclipse.cdt.ui/icons/obj16/filesyst.gif index 13ce11b1490b0691db9fc3b2a7a2a2055a5cf965..4b98a62c6eed7401e6fc5d44a2b319fdf56097de 100644 GIT binary patch literal 144 zcmZ?wbhEHb6krfw*v!BnlDS$SwCmuD|Ns9V|Nn8t|I3v-n!S$n`mZQ;UQyyaC(8~f z!GHu5f3h$#FmN;IfW$y%FtFGbob+71_gjX~`5)5h0xF3*POJPp9*Uh5I`d`89Sd{T mDpsFa%+I%fXlM~*P%zM%8#eWtcG&6%MSItj?e1V;um%8#wKpgL literal 310 zcmZ?wbhEHb6krfwxXQp_5i-F#Vya!t47-?VZYlHA>(@?NeB3%}s%zRpx3q<>Df3;^ z=DVfM_sd_oXx)M9kKaz+bzP!<*zR#sLvHa2#4 zb`A~>7!1bA$;rjV1&71Axw(0GczAhv`S|$w`S}F|1Ox>Ig@l9<2!yb(u!x9=sHmuz zm>3d?6c-nlkdTm+l$4T^l9ra1k&%&=m6el|L!nUe^70A_3W|z~N=iz~%E~G#Dypig zYHDig>gpOA8k(A#T3TA#+S)ogI=Z^LdU|^L`uYY228M=)Mn*=)#>OTlCZ?vQW@cvQ z=H_TL+QPyDgTY|2SR4+A$Kx$6Ev>AqtgWpH1cHr?jjgS%ot>S%y}g5jgQKIPlarIP zv$Knfi>s@vo12@vySs;nho`5fmzS5fx3`avkFT$+3kweqkBEqfjEszmii(boj){qhjg5_qi;ItsPe@2eOiWBlN=i;nPDx2g zO-)TpOG{5r&&bHg%*@Qn%F52p&dJHi&CSir%OjCUWHLEFKfj=$ps=v8sHmv8xVWUG zq_niOtgNiOyu6~KqO!8Gs;a8Gy1J&Orna`WuCA`WzP_QMp|P>Csi~>Cxw)mKrM0!S zt*x!Sy}hHOqqDQKtE;QKySt~Sr?+5S8jdpW$b9;MxcXxMxfB*3C@c8)n^z`)n{QUCr^7{Jv_V)Jv{{Hdt z@%29;KfxdX_yQEZCw!j(Ai=;FGXgi=y-kL|QC`25YpFPvUnX$KgpC>Il0Pg69nps& zm2np$h&ZGoseqA0qs|VT2NL8_aH3$V%m-ttg1k{!KHJAIgSNSZjV$qwL z&{OL*vEJigk^S^0x4EsZi#nV)b#g85a$3{lu)UvWL%-dY3ASak_xyiUfAGcsJI}x0 zfBEC#s~?Zve1G!h=d*V|pTGa{>ch`JACA8L^y|ad-=Dtz{`%wh_n*Ii{`&KuGNAaA zg^_{5o15rEb(&zAA)EYfpgZl2uvGVX>2@ zUU4}*ZwbSP5LHh{-FM|v;`}|m{NyDY<<(nTg**k-BpG`p)l#I@1U&^*pcz@*{`l= zUE9F6rjc!WliT_h_PMRDi#nV)b#iU#=3d_Aw5G>ldq2;He!DFbY|Ccv`TwZ?|D%RG z&%fV)`QzcMACKOAfAZ$%vv)uLzhC|Q{f|HIkG}fw^UsH)Z$JI|@b&knufMJ}l zr)oo!s%n^+(o8YM$_hnAA!%XV#nRFWavW-YCxzrX!|zxvtj4Szly-PFmorJH+uKhOV1_5U9={CR(L zbv^6a2DUYgZ0lRtC#EqhuVVTC|33rKK=CIFBLjmVgAPas$W8`U^8}T?l+1Y~F;9Tj9mdfG~EN$3i2aI`GVt=ykbz`*RNf? z`oQk}`*!YKK6~ljZF_cZ+HvgAv6IJ69zSyY;J$;WPMkV&@Th0*!vFtI{{R2)-9{Q{xYzi!ojzd!Hm)rnuOPWpOf;{Cn#PZn9eTp#{=Q|#Kl_?H9)`m^Y_v_E|osjQ0xhPeU?V7 zFYefq7px@erW32aOhZI~o1e+F);Uj8NSKj>%P7ZHO;TK&kDY#h literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui/icons/ovr16/cfg_ovr.gif b/core/org.eclipse.cdt.ui/icons/ovr16/cfg_ovr.gif new file mode 100644 index 0000000000000000000000000000000000000000..f82aa5fbb497b50db3e558a244f15cf0f695c8c9 GIT binary patch literal 155 zcmZ?wbhEHbWMg1sXc1+Qa&46LY~cu<^J|3Jh1PA|dq&N(!Z@HZp>ApQj9uH0 z-*(HJ)4%@g@&h-XzWws!_us$&{{8>|pMf}__>+Z^fkB8t2c#TiCj+a>0u`@7OE;d! j9f6w-IBz>$j+3?x7IEPn{37>k44ofy`glX(f`bOrc?xK=gK zDXW`S(>k}JVMcB1tj;OR9>4z4J#G15DcpTGsJ6w(z^Q^SiVO zy0#0ucM7|Ah`4u%dUT3$5eL_B&Q0x%zw+Pzo$cYkyV0+RE8j%?`u*0ulkaBiziwpwgJJFk W))VPjF;{__89ZJ6T-G@yGywo)347)M literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui/icons/ovr16/global_ovr.gif b/core/org.eclipse.cdt.ui/icons/ovr16/global_ovr.gif new file mode 100644 index 0000000000000000000000000000000000000000..2888b2eefa908bc38baf63757b37267cab962d9a GIT binary patch literal 271 zcmZ?wbhEHbWM^P!SgOiUnpY5(v^c47O;*u_$h;L{NzFld>!WifW!KIxtnLl3SmE4% zrKo#W_~IjxQ&(ASz3g=GVdT=S`I|Q{ym)cV&1;Jf%$>5Ock7i|NAI>R+2*-t@5b{N z4$qtGa{bcOnbVqQPw%{aX2I?2=YBjt@&C*H+H~jt)CP(_Sr{1@>=|?zfB@tt2R5Ap zmyRiI%<&TPXkjr>QCrOS>`}lUr=G(HKHv6mP&#?odu56RN7J&60xVqf6&S1mYv!xl literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui/icons/ovr16/import_co.gif b/core/org.eclipse.cdt.ui/icons/ovr16/import_co.gif new file mode 100644 index 0000000000000000000000000000000000000000..b0a24b278447ece4d5bf72be153df525cc7568af GIT binary patch literal 68 zcmZ?wbhEHbWMN=oSj50^?AXUsr#=}MEHN%v>`=a(H)hs7z8?<6Bz_r7#OSp^$SR; literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui/icons/ovr16/lock_ovr.gif b/core/org.eclipse.cdt.ui/icons/ovr16/lock_ovr.gif new file mode 100644 index 0000000000000000000000000000000000000000..4499ad076d3032c1962f605cbcc968287e0dc2b2 GIT binary patch literal 115 zcmZ?wbhEHbWM|-D*v!E2?P7A5LYwJeD^zUu0gD_M|kyjcq#X zro?u|@%JYS{{R1TG*Q3z1RNtUjM)3+y5os|8M&b1TX);+PR=0 z6U6-gp8*UMf3h$#Fz_ + + + + + + + + + + + + + + + + + + + + + + + + + + + + [Enter description of this extension point.] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [Enter the first release in which this extension point appears.] + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + [Enter API information here.] + + + + + + + + + [Enter information about supplied implementation of this extension point.] + + + + + diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/ImageCombo.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/ImageCombo.java new file mode 100644 index 00000000000..8b71742590a --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/ImageCombo.java @@ -0,0 +1,1471 @@ +/******************************************************************************* + * Copyright (c) 2000, 2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * Tom Seidel - enhancements for image-handling + *******************************************************************************/ +package org.eclipse.cdt.internal.ui; + +import java.util.Arrays; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.SWTException; +import org.eclipse.swt.accessibility.ACC; +import org.eclipse.swt.accessibility.AccessibleAdapter; +import org.eclipse.swt.accessibility.AccessibleControlAdapter; +import org.eclipse.swt.accessibility.AccessibleControlEvent; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.accessibility.AccessibleTextAdapter; +import org.eclipse.swt.accessibility.AccessibleTextEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Layout; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.TypedListener; +import org.eclipse.swt.widgets.Widget; + +/** + * The ImageCombo class represents a selectable user interface object + * that combines a text field and a table and issues notification + * when an item is selected from the table. + *

+ * Note that although this class is a subclass of Composite, + * it does not make sense to add children to it, or set a layout on it. + *

+ *
+ *
Styles: + *
BORDER, READ_ONLY, FLAT
+ *
Events: + *
Selection
+ *
+ */ +public final class ImageCombo extends Composite { + + Text text; + Table table; + int visibleItemCount = 5; + Shell popup; + Button arrow; + boolean hasFocus; + Listener listener, filter; + Color foreground, background; + Font font; + +/** + * Constructs a new instance of this class given its parent + * and a style value describing its behavior and appearance. + *

+ * The style value is either one of the style constants defined in + * class SWT which is applicable to instances of this + * class, or must be built by bitwise OR'ing together + * (that is, using the int "|" operator) two or more + * of those SWT style constants. The class description + * lists the style constants that are applicable to the class. + * Style bits are also inherited from superclasses. + *

+ * + * @param parent a widget which will be the parent of the new instance (cannot be null) + * @param style the style of widget to construct + * + * @exception IllegalArgumentException
    + *
  • ERROR_NULL_ARGUMENT - if the parent is null
  • + *
+ * @exception SWTException
    + *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
  • + *
+ * + * @see SWT#BORDER + * @see SWT#READ_ONLY + * @see SWT#FLAT + * @see Widget#getStyle() + */ +public ImageCombo (Composite parent, int style) { + super (parent, style = checkStyle (style)); + + int textStyle = SWT.SINGLE; + if ((style & SWT.READ_ONLY) != 0) textStyle |= SWT.READ_ONLY; + if ((style & SWT.FLAT) != 0) textStyle |= SWT.FLAT; + text = new Text (this, SWT.NONE); + int arrowStyle = SWT.ARROW | SWT.DOWN; + if ((style & SWT.FLAT) != 0) arrowStyle |= SWT.FLAT; + arrow = new Button (this, arrowStyle); + + listener = new Listener () { + public void handleEvent (Event event) { + if (popup == event.widget) { + popupEvent (event); + return; + } + if (text == event.widget) { + textEvent (event); + return; + } + if (table == event.widget) { + listEvent (event); + return; + } + if (arrow == event.widget) { + arrowEvent (event); + return; + } + if (ImageCombo.this == event.widget) { + comboEvent (event); + return; + } + if (getShell () == event.widget) { + handleFocus (SWT.FocusOut); + } + } + }; + filter = new Listener() { + public void handleEvent(Event event) { + Shell shell = ((Control)event.widget).getShell (); + if (shell == ImageCombo.this.getShell ()) { + handleFocus (SWT.FocusOut); + } + } + }; + + int [] comboEvents = {SWT.Dispose, SWT.Move, SWT.Resize}; + for (int i=0; i + *
  • ERROR_NULL_ARGUMENT - if the string is null
  • + * + * @exception SWTException
      + *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • + *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • + *
    + * + * @see #add(String,int) + */ +public void add (String string, Image image) { + checkWidget(); + if (string == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); + TableItem newItem = new TableItem(this.table,SWT.NONE); + newItem.setText(string); + if (image != null) newItem.setImage(image); +} +/** + * Adds the argument to the receiver's list at the given + * zero-relative index. + *

    + * Note: To add an item at the end of the list, use the + * result of calling getItemCount() as the + * index or use add(String). + *

    + * + * @param string the new item + * @param index the index for the item + * + * @exception IllegalArgumentException
      + *
    • ERROR_NULL_ARGUMENT - if the string is null
    • + *
    • ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list (inclusive)
    • + *
    + * @exception SWTException
      + *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • + *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • + *
    + * + * @see #add(String) + */ +public void add (String string,Image image, int index) { + checkWidget(); + if (string == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); + TableItem newItem = new TableItem(this.table,SWT.NONE,index); + if (image != null) newItem.setImage(image); +} +/** + * Adds the listener to the collection of listeners who will + * be notified when the receiver's text is modified, by sending + * it one of the messages defined in the ModifyListener + * interface. + * + * @param listener the listener which should be notified + * + * @exception IllegalArgumentException
      + *
    • ERROR_NULL_ARGUMENT - if the listener is null
    • + *
    + * @exception SWTException
      + *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • + *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • + *
    + * + * @see ModifyListener + * @see #removeModifyListener + */ +public void addModifyListener (ModifyListener listener) { + checkWidget(); + if (listener == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); + TypedListener typedListener = new TypedListener (listener); + addListener (SWT.Modify, typedListener); +} +/** + * Adds the listener to the collection of listeners who will + * be notified when the receiver's selection changes, by sending + * it one of the messages defined in the SelectionListener + * interface. + *

    + * widgetSelected is called when the combo's list selection changes. + * widgetDefaultSelected is typically called when ENTER is pressed the combo's text area. + *

    + * + * @param listener the listener which should be notified + * + * @exception IllegalArgumentException
      + *
    • ERROR_NULL_ARGUMENT - if the listener is null
    • + *
    + * @exception SWTException
      + *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • + *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • + *
    + * + * @see SelectionListener + * @see #removeSelectionListener + * @see SelectionEvent + */ +public void addSelectionListener(SelectionListener listener) { + checkWidget(); + if (listener == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); + TypedListener typedListener = new TypedListener (listener); + addListener (SWT.Selection,typedListener); + addListener (SWT.DefaultSelection,typedListener); +} +void arrowEvent (Event event) { + switch (event.type) { + case SWT.FocusIn: { + handleFocus (SWT.FocusIn); + break; + } + case SWT.Selection: { + dropDown (!isDropped ()); + break; + } + } +} +/** + * Sets the selection in the receiver's text field to an empty + * selection starting just before the first character. If the + * text field is editable, this has the effect of placing the + * i-beam at the start of the text. + *

    + * Note: To clear the selected items in the receiver's list, + * use deselectAll(). + *

    + * + * @exception SWTException
      + *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • + *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • + *
    + * + * @see #deselectAll + */ +public void clearSelection () { + checkWidget (); + text.clearSelection (); + table.deselectAll (); +} +void comboEvent (Event event) { + switch (event.type) { + case SWT.Dispose: + if (popup != null && !popup.isDisposed ()) { + table.removeListener (SWT.Dispose, listener); + popup.dispose (); + } + Shell shell = getShell (); + shell.removeListener (SWT.Deactivate, listener); + Display display = getDisplay (); + display.removeFilter (SWT.FocusIn, filter); + popup = null; + text = null; + table = null; + arrow = null; + break; + case SWT.Move: + dropDown (false); + break; + case SWT.Resize: + internalLayout (false); + break; + } +} + +public Point computeSize (int wHint, int hHint, boolean changed) { + checkWidget (); + int width = 0, height = 0; + String[] items = getStringsFromTable(); + int textWidth = 0; + GC gc = new GC (text); + int spacer = gc.stringExtent (" ").x; //$NON-NLS-1$ + for (int i = 0; i < items.length; i++) { + textWidth = Math.max (gc.stringExtent (items[i]).x, textWidth); + } + gc.dispose(); + Point textSize = text.computeSize (SWT.DEFAULT, SWT.DEFAULT, changed); + Point arrowSize = arrow.computeSize (SWT.DEFAULT, SWT.DEFAULT, changed); + Point listSize = table.computeSize (wHint, SWT.DEFAULT, changed); + int borderWidth = getBorderWidth (); + + height = Math.max (hHint, Math.max (textSize.y, arrowSize.y) + 2*borderWidth); + width = Math.max (wHint, Math.max (textWidth + 2*spacer + arrowSize.x + 2*borderWidth, listSize.x)); + return new Point (width, height); +} +void createPopup(int selectionIndex) { + // create shell and list + popup = new Shell (getShell (), SWT.NO_TRIM | SWT.ON_TOP); + int style = getStyle (); + int listStyle = SWT.SINGLE | SWT.V_SCROLL; + if ((style & SWT.FLAT) != 0) listStyle |= SWT.FLAT; + if ((style & SWT.RIGHT_TO_LEFT) != 0) listStyle |= SWT.RIGHT_TO_LEFT; + if ((style & SWT.LEFT_TO_RIGHT) != 0) listStyle |= SWT.LEFT_TO_RIGHT; + // create a table instead of a list. + table = new Table (popup, listStyle); + if (font != null) table.setFont (font); + if (foreground != null) table.setForeground (foreground); + if (background != null) table.setBackground (background); + + int [] popupEvents = {SWT.Close, SWT.Paint, SWT.Deactivate}; + for (int i=0; i + *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • + *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • + * + */ +public void deselect (int index) { + checkWidget (); + table.deselect (index); +} +/** + * Deselects all selected items in the receiver's list. + *

    + * Note: To clear the selection in the receiver's text field, + * use clearSelection(). + *

    + * + * @exception SWTException
      + *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • + *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • + *
    + * + * @see #clearSelection + */ +public void deselectAll () { + checkWidget (); + table.deselectAll (); +} +void dropDown (boolean drop) { + if (drop == isDropped ()) return; + if (!drop) { + popup.setVisible (false); + if (!isDisposed ()&& arrow.isFocusControl()) { + text.setFocus(); + } + return; + } + + if (getShell() != popup.getParent ()) { + TableItem[] items = table.getItems (); + int selectionIndex = table.getSelectionIndex (); + table.removeListener (SWT.Dispose, listener); + popup.dispose(); + popup = null; + table = null; + createPopup (selectionIndex); + } + + Point size = getSize (); + int itemCount = table.getItemCount (); + itemCount = (itemCount == 0) ? visibleItemCount : Math.min(visibleItemCount, itemCount); + int itemHeight = table.getItemHeight () * itemCount; + Point listSize = table.computeSize (SWT.DEFAULT, itemHeight, false); + table.setBounds (1, 1, Math.max (size.x - 2, listSize.x), listSize.y); + + int index = table.getSelectionIndex (); + if (index != -1) table.setTopIndex (index); + Display display = getDisplay (); + Rectangle listRect = table.getBounds (); + Rectangle parentRect = display.map (getParent (), null, getBounds ()); + Point comboSize = getSize (); + Rectangle displayRect = getMonitor ().getClientArea (); + int width = Math.max (comboSize.x, listRect.width + 2); + int height = listRect.height + 2; + int x = parentRect.x; + int y = parentRect.y + comboSize.y; + if (y + height > displayRect.y + displayRect.height) y = parentRect.y - height; + popup.setBounds (x, y, width, height); + popup.setVisible (true); + table.setFocus (); +} +/* + * Return the Label immediately preceding the receiver in the z-order, + * or null if none. + */ +Label getAssociatedLabel () { + Control[] siblings = getParent ().getChildren (); + for (int i = 0; i < siblings.length; i++) { + if (siblings [i] == ImageCombo.this) { + if (i > 0 && siblings [i-1] instanceof Label) { + return (Label) siblings [i-1]; + } + } + } + return null; +} +public Control [] getChildren () { + checkWidget(); + return new Control [0]; +} +/** + * Gets the editable state. + * + * @return whether or not the reciever is editable + * + * @exception SWTException
      + *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • + *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • + *
    + * + * @since 3.0 + */ +public boolean getEditable () { + checkWidget (); + return text.getEditable(); +} +/** + * Returns the item at the given, zero-relative index in the + * receiver's list. Throws an exception if the index is out + * of range. + * + * @param index the index of the item to return + * @return the item at the given index + * + * @exception IllegalArgumentException
      + *
    • ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)
    • + *
    + * @exception SWTException
      + *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • + *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • + *
    + */ +public TableItem getItem (int index) { + checkWidget(); + return this.table.getItem (index); +} +/** + * Returns the number of items contained in the receiver's list. + * + * @return the number of items + * + * @exception SWTException
      + *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • + *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • + *
    + */ +public int getItemCount () { + checkWidget (); + return table.getItemCount (); +} +/** + * Returns the height of the area which would be used to + * display one of the items in the receiver's list. + * + * @return the height of one item + * + * @exception SWTException
      + *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • + *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • + *
    + */ +public int getItemHeight () { + checkWidget (); + return table.getItemHeight (); +} +/** + * Returns an array of Strings which are the items + * in the receiver's list. + *

    + * Note: This is not the actual structure used by the receiver + * to maintain its list of items, so modifying the array will + * not affect the receiver. + *

    + * + * @return the items in the receiver's list + * + * @exception SWTException
      + *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • + *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • + *
    + */ +public TableItem [] getItems () { + checkWidget (); + return table.getItems (); +} +char getMnemonic (String string) { + int index = 0; + int length = string.length (); + do { + while ((index < length) && (string.charAt (index) != '&')) index++; + if (++index >= length) return '\0'; + if (string.charAt (index) != '&') return string.charAt (index); + index++; + } while (index < length); + return '\0'; +} + +String [] getStringsFromTable() +{ + String[] items = new String[this.table.getItems().length]; + for (int i = 0, n = items.length; i < n; i++) { + items[i]=this.table.getItem(i).getText(); + } + return items; +} +/** + * Returns a Point whose x coordinate is the start + * of the selection in the receiver's text field, and whose y + * coordinate is the end of the selection. The returned values + * are zero-relative. An "empty" selection as indicated by + * the the x and y coordinates having the same value. + * + * @return a point representing the selection start and end + * + * @exception SWTException
      + *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • + *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • + *
    + */ +public Point getSelection () { + checkWidget (); + return text.getSelection (); +} +/** + * Returns the zero-relative index of the item which is currently + * selected in the receiver's list, or -1 if no item is selected. + * + * @return the index of the selected item + * + * @exception SWTException
      + *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • + *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • + *
    + */ +public int getSelectionIndex () { + checkWidget (); + return table.getSelectionIndex (); +} +public int getStyle () { + int style = super.getStyle (); + style &= ~SWT.READ_ONLY; + if (!text.getEditable()) style |= SWT.READ_ONLY; + return style; +} +/** + * Returns a string containing a copy of the contents of the + * receiver's text field. + * + * @return the receiver's text + * + * @exception SWTException
      + *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • + *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • + *
    + */ +public String getText () { + checkWidget (); + return text.getText (); +} +/** + * Returns the height of the receivers's text field. + * + * @return the text height + * + * @exception SWTException
      + *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • + *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • + *
    + */ +public int getTextHeight () { + checkWidget (); + return text.getLineHeight (); +} +/** + * Returns the maximum number of characters that the receiver's + * text field is capable of holding. If this has not been changed + * by setTextLimit(), it will be the constant + * Combo.LIMIT. + * + * @return the text limit + * + * @exception SWTException
      + *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • + *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • + *
    + */ +public int getTextLimit () { + checkWidget (); + return text.getTextLimit (); +} +/** + * Gets the number of items that are visible in the drop + * down portion of the receiver's list. + * + * @return the number of items that are visible + * + * @exception SWTException
      + *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • + *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • + *
    + * + * @since 3.0 + */ +public int getVisibleItemCount () { + checkWidget (); + return visibleItemCount; +} +void handleFocus (int type) { + if (isDisposed ()) return; + switch (type) { + case SWT.FocusIn: { + if (hasFocus) return; + if (getEditable ()) text.selectAll (); + hasFocus = true; + Shell shell = getShell (); + shell.removeListener (SWT.Deactivate, listener); + shell.addListener (SWT.Deactivate, listener); + Display display = getDisplay (); + display.removeFilter (SWT.FocusIn, filter); + display.addFilter (SWT.FocusIn, filter); + Event e = new Event (); + notifyListeners (SWT.FocusIn, e); + break; + } + case SWT.FocusOut: { + if (!hasFocus) return; + Control focusControl = getDisplay ().getFocusControl (); + if (focusControl == arrow || focusControl == table || focusControl == text) return; + hasFocus = false; + Shell shell = getShell (); + shell.removeListener(SWT.Deactivate, listener); + Display display = getDisplay (); + display.removeFilter (SWT.FocusIn, filter); + Event e = new Event (); + notifyListeners (SWT.FocusOut, e); + break; + } + } +} +/** + * Searches the receiver's list starting at the first item + * (index 0) until an item is found that is equal to the + * argument, and returns the index of that item. If no item + * is found, returns -1. + * + * @param string the search item + * @return the index of the item + * + * @exception IllegalArgumentException
      + *
    • ERROR_NULL_ARGUMENT - if the string is null
    • + *
    + * @exception SWTException
      + *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • + *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • + *
    + */ +public int indexOf (String string) { + checkWidget (); + if (string == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); + return Arrays.asList(getStringsFromTable()).indexOf (string); +} + + +void initAccessible() { + AccessibleAdapter accessibleAdapter = new AccessibleAdapter () { + public void getName (AccessibleEvent e) { + String name = null; + Label label = getAssociatedLabel (); + if (label != null) { + name = stripMnemonic (label.getText()); + } + e.result = name; + } + public void getKeyboardShortcut(AccessibleEvent e) { + String shortcut = null; + Label label = getAssociatedLabel (); + if (label != null) { + String text = label.getText (); + if (text != null) { + char mnemonic = getMnemonic (text); + if (mnemonic != '\0') { + shortcut = "Alt+"+mnemonic; //$NON-NLS-1$ + } + } + } + e.result = shortcut; + } + public void getHelp (AccessibleEvent e) { + e.result = getToolTipText (); + } + }; + getAccessible ().addAccessibleListener (accessibleAdapter); + text.getAccessible ().addAccessibleListener (accessibleAdapter); + table.getAccessible ().addAccessibleListener (accessibleAdapter); + + arrow.getAccessible ().addAccessibleListener (new AccessibleAdapter() { + public void getName (AccessibleEvent e) { + e.result = isDropped () ? SWT.getMessage ("SWT_Close") : SWT.getMessage ("SWT_Open"); //$NON-NLS-1$ //$NON-NLS-2$ + } + public void getKeyboardShortcut (AccessibleEvent e) { + e.result = "Alt+Down Arrow"; //$NON-NLS-1$ + } + public void getHelp (AccessibleEvent e) { + e.result = getToolTipText (); + } + }); + + getAccessible().addAccessibleTextListener (new AccessibleTextAdapter() { + public void getCaretOffset (AccessibleTextEvent e) { + e.offset = text.getCaretPosition (); + } + }); + + getAccessible().addAccessibleControlListener (new AccessibleControlAdapter() { + public void getChildAtPoint (AccessibleControlEvent e) { + Point testPoint = toControl (e.x, e.y); + if (getBounds ().contains (testPoint)) { + e.childID = ACC.CHILDID_SELF; + } + } + + public void getLocation (AccessibleControlEvent e) { + Rectangle location = getBounds (); + Point pt = toDisplay (location.x, location.y); + e.x = pt.x; + e.y = pt.y; + e.width = location.width; + e.height = location.height; + } + + public void getChildCount (AccessibleControlEvent e) { + e.detail = 0; + } + + public void getRole (AccessibleControlEvent e) { + e.detail = ACC.ROLE_COMBOBOX; + } + + public void getState (AccessibleControlEvent e) { + e.detail = ACC.STATE_NORMAL; + } + + public void getValue (AccessibleControlEvent e) { + e.result = getText (); + } + }); + + text.getAccessible ().addAccessibleControlListener (new AccessibleControlAdapter () { + public void getRole (AccessibleControlEvent e) { + e.detail = text.getEditable () ? ACC.ROLE_TEXT : ACC.ROLE_LABEL; + } + }); + + arrow.getAccessible ().addAccessibleControlListener (new AccessibleControlAdapter() { + public void getDefaultAction (AccessibleControlEvent e) { + e.result = isDropped () ? SWT.getMessage ("SWT_Close") : SWT.getMessage ("SWT_Open"); //$NON-NLS-1$ //$NON-NLS-2$ + } + }); +} +boolean isDropped () { + return popup.getVisible (); +} +public boolean isFocusControl () { + checkWidget(); + if (text.isFocusControl () || arrow.isFocusControl () || table.isFocusControl () || popup.isFocusControl ()) { + return true; + } + return super.isFocusControl (); +} +void internalLayout (boolean changed) { + if (isDropped ()) dropDown (false); + Rectangle rect = getClientArea (); + int width = rect.width; + int height = rect.height; + Point arrowSize = arrow.computeSize (SWT.DEFAULT, height, changed); + text.setBounds (0, 0, width - arrowSize.x, height); + arrow.setBounds (width - arrowSize.x, 0, arrowSize.x, arrowSize.y); +} +void listEvent (Event event) { + switch (event.type) { + case SWT.Dispose: + if (getShell () != popup.getParent ()) { + TableItem[] items = table.getItems (); + int selectionIndex = table.getSelectionIndex (); + popup = null; + table = null; + createPopup (selectionIndex); + } + break; + case SWT.FocusIn: { + handleFocus (SWT.FocusIn); + break; + } + case SWT.MouseUp: { + if (event.button != 1) return; + dropDown (false); + break; + } + case SWT.Selection: { + int index = table.getSelectionIndex (); + if (index == -1) return; + text.setText (table.getItem (index).getText()); + text.selectAll (); + table.setSelection (index); + Event e = new Event (); + e.time = event.time; + e.stateMask = event.stateMask; + e.doit = event.doit; + notifyListeners (SWT.Selection, e); + event.doit = e.doit; + break; + } + case SWT.Traverse: { + switch (event.detail) { + case SWT.TRAVERSE_RETURN: + case SWT.TRAVERSE_ESCAPE: + case SWT.TRAVERSE_ARROW_PREVIOUS: + case SWT.TRAVERSE_ARROW_NEXT: + event.doit = false; + break; + } + Event e = new Event (); + e.time = event.time; + e.detail = event.detail; + e.doit = event.doit; + e.character = event.character; + e.keyCode = event.keyCode; + notifyListeners (SWT.Traverse, e); + event.doit = e.doit; + event.detail = e.detail; + break; + } + case SWT.KeyUp: { + Event e = new Event (); + e.time = event.time; + e.character = event.character; + e.keyCode = event.keyCode; + e.stateMask = event.stateMask; + notifyListeners (SWT.KeyUp, e); + break; + } + case SWT.KeyDown: { + if (event.character == SWT.ESC) { + // Escape key cancels popup list + dropDown (false); + } + if ((event.stateMask & SWT.ALT) != 0 && (event.keyCode == SWT.ARROW_UP || event.keyCode == SWT.ARROW_DOWN)) { + dropDown (false); + } + if (event.character == SWT.CR) { + // Enter causes default selection + dropDown (false); + Event e = new Event (); + e.time = event.time; + e.stateMask = event.stateMask; + notifyListeners (SWT.DefaultSelection, e); + } + // At this point the widget may have been disposed. + // If so, do not continue. + if (isDisposed ()) break; + Event e = new Event(); + e.time = event.time; + e.character = event.character; + e.keyCode = event.keyCode; + e.stateMask = event.stateMask; + notifyListeners(SWT.KeyDown, e); + break; + + } + } +} + +void popupEvent(Event event) { + switch (event.type) { + case SWT.Paint: + // draw black rectangle around list + Rectangle listRect = table.getBounds(); + Color black = getDisplay().getSystemColor(SWT.COLOR_BLACK); + event.gc.setForeground(black); + event.gc.drawRectangle(0, 0, listRect.width + 1, listRect.height + 1); + break; + case SWT.Close: + event.doit = false; + dropDown (false); + break; + case SWT.Deactivate: + dropDown (false); + break; + } +} +public void redraw () { + super.redraw(); + text.redraw(); + arrow.redraw(); + if (popup.isVisible()) table.redraw(); +} +public void redraw (int x, int y, int width, int height, boolean all) { + super.redraw(x, y, width, height, true); +} + +/** + * Removes the item from the receiver's list at the given + * zero-relative index. + * + * @param index the index for the item + * + * @exception IllegalArgumentException
      + *
    • ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)
    • + *
    + * @exception SWTException
      + *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • + *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • + *
    + */ +public void remove (int index) { + checkWidget(); + table.remove (index); +} +/** + * Removes the items from the receiver's list which are + * between the given zero-relative start and end + * indices (inclusive). + * + * @param start the start of the range + * @param end the end of the range + * + * @exception IllegalArgumentException
      + *
    • ERROR_INVALID_RANGE - if either the start or end are not between 0 and the number of elements in the list minus 1 (inclusive)
    • + *
    + * @exception SWTException
      + *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • + *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • + *
    + */ +public void remove (int start, int end) { + checkWidget(); + table.remove (start, end); +} +/** + * Searches the receiver's list starting at the first item + * until an item is found that is equal to the argument, + * and removes that item from the list. + * + * @param string the item to remove + * + * @exception IllegalArgumentException
      + *
    • ERROR_NULL_ARGUMENT - if the string is null
    • + *
    • ERROR_INVALID_ARGUMENT - if the string is not found in the list
    • + *
    + * @exception SWTException
      + *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • + *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • + *
    + */ +public void remove (String string) { + checkWidget(); + if (string == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); + int index = -1; + for (int i = 0, n = table.getItemCount(); i < n; i++) { + if (table.getItem(i).getText().equals(string)) { + index = i; + break; + } + } + remove(index); +} +/** + * Removes all of the items from the receiver's list and clear the + * contents of receiver's text field. + *

    + * @exception SWTException

      + *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • + *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • + *
    + */ +public void removeAll () { + checkWidget(); + text.setText (""); //$NON-NLS-1$ + table.removeAll (); +} +/** + * Removes the listener from the collection of listeners who will + * be notified when the receiver's text is modified. + * + * @param listener the listener which should no longer be notified + * + * @exception IllegalArgumentException
      + *
    • ERROR_NULL_ARGUMENT - if the listener is null
    • + *
    + * @exception SWTException
      + *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • + *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • + *
    + * + * @see ModifyListener + * @see #addModifyListener + */ +public void removeModifyListener (ModifyListener listener) { + checkWidget(); + if (listener == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); + removeListener(SWT.Modify, listener); +} +/** + * Removes the listener from the collection of listeners who will + * be notified when the receiver's selection changes. + * + * @param listener the listener which should no longer be notified + * + * @exception IllegalArgumentException
      + *
    • ERROR_NULL_ARGUMENT - if the listener is null
    • + *
    + * @exception SWTException
      + *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • + *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • + *
    + * + * @see SelectionListener + * @see #addSelectionListener + */ +public void removeSelectionListener (SelectionListener listener) { + checkWidget(); + if (listener == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); + removeListener(SWT.Selection, listener); + removeListener(SWT.DefaultSelection,listener); +} +/** + * Selects the item at the given zero-relative index in the receiver's + * list. If the item at the index was already selected, it remains + * selected. Indices that are out of range are ignored. + * + * @param index the index of the item to select + * + * @exception SWTException
      + *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • + *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • + *
    + */ +public void select (int index) { + checkWidget(); + if (index == -1) { + table.deselectAll (); + text.setText (""); //$NON-NLS-1$ + return; + } + if (0 <= index && index < table.getItemCount()) { + if (index != getSelectionIndex()) { + text.setText (table.getItem (index).getText()); + text.selectAll (); + table.select (index); + table.showSelection (); + } + } +} +public void setBackground (Color color) { + super.setBackground(color); + background = color; + if (text != null) text.setBackground(color); + if (table != null) table.setBackground(color); + if (arrow != null) arrow.setBackground(color); +} +/** + * Sets the editable state. + * + * @param editable the new editable state + * + * @exception SWTException
      + *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • + *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • + *
    + * + * @since 3.0 + */ +public void setEditable (boolean editable) { + checkWidget (); + text.setEditable(editable); +} +public void setEnabled (boolean enabled) { + super.setEnabled(enabled); + if (popup != null) popup.setVisible (false); + if (text != null) text.setEnabled(enabled); + if (arrow != null) arrow.setEnabled(enabled); +} +public boolean setFocus () { + checkWidget(); + return text.setFocus (); +} +public void setFont (Font font) { + super.setFont (font); + this.font = font; + text.setFont (font); + table.setFont (font); + internalLayout (true); +} +public void setForeground (Color color) { + super.setForeground(color); + foreground = color; + if (text != null) text.setForeground(color); + if (table != null) table.setForeground(color); + if (arrow != null) arrow.setForeground(color); +} +/** + * Sets the text of the item in the receiver's list at the given + * zero-relative index to the string argument. This is equivalent + * to remove'ing the old item at the index, and then + * add'ing the new item at that index. + * + * @param index the index for the item + * @param string the new text for the item + * + * @exception IllegalArgumentException
      + *
    • ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)
    • + *
    • ERROR_NULL_ARGUMENT - if the string is null
    • + *
    + * @exception SWTException
      + *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • + *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • + *
    + */ +public void setItem (int index, String string, Image image) { + checkWidget(); + remove(index); + add(string,image,index); +} +/** + * Sets the receiver's list to be the given array of items. + * + * @param items the array of items + * + * @exception IllegalArgumentException
      + *
    • ERROR_NULL_ARGUMENT - if the items array is null
    • + *
    • ERROR_INVALID_ARGUMENT - if an item in the items array is null
    • + *
    + * @exception SWTException
      + *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • + *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • + *
    + */ +public void setItems (String [] items) { + checkWidget (); + this.table.removeAll(); + for (int i = 0, n = items.length; i < n; i++) { + add(items[i],null); + } + if (!text.getEditable ()) text.setText (""); //$NON-NLS-1$ +} + +/** + * Sets the layout which is associated with the receiver to be + * the argument which may be null. + *

    + * Note : No Layout can be set on this Control because it already + * manages the size and position of its children. + *

    + * + * @param layout the receiver's new layout or null + * + * @exception SWTException
      + *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • + *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • + *
    + */ +public void setLayout (Layout layout) { + checkWidget (); + return; +} +/** + * Sets the selection in the receiver's text field to the + * range specified by the argument whose x coordinate is the + * start of the selection and whose y coordinate is the end + * of the selection. + * + * @param selection a point representing the new selection start and end + * + * @exception IllegalArgumentException
      + *
    • ERROR_NULL_ARGUMENT - if the point is null
    • + *
    + * @exception SWTException
      + *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • + *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • + *
    + */ +public void setSelection (Point selection) { + checkWidget(); + if (selection == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); + text.setSelection (selection.x, selection.y); +} + +/** + * Sets the contents of the receiver's text field to the + * given string. + *

    + * Note: The text field in a Combo is typically + * only capable of displaying a single line of text. Thus, + * setting the text to a string containing line breaks or + * other special characters will probably cause it to + * display incorrectly. + *

    + * + * @param string the new text + * + * @exception IllegalArgumentException
      + *
    • ERROR_NULL_ARGUMENT - if the string is null
    • + *
    + * @exception SWTException
      + *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • + *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • + *
    + */ +public void setText (String string) { + checkWidget(); + if (string == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); + int index = -1; + for (int i = 0, n = table.getItemCount(); i < n; i++) { + if (table.getItem(i).getText().equals(string)) { + index = i; + break; + } + } + if (index == -1) { + table.deselectAll (); + text.setText (string); + return; + } + text.setText (string); + text.selectAll (); + table.setSelection (index); + table.showSelection (); +} +/** + * Sets the maximum number of characters that the receiver's + * text field is capable of holding to be the argument. + * + * @param limit new text limit + * + * @exception IllegalArgumentException
      + *
    • ERROR_CANNOT_BE_ZERO - if the limit is zero
    • + *
    + * @exception SWTException
      + *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • + *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • + *
    + */ +public void setTextLimit (int limit) { + checkWidget(); + text.setTextLimit (limit); +} + +public void setToolTipText (String string) { + checkWidget(); + super.setToolTipText(string); + arrow.setToolTipText (string); + text.setToolTipText (string); +} + +public void setVisible (boolean visible) { + super.setVisible(visible); + if (!visible) popup.setVisible(false); +} +/** + * Sets the number of items that are visible in the drop + * down portion of the receiver's list. + * + * @param count the new number of items to be visible + * + * @exception SWTException
      + *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • + *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • + *
    + * + * @since 3.0 + */ +public void setVisibleItemCount (int count) { + checkWidget (); + if (count < 0) return; + visibleItemCount = count; +} +String stripMnemonic (String string) { + int index = 0; + int length = string.length (); + do { + while ((index < length) && (string.charAt (index) != '&')) index++; + if (++index >= length) return string; + if (string.charAt (index) != '&') { + return string.substring(0, index-1) + string.substring(index, length); + } + index++; + } while (index < length); + return string; +} +void textEvent (Event event) { + switch (event.type) { + case SWT.FocusIn: { + handleFocus (SWT.FocusIn); + break; + } + case SWT.KeyDown: { + if (event.character == SWT.CR) { + dropDown (false); + Event e = new Event (); + e.time = event.time; + e.stateMask = event.stateMask; + notifyListeners (SWT.DefaultSelection, e); + } + //At this point the widget may have been disposed. + // If so, do not continue. + if (isDisposed ()) break; + + if (event.keyCode == SWT.ARROW_UP || event.keyCode == SWT.ARROW_DOWN) { + event.doit = false; + if ((event.stateMask & SWT.ALT) != 0) { + boolean dropped = isDropped (); + text.selectAll (); + if (!dropped) setFocus (); + dropDown (!dropped); + break; + } + + int oldIndex = getSelectionIndex (); + if (event.keyCode == SWT.ARROW_UP) { + select (Math.max (oldIndex - 1, 0)); + } else { + select (Math.min (oldIndex + 1, getItemCount () - 1)); + } + if (oldIndex != getSelectionIndex ()) { + Event e = new Event(); + e.time = event.time; + e.stateMask = event.stateMask; + notifyListeners (SWT.Selection, e); + } + //At this point the widget may have been disposed. + // If so, do not continue. + if (isDisposed ()) break; + } + + // Further work : Need to add support for incremental search in + // pop up list as characters typed in text widget + + Event e = new Event (); + e.time = event.time; + e.character = event.character; + e.keyCode = event.keyCode; + e.stateMask = event.stateMask; + notifyListeners (SWT.KeyDown, e); + break; + } + case SWT.KeyUp: { + Event e = new Event (); + e.time = event.time; + e.character = event.character; + e.keyCode = event.keyCode; + e.stateMask = event.stateMask; + notifyListeners (SWT.KeyUp, e); + break; + } + case SWT.Modify: { + table.deselectAll (); + Event e = new Event (); + e.time = event.time; + notifyListeners (SWT.Modify, e); + break; + } + case SWT.MouseDown: { + if (event.button != 1) return; + if (text.getEditable ()) return; + boolean dropped = isDropped (); + text.selectAll (); + if (!dropped) setFocus (); + dropDown (!dropped); + break; + } + case SWT.MouseUp: { + if (event.button != 1) return; + if (text.getEditable ()) return; + text.selectAll (); + break; + } + case SWT.Traverse: { + switch (event.detail) { + case SWT.TRAVERSE_RETURN: + case SWT.TRAVERSE_ARROW_PREVIOUS: + case SWT.TRAVERSE_ARROW_NEXT: + // The enter causes default selection and + // the arrow keys are used to manipulate the list contents so + // do not use them for traversal. + event.doit = false; + break; + } + + Event e = new Event (); + e.time = event.time; + e.detail = event.detail; + e.doit = event.doit; + e.character = event.character; + e.keyCode = event.keyCode; + notifyListeners (SWT.Traverse, e); + event.doit = e.doit; + event.detail = e.detail; + break; + } + } +} +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/AbstractLanguageSettingProviderOptionPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/AbstractLanguageSettingProviderOptionPage.java new file mode 100644 index 00000000000..7ac9d439827 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/AbstractLanguageSettingProviderOptionPage.java @@ -0,0 +1,13 @@ +package org.eclipse.cdt.internal.ui.language.settings.providers; + +import org.eclipse.cdt.ui.dialogs.AbstractCOptionPage; + +public abstract class AbstractLanguageSettingProviderOptionPage extends AbstractCOptionPage { + protected LanguageSettingsProviderTab providerTab; + protected String providerId; + + protected void init(LanguageSettingsProviderTab providerTab, String providerId) { + this.providerTab = providerTab; + this.providerId = providerId; + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingEntryDialog.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingEntryDialog.java new file mode 100644 index 00000000000..ef4be0ea722 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingEntryDialog.java @@ -0,0 +1,644 @@ +/******************************************************************************* + * Copyright (c) 2010, 2010 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 (Quoin Inc.) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.language.settings.providers; + +import org.eclipse.core.resources.IProject; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; + +import org.eclipse.cdt.core.settings.model.CIncludeFileEntry; +import org.eclipse.cdt.core.settings.model.CIncludePathEntry; +import org.eclipse.cdt.core.settings.model.CLibraryFileEntry; +import org.eclipse.cdt.core.settings.model.CLibraryPathEntry; +import org.eclipse.cdt.core.settings.model.CMacroEntry; +import org.eclipse.cdt.core.settings.model.CMacroFileEntry; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; +import org.eclipse.cdt.core.settings.model.ICSettingEntry; +import org.eclipse.cdt.ui.CDTSharedImages; +import org.eclipse.cdt.ui.newui.AbstractCPropertyTab; +import org.eclipse.cdt.ui.newui.AbstractPropertyDialog; + +import org.eclipse.cdt.internal.ui.ImageCombo; +import org.eclipse.cdt.internal.ui.newui.LanguageSettingsImages; +import org.eclipse.cdt.internal.ui.newui.Messages; + +/** + * @noextend This class is not intended to be subclassed by clients. + */ +public class LanguageSettingEntryDialog extends AbstractPropertyDialog { + private static final String SLASH = "/"; //$NON-NLS-1$ + + private ICConfigurationDescription cfgDescription; + private IProject project; + private ICLanguageSettingEntry entry; + private boolean clearValue; + private int kind; + + private Label iconComboKind; + private ImageCombo comboKind; + private ImageCombo comboPathCategory; + private Label labelInput; + public Text inputName; + private Label checkBoxValue; + public Text inputValue; + private Button buttonBrowse; + private Button buttonVars; + private Button checkBoxBuiltIn; + private Button checkBoxFramework; + + private Button checkBoxAllCfgs; + private Button checkBoxAllLangs; + + private Button buttonOk; + private Button buttonCancel; + + + private static final int COMBO_INDEX_INCLUDE_PATH = 0; + private static final int COMBO_INDEX_MACRO = 1; + private static final int COMBO_INDEX_INCLUDE_FILE = 2; + private static final int COMBO_INDEX_MACRO_FILE = 3; + private static final int COMBO_INDEX_LIBRARY_PATH = 4; + private static final int COMBO_INDEX_LIBRARY_FILE = 5; + + final private String [] comboKindItems = { + "Include Directory", + "Preprocessor Macro", + "Include File", + "Preprocessor Macros File", + "Library Path", + "Library", + }; + final private Image[] comboKindImages = { + CDTSharedImages.getImage(CDTSharedImages.IMG_OBJS_INCLUDES_FOLDER), + CDTSharedImages.getImage(CDTSharedImages.IMG_OBJS_MACRO), + CDTSharedImages.getImage(CDTSharedImages.IMG_OBJS_TUNIT_HEADER), + CDTSharedImages.getImage(CDTSharedImages.IMG_OBJS_MACROS_FILE), + CDTSharedImages.getImage(CDTSharedImages.IMG_OBJS_LIBRARY_FOLDER), + CDTSharedImages.getImage(CDTSharedImages.IMG_OBJS_LIBRARY), + }; + + private static final int COMBO_PATH_INDEX_PROJECT = 0; + private static final int COMBO_PATH_INDEX_WORKSPACE = 1; + private static final int COMBO_PATH_INDEX_FILESYSTEM = 2; + + final private String [] pathCategories = { + "Project-Relative", + "Workspace Path", + "Filesystem", + }; + final private Image[] pathCategoryImages = { + CDTSharedImages.getImage(CDTSharedImages.IMG_ETOOL_PROJECT), + CDTSharedImages.getImage(CDTSharedImages.IMG_OBJS_WORKSPACE), + CDTSharedImages.getImage(CDTSharedImages.IMG_OBJS_FILESYSTEM), + }; + + + + private ICLanguageSettingEntry[] entries; + private Composite comp1; + + public LanguageSettingEntryDialog(Shell parent, ICConfigurationDescription cfgDescription, int kind) { + super(parent, ""); + this.cfgDescription = cfgDescription; + this.project = cfgDescription.getProjectDescription().getProject(); + this.entry = null; + this.clearValue = true; + this.kind = kind; + } + + /** + * This constructor is intended to be used with {@code clearValue=true} for "Add" dialogs + * where provided entry is used as a template. + */ + public LanguageSettingEntryDialog(Shell parent, ICConfigurationDescription cfgDescription, ICLanguageSettingEntry entry, boolean clearValue) { + super(parent, ""); + this.cfgDescription = cfgDescription; + this.project = cfgDescription.getProjectDescription().getProject(); + this.entry = entry; + this.kind = entry!=null ? entry.getKind() : ICSettingEntry.INCLUDE_PATH; + this.clearValue = clearValue; + } + + /** + * This constructor is used for "Edit" dialogs to edit provided entry + */ + public LanguageSettingEntryDialog(Shell parent, ICConfigurationDescription cfgDescription, ICLanguageSettingEntry entry) { + this(parent, cfgDescription, entry, false); + } + + private int comboIndexToKind(int index) { + int kind=0; + switch (index) { + case COMBO_INDEX_INCLUDE_PATH: + kind = ICSettingEntry.INCLUDE_PATH; + break; + case COMBO_INDEX_MACRO: + kind = ICSettingEntry.MACRO; + break; + case COMBO_INDEX_INCLUDE_FILE: + kind = ICSettingEntry.INCLUDE_FILE; + break; + case COMBO_INDEX_MACRO_FILE: + kind = ICSettingEntry.MACRO_FILE; + break; + case COMBO_INDEX_LIBRARY_PATH: + kind = ICSettingEntry.LIBRARY_PATH; + break; + case COMBO_INDEX_LIBRARY_FILE: + kind = ICSettingEntry.LIBRARY_FILE; + break; + } + return kind; + } + + private int kindToComboIndex(int kind) { + int index=0; + switch (kind) { + case ICSettingEntry.INCLUDE_PATH: + index = COMBO_INDEX_INCLUDE_PATH; + break; + case ICSettingEntry.MACRO: + index = COMBO_INDEX_MACRO; + break; + case ICSettingEntry.INCLUDE_FILE: + index = COMBO_INDEX_INCLUDE_FILE; + break; + case ICSettingEntry.MACRO_FILE: + index = COMBO_INDEX_MACRO_FILE; + break; + case ICSettingEntry.LIBRARY_PATH: + index = COMBO_INDEX_LIBRARY_PATH; + break; + case ICSettingEntry.LIBRARY_FILE: + index = COMBO_INDEX_LIBRARY_FILE; + break; + } + return index; + } + + @Override + protected Control createDialogArea(Composite parent) { + parent.setLayout(new GridLayout(4, false)); + GridData gd; + + // Composite comp1 + comp1 = new Composite (parent, SWT.NONE); + gd = new GridData(GridData.FILL_HORIZONTAL); + gd.verticalAlignment = SWT.TOP; + gd.horizontalSpan = 7; + comp1.setLayoutData(gd); + comp1.setLayout(new GridLayout(7, false)); + + // Icon for kind + iconComboKind = new Label (comp1, SWT.NONE); + gd = new GridData(); + gd.verticalAlignment = SWT.TOP; + gd.horizontalAlignment = SWT.RIGHT; + iconComboKind.setLayoutData(gd); + iconComboKind.setText("Select Kind:"); + int kindToComboIndex = kindToComboIndex(kind); + iconComboKind.setImage(comboKindImages[kindToComboIndex]); + + // Combo for the setting entry kind + comboKind = new ImageCombo(comp1, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER); + for (int i = 0; i < comboKindItems.length; i++) { + comboKind.add(comboKindItems[i], comboKindImages[i]); + } + comboKind.setText(comboKindItems[kindToComboIndex]); + + comboKind.addSelectionListener(new SelectionListener() { + public void widgetSelected(SelectionEvent e) { + updateImages(); + setButtons(); + } + public void widgetDefaultSelected(SelectionEvent e) { + widgetSelected(e); + + } + }); + comboKind.setEnabled(clearValue); + + + // + // Icon for path category + final Label comboPathCategoryIcon = new Label (comp1, SWT.NONE); + gd = new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_END); + gd.verticalAlignment = SWT.TOP; + gd.widthHint = 15; + comboPathCategoryIcon.setLayoutData(gd); + comboPathCategoryIcon.setText(""); + + // Combo for path category + comboPathCategory = new ImageCombo(comp1, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER); + for (int i = 0; i < pathCategories.length; i++) { + comboPathCategory.add(pathCategories[i], pathCategoryImages[i]); + } + int pcindex = COMBO_PATH_INDEX_PROJECT; + if (entry!=null) { + if ( (entry.getFlags() & ICSettingEntry.VALUE_WORKSPACE_PATH) == 0) { + pcindex = COMBO_PATH_INDEX_FILESYSTEM; + } else { + if (entry.getName().startsWith(SLASH)) { + pcindex = COMBO_PATH_INDEX_WORKSPACE; + } else { + pcindex = COMBO_PATH_INDEX_PROJECT; + } + } + + } + comboPathCategory.setText(pathCategories[pcindex]); + gd = new GridData(SWT.FILL, SWT.NONE, false, false); + gd.verticalAlignment = SWT.TOP; + gd.horizontalSpan = 4; + comboPathCategory.setLayoutData(gd); + + comboPathCategory.addSelectionListener(new SelectionListener() { + public void widgetSelected(SelectionEvent e) { + updateImages(); + setButtons(); + } + public void widgetDefaultSelected(SelectionEvent e) { + widgetSelected(e); + + } + }); + + // Dir/File/Name label + labelInput = new Label(comp1, SWT.NONE); + labelInput.setText("Dir:"); + gd = new GridData(); + labelInput.setLayoutData(gd); + + // Dir/File/Name input + inputName = new Text(comp1, SWT.SINGLE | SWT.BORDER); + if (entry!=null && !clearValue) { + inputName.setText(entry.getName()); + } + gd = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL); + gd.horizontalSpan = 2; + gd.widthHint = 200; + inputName.setLayoutData(gd); + inputName.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + setButtons(); + }}); + + inputName.setFocus(); + inputName.setSelection(0, inputName.getText().length()); + + // Value label + checkBoxValue = new Label(comp1, SWT.NONE); + checkBoxValue.setText("Value:"); + gd = new GridData(); + checkBoxValue.setLayoutData(gd); + + // Path button + buttonBrowse = new Button(comp1, SWT.PUSH); + buttonBrowse.setText("..."); + buttonBrowse.setImage(pathCategoryImages[0]); + buttonBrowse.setLayoutData(new GridData()); + buttonBrowse.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent event) { + buttonPressed(event); + } + }); + + // Variables button + buttonVars = new Button(comp1, SWT.PUSH); + buttonVars.setText(AbstractCPropertyTab.VARIABLESBUTTON_NAME); + buttonVars.setLayoutData(new GridData()); + buttonVars.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent event) { + buttonPressed(event); + } + }); + + // Value input. Located after the other controls to get sufficient width + int comboPathWidth = comboPathCategory.computeSize(SWT.DEFAULT, SWT.NONE).x; + inputValue = new Text(comp1, SWT.SINGLE | SWT.BORDER); + if (entry!=null && !clearValue) { + inputValue.setText(entry.getValue()); + } + gd = new GridData(SWT.FILL, SWT.NONE, false, false); + gd.widthHint = comboPathWidth; + inputValue.setLayoutData(gd); + + if (entry!=null && kind==ICSettingEntry.MACRO && !clearValue) { + inputValue.setFocus(); + inputValue.setSelection(0, inputValue.getText().length()); + } + + // Checkboxes + Composite compCheckboxes = new Composite (parent, SWT.NONE); + gd = new GridData(GridData.FILL_HORIZONTAL); + gd.verticalAlignment = SWT.TOP; + gd.horizontalSpan = 4; + compCheckboxes.setLayoutData(gd); + compCheckboxes.setLayout(new GridLayout(1, false)); + + // Checkbox "Built-In" + checkBoxBuiltIn = new Button(compCheckboxes, SWT.CHECK); + checkBoxBuiltIn.setText("Treat as Built-In (Ignore during build)"); + checkBoxBuiltIn.setSelection(entry!=null && (entry.getFlags()&ICSettingEntry.BUILTIN)!=0); + gd = new GridData(GridData.FILL_HORIZONTAL); + checkBoxBuiltIn.setLayoutData(gd); + checkBoxBuiltIn.addSelectionListener(new SelectionListener() { + + public void widgetSelected(SelectionEvent e) { + updateImages(); + setButtons(); + } + + public void widgetDefaultSelected(SelectionEvent e) { + widgetSelected(e); + } + }); + + // Checkbox "Framework" + checkBoxFramework = new Button(compCheckboxes, SWT.CHECK); + checkBoxFramework.setText("Framework folder (Mac only)"); + checkBoxFramework.setSelection(entry!=null && (entry.getFlags()&ICSettingEntry.FRAMEWORKS_MAC)!=0); + gd = new GridData(GridData.FILL_HORIZONTAL); + checkBoxFramework.setLayoutData(gd); + checkBoxFramework.addSelectionListener(new SelectionListener() { + + public void widgetSelected(SelectionEvent e) { + updateImages(); + setButtons(); + } + + public void widgetDefaultSelected(SelectionEvent e) { + widgetSelected(e); + } + }); + + // Separator + @SuppressWarnings("unused") + Label separator = new Label(compCheckboxes, SWT.SEPARATOR | SWT.HORIZONTAL | SWT.SHADOW_NONE); + + // Checkbox "All configurations" + checkBoxAllCfgs = new Button(compCheckboxes, SWT.CHECK); + checkBoxAllCfgs.setText(Messages.IncludeDialog_2); + gd = new GridData(GridData.FILL_HORIZONTAL); + checkBoxAllCfgs.setLayoutData(gd); + checkBoxAllCfgs.setEnabled(false); + checkBoxAllCfgs.setToolTipText("Not implemented yet"); + + // Checkbox "All languages" + checkBoxAllLangs = new Button(compCheckboxes, SWT.CHECK); + checkBoxAllLangs.setText(Messages.IncludeDialog_3); + gd = new GridData(GridData.FILL_HORIZONTAL); + checkBoxAllLangs.setLayoutData(gd); + checkBoxAllLangs.setEnabled(false); + checkBoxAllLangs.setToolTipText("Not implemented yet"); + + // Buttons + Composite compButtons = new Composite (parent, SWT.FILL); + gd = new GridData(SWT.RIGHT, SWT.BOTTOM, false, false); + gd.horizontalSpan = 4; + gd.grabExcessVerticalSpace = true; + compButtons.setLayoutData(gd); + compButtons.setLayout(new GridLayout(4, false)); + + // placeholder + Label placeholder = new Label(compButtons, 0); + placeholder.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL)); + + // Button OK + buttonOk = new Button(compButtons, SWT.PUSH); + buttonOk.setText(IDialogConstants.OK_LABEL); + gd = new GridData(); + gd.widthHint = buttonVars.computeSize(SWT.DEFAULT,SWT.NONE).x; + buttonOk.setLayoutData(gd); + buttonOk.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent event) { + buttonPressed(event); + } + }); + + // Button Cancel + buttonCancel = new Button(compButtons, SWT.PUSH); + buttonCancel.setText(IDialogConstants.CANCEL_LABEL); + gd = new GridData(); + gd.widthHint = buttonVars.computeSize(SWT.DEFAULT, SWT.NONE).x; + buttonCancel.setLayoutData(gd); + buttonCancel.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent event) { + buttonPressed(event); + } + }); + + parent.getShell().setDefaultButton(buttonOk); + parent.pack(); + + updateImages(); + setButtons(); + return parent; + } + + private void setButtons() { + int kindSelectionIndex = comboKind.getSelectionIndex(); + boolean isMacroSelected = kindSelectionIndex==COMBO_INDEX_MACRO; + comboPathCategory.setVisible(!isMacroSelected); + buttonBrowse.setVisible(!isMacroSelected); + buttonVars.setVisible(!isMacroSelected); + checkBoxValue.setVisible(isMacroSelected); + inputValue.setVisible(isMacroSelected); + + ((GridData)checkBoxValue.getLayoutData()).exclude = !isMacroSelected; + ((GridData)inputValue.getLayoutData()).exclude = !isMacroSelected; + + ((GridData)buttonBrowse.getLayoutData()).exclude = isMacroSelected; + ((GridData)buttonVars.getLayoutData()).exclude = isMacroSelected; + + switch (kindSelectionIndex) { + case COMBO_INDEX_INCLUDE_PATH: + case COMBO_INDEX_LIBRARY_PATH: + labelInput.setText("Path:"); + break; + case COMBO_INDEX_INCLUDE_FILE: + case COMBO_INDEX_MACRO_FILE: + case COMBO_INDEX_LIBRARY_FILE: + labelInput.setText("File:"); + break; + case COMBO_INDEX_MACRO: + default: + labelInput.setText("Name:"); + } + + inputValue.setEnabled(isMacroSelected); + + int indexPathKind = comboPathCategory.getSelectionIndex(); + boolean isProjectSelected = indexPathKind==COMBO_PATH_INDEX_PROJECT; + boolean isWorkspaceSelected = indexPathKind==COMBO_PATH_INDEX_WORKSPACE; + boolean isFilesystemSelected = indexPathKind==COMBO_PATH_INDEX_FILESYSTEM; + + String path = inputName.getText(); + if (path.trim().length()==0) { + buttonOk.setEnabled(false); + } else { + buttonOk.setEnabled((isProjectSelected && !path.startsWith(SLASH)) || + (isWorkspaceSelected && path.startsWith(SLASH)) || isFilesystemSelected); + } + + buttonVars.setEnabled(isFilesystemSelected); + + comp1.layout(true); + } + + @Override + public void buttonPressed(SelectionEvent e) { + String s=null; + if (e.widget.equals(buttonOk)) { + String name = inputName.getText(); + text1 = name; + String value = inputValue.getText(); + check1 = checkBoxAllCfgs.getSelection(); + check3 = checkBoxAllLangs.getSelection(); + result = true; + + int flagBuiltIn = checkBoxBuiltIn.getSelection() ? ICSettingEntry.BUILTIN : 0; + int flagFramework = checkBoxFramework.getSelection() ? ICSettingEntry.FRAMEWORKS_MAC : 0; + int indexPathKind = comboPathCategory.getSelectionIndex(); + int kind = comboKind.getSelectionIndex(); + boolean isProjectPath = indexPathKind==COMBO_PATH_INDEX_PROJECT; + boolean isWorkspacePath = (kind!=COMBO_INDEX_MACRO) && (isProjectPath || indexPathKind==COMBO_PATH_INDEX_WORKSPACE); + int flagWorkspace = isWorkspacePath ? ICSettingEntry.VALUE_WORKSPACE_PATH : 0; + int flags = flagBuiltIn | flagWorkspace | flagFramework; + + ICLanguageSettingEntry entry=null; + switch (comboKind.getSelectionIndex()) { + case COMBO_INDEX_INCLUDE_PATH: + entry = new CIncludePathEntry(name, flags); + break; + case COMBO_INDEX_MACRO: + // note that value=null is not supported by CMacroEntry + entry = new CMacroEntry(name, value, flags); + break; + case COMBO_INDEX_INCLUDE_FILE: + entry = new CIncludeFileEntry(name, flags); + break; + case COMBO_INDEX_MACRO_FILE: + entry = new CMacroFileEntry(name, flags); + break; + case COMBO_INDEX_LIBRARY_PATH: + entry = new CLibraryPathEntry(name, flags); + break; + case COMBO_INDEX_LIBRARY_FILE: + entry = new CLibraryFileEntry(name, flags); + break; + default: + result = false; + } + + entries = new ICLanguageSettingEntry[] {entry}; + shell.dispose(); + } else if (e.widget.equals(buttonCancel)) { + shell.dispose(); + } else if (e.widget.equals(buttonBrowse)) { + boolean isDirectory = false; + boolean isFile = false; + switch (comboKind.getSelectionIndex()) { + case COMBO_INDEX_INCLUDE_PATH: + case COMBO_INDEX_LIBRARY_PATH: + isDirectory = true; + break; + case COMBO_INDEX_INCLUDE_FILE: + case COMBO_INDEX_MACRO_FILE: + case COMBO_INDEX_LIBRARY_FILE: + isFile = true; + break; + case COMBO_INDEX_MACRO: + break; + } + + if (isDirectory) { + switch (comboPathCategory.getSelectionIndex()) { + case COMBO_PATH_INDEX_WORKSPACE: + s = AbstractCPropertyTab.getWorkspaceDirDialog(shell, inputName.getText()); + break; + case COMBO_PATH_INDEX_PROJECT: + s = AbstractCPropertyTab.getProjectDirDialog(shell, inputName.getText(), project); + break; + case COMBO_PATH_INDEX_FILESYSTEM: + s = AbstractCPropertyTab.getFileSystemDirDialog(shell, inputName.getText()); + break; + } + } else if (isFile) { + switch (comboPathCategory.getSelectionIndex()) { + case COMBO_PATH_INDEX_WORKSPACE: + s = AbstractCPropertyTab.getWorkspaceFileDialog(shell, inputName.getText()); + break; + case COMBO_PATH_INDEX_PROJECT: + s = AbstractCPropertyTab.getProjectFileDialog(shell, inputName.getText(), project); + break; + case COMBO_PATH_INDEX_FILESYSTEM: + s = AbstractCPropertyTab.getFileSystemFileDialog(shell, inputName.getText()); + break; + } + } + + if (s != null) { + s = strip_wsp(s); + if (comboPathCategory.getSelectionIndex()==COMBO_PATH_INDEX_PROJECT && s.startsWith(SLASH+project.getName()+SLASH)) { + s=s.substring(project.getName().length()+2); + } + inputName.setText(s); + } + } else if (e.widget.equals(buttonVars)) { + s = AbstractCPropertyTab.getVariableDialog(shell, cfgDescription); + if (s != null) inputName.insert(s); + } + } + + public ICLanguageSettingEntry[] getEntries() { + return entries; + } + + private void updateImages() { + int indexEntryKind = comboKind.getSelectionIndex(); + int indexPathKind = comboPathCategory.getSelectionIndex(); + shell.setText("Add " + comboKindItems[indexEntryKind]); + + int kind = comboIndexToKind(indexEntryKind); + int flagBuiltin = checkBoxBuiltIn.getSelection() ? ICSettingEntry.BUILTIN : 0; + int flagFramework = checkBoxFramework.getSelection() ? ICSettingEntry.FRAMEWORKS_MAC : 0; + boolean isWorkspacePath = indexPathKind==COMBO_PATH_INDEX_PROJECT || indexPathKind==COMBO_PATH_INDEX_WORKSPACE; + int flagWorkspace = isWorkspacePath ? ICSettingEntry.VALUE_WORKSPACE_PATH : 0; + int flags = flagBuiltin | flagWorkspace | flagFramework; + Image image = LanguageSettingsImages.getImage(kind, flags, indexPathKind==COMBO_PATH_INDEX_PROJECT); + + iconComboKind.setImage(image); + shell.setImage(image); + + buttonBrowse.setImage(pathCategoryImages[indexPathKind]); + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java new file mode 100644 index 00000000000..09c5ab848ca --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java @@ -0,0 +1,1128 @@ +/******************************************************************************* + * Copyright (c) 2010, 2011 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.internal.ui.language.settings.providers; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.viewers.IDecoration; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.SashForm; +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.events.PaintListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeColumn; +import org.eclipse.swt.widgets.TreeItem; + +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsBaseProvider; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager_TBD; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable; +import org.eclipse.cdt.core.model.ILanguageDescriptor; +import org.eclipse.cdt.core.model.LanguageManager; +import org.eclipse.cdt.core.model.util.CDTListComparator; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICFileDescription; +import org.eclipse.cdt.core.settings.model.ICFolderDescription; +import org.eclipse.cdt.core.settings.model.ICLanguageSetting; +import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; +import org.eclipse.cdt.core.settings.model.ICResourceDescription; +import org.eclipse.cdt.core.settings.model.ICSettingBase; +import org.eclipse.cdt.core.settings.model.ICSettingEntry; +import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider; +import org.eclipse.cdt.ui.CDTSharedImages; +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.cdt.ui.newui.AbstractCPropertyTab; +import org.eclipse.cdt.ui.newui.CDTPrefUtil; + +import org.eclipse.cdt.internal.ui.newui.LanguageSettingsImages; +import org.eclipse.cdt.internal.ui.newui.Messages; +import org.eclipse.cdt.internal.ui.newui.StatusMessageLine; + + +/** + * This tab presents language settings entries categorized by language + * settings providers. + * + *@noinstantiate This class is not intended to be instantiated by clients. + *@noextend This class is not intended to be subclassed by clients. + */ +public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { + private static final int[] DEFAULT_ENTRIES_SASH_WEIGHTS = new int[] { 10, 30 }; + + private SashForm sashFormEntries; + private Tree treeLanguages; + private Tree treeEntries; + private TreeViewer treeEntriesViewer; + private ICLanguageSetting currentLanguageSetting = null; + private ICLanguageSetting[] allLanguages; + + private Button builtInCheckBox; + private Button enableProvidersCheckBox; + private StatusMessageLine fStatusLine; + + private Page_LanguageSettingsProviders masterPropertyPage = null; + + private static final int BUTTON_ADD = 0; + private static final int BUTTON_EDIT = 1; + private static final int BUTTON_DELETE = 2; + // there is a separator instead of button #3 + private static final int BUTTON_MOVE_UP = 4; + private static final int BUTTON_MOVE_DOWN = 5; + + private final static String[] BUTTON_LABELS = { + ADD_STR, + EDIT_STR, + DEL_STR, + null, + MOVEUP_STR, + MOVEDOWN_STR, + }; + private static final String CLEAR_STR = Messages.LanguageSettingsProviderTab_Clear; + + private Map> initialProvidersMap = new HashMap>(); + private boolean initialEnablement =false; + + private class EntriesTreeLabelProvider extends LanguageSettingsProvidersLabelProvider { + @Override + protected String[] getOverlayKeys(ILanguageSettingsProvider provider) { + String[] overlayKeys = super.getOverlayKeys(provider); + +// if (LanguageSettingsManager.isWorkspaceProvider(provider)) +// provider = LanguageSettingsManager.getRawWorkspaceProvider(provider.getId()); +// + if (currentLanguageSetting != null) { + IResource rc = getResource(); + List entries = getSettingEntries(provider); + if (entries == null && !(rc instanceof IProject)) { + List entriesParent = getSettingEntriesUpResourceTree(provider); + if (entriesParent != null /*&& entriesParent.size() > 0*/) { + overlayKeys[IDecoration.TOP_RIGHT] = CDTSharedImages.IMG_OVR_PARENT; + } + } else if (provider instanceof ILanguageSettingsEditableProvider && (page.isForFile() || page.isForFolder())) { + // Assuming that the default entries for a resource are always null. + // Using that for performance reasons. See note in PerformDefaults(). + String languageId = currentLanguageSetting.getLanguageId(); + List entriesParent = provider.getSettingEntries(null, null, languageId); + if (entries!=null && !entries.equals(entriesParent)) { + overlayKeys[IDecoration.TOP_RIGHT] = CDTSharedImages.IMG_OVR_SETTING; + } + } + } + + // TODO + ICConfigurationDescription cfgDescription = getConfigurationDescription(); + List initialProviders = initialProvidersMap.get(cfgDescription.getId()); + if (initialProviders!=null && !initialProviders.contains(provider)) { + overlayKeys[IDecoration.TOP_RIGHT] = CDTSharedImages.IMG_OVR_EDITED; + } + return overlayKeys; + } + + @Override + public Image getImage(Object element) { + if (element instanceof ICLanguageSettingEntry) { + ICLanguageSettingEntry entry = (ICLanguageSettingEntry) element; + return LanguageSettingsImages.getImage(entry); + } + + return super.getImage(element); + } + + @Override + public String getText(Object element) { + if (element instanceof ICLanguageSettingEntry) { + ICLanguageSettingEntry entry = (ICLanguageSettingEntry) element; + String s = entry.getName(); + if ((entry.getKind() == ICSettingEntry.MACRO) && (entry.getFlags()&ICSettingEntry.UNDEFINED) == 0) { + s = s + '=' + entry.getValue(); + } + return s; + } + + return super.getText(element); + } + } + + /** + * Content provider for setting entries tree. + */ + private class EntriesTreeContentProvider implements ITreeContentProvider { + public Object[] getElements(Object inputElement) { + return getChildren(inputElement); + } + + public Object[] getChildren(Object parentElement) { + if (parentElement instanceof Object[]) + return (Object[]) parentElement; + if (parentElement instanceof ILanguageSettingsProvider) { + ILanguageSettingsProvider lsProvider = (ILanguageSettingsProvider)parentElement; + List entriesList = getSettingEntriesUpResourceTree(lsProvider); + + if (builtInCheckBox.getSelection()==false) { + for (Iterator iter = entriesList.iterator(); iter.hasNext();) { + ICLanguageSettingEntry entry = iter.next(); + if (entry.isBuiltIn()) { + iter.remove(); + } + } + } + + if (entriesList!=null) { + return entriesList.toArray(); + } + } + return null; + } + + public Object getParent(Object element) { + return null; + } + + public boolean hasChildren(Object element) { + Object[] children = getChildren(element); + return children!=null && children.length>0; + } + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + } + + public void dispose() { + } + + } + + /** + * Shortcut for getting the current resource for the property page. + */ + private IResource getResource() { + return (IResource)page.getElement(); + } + + /** + * Shortcut for getting the current configuration description. + */ + private ICConfigurationDescription getConfigurationDescription() { + return getResDesc().getConfiguration(); + } + + /** + * Shortcut for getting the currently selected provider. + */ + private ILanguageSettingsProvider getSelectedProvider() { + ILanguageSettingsProvider provider = null; + + TreeItem[] items = treeEntries.getSelection(); + if (items.length>0) { + TreeItem item = items[0]; + Object itemData = item.getData(); + if (itemData instanceof ICLanguageSettingEntry) { + item = item.getParentItem(); + if (item!=null) { + itemData = item.getData(); + } + } + if (itemData instanceof ILanguageSettingsProvider) { + provider = (ILanguageSettingsProvider)itemData; + } + } + return provider; + } + + /** + * Shortcut for getting the currently selected setting entry. + */ + private ICLanguageSettingEntry getSelectedEntry() { + ICLanguageSettingEntry entry = null; + + TreeItem[] selItems = treeEntries.getSelection(); + if (selItems.length==0) { + return null; + } + + TreeItem item = selItems[0]; + Object itemData = item.getData(); + if (itemData instanceof ICLanguageSettingEntry) { + entry = (ICLanguageSettingEntry)itemData; + } + return entry; + } + + /** + * Shortcut for getting setting entries for current context. {@link LanguageSettingsManager} + * will be checking parent resources if no settings defined for current resource. + * + * @return list of setting entries for the current context. + */ + private List getSettingEntriesUpResourceTree(ILanguageSettingsProvider provider) { + if (currentLanguageSetting==null) + return null; + + String languageId = currentLanguageSetting.getLanguageId(); + if (languageId==null) + return null; + + ICConfigurationDescription cfgDescription = getConfigurationDescription(); + IResource rc = getResource(); + List entries = LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, cfgDescription, rc, languageId); + return entries; + } + + /** + * Shortcut for getting setting entries for current context without checking the parent resource. + * @return list of setting entries for the current context. + */ + private List getSettingEntries(ILanguageSettingsProvider provider) { + String languageId = currentLanguageSetting.getLanguageId(); + if (languageId==null) + return null; + + ICConfigurationDescription cfgDescription = getConfigurationDescription(); + IResource rc = getResource(); + return provider.getSettingEntries(cfgDescription, rc, languageId); + } + + private void addTreeForLanguages(Composite comp) { + treeLanguages = new Tree(comp, SWT.BORDER | SWT.SINGLE | SWT.H_SCROLL); + treeLanguages.setLayoutData(new GridData(GridData.FILL_VERTICAL)); + treeLanguages.setHeaderVisible(true); + + treeLanguages.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + TreeItem[] items = treeLanguages.getSelection(); + if (items.length > 0) { + ICLanguageSetting langSetting = (ICLanguageSetting) items[0].getData(); + if (langSetting != null) { + currentLanguageSetting = langSetting; + updateTreeEntries(); + updateButtons(); + } + } + } + }); + + final TreeColumn columnLanguages = new TreeColumn(treeLanguages, SWT.NONE); + columnLanguages.setText(Messages.AbstractLangsListTab_Languages); + columnLanguages.setWidth(200); + columnLanguages.setResizable(false); + columnLanguages.setToolTipText(Messages.AbstractLangsListTab_Languages); + + treeLanguages.addPaintListener(new PaintListener() { + public void paintControl(PaintEvent e) { + int x = treeLanguages.getBounds().width - 5; + if (columnLanguages.getWidth() != x) + columnLanguages.setWidth(x); + } + }); + + } + + private void addTreeForEntries(Composite comp) { + treeEntries = new Tree(comp, SWT.BORDER | SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL); + treeEntries.setLayoutData(new GridData(GridData.FILL_VERTICAL)); + treeEntries.setHeaderVisible(true); + treeEntries.setLinesVisible(true); + + final TreeColumn treeCol = new TreeColumn(treeEntries, SWT.NONE); + treeEntries.addPaintListener(new PaintListener() { + public void paintControl(PaintEvent e) { + int x = treeEntries.getClientArea().width; + if (treeCol.getWidth() != x) + treeCol.setWidth(x); + } + }); + + treeCol.setText(Messages.LanguageSettingsProviderTab_SettingEntries); + treeCol.setWidth(200); + treeCol.setResizable(false); + treeCol.setToolTipText(Messages.LanguageSettingsProviderTab_SettingEntriesTooltip); + + treeEntriesViewer = new TreeViewer(treeEntries); + treeEntriesViewer.setContentProvider(new EntriesTreeContentProvider()); + treeEntriesViewer.setLabelProvider(new EntriesTreeLabelProvider()); + + treeEntriesViewer.setUseHashlookup(true); + + treeEntries.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + updateStatusLine(); + updateButtons(); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + if (buttonIsEnabled(BUTTON_EDIT) && treeEntries.getSelection().length>0) + buttonPressed(BUTTON_EDIT); + } + }); + + } + + private void trackInitialSettings() { + if (!page.isForPrefs()) { + ICConfigurationDescription[] cfgDescriptions = page.getCfgsEditable(); + for (ICConfigurationDescription cfgDescription : cfgDescriptions) { + if (cfgDescription!=null) { + String cfgId = cfgDescription.getId(); + List initialProviders = cfgDescription.getLanguageSettingProviders(); + initialProvidersMap.put(cfgId, initialProviders); + } + } + initialEnablement = LanguageSettingsManager.isLanguageSettingsProvidersEnabled(page.getProject()); + } + } + + @Override + public void createControls(Composite parent) { + super.createControls(parent); + usercomp.setLayout(new GridLayout()); + GridData gd = (GridData) usercomp.getLayoutData(); + // Discourage settings entry table from trying to show all its items at once, see bug 264330 + gd.heightHint =1; + + if (page instanceof Page_LanguageSettingsProviders) { + masterPropertyPage = (Page_LanguageSettingsProviders) page; + } + + trackInitialSettings(); + + // SashForms for each mode + createShowEntriesSashForm(); + + // Status line + fStatusLine = new StatusMessageLine(usercomp, SWT.LEFT, 2); + + // "Show built-ins" checkbox + builtInCheckBox = setupCheck(usercomp, Messages.AbstractLangsListTab_ShowBuiltin, 1, GridData.FILL_HORIZONTAL); + builtInCheckBox.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + updateTreeEntries(); + } + }); + builtInCheckBox.setSelection(true); + builtInCheckBox.setEnabled(true); + + // "I want to try new scanner discovery" temporary checkbox + enableProvidersCheckBox = setupCheck(usercomp, Messages.CDTMainWizardPage_TrySD90, 2, GridData.FILL_HORIZONTAL); + enableProvidersCheckBox.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + boolean enabled = enableProvidersCheckBox.getSelection(); + if (masterPropertyPage!=null) + masterPropertyPage.setLanguageSettingsProvidersEnabled(enabled); + enableControls(enabled); + updateStatusLine(); + } + }); + + if (masterPropertyPage!=null) + enableProvidersCheckBox.setSelection(masterPropertyPage.isLanguageSettingsProvidersEnabled()); + else + enableProvidersCheckBox.setSelection(LanguageSettingsManager.isLanguageSettingsProvidersEnabled(page.getProject())); + // display but disable the checkbox for file/folder resource + enableProvidersCheckBox.setEnabled(page.isForProject()/* && !isConfigureMode*/); + enableControls(enableProvidersCheckBox.getSelection()); + + initButtons(BUTTON_LABELS); + updateData(getResDesc()); + } + + private void createShowEntriesSashForm() { + sashFormEntries = new SashForm(usercomp,SWT.HORIZONTAL); + + GridData gd = new GridData(GridData.FILL_BOTH); + gd.horizontalSpan = 2; + gd.grabExcessVerticalSpace = true; + sashFormEntries.setLayoutData(gd); + + GridLayout layout = new GridLayout(); + sashFormEntries.setLayout(layout); + + addTreeForLanguages(sashFormEntries); + addTreeForEntries(sashFormEntries); + + sashFormEntries.setWeights(DEFAULT_ENTRIES_SASH_WEIGHTS); + } + + private void enableControls(boolean enable) { + sashFormEntries.setEnabled(enable); + treeLanguages.setEnabled(enable); + treeEntries.setEnabled(enable); + builtInCheckBox.setEnabled(enable); + + buttoncomp.setEnabled(enable); + + if (enable) { + updateTreeEntries(); + } else { + disableButtons(); + } + } + + private void disableButtons() { + buttonSetEnabled(BUTTON_ADD, false); + buttonSetEnabled(BUTTON_EDIT, false); + buttonSetEnabled(BUTTON_DELETE, false); + buttonSetEnabled(BUTTON_MOVE_UP, false); + buttonSetEnabled(BUTTON_MOVE_DOWN, false); +// buttonSetEnabled(BUTTON_CONFIGURE, false); + } + + /** + * Updates state for all buttons. Called when table selection changes. + */ + @Override + protected void updateButtons() { + ILanguageSettingsProvider provider = getSelectedProvider(); + ICLanguageSettingEntry entry = getSelectedEntry(); + List entries = getSettingEntriesUpResourceTree(provider); + + boolean isEntrySelected = entry!=null; + boolean isProviderSelected = !isEntrySelected && (provider!=null); + + boolean isProviderEditable = provider instanceof ILanguageSettingsEditableProvider; +// boolean isUserProvider = provider instanceof UserLanguageSettingsProvider; + + boolean canAdd = isProviderEditable; + boolean canEdit = isProviderEditable && isEntrySelected; + boolean canDelete = isProviderEditable && isEntrySelected; + boolean canClear = isProviderEditable && isProviderSelected && entries!=null && entries.size()>0; + + boolean canMoveUp = false; + boolean canMoveDown = false; + if (isProviderEditable && isEntrySelected && entries!=null) { + int last = entries.size()-1; + int pos = getExactIndex(entries, entry); + + if (pos>=0 && pos<=last) { + canMoveUp = pos!=0; + canMoveDown = pos!=last; + } + } + + buttonSetText(BUTTON_DELETE, isProviderSelected ? CLEAR_STR : DEL_STR); + + buttonSetEnabled(BUTTON_ADD, canAdd); + buttonSetEnabled(BUTTON_EDIT, canEdit); + buttonSetEnabled(BUTTON_DELETE, canDelete || canClear); + + buttonSetEnabled(BUTTON_MOVE_UP, canMoveUp); + buttonSetEnabled(BUTTON_MOVE_DOWN, canMoveDown); + + } + + /** + * Displays warning message - if any - for selected language settings entry. + */ + private void updateStatusLine() { + IStatus status=null; + if (enableProvidersCheckBox.getSelection()==true) { + status = LanguageSettingsImages.getStatus(getSelectedEntry()); + } + if (status==null || status==Status.OK_STATUS) { + ILanguageSettingsProvider provider = getSelectedProvider(); + if (provider!=null && !(provider instanceof UserLanguageSettingsProvider)) { + String msg = "Setting entries for this provider are supplied by system and are not editable."; + status = new Status(IStatus.INFO, CUIPlugin.PLUGIN_ID, msg); + } + } + fStatusLine.setErrorStatus(status); + } + + /** + * Handle buttons + */ + @Override + public void buttonPressed(int buttonIndex) { + ILanguageSettingsProvider selectedProvider = getSelectedProvider(); + ICLanguageSettingEntry selectedEntry = getSelectedEntry(); + + switch (buttonIndex) { + case BUTTON_ADD: + performAdd(selectedProvider); + break; + case BUTTON_EDIT: + performEdit(selectedProvider, selectedEntry); + break; + case BUTTON_DELETE: + performDelete(selectedProvider, selectedEntry); + break; +// case BUTTON_CONFIGURE: +// performConfigure(selectedProvider); +// break; + case BUTTON_MOVE_UP: + performMoveUp(selectedProvider, selectedEntry); + break; + case BUTTON_MOVE_DOWN: + performMoveDown(selectedProvider, selectedEntry); + break; + default: + } + treeEntries.setFocus(); + } + + /** + * That method returns exact position of an element in the list. + * Note that {@link List#indexOf(Object)} returns position of the first element + * equals to the given one, not exact element. + * + * @param entries + * @param entry + * @return exact position of the element or -1 of not found. + */ + private int getExactIndex(List entries, ICLanguageSettingEntry entry) { + if (entries!=null) { + for (int i=0;i0) { + treeEntries.showItem(providerItem.getItems()[0]); + } + TreeItem entryItem = findEntryItem(providerId, entry); + if (entryItem!=null) { + treeEntries.showItem(entryItem); + treeEntries.select(entryItem); + } + } + } + + private void addEntry(ILanguageSettingsProvider provider, ICLanguageSettingEntry entry) { + if (provider!=null && entry != null) { + String providerId = provider.getId(); + + List entries = getWritableEntries(provider); + ICLanguageSettingEntry selectedEntry = getSelectedEntry(); + int pos = getExactIndex(entries, selectedEntry); + entries.add(pos+1, entry); + saveEntries(provider, entries); + + updateTreeEntries(); + selectItem(providerId, entry); + updateButtons(); + } + } + + private void saveEntries(ILanguageSettingsProvider provider, List entries) { + ICConfigurationDescription cfgDescription = getConfigurationDescription(); + IResource rc = getResource(); + String languageId = currentLanguageSetting.getLanguageId(); + + if (provider instanceof LanguageSettingsSerializable) { + if (entries!=null && rc!=null) { + List parentEntries = null; + if (rc instanceof IProject) { + parentEntries = new ArrayList(); + } else { + parentEntries = LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, cfgDescription, rc.getParent(), languageId); + } + if (entries.equals(parentEntries)) { + // to use parent entries instead + entries = null; + } + } + ((LanguageSettingsSerializable)provider).setSettingEntries(cfgDescription, rc, languageId, entries); + } + } + + private List getWritableEntries(ILanguageSettingsProvider provider) { + ICConfigurationDescription cfgDescription = getConfigurationDescription(); + IResource rc = getResource(); + String languageId = currentLanguageSetting.getLanguageId(); + + List entries = provider.getSettingEntries(cfgDescription, rc, languageId); + if (entries==null) { + entries = getSettingEntriesUpResourceTree(provider); + } + entries = new ArrayList(entries); + return entries; + } + + private ICLanguageSettingEntry doAdd() { + ICLanguageSettingEntry selectedEntry = getSelectedEntry(); + ICConfigurationDescription cfgDescription = getConfigurationDescription(); + LanguageSettingEntryDialog dlg = new LanguageSettingEntryDialog(usercomp.getShell(), cfgDescription, selectedEntry, true); + if (dlg.open()) { + return dlg.getEntries()[0]; + } + return null; + } + + private void performAdd(ILanguageSettingsProvider selectedProvider) { + if (selectedProvider instanceof ILanguageSettingsEditableProvider) { + ICLanguageSettingEntry settingEntry = doAdd(); + if (settingEntry!=null) { + selectedProvider = arrangeEditedCopy((ILanguageSettingsEditableProvider)selectedProvider); + addEntry(selectedProvider, settingEntry); + } + } + } + + /** + * @param selectedProvider + * @return + */ + private ILanguageSettingsEditableProvider arrangeEditedCopy(ILanguageSettingsEditableProvider selectedProvider) { + ICConfigurationDescription cfgDescription = getConfigurationDescription(); + List initialProviders = initialProvidersMap.get(cfgDescription.getId()); + if (initialProviders.contains(selectedProvider)) { + List providers = new ArrayList(cfgDescription.getLanguageSettingProviders()); + int pos = providers.indexOf(selectedProvider); + if (pos>=0) { + try { + selectedProvider = selectedProvider.clone(); + providers.set(pos, selectedProvider); + cfgDescription.setLanguageSettingProviders(providers); + } catch (CloneNotSupportedException e) { + CUIPlugin.log("Internal Error: cannot clone provider "+selectedProvider.getId(), e); + } + } else { + CUIPlugin.getDefault().logErrorMessage("Internal Error: cannot find provider "+selectedProvider.getId()); + } + } + return selectedProvider; + } + + private ICLanguageSettingEntry doEdit(ICLanguageSettingEntry ent) { + ICLanguageSettingEntry selectedEntry = getSelectedEntry(); + ICConfigurationDescription cfgDecsription = getConfigurationDescription(); + LanguageSettingEntryDialog dlg = new LanguageSettingEntryDialog(usercomp.getShell(), cfgDecsription, selectedEntry); + if (dlg.open()) { + return dlg.getEntries()[0]; + } + return null; + } + + private void performEdit(ILanguageSettingsProvider selectedProvider, ICLanguageSettingEntry selectedEntry) { + if (selectedProvider instanceof ILanguageSettingsEditableProvider) { + ICLanguageSettingEntry settingEntry = doEdit(selectedEntry); + if (settingEntry!=null) { + selectedProvider = arrangeEditedCopy((ILanguageSettingsEditableProvider)selectedProvider); + deleteEntry(selectedProvider, selectedEntry); + addEntry(selectedProvider, settingEntry); + } + } + } + + private void deleteEntry(ILanguageSettingsProvider provider, ICLanguageSettingEntry entry) { + if (provider!=null && entry != null) { + String providerId = provider.getId(); + + List entries = getWritableEntries(provider); + int pos = getExactIndex(getSettingEntriesUpResourceTree(provider), entry); + entries.remove(entry); + saveEntries(provider, entries); + + if (pos>=entries.size()) + pos = entries.size()-1; + ICLanguageSettingEntry nextEntry = pos>=0 ? entries.get(pos) : null; + + updateTreeEntries(); + selectItem(providerId, nextEntry); + updateButtons(); + } + } + + private void clearProvider(ILanguageSettingsProvider provider) { + if (provider!=null) { + String providerId = provider.getId(); + List empty = new ArrayList(); + saveEntries(provider, empty); + + updateTreeEntries(); + selectItem(providerId, null); + updateButtons(); + } + } + + private void performDelete(ILanguageSettingsProvider selectedProvider, ICLanguageSettingEntry selectedEntry) { + if (selectedProvider instanceof ILanguageSettingsEditableProvider) { + selectedProvider = arrangeEditedCopy((ILanguageSettingsEditableProvider)selectedProvider); + if (selectedEntry!=null) { + deleteEntry(selectedProvider, selectedEntry); + } else { + clearProvider(selectedProvider); + } + } + } + + private void moveEntry(ILanguageSettingsProvider provider, ICLanguageSettingEntry entry, boolean up) { + if (provider!=null && entry != null) { + String providerId = provider.getId(); + + List entries = getWritableEntries(provider); + int pos = getExactIndex(entries, entry); + int newPos = up ? pos-1 : pos+1; + Collections.swap(entries, pos, newPos); + saveEntries(provider, entries); + + updateTreeEntries(); + selectItem(providerId, entry); + updateButtons(); + } + } + + private void performMoveUp(ILanguageSettingsProvider selectedProvider, ICLanguageSettingEntry selectedEntry) { + if (selectedEntry!=null && (selectedProvider instanceof ILanguageSettingsEditableProvider)) { + selectedProvider = arrangeEditedCopy((ILanguageSettingsEditableProvider)selectedProvider); + moveEntry(selectedProvider, selectedEntry, true); + } + } + + private void performMoveDown(ILanguageSettingsProvider selectedProvider, ICLanguageSettingEntry selectedEntry) { + if (selectedEntry!=null && (selectedProvider instanceof ILanguageSettingsEditableProvider)) { + selectedProvider = arrangeEditedCopy((ILanguageSettingsEditableProvider)selectedProvider); + moveEntry(selectedProvider, selectedEntry, false); + } + } + + /** + * Get list of providers to display in the settings entry tree. + */ + private List getProviders(ICLanguageSetting languageSetting) { + List itemsList = new LinkedList(); + if (languageSetting!=null) { + String langId = languageSetting.getLanguageId(); + if (langId != null) { + IResource rc = getResource(); + ICConfigurationDescription cfgDescription = getConfigurationDescription(); + if (rc!=null && cfgDescription!=null) { + List cfgProviders = cfgDescription.getLanguageSettingProviders(); + for (ILanguageSettingsProvider cfgProvider : cfgProviders) { + ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(cfgProvider); + if (rawProvider instanceof LanguageSettingsBaseProvider) { + // filter out providers incapable of providing entries for this language + List languageIds = ((LanguageSettingsBaseProvider)rawProvider).getLanguageScope(); + if (languageIds!=null && !languageIds.contains(langId)) { + continue; + } + } + itemsList.add(cfgProvider); + } + } + } + } + return itemsList; + } + + /** + * Refreshes the entries tree in "Show Entries" mode. + */ + public void updateTreeEntries() { + List tableItems = getProviders(currentLanguageSetting); + treeEntriesViewer.setInput(tableItems.toArray(new Object[tableItems.size()])); + updateStatusLine(); + updateButtons(); + } + + private ICLanguageSetting[] getLangSettings(ICResourceDescription rcDes) { + switch (rcDes.getType()) { + case ICSettingBase.SETTING_PROJECT: + case ICSettingBase.SETTING_CONFIGURATION: + case ICSettingBase.SETTING_FOLDER: + ICFolderDescription foDes = (ICFolderDescription) rcDes; + return foDes.getLanguageSettings(); + case ICSettingBase.SETTING_FILE: + ICFileDescription fiDes = (ICFileDescription) rcDes; + ICLanguageSetting langSetting = fiDes.getLanguageSetting(); + return (langSetting != null) ? new ICLanguageSetting[] { langSetting } : null; + } + return null; + } + + private void updateTreeLanguages(ICResourceDescription rcDes) { + treeLanguages.removeAll(); + TreeItem selectedLanguageItem = null; + allLanguages = getLangSettings(rcDes); + if (allLanguages != null) { + Arrays.sort(allLanguages, CDTListComparator.getInstance()); + for (ICLanguageSetting langSetting : allLanguages) { + String langId = langSetting.getLanguageId(); + if (langId==null || langId.length()==0) + continue; + + LanguageManager langManager = LanguageManager.getInstance(); + ILanguageDescriptor langDes = langManager.getLanguageDescriptor(langId); + if (langDes == null) + continue; + + langId = langDes.getName(); + if (langId == null || langId.length()==0) + continue; + + TreeItem t = new TreeItem(treeLanguages, SWT.NONE); + t.setText(0, langId); + t.setData(langSetting); + if (selectedLanguageItem == null) { + if (currentLanguageSetting!=null) { + if (currentLanguageSetting.getLanguageId().equals(langSetting.getLanguageId())) { + selectedLanguageItem = t; + currentLanguageSetting = langSetting; + } + } else { + selectedLanguageItem = t; + currentLanguageSetting = langSetting; + } + } + } + + if (selectedLanguageItem != null) { + treeLanguages.setSelection(selectedLanguageItem); + } + } + } + + /** + * Called when configuration changed Refreshes languages list entries tree. + */ + @Override + public void updateData(ICResourceDescription rcDes) { + if (!canBeVisible()) + return; + + if (rcDes!=null) { + if (page.isMultiCfg()) { + setAllVisible(false, null); + return; + } else { + setAllVisible(true, null); + } + + updateTreeLanguages(rcDes); + updateTreeEntries(); + if (masterPropertyPage!=null) { + boolean enabled = masterPropertyPage.isLanguageSettingsProvidersEnabled(); + enableProvidersCheckBox.setSelection(enabled); + enableControls(enabled); + } + } + updateButtons(); + } + + @Override + protected void performDefaults() { + // This page restores defaults for file/folder only. + // Project and Preferences page are restored by LanguageSettingsProviderTab. + if (page.isForFile() || page.isForFolder()) { + // The logic below is not exactly correct as the default for a resource could be different than null. + // It is supposed to match the one taken from extension for the same resource which in theory can be non-null. + // However for the performance reasons for resource decorators where the same logic is used + // we use null for resetting file/folder resource which should be correct in most cases. + // Count that as a feature. + boolean changed = false; + ICConfigurationDescription cfgDescription = getConfigurationDescription(); + IResource rc = getResource(); + List providers = cfgDescription.getLanguageSettingProviders(); + List writableProviders = new ArrayList(providers.size()); + +providers: for (ILanguageSettingsProvider provider : providers) { + ILanguageSettingsEditableProvider writableProvider = null; + if (provider instanceof ILanguageSettingsEditableProvider) { + TreeItem[] tisLang = treeLanguages.getItems(); + for (TreeItem tiLang : tisLang) { + Object item = tiLang.getData(); + if (item instanceof ICLanguageSetting) { + String languageId = ((ICLanguageSetting)item).getLanguageId(); + if (languageId!=null) { + if (provider.getSettingEntries(cfgDescription, rc, languageId)!=null) { + try { + // clone providers to be able to "Cancel" in UI + if (writableProvider==null) { + writableProvider = ((ILanguageSettingsEditableProvider) provider).clone(); + } + writableProvider.setSettingEntries(cfgDescription, rc, languageId, null); + changed = true; + } catch (CloneNotSupportedException e) { + CUIPlugin.log("Internal Error: cannot clone provider "+provider.getId(), e); + continue providers; + } + } + } + } + } + } + if (writableProvider!=null) + writableProviders.add(writableProvider); + else + writableProviders.add(provider); + } + if (changed) { + cfgDescription.setLanguageSettingProviders(writableProviders); +// updateTreeEntries(); +// updateData(getResDesc()); + List tableItems = getProviders(currentLanguageSetting); + treeEntriesViewer.setInput(tableItems.toArray(new Object[tableItems.size()])); + } + } + } + + @Override + protected void performApply(ICResourceDescription srcRcDescription, ICResourceDescription destRcDescription) { + if (!page.isForPrefs()) { + ICConfigurationDescription srcCfgDescription = srcRcDescription.getConfiguration(); + ICConfigurationDescription destCfgDescription = destRcDescription.getConfiguration(); + + List providers = srcCfgDescription.getLanguageSettingProviders(); + destCfgDescription.setLanguageSettingProviders(providers); + } + + if (!page.isForPrefs()) { + ICConfigurationDescription sd = srcRcDescription.getConfiguration(); + ICConfigurationDescription dd = destRcDescription.getConfiguration(); + List newProviders = sd.getLanguageSettingProviders(); + dd.setLanguageSettingProviders(newProviders); + } + + performOK(); + } + + @Override + protected void performOK() { + if (page.isForProject() && enableProvidersCheckBox!=null) { + boolean enabled = enableProvidersCheckBox.getSelection(); + if (masterPropertyPage!=null) + enabled = masterPropertyPage.isLanguageSettingsProvidersEnabled(); + LanguageSettingsManager.setLanguageSettingsProvidersEnabled(page.getProject(), enabled); + enableProvidersCheckBox.setSelection(enabled); + } + + try { + LanguageSettingsManager_TBD.serializeWorkspaceProviders(); + } catch (CoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + throw new UnsupportedOperationException("Internal Error"); + } + + trackInitialSettings(); + updateData(getResDesc()); + } + + @Override + public boolean canBeVisible() { + if (CDTPrefUtil.getBool(CDTPrefUtil.KEY_NO_SHOW_PROVIDERS)) + return false; + if (page.isForPrefs()) + return true; + + ICLanguageSetting [] langSettings = getLangSettings(getResDesc()); + if (langSettings == null) + return false; + + for (ICLanguageSetting langSetting : langSettings) { + String langId = langSetting.getLanguageId(); + if (langId!=null && langId.length()>0) { + LanguageManager langManager = LanguageManager.getInstance(); + ILanguageDescriptor langDes = langManager.getLanguageDescriptor(langId); + if (langDes != null) + return true; + } + } + + return false; + } + + /** + * Shortcut for setting setting entries for current context. + * + */ + private void setSettingEntries(ILanguageSettingsEditableProvider provider, List entries) { + ICConfigurationDescription cfgDescription = getConfigurationDescription(); + IResource rc = getResource(); + String languageId = currentLanguageSetting.getLanguageId(); + if (languageId!=null) + provider.setSettingEntries(cfgDescription, rc, languageId, entries); + } + + @Override + protected boolean isIndexerAffected() { +// List newProvidersList = null; +// ICConfigurationDescription cfgDescription = getConfigurationDescription(); +// if (cfgDescription!=null) { +// newProvidersList = cfgDescription.getLanguageSettingProviders(); +// } +// boolean newEnablement = LanguageSettingsManager.isLanguageSettingsProvidersEnabled(page.getProject()); +// +// boolean isEqualList = (newProvidersList==initialProvidersList) || (newProvidersList!=null && newProvidersList.equals(initialProvidersList)); +// return newEnablement!=initialEnablement || (newEnablement==true && !isEqualList); + // FIXME + return true; + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderAssociation.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderAssociation.java new file mode 100644 index 00000000000..76537635cd5 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderAssociation.java @@ -0,0 +1,246 @@ +package org.eclipse.cdt.internal.ui.language.settings.providers; + +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtension; +import org.eclipse.core.runtime.IExtensionPoint; +import org.eclipse.core.runtime.IExtensionRegistry; +import org.eclipse.core.runtime.Platform; + +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; +import org.eclipse.cdt.ui.CDTSharedImages; +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.cdt.ui.dialogs.ICOptionPage; + +public class LanguageSettingsProviderAssociation { + public static final String LANGUAGE_SETTINGS_PROVIDER_UI = "LanguageSettingsProviderAssociation"; //$NON-NLS-1$ + + private static final String ELEM_ID_ASSOCIATION = "id-association"; //$NON-NLS-1$ + private static final String ELEM_CLASS_ASSOCIATION = "class-association"; //$NON-NLS-1$ + private static final String ATTR_ID = "id"; //$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_PAGE = "page"; //$NON-NLS-1$ + + static private List loadedIcons = null; + static private Map fImagesUrlById = null; + static private Map fImagesUrlByClass = null; + static private List fRegirestedIds = null; + static private List fRegisteredClasses = null; + + private static void loadExtensions() { + if (loadedIcons!=null) { + return; + } + if (loadedIcons==null) loadedIcons = new ArrayList(); + if (fImagesUrlById==null) fImagesUrlById = new HashMap(); + if (fImagesUrlByClass==null) fImagesUrlByClass = new HashMap(); + if (fRegirestedIds==null) fRegirestedIds = new ArrayList(); + if (fRegisteredClasses==null) fRegisteredClasses = new ArrayList(); + + IExtensionRegistry registry = Platform.getExtensionRegistry(); + IExtensionPoint extension = registry.getExtensionPoint(CUIPlugin.PLUGIN_ID, LanguageSettingsProviderAssociation.LANGUAGE_SETTINGS_PROVIDER_UI); + if (extension != null) { + IExtension[] extensions = extension.getExtensions(); + for (IExtension ext : extensions) { + @SuppressWarnings("unused") + String extensionID = ext.getUniqueIdentifier(); + for (IConfigurationElement cfgEl : ext.getConfigurationElements()) { + if (cfgEl.getName().equals(ELEM_ID_ASSOCIATION)) { + String id = cfgEl.getAttribute(ATTR_ID); + URL url = getIconUrl(cfgEl); + fImagesUrlById.put(id, url); + fRegirestedIds.add(id); + } else if (cfgEl.getName().equals(ELEM_CLASS_ASSOCIATION)) { + String className = cfgEl.getAttribute(ATTR_CLASS); + URL url = getIconUrl(cfgEl); + fImagesUrlByClass.put(className, url); + String pageClass = cfgEl.getAttribute(ATTR_PAGE); + if (pageClass!=null && pageClass.trim().length()>0) { + fRegisteredClasses.add(className); + } + } + } + } + } + + } + + private static URL getIconUrl(IConfigurationElement config) { + URL url = null; + try { + String iconName = config.getAttribute(ATTR_ICON); + if (iconName != null) { + URL pluginInstallUrl = Platform.getBundle(config.getDeclaringExtension().getContributor().getName()).getEntry("/"); //$NON-NLS-1$ + url = new URL(pluginInstallUrl, iconName); + if (loadedIcons.contains(url)) + return url; + } + } catch (MalformedURLException exception) {} + + loadedIcons.add(url); + if (url!=null) { + CDTSharedImages.register(url); + } + + return url; + } + + public static URL getImageUrl(String id) { + if (fImagesUrlById==null) { + loadExtensions(); + } + return fImagesUrlById.get(id); + } + + private static ICOptionPage createOptionsPageById(String providerId) { + if (fRegirestedIds==null) { + loadExtensions(); + } + if (fRegirestedIds.contains(providerId)) { + IExtensionRegistry registry = Platform.getExtensionRegistry(); + IExtensionPoint extension = registry.getExtensionPoint(CUIPlugin.PLUGIN_ID, LanguageSettingsProviderAssociation.LANGUAGE_SETTINGS_PROVIDER_UI); + if (extension != null) { + IExtension[] extensions = extension.getExtensions(); + for (IExtension ext : extensions) { + try { + @SuppressWarnings("unused") + String extensionID = ext.getUniqueIdentifier(); + for (IConfigurationElement cfgEl : ext.getConfigurationElements()) { + if (cfgEl.getName().equals(ELEM_ID_ASSOCIATION)) { + String id = cfgEl.getAttribute(ATTR_ID); + if (providerId.equals(id)) { + String pageClass = cfgEl.getAttribute(ATTR_PAGE); + if (pageClass!=null && pageClass.trim().length()>0) { + ICOptionPage page = (ICOptionPage) cfgEl.createExecutableExtension(ATTR_PAGE); + return page; + } + } + } + } + } catch (Exception e) { + CUIPlugin.log("Cannot load LanguageSettingsProviderAssociation extension " + ext.getUniqueIdentifier(), e); //$NON-NLS-1$ + } + } + } + } + return null; + } + + private static ICOptionPage createOptionsPageByClass(String providerClassName) { + if (fRegisteredClasses==null) { + loadExtensions(); + } + if (fRegisteredClasses.contains(providerClassName)) { + IExtensionRegistry registry = Platform.getExtensionRegistry(); + IExtensionPoint extension = registry.getExtensionPoint(CUIPlugin.PLUGIN_ID, LanguageSettingsProviderAssociation.LANGUAGE_SETTINGS_PROVIDER_UI); + if (extension != null) { + IExtension[] extensions = extension.getExtensions(); + for (IExtension ext : extensions) { + try { + @SuppressWarnings("unused") + String extensionID = ext.getUniqueIdentifier(); + for (IConfigurationElement cfgEl : ext.getConfigurationElements()) { + if (cfgEl.getName().equals(ELEM_CLASS_ASSOCIATION)) { + String className = cfgEl.getAttribute(ATTR_CLASS); + if (providerClassName.equals(className)) { + String pageClass = cfgEl.getAttribute(ATTR_PAGE); + if (pageClass!=null && pageClass.trim().length()>0) { + ICOptionPage page = (ICOptionPage) cfgEl.createExecutableExtension(ATTR_PAGE); + return page; + } + } + } + } + } catch (Exception e) { + CUIPlugin.log("Cannot load LanguageSettingsProviderAssociation extension " + ext.getUniqueIdentifier(), e); //$NON-NLS-1$ + } + } + } + } + return null; + } + + /** + * Returns Language Settings Provider image registered for closest superclass + * or interface. + * + * @param clazz - class to find Language Settings Provider image. + * @return image or {@code null} + */ + public static URL getImage(Class clazz) { + URL url = null; + + outer: for (Class cl=clazz;cl!=null;cl=cl.getSuperclass()) { + url = getImageURL(cl); + if (url!=null) + break; + + // this does not check for superinterfaces, feel free to implement as needed + for (Class in : cl.getInterfaces()) { + url = getImageURL(in); + if (url!=null) + break outer; + } + } + return url; + } + + private static URL getImageURL(Class clazz) { + String className = clazz.getCanonicalName(); + Set> entrySet = fImagesUrlByClass.entrySet(); + for (Entry entry : entrySet) { + if (entry.getKey().equals(className)) { + return entry.getValue(); + } + } + return null; + } + + /** + * Returns Language Settings Provider image registered for closest superclass. + * @param provider TODO + * @return image or {@code null} + */ + public static ICOptionPage createOptionsPage(ILanguageSettingsProvider provider) { + String id = provider.getId(); + ICOptionPage optionsPage = createOptionsPageById(id); + if (optionsPage!=null) { + return optionsPage; + } + + Class clazz = provider.getClass(); + outer: for (Class cl=clazz;cl!=null;cl=cl.getSuperclass()) { + optionsPage = createOptionsPageByClass(cl); + if (optionsPage!=null) + break; + + // this does not check for superinterfaces, feel free to implement as needed + for (Class in : cl.getInterfaces()) { + optionsPage = createOptionsPageByClass(in); + if (optionsPage!=null) + break outer; + } + } + return optionsPage; + } + + private static ICOptionPage createOptionsPageByClass(Class c) { + ICOptionPage optionsPage = null; + String className = c.getCanonicalName(); + if (fRegisteredClasses.contains(className)) { + optionsPage = createOptionsPageByClass(className); + } + return optionsPage; + } + + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java new file mode 100644 index 00000000000..afcc404fad5 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java @@ -0,0 +1,1059 @@ +/******************************************************************************* + * Copyright (c) 2010, 2011 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.internal.ui.language.settings.providers; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; + +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.CheckStateChangedEvent; +import org.eclipse.jface.viewers.CheckboxTableViewer; +import org.eclipse.jface.viewers.ICheckStateListener; +import org.eclipse.jface.viewers.IDecoration; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.SashForm; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Link; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Table; +import org.eclipse.ui.dialogs.PreferencesUtil; + +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager_TBD; +import org.eclipse.cdt.core.model.ILanguageDescriptor; +import org.eclipse.cdt.core.model.LanguageManager; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICFileDescription; +import org.eclipse.cdt.core.settings.model.ICFolderDescription; +import org.eclipse.cdt.core.settings.model.ICLanguageSetting; +import org.eclipse.cdt.core.settings.model.ICResourceDescription; +import org.eclipse.cdt.core.settings.model.ICSettingBase; +import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider; +import org.eclipse.cdt.ui.CDTSharedImages; +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.cdt.ui.dialogs.DialogsMessages; +import org.eclipse.cdt.ui.dialogs.ICOptionPage; +import org.eclipse.cdt.ui.newui.AbstractCPropertyTab; +import org.eclipse.cdt.ui.newui.CDTPrefUtil; +import org.eclipse.cdt.utils.ui.controls.TabFolderLayout; + +import org.eclipse.cdt.internal.ui.newui.Messages; +import org.eclipse.cdt.internal.ui.newui.StatusMessageLine; + +/** + * This tab presents language settings entries categorized by language + * settings providers. + * + *@noinstantiate This class is not intended to be instantiated by clients. + *@noextend This class is not intended to be subclassed by clients. + */ +public class LanguageSettingsProviderTab extends AbstractCPropertyTab { + private static final String WORKSPACE_PREFERENCE_PAGE = "org.eclipse.cdt.ui.preferences.BuildSettingProperties"; //$NON-NLS-1$ + // TODO: generalize + private static final String TEST_PLUGIN_ID_PATTERN = "org.eclipse.cdt.*.tests.*"; //$NON-NLS-1$ + +// private static final String RENAME_STR = "Rename..."; +// private static final String RUN_STR = Messages.LanguageSettingsProviderTab_Run; + private static final String CLEAR_STR = Messages.LanguageSettingsProviderTab_Clear; + private static final String RESET_STR = "Reset"; + +// private static final int BUTTON_RENAME = 0; +// private static final int BUTTON_RUN = 0; + private static final int BUTTON_CLEAR = 0; + private static final int BUTTON_RESET = 1; + // there is a separator instead of button #2 + private static final int BUTTON_MOVE_UP = 3; + private static final int BUTTON_MOVE_DOWN = 4; + + private final static String[] BUTTON_LABELS_PROJECT = { +// RENAME_STR, +// RUN_STR, + CLEAR_STR, + RESET_STR, + null, + MOVEUP_STR, + MOVEDOWN_STR, + }; + + private final static String[] BUTTON_LABELS_PREF = { +// RENAME_STR, +// RUN_STR, + CLEAR_STR, + RESET_STR, + }; + + private static final int[] DEFAULT_CONFIGURE_SASH_WEIGHTS = new int[] { 50, 50 }; + private SashForm sashFormConfigure; + + private Table tableProviders; + private CheckboxTableViewer tableProvidersViewer; + private Group groupOptionsPage; + private ICOptionPage currentOptionsPage = null; + private Composite compositeOptionsPage; + + private Button enableProvidersCheckBox; + private StatusMessageLine fStatusLine; + + private Button globalProviderCheckBox = null; + private Link linkWorkspacePreferences = null; + + private Page_LanguageSettingsProviders masterPropertyPage = null; + + /** + * List of providers presented to the user. + * For global providers included in a configuration this contains references + * not raw providers. + */ + private List presentedProviders = null; + private final Map optionsPageMap = new HashMap(); + private Map> initialProvidersByCfg = new HashMap>(); + + private boolean initialEnablement = false; + + /** + * Returns current working copy of the provider. Creates one if it has not been created yet. + * Used by option pages when there is a need to modify the provider. + * Warning: Do not cache the result as the provider can be replaced at any time. + * @param providerId + * + * @return the provider + */ + public ILanguageSettingsProvider getWorkingCopy(String providerId) { + ILanguageSettingsProvider provider = findProvider(providerId, presentedProviders); + if (isWorkingCopy(provider)) + return provider; + + ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); + Assert.isTrue(rawProvider instanceof ILanguageSettingsEditableProvider); + + ILanguageSettingsEditableProvider editableProvider = (ILanguageSettingsEditableProvider)rawProvider; + try { + ILanguageSettingsEditableProvider newProvider = editableProvider.clone(); + replaceSelectedProvider(newProvider); + return newProvider; + + } catch (CloneNotSupportedException e) { + CUIPlugin.log("Error cloning provider " + editableProvider.getId(), e); + // TODO warning dialog for user? + } + + return null; + } + + private class ProvidersTableLabelProvider extends LanguageSettingsProvidersLabelProvider { + @Override + protected String[] getOverlayKeys(ILanguageSettingsProvider provider) { + String[] overlayKeys = super.getOverlayKeys(provider); + + ILanguageSettingsProvider rawProvider = page.isForPrefs() ? LanguageSettingsManager.getRawProvider(provider) : provider; + if (LanguageSettingsManager_TBD.isReconfigured(rawProvider)) { + overlayKeys[IDecoration.TOP_RIGHT] = CDTSharedImages.IMG_OVR_SETTING; + } + + if (isWorkingCopy(provider)) { + overlayKeys[IDecoration.TOP_RIGHT] = CDTSharedImages.IMG_OVR_EDITED; + } + return overlayKeys; + } + } + + /** + * Shortcut for getting the current resource for the property page. + */ + private IResource getResource() { + return (IResource)page.getElement(); + } + + /** + * Shortcut for getting the current configuration description. + */ + private ICConfigurationDescription getConfigurationDescription() { + if (page.isForPrefs()) + return null; + + ICConfigurationDescription cfgDescription = getResDesc().getConfiguration(); + return cfgDescription; + } + + /** + * Shortcut for getting the currently selected provider. + */ + private ILanguageSettingsProvider getSelectedProvider() { + ILanguageSettingsProvider provider = null; + + int pos = tableProviders.getSelectionIndex(); + if (pos >= 0 && pos initialProviders = cfgDescription.getLanguageSettingProviders(); + initialProvidersByCfg.put(cfgId, initialProviders); + } + } + initialEnablement = LanguageSettingsManager.isLanguageSettingsProvidersEnabled(page.getProject()); + } + } + + @Override + public void createControls(Composite parent) { + super.createControls(parent); + usercomp.setLayout(new GridLayout()); + GridData gd = (GridData) usercomp.getLayoutData(); + // Discourage settings entry table from trying to show all its items at once, see bug 264330 + gd.heightHint =1; + + if (page instanceof Page_LanguageSettingsProviders) { + masterPropertyPage = (Page_LanguageSettingsProviders) page; + } + + trackInitialSettings(); + + // SashForms for each mode + createConfigureSashForm(); + + // Status line + fStatusLine = new StatusMessageLine(usercomp, SWT.LEFT, 2); + + // "I want to try new scanner discovery" temporary checkbox + enableProvidersCheckBox = setupCheck(usercomp, Messages.CDTMainWizardPage_TrySD90, 2, GridData.FILL_HORIZONTAL); + enableProvidersCheckBox.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + boolean enabled = enableProvidersCheckBox.getSelection(); + if (masterPropertyPage!=null) + masterPropertyPage.setLanguageSettingsProvidersEnabled(enabled); + enableControls(enabled); + updateStatusLine(); + } + }); + + if (masterPropertyPage!=null) + enableProvidersCheckBox.setSelection(masterPropertyPage.isLanguageSettingsProvidersEnabled()); + else + enableProvidersCheckBox.setSelection(LanguageSettingsManager.isLanguageSettingsProvidersEnabled(page.getProject())); + // display but disable the checkbox for file/folder resource + enableProvidersCheckBox.setEnabled(page.isForProject() /*|| page.isForPrefs()*/); + enableControls(enableProvidersCheckBox.getSelection()); + + if (page.isForPrefs()) { + initButtons(BUTTON_LABELS_PREF); + } else { + initButtons(BUTTON_LABELS_PROJECT); + } + updateData(getResDesc()); + } + + private void createConfigureSashForm() { + // SashForm for Configure + sashFormConfigure = new SashForm(usercomp, SWT.VERTICAL); + GridLayout layout = new GridLayout(); + sashFormConfigure.setLayout(layout); + + // Providers table + Composite compositeSashForm = new Composite(sashFormConfigure, SWT.BORDER | SWT.SINGLE); + compositeSashForm.setLayout(new GridLayout()); + + // items checkboxes only for project properties page + tableProviders = new Table(compositeSashForm, page.isForPrefs() ? SWT.NONE : SWT.CHECK); + tableProviders.setLayoutData(new GridData(GridData.FILL_BOTH)); + tableProviders.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + displaySelectedOptionPage(); + updateButtons(); + } + }); + tableProvidersViewer = new CheckboxTableViewer(tableProviders); + tableProvidersViewer.setContentProvider(new ArrayContentProvider()); + tableProvidersViewer.setLabelProvider(new ProvidersTableLabelProvider()); + + tableProvidersViewer.addCheckStateListener(new ICheckStateListener() { + public void checkStateChanged(CheckStateChangedEvent e) { + saveCheckedProviders(e.getElement()); + tableProvidersViewer.update(e.getElement(), null); + }}); + + createOptionsControl(); + + sashFormConfigure.setWeights(DEFAULT_CONFIGURE_SASH_WEIGHTS); + enableSashForm(sashFormConfigure, true); + } + + private Link createLinkToPreferences(final Composite parent) { + Link link = new Link(parent, SWT.NONE); +// // FIXME +// link.setText(DialogsMessages.RegexErrorParserOptionPage_LinkToPreferencesMessage + " Select Discovery Tab."); + + link.addListener(SWT.Selection, new Listener() { + public void handleEvent(Event event) { + // Use event.text to tell which link was used + PreferencesUtil.createPreferenceDialogOn(parent.getShell(), WORKSPACE_PREFERENCE_PAGE, null, null).open(); + } + }); + + return link; + } + + // Called from globalProviderCheckBox listener + private void toggleGlobalProvider(ILanguageSettingsProvider oldProvider, boolean toGlobal) { + ILanguageSettingsProvider newProvider = null; + + String id = oldProvider.getId(); + if (toGlobal) { + newProvider = LanguageSettingsManager.getWorkspaceProvider(id); + } else { + // Local provider instance chosen + try { + ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(oldProvider); + if (rawProvider instanceof ILanguageSettingsEditableProvider) { + newProvider = ((ILanguageSettingsEditableProvider) rawProvider).cloneShallow(); + } + } catch (CloneNotSupportedException e) { + CUIPlugin.log("Error cloning provider " + oldProvider.getId(), e); + } + } + if (newProvider!=null) { + replaceSelectedProvider(newProvider); + + ICConfigurationDescription cfgDescription = getConfigurationDescription(); + initializeOptionsPage(newProvider, cfgDescription); + displaySelectedOptionPage(); + } + } + + private void replaceSelectedProvider(ILanguageSettingsProvider newProvider) { + int pos = tableProviders.getSelectionIndex(); + presentedProviders.set(pos, newProvider); + tableProvidersViewer.setInput(presentedProviders); + tableProviders.setSelection(pos); + + ICConfigurationDescription cfgDescription = null; + if (!page.isForPrefs()) { + cfgDescription = getConfigurationDescription(); + + List cfgProviders = new ArrayList(cfgDescription.getLanguageSettingProviders()); + pos = getProviderIndex(newProvider.getId(), cfgProviders); + cfgProviders.set(pos, newProvider); + cfgDescription.setLanguageSettingProviders(cfgProviders); + tableProvidersViewer.setCheckedElements(cfgProviders.toArray(new ILanguageSettingsProvider[0])); + } + refreshItem(newProvider); + } + + public void refreshItem(ILanguageSettingsProvider provider) { + tableProvidersViewer.refresh(provider); + updateButtons(); + } + + private void createOptionsControl() { + groupOptionsPage = new Group(sashFormConfigure, SWT.SHADOW_ETCHED_IN); + groupOptionsPage.setText("Language Settings Provider Options"); + groupOptionsPage.setLayout(new GridLayout(2, false)); + + if (!page.isForPrefs()) { + if (globalProviderCheckBox==null) { + globalProviderCheckBox = new Button(groupOptionsPage, SWT.CHECK); + globalProviderCheckBox.setText("Use global provider sharing settings among projects"); + globalProviderCheckBox.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + boolean isGlobal = globalProviderCheckBox.getSelection(); + ILanguageSettingsProvider provider = getSelectedProvider(); + if (isGlobal != LanguageSettingsManager.isWorkspaceProvider(provider)) { + toggleGlobalProvider(provider, isGlobal); + } + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + widgetSelected(e); + } + + }); + + linkWorkspacePreferences = createLinkToPreferences(groupOptionsPage); + } + } + + compositeOptionsPage = new Composite(groupOptionsPage, SWT.NONE); + compositeOptionsPage.setLayout(new TabFolderLayout()); + } + + private void enableSashForm(SashForm sashForm, boolean enable) { + sashForm.setVisible(enable); + // Some of woodoo to fill properties page vertically and still keep right border visible in preferences + GridData gd = new GridData(enable || page.isForPrefs() ? GridData.FILL_BOTH : SWT.NONE); + gd.horizontalSpan = 2; + gd.heightHint = enable ? SWT.DEFAULT : 0; + sashForm.setLayoutData(gd); + } + + private void enableControls(boolean enable) { + sashFormConfigure.setEnabled(enable); + tableProviders.setEnabled(enable); + compositeOptionsPage.setEnabled(enable); + + buttoncomp.setEnabled(enable); + + if (enable) { + displaySelectedOptionPage(); + } else { + if (currentOptionsPage != null) { + currentOptionsPage.setVisible(false); + } + disableButtons(); + } + } + + /** + * Populate provider tables and their option pages which are used in Configure mode + */ + private void updateProvidersTable() { + ILanguageSettingsProvider selectedProvider = getSelectedProvider(); + String selectedId = selectedProvider!=null ? selectedProvider.getId() : null; + + // update viewer if the list of providers changed + tableProvidersViewer.setInput(presentedProviders); + + ICConfigurationDescription cfgDescription = getConfigurationDescription(); + if (cfgDescription!=null) { + List cfgProviders = cfgDescription.getLanguageSettingProviders(); + tableProvidersViewer.setCheckedElements(cfgProviders.toArray(new ILanguageSettingsProvider[0])); + } + + if (selectedId!=null) { + for (int i=0; i idsList = new ArrayList(); + + List providers; + ICConfigurationDescription cfgDescription = getConfigurationDescription(); + if (cfgDescription!=null) { + providers = new ArrayList(cfgDescription.getLanguageSettingProviders()); + for (ILanguageSettingsProvider provider : providers) { + idsList.add(provider.getId()); + } + } else { + providers = new ArrayList(); + } + + List workspaceProviders = LanguageSettingsManager.getWorkspaceProviders(); + + // ensure sorting by name all unchecked providers + Set allAvailableProvidersSet = new TreeSet(new Comparator() { + public int compare(ILanguageSettingsProvider prov1, ILanguageSettingsProvider prov2) { + Boolean isTest1 = prov1.getId().matches(TEST_PLUGIN_ID_PATTERN); + Boolean isTest2 = prov2.getId().matches(TEST_PLUGIN_ID_PATTERN); + int result = isTest1.compareTo(isTest2); + if (result==0) + result = prov1.getName().compareTo(prov2.getName()); + return result; + } + }); + allAvailableProvidersSet.addAll(workspaceProviders); + + for (ILanguageSettingsProvider provider : allAvailableProvidersSet) { + String id = provider.getId(); + if (!idsList.contains(id)) { + providers.add(provider); + idsList.add(id); + } + } + + // renders better when using temporary + presentedProviders = providers; + tableProvidersViewer.setInput(presentedProviders); + } + + private ICOptionPage createOptionsPage(ILanguageSettingsProvider provider, ICConfigurationDescription cfgDescription) { + ICOptionPage optionsPage = null; + if (provider!=null) { + ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); + if (rawProvider!=null) { + optionsPage = LanguageSettingsProviderAssociation.createOptionsPage(rawProvider); + } + + if (optionsPage instanceof AbstractLanguageSettingProviderOptionPage) { + ((AbstractLanguageSettingProviderOptionPage)optionsPage).init(this, provider.getId()); + } + } + + return optionsPage; + } + + private void initializeOptionsPage(ILanguageSettingsProvider provider, ICConfigurationDescription cfgDescription) { + ICOptionPage optionsPage = createOptionsPage(provider, cfgDescription); + + if (optionsPage!=null) { + ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); + boolean isEditableForProject = page.isForProject() && provider instanceof ILanguageSettingsEditableProvider; + boolean isEditableForPrefs = page.isForPrefs() && rawProvider instanceof ILanguageSettingsEditableProvider; + boolean isEditable = isEditableForProject || isEditableForPrefs; + compositeOptionsPage.setEnabled(isEditable); + + String id = (provider!=null) ? provider.getId() : null; + optionsPageMap.put(id, optionsPage); + optionsPage.setContainer(page); + optionsPage.createControl(compositeOptionsPage); + optionsPage.setVisible(false); + compositeOptionsPage.layout(true); + } + } + + private void displaySelectedOptionPage() { + if (currentOptionsPage != null) { + currentOptionsPage.setVisible(false); + } + + ILanguageSettingsProvider provider = getSelectedProvider(); + String id = (provider!=null) ? provider.getId() : null; + + boolean isGlobal = LanguageSettingsManager.isWorkspaceProvider(provider); + ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); + + currentOptionsPage = optionsPageMap.get(id); + + boolean isChecked = tableProvidersViewer.getChecked(provider); + if (!page.isForPrefs()) { + boolean isRawProviderEditable = rawProvider instanceof ILanguageSettingsEditableProvider; + globalProviderCheckBox.setSelection(isGlobal); + globalProviderCheckBox.setEnabled(isChecked && isRawProviderEditable); + globalProviderCheckBox.setVisible(provider!=null); + + boolean needPreferencesLink=isGlobal && currentOptionsPage!=null; + // TODO: message + linkWorkspacePreferences.setText(needPreferencesLink ? DialogsMessages.RegexErrorParserOptionPage_LinkToPreferencesMessage + " Select Discovery Tab." : ""); + linkWorkspacePreferences.pack(); + } + + if (currentOptionsPage != null) { + boolean isEditableForProject = page.isForProject() && provider instanceof ILanguageSettingsEditableProvider; + boolean isEditableForPrefs = page.isForPrefs() && rawProvider instanceof ILanguageSettingsEditableProvider; + boolean isEditable = isEditableForProject || isEditableForPrefs; + currentOptionsPage.getControl().setEnabled(isEditable); + currentOptionsPage.setVisible(true); + + compositeOptionsPage.setEnabled(isEditable); +// compositeOptionsPage.layout(true); + } + } + + + private void saveCheckedProviders(Object selectedElement) { + if (page.isForProject()) { + Object[] checked = tableProvidersViewer.getCheckedElements(); + List providers = new ArrayList(checked.length); + for (Object element : checked) { + ILanguageSettingsProvider provider = (ILanguageSettingsProvider)element; + providers.add(provider); + } + ICConfigurationDescription cfgDescription = getConfigurationDescription(); + cfgDescription.setLanguageSettingProviders(providers); + + if (selectedElement!=null) { + tableProvidersViewer.update(selectedElement, null); + if (selectedElement instanceof ILanguageSettingsProvider) { + ILanguageSettingsProvider selectedProvider = (ILanguageSettingsProvider) selectedElement; + initializeOptionsPage(selectedProvider, cfgDescription); + displaySelectedOptionPage(); + } + } + } + } + + private void disableButtons() { +// buttonSetEnabled(BUTTON_RENAME, false); +// buttonSetEnabled(BUTTON_RUN, false); + buttonSetEnabled(BUTTON_CLEAR, false); + buttonSetEnabled(BUTTON_RESET, false); + buttonSetEnabled(BUTTON_MOVE_UP, false); + buttonSetEnabled(BUTTON_MOVE_DOWN, false); +// buttonSetEnabled(BUTTON_CONFIGURE, false); + } + + /** + * Updates state for all buttons. Called when table selection changes. + */ + @Override + protected void updateButtons() { + ILanguageSettingsProvider provider = getSelectedProvider(); + boolean isProviderSelected =provider!=null; + boolean canForWorkspace = isProviderSelected && page.isForPrefs(); + boolean canForProject = isProviderSelected && page.isForProject() && !LanguageSettingsManager.isWorkspaceProvider(provider); + + int pos = tableProviders.getSelectionIndex(); + int count = tableProviders.getItemCount(); + int last = count - 1; + boolean isRangeOk = pos >= 0 && pos <= last; + + ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); + boolean canClear = false; + if (rawProvider instanceof ILanguageSettingsEditableProvider) { + if (!((ILanguageSettingsEditableProvider) rawProvider).isEmpty()) { + canClear = canForWorkspace || canForProject; + } + } + + boolean canReset = false; + if (rawProvider!=null && (canForWorkspace || canForProject)) { + canReset = ! LanguageSettingsManager_TBD.isEqualExtensionProvider(rawProvider); + } + + boolean canMoveUp = page.isForProject() && isProviderSelected && isRangeOk && pos!=0; + boolean canMoveDown = page.isForProject() && isProviderSelected && isRangeOk && pos!=last; + +// buttonSetEnabled(BUTTON_RENAME, false); +// buttonSetEnabled(BUTTON_RUN, false); + buttonSetEnabled(BUTTON_CLEAR, canClear); + buttonSetEnabled(BUTTON_RESET, canReset); + buttonSetEnabled(BUTTON_MOVE_UP, canMoveUp); + buttonSetEnabled(BUTTON_MOVE_DOWN, canMoveDown); + } + + /** + * Displays warning message - if any - for selected language settings entry. + */ + private void updateStatusLine() { +// IStatus status=null; +// fStatusLine.setErrorStatus(status); + } + + /** + * Handle buttons + */ + @Override + public void buttonPressed(int buttonIndex) { + ILanguageSettingsProvider selectedProvider = getSelectedProvider(); + + switch (buttonIndex) { +// case BUTTON_RENAME: +// performRename(selectedProvider); +// break; +// case BUTTON_RUN: +// performRun(selectedProvider); +// break; + case BUTTON_CLEAR: + performClear(selectedProvider); + break; + case BUTTON_RESET: + performReset(selectedProvider); + break; + case BUTTON_MOVE_UP: + performMoveUp(selectedProvider); + break; + case BUTTON_MOVE_DOWN: + performMoveDown(selectedProvider); + break; + default: + } + } + + private void performClear(ILanguageSettingsProvider selectedProvider) { + if (isWorkingCopy(selectedProvider)) { + if (selectedProvider instanceof ILanguageSettingsEditableProvider) { + ILanguageSettingsEditableProvider editableProvider = (ILanguageSettingsEditableProvider) selectedProvider; + editableProvider.clear(); + tableProvidersViewer.update(selectedProvider, null); + } + } else { + ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(selectedProvider); + if (rawProvider instanceof ILanguageSettingsEditableProvider) { + ILanguageSettingsEditableProvider editableProvider = (ILanguageSettingsEditableProvider) rawProvider; + + try { + ILanguageSettingsEditableProvider newProvider = editableProvider.cloneShallow(); + replaceSelectedProvider(newProvider); + + ICConfigurationDescription cfgDescription = getConfigurationDescription(); + initializeOptionsPage(newProvider, cfgDescription); + displaySelectedOptionPage(); + + } catch (CloneNotSupportedException e) { + CUIPlugin.log("Error cloning provider " + editableProvider.getId(), e); + return; + } + } + + } + updateButtons(); + } + + private void performReset(ILanguageSettingsProvider selectedProvider) { + ILanguageSettingsProvider newProvider = LanguageSettingsManager.getExtensionProviderCopy(selectedProvider.getId()); + replaceSelectedProvider(newProvider); + + ICConfigurationDescription cfgDescription = getConfigurationDescription(); + initializeOptionsPage(newProvider, cfgDescription); + displaySelectedOptionPage(); + updateButtons(); + } + + private boolean isWorkingCopy(ILanguageSettingsProvider provider) { + boolean isWorkingCopy = false; + if (page.isForPrefs()) { + isWorkingCopy = ! LanguageSettingsManager.isWorkspaceProvider(provider); + } else { + if (!LanguageSettingsManager.isWorkspaceProvider(provider)) { + ICConfigurationDescription cfgDescription = getConfigurationDescription(); + List initialProviders = initialProvidersByCfg.get(cfgDescription.getId()); + isWorkingCopy = ! initialProviders.contains(provider); + } + + } + return isWorkingCopy; + } + + private void performMoveUp(ILanguageSettingsProvider selectedProvider) { + int pos = presentedProviders.indexOf(selectedProvider); + if (pos > 0) { + moveProvider(pos, pos-1); + } + } + + private void performMoveDown(ILanguageSettingsProvider selectedProvider) { + int pos = presentedProviders.indexOf(selectedProvider); + int last = presentedProviders.size() - 1; + if (pos >= 0 && pos < last) { + moveProvider(pos, pos+1); + } + } + + private void moveProvider(int oldPos, int newPos) { + Collections.swap(presentedProviders, oldPos, newPos); + + updateProvidersTable(); + tableProviders.setSelection(newPos); + + saveCheckedProviders(null); + updateButtons(); + } + + private ICLanguageSetting[] getLangSettings(ICResourceDescription rcDes) { + switch (rcDes.getType()) { + case ICSettingBase.SETTING_PROJECT: + case ICSettingBase.SETTING_CONFIGURATION: + case ICSettingBase.SETTING_FOLDER: + ICFolderDescription foDes = (ICFolderDescription) rcDes; + return foDes.getLanguageSettings(); + case ICSettingBase.SETTING_FILE: + ICFileDescription fiDes = (ICFileDescription) rcDes; + ICLanguageSetting langSetting = fiDes.getLanguageSetting(); + return (langSetting != null) ? new ICLanguageSetting[] { langSetting } : null; + } + return null; + } + + /** + * Called when configuration changed + */ + @Override + public void updateData(ICResourceDescription rcDes) { + if (!canBeVisible()) + return; + + if (rcDes!=null) { + if (page.isMultiCfg()) { + setAllVisible(false, null); + return; + } else { + setAllVisible(true, null); + } + + if (masterPropertyPage!=null) { + boolean enabled = masterPropertyPage.isLanguageSettingsProvidersEnabled(); + enableProvidersCheckBox.setSelection(enabled); + enableControls(enabled); + } + } + + // for Preference page initialize providers list just once as no configuration here to change + // and re-initializing could ruins modified providers in case of switching tabs or pages + if (!page.isForPrefs() || presentedProviders==null) { + initializeProviders(); + } + updateProvidersTable(); + updateButtons(); + } + + @Override + protected void performDefaults() { + if (enableProvidersCheckBox==null || enableProvidersCheckBox.getSelection()==false) + return; + + if (page.isForPrefs() || page.isForProject()) { + if (MessageDialog.openQuestion(usercomp.getShell(), + Messages.LanguageSettingsProviderTab_TitleResetProviders, + Messages.LanguageSettingsProviderTab_AreYouSureToResetProviders)) { + + if (page.isForProject()) { + ICConfigurationDescription cfgDescription = getConfigurationDescription(); + List cfgProviders = new ArrayList(cfgDescription.getLanguageSettingProviders()); + boolean atLeastOneChanged = false; + for (int i=0;i providers = new ArrayList(presentedProviders); + for (int i=0;i destProviders = new ArrayList(); + + List srcProviders = srcCfgDescription.getLanguageSettingProviders(); + for (ILanguageSettingsProvider pro : srcProviders) { + // TODO: clone + destProviders.add(pro); + } + + destCfgDescription.setLanguageSettingProviders(destProviders); + } + + if (!page.isForPrefs()) { + ICConfigurationDescription sd = srcRcDescription.getConfiguration(); + ICConfigurationDescription dd = destRcDescription.getConfiguration(); + List newProviders = sd.getLanguageSettingProviders(); + dd.setLanguageSettingProviders(newProviders); + } + + performOK(); + } + + @Override + protected void performOK() { + if (!page.isForPrefs()) { + // FIXME: for now only handles current configuration + ICResourceDescription rcDesc = getResDesc(); + IResource rc = getResource(); + ICConfigurationDescription cfgDescription = rcDesc.getConfiguration(); + + List destProviders = new ArrayList(); + List providers = cfgDescription.getLanguageSettingProviders(); + for (ILanguageSettingsProvider pro : providers) { + // TODO: clone + destProviders.add(pro); + } + cfgDescription.setLanguageSettingProviders(destProviders); + } + + // Build Settings page + if (page.isForPrefs()) { + try { + LanguageSettingsManager.setWorkspaceProviders(presentedProviders); + } catch (CoreException e) { + CUIPlugin.log("Error setting user defined providers", e); + } + initializeProviders(); + } + + if (page.isForProject() && enableProvidersCheckBox!=null) { + boolean enabled = enableProvidersCheckBox.getSelection(); + if (masterPropertyPage!=null) + enabled = masterPropertyPage.isLanguageSettingsProvidersEnabled(); + LanguageSettingsManager.setLanguageSettingsProvidersEnabled(page.getProject(), enabled); + enableProvidersCheckBox.setSelection(enabled); + } + + Collection optionPages = optionsPageMap.values(); + for (ICOptionPage op : optionPages) { + try { + op.performApply(null); + } catch (CoreException e) { + CUIPlugin.log("Error applying options page", e); + } + } + + try { + LanguageSettingsManager_TBD.serializeWorkspaceProviders(); + } catch (CoreException e) { + CUIPlugin.log("Internal Error", e); + throw new UnsupportedOperationException("Internal Error"); + } + + trackInitialSettings(); + updateData(getResDesc()); + } + + @Override + public boolean canBeVisible() { + if (CDTPrefUtil.getBool(CDTPrefUtil.KEY_NO_SHOW_PROVIDERS)) + return false; + if (page.isForPrefs()) + return true; + + if (!page.isForProject()) + return false; + + ICLanguageSetting [] langSettings = getLangSettings(getResDesc()); + if (langSettings == null) + return false; + + for (ICLanguageSetting langSetting : langSettings) { + String langId = langSetting.getLanguageId(); + if (langId!=null && langId.length()>0) { + LanguageManager langManager = LanguageManager.getInstance(); + ILanguageDescriptor langDes = langManager.getLanguageDescriptor(langId); + if (langDes != null) + return true; + } + } + + return false; + } + + @Override + protected boolean isIndexerAffected() { + List newProvidersList = null; + ICConfigurationDescription cfgDescription = getConfigurationDescription(); + if (cfgDescription!=null) { + newProvidersList = cfgDescription.getLanguageSettingProviders(); + } + boolean newEnablement = LanguageSettingsManager.isLanguageSettingsProvidersEnabled(page.getProject()); + + // TODO + boolean isEqualList = false; +// boolean isEqualList = (newProvidersList==initialProvidersMap) || (newProvidersList!=null && newProvidersList.equals(initialProvidersMap)); + return newEnablement!=initialEnablement || (newEnablement==true && !isEqualList); + } + + private ILanguageSettingsProvider findRawProvider(String id, List providers) { + for (ILanguageSettingsProvider provider : providers) { + if (provider.getId().equals(id)) { + provider = LanguageSettingsManager.getRawProvider(provider); + return provider; + } + } + return null; + } + + private ILanguageSettingsProvider findProvider(String id, List providers) { + for (ILanguageSettingsProvider provider : providers) { + if (provider.getId().equals(id)) { + return provider; + } + } + return null; + } + + public ILanguageSettingsProvider getProvider(String id) { + return findProvider(id, presentedProviders); + } + + private int getProviderIndex(String id, List providers) { + int pos = 0; + for (ILanguageSettingsProvider p : providers) { + if (p.getId().equals(id)) + return pos; + pos++; + } + return -1; + } + +// private void informOptionPages(boolean apply) { +// Collection pages = optionsPageMap.values(); +// for (ICOptionPage dynamicPage : pages) { +// if (dynamicPage!=null && dynamicPage.isValid() && dynamicPage.getControl() != null) { +// try { +// if (apply) +// dynamicPage.performApply(new NullProgressMonitor()); +// else +// dynamicPage.performDefaults(); +// } catch (CoreException e) { +// CUIPlugin.log("ErrorParsTab.error.OnApplyingSettings", e); +// } +// } +// } +//} + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProvidersLabelProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProvidersLabelProvider.java new file mode 100644 index 00000000000..0a810a02498 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProvidersLabelProvider.java @@ -0,0 +1,118 @@ +/******************************************************************************* + * Copyright (c) 2010, 2011 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.internal.ui.language.settings.providers; + +import java.net.URL; + +import org.eclipse.jface.viewers.IDecoration; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.swt.graphics.Image; + +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable; +import org.eclipse.cdt.ui.CDTSharedImages; + + +/** + * Label provider for language settings providers. + * + */ +class LanguageSettingsProvidersLabelProvider extends LabelProvider { + private static final String TEST_PLUGIN_ID_PATTERN = "org.eclipse.cdt.*.tests.*"; //$NON-NLS-1$ + private static final String OOPS = "OOPS"; //$NON-NLS-1$ + + /** + * Returns base image key (for image without overlay). + */ + protected String getBaseKey(ILanguageSettingsProvider provider) { + String imageKey = null; + // try id-association + String id = provider.getId(); + URL url = LanguageSettingsProviderAssociation.getImageUrl(id); + // try class-association + if (url==null) { + ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); + if (rawProvider!=null) { + url = LanguageSettingsProviderAssociation.getImage(rawProvider.getClass()); + } + } + if (url!=null) { + imageKey = url.toString(); + } + + if (imageKey==null) { + if (id.matches(TEST_PLUGIN_ID_PATTERN)) { + imageKey = CDTSharedImages.IMG_OBJS_CDT_TESTING; + } else { + imageKey = CDTSharedImages.IMG_OBJS_EXTENSION; + } + } + return imageKey; + } + + /** + * Returns keys for image overlays. Returning {@code null} is not allowed. + */ + protected String[] getOverlayKeys(ILanguageSettingsProvider provider) { + String[] overlayKeys = new String[5]; + { // TODO temporary for debugging +// final String MBS_LANGUAGE_SETTINGS_PROVIDER = "org.eclipse.cdt.managedbuilder.core.LanguageSettingsProvider"; +// boolean isSpecial = provider.getId().equals(MBS_LANGUAGE_SETTINGS_PROVIDER); + + ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); + if (rawProvider instanceof LanguageSettingsSerializable) { + if (((LanguageSettingsSerializable)rawProvider).isEmpty()) { + overlayKeys[IDecoration.BOTTOM_RIGHT] = CDTSharedImages.IMG_OVR_EMPTY; + } + } + + if (LanguageSettingsManager.isWorkspaceProvider(provider) /*&& !isSpecial*/) { + overlayKeys[IDecoration.TOP_LEFT] = CDTSharedImages.IMG_OVR_GLOBAL; +// overlayKeys[IDecoration.TOP_LEFT] = CDTSharedImages.IMG_OVR_REFERENCE; +// overlayKeys[IDecoration.TOP_RIGHT] = CDTSharedImages.IMG_OVR_PARENT; +// overlayKeys[IDecoration.BOTTOM_RIGHT] = CDTSharedImages.IMG_OVR_LINK; + } else { +// overlayKeys[IDecoration.TOP_LEFT] = CDTSharedImages.IMG_OVR_CONFIGURATION; +// overlayKeys[IDecoration.TOP_LEFT] = CDTSharedImages.IMG_OVR_INDEXED; +// overlayKeys[IDecoration.TOP_LEFT] = CDTSharedImages.IMG_OVR_CONTEXT; + +// overlayKeys[IDecoration.TOP_LEFT] = CDTSharedImages.IMG_OVR_PROJECT; + } + + } + return overlayKeys; + } + + @Override + public Image getImage(Object element) { + if (element instanceof ILanguageSettingsProvider) { + ILanguageSettingsProvider provider = (ILanguageSettingsProvider)element; + String imageKey = getBaseKey(provider); + String[] overlayKeys = getOverlayKeys(provider); + return CDTSharedImages.getImageOverlaid(imageKey, overlayKeys); + } + return null; + } + + @Override + public String getText(Object element) { + if (element instanceof ILanguageSettingsProvider) { + String name = ((ILanguageSettingsProvider) element).getName(); + if (name!=null) + return name; + String id = ((ILanguageSettingsProvider) element).getId(); + return "[ Not accessible id="+id+" ]"; + } + return OOPS; + } +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/Page_LanguageSettingsProviders.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/Page_LanguageSettingsProviders.java new file mode 100644 index 00000000000..ef6d4c3f495 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/Page_LanguageSettingsProviders.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Intel Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Intel Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.language.settings.providers; + +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; +import org.eclipse.cdt.ui.newui.AbstractPage; +import org.eclipse.cdt.ui.newui.ICPropertyTab; + + +/** + * @noextend This class is not intended to be subclassed by clients. + * @noinstantiate This class is not intended to be instantiated by clients. + */ +public class Page_LanguageSettingsProviders extends AbstractPage { + private Boolean isLanguageSettingsProvidersEnabled = null; + + @Override + protected boolean isSingle() { + return false; + } + + public boolean isLanguageSettingsProvidersEnabled() { + if (isLanguageSettingsProvidersEnabled==null) { + isLanguageSettingsProvidersEnabled = LanguageSettingsManager.isLanguageSettingsProvidersEnabled(getProject()); + } + return isLanguageSettingsProvidersEnabled; + } + + public void setLanguageSettingsProvidersEnabled(boolean enable) { + isLanguageSettingsProvidersEnabled = enable; + forEach(ICPropertyTab.UPDATE,getResDesc()); + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/UserLanguageSettingsProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/UserLanguageSettingsProvider.java new file mode 100644 index 00000000000..2dee6cb8000 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/UserLanguageSettingsProvider.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2009, 2009 Andrew Gvozdev (Quoin Inc.) 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 (Quoin Inc.) - initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.internal.ui.language.settings.providers; + +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable; +import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider; + +/** + * Provider to support user interface for language settings. The important difference with + * {@link LanguageSettingsSerializable} is that it implements {@link ILanguageSettingsEditableProvider}. + * + */ +public class UserLanguageSettingsProvider extends LanguageSettingsSerializable implements ILanguageSettingsEditableProvider { + + @Override + public int hashCode() { + return super.hashCode()*13 + 1; + } + + @Override + public boolean equals(Object o) { + if (o instanceof UserLanguageSettingsProvider) { + return super.equals(o); + } + return false; + } + + @Override + public UserLanguageSettingsProvider cloneShallow() throws CloneNotSupportedException { + return (UserLanguageSettingsProvider)super.cloneShallow(); + } + + @Override + public UserLanguageSettingsProvider clone() throws CloneNotSupportedException { + return (UserLanguageSettingsProvider)super.clone(); + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/LanguageSettingsImages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/LanguageSettingsImages.java new file mode 100644 index 00000000000..32f06aad27a --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/LanguageSettingsImages.java @@ -0,0 +1,195 @@ +/******************************************************************************* + * Copyright (c) 2010 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.internal.ui.newui; + +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; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.viewers.IDecoration; +import org.eclipse.swt.graphics.Image; + +import org.eclipse.cdt.core.settings.model.ACPathEntry; +import org.eclipse.cdt.core.settings.model.CMacroEntry; +import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; +import org.eclipse.cdt.core.settings.model.ICSettingEntry; +import org.eclipse.cdt.ui.CDTSharedImages; +import org.eclipse.cdt.ui.CUIPlugin; + +/** + * Helper class to provide unified images for {@link ICLanguageSettingEntry}. + */ +public class LanguageSettingsImages { + public static Image getImage(int kind, int flags, boolean isProjectRelative) { + String imageKey = getImageKey(kind, flags, isProjectRelative); + if (imageKey!=null) { +// String overlayKey = getErrorOverlayKey(kind, flags, isProjectRelative); +// if (overlayKey!=null) { +// return getOverlaidImage(imageKey, overlayKey, IDecoration.BOTTOM_LEFT); +// } + return CDTSharedImages.getImage(imageKey); + } + return null; + } + + /** + * Returns image for the given entry from internally managed repository including + * necessary overlays. This method is shortcut for {@link #getImage(ICLanguageSettingEntry, String)} + * when no project is available. + * + * @param entry - language settings entry to get an image for. + * @return the image for the entry with appropriate overlays. + */ + public static Image getImage(ICLanguageSettingEntry entry) { + return getImage(entry, null); + } + + /** + * Returns image for the given entry from internally managed repository including + * necessary overlays. + * + * @param entry - language settings entry to get an image for. + * @param projectName - pass project name if available. That lets to put "project" metaphor + * on the image. Pass {@code null} if no project name is available. + * @return the image for the entry with appropriate overlays. + */ + public static Image getImage(ICLanguageSettingEntry entry, String projectName) { + int kind = entry.getKind(); + boolean isWorkspacePath = (entry.getFlags() & ICSettingEntry.VALUE_WORKSPACE_PATH) != 0; + String path = entry.getName(); + boolean isProjectRelative = projectName!=null && isWorkspacePath && path.startsWith(IPath.SEPARATOR+projectName+IPath.SEPARATOR); + // FIXME + isProjectRelative = isProjectRelative || (isWorkspacePath && path.charAt(0)!=IPath.SEPARATOR); + int flags = entry.getFlags(); + String imageKey = getImageKey(kind, flags, isProjectRelative); + if (imageKey!=null) { + if ((entry.getFlags()&ICSettingEntry.UNDEFINED) == ICSettingEntry.UNDEFINED) + return CDTSharedImages.getImageOverlaid(imageKey, CDTSharedImages.IMG_OVR_INACTIVE, IDecoration.BOTTOM_LEFT); + + if (entry instanceof ACPathEntry) { + String overlayKey=null; + IStatus status = getStatus(entry); + switch (status.getSeverity()) { + case IStatus.ERROR: + overlayKey = CDTSharedImages.IMG_OVR_ERROR; + break; + case IStatus.WARNING: + overlayKey = CDTSharedImages.IMG_OVR_WARNING; + break; + case IStatus.INFO: + overlayKey = CDTSharedImages.IMG_OVR_WARNING; + break; + } + return CDTSharedImages.getImageOverlaid(imageKey, overlayKey, IDecoration.BOTTOM_LEFT); + } + return CDTSharedImages.getImage(imageKey); + } + return null; + } + + /** + * Checking if the entry points to existing or accessible location. + */ + private static boolean isLocationOk(ACPathEntry entry) { + // have to trust paths which contain variables + if (entry.getName().contains("${")) //$NON-NLS-1$ + return true; + + boolean exists = true; + boolean isWorkspacePath = (entry.getFlags() & ICSettingEntry.VALUE_WORKSPACE_PATH) != 0; + if (isWorkspacePath) { + IPath path = new Path(entry.getValue()); + IResource rc = ResourcesPlugin.getWorkspace().getRoot().findMember(path); + exists = rc!=null && rc.isAccessible(); + } else { + String pathname = entry.getName(); + java.io.File file = new java.io.File(pathname); + exists = file.exists(); + } + return exists; + } + + /** + * Defines status object for the status message line. + * + * @param entry - the entry to check status on. + * @return a status object defining severity and message. + */ + public static IStatus getStatus(ICLanguageSettingEntry entry) { + if (entry instanceof ACPathEntry) { + ACPathEntry acEntry = (ACPathEntry)entry; + IPath path = new Path(acEntry.getName()); + if (!path.isAbsolute()) { + String msg = "Using relative paths is ambiguous and not recommended. It can cause unexpected side-effects."; + return new Status(IStatus.INFO, CUIPlugin.PLUGIN_ID, msg); + } + if (!isLocationOk(acEntry)) { + String msg; + if (acEntry.isFile()) + msg = "The selected file does not exist or not accessible."; + else + msg = "The selected folder does not exist or not accessible."; + return new Status(IStatus.WARNING, CUIPlugin.PLUGIN_ID, msg); + } + + } + return Status.OK_STATUS; + } + + /** + * @return the base key for the image. + */ + private static String getImageKey(int kind, int flag, boolean isProjectRelative) { + String imageKey = null; + + boolean isWorkspacePath = (flag & ICSettingEntry.VALUE_WORKSPACE_PATH) != 0; + boolean isBuiltin = (flag & ICSettingEntry.BUILTIN) != 0; + boolean isFramework = (flag & ICSettingEntry.FRAMEWORKS_MAC) != 0; + + switch (kind) { + case ICSettingEntry.INCLUDE_PATH: + if (isWorkspacePath) + if (isProjectRelative) + imageKey = CDTSharedImages.IMG_OBJS_INCLUDES_FOLDER_PROJECT; + else + imageKey = CDTSharedImages.IMG_OBJS_INCLUDES_FOLDER_WORKSPACE; + else if (isFramework) + imageKey = CDTSharedImages.IMG_OBJS_FRAMEWORKS_FOLDER; + else if (isBuiltin) + imageKey = CDTSharedImages.IMG_OBJS_INCLUDES_FOLDER_SYSTEM; + else + imageKey = CDTSharedImages.IMG_OBJS_INCLUDES_FOLDER; + break; + case ICSettingEntry.INCLUDE_FILE: + imageKey = CDTSharedImages.IMG_OBJS_TUNIT_HEADER; + break; + case ICSettingEntry.MACRO: + imageKey = CDTSharedImages.IMG_OBJS_MACRO; + break; + case ICSettingEntry.MACRO_FILE: + imageKey = CDTSharedImages.IMG_OBJS_MACROS_FILE; + break; + case ICSettingEntry.LIBRARY_PATH: + imageKey = CDTSharedImages.IMG_OBJS_LIBRARY_FOLDER; + break; + case ICSettingEntry.LIBRARY_FILE: + imageKey = CDTSharedImages.IMG_OBJS_LIBRARY; + break; + } + if (imageKey==null) + imageKey = CDTSharedImages.IMG_OBJS_UNKNOWN_TYPE; + return imageKey; + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/Messages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/Messages.java index fe48a3b97b8..ba35da75ca9 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/Messages.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/Messages.java @@ -84,6 +84,7 @@ public class Messages extends NLS { public static String CDTCommonProjectWizard_creatingProject; public static String CDTMainWizardPage_0; public static String CDTMainWizardPage_1; + public static String CDTMainWizardPage_TrySD90; public static String CLocationOutputTab_0; public static String CLocationSourceTab_0; public static String CLocationTab_0; @@ -186,6 +187,16 @@ public class Messages extends NLS { public static String IncludeTab_2; public static String IncludeTab_export; public static String IncludeTab_import; + public static String LanguageSettingsProviderTab_AreYouSureToResetProviders; + public static String LanguageSettingsProviderTab_Clear; + public static String LanguageSettingsProviderTab_Configure; + public static String LanguageSettingsProviderTab_ErrorPerformingDefaults; + public static String LanguageSettingsProviderTab_ProviderOptions; +// public static String LanguageSettingsProviderTab_Run; + public static String LanguageSettingsProviderTab_SettingEntries; + public static String LanguageSettingsProviderTab_SettingEntriesTooltip; + public static String LanguageSettingsProviderTab_ShowEntries; + public static String LanguageSettingsProviderTab_TitleResetProviders; public static String LanguagesTab_0; public static String LanguagesTab_1; public static String LibraryPathTab_1; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/Messages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/Messages.properties index 80f166a65c7..e26bd03bb53 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/Messages.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/Messages.properties @@ -166,6 +166,16 @@ IncludeDialog_0=Directory: IncludeDialog_1=File: IncludeDialog_2=Add to all configurations IncludeDialog_3=Add to all languages +LanguageSettingsProviderTab_AreYouSureToResetProviders=Are you sure you want to reset all customized language settings providers? +LanguageSettingsProviderTab_Clear=Clear Entries +LanguageSettingsProviderTab_Configure=Configure +LanguageSettingsProviderTab_ErrorPerformingDefaults=Error restoring defaults for language settings providers +LanguageSettingsProviderTab_ProviderOptions=Language Settings Provider Options +#LanguageSettingsProviderTab_Run=Run +LanguageSettingsProviderTab_SettingEntries=Setting Entries +LanguageSettingsProviderTab_SettingEntriesTooltip=Setting Entries +LanguageSettingsProviderTab_ShowEntries=Show Entries +LanguageSettingsProviderTab_TitleResetProviders=Reset Language Settings Providers LanguagesTab_0=Content type LanguagesTab_1=Language LibraryPathTab_1=Add... @@ -269,6 +279,7 @@ StringVariableSelectionDialog_message=&Choose a variable (? = any character, * = StringVariableSelectionDialog_columnDescription=&Variable Description: CDTMainWizardPage_0=Project name cannot contain '\#' symbol CDTMainWizardPage_1=Project category is selected. Expand the category and select a concrete project type. +CDTMainWizardPage_TrySD90=I want to try new upcoming version of Scanner Discovery in CDT 9.0 (v.0.1.0) CProjectWizard_0=Add C Project Nature CCProjectWizard_0=Add CC Project Nature WorkingSetConfigAction_21=Building project diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/StatusMessageLine.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/StatusMessageLine.java new file mode 100644 index 00000000000..aacedf2cbcb --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/StatusMessageLine.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * Copyright (c) 2010 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.internal.ui.newui; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CLabel; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; + +/** + * A message line displaying a status. + * See also org.eclipse.jface.dialogs.StatusDialog.MessageLine. + */ +public class StatusMessageLine { + private CLabel fLabel; + + /** + * Constructor. + * + * @param parent - parent element. + * @param style - the style of the control. Refer to {@link CLabel#CLabel(Composite, int)}. + * @param span - how many columns it should span. + */ + public StatusMessageLine(Composite parent, int style, int span) { + fLabel = new CLabel(parent, style); + if (span!=1) { + GridData gd = new GridData(SWT.FILL, SWT.NONE, true, false); + gd.horizontalSpan = span; + fLabel.setLayoutData(gd); + } + } + + /** + * Find an image associated with the status. + */ + private Image findImage(IStatus status) { + if (status.isOK()) { + return null; + } else if (status.matches(IStatus.ERROR)) { + return JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_ERROR); + } else if (status.matches(IStatus.WARNING)) { + return JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_WARNING); + } else if (status.matches(IStatus.INFO)) { + return JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_INFO); + } + return null; + } + + /** + * Assign {@link IStatus} object to the message line. The status should provide + * severity for the icon and message to display. + * + * @param status - status object for the message line. + */ + public void setErrorStatus(IStatus status) { + if (status != null && !status.isOK()) { + String message = status.getMessage(); + if (message != null && message.length() > 0) { + fLabel.setText(message); + fLabel.setImage(findImage(status)); + fLabel.layout(); + return; + } + } + fLabel.setText(""); //$NON-NLS-1$ + fLabel.setImage(null); + } +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/ProblemsLabelDecorator.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/ProblemsLabelDecorator.java index 17232c410cc..e576c176e62 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/ProblemsLabelDecorator.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/ProblemsLabelDecorator.java @@ -29,6 +29,7 @@ import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.ui.texteditor.MarkerUtilities; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager_TBD; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.ICElement; @@ -387,7 +388,8 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe if (cfgDescription != null) { IPath path = rc.getProjectRelativePath(); ICResourceDescription rcDescription = cfgDescription.getResourceDescription(path, true); - if (rcDescription != null) + boolean isLSCustomized = LanguageSettingsManager_TBD.isCustomizedResource(cfgDescription, rc); + if (rcDescription != null || isLSCustomized) result |= TICK_CONFIGURATION; } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CDTSharedImages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CDTSharedImages.java index 73cbf49068b..95c5d4618d5 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CDTSharedImages.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CDTSharedImages.java @@ -116,6 +116,7 @@ public class CDTSharedImages { public static final String IMG_OBJS_INCLUDES_FOLDER_WORKSPACE = "icons/obj16/wsp_includefolder.gif"; //$NON-NLS-1$ public static final String IMG_OBJS_QUOTE_INCLUDES_FOLDER = "icons/obj16/hfolder_quote_obj.gif"; //$NON-NLS-1$ public static final String IMG_OBJS_INCLUDES_FOLDER_SYSTEM = "icons/obj16/fldr_sys_obj.gif"; //$NON-NLS-1$ + public static final String IMG_OBJS_FRAMEWORKS_FOLDER = "icons/obj16/frameworks.gif"; //$NON-NLS-1$ public static final String IMG_OBJS_MACROS_FILE= "icons/obj16/macros_file.gif"; //$NON-NLS-1$ public static final String IMG_OBJS_LIBRARY_FOLDER= "icons/obj16/fldr_lib_obj.gif"; // $NON-NLS-1$ //$NON-NLS-1$ public static final String IMG_OBJS_ORDER = "icons/obj16/cp_order_obj.gif"; //$NON-NLS-1$ @@ -208,6 +209,23 @@ public class CDTSharedImages { public static final String IMG_VIEW_PIN_ACTION_B = "icons/obj16/toolbar_pinned_b.gif"; //$NON-NLS-1$ public static final String IMG_VIEW_PIN_ACTION_MULTI = "icons/obj16/toolbar_pinned_multi.gif"; //$NON-NLS-1$ + // Language Settings Images + public static final String IMG_OBJS_LANG_SETTINGS_PROVIDER = "icons/obj16/ls_entries_provider.gif"; //$NON-NLS-1$ + public static final String IMG_ETOOL_PROJECT = "icons/etool16/prj_obj.gif"; //$NON-NLS-1$ + + public static final String IMG_OVR_GLOBAL = "icons/ovr16/global_ovr.gif"; //$NON-NLS-1$ + public static final String IMG_OVR_IMPORT = "icons/ovr16/import_co.gif"; //$NON-NLS-1$ + public static final String IMG_OVR_LINK = "icons/ovr16/link_ovr.gif"; //$NON-NLS-1$ + public static final String IMG_OVR_CONFIGURATION = "icons/ovr16/cfg_ovr.gif"; //$NON-NLS-1$ + public static final String IMG_OVR_PARENT = "icons/ovr16/path_inherit_co.gif"; //$NON-NLS-1$ + public static final String IMG_OVR_INDEXED = "icons/ovr16/indexedFile.gif"; //$NON-NLS-1$ + public static final String IMG_OVR_REFERENCE = "icons/ovr16/referencedby_co.gif"; //$NON-NLS-1$ + public static final String IMG_OVR_PROJECT = "icons/ovr16/project_co.gif"; //$NON-NLS-1$ + public static final String IMG_OVR_CONTEXT = "icons/ovr16/overlay-has-context.gif"; //$NON-NLS-1$ + public static final String IMG_OVR_LOCK = "icons/ovr16/lock_ovr.gif"; //$NON-NLS-1$ + public static final String IMG_OVR_EDITED = "icons/ovr16/edited_ov.gif"; //$NON-NLS-1$ + public static final String IMG_OVR_EMPTY = "icons/ovr16/empty_ovr.png"; //$NON-NLS-1$ + /** * The method finds URL of the image corresponding to the key which could be project-relative path * of the image in org.eclipse.cdt.ui plugin or a (previously registered) string representation of URL diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/AbstractCPropertyTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/AbstractCPropertyTab.java index 2ff7b9cd963..691ea16bf74 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/AbstractCPropertyTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/AbstractCPropertyTab.java @@ -94,6 +94,7 @@ public abstract class AbstractCPropertyTab implements ICPropertyTab { public static final String EDIT_STR = Messages.FileListControl_edit; public static final String MOVEUP_STR = Messages.FileListControl_moveup; public static final String MOVEDOWN_STR = Messages.FileListControl_movedown; + public static final String PROJECTBUTTON_NAME = "Project..."; public static final String WORKSPACEBUTTON_NAME = Messages.FileListControl_button_workspace; public static final String FILESYSTEMBUTTON_NAME = Messages.FileListControl_button_fs; public static final String VARIABLESBUTTON_NAME = Messages.AbstractCPropertyTab_1; @@ -450,6 +451,12 @@ public abstract class AbstractCPropertyTab implements ICPropertyTab { public static String getWorkspaceFileDialog(Shell shell, String text) { return getWorkspaceDialog(shell, text, false, null); } + public static String getProjectDirDialog(Shell shell, String text, IProject prj) { + return getWorkspaceDialog(shell, text, true, prj); + } + public static String getProjectFileDialog(Shell shell, String text, IProject prj) { + return getWorkspaceDialog(shell, text, false, prj); + } private static String getWorkspaceDialog(Shell shell, String text, boolean dir, IProject prj) { String currentPathText; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/AbstractLangsListTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/AbstractLangsListTab.java index 7528b6f7fde..38318888296 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/AbstractLangsListTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/AbstractLangsListTab.java @@ -9,6 +9,7 @@ * Intel Corporation - initial API and implementation * IBM Corporation * Markus Schorn (Wind River Systems) + * Andrew Gvozdev (Quoin Inc.) *******************************************************************************/ package org.eclipse.cdt.ui.newui; @@ -18,6 +19,7 @@ import java.util.Comparator; import java.util.LinkedList; import java.util.List; +import org.eclipse.core.resources.IProject; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.viewers.IFontProvider; import org.eclipse.jface.viewers.IStructuredContentProvider; @@ -66,9 +68,10 @@ import org.eclipse.cdt.core.settings.model.ICSettingBase; import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.core.settings.model.MultiLanguageSetting; import org.eclipse.cdt.core.settings.model.util.CDataUtil; -import org.eclipse.cdt.ui.CDTSharedImages; +import org.eclipse.cdt.internal.ui.newui.LanguageSettingsImages; import org.eclipse.cdt.internal.ui.newui.Messages; +import org.eclipse.cdt.internal.ui.newui.StatusMessageLine; public abstract class AbstractLangsListTab extends AbstractCPropertyTab { protected Table table; @@ -78,6 +81,8 @@ public abstract class AbstractLangsListTab extends AbstractCPropertyTab { protected Button showBIButton; protected boolean toAllCfgs = false; protected boolean toAllLang = false; + private StatusMessageLine fStatusLine; + /** @deprecated as of CDT 8.0. {@code linkStringListMode} is used instead. */ @Deprecated protected Label lb1, lb2; @@ -120,12 +125,6 @@ public abstract class AbstractLangsListTab extends AbstractCPropertyTab { private static final Comparator comp = CDTListComparator.getInstance(); - private final static Image IMG_FOLDER = CDTSharedImages.getImage(CDTSharedImages.IMG_OBJS_FOLDER); - private final static Image IMG_INCLUDES_FOLDER = CDTSharedImages.getImage(CDTSharedImages.IMG_OBJS_INCLUDES_FOLDER); - private final static Image IMG_BUILTIN_FOLDER = CDTSharedImages.getImage(CDTSharedImages.IMG_OBJS_INCLUDES_FOLDER_SYSTEM); - private final static Image IMG_WORKSPACE = CDTSharedImages.getImage(CDTSharedImages.IMG_OBJS_WORKSPACE); - private final static Image IMG_INCLUDES_FOLDER_WORKSPACE = CDTSharedImages.getImage(CDTSharedImages.IMG_OBJS_INCLUDES_FOLDER_WORKSPACE); - private final static Image IMG_MACRO = CDTSharedImages.getImage(CDTSharedImages.IMG_OBJS_MACRO); private static final int[] DEFAULT_SASH_WEIGHTS = new int[] { 10, 30 }; @Override @@ -182,11 +181,12 @@ public abstract class AbstractLangsListTab extends AbstractCPropertyTab { public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {} }); - tv.setLabelProvider(new RichLabelProvider()); + tv.setLabelProvider(new LanguageSettingsEntriesLabelProvider()); table.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { + updateStatusLine(); updateButtons(); } @@ -205,6 +205,8 @@ public abstract class AbstractLangsListTab extends AbstractCPropertyTab { setColumnToFit(); }}); + fStatusLine = new StatusMessageLine(usercomp, SWT.LEFT, 2); + showBIButton = setupCheck(usercomp, Messages.AbstractLangsListTab_ShowBuiltin, 1, GridData.GRAB_HORIZONTAL); gd = (GridData) showBIButton.getLayoutData(); showBIButton.addSelectionListener(new SelectionAdapter() { @@ -226,6 +228,17 @@ public abstract class AbstractLangsListTab extends AbstractCPropertyTab { updateData(getResDesc()); } + /** + * @return selected entry when only one is selected or {@code null}. + */ + private ICLanguageSettingEntry getSelectedEntry() { + int index = table.getSelectionIndex(); + if (index<0 || table.getSelectionIndices().length!=1) + return null; + + return (ICLanguageSettingEntry)(table.getItem(index).getData()); + } + /** * Used to display UI control for multiple configurations string list mode * (see Multiple Configurations Edit Preference page). @@ -236,6 +249,14 @@ public abstract class AbstractLangsListTab extends AbstractCPropertyTab { stringListModeControl.updateStringListModeControl(); } + /** + * Displays warning message - if any - for selected language settings entry. + * Multiline selection is not supported. + */ + private void updateStatusLine() { + fStatusLine.setErrorStatus(LanguageSettingsImages.getStatus(getSelectedEntry())); + } + /** * Updates state for all buttons * Called when table selection changes. @@ -342,6 +363,7 @@ public abstract class AbstractLangsListTab extends AbstractCPropertyTab { } updateStringListModeControl(); + updateStatusLine(); updateButtons(); } @@ -682,67 +704,60 @@ public abstract class AbstractLangsListTab extends AbstractCPropertyTab { } // Extended label provider - private class RichLabelProvider extends LabelProvider implements IFontProvider, ITableLabelProvider /*, IColorProvider*/{ - public RichLabelProvider(){} + private class LanguageSettingsEntriesLabelProvider extends LabelProvider implements IFontProvider, ITableLabelProvider /*, IColorProvider*/{ @Override public Image getImage(Object element) { return getColumnImage(element, 0); } + public Image getColumnImage(Object element, int columnIndex) { - if (columnIndex > 0) return null; - if (! (element instanceof ICLanguageSettingEntry)) return null; - - ICLanguageSettingEntry le = (ICLanguageSettingEntry) element; - if (le.getKind() == ICSettingEntry.MACRO) - return IMG_MACRO; - if ((le.getFlags() & ICSettingEntry.BUILTIN) != 0) - return IMG_BUILTIN_FOLDER; - - boolean isWorkspacePath = (le.getFlags() & ICSettingEntry.VALUE_WORKSPACE_PATH) != 0; - if (le.getKind() == ICSettingEntry.INCLUDE_PATH || le.getKind() == ICSettingEntry.INCLUDE_FILE) { - if (isWorkspacePath) - return IMG_INCLUDES_FOLDER_WORKSPACE; - else - return IMG_INCLUDES_FOLDER; - } else { - if (isWorkspacePath) - return IMG_WORKSPACE; - else - return IMG_FOLDER; + if (columnIndex==0 && (element instanceof ICLanguageSettingEntry)) { + ICConfigurationDescription cfg = getResDesc().getConfiguration(); + IProject project = cfg.getProjectDescription().getProject(); + return LanguageSettingsImages.getImage((ICLanguageSettingEntry) element, project.getName()); } + return null; } + @Override public String getText(Object element) { return getColumnText(element, 0); } + public String getColumnText(Object element, int columnIndex) { - if (! (element instanceof ICLanguageSettingEntry)) { - return (columnIndex == 0) ? element.toString() : EMPTY_STR; - } - ICLanguageSettingEntry le = (ICLanguageSettingEntry) element; - if (columnIndex == 0) { - String s = le.getName(); - if (exported.contains(resolve(le))) - s = s + Messages.AbstractLangsListTab_ExportIndicator; - return s; - } - if (le.getKind() == ICSettingEntry.MACRO) { + if (element instanceof ICLanguageSettingEntry) { + ICLanguageSettingEntry entry = (ICLanguageSettingEntry) element; switch (columnIndex) { - case 1: return le.getValue(); + case 0: + String name = entry.getName(); + if (exported.contains(resolve(entry))) + name = name + Messages.AbstractLangsListTab_ExportIndicator; + return name; + case 1: + if (entry.getKind() == ICSettingEntry.MACRO) { + return entry.getValue(); } + return null; + } + } else if (columnIndex == 0) { + return element.toString(); } - return EMPTY_STR; + + return null; } public Font getFont(Object element) { - if (! (element instanceof ICLanguageSettingEntry)) return null; - ICLanguageSettingEntry le = (ICLanguageSettingEntry) element; - if (le.isBuiltIn()) return null; // built in - if (le.isReadOnly()) // read only + if (element instanceof ICLanguageSettingEntry) { + ICLanguageSettingEntry entry = (ICLanguageSettingEntry) element; + if (entry.isBuiltIn()) + return null; + if (entry.isReadOnly()) return JFaceResources.getFontRegistry().getItalic(JFaceResources.DIALOG_FONT); // normal return JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT); } + return null; + } } public ICLanguageSetting[] getLangSetting(ICResourceDescription rcDes) { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/CDTPrefUtil.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/CDTPrefUtil.java index 4422ba202a0..58594cf3146 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/CDTPrefUtil.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/CDTPrefUtil.java @@ -33,11 +33,13 @@ import org.eclipse.cdt.internal.ui.workingsets.WorkingSetConfigurationManager; public class CDTPrefUtil { // boolean keys (KEY_NO-s are to be inverted !) public static final String KEY_NOSUPP = "wizard.show.unsupported.disable"; //$NON-NLS-1$ + public static final String KEY_NEWSD = "wizard.try.new.sd.enable"; //$NON-NLS-1$ public static final String KEY_OTHERS = "wizard.group.others.enable"; //$NON-NLS-1$ public static final String KEY_NOMNG = "properties.manage.config.disable"; //$NON-NLS-1$ public static final String KEY_DTREE = "properties.data.hierarchy.enable"; //$NON-NLS-1$ public static final String KEY_NOTOOLM = "properties.toolchain.modification.disable"; //$NON-NLS-1$ public static final String KEY_EXPORT = "properties.export.page.enable"; //$NON-NLS-1$ + public static final String KEY_NO_SHOW_PROVIDERS = "properties.providers.tab.disable"; //$NON-NLS-1$ /** @since 5.2 Show the "Include Files" settings entry tab */ public static final String KEY_SHOW_INC_FILES = "properties.includefiles.page.enable"; //$NON-NLS-1$ /** @since 5.2 */ diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/CDTMainWizardPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/CDTMainWizardPage.java index f214a9fd72b..589b32ece43 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/CDTMainWizardPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/CDTMainWizardPage.java @@ -67,6 +67,7 @@ import org.eclipse.cdt.internal.ui.newui.Messages; private Tree tree; private Composite right; private Button show_sup; + private Button checkBoxTryNewSD; private Label right_label; public CWizardHandler h_selected = null; @@ -154,6 +155,20 @@ import org.eclipse.cdt.internal.ui.newui.Messages; // restore settings from preferences show_sup.setSelection(!CDTPrefUtil.getBool(CDTPrefUtil.KEY_NOSUPP)); + + checkBoxTryNewSD = new Button(c, SWT.CHECK); + checkBoxTryNewSD.setText(Messages.CDTMainWizardPage_TrySD90); + /* GridData */gd = new GridData(GridData.FILL_HORIZONTAL); + gd.horizontalSpan = 2; + checkBoxTryNewSD.setLayoutData(gd); + + // restore settings from preferences + boolean isTryNewSD = true; + boolean contains = CUIPlugin.getDefault().getPreferenceStore().contains(CDTPrefUtil.KEY_NEWSD); + if (contains) { + isTryNewSD = CDTPrefUtil.getBool(CDTPrefUtil.KEY_NEWSD); + } + checkBoxTryNewSD.setSelection(isTryNewSD); } @Override @@ -478,5 +493,9 @@ import org.eclipse.cdt.internal.ui.newui.Messages; public List filterItems(List items) { return items; } + + public boolean isTryingNewSD() { + return checkBoxTryNewSD.getSelection(); + } } diff --git a/xlc/org.eclipse.cdt.managedbuilder.xlc.core/plugin.xml b/xlc/org.eclipse.cdt.managedbuilder.xlc.core/plugin.xml index 37b503d103b..668e82b3759 100644 --- a/xlc/org.eclipse.cdt.managedbuilder.xlc.core/plugin.xml +++ b/xlc/org.eclipse.cdt.managedbuilder.xlc.core/plugin.xml @@ -74,6 +74,24 @@ class="org.eclipse.cdt.make.xlc.core.scannerconfig.XlCSpecsConsoleParser"> - + + + + + + + + + + diff --git a/xlc/org.eclipse.cdt.managedbuilder.xlc.core/src/org/eclipse/cdt/managedbuilder/xlc/core/XlcBuiltinSpecsDetector.java b/xlc/org.eclipse.cdt.managedbuilder.xlc.core/src/org/eclipse/cdt/managedbuilder/xlc/core/XlcBuiltinSpecsDetector.java new file mode 100644 index 00000000000..056ca8305dd --- /dev/null +++ b/xlc/org.eclipse.cdt.managedbuilder.xlc.core/src/org/eclipse/cdt/managedbuilder/xlc/core/XlcBuiltinSpecsDetector.java @@ -0,0 +1,97 @@ +/******************************************************************************* + * Copyright (c) 2009, 2011 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.managedbuilder.xlc.core; + +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.eclipse.cdt.core.settings.model.ICSettingEntry; +import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider; +import org.eclipse.cdt.managedbuilder.internal.scannerconfig.AbstractBuiltinSpecsDetector; + + +/** + * + +> xlC -E -V -P -w ~/tmp/spec.C +export XL_CONFIG=/etc/vac.cfg:xlC +/usr/vac/exe/xlCcpp /home/me/tmp/spec.C - -qc++=/usr/vacpp/include -D_AIX -D_AIX32 -D_AIX41 -D_AIX43 -D_AIX50 -D_AIX51 -D_AIX52 -D_IBMR2 -D_POWER -E -P -w -qlanglvl=ansi -qansialias +rm /tmp/xlcW0lt4Jia +rm /tmp/xlcW1lt4Jib +rm /tmp/xlcW2lt4Jic + + */ + +/** + * Class to detect built-in compiler settings. Note that currently this class is hardwired + * to GCC toolchain {@code cdt.managedbuild.toolchain.gnu.base}. + * + */ +public class XlcBuiltinSpecsDetector extends AbstractBuiltinSpecsDetector implements ILanguageSettingsEditableProvider { + // must match the toolchain definition in org.eclipse.cdt.managedbuilder.core.buildDefinitions extension point + // FIXME - ill defined XLC toolchain +// private static final String XLC_TOOLCHAIN_ID = "cdt.managedbuild.toolchain.xlc.exe.debug"; //$NON-NLS-1$ + private static final String GCC_TOOLCHAIN_ID = "cdt.managedbuild.toolchain.gnu.base"; //$NON-NLS-1$ + + private static final Pattern OPTIONS_PATTERN = Pattern.compile("-[^\\s\"']*(\\s*((\".*?\")|('.*?')|([^-\\s][^\\s]+)))?"); //$NON-NLS-1$ + private static final int OPTION_GROUP = 0; + + @SuppressWarnings("nls") + private static final AbstractOptionParser[] optionParsers = { + new IncludePathOptionParser("-I\\s*([\"'])(.*)\\1", "$2", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY | ICSettingEntry.LOCAL), + new IncludePathOptionParser("-I\\s*([^\\s\"']*)", "$1", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), + new IncludePathOptionParser("-qc\\+\\+=\\s*([^\\s\"']*)", "$1", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), + new MacroOptionParser("-D\\s*([\"'])([^=]*)(=(.*))?\\1", "$2", "$4", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), + new MacroOptionParser("-D\\s*([^\\s=\"']*)=(\\\\([\"']))(.*?)\\2", "$1", "$3$4$3", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), + new MacroOptionParser("-D\\s*([^\\s=\"']*)=([\"'])(.*?)\\2", "$1", "$3", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), + new MacroOptionParser("-D\\s*([^\\s=\"']*)(=([^\\s\"']*))?", "$1", "$3", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), + }; + + @Override + protected String getToolchainId() { +// return XLC_TOOLCHAIN_ID; + return GCC_TOOLCHAIN_ID; + } + + @Override + protected AbstractOptionParser[] getOptionParsers() { + return optionParsers; + } + + @Override + protected List parseForOptions(String line) { + List options = new ArrayList(); + Matcher optionMatcher = OPTIONS_PATTERN.matcher(line); + while (optionMatcher.find()) { + String option = optionMatcher.group(OPTION_GROUP); + if (option!=null) { + options.add(option); + } + } + return options; + } + + + @Override + public XlcBuiltinSpecsDetector cloneShallow() throws CloneNotSupportedException { + return (XlcBuiltinSpecsDetector) super.cloneShallow(); + } + + @Override + public XlcBuiltinSpecsDetector clone() throws CloneNotSupportedException { + return (XlcBuiltinSpecsDetector) super.clone(); + } + + +} From cf55505f7b17c957f9d8057df13f21c31865b828 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Sun, 10 Jul 2011 08:33:14 -0400 Subject: [PATCH 002/120] testAbstractBuiltinSpecsDetector_Launch() --- .../tests/GCCBuiltinSpecsDetectorTest.java | 31 ++++++++++++++++++- .../GCCBuiltinSpecsDetector.java | 9 ------ 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/GCCBuiltinSpecsDetectorTest.java b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/GCCBuiltinSpecsDetectorTest.java index 5e5ff994266..21d1a22c2b7 100644 --- a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/GCCBuiltinSpecsDetectorTest.java +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/GCCBuiltinSpecsDetectorTest.java @@ -401,6 +401,35 @@ public class GCCBuiltinSpecsDetectorTest extends TestCase { } } + public void testAbstractBuiltinSpecsDetector_Launch() throws Exception { + // Create model project and accompanied descriptions + String projectName = getName(); + IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); + + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + AbstractBuiltinSpecsDetector detector = new MockBuiltinSpecsDetector() { + @Override + public boolean processLine(String line) { + // pretending that we parsed the line + detectedSettingEntries.add(new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY)); + return true; + } + }; + detector.setLanguageScope(new ArrayList() {{add(LANGUAGE_ID);}}); + detector.setCustomParameter("echo #define MACRO VALUE"); + + detector.run(cfgDescription, LANGUAGE_ID, null, null, null); + + List noentries = detector.getSettingEntries(null, null, null); + assertNull(noentries); + + List entries = detector.getSettingEntries(cfgDescription, null, LANGUAGE_ID); + ICLanguageSettingEntry expected = new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); + assertEquals(expected, entries.get(0)); + } + public void testAbstractBuiltinSpecsDetector_GroupSettings() throws Exception { // define benchmarks final CIncludePathEntry includePath_1 = new CIncludePathEntry("/include/path_1", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); @@ -606,7 +635,7 @@ public class GCCBuiltinSpecsDetectorTest extends TestCase { detector.processLine(" "+loc+"/misplaced/include2"); detector.processLine("Framework search starts here:"); detector.processLine(" "+loc+"/System/Library/Frameworks"); - detector.processLine("End of search list."); + detector.processLine("End of framework search list."); detector.processLine(" "+loc+"/misplaced/include3"); detector.shutdown(); diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/GCCBuiltinSpecsDetector.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/GCCBuiltinSpecsDetector.java index d5fee24780e..6b01c80d53b 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/GCCBuiltinSpecsDetector.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/GCCBuiltinSpecsDetector.java @@ -63,15 +63,6 @@ public class GCCBuiltinSpecsDetector extends AbstractBuiltinSpecsDetector implem return makeList(line); } - /** - -Framework search starts here: - /System/Library/Frameworks - /Library/Frameworks -End of framework search list. - - */ - // contribution of includes if (line.equals("#include \"...\" search starts here:")) { state = State.EXPECTING_LOCAL_INCLUDE; From 3bf0f468ad1bfc1ac10abd13865503de9602680b Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Wed, 13 Jul 2011 14:20:45 -0400 Subject: [PATCH 003/120] Cygwin Specs Detector using EFSExtensionProvider --- .../GCCBuildCommandParserTest.java | 10 +- ...AbstractLanguageSettingsOutputScanner.java | 62 +++++++---- .../tests/GCCBuiltinSpecsDetectorTest.java | 62 ++++++++++- .../plugin.xml | 2 +- .../AbstractBuiltinSpecsDetector.java | 26 +++++ .../GCCBuiltinSpecsDetector.java | 4 +- .../GCCBuiltinSpecsDetectorCygwin.java | 81 ++++++++++++++ core/org.eclipse.cdt.core/plugin.xml | 7 ++ .../resources/CygwinEFSExtensionProvider.java | 101 ++++++++++++++++++ 9 files changed, 321 insertions(+), 34 deletions(-) create mode 100644 build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/GCCBuiltinSpecsDetectorCygwin.java create mode 100644 core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/resources/CygwinEFSExtensionProvider.java diff --git a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java index 1f71546aaca..a1aef93e593 100644 --- a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java +++ b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java @@ -1026,17 +1026,13 @@ public class GCCBuildCommandParserTest extends TestCase { // parse line parser.startup(cfgDescription); parser.processLine("gcc " - + " -IC:\\path" + + " -IX:\\path" + " file.cpp"); parser.shutdown(); // check populated entries - IPath path0 = new Path("C:\\path").setDevice(project.getLocation().getDevice()); - { - List entries = parser.getSettingEntries(cfgDescription, file, languageId); - CIncludePathEntry expected = new CIncludePathEntry(path0, 0); - assertEquals(expected, entries.get(0)); - } + List entries = parser.getSettingEntries(cfgDescription, file, languageId); + assertEquals(new CIncludePathEntry(new Path("X:\\path"), 0), entries.get(0)); } /** diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java index 4f30aaba5f5..d5ad2a07fa5 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java @@ -242,18 +242,24 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett currentResource = findResource(parsedResourceName); + /** + * URI of directory where the build is happening. This URI could point to a remote filesystem + * for remote builds. Most often it is the same filesystem as for currentResource but + * it can be different filesystem (and different URI schema). + */ + URI buildDirURI = null; + /** * Where source tree starts if mapped. This kind of mapping is useful for example in cases when * the absolute path to the source file on the remote system is simulated inside a project in the * workspace. + * This URI is rooted on the same filesystem where currentResource resides. In general this filesystem + * (or even URI schema) does not have to match that of buildDirURI. */ URI mappedRootURI = null; - URI buildDirURI = null; - + if (isResolvingPaths) { - if (currentResource!=null) { - mappedRootURI = getMappedRootURI(currentResource, parsedResourceName); - } + mappedRootURI = getMappedRootURI(currentResource, parsedResourceName); buildDirURI = getBuildDirURI(mappedRootURI); } @@ -346,7 +352,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett ICLanguageSettingEntry entry; String resolvedPath = null; - URI uri = determineURI(parsedPath, baseURI); + URI uri = determineMappedURI(parsedPath, baseURI); IResource rc = null; if (uri != null && uri.isAbsolute()) { rc = findResourceForLocationURI(uri, optionParser.kind, currentProject); @@ -417,7 +423,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett return sourceFile; } - private URI getBuildDirURI(URI mappedRootURI) { + protected URI getBuildDirURI(URI mappedRootURI) { URI buildDirURI = null; URI cwdURI = null; @@ -457,13 +463,13 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett } /** - * Determine URI appending to baseURI when possible. + * Determine URI on the local filesystem considering possible mapping. * * @param pathStr - path to the resource, can be absolute or relative * @param baseURI - base {@link URI} where path to the resource is rooted * @return {@link URI} of the resource */ - private static URI determineURI(String pathStr, URI baseURI) { + private static URI determineMappedURI(String pathStr, URI baseURI) { URI uri = null; if (baseURI==null) { @@ -476,9 +482,15 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett // careful not to use Path here but 'pathStr' as String as we want to properly navigate symlinks uri = resolvePathFromBaseLocation(pathStr, baseLocation); } else { - // use canonicalized path here, in particular replace all '\' with '/' for Windows paths - Path path = new Path(pathStr); - uri = EFSExtensionManager.getDefault().append(baseURI, path.toString()); + // location on a remote filesystem + IPath path = new Path(pathStr); // use canonicalized path here, in particular replace all '\' with '/' for Windows paths + URI remoteUri = EFSExtensionManager.getDefault().append(baseURI, path.toString()); + if (remoteUri!=null) { + String localPath = EFSExtensionManager.getDefault().getMappedPath(remoteUri); + if (localPath!=null) { + uri = org.eclipse.core.filesystem.URIUtil.toURI(localPath); + } + } } if (uri == null) { @@ -642,7 +654,11 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett * @param parsedResourceName - path as appears in the output * @return mapped path as URI */ - private static URI getMappedRootURI(IResource sourceFile, String parsedResourceName) { + protected URI getMappedRootURI(IResource sourceFile, String parsedResourceName) { + if (currentResource==null) { + return null; + } + URI fileURI = sourceFile.getLocationURI(); String mappedRoot = "/"; //$NON-NLS-1$ @@ -674,17 +690,19 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett private static URI resolvePathFromBaseLocation(String name, IPath baseLocation) { String pathName = name; if (baseLocation != null && !baseLocation.isEmpty()) { - String device = new Path(pathName).getDevice(); - if (device != null && device.length() > 0) { - pathName = pathName.substring(device.length()); - } pathName = pathName.replace(File.separatorChar, '/'); - - baseLocation = baseLocation.addTrailingSeparator(); - if (pathName.startsWith("/")) { //$NON-NLS-1$ - pathName = pathName.substring(1); + String device = new Path(pathName).getDevice(); + if (device==null || device.equals(baseLocation.getDevice())) { + if (device != null && device.length() > 0) { + pathName = pathName.substring(device.length()); + } + + baseLocation = baseLocation.addTrailingSeparator(); + if (pathName.startsWith("/")) { //$NON-NLS-1$ + pathName = pathName.substring(1); + } + pathName = baseLocation.toString() + pathName; } - pathName = baseLocation.toString() + pathName; } try { diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/GCCBuiltinSpecsDetectorTest.java b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/GCCBuiltinSpecsDetectorTest.java index 21d1a22c2b7..965122671ba 100644 --- a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/GCCBuiltinSpecsDetectorTest.java +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/GCCBuiltinSpecsDetectorTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 Andrew Gvozdev and others. + * Copyright (c) 2010, 2011 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 @@ -33,6 +33,7 @@ import org.eclipse.cdt.core.testplugin.ResourceHelper; import org.eclipse.cdt.internal.core.XmlUtil; import org.eclipse.cdt.managedbuilder.internal.scannerconfig.AbstractBuiltinSpecsDetector; import org.eclipse.cdt.managedbuilder.internal.scannerconfig.GCCBuiltinSpecsDetector; +import org.eclipse.cdt.managedbuilder.internal.scannerconfig.GCCBuiltinSpecsDetectorCygwin; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; @@ -280,7 +281,6 @@ public class GCCBuiltinSpecsDetectorTest extends TestCase { String projectName = getName(); IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); - ICConfigurationDescription cfgDescription = cfgDescriptions[0]; AbstractBuiltinSpecsDetector detector = new GCCBuiltinSpecsDetector() { @@ -684,5 +684,63 @@ public class GCCBuiltinSpecsDetectorTest extends TestCase { assertEquals(expected, entries.get(0)); assertEquals(1, entries.size()); } + + public void testGCCBuiltinSpecsDetector_Cygwin_NoProject() throws Exception { + String windowsLocation; + String cygwinLocation = "/usr/include"; + try { + windowsLocation = ResourceHelper.cygwinToWindowsPath(cygwinLocation); + } catch (UnsupportedOperationException e) { + // Skip the test if Cygwin is not available. + return; + } + assertTrue("windowsLocation=["+windowsLocation+"]", new Path(windowsLocation).getDevice()!=null); + + AbstractBuiltinSpecsDetector detector = new GCCBuiltinSpecsDetectorCygwin(); + + detector.startup(null); + detector.processLine("#include <...> search starts here:"); + detector.processLine(" /usr/include"); + detector.processLine("End of search list."); + detector.shutdown(); + + // check populated entries + List entries = detector.getSettingEntries(null, null, null); + assertEquals(new CIncludePathEntry(new Path(windowsLocation), ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), entries.get(0)); + assertEquals(1, entries.size()); + + } + + public void testGCCBuiltinSpecsDetector_Cygwin_Configuration() throws Exception { + String windowsLocation; + String cygwinLocation = "/usr/include"; + try { + windowsLocation = ResourceHelper.cygwinToWindowsPath(cygwinLocation); + } catch (UnsupportedOperationException e) { + // Skip the test if Cygwin is not available. + return; + } + assertTrue("windowsLocation=["+windowsLocation+"]", new Path(windowsLocation).getDevice()!=null); + + + // Create model project and folders to test + String projectName = getName(); + IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + AbstractBuiltinSpecsDetector detector = new GCCBuiltinSpecsDetectorCygwin(); + + detector.startup(cfgDescription); + detector.processLine("#include <...> search starts here:"); + detector.processLine(" /usr/include"); + detector.processLine("End of search list."); + detector.shutdown(); + + // check populated entries + List entries = detector.getSettingEntries(null, null, null); + assertEquals(new CIncludePathEntry(new Path(windowsLocation), ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), entries.get(0)); + assertEquals(1, entries.size()); + } } diff --git a/build/org.eclipse.cdt.managedbuilder.core/plugin.xml b/build/org.eclipse.cdt.managedbuilder.core/plugin.xml index fa816ec68e8..5514f2173e0 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/plugin.xml +++ b/build/org.eclipse.cdt.managedbuilder.core/plugin.xml @@ -609,7 +609,7 @@ diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/AbstractBuiltinSpecsDetector.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/AbstractBuiltinSpecsDetector.java index 4b0a3ac816e..488c155cfa7 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/AbstractBuiltinSpecsDetector.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/AbstractBuiltinSpecsDetector.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.managedbuilder.internal.scannerconfig; import java.io.IOException; import java.io.OutputStream; +import java.net.URI; import java.net.URL; import java.util.ArrayList; import java.util.HashMap; @@ -79,6 +80,9 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti protected java.io.File specFile = null; protected boolean preserveSpecFile = false; + protected URI mappedRootURI = null; + protected URI buildDirURI = null; + /** * TODO */ @@ -151,6 +155,22 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti return currentLanguageId; } + @Override + protected URI getMappedRootURI(IResource sourceFile, String parsedResourceName) { + if (mappedRootURI==null) { + mappedRootURI = super.getMappedRootURI(sourceFile, parsedResourceName); + } + return mappedRootURI; + } + + @Override + protected URI getBuildDirURI(URI mappedRootURI) { + if (buildDirURI==null) { + buildDirURI = super.getBuildDirURI(mappedRootURI); + } + return buildDirURI; + } + @Override public void startup(ICConfigurationDescription cfgDescription) throws CoreException { // for workspace provider cfgDescription is used to figure out the current project for build console @@ -165,10 +185,16 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti specFile = null; currentCommandResolved = resolveCommand(currentLanguageId); + + mappedRootURI = null; + buildDirURI = null; } @Override public void shutdown() { + buildDirURI = null; + mappedRootURI = null; + if (detectedSettingEntries!=null && detectedSettingEntries.size()>0) { groupEntries(detectedSettingEntries); setSettingEntries(currentCfgDescription, currentResource, currentLanguageId, detectedSettingEntries); diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/GCCBuiltinSpecsDetector.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/GCCBuiltinSpecsDetector.java index 6b01c80d53b..b080fab86f5 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/GCCBuiltinSpecsDetector.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/GCCBuiltinSpecsDetector.java @@ -29,10 +29,10 @@ public class GCCBuiltinSpecsDetector extends AbstractBuiltinSpecsDetector implem private static final String GCC_TOOLCHAIN_ID = "cdt.managedbuild.toolchain.gnu.base"; //$NON-NLS-1$ private enum State {NONE, EXPECTING_LOCAL_INCLUDE, EXPECTING_SYSTEM_INCLUDE, EXPECTING_FRAMEWORKS} - State state = State.NONE; + private State state = State.NONE; @SuppressWarnings("nls") - static final AbstractOptionParser[] optionParsers = { + private static final AbstractOptionParser[] optionParsers = { new IncludePathOptionParser("#include \"(\\S.*)\"", "$1", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY | ICSettingEntry.LOCAL), new IncludePathOptionParser("#include <(\\S.*)>", "$1", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), new IncludePathOptionParser("#framework <(\\S.*)>", "$1", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY | ICSettingEntry.FRAMEWORKS_MAC), diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/GCCBuiltinSpecsDetectorCygwin.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/GCCBuiltinSpecsDetectorCygwin.java new file mode 100644 index 00000000000..64389f7a5b3 --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/GCCBuiltinSpecsDetectorCygwin.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * Copyright (c) 2009, 2011 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.managedbuilder.internal.scannerconfig; + +import java.net.URI; +import java.net.URISyntaxException; + +import org.eclipse.cdt.core.settings.model.ICSettingEntry; +import org.eclipse.core.resources.IResource; + +/** + * Class to detect built-in compiler settings. + * The paths are converted to cygwin "filesystem" representation. Then + * + */ +public class GCCBuiltinSpecsDetectorCygwin extends GCCBuiltinSpecsDetector { + private static final URI CYGWIN_ROOT; + static { + try { + CYGWIN_ROOT = new URI("cygwin:/"); //$NON-NLS-1$ + } catch (URISyntaxException e) { + // hey we know this works + throw new IllegalStateException(e); + } + } + + @SuppressWarnings("nls") + private static final AbstractOptionParser[] optionParsers = { + new IncludePathOptionParser("#include \"(\\S.*)\"", "$1", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY | ICSettingEntry.LOCAL), + new IncludePathOptionParser("#include <(\\S.*)>", "$1", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), + new MacroOptionParser("#define (\\S*\\(.*?\\)) *(.*)", "$1", "$2", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), + new MacroOptionParser("#define (\\S*) *(.*)", "$1", "$2", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), + }; + + @Override + protected AbstractOptionParser[] getOptionParsers() { + return optionParsers; + } + + @Override + protected URI getMappedRootURI(IResource sourceFile, String parsedResourceName) { + if (mappedRootURI==null) { + mappedRootURI = super.getMappedRootURI(sourceFile, parsedResourceName); + if (mappedRootURI==null) { + mappedRootURI = CYGWIN_ROOT; + } + } + return mappedRootURI; + } + + @Override + protected URI getBuildDirURI(URI mappedRootURI) { + if (buildDirURI==null) { + buildDirURI = super.getBuildDirURI(mappedRootURI); + if (buildDirURI==null) { + buildDirURI = CYGWIN_ROOT; + } + } + return buildDirURI; + } + + @Override + public GCCBuiltinSpecsDetectorCygwin cloneShallow() throws CloneNotSupportedException { + return (GCCBuiltinSpecsDetectorCygwin) super.cloneShallow(); + } + + @Override + public GCCBuiltinSpecsDetectorCygwin clone() throws CloneNotSupportedException { + return (GCCBuiltinSpecsDetectorCygwin) super.clone(); + } + +} diff --git a/core/org.eclipse.cdt.core/plugin.xml b/core/org.eclipse.cdt.core/plugin.xml index c8167c62bf1..95349032069 100644 --- a/core/org.eclipse.cdt.core/plugin.xml +++ b/core/org.eclipse.cdt.core/plugin.xml @@ -751,5 +751,12 @@ factoryClass="org.eclipse.cdt.internal.core.resources.ResourceExclusionFactory"> + + + + diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/resources/CygwinEFSExtensionProvider.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/resources/CygwinEFSExtensionProvider.java new file mode 100644 index 00000000000..5e78daf609b --- /dev/null +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/resources/CygwinEFSExtensionProvider.java @@ -0,0 +1,101 @@ +/******************************************************************************* + * Copyright (c) 2011, 2011 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.internal.core.resources; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.URI; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.EFSExtensionProvider; +import org.eclipse.core.runtime.Platform; + +public class CygwinEFSExtensionProvider extends EFSExtensionProvider { + @Override + public String getMappedPath(URI locationURI) { + String cygwinPath = getPathFromURI(locationURI); + String windowsPath = null; + try { + windowsPath = cygwinToWindowsPath(cygwinPath); + } catch (Exception e) { + CCorePlugin.log(e); + } + return windowsPath; + } + + /** + * Conversion from Windows path to Cygwin path. + * + * @param windowsPath - Windows path. + * @return Cygwin style converted path. + * @throws UnsupportedOperationException if Cygwin is unavailable. + * @throws IOException on IO problem. + * + * See ResourceHelper.windowsToCygwinPath(...) + */ + public static String windowsToCygwinPath(String windowsPath) throws IOException, UnsupportedOperationException { + if (!Platform.getOS().equals(Platform.OS_WIN32)) { + // Don't run this on non-windows platforms + throw new UnsupportedOperationException("Not a Windows system, Cygwin is unavailable."); + } + @SuppressWarnings("nls") + String[] args = {"cygpath", "-u", windowsPath}; + Process cygpath; + try { + cygpath = Runtime.getRuntime().exec(args); + } catch (IOException ioe) { + throw new UnsupportedOperationException("Cygwin utility cygpath is not in the system search path."); + } + BufferedReader stdout = new BufferedReader(new InputStreamReader(cygpath.getInputStream())); + + String cygwinPath = stdout.readLine(); + if (cygwinPath == null) { + throw new UnsupportedOperationException("Cygwin utility cygpath is not available."); + } + return cygwinPath.trim(); + } + + /** + * Conversion from Cygwin path to Windows path. + * + * @param cygwinPath - Cygwin path. + * @return Windows style converted path. + * @throws UnsupportedOperationException if Cygwin is unavailable. + * @throws IOException on IO problem. + * + * * See ResourceHelper.cygwinToWindowsPath(...) + */ + public static String cygwinToWindowsPath(String cygwinPath) throws IOException, UnsupportedOperationException { + if (!Platform.getOS().equals(Platform.OS_WIN32)) { + // Don't run this on non-windows platforms + throw new UnsupportedOperationException("Not a Windows system, Cygwin is unavailable."); + } + @SuppressWarnings("nls") + String[] args = {"cygpath", "-w", cygwinPath}; + Process cygpath; + try { + cygpath = Runtime.getRuntime().exec(args); + } catch (IOException ioe) { + throw new UnsupportedOperationException("Cygwin utility cygpath is not in the system search path."); + } + BufferedReader stdout = new BufferedReader(new InputStreamReader(cygpath.getInputStream())); + + String windowsPath = stdout.readLine(); + if (windowsPath == null) { + throw new UnsupportedOperationException("Cygwin utility cygpath is not available."); + } + return windowsPath.trim(); + } + + +} From 91db1a77f8ccac3afadb776ff0b3fd611150bdaa Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Fri, 15 Jul 2011 10:31:43 -0400 Subject: [PATCH 004/120] release resources for garbage collector on shutdown() --- .../AbstractLanguageSettingsOutputScanner.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java index d5ad2a07fa5..3a19b8f093b 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java @@ -230,6 +230,14 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett } public void shutdown() { + // release resources for garbage collector + currentCfgDescription = null; + currentProject = null; + currentResource = null; + currentLanguageId = null; + + errorParserManager = null; + parsedResourceName = null; } public boolean processLine(String line, ErrorParserManager epm) { From 7f3232a9591de3b09ee66897789c0b153dd2017c Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Tue, 19 Jul 2011 18:35:06 -0400 Subject: [PATCH 005/120] Use WeakHashMap to keep LSE in common pool. --- .../LanguageSettingsSerializable.java | 34 +++-------------- .../core/settings/model/ACSettingEntry.java | 31 +++++++-------- .../cdt/core/settings/model/CMacroEntry.java | 21 ++++++++-- .../core/settings/model/util/CDataUtil.java | 38 ++++++++++++++----- 4 files changed, 68 insertions(+), 56 deletions(-) diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java index 709a84e67d6..460824da26c 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java @@ -19,15 +19,10 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; -import org.eclipse.cdt.core.settings.model.CIncludeFileEntry; -import org.eclipse.cdt.core.settings.model.CIncludePathEntry; -import org.eclipse.cdt.core.settings.model.CLibraryFileEntry; -import org.eclipse.cdt.core.settings.model.CLibraryPathEntry; -import org.eclipse.cdt.core.settings.model.CMacroEntry; -import org.eclipse.cdt.core.settings.model.CMacroFileEntry; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICSettingEntry; +import org.eclipse.cdt.core.settings.model.util.CDataUtil; import org.eclipse.cdt.core.settings.model.util.LanguageSettingEntriesSerializer; import org.eclipse.cdt.internal.core.XmlUtil; import org.eclipse.core.resources.IResource; @@ -264,28 +259,11 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { } - ICLanguageSettingEntry entry = null; - switch (LanguageSettingEntriesSerializer.stringToKind(settingKind)) { - case ICSettingEntry.INCLUDE_PATH: - entry = new CIncludePathEntry(settingName, flags); - break; - case ICSettingEntry.INCLUDE_FILE: - entry = new CIncludeFileEntry(settingName, flags); - break; - case ICSettingEntry.MACRO: - String settingValue = XmlUtil.determineAttributeValue(parentElement, ATTR_VALUE); - entry = new CMacroEntry(settingName, settingValue, flags); - break; - case ICSettingEntry.MACRO_FILE: - entry = new CMacroFileEntry(settingName, flags); - break; - case ICSettingEntry.LIBRARY_PATH: - entry = new CLibraryPathEntry(settingName, flags); - break; - case ICSettingEntry.LIBRARY_FILE: - entry = new CLibraryFileEntry(settingName, flags); - break; - } + String settingValue = null; + int kind = LanguageSettingEntriesSerializer.stringToKind(settingKind); + if (kind == ICSettingEntry.MACRO) + settingValue = XmlUtil.determineAttributeValue(parentElement, ATTR_VALUE); + ICLanguageSettingEntry entry = (ICLanguageSettingEntry) CDataUtil.createEntry(kind, settingName, settingValue, null, flags); return entry; } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ACSettingEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ACSettingEntry.java index 37420be10a1..03d3c54c7bc 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ACSettingEntry.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ACSettingEntry.java @@ -51,30 +51,31 @@ public abstract class ACSettingEntry implements ICSettingEntry { } @Override - public boolean equals(Object other){ - if(other == this) + public boolean equals(Object obj) { + if (this == obj) return true; - - if(!(other instanceof ACSettingEntry)) + if (obj == null) return false; - - ACSettingEntry e = (ACSettingEntry)other; - - if(getKind() != e.getKind()) + if (getClass() != obj.getClass()) return false; - - if(fFlags != e.fFlags) + ACSettingEntry other = (ACSettingEntry) obj; + if (fFlags != other.fFlags) return false; - - if(!fName.equals(e.fName)) + if (fName == null) { + if (other.fName != null) + return false; + } else if (!fName.equals(other.fName)) return false; - return true; } @Override - public int hashCode(){ - return getKind() + fFlags + fName.hashCode(); + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + fFlags; + result = prime * result + ((fName == null) ? 0 : fName.hashCode()); + return result; } public int getFlags() { diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/CMacroEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/CMacroEntry.java index 451efd313d8..4c2750d35c4 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/CMacroEntry.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/CMacroEntry.java @@ -34,15 +34,28 @@ public final class CMacroEntry extends ACSettingEntry implements ICMacroEntry{ } @Override - public boolean equals(Object other) { - if(!super.equals(other)) + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) return false; - return fValue.equals(((CMacroEntry)other).fValue); + if (getClass() != obj.getClass()) + return false; + CMacroEntry other = (CMacroEntry) obj; + if (fValue == null) { + if (other.fValue != null) + return false; + } else if (!fValue.equals(other.fValue)) + return false; + return true; } @Override public int hashCode() { - return super.hashCode() + fValue.hashCode(); + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((fValue == null) ? 0 : fValue.hashCode()); + return result; } @Override diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/CDataUtil.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/CDataUtil.java index 4081606adac..761fa3f0cfb 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/CDataUtil.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/CDataUtil.java @@ -56,6 +56,7 @@ import org.eclipse.cdt.core.settings.model.extension.CResourceData; import org.eclipse.cdt.core.settings.model.extension.CTargetPlatformData; import org.eclipse.cdt.core.settings.model.extension.impl.CDataFactory; import org.eclipse.cdt.core.settings.model.extension.impl.CDefaultLanguageData; +import org.eclipse.cdt.internal.core.parser.util.WeakHashSet; import org.eclipse.cdt.internal.core.settings.model.ExceptionFactory; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.ProjectScope; @@ -74,6 +75,14 @@ public class CDataUtil { private static Random randomNumber; public static final String[] EMPTY_STRING_ARRAY = new String[0]; + + private static WeakHashSet languageSettingsPool = new WeakHashSet() { + @Override + public synchronized ICSettingEntry add(ICSettingEntry entry) { + return super.add(entry); + } + + }; public static int genRandomNumber(){ if (randomNumber == null) { @@ -301,25 +310,36 @@ public class CDataUtil { public static ICSettingEntry createEntry(int kind, String name, String value, IPath[] exclusionPatterns, int flags, IPath srcPath, IPath srcRootPath, IPath srcPrefixMapping){ + ICSettingEntry entry = null; switch (kind){ case ICLanguageSettingEntry.INCLUDE_PATH: - return new CIncludePathEntry(name, flags); + entry = new CIncludePathEntry(name, flags); + break; case ICLanguageSettingEntry.MACRO: - return new CMacroEntry(name, value, flags); + entry = new CMacroEntry(name, value, flags); + break; case ICLanguageSettingEntry.INCLUDE_FILE: - return new CIncludeFileEntry(name, flags); + entry = new CIncludeFileEntry(name, flags); + break; case ICLanguageSettingEntry.MACRO_FILE: - return new CMacroFileEntry(name, flags); + entry = new CMacroFileEntry(name, flags); + break; case ICLanguageSettingEntry.LIBRARY_PATH: - return new CLibraryPathEntry(name, flags); + entry = new CLibraryPathEntry(name, flags); + break; case ICLanguageSettingEntry.LIBRARY_FILE: - return new CLibraryFileEntry(name, flags, srcPath, srcRootPath, srcPrefixMapping); + entry = new CLibraryFileEntry(name, flags, srcPath, srcRootPath, srcPrefixMapping); + break; case ICLanguageSettingEntry.OUTPUT_PATH: - return new COutputEntry(name, exclusionPatterns, flags); + entry = new COutputEntry(name, exclusionPatterns, flags); + break; case ICLanguageSettingEntry.SOURCE_PATH: - return new CSourceEntry(name, exclusionPatterns, flags); + entry = new CSourceEntry(name, exclusionPatterns, flags); + break; + default: + throw new IllegalArgumentException(); } - throw new IllegalArgumentException(); + return languageSettingsPool.add(entry); } public static String[] getSourceExtensions(IProject project, CLanguageData data) { From 64982d49e8da90bcb1fcb2ce9c0c536d6adcd597 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Thu, 21 Jul 2011 09:28:03 -0400 Subject: [PATCH 006/120] Sort LSE by kinds --- .../GCCBuildCommandParserTest.java | 57 ++----- .../AbstractBuiltinSpecsDetector.java | 28 ---- .../LanguageSettingsSerializableTests.java | 155 +++++++++++++++++- .../LanguageSettingsSerializable.java | 23 ++- 4 files changed, 191 insertions(+), 72 deletions(-) diff --git a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java index a1aef93e593..8d4feecca84 100644 --- a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java +++ b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java @@ -770,46 +770,21 @@ public class GCCBuildCommandParserTest extends TestCase { // check populated entries List entries = parser.getSettingEntries(cfgDescription, file, languageId); + String device = project.getLocation().getDevice(); // + " -I/path0 " - { - IPath path = new Path("/path0").setDevice(project.getLocation().getDevice()); - CIncludePathEntry expected = new CIncludePathEntry(path, 0); - assertEquals(expected, entries.get(0)); - } -// + " -DMACRO1=value" - { - CMacroEntry expected = new CMacroEntry("MACRO1", "value", 0); - assertEquals(expected, entries.get(1)); - } -// + " -ldomain" - { - CLibraryFileEntry expected = new CLibraryFileEntry("libdomain.a", 0); - assertEquals(expected, entries.get(2)); - } + assertEquals(new CIncludePathEntry(new Path("/path0").setDevice(device), 0), entries.get(0)); // + " -I /path1 " - { - IPath path = new Path("/path1").setDevice(project.getLocation().getDevice()); - CIncludePathEntry expected = new CIncludePathEntry(path, 0); - assertEquals(expected, entries.get(3)); - } -// + " -DMACRO2=\"value with spaces\"" - { - CMacroEntry expected = new CMacroEntry("MACRO2", "value with spaces", 0); - assertEquals(expected, entries.get(4)); - } + assertEquals(new CIncludePathEntry(new Path("/path1").setDevice(device), 0), entries.get(1)); // + " -I\"/path with spaces\"" - { - IPath path = new Path("/path with spaces").setDevice(project.getLocation().getDevice()); - CIncludePathEntry expected = new CIncludePathEntry(path, 0); - assertEquals(expected, entries.get(5)); - } + assertEquals(new CIncludePathEntry(new Path("/path with spaces").setDevice(device), 0), entries.get(2)); +// + " -DMACRO1=value" + assertEquals(new CMacroEntry("MACRO1", "value", 0), entries.get(3)); +// + " -DMACRO2=\"value with spaces\"" + assertEquals(new CMacroEntry("MACRO2", "value with spaces", 0), entries.get(4)); // + " -L/usr/lib" - { - IPath path = new Path("/usr/lib").setDevice(project.getLocation().getDevice()); - CLibraryPathEntry expected = new CLibraryPathEntry(path, 0); - assertEquals(expected, entries.get(6)); - } - + assertEquals(new CLibraryPathEntry(new Path("/usr/lib").setDevice(device), 0), entries.get(5)); +// + " -ldomain" + assertEquals(new CLibraryFileEntry("libdomain.a", 0), entries.get(6)); assertEquals(7, entries.size()); } @@ -1811,11 +1786,11 @@ public class GCCBuildCommandParserTest extends TestCase { // check populated entries { List entries = parser.getSettingEntries(cfgDescription, file, languageId); - assertEquals(new CMacroEntry("BOOST_ALL_NO_LIB", "1", 0), entries.get(0)); - assertEquals(new CMacroEntry("BOOST_PYTHON_SOURCE", "", 0), entries.get(1)); - assertEquals(new CMacroEntry("BOOST_PYTHON_STATIC_LIB", "", 0), entries.get(2)); - assertEquals(new CIncludePathEntry(project.getFullPath(), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(3)); - assertEquals(new CIncludePathEntry(new Path("/Python1025/Include").setDevice(project.getLocation().getDevice()), 0), entries.get(4)); + assertEquals(new CIncludePathEntry(project.getFullPath(), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(0)); + assertEquals(new CIncludePathEntry(new Path("/Python1025/Include").setDevice(project.getLocation().getDevice()), 0), entries.get(1)); + assertEquals(new CMacroEntry("BOOST_ALL_NO_LIB", "1", 0), entries.get(2)); + assertEquals(new CMacroEntry("BOOST_PYTHON_SOURCE", "", 0), entries.get(3)); + assertEquals(new CMacroEntry("BOOST_PYTHON_STATIC_LIB", "", 0), entries.get(4)); assertEquals(5, entries.size()); } } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/AbstractBuiltinSpecsDetector.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/AbstractBuiltinSpecsDetector.java index 488c155cfa7..b21b0b4f64c 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/AbstractBuiltinSpecsDetector.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/AbstractBuiltinSpecsDetector.java @@ -196,7 +196,6 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti mappedRootURI = null; if (detectedSettingEntries!=null && detectedSettingEntries.size()>0) { - groupEntries(detectedSettingEntries); setSettingEntries(currentCfgDescription, currentResource, currentLanguageId, detectedSettingEntries); IStatus status = new Status(IStatus.INFO, MakeCorePlugin.PLUGIN_ID, getClass().getSimpleName() @@ -213,33 +212,6 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti currentCommandResolved = null; } - protected void groupEntries(List inputEntries) { - Map> groupedEntries = new HashMap>(); - int kindMax = 0; - for (ICLanguageSettingEntry entry : inputEntries) { - int kind = entry.getKind(); - if (kind>kindMax) { - kindMax = kind; - } - - List entries = groupedEntries.get(kind); - if (entries==null) { - entries = new ArrayList(); - groupedEntries.put(kind, entries); - } - entries.add(entry); - } - - inputEntries.clear(); - - for (int kind=1;kind<=kindMax;kind++) { - List entries = groupedEntries.get(kind); - if (entries!=null) { - inputEntries.addAll(entries); - } - } - } - public void run(IProject project, String languageId, IPath workingDirectory, String[] env, IProgressMonitor monitor) throws CoreException, IOException { if (isRunOnce() && !isEmpty()) { diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java index 0cde8b59f0a..79803db2061 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java @@ -25,6 +25,7 @@ import org.eclipse.cdt.core.settings.model.CMacroEntry; import org.eclipse.cdt.core.settings.model.CMacroFileEntry; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; +import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.core.testplugin.CModelMock; import org.eclipse.cdt.core.testplugin.ResourceHelper; import org.eclipse.cdt.internal.core.XmlUtil; @@ -797,9 +798,9 @@ public class LanguageSettingsSerializableTests extends TestCase { public void testMixedSettingEntries() throws Exception { Element elementProvider; List entries = new ArrayList(); - entries.add(new CMacroEntry("MACRO0", "value0",1)); entries.add(new CIncludePathEntry("path0", 1)); entries.add(new CIncludePathEntry("path1", 1)); + entries.add(new CMacroEntry("MACRO0", "value0",1)); { // create a provider and serialize its settings LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); @@ -822,6 +823,156 @@ public class LanguageSettingsSerializableTests extends TestCase { } } + /** + */ + public void testSort_Kinds() throws Exception { + // create sample entries + CIncludePathEntry includePathEntry1 = new CIncludePathEntry("path1", 0); + CIncludePathEntry includePathEntry2 = new CIncludePathEntry("path2", 0); + CMacroEntry macroEntry1 = new CMacroEntry("MACRO1", null, 0); + CMacroEntry macroEntry2 = new CMacroEntry("MACRO2", null, 0); + CIncludeFileEntry includeFileEntry1 = new CIncludeFileEntry("file1", 0); + CIncludeFileEntry includeFileEntry2 = new CIncludeFileEntry("file2", 0); + CMacroFileEntry macroFileEntry1 = new CMacroFileEntry("file1", 0); + CMacroFileEntry macroFileEntry2 = new CMacroFileEntry("file2", 0); + CLibraryPathEntry libraryPathEntry1 = new CLibraryPathEntry("lib1", 0); + CLibraryPathEntry libraryPathEntry2 = new CLibraryPathEntry("lib2", 0); + CLibraryFileEntry libraryFileEntry1 = new CLibraryFileEntry("file1", 0); + CLibraryFileEntry libraryFileEntry2 = new CLibraryFileEntry("file2", 0); + + // place entries in unsorted list + List unsortedEntries = new ArrayList(); + unsortedEntries.add(macroEntry1); + unsortedEntries.add(macroFileEntry1); + unsortedEntries.add(macroEntry2); + unsortedEntries.add(includePathEntry1); + unsortedEntries.add(includeFileEntry1); + unsortedEntries.add(macroFileEntry2); + unsortedEntries.add(libraryFileEntry1); + unsortedEntries.add(includeFileEntry2); + unsortedEntries.add(libraryFileEntry2); + unsortedEntries.add(libraryPathEntry1); + unsortedEntries.add(includePathEntry2); + unsortedEntries.add(libraryPathEntry2); + + // create a provider and set the entries + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + provider.setSettingEntries(null, null, null, unsortedEntries); + + // retrieve and check that language settings got sorted properly + assertEquals(PROVIDER_1, provider.getId()); + int i=0; + List actual = provider.getSettingEntries(null, null, null); + assertEquals(includePathEntry1, actual.get(i++)); + assertEquals(includePathEntry2, actual.get(i++)); + assertEquals(includeFileEntry1, actual.get(i++)); + assertEquals(includeFileEntry2, actual.get(i++)); + assertEquals(macroEntry1, actual.get(i++)); + assertEquals(macroEntry2, actual.get(i++)); + assertEquals(macroFileEntry1, actual.get(i++)); + assertEquals(macroFileEntry2, actual.get(i++)); + assertEquals(libraryPathEntry1, actual.get(i++)); + assertEquals(libraryPathEntry2, actual.get(i++)); + assertEquals(libraryFileEntry1, actual.get(i++)); + assertEquals(libraryFileEntry2, actual.get(i++)); + + assertEquals(unsortedEntries.size(), actual.size()); + } + + /** + */ + public void testSort_Entries() throws Exception { + // create sample entries + CIncludePathEntry includePathEntry1 = new CIncludePathEntry("path_B", 0); + CIncludePathEntry includePathEntry2 = new CIncludePathEntry("path_A", 0); + CMacroEntry macroEntry1 = new CMacroEntry("MACRO_A", null, 0); + CMacroEntry macroEntry2 = new CMacroEntry("MACRO_B", null, 0); + CIncludeFileEntry includeFileEntry1 = new CIncludeFileEntry("file_B", 0); + CIncludeFileEntry includeFileEntry2 = new CIncludeFileEntry("file_A", 0); + CMacroFileEntry macroFileEntry1 = new CMacroFileEntry("file_B", 0); + CMacroFileEntry macroFileEntry2 = new CMacroFileEntry("file_A", 0); + CLibraryPathEntry libraryPathEntry1 = new CLibraryPathEntry("lib_B", 0); + CLibraryPathEntry libraryPathEntry2 = new CLibraryPathEntry("lib_A", 0); + CLibraryFileEntry libraryFileEntry1 = new CLibraryFileEntry("file_B", 0); + CLibraryFileEntry libraryFileEntry2 = new CLibraryFileEntry("file_A", 0); + + // place entries in unsorted list + List unsortedEntries = new ArrayList(); + // macros will be sorted by name + unsortedEntries.add(macroEntry2); + unsortedEntries.add(macroEntry1); + // paths are not sorted only grouped by kind + unsortedEntries.add(macroFileEntry1); + unsortedEntries.add(macroFileEntry2); + unsortedEntries.add(includePathEntry1); + unsortedEntries.add(includePathEntry2); + unsortedEntries.add(includeFileEntry1); + unsortedEntries.add(includeFileEntry2); + unsortedEntries.add(libraryFileEntry1); + unsortedEntries.add(libraryFileEntry2); + unsortedEntries.add(libraryPathEntry1); + unsortedEntries.add(libraryPathEntry2); + + // create a provider and set the entries + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + provider.setSettingEntries(null, null, null, unsortedEntries); + + // retrieve and check that language settings got sorted properly + assertEquals(PROVIDER_1, provider.getId()); + int i=0; + List actual = provider.getSettingEntries(null, null, null); + assertEquals(includePathEntry1, actual.get(i++)); + assertEquals(includePathEntry2, actual.get(i++)); + assertEquals(includeFileEntry1, actual.get(i++)); + assertEquals(includeFileEntry2, actual.get(i++)); + assertEquals(macroEntry1, actual.get(i++)); + assertEquals(macroEntry2, actual.get(i++)); + assertEquals(macroFileEntry1, actual.get(i++)); + assertEquals(macroFileEntry2, actual.get(i++)); + assertEquals(libraryPathEntry1, actual.get(i++)); + assertEquals(libraryPathEntry2, actual.get(i++)); + assertEquals(libraryFileEntry1, actual.get(i++)); + assertEquals(libraryFileEntry2, actual.get(i++)); + + assertEquals(unsortedEntries.size(), actual.size()); + } + + /** + */ + public void testSort_Undef() throws Exception { + // create sample entries + CMacroEntry macroEntry1 = new CMacroEntry("MACRO_1", null, 0); + CMacroEntry macroEntry2A = new CMacroEntry("MACRO_2", null, ICSettingEntry.UNDEFINED); + CMacroEntry macroEntry2B = new CMacroEntry("MACRO_2", null, 0); + CMacroEntry macroEntry2C = new CMacroEntry("MACRO_2", null, ICSettingEntry.BUILTIN); + CMacroEntry macroEntry3 = new CMacroEntry("MACRO_3", null, 0); + + // place entries in unsorted list + List unsortedEntries = new ArrayList(); + // macros will be sorted by name and keep order for the same name + unsortedEntries.add(macroEntry2A); + unsortedEntries.add(macroEntry3); + unsortedEntries.add(macroEntry2B); + unsortedEntries.add(macroEntry1); + unsortedEntries.add(macroEntry2C); + + // create a provider and set the entries + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + provider.setSettingEntries(null, null, null, unsortedEntries); + + // retrieve and check that language settings got sorted properly + assertEquals(PROVIDER_1, provider.getId()); + int i=0; + List actual = provider.getSettingEntries(null, null, null); + assertEquals(macroEntry1, actual.get(i++)); + assertEquals(macroEntry2A, actual.get(i++)); + assertEquals(macroEntry2B, actual.get(i++)); + assertEquals(macroEntry2C, actual.get(i++)); + assertEquals(macroEntry3, actual.get(i++)); + + assertEquals(unsortedEntries.size(), actual.size()); + } + /** */ public void testLanguageAndNull() throws Exception { @@ -1056,9 +1207,9 @@ public class LanguageSettingsSerializableTests extends TestCase { public void testClone() throws Exception { // define sample data List sampleEntries_1 = new ArrayList(); - sampleEntries_1.add(new CMacroEntry("MACRO0", "value0",1)); sampleEntries_1.add(new CIncludePathEntry("path0", 1)); sampleEntries_1.add(new CIncludePathEntry("path1", 1)); + sampleEntries_1.add(new CMacroEntry("MACRO0", "value0",1)); List sampleEntries_2 = new ArrayList(); sampleEntries_2.add(new CIncludePathEntry("path0", 1)); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java index 460824da26c..da29eb269b8 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.core.language.settings.providers; import java.util.ArrayList; import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -119,7 +120,8 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { langMap = new HashMap>(); fStorage.put(languageId, langMap); } - langMap.put(rcProjectPath, entries); + List sortedEntries = sortEntries(entries); + langMap.put(rcProjectPath, sortedEntries); } else { // do not keep nulls in the tables Map> langMap = fStorage.get(languageId); @@ -132,6 +134,25 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { } } + protected List sortEntries(List entries) { + List sortedEntries = new ArrayList(entries); + Collections.sort(sortedEntries, new Comparator(){ + /** + * This comparator sorts by kinds first and the macros are sorted additionally by name. + */ + public int compare(ICLanguageSettingEntry entry0, ICLanguageSettingEntry entry1) { + int kind0 = entry0.getKind(); + int kind1 = entry1.getKind(); + if (kind0==ICSettingEntry.MACRO && kind1==ICSettingEntry.MACRO) { + return entry0.getName().compareTo(entry1.getName()); + } + + return kind0 - kind1; + }}); + + return sortedEntries; + } + /** * Sets language settings entries for the provider. * Note that the entries are not persisted at that point. To persist use TODO From 2d2311a2a6a83b657f0c35c5e2aec6a49ca4e43a Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Sat, 23 Jul 2011 08:13:57 -0400 Subject: [PATCH 007/120] Use WeakHashMap to keep LSE lists in common pool. --- .../LanguageSettingsSerializable.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java index da29eb269b8..ccd1770bcdd 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java @@ -26,6 +26,7 @@ import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.core.settings.model.util.CDataUtil; import org.eclipse.cdt.core.settings.model.util.LanguageSettingEntriesSerializer; import org.eclipse.cdt.internal.core.XmlUtil; +import org.eclipse.cdt.internal.core.parser.util.WeakHashSet; import org.eclipse.core.resources.IResource; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -50,6 +51,14 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { private static final String ELEM_FLAG = "flag"; //$NON-NLS-1$ + private static WeakHashSet> listLSEPool = new WeakHashSet>() { + @Override + public synchronized List add(List list) { + return super.add(list); + } + + }; + private Map>(); fStorage.put(languageId, langMap); } - List sortedEntries = sortEntries(entries); + List sortedEntries = listLSEPool.add(Collections.unmodifiableList(sortEntries(entries))); langMap.put(rcProjectPath, sortedEntries); } else { // do not keep nulls in the tables @@ -152,7 +161,7 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { return sortedEntries; } - + /** * Sets language settings entries for the provider. * Note that the entries are not persisted at that point. To persist use TODO @@ -170,6 +179,8 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { /** * {@inheritDoc} + * + * Note that this list is unmodifiable. */ @Override public List getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) { @@ -178,7 +189,7 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { String rcProjectPath = rc!=null ? rc.getProjectRelativePath().toString() : null; List entries = langMap.get(rcProjectPath); if (entries!=null) - return Collections.unmodifiableList(entries); + return entries; } if (languageId!=null && (languageScope==null || languageScope.contains(languageId))) { @@ -408,8 +419,8 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { for (Entry> entryRc : entrySetRc) { String rcProjectPath = entryRc.getKey(); List lsEntries = entryRc.getValue(); - List lsEntriesClone = new ArrayList(lsEntries); - mapRcClone.put(rcProjectPath, lsEntriesClone); + // don't need to clone entries, they are from the pool + mapRcClone.put(rcProjectPath, lsEntries); } // mapLangClone.put(langId, mapRcClone); storageClone.put(langId, mapRcClone); From e1e1bc2e1906dcbf5e004ff5537c2a8bd0f5d9ee Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Tue, 2 Aug 2011 13:11:30 -0400 Subject: [PATCH 008/120] making resource tree to appear as "compacted" for the user --- .../AbstractBuildCommandParser.java | 7 + .../LanguageSettingsManagerTests.java | 123 ++++++++ .../LanguageSettingsSerializableTests.java | 298 +++++++++--------- .../providers/LanguageSettingsManager.java | 8 + .../LanguageSettingsSerializable.java | 4 +- .../LanguageSettingsExtensionManager.java | 100 ++++++ 6 files changed, 388 insertions(+), 152 deletions(-) diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java index e6a9d2de807..508410b6e4c 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java @@ -100,6 +100,13 @@ public abstract class AbstractBuildCommandParser extends AbstractLanguageSetting return super.processLine(line, epm); } + // TODO - test cases + @Override + public void shutdown() { + LanguageSettingsManager.buildResourceTree(this, currentCfgDescription, currentLanguageId, currentProject); + super.shutdown(); + } + /** * Trivial Error Parser which allows highlighting of output lines matching the patterns * of this parser. Intended for better troubleshooting experience. diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java index 066ac866a66..2c4cce01795 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java @@ -778,4 +778,127 @@ public class LanguageSettingsManagerTests extends TestCase { // check for no side effect assertSame(provider, providers.get(0)); } + + /** + */ + public void testBuildResourceTree_FileInFolder() throws Exception { + // sample entries + CMacroEntry entry = new CMacroEntry("MACRO", null, 0); + List entries = new ArrayList(); + entries.add(entry); + + // create resources + IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName()); + IFile file = ResourceHelper.createFile(project, "file.cpp"); + assertNotNull(file); + + // create a provider and set the entries + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + provider.setSettingEntries(null, file, null, entries); + // build the hierarchy + LanguageSettingsExtensionManager.buildResourceTree(provider, null, null, project); + + // check that entries go to highest possible level + assertEquals(entries, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file, null)); + assertEquals(entries, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, project, null)); + } + + /** + */ + public void testBuildResourceTree_FileInSubFolder() throws Exception { + // sample entries + CMacroEntry entry = new CMacroEntry("MACRO", null, 0); + List entries = new ArrayList(); + entries.add(entry); + + // create resources + IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName()); + IFolder folder = ResourceHelper.createFolder(project, "Folder"); + IFile file = ResourceHelper.createFile(project, "Folder/file.cpp"); + + // create a provider and set the entries + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + provider.setSettingEntries(null, file, null, entries); + // build the hierarchy + LanguageSettingsExtensionManager.buildResourceTree(provider, null, null, project); + + // check that entries go to highest possible level + assertEquals(entries, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file, null)); + assertEquals(entries, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, folder, null)); + assertEquals(entries, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, project, null)); + } + + /** + */ + public void testBuildResourceTree_TwoSubFolders() throws Exception { + // sample entries + List entries1 = new ArrayList(); + entries1.add(new CMacroEntry("MACRO_1", null, 0)); + List entries2 = new ArrayList(); + entries2.add(new CMacroEntry("MACRO_2", null, 0)); + + // create resources + IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName()); + IFolder folder1 = ResourceHelper.createFolder(project, "Folder1"); + IFolder folder2 = ResourceHelper.createFolder(project, "Folder2"); + IFile file1 = ResourceHelper.createFile(project, "Folder1/file1.cpp"); + IFile file2 = ResourceHelper.createFile(project, "Folder2/file2.cpp"); + + // create a provider and set the entries + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + provider.setSettingEntries(null, file1, null, entries1); + provider.setSettingEntries(null, file2, null, entries2); + // build the hierarchy + LanguageSettingsExtensionManager.buildResourceTree(provider, null, null, project); + + // check that entries go to highest possible level + assertEquals(entries1, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file1, null)); + assertEquals(entries1, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, folder1, null)); + + assertEquals(entries2, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file2, null)); + assertEquals(entries2, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, folder2, null)); + + assertEquals(0, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, project, null).size()); + } + + /** + */ + public void testBuildResourceTree_IncrementalBuildFlippingSettings() throws Exception { + // sample entries + List entries1 = new ArrayList(); + entries1.add(new CMacroEntry("MACRO_1", null, 0)); + List entries2 = new ArrayList(); + entries2.add(new CMacroEntry("MACRO_2", null, 0)); + + // create resources + IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName()); + IFile file1 = ResourceHelper.createFile(project, "file1.cpp"); + IFile file2 = ResourceHelper.createFile(project, "file2.cpp"); + IFile file3 = ResourceHelper.createFile(project, "file3.cpp"); + + // create a provider + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + + // set the entries for the first 2 files + provider.setSettingEntries(null, file1, null, entries1); + provider.setSettingEntries(null, file2, null, entries1); + // build the hierarchy + LanguageSettingsExtensionManager.buildResourceTree(provider, null, null, project); + // double-check where the entries go + assertEquals(entries1, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file1, null)); + assertEquals(entries1, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file2, null)); + assertEquals(entries1, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, project, null)); + + // set the entries for the second+third files (with overlap) + provider.setSettingEntries(null, file2, null, entries2); + provider.setSettingEntries(null, file3, null, entries2); + // build the hierarchy + LanguageSettingsExtensionManager.buildResourceTree(provider, null, null, project); + // check where the entries go, it should not lose entries for the first file + assertEquals(entries1, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file1, null)); + assertEquals(entries2, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file2, null)); + assertEquals(entries2, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file3, null)); + assertEquals(entries2, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, project, null)); + } + } diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java index 79803db2061..b65fb14b78b 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java @@ -823,156 +823,6 @@ public class LanguageSettingsSerializableTests extends TestCase { } } - /** - */ - public void testSort_Kinds() throws Exception { - // create sample entries - CIncludePathEntry includePathEntry1 = new CIncludePathEntry("path1", 0); - CIncludePathEntry includePathEntry2 = new CIncludePathEntry("path2", 0); - CMacroEntry macroEntry1 = new CMacroEntry("MACRO1", null, 0); - CMacroEntry macroEntry2 = new CMacroEntry("MACRO2", null, 0); - CIncludeFileEntry includeFileEntry1 = new CIncludeFileEntry("file1", 0); - CIncludeFileEntry includeFileEntry2 = new CIncludeFileEntry("file2", 0); - CMacroFileEntry macroFileEntry1 = new CMacroFileEntry("file1", 0); - CMacroFileEntry macroFileEntry2 = new CMacroFileEntry("file2", 0); - CLibraryPathEntry libraryPathEntry1 = new CLibraryPathEntry("lib1", 0); - CLibraryPathEntry libraryPathEntry2 = new CLibraryPathEntry("lib2", 0); - CLibraryFileEntry libraryFileEntry1 = new CLibraryFileEntry("file1", 0); - CLibraryFileEntry libraryFileEntry2 = new CLibraryFileEntry("file2", 0); - - // place entries in unsorted list - List unsortedEntries = new ArrayList(); - unsortedEntries.add(macroEntry1); - unsortedEntries.add(macroFileEntry1); - unsortedEntries.add(macroEntry2); - unsortedEntries.add(includePathEntry1); - unsortedEntries.add(includeFileEntry1); - unsortedEntries.add(macroFileEntry2); - unsortedEntries.add(libraryFileEntry1); - unsortedEntries.add(includeFileEntry2); - unsortedEntries.add(libraryFileEntry2); - unsortedEntries.add(libraryPathEntry1); - unsortedEntries.add(includePathEntry2); - unsortedEntries.add(libraryPathEntry2); - - // create a provider and set the entries - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); - provider.setSettingEntries(null, null, null, unsortedEntries); - - // retrieve and check that language settings got sorted properly - assertEquals(PROVIDER_1, provider.getId()); - int i=0; - List actual = provider.getSettingEntries(null, null, null); - assertEquals(includePathEntry1, actual.get(i++)); - assertEquals(includePathEntry2, actual.get(i++)); - assertEquals(includeFileEntry1, actual.get(i++)); - assertEquals(includeFileEntry2, actual.get(i++)); - assertEquals(macroEntry1, actual.get(i++)); - assertEquals(macroEntry2, actual.get(i++)); - assertEquals(macroFileEntry1, actual.get(i++)); - assertEquals(macroFileEntry2, actual.get(i++)); - assertEquals(libraryPathEntry1, actual.get(i++)); - assertEquals(libraryPathEntry2, actual.get(i++)); - assertEquals(libraryFileEntry1, actual.get(i++)); - assertEquals(libraryFileEntry2, actual.get(i++)); - - assertEquals(unsortedEntries.size(), actual.size()); - } - - /** - */ - public void testSort_Entries() throws Exception { - // create sample entries - CIncludePathEntry includePathEntry1 = new CIncludePathEntry("path_B", 0); - CIncludePathEntry includePathEntry2 = new CIncludePathEntry("path_A", 0); - CMacroEntry macroEntry1 = new CMacroEntry("MACRO_A", null, 0); - CMacroEntry macroEntry2 = new CMacroEntry("MACRO_B", null, 0); - CIncludeFileEntry includeFileEntry1 = new CIncludeFileEntry("file_B", 0); - CIncludeFileEntry includeFileEntry2 = new CIncludeFileEntry("file_A", 0); - CMacroFileEntry macroFileEntry1 = new CMacroFileEntry("file_B", 0); - CMacroFileEntry macroFileEntry2 = new CMacroFileEntry("file_A", 0); - CLibraryPathEntry libraryPathEntry1 = new CLibraryPathEntry("lib_B", 0); - CLibraryPathEntry libraryPathEntry2 = new CLibraryPathEntry("lib_A", 0); - CLibraryFileEntry libraryFileEntry1 = new CLibraryFileEntry("file_B", 0); - CLibraryFileEntry libraryFileEntry2 = new CLibraryFileEntry("file_A", 0); - - // place entries in unsorted list - List unsortedEntries = new ArrayList(); - // macros will be sorted by name - unsortedEntries.add(macroEntry2); - unsortedEntries.add(macroEntry1); - // paths are not sorted only grouped by kind - unsortedEntries.add(macroFileEntry1); - unsortedEntries.add(macroFileEntry2); - unsortedEntries.add(includePathEntry1); - unsortedEntries.add(includePathEntry2); - unsortedEntries.add(includeFileEntry1); - unsortedEntries.add(includeFileEntry2); - unsortedEntries.add(libraryFileEntry1); - unsortedEntries.add(libraryFileEntry2); - unsortedEntries.add(libraryPathEntry1); - unsortedEntries.add(libraryPathEntry2); - - // create a provider and set the entries - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); - provider.setSettingEntries(null, null, null, unsortedEntries); - - // retrieve and check that language settings got sorted properly - assertEquals(PROVIDER_1, provider.getId()); - int i=0; - List actual = provider.getSettingEntries(null, null, null); - assertEquals(includePathEntry1, actual.get(i++)); - assertEquals(includePathEntry2, actual.get(i++)); - assertEquals(includeFileEntry1, actual.get(i++)); - assertEquals(includeFileEntry2, actual.get(i++)); - assertEquals(macroEntry1, actual.get(i++)); - assertEquals(macroEntry2, actual.get(i++)); - assertEquals(macroFileEntry1, actual.get(i++)); - assertEquals(macroFileEntry2, actual.get(i++)); - assertEquals(libraryPathEntry1, actual.get(i++)); - assertEquals(libraryPathEntry2, actual.get(i++)); - assertEquals(libraryFileEntry1, actual.get(i++)); - assertEquals(libraryFileEntry2, actual.get(i++)); - - assertEquals(unsortedEntries.size(), actual.size()); - } - - /** - */ - public void testSort_Undef() throws Exception { - // create sample entries - CMacroEntry macroEntry1 = new CMacroEntry("MACRO_1", null, 0); - CMacroEntry macroEntry2A = new CMacroEntry("MACRO_2", null, ICSettingEntry.UNDEFINED); - CMacroEntry macroEntry2B = new CMacroEntry("MACRO_2", null, 0); - CMacroEntry macroEntry2C = new CMacroEntry("MACRO_2", null, ICSettingEntry.BUILTIN); - CMacroEntry macroEntry3 = new CMacroEntry("MACRO_3", null, 0); - - // place entries in unsorted list - List unsortedEntries = new ArrayList(); - // macros will be sorted by name and keep order for the same name - unsortedEntries.add(macroEntry2A); - unsortedEntries.add(macroEntry3); - unsortedEntries.add(macroEntry2B); - unsortedEntries.add(macroEntry1); - unsortedEntries.add(macroEntry2C); - - // create a provider and set the entries - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); - provider.setSettingEntries(null, null, null, unsortedEntries); - - // retrieve and check that language settings got sorted properly - assertEquals(PROVIDER_1, provider.getId()); - int i=0; - List actual = provider.getSettingEntries(null, null, null); - assertEquals(macroEntry1, actual.get(i++)); - assertEquals(macroEntry2A, actual.get(i++)); - assertEquals(macroEntry2B, actual.get(i++)); - assertEquals(macroEntry2C, actual.get(i++)); - assertEquals(macroEntry3, actual.get(i++)); - - assertEquals(unsortedEntries.size(), actual.size()); - } - /** */ public void testLanguageAndNull() throws Exception { @@ -1292,6 +1142,154 @@ public class LanguageSettingsSerializableTests extends TestCase { List actual = providerClone.getSettingEntries(null, null, null); assertNull(actual); } + + /** + */ + public void testSort_Kinds() throws Exception { + // create sample entries + CIncludePathEntry includePathEntry1 = new CIncludePathEntry("path1", 0); + CIncludePathEntry includePathEntry2 = new CIncludePathEntry("path2", 0); + CMacroEntry macroEntry1 = new CMacroEntry("MACRO1", null, 0); + CMacroEntry macroEntry2 = new CMacroEntry("MACRO2", null, 0); + CIncludeFileEntry includeFileEntry1 = new CIncludeFileEntry("file1", 0); + CIncludeFileEntry includeFileEntry2 = new CIncludeFileEntry("file2", 0); + CMacroFileEntry macroFileEntry1 = new CMacroFileEntry("file1", 0); + CMacroFileEntry macroFileEntry2 = new CMacroFileEntry("file2", 0); + CLibraryPathEntry libraryPathEntry1 = new CLibraryPathEntry("lib1", 0); + CLibraryPathEntry libraryPathEntry2 = new CLibraryPathEntry("lib2", 0); + CLibraryFileEntry libraryFileEntry1 = new CLibraryFileEntry("file1", 0); + CLibraryFileEntry libraryFileEntry2 = new CLibraryFileEntry("file2", 0); + + // place entries in unsorted list + List unsortedEntries = new ArrayList(); + unsortedEntries.add(macroEntry1); + unsortedEntries.add(macroFileEntry1); + unsortedEntries.add(macroEntry2); + unsortedEntries.add(includePathEntry1); + unsortedEntries.add(includeFileEntry1); + unsortedEntries.add(macroFileEntry2); + unsortedEntries.add(libraryFileEntry1); + unsortedEntries.add(includeFileEntry2); + unsortedEntries.add(libraryFileEntry2); + unsortedEntries.add(libraryPathEntry1); + unsortedEntries.add(includePathEntry2); + unsortedEntries.add(libraryPathEntry2); + + // create a provider and set the entries + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + provider.setSettingEntries(null, null, null, unsortedEntries); + + // retrieve and check that language settings got sorted properly + int i=0; + List actual = provider.getSettingEntries(null, null, null); + assertEquals(includePathEntry1, actual.get(i++)); + assertEquals(includePathEntry2, actual.get(i++)); + assertEquals(includeFileEntry1, actual.get(i++)); + assertEquals(includeFileEntry2, actual.get(i++)); + assertEquals(macroEntry1, actual.get(i++)); + assertEquals(macroEntry2, actual.get(i++)); + assertEquals(macroFileEntry1, actual.get(i++)); + assertEquals(macroFileEntry2, actual.get(i++)); + assertEquals(libraryPathEntry1, actual.get(i++)); + assertEquals(libraryPathEntry2, actual.get(i++)); + assertEquals(libraryFileEntry1, actual.get(i++)); + assertEquals(libraryFileEntry2, actual.get(i++)); + + assertEquals(unsortedEntries.size(), actual.size()); + } + + /** + */ + public void testSort_Entries() throws Exception { + // create sample entries + CIncludePathEntry includePathEntry1 = new CIncludePathEntry("path_B", 0); + CIncludePathEntry includePathEntry2 = new CIncludePathEntry("path_A", 0); + CMacroEntry macroEntry1 = new CMacroEntry("MACRO_A", null, 0); + CMacroEntry macroEntry2 = new CMacroEntry("MACRO_B", null, 0); + CIncludeFileEntry includeFileEntry1 = new CIncludeFileEntry("file_B", 0); + CIncludeFileEntry includeFileEntry2 = new CIncludeFileEntry("file_A", 0); + CMacroFileEntry macroFileEntry1 = new CMacroFileEntry("file_B", 0); + CMacroFileEntry macroFileEntry2 = new CMacroFileEntry("file_A", 0); + CLibraryPathEntry libraryPathEntry1 = new CLibraryPathEntry("lib_B", 0); + CLibraryPathEntry libraryPathEntry2 = new CLibraryPathEntry("lib_A", 0); + CLibraryFileEntry libraryFileEntry1 = new CLibraryFileEntry("file_B", 0); + CLibraryFileEntry libraryFileEntry2 = new CLibraryFileEntry("file_A", 0); + + // place entries in unsorted list + List unsortedEntries = new ArrayList(); + // macros will be sorted by name + unsortedEntries.add(macroEntry2); + unsortedEntries.add(macroEntry1); + // paths are not sorted only grouped by kind + unsortedEntries.add(macroFileEntry1); + unsortedEntries.add(macroFileEntry2); + unsortedEntries.add(includePathEntry1); + unsortedEntries.add(includePathEntry2); + unsortedEntries.add(includeFileEntry1); + unsortedEntries.add(includeFileEntry2); + unsortedEntries.add(libraryFileEntry1); + unsortedEntries.add(libraryFileEntry2); + unsortedEntries.add(libraryPathEntry1); + unsortedEntries.add(libraryPathEntry2); + + // create a provider and set the entries + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + provider.setSettingEntries(null, null, null, unsortedEntries); + + // retrieve and check that language settings got sorted properly + int i=0; + List actual = provider.getSettingEntries(null, null, null); + assertEquals(includePathEntry1, actual.get(i++)); + assertEquals(includePathEntry2, actual.get(i++)); + assertEquals(includeFileEntry1, actual.get(i++)); + assertEquals(includeFileEntry2, actual.get(i++)); + assertEquals(macroEntry1, actual.get(i++)); + assertEquals(macroEntry2, actual.get(i++)); + assertEquals(macroFileEntry1, actual.get(i++)); + assertEquals(macroFileEntry2, actual.get(i++)); + assertEquals(libraryPathEntry1, actual.get(i++)); + assertEquals(libraryPathEntry2, actual.get(i++)); + assertEquals(libraryFileEntry1, actual.get(i++)); + assertEquals(libraryFileEntry2, actual.get(i++)); + + assertEquals(unsortedEntries.size(), actual.size()); + } + + /** + */ + public void testSort_Undef() throws Exception { + // create sample entries + CMacroEntry macroEntry1 = new CMacroEntry("MACRO_1", null, 0); + CMacroEntry macroEntry2A = new CMacroEntry("MACRO_2", null, ICSettingEntry.UNDEFINED); + CMacroEntry macroEntry2B = new CMacroEntry("MACRO_2", null, 0); + CMacroEntry macroEntry2C = new CMacroEntry("MACRO_2", null, ICSettingEntry.BUILTIN); + CMacroEntry macroEntry3 = new CMacroEntry("MACRO_3", null, 0); + + // place entries in unsorted list + List unsortedEntries = new ArrayList(); + // macros will be sorted by name and keep order for the same name + unsortedEntries.add(macroEntry2A); + unsortedEntries.add(macroEntry3); + unsortedEntries.add(macroEntry2B); + unsortedEntries.add(macroEntry1); + unsortedEntries.add(macroEntry2C); + + // create a provider and set the entries + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + provider.setSettingEntries(null, null, null, unsortedEntries); + + // retrieve and check that language settings got sorted properly + int i=0; + List actual = provider.getSettingEntries(null, null, null); + assertEquals(macroEntry1, actual.get(i++)); + assertEquals(macroEntry2A, actual.get(i++)); + assertEquals(macroEntry2B, actual.get(i++)); + assertEquals(macroEntry2C, actual.get(i++)); + assertEquals(macroEntry3, actual.get(i++)); + + assertEquals(unsortedEntries.size(), actual.size()); + } + } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java index b837908fe1f..730d92d56b9 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java @@ -60,6 +60,14 @@ public class LanguageSettingsManager { return LanguageSettingsExtensionManager.getSettingEntriesUpResourceTree(provider, cfgDescription, rc, languageId); } + /** + * TODO + */ + public static void buildResourceTree(LanguageSettingsSerializable provider, ICConfigurationDescription cfgDescription, String languageId, IProject project) { + LanguageSettingsExtensionManager.buildResourceTree(provider, cfgDescription, languageId, project); + } + + /** * Returns the list of setting entries of a certain kind (such as include paths) * for the given configuration description, resource and language. This is a diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java index ccd1770bcdd..3129996a925 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java @@ -51,7 +51,7 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { private static final String ELEM_FLAG = "flag"; //$NON-NLS-1$ - private static WeakHashSet> listLSEPool = new WeakHashSet>() { + private static WeakHashSet> lseListPool = new WeakHashSet>() { @Override public synchronized List add(List list) { return super.add(list); @@ -129,7 +129,7 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { langMap = new HashMap>(); fStorage.put(languageId, langMap); } - List sortedEntries = listLSEPool.add(Collections.unmodifiableList(sortEntries(entries))); + List sortedEntries = lseListPool.add(Collections.unmodifiableList(sortEntries(entries))); langMap.put(rcProjectPath, sortedEntries); } else { // do not keep nulls in the tables diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java index d595114bea7..f45ca85be19 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java @@ -13,8 +13,10 @@ package org.eclipse.cdt.internal.core.language.settings.providers; import java.util.ArrayList; import java.util.Comparator; +import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.TreeSet; @@ -23,12 +25,16 @@ import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsBaseProvider; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable; +import org.eclipse.cdt.core.model.ILanguage; +import org.eclipse.cdt.core.model.LanguageManager; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider; import org.eclipse.cdt.core.settings.model.util.CDataUtil; import org.eclipse.cdt.core.settings.model.util.LanguageSettingEntriesSerializer; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IWorkspaceRoot; @@ -41,6 +47,7 @@ import org.eclipse.core.runtime.IExtensionRegistry; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.content.IContentType; /** * Class {@code LanguageSettingsExtensionManager} manages {@link ILanguageSettingsProvider} extensions @@ -385,6 +392,99 @@ public class LanguageSettingsExtensionManager { return new ArrayList(0); } + /** + * TODO + */ + public static void buildResourceTree(LanguageSettingsSerializable provider, ICConfigurationDescription cfgDescription, String languageId, IContainer folder) { + IResource[] members = null; + try { + members = folder.members(); + } catch (Exception e) { + CCorePlugin.log(e); + } + if (members==null) + return; + + for (IResource rc : members) { + if (rc instanceof IContainer) { + buildResourceTree(provider, cfgDescription, languageId, (IContainer) rc); + } + } + + int rcNumber = members.length; + + Map, Integer> listMap = new HashMap, Integer>(); + + // on the first pass find majority entries + List majorityEntries = null; + List candidate = null; + int candidateCount = 0; + for (IResource rc : members) { + if (rc instanceof IFile) { + IContentType contentType = Platform.getContentTypeManager().findContentTypeFor(rc.getName()); + if (contentType==null) { + rcNumber--; + if (candidateCount > rcNumber/2) { + majorityEntries = candidate; + break; + } + continue; + } + + ILanguage lang = LanguageManager.getInstance().getLanguage(contentType); + List languageScope = provider.getLanguageScope(); + if (lang==null || (languageScope!=null && !languageScope.contains(lang.getId()))) { + rcNumber--; + if (candidateCount > rcNumber/2) { + majorityEntries = candidate; + break; + } + continue; + } + } + + List entries = provider.getSettingEntries(null, rc, languageId); + if (entries==null && rc instanceof IContainer) { + rcNumber--; + if (candidateCount > rcNumber/2) { + majorityEntries = candidate; + break; + } + continue; + } + + Integer count = listMap.get(entries); + if (count==null) { + count = 0; + } + count++; + if (count > rcNumber/2) { + majorityEntries = entries; + break; + } + if (count>candidateCount) { + candidateCount = count; + candidate = entries; + } + + listMap.put(entries, count); + + } + + if (majorityEntries!=null) { + provider.setSettingEntries(cfgDescription, folder, languageId, majorityEntries); + } + + for (IResource rc : members) { + List entries = provider.getSettingEntries(null, rc, languageId); + if (entries!=null && entries==majorityEntries) { + if (!(rc instanceof IFile)) { // preserve information which files were collected + provider.setSettingEntries(cfgDescription, rc, languageId, null); + } + } + } + } + private static boolean checkBit(int flags, int bit) { return (flags & bit) == bit; } From f8a545a2fb9815a2d5f0b1a5df6f9c7ae31426e9 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Tue, 2 Aug 2011 17:02:37 -0400 Subject: [PATCH 009/120] resource tree to present nice looking hierarchical view to the user --- .../providers/LanguageSettingsManager.java | 7 +- .../LanguageSettingsExtensionManager.java | 84 +++++++++---------- 2 files changed, 48 insertions(+), 43 deletions(-) diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java index 730d92d56b9..3007beeb376 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java @@ -61,7 +61,12 @@ public class LanguageSettingsManager { } /** - * TODO + * Builds for the provider a nice looking resource tree to present hierarchical view to the user. + * + * @param provider - language settings provider to build the tree for. + * @param cfgDescription - configuration description. + * @param languageId - language ID. + * @param project - the project which is considered the root of the resource tree. */ public static void buildResourceTree(LanguageSettingsSerializable provider, ICConfigurationDescription cfgDescription, String languageId, IProject project) { LanguageSettingsExtensionManager.buildResourceTree(provider, cfgDescription, languageId, project); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java index f45ca85be19..cdd38dc38d4 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java @@ -393,7 +393,14 @@ public class LanguageSettingsExtensionManager { } /** - * TODO + * Builds for the provider a nice looking resource tree to present hierarchical view to the user. + * Note that it is not advisable to "compact" the tree because of potential loss of information + * which is especially important during partial or incremental builds. + * + * @param provider - language settings provider to build the tree for. + * @param cfgDescription - configuration description. + * @param languageId - language ID. + * @param folder - container where the tree roots. */ public static void buildResourceTree(LanguageSettingsSerializable provider, ICConfigurationDescription cfgDescription, String languageId, IContainer folder) { IResource[] members = null; @@ -420,61 +427,39 @@ public class LanguageSettingsExtensionManager { List candidate = null; int candidateCount = 0; for (IResource rc : members) { - if (rc instanceof IFile) { - IContentType contentType = Platform.getContentTypeManager().findContentTypeFor(rc.getName()); - if (contentType==null) { + if (!isLanguageInScope(rc, cfgDescription, languageId)) { + rcNumber--; + } else { + List entries = provider.getSettingEntries(null, rc, languageId); + if (entries==null && rc instanceof IContainer) { rcNumber--; - if (candidateCount > rcNumber/2) { - majorityEntries = candidate; - break; + } else { + Integer count = listMap.get(entries); + if (count==null) { + count = 0; } - continue; - } - - ILanguage lang = LanguageManager.getInstance().getLanguage(contentType); - List languageScope = provider.getLanguageScope(); - if (lang==null || (languageScope!=null && !languageScope.contains(lang.getId()))) { - rcNumber--; - if (candidateCount > rcNumber/2) { - majorityEntries = candidate; - break; + count++; + + if (count>candidateCount) { + candidateCount = count; + candidate = entries; } - continue; + + listMap.put(entries, count); } } - List entries = provider.getSettingEntries(null, rc, languageId); - if (entries==null && rc instanceof IContainer) { - rcNumber--; - if (candidateCount > rcNumber/2) { - majorityEntries = candidate; - break; - } - continue; - } - - Integer count = listMap.get(entries); - if (count==null) { - count = 0; - } - count++; - if (count > rcNumber/2) { - majorityEntries = entries; + if (candidateCount > rcNumber/2) { + majorityEntries = candidate; break; } - if (count>candidateCount) { - candidateCount = count; - candidate = entries; - } - - listMap.put(entries, count); - } if (majorityEntries!=null) { provider.setSettingEntries(cfgDescription, folder, languageId, majorityEntries); } + // second pass - assign the entries to the folders for (IResource rc : members) { List entries = provider.getSettingEntries(null, rc, languageId); if (entries!=null && entries==majorityEntries) { @@ -484,6 +469,21 @@ public class LanguageSettingsExtensionManager { } } } + + private static boolean isLanguageInScope(IResource rc, ICConfigurationDescription cfgDescription, String languageId) { + if (rc instanceof IFile) { + ILanguage lang = null; + try { + lang = LanguageManager.getInstance().getLanguageForFile((IFile) rc, cfgDescription); + } catch (CoreException e) { + CCorePlugin.log("Error loading language settings providers extensions", e); //$NON-NLS-1$ + } + if (lang==null || (languageId!=null && languageId.equals(lang.getId()))) { + return false; + } + } + return true; + } private static boolean checkBit(int flags, int bit) { return (flags & bit) == bit; From 80e4cd9fc65b3b72e6f9f38418dfc5104ec15250 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Wed, 3 Aug 2011 23:34:46 -0400 Subject: [PATCH 010/120] Test cases added --- .../GCCBuildCommandParserTest.java | 36 ++++++++++++++++- .../tests/GCCBuiltinSpecsDetectorTest.java | 6 ++- .../LanguageSettingsManagerTests.java | 40 ++++++++++++++++--- .../LanguageSettingsExtensionManager.java | 3 +- 4 files changed, 74 insertions(+), 11 deletions(-) diff --git a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java index 8d4feecca84..648577bcf3e 100644 --- a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java +++ b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java @@ -21,6 +21,7 @@ import java.util.Set; import junit.framework.TestCase; import org.eclipse.cdt.core.ErrorParserManager; +import org.eclipse.cdt.core.dom.ast.gnu.cpp.GPPLanguage; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.settings.model.CIncludeFileEntry; @@ -59,7 +60,7 @@ public class GCCBuildCommandParserTest extends TestCase { private static final String GCC_BUILD_COMMAND_PARSER_EXT = "org.eclipse.cdt.make.core.build.command.parser.gcc"; //$NON-NLS-1$ private static final String ELEM_TEST = "test"; - private static final String LANG_CPP = "org.eclipse.cdt.core.g++"; + private static final String LANG_CPP = GPPLanguage.ID; // those attributes must match that in AbstractBuiltinSpecsDetector private static final String ATTR_EXPAND_RELATIVE_PATHS = "expand-relative-paths"; //$NON-NLS-1$ @@ -1872,4 +1873,37 @@ public class GCCBuildCommandParserTest extends TestCase { } } + /** + */ + public void testBuildResourceTree() throws Exception { + // create resources + IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName()); + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + IFolder folder = ResourceHelper.createFolder(project, "Folder"); + IFile file = ResourceHelper.createFile(project, "Folder/file.cpp"); + + // create GCCBuildCommandParser + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + ErrorParserManager epm = new ErrorParserManager(project, null); + + // parse line + parser.startup(cfgDescription); + parser.processLine("gcc " + + " -DMACRO" + + " Folder/file.cpp", + epm); + parser.shutdown(); + + // check that entries go to highest possible level + CMacroEntry entry = new CMacroEntry("MACRO", null, 0); + List entries = new ArrayList(); + entries.add(entry); + + assertEquals(entries, LanguageSettingsManager.getSettingEntriesUpResourceTree(parser, cfgDescription, file, LANG_CPP)); + assertEquals(entries, LanguageSettingsManager.getSettingEntriesUpResourceTree(parser, cfgDescription, folder, LANG_CPP)); + assertEquals(entries, LanguageSettingsManager.getSettingEntriesUpResourceTree(parser, cfgDescription, project, LANG_CPP)); + } + + } diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/GCCBuiltinSpecsDetectorTest.java b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/GCCBuiltinSpecsDetectorTest.java index 965122671ba..6281f189c44 100644 --- a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/GCCBuiltinSpecsDetectorTest.java +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/GCCBuiltinSpecsDetectorTest.java @@ -17,6 +17,8 @@ import java.util.List; import junit.framework.TestCase; +import org.eclipse.cdt.core.dom.ast.gnu.c.GCCLanguage; +import org.eclipse.cdt.core.dom.ast.gnu.cpp.GPPLanguage; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.settings.model.CIncludeFileEntry; import org.eclipse.cdt.core.settings.model.CIncludePathEntry; @@ -46,8 +48,8 @@ public class GCCBuiltinSpecsDetectorTest extends TestCase { private static final String PROVIDER_ID = "provider.id"; private static final String PROVIDER_NAME = "provider name"; private static final String LANGUAGE_ID = "language.test.id"; - private static final String LANGUAGE_ID_C = "org.eclipse.cdt.core.gcc"; - private static final String LANGUAGE_ID_CPP = "org.eclipse.cdt.core.g++"; + private static final String LANGUAGE_ID_C = GCCLanguage.ID; + private static final String LANGUAGE_ID_CPP = GPPLanguage.ID; private static final String CUSTOM_PARAMETER = "customParameter"; private static final String ELEM_TEST = "test"; diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java index 2c4cce01795..ebff84f3c76 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java @@ -18,6 +18,7 @@ import junit.framework.TestCase; import junit.framework.TestSuite; import org.eclipse.cdt.core.AbstractExecutableExtensionBase; +import org.eclipse.cdt.core.dom.ast.gnu.cpp.GPPLanguage; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.settings.model.CIncludePathEntry; import org.eclipse.cdt.core.settings.model.CMacroEntry; @@ -48,6 +49,7 @@ public class LanguageSettingsManagerTests extends TestCase { private static final IFile FILE_0 = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("/project/path0")); private static final String CFG_ID = "test.configuration.id"; private static final String LANG_ID = "test.lang.id"; + private static final String LANG_CPP = GPPLanguage.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"; @@ -230,6 +232,7 @@ public class LanguageSettingsManagerTests extends TestCase { // use careless provider causing an exception { ILanguageSettingsProvider providerNPE = new MockProvider(PROVIDER_1, PROVIDER_NAME_1, null) { + @Override public List getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) { throw new NullPointerException("Can you handle me?"); } @@ -820,7 +823,7 @@ public class LanguageSettingsManagerTests extends TestCase { LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); provider.setSettingEntries(null, file, null, entries); // build the hierarchy - LanguageSettingsExtensionManager.buildResourceTree(provider, null, null, project); + LanguageSettingsManager.buildResourceTree(provider, null, null, project); // check that entries go to highest possible level assertEquals(entries, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file, null)); @@ -849,7 +852,7 @@ public class LanguageSettingsManagerTests extends TestCase { provider.setSettingEntries(null, file1, null, entries1); provider.setSettingEntries(null, file2, null, entries2); // build the hierarchy - LanguageSettingsExtensionManager.buildResourceTree(provider, null, null, project); + LanguageSettingsManager.buildResourceTree(provider, null, null, project); // check that entries go to highest possible level assertEquals(entries1, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file1, null)); @@ -863,7 +866,7 @@ public class LanguageSettingsManagerTests extends TestCase { /** */ - public void testBuildResourceTree_IncrementalBuildFlippingSettings() throws Exception { + public void testBuildResourceTree_FlippingSettings() throws Exception { // sample entries List entries1 = new ArrayList(); entries1.add(new CMacroEntry("MACRO_1", null, 0)); @@ -883,17 +886,17 @@ public class LanguageSettingsManagerTests extends TestCase { provider.setSettingEntries(null, file1, null, entries1); provider.setSettingEntries(null, file2, null, entries1); // build the hierarchy - LanguageSettingsExtensionManager.buildResourceTree(provider, null, null, project); + LanguageSettingsManager.buildResourceTree(provider, null, null, project); // double-check where the entries go assertEquals(entries1, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file1, null)); assertEquals(entries1, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file2, null)); assertEquals(entries1, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, project, null)); - // set the entries for the second+third files (with overlap) + // set the entries for the second+third files (second file flips the settings) provider.setSettingEntries(null, file2, null, entries2); provider.setSettingEntries(null, file3, null, entries2); // build the hierarchy - LanguageSettingsExtensionManager.buildResourceTree(provider, null, null, project); + LanguageSettingsManager.buildResourceTree(provider, null, null, project); // check where the entries go, it should not lose entries for the first file assertEquals(entries1, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file1, null)); assertEquals(entries2, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file2, null)); @@ -901,4 +904,29 @@ public class LanguageSettingsManagerTests extends TestCase { assertEquals(entries2, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, project, null)); } + /** + */ + public void testBuildResourceTree_WithLanguage() throws Exception { + // sample entries + CMacroEntry entry = new CMacroEntry("MACRO", null, 0); + List entries = new ArrayList(); + entries.add(entry); + + // create resources + IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName()); + IFolder folder = ResourceHelper.createFolder(project, "Folder"); + IFile file = ResourceHelper.createFile(project, "Folder/file.cpp"); + + // create a provider and set the entries + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + provider.setSettingEntries(null, file, LANG_CPP, entries); + // build the hierarchy + LanguageSettingsManager.buildResourceTree(provider, null, LANG_CPP, project); + + // check that entries go to highest possible level + assertEquals(entries, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file, LANG_CPP)); + assertEquals(entries, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, folder, LANG_CPP)); + assertEquals(entries, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, project, LANG_CPP)); + } + } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java index cdd38dc38d4..231a52a16e6 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java @@ -47,7 +47,6 @@ import org.eclipse.core.runtime.IExtensionRegistry; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.content.IContentType; /** * Class {@code LanguageSettingsExtensionManager} manages {@link ILanguageSettingsProvider} extensions @@ -478,7 +477,7 @@ public class LanguageSettingsExtensionManager { } catch (CoreException e) { CCorePlugin.log("Error loading language settings providers extensions", e); //$NON-NLS-1$ } - if (lang==null || (languageId!=null && languageId.equals(lang.getId()))) { + if (lang==null || (languageId!=null && !languageId.equals(lang.getId()))) { return false; } } From 53b2453e3f58012ab8c1eb584f8143a2c22c794d Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Thu, 4 Aug 2011 16:28:17 -0400 Subject: [PATCH 011/120] Trying a bit different wording for global workspace provider --- .../providers/LanguageSettingsProviderTab.java | 2 +- .../LanguageSettingsProvidersLabelProvider.java | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java index afcc404fad5..784fc9bfc8d 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java @@ -389,7 +389,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { if (!page.isForPrefs()) { if (globalProviderCheckBox==null) { globalProviderCheckBox = new Button(groupOptionsPage, SWT.CHECK); - globalProviderCheckBox.setText("Use global provider sharing settings among projects"); + globalProviderCheckBox.setText("Share setting entries between projects (global provider)"); globalProviderCheckBox.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProvidersLabelProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProvidersLabelProvider.java index 0a810a02498..45064253876 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProvidersLabelProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProvidersLabelProvider.java @@ -107,10 +107,15 @@ class LanguageSettingsProvidersLabelProvider extends LabelProvider { @Override public String getText(Object element) { if (element instanceof ILanguageSettingsProvider) { - String name = ((ILanguageSettingsProvider) element).getName(); - if (name!=null) + ILanguageSettingsProvider provider = (ILanguageSettingsProvider) element; + String name = provider.getName(); + if (name!=null) { + if (LanguageSettingsManager.isWorkspaceProvider(provider)) { + name = name + " [ Shared ]"; + } return name; - String id = ((ILanguageSettingsProvider) element).getId(); + } + String id = provider.getId(); return "[ Not accessible id="+id+" ]"; } return OOPS; From fef68e3d8a50289fbf61c90e6ad169fac9224e35 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Fri, 5 Aug 2011 00:55:40 -0400 Subject: [PATCH 012/120] Added checkbox for storing entries inside the project --- core/org.eclipse.cdt.ui/plugin.xml | 2 +- .../LanguageSettingsProviderTab.java | 22 ++++++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml index 5f3b51046b9..78dc63a0003 100644 --- a/core/org.eclipse.cdt.ui/plugin.xml +++ b/core/org.eclipse.cdt.ui/plugin.xml @@ -2870,7 +2870,7 @@ diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java index 784fc9bfc8d..750559b9e86 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java @@ -48,6 +48,7 @@ import org.eclipse.ui.dialogs.PreferencesUtil; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager_TBD; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable; import org.eclipse.cdt.core.model.ILanguageDescriptor; import org.eclipse.cdt.core.model.LanguageManager; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; @@ -59,7 +60,6 @@ import org.eclipse.cdt.core.settings.model.ICSettingBase; import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider; import org.eclipse.cdt.ui.CDTSharedImages; import org.eclipse.cdt.ui.CUIPlugin; -import org.eclipse.cdt.ui.dialogs.DialogsMessages; import org.eclipse.cdt.ui.dialogs.ICOptionPage; import org.eclipse.cdt.ui.newui.AbstractCPropertyTab; import org.eclipse.cdt.ui.newui.CDTPrefUtil; @@ -124,6 +124,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { private Button globalProviderCheckBox = null; private Link linkWorkspacePreferences = null; + private Button projectStorageCheckBox = null; private Page_LanguageSettingsProviders masterPropertyPage = null; @@ -315,10 +316,11 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { enableSashForm(sashFormConfigure, true); } - private Link createLinkToPreferences(final Composite parent) { + private Link createLinkToPreferences(final Composite parent, int span) { Link link = new Link(parent, SWT.NONE); -// // FIXME -// link.setText(DialogsMessages.RegexErrorParserOptionPage_LinkToPreferencesMessage + " Select Discovery Tab."); + GridData gd = new GridData(); + gd.horizontalSpan = span; + link.setLayoutData(gd); link.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { @@ -407,7 +409,10 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { }); - linkWorkspacePreferences = createLinkToPreferences(groupOptionsPage); + projectStorageCheckBox = new Button(groupOptionsPage, SWT.CHECK); + projectStorageCheckBox.setText("Store entries under project settings folder (supporting project miration)"); + + linkWorkspacePreferences = createLinkToPreferences(groupOptionsPage, 2); } } @@ -574,10 +579,15 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { globalProviderCheckBox.setEnabled(isChecked && isRawProviderEditable); globalProviderCheckBox.setVisible(provider!=null); + projectStorageCheckBox.setEnabled(!isGlobal); + projectStorageCheckBox.setVisible(rawProvider instanceof LanguageSettingsSerializable); + boolean needPreferencesLink=isGlobal && currentOptionsPage!=null; // TODO: message - linkWorkspacePreferences.setText(needPreferencesLink ? DialogsMessages.RegexErrorParserOptionPage_LinkToPreferencesMessage + " Select Discovery Tab." : ""); + final String linkMsg = needPreferencesLink ? "Options of global providers can be changed in Workspace Settings, Discovery Tab." : ""; + linkWorkspacePreferences.setText(linkMsg); linkWorkspacePreferences.pack(); + linkWorkspacePreferences.setEnabled(isChecked); } if (currentOptionsPage != null) { From 455dfb65413b00e5ba9bbc25617e4d79e627595d Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Sun, 7 Aug 2011 22:49:52 -0400 Subject: [PATCH 013/120] minor refactoring --- .../providers/LanguageSettingsPersistenceProjectTests.java | 3 ++- .../providers/LanguageSettingsProvidersSerializer.java | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java index ef7a1544b84..00f3d49cce4 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java @@ -37,6 +37,7 @@ import org.w3c.dom.Element; * Test cases testing LanguageSettingsProvider functionality */ public class LanguageSettingsPersistenceProjectTests extends TestCase { + private static final String LANGUAGE_SETTINGS_PROJECT_XML = ".settings/language.settings.xml"; // Should match id of extension point defined in plugin.xml private static final String EXTENSION_PROVIDER_ID = "org.eclipse.cdt.core.tests.language.settings.base.provider.subclass"; private static final String EXTENSION_PROVIDER_NAME = "Test Plugin Base Provider Subclass"; @@ -744,7 +745,7 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase { // write to project description coreModel.setProjectDescription(project, writableProjDescription); - IFile xmlStorageFile = project.getFile(".settings/language.settings.xml"); + IFile xmlStorageFile = project.getFile(LANGUAGE_SETTINGS_PROJECT_XML); assertTrue(xmlStorageFile.exists()); xmlStorageFileLocation = xmlStorageFile.getLocation().toOSString(); } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java index 6868b13c53d..4d813f769d8 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java @@ -157,14 +157,14 @@ public class LanguageSettingsProvidersSerializer { * @param store - name of the store * @return location of the store in the plug-in state area */ - private static URI getStoreLocation(String store) { + private static URI getStoreLocationInWorkspaceArea(String store) { IPath location = CCorePlugin.getDefault().getStateLocation().append(store); URI uri = URIUtil.toURI(location); return uri; } public static void serializeLanguageSettingsWorkspace() throws CoreException { - URI uriLocation = getStoreLocation(STORAGE_WORKSPACE_LANGUAGE_SETTINGS); + URI uriLocation = getStoreLocationInWorkspaceArea(STORAGE_WORKSPACE_LANGUAGE_SETTINGS); List serializableExtensionProviders = new ArrayList(); for (ILanguageSettingsProvider provider : rawGlobalWorkspaceProviders.values()) { if (provider instanceof LanguageSettingsSerializable) { @@ -206,7 +206,7 @@ public class LanguageSettingsProvidersSerializer { public static void loadLanguageSettingsWorkspace() throws CoreException { List providers = null; - URI uriLocation = getStoreLocation(STORAGE_WORKSPACE_LANGUAGE_SETTINGS); + URI uriLocation = getStoreLocationInWorkspaceArea(STORAGE_WORKSPACE_LANGUAGE_SETTINGS); Document doc = null; try { From 3d7d7d44d680bd897a13a901c00cacdfe8d22040 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Sat, 6 Aug 2011 15:23:48 -0400 Subject: [PATCH 014/120] Store entries in project settings folder, provider flag and UI --- .../LanguageSettingsSerializableTests.java | 47 ++++++++++++++++++- .../LanguageSettingsSerializable.java | 41 ++++++++++++++-- .../LanguageSettingsProviderTab.java | 31 ++++++++++-- 3 files changed, 110 insertions(+), 9 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java index b65fb14b78b..12c6bb9281f 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java @@ -61,7 +61,8 @@ public class LanguageSettingsSerializableTests extends TestCase { 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 CUSTOM_PARAMETER = "custom.parameter"; - + private static final String ATTR_STORE_ENTRIES = "store-entries"; + private static final String VALUE_PROJECT = "project"; private static final String ELEM_TEST = "test"; /** @@ -119,6 +120,11 @@ public class LanguageSettingsSerializableTests extends TestCase { assertEquals(PROVIDER_NAME_2, mockProvider.getName()); mockProvider.setCustomParameter(CUSTOM_PARAMETER); assertEquals(CUSTOM_PARAMETER, mockProvider.getCustomParameter()); + + assertEquals(false, mockProvider.isEntriesStorageWithProject()); + mockProvider.setEntriesStorageWithProject(true); + assertEquals(true, mockProvider.isEntriesStorageWithProject()); + mockProvider.setLanguageScope(languages); assertEquals(languages, mockProvider.getLanguageScope()); mockProvider.setLanguageScope(null); @@ -195,6 +201,31 @@ public class LanguageSettingsSerializableTests extends TestCase { } } + /** + */ + public void testStoreEntriesWithProject() throws Exception { + Element elementProvider; + { + // create provider with custom parameter + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + assertEquals(false, provider.isEntriesStorageWithProject()); + provider.setEntriesStorageWithProject(true); + assertEquals(true, provider.isEntriesStorageWithProject()); + + Document doc = XmlUtil.newDocument(); + Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST); + elementProvider = provider.serialize(rootElement); + String xmlString = XmlUtil.toString(doc); + assertTrue(xmlString.contains(ATTR_STORE_ENTRIES)); + assertTrue(xmlString.contains(VALUE_PROJECT)); + } + { + // re-load and check custom parameter of the newly loaded provider + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(elementProvider); + assertEquals(true, provider.isEntriesStorageWithProject()); + } + } + /** */ public void testLanguages() throws Exception { @@ -1012,6 +1043,8 @@ public class LanguageSettingsSerializableTests extends TestCase { LanguageSettingsSerializable provider1 = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); provider1.setLanguageScope(sampleLanguages); provider1.setCustomParameter(CUSTOM_PARAMETER); + assertEquals(false, provider1.isEntriesStorageWithProject()); + provider1.setEntriesStorageWithProject(true); provider1.setSettingEntries(MOCK_CFG, MOCK_RC, LANG_ID, sampleEntries_1); provider1.setSettingEntries(null, null, LANG_ID, sampleEntries_2); @@ -1034,6 +1067,12 @@ public class LanguageSettingsSerializableTests extends TestCase { assertFalse(provider1.hashCode()==provider2.hashCode()); provider2.setCustomParameter(CUSTOM_PARAMETER); + assertFalse(provider1.equals(provider2)); + assertFalse(provider1.hashCode()==provider2.hashCode()); + + provider2.setEntriesStorageWithProject(true); + + // All set now, so they should be equal assertTrue(provider1.equals(provider2)); assertTrue(provider1.hashCode()==provider2.hashCode()); @@ -1081,6 +1120,8 @@ public class LanguageSettingsSerializableTests extends TestCase { LanguageSettingsSerializableMock provider1 = new LanguageSettingsSerializableMock(PROVIDER_1, PROVIDER_NAME_1); provider1.setLanguageScope(sampleLanguages); provider1.setCustomParameter(CUSTOM_PARAMETER); + assertEquals(false, provider1.isEntriesStorageWithProject()); + provider1.setEntriesStorageWithProject(true); provider1.setSettingEntries(MOCK_CFG, MOCK_RC, LANG_ID, sampleEntries_1); provider1.setSettingEntries(null, null, LANG_ID, sampleEntries_2); @@ -1090,6 +1131,7 @@ public class LanguageSettingsSerializableTests extends TestCase { assertTrue(provider1.equals(providerClone)); assertTrue(provider1.getClass()==providerClone.getClass()); assertEquals(provider1.getCustomParameter(), providerClone.getCustomParameter()); + assertEquals(provider1.isEntriesStorageWithProject(), providerClone.isEntriesStorageWithProject()); assertEquals(provider1.getLanguageScope().get(0), providerClone.getLanguageScope().get(0)); List actual1 = providerClone.getSettingEntries(MOCK_CFG, MOCK_RC, LANG_ID); @@ -1126,6 +1168,8 @@ public class LanguageSettingsSerializableTests extends TestCase { LanguageSettingsSerializableMock provider1 = new LanguageSettingsSerializableMock(PROVIDER_1, PROVIDER_NAME_1); provider1.setLanguageScope(sampleLanguages); provider1.setCustomParameter(CUSTOM_PARAMETER); + assertEquals(false, provider1.isEntriesStorageWithProject()); + provider1.setEntriesStorageWithProject(true); List entries = new ArrayList(); entries.add(new CIncludePathEntry("path", 1)); @@ -1137,6 +1181,7 @@ public class LanguageSettingsSerializableTests extends TestCase { assertFalse(provider1.equals(providerClone)); assertTrue(provider1.getClass()==providerClone.getClass()); assertEquals(provider1.getCustomParameter(), providerClone.getCustomParameter()); + assertEquals(provider1.isEntriesStorageWithProject(), providerClone.isEntriesStorageWithProject()); assertEquals(provider1.getLanguageScope().get(0), providerClone.getLanguageScope().get(0)); List actual = providerClone.getSettingEntries(null, null, null); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java index 3129996a925..0d0f8aef5ee 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Andrew Gvozdev (Quoin Inc.) and others. + * Copyright (c) 2009, 2011 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 (Quoin Inc.) - initial API and implementation + * Andrew Gvozdev - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.core.language.settings.providers; @@ -45,12 +45,15 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { private static final String ELEM_ENTRY = "entry"; //$NON-NLS-1$ private static final String ATTR_KIND = "kind"; //$NON-NLS-1$ private static final String ATTR_NAME = "name"; //$NON-NLS-1$ + private static final String ATTR_VALUE = "value"; //$NON-NLS-1$ private static final String ATTR_CLASS = "class"; //$NON-NLS-1$ private static final String ATTR_PARAMETER = "parameter"; //$NON-NLS-1$ - private static final String ATTR_VALUE = "value"; //$NON-NLS-1$ - private static final String ELEM_FLAG = "flag"; //$NON-NLS-1$ + private static final String ATTR_STORE_ENTRIES = "store-entries"; //$NON-NLS-1$ + private static final String VALUE_WORKSPACE = "workspace"; //$NON-NLS-1$ + private static final String VALUE_PROJECT = "project"; //$NON-NLS-1$ + private static WeakHashSet> lseListPool = new WeakHashSet>() { @Override public synchronized List add(List list) { @@ -59,6 +62,7 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { }; + private boolean isEntriesStorageWithProject = false; private Map entries) { if (entries!=null) { Map> langMap = fStorage.get(languageId); @@ -217,6 +240,7 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { ATTR_NAME, getName(), ATTR_CLASS, getClass().getCanonicalName(), ATTR_PARAMETER, getCustomParameter(), + ATTR_STORE_ENTRIES, isEntriesStorageWithProject() ? VALUE_PROJECT : VALUE_WORKSPACE, }); if (languageScope!=null) { @@ -309,9 +333,12 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { String providerId = XmlUtil.determineAttributeValue(providerNode, ATTR_ID); String providerName = XmlUtil.determineAttributeValue(providerNode, ATTR_NAME); String providerParameter = XmlUtil.determineAttributeValue(providerNode, ATTR_PARAMETER); + String providerStoreEntries = XmlUtil.determineAttributeValue(providerNode, ATTR_STORE_ENTRIES); + this.setId(providerId); this.setName(providerName); this.setCustomParameter(providerParameter); + this.setEntriesStorageWithProject(VALUE_PROJECT.equals(providerStoreEntries)); List settings = new ArrayList(); NodeList nodes = providerNode.getChildNodes(); @@ -456,6 +483,7 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { result = prime * result + ((getName() == null) ? 0 : getName().hashCode()); result = prime * result + ((languageScope == null) ? 0 : languageScope.hashCode()); result = prime * result + ((customParameter == null) ? 0 : customParameter.hashCode()); + result = prime * result + (isEntriesStorageWithProject ? 0 : 1); result = prime * result + ((fStorage == null) ? 0 : fStorage.hashCode()); result = prime * result + getClass().hashCode(); return result; @@ -503,6 +531,9 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { return false; } else if (!customParameter.equals(other.customParameter)) return false; + + if (isEntriesStorageWithProject!=other.isEntriesStorageWithProject) + return false; if (fStorage == null) { if (other.fStorage != null) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java index 750559b9e86..10e1cf6a374 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java @@ -206,6 +206,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { /** * Shortcut for getting the currently selected provider. + * Do not use if you need to change provider's settings, use {@link #getWorkingCopy(String)}. */ private ILanguageSettingsProvider getSelectedProvider() { ILanguageSettingsProvider provider = null; @@ -333,7 +334,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { } // Called from globalProviderCheckBox listener - private void toggleGlobalProvider(ILanguageSettingsProvider oldProvider, boolean toGlobal) { + private ILanguageSettingsProvider toggleGlobalProvider(ILanguageSettingsProvider oldProvider, boolean toGlobal) { ILanguageSettingsProvider newProvider = null; String id = oldProvider.getId(); @@ -356,7 +357,11 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { ICConfigurationDescription cfgDescription = getConfigurationDescription(); initializeOptionsPage(newProvider, cfgDescription); displaySelectedOptionPage(); + } else { + newProvider = oldProvider; } + + return newProvider; } private void replaceSelectedProvider(ILanguageSettingsProvider newProvider) { @@ -398,8 +403,10 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { boolean isGlobal = globalProviderCheckBox.getSelection(); ILanguageSettingsProvider provider = getSelectedProvider(); if (isGlobal != LanguageSettingsManager.isWorkspaceProvider(provider)) { - toggleGlobalProvider(provider, isGlobal); + provider = toggleGlobalProvider(provider, isGlobal); } + projectStorageCheckBox.setSelection(provider instanceof LanguageSettingsSerializable + && ((LanguageSettingsSerializable) provider).isEntriesStorageWithProject()); } @Override @@ -410,7 +417,23 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { }); projectStorageCheckBox = new Button(groupOptionsPage, SWT.CHECK); - projectStorageCheckBox.setText("Store entries under project settings folder (supporting project miration)"); + projectStorageCheckBox.setText("Store entries in project settings folder (supporting project miration)"); + projectStorageCheckBox.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + boolean isWithProject = projectStorageCheckBox.getSelection(); + ILanguageSettingsProvider provider = getWorkingCopy(getSelectedProvider().getId()); + Assert.isTrue(provider instanceof LanguageSettingsSerializable); + ((LanguageSettingsSerializable)provider).setEntriesStorageWithProject(isWithProject); + refreshItem(provider); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + widgetSelected(e); + } + + }); linkWorkspacePreferences = createLinkToPreferences(groupOptionsPage, 2); } @@ -581,6 +604,8 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { projectStorageCheckBox.setEnabled(!isGlobal); projectStorageCheckBox.setVisible(rawProvider instanceof LanguageSettingsSerializable); + projectStorageCheckBox.setSelection(provider instanceof LanguageSettingsSerializable + && ((LanguageSettingsSerializable)provider).isEntriesStorageWithProject()); boolean needPreferencesLink=isGlobal && currentOptionsPage!=null; // TODO: message From da2ab70baca92981904d29a00e5dbf4467fbb31b Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Fri, 12 Aug 2011 20:14:08 -0400 Subject: [PATCH 015/120] Account for compiler path --- .../GCCBuildCommandParserTest.java | 18 ++++++++++++++++++ .../AbstractBuildCommandParser.java | 7 ++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java index 648577bcf3e..0804f98b93b 100644 --- a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java +++ b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java @@ -344,6 +344,9 @@ public class GCCBuildCommandParserTest extends TestCase { IFile file3=ResourceHelper.createFile(project, "file3.cpp"); IFile file4=ResourceHelper.createFile(project, "file4.cpp"); IFile file5=ResourceHelper.createFile(project, "file5.cpp"); + IFile file6=ResourceHelper.createFile(project, "file6.cpp"); + IFile file7=ResourceHelper.createFile(project, "file7.cpp"); + IFile file8=ResourceHelper.createFile(project, "file8.cpp"); ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file1.getProjectRelativePath(), true); String languageId = ls.getLanguageId(); @@ -357,6 +360,9 @@ public class GCCBuildCommandParserTest extends TestCase { parser.processLine("g++ -I/path0 file3.cpp"); parser.processLine("c++ -I/path0 file4.cpp"); parser.processLine("\"gcc\" -I/path0 file5.cpp"); + parser.processLine("/absolute/path/gcc -I/path0 file6.cpp"); + parser.processLine(" \"/absolute/path/gcc\" -I/path0 file7.cpp"); + parser.processLine("../relative/path/gcc -I/path0 file8.cpp"); parser.shutdown(); // check populated entries @@ -381,6 +387,18 @@ public class GCCBuildCommandParserTest extends TestCase { List entries = parser.getSettingEntries(cfgDescription, file5, languageId); assertEquals(new CIncludePathEntry(path0, 0), entries.get(0)); } + { + List entries = parser.getSettingEntries(cfgDescription, file6, languageId); + assertEquals(new CIncludePathEntry(path0, 0), entries.get(0)); + } + { + List entries = parser.getSettingEntries(cfgDescription, file7, languageId); + assertEquals(new CIncludePathEntry(path0, 0), entries.get(0)); + } + { + List entries = parser.getSettingEntries(cfgDescription, file8, languageId); + assertEquals(new CIncludePathEntry(path0, 0), entries.get(0)); + } } /** diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java index 508410b6e4c..1f0fb9ad089 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java @@ -26,6 +26,7 @@ import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; public abstract class AbstractBuildCommandParser extends AbstractLanguageSettingsOutputScanner implements ILanguageSettingsBuildOutputScanner { + private static final String LEADING_PATH_PATTERN = "\\S+[/\\\\]"; //$NON-NLS-1$ private static final Pattern OPTIONS_PATTERN = Pattern.compile("-[^\\s\"']*(\\s*((\".*?\")|('.*?')|([^-\\s][^\\s]+)))?"); //$NON-NLS-1$ private static final int OPTION_GROUP = 0; @@ -34,8 +35,8 @@ public abstract class AbstractBuildCommandParser extends AbstractLanguageSetting */ @SuppressWarnings("nls") private static final String[] PATTERN_TEMPLATES = { - "\\s*\"?${COMPILER_PATTERN}\"?.*\\s" + "()([^'\"\\s]*\\.${EXTENSIONS_PATTERN})(\\s.*)?[\r\n]*", // compiling unquoted file - "\\s*\"?${COMPILER_PATTERN}\"?.*\\s" + "(['\"])(.*\\.${EXTENSIONS_PATTERN})\\${COMPILER_GROUPS+1}(\\s.*)?[\r\n]*" // compiling quoted file + "${COMPILER_PATTERN}.*\\s" + "()([^'\"\\s]*\\.${EXTENSIONS_PATTERN})(\\s.*)?[\r\n]*", // compiling unquoted file + "${COMPILER_PATTERN}.*\\s" + "(['\"])(.*\\.${EXTENSIONS_PATTERN})\\${COMPILER_GROUPS+1}(\\s.*)?[\r\n]*" // compiling quoted file }; private static final int FILE_GROUP = 2; @@ -43,7 +44,7 @@ public abstract class AbstractBuildCommandParser extends AbstractLanguageSetting @SuppressWarnings("nls") private String getCompilerCommandPattern() { String parameter = getCustomParameter(); - return "(" + parameter + ")"; + return "\\s*\"?("+LEADING_PATH_PATTERN+")?(" + parameter + ")\"?"; } private int adjustFileGroup() { From 6088b4e98032a04534d3fedc7c20ae63b787c990 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Sat, 13 Aug 2011 08:28:19 -0400 Subject: [PATCH 016/120] More detailed API to allow for separate persistence of attributes and entries --- ...AbstractLanguageSettingsOutputScanner.java | 8 +- .../LanguageSettingsSerializable.java | 76 +++++++++++-------- 2 files changed, 50 insertions(+), 34 deletions(-) diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java index 3a19b8f093b..5c35b4dac98 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java @@ -807,15 +807,15 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett } @Override - public Element serialize(Element parentElement) { - Element elementProvider = super.serialize(parentElement); + public Element serializeAttributes(Element parentElement) { + Element elementProvider = super.serializeAttributes(parentElement); elementProvider.setAttribute(ATTR_EXPAND_RELATIVE_PATHS, Boolean.toString(isResolvingPaths)); return elementProvider; } @Override - public void load(Element providerNode) { - super.load(providerNode); + public void loadAttributes(Element providerNode) { + super.loadAttributes(providerNode); String expandRelativePathsValue = XmlUtil.determineAttributeValue(providerNode, ATTR_EXPAND_RELATIVE_PATHS); if (expandRelativePathsValue!=null) diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java index 0d0f8aef5ee..abf370119f9 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java @@ -235,6 +235,12 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { */ // provider/configuration/language/resource/entry public Element serialize(Element parentElement) { + Element elementProvider = serializeAttributes(parentElement); + serializeEntries(elementProvider); + return elementProvider; + } + + public Element serializeAttributes(Element parentElement) { Element elementProvider = XmlUtil.appendElement(parentElement, ELEM_PROVIDER, new String[] { ATTR_ID, getId(), ATTR_NAME, getName(), @@ -248,10 +254,13 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { XmlUtil.appendElement(elementProvider, ELEM_LANGUAGE_SCOPE, new String[] {ATTR_ID, langId}); } } + return elementProvider; + } + + public void serializeEntries(Element elementProvider) { for (Entry>> entryLang : fStorage.entrySet()) { serializeLanguage(elementProvider, entryLang); } - return elementProvider; } private void serializeLanguage(Element parentElement, Entry>> entryLang) { @@ -330,40 +339,47 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { languageScope = null; if (providerNode!=null) { - String providerId = XmlUtil.determineAttributeValue(providerNode, ATTR_ID); - String providerName = XmlUtil.determineAttributeValue(providerNode, ATTR_NAME); - String providerParameter = XmlUtil.determineAttributeValue(providerNode, ATTR_PARAMETER); - String providerStoreEntries = XmlUtil.determineAttributeValue(providerNode, ATTR_STORE_ENTRIES); + loadAttributes(providerNode); + loadEntries(providerNode); + } + } - this.setId(providerId); - this.setName(providerName); - this.setCustomParameter(providerParameter); - this.setEntriesStorageWithProject(VALUE_PROJECT.equals(providerStoreEntries)); + public void loadAttributes(Element providerNode) { + String providerId = XmlUtil.determineAttributeValue(providerNode, ATTR_ID); + String providerName = XmlUtil.determineAttributeValue(providerNode, ATTR_NAME); + String providerParameter = XmlUtil.determineAttributeValue(providerNode, ATTR_PARAMETER); + String providerStoreEntries = XmlUtil.determineAttributeValue(providerNode, ATTR_STORE_ENTRIES); - List settings = new ArrayList(); - NodeList nodes = providerNode.getChildNodes(); - for (int i=0;i settings = new ArrayList(); + NodeList nodes = providerNode.getChildNodes(); + for (int i=0;i0) { - setSettingEntriesInternal(null, null, settings); - } + } + // set settings + if (settings.size()>0) { + setSettingEntriesInternal(null, null, settings); } } From 36c081996e188b801c3ecc948844088c4a2693dd Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Mon, 15 Aug 2011 12:21:47 -0400 Subject: [PATCH 017/120] Serialization of LSE entries in workspace area --- ...nguageSettingsPersistenceProjectTests.java | 289 ++++++++++++++-- .../LanguageSettingsSerializableTests.java | 318 ++++++++++++------ .../LanguageSettingsSerializable.java | 253 ++++++++++---- .../LanguageSettingsProvidersSerializer.java | 266 +++++++++++---- .../LanguageSettingsProviderTab.java | 136 ++++---- 5 files changed, 941 insertions(+), 321 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java index 00f3d49cce4..103ebbb4c45 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 Andrew Gvozdev and others. + * Copyright (c) 2009, 2011 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 @@ -17,6 +17,7 @@ import java.util.List; import junit.framework.TestCase; import junit.framework.TestSuite; +import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.settings.model.CIncludePathEntry; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; @@ -30,6 +31,7 @@ import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSetting import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IPath; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -38,6 +40,7 @@ import org.w3c.dom.Element; */ public class LanguageSettingsPersistenceProjectTests extends TestCase { private static final String LANGUAGE_SETTINGS_PROJECT_XML = ".settings/language.settings.xml"; + private static final String LANGUAGE_SETTINGS_WORKSPACE_XML = "language.settings.xml"; // Should match id of extension point defined in plugin.xml private static final String EXTENSION_PROVIDER_ID = "org.eclipse.cdt.core.tests.language.settings.base.provider.subclass"; private static final String EXTENSION_PROVIDER_NAME = "Test Plugin Base Provider Subclass"; @@ -162,6 +165,16 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase { return cfgDescription; } + /** + */ + public void testNoProviders() throws Exception { + // serialize language settings of user defined providers (on workspace level) + LanguageSettingsProvidersSerializer.serializeLanguageSettingsWorkspace(); + LanguageSettingsProvidersSerializer.loadLanguageSettingsWorkspace(); + + // test passes if no exception was thrown + } + /** */ public void testWorkspacePersistence_ModifiedExtensionProvider() throws Exception { @@ -174,7 +187,7 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase { LanguageSettingsSerializable extProvider = (LanguageSettingsSerializable) LanguageSettingsManager.getRawProvider(provider); assertNotNull(extProvider); assertEquals(EXTENSION_SERIALIZABLE_PROVIDER_ID, extProvider.getId()); - + // add entries extProvider.setSettingEntries(null, null, null, entries); List actual = extProvider.getSettingEntries(null, null, null); @@ -183,7 +196,7 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase { // serialize language settings of workspace providers LanguageSettingsProvidersSerializer.serializeLanguageSettingsWorkspace(); - + // clear the provider extProvider.setSettingEntries(null, null, null, null); } @@ -234,7 +247,7 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase { assertEquals(CUSTOM_PARAMETER, rawProvider.getCustomParameter()); } } - + /** */ public void testWorkspacePersistence_ShadowedExtensionProvider() throws Exception { @@ -263,18 +276,18 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase { assertEquals(EXTENSION_PROVIDER_ID, rawProvider.getId()); assertEquals(PROVIDER_NAME_0, rawProvider.getName()); } - + { // re-load to check serialization LanguageSettingsProvidersSerializer.loadLanguageSettingsWorkspace(); - + ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_PROVIDER_ID); ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); assertTrue(rawProvider instanceof MockLanguageSettingsSerializableProvider); assertEquals(EXTENSION_PROVIDER_ID, rawProvider.getId()); assertEquals(PROVIDER_NAME_0, rawProvider.getName()); } - + { // reset workspace providers, that will also serialize LanguageSettingsManager.setWorkspaceProviders(null); @@ -290,7 +303,7 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase { { // re-load to check serialization LanguageSettingsProvidersSerializer.loadLanguageSettingsWorkspace(); - + ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_PROVIDER_ID); ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); assertTrue(rawProvider instanceof LanguageSettingsBaseProvider); @@ -298,7 +311,7 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase { assertEquals(EXTENSION_PROVIDER_NAME, rawProvider.getName()); } } - + /** */ public void testProjectPersistence_SerializableProviderDOM() throws Exception { @@ -317,6 +330,7 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase { LanguageSettingsSerializable serializableProvider = new LanguageSettingsSerializable(PROVIDER_0, PROVIDER_NAME_0); serializableProvider.setSettingEntries(null, null, null, entries); + serializableProvider.setStoringEntriesInProjectArea(true); ArrayList providers = new ArrayList(); providers.add(serializableProvider); @@ -326,12 +340,12 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase { Document doc = XmlUtil.newDocument(); rootElement = XmlUtil.appendElement(doc, ELEM_TEST); // serialize language settings to the DOM - LanguageSettingsProvidersSerializer.serializeLanguageSettings(rootElement, mockPrjDescription); + LanguageSettingsProvidersSerializer.serializeLanguageSettingsInternal(rootElement, null, mockPrjDescription); } { // re-load and check language settings of the newly loaded provider MockProjectDescription mockPrjDescription = new MockProjectDescription(new MockConfigurationDescription(CFG_ID)); - LanguageSettingsProvidersSerializer.loadLanguageSettings(rootElement, mockPrjDescription); + LanguageSettingsProvidersSerializer.loadLanguageSettingsInternal(rootElement, null, mockPrjDescription); ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations(); assertNotNull(cfgDescriptions); @@ -378,6 +392,7 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase { assertNotNull(cfgDescription1); assertEquals(CFG_ID, cfgDescription1.getId()); LanguageSettingsSerializable provider1 = new LanguageSettingsSerializable(PROVIDER_0, PROVIDER_NAME_0); + provider1.setStoringEntriesInProjectArea(true); provider1.setSettingEntries(null, null, null, entries); ArrayList providers = new ArrayList(); providers.add(provider1); @@ -389,6 +404,7 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase { assertNotNull(cfgDescription2); assertEquals(CFG_ID_2, cfgDescription2.getId()); LanguageSettingsSerializable provider2 = new LanguageSettingsSerializable(PROVIDER_0, PROVIDER_NAME_0); + provider2.setStoringEntriesInProjectArea(true); provider2.setSettingEntries(null, null, null, entries2); ArrayList providers = new ArrayList(); providers.add(provider2); @@ -433,7 +449,7 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase { Document doc = XmlUtil.newDocument(); rootElement = XmlUtil.appendElement(doc, ELEM_TEST); // serialize language settings to the DOM - LanguageSettingsProvidersSerializer.serializeLanguageSettings(rootElement, mockPrjDescription); + LanguageSettingsProvidersSerializer.serializeLanguageSettingsInternal(rootElement, null, mockPrjDescription); } { // re-create a project description and re-load language settings for each configuration @@ -443,7 +459,7 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase { new MockConfigurationDescription(CFG_ID_2), }); // load - LanguageSettingsProvidersSerializer.loadLanguageSettings(rootElement, mockPrjDescription); + LanguageSettingsProvidersSerializer.loadLanguageSettingsInternal(rootElement, null, mockPrjDescription); ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations(); assertNotNull(cfgDescriptions); @@ -495,6 +511,7 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase { LanguageSettingsSerializable serializableProvider = new MockLanguageSettingsSerializableProvider(PROVIDER_0, PROVIDER_NAME_0); serializableProvider.setSettingEntries(null, null, null, entries); + serializableProvider.setStoringEntriesInProjectArea(true); ArrayList providers = new ArrayList(); providers.add(serializableProvider); @@ -504,12 +521,12 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase { Document doc = XmlUtil.newDocument(); rootElement = XmlUtil.appendElement(doc, ELEM_TEST); // serialize language settings to the DOM - LanguageSettingsProvidersSerializer.serializeLanguageSettings(rootElement, mockPrjDescription); + LanguageSettingsProvidersSerializer.serializeLanguageSettingsInternal(rootElement, null, mockPrjDescription); } { // re-load and check language settings of the newly loaded provider MockProjectDescription mockPrjDescription = new MockProjectDescription(new MockConfigurationDescription(CFG_ID)); - LanguageSettingsProvidersSerializer.loadLanguageSettings(rootElement, mockPrjDescription); + LanguageSettingsProvidersSerializer.loadLanguageSettingsInternal(rootElement, null, mockPrjDescription); ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations(); assertNotNull(cfgDescriptions); @@ -553,12 +570,12 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase { Document doc = XmlUtil.newDocument(); rootElement = XmlUtil.appendElement(doc, ELEM_TEST); // serialize language settings to the DOM - LanguageSettingsProvidersSerializer.serializeLanguageSettings(rootElement, mockPrjDescription); + LanguageSettingsProvidersSerializer.serializeLanguageSettingsInternal(rootElement, null, mockPrjDescription); } { // re-load MockProjectDescription mockPrjDescription = new MockProjectDescription(new MockConfigurationDescription(CFG_ID)); - LanguageSettingsProvidersSerializer.loadLanguageSettings(rootElement, mockPrjDescription); + LanguageSettingsProvidersSerializer.loadLanguageSettingsInternal(rootElement, null, mockPrjDescription); ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations(); assertNotNull(cfgDescriptions); @@ -593,7 +610,8 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase { assertNotNull(cfgDescription); // populate with provider overriding the extension (must be SerializableLanguageSettingsProvider or a class from another extension) - ILanguageSettingsProvider providerOverride = new MockLanguageSettingsSerializableProvider(idExt, PROVIDER_NAME_0); + MockLanguageSettingsSerializableProvider providerOverride = new MockLanguageSettingsSerializableProvider(idExt, PROVIDER_NAME_0); + providerOverride.setStoringEntriesInProjectArea(true); List providers = new ArrayList(); providers.add(providerOverride); cfgDescription.setLanguageSettingProviders(providers); @@ -603,12 +621,12 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase { Document doc = XmlUtil.newDocument(); rootElement = XmlUtil.appendElement(doc, ELEM_TEST); // serialize language settings to the DOM - LanguageSettingsProvidersSerializer.serializeLanguageSettings(rootElement, mockPrjDescription); + LanguageSettingsProvidersSerializer.serializeLanguageSettingsInternal(rootElement, null, mockPrjDescription); } { // re-load MockProjectDescription mockPrjDescription = new MockProjectDescription(new MockConfigurationDescription(CFG_ID)); - LanguageSettingsProvidersSerializer.loadLanguageSettings(rootElement, mockPrjDescription); + LanguageSettingsProvidersSerializer.loadLanguageSettingsInternal(rootElement, null, mockPrjDescription); ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations(); assertNotNull(cfgDescriptions); @@ -658,9 +676,11 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase { // 3. Providers defined in a configuration // 3.1 LanguageSettingsSerializable mockProvider1 = new LanguageSettingsSerializable(PROVIDER_0, PROVIDER_NAME_0); + mockProvider1.setStoringEntriesInProjectArea(true); mockProvider1.setSettingEntries(null, null, null, entries_31); // 3.2 LanguageSettingsSerializable mockProvider2 = new MockLanguageSettingsSerializableProvider(PROVIDER_2, PROVIDER_NAME_2); + mockProvider2.setStoringEntriesInProjectArea(true); mockProvider2.setSettingEntries(null, null, null, entries_32); ArrayList providers = new ArrayList(); @@ -674,13 +694,13 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase { Document doc = XmlUtil.newDocument(); rootElement = XmlUtil.appendElement(doc, ELEM_TEST); // serialize language settings to the DOM - LanguageSettingsProvidersSerializer.serializeLanguageSettings(rootElement, mockPrjDescription); + LanguageSettingsProvidersSerializer.serializeLanguageSettingsInternal(rootElement, null, mockPrjDescription); XmlUtil.toString(doc); } { // re-load and check language settings of the newly loaded provider MockProjectDescription mockPrjDescription = new MockProjectDescription(new MockConfigurationDescription(CFG_ID)); - LanguageSettingsProvidersSerializer.loadLanguageSettings(rootElement, mockPrjDescription); + LanguageSettingsProvidersSerializer.loadLanguageSettingsInternal(rootElement, null, mockPrjDescription); ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations(); assertNotNull(cfgDescriptions); @@ -736,6 +756,7 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase { // create a provider LanguageSettingsSerializable mockProvider = new LanguageSettingsSerializable(PROVIDER_0, PROVIDER_NAME_0); + mockProvider.setStoringEntriesInProjectArea(true); mockProvider.setSettingEntries(cfgDescription, null, null, entries); List providers = new ArrayList(); providers.add(mockProvider); @@ -772,6 +793,12 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase { 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 @@ -836,5 +863,223 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase { } } + /** + */ + public void testProjectPersistence_SplitStorageDOM() throws Exception { + Element prjStorageElement = null; + Element wspStorageElement = null; + + List entries = new ArrayList(); + entries.add(new CIncludePathEntry("path0", 0)); + + { + // create a provider + MockProjectDescription mockPrjDescription = new MockProjectDescription(new MockConfigurationDescription(CFG_ID)); + + ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations(); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + assertNotNull(cfgDescription); + + LanguageSettingsSerializable serializableProvider = new LanguageSettingsSerializable(PROVIDER_0, PROVIDER_NAME_0); + serializableProvider.setSettingEntries(null, null, null, entries); + // do not store entries inside project + serializableProvider.setStoringEntriesInProjectArea(false); + + ArrayList providers = new ArrayList(); + providers.add(serializableProvider); + cfgDescription.setLanguageSettingProviders(providers); + + // prepare DOM storage + Document prjDoc = XmlUtil.newDocument(); + prjStorageElement = XmlUtil.appendElement(prjDoc, ELEM_TEST); + Document wspDoc = XmlUtil.newDocument(); + wspStorageElement = XmlUtil.appendElement(wspDoc, ELEM_TEST); + // serialize language settings to the DOM + LanguageSettingsProvidersSerializer.serializeLanguageSettingsInternal(prjStorageElement, wspStorageElement, mockPrjDescription); + } + { + // re-load and check language settings of the newly loaded provider + MockProjectDescription mockPrjDescription = new MockProjectDescription(new MockConfigurationDescription(CFG_ID)); + LanguageSettingsProvidersSerializer.loadLanguageSettingsInternal(prjStorageElement, wspStorageElement, mockPrjDescription); + + ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations(); + assertNotNull(cfgDescriptions); + assertEquals(1, cfgDescriptions.length); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + assertNotNull(cfgDescription); + + List providers = cfgDescription.getLanguageSettingProviders(); + assertNotNull(providers); + assertEquals(1, providers.size()); + ILanguageSettingsProvider provider = providers.get(0); + assertTrue(provider instanceof LanguageSettingsSerializable); + + List actual = provider.getSettingEntries(null, null, null); + assertEquals(entries.get(0), actual.get(0)); + assertEquals(entries.size(), actual.size()); + } + } + + /** + * TODO: refactor with ErrorParserManager + * + * @param store - name of the store + * @return location of the store in the plug-in state area + */ + private static String getStoreLocationInWorkspaceArea(String store) { + IPath location = CCorePlugin.getDefault().getStateLocation().append(store); + return location.toString(); + } + + /** + */ + public void testProjectPersistence_RealProjectSplitStorage() throws Exception { + IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName()); + String xmlStorageFileLocation; + String xmlOutOfTheWay; + String xmlWspStorageFileLocation; + String xmlWspOutOfTheWay; + + List entries = new ArrayList(); + entries.add(new CIncludePathEntry("path0", 0)); + + { + // get project descriptions + ICProjectDescription writableProjDescription = coreModel.getProjectDescription(project); + assertNotNull(writableProjDescription); + ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); + assertEquals(1, cfgDescriptions.length); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + // create a provider + LanguageSettingsSerializable mockProvider = new LanguageSettingsSerializable(PROVIDER_0, PROVIDER_NAME_0); + mockProvider.setStoringEntriesInProjectArea(false); + mockProvider.setSettingEntries(cfgDescription, null, null, entries); + List providers = new ArrayList(); + providers.add(mockProvider); + cfgDescription.setLanguageSettingProviders(providers); + List storedProviders = cfgDescription.getLanguageSettingProviders(); + assertEquals(1, storedProviders.size()); + + // write to project description + coreModel.setProjectDescription(project, writableProjDescription); + 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()); + } + { + coreModel.getProjectDescription(project); + ICConfigurationDescription cfgDescription = getFirstConfigurationDescription(project); + List providers = cfgDescription.getLanguageSettingProviders(); + assertEquals(1, providers.size()); + ILanguageSettingsProvider provider = providers.get(0); + assertTrue(provider instanceof LanguageSettingsSerializable); + assertEquals(PROVIDER_0, provider.getId()); + assertEquals(PROVIDER_NAME_0, provider.getName()); + + List 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 writableProjDescription = coreModel.getProjectDescription(project); + ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); + assertEquals(1, cfgDescriptions.length); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + assertNotNull(cfgDescription); + + cfgDescription.setLanguageSettingProviders(new ArrayList()); + coreModel.setProjectDescription(project, writableProjDescription); + List providers = cfgDescription.getLanguageSettingProviders(); + assertEquals(0, providers.size()); + } + { + // re-check if it really took it + ICConfigurationDescription cfgDescription = getFirstConfigurationDescription(project); + List providers = 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); + List providers = 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); + List providers = cfgDescription.getLanguageSettingProviders(); + assertEquals(1, providers.size()); + ILanguageSettingsProvider loadedProvider = providers.get(0); + assertTrue(loadedProvider instanceof LanguageSettingsSerializable); + assertEquals(PROVIDER_0, loadedProvider.getId()); + assertEquals(PROVIDER_NAME_0, loadedProvider.getName()); + + List actual = loadedProvider.getSettingEntries(cfgDescription, null, null); + assertEquals(entries.get(0), actual.get(0)); + assertEquals(entries.size(), actual.size()); + } + } + } diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java index 12c6bb9281f..f8dcc9d252b 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java @@ -29,7 +29,6 @@ import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.core.testplugin.CModelMock; import org.eclipse.cdt.core.testplugin.ResourceHelper; import org.eclipse.cdt.internal.core.XmlUtil; -import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; @@ -43,12 +42,7 @@ import org.w3c.dom.Element; * Test cases testing LanguageSettingsProvider functionality */ public class LanguageSettingsSerializableTests extends TestCase { - // Should match id of extension point defined in plugin.xml - private static final String EXTENSION_SERIALIZABLE_PROVIDER_ID = "org.eclipse.cdt.core.tests.custom.serializable.language.settings.provider"; - private static final String CFG_ID = "test.configuration.id"; - private static final String CFG_ID_1 = "test.configuration.id.1"; - private static final String CFG_ID_2 = "test.configuration.id.2"; private static final ICConfigurationDescription MOCK_CFG = new CModelMock.DummyCConfigurationDescription(CFG_ID); private static final IResource MOCK_RC = ResourcesPlugin.getWorkspace().getRoot(); private static final String LANG_ID = "test.lang.id"; @@ -101,7 +95,7 @@ public class LanguageSettingsSerializableTests extends TestCase { /** */ - public void testProvider() throws Exception { + public void testProvider_SettersGetters() throws Exception { // benchmark data List entries = new ArrayList(); entries.add(new CIncludePathEntry("path0", 0)); @@ -112,7 +106,7 @@ public class LanguageSettingsSerializableTests extends TestCase { LanguageSettingsSerializable mockProvider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); // test isEmpty() assertTrue(mockProvider.isEmpty()); - + // test setters and getters mockProvider.setId(PROVIDER_2); assertEquals(PROVIDER_2, mockProvider.getId()); @@ -120,16 +114,16 @@ public class LanguageSettingsSerializableTests extends TestCase { assertEquals(PROVIDER_NAME_2, mockProvider.getName()); mockProvider.setCustomParameter(CUSTOM_PARAMETER); assertEquals(CUSTOM_PARAMETER, mockProvider.getCustomParameter()); - - assertEquals(false, mockProvider.isEntriesStorageWithProject()); - mockProvider.setEntriesStorageWithProject(true); - assertEquals(true, mockProvider.isEntriesStorageWithProject()); - + + assertEquals(false, mockProvider.isStoringEntriesInProjectArea()); + mockProvider.setStoringEntriesInProjectArea(true); + assertEquals(true, mockProvider.isStoringEntriesInProjectArea()); + mockProvider.setLanguageScope(languages); assertEquals(languages, mockProvider.getLanguageScope()); mockProvider.setLanguageScope(null); assertEquals(null, mockProvider.getLanguageScope()); - + mockProvider.setSettingEntries(null, MOCK_RC, LANG_ID, entries); List actual = mockProvider.getSettingEntries(null, MOCK_RC, LANG_ID); assertEquals(entries.get(0), actual.get(0)); @@ -143,17 +137,153 @@ public class LanguageSettingsSerializableTests extends TestCase { /** */ - public void testNoProviders() throws Exception { - // serialize language settings of user defined providers (on workspace level) - LanguageSettingsProvidersSerializer.serializeLanguageSettingsWorkspace(); - LanguageSettingsProvidersSerializer.loadLanguageSettingsWorkspace(); + public void testProvider_RegularDOM() throws Exception { + Element elementProvider; + { + // create customized provider + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + provider.setStoringEntriesInProjectArea(true); + provider.setCustomParameter(CUSTOM_PARAMETER); - // test passes if no exception was thrown + List languageScope = new ArrayList(); + languageScope.add(LANG_ID); + provider.setLanguageScope(languageScope); + + List entries = new ArrayList(); + entries.add(new CIncludePathEntry("path0", 1)); + provider.setSettingEntries(null, null, null, entries); + + // serialize + Document doc = XmlUtil.newDocument(); + Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST); + elementProvider = provider.serialize(rootElement); + // check XML + String xmlString = XmlUtil.toString(doc); + assertTrue(xmlString.contains(PROVIDER_1)); + assertTrue(xmlString.contains(PROVIDER_NAME_1)); + assertTrue(xmlString.contains(CUSTOM_PARAMETER)); + assertTrue(xmlString.contains(LANG_ID)); + assertTrue(xmlString.contains("path0")); + } + { + // re-load and check language settings of the newly loaded provider + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(elementProvider); + assertEquals(PROVIDER_1, provider.getId()); + assertEquals(true, provider.isStoringEntriesInProjectArea()); + assertEquals(CUSTOM_PARAMETER, provider.getCustomParameter()); + assertNotNull(provider.getLanguageScope()); + assertTrue(provider.getLanguageScope().size()>0); + assertEquals(LANG_ID, provider.getLanguageScope().get(0)); + + List entries = provider.getSettingEntries(null, null, null); + assertNotNull(entries); + assertTrue(entries.size()>0); + assertEquals(new CIncludePathEntry("path0", 1), entries.get(0)); + } } /** */ - public void testEmptyProvider() throws Exception { + public void testProvider_serializeAttributesDOM() throws Exception { + Element elementProvider; + { + // create customized provider + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + provider.setStoringEntriesInProjectArea(true); + provider.setCustomParameter(CUSTOM_PARAMETER); + + List languageScope = new ArrayList(); + languageScope.add(LANG_ID); + provider.setLanguageScope(languageScope); + + List entries = new ArrayList(); + entries.add(new CIncludePathEntry("path0", 1)); + provider.setSettingEntries(null, null, null, entries); + + // serialize + Document doc = XmlUtil.newDocument(); + Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST); + elementProvider = provider.serializeAttributes(rootElement); + // check XML + String xmlString = XmlUtil.toString(doc); + assertTrue(xmlString.contains(PROVIDER_1)); + assertTrue(xmlString.contains(PROVIDER_NAME_1)); + assertTrue(xmlString.contains(CUSTOM_PARAMETER)); + assertTrue(xmlString.contains(LANG_ID)); + // no entries + assertFalse(xmlString.contains("path0")); + } + { + // re-load and check language settings of the newly loaded provider + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(); + provider.loadAttributes(elementProvider); + assertEquals(PROVIDER_1, provider.getId()); + assertEquals(true, provider.isStoringEntriesInProjectArea()); + assertEquals(CUSTOM_PARAMETER, provider.getCustomParameter()); + assertNotNull(provider.getLanguageScope()); + assertTrue(provider.getLanguageScope().size()>0); + assertEquals(LANG_ID, provider.getLanguageScope().get(0)); + // no entries should be loaded + List entries = provider.getSettingEntries(null, null, null); + assertNull(entries); + } + } + + /** + */ + public void testProvider_serializeEntriesDOM() throws Exception { + Element rootElement; + { + // create customized provider + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + provider.setStoringEntriesInProjectArea(true); + provider.setCustomParameter(CUSTOM_PARAMETER); + + List languageScope = new ArrayList(); + languageScope.add(LANG_ID); + provider.setLanguageScope(languageScope); + + List entries = new ArrayList(); + entries.add(new CIncludePathEntry("path0", 1)); + provider.setSettingEntries(null, null, null, entries); + + // serialize + Document doc = XmlUtil.newDocument(); + rootElement = XmlUtil.appendElement(doc, ELEM_TEST); + provider.serializeEntries(rootElement); + // check XML + String xmlString = XmlUtil.toString(doc); + // no attributes + assertFalse(xmlString.contains(PROVIDER_1)); + assertFalse(xmlString.contains(PROVIDER_NAME_1)); + assertFalse(xmlString.contains(CUSTOM_PARAMETER)); + assertFalse(xmlString.contains(LANG_ID)); + // entries should be present + assertTrue(xmlString.contains("path0")); + } + { + // re-load and check language settings of the newly loaded provider + LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_2, PROVIDER_NAME_2); + provider.loadEntries(rootElement); + assertEquals(PROVIDER_2, provider.getId()); + assertEquals(PROVIDER_NAME_2, provider.getName()); + // no attributes should be loaded + assertFalse(PROVIDER_1.equals(provider.getId())); + assertFalse(PROVIDER_NAME_1.equals(provider.getName())); + assertFalse(true==provider.isStoringEntriesInProjectArea()); + assertFalse(CUSTOM_PARAMETER.equals(provider.getCustomParameter())); + assertNull(provider.getLanguageScope()); + // entries should be loaded + List entries = provider.getSettingEntries(null, null, null); + assertNotNull(entries); + assertTrue(entries.size()>0); + assertEquals(new CIncludePathEntry("path0", 1), entries.get(0)); + } + } + + /** + */ + public void testProvider_EmptyDOM() throws Exception { Element elementProvider; { // create null provider @@ -180,7 +310,7 @@ public class LanguageSettingsSerializableTests extends TestCase { /** */ - public void testCustomParameter() throws Exception { + public void testCustomParameterDOM() throws Exception { Element elementProvider; { // create provider with custom parameter @@ -203,15 +333,15 @@ public class LanguageSettingsSerializableTests extends TestCase { /** */ - public void testStoreEntriesWithProject() throws Exception { + public void testStoreEntriesWithProjectDOM() throws Exception { Element elementProvider; { // create provider with custom parameter LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); - assertEquals(false, provider.isEntriesStorageWithProject()); - provider.setEntriesStorageWithProject(true); - assertEquals(true, provider.isEntriesStorageWithProject()); - + assertEquals(false, provider.isStoringEntriesInProjectArea()); + provider.setStoringEntriesInProjectArea(true); + assertEquals(true, provider.isStoringEntriesInProjectArea()); + Document doc = XmlUtil.newDocument(); Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST); elementProvider = provider.serialize(rootElement); @@ -222,13 +352,13 @@ public class LanguageSettingsSerializableTests extends TestCase { { // re-load and check custom parameter of the newly loaded provider LanguageSettingsSerializable provider = new LanguageSettingsSerializable(elementProvider); - assertEquals(true, provider.isEntriesStorageWithProject()); + assertEquals(true, provider.isStoringEntriesInProjectArea()); } } - + /** */ - public void testLanguages() throws Exception { + public void testLanguagesDOM() throws Exception { List expectedLanguageIds = new ArrayList(); expectedLanguageIds.add(LANG_ID); expectedLanguageIds.add(LANG_ID_1); @@ -259,19 +389,19 @@ public class LanguageSettingsSerializableTests extends TestCase { assertEquals(expectedLanguageIds.size(), actualIds.size()); } } - + /** */ - public void testLanguageScope() throws Exception { + public void testLanguageScopeDOM() throws Exception { // benchmark entries List entries = new ArrayList(); entries.add(new CIncludePathEntry("path0", 0)); - + // define the scope List expectedLanguageIds = new ArrayList(); expectedLanguageIds.add(LANG_ID); expectedLanguageIds.add(LANG_ID_1); - + Element elementProvider; { // create provider with no scope by default @@ -288,14 +418,14 @@ public class LanguageSettingsSerializableTests extends TestCase { List actual = provider.getSettingEntries(null, null, LANG_ID_2); assertEquals(entries, actual); } - + // set the scope provider.setLanguageScope(expectedLanguageIds); List actualIds = provider.getLanguageScope(); assertEquals(LANG_ID, actualIds.get(0)); assertEquals(LANG_ID_1, actualIds.get(1)); assertEquals(2, actualIds.size()); - + { // check for language scope itself List actual = provider.getSettingEntries(null, null, null); @@ -311,7 +441,7 @@ public class LanguageSettingsSerializableTests extends TestCase { List actual = provider.getSettingEntries(null, null, LANG_ID_2); assertNull(actual); } - + Document doc = XmlUtil.newDocument(); Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST); elementProvider = provider.serialize(rootElement); @@ -347,7 +477,7 @@ public class LanguageSettingsSerializableTests extends TestCase { /** */ - public void testNullConfiguration() throws Exception { + public void testNullConfigurationDOM() throws Exception { // provider/configuration/language/resource/settingEntry Element elementProvider; List entries = new ArrayList(); @@ -376,7 +506,7 @@ public class LanguageSettingsSerializableTests extends TestCase { /** */ - public void testNullLanguage() throws Exception { + public void testNullLanguageDOM() throws Exception { // provider/configuration/language/resource/settingEntry Element elementProvider; List entries = new ArrayList(); @@ -406,20 +536,20 @@ public class LanguageSettingsSerializableTests extends TestCase { /** */ - public void testNullLanguageScope() throws Exception { + public void testNullLanguageScopeDOM() throws Exception { // define benchmark entries List entriesNullLanguage = new ArrayList(); entriesNullLanguage.add(new CIncludePathEntry("path_null", 0)); List entriesLanguage = new ArrayList(); entriesLanguage.add(new CIncludePathEntry("path", 0)); - + Element elementProvider; { // create a provider LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); assertEquals(null, provider.getLanguageScope()); - + // add null language provider.setSettingEntries(null, MOCK_RC, null, entriesNullLanguage); assertEquals(null, provider.getLanguageScope()); @@ -435,7 +565,7 @@ public class LanguageSettingsSerializableTests extends TestCase { assertEquals(entriesNullLanguage.get(0), actual.get(0)); assertEquals(entriesNullLanguage.size(), actual.size()); } - + // add non-null language provider.setSettingEntries(MOCK_CFG, MOCK_RC, LANG_ID, entriesLanguage); assertNull(provider.getLanguageScope()); @@ -451,12 +581,12 @@ public class LanguageSettingsSerializableTests extends TestCase { assertEquals(entriesLanguage.get(0), actual.get(0)); assertEquals(entriesLanguage.size(), actual.size()); } - + // provider/configuration/language/resource/settingEntry Document doc = XmlUtil.newDocument(); Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST); elementProvider = provider.serialize(rootElement); - + // verify that "language" element is saved in XML String xmlString = XmlUtil.toString(doc); assertTrue(xmlString.contains(" entries = new ArrayList(); @@ -510,7 +640,7 @@ public class LanguageSettingsSerializableTests extends TestCase { /** */ - public void testNullConfigurationLanguage() throws Exception { + public void testNullConfigurationLanguageDOM() throws Exception { // provider/configuration/language/resource/settingEntry Element elementProvider; List entries = new ArrayList(); @@ -540,7 +670,7 @@ public class LanguageSettingsSerializableTests extends TestCase { /** */ - public void testNullConfigurationResource() throws Exception { + public void testNullConfigurationResourceDOM() throws Exception { // provider/configuration/language/resource/settingEntry Element elementProvider; List entries = new ArrayList(); @@ -570,7 +700,7 @@ public class LanguageSettingsSerializableTests extends TestCase { /** */ - public void testNullLanguageResource() throws Exception { + public void testNullLanguageResourceDOM() throws Exception { // provider/configuration/language/resource/settingEntry Element elementProvider; List entries = new ArrayList(); @@ -600,7 +730,7 @@ public class LanguageSettingsSerializableTests extends TestCase { /** */ - public void testNullConfigurationLanguageResourceFlag() throws Exception { + public void testNullConfigurationLanguageResourceFlagDOM() throws Exception { // provider/configuration/language/resource/settingEntry Element elementProvider; List entries = new ArrayList(); @@ -633,7 +763,7 @@ public class LanguageSettingsSerializableTests extends TestCase { /** */ - public void testCIncludePathEntry() throws Exception { + public void testCIncludePathEntryDOM() throws Exception { Element elementProvider; List entries = new ArrayList(); entries.add(new CIncludePathEntry("path0", 1)); @@ -666,7 +796,7 @@ public class LanguageSettingsSerializableTests extends TestCase { /** */ - public void testCIncludeFileEntry() throws Exception { + public void testCIncludeFileEntryDOM() throws Exception { Element elementProvider; List entries = new ArrayList(); entries.add(new CIncludeFileEntry("name", 1)); @@ -698,7 +828,7 @@ public class LanguageSettingsSerializableTests extends TestCase { /** */ - public void testCMacroEntry() throws Exception { + public void testCMacroEntryDOM() throws Exception { Element elementProvider; List entries = new ArrayList(); entries.add(new CMacroEntry("MACRO0", "value0",1)); @@ -730,7 +860,7 @@ public class LanguageSettingsSerializableTests extends TestCase { /** */ - public void testCMacroFileEntry() throws Exception { + public void testCMacroFileEntryDOM() throws Exception { Element elementProvider; List entries = new ArrayList(); entries.add(new CMacroFileEntry("name", 1)); @@ -762,7 +892,7 @@ public class LanguageSettingsSerializableTests extends TestCase { /** */ - public void testCLibraryPathEntry() throws Exception { + public void testCLibraryPathEntryDOM() throws Exception { Element elementProvider; List entries = new ArrayList(); entries.add(new CLibraryPathEntry("name", 1)); @@ -794,7 +924,7 @@ public class LanguageSettingsSerializableTests extends TestCase { /** */ - public void testCLibraryFileEntry() throws Exception { + public void testCLibraryFileEntryDOM() throws Exception { Element elementProvider; List entries = new ArrayList(); entries.add(new CLibraryFileEntry("name", 1)); @@ -826,7 +956,7 @@ public class LanguageSettingsSerializableTests extends TestCase { /** */ - public void testMixedSettingEntries() throws Exception { + public void testMixedSettingEntriesDOM() throws Exception { Element elementProvider; List entries = new ArrayList(); entries.add(new CIncludePathEntry("path0", 1)); @@ -856,7 +986,7 @@ public class LanguageSettingsSerializableTests extends TestCase { /** */ - public void testLanguageAndNull() throws Exception { + public void testLanguageAndNullDOM() throws Exception { Element elementProvider = null; List entries = new ArrayList(); @@ -892,7 +1022,7 @@ public class LanguageSettingsSerializableTests extends TestCase { /** */ - public void testTwoLanguages() throws Exception { + public void testTwoLanguagesDOM() throws Exception { Element elementProvider = null; List entries = new ArrayList(); @@ -930,7 +1060,7 @@ public class LanguageSettingsSerializableTests extends TestCase { /** */ - public void testTwoResources() throws Exception { + public void testTwoResourcesDOM() throws Exception { // Create resources IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName()); IFile rc1 = ResourceHelper.createFile(project, "rc1"); @@ -1043,8 +1173,8 @@ public class LanguageSettingsSerializableTests extends TestCase { LanguageSettingsSerializable provider1 = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); provider1.setLanguageScope(sampleLanguages); provider1.setCustomParameter(CUSTOM_PARAMETER); - assertEquals(false, provider1.isEntriesStorageWithProject()); - provider1.setEntriesStorageWithProject(true); + assertEquals(false, provider1.isStoringEntriesInProjectArea()); + provider1.setStoringEntriesInProjectArea(true); provider1.setSettingEntries(MOCK_CFG, MOCK_RC, LANG_ID, sampleEntries_1); provider1.setSettingEntries(null, null, LANG_ID, sampleEntries_2); @@ -1070,8 +1200,8 @@ public class LanguageSettingsSerializableTests extends TestCase { assertFalse(provider1.equals(provider2)); assertFalse(provider1.hashCode()==provider2.hashCode()); - provider2.setEntriesStorageWithProject(true); - + provider2.setStoringEntriesInProjectArea(true); + // All set now, so they should be equal assertTrue(provider1.equals(provider2)); assertTrue(provider1.hashCode()==provider2.hashCode()); @@ -1120,8 +1250,8 @@ public class LanguageSettingsSerializableTests extends TestCase { LanguageSettingsSerializableMock provider1 = new LanguageSettingsSerializableMock(PROVIDER_1, PROVIDER_NAME_1); provider1.setLanguageScope(sampleLanguages); provider1.setCustomParameter(CUSTOM_PARAMETER); - assertEquals(false, provider1.isEntriesStorageWithProject()); - provider1.setEntriesStorageWithProject(true); + assertEquals(false, provider1.isStoringEntriesInProjectArea()); + provider1.setStoringEntriesInProjectArea(true); provider1.setSettingEntries(MOCK_CFG, MOCK_RC, LANG_ID, sampleEntries_1); provider1.setSettingEntries(null, null, LANG_ID, sampleEntries_2); @@ -1131,7 +1261,7 @@ public class LanguageSettingsSerializableTests extends TestCase { assertTrue(provider1.equals(providerClone)); assertTrue(provider1.getClass()==providerClone.getClass()); assertEquals(provider1.getCustomParameter(), providerClone.getCustomParameter()); - assertEquals(provider1.isEntriesStorageWithProject(), providerClone.isEntriesStorageWithProject()); + assertEquals(provider1.isStoringEntriesInProjectArea(), providerClone.isStoringEntriesInProjectArea()); assertEquals(provider1.getLanguageScope().get(0), providerClone.getLanguageScope().get(0)); List actual1 = providerClone.getSettingEntries(MOCK_CFG, MOCK_RC, LANG_ID); @@ -1153,7 +1283,7 @@ public class LanguageSettingsSerializableTests extends TestCase { // define sample data List sampleLanguages = new ArrayList(); sampleLanguages.add(LANG_ID); - + // create a model provider class LanguageSettingsSerializableMock extends LanguageSettingsSerializable implements Cloneable { public LanguageSettingsSerializableMock(String id, String name) { @@ -1163,31 +1293,31 @@ public class LanguageSettingsSerializableTests extends TestCase { public LanguageSettingsSerializableMock cloneShallow() throws CloneNotSupportedException { return (LanguageSettingsSerializableMock) super.cloneShallow(); } - + } LanguageSettingsSerializableMock provider1 = new LanguageSettingsSerializableMock(PROVIDER_1, PROVIDER_NAME_1); provider1.setLanguageScope(sampleLanguages); provider1.setCustomParameter(CUSTOM_PARAMETER); - assertEquals(false, provider1.isEntriesStorageWithProject()); - provider1.setEntriesStorageWithProject(true); - + assertEquals(false, provider1.isStoringEntriesInProjectArea()); + provider1.setStoringEntriesInProjectArea(true); + List entries = new ArrayList(); entries.add(new CIncludePathEntry("path", 1)); provider1.setSettingEntries(null, null, null, entries); - + // clone provider LanguageSettingsSerializableMock providerClone = provider1.cloneShallow(); assertNotSame(provider1, providerClone); assertFalse(provider1.equals(providerClone)); assertTrue(provider1.getClass()==providerClone.getClass()); assertEquals(provider1.getCustomParameter(), providerClone.getCustomParameter()); - assertEquals(provider1.isEntriesStorageWithProject(), providerClone.isEntriesStorageWithProject()); + assertEquals(provider1.isStoringEntriesInProjectArea(), providerClone.isStoringEntriesInProjectArea()); assertEquals(provider1.getLanguageScope().get(0), providerClone.getLanguageScope().get(0)); - + List actual = providerClone.getSettingEntries(null, null, null); assertNull(actual); } - + /** */ public void testSort_Kinds() throws Exception { @@ -1204,7 +1334,7 @@ public class LanguageSettingsSerializableTests extends TestCase { CLibraryPathEntry libraryPathEntry2 = new CLibraryPathEntry("lib2", 0); CLibraryFileEntry libraryFileEntry1 = new CLibraryFileEntry("file1", 0); CLibraryFileEntry libraryFileEntry2 = new CLibraryFileEntry("file2", 0); - + // place entries in unsorted list List unsortedEntries = new ArrayList(); unsortedEntries.add(macroEntry1); @@ -1223,7 +1353,7 @@ public class LanguageSettingsSerializableTests extends TestCase { // create a provider and set the entries LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); provider.setSettingEntries(null, null, null, unsortedEntries); - + // retrieve and check that language settings got sorted properly int i=0; List actual = provider.getSettingEntries(null, null, null); @@ -1233,16 +1363,16 @@ public class LanguageSettingsSerializableTests extends TestCase { assertEquals(includeFileEntry2, actual.get(i++)); assertEquals(macroEntry1, actual.get(i++)); assertEquals(macroEntry2, actual.get(i++)); - assertEquals(macroFileEntry1, actual.get(i++)); - assertEquals(macroFileEntry2, actual.get(i++)); + assertEquals(macroFileEntry1, actual.get(i++)); + assertEquals(macroFileEntry2, actual.get(i++)); assertEquals(libraryPathEntry1, actual.get(i++)); assertEquals(libraryPathEntry2, actual.get(i++)); assertEquals(libraryFileEntry1, actual.get(i++)); assertEquals(libraryFileEntry2, actual.get(i++)); - + assertEquals(unsortedEntries.size(), actual.size()); } - + /** */ public void testSort_Entries() throws Exception { @@ -1259,7 +1389,7 @@ public class LanguageSettingsSerializableTests extends TestCase { CLibraryPathEntry libraryPathEntry2 = new CLibraryPathEntry("lib_A", 0); CLibraryFileEntry libraryFileEntry1 = new CLibraryFileEntry("file_B", 0); CLibraryFileEntry libraryFileEntry2 = new CLibraryFileEntry("file_A", 0); - + // place entries in unsorted list List unsortedEntries = new ArrayList(); // macros will be sorted by name @@ -1276,11 +1406,11 @@ public class LanguageSettingsSerializableTests extends TestCase { unsortedEntries.add(libraryFileEntry2); unsortedEntries.add(libraryPathEntry1); unsortedEntries.add(libraryPathEntry2); - + // create a provider and set the entries LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); provider.setSettingEntries(null, null, null, unsortedEntries); - + // retrieve and check that language settings got sorted properly int i=0; List actual = provider.getSettingEntries(null, null, null); @@ -1290,16 +1420,16 @@ public class LanguageSettingsSerializableTests extends TestCase { assertEquals(includeFileEntry2, actual.get(i++)); assertEquals(macroEntry1, actual.get(i++)); assertEquals(macroEntry2, actual.get(i++)); - assertEquals(macroFileEntry1, actual.get(i++)); - assertEquals(macroFileEntry2, actual.get(i++)); + assertEquals(macroFileEntry1, actual.get(i++)); + assertEquals(macroFileEntry2, actual.get(i++)); assertEquals(libraryPathEntry1, actual.get(i++)); assertEquals(libraryPathEntry2, actual.get(i++)); assertEquals(libraryFileEntry1, actual.get(i++)); assertEquals(libraryFileEntry2, actual.get(i++)); - + assertEquals(unsortedEntries.size(), actual.size()); } - + /** */ public void testSort_Undef() throws Exception { @@ -1309,7 +1439,7 @@ public class LanguageSettingsSerializableTests extends TestCase { CMacroEntry macroEntry2B = new CMacroEntry("MACRO_2", null, 0); CMacroEntry macroEntry2C = new CMacroEntry("MACRO_2", null, ICSettingEntry.BUILTIN); CMacroEntry macroEntry3 = new CMacroEntry("MACRO_3", null, 0); - + // place entries in unsorted list List unsortedEntries = new ArrayList(); // macros will be sorted by name and keep order for the same name @@ -1318,11 +1448,11 @@ public class LanguageSettingsSerializableTests extends TestCase { unsortedEntries.add(macroEntry2B); unsortedEntries.add(macroEntry1); unsortedEntries.add(macroEntry2C); - + // create a provider and set the entries LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); provider.setSettingEntries(null, null, null, unsortedEntries); - + // retrieve and check that language settings got sorted properly int i=0; List actual = provider.getSettingEntries(null, null, null); @@ -1331,10 +1461,10 @@ public class LanguageSettingsSerializableTests extends TestCase { assertEquals(macroEntry2B, actual.get(i++)); assertEquals(macroEntry2C, actual.get(i++)); assertEquals(macroEntry3, actual.get(i++)); - + assertEquals(unsortedEntries.size(), actual.size()); } - + } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java index abf370119f9..61016b4006b 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java @@ -33,6 +33,13 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; +/** + * This class is the base class for language settings providers able to serialize + * into XML storage. + * + * TODO - more JavaDoc, info and hints about class hierarchy + * + */ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { public static final String ELEM_PROVIDER = "provider"; //$NON-NLS-1$ private static final String ATTR_ID = "id"; //$NON-NLS-1$ @@ -53,29 +60,53 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { private static final String ATTR_STORE_ENTRIES = "store-entries"; //$NON-NLS-1$ private static final String VALUE_WORKSPACE = "workspace"; //$NON-NLS-1$ private static final String VALUE_PROJECT = "project"; //$NON-NLS-1$ - - private static WeakHashSet> lseListPool = new WeakHashSet>() { + + /** + * Pool of LSE lists implemented as WeakHashSet. That allows to gain memory savings + * at the expense of CPU time. WeakHashSet handles garbage collection when a list is not + * referenced anywhere else. See JavaDoc {@link java.lang.ref.WeakReference} about weak reference objects. + */ + private static WeakHashSet> listPool = new WeakHashSet>() { @Override public synchronized List add(List list) { return super.add(list); } - + }; - private boolean isEntriesStorageWithProject = false; + /** Tells if language settings entries are persisted with the project or in workspace area while serializing. */ + private boolean storeEntriesInProjectArea = false; + /** + * Storage to keep settings entries. Note that it is not necessary to keep configuration in the maps + * as the configuration is always the one provider belongs to. + */ private Map>> fStorage = new HashMap>>(); + /** + * Default constructor. This constructor has to be always followed with setting id and name of the provider. + */ public LanguageSettingsSerializable() { super(); } + /** + * Constructor. + * + * @param id - id of the provider. + * @param name - name of the provider. Note that this name may show up in UI. + */ public LanguageSettingsSerializable(String id, String name) { super(id, name); } + /** + * Constructor which allows to instantiate provider defined via XML markup. + * + * @param elementProvider + */ public LanguageSettingsSerializable(Element elementProvider) { super(); load(elementProvider); @@ -104,10 +135,10 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { /** * Set the language scope of the provider. - * + * * @param languages - the list of languages this provider provides for. * If {@code null}, the provider provides for any language. - * + * * @see #getLanguageScope() */ public void setLanguageScope(List languages) { @@ -117,6 +148,12 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { this.languageScope = new ArrayList(languages); } + /** + * Set custom parameter for the provider. + * Subclasses are free to define how their behavior depends on custom parameter. + * + * @param customParameter + */ public void setCustomParameter(String customParameter) { this.customParameter = customParameter; } @@ -125,11 +162,11 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { * Tells if language settings entries are persisted with the project (under .settings folder) * or in workspace area. Persistence in the project area lets the entries migrate with the * project. - * + * * @return {@code true} if LSE persisted with the project or {@code false} if in the workspace. */ - public boolean isEntriesStorageWithProject() { - return isEntriesStorageWithProject; + public boolean isStoringEntriesInProjectArea() { + return storeEntriesInProjectArea; } /** @@ -137,14 +174,20 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { * @param storeEntriesWithProject - {@code true} if with the project, * {@code false} if in workspace area. */ - public void setEntriesStorageWithProject(boolean storeEntriesWithProject) { - this.isEntriesStorageWithProject = storeEntriesWithProject; + public void setStoringEntriesInProjectArea(boolean storeEntriesWithProject) { + this.storeEntriesInProjectArea = storeEntriesWithProject; } + /** + * Clear all the entries for all configurations, all resources and all languages. + */ public void clear() { fStorage.clear(); } + /** + * Internal convenience method to set language settings entries. + */ private void setSettingEntriesInternal(String rcProjectPath, String languageId, List entries) { if (entries!=null) { Map> langMap = fStorage.get(languageId); @@ -152,7 +195,7 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { langMap = new HashMap>(); fStorage.put(languageId, langMap); } - List sortedEntries = lseListPool.add(Collections.unmodifiableList(sortEntries(entries))); + List sortedEntries = listPool.add(Collections.unmodifiableList(sortEntries(entries))); langMap.put(rcProjectPath, sortedEntries); } else { // do not keep nulls in the tables @@ -166,11 +209,19 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { } } + /** + * Some providers may collect entries in pretty much random order. For the purposes of + * predictability, UI usability and efficient storage the entries are sorted by kinds + * and secondary by name for kinds where the secondary order is not significant. + * + * @param entries - list of entries to sort. + * @return - sorted entries. + */ protected List sortEntries(List entries) { List sortedEntries = new ArrayList(entries); Collections.sort(sortedEntries, new Comparator(){ /** - * This comparator sorts by kinds first and the macros are sorted additionally by name. + * This comparator sorts by kinds first and the macros are sorted additionally by name. */ public int compare(ICLanguageSettingEntry entry0, ICLanguageSettingEntry entry1) { int kind0 = entry0.getKind(); @@ -178,17 +229,17 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { if (kind0==ICSettingEntry.MACRO && kind1==ICSettingEntry.MACRO) { return entry0.getName().compareTo(entry1.getName()); } - + return kind0 - kind1; }}); return sortedEntries; } - + /** * Sets language settings entries for the provider. * Note that the entries are not persisted at that point. To persist use TODO - * + * * @param cfgDescription - configuration description. * @param rc - resource such as file or folder. * @param languageId - language id. If {@code null}, then entries are considered to be defined for @@ -202,8 +253,9 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { /** * {@inheritDoc} - * - * Note that this list is unmodifiable. + *
    Note that this list is unmodifiable. To modify the list copy it, change and use + * {@link #setSettingEntries(ICConfigurationDescription, IResource, String, List)}. + * */ @Override public List getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) { @@ -214,7 +266,7 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { if (entries!=null) return entries; } - + if (languageId!=null && (languageScope==null || languageScope.contains(languageId))) { List entries = getSettingEntries(cfgDescription, rc, null); return entries; @@ -223,30 +275,44 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { return null; } - /* - - - - - - - - - */ - // provider/configuration/language/resource/entry + /** + * Serialize the provider under parent XML element. + * + * @param parentElement - element where to serialize. + * @return - newly created element. That element will already be + * attached to the parent element. + */ public Element serialize(Element parentElement) { + /* + + + + + + + + + */ Element elementProvider = serializeAttributes(parentElement); serializeEntries(elementProvider); return elementProvider; } + /** + * Serialize the provider attributes under parent XML element. That is + * equivalent to serializing everything (including language scope) except entries. + * + * @param parentElement - element where to serialize. + * @return - newly created element. That element will already be + * attached to the parent element. + */ public Element serializeAttributes(Element parentElement) { Element elementProvider = XmlUtil.appendElement(parentElement, ELEM_PROVIDER, new String[] { ATTR_ID, getId(), ATTR_NAME, getName(), ATTR_CLASS, getClass().getCanonicalName(), ATTR_PARAMETER, getCustomParameter(), - ATTR_STORE_ENTRIES, isEntriesStorageWithProject() ? VALUE_PROJECT : VALUE_WORKSPACE, + ATTR_STORE_ENTRIES, isStoringEntriesInProjectArea() ? VALUE_PROJECT : VALUE_WORKSPACE, }); if (languageScope!=null) { @@ -256,13 +322,20 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { } return elementProvider; } - + + /** + * Serialize the provider entries under parent XML element. + * @param elementProvider - element where to serialize the entries. + */ public void serializeEntries(Element elementProvider) { for (Entry>> entryLang : fStorage.entrySet()) { serializeLanguage(elementProvider, entryLang); } } + /** + * Serialize the provider entries for a given language list. + */ private void serializeLanguage(Element parentElement, Entry>> entryLang) { String langId = entryLang.getKey(); if (langId!=null) { @@ -274,6 +347,9 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { } } + /** + * Serialize the provider entries for a given resource list. + */ private void serializeResource(Element parentElement, Entry> entryRc) { String rcProjectPath = entryRc.getKey(); if (rcProjectPath!=null) { @@ -283,6 +359,9 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { serializeSettingEntries(parentElement, entryRc.getValue()); } + /** + * Serialize given settings entries. + */ private void serializeSettingEntries(Element parentElement, List settingEntries) { for (ICLanguageSettingEntry entry : settingEntries) { Element elementSettingEntry = XmlUtil.appendElement(parentElement, ELEM_ENTRY, new String[] { @@ -293,9 +372,9 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { case ICSettingEntry.MACRO: elementSettingEntry.setAttribute(ATTR_VALUE, entry.getValue()); break; -// case ICLanguageSettingEntry.LIBRARY_FILE: - // TODO: sourceAttachment fields need to be covered -// break; +// case ICLanguageSettingEntry.LIBRARY_FILE: +// // TODO: sourceAttachment fields may need to be covered +// break; } int flags = entry.getFlags(); if (flags!=0) { @@ -307,6 +386,9 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { } } + /** + * Load a setting entry from XML element. + */ private ICLanguageSettingEntry loadSettingEntry(Node parentElement) { String settingKind = XmlUtil.determineAttributeValue(parentElement, ATTR_KIND); String settingName = XmlUtil.determineAttributeValue(parentElement, ATTR_NAME); @@ -333,17 +415,25 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { } - // provider/configuration/language/resource/entry + /** + * Load provider from XML provider element. + * @param providerNode - XML element to load provider from. + */ public void load(Element providerNode) { fStorage.clear(); languageScope = null; + // provider/configuration/language/resource/entry if (providerNode!=null) { loadAttributes(providerNode); loadEntries(providerNode); } } + /** + * Load attributes from XML provider element. + * @param providerNode - XML element to load attributes from. + */ public void loadAttributes(Element providerNode) { String providerId = XmlUtil.determineAttributeValue(providerNode, ATTR_ID); String providerName = XmlUtil.determineAttributeValue(providerNode, ATTR_NAME); @@ -353,11 +443,8 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { this.setId(providerId); this.setName(providerName); this.setCustomParameter(providerParameter); - this.setEntriesStorageWithProject(VALUE_PROJECT.equals(providerStoreEntries)); - } + this.setStoringEntriesInProjectArea(VALUE_PROJECT.equals(providerStoreEntries)); - public void loadEntries(Element providerNode) { - List settings = new ArrayList(); NodeList nodes = providerNode.getChildNodes(); for (int i=0;i where entries are defined. + */ + public void loadEntries(Element providerNode) { + List settings = new ArrayList(); + NodeList nodes = providerNode.getChildNodes(); + for (int i=0;i(); @@ -392,6 +499,9 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { } + /** + * Load entries defined in language element. + */ private void loadLanguageElement(Node parentNode, String cfgId) { String langId = XmlUtil.determineAttributeValue(parentNode, ATTR_ID); if (langId.length()==0) { @@ -420,6 +530,9 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { } } + /** + * Load entries defined in resource element. + */ private void loadResourceElement(Node parentNode, String cfgId, String langId) { String rcProjectPath = XmlUtil.determineAttributeValue(parentNode, ATTR_PROJECT_PATH); @@ -444,46 +557,47 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { } } + /** + * Clone storage for the entries. Copies references for lists of entries as a whole. + * Note that is OK as the lists kept in storage are unmodifiable. + */ private Map>> cloneStorage() { Map>> storageClone = new HashMap>>(); -// Set>>>> entrySetCfg = fStorage.entrySet(); -// for (Entry>>> entryCfg : entrySetCfg) { -// String cfgDescriptionId = entryCfg.getKey(); -// Map>> mapLang = entryCfg.getValue(); -// Map>> mapLangClone = new HashMap>>(); - Set>>> entrySetLang = fStorage.entrySet(); - for (Entry>> entryLang : entrySetLang) { - String langId = entryLang.getKey(); - Map> mapRc = entryLang.getValue(); - Map> mapRcClone = new HashMap>(); - Set>> entrySetRc = mapRc.entrySet(); - for (Entry> entryRc : entrySetRc) { - String rcProjectPath = entryRc.getKey(); - List lsEntries = entryRc.getValue(); - // don't need to clone entries, they are from the pool - mapRcClone.put(rcProjectPath, lsEntries); - } -// mapLangClone.put(langId, mapRcClone); - storageClone.put(langId, mapRcClone); + Set>>> entrySetLang = fStorage.entrySet(); + for (Entry>> entryLang : entrySetLang) { + String langId = entryLang.getKey(); + Map> mapRc = entryLang.getValue(); + Map> mapRcClone = new HashMap>(); + Set>> entrySetRc = mapRc.entrySet(); + for (Entry> entryRc : entrySetRc) { + String rcProjectPath = entryRc.getKey(); + List lsEntries = entryRc.getValue(); + // don't need to clone entries, they are from the LSE pool + mapRcClone.put(rcProjectPath, lsEntries); } -// } + storageClone.put(langId, mapRcClone); + } return storageClone; } + /** + * Shallow clone of the provider. "Shallow" is defined here as the exact copy except that + * the copy will have zero language settings entries. + * + * @return shallow copy of the provider. + * @throws CloneNotSupportedException in case {@link #clone()} throws the exception. + */ protected LanguageSettingsSerializable cloneShallow() throws CloneNotSupportedException { LanguageSettingsSerializable clone = (LanguageSettingsSerializable)super.clone(); if (languageScope!=null) clone.languageScope = new ArrayList(languageScope); - + clone.fStorage = new HashMap>>(); return clone; } - /* (non-Javadoc) - * @see java.lang.Object#clone() - */ @Override protected LanguageSettingsSerializable clone() throws CloneNotSupportedException { LanguageSettingsSerializable clone = cloneShallow(); @@ -499,7 +613,7 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { result = prime * result + ((getName() == null) ? 0 : getName().hashCode()); result = prime * result + ((languageScope == null) ? 0 : languageScope.hashCode()); result = prime * result + ((customParameter == null) ? 0 : customParameter.hashCode()); - result = prime * result + (isEntriesStorageWithProject ? 0 : 1); + result = prime * result + (storeEntriesInProjectArea ? 0 : 1); result = prime * result + ((fStorage == null) ? 0 : fStorage.hashCode()); result = prime * result + getClass().hashCode(); return result; @@ -507,7 +621,6 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { /** * @return {@code true} if the objects are equal, {@code false } otherwise. - * * @see java.lang.Object#equals(java.lang.Object) */ @Override @@ -547,8 +660,8 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { return false; } else if (!customParameter.equals(other.customParameter)) return false; - - if (isEntriesStorageWithProject!=other.isEntriesStorageWithProject) + + if (storeEntriesInProjectArea!=other.storeEntriesInProjectArea) return false; if (fStorage == null) { diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java index 4d813f769d8..7e1056d4450 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java @@ -1,3 +1,14 @@ +/******************************************************************************* + * Copyright (c) 2009, 2011 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.internal.core.language.settings.providers; import java.net.URI; @@ -41,11 +52,12 @@ public class LanguageSettingsProvidersSerializer { private static final String ATTR_POINT = "point"; //$NON-NLS-1$ private static final String ELEM_PROJECT = "project"; //$NON-NLS-1$ private static final String ELEM_CONFIGURATION = "configuration"; //$NON-NLS-1$ + private static final String ELEM_PROVIDER = "provider"; //$NON-NLS-1$ private static final String ELEM_PROVIDER_REFERENCE = "provider-reference"; //$NON-NLS-1$ /** Cache of globally available providers to be consumed by calling clients */ private static Map rawGlobalWorkspaceProviders = new HashMap(); private static Object serializingLock = new Object(); - + private static class LanguageSettingsWorkspaceProvider implements ILanguageSettingsProvider { private String providerId; @@ -54,7 +66,7 @@ public class LanguageSettingsProvidersSerializer { Assert.isTrue(id.length()>0); providerId = id; } - + public String getId() { return providerId; } @@ -72,12 +84,12 @@ public class LanguageSettingsProvidersSerializer { } /** - * Do not cache the "raw" provider as workspace provider can be changed at any time. + * Do not cache the "raw" provider as workspace provider can be changed at any time. */ private ILanguageSettingsProvider getRawProvider() { return LanguageSettingsProvidersSerializer.getRawWorkspaceProvider(providerId); } - + @Override public boolean equals(Object obj) { if (obj instanceof LanguageSettingsWorkspaceProvider) { @@ -96,7 +108,7 @@ public class LanguageSettingsProvidersSerializer { } } - + /** static initializer */ static { try { @@ -104,9 +116,31 @@ public class LanguageSettingsProvidersSerializer { } catch (Throwable e) { CCorePlugin.log("Error loading workspace language settings providers", e); //$NON-NLS-1$ } finally { + // swallow any exception } } + private static IFile getStoreInProjectArea(IProject project) throws CoreException { + IFolder folder = project.getFolder(SETTINGS_FOLDER_NAME); + if (!folder.exists()) { + folder.create(true, true, null); + } + IFile storage = folder.getFile(STORAGE_PROJECT_LANGUAGE_SETTINGS); + return storage; + } + + /** + * TODO: refactor with ErrorParserManager ? + * + * @param store - name of the store + * @return location of the store in the plug-in state area + */ + private static URI getStoreInWorkspaceArea(String store) { + IPath location = CCorePlugin.getDefault().getStateLocation().append(store); + URI uri = URIUtil.toURI(location); + return uri; + } + /** * Set and store in workspace area user defined providers. * @@ -132,7 +166,7 @@ public class LanguageSettingsProvidersSerializer { rawWorkspaceProviders.put(rawExtensionProvider.getId(), rawExtensionProvider); } } - + if (providers!=null) { List rawProviders = new ArrayList(); for (ILanguageSettingsProvider provider : providers) { @@ -147,24 +181,12 @@ public class LanguageSettingsProvidersSerializer { rawWorkspaceProviders.put(provider.getId(), provider); } } - + rawGlobalWorkspaceProviders = rawWorkspaceProviders; } - /** - * TODO: refactor with ErrorParserManager - * - * @param store - name of the store - * @return location of the store in the plug-in state area - */ - private static URI getStoreLocationInWorkspaceArea(String store) { - IPath location = CCorePlugin.getDefault().getStateLocation().append(store); - URI uri = URIUtil.toURI(location); - return uri; - } - public static void serializeLanguageSettingsWorkspace() throws CoreException { - URI uriLocation = getStoreLocationInWorkspaceArea(STORAGE_WORKSPACE_LANGUAGE_SETTINGS); + URI uriLocation = getStoreInWorkspaceArea(STORAGE_WORKSPACE_LANGUAGE_SETTINGS); List serializableExtensionProviders = new ArrayList(); for (ILanguageSettingsProvider provider : rawGlobalWorkspaceProviders.values()) { if (provider instanceof LanguageSettingsSerializable) { @@ -183,19 +205,19 @@ public class LanguageSettingsProvidersSerializer { } return; } - + Document doc = XmlUtil.newDocument(); Element rootElement = XmlUtil.appendElement(doc, ELEM_PLUGIN); Element elementExtension = XmlUtil.appendElement(rootElement, ELEM_EXTENSION, new String[] {ATTR_POINT, LanguageSettingsExtensionManager.PROVIDER_EXTENSION_FULL_ID}); - + for (LanguageSettingsSerializable provider : serializableExtensionProviders) { provider.serialize(elementExtension); } - + synchronized (serializingLock) { XmlUtil.serializeXml(doc, uriLocation); } - + } catch (Exception e) { CCorePlugin.log("Internal error while trying to serialize language settings", e); //$NON-NLS-1$ IStatus s = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "Internal error while trying to serialize language settings", e); @@ -205,9 +227,9 @@ public class LanguageSettingsProvidersSerializer { public static void loadLanguageSettingsWorkspace() throws CoreException { List providers = null; - - URI uriLocation = getStoreLocationInWorkspaceArea(STORAGE_WORKSPACE_LANGUAGE_SETTINGS); - + + URI uriLocation = getStoreInWorkspaceArea(STORAGE_WORKSPACE_LANGUAGE_SETTINGS); + Document doc = null; try { synchronized (serializingLock) { @@ -216,12 +238,12 @@ public class LanguageSettingsProvidersSerializer { } catch (Exception e) { CCorePlugin.log("Can't load preferences from file "+uriLocation, e); //$NON-NLS-1$ } - + if (doc!=null) { Element rootElement = doc.getDocumentElement(); NodeList providerNodes = rootElement.getElementsByTagName(LanguageSettingsSerializable.ELEM_PROVIDER); - - List userDefinedProvidersIds = new ArrayList(); + + List userDefinedProvidersIds = new ArrayList(); for (int i=0;i(); - + if (!LanguageSettingsExtensionManager.equalsExtensionProvider(provider)) { providers.add(provider); } @@ -246,17 +268,24 @@ public class LanguageSettingsProvidersSerializer { setWorkspaceProvidersInternal(providers); } - public static void serializeLanguageSettings(Element parentElement, ICProjectDescription prjDescription) throws CoreException { + /** + * @noreference This method is not intended to be referenced by clients. + * It is public solely for benefit of JUnit testing. + */ + public static void serializeLanguageSettingsInternal(Element projectElementPrjStore, Element projectElementWspStore, ICProjectDescription prjDescription) throws CoreException { + ICConfigurationDescription[] cfgDescriptions = prjDescription.getConfigurations(); for (ICConfigurationDescription cfgDescription : cfgDescriptions) { - Element elementConfiguration = XmlUtil.appendElement(parentElement, ELEM_CONFIGURATION, new String[] { + Element elementConfiguration = XmlUtil.appendElement(projectElementPrjStore, ELEM_CONFIGURATION, new String[] { LanguageSettingsExtensionManager.ATTR_ID, cfgDescription.getId(), LanguageSettingsExtensionManager.ATTR_NAME, cfgDescription.getName(), }); + Element elementConfigurationWsp = null; List providers = cfgDescription.getLanguageSettingProviders(); if (providers.size()>0) { Element elementExtension = XmlUtil.appendElement(elementConfiguration, ELEM_EXTENSION, new String[] { ATTR_POINT, LanguageSettingsExtensionManager.PROVIDER_EXTENSION_FULL_ID}); + Element elementExtensionWsp = null; for (ILanguageSettingsProvider provider : providers) { if (isWorkspaceProvider(provider)) { // Element elementProviderReference = @@ -265,7 +294,29 @@ public class LanguageSettingsProvidersSerializer { continue; } if (provider instanceof LanguageSettingsSerializable) { - ((LanguageSettingsSerializable) provider).serialize(elementExtension); + LanguageSettingsSerializable lss = (LanguageSettingsSerializable) provider; + + boolean useWsp = projectElementWspStore!=null && projectElementPrjStore!=projectElementWspStore; + if (lss.isStoringEntriesInProjectArea() || !useWsp) { + lss.serialize(elementExtension); + } else { + lss.serializeAttributes(elementExtension); + + // lazy initialization of elements - to avoid serialization of no-data file + if (elementExtensionWsp==null) { + if (elementConfigurationWsp==null) { + elementConfigurationWsp = XmlUtil.appendElement(projectElementWspStore, ELEM_CONFIGURATION, new String[] { + LanguageSettingsExtensionManager.ATTR_ID, cfgDescription.getId(), + LanguageSettingsExtensionManager.ATTR_NAME, cfgDescription.getName(), + }); + } + elementExtensionWsp = XmlUtil.appendElement(elementConfigurationWsp, ELEM_EXTENSION, new String[] { + ATTR_POINT, LanguageSettingsExtensionManager.PROVIDER_EXTENSION_FULL_ID}); + } + Element elementProviderWsp = XmlUtil.appendElement(elementExtensionWsp, ELEM_PROVIDER, new String[] { + LanguageSettingsExtensionManager.ATTR_ID, provider.getId()}); + lss.serializeEntries(elementProviderWsp); + } } else { // Element elementProvider = XmlUtil.appendElement(elementExtension, LanguageSettingsExtensionManager.ELEM_PROVIDER, new String[] { @@ -279,27 +330,35 @@ public class LanguageSettingsProvidersSerializer { } } - private static IFile getStorage(IProject project) throws CoreException { - IFolder folder = project.getFolder(SETTINGS_FOLDER_NAME); - if (!folder.exists()) { - folder.create(true, true, null); - } - IFile storage = folder.getFile(STORAGE_PROJECT_LANGUAGE_SETTINGS); - return storage; - } - public static void serializeLanguageSettings(ICProjectDescription prjDescription) throws CoreException { IProject project = prjDescription.getProject(); try { - Document doc = XmlUtil.newDocument(); - Element rootElement = XmlUtil.appendElement(doc, ELEM_PROJECT); - serializeLanguageSettings(rootElement, prjDescription); - - IFile file = getStorage(project); + // Document to store in project area + Document docPrjStore = XmlUtil.newDocument(); + Element projectElementPrjStore = XmlUtil.appendElement(docPrjStore, ELEM_PROJECT); + // Document to store in workspace area + Document docWspStore = XmlUtil.newDocument(); + Element projectElementWspStore = XmlUtil.appendElement(docWspStore, ELEM_PROJECT); + + serializeLanguageSettingsInternal(projectElementPrjStore, projectElementWspStore, prjDescription); + + IFile filePrjStore = getStoreInProjectArea(project); + URI uriWspStore = null; + boolean isWorkspaceStoreEmpty = projectElementWspStore.getChildNodes().getLength() == 0; + uriWspStore = getStoreInWorkspaceArea(project.getName()+'.'+STORAGE_WORKSPACE_LANGUAGE_SETTINGS); + synchronized (serializingLock){ - XmlUtil.serializeXml(doc, file); + // The project store should not be absent. Absent store means legacy project, not 0 providers. + XmlUtil.serializeXml(docPrjStore, filePrjStore); + + // project-specific location in workspace area + if (!isWorkspaceStoreEmpty) { + XmlUtil.serializeXml(docWspStore, uriWspStore); + } else { + new java.io.File(uriWspStore).delete(); + } } - + } catch (Exception e) { IStatus s = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "Internal error while trying to serialize language settings", e); CCorePlugin.log(s); @@ -307,7 +366,11 @@ public class LanguageSettingsProvidersSerializer { } } - public static void loadLanguageSettings(Element parentElement, ICProjectDescription prjDescription) { + /** + * @noreference This method is not intended to be referenced by clients. + * It is public solely for benefit of JUnit testing. + */ + public static void loadLanguageSettingsInternal(Element projectElementPrj, Element projectElementWsp, ICProjectDescription prjDescription) { /* @@ -318,7 +381,7 @@ public class LanguageSettingsProvidersSerializer { */ - NodeList configurationNodes = parentElement.getChildNodes(); + NodeList configurationNodes = projectElementPrj.getChildNodes(); for (int ic=0;ic + + + + + + + + */ + NodeList configurationNodes = projectElementWsp.getChildNodes(); + for (int ic=0;ic - loadLanguageSettings(rootElement, prjDescription); + Element rootElementPrj = doc.getDocumentElement(); // + + URI uriLocation = getStoreInWorkspaceArea(project.getName()+'.'+STORAGE_WORKSPACE_LANGUAGE_SETTINGS); + Document docWsp = null; + synchronized (serializingLock) { + docWsp = XmlUtil.loadXml(uriLocation); + } + + Element rootElementWsp = null; // + if (docWsp!=null) { + rootElementWsp = docWsp.getDocumentElement(); + } + + + loadLanguageSettingsInternal(rootElementPrj, rootElementWsp, prjDescription); } catch (Exception e) { CCorePlugin.log("Can't load preferences from file "+file.getLocation(), e); //$NON-NLS-1$ } - + if (doc!=null) { } - + } else { // Already existing legacy projects ICConfigurationDescription[] cfgDescriptions = prjDescription.getConfigurations(); @@ -408,7 +540,7 @@ public class LanguageSettingsProvidersSerializer { cfgDescription.setLanguageSettingProviders(providers); } } - + } } @@ -433,7 +565,7 @@ public class LanguageSettingsProvidersSerializer { /** * TODO * @return ordered set of providers defined in the workspace which include contributed through extension + user defined ones - * + * */ public static List getWorkspaceProviders() { ArrayList workspaceProviders = new ArrayList(); @@ -448,9 +580,9 @@ public class LanguageSettingsProvidersSerializer { * * @param provider - provider to check. * @return {@code true} if the given provider is workspace provider, {@code false} otherwise. - * + * */ public static boolean isWorkspaceProvider(ILanguageSettingsProvider provider) { return provider instanceof LanguageSettingsWorkspaceProvider; } -} \ No newline at end of file +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java index 10e1cf6a374..7d9f26622e2 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java @@ -102,14 +102,14 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { MOVEUP_STR, MOVEDOWN_STR, }; - + private final static String[] BUTTON_LABELS_PREF = { // RENAME_STR, // RUN_STR, CLEAR_STR, RESET_STR, }; - + private static final int[] DEFAULT_CONFIGURE_SASH_WEIGHTS = new int[] { 50, 50 }; private SashForm sashFormConfigure; @@ -118,14 +118,14 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { private Group groupOptionsPage; private ICOptionPage currentOptionsPage = null; private Composite compositeOptionsPage; - + private Button enableProvidersCheckBox; private StatusMessageLine fStatusLine; private Button globalProviderCheckBox = null; private Link linkWorkspacePreferences = null; private Button projectStorageCheckBox = null; - + private Page_LanguageSettingsProviders masterPropertyPage = null; /** @@ -136,36 +136,36 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { private List presentedProviders = null; private final Map optionsPageMap = new HashMap(); private Map> initialProvidersByCfg = new HashMap>(); - + private boolean initialEnablement = false; - + /** * Returns current working copy of the provider. Creates one if it has not been created yet. * Used by option pages when there is a need to modify the provider. * Warning: Do not cache the result as the provider can be replaced at any time. - * @param providerId - * + * @param providerId + * * @return the provider */ public ILanguageSettingsProvider getWorkingCopy(String providerId) { ILanguageSettingsProvider provider = findProvider(providerId, presentedProviders); if (isWorkingCopy(provider)) return provider; - + ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); Assert.isTrue(rawProvider instanceof ILanguageSettingsEditableProvider); - + ILanguageSettingsEditableProvider editableProvider = (ILanguageSettingsEditableProvider)rawProvider; try { ILanguageSettingsEditableProvider newProvider = editableProvider.clone(); replaceSelectedProvider(newProvider); return newProvider; - + } catch (CloneNotSupportedException e) { CUIPlugin.log("Error cloning provider " + editableProvider.getId(), e); // TODO warning dialog for user? } - + return null; } @@ -173,19 +173,19 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { @Override protected String[] getOverlayKeys(ILanguageSettingsProvider provider) { String[] overlayKeys = super.getOverlayKeys(provider); - + ILanguageSettingsProvider rawProvider = page.isForPrefs() ? LanguageSettingsManager.getRawProvider(provider) : provider; if (LanguageSettingsManager_TBD.isReconfigured(rawProvider)) { overlayKeys[IDecoration.TOP_RIGHT] = CDTSharedImages.IMG_OVR_SETTING; } - + if (isWorkingCopy(provider)) { overlayKeys[IDecoration.TOP_RIGHT] = CDTSharedImages.IMG_OVR_EDITED; } return overlayKeys; } } - + /** * Shortcut for getting the current resource for the property page. */ @@ -199,7 +199,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { private ICConfigurationDescription getConfigurationDescription() { if (page.isForPrefs()) return null; - + ICConfigurationDescription cfgDescription = getResDesc().getConfiguration(); return cfgDescription; } @@ -231,7 +231,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { initialEnablement = LanguageSettingsManager.isLanguageSettingsProvidersEnabled(page.getProject()); } } - + @Override public void createControls(Composite parent) { super.createControls(parent); @@ -239,7 +239,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { GridData gd = (GridData) usercomp.getLayoutData(); // Discourage settings entry table from trying to show all its items at once, see bug 264330 gd.heightHint =1; - + if (page instanceof Page_LanguageSettingsProviders) { masterPropertyPage = (Page_LanguageSettingsProviders) page; } @@ -248,7 +248,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { // SashForms for each mode createConfigureSashForm(); - + // Status line fStatusLine = new StatusMessageLine(usercomp, SWT.LEFT, 2); @@ -290,7 +290,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { // Providers table Composite compositeSashForm = new Composite(sashFormConfigure, SWT.BORDER | SWT.SINGLE); compositeSashForm.setLayout(new GridLayout()); - + // items checkboxes only for project properties page tableProviders = new Table(compositeSashForm, page.isForPrefs() ? SWT.NONE : SWT.CHECK); tableProviders.setLayoutData(new GridData(GridData.FILL_BOTH)); @@ -353,14 +353,14 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { } if (newProvider!=null) { replaceSelectedProvider(newProvider); - + ICConfigurationDescription cfgDescription = getConfigurationDescription(); initializeOptionsPage(newProvider, cfgDescription); displaySelectedOptionPage(); } else { newProvider = oldProvider; } - + return newProvider; } @@ -373,7 +373,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { ICConfigurationDescription cfgDescription = null; if (!page.isForPrefs()) { cfgDescription = getConfigurationDescription(); - + List cfgProviders = new ArrayList(cfgDescription.getLanguageSettingProviders()); pos = getProviderIndex(newProvider.getId(), cfgProviders); cfgProviders.set(pos, newProvider); @@ -392,7 +392,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { groupOptionsPage = new Group(sashFormConfigure, SWT.SHADOW_ETCHED_IN); groupOptionsPage.setText("Language Settings Provider Options"); groupOptionsPage.setLayout(new GridLayout(2, false)); - + if (!page.isForPrefs()) { if (globalProviderCheckBox==null) { globalProviderCheckBox = new Button(groupOptionsPage, SWT.CHECK); @@ -406,7 +406,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { provider = toggleGlobalProvider(provider, isGlobal); } projectStorageCheckBox.setSelection(provider instanceof LanguageSettingsSerializable - && ((LanguageSettingsSerializable) provider).isEntriesStorageWithProject()); + && ((LanguageSettingsSerializable) provider).isStoringEntriesInProjectArea()); } @Override @@ -415,7 +415,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { } }); - + projectStorageCheckBox = new Button(groupOptionsPage, SWT.CHECK); projectStorageCheckBox.setText("Store entries in project settings folder (supporting project miration)"); projectStorageCheckBox.addSelectionListener(new SelectionAdapter() { @@ -424,7 +424,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { boolean isWithProject = projectStorageCheckBox.getSelection(); ILanguageSettingsProvider provider = getWorkingCopy(getSelectedProvider().getId()); Assert.isTrue(provider instanceof LanguageSettingsSerializable); - ((LanguageSettingsSerializable)provider).setEntriesStorageWithProject(isWithProject); + ((LanguageSettingsSerializable)provider).setStoringEntriesInProjectArea(isWithProject); refreshItem(provider); } @@ -434,7 +434,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { } }); - + linkWorkspacePreferences = createLinkToPreferences(groupOptionsPage, 2); } } @@ -445,7 +445,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { private void enableSashForm(SashForm sashForm, boolean enable) { sashForm.setVisible(enable); - // Some of woodoo to fill properties page vertically and still keep right border visible in preferences + // Some of woodoo to fill properties page vertically and still keep right border visible in preferences GridData gd = new GridData(enable || page.isForPrefs() ? GridData.FILL_BOTH : SWT.NONE); gd.horizontalSpan = 2; gd.heightHint = enable ? SWT.DEFAULT : 0; @@ -456,7 +456,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { sashFormConfigure.setEnabled(enable); tableProviders.setEnabled(enable); compositeOptionsPage.setEnabled(enable); - + buttoncomp.setEnabled(enable); if (enable) { @@ -468,7 +468,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { disableButtons(); } } - + /** * Populate provider tables and their option pages which are used in Configure mode */ @@ -484,7 +484,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { List cfgProviders = cfgDescription.getLanguageSettingProviders(); tableProvidersViewer.setCheckedElements(cfgProviders.toArray(new ILanguageSettingsProvider[0])); } - + if (selectedId!=null) { for (int i=0; i(); } - + List workspaceProviders = LanguageSettingsManager.getWorkspaceProviders(); - + // ensure sorting by name all unchecked providers Set allAvailableProvidersSet = new TreeSet(new Comparator() { public int compare(ILanguageSettingsProvider prov1, ILanguageSettingsProvider prov2) { @@ -541,7 +541,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { idsList.add(id); } } - + // renders better when using temporary presentedProviders = providers; tableProvidersViewer.setInput(presentedProviders); @@ -559,20 +559,20 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { ((AbstractLanguageSettingProviderOptionPage)optionsPage).init(this, provider.getId()); } } - + return optionsPage; } private void initializeOptionsPage(ILanguageSettingsProvider provider, ICConfigurationDescription cfgDescription) { ICOptionPage optionsPage = createOptionsPage(provider, cfgDescription); - + if (optionsPage!=null) { ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); boolean isEditableForProject = page.isForProject() && provider instanceof ILanguageSettingsEditableProvider; boolean isEditableForPrefs = page.isForPrefs() && rawProvider instanceof ILanguageSettingsEditableProvider; boolean isEditable = isEditableForProject || isEditableForPrefs; compositeOptionsPage.setEnabled(isEditable); - + String id = (provider!=null) ? provider.getId() : null; optionsPageMap.put(id, optionsPage); optionsPage.setContainer(page); @@ -601,12 +601,12 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { globalProviderCheckBox.setSelection(isGlobal); globalProviderCheckBox.setEnabled(isChecked && isRawProviderEditable); globalProviderCheckBox.setVisible(provider!=null); - + projectStorageCheckBox.setEnabled(!isGlobal); projectStorageCheckBox.setVisible(rawProvider instanceof LanguageSettingsSerializable); projectStorageCheckBox.setSelection(provider instanceof LanguageSettingsSerializable - && ((LanguageSettingsSerializable)provider).isEntriesStorageWithProject()); - + && ((LanguageSettingsSerializable)provider).isStoringEntriesInProjectArea()); + boolean needPreferencesLink=isGlobal && currentOptionsPage!=null; // TODO: message final String linkMsg = needPreferencesLink ? "Options of global providers can be changed in Workspace Settings, Discovery Tab." : ""; @@ -614,7 +614,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { linkWorkspacePreferences.pack(); linkWorkspacePreferences.setEnabled(isChecked); } - + if (currentOptionsPage != null) { boolean isEditableForProject = page.isForProject() && provider instanceof ILanguageSettingsEditableProvider; boolean isEditableForPrefs = page.isForPrefs() && rawProvider instanceof ILanguageSettingsEditableProvider; @@ -638,7 +638,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { } ICConfigurationDescription cfgDescription = getConfigurationDescription(); cfgDescription.setLanguageSettingProviders(providers); - + if (selectedElement!=null) { tableProvidersViewer.update(selectedElement, null); if (selectedElement instanceof ILanguageSettingsProvider) { @@ -682,15 +682,15 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { canClear = canForWorkspace || canForProject; } } - + boolean canReset = false; if (rawProvider!=null && (canForWorkspace || canForProject)) { canReset = ! LanguageSettingsManager_TBD.isEqualExtensionProvider(rawProvider); } - + boolean canMoveUp = page.isForProject() && isProviderSelected && isRangeOk && pos!=0; boolean canMoveDown = page.isForProject() && isProviderSelected && isRangeOk && pos!=last; - + // buttonSetEnabled(BUTTON_RENAME, false); // buttonSetEnabled(BUTTON_RUN, false); buttonSetEnabled(BUTTON_CLEAR, canClear); @@ -748,7 +748,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(selectedProvider); if (rawProvider instanceof ILanguageSettingsEditableProvider) { ILanguageSettingsEditableProvider editableProvider = (ILanguageSettingsEditableProvider) rawProvider; - + try { ILanguageSettingsEditableProvider newProvider = editableProvider.cloneShallow(); replaceSelectedProvider(newProvider); @@ -756,13 +756,13 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { ICConfigurationDescription cfgDescription = getConfigurationDescription(); initializeOptionsPage(newProvider, cfgDescription); displaySelectedOptionPage(); - + } catch (CloneNotSupportedException e) { CUIPlugin.log("Error cloning provider " + editableProvider.getId(), e); return; } } - + } updateButtons(); } @@ -787,7 +787,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { List initialProviders = initialProvidersByCfg.get(cfgDescription.getId()); isWorkingCopy = ! initialProviders.contains(provider); } - + } return isWorkingCopy; } @@ -809,10 +809,10 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { private void moveProvider(int oldPos, int newPos) { Collections.swap(presentedProviders, oldPos, newPos); - + updateProvidersTable(); tableProviders.setSelection(newPos); - + saveCheckedProviders(null); updateButtons(); } @@ -847,7 +847,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { } else { setAllVisible(true, null); } - + if (masterPropertyPage!=null) { boolean enabled = masterPropertyPage.isLanguageSettingsProvidersEnabled(); enableProvidersCheckBox.setSelection(enabled); @@ -868,12 +868,12 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { protected void performDefaults() { if (enableProvidersCheckBox==null || enableProvidersCheckBox.getSelection()==false) return; - + if (page.isForPrefs() || page.isForProject()) { if (MessageDialog.openQuestion(usercomp.getShell(), Messages.LanguageSettingsProviderTab_TitleResetProviders, Messages.LanguageSettingsProviderTab_AreYouSureToResetProviders)) { - + if (page.isForProject()) { ICConfigurationDescription cfgDescription = getConfigurationDescription(); List cfgProviders = new ArrayList(cfgDescription.getLanguageSettingProviders()); @@ -889,7 +889,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { if (atLeastOneChanged) { cfgDescription.setLanguageSettingProviders(cfgProviders); } - + } else if (page.isForPrefs()) { int pos = tableProviders.getSelectionIndex(); List providers = new ArrayList(presentedProviders); @@ -905,11 +905,11 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { presentedProviders = providers; tableProvidersViewer.setInput(presentedProviders); tableProviders.setSelection(pos); - + updateButtons(); } } - + updateData(getResDesc()); } } @@ -934,7 +934,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { destCfgDescription.setLanguageSettingProviders(destProviders); } - + if (!page.isForPrefs()) { ICConfigurationDescription sd = srcRcDescription.getConfiguration(); ICConfigurationDescription dd = destRcDescription.getConfiguration(); @@ -952,7 +952,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { ICResourceDescription rcDesc = getResDesc(); IResource rc = getResource(); ICConfigurationDescription cfgDescription = rcDesc.getConfiguration(); - + List destProviders = new ArrayList(); List providers = cfgDescription.getLanguageSettingProviders(); for (ILanguageSettingsProvider pro : providers) { @@ -961,7 +961,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { } cfgDescription.setLanguageSettingProviders(destProviders); } - + // Build Settings page if (page.isForPrefs()) { try { @@ -971,7 +971,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { } initializeProviders(); } - + if (page.isForProject() && enableProvidersCheckBox!=null) { boolean enabled = enableProvidersCheckBox.getSelection(); if (masterPropertyPage!=null) @@ -979,7 +979,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { LanguageSettingsManager.setLanguageSettingsProvidersEnabled(page.getProject(), enabled); enableProvidersCheckBox.setSelection(enabled); } - + Collection optionPages = optionsPageMap.values(); for (ICOptionPage op : optionPages) { try { @@ -1006,7 +1006,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { return false; if (page.isForPrefs()) return true; - + if (!page.isForProject()) return false; @@ -1035,7 +1035,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { newProvidersList = cfgDescription.getLanguageSettingProviders(); } boolean newEnablement = LanguageSettingsManager.isLanguageSettingsProvidersEnabled(page.getProject()); - + // TODO boolean isEqualList = false; // boolean isEqualList = (newProvidersList==initialProvidersMap) || (newProvidersList!=null && newProvidersList.equals(initialProvidersMap)); @@ -1060,11 +1060,11 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { } return null; } - + public ILanguageSettingsProvider getProvider(String id) { return findProvider(id, presentedProviders); } - + private int getProviderIndex(String id, List providers) { int pos = 0; for (ILanguageSettingsProvider p : providers) { From af5998ac94fd53929530c440d214ecc0f2bda3e7 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Mon, 15 Aug 2011 14:40:51 -0400 Subject: [PATCH 018/120] Fixed losing selection after "Restore Defaults" in some cases. --- .../settings/providers/LanguageSettingsProviderTab.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java index 7d9f26622e2..5b3f2a35f12 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java @@ -477,7 +477,9 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { String selectedId = selectedProvider!=null ? selectedProvider.getId() : null; // update viewer if the list of providers changed + int pos = tableProviders.getSelectionIndex(); tableProvidersViewer.setInput(presentedProviders); + tableProviders.setSelection(pos); ICConfigurationDescription cfgDescription = getConfigurationDescription(); if (cfgDescription!=null) { @@ -544,7 +546,10 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { // renders better when using temporary presentedProviders = providers; + + int pos = tableProviders.getSelectionIndex(); tableProvidersViewer.setInput(presentedProviders); + tableProviders.setSelection(pos); } private ICOptionPage createOptionsPage(ILanguageSettingsProvider provider, ICConfigurationDescription cfgDescription) { @@ -891,7 +896,6 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { } } else if (page.isForPrefs()) { - int pos = tableProviders.getSelectionIndex(); List providers = new ArrayList(presentedProviders); for (int i=0;i Date: Tue, 6 Sep 2011 11:26:09 -0400 Subject: [PATCH 019/120] Better legacy and compatibility support --- .../scannerconfig/ScannerConfigBuilder.java | 12 ++ .../ScannerInfoConsoleParserFactory.java | 44 +++--- .../ui/dialogs/DiscoveryOptionsBlock.java | 13 +- .../scannerconfig/ScannerConfigBuilder.java | 7 +- .../scannerconfig/CfgScannerConfigUtil.java | 9 +- .../CfgScannerConfigProfileManager.java | 36 ----- .../core/ExternalBuildRunner.java | 45 ++++--- .../internal/core/InputType.java | 56 +++++++- .../internal/core/ToolChain.java | 69 ++++++++-- .../plugin.xml | 6 +- .../ui/properties/DiscoveryTab.java | 41 +++++- .../ui/wizards/MBSWizardHandler.java | 14 +- .../ui/wizards/NewMakeProjFromExisting.java | 18 +-- .../ui/wizards/STDWizardHandler.java | 15 +-- .../providers/LanguageSettingsManager.java | 49 +------ .../ScannerDiscoveryLegacySupport.java | 125 ++++++++++++++++++ .../model/util/PathEntryTranslator.java | 3 +- .../LanguageSettingsExtensionManager.java | 11 +- .../LanguageSettingsProvidersSerializer.java | 4 +- .../model/ScannerInfoProviderProxy.java | 4 +- .../providers/LanguageSettingsEntriesTab.java | 8 +- .../LanguageSettingsProviderTab.java | 10 +- ...anguageSettingsProvidersLabelProvider.java | 3 +- .../Page_LanguageSettingsProviders.java | 5 +- 24 files changed, 400 insertions(+), 207 deletions(-) create mode 100644 core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ScannerDiscoveryLegacySupport.java diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/ScannerConfigBuilder.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/ScannerConfigBuilder.java index 304a6c78e10..86328c85459 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/ScannerConfigBuilder.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/ScannerConfigBuilder.java @@ -13,6 +13,8 @@ package org.eclipse.cdt.make.core.scannerconfig; import java.util.Map; import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySupport; +import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.resources.ACBuilder; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICProjectDescription; @@ -75,6 +77,11 @@ public class ScannerConfigBuilder extends ACBuilder { buildInfo2 = ScannerConfigProfileManager.createScannerConfigBuildInfo2(getProject()); autodiscoveryEnabled2 = buildInfo2.isAutoDiscoveryEnabled(); + if (autodiscoveryEnabled2) { + ICProjectDescription projDesc = CoreModel.getDefault().getProjectDescription(getProject()); + ICConfigurationDescription cfgDescription = projDesc.getActiveConfiguration(); + autodiscoveryEnabled2 = ScannerDiscoveryLegacySupport.isMbsLanguageSettingsProviderOn(cfgDescription); + } if (autodiscoveryEnabled2) { monitor.beginTask(MakeMessages.getString("ScannerConfigBuilder.Invoking_Builder"), 100); //$NON-NLS-1$ @@ -129,6 +136,11 @@ public class ScannerConfigBuilder extends ACBuilder { protected boolean build(IProject project, InfoContext context, IScannerConfigBuilderInfo2 buildInfo2, IProgressMonitor monitor){ boolean autodiscoveryEnabled2 = buildInfo2.isAutoDiscoveryEnabled(); + if (autodiscoveryEnabled2) { + ICProjectDescription projDesc = CoreModel.getDefault().getProjectDescription(getProject()); + ICConfigurationDescription cfgDescription = projDesc.getActiveConfiguration(); + autodiscoveryEnabled2 = ScannerDiscoveryLegacySupport.isMbsLanguageSettingsProviderOn(cfgDescription); + } if (autodiscoveryEnabled2) { monitor.beginTask(MakeMessages.getString("ScannerConfigBuilder.Invoking_Builder"), 100); //$NON-NLS-1$ diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/ScannerInfoConsoleParserFactory.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/ScannerInfoConsoleParserFactory.java index 0bd3ebaf6b6..369a5cd3ef5 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/ScannerInfoConsoleParserFactory.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/ScannerInfoConsoleParserFactory.java @@ -14,6 +14,10 @@ package org.eclipse.cdt.make.internal.core.scannerconfig; import java.io.OutputStream; import org.eclipse.cdt.core.IMarkerGenerator; +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.internal.core.ConsoleOutputSniffer; import org.eclipse.cdt.make.core.MakeBuilder; import org.eclipse.cdt.make.core.MakeBuilderUtil; @@ -118,23 +122,29 @@ public class ScannerInfoConsoleParserFactory { // builder not installed or disabled } } - if (scBuildInfo != null && - scBuildInfo.isAutoDiscoveryEnabled() && - scBuildInfo.isBuildOutputParserEnabled()) { - // get the make builder console parser - SCProfileInstance profileInstance = ScannerConfigProfileManager.getInstance(). - getSCProfileInstance(currentProject, context, scBuildInfo.getSelectedProfileId()); - IScannerInfoConsoleParser clParser = profileInstance.createBuildOutputParser(); - if (collector == null) { - collector = profileInstance.getScannerInfoCollector(); - } - if(clParser != null){ - clParser.startup(currentProject, workingDirectory, collector, - scBuildInfo.isProblemReportingEnabled() ? markerGenerator : null); - // create an output stream sniffer - return new ConsoleOutputSniffer(outputStream, errorStream, new - IScannerInfoConsoleParser[] {clParser}); - } + if (scBuildInfo != null) { + boolean autodiscoveryEnabled2 = scBuildInfo.isAutoDiscoveryEnabled(); + if (autodiscoveryEnabled2) { + ICProjectDescription projDesc = CoreModel.getDefault().getProjectDescription(currentProject); + ICConfigurationDescription cfgDescription = projDesc.getActiveConfiguration(); + autodiscoveryEnabled2 = ScannerDiscoveryLegacySupport.isMbsLanguageSettingsProviderOn(cfgDescription); + } + if (autodiscoveryEnabled2 && scBuildInfo.isBuildOutputParserEnabled()) { + // get the make builder console parser + SCProfileInstance profileInstance = ScannerConfigProfileManager.getInstance(). + getSCProfileInstance(currentProject, context, scBuildInfo.getSelectedProfileId()); + IScannerInfoConsoleParser clParser = profileInstance.createBuildOutputParser(); + if (collector == null) { + collector = profileInstance.getScannerInfoCollector(); + } + if(clParser != null){ + clParser.startup(currentProject, workingDirectory, collector, + scBuildInfo.isProblemReportingEnabled() ? markerGenerator : null); + // create an output stream sniffer + return new ConsoleOutputSniffer(outputStream, errorStream, new + IScannerInfoConsoleParser[] {clParser}); + } + } } } // } diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/DiscoveryOptionsBlock.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/DiscoveryOptionsBlock.java index 56e44b3efec..e454eeaa0f7 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/DiscoveryOptionsBlock.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/DiscoveryOptionsBlock.java @@ -15,10 +15,13 @@ import java.util.Arrays; import java.util.Iterator; import java.util.List; +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.ICProject; import org.eclipse.cdt.core.model.IPathEntry; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.make.core.MakeCorePlugin; import org.eclipse.cdt.make.core.MakeProjectNature; import org.eclipse.cdt.make.core.scannerconfig.IScannerConfigBuilderInfo2; @@ -180,8 +183,14 @@ public class DiscoveryOptionsBlock extends AbstractDiscoveryOptionsBlock { ((GridData)scEnabledButton.getLayoutData()).horizontalSpan = numColumns; ((GridData)scEnabledButton.getLayoutData()).grabExcessHorizontalSpace = true; // VMIR* old projects will have discovery disabled by default - scEnabledButton.setSelection(needsSCNature ? false - : (getBuildInfo().isAutoDiscoveryEnabled() + boolean autodiscoveryEnabled2 = getBuildInfo().isAutoDiscoveryEnabled(); + if (autodiscoveryEnabled2) { + ICProjectDescription projDesc = CoreModel.getDefault().getProjectDescription(getProject()); + ICConfigurationDescription cfgDescription = projDesc.getActiveConfiguration(); + autodiscoveryEnabled2 = ScannerDiscoveryLegacySupport.isMbsLanguageSettingsProviderOn(cfgDescription); + } + scEnabledButton.setSelection(needsSCNature ? false + : (autodiscoveryEnabled2 && !getBuildInfo().getSelectedProfileId().equals(ScannerConfigProfileManager.NULL_PROFILE_ID))); scEnabledButton.addSelectionListener(new SelectionAdapter() { @Override diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/build/core/scannerconfig/ScannerConfigBuilder.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/build/core/scannerconfig/ScannerConfigBuilder.java index e20b258eb67..d58dd7b3563 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/build/core/scannerconfig/ScannerConfigBuilder.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/build/core/scannerconfig/ScannerConfigBuilder.java @@ -20,6 +20,7 @@ import org.eclipse.cdt.build.internal.core.scannerconfig2.CfgScannerConfigProfil import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.envvar.IEnvironmentVariable; import org.eclipse.cdt.core.envvar.IEnvironmentVariableManager; +import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySupport; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.resources.ACBuilder; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; @@ -180,7 +181,11 @@ public class ScannerConfigBuilder extends ACBuilder { public static SCProfileInstance build(CfgInfoContext context, IScannerConfigBuilderInfo2 buildInfo2, int flags, Properties env, IProgressMonitor monitor) throws CoreException{ IConfiguration cfg = context.getConfiguration(); IProject project = cfg.getOwner().getProject(); - boolean autodiscoveryEnabled2 = buildInfo2.isAutoDiscoveryEnabled(); + boolean autodiscoveryEnabled2 = buildInfo2.isAutoDiscoveryEnabled(); + if (autodiscoveryEnabled2) { + ICConfigurationDescription cfgDescription = ManagedBuildManager.getDescriptionForConfiguration(cfg); + autodiscoveryEnabled2 = ScannerDiscoveryLegacySupport.isMbsLanguageSettingsProviderOn(cfgDescription); + } if (autodiscoveryEnabled2 || ((flags & FORCE_DISCOVERY) != 0)) { monitor.beginTask(MakeMessages.getString("ScannerConfigBuilder.Invoking_Builder"), 100); //$NON-NLS-1$ diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/build/internal/core/scannerconfig/CfgScannerConfigUtil.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/build/internal/core/scannerconfig/CfgScannerConfigUtil.java index 6c27670a7b6..bc1bf490785 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/build/internal/core/scannerconfig/CfgScannerConfigUtil.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/build/internal/core/scannerconfig/CfgScannerConfigUtil.java @@ -159,7 +159,12 @@ public class CfgScannerConfigUtil { Set profiles = new TreeSet(); if (toolchain!=null) { - String toolchainProfileId = toolchain.getScannerConfigDiscoveryProfileId(); + String toolchainProfileId = null; + if (toolchain instanceof ToolChain) { + toolchainProfileId = ((ToolChain) toolchain).getLegacyScannerConfigDiscoveryProfileId(); + } else { + toolchainProfileId = toolchain.getScannerConfigDiscoveryProfileId(); + } if (toolchainProfileId!=null && toolchainProfileId.length()>0) { profiles.add(toolchainProfileId); } @@ -227,7 +232,7 @@ public class CfgScannerConfigUtil { Set profiles = new TreeSet(); - String attribute = ((InputType) inputType).getDiscoveryProfileIdAttribute(); + String attribute = ((InputType) inputType).getLegacyDiscoveryProfileIdAttribute(); if (attribute!=null) { // FIXME: temporary; we should add new method to IInputType instead of that for (String profileId : attribute.split("\\|")) { //$NON-NLS-1$ diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/build/internal/core/scannerconfig2/CfgScannerConfigProfileManager.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/build/internal/core/scannerconfig2/CfgScannerConfigProfileManager.java index 632659b2a55..bef0ef6047f 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/build/internal/core/scannerconfig2/CfgScannerConfigProfileManager.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/build/internal/core/scannerconfig2/CfgScannerConfigProfileManager.java @@ -10,14 +10,8 @@ *******************************************************************************/ package org.eclipse.cdt.build.internal.core.scannerconfig2; -import java.util.Collection; -import java.util.Map; - import org.eclipse.cdt.build.core.scannerconfig.CfgInfoContext; import org.eclipse.cdt.build.core.scannerconfig.ICfgScannerConfigBuilderInfo2Set; -import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; -import org.eclipse.cdt.core.settings.model.ICProjectDescription; -import org.eclipse.cdt.make.core.scannerconfig.IScannerConfigBuilderInfo2; import org.eclipse.cdt.make.core.scannerconfig.InfoContext; import org.eclipse.cdt.make.core.scannerconfig.ScannerConfigScope; import org.eclipse.cdt.make.internal.core.scannerconfig2.ScannerConfigProfile; @@ -50,34 +44,4 @@ public class CfgScannerConfigProfileManager { return new CfgInfoContext(cfg).toInfoContext(); return new InfoContext(project); } - - public static boolean disableScannerDiscovery(IConfiguration cfg) { - boolean isChanged = false; - - ICfgScannerConfigBuilderInfo2Set info2set = getCfgScannerConfigBuildInfo(cfg); - Map infoMap = info2set.getInfoMap(); - Collection infos = infoMap.values(); - for (IScannerConfigBuilderInfo2 info2 : infos) { - isChanged = isChanged || info2.isAutoDiscoveryEnabled(); - info2.setAutoDiscoveryEnabled(false); - } - return isChanged; - } - - public static boolean disableScannerDiscovery(ICProjectDescription prjDescription) { - boolean isChanged = false; - - ICConfigurationDescription[] cfgDescs = prjDescription.getConfigurations(); - if (cfgDescs!=null) { - for (ICConfigurationDescription cfgDesc : cfgDescs) { - IConfiguration cfg = ManagedBuildManager.getConfigurationForDescription(cfgDesc); - boolean changed=CfgScannerConfigProfileManager.disableScannerDiscovery(cfg); - if (changed) { - isChanged = true; - } - - } - } - return isChanged; - } } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ExternalBuildRunner.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ExternalBuildRunner.java index 171046d3e2c..f518772b791 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ExternalBuildRunner.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ExternalBuildRunner.java @@ -34,6 +34,7 @@ import org.eclipse.cdt.core.envvar.IEnvironmentVariableManager; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager_TBD; +import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySupport; import org.eclipse.cdt.core.model.ICModelMarker; import org.eclipse.cdt.core.resources.IConsole; import org.eclipse.cdt.core.resources.RefreshScopeManager; @@ -439,28 +440,34 @@ public class ExternalBuildRunner extends AbstractBuildRunner { IScannerConfigBuilderInfo2 info = map.get(context); InfoContext ic = context.toInfoContext(); boolean added = false; - if (info != null && - info.isAutoDiscoveryEnabled() && - info.isBuildOutputParserEnabled()) { + if (info != null) { + boolean autodiscoveryEnabled2 = info.isAutoDiscoveryEnabled(); + if (autodiscoveryEnabled2) { + IConfiguration cfg = context.getConfiguration(); + ICConfigurationDescription cfgDescription = ManagedBuildManager.getDescriptionForConfiguration(cfg); + autodiscoveryEnabled2 = ScannerDiscoveryLegacySupport.isMbsLanguageSettingsProviderOn(cfgDescription); + } + if (autodiscoveryEnabled2 && info.isBuildOutputParserEnabled()) { - String id = info.getSelectedProfileId(); - ScannerConfigProfile profile = ScannerConfigProfileManager.getInstance().getSCProfileConfiguration(id); - if(profile.getBuildOutputProviderElement() != null){ - // get the make builder console parser - SCProfileInstance profileInstance = ScannerConfigProfileManager.getInstance(). - getSCProfileInstance(project, ic, id); + String id = info.getSelectedProfileId(); + ScannerConfigProfile profile = ScannerConfigProfileManager.getInstance().getSCProfileConfiguration(id); + if(profile.getBuildOutputProviderElement() != null){ + // get the make builder console parser + SCProfileInstance profileInstance = ScannerConfigProfileManager.getInstance(). + getSCProfileInstance(project, ic, id); - IScannerInfoConsoleParser clParser = profileInstance.createBuildOutputParser(); - if (collector == null) { - collector = profileInstance.getScannerInfoCollector(); - } - if(clParser != null){ - clParser.startup(project, workingDirectory, collector, - info.isProblemReportingEnabled() ? markerGenerator : null); - parserList.add(clParser); - added = true; - } + IScannerInfoConsoleParser clParser = profileInstance.createBuildOutputParser(); + if (collector == null) { + collector = profileInstance.getScannerInfoCollector(); + } + if(clParser != null){ + clParser.startup(project, workingDirectory, collector, + info.isProblemReportingEnabled() ? markerGenerator : null); + parserList.add(clParser); + added = true; + } + } } } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/InputType.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/InputType.java index d2088edbfc4..946068c736f 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/InputType.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/InputType.java @@ -17,11 +17,13 @@ import java.util.List; import java.util.StringTokenizer; import java.util.Vector; +import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySupport; import org.eclipse.cdt.core.settings.model.ICStorageElement; import org.eclipse.cdt.core.settings.model.util.CDataUtil; import org.eclipse.cdt.internal.core.SafeStringInterner; import org.eclipse.cdt.managedbuilder.core.IAdditionalInput; import org.eclipse.cdt.managedbuilder.core.IBuildObject; +import org.eclipse.cdt.managedbuilder.core.IConfiguration; import org.eclipse.cdt.managedbuilder.core.IFileInfo; import org.eclipse.cdt.managedbuilder.core.IInputOrder; import org.eclipse.cdt.managedbuilder.core.IInputType; @@ -35,14 +37,15 @@ import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; import org.eclipse.cdt.managedbuilder.internal.enablement.OptionEnablementExpression; import org.eclipse.cdt.managedbuilder.makegen.IManagedDependencyGeneratorType; import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; -import org.osgi.framework.Version; import org.eclipse.core.runtime.content.IContentType; import org.eclipse.core.runtime.content.IContentTypeManager; +import org.osgi.framework.Version; public class InputType extends BuildObject implements IInputType { @@ -1774,9 +1777,56 @@ public class InputType extends BuildObject implements IInputType { return id; } + /** + * Temporary method to support compatibility during SD transition. + */ + private boolean isLanguageSettingsProvidersFunctionalityEnabled() { + boolean isLanguageSettingsProvidersEnabled = false; + ITool tool = getParent(); + if (tool!=null) { + IBuildObject bo = tool.getParent(); + if (bo instanceof IToolChain) { + IConfiguration cfg = ((IToolChain) bo).getParent(); + if (cfg!=null) { + IResource rc = cfg.getOwner(); + if (rc!=null) { + IProject project = rc.getProject(); + isLanguageSettingsProvidersEnabled = ScannerDiscoveryLegacySupport.isLanguageSettingsProvidersFunctionalityEnabled(project); + } + } + } + } + return isLanguageSettingsProvidersEnabled; + } + + /** + * Temporary method to support compatibility during SD transition. + * @noreference This method is not intended to be referenced by clients. + */ + public String getLegacyDiscoveryProfileIdAttribute(){ + String profileId = buildInfoDicsoveryProfileId; + if (profileId == null) { + profileId = ScannerDiscoveryLegacySupport.getDeprecatedLegacyProfiles(id); + if (profileId == null && superClass instanceof InputType) { + profileId = ((InputType)superClass).getLegacyDiscoveryProfileIdAttribute(); + } + } + return profileId; + } + public String getDiscoveryProfileIdAttribute(){ - if(buildInfoDicsoveryProfileId == null && superClass != null) - return ((InputType)superClass).getDiscoveryProfileIdAttribute(); + if (!isLanguageSettingsProvidersFunctionalityEnabled()) + return getLegacyDiscoveryProfileIdAttribute(); + + return getDiscoveryProfileIdAttributeInternal(); + } + + /** + * Method extracted temporarily to support compatibility during SD transition. + */ + private String getDiscoveryProfileIdAttributeInternal(){ + if(buildInfoDicsoveryProfileId == null && superClass instanceof InputType) + return ((InputType)superClass).getDiscoveryProfileIdAttributeInternal(); return buildInfoDicsoveryProfileId; } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolChain.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolChain.java index fb0bca68433..d9204d3aa89 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolChain.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolChain.java @@ -24,6 +24,7 @@ import java.util.SortedMap; import java.util.StringTokenizer; import org.eclipse.cdt.build.internal.core.scannerconfig.CfgDiscoveredPathManager.PathInfoCache; +import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySupport; import org.eclipse.cdt.core.settings.model.ICStorageElement; import org.eclipse.cdt.core.settings.model.extension.CTargetPlatformData; import org.eclipse.cdt.core.settings.model.util.CDataUtil; @@ -50,6 +51,8 @@ import org.eclipse.cdt.managedbuilder.envvar.IConfigurationEnvironmentVariableSu import org.eclipse.cdt.managedbuilder.internal.dataprovider.ConfigurationDataProvider; import org.eclipse.cdt.managedbuilder.internal.enablement.OptionEnablementExpression; import org.eclipse.cdt.managedbuilder.macros.IConfigurationBuildMacroSupplier; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtension; @@ -1509,18 +1512,62 @@ public class ToolChain extends HoldsOptions implements IToolChain, IMatchKeyProv return defaultLanguageSettingsProvidersIds; } - /* (non-Javadoc) - * @see org.eclipse.cdt.managedbuilder.core.IToolChain#getScannerConfigDiscoveryProfileId() - */ - public String getScannerConfigDiscoveryProfileId() { - if (scannerConfigDiscoveryProfileId == null) { - if (getSuperClass() != null) { - return getSuperClass().getScannerConfigDiscoveryProfileId(); - } - } - return scannerConfigDiscoveryProfileId; - } + /** + * Temporary method to support compatibility during SD transition. + */ + private boolean isLanguageSettingsProvidersFunctionalityEnabled() { + boolean isLanguageSettingsProvidersEnabled = false; + IConfiguration cfg = getParent(); + if (cfg!=null) { + IResource rc = cfg.getOwner(); + if (rc!=null) { + IProject project = rc.getProject(); + isLanguageSettingsProvidersEnabled = ScannerDiscoveryLegacySupport.isLanguageSettingsProvidersFunctionalityEnabled(project); + } + } + return isLanguageSettingsProvidersEnabled; + } + /** + * Temporary method to support compatibility during SD transition. + * @noreference This method is not intended to be referenced by clients. + */ + public String getLegacyScannerConfigDiscoveryProfileId() { + String profileId = scannerConfigDiscoveryProfileId; + if (profileId==null) { + profileId = ScannerDiscoveryLegacySupport.getDeprecatedLegacyProfiles(id); + if (profileId == null) { + IToolChain superClass = getSuperClass(); + if (superClass instanceof ToolChain) { + profileId = ((ToolChain) superClass).getLegacyScannerConfigDiscoveryProfileId(); + } + } + } + return profileId; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.managedbuilder.core.IToolChain#getScannerConfigDiscoveryProfileId() + */ + public String getScannerConfigDiscoveryProfileId() { + if (!isLanguageSettingsProvidersFunctionalityEnabled()) + return getLegacyScannerConfigDiscoveryProfileId(); + + return getScannerConfigDiscoveryProfileIdInternal(); + } + + /** + * Method extracted temporarily to support compatibility during SD transition. + */ + private String getScannerConfigDiscoveryProfileIdInternal() { + if (scannerConfigDiscoveryProfileId == null && superClass instanceof ToolChain) { + return ((ToolChain) getSuperClass()).getScannerConfigDiscoveryProfileIdInternal(); + } + return scannerConfigDiscoveryProfileId; + } + /* (non-Javadoc) * @see org.eclipse.cdt.managedbuilder.core.IToolChain#setScannerConfigDiscoveryProfileId(java.lang.String) */ diff --git a/build/org.eclipse.cdt.managedbuilder.gnu.ui/plugin.xml b/build/org.eclipse.cdt.managedbuilder.gnu.ui/plugin.xml index c4788810994..fe404978003 100644 --- a/build/org.eclipse.cdt.managedbuilder.gnu.ui/plugin.xml +++ b/build/org.eclipse.cdt.managedbuilder.gnu.ui/plugin.xml @@ -1253,7 +1253,6 @@ dependencyExtensions="h" dependencyCalculator="org.eclipse.cdt.managedbuilder.makegen.gnu.DefaultGCCDependencyCalculator2" id="cdt.managedbuild.tool.gnu.c.compiler.input" - scannerConfigDiscoveryProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileC|org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile" languageId="org.eclipse.cdt.core.gcc"> + /> + /> baseInfoMap; @@ -116,6 +121,8 @@ public class DiscoveryTab extends AbstractCBuildPropertyTab implements IBuildInf private DiscoveryPageWrapper wrapper = null; + private StatusMessageLine fStatusLine; + /* * (non-Javadoc) * @@ -184,6 +191,9 @@ public class DiscoveryTab extends AbstractCBuildPropertyTab implements IBuildInf profileOptionsComposite.setLayoutData(gd); profileOptionsComposite.setLayout(new TabFolderLayout()); + fStatusLine = new StatusMessageLine(usercomp, SWT.LEFT, 2); + setEnablement(); + sashForm.setWeights(DEFAULT_SASH_WEIGHTS); } @@ -236,7 +246,7 @@ public class DiscoveryTab extends AbstractCBuildPropertyTab implements IBuildInf Label clearLabel = ControlFactory.createLabel(autoDiscoveryGroup, Messages.DiscoveryTab_ClearDisoveredEntries); // "Clear" button - Button clearButton = ControlFactory.createPushButton(autoDiscoveryGroup, Messages.DiscoveryTab_Clear); + clearButton = ControlFactory.createPushButton(autoDiscoveryGroup, Messages.DiscoveryTab_Clear); GridData gd = (GridData) clearButton.getLayoutData(); gd.grabExcessHorizontalSpace = true; //Bug 331783 - NLS: "Clear" button label in Makefile Project preferences truncated @@ -334,6 +344,27 @@ public class DiscoveryTab extends AbstractCBuildPropertyTab implements IBuildInf } else { setVisibility(Messages.DiscoveryTab_6); } + + setEnablement(); + } + + private void setEnablement() { + IStatus status = null; + ICConfigurationDescription cfgDescription = page.getResDesc().getConfiguration(); + boolean isEnabled = ScannerDiscoveryLegacySupport.isMbsLanguageSettingsProviderOn(cfgDescription); + if (!isEnabled) { + status = new Status(IStatus.INFO, CUIPlugin.PLUGIN_ID, "Managed Build language settings provider is not enabled."); + } + + scopeComboBox.setEnabled(isEnabled); + resTable.setEnabled(isEnabled); + boolean isSCDEnabled = autoDiscoveryCheckBox.getSelection(); + reportProblemsCheckBox.setEnabled(isEnabled && isSCDEnabled); + autoDiscoveryCheckBox.setEnabled(isEnabled); + autoDiscoveryGroup.setEnabled(isEnabled); + clearButton.setEnabled(isEnabled); + + fStatusLine.setErrorStatus(status); } private void setVisibility(String errMsg) { @@ -372,7 +403,13 @@ public class DiscoveryTab extends AbstractCBuildPropertyTab implements IBuildInf buildInfo = (IScannerConfigBuilderInfo2) ti.getData("info"); //$NON-NLS-1$ String selectedProfileId = buildInfo.getSelectedProfileId(); iContext = (CfgInfoContext) ti.getData("cont"); //$NON-NLS-1$ - autoDiscoveryCheckBox.setSelection(buildInfo.isAutoDiscoveryEnabled() + boolean autodiscoveryEnabled2 = buildInfo.isAutoDiscoveryEnabled(); + if (autodiscoveryEnabled2) { + IConfiguration cfg = iContext.getConfiguration(); + ICConfigurationDescription cfgDescription = ManagedBuildManager.getDescriptionForConfiguration(cfg); + autodiscoveryEnabled2 = ScannerDiscoveryLegacySupport.isMbsLanguageSettingsProviderOn(cfgDescription); + } + autoDiscoveryCheckBox.setSelection(autodiscoveryEnabled2 && !selectedProfileId.equals(ScannerConfigProfileManager.NULL_PROFILE_ID)); reportProblemsCheckBox.setSelection(buildInfo.isProblemReportingEnabled()); diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/MBSWizardHandler.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/MBSWizardHandler.java index ef874834d15..1476aa919e8 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/MBSWizardHandler.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/MBSWizardHandler.java @@ -26,6 +26,7 @@ import java.util.TreeSet; import org.eclipse.cdt.build.internal.core.scannerconfig2.CfgScannerConfigProfileManager; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; +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; @@ -605,9 +606,8 @@ public class MBSWizardHandler extends CWizardHandler { if (cfgFirst == null) // select at least first configuration cfgFirst = cfgDes; + ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, isTryingNewSD); if (isTryingNewSD) { - CfgScannerConfigProfileManager.disableScannerDiscovery(config); - List providers = ManagedBuildManager.getLanguageSettingsProviders(config); cfgDes.setLanguageSettingProviders(providers); } else { @@ -620,16 +620,6 @@ public class MBSWizardHandler extends CWizardHandler { monitor.worked(work); } mngr.setProjectDescription(project, des); - - // FIXME if scanner discovery is empty it is "fixed" deeply inside setProjectDescription(), taking the easy road here for the moment - if (isTryingNewSD) { - des = mngr.getProjectDescription(project); - boolean isChanged = CfgScannerConfigProfileManager.disableScannerDiscovery(des); - - if (isChanged) { - mngr.setProjectDescription(project, des); - } - } } @Override diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/NewMakeProjFromExisting.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/NewMakeProjFromExisting.java index 666a8dce04f..d7b13a88ae3 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/NewMakeProjFromExisting.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/NewMakeProjFromExisting.java @@ -14,11 +14,11 @@ import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.List; -import org.eclipse.cdt.build.internal.core.scannerconfig2.CfgScannerConfigProfileManager; import org.eclipse.cdt.core.CCProjectNature; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; +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; @@ -118,9 +118,8 @@ public class NewMakeProjFromExisting extends Wizard implements IImportWizard, IN CConfigurationData data = config.getConfigurationData(); ICConfigurationDescription cfgDes = projDesc.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID, data); + ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, isTryingNewSD); if (isTryingNewSD) { - CfgScannerConfigProfileManager.disableScannerDiscovery(config); - List providers = ManagedBuildManager.getLanguageSettingsProviders(config); cfgDes.setLanguageSettingProviders(providers); } else { @@ -130,25 +129,12 @@ public class NewMakeProjFromExisting extends Wizard implements IImportWizard, IN cfgDes.setLanguageSettingProviders(providers); } - monitor.worked(1); pdMgr.setProjectDescription(project, projDesc); - - // FIXME if scanner discovery is empty it is "fixed" deeply inside setProjectDescription(), taking the easy road here for the moment - if (isTryingNewSD) { - ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager(); - ICProjectDescription des = mngr.getProjectDescription(project); - boolean isChanged = CfgScannerConfigProfileManager.disableScannerDiscovery(des); - - if (isChanged) { - mngr.setProjectDescription(project, des); - } - } } catch (Throwable e) { ManagedBuilderUIPlugin.log(e); } - monitor.done(); } }; diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/STDWizardHandler.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/STDWizardHandler.java index 83951ab46c9..cb515055f89 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/STDWizardHandler.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/STDWizardHandler.java @@ -14,9 +14,9 @@ package org.eclipse.cdt.managedbuilder.ui.wizards; import java.util.ArrayList; import java.util.List; -import org.eclipse.cdt.build.internal.core.scannerconfig2.CfgScannerConfigProfileManager; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; +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; @@ -118,9 +118,8 @@ public class STDWizardHandler extends MBSWizardHandler { CConfigurationData data = cfg.getConfigurationData(); ICConfigurationDescription cfgDes = des.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID, data); + ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, isTryingNewSD); if (isTryingNewSD) { - CfgScannerConfigProfileManager.disableScannerDiscovery(cfg); - List providers = ManagedBuildManager.getLanguageSettingsProviders(cfg); cfgDes.setLanguageSettingProviders(providers); } else { @@ -133,16 +132,6 @@ public class STDWizardHandler extends MBSWizardHandler { monitor.worked(work); } mngr.setProjectDescription(project, des); - - // FIXME if scanner discovery is empty it is "fixed" deeply inside setProjectDescription(), taking the easy road here for the moment - if (isTryingNewSD) { - des = mngr.getProjectDescription(project); - boolean isChanged = CfgScannerConfigProfileManager.disableScannerDiscovery(des); - - if (isChanged) { - mngr.setProjectDescription(project, des); - } - } } public boolean canCreateWithoutToolchain() { return true; } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java index 3007beeb376..38cb0717062 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Andrew Gvozdev (Quoin Inc.) and others. + * Copyright (c) 2009, 2011 Andrew Gvozdev (Quoin Inc.) 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 @@ -13,7 +13,6 @@ package org.eclipse.cdt.core.language.settings.providers; import java.util.List; -import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICSettingEntry; @@ -25,7 +24,6 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.preferences.InstanceScope; -import org.osgi.service.prefs.BackingStoreException; import org.osgi.service.prefs.Preferences; /** @@ -35,13 +33,6 @@ import org.osgi.service.prefs.Preferences; * @since 6.0 */ public class LanguageSettingsManager { - /** @noreference This field is temporary and not intended to be referenced by clients. */ - public static String USE_LANGUAGE_SETTINGS_PROVIDERS_PREFERENCE = "enabled"; //$NON-NLS-1$ - public static boolean USE_LANGUAGE_SETTINGS_PROVIDERS_DEFAULT = true; - - private static final String PREFERENCES_QUALIFIER = CCorePlugin.PLUGIN_ID; - private static final String LANGUAGE_SETTINGS_PROVIDERS_NODE = "languageSettingsProviders"; //$NON-NLS-1$ - /** * Returns the list of setting entries of the given provider * for the given configuration description, resource and language. @@ -176,42 +167,4 @@ public class LanguageSettingsManager { return provider; } - private static Preferences getPreferences(IProject project) { - if (project == null) - return InstanceScope.INSTANCE.getNode(PREFERENCES_QUALIFIER).node(LANGUAGE_SETTINGS_PROVIDERS_NODE); - else - return new LocalProjectScope(project).getNode(PREFERENCES_QUALIFIER).node(LANGUAGE_SETTINGS_PROVIDERS_NODE); - } - - /** - * Checks if Language Settings functionality is enabled for given project. - * - * @param project - project to check the preference - * @return {@code true} if functionality is enabled - * - * @noreference This method is temporary and not intended to be referenced by clients. - */ - public static boolean isLanguageSettingsProvidersEnabled(IProject project) { - Preferences pref = LanguageSettingsManager.getPreferences(project); - return pref.getBoolean(LanguageSettingsManager.USE_LANGUAGE_SETTINGS_PROVIDERS_PREFERENCE, LanguageSettingsManager.USE_LANGUAGE_SETTINGS_PROVIDERS_DEFAULT); - } - - /** - * Enable/disable Language Settings functionality for the given project. - * - * @param project - * @param value {@code true} to enable or {@code false} to disable the functionality. - * - * @noreference This method is temporary and not intended to be referenced by clients. - */ - public static void setLanguageSettingsProvidersEnabled(IProject project, boolean value) { - Preferences pref = LanguageSettingsManager.getPreferences(project); - pref.putBoolean(LanguageSettingsManager.USE_LANGUAGE_SETTINGS_PROVIDERS_PREFERENCE, value); - try { - pref.flush(); - } catch (BackingStoreException e) { - CCorePlugin.log(e); - } - } - } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ScannerDiscoveryLegacySupport.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ScannerDiscoveryLegacySupport.java new file mode 100644 index 00000000000..42dc4595b58 --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ScannerDiscoveryLegacySupport.java @@ -0,0 +1,125 @@ +/******************************************************************************* + * Copyright (c) 2009, 2011 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.core.language.settings.providers; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.internal.core.LocalProjectScope; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.preferences.InstanceScope; +import org.osgi.service.prefs.BackingStoreException; +import org.osgi.service.prefs.Preferences; + +/** + * Collection of utilities for legacy support of older Scanner Discovery functionality. + * This class is temporary and not intended to be used by clients. + * + * @noextend This class is not intended to be subclassed by clients. + * @noinstantiate This class is not intended to be instantiated by clients. + */ +public class ScannerDiscoveryLegacySupport { + /** Name of MBS language settings provider (from org.eclipse.cdt.managedbuilder.core) */ + public static final String MBS_LANGUAGE_SETTINGS_PROVIDER = "org.eclipse.cdt.managedbuilder.core.LanguageSettingsProvider"; //$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 + private static boolean USE_LANGUAGE_SETTINGS_PROVIDERS_DEFAULT = false; + private static final String PREFERENCES_QUALIFIER = CCorePlugin.PLUGIN_ID; + private static final String LANGUAGE_SETTINGS_PROVIDERS_NODE = "languageSettingsProviders"; //$NON-NLS-1$ + + private static Map legacyProfiles = null; + + + private static Preferences getPreferences(IProject project) { + if (project == null) + return InstanceScope.INSTANCE.getNode(PREFERENCES_QUALIFIER).node(LANGUAGE_SETTINGS_PROVIDERS_NODE); + else + return new LocalProjectScope(project).getNode(PREFERENCES_QUALIFIER).node(LANGUAGE_SETTINGS_PROVIDERS_NODE); + } + + /** + * Checks if Language Settings functionality is enabled for given project. + * + * @param project - project to check the preference + * @return {@code true} if functionality is enabled + * + * @noreference This method is temporary and not intended to be referenced by clients. + */ + public static boolean isLanguageSettingsProvidersFunctionalityEnabled(IProject project) { + Preferences pref = getPreferences(project); + return pref.getBoolean(USE_LANGUAGE_SETTINGS_PROVIDERS_PREFERENCE, USE_LANGUAGE_SETTINGS_PROVIDERS_DEFAULT); + } + + /** + * Enable/disable Language Settings functionality for the given project. + * + * @param project + * @param value {@code true} to enable or {@code false} to disable the functionality. + * + * @noreference This method is temporary and not intended to be referenced by clients. + */ + public static void setLanguageSettingsProvidersFunctionalityEnabled(IProject project, boolean value) { + Preferences pref = getPreferences(project); + pref.putBoolean(USE_LANGUAGE_SETTINGS_PROVIDERS_PREFERENCE, value); + try { + pref.flush(); + } catch (BackingStoreException e) { + CCorePlugin.log(e); + } + } + + /** + * @noreference This is internal helper method to support compatibility with previous versions + * which is not intended to be referenced by clients. + */ + public static boolean isMbsLanguageSettingsProviderOn(ICConfigurationDescription cfgDescription) { + List lsProviders = cfgDescription.getLanguageSettingProviders(); + for (ILanguageSettingsProvider lsp : lsProviders) { + if (MBS_LANGUAGE_SETTINGS_PROVIDER.equals(lsp.getId())) { + return true; + } + } + return false; + } + + /** + * Returns the values of scanner discovery profiles (scannerConfigDiscoveryProfileId) which were deprecated + * and replaced with language settings providers in plugin.xml. + * This (temporary) function serves as fail-safe switch during the transition. + * + * @param id - can be id of either org.eclipse.cdt.managedbuilder.internal.core.InputType + * or org.eclipse.cdt.managedbuilder.internal.core.ToolChain. + * @return legacy scannerConfigDiscoveryProfileId. + */ + @SuppressWarnings("nls") + public static String getDeprecatedLegacyProfiles(String id) { + if (legacyProfiles == null) { + legacyProfiles = new HashMap(); + + // InputTypes + legacyProfiles.put("cdt.managedbuild.tool.gnu.c.compiler.input", "org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileC|org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile"); + legacyProfiles.put("cdt.managedbuild.tool.gnu.cpp.compiler.input", "org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileCPP|org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile"); + legacyProfiles.put("cdt.managedbuild.tool.gnu.c.compiler.input.cygwin", "org.eclipse.cdt.managedbuilder.core.GCCWinManagedMakePerProjectProfileC"); + legacyProfiles.put("cdt.managedbuild.tool.gnu.cpp.compiler.input.cygwin", "org.eclipse.cdt.managedbuilder.core.GCCWinManagedMakePerProjectProfileCPP"); + + // Toolchains +// legacyProfiles.put(, ); + } + + return legacyProfiles.get(id); + } + +} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/PathEntryTranslator.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/PathEntryTranslator.java index e7a41760ebb..3cd067e61ba 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/PathEntryTranslator.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/PathEntryTranslator.java @@ -27,6 +27,7 @@ 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.LanguageSettingsManager; +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; @@ -2091,7 +2092,7 @@ public class PathEntryTranslator { IProject project = des.getProjectDescription().getProject(); - if (LanguageSettingsManager.isLanguageSettingsProvidersEnabled(project)) { + if (ScannerDiscoveryLegacySupport.isLanguageSettingsProvidersFunctionalityEnabled(project)) { IResource rc = getResource(project, data.getPath()); for (CLanguageData lData : lDatas) { list.addAll(LanguageSettingsManager.getSettingEntriesByKind(des, rc, lData.getLanguageId(), kind)); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java index 231a52a16e6..c5b204df57f 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Andrew Gvozdev (Quoin Inc.) and others. + * Copyright (c) 2009, 2011 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 (Quoin Inc.) - initial API and implementation + * Andrew Gvozdev - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.internal.core.language.settings.providers; @@ -53,9 +53,9 @@ import org.eclipse.core.runtime.Status; */ public class LanguageSettingsExtensionManager { /** Name of the extension point for contributing language settings */ - final static String PROVIDER_EXTENSION_FULL_ID = "org.eclipse.cdt.core.LanguageSettingsProvider"; //$NON-NLS-1$ - final static String PROVIDER_EXTENSION_SIMPLE_ID = "LanguageSettingsProvider"; //$NON-NLS-1$ - + static final String PROVIDER_EXTENSION_FULL_ID = "org.eclipse.cdt.core.LanguageSettingsProvider"; //$NON-NLS-1$ + static final String PROVIDER_EXTENSION_SIMPLE_ID = "LanguageSettingsProvider"; //$NON-NLS-1$ + static final String ELEM_PROVIDER = "provider"; //$NON-NLS-1$ static final String ATTR_CLASS = "class"; //$NON-NLS-1$ static final String ATTR_ID = "id"; //$NON-NLS-1$ @@ -613,4 +613,5 @@ public class LanguageSettingsExtensionManager { return provider.equals(extensionProvider); } + } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java index 7e1056d4450..f971d336b3c 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java @@ -20,6 +20,7 @@ import java.util.Map; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable; +import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySupport; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICProjectDescription; @@ -46,7 +47,6 @@ public class LanguageSettingsProvidersSerializer { private static final String SETTINGS_FOLDER_NAME = ".settings/"; //$NON-NLS-1$ private static final String STORAGE_PROJECT_LANGUAGE_SETTINGS = "language.settings.xml"; //$NON-NLS-1$ public static final char PROVIDER_DELIMITER = ';'; - private static final String MBS_LANGUAGE_SETTINGS_PROVIDER = "org.eclipse.cdt.managedbuilder.core.LanguageSettingsProvider"; private static final String ELEM_PLUGIN = "plugin"; //$NON-NLS-1$ private static final String ELEM_EXTENSION = "extension"; //$NON-NLS-1$ private static final String ATTR_POINT = "point"; //$NON-NLS-1$ @@ -535,7 +535,7 @@ public class LanguageSettingsProvidersSerializer { for (ICConfigurationDescription cfgDescription : cfgDescriptions) { if (cfgDescription!=null) { List providers = new ArrayList(2); - ILanguageSettingsProvider userProvider = getWorkspaceProvider(MBS_LANGUAGE_SETTINGS_PROVIDER); + ILanguageSettingsProvider userProvider = getWorkspaceProvider(ScannerDiscoveryLegacySupport.MBS_LANGUAGE_SETTINGS_PROVIDER); providers.add(userProvider); cfgDescription.setLanguageSettingProviders(providers); } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/ScannerInfoProviderProxy.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/ScannerInfoProviderProxy.java index 64cf620e576..d94f7562faa 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/ScannerInfoProviderProxy.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/ScannerInfoProviderProxy.java @@ -16,7 +16,7 @@ import java.util.List; import java.util.Map; import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; +import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySupport; import org.eclipse.cdt.core.parser.IScannerInfo; import org.eclipse.cdt.core.parser.IScannerInfoChangeListener; import org.eclipse.cdt.core.parser.IScannerInfoProvider; @@ -39,7 +39,7 @@ public class ScannerInfoProviderProxy extends AbstractCExtensionProxy implements } public IScannerInfo getScannerInformation(IResource resource) { - if (LanguageSettingsManager.isLanguageSettingsProvidersEnabled(getProject())) { + if (ScannerDiscoveryLegacySupport.isLanguageSettingsProvidersFunctionalityEnabled(getProject())) { LanguageSettingsScannerInfoProvider lsProvider = new LanguageSettingsScannerInfoProvider(); return lsProvider.getScannerInformation(resource); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java index 09c5ab848ca..00ed09ddbf8 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java @@ -49,6 +49,7 @@ import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsBaseProv import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager_TBD; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable; +import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySupport; import org.eclipse.cdt.core.model.ILanguageDescriptor; import org.eclipse.cdt.core.model.LanguageManager; import org.eclipse.cdt.core.model.util.CDTListComparator; @@ -66,6 +67,7 @@ import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.newui.AbstractCPropertyTab; import org.eclipse.cdt.ui.newui.CDTPrefUtil; + import org.eclipse.cdt.internal.ui.newui.LanguageSettingsImages; import org.eclipse.cdt.internal.ui.newui.Messages; import org.eclipse.cdt.internal.ui.newui.StatusMessageLine; @@ -401,7 +403,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { initialProvidersMap.put(cfgId, initialProviders); } } - initialEnablement = LanguageSettingsManager.isLanguageSettingsProvidersEnabled(page.getProject()); + initialEnablement = ScannerDiscoveryLegacySupport.isLanguageSettingsProvidersFunctionalityEnabled(page.getProject()); } } @@ -452,7 +454,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { if (masterPropertyPage!=null) enableProvidersCheckBox.setSelection(masterPropertyPage.isLanguageSettingsProvidersEnabled()); else - enableProvidersCheckBox.setSelection(LanguageSettingsManager.isLanguageSettingsProvidersEnabled(page.getProject())); + enableProvidersCheckBox.setSelection(ScannerDiscoveryLegacySupport.isLanguageSettingsProvidersFunctionalityEnabled(page.getProject())); // display but disable the checkbox for file/folder resource enableProvidersCheckBox.setEnabled(page.isForProject()/* && !isConfigureMode*/); enableControls(enableProvidersCheckBox.getSelection()); @@ -1058,7 +1060,7 @@ providers: for (ILanguageSettingsProvider provider : providers) { boolean enabled = enableProvidersCheckBox.getSelection(); if (masterPropertyPage!=null) enabled = masterPropertyPage.isLanguageSettingsProvidersEnabled(); - LanguageSettingsManager.setLanguageSettingsProvidersEnabled(page.getProject(), enabled); + ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(page.getProject(), enabled); enableProvidersCheckBox.setSelection(enabled); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java index 5b3f2a35f12..197f902266e 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java @@ -49,6 +49,7 @@ import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvide import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager_TBD; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable; +import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySupport; import org.eclipse.cdt.core.model.ILanguageDescriptor; import org.eclipse.cdt.core.model.LanguageManager; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; @@ -65,6 +66,7 @@ import org.eclipse.cdt.ui.newui.AbstractCPropertyTab; import org.eclipse.cdt.ui.newui.CDTPrefUtil; import org.eclipse.cdt.utils.ui.controls.TabFolderLayout; + import org.eclipse.cdt.internal.ui.newui.Messages; import org.eclipse.cdt.internal.ui.newui.StatusMessageLine; @@ -228,7 +230,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { initialProvidersByCfg.put(cfgId, initialProviders); } } - initialEnablement = LanguageSettingsManager.isLanguageSettingsProvidersEnabled(page.getProject()); + initialEnablement = ScannerDiscoveryLegacySupport.isLanguageSettingsProvidersFunctionalityEnabled(page.getProject()); } } @@ -268,7 +270,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { if (masterPropertyPage!=null) enableProvidersCheckBox.setSelection(masterPropertyPage.isLanguageSettingsProvidersEnabled()); else - enableProvidersCheckBox.setSelection(LanguageSettingsManager.isLanguageSettingsProvidersEnabled(page.getProject())); + enableProvidersCheckBox.setSelection(ScannerDiscoveryLegacySupport.isLanguageSettingsProvidersFunctionalityEnabled(page.getProject())); // display but disable the checkbox for file/folder resource enableProvidersCheckBox.setEnabled(page.isForProject() /*|| page.isForPrefs()*/); enableControls(enableProvidersCheckBox.getSelection()); @@ -982,7 +984,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { boolean enabled = enableProvidersCheckBox.getSelection(); if (masterPropertyPage!=null) enabled = masterPropertyPage.isLanguageSettingsProvidersEnabled(); - LanguageSettingsManager.setLanguageSettingsProvidersEnabled(page.getProject(), enabled); + ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(page.getProject(), enabled); enableProvidersCheckBox.setSelection(enabled); } @@ -1040,7 +1042,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { if (cfgDescription!=null) { newProvidersList = cfgDescription.getLanguageSettingProviders(); } - boolean newEnablement = LanguageSettingsManager.isLanguageSettingsProvidersEnabled(page.getProject()); + boolean newEnablement = ScannerDiscoveryLegacySupport.isLanguageSettingsProvidersFunctionalityEnabled(page.getProject()); // TODO boolean isEqualList = false; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProvidersLabelProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProvidersLabelProvider.java index 45064253876..7eb9160364e 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProvidersLabelProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProvidersLabelProvider.java @@ -66,8 +66,7 @@ class LanguageSettingsProvidersLabelProvider extends LabelProvider { protected String[] getOverlayKeys(ILanguageSettingsProvider provider) { String[] overlayKeys = new String[5]; { // TODO temporary for debugging -// final String MBS_LANGUAGE_SETTINGS_PROVIDER = "org.eclipse.cdt.managedbuilder.core.LanguageSettingsProvider"; -// boolean isSpecial = provider.getId().equals(MBS_LANGUAGE_SETTINGS_PROVIDER); +// boolean isSpecial = provider.getId().equals(LegacySupport.MBS_LANGUAGE_SETTINGS_PROVIDER); ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); if (rawProvider instanceof LanguageSettingsSerializable) { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/Page_LanguageSettingsProviders.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/Page_LanguageSettingsProviders.java index ef6d4c3f495..a27cc162494 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/Page_LanguageSettingsProviders.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/Page_LanguageSettingsProviders.java @@ -10,11 +10,12 @@ *******************************************************************************/ package org.eclipse.cdt.internal.ui.language.settings.providers; -import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; +import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySupport; import org.eclipse.cdt.ui.newui.AbstractPage; import org.eclipse.cdt.ui.newui.ICPropertyTab; + /** * @noextend This class is not intended to be subclassed by clients. * @noinstantiate This class is not intended to be instantiated by clients. @@ -29,7 +30,7 @@ public class Page_LanguageSettingsProviders extends AbstractPage { public boolean isLanguageSettingsProvidersEnabled() { if (isLanguageSettingsProvidersEnabled==null) { - isLanguageSettingsProvidersEnabled = LanguageSettingsManager.isLanguageSettingsProvidersEnabled(getProject()); + isLanguageSettingsProvidersEnabled = ScannerDiscoveryLegacySupport.isLanguageSettingsProvidersFunctionalityEnabled(getProject()); } return isLanguageSettingsProvidersEnabled; } From 20e689bd276ebd3b5cc88c0cbd31f19d89222164 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Wed, 7 Sep 2011 16:12:32 -0400 Subject: [PATCH 020/120] Use ILanguage rather than ILanguageDescriptor for getName() --- .../scannerconfig/AbstractBuiltinSpecsDetector.java | 6 ++---- .../settings/providers/LanguageSettingsEntriesTab.java | 8 ++++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/AbstractBuiltinSpecsDetector.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/AbstractBuiltinSpecsDetector.java index b21b0b4f64c..72f6413f8b2 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/AbstractBuiltinSpecsDetector.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/AbstractBuiltinSpecsDetector.java @@ -16,16 +16,14 @@ import java.io.OutputStream; import java.net.URI; import java.net.URL; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CommandLauncher; import org.eclipse.cdt.core.ErrorParserManager; import org.eclipse.cdt.core.ICommandLauncher; import org.eclipse.cdt.core.IConsoleParser; -import org.eclipse.cdt.core.model.ILanguageDescriptor; +import org.eclipse.cdt.core.model.ILanguage; import org.eclipse.cdt.core.model.LanguageManager; import org.eclipse.cdt.core.resources.IConsole; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; @@ -368,7 +366,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti } private IConsole startProviderConsole() { - ILanguageDescriptor ld = LanguageManager.getInstance().getLanguageDescriptor(currentLanguageId); + ILanguage ld = LanguageManager.getInstance().getLanguage(currentLanguageId); String consoleId = MakeCorePlugin.PLUGIN_ID + '.' + getId() + '.' + currentLanguageId; String consoleName = getName() + ", " + ld.getName(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java index 00ed09ddbf8..5b21eab569a 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java @@ -50,6 +50,7 @@ import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager_TBD; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable; import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySupport; +import org.eclipse.cdt.core.model.ILanguage; import org.eclipse.cdt.core.model.ILanguageDescriptor; import org.eclipse.cdt.core.model.LanguageManager; import org.eclipse.cdt.core.model.util.CDTListComparator; @@ -919,12 +920,11 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { if (langId==null || langId.length()==0) continue; - LanguageManager langManager = LanguageManager.getInstance(); - ILanguageDescriptor langDes = langManager.getLanguageDescriptor(langId); - if (langDes == null) + ILanguage language = LanguageManager.getInstance().getLanguage(langId); + if (language == null) continue; - langId = langDes.getName(); + langId = language.getName(); if (langId == null || langId.length()==0) continue; From d2a59fe2f37bc0ced39c2a9cdf674b26fc63131b Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Thu, 8 Sep 2011 12:02:07 -0400 Subject: [PATCH 021/120] Tabs visibility when no language is found --- .../providers/LanguageSettingsEntriesTab.java | 38 ++++++++++++------- .../LanguageSettingsProviderTab.java | 21 +--------- 2 files changed, 25 insertions(+), 34 deletions(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java index 5b21eab569a..3ba27138aa5 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java @@ -563,6 +563,12 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { status = new Status(IStatus.INFO, CUIPlugin.PLUGIN_ID, msg); } } + if (status==null || status==Status.OK_STATUS) { + if (treeLanguages.getItemCount()<=0) { + String msg = "Cannot determine toolchain languages."; + status = new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, msg); + } + } fStatusLine.setErrorStatus(status); } @@ -1080,24 +1086,28 @@ providers: for (ILanguageSettingsProvider provider : providers) { public boolean canBeVisible() { if (CDTPrefUtil.getBool(CDTPrefUtil.KEY_NO_SHOW_PROVIDERS)) return false; - if (page.isForPrefs()) - return true; - ICLanguageSetting [] langSettings = getLangSettings(getResDesc()); - if (langSettings == null) - return false; + //filter out files not associated with any languages + if (page.isForFile()) { + ICLanguageSetting [] langSettings = getLangSettings(getResDesc()); + if (langSettings == null) + return false; - for (ICLanguageSetting langSetting : langSettings) { - String langId = langSetting.getLanguageId(); - if (langId!=null && langId.length()>0) { - LanguageManager langManager = LanguageManager.getInstance(); - ILanguageDescriptor langDes = langManager.getLanguageDescriptor(langId); - if (langDes != null) - return true; + // files like *.o may have langSettings but no associated language + for (ICLanguageSetting langSetting : langSettings) { + String langId = langSetting.getLanguageId(); + if (langId!=null && langId.length()>0) { + LanguageManager langManager = LanguageManager.getInstance(); + ILanguageDescriptor langDes = langManager.getLanguageDescriptor(langId); + if (langDes != null) + return true; + } } + + return false; } - - return false; + + return true; } /** diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java index 197f902266e..9ef1e62d10f 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java @@ -1012,27 +1012,8 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { public boolean canBeVisible() { if (CDTPrefUtil.getBool(CDTPrefUtil.KEY_NO_SHOW_PROVIDERS)) return false; - if (page.isForPrefs()) - return true; - if (!page.isForProject()) - return false; - - ICLanguageSetting [] langSettings = getLangSettings(getResDesc()); - if (langSettings == null) - return false; - - for (ICLanguageSetting langSetting : langSettings) { - String langId = langSetting.getLanguageId(); - if (langId!=null && langId.length()>0) { - LanguageManager langManager = LanguageManager.getInstance(); - ILanguageDescriptor langDes = langManager.getLanguageDescriptor(langId); - if (langDes != null) - return true; - } - } - - return false; + return page.isForPrefs() || page.isForProject(); } @Override From d192508e91ee6560b3710009d5e94544c4a973cc Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Thu, 8 Sep 2011 12:47:44 -0400 Subject: [PATCH 022/120] tidy up - using language id to keep track of current language rather than ICLanguageSetting --- .../providers/LanguageSettingsEntriesTab.java | 83 ++++++++----------- .../LanguageSettingsProviderTab.java | 15 ---- 2 files changed, 34 insertions(+), 64 deletions(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java index 3ba27138aa5..04331a7ae4c 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java @@ -88,7 +88,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { private Tree treeLanguages; private Tree treeEntries; private TreeViewer treeEntriesViewer; - private ICLanguageSetting currentLanguageSetting = null; + private String currentLanguageId = null; private ICLanguageSetting[] allLanguages; private Button builtInCheckBox; @@ -125,7 +125,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { // if (LanguageSettingsManager.isWorkspaceProvider(provider)) // provider = LanguageSettingsManager.getRawWorkspaceProvider(provider.getId()); // - if (currentLanguageSetting != null) { + if (currentLanguageId != null) { IResource rc = getResource(); List entries = getSettingEntries(provider); if (entries == null && !(rc instanceof IProject)) { @@ -136,8 +136,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { } else if (provider instanceof ILanguageSettingsEditableProvider && (page.isForFile() || page.isForFolder())) { // Assuming that the default entries for a resource are always null. // Using that for performance reasons. See note in PerformDefaults(). - String languageId = currentLanguageSetting.getLanguageId(); - List entriesParent = provider.getSettingEntries(null, null, languageId); + List entriesParent = provider.getSettingEntries(null, null, currentLanguageId); if (entries!=null && !entries.equals(entriesParent)) { overlayKeys[IDecoration.TOP_RIGHT] = CDTSharedImages.IMG_OVR_SETTING; } @@ -289,16 +288,12 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { * @return list of setting entries for the current context. */ private List getSettingEntriesUpResourceTree(ILanguageSettingsProvider provider) { - if (currentLanguageSetting==null) - return null; - - String languageId = currentLanguageSetting.getLanguageId(); - if (languageId==null) + if (currentLanguageId==null) return null; ICConfigurationDescription cfgDescription = getConfigurationDescription(); IResource rc = getResource(); - List entries = LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, cfgDescription, rc, languageId); + List entries = LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, cfgDescription, rc, currentLanguageId); return entries; } @@ -307,13 +302,12 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { * @return list of setting entries for the current context. */ private List getSettingEntries(ILanguageSettingsProvider provider) { - String languageId = currentLanguageSetting.getLanguageId(); - if (languageId==null) + if (currentLanguageId==null) return null; ICConfigurationDescription cfgDescription = getConfigurationDescription(); IResource rc = getResource(); - return provider.getSettingEntries(cfgDescription, rc, languageId); + return provider.getSettingEntries(cfgDescription, rc, currentLanguageId); } private void addTreeForLanguages(Composite comp) { @@ -328,7 +322,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { if (items.length > 0) { ICLanguageSetting langSetting = (ICLanguageSetting) items[0].getData(); if (langSetting != null) { - currentLanguageSetting = langSetting; + currentLanguageId = langSetting.getLanguageId(); updateTreeEntries(); updateButtons(); } @@ -689,33 +683,29 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { } private void saveEntries(ILanguageSettingsProvider provider, List entries) { - ICConfigurationDescription cfgDescription = getConfigurationDescription(); - IResource rc = getResource(); - String languageId = currentLanguageSetting.getLanguageId(); - if (provider instanceof LanguageSettingsSerializable) { + ICConfigurationDescription cfgDescription = getConfigurationDescription(); + IResource rc = getResource(); if (entries!=null && rc!=null) { List parentEntries = null; if (rc instanceof IProject) { parentEntries = new ArrayList(); } else { - parentEntries = LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, cfgDescription, rc.getParent(), languageId); + parentEntries = LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, cfgDescription, rc.getParent(), currentLanguageId); } if (entries.equals(parentEntries)) { // to use parent entries instead entries = null; } } - ((LanguageSettingsSerializable)provider).setSettingEntries(cfgDescription, rc, languageId, entries); + ((LanguageSettingsSerializable)provider).setSettingEntries(cfgDescription, rc, currentLanguageId, entries); } } private List getWritableEntries(ILanguageSettingsProvider provider) { ICConfigurationDescription cfgDescription = getConfigurationDescription(); IResource rc = getResource(); - String languageId = currentLanguageSetting.getLanguageId(); - - List entries = provider.getSettingEntries(cfgDescription, rc, languageId); + List entries = provider.getSettingEntries(cfgDescription, rc, currentLanguageId); if (entries==null) { entries = getSettingEntriesUpResourceTree(provider); } @@ -864,26 +854,23 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { /** * Get list of providers to display in the settings entry tree. */ - private List getProviders(ICLanguageSetting languageSetting) { + private List getProviders(String languageSettingId) { List itemsList = new LinkedList(); - if (languageSetting!=null) { - String langId = languageSetting.getLanguageId(); - if (langId != null) { - IResource rc = getResource(); - ICConfigurationDescription cfgDescription = getConfigurationDescription(); - if (rc!=null && cfgDescription!=null) { - List cfgProviders = cfgDescription.getLanguageSettingProviders(); - for (ILanguageSettingsProvider cfgProvider : cfgProviders) { - ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(cfgProvider); - if (rawProvider instanceof LanguageSettingsBaseProvider) { - // filter out providers incapable of providing entries for this language - List languageIds = ((LanguageSettingsBaseProvider)rawProvider).getLanguageScope(); - if (languageIds!=null && !languageIds.contains(langId)) { - continue; - } + if (currentLanguageId!=null) { + IResource rc = getResource(); + ICConfigurationDescription cfgDescription = getConfigurationDescription(); + if (rc!=null && cfgDescription!=null) { + List cfgProviders = cfgDescription.getLanguageSettingProviders(); + for (ILanguageSettingsProvider cfgProvider : cfgProviders) { + ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(cfgProvider); + if (rawProvider instanceof LanguageSettingsBaseProvider) { + // filter out providers incapable of providing entries for this language + List languageIds = ((LanguageSettingsBaseProvider)rawProvider).getLanguageScope(); + if (languageIds!=null && !languageIds.contains(currentLanguageId)) { + continue; } - itemsList.add(cfgProvider); } + itemsList.add(cfgProvider); } } } @@ -894,7 +881,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { * Refreshes the entries tree in "Show Entries" mode. */ public void updateTreeEntries() { - List tableItems = getProviders(currentLanguageSetting); + List tableItems = getProviders(currentLanguageId); treeEntriesViewer.setInput(tableItems.toArray(new Object[tableItems.size()])); updateStatusLine(); updateButtons(); @@ -938,14 +925,13 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { t.setText(0, langId); t.setData(langSetting); if (selectedLanguageItem == null) { - if (currentLanguageSetting!=null) { - if (currentLanguageSetting.getLanguageId().equals(langSetting.getLanguageId())) { + if (currentLanguageId!=null) { + if (currentLanguageId.equals(langSetting.getLanguageId())) { selectedLanguageItem = t; - currentLanguageSetting = langSetting; } } else { selectedLanguageItem = t; - currentLanguageSetting = langSetting; + currentLanguageId = langSetting.getLanguageId(); } } } @@ -1034,7 +1020,7 @@ providers: for (ILanguageSettingsProvider provider : providers) { cfgDescription.setLanguageSettingProviders(writableProviders); // updateTreeEntries(); // updateData(getResDesc()); - List tableItems = getProviders(currentLanguageSetting); + List tableItems = getProviders(currentLanguageId); treeEntriesViewer.setInput(tableItems.toArray(new Object[tableItems.size()])); } } @@ -1117,9 +1103,8 @@ providers: for (ILanguageSettingsProvider provider : providers) { private void setSettingEntries(ILanguageSettingsEditableProvider provider, List entries) { ICConfigurationDescription cfgDescription = getConfigurationDescription(); IResource rc = getResource(); - String languageId = currentLanguageSetting.getLanguageId(); - if (languageId!=null) - provider.setSettingEntries(cfgDescription, rc, languageId, entries); + if (currentLanguageId!=null) + provider.setSettingEntries(cfgDescription, rc, currentLanguageId, entries); } @Override diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java index 9ef1e62d10f..9277ca42dc0 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java @@ -824,21 +824,6 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { updateButtons(); } - private ICLanguageSetting[] getLangSettings(ICResourceDescription rcDes) { - switch (rcDes.getType()) { - case ICSettingBase.SETTING_PROJECT: - case ICSettingBase.SETTING_CONFIGURATION: - case ICSettingBase.SETTING_FOLDER: - ICFolderDescription foDes = (ICFolderDescription) rcDes; - return foDes.getLanguageSettings(); - case ICSettingBase.SETTING_FILE: - ICFileDescription fiDes = (ICFileDescription) rcDes; - ICLanguageSetting langSetting = fiDes.getLanguageSetting(); - return (langSetting != null) ? new ICLanguageSetting[] { langSetting } : null; - } - return null; - } - /** * Called when configuration changed */ From e5fb5bf1c00c8b2d9c865e487b07efe9888ae740 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Fri, 9 Sep 2011 12:51:23 -0400 Subject: [PATCH 023/120] utility function to get languages from ICResourceDescription --- ...AbstractLanguageSettingsOutputScanner.java | 33 +++-- .../core/ManagedBuildManager.java | 12 +- .../AbstractBuiltinSpecsDetector.java | 2 +- .../providers/LanguageSettingsManager.java | 95 ++++++++++++- .../LanguageSettingsManager_TBD.java | 43 ++---- .../LanguageSettingsScannerInfoProvider.java | 78 +---------- .../providers/LanguageSettingsEntriesTab.java | 132 ++++++------------ 7 files changed, 171 insertions(+), 224 deletions(-) diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java index 5c35b4dac98..fc800c84be7 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java @@ -26,9 +26,8 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import org.eclipse.cdt.core.ErrorParserManager; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable; -import org.eclipse.cdt.core.model.ILanguage; -import org.eclipse.cdt.core.model.LanguageManager; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICSettingEntry; @@ -243,13 +242,12 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett public boolean processLine(String line, ErrorParserManager epm) { errorParserManager = epm; parsedResourceName = parseForResourceName(line); + currentResource = findResource(parsedResourceName); - currentLanguageId = determineLanguage(parsedResourceName); + currentLanguageId = determineLanguage(); if (!isLanguageInScope(currentLanguageId)) return false; - currentResource = findResource(parsedResourceName); - /** * URI of directory where the build is happening. This URI could point to a remote filesystem * for remote builds. Most often it is the same filesystem as for currentResource but @@ -316,21 +314,22 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett MakeCorePlugin.log(status); } - protected String determineLanguage(String parsedResourceName) { - if (parsedResourceName==null) + protected String determineLanguage() { + IResource rc = currentResource; + if (rc == null && currentProject != null && parsedResourceName != null) { + String fileName = new Path(parsedResourceName).lastSegment().toString(); + // use handle; resource does not need to exist + rc = currentProject.getFile("__" + fileName); + } + + if (rc == null) return null; - String fileName = new Path(parsedResourceName).lastSegment().toString(); - IContentTypeManager manager = Platform.getContentTypeManager(); - IContentType contentType = manager.findContentTypeFor(fileName); - if (contentType==null) + List languageIds = LanguageSettingsManager.getLanguages(rc, currentCfgDescription); + if (languageIds.isEmpty()) return null; - - ILanguage lang = LanguageManager.getInstance().getLanguage(contentType); - if (lang==null) - return null; - - return lang.getId(); + + return languageIds.get(0); } protected boolean isLanguageInScope(String languageId) { diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java index 296753806cd..337801b1342 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java @@ -60,8 +60,6 @@ import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.parser.IScannerInfo; import org.eclipse.cdt.core.parser.IScannerInfoChangeListener; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; -import org.eclipse.cdt.core.settings.model.ICFolderDescription; -import org.eclipse.cdt.core.settings.model.ICLanguageSetting; import org.eclipse.cdt.core.settings.model.ICMultiConfigDescription; import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager; @@ -4813,13 +4811,9 @@ public class ManagedBuildManager extends AbstractCExtension { static public void runBuiltinSpecsDetectors(ICConfigurationDescription cfgDescription, IPath workingDirectory, String[] env, IProgressMonitor monitor) { IProject project = cfgDescription.getProjectDescription().getProject(); - ICFolderDescription rootFolderDescription = cfgDescription.getRootFolderDescription(); - List languageIds = new ArrayList(); - for (ICLanguageSetting languageSetting : rootFolderDescription.getLanguageSettings()) { - String id = languageSetting.getLanguageId(); - if (id!=null) { - languageIds.add(id); - } + List languageIds = LanguageSettingsManager.getLanguages(project, cfgDescription); + if (languageIds.isEmpty()) { + return; } for (ILanguageSettingsProvider provider : cfgDescription.getLanguageSettingProviders()) { diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/AbstractBuiltinSpecsDetector.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/AbstractBuiltinSpecsDetector.java index 72f6413f8b2..586a7200c25 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/AbstractBuiltinSpecsDetector.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/AbstractBuiltinSpecsDetector.java @@ -148,7 +148,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti } @Override - protected String determineLanguage(String parsedResourceName) { + protected String determineLanguage() { // language id is supposed to be set by run(), just return it return currentLanguageId; } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java index 38cb0717062..6463f01a146 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java @@ -1,30 +1,37 @@ /******************************************************************************* - * Copyright (c) 2009, 2011 Andrew Gvozdev (Quoin Inc.) and others. + * Copyright (c) 2009, 2011 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 (Quoin Inc.) - initial API and implementation + * Andrew Gvozdev - initial API and implementation *******************************************************************************/ 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.model.ILanguage; +import org.eclipse.cdt.core.model.LanguageManager; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICFileDescription; +import org.eclipse.cdt.core.settings.model.ICFolderDescription; +import org.eclipse.cdt.core.settings.model.ICLanguageSetting; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; +import org.eclipse.cdt.core.settings.model.ICResourceDescription; import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider; -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.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.preferences.InstanceScope; -import org.osgi.service.prefs.Preferences; +import org.eclipse.core.runtime.IPath; /** * A collection of utility methods to manage language settings providers. @@ -167,4 +174,82 @@ public class LanguageSettingsManager { return provider; } + /** + * Find language IDs for the resource represented by resource description. + * Under the hood build component is inquired and the language IDs would + * commonly come from the input type(s). + * + * @param rcDescription - resource description + * @return list of language IDs for the resource. + * Never returns {@code null} but empty list if no languages can be found. + * + */ + public static List getLanguages(ICResourceDescription rcDescription) { + ICLanguageSetting[] languageSettings = null; + if (rcDescription instanceof ICFileDescription) { + ICLanguageSetting languageSetting = ((ICFileDescription)rcDescription).getLanguageSetting(); + if (languageSetting != null) { + languageSettings = new ICLanguageSetting[] {languageSetting}; + } + } else if (rcDescription instanceof ICFolderDescription) { + languageSettings = ((ICFolderDescription)rcDescription).getLanguageSettings(); + } + + List languageIds = new ArrayList(); + if (languageSettings != null) { + for (ICLanguageSetting languageSetting : languageSettings) { + if (languageSetting!=null) { + String languageId = languageSetting.getLanguageId(); + if (languageId != null && !languageId.isEmpty()) { + languageIds.add(languageId); + } + } + } + } + + return languageIds; + } + + /** + * Find language IDs for the resource in given build configuration. + * Under the hood build component is inquired and the language IDs would + * commonly come from the input type(s). + * + * @param resource - the resource to find languages for. + * @param cfgDescription + * @return list of language IDs for the resource. + * Never returns {@code null} but empty list if no languages can be found. + */ + public static List getLanguages(IResource resource, ICConfigurationDescription cfgDescription) { + List languageIds = new ArrayList(); + IPath prjRelPath = resource.getProjectRelativePath(); + if (resource instanceof IFile) { + String langId = null; + if (cfgDescription != null) { + ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(prjRelPath, true); + if (ls != null) { + langId = ls.getLanguageId(); + } + } else { + try { + ILanguage lang = LanguageManager.getInstance().getLanguageForFile((IFile) resource, null); + langId = lang.getId(); + } catch (CoreException e) { + CCorePlugin.log(e); + } + } + if (langId != null) { + languageIds.add(langId); + } + } else { + ICResourceDescription rcDes = cfgDescription.getResourceDescription(prjRelPath, false); + if (rcDes == null) { + rcDes = cfgDescription.getRootFolderDescription(); + } + languageIds = getLanguages(rcDes); + } + + return languageIds; + } + } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager_TBD.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager_TBD.java index b92da74a593..efb8bdd8958 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager_TBD.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager_TBD.java @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright (c) 2009, 2009 Andrew Gvozdev (Quoin Inc.) and others. + * Copyright (c) 2009, 2011 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 (Quoin Inc.) - initial API and implementation + * Andrew Gvozdev - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.core.language.settings.providers; @@ -15,11 +15,7 @@ import java.util.List; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; -import org.eclipse.cdt.core.settings.model.ICFileDescription; -import org.eclipse.cdt.core.settings.model.ICFolderDescription; -import org.eclipse.cdt.core.settings.model.ICLanguageSetting; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; -import org.eclipse.cdt.core.settings.model.ICResourceDescription; import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider; import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsExtensionManager; import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer; @@ -28,29 +24,13 @@ import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; /** - * TODO - * This layer of language settings in TODO - * - * Duplicate entries are filtered where only first entry is preserved. - * + * This temporary class keeps the utility methods being looking for better home */ public class LanguageSettingsManager_TBD { public static final String PROVIDER_UNKNOWN = "org.eclipse.cdt.projectmodel.4.0.0"; public static final String PROVIDER_UI_USER = "org.eclipse.cdt.ui.user.LanguageSettingsProvider"; public static final char PROVIDER_DELIMITER = LanguageSettingsProvidersSerializer.PROVIDER_DELIMITER; - private static ICLanguageSetting[] getLanguageIds(ICResourceDescription rcDescription) { - if (rcDescription instanceof ICFileDescription) { - ICFileDescription fileDescription = (ICFileDescription)rcDescription; - return new ICLanguageSetting[] {fileDescription.getLanguageSetting()}; - } else if (rcDescription instanceof ICFolderDescription) { - ICFolderDescription folderDescription = (ICFolderDescription)rcDescription; - return folderDescription.getLanguageSettings(); - } - - return null; - } - public static boolean isCustomizedResource(ICConfigurationDescription cfgDescription, IResource rc) { if (rc instanceof IProject) return false; @@ -59,16 +39,13 @@ public class LanguageSettingsManager_TBD { // FIXME // if (!LanguageSettingsManager.isWorkspaceProvider(provider)) { if (provider instanceof ILanguageSettingsEditableProvider || provider instanceof LanguageSettingsSerializable) { - ICResourceDescription rcDescription = cfgDescription.getResourceDescription(rc.getProjectRelativePath(), false); - for (ICLanguageSetting languageSetting : getLanguageIds(rcDescription)) { - String languageId = languageSetting.getLanguageId(); - if (languageId!=null) { - List list = provider.getSettingEntries(cfgDescription, rc, languageId); - if (list!=null) { - List listDefault = provider.getSettingEntries(null, null, languageId); - if (!list.equals(listDefault)) - return true; - } + for (String languageId : LanguageSettingsManager.getLanguages(rc, cfgDescription)) { + List list = provider.getSettingEntries(cfgDescription, rc, languageId); + if (list!=null) { + List listDefault = provider.getSettingEntries(null, null, languageId); + // != is OK here due as the equal lists will have the same reference in WeakHashSet + if (list != listDefault) + return true; } } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsScannerInfoProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsScannerInfoProvider.java index 0b6f4b8a1c5..ed3960a11bf 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsScannerInfoProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsScannerInfoProvider.java @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright (c) 2010, 2010 Andrew Gvozdev (Quoin Inc.) and others. + * Copyright (c) 2010, 2011 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 (Quoin Inc.) - initial API and implementation + * Andrew Gvozdev - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.internal.core.language.settings.providers; @@ -20,24 +20,18 @@ import java.util.Map; 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.model.ILanguage; -import org.eclipse.cdt.core.model.LanguageManager; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; import org.eclipse.cdt.core.parser.ExtendedScannerInfo; import org.eclipse.cdt.core.parser.IScannerInfoChangeListener; import org.eclipse.cdt.core.parser.IScannerInfoProvider; import org.eclipse.cdt.core.settings.model.ACPathEntry; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; -import org.eclipse.cdt.core.settings.model.ICFolderDescription; -import org.eclipse.cdt.core.settings.model.ICLanguageSetting; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; -import org.eclipse.cdt.core.settings.model.ICLanguageSettingPathEntry; import org.eclipse.cdt.core.settings.model.ICMacroEntry; import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager; import org.eclipse.cdt.internal.core.settings.model.SettingsModelMessages; -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; @@ -72,8 +66,10 @@ public class LanguageSettingsScannerInfoProvider implements IScannerInfoProvider if (cfgDescription==null) return DUMMY_SCANNER_INFO; - List languageIds = getLanguageIds(cfgDescription, rc); - if (languageIds==null || languageIds.size()==0) { + List languageIds = LanguageSettingsManager.getLanguages(rc, cfgDescription); + if (languageIds.isEmpty()) { + String msg = NLS.bind(SettingsModelMessages.getString("LanguageSettingsScannerInfoProvider.UnableToDetermineLanguage"), rc.toString()); //$NON-NLS-1$ + CCorePlugin.log(new CoreException(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, msg))); return DUMMY_SCANNER_INFO; } @@ -121,66 +117,6 @@ public class LanguageSettingsScannerInfoProvider implements IScannerInfoProvider return new ExtendedScannerInfo(definedMacros, includePaths, macroFiles, includeFiles, includePathsLocal); } - private List getLanguageIds(ICConfigurationDescription cfgDescription, IResource resource) { - List languageIds = null; - if (resource instanceof IFile) { - String langId = getLanguageIdForFile(cfgDescription, resource); - if (langId!=null) { - languageIds = new ArrayList(1); - languageIds.add(langId); - } - } else if (resource instanceof IContainer) { // IResource can be either IFile or IContainer - languageIds = getLanguageIdsForFolder(cfgDescription, (IContainer) resource); - } - if (languageIds==null || languageIds.size()==0) { - String msg = NLS.bind(SettingsModelMessages.getString("LanguageSettingsScannerInfoProvider.UnableToDetermineLanguage"), resource.toString()); //$NON-NLS-1$ - CCorePlugin.log(new CoreException(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, msg))); - } - return languageIds; - } - - private String getLanguageIdForFile(ICConfigurationDescription cfgDescription, IResource resource) { - // For files using LanguageManager - try { - ILanguage language = LanguageManager.getInstance().getLanguageForFile((IFile) resource, cfgDescription); - if (language!=null) { - return language.getId(); - } - } catch (CoreException e) { - CCorePlugin.log(e); - } - return null; - } - - private List getLanguageIdsForFolder(ICConfigurationDescription cfgDescription, IContainer resource) { - // Using MBS for folders. That will take language ID from input type of applicable tools in the toolchain. - List languageIds = new ArrayList(); - - ICFolderDescription rcDes = null; - ICLanguageSetting[] langSettings = null; - if (resource.getType() == IResource.FOLDER) { // but not IResource.PROJECT - IPath rcPath = resource.getProjectRelativePath(); - rcDes = (ICFolderDescription) cfgDescription.getResourceDescription(rcPath, false); - langSettings = rcDes.getLanguageSettings(); - } - if (langSettings==null || langSettings.length==0) { - // not found or IResource.PROJECT - ICFolderDescription rootDes = cfgDescription.getRootFolderDescription(); - langSettings = rootDes.getLanguageSettings(); - } - - if (langSettings!=null) { - for (ICLanguageSetting ls : langSettings) { - String langId = ls.getLanguageId(); - if (langId!=null && !languageIds.contains(langId)) { - languageIds.add(langId); - } - } - } - - return languageIds; - } - private IPath expandVariables(IPath path, ICConfigurationDescription cfgDescription) { ICdtVariableManager varManager = CCorePlugin.getDefault().getCdtVariableManager(); String pathStr = path.toString(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java index 04331a7ae4c..7be2531e347 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java @@ -12,7 +12,6 @@ package org.eclipse.cdt.internal.ui.language.settings.providers; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; @@ -51,16 +50,10 @@ import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager_ import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable; import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySupport; import org.eclipse.cdt.core.model.ILanguage; -import org.eclipse.cdt.core.model.ILanguageDescriptor; import org.eclipse.cdt.core.model.LanguageManager; -import org.eclipse.cdt.core.model.util.CDTListComparator; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; -import org.eclipse.cdt.core.settings.model.ICFileDescription; -import org.eclipse.cdt.core.settings.model.ICFolderDescription; -import org.eclipse.cdt.core.settings.model.ICLanguageSetting; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICResourceDescription; -import org.eclipse.cdt.core.settings.model.ICSettingBase; import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider; import org.eclipse.cdt.ui.CDTSharedImages; @@ -68,7 +61,6 @@ import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.newui.AbstractCPropertyTab; import org.eclipse.cdt.ui.newui.CDTPrefUtil; - import org.eclipse.cdt.internal.ui.newui.LanguageSettingsImages; import org.eclipse.cdt.internal.ui.newui.Messages; import org.eclipse.cdt.internal.ui.newui.StatusMessageLine; @@ -89,7 +81,6 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { private Tree treeEntries; private TreeViewer treeEntriesViewer; private String currentLanguageId = null; - private ICLanguageSetting[] allLanguages; private Button builtInCheckBox; private Button enableProvidersCheckBox; @@ -320,12 +311,9 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { public void widgetSelected(SelectionEvent e) { TreeItem[] items = treeLanguages.getSelection(); if (items.length > 0) { - ICLanguageSetting langSetting = (ICLanguageSetting) items[0].getData(); - if (langSetting != null) { - currentLanguageId = langSetting.getLanguageId(); - updateTreeEntries(); - updateButtons(); - } + currentLanguageId = (String) items[0].getData(); + updateTreeEntries(); + updateButtons(); } } }); @@ -887,58 +875,38 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { updateButtons(); } - private ICLanguageSetting[] getLangSettings(ICResourceDescription rcDes) { - switch (rcDes.getType()) { - case ICSettingBase.SETTING_PROJECT: - case ICSettingBase.SETTING_CONFIGURATION: - case ICSettingBase.SETTING_FOLDER: - ICFolderDescription foDes = (ICFolderDescription) rcDes; - return foDes.getLanguageSettings(); - case ICSettingBase.SETTING_FILE: - ICFileDescription fiDes = (ICFileDescription) rcDes; - ICLanguageSetting langSetting = fiDes.getLanguageSetting(); - return (langSetting != null) ? new ICLanguageSetting[] { langSetting } : null; - } - return null; - } - private void updateTreeLanguages(ICResourceDescription rcDes) { treeLanguages.removeAll(); TreeItem selectedLanguageItem = null; - allLanguages = getLangSettings(rcDes); - if (allLanguages != null) { - Arrays.sort(allLanguages, CDTListComparator.getInstance()); - for (ICLanguageSetting langSetting : allLanguages) { - String langId = langSetting.getLanguageId(); - if (langId==null || langId.length()==0) - continue; - ILanguage language = LanguageManager.getInstance().getLanguage(langId); - if (language == null) - continue; + List languageIds = LanguageSettingsManager.getLanguages(rcDes); + Collections.sort(languageIds); + for (String langId : languageIds) { + ILanguage language = LanguageManager.getInstance().getLanguage(langId); + if (language == null) + continue; - langId = language.getName(); - if (langId == null || langId.length()==0) - continue; + String langName = language.getName(); + if (langName == null || langName.length()==0) + continue; - TreeItem t = new TreeItem(treeLanguages, SWT.NONE); - t.setText(0, langId); - t.setData(langSetting); - if (selectedLanguageItem == null) { - if (currentLanguageId!=null) { - if (currentLanguageId.equals(langSetting.getLanguageId())) { - selectedLanguageItem = t; - } - } else { + TreeItem t = new TreeItem(treeLanguages, SWT.NONE); + t.setText(0, langName); + t.setData(langId); + if (selectedLanguageItem == null) { + if (currentLanguageId!=null) { + if (currentLanguageId.equals(langId)) { selectedLanguageItem = t; - currentLanguageId = langSetting.getLanguageId(); } + } else { + selectedLanguageItem = t; + currentLanguageId = langId; } } + } - if (selectedLanguageItem != null) { - treeLanguages.setSelection(selectedLanguageItem); - } + if (selectedLanguageItem != null) { + treeLanguages.setSelection(selectedLanguageItem); } } @@ -988,24 +956,20 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { providers: for (ILanguageSettingsProvider provider : providers) { ILanguageSettingsEditableProvider writableProvider = null; if (provider instanceof ILanguageSettingsEditableProvider) { - TreeItem[] tisLang = treeLanguages.getItems(); - for (TreeItem tiLang : tisLang) { - Object item = tiLang.getData(); - if (item instanceof ICLanguageSetting) { - String languageId = ((ICLanguageSetting)item).getLanguageId(); - if (languageId!=null) { - if (provider.getSettingEntries(cfgDescription, rc, languageId)!=null) { - try { - // clone providers to be able to "Cancel" in UI - if (writableProvider==null) { - writableProvider = ((ILanguageSettingsEditableProvider) provider).clone(); - } - writableProvider.setSettingEntries(cfgDescription, rc, languageId, null); - changed = true; - } catch (CloneNotSupportedException e) { - CUIPlugin.log("Internal Error: cannot clone provider "+provider.getId(), e); - continue providers; + for (TreeItem langItems : treeLanguages.getItems()) { + String langId = (String)langItems.getData(); + if (langId!=null) { + if (provider.getSettingEntries(cfgDescription, rc, langId)!=null) { + try { + // clone providers to be able to "Cancel" in UI + if (writableProvider==null) { + writableProvider = ((ILanguageSettingsEditableProvider) provider).clone(); } + writableProvider.setSettingEntries(cfgDescription, rc, langId, null); + changed = true; + } catch (CloneNotSupportedException e) { + CUIPlugin.log("Internal Error: cannot clone provider "+provider.getId(), e); + continue providers; } } } @@ -1073,23 +1037,15 @@ providers: for (ILanguageSettingsProvider provider : providers) { if (CDTPrefUtil.getBool(CDTPrefUtil.KEY_NO_SHOW_PROVIDERS)) return false; - //filter out files not associated with any languages + //filter out files not associated with any languages such as *.o if (page.isForFile()) { - ICLanguageSetting [] langSettings = getLangSettings(getResDesc()); - if (langSettings == null) - return false; - - // files like *.o may have langSettings but no associated language - for (ICLanguageSetting langSetting : langSettings) { - String langId = langSetting.getLanguageId(); - if (langId!=null && langId.length()>0) { - LanguageManager langManager = LanguageManager.getInstance(); - ILanguageDescriptor langDes = langManager.getLanguageDescriptor(langId); - if (langDes != null) - return true; - } + List languageIds = LanguageSettingsManager.getLanguages(getResDesc()); + for (String langId : languageIds) { + LanguageManager langManager = LanguageManager.getInstance(); + ILanguage language = langManager.getLanguage(langId); + if (language != null) + return true; } - return false; } From c5586cefbadb92e0132ae1674a47c13ae21b381a Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Sat, 10 Sep 2011 12:45:04 -0400 Subject: [PATCH 024/120] Converted xlC toolchain --- .../ScannerDiscoveryLegacySupport.java | 6 +- .../plugin.xml | 101 ++++++++++-------- 2 files changed, 59 insertions(+), 48 deletions(-) diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ScannerDiscoveryLegacySupport.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ScannerDiscoveryLegacySupport.java index 42dc4595b58..df9429f4770 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ScannerDiscoveryLegacySupport.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ScannerDiscoveryLegacySupport.java @@ -110,13 +110,17 @@ public class ScannerDiscoveryLegacySupport { legacyProfiles = new HashMap(); // InputTypes +// legacyProfiles.put(inputTypeId, scannerConfigDiscoveryProfileId); legacyProfiles.put("cdt.managedbuild.tool.gnu.c.compiler.input", "org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileC|org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile"); legacyProfiles.put("cdt.managedbuild.tool.gnu.cpp.compiler.input", "org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileCPP|org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile"); legacyProfiles.put("cdt.managedbuild.tool.gnu.c.compiler.input.cygwin", "org.eclipse.cdt.managedbuilder.core.GCCWinManagedMakePerProjectProfileC"); legacyProfiles.put("cdt.managedbuild.tool.gnu.cpp.compiler.input.cygwin", "org.eclipse.cdt.managedbuilder.core.GCCWinManagedMakePerProjectProfileCPP"); + legacyProfiles.put("cdt.managedbuild.tool.xlc.c.compiler.input", "org.eclipse.cdt.managedbuilder.xlc.core.XLCManagedMakePerProjectProfile"); + legacyProfiles.put("cdt.managedbuild.tool.xlc.cpp.c.compiler.input", "org.eclipse.cdt.managedbuilder.xlc.core.XLCManagedMakePerProjectProfile"); + legacyProfiles.put("cdt.managedbuild.tool.xlc.cpp.compiler.input", "org.eclipse.cdt.managedbuilder.xlc.core.XLCManagedMakePerProjectProfileCPP"); // Toolchains -// legacyProfiles.put(, ); +// legacyProfiles.put(toolchainId, scannerConfigDiscoveryProfileId); } return legacyProfiles.get(id); diff --git a/xlc/org.eclipse.cdt.managedbuilder.xlc.ui/plugin.xml b/xlc/org.eclipse.cdt.managedbuilder.xlc.ui/plugin.xml index f6c2ea28a99..1a3575471fd 100644 --- a/xlc/org.eclipse.cdt.managedbuilder.xlc.ui/plugin.xml +++ b/xlc/org.eclipse.cdt.managedbuilder.xlc.ui/plugin.xml @@ -522,18 +522,19 @@ name="%TargetName.xlc.exe" projectMacroSupplier="org.eclipse.cdt.managedbuilder.xlc.ui.XLCProjectMacroSupplier"> + artifactExtension="exe" + cleanCommand="rm -rf" + errorParsers="org.eclipse.cdt.errorparsers.xlc.XlcErrorParser" + id="cdt.managedbuild.config.xlc.exe.debug" + languageSettingsProviders="org.eclipse.cdt.ui.user.LanguageSettingsProvider;org.eclipse.cdt.managedbuilder.core.LanguageSettingsProvider;${Toolchain};-org.eclipse.cdt.managedbuilder.xlc.core.xlc.build.command.parser" + name="%ConfigName.Dbg"> + name="%ConfigName.Rel" + artifactExtension="exe" + cleanCommand="rm -rf" + errorParsers="org.eclipse.cdt.errorparsers.xlc.XlcErrorParser" + languageSettingsProviders="org.eclipse.cdt.ui.user.LanguageSettingsProvider;org.eclipse.cdt.managedbuilder.core.LanguageSettingsProvider;${Toolchain};-org.eclipse.cdt.managedbuilder.xlc.core.xlc.build.command.parser" + id="cdt.managedbuild.config.xlc.exe.release"> + name="%ConfigName.Dbg" + cleanCommand="rm -rf" + artifactExtension="so" + errorParsers="org.eclipse.cdt.errorparsers.xlc.XlcErrorParser" + languageSettingsProviders="org.eclipse.cdt.ui.user.LanguageSettingsProvider;org.eclipse.cdt.managedbuilder.core.LanguageSettingsProvider;${Toolchain};-org.eclipse.cdt.managedbuilder.xlc.core.xlc.build.command.parser" + id="cdt.managedbuild.config.xlc.so.debug"> + id="cdt.managedbuild.toolchain.xlc.so.debug" + languageSettingsProviders="org.eclipse.cdt.managedbuilder.xlc.core.xlc.build.command.parser;*org.eclipse.cdt.managedbuilder.xlc.core.xlc.specs.detector" + name="%ToolChainName.Dbg" + targetTool="cdt.managedbuild.tool.xlc.c.linker.so.debug;cdt.managedbuild.tool.xlc.cpp.linker.so.debug"> + name="%ConfigName.Rel" + cleanCommand="rm -rf" + artifactExtension="so" + errorParsers="org.eclipse.cdt.errorparsers.xlc.XlcErrorParser" + languageSettingsProviders="org.eclipse.cdt.ui.user.LanguageSettingsProvider;org.eclipse.cdt.managedbuilder.core.LanguageSettingsProvider;${Toolchain};-org.eclipse.cdt.managedbuilder.xlc.core.xlc.build.command.parser" + id="cdt.managedbuild.config.xlc.so.release"> + id="cdt.managedbuild.toolchain.xlc.so.release" + languageSettingsProviders="org.eclipse.cdt.managedbuilder.xlc.core.xlc.build.command.parser;*org.eclipse.cdt.managedbuilder.xlc.core.xlc.specs.detector" + name="%ToolChainName.Rel" + targetTool="cdt.managedbuild.tool.xlc.c.linker.so.release;cdt.managedbuild.tool.xlc.cpp.linker.so.release"> + name="%ConfigName.Dbg" + cleanCommand="rm -rf" + artifactExtension="lib" + errorParsers="org.eclipse.cdt.errorparsers.xlc.XlcErrorParser" + languageSettingsProviders="org.eclipse.cdt.ui.user.LanguageSettingsProvider;org.eclipse.cdt.managedbuilder.core.LanguageSettingsProvider;${Toolchain};-org.eclipse.cdt.managedbuilder.xlc.core.xlc.build.command.parser" + id="cdt.managedbuild.config.xlc.lib.debug"> + id="cdt.managedbuild.toolchain.xlc.lib.debug" + languageSettingsProviders="org.eclipse.cdt.managedbuilder.xlc.core.xlc.build.command.parser;*org.eclipse.cdt.managedbuilder.xlc.core.xlc.specs.detector" + name="%ToolChainName.Dbg" + targetTool="cdt.managedbuild.tool.xlc.archiver.lib.debug"> + name="%ConfigName.Rel" + cleanCommand="rm -rf" + artifactExtension="lib" + errorParsers="org.eclipse.cdt.errorparsers.xlc.XlcErrorParser" + languageSettingsProviders="org.eclipse.cdt.ui.user.LanguageSettingsProvider;org.eclipse.cdt.managedbuilder.core.LanguageSettingsProvider;${Toolchain};-org.eclipse.cdt.managedbuilder.xlc.core.xlc.build.command.parser" + id="cdt.managedbuild.config.xlc.lib.release"> + id="cdt.managedbuild.toolchain.xlc.lib.release" + languageSettingsProviders="org.eclipse.cdt.managedbuilder.xlc.core.xlc.build.command.parser;*org.eclipse.cdt.managedbuilder.xlc.core.xlc.specs.detector" + name="%ToolChainName.Rel" + targetTool="cdt.managedbuild.tool.xlc.archiver.lib.release"> @@ -3753,7 +3762,6 @@ id="cdt.managedbuild.tool.xlc.cpp.c.compiler.input" name="%inputType.c.name.2" primaryInput="true" - scannerConfigDiscoveryProfileId="org.eclipse.cdt.managedbuilder.xlc.core.XLCManagedMakePerProjectProfile" sourceContentType="org.eclipse.cdt.core.cSource" sources="c"> @@ -3763,7 +3771,6 @@ id="cdt.managedbuild.tool.xlc.cpp.compiler.input" name="%inputType.cpp.name" primaryInput="true" - scannerConfigDiscoveryProfileId="org.eclipse.cdt.managedbuilder.xlc.core.XLCManagedMakePerProjectProfileCPP" sourceContentType="org.eclipse.cdt.core.cxxSource" sources="c,C,cc,cxx,cpp"> From 5587687e1e9595100dce57172e6c109d4f1e55cb Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Sat, 10 Sep 2011 19:47:12 -0400 Subject: [PATCH 025/120] externalization --- .../plugin.properties | 5 ++++- xlc/org.eclipse.cdt.managedbuilder.xlc.core/plugin.xml | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/xlc/org.eclipse.cdt.managedbuilder.xlc.core/plugin.properties b/xlc/org.eclipse.cdt.managedbuilder.xlc.core/plugin.properties index 9d000f26688..1f8857cdb4d 100644 --- a/xlc/org.eclipse.cdt.managedbuilder.xlc.core/plugin.properties +++ b/xlc/org.eclipse.cdt.managedbuilder.xlc.core/plugin.properties @@ -16,4 +16,7 @@ providerName=Eclipse CDT objectFileName=Object File profileName=XL C managed make per project scanner discovery profile -profileNameCPP=XL C++ managed make per project scanner discovery profile \ No newline at end of file +profileNameCPP=XL C++ managed make per project scanner discovery profile + +XlcBuiltinSpecsDetectorName=CDT XLC Builtin Compiler Settings +XlcBuildCommandParserName=CDT XLC Build Output Parser diff --git a/xlc/org.eclipse.cdt.managedbuilder.xlc.core/plugin.xml b/xlc/org.eclipse.cdt.managedbuilder.xlc.core/plugin.xml index 9761cfab117..bebad46f5a3 100644 --- a/xlc/org.eclipse.cdt.managedbuilder.xlc.core/plugin.xml +++ b/xlc/org.eclipse.cdt.managedbuilder.xlc.core/plugin.xml @@ -81,7 +81,7 @@ @@ -89,7 +89,7 @@ From 28fec5efe643432c30fd4957d5057317f276ab67 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Mon, 12 Sep 2011 10:25:12 -0400 Subject: [PATCH 026/120] Using cfgDescription.getLanguageSettingForFile() in MBSLanguageSettingsProvider --- .../MBSLanguageSettingsProvider.java | 38 +++++++++++++------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/MBSLanguageSettingsProvider.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/MBSLanguageSettingsProvider.java index ebddb38e568..88515fbaa4e 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/MBSLanguageSettingsProvider.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/MBSLanguageSettingsProvider.java @@ -24,6 +24,7 @@ import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICResourceDescription; import org.eclipse.cdt.core.settings.model.ICSettingBase; import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider; +import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IPath; @@ -33,24 +34,37 @@ public class MBSLanguageSettingsProvider extends AbstractExecutableExtensionBase public List getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) { IPath projectPath = rc.getProjectRelativePath(); - ICResourceDescription rcDescription = cfgDescription.getResourceDescription(projectPath, false); + ICLanguageSetting[] languageSettings = null; + + if (rc instanceof IFile) { + ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(projectPath, true); + if (ls != null) { + languageSettings = new ICLanguageSetting[] {ls}; + } + } else { + ICResourceDescription rcDescription = cfgDescription.getResourceDescription(projectPath, false); + languageSettings = getLanguageSettings(rcDescription); + } List list = new ArrayList(); - for (ICLanguageSetting languageSetting : getLanguageSettings(rcDescription)) { - if (languageSetting!=null) { - String id = languageSetting.getLanguageId(); - if (id!=null && id.equals(languageId)) { - int kindsBits = languageSetting.getSupportedEntryKinds(); - for (int kind=1;kind<=kindsBits;kind<<=1) { - if ((kindsBits & kind) != 0) { - list.addAll(languageSetting.getSettingEntriesList(kind)); + + if (languageSettings != null) { + for (ICLanguageSetting langSetting : languageSettings) { + if (langSetting!=null) { + String id = langSetting.getLanguageId(); + if (id!=null && id.equals(languageId)) { + int kindsBits = langSetting.getSupportedEntryKinds(); + for (int kind=1;kind<=kindsBits;kind<<=1) { + if ((kindsBits & kind) != 0) { + list.addAll(langSetting.getSettingEntriesList(kind)); + } } + } else { + // System.err.println("languageSetting id=null: name=" + languageSetting.getName()); } } else { -// System.err.println("languageSetting id=null: name=" + languageSetting.getName()); + System.err.println("languageSetting=null: rc=" + rc); } - } else { - System.err.println("languageSetting=null: rcDescription=" + rcDescription.getName()); } } return list; From d29e766785be4c5008fc1f1325017e4eb6ec387e Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Mon, 12 Sep 2011 15:40:19 -0400 Subject: [PATCH 027/120] Do not create default legacy SD profile when LSP functionality is enabled --- .../scannerconfig2/CfgScannerConfigInfoFactory2.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/build/internal/core/scannerconfig2/CfgScannerConfigInfoFactory2.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/build/internal/core/scannerconfig2/CfgScannerConfigInfoFactory2.java index 5f04bca0b9f..a6257e4bf01 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/build/internal/core/scannerconfig2/CfgScannerConfigInfoFactory2.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/build/internal/core/scannerconfig2/CfgScannerConfigInfoFactory2.java @@ -19,6 +19,7 @@ import java.util.Map.Entry; import org.eclipse.cdt.build.core.scannerconfig.CfgInfoContext; import org.eclipse.cdt.build.core.scannerconfig.ICfgScannerConfigBuilderInfo2Set; import org.eclipse.cdt.build.internal.core.scannerconfig.CfgScannerConfigUtil; +import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySupport; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.make.core.MakeCorePlugin; @@ -36,6 +37,7 @@ import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin; import org.eclipse.cdt.managedbuilder.internal.core.Configuration; import org.eclipse.cdt.managedbuilder.internal.dataprovider.BuildConfigurationData; +import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.Preferences; import org.eclipse.core.runtime.QualifiedName; @@ -209,7 +211,12 @@ public class CfgScannerConfigInfoFactory2 { } } if (id == null) { - id = CfgScannerConfigUtil.getDefaultProfileId(context, true); + // Language Settings Providers are meant to replace legacy scanner discovery + // so do not try to find default profile + IProject project = cfg.getOwner().getProject(); + if (!ScannerDiscoveryLegacySupport.isLanguageSettingsProvidersFunctionalityEnabled(project)) { + id = CfgScannerConfigUtil.getDefaultProfileId(context, true); + } } InfoContext baseContext = context.toInfoContext(); From 25687e1b6c9167b94a93b78be5b676857aaf7d54 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Tue, 13 Sep 2011 12:12:32 -0400 Subject: [PATCH 028/120] Turn off MBS provider for New Project Makefile "Other" --- build/org.eclipse.cdt.managedbuilder.core/plugin.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build/org.eclipse.cdt.managedbuilder.core/plugin.xml b/build/org.eclipse.cdt.managedbuilder.core/plugin.xml index 5514f2173e0..f1579d629c5 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/plugin.xml +++ b/build/org.eclipse.cdt.managedbuilder.core/plugin.xml @@ -313,9 +313,9 @@ + id="org.eclipse.cdt.build.core.prefbase.cfg" + languageSettingsProviders="org.eclipse.cdt.ui.user.LanguageSettingsProvider;${Toolchain}" + name="%cfg1_base"> Date: Tue, 13 Sep 2011 14:58:27 -0400 Subject: [PATCH 029/120] Removed an attempt to present entries in resource hierarchy for BOP providers. It should be OK to keep it on per-file bases as there is no duplication/memory bloating which has been addressed in LanguageSettingsSerializable. --- .../GCCBuildCommandParserTest.java | 33 ------------------- .../AbstractBuildCommandParser.java | 7 ---- .../providers/LanguageSettingsManager.java | 5 +++ 3 files changed, 5 insertions(+), 40 deletions(-) diff --git a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java index 0804f98b93b..8d288d9923b 100644 --- a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java +++ b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java @@ -1891,37 +1891,4 @@ public class GCCBuildCommandParserTest extends TestCase { } } - /** - */ - public void testBuildResourceTree() throws Exception { - // create resources - IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName()); - ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); - ICConfigurationDescription cfgDescription = cfgDescriptions[0]; - IFolder folder = ResourceHelper.createFolder(project, "Folder"); - IFile file = ResourceHelper.createFile(project, "Folder/file.cpp"); - - // create GCCBuildCommandParser - GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); - ErrorParserManager epm = new ErrorParserManager(project, null); - - // parse line - parser.startup(cfgDescription); - parser.processLine("gcc " - + " -DMACRO" - + " Folder/file.cpp", - epm); - parser.shutdown(); - - // check that entries go to highest possible level - CMacroEntry entry = new CMacroEntry("MACRO", null, 0); - List entries = new ArrayList(); - entries.add(entry); - - assertEquals(entries, LanguageSettingsManager.getSettingEntriesUpResourceTree(parser, cfgDescription, file, LANG_CPP)); - assertEquals(entries, LanguageSettingsManager.getSettingEntriesUpResourceTree(parser, cfgDescription, folder, LANG_CPP)); - assertEquals(entries, LanguageSettingsManager.getSettingEntriesUpResourceTree(parser, cfgDescription, project, LANG_CPP)); - } - - } diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java index 1f0fb9ad089..28fa853138d 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java @@ -101,13 +101,6 @@ public abstract class AbstractBuildCommandParser extends AbstractLanguageSetting return super.processLine(line, epm); } - // TODO - test cases - @Override - public void shutdown() { - LanguageSettingsManager.buildResourceTree(this, currentCfgDescription, currentLanguageId, currentProject); - super.shutdown(); - } - /** * Trivial Error Parser which allows highlighting of output lines matching the patterns * of this parser. Intended for better troubleshooting experience. diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java index 6463f01a146..b7e8b2ea666 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java @@ -61,6 +61,11 @@ public class LanguageSettingsManager { /** * Builds for the provider a nice looking resource tree to present hierarchical view to the user. * + * TODO - Note that after using this method for a while for BOP parsers it appears that disadvantages + * outweight benefits. In particular, it doesn't result in saving memory as the language settings + * (and the lists itself) are not duplicated in memory anyway but optimized with using WeakHashSet + * and SafeStringInterner. + * * @param provider - language settings provider to build the tree for. * @param cfgDescription - configuration description. * @param languageId - language ID. From e101cace9e87fa2884f6b30845d2b086a989219b Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Tue, 13 Sep 2011 16:09:40 -0400 Subject: [PATCH 030/120] Enablement of provider tab controls on preference page fixed --- .../LanguageSettingsProviderTab.java | 45 ++++++++++--------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java index 9277ca42dc0..85ea81ead9d 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java @@ -254,30 +254,31 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { // Status line fStatusLine = new StatusMessageLine(usercomp, SWT.LEFT, 2); - // "I want to try new scanner discovery" temporary checkbox - enableProvidersCheckBox = setupCheck(usercomp, Messages.CDTMainWizardPage_TrySD90, 2, GridData.FILL_HORIZONTAL); - enableProvidersCheckBox.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - boolean enabled = enableProvidersCheckBox.getSelection(); - if (masterPropertyPage!=null) - masterPropertyPage.setLanguageSettingsProvidersEnabled(enabled); - enableControls(enabled); - updateStatusLine(); - } - }); - - if (masterPropertyPage!=null) - enableProvidersCheckBox.setSelection(masterPropertyPage.isLanguageSettingsProvidersEnabled()); - else - enableProvidersCheckBox.setSelection(ScannerDiscoveryLegacySupport.isLanguageSettingsProvidersFunctionalityEnabled(page.getProject())); - // display but disable the checkbox for file/folder resource - enableProvidersCheckBox.setEnabled(page.isForProject() /*|| page.isForPrefs()*/); - enableControls(enableProvidersCheckBox.getSelection()); - if (page.isForPrefs()) { initButtons(BUTTON_LABELS_PREF); + } else { + // "I want to try new scanner discovery" temporary checkbox + enableProvidersCheckBox = setupCheck(usercomp, Messages.CDTMainWizardPage_TrySD90, 2, GridData.FILL_HORIZONTAL); + enableProvidersCheckBox.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + boolean enabled = enableProvidersCheckBox.getSelection(); + if (masterPropertyPage!=null) + masterPropertyPage.setLanguageSettingsProvidersEnabled(enabled); + enableControls(enabled); + updateStatusLine(); + } + }); + + if (masterPropertyPage!=null) + enableProvidersCheckBox.setSelection(masterPropertyPage.isLanguageSettingsProvidersEnabled()); + else + enableProvidersCheckBox.setSelection(ScannerDiscoveryLegacySupport.isLanguageSettingsProvidersFunctionalityEnabled(page.getProject())); + // display but disable the checkbox for file/folder resource + enableProvidersCheckBox.setEnabled(page.isForProject()); + enableControls(enableProvidersCheckBox.getSelection()); + initButtons(BUTTON_LABELS_PROJECT); } updateData(getResDesc()); @@ -840,7 +841,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { setAllVisible(true, null); } - if (masterPropertyPage!=null) { + if (enableProvidersCheckBox!=null && masterPropertyPage!=null) { boolean enabled = masterPropertyPage.isLanguageSettingsProvidersEnabled(); enableProvidersCheckBox.setSelection(enabled); enableControls(enabled); From c82202c144805eba16b45ceabcce6dc8b8d2f29c Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Wed, 14 Sep 2011 11:18:11 -0400 Subject: [PATCH 031/120] test to run SpecsDetectors globally without a project --- .../tests/GCCBuiltinSpecsDetectorTest.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/GCCBuiltinSpecsDetectorTest.java b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/GCCBuiltinSpecsDetectorTest.java index 6281f189c44..2f7252d7161 100644 --- a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/GCCBuiltinSpecsDetectorTest.java +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/GCCBuiltinSpecsDetectorTest.java @@ -335,6 +335,28 @@ public class GCCBuiltinSpecsDetectorTest extends TestCase { assertEquals(expected, entries.get(0)); } + public void testAbstractBuiltinSpecsDetector_RunGlobal() throws Exception { + AbstractBuiltinSpecsDetector detector = new GCCBuiltinSpecsDetector() { + @Override + protected boolean runProgram(String command, String[] env, IPath workingDirectory, IProgressMonitor monitor, + OutputStream consoleOut, OutputStream consoleErr) throws CoreException, IOException { + printLine(consoleOut, "#define MACRO VALUE"); + consoleOut.close(); + consoleErr.close(); + return true; + } + }; + + detector.setLanguageScope(new ArrayList() {{add(LANGUAGE_ID);}}); + + detector.run((IProject)null, LANGUAGE_ID, null, null, null); + assertFalse(detector.isEmpty()); + + List entries = detector.getSettingEntries(null, null, LANGUAGE_ID); + ICLanguageSettingEntry expected = new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); + assertEquals(expected, entries.get(0)); + } + public void testAbstractBuiltinSpecsDetector_RunOnce() throws Exception { // Create model project and accompanied descriptions String projectName = getName(); From 4ab906dea61a97b0afcac4e5c95434602018ad7e Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Wed, 14 Sep 2011 23:06:09 -0400 Subject: [PATCH 032/120] Cosmetics, more readable names --- .../model/CProjectDescriptionDeltaTests.java | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/settings/model/CProjectDescriptionDeltaTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/settings/model/CProjectDescriptionDeltaTests.java index cc93290745c..ff562be920b 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/settings/model/CProjectDescriptionDeltaTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/settings/model/CProjectDescriptionDeltaTests.java @@ -28,14 +28,14 @@ import org.eclipse.core.resources.IProject; public class CProjectDescriptionDeltaTests extends BaseTestCase{ - private Listener listener; + private MockListener listener; - private class Listener implements ICProjectDescriptionListener { + private class MockListener implements ICProjectDescriptionListener { private boolean fIsNotified; private String fProjName; private ICDescriptionDelta fDelta; - public Listener(String projName){ + public MockListener(String projName){ fProjName = projName; fIsNotified = false; fDelta = null; @@ -52,7 +52,7 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ return fIsNotified; } - void resetNotified(){ + void clearNotified(){ fIsNotified = false; fDelta = null; } @@ -78,7 +78,7 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager(); if(listener != null) mngr.removeCProjectDescriptionListener(listener); - listener = new Listener(projName); + listener = new MockListener(projName); mngr.addCProjectDescriptionListener(listener, CProjectDescriptionEvent.APPLIED); assertFalse(listener.isNotified()); @@ -123,7 +123,7 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ prjDescription.setActiveConfiguration(cfgDescription1); // Write project description - listener.resetNotified(); + listener.clearNotified(); mngr.setProjectDescription(project, prjDescription); assertEquals(true, listener.isNotified()); @@ -165,7 +165,7 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ cfgDescription.setName(newName); // Write project description - listener.resetNotified(); + listener.clearNotified(); mngr.setProjectDescription(project, prjDescription); assertEquals(true, listener.isNotified()); @@ -207,7 +207,7 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ cfgDescription.setDescription("New description"); // Write project description - listener.resetNotified(); + listener.clearNotified(); mngr.setProjectDescription(project, prjDescription); assertEquals(true, listener.isNotified()); @@ -254,7 +254,7 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ langSetting.setLanguageId(newLanguageId); // Write project description - listener.resetNotified(); + listener.clearNotified(); mngr.setProjectDescription(project, prjDescription); assertEquals(true, listener.isNotified()); @@ -299,7 +299,7 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ langSetting.setSourceContentTypeIds(new String[] {testContentType}); // Write project description - listener.resetNotified(); + listener.clearNotified(); mngr.setProjectDescription(project, prjDescription); assertEquals(true, listener.isNotified()); @@ -349,7 +349,7 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ // Write project description - listener.resetNotified(); + listener.clearNotified(); mngr.setProjectDescription(project, prjDescription); assertEquals(true, listener.isNotified()); @@ -397,7 +397,7 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ langSetting.setSettingEntries(ICSettingEntry.INCLUDE_PATH, entries); // Write project description - listener.resetNotified(); + listener.clearNotified(); mngr.setProjectDescription(project, prjDescription); assertEquals(true, listener.isNotified()); @@ -442,7 +442,7 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ targetPlatformSetting.setBinaryParserIds(new String[] {testBinaryParserId}); // Write project description - listener.resetNotified(); + listener.clearNotified(); mngr.setProjectDescription(project, prjDescription); assertEquals(true, listener.isNotified()); @@ -487,7 +487,7 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ cfgDescription.getBuildSetting().setErrorParserIDs(new String[] {testErrorParserId}); // Write project description - listener.resetNotified(); + listener.clearNotified(); mngr.setProjectDescription(project, prjDescription); assertEquals(true, listener.isNotified()); @@ -550,7 +550,7 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ fileDescription.setExcluded(true); // Write project description - listener.resetNotified(); + listener.clearNotified(); mngr.setProjectDescription(project, prjDescription); assertEquals(true, listener.isNotified()); @@ -596,7 +596,7 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ cfgDescription.setSourceEntries(sourceEntries.toArray(new ICSourceEntry[0])); // Write project description - listener.resetNotified(); + listener.clearNotified(); mngr.setProjectDescription(project, prjDescription); assertEquals(true, listener.isNotified()); @@ -655,7 +655,7 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ cfgDescription.setSourceEntries(new ICSourceEntry[0]); // Write project description - listener.resetNotified(); + listener.clearNotified(); mngr.setProjectDescription(project, prjDescription); assertEquals(true, listener.isNotified()); @@ -701,7 +701,7 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ ICExternalSetting testExternalSetting = cfgDescription.createExternalSetting(null, null, null, new ICSettingEntry[] {testSettingEntry}); // Write project description - listener.resetNotified(); + listener.clearNotified(); mngr.setProjectDescription(project, prjDescription); assertEquals(true, listener.isNotified()); @@ -759,7 +759,7 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ cfgDescription.removeExternalSettings(); // Write project description - listener.resetNotified(); + listener.clearNotified(); mngr.setProjectDescription(project, prjDescription); assertEquals(true, listener.isNotified()); @@ -810,7 +810,7 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ cfgDescription.setReferenceInfo(refs); // Write project description - listener.resetNotified(); + listener.clearNotified(); mngr.setProjectDescription(project, prjDescription); assertEquals(true, listener.isNotified()); @@ -870,7 +870,7 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ cfgDescription.setReferenceInfo(new HashMap()); // Write project description - listener.resetNotified(); + listener.clearNotified(); mngr.setProjectDescription(project, prjDescription); assertEquals(true, listener.isNotified()); @@ -918,7 +918,7 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ targetPlatformSetting.setBinaryParserIds(new String[] {testBinaryParserId}); // Write project description - listener.resetNotified(); + listener.clearNotified(); mngr.setProjectDescription(project, prjDescription); assertEquals(true, listener.isNotified()); @@ -971,7 +971,7 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ prjDescription.setDefaultSettingConfiguration(cfgDescription1); // Write project description - listener.resetNotified(); + listener.clearNotified(); mngr.setProjectDescription(project, prjDescription); assertEquals(true, listener.isNotified()); From 13efdec7b7248cdc88605c9db3ecfbccfc861805 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Wed, 14 Sep 2011 23:08:04 -0400 Subject: [PATCH 033/120] Do not allow changing list of providers for read-only configuration description --- ...nguageSettingsPersistenceProjectTests.java | 21 +++++ ...guageSettingsScannerInfoProviderTests.java | 76 ++++++++++++++----- .../model/CConfigurationDescriptionCache.java | 6 +- 3 files changed, 81 insertions(+), 22 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java index 103ebbb4c45..7dbdb464a2d 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java @@ -24,6 +24,7 @@ import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager; +import org.eclipse.cdt.core.settings.model.WriteAccessException; import org.eclipse.cdt.core.testplugin.CModelMock; import org.eclipse.cdt.core.testplugin.ResourceHelper; import org.eclipse.cdt.internal.core.XmlUtil; @@ -175,6 +176,26 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase { // test passes if no exception was thrown } + /** + */ + public void testReadOnlyDescription() throws Exception { + // create a project + IProject project = ResourceHelper.createCDTProjectWithConfig(getName()); + // get read-only description + ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false); + assertNotNull(prjDescription); + ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); + assertNotNull(cfgDescription); + + try { + List providers = new ArrayList(); + cfgDescription.setLanguageSettingProviders(providers); + fail("WriteAccessException was expected but it was not throw."); + } catch (WriteAccessException e) { + // exception is expected + } + } + /** */ public void testWorkspacePersistence_ModifiedExtensionProvider() throws Exception { diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsScannerInfoProviderTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsScannerInfoProviderTests.java index 5615a97bd41..dd2f0fa285d 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsScannerInfoProviderTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsScannerInfoProviderTests.java @@ -51,6 +51,10 @@ public class LanguageSettingsScannerInfoProviderTests extends TestCase { private static final String PROVIDER_ID = "test.provider.id"; private static final String PROVIDER_ID_2 = "test.provider.id.2"; private static final String PROVIDER_NAME = "test.provider.name"; + + // constants for getProjectDescription() + private static final boolean READ_ONLY = false; + private static final boolean WRITEABLE = true; private class MockProvider extends LanguageSettingsBaseProvider implements ILanguageSettingsProvider { private final List entries; @@ -106,7 +110,7 @@ public class LanguageSettingsScannerInfoProviderTests extends TestCase { private void setBuilderCWD(IProject project, IPath buildCWD) throws CoreException { CProjectDescriptionManager manager = CProjectDescriptionManager.getInstance(); { - ICProjectDescription prjDescription = manager.getProjectDescription(project, true); + ICProjectDescription prjDescription = manager.getProjectDescription(project, WRITEABLE); assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); assertNotNull(cfgDescription); @@ -119,7 +123,7 @@ public class LanguageSettingsScannerInfoProviderTests extends TestCase { } { // triplecheck builderCWD for different project/configuration descriptions - ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false); + ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, READ_ONLY); assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); assertNotNull(cfgDescription); @@ -148,7 +152,7 @@ public class LanguageSettingsScannerInfoProviderTests extends TestCase { { // Handle prjDescription==null IProject project = FAKE_FILE.getProject(); - ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false); + ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, READ_ONLY); assertNull(prjDescription); LanguageSettingsScannerInfoProvider scannerInfoProvider = new LanguageSettingsScannerInfoProvider(); @@ -166,7 +170,7 @@ public class LanguageSettingsScannerInfoProviderTests extends TestCase { IProject project = ResourceHelper.createCDTProjectWithConfig(getName()); IFile file = ResourceHelper.createFile(project, "file"); - ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false); + ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, READ_ONLY); assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); assertNotNull(cfgDescription); @@ -191,7 +195,7 @@ public class LanguageSettingsScannerInfoProviderTests extends TestCase { IFile file = ResourceHelper.createFile(project, "file.c"); // confirm that language==null - ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false); + ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, READ_ONLY); assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); assertNotNull(cfgDescription); @@ -213,7 +217,7 @@ public class LanguageSettingsScannerInfoProviderTests extends TestCase { public void testRegular() throws Exception { // create a project IProject project = ResourceHelper.createCDTProjectWithConfig(getName()); - ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false); + ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, WRITEABLE); assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); assertNotNull(cfgDescription); @@ -250,6 +254,9 @@ public class LanguageSettingsScannerInfoProviderTests extends TestCase { providers.add(provider); cfgDescription.setLanguageSettingProviders(providers); + // set project description + CProjectDescriptionManager.getInstance().setProjectDescription(project, prjDescription); + // test that the scannerInfoProvider gets the entries LanguageSettingsScannerInfoProvider scannerInfoProvider = new LanguageSettingsScannerInfoProvider(); ExtendedScannerInfo info = scannerInfoProvider.getScannerInformation(file); @@ -281,7 +288,7 @@ public class LanguageSettingsScannerInfoProviderTests extends TestCase { public void testLocal() throws Exception { // create a project IProject project = ResourceHelper.createCDTProjectWithConfig(getName()); - ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false); + ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, WRITEABLE); assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); assertNotNull(cfgDescription); @@ -310,6 +317,9 @@ public class LanguageSettingsScannerInfoProviderTests extends TestCase { providers.add(provider); cfgDescription.setLanguageSettingProviders(providers); + // set project description + CProjectDescriptionManager.getInstance().setProjectDescription(project, prjDescription); + // test that the scannerInfoProvider gets the entries LanguageSettingsScannerInfoProvider scannerInfoProvider = new LanguageSettingsScannerInfoProvider(); ExtendedScannerInfo info = scannerInfoProvider.getScannerInformation(file); @@ -331,7 +341,7 @@ public class LanguageSettingsScannerInfoProviderTests extends TestCase { public void testFramework() throws Exception { // create a project IProject project = ResourceHelper.createCDTProjectWithConfig(getName()); - ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false); + ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, WRITEABLE); assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); assertNotNull(cfgDescription); @@ -351,7 +361,10 @@ public class LanguageSettingsScannerInfoProviderTests extends TestCase { List providers = new ArrayList(); providers.add(provider); cfgDescription.setLanguageSettingProviders(providers); - + + // set project description + CProjectDescriptionManager.getInstance().setProjectDescription(project, prjDescription); + // test that the scannerInfoProvider gets the entries LanguageSettingsScannerInfoProvider scannerInfoProvider = new LanguageSettingsScannerInfoProvider(); ExtendedScannerInfo info = scannerInfoProvider.getScannerInformation(file); @@ -370,7 +383,7 @@ public class LanguageSettingsScannerInfoProviderTests extends TestCase { public void testDuplicate() throws Exception { // create a project IProject project = ResourceHelper.createCDTProjectWithConfig(getName()); - ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false); + ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, WRITEABLE); assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); assertNotNull(cfgDescription); @@ -397,6 +410,9 @@ public class LanguageSettingsScannerInfoProviderTests extends TestCase { providers.add(provider); cfgDescription.setLanguageSettingProviders(providers); + // set project description + CProjectDescriptionManager.getInstance().setProjectDescription(project, prjDescription); + // test that the scannerInfoProvider gets the entries LanguageSettingsScannerInfoProvider scannerInfoProvider = new LanguageSettingsScannerInfoProvider(); ExtendedScannerInfo info = scannerInfoProvider.getScannerInformation(file); @@ -416,7 +432,7 @@ public class LanguageSettingsScannerInfoProviderTests extends TestCase { public void testWorkspacePath() throws Exception { // create a project IProject project = ResourceHelper.createCDTProjectWithConfig(getName()); - ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false); + ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, WRITEABLE); assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); assertNotNull(cfgDescription); @@ -454,6 +470,9 @@ public class LanguageSettingsScannerInfoProviderTests extends TestCase { providers.add(provider); cfgDescription.setLanguageSettingProviders(providers); + // set project description + CProjectDescriptionManager.getInstance().setProjectDescription(project, prjDescription); + // test the entries received from the scannerInfoProvider LanguageSettingsScannerInfoProvider scannerInfoProvider = new LanguageSettingsScannerInfoProvider(); ExtendedScannerInfo info = scannerInfoProvider.getScannerInformation(file); @@ -481,7 +500,7 @@ public class LanguageSettingsScannerInfoProviderTests extends TestCase { // String buildCwdDevice = buildCWD.getDevice(); // get project/configuration descriptions - ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false); + ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, WRITEABLE); assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); assertNotNull(cfgDescription); @@ -502,6 +521,9 @@ public class LanguageSettingsScannerInfoProviderTests extends TestCase { providers.add(provider); cfgDescription.setLanguageSettingProviders(providers); + // set project description + CProjectDescriptionManager.getInstance().setProjectDescription(project, prjDescription); + // test the entries received from the scannerInfoProvider LanguageSettingsScannerInfoProvider scannerInfoProvider = new LanguageSettingsScannerInfoProvider(); ExtendedScannerInfo info = scannerInfoProvider.getScannerInformation(file); @@ -529,7 +551,7 @@ public class LanguageSettingsScannerInfoProviderTests extends TestCase { setBuilderCWD(project, buildCWD); // get project/configuration descriptions - ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false); + ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, WRITEABLE); assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); assertNotNull(cfgDescription); @@ -552,6 +574,9 @@ public class LanguageSettingsScannerInfoProviderTests extends TestCase { providers.add(provider); cfgDescription.setLanguageSettingProviders(providers); + // set project description + CProjectDescriptionManager.getInstance().setProjectDescription(project, prjDescription); + // test the entries received from the scannerInfoProvider LanguageSettingsScannerInfoProvider scannerInfoProvider = new LanguageSettingsScannerInfoProvider(); ExtendedScannerInfo info = scannerInfoProvider.getScannerInformation(file); @@ -595,7 +620,7 @@ public class LanguageSettingsScannerInfoProviderTests extends TestCase { IFolder incFolder_dotdot_slash_path = ResourceHelper.createFolder(project, "include2"); // "/ProjPath/buildDir/../include2" // get project/configuration descriptions - ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false); + ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, WRITEABLE); assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); assertNotNull(cfgDescription); @@ -628,6 +653,9 @@ public class LanguageSettingsScannerInfoProviderTests extends TestCase { providers.add(provider); cfgDescription.setLanguageSettingProviders(providers); + // set project description + CProjectDescriptionManager.getInstance().setProjectDescription(project, prjDescription); + // test the entries received from the scannerInfoProvider LanguageSettingsScannerInfoProvider scannerInfoProvider = new LanguageSettingsScannerInfoProvider(); ExtendedScannerInfo info = scannerInfoProvider.getScannerInformation(file); @@ -674,7 +702,7 @@ public class LanguageSettingsScannerInfoProviderTests extends TestCase { String envPathStr = "${ProjDirPath}/Folder"; // get project/configuration descriptions - ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false); + ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, WRITEABLE); assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); assertNotNull(cfgDescription); @@ -693,6 +721,9 @@ public class LanguageSettingsScannerInfoProviderTests extends TestCase { providers.add(provider); cfgDescription.setLanguageSettingProviders(providers); + // set project description + CProjectDescriptionManager.getInstance().setProjectDescription(project, prjDescription); + // test the entries received from the scannerInfoProvider LanguageSettingsScannerInfoProvider scannerInfoProvider = new LanguageSettingsScannerInfoProvider(); ExtendedScannerInfo info = scannerInfoProvider.getScannerInformation(file); @@ -726,7 +757,7 @@ public class LanguageSettingsScannerInfoProviderTests extends TestCase { // create a project IProject project = ResourceHelper.createCDTProjectWithConfig(getName()); - ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false); + ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, WRITEABLE); assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); assertNotNull(cfgDescription); @@ -751,6 +782,9 @@ public class LanguageSettingsScannerInfoProviderTests extends TestCase { providers.add(provider); cfgDescription.setLanguageSettingProviders(providers); + // set project description + CProjectDescriptionManager.getInstance().setProjectDescription(project, prjDescription); + // test that the scannerInfoProvider gets the entries for LanguageSettingsScannerInfoProvider scannerInfoProvider = new LanguageSettingsScannerInfoProvider(); ExtendedScannerInfo info = scannerInfoProvider.getScannerInformation(file); @@ -770,7 +804,7 @@ public class LanguageSettingsScannerInfoProviderTests extends TestCase { String envPathStr = "${ProjDirPath}/Folder"; // get project/configuration descriptions - ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false); + ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, WRITEABLE); assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); assertNotNull(cfgDescription); @@ -788,6 +822,9 @@ public class LanguageSettingsScannerInfoProviderTests extends TestCase { List providers = new ArrayList(); providers.add(provider); cfgDescription.setLanguageSettingProviders(providers); + + // set project description + CProjectDescriptionManager.getInstance().setProjectDescription(project, prjDescription); // test the entries received from the scannerInfoProvider LanguageSettingsScannerInfoProvider scannerInfoProvider = new LanguageSettingsScannerInfoProvider(); @@ -848,7 +885,7 @@ public class LanguageSettingsScannerInfoProviderTests extends TestCase { IFolder incFolderC = ResourceHelper.createFolder(project, "includeC"); // get project/configuration descriptions - ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false); + ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, WRITEABLE); assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); assertNotNull(cfgDescription); @@ -878,6 +915,9 @@ public class LanguageSettingsScannerInfoProviderTests extends TestCase { providers.add(provider2); cfgDescription.setLanguageSettingProviders(providers); + // set project description + CProjectDescriptionManager.getInstance().setProjectDescription(project, prjDescription); + // test the entries received from the scannerInfoProvider LanguageSettingsScannerInfoProvider scannerInfoProvider = new LanguageSettingsScannerInfoProvider(); ExtendedScannerInfo info = scannerInfoProvider.getScannerInformation(folder); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationDescriptionCache.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationDescriptionCache.java index 0c64dbc3ce3..c96186948e8 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationDescriptionCache.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationDescriptionCache.java @@ -559,10 +559,8 @@ public class CConfigurationDescriptionCache extends CDefaultConfigurationData } public void setLanguageSettingProviders(List providers) { -// FIXME? - not sure -// if(!fInitializing) -// throw ExceptionFactory.createIsReadOnlyException(); - + if(!fInitializing) + throw ExceptionFactory.createIsReadOnlyException(); fSpecSettings.setLanguageSettingProviders(providers); } From 36ffaae0d0e1d8357963ac985a8bc6abc3fe08ec Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Wed, 14 Sep 2011 23:53:10 -0400 Subject: [PATCH 034/120] permissions mismatch --- .../depCalcProjects/test1DepCalc2/test1DepCalc2.zip | Bin .../depCalcProjects/test1DepCalc3/test1DepCalc3.zip | Bin .../test1DepCalcPreBuild/test1DepCalcPreBuild.zip | Bin .../ManagedBuildDependencyCalculatorTests.java | 0 .../makegen/IManagedDependencyCalculator.java | 0 .../makegen/IManagedDependencyCommands.java | 0 .../makegen/IManagedDependencyGeneratorType.java | 0 .../makegen/IManagedDependencyInfo.java | 0 .../makegen/IManagedDependencyPreBuild.java | 0 .../gnu/DefaultGCCDependencyCalculator2.java | 0 .../DefaultGCCDependencyCalculator2Commands.java | 0 .../gnu/DefaultGCCDependencyCalculator3.java | 0 .../DefaultGCCDependencyCalculator3Commands.java | 0 .../gnu/DefaultGCCDependencyCalculatorPreBuild.java | 0 ...aultGCCDependencyCalculatorPreBuildCommands.java | 0 .../makegen/gnu/GnuDependencyGroupInfo.java | 0 .../os/macosx/x86/libpty.jnilib | Bin .../os/macosx/x86/libspawner.jnilib | Bin cross/org.eclipse.cdt.build.crossgcc/.classpath | 0 cross/org.eclipse.cdt.build.crossgcc/.project | 0 .../.settings/org.eclipse.jdt.core.prefs | 0 .../META-INF/MANIFEST.MF | 0 .../org.eclipse.cdt.build.crossgcc/build.properties | 0 .../cdt/build/crossgcc/SetCrossCommandProcess.java | 0 .../cdt/internal/build/crossgcc/Activator.java | 0 .../build/crossgcc/CrossCommandLineGenerator.java | 0 .../crossgcc/CrossEnvironmentVariableSupplier.java | 0 .../templates/setCrossCommand/template.xml | 0 .../debug/core/command/CCommandAdapterFactory.java | 0 .../cdt/debug/core/command/CForEachCommand.java | 0 .../cdt/debug/core/command/RestartCommand.java | 0 .../icons/obj16/reverse_stepinto.gif | Bin .../icons/obj16/reverse_stepover.gif | Bin .../org.eclipse.cdt.debug.ui/icons/obj16/uncall.gif | Bin doc/org.eclipse.cdt.doc.user/images/btn_columns.png | Bin .../images/btn_import_executables.png | Bin doc/org.eclipse.cdt.doc.user/images/btn_restart.png | Bin doc/org.eclipse.cdt.doc.user/images/c_exe_obj.png | Bin .../images/c_object_file.png | Bin .../images/cdt_dlg_define_build_var.png | Bin .../images/cdt_dlg_edit_build_var.png | Bin .../images/cdt_menu_toggle_comments.png | Bin .../images/cdt_pref_build_vars.png | Bin .../images/cdt_pref_new_task_tag_dlg.png | Bin .../images/cdt_pref_task_tags.png | Bin .../images/cdt_w_basic06a.png | Bin .../images/cdt_w_debug_configurations_01.png | Bin .../images/cdt_w_debug_configurations_02.png | Bin .../images/command_link.png | Bin .../images/editor_mark_preferences.png | Bin .../images/editor_save_actions_preferences.png | Bin .../images/hierarchy_co.gif | Bin .../images/history_list.gif | Bin .../images/icon_build_make_target.png | Bin .../images/icon_clear_console.png | Bin .../images/icon_edit_make_target.png | Bin .../images/icon_expand_all.png | Bin .../images/icon_hide_inactive_includes.png | Bin .../images/icon_hide_make_targets.png | Bin .../images/icon_hide_sys_includes.png | Bin .../images/icon_new_make_target.png | Bin .../images/icon_next_error.png | Bin .../images/icon_open_console.png | Bin doc/org.eclipse.cdt.doc.user/images/icon_pin.png | Bin .../images/icon_prev_error.png | Bin .../images/icon_repeat_search.png | Bin .../images/icon_save_output_file.png | Bin .../images/icon_show_error.png | Bin .../images/namespace_declared_obj.png | Bin .../images/new_proj_convert_candidate.png | Bin .../images/pref_panel_build.png | Bin .../images/pref_panel_code_templates.png | Bin .../images/pref_panel_edit_template_dlg.png | Bin .../images/pref_traditional_memory_prefs.png | Bin .../images/progress_stop.gif | Bin doc/org.eclipse.cdt.doc.user/images/refresh_nav.gif | Bin doc/org.eclipse.cdt.doc.user/images/sub_co.gif | Bin doc/org.eclipse.cdt.doc.user/images/super_co.gif | Bin .../images/view_executables.png | Bin .../images/view_include_browser.png | Bin .../images/view_table_rendering.png | Bin .../icons/full/obj16/connect.gif | Bin .../icons/full/obj16/reversestepinto.gif | Bin .../icons/full/obj16/reversestepover.gif | Bin .../icons/full/obj16/stop_visual_trace.gif | Bin .../icons/full/obj16/uncall.gif | Bin dsf/org.eclipse.cdt.examples.dsf.pda/.options | 0 .../icons/memorybrowser_view.gif | Bin 88 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 build/org.eclipse.cdt.managedbuilder.core.tests/resources/depCalcProjects/test1DepCalc2/test1DepCalc2.zip mode change 100644 => 100755 build/org.eclipse.cdt.managedbuilder.core.tests/resources/depCalcProjects/test1DepCalc3/test1DepCalc3.zip mode change 100644 => 100755 build/org.eclipse.cdt.managedbuilder.core.tests/resources/depCalcProjects/test1DepCalcPreBuild/test1DepCalcPreBuild.zip mode change 100644 => 100755 build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/ManagedBuildDependencyCalculatorTests.java mode change 100644 => 100755 build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/IManagedDependencyCalculator.java mode change 100644 => 100755 build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/IManagedDependencyCommands.java mode change 100644 => 100755 build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/IManagedDependencyGeneratorType.java mode change 100644 => 100755 build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/IManagedDependencyInfo.java mode change 100644 => 100755 build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/IManagedDependencyPreBuild.java mode change 100644 => 100755 build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/DefaultGCCDependencyCalculator2.java mode change 100644 => 100755 build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/DefaultGCCDependencyCalculator2Commands.java mode change 100644 => 100755 build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/DefaultGCCDependencyCalculator3.java mode change 100644 => 100755 build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/DefaultGCCDependencyCalculator3Commands.java mode change 100644 => 100755 build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/DefaultGCCDependencyCalculatorPreBuild.java mode change 100644 => 100755 build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/DefaultGCCDependencyCalculatorPreBuildCommands.java mode change 100644 => 100755 build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/GnuDependencyGroupInfo.java mode change 100644 => 100755 core/org.eclipse.cdt.core.macosx/os/macosx/x86/libpty.jnilib mode change 100644 => 100755 core/org.eclipse.cdt.core.macosx/os/macosx/x86/libspawner.jnilib mode change 100644 => 100755 cross/org.eclipse.cdt.build.crossgcc/.classpath mode change 100644 => 100755 cross/org.eclipse.cdt.build.crossgcc/.project mode change 100644 => 100755 cross/org.eclipse.cdt.build.crossgcc/.settings/org.eclipse.jdt.core.prefs mode change 100644 => 100755 cross/org.eclipse.cdt.build.crossgcc/META-INF/MANIFEST.MF mode change 100644 => 100755 cross/org.eclipse.cdt.build.crossgcc/build.properties mode change 100644 => 100755 cross/org.eclipse.cdt.build.crossgcc/src/org/eclipse/cdt/build/crossgcc/SetCrossCommandProcess.java mode change 100644 => 100755 cross/org.eclipse.cdt.build.crossgcc/src/org/eclipse/cdt/internal/build/crossgcc/Activator.java mode change 100644 => 100755 cross/org.eclipse.cdt.build.crossgcc/src/org/eclipse/cdt/internal/build/crossgcc/CrossCommandLineGenerator.java mode change 100644 => 100755 cross/org.eclipse.cdt.build.crossgcc/src/org/eclipse/cdt/internal/build/crossgcc/CrossEnvironmentVariableSupplier.java mode change 100644 => 100755 cross/org.eclipse.cdt.build.crossgcc/templates/setCrossCommand/template.xml mode change 100644 => 100755 debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/command/CCommandAdapterFactory.java mode change 100644 => 100755 debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/command/CForEachCommand.java mode change 100644 => 100755 debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/command/RestartCommand.java mode change 100644 => 100755 debug/org.eclipse.cdt.debug.ui/icons/obj16/reverse_stepinto.gif mode change 100644 => 100755 debug/org.eclipse.cdt.debug.ui/icons/obj16/reverse_stepover.gif mode change 100644 => 100755 debug/org.eclipse.cdt.debug.ui/icons/obj16/uncall.gif mode change 100644 => 100755 doc/org.eclipse.cdt.doc.user/images/btn_columns.png mode change 100644 => 100755 doc/org.eclipse.cdt.doc.user/images/btn_import_executables.png mode change 100644 => 100755 doc/org.eclipse.cdt.doc.user/images/btn_restart.png mode change 100644 => 100755 doc/org.eclipse.cdt.doc.user/images/c_exe_obj.png mode change 100644 => 100755 doc/org.eclipse.cdt.doc.user/images/c_object_file.png mode change 100644 => 100755 doc/org.eclipse.cdt.doc.user/images/cdt_dlg_define_build_var.png mode change 100644 => 100755 doc/org.eclipse.cdt.doc.user/images/cdt_dlg_edit_build_var.png mode change 100644 => 100755 doc/org.eclipse.cdt.doc.user/images/cdt_menu_toggle_comments.png mode change 100644 => 100755 doc/org.eclipse.cdt.doc.user/images/cdt_pref_build_vars.png mode change 100644 => 100755 doc/org.eclipse.cdt.doc.user/images/cdt_pref_new_task_tag_dlg.png mode change 100644 => 100755 doc/org.eclipse.cdt.doc.user/images/cdt_pref_task_tags.png mode change 100644 => 100755 doc/org.eclipse.cdt.doc.user/images/cdt_w_basic06a.png mode change 100644 => 100755 doc/org.eclipse.cdt.doc.user/images/cdt_w_debug_configurations_01.png mode change 100644 => 100755 doc/org.eclipse.cdt.doc.user/images/cdt_w_debug_configurations_02.png mode change 100644 => 100755 doc/org.eclipse.cdt.doc.user/images/command_link.png mode change 100644 => 100755 doc/org.eclipse.cdt.doc.user/images/editor_mark_preferences.png mode change 100644 => 100755 doc/org.eclipse.cdt.doc.user/images/editor_save_actions_preferences.png mode change 100644 => 100755 doc/org.eclipse.cdt.doc.user/images/hierarchy_co.gif mode change 100644 => 100755 doc/org.eclipse.cdt.doc.user/images/history_list.gif mode change 100644 => 100755 doc/org.eclipse.cdt.doc.user/images/icon_build_make_target.png mode change 100644 => 100755 doc/org.eclipse.cdt.doc.user/images/icon_clear_console.png mode change 100644 => 100755 doc/org.eclipse.cdt.doc.user/images/icon_edit_make_target.png mode change 100644 => 100755 doc/org.eclipse.cdt.doc.user/images/icon_expand_all.png mode change 100644 => 100755 doc/org.eclipse.cdt.doc.user/images/icon_hide_inactive_includes.png mode change 100644 => 100755 doc/org.eclipse.cdt.doc.user/images/icon_hide_make_targets.png mode change 100644 => 100755 doc/org.eclipse.cdt.doc.user/images/icon_hide_sys_includes.png mode change 100644 => 100755 doc/org.eclipse.cdt.doc.user/images/icon_new_make_target.png mode change 100644 => 100755 doc/org.eclipse.cdt.doc.user/images/icon_next_error.png mode change 100644 => 100755 doc/org.eclipse.cdt.doc.user/images/icon_open_console.png mode change 100644 => 100755 doc/org.eclipse.cdt.doc.user/images/icon_pin.png mode change 100644 => 100755 doc/org.eclipse.cdt.doc.user/images/icon_prev_error.png mode change 100644 => 100755 doc/org.eclipse.cdt.doc.user/images/icon_repeat_search.png mode change 100644 => 100755 doc/org.eclipse.cdt.doc.user/images/icon_save_output_file.png mode change 100644 => 100755 doc/org.eclipse.cdt.doc.user/images/icon_show_error.png mode change 100644 => 100755 doc/org.eclipse.cdt.doc.user/images/namespace_declared_obj.png mode change 100644 => 100755 doc/org.eclipse.cdt.doc.user/images/new_proj_convert_candidate.png mode change 100644 => 100755 doc/org.eclipse.cdt.doc.user/images/pref_panel_build.png mode change 100644 => 100755 doc/org.eclipse.cdt.doc.user/images/pref_panel_code_templates.png mode change 100644 => 100755 doc/org.eclipse.cdt.doc.user/images/pref_panel_edit_template_dlg.png mode change 100644 => 100755 doc/org.eclipse.cdt.doc.user/images/pref_traditional_memory_prefs.png mode change 100644 => 100755 doc/org.eclipse.cdt.doc.user/images/progress_stop.gif mode change 100644 => 100755 doc/org.eclipse.cdt.doc.user/images/refresh_nav.gif mode change 100644 => 100755 doc/org.eclipse.cdt.doc.user/images/sub_co.gif mode change 100644 => 100755 doc/org.eclipse.cdt.doc.user/images/super_co.gif mode change 100644 => 100755 doc/org.eclipse.cdt.doc.user/images/view_executables.png mode change 100644 => 100755 doc/org.eclipse.cdt.doc.user/images/view_include_browser.png mode change 100644 => 100755 doc/org.eclipse.cdt.doc.user/images/view_table_rendering.png mode change 100644 => 100755 dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/icons/full/obj16/connect.gif mode change 100644 => 100755 dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/icons/full/obj16/reversestepinto.gif mode change 100644 => 100755 dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/icons/full/obj16/reversestepover.gif mode change 100644 => 100755 dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/icons/full/obj16/stop_visual_trace.gif mode change 100644 => 100755 dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/icons/full/obj16/uncall.gif mode change 100644 => 100755 dsf/org.eclipse.cdt.examples.dsf.pda/.options mode change 100644 => 100755 memory/org.eclipse.cdt.debug.ui.memory.memorybrowser/icons/memorybrowser_view.gif diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/resources/depCalcProjects/test1DepCalc2/test1DepCalc2.zip b/build/org.eclipse.cdt.managedbuilder.core.tests/resources/depCalcProjects/test1DepCalc2/test1DepCalc2.zip old mode 100644 new mode 100755 diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/resources/depCalcProjects/test1DepCalc3/test1DepCalc3.zip b/build/org.eclipse.cdt.managedbuilder.core.tests/resources/depCalcProjects/test1DepCalc3/test1DepCalc3.zip old mode 100644 new mode 100755 diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/resources/depCalcProjects/test1DepCalcPreBuild/test1DepCalcPreBuild.zip b/build/org.eclipse.cdt.managedbuilder.core.tests/resources/depCalcProjects/test1DepCalcPreBuild/test1DepCalcPreBuild.zip old mode 100644 new mode 100755 diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/ManagedBuildDependencyCalculatorTests.java b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/ManagedBuildDependencyCalculatorTests.java old mode 100644 new mode 100755 diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/IManagedDependencyCalculator.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/IManagedDependencyCalculator.java old mode 100644 new mode 100755 diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/IManagedDependencyCommands.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/IManagedDependencyCommands.java old mode 100644 new mode 100755 diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/IManagedDependencyGeneratorType.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/IManagedDependencyGeneratorType.java old mode 100644 new mode 100755 diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/IManagedDependencyInfo.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/IManagedDependencyInfo.java old mode 100644 new mode 100755 diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/IManagedDependencyPreBuild.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/IManagedDependencyPreBuild.java old mode 100644 new mode 100755 diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/DefaultGCCDependencyCalculator2.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/DefaultGCCDependencyCalculator2.java old mode 100644 new mode 100755 diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/DefaultGCCDependencyCalculator2Commands.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/DefaultGCCDependencyCalculator2Commands.java old mode 100644 new mode 100755 diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/DefaultGCCDependencyCalculator3.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/DefaultGCCDependencyCalculator3.java old mode 100644 new mode 100755 diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/DefaultGCCDependencyCalculator3Commands.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/DefaultGCCDependencyCalculator3Commands.java old mode 100644 new mode 100755 diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/DefaultGCCDependencyCalculatorPreBuild.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/DefaultGCCDependencyCalculatorPreBuild.java old mode 100644 new mode 100755 diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/DefaultGCCDependencyCalculatorPreBuildCommands.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/DefaultGCCDependencyCalculatorPreBuildCommands.java old mode 100644 new mode 100755 diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/GnuDependencyGroupInfo.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/GnuDependencyGroupInfo.java old mode 100644 new mode 100755 diff --git a/core/org.eclipse.cdt.core.macosx/os/macosx/x86/libpty.jnilib b/core/org.eclipse.cdt.core.macosx/os/macosx/x86/libpty.jnilib old mode 100644 new mode 100755 diff --git a/core/org.eclipse.cdt.core.macosx/os/macosx/x86/libspawner.jnilib b/core/org.eclipse.cdt.core.macosx/os/macosx/x86/libspawner.jnilib old mode 100644 new mode 100755 diff --git a/cross/org.eclipse.cdt.build.crossgcc/.classpath b/cross/org.eclipse.cdt.build.crossgcc/.classpath old mode 100644 new mode 100755 diff --git a/cross/org.eclipse.cdt.build.crossgcc/.project b/cross/org.eclipse.cdt.build.crossgcc/.project old mode 100644 new mode 100755 diff --git a/cross/org.eclipse.cdt.build.crossgcc/.settings/org.eclipse.jdt.core.prefs b/cross/org.eclipse.cdt.build.crossgcc/.settings/org.eclipse.jdt.core.prefs old mode 100644 new mode 100755 diff --git a/cross/org.eclipse.cdt.build.crossgcc/META-INF/MANIFEST.MF b/cross/org.eclipse.cdt.build.crossgcc/META-INF/MANIFEST.MF old mode 100644 new mode 100755 diff --git a/cross/org.eclipse.cdt.build.crossgcc/build.properties b/cross/org.eclipse.cdt.build.crossgcc/build.properties old mode 100644 new mode 100755 diff --git a/cross/org.eclipse.cdt.build.crossgcc/src/org/eclipse/cdt/build/crossgcc/SetCrossCommandProcess.java b/cross/org.eclipse.cdt.build.crossgcc/src/org/eclipse/cdt/build/crossgcc/SetCrossCommandProcess.java old mode 100644 new mode 100755 diff --git a/cross/org.eclipse.cdt.build.crossgcc/src/org/eclipse/cdt/internal/build/crossgcc/Activator.java b/cross/org.eclipse.cdt.build.crossgcc/src/org/eclipse/cdt/internal/build/crossgcc/Activator.java old mode 100644 new mode 100755 diff --git a/cross/org.eclipse.cdt.build.crossgcc/src/org/eclipse/cdt/internal/build/crossgcc/CrossCommandLineGenerator.java b/cross/org.eclipse.cdt.build.crossgcc/src/org/eclipse/cdt/internal/build/crossgcc/CrossCommandLineGenerator.java old mode 100644 new mode 100755 diff --git a/cross/org.eclipse.cdt.build.crossgcc/src/org/eclipse/cdt/internal/build/crossgcc/CrossEnvironmentVariableSupplier.java b/cross/org.eclipse.cdt.build.crossgcc/src/org/eclipse/cdt/internal/build/crossgcc/CrossEnvironmentVariableSupplier.java old mode 100644 new mode 100755 diff --git a/cross/org.eclipse.cdt.build.crossgcc/templates/setCrossCommand/template.xml b/cross/org.eclipse.cdt.build.crossgcc/templates/setCrossCommand/template.xml old mode 100644 new mode 100755 diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/command/CCommandAdapterFactory.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/command/CCommandAdapterFactory.java old mode 100644 new mode 100755 diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/command/CForEachCommand.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/command/CForEachCommand.java old mode 100644 new mode 100755 diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/command/RestartCommand.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/command/RestartCommand.java old mode 100644 new mode 100755 diff --git a/debug/org.eclipse.cdt.debug.ui/icons/obj16/reverse_stepinto.gif b/debug/org.eclipse.cdt.debug.ui/icons/obj16/reverse_stepinto.gif old mode 100644 new mode 100755 diff --git a/debug/org.eclipse.cdt.debug.ui/icons/obj16/reverse_stepover.gif b/debug/org.eclipse.cdt.debug.ui/icons/obj16/reverse_stepover.gif old mode 100644 new mode 100755 diff --git a/debug/org.eclipse.cdt.debug.ui/icons/obj16/uncall.gif b/debug/org.eclipse.cdt.debug.ui/icons/obj16/uncall.gif old mode 100644 new mode 100755 diff --git a/doc/org.eclipse.cdt.doc.user/images/btn_columns.png b/doc/org.eclipse.cdt.doc.user/images/btn_columns.png old mode 100644 new mode 100755 diff --git a/doc/org.eclipse.cdt.doc.user/images/btn_import_executables.png b/doc/org.eclipse.cdt.doc.user/images/btn_import_executables.png old mode 100644 new mode 100755 diff --git a/doc/org.eclipse.cdt.doc.user/images/btn_restart.png b/doc/org.eclipse.cdt.doc.user/images/btn_restart.png old mode 100644 new mode 100755 diff --git a/doc/org.eclipse.cdt.doc.user/images/c_exe_obj.png b/doc/org.eclipse.cdt.doc.user/images/c_exe_obj.png old mode 100644 new mode 100755 diff --git a/doc/org.eclipse.cdt.doc.user/images/c_object_file.png b/doc/org.eclipse.cdt.doc.user/images/c_object_file.png old mode 100644 new mode 100755 diff --git a/doc/org.eclipse.cdt.doc.user/images/cdt_dlg_define_build_var.png b/doc/org.eclipse.cdt.doc.user/images/cdt_dlg_define_build_var.png old mode 100644 new mode 100755 diff --git a/doc/org.eclipse.cdt.doc.user/images/cdt_dlg_edit_build_var.png b/doc/org.eclipse.cdt.doc.user/images/cdt_dlg_edit_build_var.png old mode 100644 new mode 100755 diff --git a/doc/org.eclipse.cdt.doc.user/images/cdt_menu_toggle_comments.png b/doc/org.eclipse.cdt.doc.user/images/cdt_menu_toggle_comments.png old mode 100644 new mode 100755 diff --git a/doc/org.eclipse.cdt.doc.user/images/cdt_pref_build_vars.png b/doc/org.eclipse.cdt.doc.user/images/cdt_pref_build_vars.png old mode 100644 new mode 100755 diff --git a/doc/org.eclipse.cdt.doc.user/images/cdt_pref_new_task_tag_dlg.png b/doc/org.eclipse.cdt.doc.user/images/cdt_pref_new_task_tag_dlg.png old mode 100644 new mode 100755 diff --git a/doc/org.eclipse.cdt.doc.user/images/cdt_pref_task_tags.png b/doc/org.eclipse.cdt.doc.user/images/cdt_pref_task_tags.png old mode 100644 new mode 100755 diff --git a/doc/org.eclipse.cdt.doc.user/images/cdt_w_basic06a.png b/doc/org.eclipse.cdt.doc.user/images/cdt_w_basic06a.png old mode 100644 new mode 100755 diff --git a/doc/org.eclipse.cdt.doc.user/images/cdt_w_debug_configurations_01.png b/doc/org.eclipse.cdt.doc.user/images/cdt_w_debug_configurations_01.png old mode 100644 new mode 100755 diff --git a/doc/org.eclipse.cdt.doc.user/images/cdt_w_debug_configurations_02.png b/doc/org.eclipse.cdt.doc.user/images/cdt_w_debug_configurations_02.png old mode 100644 new mode 100755 diff --git a/doc/org.eclipse.cdt.doc.user/images/command_link.png b/doc/org.eclipse.cdt.doc.user/images/command_link.png old mode 100644 new mode 100755 diff --git a/doc/org.eclipse.cdt.doc.user/images/editor_mark_preferences.png b/doc/org.eclipse.cdt.doc.user/images/editor_mark_preferences.png old mode 100644 new mode 100755 diff --git a/doc/org.eclipse.cdt.doc.user/images/editor_save_actions_preferences.png b/doc/org.eclipse.cdt.doc.user/images/editor_save_actions_preferences.png old mode 100644 new mode 100755 diff --git a/doc/org.eclipse.cdt.doc.user/images/hierarchy_co.gif b/doc/org.eclipse.cdt.doc.user/images/hierarchy_co.gif old mode 100644 new mode 100755 diff --git a/doc/org.eclipse.cdt.doc.user/images/history_list.gif b/doc/org.eclipse.cdt.doc.user/images/history_list.gif old mode 100644 new mode 100755 diff --git a/doc/org.eclipse.cdt.doc.user/images/icon_build_make_target.png b/doc/org.eclipse.cdt.doc.user/images/icon_build_make_target.png old mode 100644 new mode 100755 diff --git a/doc/org.eclipse.cdt.doc.user/images/icon_clear_console.png b/doc/org.eclipse.cdt.doc.user/images/icon_clear_console.png old mode 100644 new mode 100755 diff --git a/doc/org.eclipse.cdt.doc.user/images/icon_edit_make_target.png b/doc/org.eclipse.cdt.doc.user/images/icon_edit_make_target.png old mode 100644 new mode 100755 diff --git a/doc/org.eclipse.cdt.doc.user/images/icon_expand_all.png b/doc/org.eclipse.cdt.doc.user/images/icon_expand_all.png old mode 100644 new mode 100755 diff --git a/doc/org.eclipse.cdt.doc.user/images/icon_hide_inactive_includes.png b/doc/org.eclipse.cdt.doc.user/images/icon_hide_inactive_includes.png old mode 100644 new mode 100755 diff --git a/doc/org.eclipse.cdt.doc.user/images/icon_hide_make_targets.png b/doc/org.eclipse.cdt.doc.user/images/icon_hide_make_targets.png old mode 100644 new mode 100755 diff --git a/doc/org.eclipse.cdt.doc.user/images/icon_hide_sys_includes.png b/doc/org.eclipse.cdt.doc.user/images/icon_hide_sys_includes.png old mode 100644 new mode 100755 diff --git a/doc/org.eclipse.cdt.doc.user/images/icon_new_make_target.png b/doc/org.eclipse.cdt.doc.user/images/icon_new_make_target.png old mode 100644 new mode 100755 diff --git a/doc/org.eclipse.cdt.doc.user/images/icon_next_error.png b/doc/org.eclipse.cdt.doc.user/images/icon_next_error.png old mode 100644 new mode 100755 diff --git a/doc/org.eclipse.cdt.doc.user/images/icon_open_console.png b/doc/org.eclipse.cdt.doc.user/images/icon_open_console.png old mode 100644 new mode 100755 diff --git a/doc/org.eclipse.cdt.doc.user/images/icon_pin.png b/doc/org.eclipse.cdt.doc.user/images/icon_pin.png old mode 100644 new mode 100755 diff --git a/doc/org.eclipse.cdt.doc.user/images/icon_prev_error.png b/doc/org.eclipse.cdt.doc.user/images/icon_prev_error.png old mode 100644 new mode 100755 diff --git a/doc/org.eclipse.cdt.doc.user/images/icon_repeat_search.png b/doc/org.eclipse.cdt.doc.user/images/icon_repeat_search.png old mode 100644 new mode 100755 diff --git a/doc/org.eclipse.cdt.doc.user/images/icon_save_output_file.png b/doc/org.eclipse.cdt.doc.user/images/icon_save_output_file.png old mode 100644 new mode 100755 diff --git a/doc/org.eclipse.cdt.doc.user/images/icon_show_error.png b/doc/org.eclipse.cdt.doc.user/images/icon_show_error.png old mode 100644 new mode 100755 diff --git a/doc/org.eclipse.cdt.doc.user/images/namespace_declared_obj.png b/doc/org.eclipse.cdt.doc.user/images/namespace_declared_obj.png old mode 100644 new mode 100755 diff --git a/doc/org.eclipse.cdt.doc.user/images/new_proj_convert_candidate.png b/doc/org.eclipse.cdt.doc.user/images/new_proj_convert_candidate.png old mode 100644 new mode 100755 diff --git a/doc/org.eclipse.cdt.doc.user/images/pref_panel_build.png b/doc/org.eclipse.cdt.doc.user/images/pref_panel_build.png old mode 100644 new mode 100755 diff --git a/doc/org.eclipse.cdt.doc.user/images/pref_panel_code_templates.png b/doc/org.eclipse.cdt.doc.user/images/pref_panel_code_templates.png old mode 100644 new mode 100755 diff --git a/doc/org.eclipse.cdt.doc.user/images/pref_panel_edit_template_dlg.png b/doc/org.eclipse.cdt.doc.user/images/pref_panel_edit_template_dlg.png old mode 100644 new mode 100755 diff --git a/doc/org.eclipse.cdt.doc.user/images/pref_traditional_memory_prefs.png b/doc/org.eclipse.cdt.doc.user/images/pref_traditional_memory_prefs.png old mode 100644 new mode 100755 diff --git a/doc/org.eclipse.cdt.doc.user/images/progress_stop.gif b/doc/org.eclipse.cdt.doc.user/images/progress_stop.gif old mode 100644 new mode 100755 diff --git a/doc/org.eclipse.cdt.doc.user/images/refresh_nav.gif b/doc/org.eclipse.cdt.doc.user/images/refresh_nav.gif old mode 100644 new mode 100755 diff --git a/doc/org.eclipse.cdt.doc.user/images/sub_co.gif b/doc/org.eclipse.cdt.doc.user/images/sub_co.gif old mode 100644 new mode 100755 diff --git a/doc/org.eclipse.cdt.doc.user/images/super_co.gif b/doc/org.eclipse.cdt.doc.user/images/super_co.gif old mode 100644 new mode 100755 diff --git a/doc/org.eclipse.cdt.doc.user/images/view_executables.png b/doc/org.eclipse.cdt.doc.user/images/view_executables.png old mode 100644 new mode 100755 diff --git a/doc/org.eclipse.cdt.doc.user/images/view_include_browser.png b/doc/org.eclipse.cdt.doc.user/images/view_include_browser.png old mode 100644 new mode 100755 diff --git a/doc/org.eclipse.cdt.doc.user/images/view_table_rendering.png b/doc/org.eclipse.cdt.doc.user/images/view_table_rendering.png old mode 100644 new mode 100755 diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/icons/full/obj16/connect.gif b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/icons/full/obj16/connect.gif old mode 100644 new mode 100755 diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/icons/full/obj16/reversestepinto.gif b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/icons/full/obj16/reversestepinto.gif old mode 100644 new mode 100755 diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/icons/full/obj16/reversestepover.gif b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/icons/full/obj16/reversestepover.gif old mode 100644 new mode 100755 diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/icons/full/obj16/stop_visual_trace.gif b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/icons/full/obj16/stop_visual_trace.gif old mode 100644 new mode 100755 diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/icons/full/obj16/uncall.gif b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/icons/full/obj16/uncall.gif old mode 100644 new mode 100755 diff --git a/dsf/org.eclipse.cdt.examples.dsf.pda/.options b/dsf/org.eclipse.cdt.examples.dsf.pda/.options old mode 100644 new mode 100755 diff --git a/memory/org.eclipse.cdt.debug.ui.memory.memorybrowser/icons/memorybrowser_view.gif b/memory/org.eclipse.cdt.debug.ui.memory.memorybrowser/icons/memorybrowser_view.gif old mode 100644 new mode 100755 From 6a200bcbce52357df5d4444a4b1f5d2647df8ddf Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Mon, 19 Sep 2011 14:39:09 -0400 Subject: [PATCH 035/120] use platform locking for project store --- .../LanguageSettingsProvidersSerializer.java | 108 ++++++++++-------- 1 file changed, 59 insertions(+), 49 deletions(-) diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java index f971d336b3c..954461c3e75 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java @@ -36,13 +36,14 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.ILock; +import org.eclipse.core.runtime.jobs.Job; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class LanguageSettingsProvidersSerializer { - 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_LANGUAGE_SETTINGS = "language.settings.xml"; //$NON-NLS-1$ @@ -54,9 +55,9 @@ public class LanguageSettingsProvidersSerializer { private static final String ELEM_CONFIGURATION = "configuration"; //$NON-NLS-1$ private static final String ELEM_PROVIDER = "provider"; //$NON-NLS-1$ private static final String ELEM_PROVIDER_REFERENCE = "provider-reference"; //$NON-NLS-1$ + private static ILock serializingLock = Job.getJobManager().newLock(); /** Cache of globally available providers to be consumed by calling clients */ private static Map rawGlobalWorkspaceProviders = new HashMap(); - private static Object serializingLock = new Object(); private static class LanguageSettingsWorkspaceProvider implements ILanguageSettingsProvider { private String providerId; @@ -186,7 +187,7 @@ public class LanguageSettingsProvidersSerializer { } public static void serializeLanguageSettingsWorkspace() throws CoreException { - URI uriLocation = getStoreInWorkspaceArea(STORAGE_WORKSPACE_LANGUAGE_SETTINGS); + URI uriStoreWsp = getStoreInWorkspaceArea(STORAGE_WORKSPACE_LANGUAGE_SETTINGS); List serializableExtensionProviders = new ArrayList(); for (ILanguageSettingsProvider provider : rawGlobalWorkspaceProviders.values()) { if (provider instanceof LanguageSettingsSerializable) { @@ -199,23 +200,28 @@ public class LanguageSettingsProvidersSerializer { } try { if (serializableExtensionProviders.isEmpty()) { - java.io.File file = new java.io.File(uriLocation); - synchronized (serializingLock) { - file.delete(); + java.io.File fileStoreWsp = new java.io.File(uriStoreWsp); + serializingLock.acquire(); + try { + fileStoreWsp.delete(); + } finally { + serializingLock.release(); + } + } else { + Document doc = XmlUtil.newDocument(); + Element rootElement = XmlUtil.appendElement(doc, ELEM_PLUGIN); + Element elementExtension = XmlUtil.appendElement(rootElement, ELEM_EXTENSION, new String[] {ATTR_POINT, LanguageSettingsExtensionManager.PROVIDER_EXTENSION_FULL_ID}); + + for (LanguageSettingsSerializable provider : serializableExtensionProviders) { + provider.serialize(elementExtension); + } + + serializingLock.acquire(); + try { + XmlUtil.serializeXml(doc, uriStoreWsp); + } finally { + serializingLock.release(); } - return; - } - - Document doc = XmlUtil.newDocument(); - Element rootElement = XmlUtil.appendElement(doc, ELEM_PLUGIN); - Element elementExtension = XmlUtil.appendElement(rootElement, ELEM_EXTENSION, new String[] {ATTR_POINT, LanguageSettingsExtensionManager.PROVIDER_EXTENSION_FULL_ID}); - - for (LanguageSettingsSerializable provider : serializableExtensionProviders) { - provider.serialize(elementExtension); - } - - synchronized (serializingLock) { - XmlUtil.serializeXml(doc, uriLocation); } } catch (Exception e) { @@ -228,15 +234,16 @@ public class LanguageSettingsProvidersSerializer { public static void loadLanguageSettingsWorkspace() throws CoreException { List providers = null; - URI uriLocation = getStoreInWorkspaceArea(STORAGE_WORKSPACE_LANGUAGE_SETTINGS); + URI uriStoreWsp = getStoreInWorkspaceArea(STORAGE_WORKSPACE_LANGUAGE_SETTINGS); Document doc = null; + serializingLock.acquire(); try { - synchronized (serializingLock) { - doc = XmlUtil.loadXml(uriLocation); - } + doc = XmlUtil.loadXml(uriStoreWsp); } catch (Exception e) { - CCorePlugin.log("Can't load preferences from file "+uriLocation, e); //$NON-NLS-1$ + CCorePlugin.log("Can't load preferences from file "+uriStoreWsp, e); //$NON-NLS-1$ + } finally { + serializingLock.release(); } if (doc!=null) { @@ -334,29 +341,31 @@ public class LanguageSettingsProvidersSerializer { IProject project = prjDescription.getProject(); try { // Document to store in project area - Document docPrjStore = XmlUtil.newDocument(); - Element projectElementPrjStore = XmlUtil.appendElement(docPrjStore, ELEM_PROJECT); + Document docStorePrj = XmlUtil.newDocument(); + Element projectElementStorePrj = XmlUtil.appendElement(docStorePrj, ELEM_PROJECT); // Document to store in workspace area - Document docWspStore = XmlUtil.newDocument(); - Element projectElementWspStore = XmlUtil.appendElement(docWspStore, ELEM_PROJECT); + Document docStoreWsp = XmlUtil.newDocument(); + Element projectElementStoreWsp = XmlUtil.appendElement(docStoreWsp, ELEM_PROJECT); - serializeLanguageSettingsInternal(projectElementPrjStore, projectElementWspStore, prjDescription); + serializeLanguageSettingsInternal(projectElementStorePrj, projectElementStoreWsp, prjDescription); - IFile filePrjStore = getStoreInProjectArea(project); - URI uriWspStore = null; - boolean isWorkspaceStoreEmpty = projectElementWspStore.getChildNodes().getLength() == 0; - uriWspStore = getStoreInWorkspaceArea(project.getName()+'.'+STORAGE_WORKSPACE_LANGUAGE_SETTINGS); - - synchronized (serializingLock){ - // The project store should not be absent. Absent store means legacy project, not 0 providers. - XmlUtil.serializeXml(docPrjStore, filePrjStore); + IFile fileStorePrj = getStoreInProjectArea(project); + // The project store should not be absent. Absent store means legacy project, not 0 providers. + XmlUtil.serializeXml(docStorePrj, fileStorePrj); + URI uriStoreWsp = null; + boolean isWorkspaceStoreEmpty = projectElementStoreWsp.getChildNodes().getLength() == 0; + uriStoreWsp = getStoreInWorkspaceArea(project.getName()+'.'+STORAGE_WORKSPACE_LANGUAGE_SETTINGS); + serializingLock.acquire(); + try { // project-specific location in workspace area if (!isWorkspaceStoreEmpty) { - XmlUtil.serializeXml(docWspStore, uriWspStore); + XmlUtil.serializeXml(docStoreWsp, uriStoreWsp); } else { - new java.io.File(uriWspStore).delete(); + new java.io.File(uriStoreWsp).delete(); } + } finally { + serializingLock.release(); } } catch (Exception e) { @@ -493,26 +502,27 @@ public class LanguageSettingsProvidersSerializer { public static void loadLanguageSettings(ICProjectDescription prjDescription) { IProject project = prjDescription.getProject(); - IFile file = project.getFile(SETTINGS_FOLDER_NAME+STORAGE_PROJECT_LANGUAGE_SETTINGS); + IFile storePrj = project.getFile(SETTINGS_FOLDER_NAME+STORAGE_PROJECT_LANGUAGE_SETTINGS); // AG: FIXME not sure about that one // Causes java.lang.IllegalArgumentException: Attempted to beginRule: P/cdt312, does not match outer scope rule: org.eclipse.cdt.internal.ui.text.c.hover.CSourceHover$SingletonRule@6f34fb try { - file.refreshLocal(IResource.DEPTH_ZERO, null); + storePrj.refreshLocal(IResource.DEPTH_ZERO, null); } catch (CoreException e) { // ignore failure } - if (file.exists() && file.isAccessible()) { + if (storePrj.exists() && storePrj.isAccessible()) { Document doc = null; try { - synchronized (serializingLock) { - doc = XmlUtil.loadXml(file); - } + doc = XmlUtil.loadXml(storePrj); Element rootElementPrj = doc.getDocumentElement(); // - URI uriLocation = getStoreInWorkspaceArea(project.getName()+'.'+STORAGE_WORKSPACE_LANGUAGE_SETTINGS); + URI uriStoreWsp = getStoreInWorkspaceArea(project.getName()+'.'+STORAGE_WORKSPACE_LANGUAGE_SETTINGS); Document docWsp = null; - synchronized (serializingLock) { - docWsp = XmlUtil.loadXml(uriLocation); + serializingLock.acquire(); + try { + docWsp = XmlUtil.loadXml(uriStoreWsp); + } finally { + serializingLock.release(); } Element rootElementWsp = null; // @@ -523,7 +533,7 @@ public class LanguageSettingsProvidersSerializer { loadLanguageSettingsInternal(rootElementPrj, rootElementWsp, prjDescription); } catch (Exception e) { - CCorePlugin.log("Can't load preferences from file "+file.getLocation(), e); //$NON-NLS-1$ + CCorePlugin.log("Can't load preferences from file "+storePrj.getLocation(), e); //$NON-NLS-1$ } if (doc!=null) { From d581c14367341f90a461bc794695426599186dff Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Thu, 22 Sep 2011 15:23:00 -0400 Subject: [PATCH 036/120] Support for IResourceChangeListener providers --- ...nguageSettingsPersistenceProjectTests.java | 101 +++++++++++-- .../LanguageSettingsExtensionManager.java | 142 ++++++++++++++++++ .../model/CConfigurationSpecSettings.java | 3 +- .../xml/XmlProjectDescriptionStorage.java | 8 +- 4 files changed, 238 insertions(+), 16 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java index 7dbdb464a2d..bf05ecf8948 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java @@ -24,6 +24,7 @@ import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager; +import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider; import org.eclipse.cdt.core.settings.model.WriteAccessException; import org.eclipse.cdt.core.testplugin.CModelMock; import org.eclipse.cdt.core.testplugin.ResourceHelper; @@ -103,13 +104,20 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase { } } - private class MockProvider extends LanguageSettingsSerializable { - public MockProvider(String id, String name) { + private class MockEditableProvider extends LanguageSettingsSerializable implements ILanguageSettingsEditableProvider { + public MockEditableProvider(String id, String name) { super(id, name); } + @Override + public MockEditableProvider cloneShallow() throws CloneNotSupportedException { + return (MockEditableProvider) super.cloneShallow(); + } + @Override + public MockEditableProvider clone() throws CloneNotSupportedException { + return (MockEditableProvider) super.clone(); + } } - /** * Constructor. * @param name - name of the test. @@ -178,21 +186,88 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase { /** */ - public void testReadOnlyDescription() throws Exception { + public void testProjectDescription_ReadWriteProviders() throws Exception { // create a project IProject project = ResourceHelper.createCDTProjectWithConfig(getName()); - // get read-only description - ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false); - assertNotNull(prjDescription); - ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); - assertNotNull(cfgDescription); + + { + // get read-only description + ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false); + assertNotNull(prjDescription); + ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); + assertNotNull(cfgDescription); + + // try to write to it + try { + List providers = new ArrayList(); + cfgDescription.setLanguageSettingProviders(providers); + fail("WriteAccessException was expected but it was not throw."); + } catch (WriteAccessException e) { + // exception is expected + } + } - try { + List entries = new ArrayList(); + entries.add(new CIncludePathEntry("path0", 0)); + + { + // get project descriptions + ICProjectDescription writableProjDescription = coreModel.getProjectDescription(project); + assertNotNull(writableProjDescription); + ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); + assertEquals(1, cfgDescriptions.length); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + // create a provider + LanguageSettingsSerializable mockProvider = new MockEditableProvider(PROVIDER_0, PROVIDER_NAME_0); + mockProvider.setStoringEntriesInProjectArea(true); + mockProvider.setSettingEntries(cfgDescription, null, null, entries); List providers = new ArrayList(); + providers.add(mockProvider); cfgDescription.setLanguageSettingProviders(providers); - fail("WriteAccessException was expected but it was not throw."); - } catch (WriteAccessException e) { - // exception is expected + List storedProviders = cfgDescription.getLanguageSettingProviders(); + assertEquals(1, storedProviders.size()); + + // apply new project description to the project model + coreModel.setProjectDescription(project, writableProjDescription); + } + { + // get read-only project descriptions + ICProjectDescription readOnlyProjDescription = coreModel.getProjectDescription(project, false); + assertNotNull(readOnlyProjDescription); + ICConfigurationDescription[] cfgDescriptions = readOnlyProjDescription.getConfigurations(); + assertEquals(1, cfgDescriptions.length); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + List providers = cfgDescription.getLanguageSettingProviders(); + assertEquals(1, providers.size()); + ILanguageSettingsProvider loadedProvider = providers.get(0); + assertTrue(loadedProvider instanceof LanguageSettingsSerializable); + assertEquals(PROVIDER_0, loadedProvider.getId()); + assertEquals(PROVIDER_NAME_0, loadedProvider.getName()); + + List actual = loadedProvider.getSettingEntries(cfgDescription, null, null); + assertEquals(entries.get(0), actual.get(0)); + assertEquals(entries.size(), actual.size()); + } + { + // get writable project descriptions + ICProjectDescription writableProjDescription = coreModel.getProjectDescription(project); + assertNotNull(writableProjDescription); + ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); + assertEquals(1, cfgDescriptions.length); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + List providers = cfgDescription.getLanguageSettingProviders(); + assertEquals(1, providers.size()); + ILanguageSettingsProvider loadedProvider = providers.get(0); + assertTrue(loadedProvider instanceof LanguageSettingsSerializable); + assertEquals(PROVIDER_0, loadedProvider.getId()); + assertEquals(PROVIDER_NAME_0, loadedProvider.getName()); + + List actual = loadedProvider.getSettingEntries(cfgDescription, null, null); + assertEquals(entries.get(0), actual.get(0)); + assertEquals(entries.size(), actual.size()); } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java index c5b204df57f..9bb935d61cd 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java @@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.core.language.settings.providers; import java.util.ArrayList; +import java.util.Collection; import java.util.Comparator; import java.util.HashMap; import java.util.LinkedHashMap; @@ -24,11 +25,13 @@ import org.eclipse.cdt.core.AbstractExecutableExtensionBase; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsBaseProvider; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable; import org.eclipse.cdt.core.model.ILanguage; import org.eclipse.cdt.core.model.LanguageManager; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; +import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider; import org.eclipse.cdt.core.settings.model.util.CDataUtil; @@ -37,7 +40,10 @@ import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IResourceChangeListener; +import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; @@ -613,5 +619,141 @@ public class LanguageSettingsExtensionManager { return provider.equals(extensionProvider); } + /** + * TODO - remove me + * Temporary method to report inconsistency in log. + */ + @Deprecated + public static void assertConsistency(ICProjectDescription prjDescription) { + if (prjDescription != null) { + List prjProviders = new ArrayList(); + for (ICConfigurationDescription cfgDescription : prjDescription.getConfigurations()) { + List providers = cfgDescription.getLanguageSettingProviders(); + for (ILanguageSettingsProvider provider : providers) { + if (!LanguageSettingsManager.isWorkspaceProvider(provider)) { + if (isObjectInTheList(prjProviders, provider)) { + IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "Inconsistent state, duplicate LSP in project description " + + "[" + System.identityHashCode(provider) + "] " + + provider); + CoreException e = new CoreException(status); + CCorePlugin.log(e); + } + prjProviders.add(provider); + } + } + } + } + } + + /** + * TODO - remove me + * Temporary method to report inconsistency in log. + */ + @Deprecated + public static void assertConsistency(ICConfigurationDescription cfgDescription) { + List listeners = new ArrayList(); + List providers = cfgDescription.getLanguageSettingProviders(); + for (ILanguageSettingsProvider provider : providers) { + if (isObjectInTheList(listeners, provider)) { + IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "Inconsistent state, duplicate LSP in project description " + provider); + CoreException e = new CoreException(status); + CCorePlugin.log(e); + } + listeners.add(provider); + } + } + + /** + * Get a providers list including only providers of type IResourceChangeListener + * for a given project description - collecting from all configurations. + */ + private static List getResourceChangeListeners(ICProjectDescription prjDescription) { + List listeners = new ArrayList(); + if (prjDescription != null) { + for (ICConfigurationDescription cfgDescription : prjDescription.getConfigurations()) { + List providers = cfgDescription.getLanguageSettingProviders(); + for (ILanguageSettingsProvider provider : providers) { + if (provider instanceof IResourceChangeListener) { + listeners.add((IResourceChangeListener) provider); + } + } + } + } + return listeners; + } + + /** + * Unregister listeners which are not used anymore and register new listeners. + * The method is used when project description is applied to workspace. + * @param oldPrjDescription - old project descriptions being replaced in the workspace. + * @param newPrjDescription - new project description being applied to the workspace. + */ + public static void reRegisterListeners(ICProjectDescription oldPrjDescription, ICProjectDescription newPrjDescription) { + if (oldPrjDescription == newPrjDescription) { + assertConsistency(oldPrjDescription); // TODO - remove me + return; + } + + assertConsistency(oldPrjDescription); // TODO - remove me + assertConsistency(newPrjDescription); // TODO - remove me + + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + + List oldListeners = getResourceChangeListeners(oldPrjDescription); + List newListeners = getResourceChangeListeners(newPrjDescription); + + for (IResourceChangeListener listener : oldListeners) { + if (!isObjectInTheList(newListeners, listener)) { + workspace.removeResourceChangeListener(listener); + // TODO - remove me + CCorePlugin.log(new Status(IStatus.WARNING,CCorePlugin.PLUGIN_ID, oldPrjDescription.getProject() + ": Removed IResourceChangeListener " + + "[" + System.identityHashCode(listener) + "] " + + listener)); + } + } + + for (IResourceChangeListener listener : newListeners) { + if (!isObjectInTheList(oldListeners, listener)) { + workspace.addResourceChangeListener(listener); + // TODO - remove me + CCorePlugin.log(new Status(IStatus.WARNING,CCorePlugin.PLUGIN_ID, newPrjDescription.getProject() + ": Added IResourceChangeListener " + + "[" + System.identityHashCode(listener) + "] " + + listener)); + } + } + + } + + private static boolean isObjectInTheList(Collection list, T element) { + // list.contains(element) won't do it as we are interested in exact object, not in equal object + for (T elem : list) { + if (elem == element) + return true; + } + return false; + } + + /** + * Deep clone of a list of language settings providers. + * + * @param baseProviders - list of providers to clone. + * @return newly cloned list. + */ + public static List cloneProviders(List baseProviders) { + List newProviders = new ArrayList(); + for (ILanguageSettingsProvider provider : baseProviders) { + if (provider instanceof ILanguageSettingsEditableProvider) { + try { + provider = ((ILanguageSettingsEditableProvider) provider).clone(); + } catch (CloneNotSupportedException e) { + IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "Not able to clone provider " + provider.getClass()); + CCorePlugin.log(new CoreException(status)); + } + } + newProviders.add(provider); + } + return new ArrayList(newProviders); + } + } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationSpecSettings.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationSpecSettings.java index 63dd2cac673..60418d3431a 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationSpecSettings.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationSpecSettings.java @@ -41,6 +41,7 @@ import org.eclipse.cdt.internal.core.COwner; import org.eclipse.cdt.internal.core.COwnerConfiguration; import org.eclipse.cdt.internal.core.cdtvariables.StorableCdtVariables; import org.eclipse.cdt.internal.core.envvar.EnvironmentVariableManager; +import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsExtensionManager; import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer; import org.eclipse.cdt.utils.envvar.StorableEnvironment; import org.eclipse.core.runtime.CoreException; @@ -188,7 +189,7 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ copyExtensionInfo(base); - fLanguageSettingsProviders = new ArrayList(base.getLanguageSettingProviders()); + fLanguageSettingsProviders = LanguageSettingsExtensionManager.cloneProviders(base.getLanguageSettingProviders()); } // private void copyRefInfos(Map infosMap){ diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/xml/XmlProjectDescriptionStorage.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/xml/XmlProjectDescriptionStorage.java index f48a2d6d2bf..61649f71125 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/xml/XmlProjectDescriptionStorage.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/xml/XmlProjectDescriptionStorage.java @@ -34,7 +34,6 @@ import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager_TBD; import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager; import org.eclipse.cdt.core.settings.model.ICSettingsStorage; @@ -43,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.LanguageSettingsExtensionManager; 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; @@ -365,6 +365,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(des); @@ -375,6 +376,8 @@ public class XmlProjectDescriptionStorage extends AbstractCProjectDescriptionSto } else { fProjectDescription = new SoftReference(null); } + + LanguageSettingsExtensionManager.reRegisterListeners(oldDes, fProjectDescription.get()); return true; } @@ -484,10 +487,11 @@ public class XmlProjectDescriptionStorage extends AbstractCProjectDescriptionSto // Update the modification stamp projectModificaitonStamp = getModificationStamp(project.getFile(ICProjectDescriptionStorageType.STORAGE_FILE_NAME)); CProjectDescription des = new CProjectDescription(project, new XmlStorage(storage), storage, true, false); - LanguageSettingsProvidersSerializer.loadLanguageSettings(des); try { setThreadLocalProjectDesc(des); des.loadDatas(); + + LanguageSettingsProvidersSerializer.loadLanguageSettings(des); des.doneLoading(); } finally { setThreadLocalProjectDesc(null); From 57afab135d591e8505645eda9bf2937394269db1 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Thu, 22 Sep 2011 21:37:18 -0400 Subject: [PATCH 037/120] Support for global (workspace level) IResourceChangeListener providers --- .../LanguageSettingsExtensionManager.java | 143 -------------- .../LanguageSettingsProvidersSerializer.java | 187 +++++++++++++++++- .../model/CConfigurationSpecSettings.java | 3 +- .../xml/XmlProjectDescriptionStorage.java | 3 +- 4 files changed, 186 insertions(+), 150 deletions(-) diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java index 9bb935d61cd..53d271faa61 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java @@ -12,7 +12,6 @@ package org.eclipse.cdt.internal.core.language.settings.providers; import java.util.ArrayList; -import java.util.Collection; import java.util.Comparator; import java.util.HashMap; import java.util.LinkedHashMap; @@ -25,13 +24,11 @@ import org.eclipse.cdt.core.AbstractExecutableExtensionBase; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsBaseProvider; -import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable; import org.eclipse.cdt.core.model.ILanguage; import org.eclipse.cdt.core.model.LanguageManager; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; -import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider; import org.eclipse.cdt.core.settings.model.util.CDataUtil; @@ -40,10 +37,7 @@ import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceChangeListener; -import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; @@ -618,142 +612,5 @@ public class LanguageSettingsExtensionManager { ILanguageSettingsProvider extensionProvider = fExtensionProviders.get(id); return provider.equals(extensionProvider); } - - /** - * TODO - remove me - * Temporary method to report inconsistency in log. - */ - @Deprecated - public static void assertConsistency(ICProjectDescription prjDescription) { - if (prjDescription != null) { - List prjProviders = new ArrayList(); - for (ICConfigurationDescription cfgDescription : prjDescription.getConfigurations()) { - List providers = cfgDescription.getLanguageSettingProviders(); - for (ILanguageSettingsProvider provider : providers) { - if (!LanguageSettingsManager.isWorkspaceProvider(provider)) { - if (isObjectInTheList(prjProviders, provider)) { - IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "Inconsistent state, duplicate LSP in project description " - + "[" + System.identityHashCode(provider) + "] " - + provider); - CoreException e = new CoreException(status); - CCorePlugin.log(e); - } - prjProviders.add(provider); - } - } - } - } - } - - /** - * TODO - remove me - * Temporary method to report inconsistency in log. - */ - @Deprecated - public static void assertConsistency(ICConfigurationDescription cfgDescription) { - List listeners = new ArrayList(); - List providers = cfgDescription.getLanguageSettingProviders(); - for (ILanguageSettingsProvider provider : providers) { - if (isObjectInTheList(listeners, provider)) { - IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "Inconsistent state, duplicate LSP in project description " + provider); - CoreException e = new CoreException(status); - CCorePlugin.log(e); - } - listeners.add(provider); - } - } - - /** - * Get a providers list including only providers of type IResourceChangeListener - * for a given project description - collecting from all configurations. - */ - private static List getResourceChangeListeners(ICProjectDescription prjDescription) { - List listeners = new ArrayList(); - if (prjDescription != null) { - for (ICConfigurationDescription cfgDescription : prjDescription.getConfigurations()) { - List providers = cfgDescription.getLanguageSettingProviders(); - for (ILanguageSettingsProvider provider : providers) { - if (provider instanceof IResourceChangeListener) { - listeners.add((IResourceChangeListener) provider); - } - } - } - } - return listeners; - } - - /** - * Unregister listeners which are not used anymore and register new listeners. - * The method is used when project description is applied to workspace. - * @param oldPrjDescription - old project descriptions being replaced in the workspace. - * @param newPrjDescription - new project description being applied to the workspace. - */ - public static void reRegisterListeners(ICProjectDescription oldPrjDescription, ICProjectDescription newPrjDescription) { - if (oldPrjDescription == newPrjDescription) { - assertConsistency(oldPrjDescription); // TODO - remove me - return; - } - - assertConsistency(oldPrjDescription); // TODO - remove me - assertConsistency(newPrjDescription); // TODO - remove me - - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - - List oldListeners = getResourceChangeListeners(oldPrjDescription); - List newListeners = getResourceChangeListeners(newPrjDescription); - - for (IResourceChangeListener listener : oldListeners) { - if (!isObjectInTheList(newListeners, listener)) { - workspace.removeResourceChangeListener(listener); - // TODO - remove me - CCorePlugin.log(new Status(IStatus.WARNING,CCorePlugin.PLUGIN_ID, oldPrjDescription.getProject() + ": Removed IResourceChangeListener " - + "[" + System.identityHashCode(listener) + "] " - + listener)); - } - } - - for (IResourceChangeListener listener : newListeners) { - if (!isObjectInTheList(oldListeners, listener)) { - workspace.addResourceChangeListener(listener); - // TODO - remove me - CCorePlugin.log(new Status(IStatus.WARNING,CCorePlugin.PLUGIN_ID, newPrjDescription.getProject() + ": Added IResourceChangeListener " - + "[" + System.identityHashCode(listener) + "] " - + listener)); - } - } - - } - - private static boolean isObjectInTheList(Collection list, T element) { - // list.contains(element) won't do it as we are interested in exact object, not in equal object - for (T elem : list) { - if (elem == element) - return true; - } - return false; - } - - /** - * Deep clone of a list of language settings providers. - * - * @param baseProviders - list of providers to clone. - * @return newly cloned list. - */ - public static List cloneProviders(List baseProviders) { - List newProviders = new ArrayList(); - for (ILanguageSettingsProvider provider : baseProviders) { - if (provider instanceof ILanguageSettingsEditableProvider) { - try { - provider = ((ILanguageSettingsEditableProvider) provider).clone(); - } catch (CloneNotSupportedException e) { - IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "Not able to clone provider " + provider.getClass()); - CCorePlugin.log(new CoreException(status)); - } - } - newProviders.add(provider); - } - return new ArrayList(newProviders); - } - } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java index 954461c3e75..e81dd9ca1ca 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java @@ -13,12 +13,14 @@ package org.eclipse.cdt.internal.core.language.settings.providers; import java.net.URI; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable; import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySupport; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; @@ -31,6 +33,10 @@ import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IResourceChangeEvent; +import org.eclipse.core.resources.IResourceChangeListener; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; @@ -58,9 +64,11 @@ public class LanguageSettingsProvidersSerializer { private static ILock serializingLock = Job.getJobManager().newLock(); /** Cache of globally available providers to be consumed by calling clients */ private static Map rawGlobalWorkspaceProviders = new HashMap(); + private static Map globalWorkspaceProviders = new HashMap(); - private static class LanguageSettingsWorkspaceProvider implements ILanguageSettingsProvider { + private static class LanguageSettingsWorkspaceProvider implements ILanguageSettingsProvider, IResourceChangeListener { private String providerId; + private int registrationCount = 0; public LanguageSettingsWorkspaceProvider(String id) { Assert.isNotNull(id); @@ -107,6 +115,25 @@ public class LanguageSettingsProvidersSerializer { public String toString() { return "id="+getId()+", name="+getName(); } + + /** + * {@inheritDoc} + * + * LanguageSettingsWorkspaceProvider delegates event handling to raw provider. + * + */ + public void resourceChanged(IResourceChangeEvent event) { + // keep in mind that type of rawProvider can change + ILanguageSettingsProvider rawProvider = getRawProvider(); + if (rawProvider instanceof IResourceChangeListener) { + ((IResourceChangeListener) rawProvider).resourceChanged(event); + } + } + + synchronized int incrementListenerCount(int inc) { + registrationCount += inc; + return registrationCount; + } } @@ -565,7 +592,12 @@ public class LanguageSettingsProvidersSerializer { * @return the provider or {@code null} if provider is not defined. */ public static ILanguageSettingsProvider getWorkspaceProvider(String id) { - return new LanguageSettingsWorkspaceProvider(id); + ILanguageSettingsProvider provider = globalWorkspaceProviders.get(id); + if (provider == null) { + provider = new LanguageSettingsWorkspaceProvider(id); + globalWorkspaceProviders.put(id, provider); + } + return provider; } public static ILanguageSettingsProvider getRawWorkspaceProvider(String id) { @@ -580,7 +612,7 @@ public class LanguageSettingsProvidersSerializer { public static List getWorkspaceProviders() { ArrayList workspaceProviders = new ArrayList(); for (ILanguageSettingsProvider rawProvider : rawGlobalWorkspaceProviders.values()) { - workspaceProviders.add(new LanguageSettingsWorkspaceProvider(rawProvider.getId())); + workspaceProviders.add(getWorkspaceProvider(rawProvider.getId())); } return workspaceProviders; } @@ -595,4 +627,153 @@ public class LanguageSettingsProvidersSerializer { public static boolean isWorkspaceProvider(ILanguageSettingsProvider provider) { return provider instanceof LanguageSettingsWorkspaceProvider; } + + /** + * TODO - remove me + * Temporary method to report inconsistency in log. + */ + @Deprecated + public static void assertConsistency(ICProjectDescription prjDescription) { + if (prjDescription != null) { + List prjProviders = new ArrayList(); + for (ICConfigurationDescription cfgDescription : prjDescription.getConfigurations()) { + List providers = cfgDescription.getLanguageSettingProviders(); + for (ILanguageSettingsProvider provider : providers) { + if (!LanguageSettingsManager.isWorkspaceProvider(provider)) { + if (isObjectInTheList(prjProviders, provider)) { + IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "Inconsistent state, duplicate LSP in project description " + + "[" + System.identityHashCode(provider) + "] " + + provider); + CoreException e = new CoreException(status); + CCorePlugin.log(e); + } + prjProviders.add(provider); + } + } + } + } + } + + /** + * TODO - remove me + * Temporary method to report inconsistency in log. + */ + @Deprecated + public static void assertConsistency(ICConfigurationDescription cfgDescription) { + List listeners = new ArrayList(); + List providers = cfgDescription.getLanguageSettingProviders(); + for (ILanguageSettingsProvider provider : providers) { + if (isObjectInTheList(listeners, provider)) { + IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "Inconsistent state, duplicate LSP in project description " + provider); + CoreException e = new CoreException(status); + CCorePlugin.log(e); + } + listeners.add(provider); + } + } + + /** + * Get a providers list including only providers of type IResourceChangeListener + * for a given project description - collecting from all configurations. + */ + private static List getResourceChangeListeners(ICProjectDescription prjDescription) { + List listeners = new ArrayList(); + if (prjDescription != null) { + for (ICConfigurationDescription cfgDescription : prjDescription.getConfigurations()) { + List providers = cfgDescription.getLanguageSettingProviders(); + for (ILanguageSettingsProvider provider : providers) { + if (provider instanceof IResourceChangeListener) { + listeners.add((IResourceChangeListener) provider); + } + } + } + } + return listeners; + } + + /** + * Unregister listeners which are not used anymore and register new listeners. + * The method is used when project description is applied to workspace. + * @param oldPrjDescription - old project descriptions being replaced in the workspace. + * @param newPrjDescription - new project description being applied to the workspace. + */ + public static void reRegisterListeners(ICProjectDescription oldPrjDescription, ICProjectDescription newPrjDescription) { + if (oldPrjDescription == newPrjDescription) { + assertConsistency(oldPrjDescription); // TODO - remove me + return; + } + + assertConsistency(oldPrjDescription); // TODO - remove me + assertConsistency(newPrjDescription); // TODO - remove me + + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + + List oldListeners = getResourceChangeListeners(oldPrjDescription); + List newListeners = getResourceChangeListeners(newPrjDescription); + + for (IResourceChangeListener listener : oldListeners) { + if (!isObjectInTheList(newListeners, listener)) { + int count = 0; + if (listener instanceof LanguageSettingsWorkspaceProvider) { + count = ((LanguageSettingsWorkspaceProvider) listener).incrementListenerCount(-1); + } + if (count == 0) { + workspace.removeResourceChangeListener(listener); + // TODO - remove me + CCorePlugin.log(new Status(IStatus.WARNING,CCorePlugin.PLUGIN_ID, oldPrjDescription.getProject() + ": Removed IResourceChangeListener " + + "[" + System.identityHashCode(listener) + "] " + + listener)); + } + } + } + + for (IResourceChangeListener listener : newListeners) { + if (!isObjectInTheList(oldListeners, listener)) { + int count = 1; + if (listener instanceof LanguageSettingsWorkspaceProvider) { + count = ((LanguageSettingsWorkspaceProvider) listener).incrementListenerCount(1); + } + if (count == 1) { + workspace.addResourceChangeListener(listener); + // TODO - remove me + CCorePlugin.log(new Status(IStatus.WARNING,CCorePlugin.PLUGIN_ID, newPrjDescription.getProject() + ": Added IResourceChangeListener " + + "[" + System.identityHashCode(listener) + "] " + + listener)); + } + } + } + + } + + private static boolean isObjectInTheList(Collection list, T element) { + // list.contains(element) won't do it as we are interested in exact object, not in equal object + for (T elem : list) { + if (elem == element) + return true; + } + return false; + } + + /** + * Deep clone of a list of language settings providers. + * + * @param baseProviders - list of providers to clone. + * @return newly cloned list. + */ + public static List cloneProviders(List baseProviders) { + List newProviders = new ArrayList(); + for (ILanguageSettingsProvider provider : baseProviders) { + if (provider instanceof ILanguageSettingsEditableProvider) { + try { + provider = ((ILanguageSettingsEditableProvider) provider).clone(); + } catch (CloneNotSupportedException e) { + IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "Not able to clone provider " + provider.getClass()); + CCorePlugin.log(new CoreException(status)); + } + } + newProviders.add(provider); + } + return new ArrayList(newProviders); + } + } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationSpecSettings.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationSpecSettings.java index 60418d3431a..d63af54e1a2 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationSpecSettings.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationSpecSettings.java @@ -41,7 +41,6 @@ import org.eclipse.cdt.internal.core.COwner; import org.eclipse.cdt.internal.core.COwnerConfiguration; import org.eclipse.cdt.internal.core.cdtvariables.StorableCdtVariables; import org.eclipse.cdt.internal.core.envvar.EnvironmentVariableManager; -import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsExtensionManager; import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer; import org.eclipse.cdt.utils.envvar.StorableEnvironment; import org.eclipse.core.runtime.CoreException; @@ -189,7 +188,7 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ copyExtensionInfo(base); - fLanguageSettingsProviders = LanguageSettingsExtensionManager.cloneProviders(base.getLanguageSettingProviders()); + fLanguageSettingsProviders = LanguageSettingsProvidersSerializer.cloneProviders(base.getLanguageSettingProviders()); } // private void copyRefInfos(Map infosMap){ diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/xml/XmlProjectDescriptionStorage.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/xml/XmlProjectDescriptionStorage.java index 61649f71125..32a44e2c568 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/xml/XmlProjectDescriptionStorage.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/xml/XmlProjectDescriptionStorage.java @@ -42,7 +42,6 @@ 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.LanguageSettingsExtensionManager; 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; @@ -377,7 +376,7 @@ public class XmlProjectDescriptionStorage extends AbstractCProjectDescriptionSto fProjectDescription = new SoftReference(null); } - LanguageSettingsExtensionManager.reRegisterListeners(oldDes, fProjectDescription.get()); + LanguageSettingsProvidersSerializer.reRegisterListeners(oldDes, fProjectDescription.get()); return true; } From c410b4b521b3d934aa20701b126b3d58247e8616 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Fri, 23 Sep 2011 17:37:48 -0400 Subject: [PATCH 038/120] fixed backdoor access to list of providers inside configuration --- ...nguageSettingsPersistenceProjectTests.java | 42 +++++++++++++++---- .../model/CConfigurationSpecSettings.java | 2 +- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java index bf05ecf8948..dbb5f954000 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java @@ -184,6 +184,32 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase { // test passes if no exception was thrown } + /** + */ + public void testProjectDescription_PreventBackDoorAccess() throws Exception { + // create a project + IProject project = ResourceHelper.createCDTProjectWithConfig(getName()); + + // get project descriptions + ICProjectDescription writableProjDescription = coreModel.getProjectDescription(project); + assertNotNull(writableProjDescription); + ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); + assertEquals(1, cfgDescriptions.length); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + List originalProviders = cfgDescription.getLanguageSettingProviders(); + int originalSize = originalProviders.size(); + + // create new provider list + LanguageSettingsSerializable mockProvider = new MockEditableProvider(PROVIDER_0, PROVIDER_NAME_0); + List providers = new ArrayList(originalProviders); + providers.add(mockProvider); + assertTrue(originalSize != providers.size()); + + // changing providers shouldn't affect the original list + cfgDescription.setLanguageSettingProviders(providers); + assertEquals(originalSize, originalProviders.size()); + } + /** */ public void testProjectDescription_ReadWriteProviders() throws Exception { @@ -196,7 +222,7 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase { assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); assertNotNull(cfgDescription); - + // try to write to it try { List providers = new ArrayList(); @@ -206,10 +232,10 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase { // exception is expected } } - + List entries = new ArrayList(); entries.add(new CIncludePathEntry("path0", 0)); - + { // get project descriptions ICProjectDescription writableProjDescription = coreModel.getProjectDescription(project); @@ -217,7 +243,7 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase { ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; - + // create a provider LanguageSettingsSerializable mockProvider = new MockEditableProvider(PROVIDER_0, PROVIDER_NAME_0); mockProvider.setStoringEntriesInProjectArea(true); @@ -227,7 +253,7 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase { cfgDescription.setLanguageSettingProviders(providers); List storedProviders = cfgDescription.getLanguageSettingProviders(); assertEquals(1, storedProviders.size()); - + // apply new project description to the project model coreModel.setProjectDescription(project, writableProjDescription); } @@ -238,14 +264,14 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase { ICConfigurationDescription[] cfgDescriptions = readOnlyProjDescription.getConfigurations(); assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; - + List providers = cfgDescription.getLanguageSettingProviders(); assertEquals(1, providers.size()); ILanguageSettingsProvider loadedProvider = providers.get(0); assertTrue(loadedProvider instanceof LanguageSettingsSerializable); assertEquals(PROVIDER_0, loadedProvider.getId()); assertEquals(PROVIDER_NAME_0, loadedProvider.getName()); - + List actual = loadedProvider.getSettingEntries(cfgDescription, null, null); assertEquals(entries.get(0), actual.get(0)); assertEquals(entries.size(), actual.size()); @@ -270,7 +296,7 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase { assertEquals(entries.size(), actual.size()); } } - + /** */ public void testWorkspacePersistence_ModifiedExtensionProvider() throws Exception { diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationSpecSettings.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationSpecSettings.java index d63af54e1a2..9d7ab1be7a6 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationSpecSettings.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationSpecSettings.java @@ -989,7 +989,7 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ * @param providers - list of providers to keep in the specs. */ public void setLanguageSettingProviders(List providers) { - fLanguageSettingsProviders.clear(); + fLanguageSettingsProviders = new ArrayList(0); Set ids = new HashSet(); for (ILanguageSettingsProvider provider : providers) { String id = provider.getId(); From 6a09056f15c32a896e2b3db4c1fdcba4f6e392af Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Fri, 23 Sep 2011 17:53:39 -0400 Subject: [PATCH 039/120] Add a new event kind to CProjectDescriptionEvent for adding Language Settings Providers to a configuration --- .../model/CProjectDescriptionDeltaTests.java | 49 +++++++++++++++++++ .../settings/model/ICDescriptionDelta.java | 6 ++- .../model/CProjectDescriptionDelta.java | 1 + .../model/CProjectDescriptionManager.java | 5 ++ 4 files changed, 60 insertions(+), 1 deletion(-) diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/settings/model/CProjectDescriptionDeltaTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/settings/model/CProjectDescriptionDeltaTests.java index ff562be920b..4d80b3adff7 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/settings/model/CProjectDescriptionDeltaTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/settings/model/CProjectDescriptionDeltaTests.java @@ -19,6 +19,8 @@ import java.util.Map; import junit.framework.TestSuite; import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.settings.model.util.CDataUtil; import org.eclipse.cdt.core.testplugin.ResourceHelper; @@ -994,5 +996,52 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ ICProjectDescription newSetting = (ICProjectDescription)delta.getNewSetting(); assertEquals(cfgDescription1.getName(), newSetting.getDefaultSettingConfiguration().getName()); } + + public void testDelta_LANGUAGE_SETTINGS_PROVIDERS() throws Exception { + String projName = getName(); + ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager(); + + initListener(projName); + IProject project = ResourceHelper.createCDTProjectWithConfig(projName); + + // Get writable project description and its configuration + ICProjectDescription prjDescription = mngr.getProjectDescription(project, true); + assertNotNull(prjDescription); + ICConfigurationDescription cfgDescription = prjDescription.getConfigurations()[0]; + assertNotNull(cfgDescription); + List originalProviders = cfgDescription.getLanguageSettingProviders(); + + // Modification LANGUAGE_SETTINGS_PROVIDERS + ILanguageSettingsProvider provider = new LanguageSettingsSerializable("id", "name"); + List providers = new ArrayList(); + providers.add(provider); + cfgDescription.setLanguageSettingProviders(providers); + + // Write project description + listener.clearNotified(); + mngr.setProjectDescription(project, prjDescription); + assertEquals(true, listener.isNotified()); + + // Analyze delta + ICDescriptionDelta rootDelta = listener.getDelta(); + assertNotNull(rootDelta); + List deltas = findDeltas(rootDelta, ICDescriptionDelta.LANGUAGE_SETTINGS_PROVIDERS); + assertEquals(1, deltas.size()); + ICDescriptionDelta delta = deltas.get(0); + assertNotNull(delta); + assertEquals(ICDescriptionDelta.LANGUAGE_SETTINGS_PROVIDERS, delta.getChangeFlags()); + + // Check old setting + assertTrue(delta.getOldSetting() instanceof ICConfigurationDescription); + ICConfigurationDescription oldSetting = (ICConfigurationDescription)delta.getOldSetting(); + List oldProviders = oldSetting.getLanguageSettingProviders(); + assertEquals(originalProviders, oldProviders); + + // Check new setting + assertTrue(delta.getNewSetting() instanceof ICConfigurationDescription); + ICConfigurationDescription newSetting = (ICConfigurationDescription)delta.getNewSetting(); + List newProviders = newSetting.getLanguageSettingProviders(); + assertEquals(providers, newProviders); + } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICDescriptionDelta.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICDescriptionDelta.java index 8467c6966c9..11172d5d99d 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICDescriptionDelta.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICDescriptionDelta.java @@ -49,7 +49,10 @@ public interface ICDescriptionDelta { // int PATH = 1 << 3; int LANGUAGE_ID = 1 << 4; int SOURCE_CONTENT_TYPE = 1 << 5; - int SOURCE_ENTENSIONS = 1 << 6; + int SOURCE_EXTENSIONS = 1 << 6; + /** @deprecated Use ICDescriptionDelta.SOURCE_EXTENSIONS */ + @Deprecated + int SOURCE_ENTENSIONS = SOURCE_EXTENSIONS; // int HEADER_CONTENT_TYPE = 1 << 7; // int HEADER_ENTENSIONS = 1 << 8; int SETTING_ENTRIES = 1 << 9; @@ -66,6 +69,7 @@ public interface ICDescriptionDelta { int OWNER = 1 << 20; int INDEX_CFG = 1 << 21; int SETTING_CFG = INDEX_CFG; + int LANGUAGE_SETTINGS_PROVIDERS = 1 << 22; /** * specifies that the project "isCdtProjectCreating" state was set to false diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CProjectDescriptionDelta.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CProjectDescriptionDelta.java index d1b58c260d1..2905135a244 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CProjectDescriptionDelta.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CProjectDescriptionDelta.java @@ -171,6 +171,7 @@ public class CProjectDescriptionDelta implements ICDescriptionDelta { if ((flags&EXT_REF)!=0) str.append("EXT_REF|"); if ((flags&OWNER)!=0) str.append("OWNER|"); if ((flags&INDEX_CFG)!=0) str.append("INDEX_CFG|"); + if ((flags&LANGUAGE_SETTINGS_PROVIDERS)!=0) str.append("LANGUAGE_SETTINGS_PROVIDERS|"); if (str.charAt(str.length()-1)=='|') str.deleteCharAt(str.length()-1); return str.toString(); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CProjectDescriptionManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CProjectDescriptionManager.java index c23c8f9e6b9..b1ec933e40f 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CProjectDescriptionManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CProjectDescriptionManager.java @@ -50,6 +50,7 @@ import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElementDelta; @@ -1556,6 +1557,10 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager { CCorePlugin.log(e); } + List newLSProviders = newCfg.getLanguageSettingProviders(); + List oldLSProviders = oldCfg.getLanguageSettingProviders(); + if(!newLSProviders.equals(oldLSProviders)) + delta.addChangeFlags(ICDescriptionDelta.LANGUAGE_SETTINGS_PROVIDERS); calculateCfgExtSettingsDelta(delta); From 427ba73a1659452830bf4550aa56f73860132673 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Thu, 29 Sep 2011 09:38:13 -0400 Subject: [PATCH 040/120] fixed problem when Spec Detectors owned by configuration won't serialize properly --- .../internal/scannerconfig/AbstractBuiltinSpecsDetector.java | 4 ++-- .../settings/providers/LanguageSettingsSerializable.java | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/AbstractBuiltinSpecsDetector.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/AbstractBuiltinSpecsDetector.java index 586a7200c25..3fc8ba3d846 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/AbstractBuiltinSpecsDetector.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/AbstractBuiltinSpecsDetector.java @@ -457,8 +457,8 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti } @Override - public Element serialize(Element parentElement) { - Element elementProvider = super.serialize(parentElement); + public Element serializeAttributes(Element parentElement) { + Element elementProvider = super.serializeAttributes(parentElement); elementProvider.setAttribute(ATTR_RUN_ONCE, Boolean.toString(runOnce)); elementProvider.setAttribute(ATTR_CONSOLE, Boolean.toString(isConsoleEnabled)); return elementProvider; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java index 61016b4006b..c4ea03d986b 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java @@ -277,12 +277,13 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { /** * Serialize the provider under parent XML element. - * + * This is convenience method not intended to be overridden on purpose. + * * @param parentElement - element where to serialize. * @return - newly created element. That element will already be * attached to the parent element. */ - public Element serialize(Element parentElement) { + final public Element serialize(Element parentElement) { /* From 7be2df0ddebb4d67380bb8f1364955abd378ae36 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Thu, 29 Sep 2011 09:58:58 -0400 Subject: [PATCH 041/120] Remember selected language for reopening properties --- .../language/settings/providers/LanguageSettingsEntriesTab.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java index 7be2531e347..d89e8d1165b 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java @@ -80,7 +80,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { private Tree treeLanguages; private Tree treeEntries; private TreeViewer treeEntriesViewer; - private String currentLanguageId = null; + private static String currentLanguageId = null; private Button builtInCheckBox; private Button enableProvidersCheckBox; From e314ac4b68549541925d3520da2727aae128249e Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Thu, 29 Sep 2011 10:16:57 -0400 Subject: [PATCH 042/120] Added simplified global console (MessageConsole) for AbstractBuiltinSpecsDetector --- .../META-INF/MANIFEST.MF | 3 +- build/org.eclipse.cdt.make.ui/plugin.xml | 7 ++ .../ScannerDiscoveryGlobalConsole.java | 102 +++++++++++++++ .../plugin.xml | 27 ++-- .../core/ExternalBuildRunner.java | 2 +- .../core/ManagedBuildManager.java | 2 +- .../AbstractBuiltinSpecsDetector.java | 116 ++++++++++++++++-- .../internal/core/ConsoleOutputSniffer.java | 15 +-- 8 files changed, 241 insertions(+), 33 deletions(-) create mode 100644 build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/scannerconfig/ScannerDiscoveryGlobalConsole.java diff --git a/build/org.eclipse.cdt.make.ui/META-INF/MANIFEST.MF b/build/org.eclipse.cdt.make.ui/META-INF/MANIFEST.MF index 12ec26eac40..22feef84ebc 100644 --- a/build/org.eclipse.cdt.make.ui/META-INF/MANIFEST.MF +++ b/build/org.eclipse.cdt.make.ui/META-INF/MANIFEST.MF @@ -35,7 +35,8 @@ Require-Bundle: org.eclipse.ui.ide;bundle-version="[3.2.0,4.0.0)", org.eclipse.debug.ui;bundle-version="[3.2.0,4.0.0)", org.eclipse.ui.navigator;bundle-version="[3.2.0,4.0.0)";resolution:=optional, org.eclipse.compare;bundle-version="[3.3.0,4.0.0)", - org.eclipse.core.filesystem;bundle-version="1.2.0" + org.eclipse.core.filesystem;bundle-version="1.2.0", + org.eclipse.ui.console;bundle-version="3.5.100" Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: J2SE-1.5 Import-Package: com.ibm.icu.text diff --git a/build/org.eclipse.cdt.make.ui/plugin.xml b/build/org.eclipse.cdt.make.ui/plugin.xml index c9c87cb44f6..f4a3166eb0c 100644 --- a/build/org.eclipse.cdt.make.ui/plugin.xml +++ b/build/org.eclipse.cdt.make.ui/plugin.xml @@ -563,4 +563,11 @@ class="org.eclipse.cdt.make.internal.ui.scannerconfig.ScannerDiscoveryConsole"> + + + + diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/scannerconfig/ScannerDiscoveryGlobalConsole.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/scannerconfig/ScannerDiscoveryGlobalConsole.java new file mode 100644 index 00000000000..9a12186664c --- /dev/null +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/scannerconfig/ScannerDiscoveryGlobalConsole.java @@ -0,0 +1,102 @@ +/******************************************************************************* + * Copyright (c) 2011, 2011 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.make.internal.ui.scannerconfig; + +import java.io.IOException; +import java.net.URL; + +import org.eclipse.cdt.core.ConsoleOutputStream; +import org.eclipse.cdt.internal.core.ICConsole; +import org.eclipse.cdt.internal.ui.language.settings.providers.LanguageSettingsProviderAssociation; +import org.eclipse.cdt.ui.CDTSharedImages; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.ui.console.ConsolePlugin; +import org.eclipse.ui.console.IConsole; +import org.eclipse.ui.console.IConsoleManager; +import org.eclipse.ui.console.MessageConsole; +import org.eclipse.ui.console.MessageConsoleStream; + +public class ScannerDiscoveryGlobalConsole implements ICConsole { + private MessageConsole console; + private ConsoleOutputStreamAdapter stream; + + private class ConsoleOutputStreamAdapter extends ConsoleOutputStream { + private MessageConsoleStream fConsoleStream; + public ConsoleOutputStreamAdapter(MessageConsoleStream stream) { + fConsoleStream = stream; + } + @Override + public void write(int arg0) throws IOException { + fConsoleStream.write(arg0); + } + @Override + public synchronized void write(byte[] b, int off, int len) throws IOException { + fConsoleStream.write(b, off, len); + } + + @Override + public void flush() throws IOException { + fConsoleStream.flush(); + } + + @Override + public void close() throws IOException { + fConsoleStream.close(); + } + } + + public void start(IProject project) { + Assert.isTrue(project == null); + } + + public ConsoleOutputStream getOutputStream() throws CoreException { + return stream; + } + + public ConsoleOutputStream getInfoStream() throws CoreException { + return stream; + } + + public ConsoleOutputStream getErrorStream() throws CoreException { + return stream; + } + + public void init(String consoleId, String name, URL defaultIconUrl) { + console = null; + + IConsoleManager consoleManager = ConsolePlugin.getDefault().getConsoleManager(); + IConsole[] allConsoles = consoleManager.getConsoles(); + for (IConsole con : allConsoles) { + if (name.equals(con.getName()) && con instanceof MessageConsole) { + console = (MessageConsole) con; + console.clearConsole(); + break; + } + } + + if (console==null) { + URL iconUrl = LanguageSettingsProviderAssociation.getImageUrl(consoleId); + if (iconUrl==null) { + iconUrl = defaultIconUrl; + } + + console = new MessageConsole(name, CDTSharedImages.getImageDescriptor(iconUrl.toString())); + console.activate(); + consoleManager.addConsoles(new IConsole[]{ console }); + } + + stream = new ConsoleOutputStreamAdapter(console.newMessageStream()); + } + +} diff --git a/build/org.eclipse.cdt.managedbuilder.core/plugin.xml b/build/org.eclipse.cdt.managedbuilder.core/plugin.xml index f1579d629c5..be712a6d999 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/plugin.xml +++ b/build/org.eclipse.cdt.managedbuilder.core/plugin.xml @@ -617,14 +617,6 @@ - - - - + + + + + + + + + + diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ExternalBuildRunner.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ExternalBuildRunner.java index f518772b791..3ceff84cc8b 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ExternalBuildRunner.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ExternalBuildRunner.java @@ -423,7 +423,7 @@ public class ExternalBuildRunner extends AbstractBuildRunner { if(clParserList.size() != 0){ IConsoleParser[] parsers = clParserList.toArray(new IConsoleParser[clParserList.size()]); - return new ConsoleOutputSniffer(outputStream, errorStream, parsers, epm); + return new ConsoleOutputSniffer(outputStream, errorStream, parsers); } return null; diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java index 337801b1342..95fdcd6bfd2 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java @@ -4825,7 +4825,7 @@ public class ManagedBuildManager extends AbstractCExtension { if (detector.getLanguageScope()==null || detector.getLanguageScope().contains(languageId)) { try { if (isWorkspaceProvider) { - detector.run(project, languageId, workingDirectory, env, monitor); + detector.run((IProject)null, languageId, workingDirectory, env, monitor); } else { detector.run(cfgDescription, languageId, workingDirectory, env, monitor); } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/AbstractBuiltinSpecsDetector.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/AbstractBuiltinSpecsDetector.java index 3fc8ba3d846..8af3c53f939 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/AbstractBuiltinSpecsDetector.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/AbstractBuiltinSpecsDetector.java @@ -23,6 +23,8 @@ import org.eclipse.cdt.core.CommandLauncher; import org.eclipse.cdt.core.ErrorParserManager; import org.eclipse.cdt.core.ICommandLauncher; import org.eclipse.cdt.core.IConsoleParser; +import org.eclipse.cdt.core.IMarkerGenerator; +import org.eclipse.cdt.core.ProblemMarkerInfo; import org.eclipse.cdt.core.model.ILanguage; import org.eclipse.cdt.core.model.LanguageManager; import org.eclipse.cdt.core.resources.IConsole; @@ -35,7 +37,6 @@ import org.eclipse.cdt.make.core.scannerconfig.AbstractLanguageSettingsOutputSca import org.eclipse.cdt.make.core.scannerconfig.ILanguageSettingsBuiltinSpecsDetector; import org.eclipse.cdt.make.internal.core.MakeMessages; import org.eclipse.cdt.make.internal.core.StreamMonitor; -import org.eclipse.cdt.make.internal.core.scannerconfig2.SCMarkerGenerator; import org.eclipse.cdt.managedbuilder.core.IInputType; import org.eclipse.cdt.managedbuilder.core.ITool; import org.eclipse.cdt.managedbuilder.core.IToolChain; @@ -43,8 +44,11 @@ import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin; import org.eclipse.cdt.utils.CommandLineUtil; import org.eclipse.cdt.utils.PathUtil; +import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; @@ -55,6 +59,7 @@ import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.core.runtime.jobs.Job; import org.w3c.dom.Element; public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSettingsOutputScanner implements ILanguageSettingsBuiltinSpecsDetector { @@ -72,6 +77,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti private String currentCommandResolved = null; protected List detectedSettingEntries = null; + protected int collected = 0; private boolean runOnce = true; private boolean isConsoleEnabled = false; @@ -81,6 +87,67 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti protected URI mappedRootURI = null; protected URI buildDirURI = null; + private class SDMarkerGenerator implements IMarkerGenerator { + protected static final String SCANNER_DISCOVERY_PROBLEM_MARKER = ManagedBuilderCorePlugin.PLUGIN_ID + ".scanner.discovery.problem"; //$NON-NLS-1$ + protected static final String PROVIDER = "provider"; //$NON-NLS-1$ + + public void addMarker(IResource file, int lineNumber, String errorDesc, int severity, String errorVar) { + ProblemMarkerInfo info = new ProblemMarkerInfo(file, lineNumber, errorDesc, severity, errorVar); + addMarker(info); + } + + public void addMarker(final ProblemMarkerInfo problemMarkerInfo) { + final String providerName = getName(); + final String providerId = getId(); + // we have to add the marker in the job or we can deadlock other + // threads that are responding to a resource delta by doing something + // that accesses the project description + Job markerJob = new Job("Adding Scanner Discovery markers") { + @Override + protected IStatus run(IProgressMonitor monitor) { + // Try to find matching markers and don't put in duplicates + try { + IMarker[] cur = problemMarkerInfo.file.findMarkers(SDMarkerGenerator.SCANNER_DISCOVERY_PROBLEM_MARKER, false, IResource.DEPTH_ZERO); + if ((cur != null) && (cur.length > 0)) { + for (int i = 0; i < cur.length; i++) { + int sev = ((Integer) cur[i].getAttribute(IMarker.SEVERITY)).intValue(); + String mesg = (String) cur[i].getAttribute(IMarker.MESSAGE); + if (sev == problemMarkerInfo.severity && mesg.equals(problemMarkerInfo.description)) { + return Status.OK_STATUS; + } + } + } + } catch (CoreException e) { + return new Status(Status.ERROR, MakeCorePlugin.getUniqueIdentifier(), "Error removing markers.", e); + } + + // add new marker + try { + IMarker marker = problemMarkerInfo.file.createMarker(SDMarkerGenerator.SCANNER_DISCOVERY_PROBLEM_MARKER); + marker.setAttribute(IMarker.MESSAGE, problemMarkerInfo.description); + marker.setAttribute(IMarker.SEVERITY, problemMarkerInfo.severity); + marker.setAttribute(SDMarkerGenerator.PROVIDER, providerId); + + if (problemMarkerInfo.file instanceof IWorkspaceRoot) { + marker.setAttribute(IMarker.LOCATION, "SD90 Providers, [" + providerName + "] options in Preferences"); + } else { + marker.setAttribute(IMarker.LOCATION, "SD90 Providers, [" + providerName + "] options in project properties"); + } + } catch (CoreException e) { + return new Status(Status.ERROR, MakeCorePlugin.getUniqueIdentifier(), "Error adding markers.", e); + } + + return Status.OK_STATUS; + } + }; + + markerJob.setRule(problemMarkerInfo.file); + markerJob.schedule(); + } + + } + + /** * TODO */ @@ -178,6 +245,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti } detectedSettingEntries = new ArrayList(); + collected = 0; currentCommandResolved = customParameter; specFile = null; @@ -195,6 +263,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti if (detectedSettingEntries!=null && detectedSettingEntries.size()>0) { setSettingEntries(currentCfgDescription, currentResource, currentLanguageId, detectedSettingEntries); + collected = detectedSettingEntries.size(); IStatus status = new Status(IStatus.INFO, MakeCorePlugin.PLUGIN_ID, getClass().getSimpleName() + " collected " + detectedSettingEntries.size() + " entries" + " for language " + currentLanguageId); @@ -248,17 +317,30 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti if (isConsoleEnabled) { console = startProviderConsole(); } else { - // that looks in extension points registry and won't find the id + // that looks in extension points registry and won't find the id, this console is not shown console = CCorePlugin.getDefault().getConsole(MakeCorePlugin.PLUGIN_ID + ".console.hidden"); //$NON-NLS-1$ } console.start(currentProject); OutputStream cos = console.getOutputStream(); - ErrorParserManager epm = null; - if (currentProject!=null) { - epm = new ErrorParserManager(currentProject, new SCMarkerGenerator(), new String[] {GMAKE_ERROR_PARSER_ID}); - epm.setOutputStream(cos); + // Using GMAKE_ERROR_PARSER_ID as it can handle shell error messages + ErrorParserManager epm = new ErrorParserManager(currentProject, new SDMarkerGenerator(), new String[] {GMAKE_ERROR_PARSER_ID}); + epm.setOutputStream(cos); + + IResource markersResource = currentProject!= null ? currentProject : ResourcesPlugin.getWorkspace().getRoot(); + + // clear old markers + try { + IMarker[] cur = markersResource.findMarkers(SDMarkerGenerator.SCANNER_DISCOVERY_PROBLEM_MARKER, false, IResource.DEPTH_ZERO); + for (IMarker marker : cur) { + if (getId().equals(marker.getAttribute(SDMarkerGenerator.PROVIDER))) { + marker.delete(); + } + } + } catch (CoreException e) { + ManagedBuilderCorePlugin.log(e); } + if (monitor==null) { monitor = new NullProgressMonitor(); @@ -323,8 +405,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti if (p != null) { // Before launching give visual cues via the monitor monitor.subTask("Invoking command " + command); - if (launcher.waitAndRead(consoleOut, consoleErr, new SubProgressMonitor(monitor, 0)) - != ICommandLauncher.OK) { + if (launcher.waitAndRead(consoleOut, consoleErr, new SubProgressMonitor(monitor, 0)) != ICommandLauncher.OK) { errMsg = launcher.getErrorMessage(); } } else { @@ -352,6 +433,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti return false; } + printLine(consoleOut, NEWLINE + "**** Collected " + collected + " entries. ****"); return true; } @@ -366,13 +448,18 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti } private IConsole startProviderConsole() { + String extConsoleId; + if (currentProject != null) { + extConsoleId = "org.eclipse.cdt.make.internal.ui.scannerconfig.ScannerDiscoveryConsole"; + } else { + extConsoleId = "org.eclipse.cdt.make.internal.ui.scannerconfig.ScannerDiscoveryGlobalConsole"; + } ILanguage ld = LanguageManager.getInstance().getLanguage(currentLanguageId); - String consoleId = MakeCorePlugin.PLUGIN_ID + '.' + getId() + '.' + currentLanguageId; String consoleName = getName() + ", " + ld.getName(); URL defaultIcon = Platform.getBundle(PLUGIN_CDT_MAKE_UI_ID).getEntry("icons/obj16/inspect_system.gif"); - IConsole console = CCorePlugin.getDefault().getConsole("org.eclipse.cdt.make.internal.ui.scannerconfig.ScannerDiscoveryConsole", consoleId, consoleName, defaultIcon); + IConsole console = CCorePlugin.getDefault().getConsole(extConsoleId, consoleId, consoleName, defaultIcon); return console; } @@ -381,7 +468,14 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti if (envStrings!=null) { String varPrefix = envVar+'='; for (String envStr : envStrings) { - if (envStr.startsWith(varPrefix)) { + boolean found = false; + // need to convert "Path" to "PATH" on Windows + if (Platform.getOS().equals(Platform.OS_WIN32)) { + found = envStr.substring(0,varPrefix.length()).toUpperCase().startsWith(varPrefix); + } else { + found = envStr.startsWith(varPrefix); + } + if (found) { envPath = envStr.substring(varPrefix.length()); break; } diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/ConsoleOutputSniffer.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/ConsoleOutputSniffer.java index bf81b071c09..85d1dc3c62b 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/ConsoleOutputSniffer.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/ConsoleOutputSniffer.java @@ -130,8 +130,6 @@ public class ConsoleOutputSniffer { private OutputStream consoleErrorStream; private IConsoleParser[] parsers; - private ErrorParserManager errorParserManager = null; - public ConsoleOutputSniffer(IConsoleParser[] parsers) { this.parsers = parsers; } @@ -142,11 +140,6 @@ public class ConsoleOutputSniffer { this.consoleErrorStream = errorStream; } - public ConsoleOutputSniffer(OutputStream outputStream, OutputStream errorStream, IConsoleParser[] parsers, ErrorParserManager epm) { - this(outputStream, errorStream, parsers); - this.errorParserManager = epm; - } - /** * Returns an output stream that will be sniffed. * This stream should be hooked up so the command @@ -177,7 +170,7 @@ public class ConsoleOutputSniffer { if (nOpens > 0 && --nOpens == 0) { for (int i = 0; i < parsers.length; ++i) { try { - parsers[i].shutdown(); + parsers[i].shutdown(); } catch (Throwable e) { // Report exception if any but let all the parsers chance to shutdown. CCorePlugin.log(e); @@ -195,10 +188,10 @@ public class ConsoleOutputSniffer { private synchronized void processLine(String line) { for (IConsoleParser parser : parsers) { try { - if (parser instanceof IErrorParser) { - // IErrorParser interface is used here only to pass ErrorParserManager + if (consoleOutputStream instanceof ErrorParserManager && parser instanceof IErrorParser ) { + // IErrorParser interface is used here only with purpose to pass ErrorParserManager // which keeps track of CWD and provides useful methods for locating files - ((IErrorParser)parser).processLine(line, errorParserManager); + ((IErrorParser)parser).processLine(line, (ErrorParserManager) consoleOutputStream); } else { parser.processLine(line); } From b33b63d9709dc8cb79ead0be403ebe6371049955 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Tue, 4 Oct 2011 00:11:21 -0400 Subject: [PATCH 043/120] Generalizing providers as resource listeners --- .../AllLanguageSettingsProvidersTests.java | 1 + .../LanguageSettingsExtensionsTests.java | 4 +- .../LanguageSettingsListenersTests.java | 494 ++++++++++++++++++ .../LanguageSettingsManagerTests.java | 2 +- ...nguageSettingsPersistenceProjectTests.java | 4 +- .../providers/MockListenerRegisterer.java | 103 ++++ core/org.eclipse.cdt.core.tests/plugin.xml | 20 +- .../providers/ICListenerRegisterer.java | 24 + .../LanguageSettingsProvidersSerializer.java | 220 +++++--- 9 files changed, 785 insertions(+), 87 deletions(-) create mode 100644 core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsListenersTests.java create mode 100644 core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockListenerRegisterer.java create mode 100644 core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ICListenerRegisterer.java diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/AllLanguageSettingsProvidersTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/AllLanguageSettingsProvidersTests.java index fb9b5be8379..5af3487e58d 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/AllLanguageSettingsProvidersTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/AllLanguageSettingsProvidersTests.java @@ -26,6 +26,7 @@ public class AllLanguageSettingsProvidersTests { suite.addTest(LanguageSettingsManagerTests.suite()); suite.addTest(LanguageSettingsSerializableTests.suite()); suite.addTest(LanguageSettingsPersistenceProjectTests.suite()); + suite.addTest(LanguageSettingsListenersTests.suite()); suite.addTest(LanguageSettingsScannerInfoProviderTests.suite()); return suite; } diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java index 3a95102a247..d7eb6af64de 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java @@ -37,11 +37,11 @@ import org.eclipse.core.runtime.Path; public class LanguageSettingsExtensionsTests extends TestCase { // These should match corresponding entries defined in plugin.xml private static final String EXTENSION_BASE_PROVIDER_ID = "org.eclipse.cdt.core.tests.language.settings.base.provider"; - private static final String EXTENSION_BASE_PROVIDER_NAME = "Test Plugin Language Settings Base Provider"; + private static final String EXTENSION_BASE_PROVIDER_NAME = "Test Plugin Mock Language Settings Base Provider"; private static final String EXTENSION_BASE_PROVIDER_LANG_ID = "org.eclipse.cdt.core.tests.language.id"; private static final String EXTENSION_BASE_PROVIDER_PARAMETER = "custom parameter"; private static final String EXTENSION_CUSTOM_PROVIDER_ID = "org.eclipse.cdt.core.tests.custom.language.settings.provider"; - private static final String EXTENSION_CUSTOM_PROVIDER_NAME = "Test Plugin Language Settings Provider"; + private static final String EXTENSION_CUSTOM_PROVIDER_NAME = "Test Plugin Mock Language Settings Provider"; private static final String EXTENSION_BASE_SUBCLASS_PROVIDER_ID = "org.eclipse.cdt.core.tests.language.settings.base.provider.subclass"; private static final String EXTENSION_BASE_SUBCLASS_PROVIDER_PARAMETER = "custom parameter subclass"; private static final String EXTENSION_SERIALIZABLE_PROVIDER_ID = "org.eclipse.cdt.core.tests.custom.serializable.language.settings.provider"; diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsListenersTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsListenersTests.java new file mode 100644 index 00000000000..7a527624432 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsListenersTests.java @@ -0,0 +1,494 @@ +/******************************************************************************* + * Copyright (c) 2011, 2011 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.core.language.settings.providers; + +import java.util.ArrayList; +import java.util.List; + +import junit.framework.TestCase; +import junit.framework.TestSuite; + +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.ResourceHelper; +import org.eclipse.core.resources.IProject; + +/** + * Test cases testing LanguageSettingsProvider functionality + */ +public class LanguageSettingsListenersTests extends TestCase { + // Must match provider id defined as extension point + private static final String EXTENSION_REGISTERER_PROVIDER_ID = "org.eclipse.cdt.core.tests.language.settings.listener.registerer.provider"; + + private static final String PROVIDER_1 = "test.provider.1.id"; + private static final String PROVIDER_NAME_1 = "test.provider.1.name"; + private static final String PROVIDER_CUSTOM_GLOBAL = "test.provider.custom.global.id"; + private static final String PROVIDER_CUSTOM_GLOBAL_NAME = "test.provider.custom.global.name"; + + /** + * Constructor. + * @param name - name of the test. + */ + public LanguageSettingsListenersTests(String name) { + super(name); + + } + + @Override + protected void setUp() throws Exception { + } + + @Override + protected void tearDown() throws Exception { + LanguageSettingsManager.setWorkspaceProviders(null); + ResourceHelper.cleanUp(); + } + + /** + * @return - new TestSuite. + */ + public static TestSuite suite() { + return new TestSuite(LanguageSettingsListenersTests.class); + } + + /** + * main function of the class. + * + * @param args - arguments + */ + public static void main(String[] args) { + junit.textui.TestRunner.run(suite()); + } + + /** + */ + public void testListenerRegisterer_CheckExtensionProvider() throws Exception { + // check if extension provider exists + ILanguageSettingsProvider workspaceProvider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_REGISTERER_PROVIDER_ID); + ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(workspaceProvider); + assertNotNull(rawProvider); + // global listeners providers get registered only lazily + assertEquals(0, MockListenerRegisterer.getCount(EXTENSION_REGISTERER_PROVIDER_ID)); + } + + /** + */ + public void testListenerRegisterer_OneOwnedByCfg() throws Exception { + IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName()); + + { + // get project descriptions + ICProjectDescription writableProjDescription = CoreModel.getDefault().getProjectDescription(project); + assertNotNull(writableProjDescription); + ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); + assertEquals(1, cfgDescriptions.length); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + // create a provider + ILanguageSettingsProvider mockProvider = new MockListenerRegisterer(PROVIDER_1, PROVIDER_NAME_1); + List providers = new ArrayList(); + providers.add(mockProvider); + cfgDescription.setLanguageSettingProviders(providers); + List storedProviders = cfgDescription.getLanguageSettingProviders(); + assertEquals(1, storedProviders.size()); + + // write to project description + CoreModel.getDefault().setProjectDescription(project, writableProjDescription); + assertEquals(1, MockListenerRegisterer.getCount(PROVIDER_1)); + } + { + // close the project + project.close(null); + assertEquals(0, MockListenerRegisterer.getCount(PROVIDER_1)); + } + { + // reopen the project + project.open(null); + CoreModel.getDefault().getProjectDescription(project); + assertEquals(1, MockListenerRegisterer.getCount(PROVIDER_1)); + // and delete + project.delete(true, null); + assertEquals(0, MockListenerRegisterer.getCount(PROVIDER_1)); + } + + } + + /** + */ + public void testListenerRegisterer_TwoOwnedByCfgs() throws Exception { + 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", + }); + + { + // get project descriptions + ICProjectDescription writableProjDescription = CoreModel.getDefault().getProjectDescription(project); + assertNotNull(writableProjDescription); + ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); + assertEquals(2, cfgDescriptions.length); + ICConfigurationDescription cfgDescription1 = cfgDescriptions[0]; + ICConfigurationDescription cfgDescription2 = cfgDescriptions[1]; + + { + // create a provider 1 + ILanguageSettingsProvider mockProvider = new MockListenerRegisterer(PROVIDER_1, PROVIDER_NAME_1); + List providers = new ArrayList(); + providers.add(mockProvider); + cfgDescription1.setLanguageSettingProviders(providers); + List storedProviders = cfgDescription1.getLanguageSettingProviders(); + assertEquals(1, storedProviders.size()); + } + { + // create a provider 2 + ILanguageSettingsProvider mockProvider = new MockListenerRegisterer(PROVIDER_1, PROVIDER_NAME_1); + List providers = new ArrayList(); + providers.add(mockProvider); + cfgDescription2.setLanguageSettingProviders(providers); + List storedProviders = cfgDescription2.getLanguageSettingProviders(); + assertEquals(1, storedProviders.size()); + } + + // write to project description + CoreModel.getDefault().setProjectDescription(project, writableProjDescription); + assertEquals(2, MockListenerRegisterer.getCount(PROVIDER_1)); + } + { + // close the project + project.close(null); + assertEquals(0, MockListenerRegisterer.getCount(PROVIDER_1)); + } + { + // reopen the project + project.open(null); + CoreModel.getDefault().getProjectDescription(project); + assertEquals(2, MockListenerRegisterer.getCount(PROVIDER_1)); + // and delete + project.delete(true, null); + assertEquals(0, MockListenerRegisterer.getCount(PROVIDER_1)); + } + + } + + /** + */ + public void testListenerRegisterer_OneGlobal() throws Exception { + IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName()); + { + // get project descriptions + ICProjectDescription writableProjDescription = CoreModel.getDefault().getProjectDescription(project); + assertNotNull(writableProjDescription); + ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); + assertEquals(1, cfgDescriptions.length); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + // add global provider + ILanguageSettingsProvider workspaceProvider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_REGISTERER_PROVIDER_ID); + List providers = new ArrayList(); + providers.add(workspaceProvider); + cfgDescription.setLanguageSettingProviders(providers); + List storedProviders = cfgDescription.getLanguageSettingProviders(); + assertEquals(1, storedProviders.size()); + + // write to project description + CoreModel.getDefault().setProjectDescription(project, writableProjDescription); + 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); + CoreModel.getDefault().getProjectDescription(project); + assertEquals(1, MockListenerRegisterer.getCount(EXTENSION_REGISTERER_PROVIDER_ID)); + // and delete + project.delete(true, null); + assertEquals(0, MockListenerRegisterer.getCount(EXTENSION_REGISTERER_PROVIDER_ID)); + } + + } + + /** + */ + public void testListenerRegisterer_TwoGlobal() throws Exception { + 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", + }); + + { + // retrieve global provider + ILanguageSettingsProvider workspaceProvider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_REGISTERER_PROVIDER_ID); + // get project descriptions + ICProjectDescription writableProjDescription = CoreModel.getDefault().getProjectDescription(project); + assertNotNull(writableProjDescription); + ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); + assertEquals(2, cfgDescriptions.length); + ICConfigurationDescription cfgDescription1 = cfgDescriptions[0]; + ICConfigurationDescription cfgDescription2 = cfgDescriptions[1]; + + { + // add global provider to configuration 1 + List providers = new ArrayList(); + providers.add(workspaceProvider); + cfgDescription1.setLanguageSettingProviders(providers); + List storedProviders = cfgDescription1.getLanguageSettingProviders(); + assertEquals(1, storedProviders.size()); + } + { + // add global provider to configuration 2 + List providers = new ArrayList(); + providers.add(workspaceProvider); + cfgDescription2.setLanguageSettingProviders(providers); + List storedProviders = cfgDescription2.getLanguageSettingProviders(); + assertEquals(1, storedProviders.size()); + } + // write to project description + CoreModel.getDefault().setProjectDescription(project, writableProjDescription); + 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); + CoreModel.getDefault().getProjectDescription(project); + assertEquals(1, MockListenerRegisterer.getCount(EXTENSION_REGISTERER_PROVIDER_ID)); + // and delete + project.delete(true, null); + assertEquals(0, MockListenerRegisterer.getCount(EXTENSION_REGISTERER_PROVIDER_ID)); + } + } + + /** + */ + public void testListenerRegisterer_TwoGlobalMinusOne() throws Exception { + 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", + }); + + { + // retrieve workspace provider + ILanguageSettingsProvider workspaceProvider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_REGISTERER_PROVIDER_ID); + // get project descriptions + ICProjectDescription writableProjDescription = CoreModel.getDefault().getProjectDescription(project); + assertNotNull(writableProjDescription); + ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); + assertEquals(2, cfgDescriptions.length); + ICConfigurationDescription cfgDescription1 = cfgDescriptions[0]; + ICConfigurationDescription cfgDescription2 = cfgDescriptions[1]; + + { + // add global provider to configuration 1 + List providers = new ArrayList(); + providers.add(workspaceProvider); + cfgDescription1.setLanguageSettingProviders(providers); + List storedProviders = cfgDescription1.getLanguageSettingProviders(); + assertEquals(1, storedProviders.size()); + } + { + // add global provider to configuration 2 + List providers = new ArrayList(); + providers.add(workspaceProvider); + cfgDescription2.setLanguageSettingProviders(providers); + List storedProviders = cfgDescription2.getLanguageSettingProviders(); + assertEquals(1, storedProviders.size()); + } + // write to project description + CoreModel.getDefault().setProjectDescription(project, writableProjDescription); + assertEquals(1, MockListenerRegisterer.getCount(EXTENSION_REGISTERER_PROVIDER_ID)); + } + { + // retrieve workspace provider + ILanguageSettingsProvider workspaceProvider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_REGISTERER_PROVIDER_ID); + // get project descriptions + ICProjectDescription writableProjDescription = CoreModel.getDefault().getProjectDescription(project); + assertNotNull(writableProjDescription); + ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); + assertEquals(2, cfgDescriptions.length); + ICConfigurationDescription cfgDescription1 = cfgDescriptions[0]; + ICConfigurationDescription cfgDescription2 = cfgDescriptions[1]; + + { + // remove global provider from configuration 1 + List providers = new ArrayList(); + cfgDescription1.setLanguageSettingProviders(providers); + List storedProviders = cfgDescription1.getLanguageSettingProviders(); + assertEquals(0, storedProviders.size()); + } + // write to project description + CoreModel.getDefault().setProjectDescription(project, writableProjDescription); + assertEquals(1, MockListenerRegisterer.getCount(EXTENSION_REGISTERER_PROVIDER_ID)); + } + { + // close the project + project.close(null); + assertEquals(0, MockListenerRegisterer.getCount(EXTENSION_REGISTERER_PROVIDER_ID)); + } + } + + /** + */ + public void testListenerRegisterer_GlobalProviderTwoProjects() throws Exception { + // create project 1 + IProject project_1 = ResourceHelper.createCDTProjectWithConfig(this.getName() + ".1"); + { + // get project descriptions + ICProjectDescription writableProjDescription = CoreModel.getDefault().getProjectDescription(project_1); + assertNotNull(writableProjDescription); + ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); + assertEquals(1, cfgDescriptions.length); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + // add global provider + ILanguageSettingsProvider workspaceProvider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_REGISTERER_PROVIDER_ID); + List providers = new ArrayList(); + providers.add(workspaceProvider); + cfgDescription.setLanguageSettingProviders(providers); + List storedProviders = cfgDescription.getLanguageSettingProviders(); + assertEquals(1, storedProviders.size()); + + // write to project description + CoreModel.getDefault().setProjectDescription(project_1, writableProjDescription); + assertEquals(1, MockListenerRegisterer.getCount(EXTENSION_REGISTERER_PROVIDER_ID)); + } + + // create project 2 + IProject project_2 = ResourceHelper.createCDTProjectWithConfig(this.getName() + ".2"); + { + // get project descriptions + ICProjectDescription writableProjDescription = CoreModel.getDefault().getProjectDescription(project_2); + assertNotNull(writableProjDescription); + ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); + assertEquals(1, cfgDescriptions.length); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + // add global provider + ILanguageSettingsProvider workspaceProvider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_REGISTERER_PROVIDER_ID); + List providers = new ArrayList(); + providers.add(workspaceProvider); + cfgDescription.setLanguageSettingProviders(providers); + List storedProviders = cfgDescription.getLanguageSettingProviders(); + assertEquals(1, storedProviders.size()); + + // write to project description + CoreModel.getDefault().setProjectDescription(project_2, writableProjDescription); + 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)); + } + + } + + /** + */ + public void testListenerRegisterer_GlobalProviderNotInUse() throws Exception { + 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)); + + List workspaceProvidersOriginal = LanguageSettingsManager.getWorkspaceProviders(); + { + // add global provider which is not engaged + ILanguageSettingsProvider provider = new MockListenerRegisterer(PROVIDER_CUSTOM_GLOBAL, PROVIDER_CUSTOM_GLOBAL_NAME); + List providers = new ArrayList(workspaceProvidersOriginal); + providers.add(provider); + LanguageSettingsManager.setWorkspaceProviders(providers); + assertEquals(0, MockListenerRegisterer.getCount(PROVIDER_CUSTOM_GLOBAL)); + } + { + // remove global provider and restore original list + List providers = new ArrayList(workspaceProvidersOriginal); + LanguageSettingsManager.setWorkspaceProviders(providers); + assertEquals(0, MockListenerRegisterer.getCount(PROVIDER_CUSTOM_GLOBAL)); + } + } + + /** + */ + public void testListenerRegisterer_GlobalProviderAddRemoveOutsideTheProject() throws Exception { + 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 workspaceProvidersOriginal = LanguageSettingsManager.getWorkspaceProviders(); + IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName()); + { + // get project descriptions + ICProjectDescription writableProjDescription = CoreModel.getDefault().getProjectDescription(project); + assertNotNull(writableProjDescription); + ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); + assertEquals(1, cfgDescriptions.length); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + // add global provider + List providers = new ArrayList(); + providers.add(workspaceProvider); + cfgDescription.setLanguageSettingProviders(providers); + List storedProviders = cfgDescription.getLanguageSettingProviders(); + assertEquals(1, storedProviders.size()); + + // write to project description + CoreModel.getDefault().setProjectDescription(project, writableProjDescription); + // 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 providers = new ArrayList(); + providers.add(provider); + LanguageSettingsManager.setWorkspaceProviders(providers); + assertEquals(1, MockListenerRegisterer.getCount(PROVIDER_CUSTOM_GLOBAL)); + } + { + // remove global provider + List providers = new ArrayList(workspaceProvidersOriginal); + LanguageSettingsManager.setWorkspaceProviders(providers); + assertEquals(0, MockListenerRegisterer.getCount(PROVIDER_CUSTOM_GLOBAL)); + } + + { + // close project + project.close(null); + assertEquals(0, MockListenerRegisterer.getCount(PROVIDER_CUSTOM_GLOBAL)); + } + } + +} + + diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java index ebff84f3c76..d6732472b4b 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java @@ -44,7 +44,7 @@ public class LanguageSettingsManagerTests extends TestCase { // Should match id of extension point defined in plugin.xml private static final String EXTENSION_BASE_PROVIDER_ID = "org.eclipse.cdt.core.tests.language.settings.base.provider"; private static final String EXTENSION_EDITABLE_PROVIDER_ID = "org.eclipse.cdt.core.tests.custom.editable.language.settings.provider"; - private static final String EXTENSION_EDITABLE_PROVIDER_NAME = "Test Plugin Editable Language Settings Provider"; + private static final String EXTENSION_EDITABLE_PROVIDER_NAME = "Test Plugin Mock Editable Language Settings Provider"; private static final IFile FILE_0 = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("/project/path0")); private static final String CFG_ID = "test.configuration.id"; diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java index dbb5f954000..f08b723b4e6 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java @@ -43,9 +43,9 @@ import org.w3c.dom.Element; public class LanguageSettingsPersistenceProjectTests extends TestCase { private static final String LANGUAGE_SETTINGS_PROJECT_XML = ".settings/language.settings.xml"; private static final String LANGUAGE_SETTINGS_WORKSPACE_XML = "language.settings.xml"; - // Should match id of extension point defined in plugin.xml + // Should match extension points defined in plugin.xml private static final String EXTENSION_PROVIDER_ID = "org.eclipse.cdt.core.tests.language.settings.base.provider.subclass"; - private static final String EXTENSION_PROVIDER_NAME = "Test Plugin Base Provider Subclass"; + private static final String EXTENSION_PROVIDER_NAME = "Test Plugin Mock Base Provider Subclass"; private static final String EXTENSION_SERIALIZABLE_PROVIDER_ID = "org.eclipse.cdt.core.tests.custom.serializable.language.settings.provider"; private static final String CFG_ID = "test.configuration.id.0"; diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockListenerRegisterer.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockListenerRegisterer.java new file mode 100644 index 00000000000..2d4a05c4b21 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockListenerRegisterer.java @@ -0,0 +1,103 @@ +/******************************************************************************* + * Copyright (c) 2011, 2011 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.core.language.settings.providers; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider; +import org.eclipse.core.runtime.Assert; + +/** + * Language Settings Provider that keeps count how many times it has been registered. + */ +public class MockListenerRegisterer extends LanguageSettingsSerializable implements ILanguageSettingsEditableProvider, ICListenerRegisterer { + private static MockListenerManager mockListenerManager = new MockListenerManager(); + + private static class MockListenerManager { + private class ListenerCount { + private MockListenerRegisterer listener; + private int count; + public ListenerCount(MockListenerRegisterer l, int cnt) { + listener = l; + count = cnt; + } + } + private List register = new ArrayList(); + + public void registerListener(MockListenerRegisterer listener) { + for (ListenerCount lc : register) { + if (lc.listener == listener) { + lc.count++; + return; + } + } + + register.add(new ListenerCount(listener, 1)); + } + + public void unregisterListener(MockListenerRegisterer listener) { + for (ListenerCount lc : register) { + if (lc.listener == listener) { + lc.count--; + Assert.isTrue(lc.count>=0); + return; + } + } + + // attempt to unregister non-registered listener + Assert.isTrue(false); + } + + /** + * Note that that count includes all listeners with that id. + */ + public int getCount(String id) { + int count = 0; + + for (ListenerCount lc : register) { + if (lc.listener.getId().equals(id)) { + count = count + lc.count; + } + } + + return count; + } + } + + public MockListenerRegisterer() { + super(); + } + public MockListenerRegisterer(String id, String name) { + super(id, name); + } + public void registerListener(ICConfigurationDescription cfgDescription) { + mockListenerManager.registerListener(this); + } + + public void unregisterListener() { + mockListenerManager.unregisterListener(this); + } + @Override + public MockListenerRegisterer cloneShallow() throws CloneNotSupportedException { + return (MockListenerRegisterer) super.cloneShallow(); + } + @Override + public MockListenerRegisterer clone() throws CloneNotSupportedException { + return (MockListenerRegisterer) super.clone(); + } + + public static int getCount(String id) { + return mockListenerManager.getCount(id); + } +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.core.tests/plugin.xml b/core/org.eclipse.cdt.core.tests/plugin.xml index 4c4418fc9fe..c8588c34993 100644 --- a/core/org.eclipse.cdt.core.tests/plugin.xml +++ b/core/org.eclipse.cdt.core.tests/plugin.xml @@ -201,7 +201,7 @@ --> @@ -250,12 +250,12 @@ + name="Test Plugin Mock Language Settings Provider"> + name="Test Plugin Mock Serializable Language Settings Provider"> + name="Test Plugin Mock Editable Language Settings Provider"> + + + + diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ICListenerRegisterer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ICListenerRegisterer.java new file mode 100644 index 00000000000..df953e20808 --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ICListenerRegisterer.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2011, 2011 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.core.language.settings.providers; + +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; + + +/** + * Helper class to allow listeners self-register/dispose. Called by cdt core. + * TODO - expand in more detail. + */ +public interface ICListenerRegisterer { + public void registerListener(ICConfigurationDescription cfgDescription); + public void unregisterListener(); +} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java index e81dd9ca1ca..0ef6a684080 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java @@ -19,6 +19,7 @@ import java.util.List; import java.util.Map; import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.language.settings.providers.ICListenerRegisterer; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable; @@ -33,10 +34,6 @@ import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceChangeEvent; -import org.eclipse.core.resources.IResourceChangeListener; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; @@ -66,13 +63,22 @@ public class LanguageSettingsProvidersSerializer { private static Map rawGlobalWorkspaceProviders = new HashMap(); private static Map globalWorkspaceProviders = new HashMap(); - private static class LanguageSettingsWorkspaceProvider implements ILanguageSettingsProvider, IResourceChangeListener { - private String providerId; - private int registrationCount = 0; + private static class ListenerAssociation { + private ICListenerRegisterer listener; + private ICConfigurationDescription cfgDescription; + + public ListenerAssociation(ICListenerRegisterer li, ICConfigurationDescription cfgd) { + listener = li; + cfgDescription = cfgd; + } + } - public LanguageSettingsWorkspaceProvider(String id) { + private static class LanguageSettingsWorkspaceProvider implements ILanguageSettingsProvider, ICListenerRegisterer { + private String providerId; + private int projectCount = 0; + + private LanguageSettingsWorkspaceProvider(String id) { Assert.isNotNull(id); - Assert.isTrue(id.length()>0); providerId = id; } @@ -117,22 +123,38 @@ public class LanguageSettingsProvidersSerializer { } /** - * {@inheritDoc} - * - * LanguageSettingsWorkspaceProvider delegates event handling to raw provider. - * + * We count number of times workspace provider (not the raw one!) associated + * with a project. If a project includes it multiple times via different configurations + * it still counts as 1. */ - public void resourceChanged(IResourceChangeEvent event) { - // keep in mind that type of rawProvider can change - ILanguageSettingsProvider rawProvider = getRawProvider(); - if (rawProvider instanceof IResourceChangeListener) { - ((IResourceChangeListener) rawProvider).resourceChanged(event); - } + private int getProjectCount() { + return projectCount; } - synchronized int incrementListenerCount(int inc) { - registrationCount += inc; - return registrationCount; + private synchronized int incrementProjectCount() { + projectCount++; + return projectCount; + } + + private synchronized int decrementProjectCount() { + projectCount--; + return projectCount; + } + + public void registerListener(ICConfigurationDescription cfgDescription) { + // keep in mind that rawProvider can change + ILanguageSettingsProvider rawProvider = getRawProvider(); + if (rawProvider instanceof ICListenerRegisterer) { + ((ICListenerRegisterer) rawProvider).registerListener(null); + } + } + + public void unregisterListener() { + // keep in mind that rawProvider can change + ILanguageSettingsProvider rawProvider = getRawProvider(); + if (rawProvider instanceof ICListenerRegisterer) { + ((ICListenerRegisterer) rawProvider).unregisterListener(); + } } } @@ -142,9 +164,8 @@ public class LanguageSettingsProvidersSerializer { try { loadLanguageSettingsWorkspace(); } catch (Throwable e) { + // log and swallow any exception CCorePlugin.log("Error loading workspace language settings providers", e); //$NON-NLS-1$ - } finally { - // swallow any exception } } @@ -195,8 +216,8 @@ public class LanguageSettingsProvidersSerializer { } } + List rawProviders = new ArrayList(); if (providers!=null) { - List rawProviders = new ArrayList(); for (ILanguageSettingsProvider provider : providers) { if (isWorkspaceProvider(provider)) { provider = rawGlobalWorkspaceProviders.get(provider.getId()); @@ -210,6 +231,27 @@ public class LanguageSettingsProvidersSerializer { } } + List oldListeners = selectListeners(rawGlobalWorkspaceProviders.values()); + List newListeners = selectListeners(rawProviders); + + for (ICListenerRegisterer oldListener : oldListeners) { + if (!isObjectInTheList(newListeners, oldListener)) { + LanguageSettingsWorkspaceProvider wspProvider = (LanguageSettingsWorkspaceProvider) globalWorkspaceProviders.get(((ILanguageSettingsProvider)oldListener).getId()); + if (wspProvider != null && wspProvider.getProjectCount() > 0) { + oldListener.unregisterListener(); + } + } + } + + for (ICListenerRegisterer newListener : newListeners) { + if (!isObjectInTheList(oldListeners, newListener)) { + LanguageSettingsWorkspaceProvider wspProvider = (LanguageSettingsWorkspaceProvider) globalWorkspaceProviders.get(((ILanguageSettingsProvider)newListener).getId()); + if (wspProvider != null && wspProvider.getProjectCount() > 0) { + newListener.registerListener(null); + } + } + } + rawGlobalWorkspaceProviders = rawWorkspaceProviders; } @@ -654,36 +696,39 @@ public class LanguageSettingsProvidersSerializer { } } - /** - * TODO - remove me - * Temporary method to report inconsistency in log. - */ - @Deprecated - public static void assertConsistency(ICConfigurationDescription cfgDescription) { - List listeners = new ArrayList(); - List providers = cfgDescription.getLanguageSettingProviders(); - for (ILanguageSettingsProvider provider : providers) { - if (isObjectInTheList(listeners, provider)) { - IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "Inconsistent state, duplicate LSP in project description " + provider); - CoreException e = new CoreException(status); - CCorePlugin.log(e); - } - listeners.add(provider); + private static boolean isObjectInTheList(Collection list, T element) { + // list.contains(element) won't do it as we are interested in exact object, not in equal object + for (T elem : list) { + if (elem == element) + return true; } + return false; } - + + private static boolean isListenerInTheListOfAssociations(Collection list, ICListenerRegisterer element) { + // list.contains(element) won't do it as we are interested in exact object, not in equal object + for (ListenerAssociation la : list) { + if (la.listener == element) + return true; + } + return false; + } + /** - * Get a providers list including only providers of type IResourceChangeListener + * Get a providers list including only providers of type ICListenerRegisterer * for a given project description - collecting from all configurations. */ - private static List getResourceChangeListeners(ICProjectDescription prjDescription) { - List listeners = new ArrayList(); + private static List getListeners(ICProjectDescription prjDescription) { + List listeners = new ArrayList(); if (prjDescription != null) { for (ICConfigurationDescription cfgDescription : prjDescription.getConfigurations()) { List providers = cfgDescription.getLanguageSettingProviders(); for (ILanguageSettingsProvider provider : providers) { - if (provider instanceof IResourceChangeListener) { - listeners.add((IResourceChangeListener) provider); + if (provider instanceof ICListenerRegisterer) { + ICListenerRegisterer listener = (ICListenerRegisterer) provider; + if (!isObjectInTheList(listeners, listener)) { + listeners.add(listener); + } } } } @@ -691,6 +736,35 @@ public class LanguageSettingsProvidersSerializer { return listeners; } + private static List selectListeners(Collection values) { + List listeners = new ArrayList(); + for (ILanguageSettingsProvider provider : values) { + if (provider instanceof ICListenerRegisterer) + listeners.add((ICListenerRegisterer) provider); + } + return listeners; + } + + /** + * Get a providers list including only providers of type IResourceChangeListener + * for a given project description - collecting from all configurations. + */ + private static List getListenersAssociations(ICProjectDescription prjDescription) { + List associations = new ArrayList(); + if (prjDescription != null) { + for (ICConfigurationDescription cfgDescription : prjDescription.getConfigurations()) { + List providers = cfgDescription.getLanguageSettingProviders(); + List listeners = selectListeners(providers); + for (ICListenerRegisterer listener : listeners) { + if (!isListenerInTheListOfAssociations(associations, listener)) { + associations.add(new ListenerAssociation(listener, cfgDescription)); + } + } + } + } + return associations; + } + /** * Unregister listeners which are not used anymore and register new listeners. * The method is used when project description is applied to workspace. @@ -706,54 +780,46 @@ public class LanguageSettingsProvidersSerializer { assertConsistency(oldPrjDescription); // TODO - remove me assertConsistency(newPrjDescription); // TODO - remove me - IWorkspace workspace = ResourcesPlugin.getWorkspace(); + List oldListeners = getListeners(oldPrjDescription); + List newAssociations = getListenersAssociations(newPrjDescription); - List oldListeners = getResourceChangeListeners(oldPrjDescription); - List newListeners = getResourceChangeListeners(newPrjDescription); - - for (IResourceChangeListener listener : oldListeners) { - if (!isObjectInTheList(newListeners, listener)) { + for (ICListenerRegisterer oldListener : oldListeners) { + if (!isListenerInTheListOfAssociations(newAssociations, oldListener)) { int count = 0; - if (listener instanceof LanguageSettingsWorkspaceProvider) { - count = ((LanguageSettingsWorkspaceProvider) listener).incrementListenerCount(-1); + if (oldListener instanceof LanguageSettingsWorkspaceProvider) { + count = ((LanguageSettingsWorkspaceProvider) oldListener).decrementProjectCount(); } if (count == 0) { - workspace.removeResourceChangeListener(listener); - // TODO - remove me - CCorePlugin.log(new Status(IStatus.WARNING,CCorePlugin.PLUGIN_ID, oldPrjDescription.getProject() + ": Removed IResourceChangeListener " - + "[" + System.identityHashCode(listener) + "] " - + listener)); + try { + oldListener.unregisterListener(); + } catch (Throwable e) { + // protect from any exceptions from implementers + CCorePlugin.log(e); + } } } } - for (IResourceChangeListener listener : newListeners) { - if (!isObjectInTheList(oldListeners, listener)) { + for (ListenerAssociation newListenerAssociation : newAssociations) { + ICListenerRegisterer newListener = newListenerAssociation.listener; + if (!isObjectInTheList(oldListeners, newListener)) { int count = 1; - if (listener instanceof LanguageSettingsWorkspaceProvider) { - count = ((LanguageSettingsWorkspaceProvider) listener).incrementListenerCount(1); + if (newListener instanceof LanguageSettingsWorkspaceProvider) { + count = ((LanguageSettingsWorkspaceProvider) newListener).incrementProjectCount(); } if (count == 1) { - workspace.addResourceChangeListener(listener); - // TODO - remove me - CCorePlugin.log(new Status(IStatus.WARNING,CCorePlugin.PLUGIN_ID, newPrjDescription.getProject() + ": Added IResourceChangeListener " - + "[" + System.identityHashCode(listener) + "] " - + listener)); + try { + newListener.registerListener(newListenerAssociation.cfgDescription); + } catch (Throwable e) { + // protect from any exceptions from implementers + CCorePlugin.log(e); + } } } } } - private static boolean isObjectInTheList(Collection list, T element) { - // list.contains(element) won't do it as we are interested in exact object, not in equal object - for (T elem : list) { - if (elem == element) - return true; - } - return false; - } - /** * Deep clone of a list of language settings providers. * From 08529151defb71d56fa64c43a6ea97907a4d03cf Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Wed, 19 Oct 2011 18:27:13 -0400 Subject: [PATCH 044/120] Workaround for ${workspace_loc:/prj-name} returned by builder --- .../AbstractLanguageSettingsOutputScanner.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java index fc800c84be7..11b758a36e3 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java @@ -25,7 +25,10 @@ import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.ErrorParserManager; +import org.eclipse.cdt.core.cdtvariables.CdtVariableException; +import org.eclipse.cdt.core.cdtvariables.ICdtVariableManager; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; @@ -449,7 +452,14 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett } if (buildDirURI == null && currentCfgDescription != null) { - IPath builderCWD = currentCfgDescription.getBuildSetting().getBuilderCWD(); + String builderCWD = currentCfgDescription.getBuildSetting().getBuilderCWD().toString(); + try { + // TODO - here is a hack to overcome ${workspace_loc:/prj-name} returned by builder + ICdtVariableManager vmanager = CCorePlugin.getDefault().getCdtVariableManager(); + builderCWD = vmanager.resolveValue(builderCWD, "", null, currentCfgDescription); + } catch (CdtVariableException e) { + MakeCorePlugin.log(e); + } buildDirURI = org.eclipse.core.filesystem.URIUtil.toURI(builderCWD); } From 470ce6cd41fee74a9c5706821991586b78fb5f12 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Thu, 20 Oct 2011 17:18:18 -0400 Subject: [PATCH 045/120] Fixed bug breaking JUnit test --- ...AbstractLanguageSettingsOutputScanner.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java index 11b758a36e3..db838a754f4 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java @@ -452,15 +452,18 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett } if (buildDirURI == null && currentCfgDescription != null) { - String builderCWD = currentCfgDescription.getBuildSetting().getBuilderCWD().toString(); - try { - // TODO - here is a hack to overcome ${workspace_loc:/prj-name} returned by builder - ICdtVariableManager vmanager = CCorePlugin.getDefault().getCdtVariableManager(); - builderCWD = vmanager.resolveValue(builderCWD, "", null, currentCfgDescription); - } catch (CdtVariableException e) { - MakeCorePlugin.log(e); + IPath pathBuilderCWD = currentCfgDescription.getBuildSetting().getBuilderCWD(); + if (pathBuilderCWD != null) { + String builderCWD = pathBuilderCWD.toString(); + try { + // TODO - here is a hack to overcome ${workspace_loc:/prj-name} returned by builder + ICdtVariableManager vmanager = CCorePlugin.getDefault().getCdtVariableManager(); + builderCWD = vmanager.resolveValue(builderCWD, "", null, currentCfgDescription); + } catch (CdtVariableException e) { + MakeCorePlugin.log(e); + } + buildDirURI = org.eclipse.core.filesystem.URIUtil.toURI(builderCWD); } - buildDirURI = org.eclipse.core.filesystem.URIUtil.toURI(builderCWD); } if (buildDirURI == null && currentProject != null) { From 493c7268022d481ffa6e93581177a7b866533402 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Fri, 28 Oct 2011 13:09:22 -0400 Subject: [PATCH 046/120] Renamed test suites --- ...ava => AllLanguageSettingsProvidersMakeCoreTests.java} | 8 ++++---- ...sts.java => AllLanguageSettingsProvidersMBSTests.java} | 8 ++++---- ...ts.java => AllLanguageSettingsProvidersCoreTests.java} | 4 ++-- .../org/eclipse/cdt/core/model/tests/AllCoreTests.java | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) rename build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/{AllSD80Tests.java => AllLanguageSettingsProvidersMakeCoreTests.java} (73%) rename build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/{AllSD80Tests.java => AllLanguageSettingsProvidersMBSTests.java} (77%) rename core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/{AllLanguageSettingsProvidersTests.java => AllLanguageSettingsProvidersCoreTests.java} (89%) diff --git a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/AllSD80Tests.java b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/AllLanguageSettingsProvidersMakeCoreTests.java similarity index 73% rename from build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/AllSD80Tests.java rename to build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/AllLanguageSettingsProvidersMakeCoreTests.java index f4b900a04c7..a681fc24fd4 100644 --- a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/AllSD80Tests.java +++ b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/AllLanguageSettingsProvidersMakeCoreTests.java @@ -12,14 +12,14 @@ package org.eclipse.cdt.make.scannerdiscovery; import junit.framework.TestSuite; -public class AllSD80Tests extends TestSuite { +public class AllLanguageSettingsProvidersMakeCoreTests extends TestSuite { public static TestSuite suite() { - return new AllSD80Tests(); + return new AllLanguageSettingsProvidersMakeCoreTests(); } - public AllSD80Tests() { - super(AllSD80Tests.class.getName()); + public AllLanguageSettingsProvidersMakeCoreTests() { + super(AllLanguageSettingsProvidersMakeCoreTests.class.getName()); addTestSuite(GCCBuildCommandParserTest.class); } diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/AllSD80Tests.java b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/AllLanguageSettingsProvidersMBSTests.java similarity index 77% rename from build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/AllSD80Tests.java rename to build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/AllLanguageSettingsProvidersMBSTests.java index d339b469792..c521b01d261 100644 --- a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/AllSD80Tests.java +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/AllLanguageSettingsProvidersMBSTests.java @@ -15,14 +15,14 @@ import org.eclipse.cdt.build.core.scannerconfig.tests.GCCBuiltinSpecsDetectorTes import junit.framework.TestSuite; -public class AllSD80Tests extends TestSuite { +public class AllLanguageSettingsProvidersMBSTests extends TestSuite { public static TestSuite suite() { - return new AllSD80Tests(); + return new AllLanguageSettingsProvidersMBSTests(); } - public AllSD80Tests() { - super(AllSD80Tests.class.getName()); + public AllLanguageSettingsProvidersMBSTests() { + super(AllLanguageSettingsProvidersMBSTests.class.getName()); addTestSuite(GCCBuiltinSpecsDetectorTest.class); } diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/AllLanguageSettingsProvidersTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/AllLanguageSettingsProvidersCoreTests.java similarity index 89% rename from core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/AllLanguageSettingsProvidersTests.java rename to core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/AllLanguageSettingsProvidersCoreTests.java index 5af3487e58d..15d6813587c 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/AllLanguageSettingsProvidersTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/AllLanguageSettingsProvidersCoreTests.java @@ -14,13 +14,13 @@ import junit.framework.Test; import junit.framework.TestSuite; -public class AllLanguageSettingsProvidersTests { +public class AllLanguageSettingsProvidersCoreTests { public static void main(String[] args) { junit.textui.TestRunner.run(suite()); } public static Test suite() { - TestSuite suite = new TestSuite(AllLanguageSettingsProvidersTests.class.getName()); + TestSuite suite = new TestSuite(AllLanguageSettingsProvidersCoreTests.class.getName()); suite.addTest(LanguageSettingsExtensionsTests.suite()); suite.addTest(LanguageSettingsManagerTests.suite()); diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/AllCoreTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/AllCoreTests.java index 7544599c04b..f9f98edac7a 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/AllCoreTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/AllCoreTests.java @@ -14,7 +14,7 @@ package org.eclipse.cdt.core.model.tests; import junit.framework.Test; import junit.framework.TestSuite; -import org.eclipse.cdt.core.language.settings.providers.AllLanguageSettingsProvidersTests; +import org.eclipse.cdt.core.language.settings.providers.AllLanguageSettingsProvidersCoreTests; import org.eclipse.cdt.core.settings.model.AllCProjectDescriptionTests; import org.eclipse.cdt.core.settings.model.PathSettingsContainerTests; @@ -62,7 +62,7 @@ public class AllCoreTests { suite.addTest(CModelBuilderBugsTest.suite()); suite.addTest(Bug311189.suite()); - suite.addTest(AllLanguageSettingsProvidersTests.suite()); + suite.addTest(AllLanguageSettingsProvidersCoreTests.suite()); return suite; } From 2c1de87ac09150327a528570e8055395269f74cb Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Fri, 28 Oct 2011 14:12:04 -0400 Subject: [PATCH 047/120] Exported language settings providers test suites --- build/org.eclipse.cdt.make.core.tests/META-INF/MANIFEST.MF | 3 ++- .../META-INF/MANIFEST.MF | 3 ++- core/org.eclipse.cdt.core.tests/META-INF/MANIFEST.MF | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/build/org.eclipse.cdt.make.core.tests/META-INF/MANIFEST.MF b/build/org.eclipse.cdt.make.core.tests/META-INF/MANIFEST.MF index 65c44f73d2e..7b7b8f92b67 100644 --- a/build/org.eclipse.cdt.make.core.tests/META-INF/MANIFEST.MF +++ b/build/org.eclipse.cdt.make.core.tests/META-INF/MANIFEST.MF @@ -5,7 +5,8 @@ Bundle-SymbolicName: org.eclipse.cdt.make.core.tests;singleton:=true Bundle-Version: 7.0.0.qualifier Bundle-Activator: org.eclipse.cdt.make.core.tests.MakeTestsPlugin Export-Package: org.eclipse.cdt.make.builder.tests, - org.eclipse.cdt.make.core.tests + org.eclipse.cdt.make.core.tests, + org.eclipse.cdt.make.scannerdiscovery;x-internal:=true Require-Bundle: org.eclipse.core.runtime, org.junit, org.eclipse.cdt.make.core, diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/META-INF/MANIFEST.MF b/build/org.eclipse.cdt.managedbuilder.core.tests/META-INF/MANIFEST.MF index d3fff01f782..00661aa790f 100644 --- a/build/org.eclipse.cdt.managedbuilder.core.tests/META-INF/MANIFEST.MF +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/META-INF/MANIFEST.MF @@ -6,7 +6,8 @@ Bundle-Version: 8.1.0.qualifier Bundle-Activator: org.eclipse.cdt.managedbuilder.testplugin.CTestPlugin Bundle-Vendor: Eclipse CDT Bundle-Localization: plugin -Export-Package: org.eclipse.cdt.managedbuilder.core.tests, +Export-Package: org.eclipse.cdt.build.core.scannerconfig.tests;x-internal:=true, + org.eclipse.cdt.managedbuilder.core.tests, org.eclipse.cdt.managedbuilder.templateengine.tests, org.eclipse.cdt.managedbuilder.testplugin, org.eclipse.cdt.managedbuilder.tests.suite, diff --git a/core/org.eclipse.cdt.core.tests/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.core.tests/META-INF/MANIFEST.MF index fa08a99b27f..ce74fc87eea 100644 --- a/core/org.eclipse.cdt.core.tests/META-INF/MANIFEST.MF +++ b/core/org.eclipse.cdt.core.tests/META-INF/MANIFEST.MF @@ -12,6 +12,7 @@ Export-Package: org.eclipse.cdt.core.cdescriptor.tests, org.eclipse.cdt.core.internal.tests;x-internal:=true, org.eclipse.cdt.core.internal.tests.filesystem.ram, org.eclipse.cdt.core.language, + org.eclipse.cdt.core.language.settings.providers;x-internal:=true, org.eclipse.cdt.core.model.tests, org.eclipse.cdt.core.parser.tests, org.eclipse.cdt.core.parser.tests.ast2, From 66e727728970d23211d819c76303a3c0c55ff6cf Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Fri, 28 Oct 2011 17:02:52 -0400 Subject: [PATCH 048/120] Revised BOP and Specs Detectors interface hierarchy - moved classes to appropriate packages --- build/org.eclipse.cdt.make.core.tests/plugin.xml | 2 +- .../scannerdiscovery/GCCBuildCommandParserTest.java | 2 +- build/org.eclipse.cdt.make.core/plugin.xml | 2 +- .../scannerconfig/AbstractBuiltinSpecsDetector.java | 4 +--- .../core/scannerconfig/GCCBuildCommandParser.java | 5 +++-- build/org.eclipse.cdt.make.ui/plugin.xml | 13 +++++-------- .../BuiltinSpecsDetectorOptionPage.java | 4 ++-- .../tests/GCCBuiltinSpecsDetectorTest.java | 2 +- .../scannerconfig/GCCBuiltinSpecsDetector.java | 3 ++- .../scannerconfig/MBSLanguageSettingsProvider.java | 2 +- build/org.eclipse.cdt.managedbuilder.ui/plugin.xml | 4 ---- .../providers/LanguageSettingsExtensionsTests.java | 1 - .../LanguageSettingsPersistenceProjectTests.java | 1 - .../MockLanguageSettingsEditableProvider.java | 1 - .../settings/providers/MockListenerRegisterer.java | 1 - .../ILanguageSettingsEditableProvider.java | 6 +++--- .../settings/providers/LanguageSettingsManager.java | 1 - .../providers/LanguageSettingsManager_TBD.java | 1 - .../LanguageSettingsSerializableEditable.java | 1 - .../providers/LanguageSettingsExtensionManager.java | 2 +- .../LanguageSettingsProvidersSerializer.java | 2 +- .../providers/LanguageSettingsEntriesTab.java | 2 +- .../providers/LanguageSettingsProviderTab.java | 2 +- .../providers/UserLanguageSettingsProvider.java | 2 +- .../plugin.xml | 2 +- .../xlc/core/XlcBuiltinSpecsDetector.java | 4 ++-- 26 files changed, 29 insertions(+), 43 deletions(-) rename build/{org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal => org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core}/scannerconfig/AbstractBuiltinSpecsDetector.java (98%) rename build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/{ => internal}/core/scannerconfig/GCCBuildCommandParser.java (92%) rename build/{org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/preferences => org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/scannerconfig}/BuiltinSpecsDetectorOptionPage.java (98%) rename core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/{settings/model => language/settings/providers}/ILanguageSettingsEditableProvider.java (86%) diff --git a/build/org.eclipse.cdt.make.core.tests/plugin.xml b/build/org.eclipse.cdt.make.core.tests/plugin.xml index f0a7adef70f..e1239de8486 100644 --- a/build/org.eclipse.cdt.make.core.tests/plugin.xml +++ b/build/org.eclipse.cdt.make.core.tests/plugin.xml @@ -6,7 +6,7 @@ name="org.eclipse.cdt.make.core.tests ErrorParsers" point="org.eclipse.cdt.core.ErrorParser"> diff --git a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java index 8d288d9923b..93e94de98a6 100644 --- a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java +++ b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java @@ -40,8 +40,8 @@ import org.eclipse.cdt.core.testplugin.ResourceHelper; import org.eclipse.cdt.internal.core.XmlUtil; import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager; import org.eclipse.cdt.make.core.scannerconfig.AbstractBuildCommandParser; -import org.eclipse.cdt.make.core.scannerconfig.GCCBuildCommandParser; import org.eclipse.cdt.make.core.scannerconfig.ILanguageSettingsBuildOutputScanner; +import org.eclipse.cdt.make.internal.core.scannerconfig.GCCBuildCommandParser; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; diff --git a/build/org.eclipse.cdt.make.core/plugin.xml b/build/org.eclipse.cdt.make.core/plugin.xml index d9ac29dfc6d..9b0c70400ff 100644 --- a/build/org.eclipse.cdt.make.core/plugin.xml +++ b/build/org.eclipse.cdt.make.core/plugin.xml @@ -185,7 +185,7 @@ diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/AbstractBuiltinSpecsDetector.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java similarity index 98% rename from build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/AbstractBuiltinSpecsDetector.java rename to build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java index 8af3c53f939..cfdf2bc05fe 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/AbstractBuiltinSpecsDetector.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java @@ -9,7 +9,7 @@ * Andrew Gvozdev - initial API and implementation *******************************************************************************/ -package org.eclipse.cdt.managedbuilder.internal.scannerconfig; +package org.eclipse.cdt.make.core.scannerconfig; import java.io.IOException; import java.io.OutputStream; @@ -33,8 +33,6 @@ import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.internal.core.ConsoleOutputSniffer; import org.eclipse.cdt.internal.core.XmlUtil; import org.eclipse.cdt.make.core.MakeCorePlugin; -import org.eclipse.cdt.make.core.scannerconfig.AbstractLanguageSettingsOutputScanner; -import org.eclipse.cdt.make.core.scannerconfig.ILanguageSettingsBuiltinSpecsDetector; import org.eclipse.cdt.make.internal.core.MakeMessages; import org.eclipse.cdt.make.internal.core.StreamMonitor; import org.eclipse.cdt.managedbuilder.core.IInputType; diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/GCCBuildCommandParser.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/GCCBuildCommandParser.java similarity index 92% rename from build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/GCCBuildCommandParser.java rename to build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/GCCBuildCommandParser.java index 1594c0b1898..e9cff69143c 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/GCCBuildCommandParser.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/GCCBuildCommandParser.java @@ -8,12 +8,13 @@ * Contributors: * Andrew Gvozdev - initial API and implementation *******************************************************************************/ -package org.eclipse.cdt.make.core.scannerconfig; +package org.eclipse.cdt.make.internal.core.scannerconfig; import org.eclipse.cdt.core.errorparsers.RegexErrorPattern; +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsEditableProvider; import org.eclipse.cdt.core.settings.model.ICSettingEntry; -import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider; +import org.eclipse.cdt.make.core.scannerconfig.AbstractBuildCommandParser; public class GCCBuildCommandParser extends AbstractBuildCommandParser implements ILanguageSettingsEditableProvider { diff --git a/build/org.eclipse.cdt.make.ui/plugin.xml b/build/org.eclipse.cdt.make.ui/plugin.xml index f4a3166eb0c..3c02054c2da 100644 --- a/build/org.eclipse.cdt.make.ui/plugin.xml +++ b/build/org.eclipse.cdt.make.ui/plugin.xml @@ -542,19 +542,16 @@ - - - - + + diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/preferences/BuiltinSpecsDetectorOptionPage.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/scannerconfig/BuiltinSpecsDetectorOptionPage.java similarity index 98% rename from build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/preferences/BuiltinSpecsDetectorOptionPage.java rename to build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/scannerconfig/BuiltinSpecsDetectorOptionPage.java index 12885afab20..1774569dda3 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/preferences/BuiltinSpecsDetectorOptionPage.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/scannerconfig/BuiltinSpecsDetectorOptionPage.java @@ -9,13 +9,13 @@ * Andrew Gvozdev - Initial API and implementation *******************************************************************************/ -package org.eclipse.cdt.managedbuilder.ui.preferences; +package org.eclipse.cdt.make.internal.ui.scannerconfig; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; import org.eclipse.cdt.internal.ui.language.settings.providers.AbstractLanguageSettingProviderOptionPage; import org.eclipse.cdt.internal.ui.newui.StatusMessageLine; -import org.eclipse.cdt.managedbuilder.internal.scannerconfig.AbstractBuiltinSpecsDetector; +import org.eclipse.cdt.make.core.scannerconfig.AbstractBuiltinSpecsDetector; import org.eclipse.cdt.utils.ui.controls.ControlFactory; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.CoreException; diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/GCCBuiltinSpecsDetectorTest.java b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/GCCBuiltinSpecsDetectorTest.java index 2f7252d7161..f33e8d91bdc 100644 --- a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/GCCBuiltinSpecsDetectorTest.java +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/GCCBuiltinSpecsDetectorTest.java @@ -33,7 +33,7 @@ import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager; import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.core.testplugin.ResourceHelper; import org.eclipse.cdt.internal.core.XmlUtil; -import org.eclipse.cdt.managedbuilder.internal.scannerconfig.AbstractBuiltinSpecsDetector; +import org.eclipse.cdt.make.core.scannerconfig.AbstractBuiltinSpecsDetector; import org.eclipse.cdt.managedbuilder.internal.scannerconfig.GCCBuiltinSpecsDetector; import org.eclipse.cdt.managedbuilder.internal.scannerconfig.GCCBuiltinSpecsDetectorCygwin; import org.eclipse.core.resources.IProject; diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/GCCBuiltinSpecsDetector.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/GCCBuiltinSpecsDetector.java index b080fab86f5..82d2f92570b 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/GCCBuiltinSpecsDetector.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/GCCBuiltinSpecsDetector.java @@ -14,9 +14,10 @@ package org.eclipse.cdt.managedbuilder.internal.scannerconfig; import java.util.ArrayList; import java.util.List; +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsEditableProvider; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICSettingEntry; -import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider; +import org.eclipse.cdt.make.core.scannerconfig.AbstractBuiltinSpecsDetector; import org.eclipse.core.runtime.CoreException; /** diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/MBSLanguageSettingsProvider.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/MBSLanguageSettingsProvider.java index 88515fbaa4e..19b626c8b2f 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/MBSLanguageSettingsProvider.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/MBSLanguageSettingsProvider.java @@ -15,6 +15,7 @@ import java.util.ArrayList; import java.util.List; import org.eclipse.cdt.core.AbstractExecutableExtensionBase; +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsEditableProvider; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICFileDescription; @@ -23,7 +24,6 @@ import org.eclipse.cdt.core.settings.model.ICLanguageSetting; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICResourceDescription; import org.eclipse.cdt.core.settings.model.ICSettingBase; -import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IPath; diff --git a/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml b/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml index 6db04757aef..a94e74e1dc4 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml +++ b/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml @@ -654,10 +654,6 @@ id="org.eclipse.cdt.managedbuilder.core.LanguageSettingsProvider" icon="icons/obj16/mbs.gif"> - - diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java index d7eb6af64de..fcea54ca22f 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java @@ -25,7 +25,6 @@ import org.eclipse.cdt.core.settings.model.CMacroEntry; import org.eclipse.cdt.core.settings.model.CMacroFileEntry; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICSettingEntry; -import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider; import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsExtensionManager; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.ResourcesPlugin; diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java index f08b723b4e6..d35904d7f8c 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java @@ -24,7 +24,6 @@ import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager; -import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider; import org.eclipse.cdt.core.settings.model.WriteAccessException; import org.eclipse.cdt.core.testplugin.CModelMock; import org.eclipse.cdt.core.testplugin.ResourceHelper; diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockLanguageSettingsEditableProvider.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockLanguageSettingsEditableProvider.java index bdb11b3d7e7..7c8c9eaf9dc 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockLanguageSettingsEditableProvider.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockLanguageSettingsEditableProvider.java @@ -12,7 +12,6 @@ package org.eclipse.cdt.core.language.settings.providers; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable; -import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider; public class MockLanguageSettingsEditableProvider extends LanguageSettingsSerializable implements ILanguageSettingsEditableProvider { diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockListenerRegisterer.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockListenerRegisterer.java index 2d4a05c4b21..4afb94905ef 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockListenerRegisterer.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockListenerRegisterer.java @@ -15,7 +15,6 @@ import java.util.ArrayList; import java.util.List; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; -import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider; import org.eclipse.core.runtime.Assert; /** diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ILanguageSettingsEditableProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsEditableProvider.java similarity index 86% rename from core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ILanguageSettingsEditableProvider.java rename to core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsEditableProvider.java index 7b15e893d76..83052f276d9 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ILanguageSettingsEditableProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsEditableProvider.java @@ -9,12 +9,12 @@ * Andrew Gvozdev (Quoin Inc.) - initial API and implementation *******************************************************************************/ -package org.eclipse.cdt.core.settings.model; +package org.eclipse.cdt.core.language.settings.providers; import java.util.List; -import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; -import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.core.resources.IResource; /** diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java index b7e8b2ea666..fd630a320d6 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java @@ -24,7 +24,6 @@ import org.eclipse.cdt.core.settings.model.ICLanguageSetting; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICResourceDescription; import org.eclipse.cdt.core.settings.model.ICSettingEntry; -import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider; import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsExtensionManager; import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer; import org.eclipse.core.resources.IFile; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager_TBD.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager_TBD.java index efb8bdd8958..b3ba4037be2 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager_TBD.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager_TBD.java @@ -16,7 +16,6 @@ import java.util.List; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; -import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider; 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; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableEditable.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableEditable.java index 1a0fe61a846..5454e7ea697 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableEditable.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableEditable.java @@ -12,7 +12,6 @@ package org.eclipse.cdt.core.language.settings.providers; // TODO: move ILanguageSettingsEditableProvider here -import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider; public class LanguageSettingsSerializableEditable extends LanguageSettingsSerializable implements ILanguageSettingsEditableProvider { @Override diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java index 53d271faa61..900c062954e 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java @@ -22,6 +22,7 @@ import java.util.TreeSet; import org.eclipse.cdt.core.AbstractExecutableExtensionBase; import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsEditableProvider; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsBaseProvider; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable; @@ -30,7 +31,6 @@ import org.eclipse.cdt.core.model.LanguageManager; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICSettingEntry; -import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider; import org.eclipse.cdt.core.settings.model.util.CDataUtil; import org.eclipse.cdt.core.settings.model.util.LanguageSettingEntriesSerializer; import org.eclipse.core.resources.IContainer; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java index 0ef6a684080..0da61e95916 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java @@ -20,6 +20,7 @@ import java.util.Map; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.language.settings.providers.ICListenerRegisterer; +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsEditableProvider; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable; @@ -27,7 +28,6 @@ import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySu import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICProjectDescription; -import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider; import org.eclipse.cdt.internal.core.XmlUtil; import org.eclipse.core.filesystem.URIUtil; import org.eclipse.core.resources.IFile; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java index d89e8d1165b..068efb454a7 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java @@ -43,6 +43,7 @@ import org.eclipse.swt.widgets.Tree; import org.eclipse.swt.widgets.TreeColumn; import org.eclipse.swt.widgets.TreeItem; +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsEditableProvider; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsBaseProvider; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; @@ -55,7 +56,6 @@ import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICResourceDescription; import org.eclipse.cdt.core.settings.model.ICSettingEntry; -import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider; import org.eclipse.cdt.ui.CDTSharedImages; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.newui.AbstractCPropertyTab; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java index 85ea81ead9d..9289eb47e25 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java @@ -45,6 +45,7 @@ import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Table; import org.eclipse.ui.dialogs.PreferencesUtil; +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsEditableProvider; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager_TBD; @@ -58,7 +59,6 @@ import org.eclipse.cdt.core.settings.model.ICFolderDescription; import org.eclipse.cdt.core.settings.model.ICLanguageSetting; import org.eclipse.cdt.core.settings.model.ICResourceDescription; import org.eclipse.cdt.core.settings.model.ICSettingBase; -import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider; import org.eclipse.cdt.ui.CDTSharedImages; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.dialogs.ICOptionPage; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/UserLanguageSettingsProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/UserLanguageSettingsProvider.java index 2dee6cb8000..68fc50e431e 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/UserLanguageSettingsProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/UserLanguageSettingsProvider.java @@ -11,8 +11,8 @@ package org.eclipse.cdt.internal.ui.language.settings.providers; +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsEditableProvider; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable; -import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider; /** * Provider to support user interface for language settings. The important difference with diff --git a/xlc/org.eclipse.cdt.managedbuilder.xlc.core/plugin.xml b/xlc/org.eclipse.cdt.managedbuilder.xlc.core/plugin.xml index bebad46f5a3..efdbfcbd13c 100644 --- a/xlc/org.eclipse.cdt.managedbuilder.xlc.core/plugin.xml +++ b/xlc/org.eclipse.cdt.managedbuilder.xlc.core/plugin.xml @@ -87,7 +87,7 @@ diff --git a/xlc/org.eclipse.cdt.managedbuilder.xlc.core/src/org/eclipse/cdt/managedbuilder/xlc/core/XlcBuiltinSpecsDetector.java b/xlc/org.eclipse.cdt.managedbuilder.xlc.core/src/org/eclipse/cdt/managedbuilder/xlc/core/XlcBuiltinSpecsDetector.java index 056ca8305dd..5e1075551cc 100644 --- a/xlc/org.eclipse.cdt.managedbuilder.xlc.core/src/org/eclipse/cdt/managedbuilder/xlc/core/XlcBuiltinSpecsDetector.java +++ b/xlc/org.eclipse.cdt.managedbuilder.xlc.core/src/org/eclipse/cdt/managedbuilder/xlc/core/XlcBuiltinSpecsDetector.java @@ -16,9 +16,9 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsEditableProvider; import org.eclipse.cdt.core.settings.model.ICSettingEntry; -import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider; -import org.eclipse.cdt.managedbuilder.internal.scannerconfig.AbstractBuiltinSpecsDetector; +import org.eclipse.cdt.make.core.scannerconfig.AbstractBuiltinSpecsDetector; /** From 3f9cdb6fb8ec3f22c8dede591758486fee676653 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Fri, 28 Oct 2011 17:47:56 -0400 Subject: [PATCH 049/120] Revised BOP and Specs Detectors interface hierarchy - replaced interfaces with abstract classes --- .../GCCBuildCommandParserTest.java | 3 +- .../AbstractBuildCommandParser.java | 12 +++++-- .../AbstractBuiltinSpecsDetector.java | 2 +- ...AbstractLanguageSettingsOutputScanner.java | 3 +- .../ILanguageSettingsBuildOutputScanner.java | 29 --------------- ...ILanguageSettingsBuiltinSpecsDetector.java | 28 --------------- .../ILanguageSettingsOutputScanner.java | 35 ------------------- .../core/ExternalBuildRunner.java | 3 +- .../core/InternalBuildRunner.java | 4 +-- .../core/ManagedBuildManager.java | 1 - 10 files changed, 16 insertions(+), 104 deletions(-) delete mode 100644 build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/ILanguageSettingsBuildOutputScanner.java delete mode 100644 build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/ILanguageSettingsBuiltinSpecsDetector.java delete mode 100644 build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/ILanguageSettingsOutputScanner.java diff --git a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java index 93e94de98a6..1ca9c583c01 100644 --- a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java +++ b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java @@ -40,7 +40,6 @@ import org.eclipse.cdt.core.testplugin.ResourceHelper; import org.eclipse.cdt.internal.core.XmlUtil; import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager; import org.eclipse.cdt.make.core.scannerconfig.AbstractBuildCommandParser; -import org.eclipse.cdt.make.core.scannerconfig.ILanguageSettingsBuildOutputScanner; import org.eclipse.cdt.make.internal.core.scannerconfig.GCCBuildCommandParser; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; @@ -255,7 +254,7 @@ public class GCCBuildCommandParserTest extends TestCase { final IFile file=ResourceHelper.createFile(project, "file.cpp"); // create test class - ILanguageSettingsBuildOutputScanner parser = new MockBuildCommandParser() { + AbstractBuildCommandParser parser = new MockBuildCommandParser() { @Override public boolean processLine(String line, ErrorParserManager epm) { // pretending that we parsed the line diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java index 28fa853138d..56b32c4cb62 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java @@ -17,14 +17,22 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import org.eclipse.cdt.core.ErrorParserManager; +import org.eclipse.cdt.core.ICConsoleParser; +import org.eclipse.cdt.core.IErrorParser; import org.eclipse.cdt.core.IErrorParser2; import org.eclipse.cdt.core.IMarkerGenerator; import org.eclipse.cdt.core.errorparsers.RegexErrorParser; import org.eclipse.cdt.core.errorparsers.RegexErrorPattern; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; -public abstract class AbstractBuildCommandParser extends AbstractLanguageSettingsOutputScanner implements - ILanguageSettingsBuildOutputScanner { +/** + * TODO - class description + * + * Note: IErrorParser interface is used here to work around {@link ConsoleOutputSniffer} having + * no access from CDT core to build packages. TODO - elaborate? + */ +public abstract class AbstractBuildCommandParser extends AbstractLanguageSettingsOutputScanner + implements ICConsoleParser, IErrorParser { private static final String LEADING_PATH_PATTERN = "\\S+[/\\\\]"; //$NON-NLS-1$ private static final Pattern OPTIONS_PATTERN = Pattern.compile("-[^\\s\"']*(\\s*((\".*?\")|('.*?')|([^-\\s][^\\s]+)))?"); //$NON-NLS-1$ diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java index cfdf2bc05fe..85f963f849e 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java @@ -60,7 +60,7 @@ import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.core.runtime.jobs.Job; import org.w3c.dom.Element; -public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSettingsOutputScanner implements ILanguageSettingsBuiltinSpecsDetector { +public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSettingsOutputScanner { private static final String NEWLINE = System.getProperty("line.separator", "\n"); //$NON-NLS-1$ //$NON-NLS-2$ private static final String PLUGIN_CDT_MAKE_UI_ID = "org.eclipse.cdt.make.ui"; //$NON-NLS-1$ private static final String GMAKE_ERROR_PARSER_ID = "org.eclipse.cdt.core.GmakeErrorParser"; //$NON-NLS-1$ diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java index db838a754f4..33d897402a2 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java @@ -55,8 +55,7 @@ import org.eclipse.core.runtime.content.IContentType; import org.eclipse.core.runtime.content.IContentTypeManager; import org.w3c.dom.Element; -public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSettingsSerializable implements - ILanguageSettingsOutputScanner { +public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSettingsSerializable { protected static final String ATTR_EXPAND_RELATIVE_PATHS = "expand-relative-paths"; //$NON-NLS-1$ diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/ILanguageSettingsBuildOutputScanner.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/ILanguageSettingsBuildOutputScanner.java deleted file mode 100644 index 51615891c53..00000000000 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/ILanguageSettingsBuildOutputScanner.java +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011, 2011 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.make.core.scannerconfig; - -import org.eclipse.cdt.core.ErrorParserManager; -import org.eclipse.cdt.core.IErrorParser; -import org.eclipse.cdt.internal.core.ConsoleOutputSniffer; - -/** - * Note: IErrorParser interface is used here to work around {@link ConsoleOutputSniffer} having - * no access from CDT core to build packages. - */ -public interface ILanguageSettingsBuildOutputScanner extends ILanguageSettingsOutputScanner, IErrorParser { - - /** - * This method is expected to populate this.settingEntries with specific values - * parsed from supplied lines. - */ - public boolean processLine(String line, ErrorParserManager epm); -} diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/ILanguageSettingsBuiltinSpecsDetector.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/ILanguageSettingsBuiltinSpecsDetector.java deleted file mode 100644 index e094fb18dc6..00000000000 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/ILanguageSettingsBuiltinSpecsDetector.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011, 2011 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.make.core.scannerconfig; - -import java.io.IOException; -import java.util.List; - -import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; -import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; - -public interface ILanguageSettingsBuiltinSpecsDetector extends ILanguageSettingsProvider { - public List getLanguageScope(); - public void run(IProject project, String languageId, IPath workingDirectory, String[] env, IProgressMonitor monitor) throws CoreException, IOException; - public void run(ICConfigurationDescription cfgDescription, String languageId, IPath workingDirectory, String[] env, IProgressMonitor monitor) throws CoreException, IOException; -} diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/ILanguageSettingsOutputScanner.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/ILanguageSettingsOutputScanner.java deleted file mode 100644 index 642322f2d36..00000000000 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/ILanguageSettingsOutputScanner.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2009 Andrew Gvozdev (Quoin Inc.) 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 (Quoin Inc.) - initial API and implementation - *******************************************************************************/ - -package org.eclipse.cdt.make.core.scannerconfig; - -import java.util.List; - -import org.eclipse.cdt.core.ICConsoleParser; -import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; -import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; -import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; - -/** - * TODO: Is this interface superfluous? - */ -public interface ILanguageSettingsOutputScanner extends ILanguageSettingsProvider, ICConsoleParser { - - // Inherited from ICConsoleParser - public void startup(ICConfigurationDescription cfgDescription) throws CoreException; - public boolean processLine(String line); - public void shutdown(); - - // Inherited from ICLanguageSettingsProvider - public List getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId); -} diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ExternalBuildRunner.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ExternalBuildRunner.java index 3ceff84cc8b..fbb9244be9e 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ExternalBuildRunner.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ExternalBuildRunner.java @@ -42,7 +42,6 @@ import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.internal.core.ConsoleOutputSniffer; import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer; -import org.eclipse.cdt.make.core.scannerconfig.ILanguageSettingsBuiltinSpecsDetector; import org.eclipse.cdt.make.core.scannerconfig.IScannerConfigBuilderInfo2; import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector; import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoConsoleParser; @@ -409,7 +408,7 @@ public class ExternalBuildRunner extends AbstractBuildRunner { List lsProviders = cfgDescription.getLanguageSettingProviders(); for (ILanguageSettingsProvider lsProvider : lsProviders) { ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(lsProvider); - if (rawProvider instanceof ICConsoleParser && !(rawProvider instanceof ILanguageSettingsBuiltinSpecsDetector)) { + if (rawProvider instanceof ICConsoleParser) { ICConsoleParser consoleParser = (ICConsoleParser) rawProvider; try { consoleParser.startup(cfgDescription); diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/InternalBuildRunner.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/InternalBuildRunner.java index 933d9750483..5e179f38444 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/InternalBuildRunner.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/InternalBuildRunner.java @@ -29,7 +29,7 @@ import org.eclipse.cdt.core.resources.IConsole; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer; -import org.eclipse.cdt.make.core.scannerconfig.ILanguageSettingsBuildOutputScanner; +import org.eclipse.cdt.make.core.scannerconfig.AbstractBuildCommandParser; import org.eclipse.cdt.managedbuilder.buildmodel.BuildDescriptionManager; import org.eclipse.cdt.managedbuilder.buildmodel.IBuildDescription; import org.eclipse.cdt.managedbuilder.internal.buildmodel.BuildDescription; @@ -164,7 +164,7 @@ public class InternalBuildRunner extends AbstractBuildRunner { List providers = cfgDescription.getLanguageSettingProviders(); for (ILanguageSettingsProvider provider : providers) { - if (provider instanceof ILanguageSettingsBuildOutputScanner) { + if (provider instanceof AbstractBuildCommandParser) { buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$ String msg = ManagedMakeMessages.getFormattedString("BOP Language Settings Provider [{0}] is not supported by Internal Builder.", provider.getName()); buf.append("**** "+msg+" ****"); diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java index 95fdcd6bfd2..6e833544aa8 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java @@ -67,7 +67,6 @@ import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.core.settings.model.XmlStorageUtil; import org.eclipse.cdt.core.settings.model.extension.CConfigurationData; import org.eclipse.cdt.make.core.MakeCorePlugin; -import org.eclipse.cdt.make.core.scannerconfig.ILanguageSettingsBuiltinSpecsDetector; import org.eclipse.cdt.managedbuilder.buildproperties.IBuildProperty; import org.eclipse.cdt.managedbuilder.buildproperties.IBuildPropertyManager; import org.eclipse.cdt.managedbuilder.envvar.IEnvironmentBuildPathsChangeListener; From 5d7f9bf0157cc03848276b92bdbbcbb5b2ef3a11 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Fri, 28 Oct 2011 23:17:52 -0400 Subject: [PATCH 050/120] AbstractBuiltinSpecsDetector as IResourceChangeListener --- ...anguageSettingsProvidersMakeCoreTests.java | 1 + .../BuiltinSpecsDetectorTest.java | 419 ++++++++++ .../AbstractBuildCommandParser.java | 63 ++ .../AbstractBuiltinSpecsDetector.java | 583 +++++++++----- ...AbstractLanguageSettingsOutputScanner.java | 22 +- .../scannerconfig/GCCBuildCommandParser.java | 5 +- .../GCCBuildCommandParserOptionPage.java | 147 ---- .../BuiltinSpecsDetectorOptionPage.java | 66 +- .../tests/GCCBuiltinSpecsDetectorTest.java | 718 +++++------------- .../core/ExternalBuildRunner.java | 21 +- .../core/InternalBuildRunner.java | 9 +- .../core/ManagedBuildManager.java | 52 -- .../GCCBuiltinSpecsDetector.java | 10 +- .../ToolchainBuiltinSpecsDetector.java | 81 ++ .../LanguageSettingsSerializable.java | 22 +- .../internal/core/ConsoleOutputSniffer.java | 11 +- .../xlc/core/XlcBuiltinSpecsDetector.java | 4 +- 17 files changed, 1185 insertions(+), 1049 deletions(-) create mode 100644 build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/BuiltinSpecsDetectorTest.java create mode 100644 build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/scannerconfig/ToolchainBuiltinSpecsDetector.java diff --git a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/AllLanguageSettingsProvidersMakeCoreTests.java b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/AllLanguageSettingsProvidersMakeCoreTests.java index a681fc24fd4..511adb8428f 100644 --- a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/AllLanguageSettingsProvidersMakeCoreTests.java +++ b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/AllLanguageSettingsProvidersMakeCoreTests.java @@ -22,5 +22,6 @@ public class AllLanguageSettingsProvidersMakeCoreTests extends TestSuite { super(AllLanguageSettingsProvidersMakeCoreTests.class.getName()); addTestSuite(GCCBuildCommandParserTest.class); + addTestSuite(BuiltinSpecsDetectorTest.class); } } diff --git a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/BuiltinSpecsDetectorTest.java b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/BuiltinSpecsDetectorTest.java new file mode 100644 index 00000000000..a33e47724a3 --- /dev/null +++ b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/BuiltinSpecsDetectorTest.java @@ -0,0 +1,419 @@ +/******************************************************************************* + * Copyright (c) 2010, 2011 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.make.scannerdiscovery; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.List; + +import junit.framework.TestCase; + +import org.eclipse.cdt.core.ErrorParserManager; +import org.eclipse.cdt.core.model.CoreModel; +import org.eclipse.cdt.core.settings.model.CIncludeFileEntry; +import org.eclipse.cdt.core.settings.model.CIncludePathEntry; +import org.eclipse.cdt.core.settings.model.CLibraryFileEntry; +import org.eclipse.cdt.core.settings.model.CLibraryPathEntry; +import org.eclipse.cdt.core.settings.model.CMacroEntry; +import org.eclipse.cdt.core.settings.model.CMacroFileEntry; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; +import org.eclipse.cdt.core.settings.model.ICProjectDescription; +import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager; +import org.eclipse.cdt.core.settings.model.ICSettingEntry; +import org.eclipse.cdt.core.testplugin.ResourceHelper; +import org.eclipse.cdt.internal.core.XmlUtil; +import org.eclipse.cdt.make.core.scannerconfig.AbstractBuiltinSpecsDetector; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +public class BuiltinSpecsDetectorTest extends TestCase { + private static final String PROVIDER_ID = "provider.id"; + private static final String PROVIDER_NAME = "provider name"; + private static final String LANGUAGE_ID = "language.test.id"; + private static final String CUSTOM_PARAMETER = "customParameter"; + private static final String ELEM_TEST = "test"; + + // those attributes must match that in AbstractBuiltinSpecsDetector + private static final String ATTR_CONSOLE = "console"; //$NON-NLS-1$ + + private class MockBuiltinSpecsDetector extends AbstractBuiltinSpecsDetector { + @Override + protected void startupForLanguage(String languageId) throws CoreException { + super.startupForLanguage(languageId); + } + @Override + protected void shutdownForLanguage() { + super.shutdownForLanguage(); + } + @Override + protected List parseForOptions(String line) { + return null; + } + @Override + protected AbstractOptionParser[] getOptionParsers() { + return null; + } + } + + private class MockBuiltinSpecsDetectorExecutedFlag extends AbstractBuiltinSpecsDetector { + @Override + protected List parseForOptions(String line) { + return null; + } + @Override + protected AbstractOptionParser[] getOptionParsers() { + return null; + } + @Override + protected void execute() { + super.execute(); + } + protected boolean isExecuted() { + return isExecuted; + } + } + + private class MockConsoleBuiltinSpecsDetector extends AbstractBuiltinSpecsDetector { + @SuppressWarnings("nls") + private final AbstractOptionParser[] optionParsers = { + new MacroOptionParser("#define (\\S*) *(\\S*)", "$1", "$2", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), + }; + @Override + protected boolean runProgram(String command, String[] env, IPath workingDirectory, IProgressMonitor monitor, + OutputStream consoleOut, OutputStream consoleErr) throws CoreException, IOException { + printLine(consoleOut, "#define MACRO VALUE"); + consoleOut.close(); + consoleErr.close(); + return true; + } + @Override + protected IStatus runForEachLanguage(ICConfigurationDescription cfgDescription, IPath workingDirectory, + String[] env, IProgressMonitor monitor) { + return super.runForEachLanguage(cfgDescription, workingDirectory, env, monitor); + } + @Override + protected List parseForOptions(final String line) { + return new ArrayList() {{ add(line); }}; + } + @Override + protected AbstractOptionParser[] getOptionParsers() { + return optionParsers; + } + } + + @Override + protected void setUp() throws Exception { + } + + @Override + protected void tearDown() throws Exception { + ResourceHelper.cleanUp(); + } + + private ICConfigurationDescription[] getConfigurationDescriptions(IProject project) { + CoreModel coreModel = CoreModel.getDefault(); + ICProjectDescriptionManager mngr = coreModel.getProjectDescriptionManager(); + // project description + ICProjectDescription projectDescription = mngr.getProjectDescription(project); + assertNotNull(projectDescription); + assertEquals(1, projectDescription.getConfigurations().length); + // configuration description + ICConfigurationDescription[] cfgDescriptions = projectDescription.getConfigurations(); + return cfgDescriptions; + } + + public void testAbstractBuiltinSpecsDetector_GettersSetters() throws Exception { + // define mock detector + MockBuiltinSpecsDetectorExecutedFlag detector = new MockBuiltinSpecsDetectorExecutedFlag(); + + detector.configureProvider(PROVIDER_ID, PROVIDER_NAME, null, null, null); + assertEquals(PROVIDER_ID, detector.getId()); + assertEquals(PROVIDER_NAME, detector.getName()); + assertEquals(null, detector.getLanguageScope()); + assertEquals(null, detector.getSettingEntries(null, null, null)); + assertEquals(null, detector.getCustomParameter()); + assertEquals(false, detector.isExecuted()); + + List languages = new ArrayList(); + languages.add(LANGUAGE_ID); + List entries = new ArrayList(); + ICLanguageSettingEntry entry = new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); + entries.add(entry); + + detector.configureProvider(PROVIDER_ID, PROVIDER_NAME, languages, entries, CUSTOM_PARAMETER); + assertEquals(PROVIDER_ID, detector.getId()); + assertEquals(PROVIDER_NAME, detector.getName()); + assertEquals(languages, detector.getLanguageScope()); + assertEquals(entries, detector.getSettingEntries(null, null, null)); + assertEquals(CUSTOM_PARAMETER, detector.getCustomParameter()); + assertEquals(false, detector.isExecuted()); + + detector.execute(); + assertEquals(true, detector.isExecuted()); + } + + public void testAbstractBuiltinSpecsDetector_CloneAndEquals() throws Exception { + // define mock detector + class MockDetectorCloneable extends MockBuiltinSpecsDetectorExecutedFlag implements Cloneable { + @Override + public MockDetectorCloneable clone() throws CloneNotSupportedException { + return (MockDetectorCloneable) super.clone(); + } + @Override + public MockDetectorCloneable cloneShallow() throws CloneNotSupportedException { + return (MockDetectorCloneable) super.cloneShallow(); + } + } + + // create instance to compare to + MockDetectorCloneable detector = new MockDetectorCloneable(); + + List languages = new ArrayList(); + languages.add(LANGUAGE_ID); + List entries = new ArrayList(); + ICLanguageSettingEntry entry = new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); + entries.add(entry); + + // check clone after initialization + MockDetectorCloneable clone0 = detector.clone(); + assertTrue(detector.equals(clone0)); + + // configure provider + detector.configureProvider(PROVIDER_ID, PROVIDER_NAME, languages, entries, CUSTOM_PARAMETER); + assertEquals(false, detector.isConsoleEnabled()); + detector.setConsoleEnabled(true); + detector.execute(); + assertEquals(true, detector.isExecuted()); + assertFalse(detector.equals(clone0)); + + // check another clone after configuring + { + MockDetectorCloneable clone = detector.clone(); + assertTrue(detector.equals(clone)); + } + + // check custom parameter + { + MockDetectorCloneable clone = detector.clone(); + clone.setCustomParameter("changed"); + assertFalse(detector.equals(clone)); + } + + // check language scope + { + MockDetectorCloneable clone = detector.clone(); + clone.setLanguageScope(null); + assertFalse(detector.equals(clone)); + } + + // check console flag + { + MockDetectorCloneable clone = detector.clone(); + boolean isConsoleEnabled = clone.isConsoleEnabled(); + clone.setConsoleEnabled( ! isConsoleEnabled ); + assertFalse(detector.equals(clone)); + } + + // check isExecuted flag + { + MockDetectorCloneable clone = detector.clone(); + assertEquals(true, clone.isExecuted()); + clone.clear(); + assertEquals(false, clone.isExecuted()); + assertFalse(detector.equals(clone)); + } + + // check entries + { + MockDetectorCloneable clone = detector.clone(); + clone.setSettingEntries(null, null, null, null); + assertFalse(detector.equals(clone)); + } + + // check cloneShallow() + { + MockDetectorCloneable detector2 = detector.clone(); + MockDetectorCloneable clone = detector2.cloneShallow(); + assertEquals(false, clone.isExecuted()); + assertFalse(detector2.equals(clone)); + + detector2.setSettingEntries(null, null, null, null); + assertFalse(detector2.equals(clone)); + + clone.execute(); + assertTrue(detector2.equals(clone)); + } + } + + /** + */ + public void testAbstractBuiltinSpecsDetector_Serialize() throws Exception { + { + // create empty XML + Document doc = XmlUtil.newDocument(); + Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST); + + // load it to new provider + MockBuiltinSpecsDetectorExecutedFlag detector = new MockBuiltinSpecsDetectorExecutedFlag(); + detector.load(rootElement); + assertEquals(false, detector.isConsoleEnabled()); + } + + Element elementProvider; + { + // define mock detector + MockBuiltinSpecsDetectorExecutedFlag detector = new MockBuiltinSpecsDetectorExecutedFlag(); + assertEquals(false, detector.isConsoleEnabled()); + + // redefine the settings + detector.setConsoleEnabled(true); + assertEquals(true, detector.isConsoleEnabled()); + + // serialize in XML + Document doc = XmlUtil.newDocument(); + Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST); + elementProvider = detector.serialize(rootElement); + String xmlString = XmlUtil.toString(doc); + + assertTrue(xmlString.contains(ATTR_CONSOLE)); + } + { + // create another instance of the provider + MockBuiltinSpecsDetectorExecutedFlag detector = new MockBuiltinSpecsDetectorExecutedFlag(); + assertEquals(false, detector.isConsoleEnabled()); + + // load element + detector.load(elementProvider); + assertEquals(true, detector.isConsoleEnabled()); + } + } + + public void testAbstractBuiltinSpecsDetector_Nulls() throws Exception { + { + // test AbstractBuiltinSpecsDetector.processLine(...) flow + MockBuiltinSpecsDetector detector = new MockBuiltinSpecsDetector(); + detector.startup(null); + detector.startupForLanguage(null); + detector.processLine(null, null); + detector.shutdownForLanguage(); + detector.shutdown(); + } + { + // test AbstractBuiltinSpecsDetector.processLine(...) flow + MockConsoleBuiltinSpecsDetector detector = new MockConsoleBuiltinSpecsDetector(); + detector.runForEachLanguage(null, null, null, null); + } + } + + public void testAbstractBuiltinSpecsDetector_RunConfiguration() throws Exception { + // Create model project and accompanied descriptions + String projectName = getName(); + IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + MockConsoleBuiltinSpecsDetector detector = new MockConsoleBuiltinSpecsDetector(); + detector.setLanguageScope(new ArrayList() {{add(LANGUAGE_ID);}}); + + detector.runForEachLanguage(cfgDescription, null, null, null); + assertFalse(detector.isEmpty()); + + List noentries = detector.getSettingEntries(null, null, null); + assertNull(noentries); + + List entries = detector.getSettingEntries(cfgDescription, null, LANGUAGE_ID); + ICLanguageSettingEntry expected = new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); + assertEquals(expected, entries.get(0)); + } + + public void testAbstractBuiltinSpecsDetector_RunGlobal() throws Exception { + MockConsoleBuiltinSpecsDetector detector = new MockConsoleBuiltinSpecsDetector(); + detector.setLanguageScope(new ArrayList() {{add(LANGUAGE_ID);}}); + + detector.runForEachLanguage(null, null, null, null); + assertFalse(detector.isEmpty()); + + List entries = detector.getSettingEntries(null, null, LANGUAGE_ID); + ICLanguageSettingEntry expected = new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); + assertEquals(expected, entries.get(0)); + } + + public void testAbstractBuiltinSpecsDetector_GroupSettings() throws Exception { + // define benchmarks + final CIncludePathEntry includePath_1 = new CIncludePathEntry("/include/path_1", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); + final CIncludePathEntry includePath_2 = new CIncludePathEntry("/include/path_2", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); + final CIncludeFileEntry includeFile_1 = new CIncludeFileEntry(new Path("/include.file1"), ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); + final CIncludeFileEntry includeFile_2 = new CIncludeFileEntry(new Path("/include.file2"), ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); + final CMacroEntry macro_1 = new CMacroEntry("MACRO_1", "", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); + final CMacroEntry macro_2 = new CMacroEntry("MACRO_2", "", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY |ICSettingEntry.UNDEFINED); + final CMacroFileEntry macroFile_1 = new CMacroFileEntry(new Path("/macro.file1"), ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); + final CMacroFileEntry macroFile_2 = new CMacroFileEntry(new Path("/macro.file2"), ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); + final CLibraryPathEntry libraryPath_1 = new CLibraryPathEntry(new Path("/lib/path_1"), ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); + final CLibraryPathEntry libraryPath_2 = new CLibraryPathEntry(new Path("/lib/path_2"), ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); + final CLibraryFileEntry libraryFile_1 = new CLibraryFileEntry("lib_1.a", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); + final CLibraryFileEntry libraryFile_2 = new CLibraryFileEntry("lib_2.a", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); + + // Define mock detector adding unorganized entries + MockBuiltinSpecsDetector detector = new MockBuiltinSpecsDetector() { + @Override + public boolean processLine(String line, ErrorParserManager epm) { + detectedSettingEntries.add(libraryFile_1); + detectedSettingEntries.add(libraryPath_1); + detectedSettingEntries.add(macroFile_1); + detectedSettingEntries.add(macro_1); + detectedSettingEntries.add(includeFile_1); + detectedSettingEntries.add(includePath_1); + + detectedSettingEntries.add(includePath_2); + detectedSettingEntries.add(includeFile_2); + detectedSettingEntries.add(macro_2); + detectedSettingEntries.add(macroFile_2); + detectedSettingEntries.add(libraryPath_2); + detectedSettingEntries.add(libraryFile_2); + return true; + } + }; + + // run specs detector + detector.startup(null); + detector.startupForLanguage(null); + detector.processLine("", null); + detector.shutdownForLanguage(); + detector.shutdown(); + + // compare benchmarks, expected well-sorted + List entries = detector.getSettingEntries(null, null, null); + + int i=0; + assertEquals(includePath_1, entries.get(i++)); + assertEquals(includePath_2, entries.get(i++)); + assertEquals(includeFile_1, entries.get(i++)); + assertEquals(includeFile_2, entries.get(i++)); + assertEquals(macro_1, entries.get(i++)); + assertEquals(macro_2, entries.get(i++)); + assertEquals(macroFile_1, entries.get(i++)); + assertEquals(macroFile_2, entries.get(i++)); + assertEquals(libraryPath_1, entries.get(i++)); + assertEquals(libraryPath_2, entries.get(i++)); + assertEquals(libraryFile_1, entries.get(i++)); + assertEquals(libraryFile_2, entries.get(i++)); + + assertEquals(12, entries.size()); + } +} diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java index 56b32c4cb62..6b7f21f3682 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java @@ -24,6 +24,18 @@ import org.eclipse.cdt.core.IMarkerGenerator; import org.eclipse.cdt.core.errorparsers.RegexErrorParser; import org.eclipse.cdt.core.errorparsers.RegexErrorPattern; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; +import org.eclipse.cdt.internal.core.ConsoleOutputSniffer; +import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer; +import org.eclipse.cdt.make.core.MakeCorePlugin; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.ISchedulingRule; +import org.eclipse.core.runtime.jobs.Job; /** * TODO - class description @@ -103,12 +115,63 @@ public abstract class AbstractBuildCommandParser extends AbstractLanguageSetting return options; } + public boolean processLine(String line) { + return processLine(line, null); + } + // This is redundant but let us keep it here to navigate in java code easier @Override public boolean processLine(String line, ErrorParserManager epm) { return super.processLine(line, epm); } + @Override + public void shutdown() { + scheduleSerializingJob(currentCfgDescription); + super.shutdown(); + } + + + private void scheduleSerializingJob(final ICConfigurationDescription cfgDescription) { + Job job = new Job("Serialize CDT language settings entries") { + @Override + protected IStatus run(IProgressMonitor monitor) { + // FIXME - remove thread name reassigning + Thread thread = getThread(); + String oldName = thread.getName(); + thread.setName("CDT LSP Serializer,BOP"); + + IStatus status = null; + try { + if (cfgDescription != null) { + LanguageSettingsProvidersSerializer.serializeLanguageSettings(cfgDescription.getProjectDescription()); + } else { + LanguageSettingsProvidersSerializer.serializeLanguageSettingsWorkspace(); + } + } catch (CoreException e) { + status = new Status(IStatus.ERROR, MakeCorePlugin.PLUGIN_ID, IStatus.ERROR, "Error serializing language settings", e); + MakeCorePlugin.log(status); + } + + if (status == null) + status = Status.OK_STATUS; + + thread.setName(oldName); + return status; + } + }; + + ISchedulingRule rule = null; + if (currentProject != null) { + rule = currentProject.getFile(".settings/language.settings.xml"); + } + if (rule == null) { + rule = ResourcesPlugin.getWorkspace().getRoot(); + } + job.setRule(rule); + job.schedule(); + } + /** * Trivial Error Parser which allows highlighting of output lines matching the patterns * of this parser. Intended for better troubleshooting experience. diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java index 85f963f849e..96b3f81536c 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java @@ -21,63 +21,79 @@ import java.util.List; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CommandLauncher; import org.eclipse.cdt.core.ErrorParserManager; +import org.eclipse.cdt.core.ICConsoleParser; import org.eclipse.cdt.core.ICommandLauncher; import org.eclipse.cdt.core.IConsoleParser; import org.eclipse.cdt.core.IMarkerGenerator; import org.eclipse.cdt.core.ProblemMarkerInfo; +import org.eclipse.cdt.core.index.IIndexManager; +import org.eclipse.cdt.core.language.settings.providers.ICListenerRegisterer; +import org.eclipse.cdt.core.model.CoreModel; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ILanguage; +import org.eclipse.cdt.core.model.ILanguageDescriptor; import org.eclipse.cdt.core.model.LanguageManager; import org.eclipse.cdt.core.resources.IConsole; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; +import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.internal.core.ConsoleOutputSniffer; import org.eclipse.cdt.internal.core.XmlUtil; +import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer; import org.eclipse.cdt.make.core.MakeCorePlugin; import org.eclipse.cdt.make.internal.core.MakeMessages; import org.eclipse.cdt.make.internal.core.StreamMonitor; -import org.eclipse.cdt.managedbuilder.core.IInputType; -import org.eclipse.cdt.managedbuilder.core.ITool; -import org.eclipse.cdt.managedbuilder.core.IToolChain; -import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; -import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin; import org.eclipse.cdt.utils.CommandLineUtil; import org.eclipse.cdt.utils.PathUtil; import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IResourceChangeEvent; +import org.eclipse.core.resources.IResourceChangeListener; +import org.eclipse.core.resources.IResourceDelta; import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.MultiStatus; import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.core.runtime.content.IContentType; +import org.eclipse.core.runtime.jobs.ISchedulingRule; import org.eclipse.core.runtime.jobs.Job; import org.w3c.dom.Element; -public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSettingsOutputScanner { +public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSettingsOutputScanner + implements ICListenerRegisterer, IResourceChangeListener { + private static final int TICKS_STREAM_MONITOR = 100; + private static final int TICKS_CLEAN_MARKERS = 1; + private static final int TICKS_RUN_FOR_ONE_LANGUAGE = 10; + private static final int TICKS_SERIALIZATION = 1; + private static final int TICKS_SCALE = 100; private static final String NEWLINE = System.getProperty("line.separator", "\n"); //$NON-NLS-1$ //$NON-NLS-2$ private static final String PLUGIN_CDT_MAKE_UI_ID = "org.eclipse.cdt.make.ui"; //$NON-NLS-1$ private static final String GMAKE_ERROR_PARSER_ID = "org.eclipse.cdt.core.GmakeErrorParser"; //$NON-NLS-1$ private static final String PATH_ENV = "PATH"; //$NON-NLS-1$ - private static final String ATTR_RUN_ONCE = "run-once"; //$NON-NLS-1$ private static final String ATTR_CONSOLE = "console"; //$NON-NLS-1$ protected static final String COMPILER_MACRO = "${COMMAND}"; //$NON-NLS-1$ protected static final String SPEC_FILE_MACRO = "${INPUTS}"; //$NON-NLS-1$ protected static final String SPEC_EXT_MACRO = "${EXT}"; //$NON-NLS-1$ - protected static final String SPEC_FILE_BASE = "spec."; //$NON-NLS-1$ + protected static final String SPEC_FILE_BASE = "spec"; //$NON-NLS-1$ private String currentCommandResolved = null; protected List detectedSettingEntries = null; + + protected boolean isExecuted = false; protected int collected = 0; - private boolean runOnce = true; private boolean isConsoleEnabled = false; protected java.io.File specFile = null; protected boolean preserveSpecFile = false; @@ -86,7 +102,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti protected URI buildDirURI = null; private class SDMarkerGenerator implements IMarkerGenerator { - protected static final String SCANNER_DISCOVERY_PROBLEM_MARKER = ManagedBuilderCorePlugin.PLUGIN_ID + ".scanner.discovery.problem"; //$NON-NLS-1$ + protected static final String SCANNER_DISCOVERY_PROBLEM_MARKER = MakeCorePlugin.PLUGIN_ID + ".scanner.discovery.problem"; //$NON-NLS-1$ protected static final String PROVIDER = "provider"; //$NON-NLS-1$ public void addMarker(IResource file, int lineNumber, String errorDesc, int severity, String errorVar) { @@ -145,27 +161,23 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti } - /** - * TODO + * This ICConsoleParser handles each individual run for one language from + * {@link AbstractBuiltinSpecsDetector#runForEachLanguage(ICConfigurationDescription, IPath, String[], IProgressMonitor)} + * */ - protected abstract String getToolchainId(); - - @Override - public void configureProvider(String id, String name, List languages, List entries, String customParameter) { - super.configureProvider(id, name, languages, entries, customParameter); - - runOnce = true; + private class ConsoleParser implements ICConsoleParser { + public void startup(ICConfigurationDescription cfgDescription) throws CoreException { + // not used here, see instead startupForLanguage() in AbstractBuiltinSpecsDetector.runForEachLanguage(...) + } + public boolean processLine(String line) { + return AbstractBuiltinSpecsDetector.this.processLine(line, errorParserManager); + } + public void shutdown() { + // not used here, see instead shutdownForLanguage() in AbstractBuiltinSpecsDetector.runForEachLanguage(...) + } } - public void setRunOnce(boolean once) { - runOnce = once; - } - - public boolean isRunOnce() { - return runOnce; - } - public void setConsoleEnabled(boolean enable) { isConsoleEnabled = enable; } @@ -176,28 +188,21 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti protected String resolveCommand(String languageId) throws CoreException { String cmd = getCustomParameter(); - if (cmd!=null && (cmd.contains(COMPILER_MACRO) || cmd.contains(SPEC_FILE_MACRO) || cmd.contains(SPEC_EXT_MACRO))) { - String toolchainId = getToolchainId(); - ITool tool = getTool(toolchainId, languageId); - if (tool==null) { - IStatus status = new Status(IStatus.ERROR, ManagedBuilderCorePlugin.PLUGIN_ID, "Provider "+getId() - +" unable to find the compiler tool for language " + languageId - + "in toolchain " + toolchainId); - throw new CoreException(status); - } - if (cmd.contains(COMPILER_MACRO)) { - String compiler = getCompilerCommand(tool); - cmd = cmd.replace(COMPILER_MACRO, compiler); + String compiler = getCompilerCommand(languageId); + if (compiler!=null) + cmd = cmd.replace(COMPILER_MACRO, compiler); } if (cmd.contains(SPEC_FILE_MACRO)) { - String specFileName = getSpecFile(languageId, tool); - cmd = cmd.replace(SPEC_FILE_MACRO, specFileName); + String specFileName = getSpecFile(languageId); + if (specFileName!=null) + cmd = cmd.replace(SPEC_FILE_MACRO, specFileName); } if (cmd.contains(SPEC_EXT_MACRO)) { - String specFileExt = getSpecExt(languageId, tool); - cmd = cmd.replace(SPEC_EXT_MACRO, specFileExt); + String specFileExt = getSpecFileExtension(languageId); + if (specFileExt!=null) + cmd = cmd.replace(SPEC_EXT_MACRO, specFileExt); } } return cmd; @@ -234,83 +239,256 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti return buildDirURI; } - @Override - public void startup(ICConfigurationDescription cfgDescription) throws CoreException { - // for workspace provider cfgDescription is used to figure out the current project for build console + public void registerListener(ICConfigurationDescription cfgDescription) { currentCfgDescription = cfgDescription; - if (cfgDescription!=null) { - currentProject = cfgDescription.getProjectDescription().getProject(); + ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_BUILD); + // TODO - remove me + CCorePlugin.log(new Status(IStatus.INFO,CCorePlugin.PLUGIN_ID, + getPrefixForLog() + "Added listener [" + System.identityHashCode(this) + "] " + this)); + } + + public void unregisterListener() { + ResourcesPlugin.getWorkspace().removeResourceChangeListener(this); + // TODO - remove me + CCorePlugin.log(new Status(IStatus.INFO,CCorePlugin.PLUGIN_ID, + getPrefixForLog() + "Removed listener [" + System.identityHashCode(this) + "] " + this)); + } + + private String eventToString(IResourceChangeEvent event) { + String strType = null; + IResource rc = null; + if (event != null) { + int type = event.getType(); + switch (type) { + case IResourceChangeEvent.POST_CHANGE: strType = "POST_CHANGE";break; + case IResourceChangeEvent.PRE_CLOSE: strType = "PRE_CLOSE";break; + case IResourceChangeEvent.PRE_DELETE: strType = "PRE_DELETE";break; + case IResourceChangeEvent.PRE_BUILD: strType = "PRE_BUILD";break; + case IResourceChangeEvent.POST_BUILD: strType = "POST_BUILD";break; + case IResourceChangeEvent.PRE_REFRESH: strType = "PRE_REFRESH";break; + default: strType = "unknown";break; + } + strType += "=" + Integer.toHexString(type); + + IResourceDelta delta = event.getDelta(); + rc = delta!=null ? delta.getResource() : null; } + String result = "Event " + strType + ", " + rc; + return result; + } + + public void resourceChanged(IResourceChangeEvent event) { + System.out.println(eventToString(event)); + + // if (event.getType() != IResourceChangeEvent.PRE_BUILD) + // return; + // + // IResourceDelta delta = event.getDelta(); + // delta.getKind(); + // delta.getFlags(); + + execute(); + } + + protected void execute() { + if (isExecuted) { +// // TODO - remove me +// CCorePlugin.log(new Status(IStatus.INFO,CCorePlugin.PLUGIN_ID, +// getPrefixForLog() + "Already executed [" + System.identityHashCode(this) + "] " + this)); + return; + } + isExecuted = true; + + Job job = new Job("Discover compiler's built-in language settings") { + @Override + protected IStatus run(IProgressMonitor monitor) { + return runForEachLanguage(currentCfgDescription, null, null, monitor); + } + }; + + IProject ownerProject = null; + if (currentCfgDescription != null) { + ICProjectDescription prjDescription = currentCfgDescription.getProjectDescription(); + if (prjDescription != null) { + ownerProject = prjDescription.getProject(); + } + } + ISchedulingRule rule = null; + if (ownerProject != null) { + rule = ownerProject.getFile(".settings/language.settings.xml"); + } + if (rule == null) { + rule = ResourcesPlugin.getWorkspace().getRoot(); + } + job.setRule(rule); + job.schedule(); + + // TODO - remove me + CCorePlugin.log(new Status(IStatus.INFO,CCorePlugin.PLUGIN_ID, + getPrefixForLog() + "Execution scheduled [" + System.identityHashCode(this) + "] " + this)); + + } + + /** + * TODO + */ + protected IStatus runForEachLanguage(ICConfigurationDescription cfgDescription, IPath workingDirectory, + String[] env, IProgressMonitor monitor) { + + try { + startup(cfgDescription); + } catch (CoreException e) { + IStatus status = new Status(IStatus.ERROR, MakeCorePlugin.PLUGIN_ID, IStatus.ERROR, "Error preparing to run Builtin Specs Detector", e); + MakeCorePlugin.log(status); + return status; + } + + MultiStatus status = new MultiStatus(MakeCorePlugin.PLUGIN_ID, IStatus.OK, "Problem running CDT Scanner Discovery provider " + getId(), null); + + boolean isChanged = false; + mappedRootURI = null; + buildDirURI = null; + + if (monitor == null) { + monitor = new NullProgressMonitor(); + } + + try { + + List languageIds = getLanguageScope(); + if (languageIds != null) { + int totalWork = TICKS_CLEAN_MARKERS + languageIds.size()*TICKS_RUN_FOR_ONE_LANGUAGE + TICKS_SERIALIZATION; + monitor.beginTask("CDT Scanner Discovery", totalWork * TICKS_SCALE); + + IResource markersResource = currentProject!= null ? currentProject : ResourcesPlugin.getWorkspace().getRoot(); + + // clear old markers + monitor.subTask("Clearing stale markers"); + try { + IMarker[] cur = markersResource.findMarkers(SDMarkerGenerator.SCANNER_DISCOVERY_PROBLEM_MARKER, false, IResource.DEPTH_ZERO); + for (IMarker marker : cur) { + if (getId().equals(marker.getAttribute(SDMarkerGenerator.PROVIDER))) { + marker.delete(); + } + } + } catch (CoreException e) { + MakeCorePlugin.log(e); + } + + if (monitor.isCanceled()) + throw new OperationCanceledException(); + + monitor.worked(TICKS_CLEAN_MARKERS * TICKS_SCALE); + + for (String languageId : languageIds) { + List oldEntries = getSettingEntries(cfgDescription, null, languageId); + try { + startupForLanguage(languageId); + if (monitor.isCanceled()) + throw new OperationCanceledException(); + + runForLanguage(workingDirectory, env, new SubProgressMonitor(monitor, TICKS_RUN_FOR_ONE_LANGUAGE * TICKS_SCALE)); + if (monitor.isCanceled()) + throw new OperationCanceledException(); + } catch (CoreException e) { + IStatus s = new Status(IStatus.ERROR, MakeCorePlugin.PLUGIN_ID, IStatus.ERROR, "Error running Builtin Specs Detector", e); + MakeCorePlugin.log(s); + status.merge(s); + } finally { + shutdownForLanguage(); + } + List newEntries = getSettingEntries(cfgDescription, null, languageId); + isChanged = isChanged || newEntries != oldEntries; + + } + } + + monitor.subTask("Serializing results"); + if (isChanged) { // avoids resource and settings change notifications + try { + if (currentCfgDescription != null) { + LanguageSettingsProvidersSerializer.serializeLanguageSettings(currentCfgDescription.getProjectDescription()); + } else { + LanguageSettingsProvidersSerializer.serializeLanguageSettingsWorkspace(); + } + } catch (CoreException e) { + IStatus s = new Status(IStatus.ERROR, MakeCorePlugin.PLUGIN_ID, IStatus.ERROR, "Error serializing language settings", e); + MakeCorePlugin.log(s); + status.merge(s); + } + + // AG: FIXME - rather send event that ls settings changed + if (currentCfgDescription != null) { + ICProject icProject = CoreModel.getDefault().create(currentProject); + ICElement[] tuSelection = new ICElement[] {icProject}; + try { + CCorePlugin.getIndexManager().update(tuSelection, IIndexManager.UPDATE_ALL | IIndexManager.UPDATE_EXTERNAL_FILES_FOR_PROJECT); + } catch (CoreException e) { + IStatus s = new Status(IStatus.ERROR, MakeCorePlugin.PLUGIN_ID, IStatus.ERROR, "Error updating CDT index", e); + MakeCorePlugin.log(s); + status.merge(s); + } + } else { + // TODO + } + } + if (monitor.isCanceled()) + throw new OperationCanceledException(); + + monitor.worked(TICKS_SERIALIZATION * TICKS_SCALE); + } catch (OperationCanceledException e) { + if (!status.isOK()) { + MakeCorePlugin.log(status); + } + status.merge(new Status(IStatus.CANCEL, MakeCorePlugin.PLUGIN_ID, IStatus.OK, "Operation cancelled by user", e)); + } finally { + monitor.done(); + + // release resources + buildDirURI = null; + mappedRootURI = null; + shutdown(); + currentCfgDescription = cfgDescription; // current description gets cleared in super.shutdown(), keep it + } + + return status; + } + + protected void startupForLanguage(String languageId) throws CoreException { + currentLanguageId = languageId; + + specFile = null; // can get set in resolveCommand() + currentCommandResolved = resolveCommand(currentLanguageId); detectedSettingEntries = new ArrayList(); collected = 0; - currentCommandResolved = customParameter; - - specFile = null; - - currentCommandResolved = resolveCommand(currentLanguageId); - - mappedRootURI = null; - buildDirURI = null; } - @Override - public void shutdown() { - buildDirURI = null; - mappedRootURI = null; - - if (detectedSettingEntries!=null && detectedSettingEntries.size()>0) { - setSettingEntries(currentCfgDescription, currentResource, currentLanguageId, detectedSettingEntries); + protected void shutdownForLanguage() { + if (detectedSettingEntries != null && detectedSettingEntries.size() > 0) { collected = detectedSettingEntries.size(); - IStatus status = new Status(IStatus.INFO, MakeCorePlugin.PLUGIN_ID, getClass().getSimpleName() - + " collected " + detectedSettingEntries.size() + " entries" + " for language " + currentLanguageId); - ManagedBuilderCorePlugin.log(status); + IStatus status = new Status(IStatus.INFO, MakeCorePlugin.PLUGIN_ID, getPrefixForLog() + + getClass().getSimpleName() + " collected " + detectedSettingEntries.size() + " entries" + " for language " + currentLanguageId); + MakeCorePlugin.log(status); + + setSettingEntries(currentCfgDescription, currentResource, currentLanguageId, detectedSettingEntries); } detectedSettingEntries = null; - + + currentCommandResolved = null; if (specFile!=null && !preserveSpecFile) { specFile.delete(); specFile = null; } - - currentCommandResolved = null; - } - - public void run(IProject project, String languageId, IPath workingDirectory, String[] env, - IProgressMonitor monitor) throws CoreException, IOException { - if (isRunOnce() && !isEmpty()) { - return; - } - - currentProject = project; - currentLanguageId = languageId; - startup(null); - - run(workingDirectory, env, monitor); - } - - public void run(ICConfigurationDescription cfgDescription, String languageId, IPath workingDirectory, - String[] env, IProgressMonitor monitor) throws CoreException, IOException { - Assert.isNotNull(cfgDescription); - - if (isRunOnce() && !isEmpty()) { - return; - } - - currentLanguageId = languageId; - startup(cfgDescription); - - run(workingDirectory, env, monitor); - } - + currentLanguageId = null; + } + /** * TODO: test case for this function */ - private void run(IPath workingDirectory, String[] env, IProgressMonitor monitor) - throws CoreException, IOException { - + private void runForLanguage(IPath workingDirectory, String[] env, IProgressMonitor monitor) throws CoreException { IConsole console; if (isConsoleEnabled) { console = startProviderConsole(); @@ -322,59 +500,56 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti OutputStream cos = console.getOutputStream(); // Using GMAKE_ERROR_PARSER_ID as it can handle shell error messages - ErrorParserManager epm = new ErrorParserManager(currentProject, new SDMarkerGenerator(), new String[] {GMAKE_ERROR_PARSER_ID}); - epm.setOutputStream(cos); + errorParserManager = new ErrorParserManager(currentProject, new SDMarkerGenerator(), new String[] {GMAKE_ERROR_PARSER_ID}); + errorParserManager.setOutputStream(cos); - IResource markersResource = currentProject!= null ? currentProject : ResourcesPlugin.getWorkspace().getRoot(); - - // clear old markers - try { - IMarker[] cur = markersResource.findMarkers(SDMarkerGenerator.SCANNER_DISCOVERY_PROBLEM_MARKER, false, IResource.DEPTH_ZERO); - for (IMarker marker : cur) { - if (getId().equals(marker.getAttribute(SDMarkerGenerator.PROVIDER))) { - marker.delete(); - } - } - } catch (CoreException e) { - ManagedBuilderCorePlugin.log(e); - } - - - if (monitor==null) { + if (monitor == null) { monitor = new NullProgressMonitor(); } - StreamMonitor streamMon = new StreamMonitor(new SubProgressMonitor(monitor, 70), epm, 100); - OutputStream stdout = streamMon; - OutputStream stderr = streamMon; - - String msg = "Running scanner discovery: " + getName(); - monitor.subTask(msg); - printLine(stdout, "**** " + msg + " ****" + NEWLINE); - - ConsoleOutputSniffer sniffer = new ConsoleOutputSniffer(stdout, stderr, new IConsoleParser[] { this }); - OutputStream consoleOut = sniffer.getOutputStream(); - OutputStream consoleErr = sniffer.getErrorStream(); - - boolean isSuccess = false; + try { - isSuccess = runProgram(currentCommandResolved, env, workingDirectory, monitor, consoleOut, consoleErr); - } catch (Exception e) { - ManagedBuilderCorePlugin.log(e); - } - if (!isSuccess) { + // StreamMonitor will do monitor.beginTask(...) + StreamMonitor streamMon = new StreamMonitor(monitor, errorParserManager, TICKS_STREAM_MONITOR); + OutputStream stdout = streamMon; + OutputStream stderr = streamMon; + + String msg = "Running scanner discovery: " + getName(); + printLine(stdout, "**** " + msg + " ****" + NEWLINE); + + ConsoleParser consoleParser = new ConsoleParser(); + ConsoleOutputSniffer sniffer = new ConsoleOutputSniffer(stdout, stderr, new IConsoleParser[] { consoleParser }, errorParserManager); + OutputStream consoleOut = sniffer.getOutputStream(); + OutputStream consoleErr = sniffer.getErrorStream(); + + boolean isSuccess = false; try { - consoleOut.close(); - } catch (IOException e) { - ManagedBuilderCorePlugin.log(e); + isSuccess = runProgram(currentCommandResolved, env, workingDirectory, monitor, consoleOut, consoleErr); + } catch (Exception e) { + MakeCorePlugin.log(e); } - try { - consoleErr.close(); - } catch (IOException e) { - ManagedBuilderCorePlugin.log(e); + if (!isSuccess) { + try { + consoleOut.close(); + } catch (IOException e) { + MakeCorePlugin.log(e); + } + try { + consoleErr.close(); + } catch (IOException e) { + MakeCorePlugin.log(e); + } } + } finally { + // ensure monitor.done() is called in cases when StreamMonitor fails to do that + monitor.done(); } } + /** + * TODO + * Note that progress monitor life cycle is handled elsewhere. This method assumes that + * monitor.beginTask(...) has already been called. + */ protected boolean runProgram(String command, String[] env, IPath workingDirectory, IProgressMonitor monitor, OutputStream consoleOut, OutputStream consoleErr) throws CoreException, IOException { @@ -398,12 +573,15 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti System.arraycopy(cmdArray, 1, args, 0, args.length); } + if (monitor==null) { + monitor = new NullProgressMonitor(); + } Process p = launcher.execute(program, args, env, workingDirectory, monitor); if (p != null) { // Before launching give visual cues via the monitor monitor.subTask("Invoking command " + command); - if (launcher.waitAndRead(consoleOut, consoleErr, new SubProgressMonitor(monitor, 0)) != ICommandLauncher.OK) { + if (launcher.waitAndRead(consoleOut, consoleErr, monitor) != ICommandLauncher.OK) { errMsg = launcher.getErrorMessage(); } } else { @@ -431,7 +609,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti return false; } - printLine(consoleOut, NEWLINE + "**** Collected " + collected + " entries. ****"); + printLine(consoleOut, NEWLINE + "**** Collected " + detectedSettingEntries.size() + " entries. ****"); return true; } @@ -484,34 +662,19 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti return envPath; } - private ITool getTool(String toolchainId, String languageId) { - IToolChain toolchain = ManagedBuildManager.getExtensionToolChain(toolchainId); - if (toolchain != null) { - ITool[] tools = toolchain.getTools(); - for (ITool tool : tools) { - IInputType[] inputTypes = tool.getInputTypes(); - for (IInputType inType : inputTypes) { - String lang = inType.getLanguageId(tool); - if (languageId.equals(lang)) - return tool; - } - } - } - ManagedBuilderCorePlugin.error("Unable to find tool in toolchain="+toolchainId+" for language="+languageId); + protected String getCompilerCommand(String languageId) { + IStatus status = new Status(IStatus.ERROR, MakeCorePlugin.PLUGIN_ID, "Provider "+getId() + +" unable to find the compiler tool for language " + languageId); + MakeCorePlugin.log(new CoreException(status)); return null; } - private String getCompilerCommand(ITool tool) { - String compiler = tool.getToolCommand(); - if (compiler.length()==0) { - String msg = "Unable to find compiler command in toolchain="+getToolchainId(); - ManagedBuilderCorePlugin.error(msg); + protected String getSpecFile(String languageId) { + String specExt = getSpecFileExtension(languageId); + String ext = ""; //$NON-NLS-1$ + if (specExt != null) { + ext = '.' + specExt; } - return compiler; - } - - private String getSpecFile(String languageId, ITool tool) { - String ext = getSpecExt(languageId, tool); String specFileName = SPEC_FILE_BASE + ext; IPath workingLocation = MakeCorePlugin.getWorkingDirectory(); @@ -524,57 +687,91 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti try { specFile.createNewFile(); } catch (IOException e) { - ManagedBuilderCorePlugin.log(e); + MakeCorePlugin.log(e); } } return fileLocation.toString(); } - private String getSpecExt(String languageId, ITool tool) { - String ext = ""; - String[] srcFileExtensions = tool.getAllInputExtensions(); - if (srcFileExtensions!=null && srcFileExtensions.length>0) { - ext = srcFileExtensions[0]; + /** + * Determine file extension by language id. This implementation retrieves first extension + * from the list as there could be multiple extensions associated with the given language. + * + * @param languageId - given language ID. + * @return file extension associated with the language or {@code null} if not found. + */ + protected String getSpecFileExtension(String languageId) { + String ext = null; + ILanguageDescriptor langDescriptor = LanguageManager.getInstance().getLanguageDescriptor(languageId); + if (langDescriptor != null) { + IContentType[] contentTypes = langDescriptor.getContentTypes(); + if (contentTypes != null && contentTypes.length > 0) { + String[] fileExtensions = contentTypes[0].getFileSpecs(IContentType.FILE_EXTENSION_SPEC); + if (fileExtensions != null && fileExtensions.length > 0) { + ext = fileExtensions[0]; + } + } } - if (ext.length()==0) { - ManagedBuilderCorePlugin.error("Unable to find file extension for language "+languageId); + + if (ext == null) { + MakeCorePlugin.log(new Status(IStatus.ERROR, MakeCorePlugin.PLUGIN_ID, "Unable to find file extension for language "+languageId)); } return ext; } - protected void printLine(OutputStream stream, String msg) throws IOException { - stream.write((msg + NEWLINE).getBytes()); - stream.flush(); + protected void printLine(OutputStream stream, String msg) { + try { + stream.write((msg + NEWLINE).getBytes()); + stream.flush(); + } catch (IOException e) { + MakeCorePlugin.log(e); + } } @Override public Element serializeAttributes(Element parentElement) { Element elementProvider = super.serializeAttributes(parentElement); - elementProvider.setAttribute(ATTR_RUN_ONCE, Boolean.toString(runOnce)); elementProvider.setAttribute(ATTR_CONSOLE, Boolean.toString(isConsoleEnabled)); return elementProvider; } @Override - public void load(Element providerNode) { - super.load(providerNode); - - String runOnceValue = XmlUtil.determineAttributeValue(providerNode, ATTR_RUN_ONCE); - if (runOnceValue!=null) - runOnce = Boolean.parseBoolean(runOnceValue); - + public void loadAttributes(Element providerNode) { + super.loadAttributes(providerNode); + String consoleValue = XmlUtil.determineAttributeValue(providerNode, ATTR_CONSOLE); if (consoleValue!=null) isConsoleEnabled = Boolean.parseBoolean(consoleValue); } + @Override + public void loadEntries(Element providerNode) { + super.loadEntries(providerNode); + // TODO - test case for that or maybe introduce "isExecuted" attribute in XML? + if (!isEmpty()) + isExecuted = true; + } + + @Override + public void clear() { + super.clear(); + isExecuted = false; + } + + @Override + protected AbstractBuiltinSpecsDetector cloneShallow() throws CloneNotSupportedException { + AbstractBuiltinSpecsDetector clone = (AbstractBuiltinSpecsDetector) super.cloneShallow(); + clone.isExecuted = false; + return clone; + } + @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); - result = prime * result + (runOnce ? 1231 : 1237); result = prime * result + (isConsoleEnabled ? 1231 : 1237); + result = prime * result + (isExecuted ? 1231 : 1237); return result; } @@ -587,10 +784,10 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti if (!(obj instanceof AbstractBuiltinSpecsDetector)) return false; AbstractBuiltinSpecsDetector other = (AbstractBuiltinSpecsDetector) obj; - if (runOnce != other.runOnce) - return false; if (isConsoleEnabled != other.isConsoleEnabled) return false; + if (isExecuted != other.isExecuted) + return false; return true; } } diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java index 33d897402a2..30153820a62 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java @@ -226,10 +226,6 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett currentProject = cfgDescription != null ? cfgDescription.getProjectDescription().getProject() : null; } - public boolean processLine(String line) { - return processLine(line, null); - } - public void shutdown() { // release resources for garbage collector currentCfgDescription = null; @@ -307,12 +303,26 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett return false; } + // TODO - remove me + @Deprecated + protected String getPrefixForLog() { + String str; + if (currentCfgDescription!= null) { + IProject ownerProject = currentCfgDescription.getProjectDescription().getProject(); + str = ownerProject + ":" + currentCfgDescription.getName(); + } else { + str = "[global]"; + } + return str + ": "; + } + + protected void setSettingEntries(List entries) { setSettingEntries(currentCfgDescription, currentResource, currentLanguageId, entries); // TODO - for debugging only, eventually remove - IStatus status = new Status(IStatus.INFO, MakeCorePlugin.PLUGIN_ID, getClass().getSimpleName() - + " collected " + (entries!=null ? ("" + entries.size()) : "null") + " entries for " + currentResource); + IStatus status = new Status(IStatus.INFO, MakeCorePlugin.PLUGIN_ID, getPrefixForLog() + + getClass().getSimpleName() + " collected " + (entries!=null ? ("" + entries.size()) : "null") + " entries for " + currentResource); MakeCorePlugin.log(status); } diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/GCCBuildCommandParser.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/GCCBuildCommandParser.java index e9cff69143c..3c544f7d960 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/GCCBuildCommandParser.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/GCCBuildCommandParser.java @@ -16,8 +16,7 @@ import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsEditabl import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.make.core.scannerconfig.AbstractBuildCommandParser; -public class GCCBuildCommandParser extends AbstractBuildCommandParser implements - ILanguageSettingsEditableProvider { +public class GCCBuildCommandParser extends AbstractBuildCommandParser implements ILanguageSettingsEditableProvider { @SuppressWarnings("nls") static final AbstractOptionParser[] optionParsers = { new IncludePathOptionParser("-I\\s*([\"'])(.*)\\1", "$2"), @@ -51,7 +50,7 @@ public class GCCBuildCommandParser extends AbstractBuildCommandParser implements } public static class GCCBuildCommandPatternHighlighter extends AbstractBuildCommandParser.AbstractBuildCommandPatternHighlighter { - // ID of the parser taken from the extension point + // ID of the parser taken from the existing extension point private static final String GCC_BUILD_COMMAND_PARSER_EXT = "org.eclipse.cdt.make.core.build.command.parser.gcc"; //$NON-NLS-1$ public GCCBuildCommandPatternHighlighter() { diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/preferences/GCCBuildCommandParserOptionPage.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/preferences/GCCBuildCommandParserOptionPage.java index d5bf8f74541..f1d169a92c6 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/preferences/GCCBuildCommandParserOptionPage.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/preferences/GCCBuildCommandParserOptionPage.java @@ -30,7 +30,6 @@ import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; @@ -76,69 +75,7 @@ public final class GCCBuildCommandParserOptionPage extends AbstractLanguageSetti composite.setLayoutData(gd); } - -// Group groupRun = new Group(composite, SWT.SHADOW_ETCHED_IN); -//// groupRun.setText("Language Settings Provider Options"); -// -// GridLayout gridLayoutRun = new GridLayout(); -//// GridLayout gridLayoutRun = new GridLayout(2, true); -//// gridLayoutRun.makeColumnsEqualWidth = false; -//// gridLayoutRun.marginRight = -10; -//// gridLayoutRun.marginLeft = -4; -// groupRun.setLayout(gridLayoutRun); -//// GridData gdRun = new GridData(GridData.FILL_HORIZONTAL); -//// gdRun.horizontalSpan = 2; -//// groupRun.setLayoutData(gdRun); - AbstractBuildCommandParser provider = getRawProvider(); -// { -// runOnceRadioButton = new Button(groupRun, SWT.RADIO); -// runOnceRadioButton.setText("Run only once"); //$NON-NLS-1$ -// // b1.setToolTipText(UIMessages.getString("EnvironmentTab.3")); //$NON-NLS-1$ -// GridData gd = new GridData(GridData.FILL_HORIZONTAL); -// gd.horizontalSpan = 3; -// runOnceRadioButton.setLayoutData(gd); -// runOnceRadioButton.setSelection(provider.isRunOnce()); -// runOnceRadioButton.setEnabled(fEditable); -// runOnceRadioButton.addSelectionListener(new SelectionAdapter() { -// @Override -// public void widgetSelected(SelectionEvent evt) { -// boolean runOnceEnabled = runOnceRadioButton.getSelection(); -// if (runOnceEnabled) { -// AbstractBuildCommandParser provider = getRawProvider(); -// if (runOnceEnabled != provider.isRunOnce()) { -// AbstractBuildCommandParser selectedProvider = getWorkingCopy(providerId); -// selectedProvider.setRunOnce(runOnceEnabled); -// providerTab.refreshItem(selectedProvider); -// } -// } -// } -// -// }); -// } -// { -// runEveryBuildRadioButton = new Button(groupRun, SWT.RADIO); -// runEveryBuildRadioButton.setText("Activate on every build"); //$NON-NLS-1$ -// runEveryBuildRadioButton.setSelection(!provider.isRunOnce()); -// runEveryBuildRadioButton.setEnabled(fEditable); -// GridData gd = new GridData(GridData.FILL_HORIZONTAL); -// gd.horizontalSpan = 3; -// runEveryBuildRadioButton.setLayoutData(gd); -// runEveryBuildRadioButton.addSelectionListener(new SelectionAdapter() { -// @Override -// public void widgetSelected(SelectionEvent evt) { -// boolean runEveryBuildEnabled = runEveryBuildRadioButton.getSelection(); -// if (runEveryBuildEnabled) { -// AbstractBuildCommandParser provider = getRawProvider(); -// if (runEveryBuildEnabled != !provider.isRunOnce()) { -// AbstractBuildCommandParser selectedProvider = getWorkingCopy(providerId); -// selectedProvider.setRunOnce(!runEveryBuildEnabled); -// providerTab.refreshItem(selectedProvider); -// } -// } -// } -// }); -// } // Compiler specs command { @@ -187,90 +124,6 @@ public final class GCCBuildCommandParserOptionPage extends AbstractLanguageSetti // // }); // -// } - -// { -// final Button button = new Button(composite, SWT.PUSH); -// button.setFont(parent.getFont()); -// String text = fProvider.isEmpty() ? "Run Now (TODO)" : "Clear"; -// button.setText(text); -//// button.addSelectionListener(this); -// GridData data = new GridData(); -// data.horizontalSpan = 2; -//// data.horizontalAlignment = GridData.BEGINNING; -//// data.widthHint = 60; -// button.setLayoutData(data); -// // TODO -// button.setEnabled(fEditable && !fProvider.isEmpty()); -// -// button.addSelectionListener(new SelectionAdapter() { -// -// @Override -// public void widgetSelected(SelectionEvent evt) { -// if (fProvider.isEmpty()) { -// // TODO -// } else { -// fProvider.clear(); -// } -// // TODO -// button.setEnabled(fEditable && !fProvider.isEmpty()); -// String text = fProvider.isEmpty() ? "Run Now (TODO)" : "Clear"; -// button.setText(text); -// button.pack(); -// } -// -// }); -// -// } - -// // Compiler specs command -// { -// Label label = ControlFactory.createLabel(composite, "Parsing rules:"); -// GridData gd = new GridData(); -// gd.horizontalSpan = 2; -// label.setLayoutData(gd); -//// Label newLabel = new Label(composite, SWT.NONE); -////// ((GridData) newLabel.getLayoutData()).horizontalSpan = 1; -//// newLabel.setText("Command to get compiler specs:"); -// } - - -// createPatternsTable(group, composite); - - - - - - - - -// Group group = new Group(parent, SWT.SHADOW_ETCHED_IN); -// group.setText(DialogsMessages.RegexErrorParserOptionPage_Title); -// -// GridLayout gridLayout = new GridLayout(2, true); -// gridLayout.makeColumnsEqualWidth = false; -// gridLayout.marginRight = -10; -// gridLayout.marginLeft = -4; -// group.setLayout(gridLayout); -// group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); -// -// Composite composite = new Composite(group, SWT.NONE); -// GridLayout layout = new GridLayout(); -// layout.numColumns = 2; -// layout.marginWidth = 1; -// layout.marginHeight = 1; -// layout.marginRight = 1; -// composite.setLayout(layout); -// composite.setLayoutData(new GridData(GridData.FILL_BOTH)); -// Dialog.applyDialogFont(composite); -// -// if (!fEditable) -// createLinkToPreferences(composite); -// -// createPatternsTable(group, composite); -// -// if (fEditable) { -// createButtons(composite); // } { diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/scannerconfig/BuiltinSpecsDetectorOptionPage.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/scannerconfig/BuiltinSpecsDetectorOptionPage.java index 1774569dda3..f4bca39a44a 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/scannerconfig/BuiltinSpecsDetectorOptionPage.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/scannerconfig/BuiltinSpecsDetectorOptionPage.java @@ -44,8 +44,6 @@ public final class BuiltinSpecsDetectorOptionPage extends AbstractLanguageSettin private Text inputCommand; private StatusMessageLine fStatusLine; - private Button runOnceRadioButton; - private Button runEveryBuildRadioButton; private Button allocateConsoleCheckBox; /* @@ -58,7 +56,7 @@ public final class BuiltinSpecsDetectorOptionPage extends AbstractLanguageSettin // Composite optionsPageComposite = new Composite(composite, SWT.NULL); fEditable = parent.isEnabled(); - final Composite composite = new Composite(parent, SWT.NONE); + Composite composite = new Composite(parent, SWT.NONE); { GridLayout layout = new GridLayout(); layout.numColumns = 2; @@ -74,69 +72,7 @@ public final class BuiltinSpecsDetectorOptionPage extends AbstractLanguageSettin composite.setLayoutData(gd); } - - Group groupRun = new Group(composite, SWT.SHADOW_ETCHED_IN); -// groupRun.setText("Language Settings Provider Options"); - - GridLayout gridLayoutRun = new GridLayout(); -// GridLayout gridLayoutRun = new GridLayout(2, true); -// gridLayoutRun.makeColumnsEqualWidth = false; -// gridLayoutRun.marginRight = -10; -// gridLayoutRun.marginLeft = -4; - groupRun.setLayout(gridLayoutRun); -// GridData gdRun = new GridData(GridData.FILL_HORIZONTAL); -// gdRun.horizontalSpan = 2; -// groupRun.setLayoutData(gdRun); - AbstractBuiltinSpecsDetector provider = getRawProvider(); - { - runOnceRadioButton = new Button(groupRun, SWT.RADIO); - runOnceRadioButton.setText("Run only once"); //$NON-NLS-1$ - // b1.setToolTipText(UIMessages.getString("EnvironmentTab.3")); //$NON-NLS-1$ - GridData gd = new GridData(GridData.FILL_HORIZONTAL); - gd.horizontalSpan = 3; - runOnceRadioButton.setLayoutData(gd); - runOnceRadioButton.setSelection(provider.isRunOnce()); - runOnceRadioButton.setEnabled(fEditable); - runOnceRadioButton.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent evt) { - boolean runOnceEnabled = runOnceRadioButton.getSelection(); - if (runOnceEnabled) { - AbstractBuiltinSpecsDetector provider = getRawProvider(); - if (runOnceEnabled != provider.isRunOnce()) { - AbstractBuiltinSpecsDetector selectedProvider = getWorkingCopy(providerId); - selectedProvider.setRunOnce(runOnceEnabled); - providerTab.refreshItem(selectedProvider); - } - } - } - - }); - } - { - runEveryBuildRadioButton = new Button(groupRun, SWT.RADIO); - runEveryBuildRadioButton.setText("Activate on every build"); //$NON-NLS-1$ - runEveryBuildRadioButton.setSelection(!provider.isRunOnce()); - runEveryBuildRadioButton.setEnabled(fEditable); - GridData gd = new GridData(GridData.FILL_HORIZONTAL); - gd.horizontalSpan = 3; - runEveryBuildRadioButton.setLayoutData(gd); - runEveryBuildRadioButton.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent evt) { - boolean runEveryBuildEnabled = runEveryBuildRadioButton.getSelection(); - if (runEveryBuildEnabled) { - AbstractBuiltinSpecsDetector provider = getRawProvider(); - if (runEveryBuildEnabled != !provider.isRunOnce()) { - AbstractBuiltinSpecsDetector selectedProvider = getWorkingCopy(providerId); - selectedProvider.setRunOnce(!runEveryBuildEnabled); - providerTab.refreshItem(selectedProvider); - } - } - } - }); - } // Compiler specs command { diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/GCCBuiltinSpecsDetectorTest.java b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/GCCBuiltinSpecsDetectorTest.java index f33e8d91bdc..104a80775f4 100644 --- a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/GCCBuiltinSpecsDetectorTest.java +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/GCCBuiltinSpecsDetectorTest.java @@ -10,65 +10,50 @@ *******************************************************************************/ package org.eclipse.cdt.build.core.scannerconfig.tests; -import java.io.IOException; -import java.io.OutputStream; import java.util.ArrayList; import java.util.List; import junit.framework.TestCase; import org.eclipse.cdt.core.dom.ast.gnu.c.GCCLanguage; -import org.eclipse.cdt.core.dom.ast.gnu.cpp.GPPLanguage; import org.eclipse.cdt.core.model.CoreModel; -import org.eclipse.cdt.core.settings.model.CIncludeFileEntry; import org.eclipse.cdt.core.settings.model.CIncludePathEntry; -import org.eclipse.cdt.core.settings.model.CLibraryFileEntry; -import org.eclipse.cdt.core.settings.model.CLibraryPathEntry; import org.eclipse.cdt.core.settings.model.CMacroEntry; -import org.eclipse.cdt.core.settings.model.CMacroFileEntry; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager; import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.core.testplugin.ResourceHelper; -import org.eclipse.cdt.internal.core.XmlUtil; -import org.eclipse.cdt.make.core.scannerconfig.AbstractBuiltinSpecsDetector; import org.eclipse.cdt.managedbuilder.internal.scannerconfig.GCCBuiltinSpecsDetector; import org.eclipse.cdt.managedbuilder.internal.scannerconfig.GCCBuiltinSpecsDetectorCygwin; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.Path; -import org.w3c.dom.Document; -import org.w3c.dom.Element; public class GCCBuiltinSpecsDetectorTest extends TestCase { - private static final String PROVIDER_ID = "provider.id"; - private static final String PROVIDER_NAME = "provider name"; - private static final String LANGUAGE_ID = "language.test.id"; private static final String LANGUAGE_ID_C = GCCLanguage.ID; - private static final String LANGUAGE_ID_CPP = GPPLanguage.ID; - private static final String CUSTOM_PARAMETER = "customParameter"; - private static final String ELEM_TEST = "test"; - // those attributes must match that in AbstractBuiltinSpecsDetector - private static final String ATTR_CONSOLE = "console"; //$NON-NLS-1$ - private static final String ATTR_RUN_ONCE = "run-once"; //$NON-NLS-1$ + class MockGCCBuiltinSpecsDetector extends GCCBuiltinSpecsDetector { + @Override + public void startupForLanguage(String languageId) throws CoreException { + super.startupForLanguage(languageId); + } + @Override + public void shutdownForLanguage() { + super.shutdownForLanguage(); + } + } - private class MockBuiltinSpecsDetector extends AbstractBuiltinSpecsDetector { + class MockGCCBuiltinSpecsDetectorCygwin extends GCCBuiltinSpecsDetectorCygwin { @Override - protected String getToolchainId() { - return null; + public void startupForLanguage(String languageId) throws CoreException { + super.startupForLanguage(languageId); } @Override - protected List parseForOptions(String line) { - return null; - } - @Override - protected AbstractOptionParser[] getOptionParsers() { - return null; + public void shutdownForLanguage() { + super.shutdownForLanguage(); } } @@ -93,540 +78,167 @@ public class GCCBuiltinSpecsDetectorTest extends TestCase { return cfgDescriptions; } - public void testAbstractBuiltinSpecsDetector_GettersSetters() throws Exception { - // define mock detector - MockBuiltinSpecsDetector detector = new MockBuiltinSpecsDetector(); - - detector.configureProvider(PROVIDER_ID, PROVIDER_NAME, null, null, null); - assertEquals(PROVIDER_ID, detector.getId()); - assertEquals(PROVIDER_NAME, detector.getName()); - assertEquals(null, detector.getLanguageScope()); - assertEquals(null, detector.getSettingEntries(null, null, null)); - assertEquals(null, detector.getCustomParameter()); - - List languages = new ArrayList(); - languages.add(LANGUAGE_ID); - List entries = new ArrayList(); - ICLanguageSettingEntry entry = new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); - entries.add(entry); - - detector.configureProvider(PROVIDER_ID, PROVIDER_NAME, languages, entries, CUSTOM_PARAMETER); - assertEquals(PROVIDER_ID, detector.getId()); - assertEquals(PROVIDER_NAME, detector.getName()); - assertEquals(languages, detector.getLanguageScope()); - assertEquals(entries, detector.getSettingEntries(null, null, null)); - assertEquals(CUSTOM_PARAMETER, detector.getCustomParameter()); - - assertEquals(true, detector.isRunOnce()); - detector.setRunOnce(false); - assertEquals(false, detector.isRunOnce()); - } - - public void testAbstractBuiltinSpecsDetector_CloneAndEquals() throws Exception { - // define mock detector - class MockDetectorCloneable extends MockBuiltinSpecsDetector implements Cloneable { - @Override - public MockDetectorCloneable clone() throws CloneNotSupportedException { - return (MockDetectorCloneable) super.clone(); - } - @Override - public MockDetectorCloneable cloneShallow() throws CloneNotSupportedException { - return (MockDetectorCloneable) super.cloneShallow(); - } - } - - // create instance to compare to - MockDetectorCloneable detector = new MockDetectorCloneable(); - - List languages = new ArrayList(); - languages.add(LANGUAGE_ID); - List entries = new ArrayList(); - ICLanguageSettingEntry entry = new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); - entries.add(entry); - - // check clone after initialization - MockDetectorCloneable clone0 = detector.clone(); - assertTrue(detector.equals(clone0)); - - // configure provider - detector.configureProvider(PROVIDER_ID, PROVIDER_NAME, languages, entries, CUSTOM_PARAMETER); - assertEquals(true, detector.isRunOnce()); - detector.setRunOnce(false); - assertFalse(detector.equals(clone0)); - - // check another clone after configuring - { - MockDetectorCloneable clone = detector.clone(); - assertTrue(detector.equals(clone)); - } - - // check custom parameter - { - MockDetectorCloneable clone = detector.clone(); - clone.setCustomParameter("changed"); - assertFalse(detector.equals(clone)); - } - - // check language scope - { - MockDetectorCloneable clone = detector.clone(); - clone.setLanguageScope(null); - assertFalse(detector.equals(clone)); - } - - // check 'run once' flag - { - MockDetectorCloneable clone = detector.clone(); - boolean runOnce = clone.isRunOnce(); - clone.setRunOnce( ! runOnce ); - assertFalse(detector.equals(clone)); - } - - // check console flag - { - MockDetectorCloneable clone = detector.clone(); - boolean isConsoleEnabled = clone.isConsoleEnabled(); - clone.setConsoleEnabled( ! isConsoleEnabled ); - assertFalse(detector.equals(clone)); - } - - // check entries - { - MockDetectorCloneable clone = detector.clone(); - clone.setSettingEntries(null, null, null, null); - assertFalse(detector.equals(clone)); - } - - // check cloneShallow() - { - MockDetectorCloneable detector2 = detector.clone(); - MockDetectorCloneable clone = detector2.cloneShallow(); - assertFalse(detector2.equals(clone)); - detector2.setSettingEntries(null, null, null, null); - assertTrue(detector2.equals(clone)); - } - - } - - /** - */ - public void testAbstractBuiltinSpecsDetector_Serialize() throws Exception { - { - // create empty XML - Document doc = XmlUtil.newDocument(); - Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST); - - // load it to new provider - MockBuiltinSpecsDetector detector = new MockBuiltinSpecsDetector(); - detector.load(rootElement); - assertEquals(true, detector.isRunOnce()); - assertEquals(false, detector.isConsoleEnabled()); - } - - Element elementProvider; - { - // define mock detector - MockBuiltinSpecsDetector detector = new MockBuiltinSpecsDetector(); - assertEquals(true, detector.isRunOnce()); - assertEquals(false, detector.isConsoleEnabled()); - - // redefine the settings - detector.setRunOnce(false); - assertEquals(false, detector.isRunOnce()); - detector.setConsoleEnabled(true); - assertEquals(true, detector.isConsoleEnabled()); - - // serialize in XML - Document doc = XmlUtil.newDocument(); - Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST); - elementProvider = detector.serialize(rootElement); - String xmlString = XmlUtil.toString(doc); - - assertTrue(xmlString.contains(ATTR_RUN_ONCE)); - assertTrue(xmlString.contains(ATTR_CONSOLE)); - } - { - // create another instance of the provider - MockBuiltinSpecsDetector detector = new MockBuiltinSpecsDetector(); - assertEquals(true, detector.isRunOnce()); - assertEquals(false, detector.isConsoleEnabled()); - - // load element - detector.load(elementProvider); - assertEquals(false, detector.isRunOnce()); - assertEquals(true, detector.isConsoleEnabled()); - } - } - - - - public void testAbstractBuiltinSpecsDetector_Nulls() throws Exception { - { - // test AbstractBuiltinSpecsDetector.run(...); - MockBuiltinSpecsDetector detector = new MockBuiltinSpecsDetector(); - detector.run((IProject)null, null, null, null, null); - // Do not test with (ICConfigurationDescription)null as it is not allowed - } - - { - // test AbstractBuiltinSpecsDetector.processLine(...) flow - MockBuiltinSpecsDetector detector = new MockBuiltinSpecsDetector(); - detector.startup(null); - detector.processLine(null); - detector.shutdown(); - } - - } - - public void testAbstractBuiltinSpecsDetector_RunConfiguration() throws Exception { - // Create model project and accompanied descriptions - String projectName = getName(); - IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); - ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); - ICConfigurationDescription cfgDescription = cfgDescriptions[0]; - - AbstractBuiltinSpecsDetector detector = new GCCBuiltinSpecsDetector() { - @Override - protected boolean runProgram(String command, String[] env, IPath workingDirectory, IProgressMonitor monitor, - OutputStream consoleOut, OutputStream consoleErr) throws CoreException, IOException { - printLine(consoleOut, "#define MACRO VALUE"); - consoleOut.close(); - consoleErr.close(); - return true; - } - }; - - detector.setLanguageScope(new ArrayList() {{add(LANGUAGE_ID);}}); - - detector.run(cfgDescription, LANGUAGE_ID, null, null, null); - assertFalse(detector.isEmpty()); - - List noentries = detector.getSettingEntries(null, null, null); - assertNull(noentries); - - List entries = detector.getSettingEntries(cfgDescription, null, LANGUAGE_ID); - ICLanguageSettingEntry expected = new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); - assertEquals(expected, entries.get(0)); - } - - public void testAbstractBuiltinSpecsDetector_RunProject() throws Exception { - // Create model project and accompanied descriptions - String projectName = getName(); - IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); - - AbstractBuiltinSpecsDetector detector = new GCCBuiltinSpecsDetector() { - @Override - protected boolean runProgram(String command, String[] env, IPath workingDirectory, IProgressMonitor monitor, - OutputStream consoleOut, OutputStream consoleErr) throws CoreException, IOException { - printLine(consoleOut, "#define MACRO VALUE"); - consoleOut.close(); - consoleErr.close(); - return true; - } - }; - - detector.setLanguageScope(new ArrayList() {{add(LANGUAGE_ID);}}); - - detector.run(project, LANGUAGE_ID, null, null, null); - assertFalse(detector.isEmpty()); - - List entries = detector.getSettingEntries(null, null, LANGUAGE_ID); - ICLanguageSettingEntry expected = new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); - assertEquals(expected, entries.get(0)); - } - - public void testAbstractBuiltinSpecsDetector_RunGlobal() throws Exception { - AbstractBuiltinSpecsDetector detector = new GCCBuiltinSpecsDetector() { - @Override - protected boolean runProgram(String command, String[] env, IPath workingDirectory, IProgressMonitor monitor, - OutputStream consoleOut, OutputStream consoleErr) throws CoreException, IOException { - printLine(consoleOut, "#define MACRO VALUE"); - consoleOut.close(); - consoleErr.close(); - return true; - } - }; - - detector.setLanguageScope(new ArrayList() {{add(LANGUAGE_ID);}}); - - detector.run((IProject)null, LANGUAGE_ID, null, null, null); - assertFalse(detector.isEmpty()); - - List entries = detector.getSettingEntries(null, null, LANGUAGE_ID); - ICLanguageSettingEntry expected = new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); - assertEquals(expected, entries.get(0)); - } - - public void testAbstractBuiltinSpecsDetector_RunOnce() throws Exception { - // Create model project and accompanied descriptions - String projectName = getName(); - IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); - ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); - ICConfigurationDescription cfgDescription = cfgDescriptions[0]; - - // Define mock detector which collects number of entries equal to count - AbstractBuiltinSpecsDetector detector = new MockBuiltinSpecsDetector() { - int count=0; - @Override - public boolean processLine(String line) { - count++; - for (int i=0;i entries = detector.getSettingEntries(null, null, LANGUAGE_ID_C); - assertEquals(1, entries.size()); - } - - // run second time - detector.run(project, LANGUAGE_ID_C, null, null, null); - { - List entries = detector.getSettingEntries(null, null, LANGUAGE_ID_C); - assertEquals(2, entries.size()); - } - - // set to run once - detector.setRunOnce(true); - assertEquals(true, detector.isRunOnce()); - assertFalse(detector.isEmpty()); - - detector.run(project, LANGUAGE_ID_C, null, null, null); - { - // should not collect when provider is not empty - List entries = detector.getSettingEntries(null, null, LANGUAGE_ID_C); - assertEquals(2, entries.size()); - } - - detector.run(cfgDescription, LANGUAGE_ID_C, null, null, null); - { - // should not collect when provider is not empty - List entries = detector.getSettingEntries(null, null, LANGUAGE_ID_C); - assertEquals(2, entries.size()); - } - } - - public void testAbstractBuiltinSpecsDetector_Launch() throws Exception { - // Create model project and accompanied descriptions - String projectName = getName(); - IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); - ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); - - ICConfigurationDescription cfgDescription = cfgDescriptions[0]; - - AbstractBuiltinSpecsDetector detector = new MockBuiltinSpecsDetector() { - @Override - public boolean processLine(String line) { - // pretending that we parsed the line - detectedSettingEntries.add(new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY)); - return true; - } - }; - detector.setLanguageScope(new ArrayList() {{add(LANGUAGE_ID);}}); - detector.setCustomParameter("echo #define MACRO VALUE"); - - detector.run(cfgDescription, LANGUAGE_ID, null, null, null); - - List noentries = detector.getSettingEntries(null, null, null); - assertNull(noentries); - - List entries = detector.getSettingEntries(cfgDescription, null, LANGUAGE_ID); - ICLanguageSettingEntry expected = new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); - assertEquals(expected, entries.get(0)); - } - - public void testAbstractBuiltinSpecsDetector_GroupSettings() throws Exception { - // define benchmarks - final CIncludePathEntry includePath_1 = new CIncludePathEntry("/include/path_1", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); - final CIncludePathEntry includePath_2 = new CIncludePathEntry("/include/path_2", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); - final CIncludeFileEntry includeFile_1 = new CIncludeFileEntry(new Path("/include.file1"), ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); - final CIncludeFileEntry includeFile_2 = new CIncludeFileEntry(new Path("/include.file2"), ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); - final CMacroEntry macro_1 = new CMacroEntry("MACRO_1", "", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); - final CMacroEntry macro_2 = new CMacroEntry("MACRO_2", "", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY |ICSettingEntry.UNDEFINED); - final CMacroFileEntry macroFile_1 = new CMacroFileEntry(new Path("/macro.file1"), ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); - final CMacroFileEntry macroFile_2 = new CMacroFileEntry(new Path("/macro.file2"), ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); - final CLibraryPathEntry libraryPath_1 = new CLibraryPathEntry(new Path("/lib/path_1"), ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); - final CLibraryPathEntry libraryPath_2 = new CLibraryPathEntry(new Path("/lib/path_2"), ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); - final CLibraryFileEntry libraryFile_1 = new CLibraryFileEntry("lib_1.a", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); - final CLibraryFileEntry libraryFile_2 = new CLibraryFileEntry("lib_2.a", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); - - // Define mock detector adding unorganized entries - AbstractBuiltinSpecsDetector detector = new MockBuiltinSpecsDetector() { - @Override - public boolean processLine(String line) { - detectedSettingEntries.add(libraryFile_1); - detectedSettingEntries.add(libraryPath_1); - detectedSettingEntries.add(macroFile_1); - detectedSettingEntries.add(macro_1); - detectedSettingEntries.add(includeFile_1); - detectedSettingEntries.add(includePath_1); - - detectedSettingEntries.add(includePath_2); - detectedSettingEntries.add(includeFile_2); - detectedSettingEntries.add(macro_2); - detectedSettingEntries.add(macroFile_2); - detectedSettingEntries.add(libraryPath_2); - detectedSettingEntries.add(libraryFile_2); - return true; - } - }; - - // run specs detector - detector.startup(null); - detector.processLine(""); - detector.shutdown(); - - - // compare benchmarks, expected well-sorted - List entries = detector.getSettingEntries(null, null, null); - - int i=0; - assertEquals(includePath_1, entries.get(i++)); - assertEquals(includePath_2, entries.get(i++)); - assertEquals(includeFile_1, entries.get(i++)); - assertEquals(includeFile_2, entries.get(i++)); - assertEquals(macro_1, entries.get(i++)); - assertEquals(macro_2, entries.get(i++)); - assertEquals(macroFile_1, entries.get(i++)); - assertEquals(macroFile_2, entries.get(i++)); - assertEquals(libraryPath_1, entries.get(i++)); - assertEquals(libraryPath_2, entries.get(i++)); - assertEquals(libraryFile_1, entries.get(i++)); - assertEquals(libraryFile_2, entries.get(i++)); - - assertEquals(12, entries.size()); - } - - public void testGCCBuiltinSpecsDetector_Macro_NoValue() throws Exception { - AbstractBuiltinSpecsDetector detector = new GCCBuiltinSpecsDetector(); - - detector.startup(null); - detector.processLine("#define MACRO"); - detector.shutdown(); - - List entries = detector.getSettingEntries(null, null, null); - ICLanguageSettingEntry expected = new CMacroEntry("MACRO", null, ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); - assertEquals(expected, entries.get(0)); - } - public void testGCCBuiltinSpecsDetector_ResolvedCommand() throws Exception { - class MockGCCBuiltinSpecsDetector extends GCCBuiltinSpecsDetector { + class MockGCCBuiltinSpecsDetectorLocal extends GCCBuiltinSpecsDetector { @Override public String resolveCommand(String languageId) throws CoreException { return super.resolveCommand(languageId); } } { - MockGCCBuiltinSpecsDetector detector = new MockGCCBuiltinSpecsDetector(); + MockGCCBuiltinSpecsDetectorLocal detector = new MockGCCBuiltinSpecsDetectorLocal(); detector.setLanguageScope(new ArrayList() {{add(LANGUAGE_ID_C);}}); detector.setCustomParameter("${COMMAND} -E -P -v -dD ${INPUTS}"); String resolvedCommand = detector.resolveCommand(LANGUAGE_ID_C); assertTrue(resolvedCommand.startsWith("gcc -E -P -v -dD ")); assertTrue(resolvedCommand.endsWith("spec.c")); - detector.shutdown(); } { - MockGCCBuiltinSpecsDetector detector = new MockGCCBuiltinSpecsDetector(); + MockGCCBuiltinSpecsDetectorLocal detector = new MockGCCBuiltinSpecsDetectorLocal(); detector.setLanguageScope(new ArrayList() {{add(LANGUAGE_ID_C);}}); detector.setCustomParameter("${COMMAND} -E -P -v -dD file.${EXT}"); String resolvedCommand = detector.resolveCommand(LANGUAGE_ID_C); assertTrue(resolvedCommand.startsWith("gcc -E -P -v -dD ")); assertTrue(resolvedCommand.endsWith("file.c")); - detector.shutdown(); } } - public void testGCCBuiltinSpecsDetector_Macro_NoArgs() throws Exception { - AbstractBuiltinSpecsDetector detector = new GCCBuiltinSpecsDetector(); + public void testGCCBuiltinSpecsDetector_Macro_NoValue() throws Exception { + MockGCCBuiltinSpecsDetector detector = new MockGCCBuiltinSpecsDetector(); detector.startup(null); - detector.processLine("#define MACRO VALUE"); + detector.startupForLanguage(null); + detector.processLine("#define MACRO", null); + detector.shutdownForLanguage(); detector.shutdown(); List entries = detector.getSettingEntries(null, null, null); - ICLanguageSettingEntry expected = new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); - assertEquals(expected, entries.get(0)); + assertEquals(new CMacroEntry("MACRO", null, ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), entries.get(0)); + assertEquals(1, entries.size()); + } + + public void testGCCBuiltinSpecsDetector_Macro_Simple() throws Exception { + MockGCCBuiltinSpecsDetector detector = new MockGCCBuiltinSpecsDetector(); + + detector.startup(null); + detector.startupForLanguage(null); + detector.processLine("#define MACRO VALUE", null); + detector.shutdownForLanguage(); + detector.shutdown(); + + List entries = detector.getSettingEntries(null, null, null); + assertEquals(new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), entries.get(0)); + assertEquals(1, entries.size()); } public void testGCCBuiltinSpecsDetector_Macro_Const() throws Exception { - AbstractBuiltinSpecsDetector detector = new GCCBuiltinSpecsDetector(); + MockGCCBuiltinSpecsDetector detector = new MockGCCBuiltinSpecsDetector(); detector.startup(null); - detector.processLine("#define MACRO (3)"); + detector.startupForLanguage(null); + detector.processLine("#define MACRO (3)", null); + detector.shutdownForLanguage(); detector.shutdown(); List entries = detector.getSettingEntries(null, null, null); - ICLanguageSettingEntry expected = new CMacroEntry("MACRO", "(3)", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); - assertEquals(expected, entries.get(0)); + assertEquals(new CMacroEntry("MACRO", "(3)", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), entries.get(0)); + assertEquals(1, entries.size()); + } + + public void testGCCBuiltinSpecsDetector_Macro_WhiteSpaces() throws Exception { + MockGCCBuiltinSpecsDetector detector = new MockGCCBuiltinSpecsDetector(); + + detector.startup(null); + detector.startupForLanguage(null); + detector.processLine("#define \t MACRO_1 VALUE", null); + detector.processLine("#define MACRO_2 \t VALUE", null); + detector.processLine("#define MACRO_3 VALUE \t", null); + detector.shutdownForLanguage(); + detector.shutdown(); + + List entries = detector.getSettingEntries(null, null, null); + int index = 0; + assertEquals(new CMacroEntry("MACRO_1", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), entries.get(index++)); + assertEquals(new CMacroEntry("MACRO_2", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), entries.get(index++)); + assertEquals(new CMacroEntry("MACRO_3", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), entries.get(index++)); + assertEquals(index, entries.size()); } public void testGCCBuiltinSpecsDetector_Macro_EmptyArgList() throws Exception { - AbstractBuiltinSpecsDetector detector = new GCCBuiltinSpecsDetector(); + MockGCCBuiltinSpecsDetector detector = new MockGCCBuiltinSpecsDetector(); detector.startup(null); - detector.processLine("#define MACRO() VALUE"); + detector.startupForLanguage(null); + detector.processLine("#define MACRO() VALUE", null); + detector.shutdownForLanguage(); detector.shutdown(); List entries = detector.getSettingEntries(null, null, null); - ICLanguageSettingEntry expected = new CMacroEntry("MACRO()", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); - assertEquals(expected, entries.get(0)); + assertEquals(new CMacroEntry("MACRO()", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), entries.get(0)); + assertEquals(1, entries.size()); } public void testGCCBuiltinSpecsDetector_Macro_ParamUnused() throws Exception { - AbstractBuiltinSpecsDetector detector = new GCCBuiltinSpecsDetector(); + MockGCCBuiltinSpecsDetector detector = new MockGCCBuiltinSpecsDetector(); detector.startup(null); - detector.processLine("#define MACRO(X) VALUE"); + detector.startupForLanguage(null); + detector.processLine("#define MACRO(X) VALUE", null); + detector.shutdownForLanguage(); detector.shutdown(); List entries = detector.getSettingEntries(null, null, null); - ICLanguageSettingEntry expected = new CMacroEntry("MACRO(X)", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); - assertEquals(expected, entries.get(0)); + assertEquals(new CMacroEntry("MACRO(X)", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), entries.get(0)); + assertEquals(1, entries.size()); } public void testGCCBuiltinSpecsDetector_Macro_ParamSpace() throws Exception { - AbstractBuiltinSpecsDetector detector = new GCCBuiltinSpecsDetector(); + MockGCCBuiltinSpecsDetector detector = new MockGCCBuiltinSpecsDetector(); detector.startup(null); - detector.processLine("#define MACRO(P1, P2) VALUE(P1, P2)"); + detector.startupForLanguage(null); + detector.processLine("#define MACRO(P1, P2) VALUE(P1, P2)", null); + detector.shutdownForLanguage(); detector.shutdown(); List entries = detector.getSettingEntries(null, null, null); - ICLanguageSettingEntry expected = new CMacroEntry("MACRO(P1, P2)", "VALUE(P1, P2)", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); - assertEquals(expected, entries.get(0)); + assertEquals(new CMacroEntry("MACRO(P1, P2)", "VALUE(P1, P2)", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), entries.get(0)); + assertEquals(1, entries.size()); } public void testGCCBuiltinSpecsDetector_Macro_ArgsNoValue() throws Exception { - AbstractBuiltinSpecsDetector detector = new GCCBuiltinSpecsDetector(); + MockGCCBuiltinSpecsDetector detector = new MockGCCBuiltinSpecsDetector(); detector.startup(null); - detector.processLine("#define MACRO(P1, P2) "); + detector.startupForLanguage(null); + detector.processLine("#define MACRO(P1, P2) ", null); + detector.shutdownForLanguage(); detector.shutdown(); List entries = detector.getSettingEntries(null, null, null); - ICLanguageSettingEntry expected = new CMacroEntry("MACRO(P1, P2)", null, ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); - assertEquals(expected, entries.get(0)); + assertEquals(new CMacroEntry("MACRO(P1, P2)", null, ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), entries.get(0)); + assertEquals(1, entries.size()); + } + + public void testGCCBuiltinSpecsDetector_Macro_Args_WhiteSpaces() throws Exception { + MockGCCBuiltinSpecsDetector detector = new MockGCCBuiltinSpecsDetector(); + + detector.startup(null); + detector.startupForLanguage(null); + detector.processLine("#define \t MACRO_1(P1, P2) VALUE(P1, P2)", null); + detector.processLine("#define MACRO_2(P1, P2) \t VALUE(P1, P2)", null); + detector.processLine("#define MACRO_3(P1, P2) VALUE(P1, P2) \t", null); + detector.shutdownForLanguage(); + detector.shutdown(); + + List entries = detector.getSettingEntries(null, null, null); + int index = 0; + assertEquals(new CMacroEntry("MACRO_1(P1, P2)", "VALUE(P1, P2)", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), entries.get(index++)); + assertEquals(new CMacroEntry("MACRO_2(P1, P2)", "VALUE(P1, P2)", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), entries.get(index++)); + assertEquals(new CMacroEntry("MACRO_3(P1, P2)", "VALUE(P1, P2)", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), entries.get(index++)); + assertEquals(index, entries.size()); } public void testGCCBuiltinSpecsDetector_Includes() throws Exception { @@ -644,39 +256,64 @@ public class GCCBuiltinSpecsDetectorTest extends TestCase { ResourceHelper.createFolder(project, "/misplaced/include3"); String loc = tmpPath.toString(); - GCCBuiltinSpecsDetector detector = new GCCBuiltinSpecsDetector(); + MockGCCBuiltinSpecsDetector detector = new MockGCCBuiltinSpecsDetector(); detector.startup(null); + detector.startupForLanguage(null); - detector.processLine(" "+loc+"/misplaced/include1"); - detector.processLine("#include \"...\" search starts here:"); - detector.processLine(" "+loc+"/local/include"); - detector.processLine("#include <...> search starts here:"); - detector.processLine(" "+loc+"/usr/include"); - detector.processLine(" "+loc+"/usr/include/../include2"); - detector.processLine(" "+loc+"/missing/folder"); - detector.processLine(" "+loc+"/Library/Frameworks (framework directory)"); - detector.processLine("End of search list."); - detector.processLine(" "+loc+"/misplaced/include2"); - detector.processLine("Framework search starts here:"); - detector.processLine(" "+loc+"/System/Library/Frameworks"); - detector.processLine("End of framework search list."); - detector.processLine(" "+loc+"/misplaced/include3"); + detector.processLine(" "+loc+"/misplaced/include1", null); + detector.processLine("#include \"...\" search starts here:", null); + detector.processLine(" "+loc+"/local/include", null); + detector.processLine("#include <...> search starts here:", null); + detector.processLine(" "+loc+"/usr/include", null); + detector.processLine(" "+loc+"/usr/include/../include2", null); + detector.processLine(" "+loc+"/missing/folder", null); + detector.processLine(" "+loc+"/Library/Frameworks (framework directory)", null); + detector.processLine("End of search list.", null); + detector.processLine(" "+loc+"/misplaced/include2", null); + detector.processLine("Framework search starts here:", null); + detector.processLine(" "+loc+"/System/Library/Frameworks", null); + detector.processLine("End of framework search list.", null); + detector.processLine(" "+loc+"/misplaced/include3", null); + detector.shutdownForLanguage(); detector.shutdown(); List entries = detector.getSettingEntries(null, null, null); - assertEquals(new CIncludePathEntry(loc+"/local/include", ICSettingEntry.LOCAL | ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), - entries.get(0)); - assertEquals(new CIncludePathEntry(loc+"/usr/include", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), - entries.get(1)); - assertEquals(new CIncludePathEntry(loc+"/usr/include2", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), - entries.get(2)); - assertEquals(new CIncludePathEntry(loc+"/missing/folder", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), - entries.get(3)); - assertEquals(new CIncludePathEntry(loc+"/Library/Frameworks", ICSettingEntry.FRAMEWORKS_MAC | ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), - entries.get(4)); - assertEquals(new CIncludePathEntry(loc+"/System/Library/Frameworks", ICSettingEntry.FRAMEWORKS_MAC | ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), - entries.get(5)); - assertEquals(6, entries.size()); + int index = 0; + assertEquals(new CIncludePathEntry(loc+"/local/include", ICSettingEntry.LOCAL | ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), entries.get(index++)); + assertEquals(new CIncludePathEntry(loc+"/usr/include", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), entries.get(index++)); + assertEquals(new CIncludePathEntry(loc+"/usr/include2", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), entries.get(index++)); + assertEquals(new CIncludePathEntry(loc+"/missing/folder", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), entries.get(index++)); + assertEquals(new CIncludePathEntry(loc+"/Library/Frameworks", ICSettingEntry.FRAMEWORKS_MAC | ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), entries.get(index++)); + assertEquals(new CIncludePathEntry(loc+"/System/Library/Frameworks", ICSettingEntry.FRAMEWORKS_MAC | ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), entries.get(index++)); + assertEquals(index, entries.size()); + } + + public void testGCCBuiltinSpecsDetector_Includes_WhiteSpaces() throws Exception { + String loc = ResourceHelper.createTemporaryFolder().toString(); + + MockGCCBuiltinSpecsDetector detector = new MockGCCBuiltinSpecsDetector(); + detector.startup(null); + detector.startupForLanguage(null); + + detector.processLine("#include \"...\" search starts here:", null); + detector.processLine(" \t "+loc+"/local/include", null); + detector.processLine("#include <...> search starts here:", null); + detector.processLine(loc+"/usr/include", null); + detector.processLine(" "+loc+"/Library/Frameworks \t (framework directory)", null); + detector.processLine("End of search list.", null); + detector.processLine("Framework search starts here:", null); + detector.processLine(" "+loc+"/System/Library/Frameworks \t ", null); + detector.processLine("End of framework search list.", null); + detector.shutdownForLanguage(); + detector.shutdown(); + + List entries = detector.getSettingEntries(null, null, null); + int index = 0; + assertEquals(new CIncludePathEntry(loc+"/local/include", ICSettingEntry.LOCAL | ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), entries.get(index++)); + assertEquals(new CIncludePathEntry(loc+"/usr/include", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), entries.get(index++)); + assertEquals(new CIncludePathEntry(loc+"/Library/Frameworks", ICSettingEntry.FRAMEWORKS_MAC | ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), entries.get(index++)); + assertEquals(new CIncludePathEntry(loc+"/System/Library/Frameworks", ICSettingEntry.FRAMEWORKS_MAC | ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), entries.get(index++)); + assertEquals(index, entries.size()); } public void testGCCBuiltinSpecsDetector_Includes_SymbolicLinkUp() throws Exception { @@ -694,18 +331,19 @@ public class GCCBuiltinSpecsDetectorTest extends TestCase { IPath linkPath = dir1.append("linked"); ResourceHelper.createSymbolicLink(linkPath, dir2); - AbstractBuiltinSpecsDetector detector = new GCCBuiltinSpecsDetector(); + MockGCCBuiltinSpecsDetector detector = new MockGCCBuiltinSpecsDetector(); detector.startup(null); - detector.processLine("#include <...> search starts here:"); - detector.processLine(" "+linkPath.toString()+"/.."); - detector.processLine("End of search list."); + detector.startupForLanguage(null); + detector.processLine("#include <...> search starts here:", null); + detector.processLine(" "+linkPath.toString()+"/..", null); + detector.processLine("End of search list.", null); + detector.shutdownForLanguage(); detector.shutdown(); // check populated entries List entries = detector.getSettingEntries(null, null, null); - CIncludePathEntry expected = new CIncludePathEntry(dir2.removeLastSegments(1), ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); - assertEquals(expected, entries.get(0)); + assertEquals(new CIncludePathEntry(dir2.removeLastSegments(1), ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), entries.get(0)); assertEquals(1, entries.size()); } @@ -720,19 +358,20 @@ public class GCCBuiltinSpecsDetectorTest extends TestCase { } assertTrue("windowsLocation=["+windowsLocation+"]", new Path(windowsLocation).getDevice()!=null); - AbstractBuiltinSpecsDetector detector = new GCCBuiltinSpecsDetectorCygwin(); + MockGCCBuiltinSpecsDetectorCygwin detector = new MockGCCBuiltinSpecsDetectorCygwin(); detector.startup(null); - detector.processLine("#include <...> search starts here:"); - detector.processLine(" /usr/include"); - detector.processLine("End of search list."); + detector.startupForLanguage(null); + detector.processLine("#include <...> search starts here:", null); + detector.processLine(" /usr/include", null); + detector.processLine("End of search list.", null); + detector.shutdownForLanguage(); detector.shutdown(); // check populated entries List entries = detector.getSettingEntries(null, null, null); assertEquals(new CIncludePathEntry(new Path(windowsLocation), ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), entries.get(0)); assertEquals(1, entries.size()); - } public void testGCCBuiltinSpecsDetector_Cygwin_Configuration() throws Exception { @@ -746,19 +385,20 @@ public class GCCBuiltinSpecsDetectorTest extends TestCase { } assertTrue("windowsLocation=["+windowsLocation+"]", new Path(windowsLocation).getDevice()!=null); - // Create model project and folders to test String projectName = getName(); IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; - AbstractBuiltinSpecsDetector detector = new GCCBuiltinSpecsDetectorCygwin(); + MockGCCBuiltinSpecsDetectorCygwin detector = new MockGCCBuiltinSpecsDetectorCygwin(); detector.startup(cfgDescription); - detector.processLine("#include <...> search starts here:"); - detector.processLine(" /usr/include"); - detector.processLine("End of search list."); + detector.startupForLanguage(null); + detector.processLine("#include <...> search starts here:", null); + detector.processLine(" /usr/include", null); + detector.processLine("End of search list.", null); + detector.shutdownForLanguage(); detector.shutdown(); // check populated entries diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ExternalBuildRunner.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ExternalBuildRunner.java index fbb9244be9e..36e2fb59281 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ExternalBuildRunner.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ExternalBuildRunner.java @@ -33,7 +33,6 @@ import org.eclipse.cdt.core.envvar.IEnvironmentVariable; import org.eclipse.cdt.core.envvar.IEnvironmentVariableManager; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; -import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager_TBD; import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySupport; import org.eclipse.cdt.core.model.ICModelMarker; import org.eclipse.cdt.core.resources.IConsole; @@ -134,11 +133,6 @@ public class ExternalBuildRunner extends AbstractBuildRunner { Map envMap = getEnvironment(builder); String[] env = getEnvStrings(envMap); - ICConfigurationDescription cfgDescription = ManagedBuildManager.getDescriptionForConfiguration(configuration); - if (kind!=IncrementalProjectBuilder.CLEAN_BUILD) { - ManagedBuildManager.runBuiltinSpecsDetectors(cfgDescription, workingDirectory, env, monitor); - } - consoleHeader[1] = configuration.getName(); consoleHeader[2] = project.getName(); buf.append(NEWLINE); @@ -213,14 +207,6 @@ public class ExternalBuildRunner extends AbstractBuildRunner { errMsg = launcher.getErrorMessage(); monitor.subTask(ManagedMakeMessages.getResourceString("MakeBuilder.Updating_project")); //$NON-NLS-1$ - // AG: FIXME -// try { -// LanguageSettingsManager.serialize(cfgDescription); -// } catch (CoreException e) { -// // TODO Auto-generated catch block -// e.printStackTrace(); -// } - try { // Do not allow the cancel of the refresh, since the builder is external // to Eclipse, files may have been created/modified and we will be out-of-sync. @@ -273,11 +259,6 @@ public class ExternalBuildRunner extends AbstractBuildRunner { consoleOut.close(); consoleErr.close(); cos.close(); - if (kind!=IncrementalProjectBuilder.CLEAN_BUILD) { - LanguageSettingsManager_TBD.serializeWorkspaceProviders(); - ICProjectDescription prjDescription = CCorePlugin.getDefault().getProjectDescription(project, false); - LanguageSettingsProvidersSerializer.serializeLanguageSettings(prjDescription); - } } } catch (Exception e) { ManagedBuilderCorePlugin.log(e); @@ -422,7 +403,7 @@ public class ExternalBuildRunner extends AbstractBuildRunner { if(clParserList.size() != 0){ IConsoleParser[] parsers = clParserList.toArray(new IConsoleParser[clParserList.size()]); - return new ConsoleOutputSniffer(outputStream, errorStream, parsers); + return new ConsoleOutputSniffer(outputStream, errorStream, parsers, epm); } return null; diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/InternalBuildRunner.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/InternalBuildRunner.java index 5e179f38444..949bd36d05c 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/InternalBuildRunner.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/InternalBuildRunner.java @@ -23,7 +23,6 @@ import org.eclipse.cdt.core.ConsoleOutputStream; import org.eclipse.cdt.core.ErrorParserManager; import org.eclipse.cdt.core.IMarkerGenerator; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; -import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager_TBD; import org.eclipse.cdt.core.model.ICModelMarker; import org.eclipse.cdt.core.resources.IConsole; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; @@ -159,9 +158,8 @@ public class InternalBuildRunner extends AbstractBuildRunner { } if (kind!=IncrementalProjectBuilder.CLEAN_BUILD) { + // TODO - AG - sanity check? elaborate ICConfigurationDescription cfgDescription = ManagedBuildManager.getDescriptionForConfiguration(configuration); - ManagedBuildManager.runBuiltinSpecsDetectors(cfgDescription, workingDirectory, env, monitor); - List providers = cfgDescription.getLanguageSettingProviders(); for (ILanguageSettingsProvider provider : providers) { if (provider instanceof AbstractBuildCommandParser) { @@ -248,11 +246,6 @@ public class InternalBuildRunner extends AbstractBuildRunner { consoleOutStream.flush(); epmOutputStream.close(); epmOutputStream = null; - if (kind!=IncrementalProjectBuilder.CLEAN_BUILD) { - LanguageSettingsManager_TBD.serializeWorkspaceProviders(); - ICProjectDescription prjDescription = CCorePlugin.getDefault().getProjectDescription(project, false); - LanguageSettingsProvidersSerializer.serializeLanguageSettings(prjDescription); - } // Generate any error markers that the build has discovered monitor.subTask(ManagedMakeMessages diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java index 6e833544aa8..f016158c2a4 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java @@ -49,14 +49,11 @@ import javax.xml.transform.stream.StreamResult; import org.eclipse.cdt.core.AbstractCExtension; import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.index.IIndexManager; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager_TBD; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModelUtil; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.parser.IScannerInfo; import org.eclipse.cdt.core.parser.IScannerInfoChangeListener; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; @@ -66,7 +63,6 @@ import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager; import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.core.settings.model.XmlStorageUtil; import org.eclipse.cdt.core.settings.model.extension.CConfigurationData; -import org.eclipse.cdt.make.core.MakeCorePlugin; import org.eclipse.cdt.managedbuilder.buildproperties.IBuildProperty; import org.eclipse.cdt.managedbuilder.buildproperties.IBuildPropertyManager; import org.eclipse.cdt.managedbuilder.envvar.IEnvironmentBuildPathsChangeListener; @@ -4804,52 +4800,4 @@ public class ManagedBuildManager extends AbstractCExtension { return false; } - /** - * TODO - better home? - */ - static public void runBuiltinSpecsDetectors(ICConfigurationDescription cfgDescription, IPath workingDirectory, - String[] env, IProgressMonitor monitor) { - IProject project = cfgDescription.getProjectDescription().getProject(); - List languageIds = LanguageSettingsManager.getLanguages(project, cfgDescription); - if (languageIds.isEmpty()) { - return; - } - - for (ILanguageSettingsProvider provider : cfgDescription.getLanguageSettingProviders()) { - ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); - if (rawProvider instanceof ILanguageSettingsBuiltinSpecsDetector) { - ILanguageSettingsBuiltinSpecsDetector detector = (ILanguageSettingsBuiltinSpecsDetector)rawProvider; - boolean isWorkspaceProvider = LanguageSettingsManager.isWorkspaceProvider(provider); - for (String languageId : languageIds) { - if (detector.getLanguageScope()==null || detector.getLanguageScope().contains(languageId)) { - try { - if (isWorkspaceProvider) { - detector.run((IProject)null, languageId, workingDirectory, env, monitor); - } else { - detector.run(cfgDescription, languageId, workingDirectory, env, monitor); - } - // detector.shutdown() is called from ConsoleOutputSniffer - } catch (Throwable e) { - IStatus status = new Status(IStatus.ERROR, MakeCorePlugin.PLUGIN_ID, "Internal error in BuiltinSpecsDetector "+detector.getId(), e); - MakeCorePlugin.log(status); - } - } - } - } - } - - - // AG: FIXME -// LanguageSettingsManager.serialize(cfgDescription); - // AG: FIXME - rather send event that ls settings changed - ICProject icProject = CoreModel.getDefault().create(project); - ICElement[] tuSelection = new ICElement[] {icProject}; - try { - CCorePlugin.getIndexManager().update(tuSelection, IIndexManager.UPDATE_ALL | IIndexManager.UPDATE_EXTERNAL_FILES_FOR_PROJECT); - } catch (CoreException e) { - IStatus status = new Status(IStatus.ERROR, ManagedBuilderCorePlugin.PLUGIN_ID, "Error updating CDT index", e); - ManagedBuilderCorePlugin.log(status); - } - } - } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/GCCBuiltinSpecsDetector.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/GCCBuiltinSpecsDetector.java index 82d2f92570b..0fe79bb509f 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/GCCBuiltinSpecsDetector.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/GCCBuiltinSpecsDetector.java @@ -17,7 +17,7 @@ import java.util.List; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsEditableProvider; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICSettingEntry; -import org.eclipse.cdt.make.core.scannerconfig.AbstractBuiltinSpecsDetector; +import org.eclipse.cdt.managedbuilder.scannerconfig.ToolchainBuiltinSpecsDetector; import org.eclipse.core.runtime.CoreException; /** @@ -25,8 +25,8 @@ import org.eclipse.core.runtime.CoreException; * to GCC toolchain {@code cdt.managedbuild.toolchain.gnu.base}. * */ -public class GCCBuiltinSpecsDetector extends AbstractBuiltinSpecsDetector implements ILanguageSettingsEditableProvider { - // must match the toolchain definition in org.eclipse.cdt.managedbuilder.core.buildDefinitions extension point +public class GCCBuiltinSpecsDetector extends ToolchainBuiltinSpecsDetector implements ILanguageSettingsEditableProvider { + // ID must match the toolchain definition in org.eclipse.cdt.managedbuilder.core.buildDefinitions extension point private static final String GCC_TOOLCHAIN_ID = "cdt.managedbuild.toolchain.gnu.base"; //$NON-NLS-1$ private enum State {NONE, EXPECTING_LOCAL_INCLUDE, EXPECTING_SYSTEM_INCLUDE, EXPECTING_FRAMEWORKS} @@ -37,8 +37,8 @@ public class GCCBuiltinSpecsDetector extends AbstractBuiltinSpecsDetector implem new IncludePathOptionParser("#include \"(\\S.*)\"", "$1", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY | ICSettingEntry.LOCAL), new IncludePathOptionParser("#include <(\\S.*)>", "$1", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), new IncludePathOptionParser("#framework <(\\S.*)>", "$1", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY | ICSettingEntry.FRAMEWORKS_MAC), - new MacroOptionParser("#define (\\S*\\(.*?\\)) *(.*)", "$1", "$2", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), - new MacroOptionParser("#define (\\S*) *(.*)", "$1", "$2", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), + new MacroOptionParser("#define\\s+(\\S*\\(.*?\\))\\s*(.*)", "$1", "$2", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), + new MacroOptionParser("#define\\s+(\\S*)\\s*(\\S*)", "$1", "$2", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), }; @Override diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/scannerconfig/ToolchainBuiltinSpecsDetector.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/scannerconfig/ToolchainBuiltinSpecsDetector.java new file mode 100644 index 00000000000..c8fb17ca9be --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/scannerconfig/ToolchainBuiltinSpecsDetector.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * Copyright (c) 2009, 2011 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.managedbuilder.scannerconfig; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.cdt.make.core.scannerconfig.AbstractBuiltinSpecsDetector; +import org.eclipse.cdt.managedbuilder.core.IInputType; +import org.eclipse.cdt.managedbuilder.core.ITool; +import org.eclipse.cdt.managedbuilder.core.IToolChain; +import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; +import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin; + +public abstract class ToolchainBuiltinSpecsDetector extends AbstractBuiltinSpecsDetector { + private Map toolMap = new HashMap(); + /** + * TODO + */ + protected abstract String getToolchainId(); + + private ITool getTool(String languageId) { + ITool langTool = toolMap.get(languageId); + if (langTool != null) { + return langTool; + } + + String toolchainId = getToolchainId(); + IToolChain toolchain = ManagedBuildManager.getExtensionToolChain(toolchainId); + if (toolchain != null) { + ITool[] tools = toolchain.getTools(); + for (ITool tool : tools) { + IInputType[] inputTypes = tool.getInputTypes(); + for (IInputType inType : inputTypes) { + String lang = inType.getLanguageId(tool); + if (languageId.equals(lang)) { + toolMap.put(languageId, tool); + return tool; + } + } + } + } + ManagedBuilderCorePlugin.error("Unable to find tool in toolchain="+toolchainId+" for language="+languageId); + return null; + } + + @Override + protected String getCompilerCommand(String languageId) { + ITool tool = getTool(languageId); + String compiler = tool.getToolCommand(); + if (compiler.length() == 0) { + String msg = "Unable to find compiler command in toolchain="+getToolchainId(); + ManagedBuilderCorePlugin.error(msg); + } + return compiler; + } + + @Override + protected String getSpecFileExtension(String languageId) { + String ext = null; + ITool tool = getTool(languageId); + String[] srcFileExtensions = tool.getAllInputExtensions(); + if (srcFileExtensions != null && srcFileExtensions.length > 0) { + ext = srcFileExtensions[0]; + } + if (ext == null || ext.length() == 0) { + ManagedBuilderCorePlugin.error("Unable to find file extension for language "+languageId); + } + return ext; + } + +} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java index c4ea03d986b..d9e92b444b4 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java @@ -584,13 +584,10 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { } /** - * Shallow clone of the provider. "Shallow" is defined here as the exact copy except that - * the copy will have zero language settings entries. - * - * @return shallow copy of the provider. - * @throws CloneNotSupportedException in case {@link #clone()} throws the exception. + * See {@link #cloneShallow()}. This method is extracted + * to avoid expressing {@link #clone()} via {@link #cloneShallow()}. */ - protected LanguageSettingsSerializable cloneShallow() throws CloneNotSupportedException { + private LanguageSettingsSerializable cloneShallowInternal() throws CloneNotSupportedException { LanguageSettingsSerializable clone = (LanguageSettingsSerializable)super.clone(); if (languageScope!=null) clone.languageScope = new ArrayList(languageScope); @@ -599,9 +596,20 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { return clone; } + /** + * Shallow clone of the provider. "Shallow" is defined here as the exact copy except that + * the copy will have zero language settings entries. + * + * @return shallow copy of the provider. + * @throws CloneNotSupportedException in case {@link #clone()} throws the exception. + */ + protected LanguageSettingsSerializable cloneShallow() throws CloneNotSupportedException { + return cloneShallowInternal(); + } + @Override protected LanguageSettingsSerializable clone() throws CloneNotSupportedException { - LanguageSettingsSerializable clone = cloneShallow(); + LanguageSettingsSerializable clone = cloneShallowInternal(); clone.fStorage = cloneStorage(); return clone; } diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/ConsoleOutputSniffer.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/ConsoleOutputSniffer.java index 85d1dc3c62b..636fe70164e 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/ConsoleOutputSniffer.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/ConsoleOutputSniffer.java @@ -130,6 +130,8 @@ public class ConsoleOutputSniffer { private OutputStream consoleErrorStream; private IConsoleParser[] parsers; + private ErrorParserManager errorParserManager = null; + public ConsoleOutputSniffer(IConsoleParser[] parsers) { this.parsers = parsers; } @@ -140,6 +142,11 @@ public class ConsoleOutputSniffer { this.consoleErrorStream = errorStream; } + public ConsoleOutputSniffer(OutputStream outputStream, OutputStream errorStream, IConsoleParser[] parsers, ErrorParserManager epm) { + this(outputStream, errorStream, parsers); + this.errorParserManager = epm; + } + /** * Returns an output stream that will be sniffed. * This stream should be hooked up so the command @@ -188,10 +195,10 @@ public class ConsoleOutputSniffer { private synchronized void processLine(String line) { for (IConsoleParser parser : parsers) { try { - if (consoleOutputStream instanceof ErrorParserManager && parser instanceof IErrorParser ) { + if (parser instanceof IErrorParser) { // IErrorParser interface is used here only with purpose to pass ErrorParserManager // which keeps track of CWD and provides useful methods for locating files - ((IErrorParser)parser).processLine(line, (ErrorParserManager) consoleOutputStream); + ((IErrorParser)parser).processLine(line, errorParserManager); } else { parser.processLine(line); } diff --git a/xlc/org.eclipse.cdt.managedbuilder.xlc.core/src/org/eclipse/cdt/managedbuilder/xlc/core/XlcBuiltinSpecsDetector.java b/xlc/org.eclipse.cdt.managedbuilder.xlc.core/src/org/eclipse/cdt/managedbuilder/xlc/core/XlcBuiltinSpecsDetector.java index 5e1075551cc..b2fc7ca939d 100644 --- a/xlc/org.eclipse.cdt.managedbuilder.xlc.core/src/org/eclipse/cdt/managedbuilder/xlc/core/XlcBuiltinSpecsDetector.java +++ b/xlc/org.eclipse.cdt.managedbuilder.xlc.core/src/org/eclipse/cdt/managedbuilder/xlc/core/XlcBuiltinSpecsDetector.java @@ -18,7 +18,7 @@ import java.util.regex.Pattern; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsEditableProvider; import org.eclipse.cdt.core.settings.model.ICSettingEntry; -import org.eclipse.cdt.make.core.scannerconfig.AbstractBuiltinSpecsDetector; +import org.eclipse.cdt.managedbuilder.scannerconfig.ToolchainBuiltinSpecsDetector; /** @@ -38,7 +38,7 @@ rm /tmp/xlcW2lt4Jic * to GCC toolchain {@code cdt.managedbuild.toolchain.gnu.base}. * */ -public class XlcBuiltinSpecsDetector extends AbstractBuiltinSpecsDetector implements ILanguageSettingsEditableProvider { +public class XlcBuiltinSpecsDetector extends ToolchainBuiltinSpecsDetector implements ILanguageSettingsEditableProvider { // must match the toolchain definition in org.eclipse.cdt.managedbuilder.core.buildDefinitions extension point // FIXME - ill defined XLC toolchain // private static final String XLC_TOOLCHAIN_ID = "cdt.managedbuild.toolchain.xlc.exe.debug"; //$NON-NLS-1$ From babba4a0a73ebdda234573c6a8fed844ff452abd Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Sun, 30 Oct 2011 14:41:02 -0400 Subject: [PATCH 051/120] AbstractBuiltinSpecsDetector to execute() on registering, no more IResourceChangeListener --- .../AbstractBuiltinSpecsDetector.java | 46 ++----------------- .../LanguageSettingsProvidersSerializer.java | 6 +++ 2 files changed, 9 insertions(+), 43 deletions(-) diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java index 96b3f81536c..02ac1c74c7d 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java @@ -49,9 +49,6 @@ import org.eclipse.cdt.utils.PathUtil; import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceChangeEvent; -import org.eclipse.core.resources.IResourceChangeListener; -import org.eclipse.core.resources.IResourceDelta; import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; @@ -70,8 +67,7 @@ import org.eclipse.core.runtime.jobs.ISchedulingRule; import org.eclipse.core.runtime.jobs.Job; import org.w3c.dom.Element; -public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSettingsOutputScanner - implements ICListenerRegisterer, IResourceChangeListener { +public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSettingsOutputScanner implements ICListenerRegisterer { private static final int TICKS_STREAM_MONITOR = 100; private static final int TICKS_CLEAN_MARKERS = 1; private static final int TICKS_RUN_FOR_ONE_LANGUAGE = 10; @@ -241,55 +237,19 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti public void registerListener(ICConfigurationDescription cfgDescription) { currentCfgDescription = cfgDescription; - ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_BUILD); // TODO - remove me CCorePlugin.log(new Status(IStatus.INFO,CCorePlugin.PLUGIN_ID, getPrefixForLog() + "Added listener [" + System.identityHashCode(this) + "] " + this)); + + execute(); } public void unregisterListener() { - ResourcesPlugin.getWorkspace().removeResourceChangeListener(this); // TODO - remove me CCorePlugin.log(new Status(IStatus.INFO,CCorePlugin.PLUGIN_ID, getPrefixForLog() + "Removed listener [" + System.identityHashCode(this) + "] " + this)); } - private String eventToString(IResourceChangeEvent event) { - String strType = null; - IResource rc = null; - if (event != null) { - int type = event.getType(); - switch (type) { - case IResourceChangeEvent.POST_CHANGE: strType = "POST_CHANGE";break; - case IResourceChangeEvent.PRE_CLOSE: strType = "PRE_CLOSE";break; - case IResourceChangeEvent.PRE_DELETE: strType = "PRE_DELETE";break; - case IResourceChangeEvent.PRE_BUILD: strType = "PRE_BUILD";break; - case IResourceChangeEvent.POST_BUILD: strType = "POST_BUILD";break; - case IResourceChangeEvent.PRE_REFRESH: strType = "PRE_REFRESH";break; - default: strType = "unknown";break; - } - strType += "=" + Integer.toHexString(type); - - IResourceDelta delta = event.getDelta(); - rc = delta!=null ? delta.getResource() : null; - } - String result = "Event " + strType + ", " + rc; - return result; - } - - public void resourceChanged(IResourceChangeEvent event) { - System.out.println(eventToString(event)); - - // if (event.getType() != IResourceChangeEvent.PRE_BUILD) - // return; - // - // IResourceDelta delta = event.getDelta(); - // delta.getKind(); - // delta.getFlags(); - - execute(); - } - protected void execute() { if (isExecuted) { // // TODO - remove me diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java index 0da61e95916..1e5852a9194 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java @@ -41,12 +41,15 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.ILock; import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.InstanceScope; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class LanguageSettingsProvidersSerializer { + private static final String PREFERENCE_WORSPACE_PROVIDERS_SET = "language.settings.providers.set.for.workspace"; 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_LANGUAGE_SETTINGS = "language.settings.xml"; //$NON-NLS-1$ @@ -199,6 +202,9 @@ public class LanguageSettingsProvidersSerializer { public static void setWorkspaceProviders(List providers) throws CoreException { setWorkspaceProvidersInternal(providers); serializeLanguageSettingsWorkspace(); + // generate preference change event + IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(CCorePlugin.PLUGIN_ID); + prefs.putBoolean(PREFERENCE_WORSPACE_PROVIDERS_SET, ! prefs.getBoolean(PREFERENCE_WORSPACE_PROVIDERS_SET, false)); } /** From 5fffd285f0e4843de916df4a9d6b9e9ce89e5cd6 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Sun, 30 Oct 2011 00:46:14 -0400 Subject: [PATCH 052/120] ILanguageSettingsChangeEvent notifications --- .../LanguageSettingsListenersTests.java | 569 ++++++++++++++++++ .../LanguageSettingsManagerTests.java | 10 +- .../MockLanguageSettingsEditableProvider.java | 4 + .../providers/LanguageSettingsManager.java | 6 +- .../LanguageSettingsManager_TBD.java | 6 - .../LanguageSettingsSerializable.java | 354 ++--------- .../LanguageSettingsSerializableEditable.java | 3 +- .../model/ICConfigurationDescription.java | 2 + .../ILanguageSettingsChangeEvent.java | 36 ++ .../ILanguageSettingsChangeListener.java | 22 + .../providers/LanguageSettingsDelta.java | 155 +++++ .../LanguageSettingsExtensionManager.java | 273 --------- .../LanguageSettingsProvidersSerializer.java | 485 ++++++++++++++- .../LanguageSettingsScannerInfoProvider.java | 10 +- .../providers/LanguageSettingsStorage.java | 378 ++++++++++++ .../model/CConfigurationSpecSettings.java | 46 ++ .../pdom/LanguageSettingsChangeListener.java | 77 +++ .../cdt/internal/core/pdom/PDOMManager.java | 5 + .../providers/LanguageSettingsEntriesTab.java | 25 - .../LanguageSettingsProviderTab.java | 29 - 20 files changed, 1826 insertions(+), 669 deletions(-) create mode 100644 core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/ILanguageSettingsChangeEvent.java create mode 100644 core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/ILanguageSettingsChangeListener.java create mode 100644 core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsDelta.java create mode 100644 core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsStorage.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/LanguageSettingsChangeListener.java diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsListenersTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsListenersTests.java index 7a527624432..b17b0351b8a 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsListenersTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsListenersTests.java @@ -18,9 +18,14 @@ import junit.framework.TestCase; import junit.framework.TestSuite; import org.eclipse.cdt.core.model.CoreModel; +import org.eclipse.cdt.core.settings.model.CMacroEntry; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.core.testplugin.ResourceHelper; +import org.eclipse.cdt.internal.core.language.settings.providers.ILanguageSettingsChangeEvent; +import org.eclipse.cdt.internal.core.language.settings.providers.ILanguageSettingsChangeListener; +import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer; import org.eclipse.core.resources.IProject; /** @@ -29,12 +34,38 @@ import org.eclipse.core.resources.IProject; public class LanguageSettingsListenersTests extends TestCase { // Must match provider id defined as extension point private static final String EXTENSION_REGISTERER_PROVIDER_ID = "org.eclipse.cdt.core.tests.language.settings.listener.registerer.provider"; + private static final String EXTENSION_EDITABLE_PROVIDER_ID = "org.eclipse.cdt.core.tests.custom.editable.language.settings.provider"; private static final String PROVIDER_1 = "test.provider.1.id"; private static final String PROVIDER_NAME_1 = "test.provider.1.name"; private static final String PROVIDER_CUSTOM_GLOBAL = "test.provider.custom.global.id"; private static final String PROVIDER_CUSTOM_GLOBAL_NAME = "test.provider.custom.global.name"; + private static final CMacroEntry SAMPLE_LSE = new CMacroEntry("MACRO", "value",0); + private class MockLanguageSettingsChangeListener implements ILanguageSettingsChangeListener { + private int count = 0; + private ILanguageSettingsChangeEvent lastEvent = null; + + public void handleEvent(ILanguageSettingsChangeEvent event) { + count++; + lastEvent = event; + } + + public int getCount() { + return count; + } + + public void resetCount() { + count = 0; + lastEvent = null; + } + + public ILanguageSettingsChangeEvent getLastEvent() { + return lastEvent; + } + } + private MockLanguageSettingsChangeListener mockLseListener = new MockLanguageSettingsChangeListener(); + /** * Constructor. * @param name - name of the test. @@ -50,6 +81,7 @@ public class LanguageSettingsListenersTests extends TestCase { @Override protected void tearDown() throws Exception { + LanguageSettingsProvidersSerializer.unregisterLanguageSettingsChangeListener(mockLseListener); LanguageSettingsManager.setWorkspaceProviders(null); ResourceHelper.cleanUp(); } @@ -489,6 +521,543 @@ public class LanguageSettingsListenersTests extends TestCase { } } + /** + */ + public void testNotification_cfgProvider_AddEmptyProvider() throws Exception { + IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName()); + // First clear default providers + { + // get project descriptions + ICProjectDescription writableProjDescription = CoreModel.getDefault().getProjectDescription(project); + assertNotNull(writableProjDescription); + ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); + assertEquals(1, cfgDescriptions.length); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + // clear providers + List providers = new ArrayList(); + cfgDescription.setLanguageSettingProviders(providers); + List storedProviders = cfgDescription.getLanguageSettingProviders(); + assertEquals(0, storedProviders.size()); + + // write to project description + CoreModel.getDefault().setProjectDescription(project, writableProjDescription); + } + + // register mock listener to inspect the notifications + LanguageSettingsProvidersSerializer.registerLanguageSettingsChangeListener(mockLseListener); + assertEquals(0, mockLseListener.getCount()); + assertEquals(null, mockLseListener.getLastEvent()); + + // Add empty provider + { + // get project descriptions + ICProjectDescription writableProjDescription = CoreModel.getDefault().getProjectDescription(project); + assertNotNull(writableProjDescription); + ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); + assertEquals(1, cfgDescriptions.length); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + // create a provider and add to cfgDescription + ILanguageSettingsProvider mockProvider = new MockLanguageSettingsEditableProvider(PROVIDER_1, PROVIDER_NAME_1); + List providers = new ArrayList(); + providers.add(mockProvider); + cfgDescription.setLanguageSettingProviders(providers); + List storedProviders = cfgDescription.getLanguageSettingProviders(); + assertEquals(1, storedProviders.size()); + + // write to project description + CoreModel.getDefault().setProjectDescription(project, writableProjDescription); + } + + // No notifications expected + assertEquals(0, mockLseListener.getCount()); + assertEquals(null, mockLseListener.getLastEvent()); + } + + /** + */ + public void testNotification_cfgProvider_AddNonEmptyProvider() throws Exception { + IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName()); + // First clear default providers + { + // get project descriptions + ICProjectDescription writableProjDescription = CoreModel.getDefault().getProjectDescription(project); + assertNotNull(writableProjDescription); + ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); + assertEquals(1, cfgDescriptions.length); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + // clear providers + List providers = new ArrayList(); + cfgDescription.setLanguageSettingProviders(providers); + List storedProviders = cfgDescription.getLanguageSettingProviders(); + assertEquals(0, storedProviders.size()); + + // write to project description + CoreModel.getDefault().setProjectDescription(project, writableProjDescription); + } + + // register mock listener to inspect the notifications + LanguageSettingsProvidersSerializer.registerLanguageSettingsChangeListener(mockLseListener); + assertEquals(0, mockLseListener.getCount()); + assertEquals(null, mockLseListener.getLastEvent()); + + // Add non-empty provider + { + // get project descriptions + ICProjectDescription writableProjDescription = CoreModel.getDefault().getProjectDescription(project); + assertNotNull(writableProjDescription); + ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); + assertEquals(1, cfgDescriptions.length); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + String cfgDescriptionId = cfgDescription.getId(); + + // create a provider and add entries + MockLanguageSettingsEditableProvider mockProvider = new MockLanguageSettingsEditableProvider(PROVIDER_1, PROVIDER_NAME_1); + List entries = new ArrayList(); + entries.add(SAMPLE_LSE); + mockProvider.setSettingEntries(cfgDescription, project, null, entries); + List providers = new ArrayList(); + providers.add(mockProvider); + cfgDescription.setLanguageSettingProviders(providers); + List storedProviders = cfgDescription.getLanguageSettingProviders(); + assertEquals(1, storedProviders.size()); + + // write to project description + CoreModel.getDefault().setProjectDescription(project, writableProjDescription); + + // 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]); + assertEquals(1, event.getResources(cfgDescriptionId).length); + assertEquals(project, event.getResources(cfgDescriptionId)[0]); + } + } + + /** + */ + public void testNotification_cfgProvider_SerializeEntries() throws Exception { + IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName()); + + // add the mock provider + { + // get project descriptions + ICProjectDescription writableProjDescription = CoreModel.getDefault().getProjectDescription(project); + assertNotNull(writableProjDescription); + ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); + assertEquals(1, cfgDescriptions.length); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + // create a provider and add to cfgDescription + List providers = new ArrayList(); + providers.add(new MockLanguageSettingsEditableProvider(PROVIDER_1, PROVIDER_NAME_1)); + cfgDescription.setLanguageSettingProviders(providers); + List storedProviders = cfgDescription.getLanguageSettingProviders(); + assertEquals(1, storedProviders.size()); + + // write to project description + CoreModel.getDefault().setProjectDescription(project, writableProjDescription); + } + + // register mock listener to inspect the notifications + LanguageSettingsProvidersSerializer.registerLanguageSettingsChangeListener(mockLseListener); + assertEquals(0, mockLseListener.getCount()); + assertEquals(null, mockLseListener.getLastEvent()); + + // Change the provider's entries + { + // get project descriptions + ICProjectDescription prjDescription = CoreModel.getDefault().getProjectDescription(project, false); + assertNotNull(prjDescription); + ICConfigurationDescription[] cfgDescriptions = prjDescription.getConfigurations(); + assertEquals(1, cfgDescriptions.length); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + String cfgDescriptionId = cfgDescription.getId(); + + // Add entries + List entries = new ArrayList(); + entries.add(SAMPLE_LSE); + List providers = cfgDescription.getLanguageSettingProviders(); + assertEquals(1, providers.size()); + assertTrue(providers.get(0) instanceof MockLanguageSettingsEditableProvider); + MockLanguageSettingsEditableProvider mockProvider = (MockLanguageSettingsEditableProvider) providers.get(0); + mockProvider.setSettingEntries(cfgDescription, project, null, entries); + assertEquals(0, mockLseListener.getCount()); + assertEquals(null, mockLseListener.getLastEvent()); + + // Serialize settings + LanguageSettingsProvidersSerializer.serializeLanguageSettings(prjDescription); + // inspect event + 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]); + assertEquals(1, event.getResources(cfgDescriptionId).length); + assertEquals(project, event.getResources(cfgDescriptionId)[0]); + // TODO - drill to the entries + } + } + + /** + */ + public void testNotification_cfgProvider_SerializeEntriesConcurrent() throws Exception { + IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName()); + + // add the mock provider + { + // get project descriptions + ICProjectDescription writableProjDescription = CoreModel.getDefault().getProjectDescription(project); + assertNotNull(writableProjDescription); + ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); + assertEquals(1, cfgDescriptions.length); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + // create a provider and add to cfgDescription + List providers = new ArrayList(); + providers.add(new MockLanguageSettingsEditableProvider(PROVIDER_1, PROVIDER_NAME_1)); + cfgDescription.setLanguageSettingProviders(providers); + List storedProviders = cfgDescription.getLanguageSettingProviders(); + assertEquals(1, storedProviders.size()); + + // write to project description + CoreModel.getDefault().setProjectDescription(project, writableProjDescription); + } + + // register mock listener to inspect the notifications + LanguageSettingsProvidersSerializer.registerLanguageSettingsChangeListener(mockLseListener); + assertEquals(0, mockLseListener.getCount()); + assertEquals(null, mockLseListener.getLastEvent()); + + // Change the provider's entries concurrently + + // get project descriptions + ICProjectDescription prjDescription_1 = CoreModel.getDefault().getProjectDescription(project, false); + assertNotNull(prjDescription_1); + ICProjectDescription prjDescription_2 = CoreModel.getDefault().getProjectDescription(project, false); + assertNotNull(prjDescription_2); + { + ICConfigurationDescription[] cfgDescriptions = prjDescription_1.getConfigurations(); + assertEquals(1, cfgDescriptions.length); + ICConfigurationDescription cfgDescriptionWritable = cfgDescriptions[0]; + String cfgDescriptionId = cfgDescriptionWritable.getId(); + + // Add entries + List entries = new ArrayList(); + entries.add(SAMPLE_LSE); + List providers = cfgDescriptionWritable.getLanguageSettingProviders(); + assertEquals(1, providers.size()); + assertTrue(providers.get(0) instanceof MockLanguageSettingsEditableProvider); + MockLanguageSettingsEditableProvider mockProvider = (MockLanguageSettingsEditableProvider) providers.get(0); + mockProvider.setSettingEntries(cfgDescriptionWritable, project, null, entries); + + // reset count + mockLseListener.resetCount(); + assertEquals(0, mockLseListener.getCount()); + assertNull(mockLseListener.getLastEvent()); + + // Serialize settings + LanguageSettingsProvidersSerializer.serializeLanguageSettings(prjDescription_1); + // inspect event + 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]); + assertEquals(1, event.getResources(cfgDescriptionId).length); + assertEquals(project, event.getResources(cfgDescriptionId)[0]); + // TODO - drill to the entries + } + { + ICConfigurationDescription[] cfgDescriptions = prjDescription_2.getConfigurations(); + assertEquals(1, cfgDescriptions.length); + ICConfigurationDescription cfgDescriptionWritable = cfgDescriptions[0]; + String cfgDescriptionId = cfgDescriptionWritable.getId(); + + // Add same entries + List entries = new ArrayList(); + entries.add(SAMPLE_LSE); + List providers = cfgDescriptionWritable.getLanguageSettingProviders(); + assertEquals(1, providers.size()); + assertTrue(providers.get(0) instanceof MockLanguageSettingsEditableProvider); + MockLanguageSettingsEditableProvider mockProvider = (MockLanguageSettingsEditableProvider) providers.get(0); + mockProvider.setSettingEntries(cfgDescriptionWritable, project, null, entries); + + // reset count + mockLseListener.resetCount(); + assertEquals(0, mockLseListener.getCount()); + assertNull(mockLseListener.getLastEvent()); + + // Serialize settings + LanguageSettingsProvidersSerializer.serializeLanguageSettings(prjDescription_2); + // inspect event + assertEquals(0, mockLseListener.getCount()); + ILanguageSettingsChangeEvent event = mockLseListener.getLastEvent(); + assertNull(event); + } + } + + /** + */ + public void testNotification_globalProvider_AddEmptyProvider() throws Exception { + IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName()); + // First clear default providers + { + // get project descriptions + ICProjectDescription writableProjDescription = CoreModel.getDefault().getProjectDescription(project); + assertNotNull(writableProjDescription); + ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); + assertEquals(1, cfgDescriptions.length); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + // clear providers + List providers = new ArrayList(); + cfgDescription.setLanguageSettingProviders(providers); + List storedProviders = cfgDescription.getLanguageSettingProviders(); + assertEquals(0, storedProviders.size()); + + // write to project description + CoreModel.getDefault().setProjectDescription(project, writableProjDescription); + } + + // register mock listener to inspect the notifications + LanguageSettingsProvidersSerializer.registerLanguageSettingsChangeListener(mockLseListener); + assertEquals(0, mockLseListener.getCount()); + assertEquals(null, mockLseListener.getLastEvent()); + + // Add empty global provider + { + // get project descriptions + ICProjectDescription writableProjDescription = CoreModel.getDefault().getProjectDescription(project); + assertNotNull(writableProjDescription); + ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); + assertEquals(1, cfgDescriptions.length); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + // retrieve a global provider + ILanguageSettingsProvider wspProvider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_EDITABLE_PROVIDER_ID); + assertNotNull(wspProvider); + ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(wspProvider); + assertTrue(rawProvider instanceof MockLanguageSettingsEditableProvider); + // clear it + ((MockLanguageSettingsEditableProvider) rawProvider).clear(); + assertEquals(null, wspProvider.getSettingEntries(cfgDescription, project, null)); + // add the provider to cfgDescription + List providers = new ArrayList(); + providers.add(wspProvider); + cfgDescription.setLanguageSettingProviders(providers); + List storedProviders = cfgDescription.getLanguageSettingProviders(); + assertEquals(1, storedProviders.size()); + + // write to project description + CoreModel.getDefault().setProjectDescription(project, writableProjDescription); + } + + // No notifications expected + assertEquals(0, mockLseListener.getCount()); + assertEquals(null, mockLseListener.getLastEvent()); + } + + /** + */ + public void testNotification_globalProvider_AddNonEmptyProvider() throws Exception { + IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName()); + // First clear default providers + { + // get project descriptions + ICProjectDescription writableProjDescription = CoreModel.getDefault().getProjectDescription(project); + assertNotNull(writableProjDescription); + ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); + assertEquals(1, cfgDescriptions.length); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + // clear providers + List providers = new ArrayList(); + cfgDescription.setLanguageSettingProviders(providers); + List storedProviders = cfgDescription.getLanguageSettingProviders(); + assertEquals(0, storedProviders.size()); + + // write to project description + CoreModel.getDefault().setProjectDescription(project, writableProjDescription); + } + + // register mock listener to inspect the notifications + LanguageSettingsProvidersSerializer.registerLanguageSettingsChangeListener(mockLseListener); + assertEquals(0, mockLseListener.getCount()); + assertEquals(null, mockLseListener.getLastEvent()); + + // Add non-empty provider + { + // get project descriptions + ICProjectDescription writableProjDescription = CoreModel.getDefault().getProjectDescription(project); + assertNotNull(writableProjDescription); + ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); + assertEquals(1, cfgDescriptions.length); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + 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 entries = new ArrayList(); + 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 providers = new ArrayList(); + providers.add(wspProvider); + cfgDescription.setLanguageSettingProviders(providers); + List storedProviders = cfgDescription.getLanguageSettingProviders(); + assertEquals(1, storedProviders.size()); + + // write to project description + CoreModel.getDefault().setProjectDescription(project, writableProjDescription); + + // 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]); + assertEquals(1, event.getResources(cfgDescriptionId).length); + assertEquals(project, event.getResources(cfgDescriptionId)[0]); + } + } + + /** + */ + public void testNotification_globalProvider_SerializeEntries() throws Exception { + IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName()); + + // register mock listener to inspect the notifications + LanguageSettingsProvidersSerializer.registerLanguageSettingsChangeListener(mockLseListener); + + // Add empty global provider + { + // get project descriptions + ICProjectDescription writableProjDescription = CoreModel.getDefault().getProjectDescription(project); + assertNotNull(writableProjDescription); + ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); + assertEquals(1, cfgDescriptions.length); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + // retrieve a global provider + ILanguageSettingsProvider wspProvider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_EDITABLE_PROVIDER_ID); + assertNotNull(wspProvider); + ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(wspProvider); + assertTrue(rawProvider instanceof MockLanguageSettingsEditableProvider); + // clear it + ((MockLanguageSettingsEditableProvider) rawProvider).clear(); + assertEquals(null, wspProvider.getSettingEntries(cfgDescription, project, null)); + // add the provider to cfgDescription + List providers = new ArrayList(); + providers.add(wspProvider); + cfgDescription.setLanguageSettingProviders(providers); + List storedProviders = cfgDescription.getLanguageSettingProviders(); + assertEquals(1, storedProviders.size()); + + // write to project description + CoreModel.getDefault().setProjectDescription(project, writableProjDescription); + } + + // Change the provider's entries + { + // 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 entries = new ArrayList(); + entries.add(SAMPLE_LSE); + ((MockLanguageSettingsEditableProvider) rawProvider).setSettingEntries(null, project, null, entries); + assertEquals(SAMPLE_LSE, wspProvider.getSettingEntries(null, project, null).get(0)); + + // reset count + mockLseListener.resetCount(); + assertEquals(0, mockLseListener.getCount()); + assertEquals(null, mockLseListener.getLastEvent()); + + // Serialize settings + LanguageSettingsProvidersSerializer.serializeLanguageSettingsWorkspace(); + + // get cfgDescriptionId + ICProjectDescription prjDescription = CoreModel.getDefault().getProjectDescription(project, false); + assertNotNull(prjDescription); + ICConfigurationDescription[] cfgDescriptions = prjDescription.getConfigurations(); + assertEquals(1, cfgDescriptions.length); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + String cfgDescriptionId = cfgDescription.getId(); + + // inspect event + 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]); + assertEquals(1, event.getResources(cfgDescriptionId).length); + assertEquals(project, event.getResources(cfgDescriptionId)[0]); + // TODO - drill to the entries + } + // Change the provider's entries back (bug was found for this case) + { + // retrieve a global provider + ILanguageSettingsProvider wspProvider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_EDITABLE_PROVIDER_ID); + assertNotNull(wspProvider); + ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(wspProvider); + assertTrue(rawProvider instanceof MockLanguageSettingsEditableProvider); + // clear the provider again + ((MockLanguageSettingsEditableProvider) rawProvider).clear(); + + // reset count + mockLseListener.resetCount(); + assertEquals(0, mockLseListener.getCount()); + assertEquals(null, mockLseListener.getLastEvent()); + + // Serialize settings + LanguageSettingsProvidersSerializer.serializeLanguageSettingsWorkspace(); + + // get cfgDescriptionId + ICProjectDescription prjDescription = CoreModel.getDefault().getProjectDescription(project, false); + assertNotNull(prjDescription); + ICConfigurationDescription[] cfgDescriptions = prjDescription.getConfigurations(); + assertEquals(1, cfgDescriptions.length); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + String cfgDescriptionId = cfgDescription.getId(); + + // inspect event + 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]); + assertEquals(1, event.getResources(cfgDescriptionId).length); + assertEquals(project, event.getResources(cfgDescriptionId)[0]); + // TODO - drill to the entries + } + } + } diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java index d6732472b4b..243252ea99c 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java @@ -28,7 +28,7 @@ import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.core.testplugin.CModelMock; import org.eclipse.cdt.core.testplugin.ResourceHelper; -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.settings.model.CConfigurationDescription; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; @@ -561,7 +561,7 @@ public class LanguageSettingsManagerTests extends TestCase { { // retrieve local entries - List includes = LanguageSettingsExtensionManager + List includes = LanguageSettingsProvidersSerializer .getLocalSettingEntriesByKind(cfgDescription, FILE_0, LANG_ID, ICSettingEntry.INCLUDE_PATH); assertEquals(localIncludeEntry, includes.get(0)); assertEquals(1, includes.size()); @@ -569,7 +569,7 @@ public class LanguageSettingsManagerTests extends TestCase { { // retrieve system entries - List includes = LanguageSettingsExtensionManager + List includes = LanguageSettingsProvidersSerializer .getSystemSettingEntriesByKind(cfgDescription, FILE_0, LANG_ID, ICSettingEntry.INCLUDE_PATH); assertEquals(systemIncludeEntry, includes.get(0)); assertEquals(1, includes.size()); @@ -577,7 +577,7 @@ public class LanguageSettingsManagerTests extends TestCase { { // retrieve both local and system - List includes = LanguageSettingsExtensionManager + List includes = LanguageSettingsProvidersSerializer .getSettingEntriesByKind(cfgDescription, FILE_0, LANG_ID, ICSettingEntry.INCLUDE_PATH); assertEquals(entries.get(0), includes.get(0)); assertEquals(entries.get(1), includes.get(1)); @@ -799,7 +799,7 @@ public class LanguageSettingsManagerTests extends TestCase { LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); provider.setSettingEntries(null, file, null, entries); // build the hierarchy - LanguageSettingsExtensionManager.buildResourceTree(provider, null, null, project); + LanguageSettingsProvidersSerializer.buildResourceTree(provider, null, null, project); // check that entries go to highest possible level assertEquals(entries, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file, null)); diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockLanguageSettingsEditableProvider.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockLanguageSettingsEditableProvider.java index 7c8c9eaf9dc..32b907c017b 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockLanguageSettingsEditableProvider.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockLanguageSettingsEditableProvider.java @@ -19,6 +19,10 @@ public class MockLanguageSettingsEditableProvider extends LanguageSettingsSerial super(); } + public MockLanguageSettingsEditableProvider(String id, String name) { + super(id, name); + } + public MockLanguageSettingsEditableProvider cloneShallow() throws CloneNotSupportedException { return (MockLanguageSettingsEditableProvider) super.cloneShallow(); } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java index fd630a320d6..09d6bb1c910 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java @@ -54,7 +54,7 @@ public class LanguageSettingsManager { * although individual providers return {@code null} if no settings defined. */ public static List getSettingEntriesUpResourceTree(ILanguageSettingsProvider provider, ICConfigurationDescription cfgDescription, IResource rc, String languageId) { - return LanguageSettingsExtensionManager.getSettingEntriesUpResourceTree(provider, cfgDescription, rc, languageId); + return LanguageSettingsProvidersSerializer.getSettingEntriesUpResourceTree(provider, cfgDescription, rc, languageId); } /** @@ -71,7 +71,7 @@ public class LanguageSettingsManager { * @param project - the project which is considered the root of the resource tree. */ public static void buildResourceTree(LanguageSettingsSerializable provider, ICConfigurationDescription cfgDescription, String languageId, IProject project) { - LanguageSettingsExtensionManager.buildResourceTree(provider, cfgDescription, languageId, project); + LanguageSettingsProvidersSerializer.buildResourceTree(provider, cfgDescription, languageId, project); } @@ -93,7 +93,7 @@ public class LanguageSettingsManager { */ // FIXME: get rid of callers PathEntryTranslator and DescriptionScannerInfoProvider public static List getSettingEntriesByKind(ICConfigurationDescription cfgDescription, IResource rc, String languageId, int kind) { - return LanguageSettingsExtensionManager.getSettingEntriesByKind(cfgDescription, rc, languageId, kind); + return LanguageSettingsProvidersSerializer.getSettingEntriesByKind(cfgDescription, rc, languageId, kind); } /** diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager_TBD.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager_TBD.java index b3ba4037be2..39edb52603b 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager_TBD.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager_TBD.java @@ -20,7 +20,6 @@ import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSetting import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; /** * This temporary class keeps the utility methods being looking for better home @@ -53,11 +52,6 @@ public class LanguageSettingsManager_TBD { return false; } - @Deprecated // Shouldn't be API - public static void serializeWorkspaceProviders() throws CoreException { - LanguageSettingsProvidersSerializer.serializeLanguageSettingsWorkspace(); - } - public static boolean isReconfigured(ILanguageSettingsProvider provider) { if (provider instanceof ILanguageSettingsEditableProvider) { try { diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java index d9e92b444b4..5c5a31b25b6 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java @@ -12,13 +12,9 @@ package org.eclipse.cdt.core.language.settings.providers; import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; -import java.util.Set; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; @@ -26,7 +22,7 @@ import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.core.settings.model.util.CDataUtil; import org.eclipse.cdt.core.settings.model.util.LanguageSettingEntriesSerializer; import org.eclipse.cdt.internal.core.XmlUtil; -import org.eclipse.cdt.internal.core.parser.util.WeakHashSet; +import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsStorage; import org.eclipse.core.resources.IResource; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -45,45 +41,17 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { private static final String ATTR_ID = "id"; //$NON-NLS-1$ private static final String ELEM_LANGUAGE_SCOPE = "language-scope"; //$NON-NLS-1$ - private static final String ELEM_LANGUAGE = "language"; //$NON-NLS-1$ - private static final String ELEM_RESOURCE = "resource"; //$NON-NLS-1$ - private static final String ATTR_PROJECT_PATH = "project-relative-path"; //$NON-NLS-1$ - - private static final String ELEM_ENTRY = "entry"; //$NON-NLS-1$ - private static final String ATTR_KIND = "kind"; //$NON-NLS-1$ private static final String ATTR_NAME = "name"; //$NON-NLS-1$ - private static final String ATTR_VALUE = "value"; //$NON-NLS-1$ private static final String ATTR_CLASS = "class"; //$NON-NLS-1$ private static final String ATTR_PARAMETER = "parameter"; //$NON-NLS-1$ - private static final String ELEM_FLAG = "flag"; //$NON-NLS-1$ - private static final String ATTR_STORE_ENTRIES = "store-entries"; //$NON-NLS-1$ private static final String VALUE_WORKSPACE = "workspace"; //$NON-NLS-1$ private static final String VALUE_PROJECT = "project"; //$NON-NLS-1$ - /** - * Pool of LSE lists implemented as WeakHashSet. That allows to gain memory savings - * at the expense of CPU time. WeakHashSet handles garbage collection when a list is not - * referenced anywhere else. See JavaDoc {@link java.lang.ref.WeakReference} about weak reference objects. - */ - private static WeakHashSet> listPool = new WeakHashSet>() { - @Override - public synchronized List add(List list) { - return super.add(list); - } - - }; - /** Tells if language settings entries are persisted with the project or in workspace area while serializing. */ private boolean storeEntriesInProjectArea = false; - /** - * Storage to keep settings entries. Note that it is not necessary to keep configuration in the maps - * as the configuration is always the one provider belongs to. - */ - private Map>> fStorage = new HashMap>>(); + private LanguageSettingsStorage fStorage = new LanguageSettingsStorage(); /** * Default constructor. This constructor has to be always followed with setting id and name of the provider. @@ -185,57 +153,6 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { fStorage.clear(); } - /** - * Internal convenience method to set language settings entries. - */ - private void setSettingEntriesInternal(String rcProjectPath, String languageId, List entries) { - if (entries!=null) { - Map> langMap = fStorage.get(languageId); - if (langMap==null) { - langMap = new HashMap>(); - fStorage.put(languageId, langMap); - } - List sortedEntries = listPool.add(Collections.unmodifiableList(sortEntries(entries))); - langMap.put(rcProjectPath, sortedEntries); - } else { - // do not keep nulls in the tables - Map> langMap = fStorage.get(languageId); - if (langMap!=null) { - langMap.remove(rcProjectPath); - if (langMap.size()==0) { - fStorage.remove(languageId); - } - } - } - } - - /** - * Some providers may collect entries in pretty much random order. For the purposes of - * predictability, UI usability and efficient storage the entries are sorted by kinds - * and secondary by name for kinds where the secondary order is not significant. - * - * @param entries - list of entries to sort. - * @return - sorted entries. - */ - protected List sortEntries(List entries) { - List sortedEntries = new ArrayList(entries); - Collections.sort(sortedEntries, new Comparator(){ - /** - * This comparator sorts by kinds first and the macros are sorted additionally by name. - */ - public int compare(ICLanguageSettingEntry entry0, ICLanguageSettingEntry entry1) { - int kind0 = entry0.getKind(); - int kind1 = entry1.getKind(); - if (kind0==ICSettingEntry.MACRO && kind1==ICSettingEntry.MACRO) { - return entry0.getName().compareTo(entry1.getName()); - } - - return kind0 - kind1; - }}); - - return sortedEntries; - } - /** * Sets language settings entries for the provider. * Note that the entries are not persisted at that point. To persist use TODO @@ -248,36 +165,40 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { */ public void setSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId, List entries) { String rcProjectPath = rc!=null ? rc.getProjectRelativePath().toString() : null; - setSettingEntriesInternal(rcProjectPath, languageId, entries); + fStorage.setSettingEntries(rcProjectPath, languageId, entries); + +// // TODO - not sure what is more efficient, to do that or not to do that? +// if (fStorage.equals(lastPersistedState)) { +// lastPersistedState = null; +// } } /** * {@inheritDoc} *
    Note that this list is unmodifiable. To modify the list copy it, change and use * {@link #setSettingEntries(ICConfigurationDescription, IResource, String, List)}. - * + * + *
    Note also that you can compare these lists with simple equality operator ==, + * as lists themselves are backed by WeakHashSet> where + * identical copies (deep comparison is used) are replaced with the same one instance. */ @Override public List getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) { - Map> langMap = fStorage.get(languageId); - if (langMap!=null) { - String rcProjectPath = rc!=null ? rc.getProjectRelativePath().toString() : null; - List entries = langMap.get(rcProjectPath); - if (entries!=null) - return entries; + List entries = fStorage.getSettingEntries(cfgDescription, rc, languageId); + if (entries == null) { + if (languageId!=null && (languageScope==null || languageScope.contains(languageId))) { + entries = getSettingEntries(cfgDescription, rc, null); + } } - if (languageId!=null && (languageScope==null || languageScope.contains(languageId))) { - List entries = getSettingEntries(cfgDescription, rc, null); - return entries; - } - - return null; + return entries; } /** * Serialize the provider under parent XML element. * This is convenience method not intended to be overridden on purpose. + * Override {@link #serializeAttributes(Element)} or + * {@link #serializeEntries(Element)} instead. * * @param parentElement - element where to serialize. * @return - newly created element. That element will already be @@ -329,98 +250,18 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { * @param elementProvider - element where to serialize the entries. */ public void serializeEntries(Element elementProvider) { - for (Entry>> entryLang : fStorage.entrySet()) { - serializeLanguage(elementProvider, entryLang); - } + fStorage.serializeEntries(elementProvider); } - /** - * Serialize the provider entries for a given language list. - */ - private void serializeLanguage(Element parentElement, Entry>> entryLang) { - String langId = entryLang.getKey(); - if (langId!=null) { - Element elementLanguage = XmlUtil.appendElement(parentElement, ELEM_LANGUAGE, new String[] {ATTR_ID, langId}); - parentElement = elementLanguage; - } - for (Entry> entryRc : entryLang.getValue().entrySet()) { - serializeResource(parentElement, entryRc); - } - } - - /** - * Serialize the provider entries for a given resource list. - */ - private void serializeResource(Element parentElement, Entry> entryRc) { - String rcProjectPath = entryRc.getKey(); - if (rcProjectPath!=null) { - Element elementRc = XmlUtil.appendElement(parentElement, ELEM_RESOURCE, new String[] {ATTR_PROJECT_PATH, rcProjectPath}); - parentElement = elementRc; - } - serializeSettingEntries(parentElement, entryRc.getValue()); - } - - /** - * Serialize given settings entries. - */ - private void serializeSettingEntries(Element parentElement, List settingEntries) { - for (ICLanguageSettingEntry entry : settingEntries) { - Element elementSettingEntry = XmlUtil.appendElement(parentElement, ELEM_ENTRY, new String[] { - ATTR_KIND, LanguageSettingEntriesSerializer.kindToString(entry.getKind()), - ATTR_NAME, entry.getName(), - }); - switch(entry.getKind()) { - case ICSettingEntry.MACRO: - elementSettingEntry.setAttribute(ATTR_VALUE, entry.getValue()); - break; -// case ICLanguageSettingEntry.LIBRARY_FILE: -// // TODO: sourceAttachment fields may need to be covered -// break; - } - int flags = entry.getFlags(); - if (flags!=0) { - // Element elementFlag = - XmlUtil.appendElement(elementSettingEntry, ELEM_FLAG, new String[] { - ATTR_VALUE, LanguageSettingEntriesSerializer.composeFlagsString(entry.getFlags()) - }); - } - } - } - - /** - * Load a setting entry from XML element. - */ - private ICLanguageSettingEntry loadSettingEntry(Node parentElement) { - String settingKind = XmlUtil.determineAttributeValue(parentElement, ATTR_KIND); - String settingName = XmlUtil.determineAttributeValue(parentElement, ATTR_NAME); - - NodeList flagNodes = parentElement.getChildNodes(); - int flags = 0; - for (int i=0;i to load provider from. */ - public void load(Element providerNode) { + final public void load(Element providerNode) { fStorage.clear(); languageScope = null; @@ -431,6 +272,18 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { } } + /** + * Determine and set language scope from given XML node. + */ + private void loadLanguageScopeElement(Node parentNode) { + if (languageScope==null) { + languageScope = new ArrayList(); + } + String id = XmlUtil.determineAttributeValue(parentNode, ATTR_ID); + languageScope.add(id); + + } + /** * Load attributes from XML provider element. * @param providerNode - XML element to load attributes from. @@ -464,125 +317,9 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { * @param providerNode - parent XML element where entries are defined. */ public void loadEntries(Element providerNode) { - List settings = new ArrayList(); - NodeList nodes = providerNode.getChildNodes(); - for (int i=0;i0) { - setSettingEntriesInternal(null, null, settings); - } + fStorage.loadEntries(providerNode); } - - /** - * Determine and set language scope from given XML node. - */ - private void loadLanguageScopeElement(Node parentNode) { - if (languageScope==null) { - languageScope = new ArrayList(); - } - String id = XmlUtil.determineAttributeValue(parentNode, ATTR_ID); - languageScope.add(id); - - } - - /** - * Load entries defined in language element. - */ - private void loadLanguageElement(Node parentNode, String cfgId) { - String langId = XmlUtil.determineAttributeValue(parentNode, ATTR_ID); - if (langId.length()==0) { - langId=null; - } - - List settings = new ArrayList(); - NodeList nodes = parentNode.getChildNodes(); - for (int i=0;i0) { - setSettingEntriesInternal(null, langId, settings); - } - } - - /** - * Load entries defined in resource element. - */ - private void loadResourceElement(Node parentNode, String cfgId, String langId) { - String rcProjectPath = XmlUtil.determineAttributeValue(parentNode, ATTR_PROJECT_PATH); - - List settings = new ArrayList(); - NodeList nodes = parentNode.getChildNodes(); - for (int i=0;i0) { - setSettingEntriesInternal(rcProjectPath, langId, settings); - } - } - - /** - * Clone storage for the entries. Copies references for lists of entries as a whole. - * Note that is OK as the lists kept in storage are unmodifiable. - */ - private Map>> cloneStorage() { - Map>> storageClone = new HashMap>>(); - Set>>> entrySetLang = fStorage.entrySet(); - for (Entry>> entryLang : entrySetLang) { - String langId = entryLang.getKey(); - Map> mapRc = entryLang.getValue(); - Map> mapRcClone = new HashMap>(); - Set>> entrySetRc = mapRc.entrySet(); - for (Entry> entryRc : entrySetRc) { - String rcProjectPath = entryRc.getKey(); - List lsEntries = entryRc.getValue(); - // don't need to clone entries, they are from the LSE pool - mapRcClone.put(rcProjectPath, lsEntries); - } - storageClone.put(langId, mapRcClone); - } - return storageClone; - } - + /** * See {@link #cloneShallow()}. This method is extracted * to avoid expressing {@link #clone()} via {@link #cloneShallow()}. @@ -592,7 +329,7 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { if (languageScope!=null) clone.languageScope = new ArrayList(languageScope); - clone.fStorage = new HashMap>>(); + clone.fStorage = new LanguageSettingsStorage(); return clone; } @@ -610,7 +347,7 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { @Override protected LanguageSettingsSerializable clone() throws CloneNotSupportedException { LanguageSettingsSerializable clone = cloneShallowInternal(); - clone.fStorage = cloneStorage(); + clone.fStorage = fStorage.cloneStorage(); return clone; } @@ -680,4 +417,11 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { return false; return true; } + + /** + * @noreference This method is not intended to be referenced by clients. + */ + public LanguageSettingsStorage getStorageInternal() { + return fStorage; + } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableEditable.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableEditable.java index 5454e7ea697..22465b7b6e4 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableEditable.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableEditable.java @@ -13,7 +13,8 @@ package org.eclipse.cdt.core.language.settings.providers; // TODO: move ILanguageSettingsEditableProvider here -public class LanguageSettingsSerializableEditable extends LanguageSettingsSerializable implements ILanguageSettingsEditableProvider { +// TODO this one is unused - remove +final public class LanguageSettingsSerializableEditable extends LanguageSettingsSerializable implements ILanguageSettingsEditableProvider { @Override public LanguageSettingsSerializableEditable clone() throws CloneNotSupportedException { return (LanguageSettingsSerializableEditable) super.clone(); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICConfigurationDescription.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICConfigurationDescription.java index e58bc9ad55a..febe5a589ed 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICConfigurationDescription.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICConfigurationDescription.java @@ -395,6 +395,8 @@ public interface ICConfigurationDescription extends ICSettingContainer, ICSettin * or preprocessor macros. * * @param providers the list of providers to assign to the configuration description. + * Warning: the providers will be cloned before actual addition to the project model + * due to TODO - very important reason but I forgot why by now. * * @since 6.0 */ diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/ILanguageSettingsChangeEvent.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/ILanguageSettingsChangeEvent.java new file mode 100644 index 00000000000..c609aad9a07 --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/ILanguageSettingsChangeEvent.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2011, 2011 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.internal.core.language.settings.providers; + +import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; +import org.eclipse.core.resources.IResource; + +/** + * Contains the details of changes that occurred as a result of modifying + * language settings entries {@link ICLanguageSettingEntry}. + * + * @noextend This interface is not intended to be extended by clients. + * @noimplement This interface is not intended to be implemented by clients. + */ +public interface ILanguageSettingsChangeEvent { + public String getProjectName(); + + public String[] getConfigurationDescriptionIds(); + + public IResource[] getResources(String cfgDescriptionId); + +// // AG - YAGNI +// public List getSettingEntriesOld(ICConfigurationDescription cfgDescription, IResource rc, String languageId); +// public List getSettingEntriesNew(ICConfigurationDescription cfgDescription, IResource rc, String languageId); +// // AG - or maybe +// ILanguageSettingsDelta getDelta(ICConfigurationDescription cfgDescription); + +} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/ILanguageSettingsChangeListener.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/ILanguageSettingsChangeListener.java new file mode 100644 index 00000000000..9b54debd6ef --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/ILanguageSettingsChangeListener.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2011, 2011 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.internal.core.language.settings.providers; + +/** + * Listens to changes in language settings. + */ +public interface ILanguageSettingsChangeListener { + /** + * Indicates that language settings have been changed. + * @param event + */ + public void handleEvent(ILanguageSettingsChangeEvent event); +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsDelta.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsDelta.java new file mode 100644 index 00000000000..3cc23505630 --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsDelta.java @@ -0,0 +1,155 @@ +/******************************************************************************* + * Copyright (c) 2011, 2011 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.internal.core.language.settings.providers; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; +import org.eclipse.cdt.core.settings.model.ICSettingEntry; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.runtime.Assert; + + +// TODO possibly make an interface from that +public class LanguageSettingsDelta { + // maps need to be ordered by providers + private LinkedHashMap oldLanguageSettingsState; + private LinkedHashMap newLanguageSettingsState; + + public LanguageSettingsDelta(LinkedHashMap oldState, LinkedHashMap newState) { + oldLanguageSettingsState = oldState; + newLanguageSettingsState = newState; + } + + // FIXME - this API is no good + public Set getChangedResources(IProject project, ICConfigurationDescription cfgDescription) { + Set resources = new HashSet(); + + // Ordered collections + Collection oldStateStorages = oldLanguageSettingsState.values(); + Collection newStateStorages = newLanguageSettingsState.values(); + + for (LanguageSettingsStorage lss : oldStateStorages) { +// Map>> + Map>> mapInternal = lss.getMapInternal(); + synchronized (mapInternal) { + for (Entry>> entryLang : mapInternal.entrySet()) { + String langId = entryLang.getKey(); + for (Entry> entryRc : entryLang.getValue().entrySet()) { + String rcName = entryRc.getKey(); + IResource rc = (rcName != null) ? project.findMember(rcName) : project; + if (resources.contains(rc)) + continue; + + List lsEntriesOld = entryRc.getValue(); + List lsEntriesNew = getSettingEntries(newStateStorages, cfgDescription, rc, langId); + + if (!lsEntriesNew.equals(lsEntriesOld) && !(lsEntriesOld==null && lsEntriesNew.size()==0)) { + resources.add(rc); + } + } + } + } + } + for (LanguageSettingsStorage lss : newStateStorages) { +// Map>> + Map>> mapInternal = lss.getMapInternal(); + synchronized (mapInternal) { + for (Entry>> entryLang : mapInternal.entrySet()) { + String langId = entryLang.getKey(); + for (Entry> entryRc : entryLang.getValue().entrySet()) { + String rcName = entryRc.getKey(); + IResource rc = (rcName != null) ? project.findMember(rcName) : project; + if (resources.contains(rc)) + continue; + + List lsEntriesNew = entryRc.getValue(); + List lsEntriesOld = getSettingEntries(oldStateStorages, cfgDescription, rc, langId); + + if (!lsEntriesOld.equals(lsEntriesNew) && !(lsEntriesNew==null && lsEntriesOld.size()==0)) { + resources.add(rc); + } + } + } + } + } + + return resources; + } + + private static boolean checkBit(int flags, int bit) { + return (flags & bit) == bit; + } + + private static List getSettingEntries(Collection stores, ICConfigurationDescription cfgDescription, IResource rc, String languageId) { + List entries = new ArrayList(); + List alreadyAdded = new ArrayList(); + + for (LanguageSettingsStorage store: stores) { + List providerEntries = getSettingEntriesUpResourceTree(store, cfgDescription, rc, languageId); + for (ICLanguageSettingEntry entry : providerEntries) { + if (entry!=null) { + String entryName = entry.getName(); + // Only first entry is considered + // Entry flagged as "UNDEFINED" prevents adding entry with the same name down the line + if (!alreadyAdded.contains(entryName)) { + int flags = entry.getFlags(); + if (!checkBit(flags, ICSettingEntry.UNDEFINED)) { + entries.add(entry); + } + alreadyAdded.add(entryName); + } + } + } + } + + return entries; + } + + private static List getSettingEntriesUpResourceTree(LanguageSettingsStorage store, ICConfigurationDescription cfgDescription, IResource rc, String languageId) { + Assert.isTrue( !(rc instanceof IWorkspaceRoot) ); + if (store!=null) { + List entries = store.getSettingEntries(cfgDescription, rc, languageId); + if (entries!=null) { + return new ArrayList(entries); + } + if (rc!=null) { + IResource parentFolder = (rc instanceof IProject) ? null : rc.getParent(); + if (parentFolder!=null) { + return getSettingEntriesUpResourceTree(store, cfgDescription, parentFolder, languageId); + } + // if out of parent resources - get default entries for the applicable language scope + entries = store.getSettingEntries(null, null, languageId); + if (entries!=null) { + return new ArrayList(entries); + } + } + } + + return new ArrayList(0); + } +} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java index 900c062954e..9d7eff5361c 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java @@ -13,10 +13,8 @@ package org.eclipse.cdt.internal.core.language.settings.providers; import java.util.ArrayList; import java.util.Comparator; -import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; -import java.util.Map; import java.util.Set; import java.util.TreeSet; @@ -26,19 +24,9 @@ import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsEditabl import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsBaseProvider; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable; -import org.eclipse.cdt.core.model.ILanguage; -import org.eclipse.cdt.core.model.LanguageManager; -import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; -import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.core.settings.model.util.CDataUtil; import org.eclipse.cdt.core.settings.model.util.LanguageSettingEntriesSerializer; -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtension; @@ -340,267 +328,6 @@ public class LanguageSettingsExtensionManager { return list; } - private static List safeGetSettingEntries(ILanguageSettingsProvider provider, - ICConfigurationDescription cfgDescription, IResource rc, String languageId) { - - try { - return provider.getSettingEntries(cfgDescription, rc, languageId); - } catch (Throwable e) { - String cfgId = cfgDescription!=null ? cfgDescription.getId() : null; - String msg = "Exception in provider "+provider.getId()+": getSettingEntries("+cfgId+", "+rc+", "+languageId+")"; - CCorePlugin.log(msg, e); - // return empty array to prevent climbing up the resource tree - return new ArrayList(0); - } - } - - /** - * Returns the list of setting entries of the given provider - * for the given configuration description, resource and language. - * This method reaches to the parent folder of the resource recursively - * in case the resource does not define the entries for the given provider. - * - * @param provider - language settings provider. - * @param cfgDescription - configuration description. - * @param rc - resource such as file or folder. - * @param languageId - language id. - * - * @return the list of setting entries. Never returns {@code null} - * although individual providers mandated to return {@code null} if no settings defined. - */ - public static List getSettingEntriesUpResourceTree(ILanguageSettingsProvider provider, ICConfigurationDescription cfgDescription, IResource rc, String languageId) { - Assert.isTrue( !(rc instanceof IWorkspaceRoot) ); - if (provider!=null) { - List entries = safeGetSettingEntries(provider, cfgDescription, rc, languageId); - if (entries!=null) { - return new ArrayList(entries); - } - if (rc!=null) { - IResource parentFolder = (rc instanceof IProject) ? null : rc.getParent(); - if (parentFolder!=null) { - return getSettingEntriesUpResourceTree(provider, cfgDescription, parentFolder, languageId); - } - // if out of parent resources - get default entries for the applicable language scope - entries = safeGetSettingEntries(provider, null, null, languageId); - if (entries!=null) { - return new ArrayList(entries); - } - } - } - - return new ArrayList(0); - } - - /** - * Builds for the provider a nice looking resource tree to present hierarchical view to the user. - * Note that it is not advisable to "compact" the tree because of potential loss of information - * which is especially important during partial or incremental builds. - * - * @param provider - language settings provider to build the tree for. - * @param cfgDescription - configuration description. - * @param languageId - language ID. - * @param folder - container where the tree roots. - */ - public static void buildResourceTree(LanguageSettingsSerializable provider, ICConfigurationDescription cfgDescription, String languageId, IContainer folder) { - IResource[] members = null; - try { - members = folder.members(); - } catch (Exception e) { - CCorePlugin.log(e); - } - if (members==null) - return; - - for (IResource rc : members) { - if (rc instanceof IContainer) { - buildResourceTree(provider, cfgDescription, languageId, (IContainer) rc); - } - } - - int rcNumber = members.length; - - Map, Integer> listMap = new HashMap, Integer>(); - - // on the first pass find majority entries - List majorityEntries = null; - List candidate = null; - int candidateCount = 0; - for (IResource rc : members) { - if (!isLanguageInScope(rc, cfgDescription, languageId)) { - rcNumber--; - } else { - List entries = provider.getSettingEntries(null, rc, languageId); - if (entries==null && rc instanceof IContainer) { - rcNumber--; - } else { - Integer count = listMap.get(entries); - if (count==null) { - count = 0; - } - count++; - - if (count>candidateCount) { - candidateCount = count; - candidate = entries; - } - - listMap.put(entries, count); - } - } - - if (candidateCount > rcNumber/2) { - majorityEntries = candidate; - break; - } - } - - if (majorityEntries!=null) { - provider.setSettingEntries(cfgDescription, folder, languageId, majorityEntries); - } - - // second pass - assign the entries to the folders - for (IResource rc : members) { - List entries = provider.getSettingEntries(null, rc, languageId); - if (entries!=null && entries==majorityEntries) { - if (!(rc instanceof IFile)) { // preserve information which files were collected - provider.setSettingEntries(cfgDescription, rc, languageId, null); - } - } - } - } - - private static boolean isLanguageInScope(IResource rc, ICConfigurationDescription cfgDescription, String languageId) { - if (rc instanceof IFile) { - ILanguage lang = null; - try { - lang = LanguageManager.getInstance().getLanguageForFile((IFile) rc, cfgDescription); - } catch (CoreException e) { - CCorePlugin.log("Error loading language settings providers extensions", e); //$NON-NLS-1$ - } - if (lang==null || (languageId!=null && !languageId.equals(lang.getId()))) { - return false; - } - } - return true; - } - - private static boolean checkBit(int flags, int bit) { - return (flags & bit) == bit; - } - - /** - * Returns the list of setting entries of a certain kind (such as include paths) - * for the given configuration description, resource and language. This is a - * combined list for all providers taking into account settings of parent folder - * if settings for the given resource are not defined. - * - * @param cfgDescription - configuration description. - * @param rc - resource such as file or folder. - * @param languageId - language id. - * @param kind - kind of language settings entries, such as - * {@link ICSettingEntry#INCLUDE_PATH} etc. This is a binary flag - * and it is possible to specify composite kind. - * Use {@link ICSettingEntry#ALL} to get all kinds. - * @param checkLocality - specifies if parameter {@code isLocal} should be considered. - * @param isLocal - {@code true} if "local" entries should be provided and - * {@code false} for "system" entries. This makes sense for include paths where - * [#include "..."] is "local" and [#include <...>] is system. - * - * @return the list of setting entries found. - */ - private static List getSettingEntriesByKind(ICConfigurationDescription cfgDescription, - IResource rc, String languageId, int kind, boolean checkLocality, boolean isLocal) { - - List entries = new ArrayList(); - List alreadyAdded = new ArrayList(); - - List providers = cfgDescription.getLanguageSettingProviders(); - for (ILanguageSettingsProvider provider: providers) { - List providerEntries = getSettingEntriesUpResourceTree(provider, cfgDescription, rc, languageId); - for (ICLanguageSettingEntry entry : providerEntries) { - if (entry!=null) { - String entryName = entry.getName(); - boolean isRightKind = (entry.getKind() & kind) != 0; - // Only first entry is considered - // Entry flagged as "UNDEFINED" prevents adding entry with the same name down the line - if (isRightKind && !alreadyAdded.contains(entryName)) { - int flags = entry.getFlags(); - boolean isRightLocal = !checkLocality || (checkBit(flags, ICSettingEntry.LOCAL) == isLocal); - if (isRightLocal) { - if (!checkBit(flags, ICSettingEntry.UNDEFINED)) { - entries.add(entry); - } - alreadyAdded.add(entryName); - } - } - } - } - } - - return entries; - } - - /** - * Returns the list of setting entries of a certain kind (such as include paths) - * for the given configuration description, resource and language. This is a - * combined list for all providers taking into account settings of parent folder - * if settings for the given resource are not defined. For include paths both - * local (#include "...") and system (#include <...>) entries are returned. - * - * @param cfgDescription - configuration description. - * @param rc - resource such as file or folder. - * @param languageId - language id. - * @param kind - kind of language settings entries, such as - * {@link ICSettingEntry#INCLUDE_PATH} etc. This is a binary flag - * and it is possible to specify composite kind. - * Use {@link ICSettingEntry#ALL} to get all kinds. - * - * @return the list of setting entries. - */ - public static List getSettingEntriesByKind(ICConfigurationDescription cfgDescription, IResource rc, String languageId, int kind) { - return getSettingEntriesByKind(cfgDescription, rc, languageId, kind, /* checkLocality */ false, /* isLocal */ false); - } - - /** - * Returns the list of "system" (such as [#include <...>]) setting entries of a certain kind - * for the given configuration description, resource and language. This is a - * combined list for all providers taking into account settings of parent folder - * if settings for the given resource are not defined. - * - * @param cfgDescription - configuration description. - * @param rc - resource such as file or folder. - * @param languageId - language id. - * @param kind - kind of language settings entries, such as - * {@link ICSettingEntry#INCLUDE_PATH} etc. This is a binary flag - * and it is possible to specify composite kind. - * Use {@link ICSettingEntry#ALL} to get all kinds. - * - * @return the list of setting entries. - */ - public static List getSystemSettingEntriesByKind(ICConfigurationDescription cfgDescription, IResource rc, String languageId, int kind) { - return getSettingEntriesByKind(cfgDescription, rc, languageId, kind, /* checkLocality */ true, /* isLocal */ false); - } - - /** - * Returns the list of "local" (such as [#include "..."]) setting entries of a certain kind - * for the given configuration description, resource and language. This is a - * combined list for all providers taking into account settings of parent folder - * if settings for the given resource are not defined. - * - * @param cfgDescription - configuration description. - * @param rc - resource such as file or folder. - * @param languageId - language id. - * @param kind - kind of language settings entries, such as - * {@link ICSettingEntry#INCLUDE_PATH} etc. This is a binary flag - * and it is possible to specify composite kind. - * Use {@link ICSettingEntry#ALL} to get all kinds. - * - * @return the list of setting entries. - */ - public static List getLocalSettingEntriesByKind(ICConfigurationDescription cfgDescription, IResource rc, String languageId, int kind) { - return getSettingEntriesByKind(cfgDescription, rc, languageId, kind, /* checkLocality */ true, /* isLocal */ true); - } - public static boolean equalsExtensionProviderShallow(ILanguageSettingsEditableProvider provider) throws CloneNotSupportedException { String id = provider.getId(); ILanguageSettingsProvider extensionProviderShallow = getExtensionProviderShallow(id); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java index 1e5852a9194..12450b5784d 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java @@ -25,19 +25,29 @@ import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvide import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable; import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySupport; +import org.eclipse.cdt.core.model.ILanguage; +import org.eclipse.cdt.core.model.LanguageManager; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICProjectDescription; +import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.internal.core.XmlUtil; +import org.eclipse.cdt.internal.core.settings.model.CConfigurationSpecSettings; +import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager; +import org.eclipse.cdt.internal.core.settings.model.IInternalCCfgInfo; import org.eclipse.core.filesystem.URIUtil; +import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.ListenerList; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.ILock; import org.eclipse.core.runtime.jobs.Job; @@ -61,11 +71,15 @@ public class LanguageSettingsProvidersSerializer { private static final String ELEM_CONFIGURATION = "configuration"; //$NON-NLS-1$ private static final String ELEM_PROVIDER = "provider"; //$NON-NLS-1$ private static final String ELEM_PROVIDER_REFERENCE = "provider-reference"; //$NON-NLS-1$ + private static ILock serializingLock = Job.getJobManager().newLock(); + /** Cache of globally available providers to be consumed by calling clients */ private static Map rawGlobalWorkspaceProviders = new HashMap(); private static Map globalWorkspaceProviders = new HashMap(); + private static ListenerList fLanguageSettingsChangeListeners = new ListenerList(ListenerList.IDENTITY); + private static class ListenerAssociation { private ICListenerRegisterer listener; private ICConfigurationDescription cfgDescription; @@ -161,6 +175,75 @@ public class LanguageSettingsProvidersSerializer { } } + private static class LanguageSettingsChangeEvent implements ILanguageSettingsChangeEvent { + private String projectName = null; + private Map deltaMap = new HashMap(); + + private IResource[] resources = null; + + /** + * The act of creating event resets internal delta count in configuration state. + * That implies that when the event is retrieved it must be fired or delta will go missing. + * That side effect is here to ensure atomic processing of firing & resetting the delta. + */ + public LanguageSettingsChangeEvent(ICProjectDescription prjDescription) { + Assert.isTrue(prjDescription.isReadOnly()); + + projectName = prjDescription.getName(); + ICConfigurationDescription[] cfgDescriptions = prjDescription.getConfigurations(); + for (ICConfigurationDescription cfgDescription : cfgDescriptions) { + if (cfgDescription instanceof IInternalCCfgInfo) { + CConfigurationSpecSettings specSettings = null; + try { + specSettings = ((IInternalCCfgInfo) cfgDescription).getSpecSettings(); + } catch (CoreException e) { + CCorePlugin.log(e); + } + if (specSettings != null) { + LanguageSettingsDelta delta = specSettings.dropDelta(); + if (delta != null) + deltaMap.put(cfgDescription.getId(), delta); + } else { + IStatus ss = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "Internal error: Missing specSettings for " + cfgDescription.getClass().getSimpleName()); + CCorePlugin.log(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, ss.getMessage(), new CoreException(ss))); + } + } + + } + } + + public String getProjectName() { + return projectName; + } + + public String[] getConfigurationDescriptionIds() { + String[] ids = deltaMap.keySet().toArray(new String[deltaMap.size()]); + return ids; + } + + public IResource[] getResources(String cfgDescriptionId) { + if (resources == null) { + LanguageSettingsDelta delta = deltaMap.get(cfgDescriptionId); + if (delta == null) { + resources = new IResource[0]; + } else { + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); + ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false); + ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); + resources = delta.getChangedResources(project, cfgDescription).toArray(new IResource[0]); + } + } + + return resources; + } + + @Override + public String toString() { + return "LanguageSettingsChangeEvent for project=[" + getProjectName() + "]" + + ", configurations=" + deltaMap.keySet() + ; + } + } /** static initializer */ static { @@ -261,24 +344,66 @@ public class LanguageSettingsProvidersSerializer { rawGlobalWorkspaceProviders = rawWorkspaceProviders; } + private static List createLanguageLettingsChangeEvents(List serializableProviders) { + List events = new ArrayList(); + + List serializableIds = new ArrayList(); + for (LanguageSettingsSerializable provider : serializableProviders) { + serializableIds.add(provider.getId()); + } + + IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); + IProject[] projects = root.getProjects(); +projects: + for (IProject project : projects) { + if (project.isAccessible()) { + ICProjectDescription prjDescription = CCorePlugin.getDefault().getProjectDescription(project, false); + if (prjDescription != null) { + ICConfigurationDescription[] cfgDescriptions = prjDescription.getConfigurations(); + for (ICConfigurationDescription cfgDescription : cfgDescriptions) { + for (ILanguageSettingsProvider provider : cfgDescription.getLanguageSettingProviders()) { + if (isWorkspaceProvider(provider) && serializableIds.contains(provider.getId())) { + LanguageSettingsChangeEvent event = new LanguageSettingsChangeEvent(prjDescription); + if (event.getConfigurationDescriptionIds().length > 0) { + events.add(event); + } + continue projects; + } + } + } + } + } + + } + + return events; + } + public static void serializeLanguageSettingsWorkspace() throws CoreException { + // AG TODO - remove the log + CCorePlugin.log(new Status(IStatus.WARNING, CCorePlugin.PLUGIN_ID, IStatus.OK, + "LanguageSettingsProvidersSerializer.serializeLanguageSettingsWorkspace()", new Exception())); + URI uriStoreWsp = getStoreInWorkspaceArea(STORAGE_WORKSPACE_LANGUAGE_SETTINGS); - List serializableExtensionProviders = new ArrayList(); + List serializableWorkspaceProviders = new ArrayList(); for (ILanguageSettingsProvider provider : rawGlobalWorkspaceProviders.values()) { if (provider instanceof LanguageSettingsSerializable) { // serialize all editable providers which are different from corresponding extension // and serialize all serializable ones that are not editable (those are singletons and we don't know whether they changed) if (!(provider instanceof ILanguageSettingsEditableProvider) || !LanguageSettingsExtensionManager.equalsExtensionProvider(provider)) { - serializableExtensionProviders.add((LanguageSettingsSerializable)provider); + serializableWorkspaceProviders.add((LanguageSettingsSerializable)provider); } } } try { - if (serializableExtensionProviders.isEmpty()) { + List events = null; + if (serializableWorkspaceProviders.isEmpty()) { java.io.File fileStoreWsp = new java.io.File(uriStoreWsp); - serializingLock.acquire(); try { + serializingLock.acquire(); fileStoreWsp.delete(); + // manufacture events while inside the lock + events = createLanguageLettingsChangeEvents(serializableWorkspaceProviders); } finally { serializingLock.release(); } @@ -287,17 +412,23 @@ public class LanguageSettingsProvidersSerializer { Element rootElement = XmlUtil.appendElement(doc, ELEM_PLUGIN); Element elementExtension = XmlUtil.appendElement(rootElement, ELEM_EXTENSION, new String[] {ATTR_POINT, LanguageSettingsExtensionManager.PROVIDER_EXTENSION_FULL_ID}); - for (LanguageSettingsSerializable provider : serializableExtensionProviders) { + for (LanguageSettingsSerializable provider : serializableWorkspaceProviders) { provider.serialize(elementExtension); } - serializingLock.acquire(); try { + serializingLock.acquire(); XmlUtil.serializeXml(doc, uriStoreWsp); + // manufacture events while inside the lock + events = createLanguageLettingsChangeEvents(serializableWorkspaceProviders); } finally { serializingLock.release(); } } + // notify the listeners outside the lock + for (LanguageSettingsChangeEvent event : events) { + notifyLanguageSettingsChangeListeners(event); + } } catch (Exception e) { CCorePlugin.log("Internal error while trying to serialize language settings", e); //$NON-NLS-1$ @@ -414,6 +545,10 @@ public class LanguageSettingsProvidersSerializer { public static void serializeLanguageSettings(ICProjectDescription prjDescription) throws CoreException { IProject project = prjDescription.getProject(); + // AG TODO - remove the log + CCorePlugin.log(new Status(IStatus.WARNING, CCorePlugin.PLUGIN_ID, IStatus.OK, + "LanguageSettingsProvidersSerializer.serializeLanguageSettings() for " + project, new Exception())); + try { // Document to store in project area Document docStorePrj = XmlUtil.newDocument(); @@ -422,26 +557,37 @@ public class LanguageSettingsProvidersSerializer { Document docStoreWsp = XmlUtil.newDocument(); Element projectElementStoreWsp = XmlUtil.appendElement(docStoreWsp, ELEM_PROJECT); - serializeLanguageSettingsInternal(projectElementStorePrj, projectElementStoreWsp, prjDescription); - - IFile fileStorePrj = getStoreInProjectArea(project); // The project store should not be absent. Absent store means legacy project, not 0 providers. - XmlUtil.serializeXml(docStorePrj, fileStorePrj); + IFile fileStorePrj = getStoreInProjectArea(project); + + URI uriStoreWsp = getStoreInWorkspaceArea(project.getName()+'.'+STORAGE_WORKSPACE_LANGUAGE_SETTINGS); + LanguageSettingsChangeEvent event = null; - URI uriStoreWsp = null; - boolean isWorkspaceStoreEmpty = projectElementStoreWsp.getChildNodes().getLength() == 0; - uriStoreWsp = getStoreInWorkspaceArea(project.getName()+'.'+STORAGE_WORKSPACE_LANGUAGE_SETTINGS); - serializingLock.acquire(); try { + serializingLock.acquire(); + + // Note that need for serialization may exist even if LSE event delta is empty, + // as number or properties of providers may differ + serializeLanguageSettingsInternal(projectElementStorePrj, projectElementStoreWsp, prjDescription); + XmlUtil.serializeXml(docStorePrj, fileStorePrj); + // project-specific location in workspace area + boolean isWorkspaceStoreEmpty = projectElementStoreWsp.getChildNodes().getLength() == 0; if (!isWorkspaceStoreEmpty) { XmlUtil.serializeXml(docStoreWsp, uriStoreWsp); } else { new java.io.File(uriStoreWsp).delete(); } + + // manufacture the event only if serialization was successful + event = new LanguageSettingsChangeEvent(prjDescription); } finally { serializingLock.release(); } + // notify the listeners outside the lock + if (event.getConfigurationDescriptionIds().length > 0) { + notifyLanguageSettingsChangeListeners(event); + } } catch (Exception e) { IStatus s = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "Internal error while trying to serialize language settings", e); @@ -510,8 +656,16 @@ public class LanguageSettingsProvidersSerializer { } ICConfigurationDescription cfgDescription = prjDescription.getConfigurationById(cfgId); - if (cfgDescription!=null) + if (cfgDescription!=null) { cfgDescription.setLanguageSettingProviders(providers); + if (cfgDescription instanceof IInternalCCfgInfo) { + try { + ((IInternalCCfgInfo) cfgDescription).getSpecSettings().dropDelta(); + } catch (CoreException e) { + CCorePlugin.log(e); + } + } + } } } @@ -839,8 +993,9 @@ public class LanguageSettingsProvidersSerializer { try { provider = ((ILanguageSettingsEditableProvider) provider).clone(); } catch (CloneNotSupportedException e) { - IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "Not able to clone provider " + provider.getClass()); - CCorePlugin.log(new CoreException(status)); + IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, Status.OK, + "Not able to clone provider " + provider.getClass(), e); + CCorePlugin.log(status); } } newProviders.add(provider); @@ -848,4 +1003,300 @@ public class LanguageSettingsProvidersSerializer { return new ArrayList(newProviders); } + /** + * Adds a listener that will be notified of changes in language settings. + * + * @param listener the ILanguageMappingChangeListener to add + */ + public static void registerLanguageSettingsChangeListener(ILanguageSettingsChangeListener listener) { + fLanguageSettingsChangeListeners.add(listener); + } + + /** + * Removes a language settings change listener. + * + * @param listener the ILanguageMappingChangeListener to remove. + */ + public static void unregisterLanguageSettingsChangeListener(ILanguageSettingsChangeListener listener) { + fLanguageSettingsChangeListeners.remove(listener); + } + + /** + * Notifies all language settings change listeners of a change. + * + * @param event the ILanguageSettingsChangeEvent event to be broadcast. + */ + public static void notifyLanguageSettingsChangeListeners(ILanguageSettingsChangeEvent event) { + // AG TODO - remove the log + CCorePlugin.log(new Status(IStatus.WARNING, CCorePlugin.PLUGIN_ID, IStatus.OK, + "Firing " + event, new Exception())); + + Object[] listeners = fLanguageSettingsChangeListeners.getListeners(); + for (Object obj : listeners) { + ILanguageSettingsChangeListener listener = (ILanguageSettingsChangeListener) obj; + listener.handleEvent(event); + } + } + + private static List safeGetSettingEntries(ILanguageSettingsProvider provider, + ICConfigurationDescription cfgDescription, IResource rc, String languageId) { + + try { + return provider.getSettingEntries(cfgDescription, rc, languageId); + } catch (Throwable e) { + String cfgId = cfgDescription!=null ? cfgDescription.getId() : null; + String msg = "Exception in provider "+provider.getId()+": getSettingEntries("+cfgId+", "+rc+", "+languageId+")"; + CCorePlugin.log(msg, e); + // return empty array to prevent climbing up the resource tree + return new ArrayList(0); + } + } + + /** + * Returns the list of setting entries of the given provider + * for the given configuration description, resource and language. + * This method reaches to the parent folder of the resource recursively + * in case the resource does not define the entries for the given provider. + * + * @param provider - language settings provider. + * @param cfgDescription - configuration description. + * @param rc - resource such as file or folder. + * @param languageId - language id. + * + * @return the list of setting entries. Never returns {@code null} + * although individual providers mandated to return {@code null} if no settings defined. + */ + public static List getSettingEntriesUpResourceTree(ILanguageSettingsProvider provider, ICConfigurationDescription cfgDescription, IResource rc, String languageId) { + Assert.isTrue( !(rc instanceof IWorkspaceRoot) ); + if (provider!=null) { + List entries = safeGetSettingEntries(provider, cfgDescription, rc, languageId); + if (entries!=null) { + return new ArrayList(entries); + } + if (rc!=null) { + IResource parentFolder = (rc instanceof IProject) ? null : rc.getParent(); + if (parentFolder!=null) { + return getSettingEntriesUpResourceTree(provider, cfgDescription, parentFolder, languageId); + } + // if out of parent resources - get default entries for the applicable language scope + entries = safeGetSettingEntries(provider, null, null, languageId); + if (entries!=null) { + return new ArrayList(entries); + } + } + } + + return new ArrayList(0); + } + + /** + * Builds for the provider a nice looking resource tree to present hierarchical view to the user. + * Note that it is not advisable to "compact" the tree because of potential loss of information + * which is especially important during partial or incremental builds. + * + * @param provider - language settings provider to build the tree for. + * @param cfgDescription - configuration description. + * @param languageId - language ID. + * @param folder - container where the tree roots. + */ + public static void buildResourceTree(LanguageSettingsSerializable provider, ICConfigurationDescription cfgDescription, String languageId, IContainer folder) { + IResource[] members = null; + try { + members = folder.members(); + } catch (Exception e) { + CCorePlugin.log(e); + } + if (members==null) + return; + + for (IResource rc : members) { + if (rc instanceof IContainer) { + buildResourceTree(provider, cfgDescription, languageId, (IContainer) rc); + } + } + + int rcNumber = members.length; + + Map, Integer> listMap = new HashMap, Integer>(); + + // on the first pass find majority entries + List majorityEntries = null; + List candidate = null; + int candidateCount = 0; + for (IResource rc : members) { + if (!isLanguageInScope(rc, cfgDescription, languageId)) { + rcNumber--; + } else { + List entries = provider.getSettingEntries(null, rc, languageId); + if (entries==null && rc instanceof IContainer) { + rcNumber--; + } else { + Integer count = listMap.get(entries); + if (count==null) { + count = 0; + } + count++; + + if (count>candidateCount) { + candidateCount = count; + candidate = entries; + } + + listMap.put(entries, count); + } + } + + if (candidateCount > rcNumber/2) { + majorityEntries = candidate; + break; + } + } + + if (majorityEntries!=null) { + provider.setSettingEntries(cfgDescription, folder, languageId, majorityEntries); + } + + // second pass - assign the entries to the folders + for (IResource rc : members) { + List entries = provider.getSettingEntries(null, rc, languageId); + if (entries!=null && entries==majorityEntries) { + if (!(rc instanceof IFile)) { // preserve information which files were collected + provider.setSettingEntries(cfgDescription, rc, languageId, null); + } + } + } + } + + private static boolean isLanguageInScope(IResource rc, ICConfigurationDescription cfgDescription, String languageId) { + if (rc instanceof IFile) { + ILanguage lang = null; + try { + lang = LanguageManager.getInstance().getLanguageForFile((IFile) rc, cfgDescription); + } catch (CoreException e) { + CCorePlugin.log("Error loading language settings providers extensions", e); //$NON-NLS-1$ + } + if (lang==null || (languageId!=null && !languageId.equals(lang.getId()))) { + return false; + } + } + return true; + } + + private static boolean checkBit(int flags, int bit) { + return (flags & bit) == bit; + } + + /** + * Returns the list of setting entries of a certain kind (such as include paths) + * for the given configuration description, resource and language. This is a + * combined list for all providers taking into account settings of parent folder + * if settings for the given resource are not defined. + * + * @param cfgDescription - configuration description. + * @param rc - resource such as file or folder. + * @param languageId - language id. + * @param kind - kind of language settings entries, such as + * {@link ICSettingEntry#INCLUDE_PATH} etc. This is a binary flag + * and it is possible to specify composite kind. + * Use {@link ICSettingEntry#ALL} to get all kinds. + * @param checkLocality - specifies if parameter {@code isLocal} should be considered. + * @param isLocal - {@code true} if "local" entries should be provided and + * {@code false} for "system" entries. This makes sense for include paths where + * [#include "..."] is "local" and [#include <...>] is system. + * + * @return the list of setting entries found. + */ + private static List getSettingEntriesByKind(ICConfigurationDescription cfgDescription, + IResource rc, String languageId, int kind, boolean checkLocality, boolean isLocal) { + + List entries = new ArrayList(); + List alreadyAdded = new ArrayList(); + + List providers = cfgDescription.getLanguageSettingProviders(); + for (ILanguageSettingsProvider provider: providers) { + List providerEntries = getSettingEntriesUpResourceTree(provider, cfgDescription, rc, languageId); + for (ICLanguageSettingEntry entry : providerEntries) { + if (entry!=null) { + String entryName = entry.getName(); + boolean isRightKind = (entry.getKind() & kind) != 0; + // Only first entry is considered + // Entry flagged as "UNDEFINED" prevents adding entry with the same name down the line + if (isRightKind && !alreadyAdded.contains(entryName)) { + int flags = entry.getFlags(); + boolean isRightLocal = !checkLocality || (checkBit(flags, ICSettingEntry.LOCAL) == isLocal); + if (isRightLocal) { + if (!checkBit(flags, ICSettingEntry.UNDEFINED)) { + entries.add(entry); + } + alreadyAdded.add(entryName); + } + } + } + } + } + + return entries; + } + + /** + * Returns the list of setting entries of a certain kind (such as include paths) + * for the given configuration description, resource and language. This is a + * combined list for all providers taking into account settings of parent folder + * if settings for the given resource are not defined. For include paths both + * local (#include "...") and system (#include <...>) entries are returned. + * + * @param cfgDescription - configuration description. + * @param rc - resource such as file or folder. + * @param languageId - language id. + * @param kind - kind of language settings entries, such as + * {@link ICSettingEntry#INCLUDE_PATH} etc. This is a binary flag + * and it is possible to specify composite kind. + * Use {@link ICSettingEntry#ALL} to get all kinds. + * + * @return the list of setting entries. + */ + public static List getSettingEntriesByKind(ICConfigurationDescription cfgDescription, IResource rc, String languageId, int kind) { + return getSettingEntriesByKind(cfgDescription, rc, languageId, kind, /* checkLocality */ false, /* isLocal */ false); + } + + /** + * Returns the list of "system" (such as [#include <...>]) setting entries of a certain kind + * for the given configuration description, resource and language. This is a + * combined list for all providers taking into account settings of parent folder + * if settings for the given resource are not defined. + * + * @param cfgDescription - configuration description. + * @param rc - resource such as file or folder. + * @param languageId - language id. + * @param kind - kind of language settings entries, such as + * {@link ICSettingEntry#INCLUDE_PATH} etc. This is a binary flag + * and it is possible to specify composite kind. + * Use {@link ICSettingEntry#ALL} to get all kinds. + * + * @return the list of setting entries. + */ + public static List getSystemSettingEntriesByKind(ICConfigurationDescription cfgDescription, IResource rc, String languageId, int kind) { + return getSettingEntriesByKind(cfgDescription, rc, languageId, kind, /* checkLocality */ true, /* isLocal */ false); + } + + /** + * Returns the list of "local" (such as [#include "..."]) setting entries of a certain kind + * for the given configuration description, resource and language. This is a + * combined list for all providers taking into account settings of parent folder + * if settings for the given resource are not defined. + * + * @param cfgDescription - configuration description. + * @param rc - resource such as file or folder. + * @param languageId - language id. + * @param kind - kind of language settings entries, such as + * {@link ICSettingEntry#INCLUDE_PATH} etc. This is a binary flag + * and it is possible to specify composite kind. + * Use {@link ICSettingEntry#ALL} to get all kinds. + * + * @return the list of setting entries. + */ + public static List getLocalSettingEntriesByKind(ICConfigurationDescription cfgDescription, IResource rc, String languageId, int kind) { + return getSettingEntriesByKind(cfgDescription, rc, languageId, kind, /* checkLocality */ true, /* isLocal */ true); + } + } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsScannerInfoProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsScannerInfoProvider.java index ed3960a11bf..7ed1807860f 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsScannerInfoProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsScannerInfoProvider.java @@ -80,23 +80,23 @@ public class LanguageSettingsScannerInfoProvider implements IScannerInfoProvider LinkedHashSet macroEntries = new LinkedHashSet(); for (String langId : languageIds) { - List incSys = LanguageSettingsExtensionManager.getSystemSettingEntriesByKind(cfgDescription, rc, langId, + List incSys = LanguageSettingsProvidersSerializer.getSystemSettingEntriesByKind(cfgDescription, rc, langId, ICSettingEntry.INCLUDE_PATH); includePathEntries.addAll(incSys); - List incLocal = LanguageSettingsExtensionManager.getLocalSettingEntriesByKind(cfgDescription, rc, langId, + List incLocal = LanguageSettingsProvidersSerializer.getLocalSettingEntriesByKind(cfgDescription, rc, langId, ICSettingEntry.INCLUDE_PATH); includePathLocalEntries.addAll(incLocal); - List incFiles = LanguageSettingsExtensionManager.getSettingEntriesByKind(cfgDescription, rc, langId, + List incFiles = LanguageSettingsProvidersSerializer.getSettingEntriesByKind(cfgDescription, rc, langId, ICSettingEntry.INCLUDE_FILE); includeFileEntries.addAll(incFiles); - List macroFiles = LanguageSettingsExtensionManager.getSettingEntriesByKind(cfgDescription, rc, langId, + List macroFiles = LanguageSettingsProvidersSerializer.getSettingEntriesByKind(cfgDescription, rc, langId, ICSettingEntry.MACRO_FILE); macroFileEntries.addAll(macroFiles); - List macros = LanguageSettingsExtensionManager.getSettingEntriesByKind(cfgDescription, rc, langId, + List macros = LanguageSettingsProvidersSerializer.getSettingEntriesByKind(cfgDescription, rc, langId, ICSettingEntry.MACRO); macroEntries.addAll(macros); } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsStorage.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsStorage.java new file mode 100644 index 00000000000..d7832dc6d1f --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsStorage.java @@ -0,0 +1,378 @@ +package org.eclipse.cdt.internal.core.language.settings.providers; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; +import org.eclipse.cdt.core.settings.model.ICSettingEntry; +import org.eclipse.cdt.core.settings.model.util.CDataUtil; +import org.eclipse.cdt.core.settings.model.util.LanguageSettingEntriesSerializer; +import org.eclipse.cdt.internal.core.XmlUtil; +import org.eclipse.cdt.internal.core.parser.util.WeakHashSet; +import org.eclipse.core.resources.IResource; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +public class LanguageSettingsStorage { + private static final String ELEM_LANGUAGE = "language"; //$NON-NLS-1$ + private static final String ATTR_LANGUAGE_ID = "id"; //$NON-NLS-1$ + private static final String ELEM_RESOURCE = "resource"; //$NON-NLS-1$ + private static final String ATTR_PROJECT_PATH = "project-relative-path"; //$NON-NLS-1$ + + private static final String ELEM_ENTRY = "entry"; //$NON-NLS-1$ + private static final String ATTR_KIND = "kind"; //$NON-NLS-1$ + private static final String ATTR_NAME = "name"; //$NON-NLS-1$ + private static final String ATTR_VALUE = "value"; //$NON-NLS-1$ + private static final String ELEM_FLAG = "flag"; //$NON-NLS-1$ + + /** + * Storage to keep settings entries. Note that it is not necessary to keep configuration in the maps + * as the configuration is always the one provider belongs to. + */ + private Map>> fStorage = new HashMap>>(); + + /** + * Pool of LSE lists implemented as WeakHashSet. That allows to gain memory savings + * at the expense of CPU time. WeakHashSet handles garbage collection when a list is not + * referenced anywhere else. See JavaDoc {@link java.lang.ref.WeakReference} about weak reference objects. + */ + private static WeakHashSet> listPool = new WeakHashSet>() { + @Override + public synchronized List add(List list) { + return super.add(list); + } + + }; + + /** + *
    Note that this list is unmodifiable. To modify the list copy it, change and use + * {@link #setSettingEntries(ICConfigurationDescription, IResource, String, List)}. + * + */ + public List getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) { + List entries = null; + Map> langMap = fStorage.get(languageId); + if (langMap!=null) { + String rcProjectPath = rc!=null ? rc.getProjectRelativePath().toString() : null; + entries = langMap.get(rcProjectPath); + } + return entries; + } + + /** + * Some providers may collect entries in pretty much random order. For the purposes of + * predictability, UI usability and efficient storage the entries are sorted by kinds + * and secondary by name for kinds where the secondary order is not significant. + * + * @param entries - list of entries to sort. + * @return - sorted entries. + */ + private List sortEntries(List entries) { + List sortedEntries = new ArrayList(entries); + Collections.sort(sortedEntries, new Comparator(){ + /** + * This comparator sorts by kinds first and the macros are sorted additionally by name. + */ + public int compare(ICLanguageSettingEntry entry0, ICLanguageSettingEntry entry1) { + int kind0 = entry0.getKind(); + int kind1 = entry1.getKind(); + if (kind0==ICSettingEntry.MACRO && kind1==ICSettingEntry.MACRO) { + return entry0.getName().compareTo(entry1.getName()); + } + + return kind0 - kind1; + }}); + + return sortedEntries; + } + + /** + * + */ + public void setSettingEntries(String rcProjectPath, String languageId, List entries) { + synchronized (fStorage) { + if (entries!=null) { + Map> langMap = fStorage.get(languageId); + if (langMap==null) { + langMap = new HashMap>(); + fStorage.put(languageId, langMap); + } + List sortedEntries = listPool.add(Collections.unmodifiableList(sortEntries(entries))); + langMap.put(rcProjectPath, sortedEntries); + } else { + // do not keep nulls in the tables + Map> langMap = fStorage.get(languageId); + if (langMap!=null) { + langMap.remove(rcProjectPath); + if (langMap.size()==0) { + fStorage.remove(languageId); + } + } + } + } + } + + /** + * @return {@code true} if the provider does not keep any settings yet or {@code false} if there are some. + */ + public boolean isEmpty() { + return fStorage.isEmpty(); + } + + /** + * Clear all the entries for all configurations, all resources and all languages. + */ + public void clear() { + synchronized (fStorage) { + fStorage.clear(); + } + } + + /** + * Serialize the provider entries under parent XML element. + * @param elementProvider - element where to serialize the entries. + */ + public void serializeEntries(Element elementProvider) { + synchronized (fStorage) { + for (Entry>> entryLang : fStorage.entrySet()) { + serializeLanguage(elementProvider, entryLang); + } + } + } + + /** + * Serialize the provider entries for a given language list. + */ + private void serializeLanguage(Element parentElement, Entry>> entryLang) { + String langId = entryLang.getKey(); + if (langId!=null) { + Element elementLanguage = XmlUtil.appendElement(parentElement, ELEM_LANGUAGE, new String[] {ATTR_LANGUAGE_ID, langId}); + parentElement = elementLanguage; + } + for (Entry> entryRc : entryLang.getValue().entrySet()) { + serializeResource(parentElement, entryRc); + } + } + + /** + * Serialize the provider entries for a given resource list. + */ + private void serializeResource(Element parentElement, Entry> entryRc) { + String rcProjectPath = entryRc.getKey(); + if (rcProjectPath!=null) { + Element elementRc = XmlUtil.appendElement(parentElement, ELEM_RESOURCE, new String[] {ATTR_PROJECT_PATH, rcProjectPath}); + parentElement = elementRc; + } + serializeSettingEntries(parentElement, entryRc.getValue()); + } + + /** + * Serialize given settings entries. + */ + private void serializeSettingEntries(Element parentElement, List settingEntries) { + for (ICLanguageSettingEntry entry : settingEntries) { + Element elementSettingEntry = XmlUtil.appendElement(parentElement, ELEM_ENTRY, new String[] { + ATTR_KIND, LanguageSettingEntriesSerializer.kindToString(entry.getKind()), + ATTR_NAME, entry.getName(), + }); + switch(entry.getKind()) { + case ICSettingEntry.MACRO: + elementSettingEntry.setAttribute(ATTR_VALUE, entry.getValue()); + break; +// case ICLanguageSettingEntry.LIBRARY_FILE: +// // TODO: sourceAttachment fields may need to be covered +// break; + } + int flags = entry.getFlags(); + if (flags!=0) { + // Element elementFlag = + XmlUtil.appendElement(elementSettingEntry, ELEM_FLAG, new String[] { + ATTR_VALUE, LanguageSettingEntriesSerializer.composeFlagsString(entry.getFlags()) + }); + } + } + } + + /** + * Load provider entries from XML provider element. + * @param providerNode - parent XML element where entries are defined. + */ + public void loadEntries(Element providerNode) { + List settings = new ArrayList(); + NodeList nodes = providerNode.getChildNodes(); + for (int i=0;i0) { + setSettingEntries(null, null, settings); + } + } + + /** + * Load a setting entry from XML element. + */ + private ICLanguageSettingEntry loadSettingEntry(Node parentElement) { + String settingKind = XmlUtil.determineAttributeValue(parentElement, ATTR_KIND); + String settingName = XmlUtil.determineAttributeValue(parentElement, ATTR_NAME); + + NodeList flagNodes = parentElement.getChildNodes(); + int flags = 0; + for (int i=0;i settings = new ArrayList(); + NodeList nodes = parentNode.getChildNodes(); + for (int i=0;i0) { + setSettingEntries(null, langId, settings); + } + } + + /** + * Load entries defined in resource element. + */ + private void loadResourceElement(Node parentNode, String cfgId, String langId) { + String rcProjectPath = XmlUtil.determineAttributeValue(parentNode, ATTR_PROJECT_PATH); + + List settings = new ArrayList(); + NodeList nodes = parentNode.getChildNodes(); + for (int i=0;i0) { + setSettingEntries(rcProjectPath, langId, settings); + } + } + + /** + * @noreference This method is not intended to be referenced by clients. + * Warning: but if you use it make sure you synchronize on it while traversing. + */ + Map>> getMapInternal() { + return fStorage; + } + /** + * Clone storage for the entries. Copies references for lists of entries as a whole. + * Note that is OK as the lists kept in storage are unmodifiable. + */ + public LanguageSettingsStorage cloneStorage() { + LanguageSettingsStorage storageClone = new LanguageSettingsStorage(); + synchronized (fStorage) { + Set>>> entrySetLang = fStorage.entrySet(); + for (Entry>> entryLang : entrySetLang) { + String langId = entryLang.getKey(); + Map> mapRc = entryLang.getValue(); + Map> mapRcClone = new HashMap>(); + Set>> entrySetRc = mapRc.entrySet(); + for (Entry> entryRc : entrySetRc) { + String rcProjectPath = entryRc.getKey(); + List lsEntries = entryRc.getValue(); + // don't need to clone entries, they are from the LSE pool + mapRcClone.put(rcProjectPath, lsEntries); + } + storageClone.fStorage.put(langId, mapRcClone); + } + } + return storageClone; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((fStorage == null) ? 0 : fStorage.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + LanguageSettingsStorage other = (LanguageSettingsStorage) obj; + if (fStorage == null) { + if (other.fStorage != null) + return false; + } else if (!fStorage.equals(other.fStorage)) + return false; + return true; + } + +} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationSpecSettings.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationSpecSettings.java index 9d7ab1be7a6..8c5e1968f3f 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationSpecSettings.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationSpecSettings.java @@ -24,6 +24,8 @@ import java.util.Set; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable; import org.eclipse.cdt.core.settings.model.CExternalSetting; import org.eclipse.cdt.core.settings.model.ICBuildSetting; import org.eclipse.cdt.core.settings.model.ICConfigExtensionReference; @@ -41,7 +43,9 @@ import org.eclipse.cdt.internal.core.COwner; import org.eclipse.cdt.internal.core.COwnerConfiguration; import org.eclipse.cdt.internal.core.cdtvariables.StorableCdtVariables; import org.eclipse.cdt.internal.core.envvar.EnvironmentVariableManager; +import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsDelta; import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer; +import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsStorage; import org.eclipse.cdt.utils.envvar.StorableEnvironment; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.QualifiedName; @@ -94,6 +98,8 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ // private Map fExternalSettingsProviderMap; private List fLanguageSettingsProviders = new ArrayList(0); + private LinkedHashMap lspPersistedState = new LinkedHashMap(); + private class DeltaSet { public Set extSet; @@ -189,6 +195,10 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ copyExtensionInfo(base); fLanguageSettingsProviders = LanguageSettingsProvidersSerializer.cloneProviders(base.getLanguageSettingProviders()); + for (String providerId : base.lspPersistedState.keySet()) { + LanguageSettingsStorage clone = base.lspPersistedState.get(providerId).cloneStorage(); + lspPersistedState.put(providerId, clone); + } } // private void copyRefInfos(Map infosMap){ @@ -1011,4 +1021,40 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ public List getLanguageSettingProviders() { return Collections.unmodifiableList(fLanguageSettingsProviders); } + + /** + * Returns delta and atomically updates last persisted state to the new state. + * That implies that the delta needs to be used to fire an event of it will + * be lost. + */ + public LanguageSettingsDelta dropDelta() { + LanguageSettingsDelta languageSettingsDelta = null; + // newState gets shallow map first + LinkedHashMap newStateShallow = new LinkedHashMap(); + for (ILanguageSettingsProvider provider : fLanguageSettingsProviders) { + if (LanguageSettingsManager.isWorkspaceProvider(provider)) { + provider = LanguageSettingsManager.getRawProvider(provider); + } + if (provider instanceof LanguageSettingsSerializable) { + LanguageSettingsStorage store = ((LanguageSettingsSerializable) provider).getStorageInternal(); + if (!store.isEmpty()) { + newStateShallow.put(provider.getId(), store); + } + } + } + if (!newStateShallow.equals(lspPersistedState)) { + // do deep copy if the state needs to be saved + LinkedHashMap newStateDeep = new LinkedHashMap(); + for (Entry entry : newStateShallow.entrySet()) { + String providerId = entry.getKey(); + LanguageSettingsStorage store = entry.getValue(); + newStateDeep.put(providerId, store.cloneStorage()); + } + languageSettingsDelta = new LanguageSettingsDelta(lspPersistedState, newStateDeep); + lspPersistedState = newStateDeep; + } + + return languageSettingsDelta; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/LanguageSettingsChangeListener.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/LanguageSettingsChangeListener.java new file mode 100644 index 00000000000..e15d17e208c --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/LanguageSettingsChangeListener.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2011, 2011 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.internal.core.pdom; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.index.IIndexManager; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICProjectDescription; +import org.eclipse.cdt.internal.core.language.settings.providers.ILanguageSettingsChangeEvent; +import org.eclipse.cdt.internal.core.language.settings.providers.ILanguageSettingsChangeListener; +import org.eclipse.cdt.internal.core.model.CModelManager; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; + +/** + * This class handles changes in language settings for the PDOM by reindexing the appropriate resources. + */ +public class LanguageSettingsChangeListener implements ILanguageSettingsChangeListener { + + private IIndexManager fManager; + + public LanguageSettingsChangeListener(IIndexManager manager) { + fManager = manager; + } + + public void handleEvent(ILanguageSettingsChangeEvent event) { + String projectName = event.getProjectName(); + IWorkspaceRoot wspRoot = ResourcesPlugin.getWorkspace().getRoot(); + IProject project = wspRoot.getProject(projectName); + + ICProjectDescription prjDescription = CCorePlugin.getDefault().getProjectDescription(project); + ICConfigurationDescription indexedCfgDescription = prjDescription.getDefaultSettingConfiguration(); + + CModelManager manager = CModelManager.getDefault(); + + IResource[] resources = event.getResources(indexedCfgDescription.getId()); + + if (resources.length > 0) { + ICProject cProject = manager.getCModel().getCProject(project); + List elements = new ArrayList(); + + for (IResource rc : resources) { + // AG TODO - remove the log + CCorePlugin.log(new Status(IStatus.WARNING, CCorePlugin.PLUGIN_ID, + "LanguageSettingsChangeListener"+"["+System.identityHashCode(this)+"]"+".handleEvent() for " + rc, new Exception())); + + elements.add(manager.create(rc, cProject)); + } + + try { + fManager.update(elements.toArray(new ICElement[elements.size()]), IIndexManager.UPDATE_ALL); + } catch (CoreException e) { + CCorePlugin.log(e); + } + } + + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java index e9d85a73bd2..ee646d5b969 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java @@ -60,6 +60,7 @@ import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.LanguageManager; import org.eclipse.cdt.core.settings.model.CProjectDescriptionEvent; import org.eclipse.cdt.core.settings.model.ICProjectDescriptionListener; +import org.eclipse.cdt.core.settings.model.util.LanguageSettingEntriesSerializer; import org.eclipse.cdt.internal.core.CCoreInternals; import org.eclipse.cdt.internal.core.index.IIndexFragment; import org.eclipse.cdt.internal.core.index.IWritableIndex; @@ -68,6 +69,7 @@ import org.eclipse.cdt.internal.core.index.IndexChangeEvent; import org.eclipse.cdt.internal.core.index.IndexFactory; import org.eclipse.cdt.internal.core.index.IndexerStateEvent; import org.eclipse.cdt.internal.core.index.provider.IndexProviderManager; +import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer; import org.eclipse.cdt.internal.core.pdom.PDOM.IListener; import org.eclipse.cdt.internal.core.pdom.db.ChunkCache; import org.eclipse.cdt.internal.core.pdom.dom.IPDOMLinkageFactory; @@ -163,6 +165,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; @@ -235,6 +238,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { ResourcesPlugin.getWorkspace().addResourceChangeListener(fCModelListener, IResourceChangeEvent.POST_BUILD); model.addElementChangedListener(fCModelListener); LanguageManager.getInstance().registerLanguageChangeListener(fLanguageChangeListener); + LanguageSettingsProvidersSerializer.registerLanguageSettingsChangeListener(fLanguageSettingsChangeListener); final int types= CProjectDescriptionEvent.DATA_APPLIED; CCorePlugin.getDefault().getProjectDescriptionManager().addCProjectDescriptionListener(fProjectDescriptionListener, types); @@ -255,6 +259,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { final CoreModel model = CoreModel.getDefault(); model.removeElementChangedListener(fCModelListener); ResourcesPlugin.getWorkspace().removeResourceChangeListener(fCModelListener); + LanguageSettingsProvidersSerializer.unregisterLanguageSettingsChangeListener(fLanguageSettingsChangeListener); LanguageManager.getInstance().unregisterLanguageChangeListener(fLanguageChangeListener); PDOMIndexerJob jobToCancel= null; synchronized (fTaskQueue) { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java index 068efb454a7..e003ba067cd 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java @@ -21,7 +21,6 @@ import java.util.Map; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.jface.viewers.IDecoration; @@ -47,7 +46,6 @@ import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsEditabl import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsBaseProvider; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; -import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager_TBD; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable; import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySupport; import org.eclipse.cdt.core.model.ILanguage; @@ -1019,14 +1017,6 @@ providers: for (ILanguageSettingsProvider provider : providers) { ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(page.getProject(), enabled); enableProvidersCheckBox.setSelection(enabled); } - - try { - LanguageSettingsManager_TBD.serializeWorkspaceProviders(); - } catch (CoreException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - throw new UnsupportedOperationException("Internal Error"); - } trackInitialSettings(); updateData(getResDesc()); @@ -1063,19 +1053,4 @@ providers: for (ILanguageSettingsProvider provider : providers) { provider.setSettingEntries(cfgDescription, rc, currentLanguageId, entries); } - @Override - protected boolean isIndexerAffected() { -// List newProvidersList = null; -// ICConfigurationDescription cfgDescription = getConfigurationDescription(); -// if (cfgDescription!=null) { -// newProvidersList = cfgDescription.getLanguageSettingProviders(); -// } -// boolean newEnablement = LanguageSettingsManager.isLanguageSettingsProvidersEnabled(page.getProject()); -// -// boolean isEqualList = (newProvidersList==initialProvidersList) || (newProvidersList!=null && newProvidersList.equals(initialProvidersList)); -// return newEnablement!=initialEnablement || (newEnablement==true && !isEqualList); - // FIXME - return true; - } - } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java index 9289eb47e25..b49e82a9f1f 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java @@ -51,14 +51,8 @@ import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager_TBD; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable; import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySupport; -import org.eclipse.cdt.core.model.ILanguageDescriptor; -import org.eclipse.cdt.core.model.LanguageManager; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; -import org.eclipse.cdt.core.settings.model.ICFileDescription; -import org.eclipse.cdt.core.settings.model.ICFolderDescription; -import org.eclipse.cdt.core.settings.model.ICLanguageSetting; import org.eclipse.cdt.core.settings.model.ICResourceDescription; -import org.eclipse.cdt.core.settings.model.ICSettingBase; import org.eclipse.cdt.ui.CDTSharedImages; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.dialogs.ICOptionPage; @@ -66,7 +60,6 @@ import org.eclipse.cdt.ui.newui.AbstractCPropertyTab; import org.eclipse.cdt.ui.newui.CDTPrefUtil; import org.eclipse.cdt.utils.ui.controls.TabFolderLayout; - import org.eclipse.cdt.internal.ui.newui.Messages; import org.eclipse.cdt.internal.ui.newui.StatusMessageLine; @@ -983,13 +976,6 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { } } - try { - LanguageSettingsManager_TBD.serializeWorkspaceProviders(); - } catch (CoreException e) { - CUIPlugin.log("Internal Error", e); - throw new UnsupportedOperationException("Internal Error"); - } - trackInitialSettings(); updateData(getResDesc()); } @@ -1002,21 +988,6 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { return page.isForPrefs() || page.isForProject(); } - @Override - protected boolean isIndexerAffected() { - List newProvidersList = null; - ICConfigurationDescription cfgDescription = getConfigurationDescription(); - if (cfgDescription!=null) { - newProvidersList = cfgDescription.getLanguageSettingProviders(); - } - boolean newEnablement = ScannerDiscoveryLegacySupport.isLanguageSettingsProvidersFunctionalityEnabled(page.getProject()); - - // TODO - boolean isEqualList = false; -// boolean isEqualList = (newProvidersList==initialProvidersMap) || (newProvidersList!=null && newProvidersList.equals(initialProvidersMap)); - return newEnablement!=initialEnablement || (newEnablement==true && !isEqualList); - } - private ILanguageSettingsProvider findRawProvider(String id, List providers) { for (ILanguageSettingsProvider provider : providers) { if (provider.getId().equals(id)) { From 9beee544662e36495b1b84171233f4fa6b577f87 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Mon, 31 Oct 2011 00:36:26 -0400 Subject: [PATCH 053/120] Using PDOMManager.handlePostBuildEvent() helps with perceived performance --- .../pdom/LanguageSettingsChangeListener.java | 48 +++++-------------- 1 file changed, 13 insertions(+), 35 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/LanguageSettingsChangeListener.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/LanguageSettingsChangeListener.java index e15d17e208c..a3496768e61 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/LanguageSettingsChangeListener.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/LanguageSettingsChangeListener.java @@ -10,34 +10,23 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom; -import java.util.ArrayList; -import java.util.List; - import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.index.IIndexManager; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.internal.core.language.settings.providers.ILanguageSettingsChangeEvent; import org.eclipse.cdt.internal.core.language.settings.providers.ILanguageSettingsChangeListener; -import org.eclipse.cdt.internal.core.model.CModelManager; import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; /** * This class handles changes in language settings for the PDOM by reindexing the appropriate resources. */ public class LanguageSettingsChangeListener implements ILanguageSettingsChangeListener { - private IIndexManager fManager; + private PDOMManager fManager; - public LanguageSettingsChangeListener(IIndexManager manager) { + public LanguageSettingsChangeListener(PDOMManager manager) { fManager = manager; } @@ -46,29 +35,18 @@ public class LanguageSettingsChangeListener implements ILanguageSettingsChangeLi IWorkspaceRoot wspRoot = ResourcesPlugin.getWorkspace().getRoot(); IProject project = wspRoot.getProject(projectName); - ICProjectDescription prjDescription = CCorePlugin.getDefault().getProjectDescription(project); - ICConfigurationDescription indexedCfgDescription = prjDescription.getDefaultSettingConfiguration(); - - CModelManager manager = CModelManager.getDefault(); - - IResource[] resources = event.getResources(indexedCfgDescription.getId()); - - if (resources.length > 0) { - ICProject cProject = manager.getCModel().getCProject(project); - List elements = new ArrayList(); - - for (IResource rc : resources) { - // AG TODO - remove the log - CCorePlugin.log(new Status(IStatus.WARNING, CCorePlugin.PLUGIN_ID, - "LanguageSettingsChangeListener"+"["+System.identityHashCode(this)+"]"+".handleEvent() for " + rc, new Exception())); + if (project != null) { + ICProjectDescription prjDescription = CCorePlugin.getDefault().getProjectDescription(project); + if (prjDescription != null) { + ICConfigurationDescription indexedCfgDescription = prjDescription.getDefaultSettingConfiguration(); + String indexedCfgId = indexedCfgDescription.getId(); - elements.add(manager.create(rc, cProject)); - } - - try { - fManager.update(elements.toArray(new ICElement[elements.size()]), IIndexManager.UPDATE_ALL); - } catch (CoreException e) { - CCorePlugin.log(e); + for (String cfgId : event.getConfigurationDescriptionIds()) { + if (cfgId.equals(indexedCfgId)) { + fManager.handlePostBuildEvent(); + return; + } + } } } From 8d38ea9dbb198ad5982003af2bf16fb58d98ab16 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Tue, 1 Nov 2011 22:53:15 -0400 Subject: [PATCH 054/120] removed getResources() from ILanguageSettingsChangeEvent --- .../LanguageSettingsListenersTests.java | 16 --- .../ILanguageSettingsChangeEvent.java | 26 ++-- .../providers/LanguageSettingsDelta.java | 133 +----------------- .../LanguageSettingsProvidersSerializer.java | 23 +-- 4 files changed, 21 insertions(+), 177 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsListenersTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsListenersTests.java index b17b0351b8a..d5d73f56cb3 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsListenersTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsListenersTests.java @@ -635,8 +635,6 @@ public class LanguageSettingsListenersTests extends TestCase { assertEquals(project.getName(), event.getProjectName()); assertEquals(1, event.getConfigurationDescriptionIds().length); assertEquals(cfgDescriptionId, event.getConfigurationDescriptionIds()[0]); - assertEquals(1, event.getResources(cfgDescriptionId).length); - assertEquals(project, event.getResources(cfgDescriptionId)[0]); } } @@ -701,9 +699,6 @@ public class LanguageSettingsListenersTests extends TestCase { assertEquals(project.getName(), event.getProjectName()); assertEquals(1, event.getConfigurationDescriptionIds().length); assertEquals(cfgDescriptionId, event.getConfigurationDescriptionIds()[0]); - assertEquals(1, event.getResources(cfgDescriptionId).length); - assertEquals(project, event.getResources(cfgDescriptionId)[0]); - // TODO - drill to the entries } } @@ -774,9 +769,6 @@ public class LanguageSettingsListenersTests extends TestCase { assertEquals(project.getName(), event.getProjectName()); assertEquals(1, event.getConfigurationDescriptionIds().length); assertEquals(cfgDescriptionId, event.getConfigurationDescriptionIds()[0]); - assertEquals(1, event.getResources(cfgDescriptionId).length); - assertEquals(project, event.getResources(cfgDescriptionId)[0]); - // TODO - drill to the entries } { ICConfigurationDescription[] cfgDescriptions = prjDescription_2.getConfigurations(); @@ -935,8 +927,6 @@ public class LanguageSettingsListenersTests extends TestCase { assertEquals(project.getName(), event.getProjectName()); assertEquals(1, event.getConfigurationDescriptionIds().length); assertEquals(cfgDescriptionId, event.getConfigurationDescriptionIds()[0]); - assertEquals(1, event.getResources(cfgDescriptionId).length); - assertEquals(project, event.getResources(cfgDescriptionId)[0]); } } @@ -1014,9 +1004,6 @@ public class LanguageSettingsListenersTests extends TestCase { assertEquals(project.getName(), event.getProjectName()); assertEquals(1, event.getConfigurationDescriptionIds().length); assertEquals(cfgDescriptionId, event.getConfigurationDescriptionIds()[0]); - assertEquals(1, event.getResources(cfgDescriptionId).length); - assertEquals(project, event.getResources(cfgDescriptionId)[0]); - // TODO - drill to the entries } // Change the provider's entries back (bug was found for this case) { @@ -1052,9 +1039,6 @@ public class LanguageSettingsListenersTests extends TestCase { assertEquals(project.getName(), event.getProjectName()); assertEquals(1, event.getConfigurationDescriptionIds().length); assertEquals(cfgDescriptionId, event.getConfigurationDescriptionIds()[0]); - assertEquals(1, event.getResources(cfgDescriptionId).length); - assertEquals(project, event.getResources(cfgDescriptionId)[0]); - // TODO - drill to the entries } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/ILanguageSettingsChangeEvent.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/ILanguageSettingsChangeEvent.java index c609aad9a07..63b07601810 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/ILanguageSettingsChangeEvent.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/ILanguageSettingsChangeEvent.java @@ -11,26 +11,28 @@ package org.eclipse.cdt.internal.core.language.settings.providers; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; -import org.eclipse.core.resources.IResource; /** * Contains the details of changes that occurred as a result of modifying - * language settings entries {@link ICLanguageSettingEntry}. - * + * language settings entries {@link ICLanguageSettingEntry}. The event is + * associated with a project. + * + * API notes: this interface probably is not stable yet as it is not currently + * clear how it may need to be used in future. Only bare minimum is provided + * here at this point. + * * @noextend This interface is not intended to be extended by clients. * @noimplement This interface is not intended to be implemented by clients. */ public interface ILanguageSettingsChangeEvent { + /** + * @return project name where the event occurred. + */ public String getProjectName(); - + + /** + * @return configuration IDs which are affected by the language settings changes. + */ public String[] getConfigurationDescriptionIds(); - - public IResource[] getResources(String cfgDescriptionId); - -// // AG - YAGNI -// public List getSettingEntriesOld(ICConfigurationDescription cfgDescription, IResource rc, String languageId); -// public List getSettingEntriesNew(ICConfigurationDescription cfgDescription, IResource rc, String languageId); -// // AG - or maybe -// ILanguageSettingsDelta getDelta(ICConfigurationDescription cfgDescription); } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsDelta.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsDelta.java index 3cc23505630..4b88f99e6cf 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsDelta.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsDelta.java @@ -10,29 +10,19 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.language.settings.providers; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - -import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; -import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; -import org.eclipse.cdt.core.settings.model.ICSettingEntry; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.runtime.Assert; -// TODO possibly make an interface from that +/** + * This class currently is a placeholder holding old and new states. + * If more details need to be pulled out of delta, it could be elaborated further. + */ public class LanguageSettingsDelta { // maps need to be ordered by providers + @SuppressWarnings("unused") private LinkedHashMap oldLanguageSettingsState; + @SuppressWarnings("unused") private LinkedHashMap newLanguageSettingsState; @@ -41,115 +31,4 @@ public class LanguageSettingsDelta { newLanguageSettingsState = newState; } - // FIXME - this API is no good - public Set getChangedResources(IProject project, ICConfigurationDescription cfgDescription) { - Set resources = new HashSet(); - - // Ordered collections - Collection oldStateStorages = oldLanguageSettingsState.values(); - Collection newStateStorages = newLanguageSettingsState.values(); - - for (LanguageSettingsStorage lss : oldStateStorages) { -// Map>> - Map>> mapInternal = lss.getMapInternal(); - synchronized (mapInternal) { - for (Entry>> entryLang : mapInternal.entrySet()) { - String langId = entryLang.getKey(); - for (Entry> entryRc : entryLang.getValue().entrySet()) { - String rcName = entryRc.getKey(); - IResource rc = (rcName != null) ? project.findMember(rcName) : project; - if (resources.contains(rc)) - continue; - - List lsEntriesOld = entryRc.getValue(); - List lsEntriesNew = getSettingEntries(newStateStorages, cfgDescription, rc, langId); - - if (!lsEntriesNew.equals(lsEntriesOld) && !(lsEntriesOld==null && lsEntriesNew.size()==0)) { - resources.add(rc); - } - } - } - } - } - for (LanguageSettingsStorage lss : newStateStorages) { -// Map>> - Map>> mapInternal = lss.getMapInternal(); - synchronized (mapInternal) { - for (Entry>> entryLang : mapInternal.entrySet()) { - String langId = entryLang.getKey(); - for (Entry> entryRc : entryLang.getValue().entrySet()) { - String rcName = entryRc.getKey(); - IResource rc = (rcName != null) ? project.findMember(rcName) : project; - if (resources.contains(rc)) - continue; - - List lsEntriesNew = entryRc.getValue(); - List lsEntriesOld = getSettingEntries(oldStateStorages, cfgDescription, rc, langId); - - if (!lsEntriesOld.equals(lsEntriesNew) && !(lsEntriesNew==null && lsEntriesOld.size()==0)) { - resources.add(rc); - } - } - } - } - } - - return resources; - } - - private static boolean checkBit(int flags, int bit) { - return (flags & bit) == bit; - } - - private static List getSettingEntries(Collection stores, ICConfigurationDescription cfgDescription, IResource rc, String languageId) { - List entries = new ArrayList(); - List alreadyAdded = new ArrayList(); - - for (LanguageSettingsStorage store: stores) { - List providerEntries = getSettingEntriesUpResourceTree(store, cfgDescription, rc, languageId); - for (ICLanguageSettingEntry entry : providerEntries) { - if (entry!=null) { - String entryName = entry.getName(); - // Only first entry is considered - // Entry flagged as "UNDEFINED" prevents adding entry with the same name down the line - if (!alreadyAdded.contains(entryName)) { - int flags = entry.getFlags(); - if (!checkBit(flags, ICSettingEntry.UNDEFINED)) { - entries.add(entry); - } - alreadyAdded.add(entryName); - } - } - } - } - - return entries; - } - - private static List getSettingEntriesUpResourceTree(LanguageSettingsStorage store, ICConfigurationDescription cfgDescription, IResource rc, String languageId) { - Assert.isTrue( !(rc instanceof IWorkspaceRoot) ); - if (store!=null) { - List entries = store.getSettingEntries(cfgDescription, rc, languageId); - if (entries!=null) { - return new ArrayList(entries); - } - if (rc!=null) { - IResource parentFolder = (rc instanceof IProject) ? null : rc.getParent(); - if (parentFolder!=null) { - return getSettingEntriesUpResourceTree(store, cfgDescription, parentFolder, languageId); - } - // if out of parent resources - get default entries for the applicable language scope - entries = store.getSettingEntries(null, null, languageId); - if (entries!=null) { - return new ArrayList(entries); - } - } - } - - return new ArrayList(0); - } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java index 12450b5784d..61465c6d0c7 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java @@ -33,7 +33,6 @@ import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.internal.core.XmlUtil; import org.eclipse.cdt.internal.core.settings.model.CConfigurationSpecSettings; -import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager; import org.eclipse.cdt.internal.core.settings.model.IInternalCCfgInfo; import org.eclipse.core.filesystem.URIUtil; import org.eclipse.core.resources.IContainer; @@ -179,8 +178,6 @@ public class LanguageSettingsProvidersSerializer { private String projectName = null; private Map deltaMap = new HashMap(); - private IResource[] resources = null; - /** * The act of creating event resets internal delta count in configuration state. * That implies that when the event is retrieved it must be fired or delta will go missing. @@ -208,7 +205,6 @@ public class LanguageSettingsProvidersSerializer { CCorePlugin.log(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, ss.getMessage(), new CoreException(ss))); } } - } } @@ -217,26 +213,9 @@ public class LanguageSettingsProvidersSerializer { } public String[] getConfigurationDescriptionIds() { - String[] ids = deltaMap.keySet().toArray(new String[deltaMap.size()]); - return ids; + return deltaMap.keySet().toArray(new String[deltaMap.size()]); } - public IResource[] getResources(String cfgDescriptionId) { - if (resources == null) { - LanguageSettingsDelta delta = deltaMap.get(cfgDescriptionId); - if (delta == null) { - resources = new IResource[0]; - } else { - IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); - ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false); - ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); - resources = delta.getChangedResources(project, cfgDescription).toArray(new IResource[0]); - } - } - - return resources; - } - @Override public String toString() { return "LanguageSettingsChangeEvent for project=[" + getProjectName() + "]" From 4bd04cbdfc82cbb3b2625e76f075d35df3a1dfd6 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Tue, 1 Nov 2011 23:15:46 -0400 Subject: [PATCH 055/120] Some cleanup --- .../LanguageSettingsListenersTests.java | 2 -- .../providers/LanguageSettingsManagerTests.java | 2 +- .../providers/LanguageSettingsSerializable.java | 17 ++++------------- .../ILanguageSettingsChangeListener.java | 8 ++++++-- .../LanguageSettingsProvidersSerializer.java | 4 ++++ .../model/CConfigurationSpecSettings.java | 2 +- .../pdom/LanguageSettingsChangeListener.java | 6 ++---- .../cdt/internal/core/pdom/PDOMManager.java | 1 - 8 files changed, 18 insertions(+), 24 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsListenersTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsListenersTests.java index d5d73f56cb3..3add223b0b4 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsListenersTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsListenersTests.java @@ -1041,7 +1041,5 @@ public class LanguageSettingsListenersTests extends TestCase { assertEquals(cfgDescriptionId, event.getConfigurationDescriptionIds()[0]); } } - } - diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java index 243252ea99c..9f9e45b0bac 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java @@ -41,7 +41,7 @@ import org.eclipse.core.runtime.Path; * Test cases testing LanguageSettingsProvider functionality */ public class LanguageSettingsManagerTests extends TestCase { - // Should match id of extension point defined in plugin.xml + // Those should match ids of plugin extensions defined in plugin.xml private static final String EXTENSION_BASE_PROVIDER_ID = "org.eclipse.cdt.core.tests.language.settings.base.provider"; private static final String EXTENSION_EDITABLE_PROVIDER_ID = "org.eclipse.cdt.core.tests.custom.editable.language.settings.provider"; private static final String EXTENSION_EDITABLE_PROVIDER_NAME = "Test Plugin Mock Editable Language Settings Provider"; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java index 5c5a31b25b6..3437ccd30c7 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java @@ -13,14 +13,9 @@ package org.eclipse.cdt.core.language.settings.providers; import java.util.ArrayList; import java.util.List; -import java.util.Map; -import java.util.Map.Entry; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; -import org.eclipse.cdt.core.settings.model.ICSettingEntry; -import org.eclipse.cdt.core.settings.model.util.CDataUtil; -import org.eclipse.cdt.core.settings.model.util.LanguageSettingEntriesSerializer; import org.eclipse.cdt.internal.core.XmlUtil; import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsStorage; import org.eclipse.core.resources.IResource; @@ -166,19 +161,15 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { public void setSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId, List entries) { String rcProjectPath = rc!=null ? rc.getProjectRelativePath().toString() : null; fStorage.setSettingEntries(rcProjectPath, languageId, entries); - -// // TODO - not sure what is more efficient, to do that or not to do that? -// if (fStorage.equals(lastPersistedState)) { -// lastPersistedState = null; -// } } /** * {@inheritDoc} - *
    Note that this list is unmodifiable. To modify the list copy it, change and use + *
    + * Note that this list is unmodifiable. To modify the list copy it, change and use * {@link #setSettingEntries(ICConfigurationDescription, IResource, String, List)}. - * - *
    Note also that you can compare these lists with simple equality operator ==, + *
    + * Note also that you can compare these lists with simple equality operator ==, * as lists themselves are backed by WeakHashSet> where * identical copies (deep comparison is used) are replaced with the same one instance. */ diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/ILanguageSettingsChangeListener.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/ILanguageSettingsChangeListener.java index 9b54debd6ef..3e0ae4d1a3b 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/ILanguageSettingsChangeListener.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/ILanguageSettingsChangeListener.java @@ -11,12 +11,16 @@ package org.eclipse.cdt.internal.core.language.settings.providers; /** - * Listens to changes in language settings. + * An interface for listeners to changes in language settings. + * + * @see LanguageSettingsProvidersSerializer#registerLanguageSettingsChangeListener(ILanguageSettingsChangeListener) + * @see LanguageSettingsProvidersSerializer#unregisterLanguageSettingsChangeListener(ILanguageSettingsChangeListener) */ public interface ILanguageSettingsChangeListener { /** * Indicates that language settings have been changed. - * @param event + * + * @param event - details of the event. */ public void handleEvent(ILanguageSettingsChangeEvent event); } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java index 61465c6d0c7..fc227899852 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java @@ -174,6 +174,10 @@ public class LanguageSettingsProvidersSerializer { } } + /** + * Language Settings Change Event implementation. + * + */ private static class LanguageSettingsChangeEvent implements ILanguageSettingsChangeEvent { private String projectName = null; private Map deltaMap = new HashMap(); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationSpecSettings.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationSpecSettings.java index 8c5e1968f3f..8fb4729a924 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationSpecSettings.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationSpecSettings.java @@ -1023,7 +1023,7 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ } /** - * Returns delta and atomically 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 * be lost. */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/LanguageSettingsChangeListener.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/LanguageSettingsChangeListener.java index a3496768e61..67ccc3f082f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/LanguageSettingsChangeListener.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/LanguageSettingsChangeListener.java @@ -20,10 +20,9 @@ import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.ResourcesPlugin; /** - * This class handles changes in language settings for the PDOM by reindexing the appropriate resources. + * This class handles changes in language settings for the PDOM. */ public class LanguageSettingsChangeListener implements ILanguageSettingsChangeListener { - private PDOMManager fManager; public LanguageSettingsChangeListener(PDOMManager manager) { @@ -31,9 +30,8 @@ public class LanguageSettingsChangeListener implements ILanguageSettingsChangeLi } public void handleEvent(ILanguageSettingsChangeEvent event) { - String projectName = event.getProjectName(); IWorkspaceRoot wspRoot = ResourcesPlugin.getWorkspace().getRoot(); - IProject project = wspRoot.getProject(projectName); + IProject project = wspRoot.getProject(event.getProjectName()); if (project != null) { ICProjectDescription prjDescription = CCorePlugin.getDefault().getProjectDescription(project); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java index ee646d5b969..12dd4253ad5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java @@ -60,7 +60,6 @@ import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.LanguageManager; import org.eclipse.cdt.core.settings.model.CProjectDescriptionEvent; import org.eclipse.cdt.core.settings.model.ICProjectDescriptionListener; -import org.eclipse.cdt.core.settings.model.util.LanguageSettingEntriesSerializer; import org.eclipse.cdt.internal.core.CCoreInternals; import org.eclipse.cdt.internal.core.index.IIndexFragment; import org.eclipse.cdt.internal.core.index.IWritableIndex; From 6fb9b00592eec9579a5e55a0adeff0897e09b3d5 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Wed, 2 Nov 2011 15:12:28 -0400 Subject: [PATCH 056/120] Disable debugging traces in .log by default. --- .../providers/LanguageSettingsLogger.java | 16 ++++++++-------- .../LanguageSettingsProvidersSerializer.java | 19 ++++++++++--------- .../LanguageSettingsScannerInfoProvider.java | 4 +++- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsLogger.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsLogger.java index 7483b4100bf..40d7c54fcfa 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsLogger.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsLogger.java @@ -10,10 +10,10 @@ import org.eclipse.core.runtime.Status; @Deprecated public class LanguageSettingsLogger { - /** - * - */ - private static final boolean ENABLED = false; + public static boolean isEnabled() { + return false; +// return true; + } // AG FIXME /** @@ -22,7 +22,7 @@ public class LanguageSettingsLogger { */ @Deprecated public static void logInfo(String msg) { - if (ENABLED) { + if (isEnabled()) { Exception e = new Exception(msg); IStatus status = new Status(IStatus.INFO, CCorePlugin.PLUGIN_ID, msg, e); CCorePlugin.log(status); @@ -36,7 +36,7 @@ public class LanguageSettingsLogger { */ @Deprecated public static void logWarning(String msg) { - if (ENABLED) { + if (isEnabled()) { Exception e = new Exception(msg); IStatus status = new Status(IStatus.WARNING, CCorePlugin.PLUGIN_ID, msg, e); CCorePlugin.log(status); @@ -50,7 +50,7 @@ public class LanguageSettingsLogger { */ @Deprecated public static void logError(String msg) { - if (ENABLED) { + if (isEnabled()) { Exception e = new Exception(msg); IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, msg, e); CCorePlugin.log(status); @@ -65,7 +65,7 @@ public class LanguageSettingsLogger { */ @Deprecated public static void logScannerInfoProvider(IResource rc, Object who) { - if (ENABLED) { + if (isEnabled()) { String msg = "rc="+rc+" <-- "+who.getClass().getSimpleName(); if (rc instanceof IFile) { LanguageSettingsLogger.logInfo(msg); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java index fc227899852..5a5184c243d 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java @@ -98,16 +98,19 @@ public class LanguageSettingsProvidersSerializer { providerId = id; } + @Override public String getId() { return providerId; } + @Override public String getName() { ILanguageSettingsProvider rawProvider = getRawProvider(); String name = rawProvider!=null ? rawProvider.getName() : null; return name; } + @Override public List getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) { ILanguageSettingsProvider rawProvider = getRawProvider(); List entries = rawProvider!=null ? rawProvider.getSettingEntries(cfgDescription, rc, languageId) : null; @@ -157,6 +160,7 @@ public class LanguageSettingsProvidersSerializer { return projectCount; } + @Override public void registerListener(ICConfigurationDescription cfgDescription) { // keep in mind that rawProvider can change ILanguageSettingsProvider rawProvider = getRawProvider(); @@ -165,6 +169,7 @@ public class LanguageSettingsProvidersSerializer { } } + @Override public void unregisterListener() { // keep in mind that rawProvider can change ILanguageSettingsProvider rawProvider = getRawProvider(); @@ -212,10 +217,12 @@ public class LanguageSettingsProvidersSerializer { } } + @Override public String getProjectName() { return projectName; } + @Override public String[] getConfigurationDescriptionIds() { return deltaMap.keySet().toArray(new String[deltaMap.size()]); } @@ -363,9 +370,7 @@ projects: } public static void serializeLanguageSettingsWorkspace() throws CoreException { - // AG TODO - remove the log - CCorePlugin.log(new Status(IStatus.WARNING, CCorePlugin.PLUGIN_ID, IStatus.OK, - "LanguageSettingsProvidersSerializer.serializeLanguageSettingsWorkspace()", new Exception())); + LanguageSettingsLogger.logWarning("LanguageSettingsProvidersSerializer.serializeLanguageSettingsWorkspace()"); URI uriStoreWsp = getStoreInWorkspaceArea(STORAGE_WORKSPACE_LANGUAGE_SETTINGS); List serializableWorkspaceProviders = new ArrayList(); @@ -528,9 +533,7 @@ projects: public static void serializeLanguageSettings(ICProjectDescription prjDescription) throws CoreException { IProject project = prjDescription.getProject(); - // AG TODO - remove the log - CCorePlugin.log(new Status(IStatus.WARNING, CCorePlugin.PLUGIN_ID, IStatus.OK, - "LanguageSettingsProvidersSerializer.serializeLanguageSettings() for " + project, new Exception())); + LanguageSettingsLogger.logWarning("LanguageSettingsProvidersSerializer.serializeLanguageSettings() for " + project); try { // Document to store in project area @@ -1010,9 +1013,7 @@ projects: * @param event the ILanguageSettingsChangeEvent event to be broadcast. */ public static void notifyLanguageSettingsChangeListeners(ILanguageSettingsChangeEvent event) { - // AG TODO - remove the log - CCorePlugin.log(new Status(IStatus.WARNING, CCorePlugin.PLUGIN_ID, IStatus.OK, - "Firing " + event, new Exception())); + LanguageSettingsLogger.logWarning("Firing " + event); Object[] listeners = fLanguageSettingsChangeListeners.getListeners(); for (Object obj : listeners) { diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsScannerInfoProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsScannerInfoProvider.java index 7ed1807860f..d34a52176b3 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsScannerInfoProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsScannerInfoProvider.java @@ -50,8 +50,8 @@ import org.eclipse.osgi.util.NLS; public class LanguageSettingsScannerInfoProvider implements IScannerInfoProvider { private static final ExtendedScannerInfo DUMMY_SCANNER_INFO = new ExtendedScannerInfo(); + @Override public ExtendedScannerInfo getScannerInformation(IResource rc) { - // AG FIXME LanguageSettingsLogger.logScannerInfoProvider(rc, this); IProject project = rc.getProject(); @@ -250,10 +250,12 @@ public class LanguageSettingsScannerInfoProvider implements IScannerInfoProvider return (flags & bit) == bit; } + @Override public void subscribe(IResource resource, IScannerInfoChangeListener listener) { // Handled by ScannerInfoProviderProxy for the moment } + @Override public void unsubscribe(IResource resource, IScannerInfoChangeListener listener) { // Handled by ScannerInfoProviderProxy for the moment } From 568cdaa6347b864150e3b051bb083196d9096a30 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Wed, 2 Nov 2011 17:40:16 -0400 Subject: [PATCH 057/120] More traces disabled --- .../AbstractBuiltinSpecsDetector.java | 18 ++++++------------ .../AbstractLanguageSettingsOutputScanner.java | 8 ++------ 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java index 02ac1c74c7d..b553f813981 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java @@ -40,6 +40,7 @@ import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.internal.core.ConsoleOutputSniffer; import org.eclipse.cdt.internal.core.XmlUtil; +import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsLogger; import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer; import org.eclipse.cdt.make.core.MakeCorePlugin; import org.eclipse.cdt.make.internal.core.MakeMessages; @@ -236,18 +237,14 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti } public void registerListener(ICConfigurationDescription cfgDescription) { - currentCfgDescription = cfgDescription; - // TODO - remove me - CCorePlugin.log(new Status(IStatus.INFO,CCorePlugin.PLUGIN_ID, - getPrefixForLog() + "Added listener [" + System.identityHashCode(this) + "] " + this)); + LanguageSettingsLogger.logInfo(getPrefixForLog() + "registerListener [" + System.identityHashCode(this) + "] " + this); + currentCfgDescription = cfgDescription; execute(); } public void unregisterListener() { - // TODO - remove me - CCorePlugin.log(new Status(IStatus.INFO,CCorePlugin.PLUGIN_ID, - getPrefixForLog() + "Removed listener [" + System.identityHashCode(this) + "] " + this)); + LanguageSettingsLogger.logInfo(getPrefixForLog() + "unregisterListener [" + System.identityHashCode(this) + "] " + this); } protected void execute() { @@ -284,9 +281,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti job.schedule(); // TODO - remove me - CCorePlugin.log(new Status(IStatus.INFO,CCorePlugin.PLUGIN_ID, - getPrefixForLog() + "Execution scheduled [" + System.identityHashCode(this) + "] " + this)); - + LanguageSettingsLogger.logInfo(getPrefixForLog() + "Execution scheduled [" + System.identityHashCode(this) + "] " + this); } /** @@ -428,9 +423,8 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti if (detectedSettingEntries != null && detectedSettingEntries.size() > 0) { collected = detectedSettingEntries.size(); - IStatus status = new Status(IStatus.INFO, MakeCorePlugin.PLUGIN_ID, getPrefixForLog() + LanguageSettingsLogger.logInfo(getPrefixForLog() + getClass().getSimpleName() + " collected " + detectedSettingEntries.size() + " entries" + " for language " + currentLanguageId); - MakeCorePlugin.log(status); setSettingEntries(currentCfgDescription, currentResource, currentLanguageId, detectedSettingEntries); } diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java index 30153820a62..18745eb003c 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java @@ -36,6 +36,7 @@ import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.core.settings.model.util.CDataUtil; import org.eclipse.cdt.internal.core.XmlUtil; +import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsLogger; import org.eclipse.cdt.make.core.MakeCorePlugin; import org.eclipse.cdt.utils.EFSExtensionManager; import org.eclipse.core.filesystem.EFS; @@ -47,10 +48,8 @@ import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.content.IContentType; import org.eclipse.core.runtime.content.IContentTypeManager; import org.w3c.dom.Element; @@ -315,15 +314,12 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett } return str + ": "; } - protected void setSettingEntries(List entries) { setSettingEntries(currentCfgDescription, currentResource, currentLanguageId, entries); - // TODO - for debugging only, eventually remove - IStatus status = new Status(IStatus.INFO, MakeCorePlugin.PLUGIN_ID, getPrefixForLog() + LanguageSettingsLogger.logInfo(getPrefixForLog() + getClass().getSimpleName() + " collected " + (entries!=null ? ("" + entries.size()) : "null") + " entries for " + currentResource); - MakeCorePlugin.log(status); } protected String determineLanguage() { From 503f335c1981b9f50695d25961e182f225c8f032 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Wed, 2 Nov 2011 17:24:03 -0400 Subject: [PATCH 058/120] Checking for unexpected log entries (exceptions) in tests. --- .../BuiltinSpecsDetectorTest.java | 12 +++++----- .../GCCBuildCommandParserTest.java | 12 +++++----- .../AbstractBuildCommandParser.java | 22 +++++++++++++++++-- .../AbstractBuiltinSpecsDetector.java | 13 +++++++++++ .../tests/GCCBuiltinSpecsDetectorTest.java | 8 +++---- .../LanguageSettingsExtensionsTests.java | 6 +++-- .../LanguageSettingsListenersTests.java | 8 ++++--- .../LanguageSettingsManagerTests.java | 22 +++++++++++-------- ...nguageSettingsPersistenceProjectTests.java | 7 +++--- ...guageSettingsScannerInfoProviderTests.java | 10 ++++++--- .../LanguageSettingsSerializableTests.java | 7 +++--- .../LanguageSettingsProvidersSerializer.java | 5 ++++- 12 files changed, 92 insertions(+), 40 deletions(-) diff --git a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/BuiltinSpecsDetectorTest.java b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/BuiltinSpecsDetectorTest.java index a33e47724a3..2985f1ff23b 100644 --- a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/BuiltinSpecsDetectorTest.java +++ b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/BuiltinSpecsDetectorTest.java @@ -15,8 +15,6 @@ import java.io.OutputStream; import java.util.ArrayList; import java.util.List; -import junit.framework.TestCase; - import org.eclipse.cdt.core.ErrorParserManager; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.settings.model.CIncludeFileEntry; @@ -31,6 +29,7 @@ import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager; import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.core.testplugin.ResourceHelper; +import org.eclipse.cdt.core.testplugin.util.BaseTestCase; import org.eclipse.cdt.internal.core.XmlUtil; import org.eclipse.cdt.make.core.scannerconfig.AbstractBuiltinSpecsDetector; import org.eclipse.core.resources.IProject; @@ -39,10 +38,11 @@ import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.jobs.Job; import org.w3c.dom.Document; import org.w3c.dom.Element; -public class BuiltinSpecsDetectorTest extends TestCase { +public class BuiltinSpecsDetectorTest extends BaseTestCase { private static final String PROVIDER_ID = "provider.id"; private static final String PROVIDER_NAME = "provider name"; private static final String LANGUAGE_ID = "language.test.id"; @@ -119,18 +119,20 @@ public class BuiltinSpecsDetectorTest extends TestCase { @Override protected void setUp() throws Exception { + super.setUp(); } @Override protected void tearDown() throws Exception { - ResourceHelper.cleanUp(); + Job.getJobManager().join(AbstractBuiltinSpecsDetector.JOB_FAMILY_BUILTIN_SPECS_DETECTOR, null); + super.tearDown(); } private ICConfigurationDescription[] getConfigurationDescriptions(IProject project) { CoreModel coreModel = CoreModel.getDefault(); ICProjectDescriptionManager mngr = coreModel.getProjectDescriptionManager(); // project description - ICProjectDescription projectDescription = mngr.getProjectDescription(project); + ICProjectDescription projectDescription = mngr.getProjectDescription(project, false); assertNotNull(projectDescription); assertEquals(1, projectDescription.getConfigurations().length); // configuration description diff --git a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java index 1ca9c583c01..c2acde9bd33 100644 --- a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java +++ b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java @@ -18,8 +18,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import junit.framework.TestCase; - import org.eclipse.cdt.core.ErrorParserManager; import org.eclipse.cdt.core.dom.ast.gnu.cpp.GPPLanguage; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; @@ -37,6 +35,7 @@ import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager; import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.core.testplugin.ResourceHelper; +import org.eclipse.cdt.core.testplugin.util.BaseTestCase; import org.eclipse.cdt.internal.core.XmlUtil; import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager; import org.eclipse.cdt.make.core.scannerconfig.AbstractBuildCommandParser; @@ -51,10 +50,11 @@ import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.content.IContentType; import org.eclipse.core.runtime.content.IContentTypeManager; import org.eclipse.core.runtime.content.IContentTypeSettings; +import org.eclipse.core.runtime.jobs.Job; import org.w3c.dom.Document; import org.w3c.dom.Element; -public class GCCBuildCommandParserTest extends TestCase { +public class GCCBuildCommandParserTest extends BaseTestCase { // ID of the parser taken from the extension point private static final String GCC_BUILD_COMMAND_PARSER_EXT = "org.eclipse.cdt.make.core.build.command.parser.gcc"; //$NON-NLS-1$ @@ -81,18 +81,20 @@ public class GCCBuildCommandParserTest extends TestCase { @Override protected void setUp() throws Exception { + super.setUp(); } @Override protected void tearDown() throws Exception { - ResourceHelper.cleanUp(); + Job.getJobManager().join(AbstractBuildCommandParser.JOB_FAMILY_BUILD_COMMAND_PARSER, null); + super.tearDown(); } private ICConfigurationDescription[] getConfigurationDescriptions(IProject project) { CoreModel coreModel = CoreModel.getDefault(); ICProjectDescriptionManager mngr = coreModel.getProjectDescriptionManager(); // project description - ICProjectDescription projectDescription = mngr.getProjectDescription(project); + ICProjectDescription projectDescription = mngr.getProjectDescription(project, false); assertNotNull(projectDescription); assertEquals(1, projectDescription.getConfigurations().length); // configuration description diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java index 6b7f21f3682..b0dff614c2d 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java @@ -16,6 +16,7 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.ErrorParserManager; import org.eclipse.cdt.core.ICConsoleParser; import org.eclipse.cdt.core.IErrorParser; @@ -25,10 +26,10 @@ import org.eclipse.cdt.core.errorparsers.RegexErrorParser; import org.eclipse.cdt.core.errorparsers.RegexErrorPattern; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; -import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.internal.core.ConsoleOutputSniffer; import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer; import org.eclipse.cdt.make.core.MakeCorePlugin; +import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; @@ -46,6 +47,8 @@ import org.eclipse.core.runtime.jobs.Job; public abstract class AbstractBuildCommandParser extends AbstractLanguageSettingsOutputScanner implements ICConsoleParser, IErrorParser { + public static final Object JOB_FAMILY_BUILD_COMMAND_PARSER = "org.eclipse.cdt.make.core.scannerconfig.AbstractBuildCommandParser"; + private static final String LEADING_PATH_PATTERN = "\\S+[/\\\\]"; //$NON-NLS-1$ private static final Pattern OPTIONS_PATTERN = Pattern.compile("-[^\\s\"']*(\\s*((\".*?\")|('.*?')|([^-\\s][^\\s]+)))?"); //$NON-NLS-1$ private static final int OPTION_GROUP = 0; @@ -115,6 +118,7 @@ public abstract class AbstractBuildCommandParser extends AbstractLanguageSetting return options; } + @Override public boolean processLine(String line) { return processLine(line, null); } @@ -159,11 +163,24 @@ public abstract class AbstractBuildCommandParser extends AbstractLanguageSetting thread.setName(oldName); return status; } + @Override + public boolean belongsTo(Object family) { + return family == JOB_FAMILY_BUILD_COMMAND_PARSER; + } }; ISchedulingRule rule = null; if (currentProject != null) { - rule = currentProject.getFile(".settings/language.settings.xml"); + IFolder settingsFolder = currentProject.getFolder(".settings"); + if (!settingsFolder.exists()) { + try { + settingsFolder.create(true, true, null); + if (settingsFolder.isAccessible()) + rule = currentProject.getFile(".settings/language.settings.xml"); + } catch (CoreException e) { + CCorePlugin.log(e); + } + } } if (rule == null) { rule = ResourcesPlugin.getWorkspace().getRoot(); @@ -193,6 +210,7 @@ public abstract class AbstractBuildCommandParser extends AbstractLanguageSetting } } + @Override public int getProcessLineBehaviour() { return KEEP_LONGLINES; } diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java index b553f813981..b4a5c97e452 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java @@ -69,6 +69,8 @@ import org.eclipse.core.runtime.jobs.Job; import org.w3c.dom.Element; public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSettingsOutputScanner implements ICListenerRegisterer { + public static final Object JOB_FAMILY_BUILTIN_SPECS_DETECTOR = "org.eclipse.cdt.make.core.scannerconfig.AbstractBuiltinSpecsDetector"; + private static final int TICKS_STREAM_MONITOR = 100; private static final int TICKS_CLEAN_MARKERS = 1; private static final int TICKS_RUN_FOR_ONE_LANGUAGE = 10; @@ -102,11 +104,13 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti protected static final String SCANNER_DISCOVERY_PROBLEM_MARKER = MakeCorePlugin.PLUGIN_ID + ".scanner.discovery.problem"; //$NON-NLS-1$ protected static final String PROVIDER = "provider"; //$NON-NLS-1$ + @Override public void addMarker(IResource file, int lineNumber, String errorDesc, int severity, String errorVar) { ProblemMarkerInfo info = new ProblemMarkerInfo(file, lineNumber, errorDesc, severity, errorVar); addMarker(info); } + @Override public void addMarker(final ProblemMarkerInfo problemMarkerInfo) { final String providerName = getName(); final String providerId = getId(); @@ -164,12 +168,15 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti * */ private class ConsoleParser implements ICConsoleParser { + @Override public void startup(ICConfigurationDescription cfgDescription) throws CoreException { // not used here, see instead startupForLanguage() in AbstractBuiltinSpecsDetector.runForEachLanguage(...) } + @Override public boolean processLine(String line) { return AbstractBuiltinSpecsDetector.this.processLine(line, errorParserManager); } + @Override public void shutdown() { // not used here, see instead shutdownForLanguage() in AbstractBuiltinSpecsDetector.runForEachLanguage(...) } @@ -236,6 +243,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti return buildDirURI; } + @Override public void registerListener(ICConfigurationDescription cfgDescription) { LanguageSettingsLogger.logInfo(getPrefixForLog() + "registerListener [" + System.identityHashCode(this) + "] " + this); @@ -243,6 +251,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti execute(); } + @Override public void unregisterListener() { LanguageSettingsLogger.logInfo(getPrefixForLog() + "unregisterListener [" + System.identityHashCode(this) + "] " + this); } @@ -261,6 +270,10 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti protected IStatus run(IProgressMonitor monitor) { return runForEachLanguage(currentCfgDescription, null, null, monitor); } + @Override + public boolean belongsTo(Object family) { + return family == JOB_FAMILY_BUILTIN_SPECS_DETECTOR; + } }; IProject ownerProject = null; diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/GCCBuiltinSpecsDetectorTest.java b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/GCCBuiltinSpecsDetectorTest.java index 104a80775f4..da2257694e4 100644 --- a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/GCCBuiltinSpecsDetectorTest.java +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/GCCBuiltinSpecsDetectorTest.java @@ -13,8 +13,6 @@ import java.util.ArrayList; import java.util.List; -import junit.framework.TestCase; - import org.eclipse.cdt.core.dom.ast.gnu.c.GCCLanguage; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.settings.model.CIncludePathEntry; @@ -25,6 +23,7 @@ import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager; import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.core.testplugin.ResourceHelper; +import org.eclipse.cdt.core.testplugin.util.BaseTestCase; import org.eclipse.cdt.managedbuilder.internal.scannerconfig.GCCBuiltinSpecsDetector; import org.eclipse.cdt.managedbuilder.internal.scannerconfig.GCCBuiltinSpecsDetectorCygwin; import org.eclipse.core.resources.IProject; @@ -32,7 +31,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; -public class GCCBuiltinSpecsDetectorTest extends TestCase { +public class GCCBuiltinSpecsDetectorTest extends BaseTestCase { private static final String LANGUAGE_ID_C = GCCLanguage.ID; class MockGCCBuiltinSpecsDetector extends GCCBuiltinSpecsDetector { @@ -59,11 +58,12 @@ public class GCCBuiltinSpecsDetectorTest extends TestCase { @Override protected void setUp() throws Exception { + super.setUp(); } @Override protected void tearDown() throws Exception { - ResourceHelper.cleanUp(); + super.tearDown(); } private ICConfigurationDescription[] getConfigurationDescriptions(IProject project) { diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java index fcea54ca22f..0783df36eee 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java @@ -14,7 +14,6 @@ package org.eclipse.cdt.core.language.settings.providers; import java.util.ArrayList; import java.util.List; -import junit.framework.TestCase; import junit.framework.TestSuite; import org.eclipse.cdt.core.settings.model.CIncludeFileEntry; @@ -25,6 +24,7 @@ import org.eclipse.cdt.core.settings.model.CMacroEntry; import org.eclipse.cdt.core.settings.model.CMacroFileEntry; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICSettingEntry; +import org.eclipse.cdt.core.testplugin.util.BaseTestCase; import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsExtensionManager; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.ResourcesPlugin; @@ -33,7 +33,7 @@ import org.eclipse.core.runtime.Path; /** * Test cases testing LanguageSettingsProvider functionality */ -public class LanguageSettingsExtensionsTests extends TestCase { +public class LanguageSettingsExtensionsTests extends BaseTestCase { // These should match corresponding entries defined in plugin.xml private static final String EXTENSION_BASE_PROVIDER_ID = "org.eclipse.cdt.core.tests.language.settings.base.provider"; private static final String EXTENSION_BASE_PROVIDER_NAME = "Test Plugin Mock Language Settings Base Provider"; @@ -63,10 +63,12 @@ public class LanguageSettingsExtensionsTests extends TestCase { @Override protected void setUp() throws Exception { + super.setUp(); } @Override protected void tearDown() throws Exception { + super.tearDown(); } /** diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsListenersTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsListenersTests.java index 3add223b0b4..bb2915a5359 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsListenersTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsListenersTests.java @@ -14,7 +14,6 @@ package org.eclipse.cdt.core.language.settings.providers; import java.util.ArrayList; import java.util.List; -import junit.framework.TestCase; import junit.framework.TestSuite; import org.eclipse.cdt.core.model.CoreModel; @@ -23,6 +22,7 @@ import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.core.testplugin.ResourceHelper; +import org.eclipse.cdt.core.testplugin.util.BaseTestCase; import org.eclipse.cdt.internal.core.language.settings.providers.ILanguageSettingsChangeEvent; import org.eclipse.cdt.internal.core.language.settings.providers.ILanguageSettingsChangeListener; import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer; @@ -31,7 +31,7 @@ import org.eclipse.core.resources.IProject; /** * Test cases testing LanguageSettingsProvider functionality */ -public class LanguageSettingsListenersTests extends TestCase { +public class LanguageSettingsListenersTests extends BaseTestCase { // Must match provider id defined as extension point private static final String EXTENSION_REGISTERER_PROVIDER_ID = "org.eclipse.cdt.core.tests.language.settings.listener.registerer.provider"; private static final String EXTENSION_EDITABLE_PROVIDER_ID = "org.eclipse.cdt.core.tests.custom.editable.language.settings.provider"; @@ -46,6 +46,7 @@ public class LanguageSettingsListenersTests extends TestCase { private int count = 0; private ILanguageSettingsChangeEvent lastEvent = null; + @Override public void handleEvent(ILanguageSettingsChangeEvent event) { count++; lastEvent = event; @@ -77,13 +78,14 @@ public class LanguageSettingsListenersTests extends TestCase { @Override protected void setUp() throws Exception { + super.setUp(); } @Override protected void tearDown() throws Exception { LanguageSettingsProvidersSerializer.unregisterLanguageSettingsChangeListener(mockLseListener); LanguageSettingsManager.setWorkspaceProviders(null); - ResourceHelper.cleanUp(); + super.tearDown(); } /** diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java index 9f9e45b0bac..71f8fa663e9 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java @@ -14,7 +14,6 @@ package org.eclipse.cdt.core.language.settings.providers; import java.util.ArrayList; import java.util.List; -import junit.framework.TestCase; import junit.framework.TestSuite; import org.eclipse.cdt.core.AbstractExecutableExtensionBase; @@ -28,6 +27,7 @@ import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.core.testplugin.CModelMock; import org.eclipse.cdt.core.testplugin.ResourceHelper; +import org.eclipse.cdt.core.testplugin.util.BaseTestCase; import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer; import org.eclipse.cdt.internal.core.settings.model.CConfigurationDescription; import org.eclipse.core.resources.IFile; @@ -40,7 +40,7 @@ import org.eclipse.core.runtime.Path; /** * Test cases testing LanguageSettingsProvider functionality */ -public class LanguageSettingsManagerTests extends TestCase { +public class LanguageSettingsManagerTests extends BaseTestCase { // Those should match ids of plugin extensions defined in plugin.xml private static final String EXTENSION_BASE_PROVIDER_ID = "org.eclipse.cdt.core.tests.language.settings.base.provider"; private static final String EXTENSION_EDITABLE_PROVIDER_ID = "org.eclipse.cdt.core.tests.custom.editable.language.settings.provider"; @@ -82,6 +82,7 @@ public class LanguageSettingsManagerTests extends TestCase { this.entries = entries; } + @Override public List getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) { return entries; } @@ -99,12 +100,13 @@ public class LanguageSettingsManagerTests extends TestCase { @Override protected void setUp() throws Exception { + super.setUp(); } @Override protected void tearDown() throws Exception { LanguageSettingsManager.setWorkspaceProviders(null); - ResourceHelper.cleanUp(); + super.tearDown(); } /** @@ -231,6 +233,8 @@ public class LanguageSettingsManagerTests extends TestCase { // use careless provider causing an exception { + setExpectedNumberOfLoggedNonOKStatusObjects(1); + ILanguageSettingsProvider providerNPE = new MockProvider(PROVIDER_1, PROVIDER_NAME_1, null) { @Override public List getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) { @@ -270,14 +274,14 @@ public class LanguageSettingsManagerTests extends TestCase { }; providers.add(providerYes); - // define provider returning null when configuration id matches and some entries otherwise + // define provider returning entries when configuration id does NOT match and null otherwise ILanguageSettingsProvider providerNo = new MockProvider(PROVIDER_1, PROVIDER_NAME_1, null) { @Override public List getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) { - if (cfgDescription.getId().equals(modelCfgDescription.getId())) { - return null; + if (cfgDescription!= null && !cfgDescription.getId().equals(modelCfgDescription.getId())) { + return entries; } - return entries; + return null; } }; @@ -376,10 +380,10 @@ public class LanguageSettingsManagerTests extends TestCase { ILanguageSettingsProvider provider = new MockProvider(PROVIDER_0, PROVIDER_NAME_0, null) { @Override public List getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) { - if (rc.equals(parentFolder)) { + if (rc!=null && rc.equals(parentFolder)) { return entries; } - if (rc.equals(emptySettingsPath)) { + if (rc!=null && rc.equals(emptySettingsPath)) { return new ArrayList(0); } return null; diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java index d35904d7f8c..90406f5e144 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java @@ -14,7 +14,6 @@ package org.eclipse.cdt.core.language.settings.providers; import java.util.ArrayList; import java.util.List; -import junit.framework.TestCase; import junit.framework.TestSuite; import org.eclipse.cdt.core.CCorePlugin; @@ -27,6 +26,7 @@ import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager; import org.eclipse.cdt.core.settings.model.WriteAccessException; import org.eclipse.cdt.core.testplugin.CModelMock; import org.eclipse.cdt.core.testplugin.ResourceHelper; +import org.eclipse.cdt.core.testplugin.util.BaseTestCase; import org.eclipse.cdt.internal.core.XmlUtil; import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer; import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager; @@ -39,7 +39,7 @@ import org.w3c.dom.Element; /** * Test cases testing LanguageSettingsProvider functionality */ -public class LanguageSettingsPersistenceProjectTests extends TestCase { +public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { private static final String LANGUAGE_SETTINGS_PROJECT_XML = ".settings/language.settings.xml"; private static final String LANGUAGE_SETTINGS_WORKSPACE_XML = "language.settings.xml"; // Should match extension points defined in plugin.xml @@ -128,12 +128,13 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase { @Override protected void setUp() throws Exception { + super.setUp(); } @Override protected void tearDown() throws Exception { LanguageSettingsManager.setWorkspaceProviders(null); - ResourceHelper.cleanUp(); + super.tearDown(); } /** diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsScannerInfoProviderTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsScannerInfoProviderTests.java index dd2f0fa285d..bdc83f649a2 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsScannerInfoProviderTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsScannerInfoProviderTests.java @@ -15,7 +15,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import junit.framework.TestCase; import junit.framework.TestSuite; import org.eclipse.cdt.core.model.ILanguage; @@ -32,6 +31,7 @@ import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.core.testplugin.ResourceHelper; +import org.eclipse.cdt.core.testplugin.util.BaseTestCase; import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsScannerInfoProvider; import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager; import org.eclipse.core.resources.IFile; @@ -46,7 +46,7 @@ import org.eclipse.core.runtime.Path; /** * Test cases testing LanguageSettingsProvider functionality */ -public class LanguageSettingsScannerInfoProviderTests extends TestCase { +public class LanguageSettingsScannerInfoProviderTests extends BaseTestCase { private static final IFile FAKE_FILE = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("/project/path0")); private static final String PROVIDER_ID = "test.provider.id"; private static final String PROVIDER_ID_2 = "test.provider.id.2"; @@ -81,11 +81,12 @@ public class LanguageSettingsScannerInfoProviderTests extends TestCase { @Override protected void setUp() throws Exception { + super.setUp(); } @Override protected void tearDown() throws Exception { - ResourceHelper.cleanUp(); + super.tearDown(); } /** @@ -177,6 +178,9 @@ public class LanguageSettingsScannerInfoProviderTests extends TestCase { ILanguage language = LanguageManager.getInstance().getLanguageForFile(file, cfgDescription); assertNull(language); + // AG FIXME - temporarily ignore the entry in the log + setExpectedNumberOfLoggedNonOKStatusObjects(1); + ExtendedScannerInfo info = scannerInfoProvider.getScannerInformation(file); assertEquals(0, info.getIncludePaths().length); assertEquals(0, info.getDefinedSymbols().size()); diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java index f8dcc9d252b..e3e9f98b546 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java @@ -14,7 +14,6 @@ package org.eclipse.cdt.core.language.settings.providers; import java.util.ArrayList; import java.util.List; -import junit.framework.TestCase; import junit.framework.TestSuite; import org.eclipse.cdt.core.settings.model.CIncludeFileEntry; @@ -28,6 +27,7 @@ import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.core.testplugin.CModelMock; import org.eclipse.cdt.core.testplugin.ResourceHelper; +import org.eclipse.cdt.core.testplugin.util.BaseTestCase; import org.eclipse.cdt.internal.core.XmlUtil; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; @@ -41,7 +41,7 @@ import org.w3c.dom.Element; /** * Test cases testing LanguageSettingsProvider functionality */ -public class LanguageSettingsSerializableTests extends TestCase { +public class LanguageSettingsSerializableTests extends BaseTestCase { private static final String CFG_ID = "test.configuration.id"; private static final ICConfigurationDescription MOCK_CFG = new CModelMock.DummyCConfigurationDescription(CFG_ID); private static final IResource MOCK_RC = ResourcesPlugin.getWorkspace().getRoot(); @@ -70,11 +70,12 @@ public class LanguageSettingsSerializableTests extends TestCase { @Override protected void setUp() throws Exception { + super.setUp(); } @Override protected void tearDown() throws Exception { - ResourceHelper.cleanUp(); + super.tearDown(); } /** diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java index 5a5184c243d..9c6e6c8bbeb 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java @@ -193,7 +193,10 @@ public class LanguageSettingsProvidersSerializer { * That side effect is here to ensure atomic processing of firing & resetting the delta. */ public LanguageSettingsChangeEvent(ICProjectDescription prjDescription) { - Assert.isTrue(prjDescription.isReadOnly()); + if (!prjDescription.isReadOnly()) { + String msg = "Project description " + prjDescription.getName() + " is expected to be read-only"; + CCorePlugin.log(new Status(IStatus.WARNING, CCorePlugin.PLUGIN_ID, msg, new Exception(msg))); + } projectName = prjDescription.getName(); ICConfigurationDescription[] cfgDescriptions = prjDescription.getConfigurations(); From dd426b81afa974e47645bc0bd2eabb71d5d004dd Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Wed, 2 Nov 2011 23:34:05 -0400 Subject: [PATCH 059/120] Related to commit "removed getResources() from ILanguageSettingsChangeEvent" --- .../settings/providers/LanguageSettingsStorage.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsStorage.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsStorage.java index d7832dc6d1f..0b9840b3d6d 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsStorage.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsStorage.java @@ -83,6 +83,7 @@ public class LanguageSettingsStorage { /** * This comparator sorts by kinds first and the macros are sorted additionally by name. */ + @Override public int compare(ICLanguageSettingEntry entry0, ICLanguageSettingEntry entry1) { int kind0 = entry0.getKind(); int kind1 = entry1.getKind(); @@ -318,13 +319,6 @@ public class LanguageSettingsStorage { } } - /** - * @noreference This method is not intended to be referenced by clients. - * Warning: but if you use it make sure you synchronize on it while traversing. - */ - Map>> getMapInternal() { - return fStorage; - } /** * Clone storage for the entries. Copies references for lists of entries as a whole. * Note that is OK as the lists kept in storage are unmodifiable. From df61909094f2af9fda2b7099870066e27af9fed9 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Thu, 3 Nov 2011 15:18:41 -0400 Subject: [PATCH 060/120] clearing providers relaxed --- .../settings/providers/LanguageSettingsProviderTab.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java index b49e82a9f1f..750fd028d24 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java @@ -302,6 +302,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { tableProvidersViewer.setLabelProvider(new ProvidersTableLabelProvider()); tableProvidersViewer.addCheckStateListener(new ICheckStateListener() { + @Override public void checkStateChanged(CheckStateChangedEvent e) { saveCheckedProviders(e.getElement()); tableProvidersViewer.update(e.getElement(), null); @@ -320,6 +321,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { link.setLayoutData(gd); link.addListener(SWT.Selection, new Listener() { + @Override public void handleEvent(Event event) { // Use event.text to tell which link was used PreferencesUtil.createPreferenceDialogOn(parent.getShell(), WORKSPACE_PREFERENCE_PAGE, null, null).open(); @@ -521,6 +523,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { // ensure sorting by name all unchecked providers Set allAvailableProvidersSet = new TreeSet(new Comparator() { + @Override public int compare(ILanguageSettingsProvider prov1, ILanguageSettingsProvider prov2) { Boolean isTest1 = prov1.getId().matches(TEST_PLUGIN_ID_PATTERN); Boolean isTest2 = prov2.getId().matches(TEST_PLUGIN_ID_PATTERN); @@ -679,9 +682,10 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); boolean canClear = false; if (rawProvider instanceof ILanguageSettingsEditableProvider) { - if (!((ILanguageSettingsEditableProvider) rawProvider).isEmpty()) { + // TODO - commented out because we need the means to restart failed Spec Detectors +// if (!((ILanguageSettingsEditableProvider) rawProvider).isEmpty()) { canClear = canForWorkspace || canForProject; - } +// } } boolean canReset = false; From 4f2f3a918def28f29576e46b153e01b2a3b9756f Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Thu, 3 Nov 2011 18:49:15 -0400 Subject: [PATCH 061/120] Ability to parse build output running project build from subfolder in Make Target view --- .../GCCBuildCommandParserTest.java | 40 +++++++++++++++++++ ...AbstractLanguageSettingsOutputScanner.java | 6 ++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java index c2acde9bd33..e6f11f55714 100644 --- a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java +++ b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java @@ -950,6 +950,46 @@ public class GCCBuildCommandParserTest extends BaseTestCase { } } + /** + */ + public void testFileIgnoreWrongBuildDir() throws Exception { + // Create model project and accompanied descriptions + String projectName = getName(); + IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); + IFolder folder1=ResourceHelper.createFolder(project, "Folder1"); + IFile file=ResourceHelper.createFile(project, "Folder1/Folder2/file.cpp"); + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + + ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); + String languageId = ls.getLanguageId(); + + // create GCCBuildCommandParser + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + ErrorParserManager epm = new ErrorParserManager(project, null); + // Shift build directory, that could happen if Make Target from folder1 was run + IFolder buildDir = folder1; + epm.pushDirectoryURI(buildDir.getLocationURI()); + + // parse line + parser.startup(cfgDescription); + parser.processLine("gcc " + + "-I/path0 " + + "-I. " + + "Folder1/Folder2/file.cpp", + epm); + parser.shutdown(); + + // check entries + IPath path0 = new Path("/path0").setDevice(project.getLocation().getDevice()); + { + List entries = parser.getSettingEntries(cfgDescription, file, languageId); + assertEquals(new CIncludePathEntry(path0, 0), entries.get(0)); + // Information from build output should take precedence over build dir + assertEquals(new CIncludePathEntry(project.getFullPath(), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(1)); + } + } + /** */ public void testEndOfLine() throws Exception { diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java index 18745eb003c..69366a058e5 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java @@ -271,6 +271,8 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett List options = parseForOptions(line); if (options!=null) { for (String option : options) { + @SuppressWarnings("unused") + int i =0; for (AbstractOptionParser optionParser : getOptionParsers()) { try { if (optionParser.parseOption(option)) { @@ -647,7 +649,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett return null; } else { if (path.endsWith("/" + lastSegment)) { //$NON-NLS-1$ - int pos = path.lastIndexOf(lastSegment); + int pos = path.lastIndexOf("/" + lastSegment); //$NON-NLS-1$ path = path.substring(0, pos); continue; } else { @@ -660,7 +662,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett try { cwdURI = new URI(fileURI.getScheme(), fileURI.getUserInfo(), fileURI.getHost(), - fileURI.getPort(), path, fileURI.getQuery(), fileURI.getFragment()); + fileURI.getPort(), path + '/', fileURI.getQuery(), fileURI.getFragment()); } catch (URISyntaxException e) { // It should be valid URI here or something is wrong MakeCorePlugin.log(e); From ee2c90f2e87ff35c1b346b5f479f19506f9cc01e Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Fri, 4 Nov 2011 15:30:44 -0400 Subject: [PATCH 062/120] Workspace paths added by user did not work. --- .../providers/LanguageSettingEntryDialog.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingEntryDialog.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingEntryDialog.java index ef4be0ea722..999328e7cfe 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingEntryDialog.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingEntryDialog.java @@ -230,10 +230,12 @@ public class LanguageSettingEntryDialog extends AbstractPropertyDialog { comboKind.setText(comboKindItems[kindToComboIndex]); comboKind.addSelectionListener(new SelectionListener() { + @Override public void widgetSelected(SelectionEvent e) { updateImages(); setButtons(); } + @Override public void widgetDefaultSelected(SelectionEvent e) { widgetSelected(e); @@ -276,10 +278,12 @@ public class LanguageSettingEntryDialog extends AbstractPropertyDialog { comboPathCategory.setLayoutData(gd); comboPathCategory.addSelectionListener(new SelectionListener() { + @Override public void widgetSelected(SelectionEvent e) { updateImages(); setButtons(); } + @Override public void widgetDefaultSelected(SelectionEvent e) { widgetSelected(e); @@ -302,6 +306,7 @@ public class LanguageSettingEntryDialog extends AbstractPropertyDialog { gd.widthHint = 200; inputName.setLayoutData(gd); inputName.addModifyListener(new ModifyListener() { + @Override public void modifyText(ModifyEvent e) { setButtons(); }}); @@ -369,11 +374,13 @@ public class LanguageSettingEntryDialog extends AbstractPropertyDialog { checkBoxBuiltIn.setLayoutData(gd); checkBoxBuiltIn.addSelectionListener(new SelectionListener() { + @Override public void widgetSelected(SelectionEvent e) { updateImages(); setButtons(); } + @Override public void widgetDefaultSelected(SelectionEvent e) { widgetSelected(e); } @@ -387,11 +394,13 @@ public class LanguageSettingEntryDialog extends AbstractPropertyDialog { checkBoxFramework.setLayoutData(gd); checkBoxFramework.addSelectionListener(new SelectionListener() { + @Override public void widgetSelected(SelectionEvent e) { updateImages(); setButtons(); } + @Override public void widgetDefaultSelected(SelectionEvent e) { widgetSelected(e); } @@ -530,7 +539,7 @@ public class LanguageSettingEntryDialog extends AbstractPropertyDialog { int kind = comboKind.getSelectionIndex(); boolean isProjectPath = indexPathKind==COMBO_PATH_INDEX_PROJECT; boolean isWorkspacePath = (kind!=COMBO_INDEX_MACRO) && (isProjectPath || indexPathKind==COMBO_PATH_INDEX_WORKSPACE); - int flagWorkspace = isWorkspacePath ? ICSettingEntry.VALUE_WORKSPACE_PATH : 0; + int flagWorkspace = isWorkspacePath ? ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED : 0; int flags = flagBuiltIn | flagWorkspace | flagFramework; ICLanguageSettingEntry entry=null; @@ -631,7 +640,7 @@ public class LanguageSettingEntryDialog extends AbstractPropertyDialog { int flagBuiltin = checkBoxBuiltIn.getSelection() ? ICSettingEntry.BUILTIN : 0; int flagFramework = checkBoxFramework.getSelection() ? ICSettingEntry.FRAMEWORKS_MAC : 0; boolean isWorkspacePath = indexPathKind==COMBO_PATH_INDEX_PROJECT || indexPathKind==COMBO_PATH_INDEX_WORKSPACE; - int flagWorkspace = isWorkspacePath ? ICSettingEntry.VALUE_WORKSPACE_PATH : 0; + int flagWorkspace = isWorkspacePath ? ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED : 0; int flags = flagBuiltin | flagWorkspace | flagFramework; Image image = LanguageSettingsImages.getImage(kind, flags, indexPathKind==COMBO_PATH_INDEX_PROJECT); From e95e3a02b72a86f80cf9a5f56042ab13ca319ebe Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Thu, 17 Nov 2011 16:49:35 -0500 Subject: [PATCH 063/120] Using of pooled list refined --- .../LanguageSettingsBaseProvider.java | 6 +- .../LanguageSettingsProvidersSerializer.java | 134 +++++++++--------- .../providers/LanguageSettingsStorage.java | 65 +++++++-- .../providers/LanguageSettingsEntriesTab.java | 91 +++++++----- 4 files changed, 178 insertions(+), 118 deletions(-) diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsBaseProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsBaseProvider.java index a97bb4ce46c..03e049eeb95 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsBaseProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsBaseProvider.java @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Andrew Gvozdev (Quoin Inc.) and others. + * Copyright (c) 2009, 2011 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 (Quoin Inc.) - initial API and implementation + * Andrew Gvozdev - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.core.language.settings.providers; @@ -18,7 +18,6 @@ import java.util.List; import org.eclipse.cdt.core.AbstractExecutableExtensionBase; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; -import org.eclipse.cdt.internal.core.settings.model.SettingsModelMessages; import org.eclipse.core.resources.IResource; /** @@ -131,6 +130,7 @@ public class LanguageSettingsBaseProvider extends AbstractExecutableExtensionBas * @param languageId - language id. If {@code null}, then entries defined for * the language scope are returned. See {@link #getLanguageScope()} */ + @Override public List getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) { if (languageScope==null) { if (entries==null) diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java index 9c6e6c8bbeb..165a28722d9 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java @@ -70,9 +70,9 @@ public class LanguageSettingsProvidersSerializer { private static final String ELEM_CONFIGURATION = "configuration"; //$NON-NLS-1$ private static final String ELEM_PROVIDER = "provider"; //$NON-NLS-1$ private static final String ELEM_PROVIDER_REFERENCE = "provider-reference"; //$NON-NLS-1$ - + private static ILock serializingLock = Job.getJobManager().newLock(); - + /** Cache of globally available providers to be consumed by calling clients */ private static Map rawGlobalWorkspaceProviders = new HashMap(); private static Map globalWorkspaceProviders = new HashMap(); @@ -82,7 +82,7 @@ public class LanguageSettingsProvidersSerializer { private static class ListenerAssociation { private ICListenerRegisterer listener; private ICConfigurationDescription cfgDescription; - + public ListenerAssociation(ICListenerRegisterer li, ICConfigurationDescription cfgd) { listener = li; cfgDescription = cfgd; @@ -149,7 +149,7 @@ public class LanguageSettingsProvidersSerializer { private int getProjectCount() { return projectCount; } - + private synchronized int incrementProjectCount() { projectCount++; return projectCount; @@ -159,7 +159,7 @@ public class LanguageSettingsProvidersSerializer { projectCount--; return projectCount; } - + @Override public void registerListener(ICConfigurationDescription cfgDescription) { // keep in mind that rawProvider can change @@ -186,7 +186,7 @@ public class LanguageSettingsProvidersSerializer { private static class LanguageSettingsChangeEvent implements ILanguageSettingsChangeEvent { private String projectName = null; private Map deltaMap = new HashMap(); - + /** * The act of creating event resets internal delta count in configuration state. * That implies that when the event is retrieved it must be fired or delta will go missing. @@ -315,7 +315,7 @@ public class LanguageSettingsProvidersSerializer { List oldListeners = selectListeners(rawGlobalWorkspaceProviders.values()); List newListeners = selectListeners(rawProviders); - + for (ICListenerRegisterer oldListener : oldListeners) { if (!isObjectInTheList(newListeners, oldListener)) { LanguageSettingsWorkspaceProvider wspProvider = (LanguageSettingsWorkspaceProvider) globalWorkspaceProviders.get(((ILanguageSettingsProvider)oldListener).getId()); @@ -324,7 +324,7 @@ public class LanguageSettingsProvidersSerializer { } } } - + for (ICListenerRegisterer newListener : newListeners) { if (!isObjectInTheList(oldListeners, newListener)) { LanguageSettingsWorkspaceProvider wspProvider = (LanguageSettingsWorkspaceProvider) globalWorkspaceProviders.get(((ILanguageSettingsProvider)newListener).getId()); @@ -333,13 +333,13 @@ public class LanguageSettingsProvidersSerializer { } } } - + rawGlobalWorkspaceProviders = rawWorkspaceProviders; } private static List createLanguageLettingsChangeEvents(List serializableProviders) { List events = new ArrayList(); - + List serializableIds = new ArrayList(); for (LanguageSettingsSerializable provider : serializableProviders) { serializableIds.add(provider.getId()); @@ -366,15 +366,15 @@ projects: } } } - + } - + return events; } public static void serializeLanguageSettingsWorkspace() throws CoreException { LanguageSettingsLogger.logWarning("LanguageSettingsProvidersSerializer.serializeLanguageSettingsWorkspace()"); - + URI uriStoreWsp = getStoreInWorkspaceArea(STORAGE_WORKSPACE_LANGUAGE_SETTINGS); List serializableWorkspaceProviders = new ArrayList(); for (ILanguageSettingsProvider provider : rawGlobalWorkspaceProviders.values()) { @@ -402,11 +402,11 @@ projects: Document doc = XmlUtil.newDocument(); Element rootElement = XmlUtil.appendElement(doc, ELEM_PLUGIN); Element elementExtension = XmlUtil.appendElement(rootElement, ELEM_EXTENSION, new String[] {ATTR_POINT, LanguageSettingsExtensionManager.PROVIDER_EXTENSION_FULL_ID}); - + for (LanguageSettingsSerializable provider : serializableWorkspaceProviders) { provider.serialize(elementExtension); } - + try { serializingLock.acquire(); XmlUtil.serializeXml(doc, uriStoreWsp); @@ -537,7 +537,7 @@ projects: public static void serializeLanguageSettings(ICProjectDescription prjDescription) throws CoreException { IProject project = prjDescription.getProject(); LanguageSettingsLogger.logWarning("LanguageSettingsProvidersSerializer.serializeLanguageSettings() for " + project); - + try { // Document to store in project area Document docStorePrj = XmlUtil.newDocument(); @@ -548,7 +548,7 @@ projects: // The project store should not be absent. Absent store means legacy project, not 0 providers. IFile fileStorePrj = getStoreInProjectArea(project); - + URI uriStoreWsp = getStoreInWorkspaceArea(project.getName()+'.'+STORAGE_WORKSPACE_LANGUAGE_SETTINGS); LanguageSettingsChangeEvent event = null; @@ -567,7 +567,7 @@ projects: } else { new java.io.File(uriStoreWsp).delete(); } - + // manufacture the event only if serialization was successful event = new LanguageSettingsChangeEvent(prjDescription); } finally { @@ -884,7 +884,7 @@ projects: } return listeners; } - + private static List selectListeners(Collection values) { List listeners = new ArrayList(); for (ILanguageSettingsProvider provider : values) { @@ -913,7 +913,7 @@ projects: } return associations; } - + /** * Unregister listeners which are not used anymore and register new listeners. * The method is used when project description is applied to workspace. @@ -928,10 +928,10 @@ projects: assertConsistency(oldPrjDescription); // TODO - remove me assertConsistency(newPrjDescription); // TODO - remove me - + List oldListeners = getListeners(oldPrjDescription); List newAssociations = getListenersAssociations(newPrjDescription); - + for (ICListenerRegisterer oldListener : oldListeners) { if (!isListenerInTheListOfAssociations(newAssociations, oldListener)) { int count = 0; @@ -948,7 +948,7 @@ projects: } } } - + for (ListenerAssociation newListenerAssociation : newAssociations) { ICListenerRegisterer newListener = newListenerAssociation.listener; if (!isObjectInTheList(oldListeners, newListener)) { @@ -966,12 +966,12 @@ projects: } } } - + } /** * Deep clone of a list of language settings providers. - * + * * @param baseProviders - list of providers to clone. * @return newly cloned list. */ @@ -991,19 +991,19 @@ projects: } return new ArrayList(newProviders); } - + /** * Adds a listener that will be notified of changes in language settings. - * + * * @param listener the ILanguageMappingChangeListener to add */ public static void registerLanguageSettingsChangeListener(ILanguageSettingsChangeListener listener) { fLanguageSettingsChangeListeners.add(listener); } - + /** * Removes a language settings change listener. - * + * * @param listener the ILanguageMappingChangeListener to remove. */ public static void unregisterLanguageSettingsChangeListener(ILanguageSettingsChangeListener listener) { @@ -1012,7 +1012,7 @@ projects: /** * Notifies all language settings change listeners of a change. - * + * * @param event the ILanguageSettingsChangeEvent event to be broadcast. */ public static void notifyLanguageSettingsChangeListeners(ILanguageSettingsChangeEvent event) { @@ -1025,17 +1025,17 @@ projects: } } - private static List safeGetSettingEntries(ILanguageSettingsProvider provider, + private static List getSettingEntriesPooled(ILanguageSettingsProvider provider, ICConfigurationDescription cfgDescription, IResource rc, String languageId) { - + try { - return provider.getSettingEntries(cfgDescription, rc, languageId); + return LanguageSettingsStorage.getPooledList(provider.getSettingEntries(cfgDescription, rc, languageId)); } catch (Throwable e) { String cfgId = cfgDescription!=null ? cfgDescription.getId() : null; String msg = "Exception in provider "+provider.getId()+": getSettingEntries("+cfgId+", "+rc+", "+languageId+")"; CCorePlugin.log(msg, e); - // return empty array to prevent climbing up the resource tree - return new ArrayList(0); + // return empty list to prevent getting potentially non-empty list from up the resource tree + return LanguageSettingsStorage.getPooledEmptyList(); } } @@ -1044,21 +1044,21 @@ projects: * for the given configuration description, resource and language. * This method reaches to the parent folder of the resource recursively * in case the resource does not define the entries for the given provider. - * + * * @param provider - language settings provider. * @param cfgDescription - configuration description. * @param rc - resource such as file or folder. * @param languageId - language id. - * - * @return the list of setting entries. Never returns {@code null} + * + * @return the list of setting entries which is unmodifiable. Never returns {@code null} * although individual providers mandated to return {@code null} if no settings defined. */ public static List getSettingEntriesUpResourceTree(ILanguageSettingsProvider provider, ICConfigurationDescription cfgDescription, IResource rc, String languageId) { Assert.isTrue( !(rc instanceof IWorkspaceRoot) ); if (provider!=null) { - List entries = safeGetSettingEntries(provider, cfgDescription, rc, languageId); + List entries = getSettingEntriesPooled(provider, cfgDescription, rc, languageId); if (entries!=null) { - return new ArrayList(entries); + return entries; } if (rc!=null) { IResource parentFolder = (rc instanceof IProject) ? null : rc.getParent(); @@ -1066,21 +1066,21 @@ projects: return getSettingEntriesUpResourceTree(provider, cfgDescription, parentFolder, languageId); } // if out of parent resources - get default entries for the applicable language scope - entries = safeGetSettingEntries(provider, null, null, languageId); + entries = getSettingEntriesPooled(provider, null, null, languageId); if (entries!=null) { - return new ArrayList(entries); + return entries; } } } - - return new ArrayList(0); + + return LanguageSettingsStorage.getPooledEmptyList(); } /** * Builds for the provider a nice looking resource tree to present hierarchical view to the user. * Note that it is not advisable to "compact" the tree because of potential loss of information * which is especially important during partial or incremental builds. - * + * * @param provider - language settings provider to build the tree for. * @param cfgDescription - configuration description. * @param languageId - language ID. @@ -1095,17 +1095,17 @@ projects: } if (members==null) return; - + for (IResource rc : members) { if (rc instanceof IContainer) { buildResourceTree(provider, cfgDescription, languageId, (IContainer) rc); } } - + int rcNumber = members.length; - + Map, Integer> listMap = new HashMap, Integer>(); - + // on the first pass find majority entries List majorityEntries = null; List candidate = null; @@ -1123,26 +1123,26 @@ projects: count = 0; } count++; - + if (count>candidateCount) { candidateCount = count; candidate = entries; } - + listMap.put(entries, count); } } - + if (candidateCount > rcNumber/2) { majorityEntries = candidate; break; } } - + if (majorityEntries!=null) { provider.setSettingEntries(cfgDescription, folder, languageId, majorityEntries); } - + // second pass - assign the entries to the folders for (IResource rc : members) { List entries = provider.getSettingEntries(null, rc, languageId); @@ -1178,7 +1178,7 @@ projects: * for the given configuration description, resource and language. This is a * combined list for all providers taking into account settings of parent folder * if settings for the given resource are not defined. - * + * * @param cfgDescription - configuration description. * @param rc - resource such as file or folder. * @param languageId - language id. @@ -1190,15 +1190,15 @@ projects: * @param isLocal - {@code true} if "local" entries should be provided and * {@code false} for "system" entries. This makes sense for include paths where * [#include "..."] is "local" and [#include <...>] is system. - * + * * @return the list of setting entries found. */ private static List getSettingEntriesByKind(ICConfigurationDescription cfgDescription, IResource rc, String languageId, int kind, boolean checkLocality, boolean isLocal) { - + List entries = new ArrayList(); List alreadyAdded = new ArrayList(); - + List providers = cfgDescription.getLanguageSettingProviders(); for (ILanguageSettingsProvider provider: providers) { List providerEntries = getSettingEntriesUpResourceTree(provider, cfgDescription, rc, languageId); @@ -1221,7 +1221,7 @@ projects: } } } - + return entries; } @@ -1231,7 +1231,7 @@ projects: * combined list for all providers taking into account settings of parent folder * if settings for the given resource are not defined. For include paths both * local (#include "...") and system (#include <...>) entries are returned. - * + * * @param cfgDescription - configuration description. * @param rc - resource such as file or folder. * @param languageId - language id. @@ -1239,7 +1239,7 @@ projects: * {@link ICSettingEntry#INCLUDE_PATH} etc. This is a binary flag * and it is possible to specify composite kind. * Use {@link ICSettingEntry#ALL} to get all kinds. - * + * * @return the list of setting entries. */ public static List getSettingEntriesByKind(ICConfigurationDescription cfgDescription, IResource rc, String languageId, int kind) { @@ -1247,11 +1247,11 @@ projects: } /** - * Returns the list of "system" (such as [#include <...>]) setting entries of a certain kind + * Returns the list of "system" (such as [#include <...>]) setting entries of a certain kind * for the given configuration description, resource and language. This is a * combined list for all providers taking into account settings of parent folder * if settings for the given resource are not defined. - * + * * @param cfgDescription - configuration description. * @param rc - resource such as file or folder. * @param languageId - language id. @@ -1259,7 +1259,7 @@ projects: * {@link ICSettingEntry#INCLUDE_PATH} etc. This is a binary flag * and it is possible to specify composite kind. * Use {@link ICSettingEntry#ALL} to get all kinds. - * + * * @return the list of setting entries. */ public static List getSystemSettingEntriesByKind(ICConfigurationDescription cfgDescription, IResource rc, String languageId, int kind) { @@ -1267,11 +1267,11 @@ projects: } /** - * Returns the list of "local" (such as [#include "..."]) setting entries of a certain kind + * Returns the list of "local" (such as [#include "..."]) setting entries of a certain kind * for the given configuration description, resource and language. This is a * combined list for all providers taking into account settings of parent folder * if settings for the given resource are not defined. - * + * * @param cfgDescription - configuration description. * @param rc - resource such as file or folder. * @param languageId - language id. @@ -1279,7 +1279,7 @@ projects: * {@link ICSettingEntry#INCLUDE_PATH} etc. This is a binary flag * and it is possible to specify composite kind. * Use {@link ICSettingEntry#ALL} to get all kinds. - * + * * @return the list of setting entries. */ public static List getLocalSettingEntriesByKind(ICConfigurationDescription cfgDescription, IResource rc, String languageId, int kind) { diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsStorage.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsStorage.java index 0b9840b3d6d..ec37aa13ec6 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsStorage.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsStorage.java @@ -55,8 +55,8 @@ public class LanguageSettingsStorage { }; /** - *
    Note that this list is unmodifiable. To modify the list copy it, change and use - * {@link #setSettingEntries(ICConfigurationDescription, IResource, String, List)}. + * TODO + *
    Note that this list is unmodifiable. * */ public List getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) { @@ -98,7 +98,7 @@ public class LanguageSettingsStorage { } /** - * + * */ public void setSettingEntries(String rcProjectPath, String languageId, List entries) { synchronized (fStorage) { @@ -108,7 +108,7 @@ public class LanguageSettingsStorage { langMap = new HashMap>(); fStorage.put(languageId, langMap); } - List sortedEntries = listPool.add(Collections.unmodifiableList(sortEntries(entries))); + List sortedEntries = getPooledList(sortEntries(entries), false); langMap.put(rcProjectPath, sortedEntries); } else { // do not keep nulls in the tables @@ -129,7 +129,7 @@ public class LanguageSettingsStorage { public boolean isEmpty() { return fStorage.isEmpty(); } - + /** * Clear all the entries for all configurations, all resources and all languages. */ @@ -239,20 +239,20 @@ public class LanguageSettingsStorage { private ICLanguageSettingEntry loadSettingEntry(Node parentElement) { String settingKind = XmlUtil.determineAttributeValue(parentElement, ATTR_KIND); String settingName = XmlUtil.determineAttributeValue(parentElement, ATTR_NAME); - + NodeList flagNodes = parentElement.getChildNodes(); int flags = 0; for (int i=0;i getPooledList(List entries, boolean copy) { + if (entries == null) + return null; + + List pooledList = listPool.get(entries); + if (pooledList != null) { + return pooledList; + } + + if (entries.size() == 0) { + return getPooledEmptyList(); + } + + if (copy) { + entries = new ArrayList(entries); + } + pooledList = Collections.unmodifiableList(entries); + return listPool.add(pooledList); + } + + /** + * Returns the equal list of entries from the pool to conserve the memory. + * + * @param entries - list of entries to pool. + * @return returns the list of entries from the pool. + */ + public static List getPooledList(List entries) { + return getPooledList(entries, true); + } + + /** + * @return the empty immutable list which is pooled. Use this call rather than creating + * new empty array to ensure that operator '==' can be used instead of deep equals(). + */ + public static List getPooledEmptyList() { + List pooledEmptyList = Collections.emptyList(); + return listPool.add(pooledEmptyList); + } + /** * Clone storage for the entries. Copies references for lists of entries as a whole. * Note that is OK as the lists kept in storage are unmodifiable. diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java index e003ba067cd..564cde960ac 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java @@ -79,11 +79,11 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { private Tree treeEntries; private TreeViewer treeEntriesViewer; private static String currentLanguageId = null; - + private Button builtInCheckBox; private Button enableProvidersCheckBox; private StatusMessageLine fStatusLine; - + private Page_LanguageSettingsProviders masterPropertyPage = null; private static final int BUTTON_ADD = 0; @@ -105,15 +105,15 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { private Map> initialProvidersMap = new HashMap>(); private boolean initialEnablement =false; - + private class EntriesTreeLabelProvider extends LanguageSettingsProvidersLabelProvider { @Override protected String[] getOverlayKeys(ILanguageSettingsProvider provider) { String[] overlayKeys = super.getOverlayKeys(provider); - + // if (LanguageSettingsManager.isWorkspaceProvider(provider)) // provider = LanguageSettingsManager.getRawWorkspaceProvider(provider.getId()); -// +// if (currentLanguageId != null) { IResource rc = getResource(); List entries = getSettingEntries(provider); @@ -131,7 +131,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { } } } - + // TODO ICConfigurationDescription cfgDescription = getConfigurationDescription(); List initialProviders = initialProvidersMap.get(cfgDescription.getId()); @@ -140,7 +140,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { } return overlayKeys; } - + @Override public Image getImage(Object element) { if (element instanceof ICLanguageSettingEntry) { @@ -165,21 +165,30 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { return super.getText(element); } } - + /** * Content provider for setting entries tree. */ private class EntriesTreeContentProvider implements ITreeContentProvider { + @Override public Object[] getElements(Object inputElement) { return getChildren(inputElement); } + @Override public Object[] getChildren(Object parentElement) { if (parentElement instanceof Object[]) return (Object[]) parentElement; + if (parentElement instanceof ILanguageSettingsProvider) { ILanguageSettingsProvider lsProvider = (ILanguageSettingsProvider)parentElement; List entriesList = getSettingEntriesUpResourceTree(lsProvider); + if (entriesList == null) { + return null; + } + + // convert to modifiable list + entriesList = new ArrayList(entriesList); if (builtInCheckBox.getSelection()==false) { for (Iterator iter = entriesList.iterator(); iter.hasNext();) { @@ -189,26 +198,28 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { } } } - - if (entriesList!=null) { - return entriesList.toArray(); - } + return entriesList.toArray(); } + return null; } + @Override public Object getParent(Object element) { return null; } + @Override public boolean hasChildren(Object element) { Object[] children = getChildren(element); return children!=null && children.length>0; } + @Override public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { } + @Override public void dispose() { } @@ -323,6 +334,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { columnLanguages.setToolTipText(Messages.AbstractLangsListTab_Languages); treeLanguages.addPaintListener(new PaintListener() { + @Override public void paintControl(PaintEvent e) { int x = treeLanguages.getBounds().width - 5; if (columnLanguages.getWidth() != x) @@ -340,6 +352,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { final TreeColumn treeCol = new TreeColumn(treeEntries, SWT.NONE); treeEntries.addPaintListener(new PaintListener() { + @Override public void paintControl(PaintEvent e) { int x = treeEntries.getClientArea().width; if (treeCol.getWidth() != x) @@ -355,7 +368,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { treeEntriesViewer = new TreeViewer(treeEntries); treeEntriesViewer.setContentProvider(new EntriesTreeContentProvider()); treeEntriesViewer.setLabelProvider(new EntriesTreeLabelProvider()); - + treeEntriesViewer.setUseHashlookup(true); treeEntries.addSelectionListener(new SelectionAdapter() { @@ -387,7 +400,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { initialEnablement = ScannerDiscoveryLegacySupport.isLanguageSettingsProvidersFunctionalityEnabled(page.getProject()); } } - + @Override public void createControls(Composite parent) { super.createControls(parent); @@ -395,7 +408,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { GridData gd = (GridData) usercomp.getLayoutData(); // Discourage settings entry table from trying to show all its items at once, see bug 264330 gd.heightHint =1; - + if (page instanceof Page_LanguageSettingsProviders) { masterPropertyPage = (Page_LanguageSettingsProviders) page; } @@ -404,7 +417,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { // SashForms for each mode createShowEntriesSashForm(); - + // Status line fStatusLine = new StatusMessageLine(usercomp, SWT.LEFT, 2); @@ -451,7 +464,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { gd.horizontalSpan = 2; gd.grabExcessVerticalSpace = true; sashFormEntries.setLayoutData(gd); - + GridLayout layout = new GridLayout(); sashFormEntries.setLayout(layout); @@ -466,7 +479,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { treeLanguages.setEnabled(enable); treeEntries.setEnabled(enable); builtInCheckBox.setEnabled(enable); - + buttoncomp.setEnabled(enable); if (enable) { @@ -475,7 +488,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { disableButtons(); } } - + private void disableButtons() { buttonSetEnabled(BUTTON_ADD, false); buttonSetEnabled(BUTTON_EDIT, false); @@ -499,24 +512,24 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { boolean isProviderEditable = provider instanceof ILanguageSettingsEditableProvider; // boolean isUserProvider = provider instanceof UserLanguageSettingsProvider; - + boolean canAdd = isProviderEditable; boolean canEdit = isProviderEditable && isEntrySelected; boolean canDelete = isProviderEditable && isEntrySelected; boolean canClear = isProviderEditable && isProviderSelected && entries!=null && entries.size()>0; - + boolean canMoveUp = false; boolean canMoveDown = false; if (isProviderEditable && isEntrySelected && entries!=null) { int last = entries.size()-1; int pos = getExactIndex(entries, entry); - + if (pos>=0 && pos<=last) { canMoveUp = pos!=0; canMoveDown = pos!=last; } } - + buttonSetText(BUTTON_DELETE, isProviderSelected ? CLEAR_STR : DEL_STR); buttonSetEnabled(BUTTON_ADD, canAdd); @@ -525,7 +538,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { buttonSetEnabled(BUTTON_MOVE_UP, canMoveUp); buttonSetEnabled(BUTTON_MOVE_DOWN, canMoveDown); - + } /** @@ -655,13 +668,13 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { private void addEntry(ILanguageSettingsProvider provider, ICLanguageSettingEntry entry) { if (provider!=null && entry != null) { String providerId = provider.getId(); - + List entries = getWritableEntries(provider); ICLanguageSettingEntry selectedEntry = getSelectedEntry(); int pos = getExactIndex(entries, selectedEntry); entries.add(pos+1, entry); saveEntries(provider, entries); - + updateTreeEntries(); selectItem(providerId, entry); updateButtons(); @@ -692,7 +705,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { ICConfigurationDescription cfgDescription = getConfigurationDescription(); IResource rc = getResource(); List entries = provider.getSettingEntries(cfgDescription, rc, currentLanguageId); - if (entries==null) { + if (entries == null) { entries = getSettingEntriesUpResourceTree(provider); } entries = new ArrayList(entries); @@ -718,7 +731,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { } } } - + /** * @param selectedProvider * @return @@ -768,16 +781,16 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { private void deleteEntry(ILanguageSettingsProvider provider, ICLanguageSettingEntry entry) { if (provider!=null && entry != null) { String providerId = provider.getId(); - + List entries = getWritableEntries(provider); - int pos = getExactIndex(getSettingEntriesUpResourceTree(provider), entry); + int pos = getExactIndex(entries, entry); entries.remove(entry); saveEntries(provider, entries); - + if (pos>=entries.size()) pos = entries.size()-1; ICLanguageSettingEntry nextEntry = pos>=0 ? entries.get(pos) : null; - + updateTreeEntries(); selectItem(providerId, nextEntry); updateButtons(); @@ -789,7 +802,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { String providerId = provider.getId(); List empty = new ArrayList(); saveEntries(provider, empty); - + updateTreeEntries(); selectItem(providerId, null); updateButtons(); @@ -810,13 +823,13 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { private void moveEntry(ILanguageSettingsProvider provider, ICLanguageSettingEntry entry, boolean up) { if (provider!=null && entry != null) { String providerId = provider.getId(); - + List entries = getWritableEntries(provider); int pos = getExactIndex(entries, entry); int newPos = up ? pos-1 : pos+1; Collections.swap(entries, pos, newPos); saveEntries(provider, entries); - + updateTreeEntries(); selectItem(providerId, entry); updateButtons(); @@ -923,7 +936,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { } else { setAllVisible(true, null); } - + updateTreeLanguages(rcDes); updateTreeEntries(); if (masterPropertyPage!=null) { @@ -950,7 +963,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { IResource rc = getResource(); List providers = cfgDescription.getLanguageSettingProviders(); List writableProviders = new ArrayList(providers.size()); - + providers: for (ILanguageSettingsProvider provider : providers) { ILanguageSettingsEditableProvider writableProvider = null; if (provider instanceof ILanguageSettingsEditableProvider) { @@ -997,7 +1010,7 @@ providers: for (ILanguageSettingsProvider provider : providers) { List providers = srcCfgDescription.getLanguageSettingProviders(); destCfgDescription.setLanguageSettingProviders(providers); } - + if (!page.isForPrefs()) { ICConfigurationDescription sd = srcRcDescription.getConfiguration(); ICConfigurationDescription dd = destRcDescription.getConfiguration(); @@ -1038,7 +1051,7 @@ providers: for (ILanguageSettingsProvider provider : providers) { } return false; } - + return true; } From 39431dc5f5965b9bae6dc3acb4ed64c35a0333cc Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Fri, 18 Nov 2011 16:12:29 -0500 Subject: [PATCH 064/120] Renamed ICListenerRegisterer -> ICListenerAgent --- .../AbstractBuiltinSpecsDetector.java | 4 +- .../providers/MockListenerRegisterer.java | 2 +- ...erRegisterer.java => ICListenerAgent.java} | 2 +- .../LanguageSettingsProvidersSerializer.java | 52 +++++++++---------- 4 files changed, 30 insertions(+), 30 deletions(-) rename core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/{ICListenerRegisterer.java => ICListenerAgent.java} (95%) diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java index b4a5c97e452..61a9c158ee6 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java @@ -27,7 +27,7 @@ import org.eclipse.cdt.core.IConsoleParser; import org.eclipse.cdt.core.IMarkerGenerator; import org.eclipse.cdt.core.ProblemMarkerInfo; import org.eclipse.cdt.core.index.IIndexManager; -import org.eclipse.cdt.core.language.settings.providers.ICListenerRegisterer; +import org.eclipse.cdt.core.language.settings.providers.ICListenerAgent; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICProject; @@ -68,7 +68,7 @@ import org.eclipse.core.runtime.jobs.ISchedulingRule; import org.eclipse.core.runtime.jobs.Job; import org.w3c.dom.Element; -public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSettingsOutputScanner implements ICListenerRegisterer { +public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSettingsOutputScanner implements ICListenerAgent { public static final Object JOB_FAMILY_BUILTIN_SPECS_DETECTOR = "org.eclipse.cdt.make.core.scannerconfig.AbstractBuiltinSpecsDetector"; private static final int TICKS_STREAM_MONITOR = 100; diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockListenerRegisterer.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockListenerRegisterer.java index 4afb94905ef..1a7fb6b6d7a 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockListenerRegisterer.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockListenerRegisterer.java @@ -20,7 +20,7 @@ import org.eclipse.core.runtime.Assert; /** * Language Settings Provider that keeps count how many times it has been registered. */ -public class MockListenerRegisterer extends LanguageSettingsSerializable implements ILanguageSettingsEditableProvider, ICListenerRegisterer { +public class MockListenerRegisterer extends LanguageSettingsSerializable implements ILanguageSettingsEditableProvider, ICListenerAgent { private static MockListenerManager mockListenerManager = new MockListenerManager(); private static class MockListenerManager { diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ICListenerRegisterer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ICListenerAgent.java similarity index 95% rename from core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ICListenerRegisterer.java rename to core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ICListenerAgent.java index df953e20808..7322baaa4dd 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ICListenerRegisterer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ICListenerAgent.java @@ -18,7 +18,7 @@ import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; * Helper class to allow listeners self-register/dispose. Called by cdt core. * TODO - expand in more detail. */ -public interface ICListenerRegisterer { +public interface ICListenerAgent { public void registerListener(ICConfigurationDescription cfgDescription); public void unregisterListener(); } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java index 165a28722d9..a2f0fefe6ba 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java @@ -19,7 +19,7 @@ import java.util.List; import java.util.Map; import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.language.settings.providers.ICListenerRegisterer; +import org.eclipse.cdt.core.language.settings.providers.ICListenerAgent; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsEditableProvider; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; @@ -80,16 +80,16 @@ public class LanguageSettingsProvidersSerializer { private static ListenerList fLanguageSettingsChangeListeners = new ListenerList(ListenerList.IDENTITY); private static class ListenerAssociation { - private ICListenerRegisterer listener; + private ICListenerAgent listener; private ICConfigurationDescription cfgDescription; - public ListenerAssociation(ICListenerRegisterer li, ICConfigurationDescription cfgd) { + public ListenerAssociation(ICListenerAgent li, ICConfigurationDescription cfgd) { listener = li; cfgDescription = cfgd; } } - private static class LanguageSettingsWorkspaceProvider implements ILanguageSettingsProvider, ICListenerRegisterer { + private static class LanguageSettingsWorkspaceProvider implements ILanguageSettingsProvider, ICListenerAgent { private String providerId; private int projectCount = 0; @@ -164,8 +164,8 @@ public class LanguageSettingsProvidersSerializer { public void registerListener(ICConfigurationDescription cfgDescription) { // keep in mind that rawProvider can change ILanguageSettingsProvider rawProvider = getRawProvider(); - if (rawProvider instanceof ICListenerRegisterer) { - ((ICListenerRegisterer) rawProvider).registerListener(null); + if (rawProvider instanceof ICListenerAgent) { + ((ICListenerAgent) rawProvider).registerListener(null); } } @@ -173,8 +173,8 @@ public class LanguageSettingsProvidersSerializer { public void unregisterListener() { // keep in mind that rawProvider can change ILanguageSettingsProvider rawProvider = getRawProvider(); - if (rawProvider instanceof ICListenerRegisterer) { - ((ICListenerRegisterer) rawProvider).unregisterListener(); + if (rawProvider instanceof ICListenerAgent) { + ((ICListenerAgent) rawProvider).unregisterListener(); } } } @@ -313,10 +313,10 @@ public class LanguageSettingsProvidersSerializer { } } - List oldListeners = selectListeners(rawGlobalWorkspaceProviders.values()); - List newListeners = selectListeners(rawProviders); + List oldListeners = selectListeners(rawGlobalWorkspaceProviders.values()); + List newListeners = selectListeners(rawProviders); - for (ICListenerRegisterer oldListener : oldListeners) { + for (ICListenerAgent oldListener : oldListeners) { if (!isObjectInTheList(newListeners, oldListener)) { LanguageSettingsWorkspaceProvider wspProvider = (LanguageSettingsWorkspaceProvider) globalWorkspaceProviders.get(((ILanguageSettingsProvider)oldListener).getId()); if (wspProvider != null && wspProvider.getProjectCount() > 0) { @@ -325,7 +325,7 @@ public class LanguageSettingsProvidersSerializer { } } - for (ICListenerRegisterer newListener : newListeners) { + for (ICListenerAgent newListener : newListeners) { if (!isObjectInTheList(oldListeners, newListener)) { LanguageSettingsWorkspaceProvider wspProvider = (LanguageSettingsWorkspaceProvider) globalWorkspaceProviders.get(((ILanguageSettingsProvider)newListener).getId()); if (wspProvider != null && wspProvider.getProjectCount() > 0) { @@ -854,7 +854,7 @@ projects: return false; } - private static boolean isListenerInTheListOfAssociations(Collection list, ICListenerRegisterer element) { + private static boolean isListenerInTheListOfAssociations(Collection list, ICListenerAgent element) { // list.contains(element) won't do it as we are interested in exact object, not in equal object for (ListenerAssociation la : list) { if (la.listener == element) @@ -867,14 +867,14 @@ projects: * Get a providers list including only providers of type ICListenerRegisterer * for a given project description - collecting from all configurations. */ - private static List getListeners(ICProjectDescription prjDescription) { - List listeners = new ArrayList(); + private static List getListeners(ICProjectDescription prjDescription) { + List listeners = new ArrayList(); if (prjDescription != null) { for (ICConfigurationDescription cfgDescription : prjDescription.getConfigurations()) { List providers = cfgDescription.getLanguageSettingProviders(); for (ILanguageSettingsProvider provider : providers) { - if (provider instanceof ICListenerRegisterer) { - ICListenerRegisterer listener = (ICListenerRegisterer) provider; + if (provider instanceof ICListenerAgent) { + ICListenerAgent listener = (ICListenerAgent) provider; if (!isObjectInTheList(listeners, listener)) { listeners.add(listener); } @@ -885,11 +885,11 @@ projects: return listeners; } - private static List selectListeners(Collection values) { - List listeners = new ArrayList(); + private static List selectListeners(Collection values) { + List listeners = new ArrayList(); for (ILanguageSettingsProvider provider : values) { - if (provider instanceof ICListenerRegisterer) - listeners.add((ICListenerRegisterer) provider); + if (provider instanceof ICListenerAgent) + listeners.add((ICListenerAgent) provider); } return listeners; } @@ -903,8 +903,8 @@ projects: if (prjDescription != null) { for (ICConfigurationDescription cfgDescription : prjDescription.getConfigurations()) { List providers = cfgDescription.getLanguageSettingProviders(); - List listeners = selectListeners(providers); - for (ICListenerRegisterer listener : listeners) { + List listeners = selectListeners(providers); + for (ICListenerAgent listener : listeners) { if (!isListenerInTheListOfAssociations(associations, listener)) { associations.add(new ListenerAssociation(listener, cfgDescription)); } @@ -929,10 +929,10 @@ projects: assertConsistency(oldPrjDescription); // TODO - remove me assertConsistency(newPrjDescription); // TODO - remove me - List oldListeners = getListeners(oldPrjDescription); + List oldListeners = getListeners(oldPrjDescription); List newAssociations = getListenersAssociations(newPrjDescription); - for (ICListenerRegisterer oldListener : oldListeners) { + for (ICListenerAgent oldListener : oldListeners) { if (!isListenerInTheListOfAssociations(newAssociations, oldListener)) { int count = 0; if (oldListener instanceof LanguageSettingsWorkspaceProvider) { @@ -950,7 +950,7 @@ projects: } for (ListenerAssociation newListenerAssociation : newAssociations) { - ICListenerRegisterer newListener = newListenerAssociation.listener; + ICListenerAgent newListener = newListenerAssociation.listener; if (!isObjectInTheList(oldListeners, newListener)) { int count = 1; if (newListener instanceof LanguageSettingsWorkspaceProvider) { From 1415806f83a34da179100e2d4b3a63d24cdabe92 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Fri, 18 Nov 2011 16:52:50 -0500 Subject: [PATCH 065/120] API cleanup & JavaDoc --- .../settings/providers/ICListenerAgent.java | 21 +++++++++-- .../providers/ILanguageSettingsProvider.java | 35 ++++++++++++------- .../LanguageSettingsProvidersSerializer.java | 11 +++--- .../schema/LanguageSettingsProvider.exsd | 3 ++ 4 files changed, 50 insertions(+), 20 deletions(-) diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ICListenerAgent.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ICListenerAgent.java index 7322baaa4dd..087992c1d21 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ICListenerAgent.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ICListenerAgent.java @@ -15,10 +15,27 @@ import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; /** - * Helper class to allow listeners self-register/dispose. Called by cdt core. - * TODO - expand in more detail. + * Helper class to allow listeners of arbitrary events self-register/dispose. + * + * Called by CDT core when {@linkplain ICListenerAgent} added/removed to + * the list of {@link ILanguageSettingsProvider}s managed by the model. + * {@linkplain ICListenerAgent} would commonly be implemented by a language + * settings provider. + *

    + * Implementers are to create a specific listener and register it to + * appropriate event manager in {@link #registerListener(ICConfigurationDescription)} + * then unregister and dispose in {@link #unregisterListener()}. */ public interface ICListenerAgent { + /** + * Registers a specific listener. + * + * @param cfgDescription - configuration description for the listener. + */ public void registerListener(ICConfigurationDescription cfgDescription); + + /** + * Unregister listener and dispose all resources. + */ public void unregisterListener(); } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsProvider.java index e8a30f39a24..d2eb2cdcbb0 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsProvider.java @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Andrew Gvozdev (Quoin Inc.) and others. + * Copyright (c) 2009, 2011 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 (Quoin Inc.) - initial API and implementation + * Andrew Gvozdev - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.core.language.settings.providers; @@ -20,32 +20,32 @@ import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.core.resources.IResource; /** - * Base interface to provide list of {@link ICLanguageSettingEntry}. - * This interface is used to deliver additions to compiler options such as + * Base interface to provide list of {@link ICLanguageSettingEntry}. + * This interface is used to deliver additions to compiler options such as * include paths (-I) or preprocessor defines (-D) and others (see * {@link ICSettingEntry#INCLUDE_PATH} and other kinds). - * + *
    * To define a provider like that use extension point * {@code org.eclipse.cdt.core.LanguageSettingsProvider} and implement this * interface. CDT provides a few general use implementations such as - * {@link LanguageSettingsBaseProvider} which could be used out of the box or - * extended. See extension point schema description LanguageSettingsProvider.exsd - * for more details. - * + * {@link LanguageSettingsBaseProvider} or {@link LanguageSettingsSerializable} + * which could be used out of the box or extended. See also extension point + * schema description LanguageSettingsProvider.exsd. + * * @since 6.0 */ public interface ILanguageSettingsProvider { /** * Id is used to keep track of the providers internally. Use unique id * to represent the provider. - * + * * @return Id of the provider. */ public String getId(); /** * Name is used to present the provider to the end user in UI. - * + * * @return name of the provider. */ public String getName(); @@ -53,12 +53,21 @@ public interface ILanguageSettingsProvider { /** * Returns the list of setting entries for the given configuration description, * resource and language. - * + *

    + * Note to implementers - this method should not be used to do any long running + * operations such as extensive calculations or reading files. If you need to do + * so, the recommended way is to do the calculations outside of + * this function call - in advance and on appropriate event. For example, Build + * Output Parser prepares the list and stores it in internal cache while parsing output. + * {@link #getSettingEntries(ICConfigurationDescription, IResource, String)} will + * return cached entries when asked. You can also implement {@link ICListenerAgent} + * interface to get registered and listen to arbitrary events. + * * @param cfgDescription - configuration description. * @param rc - resource such as file or folder. * @param languageId - language id * (see {@link LanguageManager#getLanguageForFile(org.eclipse.core.resources.IFile, ICConfigurationDescription)}). - * + * * @return the list of setting entries or {@code null} if no settings defined. */ public List getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java index a2f0fefe6ba..644f6f6c457 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java @@ -83,8 +83,8 @@ public class LanguageSettingsProvidersSerializer { private ICListenerAgent listener; private ICConfigurationDescription cfgDescription; - public ListenerAssociation(ICListenerAgent li, ICConfigurationDescription cfgd) { - listener = li; + public ListenerAssociation(ICListenerAgent la, ICConfigurationDescription cfgd) { + listener = la; cfgDescription = cfgd; } } @@ -864,7 +864,7 @@ projects: } /** - * Get a providers list including only providers of type ICListenerRegisterer + * Get a providers list including only providers of type {@link ICListenerAgent} * for a given project description - collecting from all configurations. */ private static List getListeners(ICProjectDescription prjDescription) { @@ -895,7 +895,7 @@ projects: } /** - * Get a providers list including only providers of type IResourceChangeListener + * Get a providers list including only providers of type {@link ICListenerAgent} * for a given project description - collecting from all configurations. */ private static List getListenersAssociations(ICProjectDescription prjDescription) { @@ -916,7 +916,8 @@ projects: /** * Unregister listeners which are not used anymore and register new listeners. - * The method is used when project description is applied to workspace. + * The method is called when project description is applied to workspace. + * * @param oldPrjDescription - old project descriptions being replaced in the workspace. * @param newPrjDescription - new project description being applied to the workspace. */ diff --git a/core/org.eclipse.cdt.core/schema/LanguageSettingsProvider.exsd b/core/org.eclipse.cdt.core/schema/LanguageSettingsProvider.exsd index 3fd10baf9c5..a384595a320 100644 --- a/core/org.eclipse.cdt.core/schema/LanguageSettingsProvider.exsd +++ b/core/org.eclipse.cdt.core/schema/LanguageSettingsProvider.exsd @@ -15,6 +15,9 @@ + + This extension point is used to contribute a new Language Settings Provider. A Language Settings Provider is used to get additions to compiler options such as include paths (-I) or preprocessor defines (-D) and others into the project model. + From 10dd44163ab9d9656561d0b6272da8fb34406415 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Fri, 18 Nov 2011 17:09:21 -0500 Subject: [PATCH 066/120] Renamed LanguageSettingsSerializable -> LanguageSettingsSerializableProvider --- ...AbstractLanguageSettingsOutputScanner.java | 4 +- .../LanguageSettingsExtensionsTests.java | 6 +- .../LanguageSettingsManagerTests.java | 16 +- ...nguageSettingsPersistenceProjectTests.java | 78 ++++----- .../LanguageSettingsSerializableTests.java | 160 +++++++++--------- .../MockLanguageSettingsEditableProvider.java | 4 +- ...kLanguageSettingsSerializableProvider.java | 4 +- .../providers/MockListenerRegisterer.java | 2 +- .../model/CProjectDescriptionDeltaTests.java | 4 +- .../ILanguageSettingsEditableProvider.java | 2 +- .../providers/ILanguageSettingsProvider.java | 2 +- .../providers/LanguageSettingsManager.java | 31 ++-- .../LanguageSettingsManager_TBD.java | 2 +- .../LanguageSettingsSerializableEditable.java | 2 +- ...LanguageSettingsSerializableProvider.java} | 20 +-- .../LanguageSettingsExtensionManager.java | 6 +- .../LanguageSettingsProvidersSerializer.java | 33 ++-- .../model/CConfigurationSpecSettings.java | 6 +- .../providers/LanguageSettingsEntriesTab.java | 6 +- .../LanguageSettingsProviderTab.java | 16 +- ...anguageSettingsProvidersLabelProvider.java | 6 +- .../UserLanguageSettingsProvider.java | 6 +- 22 files changed, 209 insertions(+), 207 deletions(-) rename core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/{LanguageSettingsSerializable.java => LanguageSettingsSerializableProvider.java} (94%) diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java index 69366a058e5..652dcfc63da 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java @@ -30,7 +30,7 @@ import org.eclipse.cdt.core.ErrorParserManager; import org.eclipse.cdt.core.cdtvariables.CdtVariableException; import org.eclipse.cdt.core.cdtvariables.ICdtVariableManager; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; -import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializableProvider; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICSettingEntry; @@ -54,7 +54,7 @@ import org.eclipse.core.runtime.content.IContentType; import org.eclipse.core.runtime.content.IContentTypeManager; import org.w3c.dom.Element; -public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSettingsSerializable { +public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSettingsSerializableProvider { protected static final String ATTR_EXPAND_RELATIVE_PATHS = "expand-relative-paths"; //$NON-NLS-1$ diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java index 0783df36eee..df125a63059 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java @@ -236,8 +236,8 @@ public class LanguageSettingsExtensionsTests extends BaseTestCase { // get raw extension provider ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(providerExt); - assertTrue(rawProvider instanceof LanguageSettingsSerializable); - LanguageSettingsSerializable provider = (LanguageSettingsSerializable) rawProvider; + assertTrue(rawProvider instanceof LanguageSettingsSerializableProvider); + LanguageSettingsSerializableProvider provider = (LanguageSettingsSerializableProvider) rawProvider; assertEquals(null, provider.getLanguageScope()); assertEquals("", provider.getCustomParameter()); @@ -259,7 +259,7 @@ public class LanguageSettingsExtensionsTests extends BaseTestCase { // get raw extension provider ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(providerExt); - assertTrue(rawProvider instanceof LanguageSettingsSerializable); + assertTrue(rawProvider instanceof LanguageSettingsSerializableProvider); assertTrue(LanguageSettingsExtensionManager.equalsExtensionProvider(rawProvider)); // compare with workspace provider diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java index 71f8fa663e9..5fb13f11277 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java @@ -696,7 +696,7 @@ public class LanguageSettingsManagerTests extends BaseTestCase { ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); assertEquals(EXTENSION_EDITABLE_PROVIDER_ID, rawProvider.getId()); assertEquals(EXTENSION_EDITABLE_PROVIDER_NAME, rawProvider.getName()); - assertTrue(rawProvider instanceof LanguageSettingsSerializable); + assertTrue(rawProvider instanceof LanguageSettingsSerializableProvider); // assert they are not the same object assertNotSame(provider, rawProvider); @@ -713,7 +713,7 @@ public class LanguageSettingsManagerTests extends BaseTestCase { List newEntries = new ArrayList(); newEntries.add(new CIncludePathEntry("path0", 0)); newEntries.add(new CIncludePathEntry("path1", 0)); - ((LanguageSettingsSerializable)rawProvider).setSettingEntries(null, null, null, newEntries); + ((LanguageSettingsSerializableProvider)rawProvider).setSettingEntries(null, null, null, newEntries); // check that the workspace provider gets them too List newRawEntries = rawProvider.getSettingEntries(null, null, null); @@ -752,7 +752,7 @@ public class LanguageSettingsManagerTests extends BaseTestCase { { // replace raw provider List providers = new ArrayList(); - LanguageSettingsSerializable newRawProvider = new LanguageSettingsSerializable(EXTENSION_EDITABLE_PROVIDER_ID, PROVIDER_NAME_0); + LanguageSettingsSerializableProvider newRawProvider = new LanguageSettingsSerializableProvider(EXTENSION_EDITABLE_PROVIDER_ID, PROVIDER_NAME_0); newRawProvider.setSettingEntries(null, null, null, newEntries); providers.add(newRawProvider); LanguageSettingsManager.setWorkspaceProviders(providers); @@ -800,7 +800,7 @@ public class LanguageSettingsManagerTests extends BaseTestCase { assertNotNull(file); // create a provider and set the entries - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); provider.setSettingEntries(null, file, null, entries); // build the hierarchy LanguageSettingsProvidersSerializer.buildResourceTree(provider, null, null, project); @@ -824,7 +824,7 @@ public class LanguageSettingsManagerTests extends BaseTestCase { IFile file = ResourceHelper.createFile(project, "Folder/file.cpp"); // create a provider and set the entries - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); provider.setSettingEntries(null, file, null, entries); // build the hierarchy LanguageSettingsManager.buildResourceTree(provider, null, null, project); @@ -852,7 +852,7 @@ public class LanguageSettingsManagerTests extends BaseTestCase { IFile file2 = ResourceHelper.createFile(project, "Folder2/file2.cpp"); // create a provider and set the entries - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); provider.setSettingEntries(null, file1, null, entries1); provider.setSettingEntries(null, file2, null, entries2); // build the hierarchy @@ -884,7 +884,7 @@ public class LanguageSettingsManagerTests extends BaseTestCase { IFile file3 = ResourceHelper.createFile(project, "file3.cpp"); // create a provider - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); // set the entries for the first 2 files provider.setSettingEntries(null, file1, null, entries1); @@ -922,7 +922,7 @@ public class LanguageSettingsManagerTests extends BaseTestCase { IFile file = ResourceHelper.createFile(project, "Folder/file.cpp"); // create a provider and set the entries - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); provider.setSettingEntries(null, file, LANG_CPP, entries); // build the hierarchy LanguageSettingsManager.buildResourceTree(provider, null, LANG_CPP, project); diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java index 90406f5e144..1d4b51c7438 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java @@ -103,7 +103,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { } } - private class MockEditableProvider extends LanguageSettingsSerializable implements ILanguageSettingsEditableProvider { + private class MockEditableProvider extends LanguageSettingsSerializableProvider implements ILanguageSettingsEditableProvider { public MockEditableProvider(String id, String name) { super(id, name); } @@ -189,7 +189,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { public void testProjectDescription_PreventBackDoorAccess() throws Exception { // create a project IProject project = ResourceHelper.createCDTProjectWithConfig(getName()); - + // get project descriptions ICProjectDescription writableProjDescription = coreModel.getProjectDescription(project); assertNotNull(writableProjDescription); @@ -198,13 +198,13 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { ICConfigurationDescription cfgDescription = cfgDescriptions[0]; List originalProviders = cfgDescription.getLanguageSettingProviders(); int originalSize = originalProviders.size(); - + // create new provider list - LanguageSettingsSerializable mockProvider = new MockEditableProvider(PROVIDER_0, PROVIDER_NAME_0); + LanguageSettingsSerializableProvider mockProvider = new MockEditableProvider(PROVIDER_0, PROVIDER_NAME_0); List providers = new ArrayList(originalProviders); providers.add(mockProvider); assertTrue(originalSize != providers.size()); - + // changing providers shouldn't affect the original list cfgDescription.setLanguageSettingProviders(providers); assertEquals(originalSize, originalProviders.size()); @@ -215,14 +215,14 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { public void testProjectDescription_ReadWriteProviders() throws Exception { // create a project IProject project = ResourceHelper.createCDTProjectWithConfig(getName()); - + { // get read-only description ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false); assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); assertNotNull(cfgDescription); - + // try to write to it try { List providers = new ArrayList(); @@ -232,10 +232,10 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { // exception is expected } } - + List entries = new ArrayList(); entries.add(new CIncludePathEntry("path0", 0)); - + { // get project descriptions ICProjectDescription writableProjDescription = coreModel.getProjectDescription(project); @@ -243,9 +243,9 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; - + // create a provider - LanguageSettingsSerializable mockProvider = new MockEditableProvider(PROVIDER_0, PROVIDER_NAME_0); + LanguageSettingsSerializableProvider mockProvider = new MockEditableProvider(PROVIDER_0, PROVIDER_NAME_0); mockProvider.setStoringEntriesInProjectArea(true); mockProvider.setSettingEntries(cfgDescription, null, null, entries); List providers = new ArrayList(); @@ -253,7 +253,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { cfgDescription.setLanguageSettingProviders(providers); List storedProviders = cfgDescription.getLanguageSettingProviders(); assertEquals(1, storedProviders.size()); - + // apply new project description to the project model coreModel.setProjectDescription(project, writableProjDescription); } @@ -264,14 +264,14 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { ICConfigurationDescription[] cfgDescriptions = readOnlyProjDescription.getConfigurations(); assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; - + List providers = cfgDescription.getLanguageSettingProviders(); assertEquals(1, providers.size()); ILanguageSettingsProvider loadedProvider = providers.get(0); - assertTrue(loadedProvider instanceof LanguageSettingsSerializable); + assertTrue(loadedProvider instanceof LanguageSettingsSerializableProvider); assertEquals(PROVIDER_0, loadedProvider.getId()); assertEquals(PROVIDER_NAME_0, loadedProvider.getName()); - + List actual = loadedProvider.getSettingEntries(cfgDescription, null, null); assertEquals(entries.get(0), actual.get(0)); assertEquals(entries.size(), actual.size()); @@ -283,20 +283,20 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; - + List providers = cfgDescription.getLanguageSettingProviders(); assertEquals(1, providers.size()); ILanguageSettingsProvider loadedProvider = providers.get(0); - assertTrue(loadedProvider instanceof LanguageSettingsSerializable); + assertTrue(loadedProvider instanceof LanguageSettingsSerializableProvider); assertEquals(PROVIDER_0, loadedProvider.getId()); assertEquals(PROVIDER_NAME_0, loadedProvider.getName()); - + List actual = loadedProvider.getSettingEntries(cfgDescription, null, null); assertEquals(entries.get(0), actual.get(0)); assertEquals(entries.size(), actual.size()); } } - + /** */ public void testWorkspacePersistence_ModifiedExtensionProvider() throws Exception { @@ -306,7 +306,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { { // get the raw extension provider ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_SERIALIZABLE_PROVIDER_ID); - LanguageSettingsSerializable extProvider = (LanguageSettingsSerializable) LanguageSettingsManager.getRawProvider(provider); + LanguageSettingsSerializableProvider extProvider = (LanguageSettingsSerializableProvider) LanguageSettingsManager.getRawProvider(provider); assertNotNull(extProvider); assertEquals(EXTENSION_SERIALIZABLE_PROVIDER_ID, extProvider.getId()); @@ -347,7 +347,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { { // get the raw extension provider ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_SERIALIZABLE_PROVIDER_ID); - LanguageSettingsSerializable rawProvider = (LanguageSettingsSerializable) LanguageSettingsManager.getRawProvider(provider); + LanguageSettingsSerializableProvider rawProvider = (LanguageSettingsSerializableProvider) LanguageSettingsManager.getRawProvider(provider); assertNotNull(rawProvider); assertEquals(EXTENSION_SERIALIZABLE_PROVIDER_ID, rawProvider.getId()); @@ -365,7 +365,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { { // check that it has not cleared ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_SERIALIZABLE_PROVIDER_ID); - LanguageSettingsSerializable rawProvider = (LanguageSettingsSerializable) LanguageSettingsManager.getRawProvider(provider); + LanguageSettingsSerializableProvider rawProvider = (LanguageSettingsSerializableProvider) LanguageSettingsManager.getRawProvider(provider); assertEquals(CUSTOM_PARAMETER, rawProvider.getCustomParameter()); } } @@ -450,7 +450,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { ICConfigurationDescription cfgDescription = cfgDescriptions[0]; assertNotNull(cfgDescription); - LanguageSettingsSerializable serializableProvider = new LanguageSettingsSerializable(PROVIDER_0, PROVIDER_NAME_0); + LanguageSettingsSerializableProvider serializableProvider = new LanguageSettingsSerializableProvider(PROVIDER_0, PROVIDER_NAME_0); serializableProvider.setSettingEntries(null, null, null, entries); serializableProvider.setStoringEntriesInProjectArea(true); @@ -479,7 +479,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { assertNotNull(providers); assertEquals(1, providers.size()); ILanguageSettingsProvider provider = providers.get(0); - assertTrue(provider instanceof LanguageSettingsSerializable); + assertTrue(provider instanceof LanguageSettingsSerializableProvider); List actual = provider.getSettingEntries(null, null, null); assertEquals(entries.get(0), actual.get(0)); @@ -513,7 +513,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { ICConfigurationDescription cfgDescription1 = cfgDescriptions[0]; assertNotNull(cfgDescription1); assertEquals(CFG_ID, cfgDescription1.getId()); - LanguageSettingsSerializable provider1 = new LanguageSettingsSerializable(PROVIDER_0, PROVIDER_NAME_0); + LanguageSettingsSerializableProvider provider1 = new LanguageSettingsSerializableProvider(PROVIDER_0, PROVIDER_NAME_0); provider1.setStoringEntriesInProjectArea(true); provider1.setSettingEntries(null, null, null, entries); ArrayList providers = new ArrayList(); @@ -525,7 +525,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { ICConfigurationDescription cfgDescription2 = cfgDescriptions[1]; assertNotNull(cfgDescription2); assertEquals(CFG_ID_2, cfgDescription2.getId()); - LanguageSettingsSerializable provider2 = new LanguageSettingsSerializable(PROVIDER_0, PROVIDER_NAME_0); + LanguageSettingsSerializableProvider provider2 = new LanguageSettingsSerializableProvider(PROVIDER_0, PROVIDER_NAME_0); provider2.setStoringEntriesInProjectArea(true); provider2.setSettingEntries(null, null, null, entries2); ArrayList providers = new ArrayList(); @@ -631,7 +631,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { ICConfigurationDescription cfgDescription = cfgDescriptions[0]; assertNotNull(cfgDescription); - LanguageSettingsSerializable serializableProvider = new MockLanguageSettingsSerializableProvider(PROVIDER_0, PROVIDER_NAME_0); + LanguageSettingsSerializableProvider serializableProvider = new MockLanguageSettingsSerializableProvider(PROVIDER_0, PROVIDER_NAME_0); serializableProvider.setSettingEntries(null, null, null, entries); serializableProvider.setStoringEntriesInProjectArea(true); @@ -673,7 +673,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { public void testProjectPersistence_ReferenceExtensionProviderDOM() throws Exception { Element rootElement = null; - // provider of other type (not LanguageSettingsSerializable) defined as an extension + // provider of other type (not LanguageSettingsSerializableProvider) defined as an extension ILanguageSettingsProvider providerExt = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_PROVIDER_ID); { @@ -797,11 +797,11 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { // 3. Providers defined in a configuration // 3.1 - LanguageSettingsSerializable mockProvider1 = new LanguageSettingsSerializable(PROVIDER_0, PROVIDER_NAME_0); + LanguageSettingsSerializableProvider mockProvider1 = new LanguageSettingsSerializableProvider(PROVIDER_0, PROVIDER_NAME_0); mockProvider1.setStoringEntriesInProjectArea(true); mockProvider1.setSettingEntries(null, null, null, entries_31); // 3.2 - LanguageSettingsSerializable mockProvider2 = new MockLanguageSettingsSerializableProvider(PROVIDER_2, PROVIDER_NAME_2); + LanguageSettingsSerializableProvider mockProvider2 = new MockLanguageSettingsSerializableProvider(PROVIDER_2, PROVIDER_NAME_2); mockProvider2.setStoringEntriesInProjectArea(true); mockProvider2.setSettingEntries(null, null, null, entries_32); @@ -841,7 +841,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { // 3.1 { ILanguageSettingsProvider provider1 = providers.get(1); - assertTrue(provider1 instanceof LanguageSettingsSerializable); + assertTrue(provider1 instanceof LanguageSettingsSerializableProvider); List actual = provider1.getSettingEntries(null, null, null); assertEquals(entries_31.get(0), actual.get(0)); assertEquals(entries_31.size(), actual.size()); @@ -877,7 +877,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { ICConfigurationDescription cfgDescription = cfgDescriptions[0]; // create a provider - LanguageSettingsSerializable mockProvider = new LanguageSettingsSerializable(PROVIDER_0, PROVIDER_NAME_0); + LanguageSettingsSerializableProvider mockProvider = new LanguageSettingsSerializableProvider(PROVIDER_0, PROVIDER_NAME_0); mockProvider.setStoringEntriesInProjectArea(true); mockProvider.setSettingEntries(cfgDescription, null, null, entries); List providers = new ArrayList(); @@ -898,7 +898,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { List providers = cfgDescription.getLanguageSettingProviders(); assertEquals(1, providers.size()); ILanguageSettingsProvider provider = providers.get(0); - assertTrue(provider instanceof LanguageSettingsSerializable); + assertTrue(provider instanceof LanguageSettingsSerializableProvider); assertEquals(PROVIDER_0, provider.getId()); assertEquals(PROVIDER_NAME_0, provider.getName()); @@ -975,7 +975,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { List providers = cfgDescription.getLanguageSettingProviders(); assertEquals(1, providers.size()); ILanguageSettingsProvider loadedProvider = providers.get(0); - assertTrue(loadedProvider instanceof LanguageSettingsSerializable); + assertTrue(loadedProvider instanceof LanguageSettingsSerializableProvider); assertEquals(PROVIDER_0, loadedProvider.getId()); assertEquals(PROVIDER_NAME_0, loadedProvider.getName()); @@ -1002,7 +1002,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { ICConfigurationDescription cfgDescription = cfgDescriptions[0]; assertNotNull(cfgDescription); - LanguageSettingsSerializable serializableProvider = new LanguageSettingsSerializable(PROVIDER_0, PROVIDER_NAME_0); + LanguageSettingsSerializableProvider serializableProvider = new LanguageSettingsSerializableProvider(PROVIDER_0, PROVIDER_NAME_0); serializableProvider.setSettingEntries(null, null, null, entries); // do not store entries inside project serializableProvider.setStoringEntriesInProjectArea(false); @@ -1034,7 +1034,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { assertNotNull(providers); assertEquals(1, providers.size()); ILanguageSettingsProvider provider = providers.get(0); - assertTrue(provider instanceof LanguageSettingsSerializable); + assertTrue(provider instanceof LanguageSettingsSerializableProvider); List actual = provider.getSettingEntries(null, null, null); assertEquals(entries.get(0), actual.get(0)); @@ -1074,7 +1074,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { ICConfigurationDescription cfgDescription = cfgDescriptions[0]; // create a provider - LanguageSettingsSerializable mockProvider = new LanguageSettingsSerializable(PROVIDER_0, PROVIDER_NAME_0); + LanguageSettingsSerializableProvider mockProvider = new LanguageSettingsSerializableProvider(PROVIDER_0, PROVIDER_NAME_0); mockProvider.setStoringEntriesInProjectArea(false); mockProvider.setSettingEntries(cfgDescription, null, null, entries); List providers = new ArrayList(); @@ -1099,7 +1099,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { List providers = cfgDescription.getLanguageSettingProviders(); assertEquals(1, providers.size()); ILanguageSettingsProvider provider = providers.get(0); - assertTrue(provider instanceof LanguageSettingsSerializable); + assertTrue(provider instanceof LanguageSettingsSerializableProvider); assertEquals(PROVIDER_0, provider.getId()); assertEquals(PROVIDER_NAME_0, provider.getName()); @@ -1193,7 +1193,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { List providers = cfgDescription.getLanguageSettingProviders(); assertEquals(1, providers.size()); ILanguageSettingsProvider loadedProvider = providers.get(0); - assertTrue(loadedProvider instanceof LanguageSettingsSerializable); + assertTrue(loadedProvider instanceof LanguageSettingsSerializableProvider); assertEquals(PROVIDER_0, loadedProvider.getId()); assertEquals(PROVIDER_NAME_0, loadedProvider.getName()); diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java index e3e9f98b546..14c8942d3f9 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java @@ -104,7 +104,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { languages.add(LANG_ID); // create a provider - LanguageSettingsSerializable mockProvider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + LanguageSettingsSerializableProvider mockProvider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); // test isEmpty() assertTrue(mockProvider.isEmpty()); @@ -142,7 +142,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { Element elementProvider; { // create customized provider - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); provider.setStoringEntriesInProjectArea(true); provider.setCustomParameter(CUSTOM_PARAMETER); @@ -168,7 +168,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { } { // re-load and check language settings of the newly loaded provider - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(elementProvider); + LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(elementProvider); assertEquals(PROVIDER_1, provider.getId()); assertEquals(true, provider.isStoringEntriesInProjectArea()); assertEquals(CUSTOM_PARAMETER, provider.getCustomParameter()); @@ -189,7 +189,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { Element elementProvider; { // create customized provider - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); provider.setStoringEntriesInProjectArea(true); provider.setCustomParameter(CUSTOM_PARAMETER); @@ -216,7 +216,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { } { // re-load and check language settings of the newly loaded provider - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(); + LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(); provider.loadAttributes(elementProvider); assertEquals(PROVIDER_1, provider.getId()); assertEquals(true, provider.isStoringEntriesInProjectArea()); @@ -236,7 +236,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { Element rootElement; { // create customized provider - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); provider.setStoringEntriesInProjectArea(true); provider.setCustomParameter(CUSTOM_PARAMETER); @@ -264,7 +264,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { } { // re-load and check language settings of the newly loaded provider - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_2, PROVIDER_NAME_2); + LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_2, PROVIDER_NAME_2); provider.loadEntries(rootElement); assertEquals(PROVIDER_2, provider.getId()); assertEquals(PROVIDER_NAME_2, provider.getName()); @@ -288,7 +288,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { Element elementProvider; { // create null provider - LanguageSettingsSerializable providerNull = new LanguageSettingsSerializable(PROVIDER_NULL, PROVIDER_NAME_NULL); + LanguageSettingsSerializableProvider providerNull = new LanguageSettingsSerializableProvider(PROVIDER_NULL, PROVIDER_NAME_NULL); assertNull(providerNull.getSettingEntries(null, null, null)); // set and get null entries providerNull.setSettingEntries(null, null, null, null); @@ -302,7 +302,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { } { // re-load and check language settings of the newly loaded provider - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(elementProvider); + LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(elementProvider); assertEquals(PROVIDER_NULL, provider.getId()); List actual = provider.getSettingEntries(null, null, null); assertNull(actual); @@ -315,7 +315,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { Element elementProvider; { // create provider with custom parameter - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); provider.setCustomParameter(CUSTOM_PARAMETER); assertEquals(CUSTOM_PARAMETER, provider.getCustomParameter()); @@ -327,7 +327,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { } { // re-load and check custom parameter of the newly loaded provider - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(elementProvider); + LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(elementProvider); assertEquals(CUSTOM_PARAMETER, provider.getCustomParameter()); } } @@ -338,7 +338,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { Element elementProvider; { // create provider with custom parameter - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); assertEquals(false, provider.isStoringEntriesInProjectArea()); provider.setStoringEntriesInProjectArea(true); assertEquals(true, provider.isStoringEntriesInProjectArea()); @@ -352,7 +352,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { } { // re-load and check custom parameter of the newly loaded provider - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(elementProvider); + LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(elementProvider); assertEquals(true, provider.isStoringEntriesInProjectArea()); } } @@ -367,7 +367,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { Element elementProvider; { // create provider with custom language scope - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); provider.setLanguageScope(expectedLanguageIds); List actualIds = provider.getLanguageScope(); assertEquals(LANG_ID, actualIds.get(0)); @@ -383,7 +383,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { } { // re-load and check language settings of the newly loaded provider - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(elementProvider); + LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(elementProvider); List actualIds = provider.getLanguageScope(); assertEquals(expectedLanguageIds.get(0), actualIds.get(0)); assertEquals(expectedLanguageIds.get(1), actualIds.get(1)); @@ -406,7 +406,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { Element elementProvider; { // create provider with no scope by default - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); // set entries for the whole language scope (now langId=null) provider.setSettingEntries(null, null, null, entries); { @@ -452,7 +452,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { } { // re-load and check language settings of the newly loaded provider - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(elementProvider); + LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(elementProvider); List actualIds = provider.getLanguageScope(); assertEquals(expectedLanguageIds.get(0), actualIds.get(0)); assertEquals(expectedLanguageIds.get(1), actualIds.get(1)); @@ -485,7 +485,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { entries.add(new CIncludePathEntry("path0", 0)); { // create a provider and serialize its settings - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); provider.setSettingEntries(null, MOCK_RC, LANG_ID, entries); Document doc = XmlUtil.newDocument(); @@ -494,11 +494,11 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { // verify that "configuration" element is collapsed and not saved in XML String xmlString = XmlUtil.toString(doc); - assertFalse(xmlString.contains(" actual = provider.getSettingEntries(null, MOCK_RC, LANG_ID); assertEquals(entries.get(0), actual.get(0)); @@ -514,7 +514,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { entries.add(new CIncludePathEntry("path0", 0)); { // create a provider and serialize its settings - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); provider.setSettingEntries(MOCK_CFG, MOCK_RC, null, entries); Document doc = XmlUtil.newDocument(); @@ -523,11 +523,11 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { // verify that "language" element is collapsed and not saved in XML String xmlString = XmlUtil.toString(doc); - assertFalse(xmlString.contains(" actual = provider.getSettingEntries(MOCK_CFG, MOCK_RC, null); assertEquals(entries.get(0), actual.get(0)); @@ -548,7 +548,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { { // create a provider - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); assertEquals(null, provider.getLanguageScope()); // add null language @@ -590,11 +590,11 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { // verify that "language" element is saved in XML String xmlString = XmlUtil.toString(doc); - assertTrue(xmlString.contains(" actual = provider.getSettingEntries(null, MOCK_RC, null); @@ -619,7 +619,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { entries.add(new CIncludePathEntry("path0", 0)); { // create a provider and serialize its settings - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); provider.setSettingEntries(MOCK_CFG, null, LANG_ID, entries); Document doc = XmlUtil.newDocument(); @@ -628,11 +628,11 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { // verify that "resource" element is collapsed and not saved in XML String xmlString = XmlUtil.toString(doc); - assertFalse(xmlString.contains(" actual = provider.getSettingEntries(MOCK_CFG, null, LANG_ID); assertEquals(entries.get(0), actual.get(0)); @@ -648,7 +648,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { entries.add(new CIncludePathEntry("path0", 0)); { // create a provider and serialize its settings - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); provider.setSettingEntries(null, MOCK_RC, null, entries); Document doc = XmlUtil.newDocument(); @@ -657,12 +657,12 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { // verify that element is collapsed and not saved in XML String xmlString = XmlUtil.toString(doc); - assertFalse(xmlString.contains(" actual = provider.getSettingEntries(null, MOCK_RC, null); assertEquals(entries.get(0), actual.get(0)); @@ -678,7 +678,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { entries.add(new CIncludePathEntry("path0", 0)); { // create a provider and serialize its settings - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); provider.setSettingEntries(null, null, LANG_ID, entries); Document doc = XmlUtil.newDocument(); @@ -687,12 +687,12 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { // verify that element is collapsed and not saved in XML String xmlString = XmlUtil.toString(doc); - assertFalse(xmlString.contains(" actual = provider.getSettingEntries(null, null, LANG_ID); assertEquals(entries.get(0), actual.get(0)); @@ -708,7 +708,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { entries.add(new CIncludePathEntry("path0", 0)); { // create a provider and serialize its settings - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); provider.setSettingEntries(MOCK_CFG, null, null, entries); Document doc = XmlUtil.newDocument(); @@ -717,12 +717,12 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { // verify that element is collapsed and not saved in XML String xmlString = XmlUtil.toString(doc); - assertFalse(xmlString.contains(" actual = provider.getSettingEntries(MOCK_CFG, null, null); assertEquals(entries.get(0), actual.get(0)); @@ -739,7 +739,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { entries.add(new CIncludePathEntry("path0", flag)); { // create a provider and serialize its settings - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); provider.setSettingEntries(null, null, null, entries); Document doc = XmlUtil.newDocument(); @@ -748,14 +748,14 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { // verify that element is collapsed and not saved in XML String xmlString = XmlUtil.toString(doc); - assertFalse(xmlString.contains(" actual = provider.getSettingEntries(null, null, null); assertEquals(entries.get(0), actual.get(0)); @@ -770,7 +770,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { entries.add(new CIncludePathEntry("path0", 1)); { // create a provider and serialize its settings - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); provider.setSettingEntries(null, null, null, entries); Document doc = XmlUtil.newDocument(); @@ -779,7 +779,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { } { // re-load and check language settings of the newly loaded provider - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(elementProvider); + LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(elementProvider); assertEquals(PROVIDER_1, provider.getId()); List actual = provider.getSettingEntries(null, null, null); @@ -803,7 +803,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { entries.add(new CIncludeFileEntry("name", 1)); { // create a provider and serialize its settings - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); provider.setSettingEntries(null, null, null, entries); Document doc = XmlUtil.newDocument(); @@ -812,7 +812,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { } { // re-load and check language settings of the newly loaded provider - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(elementProvider); + LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(elementProvider); assertEquals(PROVIDER_1, provider.getId()); List actual = provider.getSettingEntries(null, null, null); @@ -835,7 +835,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { entries.add(new CMacroEntry("MACRO0", "value0",1)); { // create a provider and serialize its settings - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); provider.setSettingEntries(null, null, null, entries); Document doc = XmlUtil.newDocument(); @@ -844,7 +844,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { } { // re-load and check language settings of the newly loaded provider - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(elementProvider); + LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(elementProvider); assertEquals(PROVIDER_1, provider.getId()); List actual = provider.getSettingEntries(null, null, null); @@ -867,7 +867,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { entries.add(new CMacroFileEntry("name", 1)); { // create a provider and serialize its settings - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); provider.setSettingEntries(null, null, null, entries); Document doc = XmlUtil.newDocument(); @@ -876,7 +876,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { } { // re-load and check language settings of the newly loaded provider - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(elementProvider); + LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(elementProvider); assertEquals(PROVIDER_1, provider.getId()); List actual = provider.getSettingEntries(null, null, null); @@ -899,7 +899,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { entries.add(new CLibraryPathEntry("name", 1)); { // create a provider and serialize its settings - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); provider.setSettingEntries(null, null, null, entries); Document doc = XmlUtil.newDocument(); @@ -908,7 +908,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { } { // re-load and check language settings of the newly loaded provider - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(elementProvider); + LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(elementProvider); assertEquals(PROVIDER_1, provider.getId()); List actual = provider.getSettingEntries(null, null, null); @@ -931,7 +931,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { entries.add(new CLibraryFileEntry("name", 1)); { // create a provider and serialize its settings - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); provider.setSettingEntries(null, null, null, entries); Document doc = XmlUtil.newDocument(); @@ -940,7 +940,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { } { // re-load and check language settings of the newly loaded provider - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(elementProvider); + LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(elementProvider); assertEquals(PROVIDER_1, provider.getId()); List actual = provider.getSettingEntries(null, null, null); @@ -965,7 +965,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { entries.add(new CMacroEntry("MACRO0", "value0",1)); { // create a provider and serialize its settings - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); provider.setSettingEntries(null, null, null, entries); Document doc = XmlUtil.newDocument(); @@ -974,7 +974,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { } { // re-load and check language settings of the newly loaded provider - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(elementProvider); + LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(elementProvider); assertEquals(PROVIDER_1, provider.getId()); List actual = provider.getSettingEntries(null, null, null); @@ -997,8 +997,8 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { { // create a provider - LanguageSettingsSerializable mockProvider = null; - mockProvider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + LanguageSettingsSerializableProvider mockProvider = null; + mockProvider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); mockProvider.setSettingEntries(null, null, null, entries); mockProvider.setSettingEntries(null, null, LANG_ID, entries2); @@ -1009,7 +1009,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { } { // re-load and check language settings of the newly loaded provider - LanguageSettingsSerializable loadedProvider = new LanguageSettingsSerializable(elementProvider); + LanguageSettingsSerializableProvider loadedProvider = new LanguageSettingsSerializableProvider(elementProvider); List actual = loadedProvider.getSettingEntries(null, null, null); assertEquals(entries.get(0), actual.get(0)); @@ -1033,8 +1033,8 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { { // create a provider - LanguageSettingsSerializable mockProvider = null; - mockProvider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + LanguageSettingsSerializableProvider mockProvider = null; + mockProvider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); mockProvider.setSettingEntries(null, null, LANG_ID_1, entries); mockProvider.setSettingEntries(null, null, LANG_ID_2, entries2); @@ -1047,7 +1047,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { } { // re-load and check language settings of the newly loaded provider - LanguageSettingsSerializable loadedProvider = new LanguageSettingsSerializable(elementProvider); + LanguageSettingsSerializableProvider loadedProvider = new LanguageSettingsSerializableProvider(elementProvider); List actual = loadedProvider.getSettingEntries(null, null, LANG_ID_1); assertEquals(entries.get(0), actual.get(0)); @@ -1079,8 +1079,8 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { { // create a provider - LanguageSettingsSerializable mockProvider = null; - mockProvider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + LanguageSettingsSerializableProvider mockProvider = null; + mockProvider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); mockProvider.setSettingEntries(null, rc1, null, entries); mockProvider.setSettingEntries(null, rc2, null, entries2); @@ -1093,7 +1093,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { } { // re-load and check language settings of the newly loaded provider - LanguageSettingsSerializable loadedProvider = new LanguageSettingsSerializable(elementProvider); + LanguageSettingsSerializableProvider loadedProvider = new LanguageSettingsSerializableProvider(elementProvider); List actual = loadedProvider.getSettingEntries(null, rc1, null); assertEquals(entries.get(0), actual.get(0)); @@ -1118,7 +1118,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { assertNotNull(emptySettingsPath); // Create provider - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); // store the entries in parent folder List entries = new ArrayList(); @@ -1171,7 +1171,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { sampleLanguages.add(LANG_ID); // create a model provider - LanguageSettingsSerializable provider1 = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + LanguageSettingsSerializableProvider provider1 = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); provider1.setLanguageScope(sampleLanguages); provider1.setCustomParameter(CUSTOM_PARAMETER); assertEquals(false, provider1.isStoringEntriesInProjectArea()); @@ -1181,7 +1181,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { { // create another provider with the same data - LanguageSettingsSerializable provider2 = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + LanguageSettingsSerializableProvider provider2 = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); assertFalse(provider1.equals(provider2)); assertFalse(provider1.hashCode()==provider2.hashCode()); @@ -1215,8 +1215,8 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { { // check that subclasses are not equal - LanguageSettingsSerializable providerSub1 = new LanguageSettingsSerializable() {}; - LanguageSettingsSerializable providerSub2 = new LanguageSettingsSerializable() {}; + LanguageSettingsSerializableProvider providerSub1 = new LanguageSettingsSerializableProvider() {}; + LanguageSettingsSerializableProvider providerSub2 = new LanguageSettingsSerializableProvider() {}; assertFalse(providerSub1.equals(providerSub2)); assertFalse(providerSub1.hashCode()==providerSub2.hashCode()); } @@ -1238,7 +1238,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { sampleLanguages.add(LANG_ID); // create a model provider - class LanguageSettingsSerializableMock extends LanguageSettingsSerializable implements Cloneable { + class LanguageSettingsSerializableMock extends LanguageSettingsSerializableProvider implements Cloneable { public LanguageSettingsSerializableMock(String id, String name) { super(id, name); } @@ -1286,7 +1286,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { sampleLanguages.add(LANG_ID); // create a model provider - class LanguageSettingsSerializableMock extends LanguageSettingsSerializable implements Cloneable { + class LanguageSettingsSerializableMock extends LanguageSettingsSerializableProvider implements Cloneable { public LanguageSettingsSerializableMock(String id, String name) { super(id, name); } @@ -1352,7 +1352,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { unsortedEntries.add(libraryPathEntry2); // create a provider and set the entries - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); provider.setSettingEntries(null, null, null, unsortedEntries); // retrieve and check that language settings got sorted properly @@ -1409,7 +1409,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { unsortedEntries.add(libraryPathEntry2); // create a provider and set the entries - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); provider.setSettingEntries(null, null, null, unsortedEntries); // retrieve and check that language settings got sorted properly @@ -1451,7 +1451,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { unsortedEntries.add(macroEntry2C); // create a provider and set the entries - LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1); + LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); provider.setSettingEntries(null, null, null, unsortedEntries); // retrieve and check that language settings got sorted properly diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockLanguageSettingsEditableProvider.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockLanguageSettingsEditableProvider.java index 32b907c017b..8db8881ad72 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockLanguageSettingsEditableProvider.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockLanguageSettingsEditableProvider.java @@ -11,10 +11,10 @@ package org.eclipse.cdt.core.language.settings.providers; -import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializableProvider; -public class MockLanguageSettingsEditableProvider extends LanguageSettingsSerializable implements ILanguageSettingsEditableProvider { +public class MockLanguageSettingsEditableProvider extends LanguageSettingsSerializableProvider implements ILanguageSettingsEditableProvider { public MockLanguageSettingsEditableProvider() { super(); } diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockLanguageSettingsSerializableProvider.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockLanguageSettingsSerializableProvider.java index 276a3400b93..2120f81fdb8 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockLanguageSettingsSerializableProvider.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockLanguageSettingsSerializableProvider.java @@ -11,10 +11,10 @@ package org.eclipse.cdt.core.language.settings.providers; -import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializableProvider; -public class MockLanguageSettingsSerializableProvider extends LanguageSettingsSerializable { +public class MockLanguageSettingsSerializableProvider extends LanguageSettingsSerializableProvider { public MockLanguageSettingsSerializableProvider() { super(); } diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockListenerRegisterer.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockListenerRegisterer.java index 1a7fb6b6d7a..f5ad3f3750e 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockListenerRegisterer.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockListenerRegisterer.java @@ -20,7 +20,7 @@ import org.eclipse.core.runtime.Assert; /** * Language Settings Provider that keeps count how many times it has been registered. */ -public class MockListenerRegisterer extends LanguageSettingsSerializable implements ILanguageSettingsEditableProvider, ICListenerAgent { +public class MockListenerRegisterer extends LanguageSettingsSerializableProvider implements ILanguageSettingsEditableProvider, ICListenerAgent { private static MockListenerManager mockListenerManager = new MockListenerManager(); private static class MockListenerManager { diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/settings/model/CProjectDescriptionDeltaTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/settings/model/CProjectDescriptionDeltaTests.java index 4d80b3adff7..b2de9f3bef9 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/settings/model/CProjectDescriptionDeltaTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/settings/model/CProjectDescriptionDeltaTests.java @@ -20,7 +20,7 @@ import junit.framework.TestSuite; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; -import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializableProvider; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.settings.model.util.CDataUtil; import org.eclipse.cdt.core.testplugin.ResourceHelper; @@ -1012,7 +1012,7 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ List originalProviders = cfgDescription.getLanguageSettingProviders(); // Modification LANGUAGE_SETTINGS_PROVIDERS - ILanguageSettingsProvider provider = new LanguageSettingsSerializable("id", "name"); + ILanguageSettingsProvider provider = new LanguageSettingsSerializableProvider("id", "name"); List providers = new ArrayList(); providers.add(provider); cfgDescription.setLanguageSettingProviders(providers); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsEditableProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsEditableProvider.java index 83052f276d9..3bb5d309dce 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsEditableProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsEditableProvider.java @@ -19,7 +19,7 @@ import org.eclipse.core.resources.IResource; /** * This interface is used in UI to identify classes allowing user to modify settings externally - * contrary to some subclasses of {@link LanguageSettingsSerializable} managing + * contrary to some subclasses of {@link LanguageSettingsSerializableProvider} managing * their settings themselves and not providing such option to the user. * */ diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsProvider.java index d2eb2cdcbb0..05b1b657ed6 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsProvider.java @@ -28,7 +28,7 @@ import org.eclipse.core.resources.IResource; * To define a provider like that use extension point * {@code org.eclipse.cdt.core.LanguageSettingsProvider} and implement this * interface. CDT provides a few general use implementations such as - * {@link LanguageSettingsBaseProvider} or {@link LanguageSettingsSerializable} + * {@link LanguageSettingsBaseProvider} or {@link LanguageSettingsSerializableProvider} * which could be used out of the box or extended. See also extension point * schema description LanguageSettingsProvider.exsd. * diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java index 09d6bb1c910..8122e0dffdf 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java @@ -59,22 +59,23 @@ public class LanguageSettingsManager { /** * Builds for the provider a nice looking resource tree to present hierarchical view to the user. - * + * * TODO - Note that after using this method for a while for BOP parsers it appears that disadvantages * outweight benefits. In particular, it doesn't result in saving memory as the language settings * (and the lists itself) are not duplicated in memory anyway but optimized with using WeakHashSet * and SafeStringInterner. - * + * * @param provider - language settings provider to build the tree for. * @param cfgDescription - configuration description. * @param languageId - language ID. * @param project - the project which is considered the root of the resource tree. */ - public static void buildResourceTree(LanguageSettingsSerializable provider, ICConfigurationDescription cfgDescription, String languageId, IProject project) { + public static void buildResourceTree(LanguageSettingsSerializableProvider provider, + ICConfigurationDescription cfgDescription, String languageId, IProject project) { LanguageSettingsProvidersSerializer.buildResourceTree(provider, cfgDescription, languageId, project); } - + /** * Returns the list of setting entries of a certain kind (such as include paths) * for the given configuration description, resource and language. This is a @@ -91,7 +92,7 @@ public class LanguageSettingsManager { * * @return the list of setting entries. */ - // FIXME: get rid of callers PathEntryTranslator and DescriptionScannerInfoProvider + // FIXME: get rid of callers PathEntryTranslator and DescriptionScannerInfoProvider public static List getSettingEntriesByKind(ICConfigurationDescription cfgDescription, IResource rc, String languageId, int kind) { return LanguageSettingsProvidersSerializer.getSettingEntriesByKind(cfgDescription, rc, languageId, kind); } @@ -132,7 +133,7 @@ public class LanguageSettingsManager { /** * TODO - helper method for often used chunk of code - * @param provider + * @param provider * @return ILanguageSettingsProvider */ public static ILanguageSettingsProvider getRawProvider(ILanguageSettingsProvider provider) { @@ -141,8 +142,8 @@ public class LanguageSettingsManager { } return provider; } - - + + /** * Set and store in workspace area user defined providers. * @@ -174,7 +175,7 @@ public class LanguageSettingsManager { } if (provider==null) provider = LanguageSettingsManager.getWorkspaceProvider(id); - + return provider; } @@ -182,11 +183,11 @@ public class LanguageSettingsManager { * Find language IDs for the resource represented by resource description. * Under the hood build component is inquired and the language IDs would * commonly come from the input type(s). - * + * * @param rcDescription - resource description * @return list of language IDs for the resource. * Never returns {@code null} but empty list if no languages can be found. - * + * */ public static List getLanguages(ICResourceDescription rcDescription) { ICLanguageSetting[] languageSettings = null; @@ -198,7 +199,7 @@ public class LanguageSettingsManager { } else if (rcDescription instanceof ICFolderDescription) { languageSettings = ((ICFolderDescription)rcDescription).getLanguageSettings(); } - + List languageIds = new ArrayList(); if (languageSettings != null) { for (ICLanguageSetting languageSetting : languageSettings) { @@ -210,7 +211,7 @@ public class LanguageSettingsManager { } } } - + return languageIds; } @@ -218,7 +219,7 @@ public class LanguageSettingsManager { * Find language IDs for the resource in given build configuration. * Under the hood build component is inquired and the language IDs would * commonly come from the input type(s). - * + * * @param resource - the resource to find languages for. * @param cfgDescription * @return list of language IDs for the resource. @@ -252,7 +253,7 @@ public class LanguageSettingsManager { } languageIds = getLanguages(rcDes); } - + return languageIds; } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager_TBD.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager_TBD.java index 39edb52603b..92785fb3645 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager_TBD.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager_TBD.java @@ -36,7 +36,7 @@ public class LanguageSettingsManager_TBD { for (ILanguageSettingsProvider provider: cfgDescription.getLanguageSettingProviders()) { // FIXME // if (!LanguageSettingsManager.isWorkspaceProvider(provider)) { - if (provider instanceof ILanguageSettingsEditableProvider || provider instanceof LanguageSettingsSerializable) { + if (provider instanceof ILanguageSettingsEditableProvider || provider instanceof LanguageSettingsSerializableProvider) { for (String languageId : LanguageSettingsManager.getLanguages(rc, cfgDescription)) { List list = provider.getSettingEntries(cfgDescription, rc, languageId); if (list!=null) { diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableEditable.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableEditable.java index 22465b7b6e4..dd49ebc7a8e 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableEditable.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableEditable.java @@ -14,7 +14,7 @@ package org.eclipse.cdt.core.language.settings.providers; // TODO: move ILanguageSettingsEditableProvider here // TODO this one is unused - remove -final public class LanguageSettingsSerializableEditable extends LanguageSettingsSerializable implements ILanguageSettingsEditableProvider { +final public class LanguageSettingsSerializableEditable extends LanguageSettingsSerializableProvider implements ILanguageSettingsEditableProvider { @Override public LanguageSettingsSerializableEditable clone() throws CloneNotSupportedException { return (LanguageSettingsSerializableEditable) super.clone(); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableProvider.java similarity index 94% rename from core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java rename to core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableProvider.java index 3437ccd30c7..74b42440d6c 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializable.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableProvider.java @@ -31,7 +31,7 @@ import org.w3c.dom.NodeList; * TODO - more JavaDoc, info and hints about class hierarchy * */ -public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { +public class LanguageSettingsSerializableProvider extends LanguageSettingsBaseProvider { public static final String ELEM_PROVIDER = "provider"; //$NON-NLS-1$ private static final String ATTR_ID = "id"; //$NON-NLS-1$ @@ -51,7 +51,7 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { /** * Default constructor. This constructor has to be always followed with setting id and name of the provider. */ - public LanguageSettingsSerializable() { + public LanguageSettingsSerializableProvider() { super(); } @@ -61,7 +61,7 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { * @param id - id of the provider. * @param name - name of the provider. Note that this name may show up in UI. */ - public LanguageSettingsSerializable(String id, String name) { + public LanguageSettingsSerializableProvider(String id, String name) { super(id, name); } @@ -70,7 +70,7 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { * * @param elementProvider */ - public LanguageSettingsSerializable(Element elementProvider) { + public LanguageSettingsSerializableProvider(Element elementProvider) { super(); load(elementProvider); } @@ -315,8 +315,8 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { * See {@link #cloneShallow()}. This method is extracted * to avoid expressing {@link #clone()} via {@link #cloneShallow()}. */ - private LanguageSettingsSerializable cloneShallowInternal() throws CloneNotSupportedException { - LanguageSettingsSerializable clone = (LanguageSettingsSerializable)super.clone(); + private LanguageSettingsSerializableProvider cloneShallowInternal() throws CloneNotSupportedException { + LanguageSettingsSerializableProvider clone = (LanguageSettingsSerializableProvider)super.clone(); if (languageScope!=null) clone.languageScope = new ArrayList(languageScope); @@ -331,13 +331,13 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { * @return shallow copy of the provider. * @throws CloneNotSupportedException in case {@link #clone()} throws the exception. */ - protected LanguageSettingsSerializable cloneShallow() throws CloneNotSupportedException { + protected LanguageSettingsSerializableProvider cloneShallow() throws CloneNotSupportedException { return cloneShallowInternal(); } @Override - protected LanguageSettingsSerializable clone() throws CloneNotSupportedException { - LanguageSettingsSerializable clone = cloneShallowInternal(); + protected LanguageSettingsSerializableProvider clone() throws CloneNotSupportedException { + LanguageSettingsSerializableProvider clone = cloneShallowInternal(); clone.fStorage = fStorage.cloneStorage(); return clone; } @@ -368,7 +368,7 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider { return false; if (getClass() != obj.getClass()) return false; - LanguageSettingsSerializable other = (LanguageSettingsSerializable) obj; + LanguageSettingsSerializableProvider other = (LanguageSettingsSerializableProvider) obj; String id = getId(); String otherId = other.getId(); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java index 9d7eff5361c..c67d632891c 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java @@ -23,7 +23,7 @@ import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsEditableProvider; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsBaseProvider; -import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializableProvider; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.util.CDataUtil; import org.eclipse.cdt.core.settings.model.util.LanguageSettingEntriesSerializer; @@ -255,8 +255,8 @@ public class LanguageSettingsExtensionManager { * @return new instance of language settings provider. */ /*package*/ static ILanguageSettingsProvider getProviderInstance(String className) { - if (className==null || className.equals(LanguageSettingsSerializable.class.getName())) { - return new LanguageSettingsSerializable(); + if (className==null || className.equals(LanguageSettingsSerializableProvider.class.getName())) { + return new LanguageSettingsSerializableProvider(); } ILanguageSettingsProvider provider = createProviderCarcass(className, Platform.getExtensionRegistry()); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java index 644f6f6c457..21d2d9c0934 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java @@ -23,7 +23,7 @@ import org.eclipse.cdt.core.language.settings.providers.ICListenerAgent; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsEditableProvider; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; -import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializableProvider; import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySupport; import org.eclipse.cdt.core.model.ILanguage; import org.eclipse.cdt.core.model.LanguageManager; @@ -337,11 +337,11 @@ public class LanguageSettingsProvidersSerializer { rawGlobalWorkspaceProviders = rawWorkspaceProviders; } - private static List createLanguageLettingsChangeEvents(List serializableProviders) { + private static List createLanguageLettingsChangeEvents(List serializableProviders) { List events = new ArrayList(); List serializableIds = new ArrayList(); - for (LanguageSettingsSerializable provider : serializableProviders) { + for (LanguageSettingsSerializableProvider provider : serializableProviders) { serializableIds.add(provider.getId()); } @@ -376,13 +376,13 @@ projects: LanguageSettingsLogger.logWarning("LanguageSettingsProvidersSerializer.serializeLanguageSettingsWorkspace()"); URI uriStoreWsp = getStoreInWorkspaceArea(STORAGE_WORKSPACE_LANGUAGE_SETTINGS); - List serializableWorkspaceProviders = new ArrayList(); + List serializableWorkspaceProviders = new ArrayList(); for (ILanguageSettingsProvider provider : rawGlobalWorkspaceProviders.values()) { - if (provider instanceof LanguageSettingsSerializable) { + if (provider instanceof LanguageSettingsSerializableProvider) { // serialize all editable providers which are different from corresponding extension // and serialize all serializable ones that are not editable (those are singletons and we don't know whether they changed) if (!(provider instanceof ILanguageSettingsEditableProvider) || !LanguageSettingsExtensionManager.equalsExtensionProvider(provider)) { - serializableWorkspaceProviders.add((LanguageSettingsSerializable)provider); + serializableWorkspaceProviders.add((LanguageSettingsSerializableProvider)provider); } } } @@ -403,7 +403,7 @@ projects: Element rootElement = XmlUtil.appendElement(doc, ELEM_PLUGIN); Element elementExtension = XmlUtil.appendElement(rootElement, ELEM_EXTENSION, new String[] {ATTR_POINT, LanguageSettingsExtensionManager.PROVIDER_EXTENSION_FULL_ID}); - for (LanguageSettingsSerializable provider : serializableWorkspaceProviders) { + for (LanguageSettingsSerializableProvider provider : serializableWorkspaceProviders) { provider.serialize(elementExtension); } @@ -445,7 +445,7 @@ projects: if (doc!=null) { Element rootElement = doc.getDocumentElement(); - NodeList providerNodes = rootElement.getElementsByTagName(LanguageSettingsSerializable.ELEM_PROVIDER); + NodeList providerNodes = rootElement.getElementsByTagName(LanguageSettingsSerializableProvider.ELEM_PROVIDER); List userDefinedProvidersIds = new ArrayList(); for (int i=0;i @@ -712,8 +712,8 @@ projects: String attrClass = XmlUtil.determineAttributeValue(providerNode, LanguageSettingsExtensionManager.ATTR_CLASS); ILanguageSettingsProvider provider = LanguageSettingsExtensionManager.getProviderInstance(attrClass); - if (provider instanceof LanguageSettingsSerializable) - ((LanguageSettingsSerializable)provider).load((Element) providerNode); + if (provider instanceof LanguageSettingsSerializableProvider) + ((LanguageSettingsSerializableProvider)provider).load((Element) providerNode); return provider; } @@ -1087,7 +1087,8 @@ projects: * @param languageId - language ID. * @param folder - container where the tree roots. */ - public static void buildResourceTree(LanguageSettingsSerializable provider, ICConfigurationDescription cfgDescription, String languageId, IContainer folder) { + public static void buildResourceTree(LanguageSettingsSerializableProvider provider, + ICConfigurationDescription cfgDescription, String languageId, IContainer folder) { IResource[] members = null; try { members = folder.members(); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationSpecSettings.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationSpecSettings.java index 8a4a4cf835d..a7c6d604840 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationSpecSettings.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationSpecSettings.java @@ -25,7 +25,7 @@ import java.util.Set; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; -import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializableProvider; import org.eclipse.cdt.core.settings.model.CExternalSetting; import org.eclipse.cdt.core.settings.model.ICBuildSetting; import org.eclipse.cdt.core.settings.model.ICConfigExtensionReference; @@ -1041,8 +1041,8 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ if (LanguageSettingsManager.isWorkspaceProvider(provider)) { provider = LanguageSettingsManager.getRawProvider(provider); } - if (provider instanceof LanguageSettingsSerializable) { - LanguageSettingsStorage store = ((LanguageSettingsSerializable) provider).getStorageInternal(); + if (provider instanceof LanguageSettingsSerializableProvider) { + LanguageSettingsStorage store = ((LanguageSettingsSerializableProvider) provider).getStorageInternal(); if (!store.isEmpty()) { newStateShallow.put(provider.getId(), store); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java index 564cde960ac..33ef8263fb7 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java @@ -46,7 +46,7 @@ import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsEditabl import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsBaseProvider; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; -import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializableProvider; import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySupport; import org.eclipse.cdt.core.model.ILanguage; import org.eclipse.cdt.core.model.LanguageManager; @@ -682,7 +682,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { } private void saveEntries(ILanguageSettingsProvider provider, List entries) { - if (provider instanceof LanguageSettingsSerializable) { + if (provider instanceof LanguageSettingsSerializableProvider) { ICConfigurationDescription cfgDescription = getConfigurationDescription(); IResource rc = getResource(); if (entries!=null && rc!=null) { @@ -697,7 +697,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { entries = null; } } - ((LanguageSettingsSerializable)provider).setSettingEntries(cfgDescription, rc, currentLanguageId, entries); + ((LanguageSettingsSerializableProvider)provider).setSettingEntries(cfgDescription, rc, currentLanguageId, entries); } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java index 750fd028d24..81567fc0185 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java @@ -49,7 +49,7 @@ import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsEditabl import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager_TBD; -import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializableProvider; import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySupport; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICResourceDescription; @@ -403,8 +403,8 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { if (isGlobal != LanguageSettingsManager.isWorkspaceProvider(provider)) { provider = toggleGlobalProvider(provider, isGlobal); } - projectStorageCheckBox.setSelection(provider instanceof LanguageSettingsSerializable - && ((LanguageSettingsSerializable) provider).isStoringEntriesInProjectArea()); + projectStorageCheckBox.setSelection(provider instanceof LanguageSettingsSerializableProvider + && ((LanguageSettingsSerializableProvider) provider).isStoringEntriesInProjectArea()); } @Override @@ -421,8 +421,8 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { public void widgetSelected(SelectionEvent e) { boolean isWithProject = projectStorageCheckBox.getSelection(); ILanguageSettingsProvider provider = getWorkingCopy(getSelectedProvider().getId()); - Assert.isTrue(provider instanceof LanguageSettingsSerializable); - ((LanguageSettingsSerializable)provider).setStoringEntriesInProjectArea(isWithProject); + Assert.isTrue(provider instanceof LanguageSettingsSerializableProvider); + ((LanguageSettingsSerializableProvider)provider).setStoringEntriesInProjectArea(isWithProject); refreshItem(provider); } @@ -607,9 +607,9 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { globalProviderCheckBox.setVisible(provider!=null); projectStorageCheckBox.setEnabled(!isGlobal); - projectStorageCheckBox.setVisible(rawProvider instanceof LanguageSettingsSerializable); - projectStorageCheckBox.setSelection(provider instanceof LanguageSettingsSerializable - && ((LanguageSettingsSerializable)provider).isStoringEntriesInProjectArea()); + projectStorageCheckBox.setVisible(rawProvider instanceof LanguageSettingsSerializableProvider); + projectStorageCheckBox.setSelection(provider instanceof LanguageSettingsSerializableProvider + && ((LanguageSettingsSerializableProvider)provider).isStoringEntriesInProjectArea()); boolean needPreferencesLink=isGlobal && currentOptionsPage!=null; // TODO: message diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProvidersLabelProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProvidersLabelProvider.java index 7eb9160364e..aa8a4db4db9 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProvidersLabelProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProvidersLabelProvider.java @@ -19,7 +19,7 @@ import org.eclipse.swt.graphics.Image; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; -import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializableProvider; import org.eclipse.cdt.ui.CDTSharedImages; @@ -69,8 +69,8 @@ class LanguageSettingsProvidersLabelProvider extends LabelProvider { // boolean isSpecial = provider.getId().equals(LegacySupport.MBS_LANGUAGE_SETTINGS_PROVIDER); ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); - if (rawProvider instanceof LanguageSettingsSerializable) { - if (((LanguageSettingsSerializable)rawProvider).isEmpty()) { + if (rawProvider instanceof LanguageSettingsSerializableProvider) { + if (((LanguageSettingsSerializableProvider)rawProvider).isEmpty()) { overlayKeys[IDecoration.BOTTOM_RIGHT] = CDTSharedImages.IMG_OVR_EMPTY; } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/UserLanguageSettingsProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/UserLanguageSettingsProvider.java index 68fc50e431e..0ade1ec3990 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/UserLanguageSettingsProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/UserLanguageSettingsProvider.java @@ -12,14 +12,14 @@ package org.eclipse.cdt.internal.ui.language.settings.providers; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsEditableProvider; -import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializableProvider; /** * Provider to support user interface for language settings. The important difference with - * {@link LanguageSettingsSerializable} is that it implements {@link ILanguageSettingsEditableProvider}. + * {@link LanguageSettingsSerializableProvider} is that it implements {@link ILanguageSettingsEditableProvider}. * */ -public class UserLanguageSettingsProvider extends LanguageSettingsSerializable implements ILanguageSettingsEditableProvider { +public class UserLanguageSettingsProvider extends LanguageSettingsSerializableProvider implements ILanguageSettingsEditableProvider { @Override public int hashCode() { From ba7591a95b19dbf4bc01e2bb92d48b49e9734df7 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Fri, 18 Nov 2011 17:21:02 -0500 Subject: [PATCH 067/120] @Override annotations + organize imports + unnecessary casts/$NON-NLS + trailing white spaces --- .../GCCBuildCommandParserOptionPage.java | 21 +- .../BuiltinSpecsDetectorOptionPage.java | 10 +- .../ScannerDiscoveryGlobalConsole.java | 17 +- .../internal/core/Configuration.java | 777 +++++++++--------- .../internal/core/MultiConfiguration.java | 71 +- .../MBSLanguageSettingsProvider.java | 14 +- .../LanguageSettingsExtensionManager.java | 23 +- .../LanguageSettingsProvidersSerializer.java | 3 +- .../model/CConfigurationDescription.java | 2 + .../model/CConfigurationDescriptionCache.java | 4 +- .../model/MultiConfigDescription.java | 2 + 11 files changed, 480 insertions(+), 464 deletions(-) diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/preferences/GCCBuildCommandParserOptionPage.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/preferences/GCCBuildCommandParserOptionPage.java index f1d169a92c6..982e2a023e6 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/preferences/GCCBuildCommandParserOptionPage.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/preferences/GCCBuildCommandParserOptionPage.java @@ -41,7 +41,7 @@ public final class GCCBuildCommandParserOptionPage extends AbstractLanguageSetti private boolean fEditable; private Text inputCommand; - + private StatusMessageLine fStatusLine; private Button runOnceRadioButton; private Button runEveryBuildRadioButton; @@ -69,7 +69,7 @@ public final class GCCBuildCommandParserOptionPage extends AbstractLanguageSetti composite.setLayout(layout); composite.setLayoutData(new GridData(GridData.FILL_BOTH)); Dialog.applyDialogFont(composite); - + GridData gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalSpan = 2; composite.setLayoutData(gd); @@ -90,15 +90,16 @@ public final class GCCBuildCommandParserOptionPage extends AbstractLanguageSetti inputCommand = ControlFactory.createTextField(composite, SWT.SINGLE | SWT.BORDER); String customParameter = provider.getCustomParameter(); inputCommand.setText(customParameter!=null ? customParameter : ""); - + GridData gd = new GridData(); gd.horizontalSpan = 1; gd.grabExcessHorizontalSpace = true; gd.horizontalAlignment = SWT.FILL; inputCommand.setLayoutData(gd); inputCommand.setEnabled(fEditable); - + inputCommand.addModifyListener(new ModifyListener() { + @Override public void modifyText(ModifyEvent e) { String text = inputCommand.getText(); AbstractBuildCommandParser provider = getRawProvider(); @@ -155,7 +156,7 @@ public final class GCCBuildCommandParserOptionPage extends AbstractLanguageSetti }); } - + { applyToProjectCheckBox = new Button(composite, SWT.CHECK); applyToProjectCheckBox.setText("Apply discovered settings on project level"); @@ -178,23 +179,23 @@ public final class GCCBuildCommandParserOptionPage extends AbstractLanguageSetti providerTab.refreshItem(selectedProvider); } } - + @Override public void widgetDefaultSelected(SelectionEvent e) { widgetSelected(e); } - + }); - + } - + // // Status line // if (fEditable) { // fStatusLine = new StatusMessageLine(composite, SWT.LEFT, 2); // IStatus status = new Status(IStatus.WARNING, CUIPlugin.PLUGIN_ID, "Note that currently not all options are persisted (FIXME)"); // fStatusLine.setErrorStatus(status); // } - + setControl(composite); } diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/scannerconfig/BuiltinSpecsDetectorOptionPage.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/scannerconfig/BuiltinSpecsDetectorOptionPage.java index f4bca39a44a..581c9b8a5d3 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/scannerconfig/BuiltinSpecsDetectorOptionPage.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/scannerconfig/BuiltinSpecsDetectorOptionPage.java @@ -30,7 +30,6 @@ import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; @@ -42,7 +41,7 @@ public final class BuiltinSpecsDetectorOptionPage extends AbstractLanguageSettin private boolean fEditable; private Text inputCommand; - + private StatusMessageLine fStatusLine; private Button allocateConsoleCheckBox; @@ -66,7 +65,7 @@ public final class BuiltinSpecsDetectorOptionPage extends AbstractLanguageSettin composite.setLayout(layout); composite.setLayoutData(new GridData(GridData.FILL_BOTH)); Dialog.applyDialogFont(composite); - + GridData gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalSpan = 2; composite.setLayoutData(gd); @@ -89,6 +88,7 @@ public final class BuiltinSpecsDetectorOptionPage extends AbstractLanguageSettin inputCommand.setText(customParameter!=null ? customParameter : ""); inputCommand.setEnabled(fEditable); inputCommand.addModifyListener(new ModifyListener() { + @Override public void modifyText(ModifyEvent e) { String text = inputCommand.getText(); AbstractBuiltinSpecsDetector provider = getRawProvider(); @@ -225,14 +225,14 @@ public final class BuiltinSpecsDetectorOptionPage extends AbstractLanguageSettin }); } - + // // Status line // if (fEditable) { // fStatusLine = new StatusMessageLine(composite, SWT.LEFT, 2); // IStatus status = new Status(IStatus.WARNING, CUIPlugin.PLUGIN_ID, "Note that currently not all options are persisted (FIXME)"); // fStatusLine.setErrorStatus(status); // } - + setControl(composite); } diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/scannerconfig/ScannerDiscoveryGlobalConsole.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/scannerconfig/ScannerDiscoveryGlobalConsole.java index 9a12186664c..4ccf5f183b8 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/scannerconfig/ScannerDiscoveryGlobalConsole.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/scannerconfig/ScannerDiscoveryGlobalConsole.java @@ -30,7 +30,7 @@ import org.eclipse.ui.console.MessageConsoleStream; public class ScannerDiscoveryGlobalConsole implements ICConsole { private MessageConsole console; private ConsoleOutputStreamAdapter stream; - + private class ConsoleOutputStreamAdapter extends ConsoleOutputStream { private MessageConsoleStream fConsoleStream; public ConsoleOutputStreamAdapter(MessageConsoleStream stream) { @@ -44,37 +44,42 @@ public class ScannerDiscoveryGlobalConsole implements ICConsole { public synchronized void write(byte[] b, int off, int len) throws IOException { fConsoleStream.write(b, off, len); } - + @Override public void flush() throws IOException { fConsoleStream.flush(); } - + @Override public void close() throws IOException { fConsoleStream.close(); } } + @Override public void start(IProject project) { Assert.isTrue(project == null); } + @Override public ConsoleOutputStream getOutputStream() throws CoreException { return stream; } + @Override public ConsoleOutputStream getInfoStream() throws CoreException { return stream; } + @Override public ConsoleOutputStream getErrorStream() throws CoreException { return stream; } + @Override public void init(String consoleId, String name, URL defaultIconUrl) { console = null; - + IConsoleManager consoleManager = ConsolePlugin.getDefault().getConsoleManager(); IConsole[] allConsoles = consoleManager.getConsoles(); for (IConsole con : allConsoles) { @@ -90,12 +95,12 @@ public class ScannerDiscoveryGlobalConsole implements ICConsole { if (iconUrl==null) { iconUrl = defaultIconUrl; } - + console = new MessageConsole(name, CDTSharedImages.getImageDescriptor(iconUrl.toString())); console.activate(); consoleManager.addConsoles(new IConsole[]{ console }); } - + stream = new ConsoleOutputStreamAdapter(console.newMessageStream()); } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java index d5ce4df6687..d0355fa95ad 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java @@ -92,10 +92,10 @@ import org.eclipse.osgi.util.NLS; import org.osgi.framework.Version; public class Configuration extends BuildObject implements IConfiguration, IBuildPropertiesRestriction, IBuildPropertyChangeListener, IRealBuildObjectAssociation { - + 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$ - + // Parent and children private String parentId; private IConfiguration parent; @@ -106,10 +106,10 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild private String artifactExtension; private String errorParserIds; private String defaultLanguageSettingsProvidersIds; - private String prebuildStep; - private String postbuildStep; - private String preannouncebuildStep; - private String postannouncebuildStep; + private String prebuildStep; + private String postbuildStep; + private String preannouncebuildStep; + private String postannouncebuildStep; private String description; private ICSourceEntry[] sourceEntries; private BuildObjectProperties buildProperties; @@ -136,10 +136,10 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild private ICfgScannerConfigBuilderInfo2Set cfgScannerInfo; private boolean isPreferenceConfig; private List excludeList; - + //property name for holding the rebuild state private static final String REBUILD_STATE = "rebuildState"; //$NON-NLS-1$ - + //The resource delta passed to the builder is not always up-to-date //for the given configuration because between two builds of the same configuration //any number of other configuration builds may occur @@ -147,7 +147,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild //with the resource tree between the two configuration builds // //The trivial approach implemented currently is to hold - //the general information of whether some resources were + //the general information of whether some resources were //removed,changed,etc. and detect whether the rebuild is needed //based upon this information // @@ -166,7 +166,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild //builder enabling/disabling as the Builder substitution functionality // // private static final String INTERNAL_BUILDER = "internalBuilder"; //$NON-NLS-1$ - //preference key that holds the Internal Builder enable state + //preference key that holds the Internal Builder enable state // private static final String INTERNAL_BUILDER_ENABLED = "enabled"; //$NON-NLS-1$ //preference key that holds the internal builder mode // private static final String INTERNAL_BUILDER_IGNORE_ERR = "ignoreErr"; //$NON-NLS-1$ @@ -192,35 +192,35 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild /** * Create an extension configuration from the project manifest file element. - * - * @param projectType The ProjectType the configuration will be added to. + * + * @param projectType The ProjectType the configuration will be added to. * @param element The element from the manifest that contains the configuration information. */ public Configuration(ProjectType projectType, IManagedConfigElement element, String managedBuildRevision) { this.projectType = projectType; isExtensionConfig = true; - + // setup for resolving resolved = false; - + setManagedBuildRevision(managedBuildRevision); - + // Initialize from the XML attributes loadFromManifest(element); - + // Hook me up to the Managed Build Manager ManagedBuildManager.addExtensionConfiguration(this); - + // Hook me up to the ProjectType if (projectType != null) { projectType.addConfiguration(this); } - + IManagedConfigElement enablements[] = element.getChildren(OptionEnablementExpression.NAME); if(enablements.length > 0) booleanExpressionCalculator = new BooleanExpressionApplicabilityCalculator(enablements); - + // Load the children IManagedConfigElement[] configElements = element.getChildren(); List srcPathList = new ArrayList(); @@ -248,23 +248,23 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild sourceEntries = seList.toArray(new ICSourceEntry[seList.size()]); } } - + sourceEntries = createSourceEntries(sourceEntries, srcPathList, excludeList); - + excludeList = null; - + if(rootFolderInfo == null) createRootFolderInfo(); - + String props = SafeStringInterner.safeIntern(element.getAttribute(BUILD_PROPERTIES)); if(props != null) buildProperties = new BuildObjectProperties(props, this, this); - + String artType = SafeStringInterner.safeIntern(element.getAttribute(BUILD_ARTEFACT_TYPE)); if(artType != null){ if(buildProperties == null) buildProperties = new BuildObjectProperties(this, this); - + try { buildProperties.setProperty(ManagedBuildManager.BUILD_ARTEFACT_TYPE_PROPERTY_ID, artType, true); } catch (CoreException e) { @@ -289,7 +289,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild setDirty(false); } - + private static ICSourceEntry[] createSourceEntries(ICSourceEntry[] curEntries, List pathList, List excludeList){ for(int i = 0; i < excludeList.size(); i++){ IPath path = excludeList.get(i); @@ -298,12 +298,12 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild } if(pathList.size() == 0) pathList.add(Path.EMPTY); - + if(pathList.size() == 1 && pathList.get(0).equals(Path.EMPTY) && excludeList.size() == 0) return curEntries; - + int pathSize = pathList.size(); Map map = new LinkedHashMap(); @@ -312,19 +312,19 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild ICSourceEntry entry = map.get(path); if(entry == null) entry = new CSourceEntry(path, null, ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED); - + entry = CDataUtil.addExcludePaths(entry, excludeList, true); if(entry != null) map.put(path, entry); } - + return map.values().toArray(new ICSourceEntry[map.size()]); } /** * Create a new extension configuration based on one already defined. - * - * @param projectType The ProjectType the configuration will be added to. + * + * @param projectType The ProjectType the configuration will be added to. * @param parentConfig The IConfiguration that is the parent configuration of this configuration * @param id A unique ID for the new configuration. */ @@ -332,25 +332,25 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild setId(id); this.projectType = projectType; isExtensionConfig = true; - + // setup for resolving resolved = false; if (parentConfig != null) { name = parentConfig.getName(); - // If this contructor is called to clone an existing - // configuration, the parent of the parent should be stored. + // If this contructor is called to clone an existing + // configuration, the parent of the parent should be stored. // As of 2.1, there is still one single level of inheritence to // worry about parent = parentConfig.getParent() == null ? parentConfig : parentConfig.getParent(); } - + // Hook me up to the Managed Build Manager ManagedBuildManager.addExtensionConfiguration(this); - + // Hook me up to the ProjectType if (projectType != null) { - projectType.addConfiguration(this); + projectType.addConfiguration(this); // set managedBuildRevision setManagedBuildRevision(projectType.getManagedBuildRevision()); } @@ -358,8 +358,8 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild /** * Create a new extension configuration and fill in the attributes and childen later. - * - * @param projectType The ProjectType the configuration will be added to. + * + * @param projectType The ProjectType the configuration will be added to. * @param parentConfig The IConfiguration that is the parent configuration of this configuration * @param id A unique ID for the new configuration. * @param name A name for the new configuration. @@ -370,10 +370,10 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild this.projectType = projectType; parent = parentConfig; isExtensionConfig = true; - + // Hook me up to the Managed Build Manager ManagedBuildManager.addExtensionConfiguration(this); - + // Hook me up to the ProjectType if (projectType != null) { projectType.addConfiguration(this); @@ -382,21 +382,21 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild } /** - * Create a Configuration based on the specification stored in the + * Create a Configuration based on the specification stored in the * project file (.cdtbuild). - * - * @param managedProject The ManagedProject the configuration will be added to. + * + * @param managedProject The ManagedProject the configuration will be added to. * @param element The XML element that contains the configuration settings. - * + * */ public Configuration(ManagedProject managedProject, ICStorageElement element, String managedBuildRevision, boolean isPreference) { this.managedProject = managedProject; this.isPreferenceConfig = isPreference; isExtensionConfig = false; fCfgData = new BuildConfigurationData(this); - + setManagedBuildRevision(managedBuildRevision); - + // Initialize from the XML attributes loadFromProject(element); @@ -428,18 +428,18 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild sourceEntries = seList.toArray(new ICSourceEntry[seList.size()]); } } - + resolveProjectReferences(true); - + sourceEntries = createSourceEntries(sourceEntries, srcPathList, excludeList); excludeList = null; - + PropertyManager mngr = PropertyManager.getInstance(); String rebuild = mngr.getProperty(this, REBUILD_STATE); if(rebuild == null || Boolean.valueOf(rebuild).booleanValue()) rebuildNeeded = true; - + String rcChangeState = mngr.getProperty(this, RC_CHANGE_STATE); if(rcChangeState == null) resourceChangeState = ~0; @@ -450,11 +450,11 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild resourceChangeState = ~0; } } - + setDirty(false); - + // Preferences prefs = getPreferences(INTERNAL_BUILDER); -// +// // internalBuilderEnabled = prefs != null ? // prefs.getBoolean(INTERNAL_BUILDER_ENABLED, false) : false; // internalBuilderIgnoreErr = prefs != null ? @@ -464,7 +464,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild public Configuration(ManagedProject managedProject, ToolChain tCh, String id, String name) { setId(id); setName(name); - + // this.description = cloneConfig.getDescription(); this.managedProject = managedProject; isExtensionConfig = false; @@ -480,38 +480,38 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild fCfgData = new BuildConfigurationData(this); if(baseCfg.buildProperties != null) this.buildProperties = new BuildObjectProperties(baseCfg.buildProperties, this, this); - + // set managedBuildRevision setManagedBuildRevision(baseCfg.getManagedBuildRevision()); - + // if(!baseCfg.isExtensionConfig) // cloneChildren = true; - // If this contructor is called to clone an existing - // configuration, the parent of the cloning config should be stored. + // If this contructor is called to clone an existing + // configuration, the parent of the cloning config should be stored. parent = baseCfg.isExtensionConfig || baseCfg.getParent() == null ? baseCfg : baseCfg.getParent(); - + // Copy the remaining attributes projectType = baseCfg.projectType; - + artifactName = baseCfg.artifactName; - + cleanCommand = baseCfg.cleanCommand; - + artifactExtension = baseCfg.artifactExtension; - + errorParserIds = baseCfg.errorParserIds; - + prebuildStep = baseCfg.prebuildStep; - + postbuildStep = baseCfg.postbuildStep; - + preannouncebuildStep = baseCfg.preannouncebuildStep; - + postannouncebuildStep = baseCfg.postannouncebuildStep; - + if(baseCfg.sourceEntries != null) sourceEntries = baseCfg.sourceEntries.clone(); - + // enableInternalBuilder(baseCfg.isInternalBuilderEnabled()); // setInternalBuilderIgnoreErr(baseCfg.getInternalBuilderIgnoreErr()); // setInternalBuilderParallel(baseCfg.getInternalBuilderParallel()); @@ -519,23 +519,23 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild // setParallelNumber(baseCfg.getParallelNumber()); // internalBuilderEnabled = cloneConfig.internalBuilderEnabled; // internalBuilderIgnoreErr = cloneConfig.internalBuilderIgnoreErr; - + // Clone the configuration's children // Tool Chain - + String tcId = ManagedBuildManager.calculateChildId(tCh.getId(), null); - + IToolChain newChain = createToolChain(tCh, tcId, tCh.getId(), false); - + // For each option/option category child of the tool-chain that is // the child of the selected configuration element, create an option/ // option category child of the cloned configuration's tool-chain element // that specifies the original tool element as its superClass. newChain.createOptions(tCh); - // For each tool element child of the tool-chain that is the child of - // the selected configuration element, create a tool element child of - // the cloned configuration's tool-chain element that specifies the + // For each tool element child of the tool-chain that is the child of + // the selected configuration element, create a tool element child of + // the cloned configuration's tool-chain element that specifies the // original tool element as its superClass. String subId; ITool[] tools = tCh.getTools(); @@ -544,11 +544,11 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild subId = ManagedBuildManager.calculateChildId(toolChild.getId(),null); newChain.createTool(toolChild, subId, toolChild.getName(), false); } - + ITargetPlatform tpBase = tCh.getTargetPlatform(); ITargetPlatform extTp = tpBase; for(;extTp != null && !extTp.isExtensionElement();extTp = extTp.getSuperClass()) {} - + TargetPlatform tp; if(extTp != null){ int nnn = ManagedBuildManager.getRandomNumber(); @@ -563,36 +563,36 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild ((ToolChain)newChain).setTargetPlatform(tp); - + // if(cloneChildren){ //copy expand build macros setting // BuildMacroProvider macroProvider = (BuildMacroProvider)ManagedBuildManager.getBuildMacroProvider(); // macroProvider.expandMacrosInBuildfile(this, // macroProvider.areMacrosExpandedInBuildfile(baseCfg)); - + //copy user-defined build macros /* UserDefinedMacroSupplier userMacros = BuildMacroProvider.fUserDefinedMacroSupplier; userMacros.setMacros( userMacros.getMacros(BuildMacroProvider.CONTEXT_CONFIGURATION,cloneConfig), BuildMacroProvider.CONTEXT_CONFIGURATION, this); - */ + */ //copy user-defined environment // UserDefinedEnvironmentSupplier userEnv = EnvironmentVariableProvider.fUserSupplier; // userEnv.setVariables( // userEnv.getVariables(cloneConfig), this); - + // } - + // Hook me up managedProject.addConfiguration(this); - + IBuilder builder = getEditableBuilder(); try { builder.setManagedBuildOn(false); } catch (CoreException e) { } - + propertiesChanged(); } setDirty(true); @@ -602,14 +602,14 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild public Configuration(ManagedProject managedProject, Configuration cloneConfig, String id, boolean cloneChildren, boolean temporary) { this(managedProject, cloneConfig, id, cloneChildren, temporary, false); } - + /** * Create a new project, non-extension, configuration based on one already defined. - * - * @param managedProject The ManagedProject the configuration will be added to. + * + * @param managedProject The ManagedProject the configuration will be added to. * @param cloneConfig The IConfiguration to copy the settings from. * @param id A unique ID for the new configuration. - * @param cloneChildren If true, the configuration's tools are cloned + * @param cloneChildren If true, the configuration's tools are cloned */ public Configuration(ManagedProject managedProject, Configuration cloneConfig, String id, boolean cloneChildren, boolean temporary, boolean isPreferenceConfig) { setId(id); @@ -618,10 +618,10 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild this.managedProject = managedProject; isExtensionConfig = false; this.isTemporary = temporary; - + copySettingsFrom(cloneConfig, cloneChildren); } - + private void copySettingsFrom(Configuration cloneConfig, boolean cloneChildren){ fCfgData = new BuildConfigurationData(this); if(cloneConfig.buildProperties != null) @@ -634,11 +634,11 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild if(!cloneConfig.isExtensionConfig) cloneChildren = true; - // If this contructor is called to clone an existing - // configuration, the parent of the cloning config should be stored. + // If this contructor is called to clone an existing + // configuration, the parent of the cloning config should be stored. parent = cloneConfig.isExtensionConfig || cloneConfig.getParent() == null ? cloneConfig : cloneConfig.getParent(); parentId = parent.getId(); - + // Copy the remaining attributes projectType = cloneConfig.projectType; if (cloneConfig.artifactName != null) { @@ -664,10 +664,10 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild } if (cloneConfig.postannouncebuildStep != null) { postannouncebuildStep = new String(cloneConfig.postannouncebuildStep); - } + } if(cloneConfig.sourceEntries != null) sourceEntries = cloneConfig.sourceEntries.clone(); - + // enableInternalBuilder(cloneConfig.isInternalBuilderEnabled()); // setInternalBuilderIgnoreErr(cloneConfig.getInternalBuilderIgnoreErr()); // setInternalBuilderParallel(cloneConfig.getInternalBuilderParallel()); @@ -675,7 +675,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild // setParallelNumber(cloneConfig.getParallelNumber()); // internalBuilderEnabled = cloneConfig.internalBuilderEnabled; // internalBuilderIgnoreErr = cloneConfig.internalBuilderIgnoreErr; - + // Clone the configuration's children // Tool Chain boolean copyIds = cloneConfig.getId().equals(id); @@ -694,12 +694,12 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild subId = copyIds ? fileInfo.getId() : ManagedBuildManager.calculateChildId(getId(), fileInfo.getPath().toString()); ResourceConfiguration newResConfig = new ResourceConfiguration(this, fileInfo, subId, toolIdMap, cloneChildren); addResourceConfiguration(newResConfig); - + } } - + resolveProjectReferences(false); - + if(cloneChildren){ //copy expand build macros setting BuildMacroProvider macroProvider = (BuildMacroProvider)ManagedBuildManager.getBuildMacroProvider(); @@ -712,23 +712,23 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild userMacros.getMacros(BuildMacroProvider.CONTEXT_CONFIGURATION,cloneConfig), BuildMacroProvider.CONTEXT_CONFIGURATION, this); -*/ +*/ //copy user-defined environment // UserDefinedEnvironmentSupplier userEnv = EnvironmentVariableProvider.fUserSupplier; // userEnv.setVariables( // userEnv.getVariables(cloneConfig), this); } - + // Hook me up if(managedProject != null){ managedProject.addConfiguration(this); } - + if(cloneConfig.isExtensionConfig){ propertiesChanged(); } - + if(copyIds){ rebuildNeeded = cloneConfig.rebuildNeeded; resourceChangeState = cloneConfig.resourceChangeState; @@ -741,7 +741,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild } } - + public void applyToManagedProject(ManagedProject mProj){ managedProject = mProj; isPreferenceConfig = false; @@ -752,28 +752,28 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild /* * E L E M E N T A T T R I B U T E R E A D E R S A N D W R I T E R S */ - + /** - * Initialize the configuration information from an element in the + * Initialize the configuration information from an element in the * manifest file or provided by a dynamicElementProvider - * - * @param element An obejct implementing IManagedConfigElement + * + * @param element An obejct implementing IManagedConfigElement */ protected void loadFromManifest(IManagedConfigElement element) { ManagedBuildManager.putConfigElement(this, element); - + // id setId(SafeStringInterner.safeIntern(element.getAttribute(IConfiguration.ID))); // name name = SafeStringInterner.safeIntern(element.getAttribute(IConfiguration.NAME)); - + // description description = SafeStringInterner.safeIntern(element.getAttribute(IConfiguration.DESCRIPTION)); - + // parent parentId = SafeStringInterner.safeIntern(element.getAttribute(IConfiguration.PARENT)); - + // if (parentID != null) { // // Lookup the parent configuration by ID // parent = ManagedBuildManager.getExtensionConfiguration(parentID); @@ -781,7 +781,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild // Get the name of the build artifact associated with configuration artifactName = SafeStringInterner.safeIntern(element.getAttribute(ARTIFACT_NAME)); - + // Get the semicolon separated list of IDs of the error parsers errorParserIds = SafeStringInterner.safeIntern(element.getAttribute(ERROR_PARSERS)); @@ -790,31 +790,31 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild // Get the artifact extension artifactExtension = SafeStringInterner.safeIntern(element.getAttribute(EXTENSION)); - + // Get the clean command cleanCommand = SafeStringInterner.safeIntern(element.getAttribute(CLEAN_COMMAND)); - - // Get the pre-build and post-build commands - prebuildStep = SafeStringInterner.safeIntern(element.getAttribute(PREBUILD_STEP)); - postbuildStep = SafeStringInterner.safeIntern(element.getAttribute(POSTBUILD_STEP)); - - // Get the pre-build and post-build announcements - preannouncebuildStep = SafeStringInterner.safeIntern(element.getAttribute(PREANNOUNCEBUILD_STEP)); + + // Get the pre-build and post-build commands + prebuildStep = SafeStringInterner.safeIntern(element.getAttribute(PREBUILD_STEP)); + postbuildStep = SafeStringInterner.safeIntern(element.getAttribute(POSTBUILD_STEP)); + + // Get the pre-build and post-build announcements + preannouncebuildStep = SafeStringInterner.safeIntern(element.getAttribute(PREANNOUNCEBUILD_STEP)); postannouncebuildStep = SafeStringInterner.safeIntern(element.getAttribute(POSTANNOUNCEBUILD_STEP)); - + String tmp = element.getAttribute(IS_SYSTEM); if(tmp != null) isTest = Boolean.valueOf(tmp).booleanValue(); } - + /** - * Initialize the configuration information from the XML element + * Initialize the configuration information from the XML element * specified in the argument - * - * @param element An XML element containing the configuration information + * + * @param element An XML element containing the configuration information */ protected void loadFromProject(ICStorageElement element) { - + // id // note: IDs are unique so no benefit to intern them setId(element.getAttribute(IConfiguration.ID)); @@ -822,20 +822,20 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild // name if (element.getAttribute(IConfiguration.NAME) != null) setName(SafeStringInterner.safeIntern(element.getAttribute(IConfiguration.NAME))); - + // description if (element.getAttribute(IConfiguration.DESCRIPTION) != null) description = SafeStringInterner.safeIntern(element.getAttribute(IConfiguration.DESCRIPTION)); - + String props = element.getAttribute(BUILD_PROPERTIES); if(props != null) buildProperties = new BuildObjectProperties(props, this, this); - + String artType = SafeStringInterner.safeIntern(element.getAttribute(BUILD_ARTEFACT_TYPE)); if(artType != null){ if(buildProperties == null) buildProperties = new BuildObjectProperties(this, this); - + try { buildProperties.setProperty(ManagedBuildManager.BUILD_ARTEFACT_TYPE_PROPERTY_ID, artType, true); } catch (CoreException e) { @@ -858,12 +858,12 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild } } - // Get the name of the build artifact associated with target (usually + // Get the name of the build artifact associated with target (usually // in the plugin specification). if (element.getAttribute(ARTIFACT_NAME) != null) { artifactName = SafeStringInterner.safeIntern(element.getAttribute(ARTIFACT_NAME)); } - + // Get the semicolon separated list of IDs of the error parsers if (element.getAttribute(ERROR_PARSERS) != null) { errorParserIds = SafeStringInterner.safeIntern(element.getAttribute(ERROR_PARSERS)); @@ -873,7 +873,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild if (element.getAttribute(EXTENSION) != null) { artifactExtension = SafeStringInterner.safeIntern(element.getAttribute(EXTENSION)); } - + // Get the clean command if (element.getAttribute(CLEAN_COMMAND) != null) { cleanCommand = SafeStringInterner.safeIntern(element.getAttribute(CLEAN_COMMAND)); @@ -903,13 +903,13 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild */ public void serialize(ICStorageElement element) { element.setAttribute(IConfiguration.ID, id); - + if (name != null) element.setAttribute(IConfiguration.NAME, name); - + if (description != null) element.setAttribute(IConfiguration.DESCRIPTION, description); - + if(buildProperties != null){ element.setAttribute(BUILD_PROPERTIES, buildProperties.toString()); @@ -919,13 +919,13 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild element.setAttribute(BUILD_ARTEFACT_TYPE, val.getId()); } } - + if (parent != null) element.setAttribute(IConfiguration.PARENT, parent.getId()); - + if (artifactName != null) element.setAttribute(ARTIFACT_NAME, artifactName); - + if (errorParserIds != null) element.setAttribute(ERROR_PARSERS, errorParserIds); @@ -952,13 +952,13 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild for(int i = 0; i < infos.length; i++){ String elementName = infos[i].getKind() == ICSettingBase.SETTING_FILE ? IFileInfo.FILE_INFO_ELEMENT_NAME : IFolderInfo.FOLDER_INFO_ELEMENT_NAME; - + ICStorageElement resElement = element.createChild(elementName); ((ResourceInfo)infos[i]).serialize(resElement); } PropertyManager.getInstance().serialize(this); - + if(sourceEntries != null && sourceEntries.length > 0){ ICStorageElement el = element.createChild(SOURCE_ENTRIES); LanguageSettingEntriesSerializer.serializeEntries(sourceEntries, el); @@ -970,7 +970,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild /* * P A R E N T A N D C H I L D H A N D L I N G */ - + /* (non-Javadoc) * @see org.eclipse.cdt.core.build.managed.IConfiguration#getParent() */ @@ -990,7 +990,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild return null; // Extension configurations don't have an "owner" } } - + /* (non-Javadoc) * @see org.eclipse.cdt.core.build.managed.IConfiguration#getProjectType() */ @@ -998,7 +998,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild public IProjectType getProjectType() { return projectType; } - + /* (non-Javadoc) * @see org.eclipse.cdt.core.build.managed.IConfiguration#getManagedProject() */ @@ -1006,7 +1006,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild public IManagedProject getManagedProject() { return managedProject; } - + /* (non-Javadoc) * @see org.eclipse.cdt.core.build.managed.IConfiguration#getToolChain(IToolChain, String, String, boolean) */ @@ -1015,25 +1015,25 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild if(rootFolderInfo == null){ createRootFolderInfo(); } - + return rootFolderInfo.createToolChain(superClass, Id, name, isExtensionElement); } - + private IFolderInfo createRootFolderInfo(){ String id = ManagedBuildManager.calculateChildId(this.id, null); String name = "/"; //$NON-NLS-1$ - + rootFolderInfo = new FolderInfo(this, new Path(name), id, name, isExtensionConfig); addResourceConfiguration(rootFolderInfo); return rootFolderInfo; } -/* +/* public IFolderInfo createFolderInfo(IPath path, IToolChain superClass, String Id, String name){ - + } public IFolderInfo createFolderInfo(IPath path, IFolderInfo baseFolderInfo, String Id, String name){ - + } */ /* (non-Javadoc) @@ -1043,7 +1043,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild public IToolChain getToolChain() { return rootFolderInfo.getToolChain(); } - + /* (non-Javadoc) * @see org.eclipse.cdt.core.build.managed.IConfiguration#getResourceConfigurations() */ @@ -1085,7 +1085,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild } /* (non-Javadoc) - * @see org.eclipse.cdt.managedbuilder.core.IConfiguration#getToolsBySuperClassId(java.lang.String) + * @see org.eclipse.cdt.managedbuilder.core.IConfiguration#getToolsBySuperClassId(java.lang.String) */ @Override public ITool[] getToolsBySuperClassId(String id) { @@ -1099,7 +1099,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild public ITool getTargetTool() { String[] targetToolIds = rootFolderInfo.getToolChain().getTargetToolList(); if (targetToolIds == null || targetToolIds.length == 0) return null; - + // For each target tool id, in list order, // look for a tool with this ID, or a tool with a superclass with this id. // Stop when we find a match @@ -1112,7 +1112,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild do { if (targetToolId.equals(tool.getId())) { return targetTool; - } + } tool = tool.getSuperClass(); } while (tool != null); } @@ -1161,10 +1161,10 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild public IOption setOption(IHoldsOptions holder, IOption option, String[] value) throws BuildException { return getRootFolderInfo().setOption(holder, option, value); } - + /* (non-Javadoc) * Adds the Resource Configuration to the Resource Configuration list and map - * + * * @param resConfig */ void addResourceConfiguration(IResourceInfo resConfig) { @@ -1177,7 +1177,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild @Override public void removeResourceConfiguration(IResourceInfo resConfig) { - ManagedBuildManager.performValueHandlerEvent(resConfig, + ManagedBuildManager.performValueHandlerEvent(resConfig, IManagedOptionValueHandler.EVENT_CLOSE); ITool tools[] = resConfig.getTools(); rcInfos.removeResourceInfo(resConfig.getPath()); @@ -1212,9 +1212,9 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild // Ask my parent first if (parent != null) { return parent.getArtifactExtension(); - } - return null; - } + } + return null; + } return artifactExtension; } @@ -1257,14 +1257,14 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild IToolChain tc = getToolChain(); IBuilder builder = tc.getBuilder(); if (builder != null) { - return builder.getCommand(); + return builder.getCommand(); } return new String("make"); //$NON-NLS-1$ } /* * (non-Javadoc) - * + * * @see org.eclipse.cdt.core.build.managed.IConfiguration#getPrebuildStep() */ @Override @@ -1284,7 +1284,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild /* * (non-Javadoc) - * + * * @see org.eclipse.cdt.core.build.managed.IConfiguration#getPostbuildStep() */ @Override @@ -1304,7 +1304,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild /* * (non-Javadoc) - * + * * @see org.eclipse.cdt.core.build.managed.IConfiguration#getPreannouncebuildStep() */ @Override @@ -1324,7 +1324,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild /* * (non-Javadoc) - * + * * @see org.eclipse.cdt.core.build.managed.IConfiguration#getPostannouncebuildStep() */ @Override @@ -1344,7 +1344,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild /* * (non-Javadoc) - * + * * @see org.eclipse.cdt.core.build.managed.IConfiguration#getCleanCommand() */ @Override @@ -1366,7 +1366,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild return cleanCommand; } } - + /* (non-Javadoc) * @see org.eclipse.cdt.core.build.managed.IConfiguration#getDescription() */ @@ -1387,14 +1387,14 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild /* * (non-Javadoc) - * + * * @see org.eclipse.cdt.managedbuilder.core.IConfiguration#getErrorParserIds() */ @Override public String getErrorParserIds() { if (errorParserIds != null) { return errorParserIds; - } + } // If I have a parent, ask it String errorParsers = null; if (parent != null) { @@ -1413,13 +1413,13 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild public String getErrorParserIdsAttribute() { if (errorParserIds != null) { return errorParserIds; - } + } // If I have a parent, ask it String errorParsers = null; if (parent != null) { errorParsers = ((Configuration)parent).getErrorParserIdsAttribute(); } - + return errorParsers; } @@ -1449,7 +1449,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild } } } - + if(includeChildren){ IResourceInfo[] rcInfos = getResourceInfos(); for(int i = 0; i < rcInfos.length; i++){ @@ -1459,7 +1459,8 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild } return set; } - + + @Override public String getDefaultLanguageSettingsProvidersIds() { return defaultLanguageSettingsProvidersIds; } @@ -1505,7 +1506,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild if (entries.contains(lib)) { entries.remove(lib); des.removeExternalSetting(setting); - des.createExternalSetting(setting.getCompatibleLanguageIds(), setting.getCompatibleContentTypeIds(), + des.createExternalSetting(setting.getCompatibleLanguageIds(), setting.getCompatibleContentTypeIds(), setting.getCompatibleExtensions(), entries.toArray(new ICSettingEntry[entries.size()])); } } @@ -1552,17 +1553,17 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild isDirty = true; } } - + /* (non-Javadoc) * @see org.eclipse.cdt.core.build.managed.IConfiguration#setDescription(java.lang.String) */ @Override public void setDescription(String description) { - if (description == null && this.description == null) return; - if (this.description == null || description == null || !description.equals(this.description)) { - this.description = description; - isDirty = true; - } + if (description == null && this.description == null) return; + if (this.description == null || description == null || !description.equals(this.description)) { + this.description = description; + isDirty = true; + } } /* (non-Javadoc) @@ -1610,60 +1611,60 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild // rebuildNeeded = true; } } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.build.managed.IConfiguration#setPrebuildStep(java.lang.String) - */ + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.build.managed.IConfiguration#setPrebuildStep(java.lang.String) + */ @Override - public void setPrebuildStep(String step) { - if (step == null && prebuildStep == null) return; - if (prebuildStep == null || step == null || !prebuildStep.equals(step)) { - prebuildStep = step; + public void setPrebuildStep(String step) { + if (step == null && prebuildStep == null) return; + if (prebuildStep == null || step == null || !prebuildStep.equals(step)) { + prebuildStep = step; // rebuildNeeded = true; - isDirty = true; - } - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.build.managed.IConfiguration#setPostbuildStep(java.lang.String) - */ + isDirty = true; + } + } + + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.build.managed.IConfiguration#setPostbuildStep(java.lang.String) + */ @Override - public void setPostbuildStep(String step) { - if (step == null && postbuildStep == null) return; - if (postbuildStep == null || step == null || !postbuildStep.equals(step)) { - postbuildStep = step; + public void setPostbuildStep(String step) { + if (step == null && postbuildStep == null) return; + if (postbuildStep == null || step == null || !postbuildStep.equals(step)) { + postbuildStep = step; // rebuildNeeded = true; - isDirty = true; - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.build.managed.IConfiguration#setPreannouncebuildStep(java.lang.String) - */ + isDirty = true; + } + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.build.managed.IConfiguration#setPreannouncebuildStep(java.lang.String) + */ @Override - public void setPreannouncebuildStep(String announceStep) { - if (announceStep == null && preannouncebuildStep == null) return; + public void setPreannouncebuildStep(String announceStep) { + if (announceStep == null && preannouncebuildStep == null) return; if (preannouncebuildStep == null || announceStep == null || !preannouncebuildStep.equals(announceStep)) { - preannouncebuildStep = announceStep; + preannouncebuildStep = announceStep; // rebuildNeeded = true; - isDirty = true; - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.build.managed.IConfiguration#setPostannouncebuildStep(java.lang.String) - */ + isDirty = true; + } + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.build.managed.IConfiguration#setPostannouncebuildStep(java.lang.String) + */ @Override - public void setPostannouncebuildStep(String announceStep) { - if (announceStep == null && postannouncebuildStep == null) return; + public void setPostannouncebuildStep(String announceStep) { + if (announceStep == null && postannouncebuildStep == null) return; if (postannouncebuildStep == null || announceStep == null || !postannouncebuildStep.equals(announceStep)) { - postannouncebuildStep = announceStep; + postannouncebuildStep = announceStep; // rebuildNeeded = true; - isDirty = true; - } - } - + isDirty = true; + } + } + /* (non-Javadoc) * @see org.eclipse.cdt.managedbuilder.core.IConfiguration#isSupported() */ @@ -1674,7 +1675,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild return foInfo.isSupported(); return false; } - + /* (non-Javadoc) * @see org.eclipse.cdt.managedbuilder.core.IConfiguration#isHeaderFile(java.lang.String) */ @@ -1686,7 +1687,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild /* * O B J E C T S T A T E M A I N T E N A N C E */ - + /* (non-Javadoc) * @see org.eclipse.cdt.managedbuilder.core.IConfiguration#isExtensionElement() */ @@ -1702,13 +1703,13 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild public boolean isDirty() { // This shouldn't be called for an extension configuration if (isExtensionConfig) return false; - + // If I need saving, just say yes if (isDirty) return true; - + // Otherwise see if any children need saving IResourceInfo infos[] = rcInfos.getResourceInfos(); - + for(int i = 0; i < infos.length; i++){ if(infos[i].isDirty()) return true; @@ -1723,18 +1724,18 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild public boolean needsRebuild() { return needsRebuild(true); } - + @Override public boolean needsFullRebuild() { return needsRebuild(false); } - + public boolean needsRebuild(boolean checkChildren) { - boolean needRebuild = rebuildNeeded || resourceChangesRequireRebuild(); - + boolean needRebuild = rebuildNeeded || resourceChangesRequireRebuild(); + if(needRebuild || !checkChildren) return needRebuild; - + IResourceInfo infos[] = rcInfos.getResourceInfos(); for(int i = 0; i < infos.length; i++){ @@ -1744,7 +1745,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild return false; } - + /* (non-Javadoc) * @see org.eclipse.cdt.managedbuilder.core.IConfiguration#setDirty(boolean) */ @@ -1769,15 +1770,15 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild public void setRebuildState(boolean rebuild) { if(isExtensionElement() && rebuild) return; - + if(rebuildNeeded != rebuild){ rebuildNeeded = rebuild; saveRebuildState(); } - + if(!rebuildNeeded){ setResourceChangeState(0); - + IResourceInfo infos[] = rcInfos.getResourceInfos(); for(int i = 0; i < infos.length; i++){ @@ -1803,7 +1804,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild return true; } } - } + } String args = builder.getArguments(); if (args != null) { String superA = superB.getArguments(); @@ -1812,23 +1813,23 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild return true; } } - } + } } } return false; } - + public void resolveReferences() { if (!resolved) { resolved = true; - + // call resolve references on any children ResourceInfo infos[] = (ResourceInfo[])rcInfos.getResourceInfos(ResourceInfo.class); for(int i = 0; i < infos.length; i++){ infos[i].resolveReferences(); } - + if (parentId != null) { // Lookup the parent configuration by ID parent = ManagedBuildManager.getExtensionConfiguration(parentId); @@ -1836,7 +1837,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild } } - + /** * Reset the configuration's, tools', options */ @@ -1851,7 +1852,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild public IResourceConfiguration createResourceConfiguration(IFile file) { return createFileInfo(file.getFullPath().removeFirstSegments(1)); - + } @Override @@ -1873,12 +1874,12 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild } return fileInfo; } - + @Override public IFileInfo createFileInfo(IPath path, IFolderInfo base, ITool baseTool, String id, String name){ if(base.getPath().equals(path)) return null; - + IFileInfo fileInfo = new ResourceConfiguration((FolderInfo)base, baseTool, id, name, path); addResourceConfiguration(fileInfo); ManagedBuildManager.performValueHandlerEvent(fileInfo, IManagedOptionValueHandler.EVENT_OPEN); @@ -1890,7 +1891,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild public IFileInfo createFileInfo(IPath path, IFileInfo base, String id, String name){ if(base.getPath().equals(path)) return null; - + IFileInfo fileInfo = new ResourceConfiguration((ResourceConfiguration)base, path, id, name); addResourceConfiguration(fileInfo); ManagedBuildManager.performValueHandlerEvent(fileInfo, IManagedOptionValueHandler.EVENT_OPEN); @@ -1921,12 +1922,12 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild } return version; } - + @Override public void setVersion(Version version) { // Do nothing } - + /* (non-Javadoc) * @see org.eclipse.cdt.managedbuilder.core.IConfiguration#getBuildMacroSupplier() */ @@ -1936,9 +1937,9 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild if(toolChain != null) return toolChain.getBuildMacroSupplier(); return null; - + } - + /* (non-Javadoc) * @see org.eclipse.cdt.managedbuilder.core.IConfiguration#isTemporary() */ @@ -1946,41 +1947,41 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild public boolean isTemporary(){ return isTemporary; } - + /* (non-Javadoc) * @see org.eclipse.cdt.managedbuilder.internal.core.BuildObject#updateManagedBuildRevision(java.lang.String) */ @Override public void updateManagedBuildRevision(String revision){ super.updateManagedBuildRevision(revision); - + ResourceInfo infos[] = (ResourceInfo[])rcInfos.getResourceInfos(ResourceInfo.class); for(int i = 0; i < infos.length; i++){ infos[i].updateManagedBuildRevision(revision); } } - + public void setParent(IConfiguration parent) { if ( this.parent != parent) { this.parent = parent; if (!isExtensionElement()) setDirty(true); - } + } } - + @Override public ITool calculateTargetTool(){ ITool tool = getTargetTool(); - + if(tool == null){ tool = getToolFromOutputExtension(getArtifactExtension()); } - + if(tool == null){ IConfiguration extCfg; - for(extCfg = this; - extCfg != null && !extCfg.isExtensionElement(); + for(extCfg = this; + extCfg != null && !extCfg.isExtensionElement(); extCfg = extCfg.getParent()){ } @@ -1988,15 +1989,15 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild tool = getToolFromOutputExtension(extCfg.getArtifactExtension()); } } - + return tool; } - + @Override public ITool getToolFromOutputExtension(String extension) { return getRootFolderInfo().getToolFromOutputExtension(extension); } - + @Override public ITool getToolFromInputExtension(String sourceExtension) { return getRootFolderInfo().getToolFromInputExtension(sourceExtension); @@ -2010,19 +2011,19 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild * with the resource tree between the two configuration builds * * The trivial approach implemented currently is to hold - * the general information of whether some resources were + * the general information of whether some resources were * removed,changed,etc. and detect whether the rebuild is needed * based upon this information - * + * * This method adds the resource change state for the configuration * specifying the resource change type performed on the project * reported while building another configuration * The method is not exported to the public API since delta handling - * mechanism will likely to be changed in the future + * mechanism will likely to be changed in the future * * In the future we might implement some more smart mechanism * for tracking delta, e.g calculate the pre-cinfiguration resource delta, etc. - * + * */ public void addResourceChangeState(int state){ setResourceChangeState(state | resourceChangeState); @@ -2034,13 +2035,13 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild saveResourceChangeState(); } } - + private boolean resourceChangesRequireRebuild(){ return isInternalBuilderEnabled() ? resourceChangeState != 0 : (resourceChangeState & IResourceDelta.REMOVED) == IResourceDelta.REMOVED; } - + private void saveRebuildState(){ PropertyManager.getInstance().setProperty(this, REBUILD_STATE, Boolean.toString(rebuildNeeded)); } @@ -2048,16 +2049,16 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild private void saveResourceChangeState(){ PropertyManager.getInstance().setProperty(this, RC_CHANGE_STATE, Integer.toString(resourceChangeState)); } - + /* * Internal Builder state API * NOTE: this is a temporary API * In the future we are going present the Internal Builder * as a special Builder object of the tool-chain and implement the internal * builder enabling/disabling as the Builder substitution functionality - * + * */ - + /* public void setInternalBuilderBoolean(boolean value, String pref) { Preferences prefs = getPreferences(INTERNAL_BUILDER); if(prefs != null){ @@ -2067,17 +2068,17 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild } catch (BackingStoreException e) {} } } -*/ +*/ /* public boolean getInternalBuilderBoolean(String pref, boolean defaultValue) { Preferences prefs = getPreferences(INTERNAL_BUILDER); return prefs != null ? prefs.getBoolean(pref, false) : defaultValue; } -*/ +*/ /** * this method is used for enabling/disabling the internal builder * for the given configuration - * + * * @param enable boolean */ public void enableInternalBuilder(boolean enable){ @@ -2089,12 +2090,12 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild if(enable){ savePrevBuilderId(getBuilder()); } - - changeBuilder(builder, + + changeBuilder(builder, ManagedBuildManager.calculateChildId(builder.getId(), null), - builder.getName(), + builder.getName(), true); - + if(enable){ try { setManagedBuildOn(true); @@ -2103,11 +2104,11 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild } } } - + public boolean canEnableInternalBuilder(boolean enable){ return getBuilderForInternalBuilderEnablement(enable, true) != null; } - + private IBuilder getBuilderForInternalBuilderEnablement(boolean enable, boolean checkCompatibility){ IBuilder newBuilder = null; if(enable){ @@ -2132,9 +2133,9 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild IBuilder b = tc.getBuilder(); if(b.isInternalBuilder()) continue; - + for(;b != null && !b.isExtensionElement(); b = b.getSuperClass()) {} - + if(b != null){ if(!checkCompatibility || isBuilderCompatible(b)){ newBuilder = b; @@ -2143,7 +2144,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild } } } - + // if(newBuilder == null){ // IBuilder builders[] = ManagedBuildManager.getRealBuilders(); // IBuilder tmpB = null; @@ -2152,7 +2153,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild // if(b.isInternalBuilder()) // continue; // -// +// // if(isBuilderCompatible(b)){ // newBuilder = b; // break; @@ -2160,7 +2161,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild // tmpB = b; // } // } -// +// // if(newBuilder == null){ // if(tmpB != null) // newBuilder = tmpB; @@ -2171,14 +2172,14 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild return newBuilder; } - + private void savePrevBuilderId(IBuilder builder){ IBuilder b = builder; for(;b != null && !b.isExtensionElement(); b = b.getSuperClass()) {} - + if(b == null) b = builder; - + ToolChain tc = (ToolChain)getToolChain(); if(tc != null) tc.setNonInternalBuilderId(b.getId()); @@ -2196,14 +2197,14 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild * @return boolean */ public boolean isInternalBuilderEnabled(){ - return getBuilder().isInternalBuilder(); + return getBuilder().isInternalBuilder(); } - + /** - * + * * sets the Internal Builder mode - * - * @param ignore if true, internal builder will ignore + * + * @param ignore if true, internal builder will ignore * build errors while building, * otherwise it will stop at the first build error */ @@ -2218,54 +2219,54 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild * returns the Internal Builder mode * if true, internal builder will ignore build errors while building, * otherwise it will stop at the first build error - * + * * @return boolean */ public boolean getInternalBuilderIgnoreErr(){ return !getBuilder().isStopOnError(); } - + /** * sets the Internal Builder Parallel mode - * @param parallel if true, internal builder will use parallel mode - * + * @param parallel if true, internal builder will use parallel mode + * * @deprecated since CDT 9.0. Use {@link #setParallelDef(boolean)} */ @Deprecated public void setInternalBuilderParallel(boolean parallel){ setParallelDef(parallel); } - + /** * returns the Internal Builder parallel mode - * if true, internal builder will work in parallel mode + * if true, internal builder will work in parallel mode * otherwise it will use only one thread * @return boolean - * + * * @deprecated since CDT 9.0. Use {@link #getParallelDef()} */ @Deprecated public boolean getInternalBuilderParallel(){ return getParallelDef(); } - + /** * Set parallel execution mode for the configuration's builder. * @see Builder#setParallelBuildOn(boolean) - * + * * @param parallel - the flag to enable or disable parallel mode. */ public void setParallelDef(boolean parallel){ if(getParallelDef() == parallel) return; - + try { getEditableBuilder().setParallelBuildOn(parallel); } catch (CoreException e) { ManagedBuilderCorePlugin.log(e); } } - + /** * Check if the configuration's builder is operating in parallel mode. * @return {@code true} if parallel mode is enabled, {@code false} otherwise. @@ -2273,10 +2274,10 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild public boolean getParallelDef(){ return getBuilder().isParallelBuildOn(); } - + /** * Sets maximum number of parallel threads/jobs to be used by builder. - * + * * @param jobs - maximum number of jobs or threads. For details how * the number is interpreted see {@link Builder#setParallelizationNum(int)}. */ @@ -2287,23 +2288,23 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild ManagedBuilderCorePlugin.log(e); } } - + /** * Returns maximum number of parallel threads/jobs used by the configuration's builder. * @see #setParallelDef(boolean) - * + * * @return - maximum number of parallel threads or jobs used by the builder. */ public int getParallelNumber(){ return getBuilder().getParallelizationNum(); } - + // private Preferences getPreferences(String name){ // if(isTemporary) // return null; -// +// // IProject project = (IProject)getOwner(); -// +// // if(project == null || !project.exists() || !project.isOpen()) // return null; // @@ -2340,12 +2341,12 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild public IFolderInfo getRootFolderInfo() { return rootFolderInfo; } - + ResourceInfoContainer getRcInfoContainer(IResourceInfo rcInfo){ PathSettingsContainer cr = pathSettings.getChildContainer(rcInfo.getPath(), true, true); return new ResourceInfoContainer(cr, false); } - + @Override public CConfigurationData getConfigurationData(){ return fCfgData; @@ -2382,7 +2383,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild public IFolderInfo createFolderInfo(IPath path, IFolderInfo base, String id, String name) { if(base.getPath().equals(path)) return null; - + FolderInfo folderInfo = new FolderInfo((FolderInfo)base, id, name, path); addResourceConfiguration(folderInfo); folderInfo.propertiesChanged(); @@ -2397,7 +2398,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild if(parent != null && sourceEntries == null) return parent.getSourceEntries(); return new ICSourceEntry[]{new CSourceEntry(Path.EMPTY, null, ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED)}; - + } return sourceEntries.clone(); } @@ -2445,13 +2446,13 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild resetErrorParsers(); Set oldSet = contributeErrorParsers(null, true); if(oldSet != null) { - oldSet.removeAll(Arrays.asList(ids)); + oldSet.removeAll(Arrays.asList(ids)); removeErrorParsers(oldSet); - } + } setErrorParserAttribute(ids); } } - + public void resetErrorParsers(){ errorParserIds = null; IResourceInfo rcInfos[] = getResourceInfos(); @@ -2460,15 +2461,15 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild rcInfo.resetErrorParsers(); } } - + void removeErrorParsers(Set set){ Set oldSet = contributeErrorParsers(null, false); if(oldSet == null) oldSet = new LinkedHashSet(); - + oldSet.removeAll(set); setErrorParserAttribute(oldSet.toArray(new String[oldSet.size()])); - + IResourceInfo rcInfos[] = getResourceInfos(); for(int i = 0; i < rcInfos.length; i++){ ResourceInfo rcInfo = (ResourceInfo)rcInfos[i]; @@ -2480,7 +2481,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild public CBuildData getBuildData() { return getEditableBuilder().getBuildData(); } - + @Override public IBuilder getEditableBuilder(){ IToolChain tc = getToolChain(); @@ -2492,17 +2493,17 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild } return builder; } - + @Override public IBuilder getBuilder(){ return getToolChain().getBuilder(); } - + @Override public String getOutputPrefix(String outputExtension) { // Treat null extensions as empty string String ext = outputExtension == null ? new String() : outputExtension; - + // Get all the tools for the current config String flags = new String(); ITool[] tools = getFilteredTools(); @@ -2514,11 +2515,11 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild } return flags; } - + public ICConfigurationDescription getConfigurationDescription(){ return fCfgDes; } - + public void setConfigurationDescription(ICConfigurationDescription cfgDes){ fCfgDes = cfgDes; } @@ -2534,7 +2535,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild } return buildProperties; } - + private BuildObjectProperties findBuildProperties(){ if(buildProperties == null){ if(parent != null){ @@ -2558,7 +2559,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild public void propertiesChanged() { if(isExtensionConfig) return; - + BooleanExpressionApplicabilityCalculator calculator = getBooleanExpressionCalculator(); if(calculator != null) calculator.adjustConfiguration(this, false); @@ -2568,7 +2569,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild ((ResourceInfo)infos[i]).propertiesChanged(); } } - + public BooleanExpressionApplicabilityCalculator getBooleanExpressionCalculator(){ if(booleanExpressionCalculator == null){ if(parent != null){ @@ -2582,10 +2583,10 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild public boolean isSystemObject() { if(isTest) return true; - + if(getProjectType() != null) return getProjectType().isSystemObject(); - + return false; } @@ -2598,7 +2599,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild public String getOutputFlag(String outputExt) { // Treat null extension as an empty string String ext = outputExt == null ? new String() : outputExt; - + // Get all the tools for the current config String flags = new String(); ITool[] tools = getFilteredTools(); @@ -2611,9 +2612,9 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild } return flags; } - + @Override - public IManagedCommandLineInfo generateToolCommandLineInfo( String sourceExtension, String[] flags, + public IManagedCommandLineInfo generateToolCommandLineInfo( String sourceExtension, String[] flags, String outputFlag, String outputPrefix, String outputName, String[] inputResources, IPath inputLocation, IPath outputLocation ){ ITool[] tools = getFilteredTools(); for (int index = 0; index < tools.length; index++) { @@ -2623,7 +2624,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild //try to resolve the build macros in the tool command try{ String resolvedCommand = null; - + if ((inputLocation != null && inputLocation.toString().indexOf(" ") != -1) || //$NON-NLS-1$ (outputLocation != null && outputLocation.toString().indexOf(" ") != -1) ) //$NON-NLS-1$ { @@ -2652,26 +2653,26 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild } if((resolvedCommand = resolvedCommand.trim()).length() > 0) cmd = resolvedCommand; - + } catch (BuildMacroException e){ } IManagedCommandLineGenerator gen = tool.getCommandLineGenerator(); - return gen.generateCommandLineInfo( tool, cmd, - flags, outputFlag, outputPrefix, outputName, inputResources, + return gen.generateCommandLineInfo( tool, cmd, + flags, outputFlag, outputPrefix, outputName, inputResources, tool.getCommandLinePattern() ); } } return null; } - + @Override public String[] getUserObjects(String extension) { Vector objs = new Vector(); ITool tool = calculateTargetTool(); if(tool == null) tool = getToolFromOutputExtension(extension); - + if(tool != null){ IOption[] opts = tool.getOptions(); // Look for the user object option type @@ -2706,14 +2707,14 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild } return objs.toArray(new String[objs.size()]); } - + @Override public String[] getLibs(String extension) { Vector libs = new Vector(); ITool tool = calculateTargetTool(); if(tool == null) tool = getToolFromOutputExtension(extension); - + if(tool != null){ IOption[] opts = tool.getOptions(); // Look for the lib option type @@ -2721,10 +2722,10 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild IOption option = opts[i]; try { if (option.getValueType() == IOption.LIBRARIES) { - + // check to see if the option has an applicability calculator IOptionApplicability applicabilitytCalculator = option.getApplicabilityCalculator(); - + if (applicabilitytCalculator == null || applicabilitytCalculator.isOptionUsedInCommandLine(this, tool, option)) { String command = option.getCommand(); @@ -2749,7 +2750,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild // TODO: report error continue; } - + } } } @@ -2789,7 +2790,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild /** * Responsible for contributing 'external' settings back to the core for use * by referenced projects. - * + * * In this case it returns Include, Library path & Library File settings * to be used be references for linking the output of this library project */ @@ -2841,13 +2842,13 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild if(!rcs[i].supportsBuild(managed)) return false; } - + if(checkBuilder){ IBuilder builder = getBuilder(); if(builder != null && !builder.supportsBuild(managed)) return false; } - + return true; } @@ -2858,10 +2859,10 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild if(props != null){ supports = props.supportsType(typeId); } - + if(!supports) supports = ((ToolChain)getToolChain()).supportsType(typeId); - + return supports; } @@ -2872,13 +2873,13 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild if(props != null){ supports = props.supportsValue(typeId, valueId); } - + if(!supports) supports = ((ToolChain)getToolChain()).supportsValue(typeId, valueId); - + return supports; } - + private SupportedProperties findSupportedProperties(){ if(supportedProperties == null){ if(parent != null){ @@ -2887,7 +2888,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild } return supportedProperties; } - + private void loadProperties(IManagedConfigElement el){ supportedProperties = new SupportedProperties(el); } @@ -2899,9 +2900,9 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild if(props != null){ list.addAll(Arrays.asList(props.getRequiredTypeIds())); } - + list.addAll(Arrays.asList(((ToolChain)getToolChain()).getRequiredTypeIds())); - + return list.toArray(new String[list.size()]); } @@ -2912,9 +2913,9 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild if(props != null){ list.addAll(Arrays.asList(props.getSupportedTypeIds())); } - + list.addAll(Arrays.asList(((ToolChain)getToolChain()).getSupportedTypeIds())); - + return list.toArray(new String[list.size()]); } @@ -2925,9 +2926,9 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild if(props != null){ list.addAll(Arrays.asList(props.getSupportedValueIds(typeId))); } - + list.addAll(Arrays.asList(((ToolChain)getToolChain()).getSupportedValueIds(typeId))); - + return list.toArray(new String[list.size()]); } @@ -2938,10 +2939,10 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild if(props != null){ requires = props.requiresType(typeId); } - + if(!requires) requires = ((ToolChain)getToolChain()).requiresType(typeId); - + return requires; } @@ -2978,22 +2979,22 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild for(;extBuilder != null && !extBuilder.isExtensionElement(); extBuilder = extBuilder.getSuperClass()) {} if(extBuilder == null) extBuilder = newBuilder; - + newCfgBuilder = new Builder(tc, extBuilder, id, name, false); newCfgBuilder.copySettings(cur, allBuildSettings); } } - + if(newCfgBuilder != null){ tc.setBuilder(newCfgBuilder); } } - + @Override public boolean isBuilderCompatible(IBuilder builder){ return builder.supportsBuild(isManagedBuildOn()); } - + ITool findToolById(String id){ IResourceInfo[] rcInfos = getResourceInfos(); ITool tool = null; @@ -3005,7 +3006,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild } return tool; } - + void resolveProjectReferences(boolean onLoad){ IResourceInfo[] rcInfos = getResourceInfos(); for(int i = 0; i < rcInfos.length; i++){ @@ -3013,7 +3014,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild info.resolveProjectReferences(onLoad); } } - + public boolean isPerRcTypeDiscovery(){ ToolChain tc = (ToolChain)getRootFolderInfo().getToolChain(); return tc.isPerRcTypeDiscovery(); @@ -3043,33 +3044,33 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild ToolChain tc = (ToolChain)getRootFolderInfo().getToolChain(); return tc.getDiscoveredPathInfo(); } - + public String getDiscoveryProfileId(){ ToolChain tc = (ToolChain)getRootFolderInfo().getToolChain(); return tc.getScannerConfigDiscoveryProfileId(); } - + public PathInfoCache clearDiscoveredPathInfo(){ ToolChain tc = (ToolChain)getRootFolderInfo().getToolChain(); return tc.clearDiscoveredPathInfo(); } - + public ICfgScannerConfigBuilderInfo2Set getCfgScannerConfigInfo(){ return cfgScannerInfo; } - + public void setCfgScannerConfigInfo(ICfgScannerConfigBuilderInfo2Set info){ cfgScannerInfo = info; } - + public void clearCachedData(){ cfgScannerInfo = null; } - + public boolean isPreference(){ return isPreferenceConfig; } - + @Override public IBuildPropertyValue getBuildArtefactType() { IBuildObjectProperties props = findBuildProperties(); @@ -3080,7 +3081,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild } return null; } - + @Override public void setBuildArtefactType(String id) throws BuildException { IBuildObjectProperties props = getBuildProperties(); @@ -3090,7 +3091,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild throw new BuildException(e.getLocalizedMessage()); } // May need to update the exports paths & symbols after artifact type change - exportArtifactInfo(); + exportArtifactInfo(); } boolean isExcluded(IPath path){ @@ -3099,7 +3100,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild ICSourceEntry[] entries = getSourceEntries(); return CDataUtil.isExcluded(path, entries); } - + void setExcluded(IPath path, boolean isFolder, boolean excluded){ // if(path.segmentCount() == 0) // return; @@ -3112,7 +3113,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild excludeList.add(path); } } - + private ICSourceEntry[] getUpdatedEntries(IPath path, boolean isFolder, boolean excluded){ try { ICSourceEntry[] entries = getSourceEntries(); @@ -3122,7 +3123,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild } return null; } - + boolean canExclude(IPath path, boolean isFolder, boolean excluded){ if(excludeList == null) { ICSourceEntry[] newEntries = getUpdatedEntries(path, isFolder, excluded); diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/MultiConfiguration.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/MultiConfiguration.java index c3e3fc4c404..df67d68d2b4 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/MultiConfiguration.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/MultiConfiguration.java @@ -50,16 +50,16 @@ import org.eclipse.core.runtime.IPath; import org.osgi.framework.Version; /** - * This class represents a set of configurations + * This class represents a set of configurations * to be edited simultaneously on property pages. */ public class MultiConfiguration extends MultiItemsHolder implements IMultiConfiguration { private static final String[] EMPTY_STR_ARRAY = new String[0]; - + protected IConfiguration[] fCfgs = null; private int curr = 0; - + public MultiConfiguration(IConfiguration[] cfs) { fCfgs = cfs; for (int i=0; i getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) { - + IPath projectPath = rc.getProjectRelativePath(); ICLanguageSetting[] languageSettings = null; - + if (rc instanceof IFile) { ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(projectPath, true); if (ls != null) { @@ -45,9 +45,9 @@ public class MBSLanguageSettingsProvider extends AbstractExecutableExtensionBase ICResourceDescription rcDescription = cfgDescription.getResourceDescription(projectPath, false); languageSettings = getLanguageSettings(rcDescription); } - + List list = new ArrayList(); - + if (languageSettings != null) { for (ICLanguageSetting langSetting : languageSettings) { if (langSetting!=null) { @@ -69,7 +69,7 @@ public class MBSLanguageSettingsProvider extends AbstractExecutableExtensionBase } return list; } - + private ICLanguageSetting[] getLanguageSettings(ICResourceDescription rcDescription) { ICLanguageSetting[] array = null; switch (rcDescription.getType()) { @@ -98,7 +98,7 @@ public class MBSLanguageSettingsProvider extends AbstractExecutableExtensionBase // lang.setSettingEntries(kind, entries); IPath projectPath = rc.getProjectRelativePath(); ICResourceDescription rcDescription = cfgDescription.getResourceDescription(projectPath, false); - + for (ICLanguageSetting languageSetting : getLanguageSettings(rcDescription)) { if (languageSetting!=null) { String id = languageSetting.getLanguageId(); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java index c67d632891c..5072a372952 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java @@ -43,7 +43,7 @@ public class LanguageSettingsExtensionManager { /** Name of the extension point for contributing language settings */ static final String PROVIDER_EXTENSION_FULL_ID = "org.eclipse.cdt.core.LanguageSettingsProvider"; //$NON-NLS-1$ static final String PROVIDER_EXTENSION_SIMPLE_ID = "LanguageSettingsProvider"; //$NON-NLS-1$ - + static final String ELEM_PROVIDER = "provider"; //$NON-NLS-1$ static final String ATTR_CLASS = "class"; //$NON-NLS-1$ static final String ATTR_ID = "id"; //$NON-NLS-1$ @@ -57,7 +57,7 @@ public class LanguageSettingsExtensionManager { static final String ATTR_KIND = "kind"; //$NON-NLS-1$ static final String ATTR_VALUE = "value"; //$NON-NLS-1$ - /** + /** * Extension providers loaded once. If the provider is editable (read cloneable) * external callers get copy rather than real instance. */ @@ -82,6 +82,7 @@ public class LanguageSettingsExtensionManager { // sort by name - for the providers taken from platform extensions Set sortedProviders = new TreeSet( new Comparator() { + @Override public int compare(ILanguageSettingsProvider pr1, ILanguageSettingsProvider pr2) { return pr1.getName().compareTo(pr2.getName()); } @@ -155,7 +156,7 @@ public class LanguageSettingsExtensionManager { /** * Configure language settings provider with parameters defined in XML metadata. - * + * * @param provider - empty non-configured provider. * @param ce - configuration element from registry representing XML. */ @@ -222,7 +223,7 @@ public class LanguageSettingsExtensionManager { if (className==null || className.length()==0) { return new LanguageSettingsBaseProvider(); } - + try { IExtensionPoint extension = registry.getExtensionPoint(CCorePlugin.PLUGIN_ID, PROVIDER_EXTENSION_SIMPLE_ID); if (extension != null) { @@ -249,8 +250,8 @@ public class LanguageSettingsExtensionManager { } /** - * Create an instance of language settings provider of given class name. - * + * Create an instance of language settings provider of given class name. + * * @param className - class name to instantiate. * @return new instance of language settings provider. */ @@ -258,7 +259,7 @@ public class LanguageSettingsExtensionManager { if (className==null || className.equals(LanguageSettingsSerializableProvider.class.getName())) { return new LanguageSettingsSerializableProvider(); } - + ILanguageSettingsProvider provider = createProviderCarcass(className, Platform.getExtensionRegistry()); if (provider==null) { IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "Not able to load provider class=" + className); @@ -280,7 +281,7 @@ public class LanguageSettingsExtensionManager { if (provider!=null) { if (!(provider instanceof ILanguageSettingsEditableProvider)) throw new CloneNotSupportedException("Not able to clone provider " + provider.getClass()); - + provider = ((ILanguageSettingsEditableProvider) provider).clone(); } return provider; @@ -288,7 +289,7 @@ public class LanguageSettingsExtensionManager { /** * TODO - * + * * @param id * @return */ @@ -305,7 +306,7 @@ public class LanguageSettingsExtensionManager { } return provider; } - + /** * @return list of providers contributed by all extensions. Preferable copy but if not possible * will return raw provider. @@ -321,7 +322,7 @@ public class LanguageSettingsExtensionManager { } if (extensionProvider==null) extensionProvider = fExtensionProviders.get(id); - + if (extensionProvider!=null) list.add(extensionProvider); } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java index 21d2d9c0934..91cd8051398 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java @@ -658,7 +658,8 @@ projects: } } - private static void loadProviderEntries(LanguageSettingsSerializableProvider provider, String cfgId, Element projectElementWsp) { + private static void loadProviderEntries(LanguageSettingsSerializableProvider provider, + String cfgId, Element projectElementWsp) { /* diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationDescription.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationDescription.java index edd8031cf5d..a068d9a0d39 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationDescription.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationDescription.java @@ -819,6 +819,7 @@ public class CConfigurationDescription extends CDataProxyContainer implements IC return status != null ? status : CConfigurationStatus.CFG_STATUS_OK; } + @Override public void setLanguageSettingProviders(List providers) { try { CConfigurationSpecSettings specSettings = getSpecSettings(); @@ -828,6 +829,7 @@ public class CConfigurationDescription extends CDataProxyContainer implements IC } } + @Override public List getLanguageSettingProviders() { try { return getSpecSettings().getLanguageSettingProviders(); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationDescriptionCache.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationDescriptionCache.java index 6b455cdd058..a58a4e717c0 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationDescriptionCache.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationDescriptionCache.java @@ -56,7 +56,7 @@ import org.eclipse.core.runtime.QualifiedName; /** * CConfigurationDescriptionCache is a proxy class for serialization of configuration description data. - * + * * An inspection of the scenario where user changes project properties and saves it yields * following sequence of events: * - Initialization: @@ -603,12 +603,14 @@ public class CConfigurationDescriptionCache extends CDefaultConfigurationData return status != null ? status : CConfigurationStatus.CFG_STATUS_OK; } + @Override public void setLanguageSettingProviders(List providers) { if(!fInitializing) throw ExceptionFactory.createIsReadOnlyException(); fSpecSettings.setLanguageSettingProviders(providers); } + @Override public List getLanguageSettingProviders() { return fSpecSettings.getLanguageSettingProviders(); } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/MultiConfigDescription.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/MultiConfigDescription.java index c0688bbf98b..939161cdf2e 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/MultiConfigDescription.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/MultiConfigDescription.java @@ -639,11 +639,13 @@ public class MultiConfigDescription extends MultiItemsHolder implements fCfgs[i].removeStorage(id); } + @Override public void setLanguageSettingProviders(List providers) { if (DEBUG) System.out.println("Bad multi access: MultiConfigDescription.setLanguageSettingProviders()"); //$NON-NLS-1$ } + @Override public List getLanguageSettingProviders() { if (DEBUG) System.out.println("Bad multi access: MultiConfigDescription.getLanguageSettingProviders()"); //$NON-NLS-1$ From da8e44baef578e924cb98c63bdd3d6f31a6fd997 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Sat, 19 Nov 2011 08:55:06 -0500 Subject: [PATCH 068/120] API cleanup & JavaDoc --- .../BuiltinSpecsDetectorTest.java | 122 +++++++++--------- .../MBSLanguageSettingsProvider.java | 4 +- .../LanguageSettingsExtensionsTests.java | 61 +++++---- .../LanguageSettingsManagerTests.java | 80 ++++++------ .../LanguageSettingsSerializableTests.java | 26 ++-- .../MockLanguageSettingsProvider.java | 6 +- .../ILanguageSettingsEditableProvider.java | 6 +- .../providers/ILanguageSettingsProvider.java | 2 +- .../LanguageSettingsBaseProvider.java | 86 ++++++------ .../ScannerDiscoveryLegacySupport.java | 12 +- .../LanguageSettingsExtensionManager.java | 14 +- .../schema/LanguageSettingsProvider.exsd | 7 +- .../core/AbstractExecutableExtensionBase.java | 6 +- 13 files changed, 222 insertions(+), 210 deletions(-) diff --git a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/BuiltinSpecsDetectorTest.java b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/BuiltinSpecsDetectorTest.java index 2985f1ff23b..b51a80e0042 100644 --- a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/BuiltinSpecsDetectorTest.java +++ b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/BuiltinSpecsDetectorTest.java @@ -48,7 +48,7 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { private static final String LANGUAGE_ID = "language.test.id"; private static final String CUSTOM_PARAMETER = "customParameter"; private static final String ELEM_TEST = "test"; - + // those attributes must match that in AbstractBuiltinSpecsDetector private static final String ATTR_CONSOLE = "console"; //$NON-NLS-1$ @@ -88,7 +88,7 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { return isExecuted; } } - + private class MockConsoleBuiltinSpecsDetector extends AbstractBuiltinSpecsDetector { @SuppressWarnings("nls") private final AbstractOptionParser[] optionParsers = { @@ -116,7 +116,7 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { return optionParsers; } } - + @Override protected void setUp() throws Exception { super.setUp(); @@ -141,35 +141,41 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { } public void testAbstractBuiltinSpecsDetector_GettersSetters() throws Exception { - // define mock detector - MockBuiltinSpecsDetectorExecutedFlag detector = new MockBuiltinSpecsDetectorExecutedFlag(); - - detector.configureProvider(PROVIDER_ID, PROVIDER_NAME, null, null, null); - assertEquals(PROVIDER_ID, detector.getId()); - assertEquals(PROVIDER_NAME, detector.getName()); - assertEquals(null, detector.getLanguageScope()); - assertEquals(null, detector.getSettingEntries(null, null, null)); - assertEquals(null, detector.getCustomParameter()); - assertEquals(false, detector.isExecuted()); + { + // provider configured with null parameters + MockBuiltinSpecsDetectorExecutedFlag detector = new MockBuiltinSpecsDetectorExecutedFlag(); + detector.configureProvider(PROVIDER_ID, PROVIDER_NAME, null, null, null); - List languages = new ArrayList(); - languages.add(LANGUAGE_ID); - List entries = new ArrayList(); - ICLanguageSettingEntry entry = new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); - entries.add(entry); + assertEquals(PROVIDER_ID, detector.getId()); + assertEquals(PROVIDER_NAME, detector.getName()); + assertEquals(null, detector.getLanguageScope()); + assertEquals(null, detector.getSettingEntries(null, null, null)); + assertEquals(null, detector.getCustomParameter()); + assertEquals(false, detector.isExecuted()); + } - detector.configureProvider(PROVIDER_ID, PROVIDER_NAME, languages, entries, CUSTOM_PARAMETER); - assertEquals(PROVIDER_ID, detector.getId()); - assertEquals(PROVIDER_NAME, detector.getName()); - assertEquals(languages, detector.getLanguageScope()); - assertEquals(entries, detector.getSettingEntries(null, null, null)); - assertEquals(CUSTOM_PARAMETER, detector.getCustomParameter()); - assertEquals(false, detector.isExecuted()); - - detector.execute(); - assertEquals(true, detector.isExecuted()); + { + // provider configured with non-null parameters + MockBuiltinSpecsDetectorExecutedFlag detector = new MockBuiltinSpecsDetectorExecutedFlag(); + List languages = new ArrayList(); + languages.add(LANGUAGE_ID); + List entries = new ArrayList(); + ICLanguageSettingEntry entry = new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); + entries.add(entry); + + detector.configureProvider(PROVIDER_ID, PROVIDER_NAME, languages, entries, CUSTOM_PARAMETER); + assertEquals(PROVIDER_ID, detector.getId()); + assertEquals(PROVIDER_NAME, detector.getName()); + assertEquals(languages, detector.getLanguageScope()); + assertEquals(entries, detector.getSettingEntries(null, null, null)); + assertEquals(CUSTOM_PARAMETER, detector.getCustomParameter()); + assertEquals(false, detector.isExecuted()); + + detector.execute(); + assertEquals(true, detector.isExecuted()); + } } - + public void testAbstractBuiltinSpecsDetector_CloneAndEquals() throws Exception { // define mock detector class MockDetectorCloneable extends MockBuiltinSpecsDetectorExecutedFlag implements Cloneable { @@ -182,10 +188,10 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { return (MockDetectorCloneable) super.cloneShallow(); } } - + // create instance to compare to MockDetectorCloneable detector = new MockDetectorCloneable(); - + List languages = new ArrayList(); languages.add(LANGUAGE_ID); List entries = new ArrayList(); @@ -195,7 +201,7 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { // check clone after initialization MockDetectorCloneable clone0 = detector.clone(); assertTrue(detector.equals(clone0)); - + // configure provider detector.configureProvider(PROVIDER_ID, PROVIDER_NAME, languages, entries, CUSTOM_PARAMETER); assertEquals(false, detector.isConsoleEnabled()); @@ -209,21 +215,21 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { MockDetectorCloneable clone = detector.clone(); assertTrue(detector.equals(clone)); } - + // check custom parameter { MockDetectorCloneable clone = detector.clone(); clone.setCustomParameter("changed"); assertFalse(detector.equals(clone)); } - + // check language scope { MockDetectorCloneable clone = detector.clone(); clone.setLanguageScope(null); assertFalse(detector.equals(clone)); } - + // check console flag { MockDetectorCloneable clone = detector.clone(); @@ -231,7 +237,7 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { clone.setConsoleEnabled( ! isConsoleEnabled ); assertFalse(detector.equals(clone)); } - + // check isExecuted flag { MockDetectorCloneable clone = detector.clone(); @@ -240,14 +246,14 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { assertEquals(false, clone.isExecuted()); assertFalse(detector.equals(clone)); } - + // check entries { MockDetectorCloneable clone = detector.clone(); clone.setSettingEntries(null, null, null, null); assertFalse(detector.equals(clone)); } - + // check cloneShallow() { MockDetectorCloneable detector2 = detector.clone(); @@ -257,12 +263,12 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { detector2.setSettingEntries(null, null, null, null); assertFalse(detector2.equals(clone)); - + clone.execute(); assertTrue(detector2.equals(clone)); } } - + /** */ public void testAbstractBuiltinSpecsDetector_Serialize() throws Exception { @@ -270,36 +276,36 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { // create empty XML Document doc = XmlUtil.newDocument(); Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST); - + // load it to new provider MockBuiltinSpecsDetectorExecutedFlag detector = new MockBuiltinSpecsDetectorExecutedFlag(); detector.load(rootElement); assertEquals(false, detector.isConsoleEnabled()); } - + Element elementProvider; { // define mock detector MockBuiltinSpecsDetectorExecutedFlag detector = new MockBuiltinSpecsDetectorExecutedFlag(); assertEquals(false, detector.isConsoleEnabled()); - + // redefine the settings detector.setConsoleEnabled(true); assertEquals(true, detector.isConsoleEnabled()); - + // serialize in XML Document doc = XmlUtil.newDocument(); Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST); elementProvider = detector.serialize(rootElement); String xmlString = XmlUtil.toString(doc); - + assertTrue(xmlString.contains(ATTR_CONSOLE)); } { // create another instance of the provider MockBuiltinSpecsDetectorExecutedFlag detector = new MockBuiltinSpecsDetectorExecutedFlag(); assertEquals(false, detector.isConsoleEnabled()); - + // load element detector.load(elementProvider); assertEquals(true, detector.isConsoleEnabled()); @@ -329,16 +335,16 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; - + MockConsoleBuiltinSpecsDetector detector = new MockConsoleBuiltinSpecsDetector(); detector.setLanguageScope(new ArrayList() {{add(LANGUAGE_ID);}}); - + detector.runForEachLanguage(cfgDescription, null, null, null); assertFalse(detector.isEmpty()); - + List noentries = detector.getSettingEntries(null, null, null); assertNull(noentries); - + List entries = detector.getSettingEntries(cfgDescription, null, LANGUAGE_ID); ICLanguageSettingEntry expected = new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); assertEquals(expected, entries.get(0)); @@ -347,10 +353,10 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { public void testAbstractBuiltinSpecsDetector_RunGlobal() throws Exception { MockConsoleBuiltinSpecsDetector detector = new MockConsoleBuiltinSpecsDetector(); detector.setLanguageScope(new ArrayList() {{add(LANGUAGE_ID);}}); - + detector.runForEachLanguage(null, null, null, null); assertFalse(detector.isEmpty()); - + List entries = detector.getSettingEntries(null, null, LANGUAGE_ID); ICLanguageSettingEntry expected = new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); assertEquals(expected, entries.get(0)); @@ -370,7 +376,7 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { final CLibraryPathEntry libraryPath_2 = new CLibraryPathEntry(new Path("/lib/path_2"), ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); final CLibraryFileEntry libraryFile_1 = new CLibraryFileEntry("lib_1.a", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); final CLibraryFileEntry libraryFile_2 = new CLibraryFileEntry("lib_2.a", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); - + // Define mock detector adding unorganized entries MockBuiltinSpecsDetector detector = new MockBuiltinSpecsDetector() { @Override @@ -381,7 +387,7 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { detectedSettingEntries.add(macro_1); detectedSettingEntries.add(includeFile_1); detectedSettingEntries.add(includePath_1); - + detectedSettingEntries.add(includePath_2); detectedSettingEntries.add(includeFile_2); detectedSettingEntries.add(macro_2); @@ -391,17 +397,17 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { return true; } }; - + // run specs detector detector.startup(null); detector.startupForLanguage(null); detector.processLine("", null); detector.shutdownForLanguage(); detector.shutdown(); - + // compare benchmarks, expected well-sorted List entries = detector.getSettingEntries(null, null, null); - + int i=0; assertEquals(includePath_1, entries.get(i++)); assertEquals(includePath_2, entries.get(i++)); @@ -415,7 +421,7 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { assertEquals(libraryPath_2, entries.get(i++)); assertEquals(libraryFile_1, entries.get(i++)); assertEquals(libraryFile_2, entries.get(i++)); - + assertEquals(12, entries.size()); } } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/MBSLanguageSettingsProvider.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/MBSLanguageSettingsProvider.java index 573eda88142..3e95c6ca3a3 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/MBSLanguageSettingsProvider.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/MBSLanguageSettingsProvider.java @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright (c) 2009, 2009 Andrew Gvozdev (Quoin Inc.) and others. + * Copyright (c) 2009, 2011 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 (Quoin Inc.) - initial API and implementation + * Andrew Gvozdev - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.managedbuilder.internal.scannerconfig; diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java index df125a63059..58208dade1b 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java @@ -111,7 +111,7 @@ public class LanguageSettingsExtensionsTests extends BaseTestCase { // get test plugin extension provider ILanguageSettingsProvider providerExt = LanguageSettingsManager.getExtensionProviderCopy(EXTENSION_BASE_PROVIDER_ID); assertTrue(LanguageSettingsManager.isWorkspaceProvider(providerExt)); - + // get raw extension provider ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(providerExt); assertTrue(rawProvider instanceof LanguageSettingsBaseProvider); @@ -225,7 +225,26 @@ public class LanguageSettingsExtensionsTests extends BaseTestCase { assertEquals(languages.size(), actualLanguageIds.size()); } } - + + /** + * LanguageSettingsBaseProvider is not allowed to be configured twice. + */ + public void testBaseProviderCantReconfigure() throws Exception { + // create LanguageSettingsBaseProvider + LanguageSettingsBaseProvider provider = new LanguageSettingsBaseProvider(); + List entries = new ArrayList(); + entries.add(new CIncludePathEntry("/usr/include/", 0)); + // configure it + provider.configureProvider("id", "name", null, entries, null); + + try { + // attempt to configure it twice should fail + provider.configureProvider("id", "name", null, entries, null); + fail("LanguageSettingsBaseProvider is not allowed to be configured twice"); + } catch (UnsupportedOperationException e) { + } + } + /** * TODO */ @@ -238,10 +257,10 @@ public class LanguageSettingsExtensionsTests extends BaseTestCase { ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(providerExt); assertTrue(rawProvider instanceof LanguageSettingsSerializableProvider); LanguageSettingsSerializableProvider provider = (LanguageSettingsSerializableProvider) rawProvider; - + assertEquals(null, provider.getLanguageScope()); assertEquals("", provider.getCustomParameter()); - + List expected = new ArrayList(); expected.add(new CMacroEntry("MACRO", "value", 0)); assertEquals(expected, provider.getSettingEntries(null, null, null)); @@ -261,65 +280,45 @@ public class LanguageSettingsExtensionsTests extends BaseTestCase { ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(providerExt); assertTrue(rawProvider instanceof LanguageSettingsSerializableProvider); assertTrue(LanguageSettingsExtensionManager.equalsExtensionProvider(rawProvider)); - + // compare with workspace provider ILanguageSettingsProvider providerWsp = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_SERIALIZABLE_PROVIDER_ID); ILanguageSettingsProvider providerWspRaw = LanguageSettingsManager.getRawProvider(providerWsp); assertSame(rawProvider, providerWspRaw); } - + // Editable providers are retrieved by copy { ILanguageSettingsProvider providerExt = LanguageSettingsManager.getExtensionProviderCopy(EXTENSION_EDITABLE_PROVIDER_ID); assertFalse(LanguageSettingsManager.isWorkspaceProvider(providerExt)); assertTrue(providerExt instanceof ILanguageSettingsEditableProvider); assertTrue(LanguageSettingsExtensionManager.equalsExtensionProvider(providerExt)); - + ILanguageSettingsProvider providerExt2 = LanguageSettingsManager.getExtensionProviderCopy(EXTENSION_EDITABLE_PROVIDER_ID); assertNotSame(providerExt, providerExt2); assertEquals(providerExt, providerExt2); - + ILanguageSettingsProvider providerWsp = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_EDITABLE_PROVIDER_ID); ILanguageSettingsProvider providerWspRaw = LanguageSettingsManager.getRawProvider(providerWsp); assertNotSame(providerExt, providerWspRaw); assertEquals(providerExt, providerWspRaw); assertTrue(LanguageSettingsExtensionManager.equalsExtensionProvider(providerWspRaw)); } - + // Test shallow copy { ILanguageSettingsProvider provider = LanguageSettingsManager.getExtensionProviderCopy(EXTENSION_EDITABLE_PROVIDER_ID); assertNotNull(provider); assertTrue(provider instanceof ILanguageSettingsEditableProvider); - + ILanguageSettingsProvider providerShallow = LanguageSettingsExtensionManager.getExtensionProviderShallow(EXTENSION_EDITABLE_PROVIDER_ID); assertNotNull(providerShallow); assertTrue(providerShallow instanceof ILanguageSettingsEditableProvider); assertFalse(provider.equals(providerShallow)); - + assertFalse(LanguageSettingsExtensionManager.equalsExtensionProvider(providerShallow)); assertTrue(LanguageSettingsExtensionManager.equalsExtensionProviderShallow((ILanguageSettingsEditableProvider) providerShallow)); - } } - -// /** -// * LanguageSettingsBaseProvider is not allowed to be configured twice. -// */ -// public void testBaseProviderConfigure() throws Exception { -// // create LanguageSettingsBaseProvider -// LanguageSettingsBaseProvider provider = new LanguageSettingsBaseProvider(); -// List entries = new ArrayList(); -// entries.add(new CIncludePathEntry("/usr/include/", 0)); -// // configure it -// provider.configureProvider("id", "name", null, entries, null); -// -// try { -// // attempt to configure it twice should fail -// provider.configureProvider("id", "name", null, entries, null); -// fail("LanguageSettingsBaseProvider is not allowed to be configured twice"); -// } catch (UnsupportedOperationException e) { -// } -// } } diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java index 5fb13f11277..93012dd56c5 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Andrew Gvozdev and others. + * Copyright (c) 2009, 2011 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 @@ -230,11 +230,11 @@ public class LanguageSettingsManagerTests extends BaseTestCase { assertNotNull(actual); assertEquals(0, actual.size()); } - + // use careless provider causing an exception { setExpectedNumberOfLoggedNonOKStatusObjects(1); - + ILanguageSettingsProvider providerNPE = new MockProvider(PROVIDER_1, PROVIDER_NAME_1, null) { @Override public List getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) { @@ -419,7 +419,7 @@ public class LanguageSettingsManagerTests extends BaseTestCase { assertEquals(0, actual.size()); } } - + /** */ public void testProvider_DefaultEntries() throws Exception { @@ -428,15 +428,15 @@ public class LanguageSettingsManagerTests extends BaseTestCase { IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); ICProjectDescription prjDescription = CoreModel.getDefault().getProjectDescription(project); ICConfigurationDescription[] cfgDescriptions = prjDescription.getConfigurations(); - + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; assertTrue(cfgDescription instanceof CConfigurationDescription); - + final IFolder parentFolder = ResourceHelper.createFolder(project, "/ParentFolder/"); assertNotNull(parentFolder); final IFile emptySettingsPath = ResourceHelper.createFile(project, "/ParentFolder/Subfolder/empty"); assertNotNull(emptySettingsPath); - + // store the entries as default entries final List entries = new ArrayList(); entries.add(new CIncludePathEntry("path0", 0)); @@ -449,11 +449,11 @@ public class LanguageSettingsManagerTests extends BaseTestCase { } return null; } - + }; providers.add(provider); cfgDescription.setLanguageSettingProviders(providers); - + { // retrieve entries for a resource IFile derived = ResourceHelper.createFile(project, "/ParentFolder/Subfolder/resource"); @@ -691,7 +691,7 @@ public class LanguageSettingsManagerTests extends BaseTestCase { ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_EDITABLE_PROVIDER_ID); assertEquals(EXTENSION_EDITABLE_PROVIDER_ID, provider.getId()); assertEquals(EXTENSION_EDITABLE_PROVIDER_NAME, provider.getName()); - + // get raw provider ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); assertEquals(EXTENSION_EDITABLE_PROVIDER_ID, rawProvider.getId()); @@ -699,7 +699,7 @@ public class LanguageSettingsManagerTests extends BaseTestCase { assertTrue(rawProvider instanceof LanguageSettingsSerializableProvider); // assert they are not the same object assertNotSame(provider, rawProvider); - + { // make sure entries are the same List entries = provider.getSettingEntries(null, null, null); @@ -707,14 +707,14 @@ public class LanguageSettingsManagerTests extends BaseTestCase { List rawEntries = rawProvider.getSettingEntries(null, null, null); assertEquals(entries, rawEntries); } - + { // set new entries to the raw provider List newEntries = new ArrayList(); newEntries.add(new CIncludePathEntry("path0", 0)); newEntries.add(new CIncludePathEntry("path1", 0)); ((LanguageSettingsSerializableProvider)rawProvider).setSettingEntries(null, null, null, newEntries); - + // check that the workspace provider gets them too List newRawEntries = rawProvider.getSettingEntries(null, null, null); assertEquals(newEntries, newRawEntries); @@ -742,13 +742,13 @@ public class LanguageSettingsManagerTests extends BaseTestCase { List entries = provider.getSettingEntries(null, null, null); assertEquals(1, entries.size()); // defined in the extension } - + // define new entries for the raw provider List newEntries = new ArrayList(); newEntries.add(new CIncludePathEntry("path0", 0)); newEntries.add(new CIncludePathEntry("path1", 0)); newEntries.add(new CIncludePathEntry("path2", 0)); - + { // replace raw provider List providers = new ArrayList(); @@ -757,7 +757,7 @@ public class LanguageSettingsManagerTests extends BaseTestCase { providers.add(newRawProvider); LanguageSettingsManager.setWorkspaceProviders(providers); } - + { // check that provider provides the new entries List entries = provider.getSettingEntries(null, null, null); @@ -765,7 +765,7 @@ public class LanguageSettingsManagerTests extends BaseTestCase { assertEquals(newEntries, entries); } } - + /** * Test ability to be called with workspace provider as well (NOOP). */ @@ -774,14 +774,14 @@ public class LanguageSettingsManagerTests extends BaseTestCase { ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_EDITABLE_PROVIDER_ID); ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); assertNotSame(provider, rawProvider); - + // attempt to "replace" with workspace provider (which is a wrapper around raw provider), should be NOOP List providers = new ArrayList(); providers.add(provider); LanguageSettingsManager.setWorkspaceProviders(providers); ILanguageSettingsProvider newRawProvider = LanguageSettingsManager.getRawProvider(provider); assertSame(rawProvider, newRawProvider); - + // check for no side effect assertSame(provider, providers.get(0)); } @@ -793,23 +793,23 @@ public class LanguageSettingsManagerTests extends BaseTestCase { CMacroEntry entry = new CMacroEntry("MACRO", null, 0); List entries = new ArrayList(); entries.add(entry); - + // create resources IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName()); IFile file = ResourceHelper.createFile(project, "file.cpp"); assertNotNull(file); - + // create a provider and set the entries LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); provider.setSettingEntries(null, file, null, entries); // build the hierarchy LanguageSettingsProvidersSerializer.buildResourceTree(provider, null, null, project); - + // check that entries go to highest possible level assertEquals(entries, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file, null)); assertEquals(entries, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, project, null)); } - + /** */ public void testBuildResourceTree_FileInSubFolder() throws Exception { @@ -817,24 +817,24 @@ public class LanguageSettingsManagerTests extends BaseTestCase { CMacroEntry entry = new CMacroEntry("MACRO", null, 0); List entries = new ArrayList(); entries.add(entry); - + // create resources IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName()); IFolder folder = ResourceHelper.createFolder(project, "Folder"); IFile file = ResourceHelper.createFile(project, "Folder/file.cpp"); - + // create a provider and set the entries LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); provider.setSettingEntries(null, file, null, entries); // build the hierarchy LanguageSettingsManager.buildResourceTree(provider, null, null, project); - + // check that entries go to highest possible level assertEquals(entries, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file, null)); assertEquals(entries, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, folder, null)); assertEquals(entries, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, project, null)); } - + /** */ public void testBuildResourceTree_TwoSubFolders() throws Exception { @@ -843,31 +843,31 @@ public class LanguageSettingsManagerTests extends BaseTestCase { entries1.add(new CMacroEntry("MACRO_1", null, 0)); List entries2 = new ArrayList(); entries2.add(new CMacroEntry("MACRO_2", null, 0)); - + // create resources IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName()); IFolder folder1 = ResourceHelper.createFolder(project, "Folder1"); IFolder folder2 = ResourceHelper.createFolder(project, "Folder2"); IFile file1 = ResourceHelper.createFile(project, "Folder1/file1.cpp"); IFile file2 = ResourceHelper.createFile(project, "Folder2/file2.cpp"); - + // create a provider and set the entries LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); provider.setSettingEntries(null, file1, null, entries1); provider.setSettingEntries(null, file2, null, entries2); // build the hierarchy LanguageSettingsManager.buildResourceTree(provider, null, null, project); - + // check that entries go to highest possible level assertEquals(entries1, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file1, null)); assertEquals(entries1, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, folder1, null)); - + assertEquals(entries2, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file2, null)); assertEquals(entries2, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, folder2, null)); assertEquals(0, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, project, null).size()); } - + /** */ public void testBuildResourceTree_FlippingSettings() throws Exception { @@ -876,16 +876,16 @@ public class LanguageSettingsManagerTests extends BaseTestCase { entries1.add(new CMacroEntry("MACRO_1", null, 0)); List entries2 = new ArrayList(); entries2.add(new CMacroEntry("MACRO_2", null, 0)); - + // create resources IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName()); IFile file1 = ResourceHelper.createFile(project, "file1.cpp"); IFile file2 = ResourceHelper.createFile(project, "file2.cpp"); IFile file3 = ResourceHelper.createFile(project, "file3.cpp"); - + // create a provider LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); - + // set the entries for the first 2 files provider.setSettingEntries(null, file1, null, entries1); provider.setSettingEntries(null, file2, null, entries1); @@ -895,7 +895,7 @@ public class LanguageSettingsManagerTests extends BaseTestCase { assertEquals(entries1, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file1, null)); assertEquals(entries1, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file2, null)); assertEquals(entries1, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, project, null)); - + // set the entries for the second+third files (second file flips the settings) provider.setSettingEntries(null, file2, null, entries2); provider.setSettingEntries(null, file3, null, entries2); @@ -915,22 +915,22 @@ public class LanguageSettingsManagerTests extends BaseTestCase { CMacroEntry entry = new CMacroEntry("MACRO", null, 0); List entries = new ArrayList(); entries.add(entry); - + // create resources IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName()); IFolder folder = ResourceHelper.createFolder(project, "Folder"); IFile file = ResourceHelper.createFile(project, "Folder/file.cpp"); - + // create a provider and set the entries LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); provider.setSettingEntries(null, file, LANG_CPP, entries); // build the hierarchy LanguageSettingsManager.buildResourceTree(provider, null, LANG_CPP, project); - + // check that entries go to highest possible level assertEquals(entries, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file, LANG_CPP)); assertEquals(entries, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, folder, LANG_CPP)); assertEquals(entries, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, project, LANG_CPP)); } - + } diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java index 14c8942d3f9..53e28a72e2d 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 Andrew Gvozdev and others. + * Copyright (c) 2009, 2011 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 @@ -1238,17 +1238,17 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { sampleLanguages.add(LANG_ID); // create a model provider - class LanguageSettingsSerializableMock extends LanguageSettingsSerializableProvider implements Cloneable { - public LanguageSettingsSerializableMock(String id, String name) { + class MockSerializableProvider extends LanguageSettingsSerializableProvider implements Cloneable { + public MockSerializableProvider(String id, String name) { super(id, name); } @Override - public LanguageSettingsSerializableMock clone() throws CloneNotSupportedException { - return (LanguageSettingsSerializableMock) super.clone(); + public MockSerializableProvider clone() throws CloneNotSupportedException { + return (MockSerializableProvider) super.clone(); } } - LanguageSettingsSerializableMock provider1 = new LanguageSettingsSerializableMock(PROVIDER_1, PROVIDER_NAME_1); + MockSerializableProvider provider1 = new MockSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); provider1.setLanguageScope(sampleLanguages); provider1.setCustomParameter(CUSTOM_PARAMETER); assertEquals(false, provider1.isStoringEntriesInProjectArea()); @@ -1257,7 +1257,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { provider1.setSettingEntries(null, null, LANG_ID, sampleEntries_2); // clone provider - LanguageSettingsSerializableMock providerClone = provider1.clone(); + MockSerializableProvider providerClone = provider1.clone(); assertNotSame(provider1, providerClone); assertTrue(provider1.equals(providerClone)); assertTrue(provider1.getClass()==providerClone.getClass()); @@ -1286,17 +1286,17 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { sampleLanguages.add(LANG_ID); // create a model provider - class LanguageSettingsSerializableMock extends LanguageSettingsSerializableProvider implements Cloneable { - public LanguageSettingsSerializableMock(String id, String name) { + class MockSerializableProvider extends LanguageSettingsSerializableProvider implements Cloneable { + public MockSerializableProvider(String id, String name) { super(id, name); } @Override - public LanguageSettingsSerializableMock cloneShallow() throws CloneNotSupportedException { - return (LanguageSettingsSerializableMock) super.cloneShallow(); + public MockSerializableProvider cloneShallow() throws CloneNotSupportedException { + return (MockSerializableProvider) super.cloneShallow(); } } - LanguageSettingsSerializableMock provider1 = new LanguageSettingsSerializableMock(PROVIDER_1, PROVIDER_NAME_1); + MockSerializableProvider provider1 = new MockSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); provider1.setLanguageScope(sampleLanguages); provider1.setCustomParameter(CUSTOM_PARAMETER); assertEquals(false, provider1.isStoringEntriesInProjectArea()); @@ -1307,7 +1307,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { provider1.setSettingEntries(null, null, null, entries); // clone provider - LanguageSettingsSerializableMock providerClone = provider1.cloneShallow(); + MockSerializableProvider providerClone = provider1.cloneShallow(); assertNotSame(provider1, providerClone); assertFalse(provider1.equals(providerClone)); assertTrue(provider1.getClass()==providerClone.getClass()); diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockLanguageSettingsProvider.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockLanguageSettingsProvider.java index 96024c7db45..5b6675f250c 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockLanguageSettingsProvider.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockLanguageSettingsProvider.java @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright (c) 2009, 2009 Andrew Gvozdev (Quoin Inc.) and others. + * Copyright (c) 2009, 2011 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 (Quoin Inc.) - initial API and implementation + * Andrew Gvozdev - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.core.language.settings.providers; @@ -14,7 +14,6 @@ package org.eclipse.cdt.core.language.settings.providers; import java.util.List; import org.eclipse.cdt.core.AbstractExecutableExtensionBase; -import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.core.resources.IResource; @@ -22,6 +21,7 @@ import org.eclipse.core.resources.IResource; public class MockLanguageSettingsProvider extends AbstractExecutableExtensionBase implements ILanguageSettingsProvider { + @Override public List getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) { return null; } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsEditableProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsEditableProvider.java index 3bb5d309dce..a65fda22cba 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsEditableProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsEditableProvider.java @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright (c) 2009, 2009 Andrew Gvozdev (Quoin Inc.) and others. + * Copyright (c) 2009, 2011 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 (Quoin Inc.) - initial API and implementation + * Andrew Gvozdev - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.core.language.settings.providers; @@ -28,7 +28,7 @@ public interface ILanguageSettingsEditableProvider extends ILanguageSettingsProv public void setSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId, List entries); public boolean isEmpty(); public void clear(); - + public ILanguageSettingsEditableProvider cloneShallow() throws CloneNotSupportedException; public ILanguageSettingsEditableProvider clone() throws CloneNotSupportedException; } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsProvider.java index 05b1b657ed6..7273b9141aa 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsProvider.java @@ -24,7 +24,7 @@ import org.eclipse.core.resources.IResource; * This interface is used to deliver additions to compiler options such as * include paths (-I) or preprocessor defines (-D) and others (see * {@link ICSettingEntry#INCLUDE_PATH} and other kinds). - *
    + *

    * To define a provider like that use extension point * {@code org.eclipse.cdt.core.LanguageSettingsProvider} and implement this * interface. CDT provides a few general use implementations such as diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsBaseProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsBaseProvider.java index 03e049eeb95..d1709352b7a 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsBaseProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsBaseProvider.java @@ -18,15 +18,17 @@ import java.util.List; import org.eclipse.cdt.core.AbstractExecutableExtensionBase; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; +import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsStorage; +import org.eclipse.cdt.internal.core.settings.model.SettingsModelMessages; import org.eclipse.core.resources.IResource; /** * {@code LanguageSettingsBaseProvider} is a basic implementation of {@link ILanguageSettingsProvider} - * defined in {@code org.eclipse.cdt.core.LanguageSettingsProvider} extension point. - * + * for the extensions defined by {@code org.eclipse.cdt.core.LanguageSettingsProvider} extension point. + * * This implementation supports "static" list of entries for languages specified in - * the extension point. - * + * the extension point. + * * @since 6.0 */ public class LanguageSettingsBaseProvider extends AbstractExecutableExtensionBase implements ILanguageSettingsProvider { @@ -43,11 +45,12 @@ public class LanguageSettingsBaseProvider extends AbstractExecutableExtensionBas * Default constructor. */ public LanguageSettingsBaseProvider() { + super(); } /** - * Constructor. Creates an "empty" provider. - * + * Constructor. Creates an "empty" non-configured provider. + * * @param id - id of the provider. * @param name - name of the provider to be presented to a user. */ @@ -57,7 +60,7 @@ public class LanguageSettingsBaseProvider extends AbstractExecutableExtensionBas /** * Constructor. - * + * * @param id - id of the provider. * @param name - name of the provider to be presented to a user. * @param languages - list of languages the {@code entries} provided for. @@ -66,15 +69,16 @@ public class LanguageSettingsBaseProvider extends AbstractExecutableExtensionBas * @param entries - the list of language settings entries this provider provides. * If {@code null} is passed, the provider creates an empty list. */ - public LanguageSettingsBaseProvider(String id, String name, List languages, List entries) { + public LanguageSettingsBaseProvider(String id, String name, List languages, + List entries) { super(id, name); this.languageScope = languages!=null ? new ArrayList(languages) : null; - this.entries = cloneList(entries); + this.entries = getPooledList(entries); } /** * Constructor. - * + * * @param id - id of the provider. * @param name - name of the provider to be presented to a user. * @param languages - list of languages the {@code entries} provided for. @@ -85,10 +89,11 @@ public class LanguageSettingsBaseProvider extends AbstractExecutableExtensionBas * @param customParameter - a custom parameter as the means to customize * providers extending this class. */ - public LanguageSettingsBaseProvider(String id, String name, List languages, List entries, String customParameter) { + public LanguageSettingsBaseProvider(String id, String name, List languages, + List entries, String customParameter) { super(id, name); this.languageScope = languages!=null ? new ArrayList(languages) : null; - this.entries = cloneList(entries); + this.entries = getPooledList(entries); this.customParameter = customParameter; } @@ -97,9 +102,9 @@ public class LanguageSettingsBaseProvider extends AbstractExecutableExtensionBas * the extension point is done in 2 steps. First, the class is created as * an executable extension using the default provider. Then this method is * used to configure the provider. - * - * FIXME It is not allowed to reconfigure the provider. - * + *

    + * It is not allowed to reconfigure the provider. + * * @param id - id of the provider. * @param name - name of the provider to be presented to a user. * @param languages - list of languages the {@code entries} provided for. @@ -109,46 +114,54 @@ public class LanguageSettingsBaseProvider extends AbstractExecutableExtensionBas * If {@code null} is passed, the provider creates an empty list. * @param customParameter - a custom parameter as the means to customize * providers extending this class from extension definition in {@code plugin.xml}. - * - * FIXME @throws UnsupportedOperationException if an attempt to reconfigure provider is made. + * + * @throws UnsupportedOperationException if an attempt to reconfigure provider is made. */ - public void configureProvider(String id, String name, List languages, List entries, String customParameter) { -// if (this.entries!=null) -// throw new UnsupportedOperationException(SettingsModelMessages.getString("LanguageSettingsBaseProvider.CanBeConfiguredOnlyOnce")); //$NON-NLS-1$ + public void configureProvider(String id, String name, List languages, + List entries, String customParameter) { + if (this.entries!=null) + throw new UnsupportedOperationException(SettingsModelMessages.getString("LanguageSettingsBaseProvider.CanBeConfiguredOnlyOnce")); //$NON-NLS-1$ setId(id); setName(name); this.languageScope = languages!=null ? new ArrayList(languages) : null; - this.entries = cloneList(entries); + this.entries = getPooledList(entries); this.customParameter = customParameter; } + private List getPooledList(List entries) { + if (entries != null) { + return LanguageSettingsStorage.getPooledList(entries); + } + return LanguageSettingsStorage.getPooledEmptyList(); + } + /** * {@inheritDoc} - * @param cfgDescription - configuration description. - * @param rc - resource such as file or folder. + * * @param languageId - language id. If {@code null}, then entries defined for * the language scope are returned. See {@link #getLanguageScope()} + * + * @return unmodifiable list of setting entries or {@code null} if no settings defined. + * the list is internally pooled and guaranteed to be the same object for equal + * lists. */ @Override - public List getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) { - if (languageScope==null) { - if (entries==null) - return null; - return Collections.unmodifiableList(entries); + public List getSettingEntries(ICConfigurationDescription cfgDescription, + IResource rc, String languageId) { + if (languageScope == null) { + return entries; } for (String lang : languageScope) { if (lang.equals(languageId)) { - if (entries==null) - return null; - return Collections.unmodifiableList(entries); + return entries; } } return null; } /** - * @return the list of languages this provider provides for. + * @return the unmodifiable list of languages this provider provides for. * If {@code null}, the provider provides for any language. */ public List getLanguageScope() { @@ -163,13 +176,4 @@ public class LanguageSettingsBaseProvider extends AbstractExecutableExtensionBas public String getCustomParameter() { return customParameter; } - - /** - * @param entries - * @return copy of the list of the entries. - */ - private List cloneList(List entries) { - return entries!=null ? new ArrayList(entries) : null; - } - } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ScannerDiscoveryLegacySupport.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ScannerDiscoveryLegacySupport.java index df9429f4770..be5c8f611cc 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ScannerDiscoveryLegacySupport.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ScannerDiscoveryLegacySupport.java @@ -26,7 +26,7 @@ import org.osgi.service.prefs.Preferences; /** * Collection of utilities for legacy support of older Scanner Discovery functionality. * This class is temporary and not intended to be used by clients. - * + * * @noextend This class is not intended to be subclassed by clients. * @noinstantiate This class is not intended to be instantiated by clients. */ @@ -99,7 +99,7 @@ public class ScannerDiscoveryLegacySupport { * Returns the values of scanner discovery profiles (scannerConfigDiscoveryProfileId) which were deprecated * and replaced with language settings providers in plugin.xml. * This (temporary) function serves as fail-safe switch during the transition. - * + * * @param id - can be id of either org.eclipse.cdt.managedbuilder.internal.core.InputType * or org.eclipse.cdt.managedbuilder.internal.core.ToolChain. * @return legacy scannerConfigDiscoveryProfileId. @@ -108,8 +108,9 @@ public class ScannerDiscoveryLegacySupport { public static String getDeprecatedLegacyProfiles(String id) { if (legacyProfiles == null) { legacyProfiles = new HashMap(); - + // InputTypes + // TODO -doublecheck // legacyProfiles.put(inputTypeId, scannerConfigDiscoveryProfileId); legacyProfiles.put("cdt.managedbuild.tool.gnu.c.compiler.input", "org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileC|org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile"); legacyProfiles.put("cdt.managedbuild.tool.gnu.cpp.compiler.input", "org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileCPP|org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile"); @@ -118,11 +119,12 @@ public class ScannerDiscoveryLegacySupport { legacyProfiles.put("cdt.managedbuild.tool.xlc.c.compiler.input", "org.eclipse.cdt.managedbuilder.xlc.core.XLCManagedMakePerProjectProfile"); legacyProfiles.put("cdt.managedbuild.tool.xlc.cpp.c.compiler.input", "org.eclipse.cdt.managedbuilder.xlc.core.XLCManagedMakePerProjectProfile"); legacyProfiles.put("cdt.managedbuild.tool.xlc.cpp.compiler.input", "org.eclipse.cdt.managedbuilder.xlc.core.XLCManagedMakePerProjectProfileCPP"); - + // Toolchains + // TODO -doublecheck // legacyProfiles.put(toolchainId, scannerConfigDiscoveryProfileId); } - + return legacyProfiles.get(id); } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java index 5072a372952..f0ffa918ff1 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java @@ -71,7 +71,6 @@ public class LanguageSettingsExtensionManager { loadProviderExtensions(); } catch (Throwable e) { CCorePlugin.log("Error loading language settings providers extensions", e); //$NON-NLS-1$ - } finally { } } @@ -79,7 +78,7 @@ public class LanguageSettingsExtensionManager { * Load language settings providers contributed via the extension point. */ synchronized private static void loadProviderExtensions() { - // sort by name - for the providers taken from platform extensions + // sort by name - the providers defined via extensions are kept in separate list sorted Set sortedProviders = new TreeSet( new Comparator() { @Override @@ -111,7 +110,7 @@ public class LanguageSettingsExtensionManager { for (IExtension ext : extensions) { for (IConfigurationElement cfgEl : ext.getConfigurationElements()) { ILanguageSettingsProvider provider = null; - String id=null; + String id = null; try { if (cfgEl.getName().equals(ELEM_PROVIDER)) { id = determineAttributeValue(cfgEl, ATTR_ID); @@ -169,8 +168,8 @@ public class LanguageSettingsExtensionManager { for (IConfigurationElement ceLang : ce.getChildren(ELEM_LANGUAGE_SCOPE)) { String langId = determineAttributeValue(ceLang, ATTR_ID); - if (langId.trim().length()>0) { - if (languages==null) { + if (langId.length() > 0) { + if (languages == null) { languages = new ArrayList(); } languages.add(langId); @@ -192,8 +191,9 @@ public class LanguageSettingsExtensionManager { ICLanguageSettingEntry entry = (ICLanguageSettingEntry) CDataUtil.createEntry( entryKind, entryName, entryValue, null, flags); - if (entries == null) + if (entries == null) { entries = new ArrayList(); + } entries.add(entry); } catch (Exception e) { @@ -213,7 +213,7 @@ public class LanguageSettingsExtensionManager { * Creates empty non-configured provider from extension point definition. The method will * inspect extension registry for extension point "org.eclipse.cdt.core.LanguageSettingsProvider" * to determine bundle and instantiate the class. - * ID and name of provider are assigned from first extension point encountered. + * ID and name of provider are assigned from the first encountered extension point specifying the class. * * @param className - full qualified class name of provider. * @param registry - extension registry diff --git a/core/org.eclipse.cdt.core/schema/LanguageSettingsProvider.exsd b/core/org.eclipse.cdt.core/schema/LanguageSettingsProvider.exsd index a384595a320..a8348b44e73 100644 --- a/core/org.eclipse.cdt.core/schema/LanguageSettingsProvider.exsd +++ b/core/org.eclipse.cdt.core/schema/LanguageSettingsProvider.exsd @@ -65,7 +65,8 @@ A fully qualified name of the Java class that implements <samp>org.eclipse.cdt.core.settings.model.ILanguageSettingsProvider</samp> interface. If empty, <samp>org.eclipse.cdt.core.language.settings.providers.LanguageSettingsBaseProvider</samp> is used by default which provides basic functionality defined by this extension point. -If there is a need to configure a provider, attribute parameter could be used in a class extending <samp>LanguageSettingsBaseProvider</samp>. +If there is a need to configure a provider in more deliberate way, attribute <samp>parameter</samp> could be used in a class extending <samp>LanguageSettingsBaseProvider</samp>. +Default constructor (constructor without arguments) of this class must be public and the package be exported in order to be able to instantiate via extension point. @@ -89,7 +90,7 @@ If there is a need to configure a provider, attribute parameter could be used in - A custom parameter to initialize provider. Used to deliver command for GCCBuiltinSpecsDetector as an example. + A custom parameter to initialize provider. For example, used to deliver command for GCCBuiltinSpecsDetector. @@ -256,7 +257,7 @@ For those cases where contributed settings entries (representing the compiler op - Copyright (c) 2009, 2010 Andrew Gvozdev (Quoin Inc.) and others. + Copyright (c) 2009, 2011 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 diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/AbstractExecutableExtensionBase.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/AbstractExecutableExtensionBase.java index d56988056f6..f371e85d1d0 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/AbstractExecutableExtensionBase.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/AbstractExecutableExtensionBase.java @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Andrew Gvozdev (Quoin Inc.) and others. + * Copyright (c) 2009, 2011 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 (Quoin Inc.) - initial API and implementation + * Andrew Gvozdev - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.core; @@ -19,7 +19,7 @@ package org.eclipse.cdt.core; public abstract class AbstractExecutableExtensionBase { private String fId; private String fName; - + /** * Default constructor will initialize with the name of the class * using reflection mechanism. From 0962b1efbb299158dc95b4ad7bd4797818c30555 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Sat, 26 Nov 2011 19:16:28 -0500 Subject: [PATCH 069/120] ILanguageSettingsBroadcastingProvider introduced, some code maintenance --- .../MBSLanguageSettingsProvider.java | 7 +- .../LanguageSettingsExtensionsTests.java | 25 ++- .../LanguageSettingsListenersTests.java | 202 +++++++++--------- .../LanguageSettingsManagerTests.java | 25 +-- ...nguageSettingsPersistenceProjectTests.java | 65 +++--- ...ILanguageSettingsBroadcastingProvider.java | 32 +++ .../ILanguageSettingsEditableProvider.java | 12 +- .../providers/ILanguageSettingsProvider.java | 4 +- .../LanguageSettingsGenericProvider.java | 28 +++ .../LanguageSettingsManager_TBD.java | 9 +- .../LanguageSettingsSerializableProvider.java | 13 +- .../LanguageSettingsExtensionManager.java | 6 + .../LanguageSettingsProvidersSerializer.java | 12 +- .../providers/LanguageSettingsEntriesTab.java | 30 +-- .../LanguageSettingsProviderTab.java | 15 +- ...anguageSettingsProvidersLabelProvider.java | 10 +- .../UserLanguageSettingsProvider.java | 8 +- 17 files changed, 279 insertions(+), 224 deletions(-) create mode 100644 core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsBroadcastingProvider.java create mode 100644 core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsGenericProvider.java diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/MBSLanguageSettingsProvider.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/MBSLanguageSettingsProvider.java index 3e95c6ca3a3..5f343e9382d 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/MBSLanguageSettingsProvider.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/MBSLanguageSettingsProvider.java @@ -15,7 +15,7 @@ import java.util.ArrayList; import java.util.List; import org.eclipse.cdt.core.AbstractExecutableExtensionBase; -import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsBroadcastingProvider; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICFileDescription; import org.eclipse.cdt.core.settings.model.ICFolderDescription; @@ -27,9 +27,7 @@ import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IPath; -//public class MBSLanguageSettingsProvider extends AbstractExecutableExtensionBase implements ILanguageSettingsEditableProvider { -public class MBSLanguageSettingsProvider extends AbstractExecutableExtensionBase implements ILanguageSettingsProvider { - +public class MBSLanguageSettingsProvider extends AbstractExecutableExtensionBase implements ILanguageSettingsBroadcastingProvider { @Override public List getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) { @@ -92,6 +90,7 @@ public class MBSLanguageSettingsProvider extends AbstractExecutableExtensionBase return array; } + @Override public void setSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId, List entries) { diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java index 58208dade1b..2869db7d782 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Andrew Gvozdev and others. + * Copyright (c) 2009, 2011 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 @@ -35,16 +35,19 @@ import org.eclipse.core.runtime.Path; */ public class LanguageSettingsExtensionsTests extends BaseTestCase { // These should match corresponding entries defined in plugin.xml - private static final String EXTENSION_BASE_PROVIDER_ID = "org.eclipse.cdt.core.tests.language.settings.base.provider"; - private static final String EXTENSION_BASE_PROVIDER_NAME = "Test Plugin Mock Language Settings Base Provider"; - private static final String EXTENSION_BASE_PROVIDER_LANG_ID = "org.eclipse.cdt.core.tests.language.id"; - private static final String EXTENSION_BASE_PROVIDER_PARAMETER = "custom parameter"; - private static final String EXTENSION_CUSTOM_PROVIDER_ID = "org.eclipse.cdt.core.tests.custom.language.settings.provider"; - private static final String EXTENSION_CUSTOM_PROVIDER_NAME = "Test Plugin Mock Language Settings Provider"; - private static final String EXTENSION_BASE_SUBCLASS_PROVIDER_ID = "org.eclipse.cdt.core.tests.language.settings.base.provider.subclass"; - private static final String EXTENSION_BASE_SUBCLASS_PROVIDER_PARAMETER = "custom parameter subclass"; - private static final String EXTENSION_SERIALIZABLE_PROVIDER_ID = "org.eclipse.cdt.core.tests.custom.serializable.language.settings.provider"; - private static final String EXTENSION_EDITABLE_PROVIDER_ID = "org.eclipse.cdt.core.tests.custom.editable.language.settings.provider"; + /*package*/ static final String EXTENSION_BASE_PROVIDER_ID = "org.eclipse.cdt.core.tests.language.settings.base.provider"; + /*package*/ static final String EXTENSION_BASE_PROVIDER_NAME = "Test Plugin Mock Language Settings Base Provider"; + /*package*/ static final String EXTENSION_BASE_PROVIDER_LANG_ID = "org.eclipse.cdt.core.tests.language.id"; + /*package*/ static final String EXTENSION_BASE_PROVIDER_PARAMETER = "custom parameter"; + /*package*/ static final String EXTENSION_CUSTOM_PROVIDER_ID = "org.eclipse.cdt.core.tests.custom.language.settings.provider"; + /*package*/ static final String EXTENSION_CUSTOM_PROVIDER_NAME = "Test Plugin Mock Language Settings Provider"; + /*package*/ static final String EXTENSION_BASE_SUBCLASS_PROVIDER_ID = "org.eclipse.cdt.core.tests.language.settings.base.provider.subclass"; + /*package*/ static final String EXTENSION_BASE_SUBCLASS_PROVIDER_PARAMETER = "custom parameter subclass"; + /*package*/ static final String EXTENSION_SERIALIZABLE_PROVIDER_ID = "org.eclipse.cdt.core.tests.custom.serializable.language.settings.provider"; + /*package*/ static final String EXTENSION_SERIALIZABLE_PROVIDER_NAME = "Test Plugin Mock Serializable Language Settings Provider"; + /*package*/ static final String EXTENSION_EDITABLE_PROVIDER_ID = "org.eclipse.cdt.core.tests.custom.editable.language.settings.provider"; + /*package*/ static final String EXTENSION_EDITABLE_PROVIDER_NAME = "Test Plugin Mock Editable Language Settings Provider"; + /*package*/ static final String EXTENSION_REGISTERER_PROVIDER_ID = "org.eclipse.cdt.core.tests.language.settings.listener.registerer.provider"; // These are made up private static final String PROVIDER_0 = "test.provider.0.id"; diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsListenersTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsListenersTests.java index bb2915a5359..199fc827abd 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsListenersTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsListenersTests.java @@ -32,20 +32,20 @@ import org.eclipse.core.resources.IProject; * Test cases testing LanguageSettingsProvider functionality */ public class LanguageSettingsListenersTests extends BaseTestCase { - // Must match provider id defined as extension point - private static final String EXTENSION_REGISTERER_PROVIDER_ID = "org.eclipse.cdt.core.tests.language.settings.listener.registerer.provider"; - private static final String EXTENSION_EDITABLE_PROVIDER_ID = "org.eclipse.cdt.core.tests.custom.editable.language.settings.provider"; - + // Must match provider id defined as extension point + private static final String EXTENSION_REGISTERER_PROVIDER_ID = LanguageSettingsExtensionsTests.EXTENSION_REGISTERER_PROVIDER_ID; + private static final String EXTENSION_EDITABLE_PROVIDER_ID = LanguageSettingsExtensionsTests.EXTENSION_EDITABLE_PROVIDER_ID; + private static final String PROVIDER_1 = "test.provider.1.id"; private static final String PROVIDER_NAME_1 = "test.provider.1.name"; private static final String PROVIDER_CUSTOM_GLOBAL = "test.provider.custom.global.id"; private static final String PROVIDER_CUSTOM_GLOBAL_NAME = "test.provider.custom.global.name"; - + private static final CMacroEntry SAMPLE_LSE = new CMacroEntry("MACRO", "value",0); private class MockLanguageSettingsChangeListener implements ILanguageSettingsChangeListener { private int count = 0; private ILanguageSettingsChangeEvent lastEvent = null; - + @Override public void handleEvent(ILanguageSettingsChangeEvent event) { count++; @@ -55,12 +55,12 @@ public class LanguageSettingsListenersTests extends BaseTestCase { public int getCount() { return count; } - + public void resetCount() { count = 0; lastEvent = null; } - + public ILanguageSettingsChangeEvent getLastEvent() { return lastEvent; } @@ -114,7 +114,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase { // global listeners providers get registered only lazily assertEquals(0, MockListenerRegisterer.getCount(EXTENSION_REGISTERER_PROVIDER_ID)); } - + /** */ public void testListenerRegisterer_OneOwnedByCfg() throws Exception { @@ -164,7 +164,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase { "org.eclipse.cdt.core.tests.configuration.id.1", "org.eclipse.cdt.core.tests.configuration.id.2", }); - + { // get project descriptions ICProjectDescription writableProjDescription = CoreModel.getDefault().getProjectDescription(project); @@ -173,7 +173,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase { assertEquals(2, cfgDescriptions.length); ICConfigurationDescription cfgDescription1 = cfgDescriptions[0]; ICConfigurationDescription cfgDescription2 = cfgDescriptions[1]; - + { // create a provider 1 ILanguageSettingsProvider mockProvider = new MockListenerRegisterer(PROVIDER_1, PROVIDER_NAME_1); @@ -192,7 +192,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase { List storedProviders = cfgDescription2.getLanguageSettingProviders(); assertEquals(1, storedProviders.size()); } - + // write to project description CoreModel.getDefault().setProjectDescription(project, writableProjDescription); assertEquals(2, MockListenerRegisterer.getCount(PROVIDER_1)); @@ -211,9 +211,9 @@ public class LanguageSettingsListenersTests extends BaseTestCase { project.delete(true, null); assertEquals(0, MockListenerRegisterer.getCount(PROVIDER_1)); } - + } - + /** */ public void testListenerRegisterer_OneGlobal() throws Exception { @@ -225,7 +225,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase { ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; - + // add global provider ILanguageSettingsProvider workspaceProvider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_REGISTERER_PROVIDER_ID); List providers = new ArrayList(); @@ -233,7 +233,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase { cfgDescription.setLanguageSettingProviders(providers); List storedProviders = cfgDescription.getLanguageSettingProviders(); assertEquals(1, storedProviders.size()); - + // write to project description CoreModel.getDefault().setProjectDescription(project, writableProjDescription); assertEquals(1, MockListenerRegisterer.getCount(EXTENSION_REGISTERER_PROVIDER_ID)); @@ -252,9 +252,9 @@ public class LanguageSettingsListenersTests extends BaseTestCase { project.delete(true, null); assertEquals(0, MockListenerRegisterer.getCount(EXTENSION_REGISTERER_PROVIDER_ID)); } - + } - + /** */ public void testListenerRegisterer_TwoGlobal() throws Exception { @@ -262,7 +262,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase { "org.eclipse.cdt.core.tests.configuration.id.1", "org.eclipse.cdt.core.tests.configuration.id.2", }); - + { // retrieve global provider ILanguageSettingsProvider workspaceProvider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_REGISTERER_PROVIDER_ID); @@ -273,7 +273,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase { assertEquals(2, cfgDescriptions.length); ICConfigurationDescription cfgDescription1 = cfgDescriptions[0]; ICConfigurationDescription cfgDescription2 = cfgDescriptions[1]; - + { // add global provider to configuration 1 List providers = new ArrayList(); @@ -309,7 +309,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase { assertEquals(0, MockListenerRegisterer.getCount(EXTENSION_REGISTERER_PROVIDER_ID)); } } - + /** */ public void testListenerRegisterer_TwoGlobalMinusOne() throws Exception { @@ -317,7 +317,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase { "org.eclipse.cdt.core.tests.configuration.id.1", "org.eclipse.cdt.core.tests.configuration.id.2", }); - + { // retrieve workspace provider ILanguageSettingsProvider workspaceProvider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_REGISTERER_PROVIDER_ID); @@ -328,7 +328,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase { assertEquals(2, cfgDescriptions.length); ICConfigurationDescription cfgDescription1 = cfgDescriptions[0]; ICConfigurationDescription cfgDescription2 = cfgDescriptions[1]; - + { // add global provider to configuration 1 List providers = new ArrayList(); @@ -359,7 +359,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase { assertEquals(2, cfgDescriptions.length); ICConfigurationDescription cfgDescription1 = cfgDescriptions[0]; ICConfigurationDescription cfgDescription2 = cfgDescriptions[1]; - + { // remove global provider from configuration 1 List providers = new ArrayList(); @@ -377,7 +377,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase { assertEquals(0, MockListenerRegisterer.getCount(EXTENSION_REGISTERER_PROVIDER_ID)); } } - + /** */ public void testListenerRegisterer_GlobalProviderTwoProjects() throws Exception { @@ -390,7 +390,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase { ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; - + // add global provider ILanguageSettingsProvider workspaceProvider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_REGISTERER_PROVIDER_ID); List providers = new ArrayList(); @@ -398,7 +398,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase { cfgDescription.setLanguageSettingProviders(providers); List storedProviders = cfgDescription.getLanguageSettingProviders(); assertEquals(1, storedProviders.size()); - + // write to project description CoreModel.getDefault().setProjectDescription(project_1, writableProjDescription); assertEquals(1, MockListenerRegisterer.getCount(EXTENSION_REGISTERER_PROVIDER_ID)); @@ -413,7 +413,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase { ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; - + // add global provider ILanguageSettingsProvider workspaceProvider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_REGISTERER_PROVIDER_ID); List providers = new ArrayList(); @@ -421,12 +421,12 @@ public class LanguageSettingsListenersTests extends BaseTestCase { cfgDescription.setLanguageSettingProviders(providers); List storedProviders = cfgDescription.getLanguageSettingProviders(); assertEquals(1, storedProviders.size()); - + // write to project description CoreModel.getDefault().setProjectDescription(project_2, writableProjDescription); assertEquals(1, MockListenerRegisterer.getCount(EXTENSION_REGISTERER_PROVIDER_ID)); } - + { // close project 1 project_1.close(null); @@ -437,7 +437,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase { project_2.close(null); assertEquals(0, MockListenerRegisterer.getCount(EXTENSION_REGISTERER_PROVIDER_ID)); } - + } /** @@ -466,17 +466,17 @@ public class LanguageSettingsListenersTests extends BaseTestCase { assertEquals(0, MockListenerRegisterer.getCount(PROVIDER_CUSTOM_GLOBAL)); } } - + /** */ public void testListenerRegisterer_GlobalProviderAddRemoveOutsideTheProject() throws Exception { 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 workspaceProvidersOriginal = LanguageSettingsManager.getWorkspaceProviders(); IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName()); @@ -487,14 +487,14 @@ public class LanguageSettingsListenersTests extends BaseTestCase { ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; - + // add global provider List providers = new ArrayList(); providers.add(workspaceProvider); cfgDescription.setLanguageSettingProviders(providers); List storedProviders = cfgDescription.getLanguageSettingProviders(); assertEquals(1, storedProviders.size()); - + // write to project description CoreModel.getDefault().setProjectDescription(project, writableProjDescription); // the global custom provider has not been added yet @@ -510,19 +510,19 @@ public class LanguageSettingsListenersTests extends BaseTestCase { assertEquals(1, MockListenerRegisterer.getCount(PROVIDER_CUSTOM_GLOBAL)); } { - // remove global provider + // remove global provider List providers = new ArrayList(workspaceProvidersOriginal); LanguageSettingsManager.setWorkspaceProviders(providers); assertEquals(0, MockListenerRegisterer.getCount(PROVIDER_CUSTOM_GLOBAL)); } - + { // close project project.close(null); assertEquals(0, MockListenerRegisterer.getCount(PROVIDER_CUSTOM_GLOBAL)); } } - + /** */ public void testNotification_cfgProvider_AddEmptyProvider() throws Exception { @@ -545,12 +545,12 @@ public class LanguageSettingsListenersTests extends BaseTestCase { // write to project description CoreModel.getDefault().setProjectDescription(project, writableProjDescription); } - + // register mock listener to inspect the notifications LanguageSettingsProvidersSerializer.registerLanguageSettingsChangeListener(mockLseListener); assertEquals(0, mockLseListener.getCount()); assertEquals(null, mockLseListener.getLastEvent()); - + // Add empty provider { // get project descriptions @@ -559,7 +559,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase { ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; - + // create a provider and add to cfgDescription ILanguageSettingsProvider mockProvider = new MockLanguageSettingsEditableProvider(PROVIDER_1, PROVIDER_NAME_1); List providers = new ArrayList(); @@ -567,16 +567,16 @@ public class LanguageSettingsListenersTests extends BaseTestCase { cfgDescription.setLanguageSettingProviders(providers); List storedProviders = cfgDescription.getLanguageSettingProviders(); assertEquals(1, storedProviders.size()); - + // write to project description CoreModel.getDefault().setProjectDescription(project, writableProjDescription); } - + // No notifications expected assertEquals(0, mockLseListener.getCount()); assertEquals(null, mockLseListener.getLastEvent()); } - + /** */ public void testNotification_cfgProvider_AddNonEmptyProvider() throws Exception { @@ -589,22 +589,22 @@ public class LanguageSettingsListenersTests extends BaseTestCase { ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; - + // clear providers List providers = new ArrayList(); cfgDescription.setLanguageSettingProviders(providers); List storedProviders = cfgDescription.getLanguageSettingProviders(); assertEquals(0, storedProviders.size()); - + // write to project description CoreModel.getDefault().setProjectDescription(project, writableProjDescription); } - + // register mock listener to inspect the notifications LanguageSettingsProvidersSerializer.registerLanguageSettingsChangeListener(mockLseListener); assertEquals(0, mockLseListener.getCount()); assertEquals(null, mockLseListener.getLastEvent()); - + // Add non-empty provider { // get project descriptions @@ -614,7 +614,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase { assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; String cfgDescriptionId = cfgDescription.getId(); - + // create a provider and add entries MockLanguageSettingsEditableProvider mockProvider = new MockLanguageSettingsEditableProvider(PROVIDER_1, PROVIDER_NAME_1); List entries = new ArrayList(); @@ -625,7 +625,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase { cfgDescription.setLanguageSettingProviders(providers); List storedProviders = cfgDescription.getLanguageSettingProviders(); assertEquals(1, storedProviders.size()); - + // write to project description CoreModel.getDefault().setProjectDescription(project, writableProjDescription); @@ -633,18 +633,18 @@ public class LanguageSettingsListenersTests extends BaseTestCase { 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]); } } - + /** */ public void testNotification_cfgProvider_SerializeEntries() throws Exception { IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName()); - + // add the mock provider { // get project descriptions @@ -653,18 +653,18 @@ public class LanguageSettingsListenersTests extends BaseTestCase { ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; - + // create a provider and add to cfgDescription List providers = new ArrayList(); providers.add(new MockLanguageSettingsEditableProvider(PROVIDER_1, PROVIDER_NAME_1)); cfgDescription.setLanguageSettingProviders(providers); List storedProviders = cfgDescription.getLanguageSettingProviders(); assertEquals(1, storedProviders.size()); - + // write to project description CoreModel.getDefault().setProjectDescription(project, writableProjDescription); } - + // register mock listener to inspect the notifications LanguageSettingsProvidersSerializer.registerLanguageSettingsChangeListener(mockLseListener); assertEquals(0, mockLseListener.getCount()); @@ -679,7 +679,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase { assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; String cfgDescriptionId = cfgDescription.getId(); - + // Add entries List entries = new ArrayList(); entries.add(SAMPLE_LSE); @@ -690,25 +690,25 @@ public class LanguageSettingsListenersTests extends BaseTestCase { mockProvider.setSettingEntries(cfgDescription, project, null, entries); assertEquals(0, mockLseListener.getCount()); assertEquals(null, mockLseListener.getLastEvent()); - + // Serialize settings LanguageSettingsProvidersSerializer.serializeLanguageSettings(prjDescription); // inspect event 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]); } } - + /** */ public void testNotification_cfgProvider_SerializeEntriesConcurrent() throws Exception { IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName()); - + // add the mock provider { // get project descriptions @@ -717,25 +717,25 @@ public class LanguageSettingsListenersTests extends BaseTestCase { ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; - + // create a provider and add to cfgDescription List providers = new ArrayList(); providers.add(new MockLanguageSettingsEditableProvider(PROVIDER_1, PROVIDER_NAME_1)); cfgDescription.setLanguageSettingProviders(providers); List storedProviders = cfgDescription.getLanguageSettingProviders(); assertEquals(1, storedProviders.size()); - + // write to project description CoreModel.getDefault().setProjectDescription(project, writableProjDescription); } - + // register mock listener to inspect the notifications LanguageSettingsProvidersSerializer.registerLanguageSettingsChangeListener(mockLseListener); assertEquals(0, mockLseListener.getCount()); assertEquals(null, mockLseListener.getLastEvent()); - + // Change the provider's entries concurrently - + // get project descriptions ICProjectDescription prjDescription_1 = CoreModel.getDefault().getProjectDescription(project, false); assertNotNull(prjDescription_1); @@ -746,7 +746,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase { assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescriptionWritable = cfgDescriptions[0]; String cfgDescriptionId = cfgDescriptionWritable.getId(); - + // Add entries List entries = new ArrayList(); entries.add(SAMPLE_LSE); @@ -755,19 +755,19 @@ public class LanguageSettingsListenersTests extends BaseTestCase { assertTrue(providers.get(0) instanceof MockLanguageSettingsEditableProvider); MockLanguageSettingsEditableProvider mockProvider = (MockLanguageSettingsEditableProvider) providers.get(0); mockProvider.setSettingEntries(cfgDescriptionWritable, project, null, entries); - + // reset count mockLseListener.resetCount(); assertEquals(0, mockLseListener.getCount()); assertNull(mockLseListener.getLastEvent()); - + // Serialize settings LanguageSettingsProvidersSerializer.serializeLanguageSettings(prjDescription_1); // inspect event 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]); @@ -777,7 +777,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase { assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescriptionWritable = cfgDescriptions[0]; String cfgDescriptionId = cfgDescriptionWritable.getId(); - + // Add same entries List entries = new ArrayList(); entries.add(SAMPLE_LSE); @@ -786,12 +786,12 @@ public class LanguageSettingsListenersTests extends BaseTestCase { assertTrue(providers.get(0) instanceof MockLanguageSettingsEditableProvider); MockLanguageSettingsEditableProvider mockProvider = (MockLanguageSettingsEditableProvider) providers.get(0); mockProvider.setSettingEntries(cfgDescriptionWritable, project, null, entries); - + // reset count mockLseListener.resetCount(); assertEquals(0, mockLseListener.getCount()); assertNull(mockLseListener.getLastEvent()); - + // Serialize settings LanguageSettingsProvidersSerializer.serializeLanguageSettings(prjDescription_2); // inspect event @@ -800,7 +800,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase { assertNull(event); } } - + /** */ public void testNotification_globalProvider_AddEmptyProvider() throws Exception { @@ -823,12 +823,12 @@ public class LanguageSettingsListenersTests extends BaseTestCase { // write to project description CoreModel.getDefault().setProjectDescription(project, writableProjDescription); } - + // register mock listener to inspect the notifications LanguageSettingsProvidersSerializer.registerLanguageSettingsChangeListener(mockLseListener); assertEquals(0, mockLseListener.getCount()); assertEquals(null, mockLseListener.getLastEvent()); - + // Add empty global provider { // get project descriptions @@ -837,7 +837,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase { ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; - + // retrieve a global provider ILanguageSettingsProvider wspProvider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_EDITABLE_PROVIDER_ID); assertNotNull(wspProvider); @@ -852,16 +852,16 @@ public class LanguageSettingsListenersTests extends BaseTestCase { cfgDescription.setLanguageSettingProviders(providers); List storedProviders = cfgDescription.getLanguageSettingProviders(); assertEquals(1, storedProviders.size()); - + // write to project description CoreModel.getDefault().setProjectDescription(project, writableProjDescription); } - + // No notifications expected assertEquals(0, mockLseListener.getCount()); assertEquals(null, mockLseListener.getLastEvent()); } - + /** */ public void testNotification_globalProvider_AddNonEmptyProvider() throws Exception { @@ -874,22 +874,22 @@ public class LanguageSettingsListenersTests extends BaseTestCase { ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; - + // clear providers List providers = new ArrayList(); cfgDescription.setLanguageSettingProviders(providers); List storedProviders = cfgDescription.getLanguageSettingProviders(); assertEquals(0, storedProviders.size()); - + // write to project description CoreModel.getDefault().setProjectDescription(project, writableProjDescription); } - + // register mock listener to inspect the notifications LanguageSettingsProvidersSerializer.registerLanguageSettingsChangeListener(mockLseListener); assertEquals(0, mockLseListener.getCount()); assertEquals(null, mockLseListener.getLastEvent()); - + // Add non-empty provider { // get project descriptions @@ -899,7 +899,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase { assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; String cfgDescriptionId = cfgDescription.getId(); - + // retrieve a global provider ILanguageSettingsProvider wspProvider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_EDITABLE_PROVIDER_ID); assertNotNull(wspProvider); @@ -925,21 +925,21 @@ public class LanguageSettingsListenersTests extends BaseTestCase { 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]); } } - + /** */ public void testNotification_globalProvider_SerializeEntries() throws Exception { IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName()); - + // register mock listener to inspect the notifications LanguageSettingsProvidersSerializer.registerLanguageSettingsChangeListener(mockLseListener); - + // Add empty global provider { // get project descriptions @@ -948,7 +948,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase { ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; - + // retrieve a global provider ILanguageSettingsProvider wspProvider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_EDITABLE_PROVIDER_ID); assertNotNull(wspProvider); @@ -963,7 +963,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase { cfgDescription.setLanguageSettingProviders(providers); List storedProviders = cfgDescription.getLanguageSettingProviders(); assertEquals(1, storedProviders.size()); - + // write to project description CoreModel.getDefault().setProjectDescription(project, writableProjDescription); } @@ -981,12 +981,12 @@ public class LanguageSettingsListenersTests extends BaseTestCase { entries.add(SAMPLE_LSE); ((MockLanguageSettingsEditableProvider) rawProvider).setSettingEntries(null, project, null, entries); assertEquals(SAMPLE_LSE, wspProvider.getSettingEntries(null, project, null).get(0)); - + // reset count mockLseListener.resetCount(); assertEquals(0, mockLseListener.getCount()); assertEquals(null, mockLseListener.getLastEvent()); - + // Serialize settings LanguageSettingsProvidersSerializer.serializeLanguageSettingsWorkspace(); @@ -997,12 +997,12 @@ public class LanguageSettingsListenersTests extends BaseTestCase { assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; String cfgDescriptionId = cfgDescription.getId(); - + // inspect event 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]); @@ -1016,15 +1016,15 @@ public class LanguageSettingsListenersTests extends BaseTestCase { assertTrue(rawProvider instanceof MockLanguageSettingsEditableProvider); // clear the provider again ((MockLanguageSettingsEditableProvider) rawProvider).clear(); - + // reset count mockLseListener.resetCount(); assertEquals(0, mockLseListener.getCount()); assertEquals(null, mockLseListener.getLastEvent()); - + // Serialize settings LanguageSettingsProvidersSerializer.serializeLanguageSettingsWorkspace(); - + // get cfgDescriptionId ICProjectDescription prjDescription = CoreModel.getDefault().getProjectDescription(project, false); assertNotNull(prjDescription); @@ -1032,12 +1032,12 @@ public class LanguageSettingsListenersTests extends BaseTestCase { assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; String cfgDescriptionId = cfgDescription.getId(); - + // inspect event 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]); diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java index 93012dd56c5..cde365d0471 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java @@ -42,9 +42,10 @@ import org.eclipse.core.runtime.Path; */ public class LanguageSettingsManagerTests extends BaseTestCase { // Those should match ids of plugin extensions defined in plugin.xml - private static final String EXTENSION_BASE_PROVIDER_ID = "org.eclipse.cdt.core.tests.language.settings.base.provider"; - private static final String EXTENSION_EDITABLE_PROVIDER_ID = "org.eclipse.cdt.core.tests.custom.editable.language.settings.provider"; - private static final String EXTENSION_EDITABLE_PROVIDER_NAME = "Test Plugin Mock Editable Language Settings Provider"; + private static final String EXTENSION_BASE_PROVIDER_ID = LanguageSettingsExtensionsTests.EXTENSION_BASE_PROVIDER_ID; + private static final String EXTENSION_SERIALIZABLE_PROVIDER_ID = LanguageSettingsExtensionsTests.EXTENSION_SERIALIZABLE_PROVIDER_ID; + private static final String EXTENSION_SERIALIZABLE_PROVIDER_NAME = LanguageSettingsExtensionsTests.EXTENSION_SERIALIZABLE_PROVIDER_NAME; + private static final String EXTENSION_EDITABLE_PROVIDER_ID = LanguageSettingsExtensionsTests.EXTENSION_EDITABLE_PROVIDER_ID; private static final IFile FILE_0 = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("/project/path0")); private static final String CFG_ID = "test.configuration.id"; @@ -688,14 +689,14 @@ public class LanguageSettingsManagerTests extends BaseTestCase { */ public void testWorkspaceProvider_Basic() throws Exception { // get workspace provider - ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_EDITABLE_PROVIDER_ID); - assertEquals(EXTENSION_EDITABLE_PROVIDER_ID, provider.getId()); - assertEquals(EXTENSION_EDITABLE_PROVIDER_NAME, provider.getName()); + ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_SERIALIZABLE_PROVIDER_ID); + assertEquals(EXTENSION_SERIALIZABLE_PROVIDER_ID, provider.getId()); + assertEquals(EXTENSION_SERIALIZABLE_PROVIDER_NAME, provider.getName()); // get raw provider ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); - assertEquals(EXTENSION_EDITABLE_PROVIDER_ID, rawProvider.getId()); - assertEquals(EXTENSION_EDITABLE_PROVIDER_NAME, rawProvider.getName()); + assertEquals(EXTENSION_SERIALIZABLE_PROVIDER_ID, rawProvider.getId()); + assertEquals(EXTENSION_SERIALIZABLE_PROVIDER_NAME, rawProvider.getName()); assertTrue(rawProvider instanceof LanguageSettingsSerializableProvider); // assert they are not the same object assertNotSame(provider, rawProvider); @@ -726,8 +727,8 @@ public class LanguageSettingsManagerTests extends BaseTestCase { * Test workspace providers equality. */ public void testWorkspaceProvider_Equals() throws Exception { - ILanguageSettingsProvider providerA = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_EDITABLE_PROVIDER_ID); - ILanguageSettingsProvider providerB = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_EDITABLE_PROVIDER_ID); + ILanguageSettingsProvider providerA = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_SERIALIZABLE_PROVIDER_ID); + ILanguageSettingsProvider providerB = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_SERIALIZABLE_PROVIDER_ID); assertEquals(providerA, providerB); } @@ -738,7 +739,7 @@ public class LanguageSettingsManagerTests extends BaseTestCase { // get sample workspace provider ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_EDITABLE_PROVIDER_ID); { - // check on its entries + // check on its entries (1 predefined entry via extension point) List entries = provider.getSettingEntries(null, null, null); assertEquals(1, entries.size()); // defined in the extension } @@ -771,7 +772,7 @@ public class LanguageSettingsManagerTests extends BaseTestCase { */ public void testWorkspaceProvider_ReplaceWithWorkspaceProvider() throws Exception { // get sample workspace provider - ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_EDITABLE_PROVIDER_ID); + ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_SERIALIZABLE_PROVIDER_ID); ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); assertNotSame(provider, rawProvider); diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java index 1d4b51c7438..d50ce050a5f 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java @@ -40,12 +40,13 @@ import org.w3c.dom.Element; * Test cases testing LanguageSettingsProvider functionality */ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { + // These should match extension points defined in plugin.xml + private static final String EXTENSION_BASE_PROVIDER_ID = LanguageSettingsExtensionsTests.EXTENSION_BASE_PROVIDER_ID; + private static final String EXTENSION_BASE_PROVIDER_NAME = LanguageSettingsExtensionsTests.EXTENSION_BASE_PROVIDER_NAME; + private static final String EXTENSION_SERIALIZABLE_PROVIDER_ID = LanguageSettingsExtensionsTests.EXTENSION_SERIALIZABLE_PROVIDER_ID; + private static final String LANGUAGE_SETTINGS_PROJECT_XML = ".settings/language.settings.xml"; private static final String LANGUAGE_SETTINGS_WORKSPACE_XML = "language.settings.xml"; - // Should match extension points defined in plugin.xml - private static final String EXTENSION_PROVIDER_ID = "org.eclipse.cdt.core.tests.language.settings.base.provider.subclass"; - private static final String EXTENSION_PROVIDER_NAME = "Test Plugin Mock Base Provider Subclass"; - private static final String EXTENSION_SERIALIZABLE_PROVIDER_ID = "org.eclipse.cdt.core.tests.custom.serializable.language.settings.provider"; private static final String CFG_ID = "test.configuration.id.0"; private static final String CFG_ID_2 = "test.configuration.id.2"; @@ -103,20 +104,6 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { } } - private class MockEditableProvider extends LanguageSettingsSerializableProvider implements ILanguageSettingsEditableProvider { - public MockEditableProvider(String id, String name) { - super(id, name); - } - @Override - public MockEditableProvider cloneShallow() throws CloneNotSupportedException { - return (MockEditableProvider) super.cloneShallow(); - } - @Override - public MockEditableProvider clone() throws CloneNotSupportedException { - return (MockEditableProvider) super.clone(); - } - } - /** * Constructor. * @param name - name of the test. @@ -200,7 +187,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { int originalSize = originalProviders.size(); // create new provider list - LanguageSettingsSerializableProvider mockProvider = new MockEditableProvider(PROVIDER_0, PROVIDER_NAME_0); + LanguageSettingsSerializableProvider mockProvider = new MockLanguageSettingsEditableProvider(PROVIDER_0, PROVIDER_NAME_0); List providers = new ArrayList(originalProviders); providers.add(mockProvider); assertTrue(originalSize != providers.size()); @@ -245,7 +232,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { ICConfigurationDescription cfgDescription = cfgDescriptions[0]; // create a provider - LanguageSettingsSerializableProvider mockProvider = new MockEditableProvider(PROVIDER_0, PROVIDER_NAME_0); + LanguageSettingsSerializableProvider mockProvider = new MockLanguageSettingsEditableProvider(PROVIDER_0, PROVIDER_NAME_0); mockProvider.setStoringEntriesInProjectArea(true); mockProvider.setSettingEntries(cfgDescription, null, null, entries); List providers = new ArrayList(); @@ -268,7 +255,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { List providers = cfgDescription.getLanguageSettingProviders(); assertEquals(1, providers.size()); ILanguageSettingsProvider loadedProvider = providers.get(0); - assertTrue(loadedProvider instanceof LanguageSettingsSerializableProvider); + assertTrue(loadedProvider instanceof MockLanguageSettingsEditableProvider); assertEquals(PROVIDER_0, loadedProvider.getId()); assertEquals(PROVIDER_NAME_0, loadedProvider.getName()); @@ -287,7 +274,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { List providers = cfgDescription.getLanguageSettingProviders(); assertEquals(1, providers.size()); ILanguageSettingsProvider loadedProvider = providers.get(0); - assertTrue(loadedProvider instanceof LanguageSettingsSerializableProvider); + assertTrue(loadedProvider instanceof MockLanguageSettingsEditableProvider); assertEquals(PROVIDER_0, loadedProvider.getId()); assertEquals(PROVIDER_NAME_0, loadedProvider.getName()); @@ -375,16 +362,16 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { public void testWorkspacePersistence_ShadowedExtensionProvider() throws Exception { { // get the raw extension provider - ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_PROVIDER_ID); + ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_BASE_PROVIDER_ID); ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); // confirm its type and name assertTrue(rawProvider instanceof LanguageSettingsBaseProvider); - assertEquals(EXTENSION_PROVIDER_ID, rawProvider.getId()); - assertEquals(EXTENSION_PROVIDER_NAME, rawProvider.getName()); + assertEquals(EXTENSION_BASE_PROVIDER_ID, rawProvider.getId()); + assertEquals(EXTENSION_BASE_PROVIDER_NAME, rawProvider.getName()); } { // replace extension provider - ILanguageSettingsProvider provider = new MockLanguageSettingsSerializableProvider(EXTENSION_PROVIDER_ID, PROVIDER_NAME_0); + ILanguageSettingsProvider provider = new MockLanguageSettingsSerializableProvider(EXTENSION_BASE_PROVIDER_ID, PROVIDER_NAME_0); List providers = new ArrayList(); providers.add(provider); // note that this will also serialize workspace providers @@ -392,10 +379,10 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { } { // doublecheck it's in the list - ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_PROVIDER_ID); + ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_BASE_PROVIDER_ID); ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); assertTrue(rawProvider instanceof MockLanguageSettingsSerializableProvider); - assertEquals(EXTENSION_PROVIDER_ID, rawProvider.getId()); + assertEquals(EXTENSION_BASE_PROVIDER_ID, rawProvider.getId()); assertEquals(PROVIDER_NAME_0, rawProvider.getName()); } @@ -403,10 +390,10 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { // re-load to check serialization LanguageSettingsProvidersSerializer.loadLanguageSettingsWorkspace(); - ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_PROVIDER_ID); + ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_BASE_PROVIDER_ID); ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); assertTrue(rawProvider instanceof MockLanguageSettingsSerializableProvider); - assertEquals(EXTENSION_PROVIDER_ID, rawProvider.getId()); + assertEquals(EXTENSION_BASE_PROVIDER_ID, rawProvider.getId()); assertEquals(PROVIDER_NAME_0, rawProvider.getName()); } @@ -416,21 +403,21 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { } { // doublecheck original one is in the list - ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_PROVIDER_ID); + ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_BASE_PROVIDER_ID); ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); assertTrue(rawProvider instanceof LanguageSettingsBaseProvider); - assertEquals(EXTENSION_PROVIDER_ID, rawProvider.getId()); - assertEquals(EXTENSION_PROVIDER_NAME, rawProvider.getName()); + assertEquals(EXTENSION_BASE_PROVIDER_ID, rawProvider.getId()); + assertEquals(EXTENSION_BASE_PROVIDER_NAME, rawProvider.getName()); } { // re-load to check serialization LanguageSettingsProvidersSerializer.loadLanguageSettingsWorkspace(); - ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_PROVIDER_ID); + ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_BASE_PROVIDER_ID); ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); assertTrue(rawProvider instanceof LanguageSettingsBaseProvider); - assertEquals(EXTENSION_PROVIDER_ID, rawProvider.getId()); - assertEquals(EXTENSION_PROVIDER_NAME, rawProvider.getName()); + assertEquals(EXTENSION_BASE_PROVIDER_ID, rawProvider.getId()); + assertEquals(EXTENSION_BASE_PROVIDER_NAME, rawProvider.getName()); } } @@ -674,7 +661,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { Element rootElement = null; // provider of other type (not LanguageSettingsSerializableProvider) defined as an extension - ILanguageSettingsProvider providerExt = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_PROVIDER_ID); + ILanguageSettingsProvider providerExt = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_BASE_PROVIDER_ID); { // create cfg description @@ -721,7 +708,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { Element rootElement = null; // provider set on workspace level overriding an extension - String idExt = EXTENSION_PROVIDER_ID; + String idExt = EXTENSION_BASE_PROVIDER_ID; ILanguageSettingsProvider providerExt = LanguageSettingsManager.getWorkspaceProvider(idExt); assertNotNull(providerExt); { @@ -791,7 +778,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { assertNotNull(cfgDescription); // 1. Provider reference to extension from plugin.xml - providerExt = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_PROVIDER_ID); + providerExt = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_BASE_PROVIDER_ID); // 2. TODO Provider reference to provider defined in the project diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsBroadcastingProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsBroadcastingProvider.java new file mode 100644 index 00000000000..8987647ad60 --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsBroadcastingProvider.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2011, 2011 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.core.language.settings.providers; + +import java.util.List; + +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; +import org.eclipse.core.resources.IResource; + +/** + * TODO + */ +public interface ILanguageSettingsBroadcastingProvider extends ILanguageSettingsProvider { + @Override + public String getId(); + @Override + public String getName(); + @Override + public List getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId); + + public void setSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId, List entries); +} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsEditableProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsEditableProvider.java index a65fda22cba..dc8c20c7657 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsEditableProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsEditableProvider.java @@ -23,11 +23,15 @@ import org.eclipse.core.resources.IResource; * their settings themselves and not providing such option to the user. * */ -public interface ILanguageSettingsEditableProvider extends ILanguageSettingsProvider, Cloneable { - +public interface ILanguageSettingsEditableProvider extends ILanguageSettingsBroadcastingProvider, Cloneable { + @Override + public String getId(); + @Override + public String getName(); + @Override + public List getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId); + @Override public void setSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId, List entries); - public boolean isEmpty(); - public void clear(); public ILanguageSettingsEditableProvider cloneShallow() throws CloneNotSupportedException; public ILanguageSettingsEditableProvider clone() throws CloneNotSupportedException; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsProvider.java index 7273b9141aa..7fb46ce045b 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsProvider.java @@ -29,8 +29,8 @@ import org.eclipse.core.resources.IResource; * {@code org.eclipse.cdt.core.LanguageSettingsProvider} and implement this * interface. CDT provides a few general use implementations such as * {@link LanguageSettingsBaseProvider} or {@link LanguageSettingsSerializableProvider} - * which could be used out of the box or extended. See also extension point - * schema description LanguageSettingsProvider.exsd. + * or {@link LanguageSettingsGenericProvider} which could be used out of the box or + * extended. See also extension point schema description LanguageSettingsProvider.exsd. * * @since 6.0 */ diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsGenericProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsGenericProvider.java new file mode 100644 index 00000000000..0439cf26051 --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsGenericProvider.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2009, 2011 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.core.language.settings.providers; + +/** + * TODO + */ +final public class LanguageSettingsGenericProvider extends LanguageSettingsSerializableProvider implements ILanguageSettingsEditableProvider { + @Override + public LanguageSettingsGenericProvider clone() throws CloneNotSupportedException { + return (LanguageSettingsGenericProvider) super.clone(); + } + + @Override + public LanguageSettingsGenericProvider cloneShallow() throws CloneNotSupportedException { + return (LanguageSettingsGenericProvider) super.cloneShallow(); + } + +} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager_TBD.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager_TBD.java index 92785fb3645..bb62b5c17d8 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager_TBD.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager_TBD.java @@ -32,14 +32,13 @@ public class LanguageSettingsManager_TBD { public static boolean isCustomizedResource(ICConfigurationDescription cfgDescription, IResource rc) { if (rc instanceof IProject) return false; - + for (ILanguageSettingsProvider provider: cfgDescription.getLanguageSettingProviders()) { - // FIXME -// if (!LanguageSettingsManager.isWorkspaceProvider(provider)) { - if (provider instanceof ILanguageSettingsEditableProvider || provider instanceof LanguageSettingsSerializableProvider) { + if (provider instanceof ILanguageSettingsBroadcastingProvider) { for (String languageId : LanguageSettingsManager.getLanguages(rc, cfgDescription)) { List list = provider.getSettingEntries(cfgDescription, rc, languageId); if (list!=null) { + // TODO - check default or check parent? List listDefault = provider.getSettingEntries(null, null, languageId); // != is OK here due as the equal lists will have the same reference in WeakHashSet if (list != listDefault) @@ -62,7 +61,7 @@ public class LanguageSettingsManager_TBD { } return false; } - + public static boolean isEqualExtensionProvider(ILanguageSettingsProvider provider) { return LanguageSettingsExtensionManager.equalsExtensionProvider(provider); } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableProvider.java index 74b42440d6c..bb5376ff49d 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableProvider.java @@ -31,7 +31,7 @@ import org.w3c.dom.NodeList; * TODO - more JavaDoc, info and hints about class hierarchy * */ -public class LanguageSettingsSerializableProvider extends LanguageSettingsBaseProvider { +public class LanguageSettingsSerializableProvider extends LanguageSettingsBaseProvider implements ILanguageSettingsBroadcastingProvider { public static final String ELEM_PROVIDER = "provider"; //$NON-NLS-1$ private static final String ATTR_ID = "id"; //$NON-NLS-1$ @@ -158,6 +158,7 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr * the language scope. See {@link #getLanguageScope()} * @param entries - language settings entries to set. */ + @Override public void setSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId, List entries) { String rcProjectPath = rc!=null ? rc.getProjectRelativePath().toString() : null; fStorage.setSettingEntries(rcProjectPath, languageId, entries); @@ -190,7 +191,7 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr * This is convenience method not intended to be overridden on purpose. * Override {@link #serializeAttributes(Element)} or * {@link #serializeEntries(Element)} instead. - * + * * @param parentElement - element where to serialize. * @return - newly created element. That element will already be * attached to the parent element. @@ -249,7 +250,7 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr * This is convenience method not intended to be overridden on purpose. * Override {@link #loadAttributes(Element)} or * {@link #loadEntries(Element)} instead. - * + * * @param providerNode - XML element to load provider from. */ final public void load(Element providerNode) { @@ -272,7 +273,7 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr } String id = XmlUtil.determineAttributeValue(parentNode, ATTR_ID); languageScope.add(id); - + } /** @@ -310,7 +311,7 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr public void loadEntries(Element providerNode) { fStorage.loadEntries(providerNode); } - + /** * See {@link #cloneShallow()}. This method is extracted * to avoid expressing {@link #clone()} via {@link #cloneShallow()}. @@ -408,7 +409,7 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr return false; return true; } - + /** * @noreference This method is not intended to be referenced by clients. */ diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java index f0ffa918ff1..4a0e688b4ce 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java @@ -23,6 +23,7 @@ import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsEditableProvider; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsBaseProvider; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsGenericProvider; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializableProvider; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.util.CDataUtil; @@ -260,6 +261,11 @@ public class LanguageSettingsExtensionManager { return new LanguageSettingsSerializableProvider(); } + // TODO unit test case for this + if (className.equals(LanguageSettingsGenericProvider.class.getName())) { + return new LanguageSettingsGenericProvider(); + } + ILanguageSettingsProvider provider = createProviderCarcass(className, Platform.getExtensionRegistry()); if (provider==null) { IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "Not able to load provider class=" + className); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java index 91cd8051398..83ecd49a078 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java @@ -337,7 +337,7 @@ public class LanguageSettingsProvidersSerializer { rawGlobalWorkspaceProviders = rawWorkspaceProviders; } - private static List createLanguageLettingsChangeEvents(List serializableProviders) { + private static List createLanguageSettingsChangeEvents(List serializableProviders) { List events = new ArrayList(); List serializableIds = new ArrayList(); @@ -379,11 +379,7 @@ projects: List serializableWorkspaceProviders = new ArrayList(); for (ILanguageSettingsProvider provider : rawGlobalWorkspaceProviders.values()) { if (provider instanceof LanguageSettingsSerializableProvider) { - // serialize all editable providers which are different from corresponding extension - // and serialize all serializable ones that are not editable (those are singletons and we don't know whether they changed) - if (!(provider instanceof ILanguageSettingsEditableProvider) || !LanguageSettingsExtensionManager.equalsExtensionProvider(provider)) { - serializableWorkspaceProviders.add((LanguageSettingsSerializableProvider)provider); - } + serializableWorkspaceProviders.add((LanguageSettingsSerializableProvider)provider); } } try { @@ -394,7 +390,7 @@ projects: serializingLock.acquire(); fileStoreWsp.delete(); // manufacture events while inside the lock - events = createLanguageLettingsChangeEvents(serializableWorkspaceProviders); + events = createLanguageSettingsChangeEvents(serializableWorkspaceProviders); } finally { serializingLock.release(); } @@ -411,7 +407,7 @@ projects: serializingLock.acquire(); XmlUtil.serializeXml(doc, uriStoreWsp); // manufacture events while inside the lock - events = createLanguageLettingsChangeEvents(serializableWorkspaceProviders); + events = createLanguageSettingsChangeEvents(serializableWorkspaceProviders); } finally { serializingLock.release(); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java index 33ef8263fb7..36048bed7fa 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java @@ -42,11 +42,11 @@ import org.eclipse.swt.widgets.Tree; import org.eclipse.swt.widgets.TreeColumn; import org.eclipse.swt.widgets.TreeItem; +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsBroadcastingProvider; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsEditableProvider; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsBaseProvider; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; -import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializableProvider; import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySupport; import org.eclipse.cdt.core.model.ILanguage; import org.eclipse.cdt.core.model.LanguageManager; @@ -122,7 +122,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { if (entriesParent != null /*&& entriesParent.size() > 0*/) { overlayKeys[IDecoration.TOP_RIGHT] = CDTSharedImages.IMG_OVR_PARENT; } - } else if (provider instanceof ILanguageSettingsEditableProvider && (page.isForFile() || page.isForFolder())) { + } else if (provider instanceof ILanguageSettingsBroadcastingProvider && (page.isForFile() || page.isForFolder())) { // Assuming that the default entries for a resource are always null. // Using that for performance reasons. See note in PerformDefaults(). List entriesParent = provider.getSettingEntries(null, null, currentLanguageId); @@ -682,7 +682,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { } private void saveEntries(ILanguageSettingsProvider provider, List entries) { - if (provider instanceof LanguageSettingsSerializableProvider) { + if (provider instanceof ILanguageSettingsEditableProvider) { ICConfigurationDescription cfgDescription = getConfigurationDescription(); IResource rc = getResource(); if (entries!=null && rc!=null) { @@ -697,7 +697,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { entries = null; } } - ((LanguageSettingsSerializableProvider)provider).setSettingEntries(cfgDescription, rc, currentLanguageId, entries); + ((ILanguageSettingsEditableProvider)provider).setSettingEntries(cfgDescription, rc, currentLanguageId, entries); } } @@ -961,11 +961,11 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { boolean changed = false; ICConfigurationDescription cfgDescription = getConfigurationDescription(); IResource rc = getResource(); - List providers = cfgDescription.getLanguageSettingProviders(); - List writableProviders = new ArrayList(providers.size()); + List oldProviders = cfgDescription.getLanguageSettingProviders(); + List newProviders = new ArrayList(oldProviders.size()); -providers: for (ILanguageSettingsProvider provider : providers) { - ILanguageSettingsEditableProvider writableProvider = null; +providers: for (ILanguageSettingsProvider provider : oldProviders) { + ILanguageSettingsEditableProvider providerCopy = null; if (provider instanceof ILanguageSettingsEditableProvider) { for (TreeItem langItems : treeLanguages.getItems()) { String langId = (String)langItems.getData(); @@ -973,10 +973,10 @@ providers: for (ILanguageSettingsProvider provider : providers) { if (provider.getSettingEntries(cfgDescription, rc, langId)!=null) { try { // clone providers to be able to "Cancel" in UI - if (writableProvider==null) { - writableProvider = ((ILanguageSettingsEditableProvider) provider).clone(); + if (providerCopy==null) { + providerCopy = ((ILanguageSettingsEditableProvider) provider).clone(); } - writableProvider.setSettingEntries(cfgDescription, rc, langId, null); + providerCopy.setSettingEntries(cfgDescription, rc, langId, null); changed = true; } catch (CloneNotSupportedException e) { CUIPlugin.log("Internal Error: cannot clone provider "+provider.getId(), e); @@ -986,13 +986,13 @@ providers: for (ILanguageSettingsProvider provider : providers) { } } } - if (writableProvider!=null) - writableProviders.add(writableProvider); + if (providerCopy!=null) + newProviders.add(providerCopy); else - writableProviders.add(provider); + newProviders.add(provider); } if (changed) { - cfgDescription.setLanguageSettingProviders(writableProviders); + cfgDescription.setLanguageSettingProviders(newProviders); // updateTreeEntries(); // updateData(getResDesc()); List tableItems = getProviders(currentLanguageId); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java index 81567fc0185..99f0614f3b5 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java @@ -150,14 +150,13 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); Assert.isTrue(rawProvider instanceof ILanguageSettingsEditableProvider); - ILanguageSettingsEditableProvider editableProvider = (ILanguageSettingsEditableProvider)rawProvider; try { - ILanguageSettingsEditableProvider newProvider = editableProvider.clone(); + ILanguageSettingsEditableProvider newProvider = ((ILanguageSettingsEditableProvider)rawProvider).clone(); replaceSelectedProvider(newProvider); return newProvider; } catch (CloneNotSupportedException e) { - CUIPlugin.log("Error cloning provider " + editableProvider.getId(), e); + CUIPlugin.log("Error cloning provider " + rawProvider.getId(), e); // TODO warning dialog for user? } @@ -249,7 +248,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { if (page.isForPrefs()) { initButtons(BUTTON_LABELS_PREF); - + } else { // "I want to try new scanner discovery" temporary checkbox enableProvidersCheckBox = setupCheck(usercomp, Messages.CDTMainWizardPage_TrySD90, 2, GridData.FILL_HORIZONTAL); @@ -545,7 +544,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { // renders better when using temporary presentedProviders = providers; - + int pos = tableProviders.getSelectionIndex(); tableProvidersViewer.setInput(presentedProviders); tableProviders.setSelection(pos); @@ -744,8 +743,8 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { private void performClear(ILanguageSettingsProvider selectedProvider) { if (isWorkingCopy(selectedProvider)) { - if (selectedProvider instanceof ILanguageSettingsEditableProvider) { - ILanguageSettingsEditableProvider editableProvider = (ILanguageSettingsEditableProvider) selectedProvider; + if (selectedProvider instanceof LanguageSettingsSerializableProvider) { + LanguageSettingsSerializableProvider editableProvider = (LanguageSettingsSerializableProvider) selectedProvider; editableProvider.clear(); tableProvidersViewer.update(selectedProvider, null); } @@ -892,7 +891,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { } // seems to render better when temporary is used presentedProviders = providers; - + int pos = tableProviders.getSelectionIndex(); tableProvidersViewer.setInput(presentedProviders); tableProviders.setSelection(pos); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProvidersLabelProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProvidersLabelProvider.java index aa8a4db4db9..a64766e8811 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProvidersLabelProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProvidersLabelProvider.java @@ -49,7 +49,7 @@ class LanguageSettingsProvidersLabelProvider extends LabelProvider { if (url!=null) { imageKey = url.toString(); } - + if (imageKey==null) { if (id.matches(TEST_PLUGIN_ID_PATTERN)) { imageKey = CDTSharedImages.IMG_OBJS_CDT_TESTING; @@ -67,7 +67,7 @@ class LanguageSettingsProvidersLabelProvider extends LabelProvider { String[] overlayKeys = new String[5]; { // TODO temporary for debugging // boolean isSpecial = provider.getId().equals(LegacySupport.MBS_LANGUAGE_SETTINGS_PROVIDER); - + ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); if (rawProvider instanceof LanguageSettingsSerializableProvider) { if (((LanguageSettingsSerializableProvider)rawProvider).isEmpty()) { @@ -84,14 +84,14 @@ class LanguageSettingsProvidersLabelProvider extends LabelProvider { // overlayKeys[IDecoration.TOP_LEFT] = CDTSharedImages.IMG_OVR_CONFIGURATION; // overlayKeys[IDecoration.TOP_LEFT] = CDTSharedImages.IMG_OVR_INDEXED; // overlayKeys[IDecoration.TOP_LEFT] = CDTSharedImages.IMG_OVR_CONTEXT; - + // overlayKeys[IDecoration.TOP_LEFT] = CDTSharedImages.IMG_OVR_PROJECT; } - + } return overlayKeys; } - + @Override public Image getImage(Object element) { if (element instanceof ILanguageSettingsProvider) { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/UserLanguageSettingsProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/UserLanguageSettingsProvider.java index 0ade1ec3990..cdc60c747e1 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/UserLanguageSettingsProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/UserLanguageSettingsProvider.java @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright (c) 2009, 2009 Andrew Gvozdev (Quoin Inc.) and others. + * Copyright (c) 2009, 2011 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 (Quoin Inc.) - initial API and implementation + * Andrew Gvozdev - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.internal.ui.language.settings.providers; @@ -20,7 +20,7 @@ import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializ * */ public class UserLanguageSettingsProvider extends LanguageSettingsSerializableProvider implements ILanguageSettingsEditableProvider { - + @Override public int hashCode() { return super.hashCode()*13 + 1; @@ -43,5 +43,5 @@ public class UserLanguageSettingsProvider extends LanguageSettingsSerializablePr public UserLanguageSettingsProvider clone() throws CloneNotSupportedException { return (UserLanguageSettingsProvider)super.clone(); } - + } From 7250f46995cdf549fff1a87b1b8805a5dfb6620b Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Sat, 26 Nov 2011 19:57:11 -0500 Subject: [PATCH 070/120] Removed UserLanguageSettingsProvider in favor of LanguageSettingsGenericProvider --- .../LanguageSettingsExtensionsTests.java | 9 ++++ .../LanguageSettingsGenericProvider.java | 10 ++-- .../LanguageSettingsSerializableEditable.java | 28 ----------- .../LanguageSettingsExtensionManager.java | 4 ++ core/org.eclipse.cdt.ui/plugin.xml | 2 +- .../providers/LanguageSettingsEntriesTab.java | 2 +- .../UserLanguageSettingsProvider.java | 47 ------------------- 7 files changed, 20 insertions(+), 82 deletions(-) delete mode 100644 core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableEditable.java delete mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/UserLanguageSettingsProvider.java diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java index 2869db7d782..79aaaa3056f 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java @@ -324,4 +324,13 @@ public class LanguageSettingsExtensionsTests extends BaseTestCase { } } + /** + * Check that LanguageSettingsGenericProvider extension defined in plugin.xml is accessible. + */ + public void testExtensionGenericProvider() throws Exception { + ILanguageSettingsProvider provider = LanguageSettingsExtensionManager.getExtensionProviderClone(LanguageSettingsManager_TBD.PROVIDER_UI_USER); + assertNotNull("extension " + LanguageSettingsManager_TBD.PROVIDER_UI_USER + " not found", provider); + assertTrue(provider instanceof LanguageSettingsGenericProvider); + } + } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsGenericProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsGenericProvider.java index 0439cf26051..f920aa29d3f 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsGenericProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsGenericProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2011 Andrew Gvozdev and others. + * Copyright (c) 2011, 2011 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 @@ -12,17 +12,17 @@ package org.eclipse.cdt.core.language.settings.providers; /** - * TODO + * Generic implementation of language settings provider which can be edited in UI + * with entries persisted between eclipse sessions. */ -final public class LanguageSettingsGenericProvider extends LanguageSettingsSerializableProvider implements ILanguageSettingsEditableProvider { +final public class LanguageSettingsGenericProvider extends LanguageSettingsSerializableProvider + implements ILanguageSettingsEditableProvider { @Override public LanguageSettingsGenericProvider clone() throws CloneNotSupportedException { return (LanguageSettingsGenericProvider) super.clone(); } - @Override public LanguageSettingsGenericProvider cloneShallow() throws CloneNotSupportedException { return (LanguageSettingsGenericProvider) super.cloneShallow(); } - } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableEditable.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableEditable.java deleted file mode 100644 index dd49ebc7a8e..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableEditable.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 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.core.language.settings.providers; - -// TODO: move ILanguageSettingsEditableProvider here - -// TODO this one is unused - remove -final public class LanguageSettingsSerializableEditable extends LanguageSettingsSerializableProvider implements ILanguageSettingsEditableProvider { - @Override - public LanguageSettingsSerializableEditable clone() throws CloneNotSupportedException { - return (LanguageSettingsSerializableEditable) super.clone(); - } - - @Override - public LanguageSettingsSerializableEditable cloneShallow() throws CloneNotSupportedException { - return (LanguageSettingsSerializableEditable) super.cloneShallow(); - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java index 4a0e688b4ce..f19f6833b47 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java @@ -265,6 +265,10 @@ public class LanguageSettingsExtensionManager { if (className.equals(LanguageSettingsGenericProvider.class.getName())) { return new LanguageSettingsGenericProvider(); } + // FIXME - older usage, will fade it out + if (className.equals("org.eclipse.cdt.internal.ui.language.settings.providers.UserLanguageSettingsProvider")) { + return new LanguageSettingsGenericProvider(); + } ILanguageSettingsProvider provider = createProviderCarcass(className, Platform.getExtensionRegistry()); if (provider==null) { diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml index 44ec840d861..4cbf7d648df 100644 --- a/core/org.eclipse.cdt.ui/plugin.xml +++ b/core/org.eclipse.cdt.ui/plugin.xml @@ -3797,7 +3797,7 @@ diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java index 36048bed7fa..4f01895a27f 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java @@ -551,7 +551,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { } if (status==null || status==Status.OK_STATUS) { ILanguageSettingsProvider provider = getSelectedProvider(); - if (provider!=null && !(provider instanceof UserLanguageSettingsProvider)) { + if (provider!=null && !(provider instanceof ILanguageSettingsBroadcastingProvider)) { String msg = "Setting entries for this provider are supplied by system and are not editable."; status = new Status(IStatus.INFO, CUIPlugin.PLUGIN_ID, msg); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/UserLanguageSettingsProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/UserLanguageSettingsProvider.java deleted file mode 100644 index cdc60c747e1..00000000000 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/UserLanguageSettingsProvider.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 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.internal.ui.language.settings.providers; - -import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsEditableProvider; -import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializableProvider; - -/** - * Provider to support user interface for language settings. The important difference with - * {@link LanguageSettingsSerializableProvider} is that it implements {@link ILanguageSettingsEditableProvider}. - * - */ -public class UserLanguageSettingsProvider extends LanguageSettingsSerializableProvider implements ILanguageSettingsEditableProvider { - - @Override - public int hashCode() { - return super.hashCode()*13 + 1; - } - - @Override - public boolean equals(Object o) { - if (o instanceof UserLanguageSettingsProvider) { - return super.equals(o); - } - return false; - } - - @Override - public UserLanguageSettingsProvider cloneShallow() throws CloneNotSupportedException { - return (UserLanguageSettingsProvider)super.cloneShallow(); - } - - @Override - public UserLanguageSettingsProvider clone() throws CloneNotSupportedException { - return (UserLanguageSettingsProvider)super.clone(); - } - -} From 57bd8abd2773c37d99273cb5910646dd646ff6f7 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Sat, 26 Nov 2011 22:12:11 -0500 Subject: [PATCH 071/120] LanguageSettingsStorage as a public class --- .../MBSLanguageSettingsProvider.java | 26 +- ...ILanguageSettingsBroadcastingProvider.java | 15 +- .../ILanguageSettingsEditableProvider.java | 22 +- .../LanguageSettingsBaseProvider.java | 1 - .../LanguageSettingsSerializableProvider.java | 25 +- .../providers/LanguageSettingsStorage.java | 234 ++++++++++ .../providers/LanguageSettingsDelta.java | 8 +- .../LanguageSettingsProvidersSerializer.java | 3 +- .../LanguageSettingsSerializableStorage.java | 225 ++++++++++ .../providers/LanguageSettingsStorage.java | 419 ------------------ .../model/CConfigurationSpecSettings.java | 47 +- 11 files changed, 561 insertions(+), 464 deletions(-) create mode 100644 core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsStorage.java create mode 100644 core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsSerializableStorage.java delete mode 100644 core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsStorage.java diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/MBSLanguageSettingsProvider.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/MBSLanguageSettingsProvider.java index 5f343e9382d..f324c2a6fc8 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/MBSLanguageSettingsProvider.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/MBSLanguageSettingsProvider.java @@ -16,6 +16,7 @@ import java.util.List; import org.eclipse.cdt.core.AbstractExecutableExtensionBase; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsBroadcastingProvider; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsStorage; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICFileDescription; import org.eclipse.cdt.core.settings.model.ICFolderDescription; @@ -27,6 +28,9 @@ import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IPath; +/** + * Implementation of language settings provider for CDT Managed Build System. + */ public class MBSLanguageSettingsProvider extends AbstractExecutableExtensionBase implements ILanguageSettingsBroadcastingProvider { @Override public List getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) { @@ -90,7 +94,6 @@ public class MBSLanguageSettingsProvider extends AbstractExecutableExtensionBase return array; } - @Override public void setSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId, List entries) { @@ -123,4 +126,25 @@ public class MBSLanguageSettingsProvider extends AbstractExecutableExtensionBase } } + @Override + public LanguageSettingsStorage copyStorage() { + class PretendStorage extends LanguageSettingsStorage { + @Override + public boolean isEmpty() { + return false; + } + @Override + public LanguageSettingsStorage clone() throws CloneNotSupportedException { + throw new CloneNotSupportedException(); +// return this; + } + @Override + public boolean equals(Object obj) { + // Note that this always triggers change event even if nothing changed in MBS + return false; + } + } + return new PretendStorage(); + } + } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsBroadcastingProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsBroadcastingProvider.java index 8987647ad60..e4ec18493d5 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsBroadcastingProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsBroadcastingProvider.java @@ -8,17 +8,19 @@ * Contributors: * Andrew Gvozdev - initial API and implementation *******************************************************************************/ - package org.eclipse.cdt.core.language.settings.providers; import java.util.List; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; +import org.eclipse.cdt.internal.core.language.settings.providers.ILanguageSettingsChangeEvent; +import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer; import org.eclipse.core.resources.IResource; /** - * TODO + * This interface is to be implemented by providers which want to broadcast the changes in their setting entries + * by {@link LanguageSettingsProvidersSerializer#notifyLanguageSettingsChangeListeners(ILanguageSettingsChangeEvent)} */ public interface ILanguageSettingsBroadcastingProvider extends ILanguageSettingsProvider { @Override @@ -28,5 +30,12 @@ public interface ILanguageSettingsBroadcastingProvider extends ILanguageSettings @Override public List getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId); - public void setSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId, List entries); + /** + * Return a copy of internal storage. This should be a deep copy/clone of the storage. + * It is used to calculate the delta and being kept in the last state object of configuration + * description to compare to a new state later. + * + * @return a copy of internal storage. + */ + public LanguageSettingsStorage copyStorage(); } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsEditableProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsEditableProvider.java index dc8c20c7657..2147b479101 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsEditableProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsEditableProvider.java @@ -30,9 +30,29 @@ public interface ILanguageSettingsEditableProvider extends ILanguageSettingsBroa public String getName(); @Override public List getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId); - @Override + + /** + * Sets language settings entries for the provider. + * + * @param cfgDescription - configuration description. + * @param rc - resource such as file or folder. + * @param languageId - language id. If {@code null}, then entries are considered to be defined for + * any language. + * @param entries - language settings entries to set. + */ public void setSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId, List entries); + /** + * Shallow clone of the provider. "Shallow" is defined here as the exact copy except that + * the copy will have zero language settings entries. + * + * @return shallow copy of the provider. + * @throws CloneNotSupportedException in case {@link #clone()} throws the exception. + */ public ILanguageSettingsEditableProvider cloneShallow() throws CloneNotSupportedException; + + /* + * @see Object#clone() + */ public ILanguageSettingsEditableProvider clone() throws CloneNotSupportedException; } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsBaseProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsBaseProvider.java index d1709352b7a..dad259c2584 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsBaseProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsBaseProvider.java @@ -18,7 +18,6 @@ import java.util.List; import org.eclipse.cdt.core.AbstractExecutableExtensionBase; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; -import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsStorage; import org.eclipse.cdt.internal.core.settings.model.SettingsModelMessages; import org.eclipse.core.resources.IResource; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableProvider.java index bb5376ff49d..446173c43c5 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableProvider.java @@ -14,10 +14,11 @@ 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.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.internal.core.XmlUtil; -import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsStorage; +import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsSerializableStorage; import org.eclipse.core.resources.IResource; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -27,6 +28,8 @@ import org.w3c.dom.NodeList; /** * This class is the base class for language settings providers able to serialize * into XML storage. + * Although this class has setter methods, it is not editable in UI by design. + * Implement {@link ILanguageSettingsEditableProvider} interface for that. * * TODO - more JavaDoc, info and hints about class hierarchy * @@ -46,7 +49,7 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr /** Tells if language settings entries are persisted with the project or in workspace area while serializing. */ private boolean storeEntriesInProjectArea = false; - private LanguageSettingsStorage fStorage = new LanguageSettingsStorage(); + private LanguageSettingsSerializableStorage fStorage = new LanguageSettingsSerializableStorage(); /** * Default constructor. This constructor has to be always followed with setting id and name of the provider. @@ -158,7 +161,6 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr * the language scope. See {@link #getLanguageScope()} * @param entries - language settings entries to set. */ - @Override public void setSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId, List entries) { String rcProjectPath = rc!=null ? rc.getProjectRelativePath().toString() : null; fStorage.setSettingEntries(rcProjectPath, languageId, entries); @@ -321,7 +323,7 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr if (languageScope!=null) clone.languageScope = new ArrayList(languageScope); - clone.fStorage = new LanguageSettingsStorage(); + clone.fStorage = new LanguageSettingsSerializableStorage(); return clone; } @@ -339,7 +341,7 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr @Override protected LanguageSettingsSerializableProvider clone() throws CloneNotSupportedException { LanguageSettingsSerializableProvider clone = cloneShallowInternal(); - clone.fStorage = fStorage.cloneStorage(); + clone.fStorage = fStorage.clone(); return clone; } @@ -410,10 +412,13 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr return true; } - /** - * @noreference This method is not intended to be referenced by clients. - */ - public LanguageSettingsStorage getStorageInternal() { - return fStorage; + @Override + public LanguageSettingsStorage copyStorage() { + try { + return fStorage.clone(); + } catch (CloneNotSupportedException e) { + CCorePlugin.log(e); + } + return null; } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsStorage.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsStorage.java new file mode 100644 index 00000000000..bc5f077954d --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsStorage.java @@ -0,0 +1,234 @@ +/******************************************************************************* + * Copyright (c) 2011, 2011 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.core.language.settings.providers; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; +import org.eclipse.cdt.core.settings.model.ICSettingEntry; +import org.eclipse.cdt.internal.core.parser.util.WeakHashSet; +import org.eclipse.core.resources.IResource; + +public class LanguageSettingsStorage implements Cloneable { + /** + * Storage to keep settings entries. Note that it is not necessary to keep configuration in the maps + * as the configuration is always the one provider belongs to. + */ + protected Map>> fStorage = new HashMap>>(); + + /** + * Pool of LSE lists implemented as WeakHashSet. That allows to gain memory savings + * at the expense of CPU time. WeakHashSet handles garbage collection when a list is not + * referenced anywhere else. See JavaDoc {@link java.lang.ref.WeakReference} about weak reference objects. + */ + private static WeakHashSet> listPool = new WeakHashSet>() { + @Override + public synchronized List add(List list) { + return super.add(list); + } + + }; + + /** + * TODO + *
    Note that this list is unmodifiable. + * + */ + public List getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) { + List entries = null; + Map> langMap = fStorage.get(languageId); + if (langMap!=null) { + String rcProjectPath = rc!=null ? rc.getProjectRelativePath().toString() : null; + entries = langMap.get(rcProjectPath); + } + return entries; + } + + /** + * Some providers may collect entries in pretty much random order. For the purposes of + * predictability, UI usability and efficient storage the entries are sorted by kinds + * and secondary by name for kinds where the secondary order is not significant. + * + * @param entries - list of entries to sort. + * @return - sorted entries. + */ + private List sortEntries(List entries) { + List sortedEntries = new ArrayList(entries); + Collections.sort(sortedEntries, new Comparator(){ + /** + * This comparator sorts by kinds first and the macros are sorted additionally by name. + */ + @Override + public int compare(ICLanguageSettingEntry entry0, ICLanguageSettingEntry entry1) { + int kind0 = entry0.getKind(); + int kind1 = entry1.getKind(); + if (kind0==ICSettingEntry.MACRO && kind1==ICSettingEntry.MACRO) { + return entry0.getName().compareTo(entry1.getName()); + } + + return kind0 - kind1; + }}); + + return sortedEntries; + } + + /** + * + */ + public void setSettingEntries(String rcProjectPath, String languageId, List entries) { + synchronized (fStorage) { + if (entries!=null) { + Map> langMap = fStorage.get(languageId); + if (langMap==null) { + langMap = new HashMap>(); + fStorage.put(languageId, langMap); + } + List sortedEntries = getPooledList(sortEntries(entries), false); + langMap.put(rcProjectPath, sortedEntries); + } else { + // do not keep nulls in the tables + Map> langMap = fStorage.get(languageId); + if (langMap!=null) { + langMap.remove(rcProjectPath); + if (langMap.size()==0) { + fStorage.remove(languageId); + } + } + } + } + } + + /** + * @return {@code true} if the provider does not keep any settings yet or {@code false} if there are some. + */ + public boolean isEmpty() { + return fStorage.isEmpty(); + } + + /** + * Clear all the entries for all configurations, all resources and all languages. + */ + public void clear() { + synchronized (fStorage) { + fStorage.clear(); + } + } + + /** + * Returns the equal list of entries from the pool to conserve the memory. + * + * @param entries - list of entries to pool. + * @param copy - specify {@code true} to copy the list in order to prevent + * back-door modification on the original list changes. + * @return returns the list of entries from the pool. + */ + private static List getPooledList(List entries, boolean copy) { + if (entries == null) + return null; + + List pooledList = listPool.get(entries); + if (pooledList != null) { + return pooledList; + } + + if (entries.size() == 0) { + return getPooledEmptyList(); + } + + if (copy) { + entries = new ArrayList(entries); + } + pooledList = Collections.unmodifiableList(entries); + return listPool.add(pooledList); + } + + /** + * Returns the equal list of entries from the pool to conserve the memory. + * + * @param entries - list of entries to pool. + * @return returns the list of entries from the pool. + */ + public static List getPooledList(List entries) { + return getPooledList(entries, true); + } + + /** + * @return the empty immutable list which is pooled. Use this call rather than creating + * new empty array to ensure that operator '==' can be used instead of deep equals(). + */ + public static List getPooledEmptyList() { + List pooledEmptyList = Collections.emptyList(); + return listPool.add(pooledEmptyList); + } + + /** + * Clone storage for the entries. Copies references for lists of entries as a whole. + * Note that is OK as the lists kept in storage are unmodifiable. + */ + @Override + public LanguageSettingsStorage clone() throws CloneNotSupportedException { + LanguageSettingsStorage storageClone = (LanguageSettingsStorage) super.clone(); + storageClone.fStorage = new HashMap>>(); + synchronized (fStorage) { + Set>>> entrySetLang = fStorage.entrySet(); + for (Entry>> entryLang : entrySetLang) { + String langId = entryLang.getKey(); + Map> mapRc = entryLang.getValue(); + Map> mapRcClone = new HashMap>(); + Set>> entrySetRc = mapRc.entrySet(); + for (Entry> entryRc : entrySetRc) { + String rcProjectPath = entryRc.getKey(); + List lsEntries = entryRc.getValue(); + // don't need to clone entries, they are from the LSE pool + mapRcClone.put(rcProjectPath, lsEntries); + } + storageClone.fStorage.put(langId, mapRcClone); + } + } + return storageClone; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((fStorage == null) ? 0 : fStorage.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + LanguageSettingsStorage other = (LanguageSettingsStorage) obj; + if (fStorage == null) { + if (other.fStorage != null) + return false; + } else if (!fStorage.equals(other.fStorage)) + return false; + return true; + } + +} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsDelta.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsDelta.java index 4b88f99e6cf..317f545e14d 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsDelta.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsDelta.java @@ -12,6 +12,8 @@ package org.eclipse.cdt.internal.core.language.settings.providers; import java.util.LinkedHashMap; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsStorage; + /** * This class currently is a placeholder holding old and new states. @@ -21,11 +23,11 @@ public class LanguageSettingsDelta { // maps need to be ordered by providers @SuppressWarnings("unused") private LinkedHashMap oldLanguageSettingsState; + LanguageSettingsStorage> oldLanguageSettingsState; @SuppressWarnings("unused") private LinkedHashMap newLanguageSettingsState; - + LanguageSettingsStorage> newLanguageSettingsState; + public LanguageSettingsDelta(LinkedHashMap oldState, LinkedHashMap newState) { oldLanguageSettingsState = oldState; newLanguageSettingsState = newState; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java index 83ecd49a078..0e237ea0d21 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java @@ -24,6 +24,7 @@ import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsEditabl import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializableProvider; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsStorage; import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySupport; import org.eclipse.cdt.core.model.ILanguage; import org.eclipse.cdt.core.model.LanguageManager; @@ -338,7 +339,7 @@ public class LanguageSettingsProvidersSerializer { } private static List createLanguageSettingsChangeEvents(List serializableProviders) { - List events = new ArrayList(); + List events = new ArrayList(); List serializableIds = new ArrayList(); for (LanguageSettingsSerializableProvider provider : serializableProviders) { diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsSerializableStorage.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsSerializableStorage.java new file mode 100644 index 00000000000..f2e05acd297 --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsSerializableStorage.java @@ -0,0 +1,225 @@ +/******************************************************************************* + * Copyright (c) 2011, 2011 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.internal.core.language.settings.providers; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsStorage; +import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; +import org.eclipse.cdt.core.settings.model.ICSettingEntry; +import org.eclipse.cdt.core.settings.model.util.CDataUtil; +import org.eclipse.cdt.core.settings.model.util.LanguageSettingEntriesSerializer; +import org.eclipse.cdt.internal.core.XmlUtil; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +public class LanguageSettingsSerializableStorage extends LanguageSettingsStorage { + private static final String ELEM_LANGUAGE = "language"; //$NON-NLS-1$ + private static final String ATTR_LANGUAGE_ID = "id"; //$NON-NLS-1$ + private static final String ELEM_RESOURCE = "resource"; //$NON-NLS-1$ + private static final String ATTR_PROJECT_PATH = "project-relative-path"; //$NON-NLS-1$ + + private static final String ELEM_ENTRY = "entry"; //$NON-NLS-1$ + private static final String ATTR_KIND = "kind"; //$NON-NLS-1$ + private static final String ATTR_NAME = "name"; //$NON-NLS-1$ + private static final String ATTR_VALUE = "value"; //$NON-NLS-1$ + private static final String ELEM_FLAG = "flag"; //$NON-NLS-1$ + + /** + * Serialize the provider entries under parent XML element. + * @param elementProvider - element where to serialize the entries. + */ + public void serializeEntries(Element elementProvider) { + synchronized (fStorage) { + for (Entry>> entryLang : fStorage.entrySet()) { + serializeLanguage(elementProvider, entryLang); + } + } + } + + /** + * Serialize the provider entries for a given language list. + */ + private void serializeLanguage(Element parentElement, Entry>> entryLang) { + String langId = entryLang.getKey(); + if (langId!=null) { + Element elementLanguage = XmlUtil.appendElement(parentElement, ELEM_LANGUAGE, new String[] {ATTR_LANGUAGE_ID, langId}); + parentElement = elementLanguage; + } + for (Entry> entryRc : entryLang.getValue().entrySet()) { + serializeResource(parentElement, entryRc); + } + } + + /** + * Serialize the provider entries for a given resource list. + */ + private void serializeResource(Element parentElement, Entry> entryRc) { + String rcProjectPath = entryRc.getKey(); + if (rcProjectPath!=null) { + Element elementRc = XmlUtil.appendElement(parentElement, ELEM_RESOURCE, new String[] {ATTR_PROJECT_PATH, rcProjectPath}); + parentElement = elementRc; + } + serializeSettingEntries(parentElement, entryRc.getValue()); + } + + /** + * Serialize given settings entries. + */ + private void serializeSettingEntries(Element parentElement, List settingEntries) { + for (ICLanguageSettingEntry entry : settingEntries) { + Element elementSettingEntry = XmlUtil.appendElement(parentElement, ELEM_ENTRY, new String[] { + ATTR_KIND, LanguageSettingEntriesSerializer.kindToString(entry.getKind()), + ATTR_NAME, entry.getName(), + }); + switch(entry.getKind()) { + case ICSettingEntry.MACRO: + elementSettingEntry.setAttribute(ATTR_VALUE, entry.getValue()); + break; +// case ICLanguageSettingEntry.LIBRARY_FILE: +// // TODO: sourceAttachment fields may need to be covered +// break; + } + int flags = entry.getFlags(); + if (flags!=0) { + // Element elementFlag = + XmlUtil.appendElement(elementSettingEntry, ELEM_FLAG, new String[] { + ATTR_VALUE, LanguageSettingEntriesSerializer.composeFlagsString(entry.getFlags()) + }); + } + } + } + + /** + * Load provider entries from XML provider element. + * @param providerNode - parent XML element where entries are defined. + */ + public void loadEntries(Element providerNode) { + List settings = new ArrayList(); + NodeList nodes = providerNode.getChildNodes(); + for (int i=0;i0) { + setSettingEntries(null, null, settings); + } + } + + /** + * Load a setting entry from XML element. + */ + private ICLanguageSettingEntry loadSettingEntry(Node parentElement) { + String settingKind = XmlUtil.determineAttributeValue(parentElement, ATTR_KIND); + String settingName = XmlUtil.determineAttributeValue(parentElement, ATTR_NAME); + + NodeList flagNodes = parentElement.getChildNodes(); + int flags = 0; + for (int i=0;i settings = new ArrayList(); + NodeList nodes = parentNode.getChildNodes(); + for (int i=0;i0) { + setSettingEntries(null, langId, settings); + } + } + + /** + * Load entries defined in resource element. + */ + private void loadResourceElement(Node parentNode, String cfgId, String langId) { + String rcProjectPath = XmlUtil.determineAttributeValue(parentNode, ATTR_PROJECT_PATH); + + List settings = new ArrayList(); + NodeList nodes = parentNode.getChildNodes(); + for (int i=0;i0) { + setSettingEntries(rcProjectPath, langId, settings); + } + } + + @Override + public LanguageSettingsSerializableStorage clone() throws CloneNotSupportedException { + return (LanguageSettingsSerializableStorage) super.clone(); + } + +} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsStorage.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsStorage.java deleted file mode 100644 index ec37aa13ec6..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsStorage.java +++ /dev/null @@ -1,419 +0,0 @@ -package org.eclipse.cdt.internal.core.language.settings.providers; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - -import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; -import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; -import org.eclipse.cdt.core.settings.model.ICSettingEntry; -import org.eclipse.cdt.core.settings.model.util.CDataUtil; -import org.eclipse.cdt.core.settings.model.util.LanguageSettingEntriesSerializer; -import org.eclipse.cdt.internal.core.XmlUtil; -import org.eclipse.cdt.internal.core.parser.util.WeakHashSet; -import org.eclipse.core.resources.IResource; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -public class LanguageSettingsStorage { - private static final String ELEM_LANGUAGE = "language"; //$NON-NLS-1$ - private static final String ATTR_LANGUAGE_ID = "id"; //$NON-NLS-1$ - private static final String ELEM_RESOURCE = "resource"; //$NON-NLS-1$ - private static final String ATTR_PROJECT_PATH = "project-relative-path"; //$NON-NLS-1$ - - private static final String ELEM_ENTRY = "entry"; //$NON-NLS-1$ - private static final String ATTR_KIND = "kind"; //$NON-NLS-1$ - private static final String ATTR_NAME = "name"; //$NON-NLS-1$ - private static final String ATTR_VALUE = "value"; //$NON-NLS-1$ - private static final String ELEM_FLAG = "flag"; //$NON-NLS-1$ - - /** - * Storage to keep settings entries. Note that it is not necessary to keep configuration in the maps - * as the configuration is always the one provider belongs to. - */ - private Map>> fStorage = new HashMap>>(); - - /** - * Pool of LSE lists implemented as WeakHashSet. That allows to gain memory savings - * at the expense of CPU time. WeakHashSet handles garbage collection when a list is not - * referenced anywhere else. See JavaDoc {@link java.lang.ref.WeakReference} about weak reference objects. - */ - private static WeakHashSet> listPool = new WeakHashSet>() { - @Override - public synchronized List add(List list) { - return super.add(list); - } - - }; - - /** - * TODO - *
    Note that this list is unmodifiable. - * - */ - public List getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) { - List entries = null; - Map> langMap = fStorage.get(languageId); - if (langMap!=null) { - String rcProjectPath = rc!=null ? rc.getProjectRelativePath().toString() : null; - entries = langMap.get(rcProjectPath); - } - return entries; - } - - /** - * Some providers may collect entries in pretty much random order. For the purposes of - * predictability, UI usability and efficient storage the entries are sorted by kinds - * and secondary by name for kinds where the secondary order is not significant. - * - * @param entries - list of entries to sort. - * @return - sorted entries. - */ - private List sortEntries(List entries) { - List sortedEntries = new ArrayList(entries); - Collections.sort(sortedEntries, new Comparator(){ - /** - * This comparator sorts by kinds first and the macros are sorted additionally by name. - */ - @Override - public int compare(ICLanguageSettingEntry entry0, ICLanguageSettingEntry entry1) { - int kind0 = entry0.getKind(); - int kind1 = entry1.getKind(); - if (kind0==ICSettingEntry.MACRO && kind1==ICSettingEntry.MACRO) { - return entry0.getName().compareTo(entry1.getName()); - } - - return kind0 - kind1; - }}); - - return sortedEntries; - } - - /** - * - */ - public void setSettingEntries(String rcProjectPath, String languageId, List entries) { - synchronized (fStorage) { - if (entries!=null) { - Map> langMap = fStorage.get(languageId); - if (langMap==null) { - langMap = new HashMap>(); - fStorage.put(languageId, langMap); - } - List sortedEntries = getPooledList(sortEntries(entries), false); - langMap.put(rcProjectPath, sortedEntries); - } else { - // do not keep nulls in the tables - Map> langMap = fStorage.get(languageId); - if (langMap!=null) { - langMap.remove(rcProjectPath); - if (langMap.size()==0) { - fStorage.remove(languageId); - } - } - } - } - } - - /** - * @return {@code true} if the provider does not keep any settings yet or {@code false} if there are some. - */ - public boolean isEmpty() { - return fStorage.isEmpty(); - } - - /** - * Clear all the entries for all configurations, all resources and all languages. - */ - public void clear() { - synchronized (fStorage) { - fStorage.clear(); - } - } - - /** - * Serialize the provider entries under parent XML element. - * @param elementProvider - element where to serialize the entries. - */ - public void serializeEntries(Element elementProvider) { - synchronized (fStorage) { - for (Entry>> entryLang : fStorage.entrySet()) { - serializeLanguage(elementProvider, entryLang); - } - } - } - - /** - * Serialize the provider entries for a given language list. - */ - private void serializeLanguage(Element parentElement, Entry>> entryLang) { - String langId = entryLang.getKey(); - if (langId!=null) { - Element elementLanguage = XmlUtil.appendElement(parentElement, ELEM_LANGUAGE, new String[] {ATTR_LANGUAGE_ID, langId}); - parentElement = elementLanguage; - } - for (Entry> entryRc : entryLang.getValue().entrySet()) { - serializeResource(parentElement, entryRc); - } - } - - /** - * Serialize the provider entries for a given resource list. - */ - private void serializeResource(Element parentElement, Entry> entryRc) { - String rcProjectPath = entryRc.getKey(); - if (rcProjectPath!=null) { - Element elementRc = XmlUtil.appendElement(parentElement, ELEM_RESOURCE, new String[] {ATTR_PROJECT_PATH, rcProjectPath}); - parentElement = elementRc; - } - serializeSettingEntries(parentElement, entryRc.getValue()); - } - - /** - * Serialize given settings entries. - */ - private void serializeSettingEntries(Element parentElement, List settingEntries) { - for (ICLanguageSettingEntry entry : settingEntries) { - Element elementSettingEntry = XmlUtil.appendElement(parentElement, ELEM_ENTRY, new String[] { - ATTR_KIND, LanguageSettingEntriesSerializer.kindToString(entry.getKind()), - ATTR_NAME, entry.getName(), - }); - switch(entry.getKind()) { - case ICSettingEntry.MACRO: - elementSettingEntry.setAttribute(ATTR_VALUE, entry.getValue()); - break; -// case ICLanguageSettingEntry.LIBRARY_FILE: -// // TODO: sourceAttachment fields may need to be covered -// break; - } - int flags = entry.getFlags(); - if (flags!=0) { - // Element elementFlag = - XmlUtil.appendElement(elementSettingEntry, ELEM_FLAG, new String[] { - ATTR_VALUE, LanguageSettingEntriesSerializer.composeFlagsString(entry.getFlags()) - }); - } - } - } - - /** - * Load provider entries from XML provider element. - * @param providerNode - parent XML element where entries are defined. - */ - public void loadEntries(Element providerNode) { - List settings = new ArrayList(); - NodeList nodes = providerNode.getChildNodes(); - for (int i=0;i0) { - setSettingEntries(null, null, settings); - } - } - - /** - * Load a setting entry from XML element. - */ - private ICLanguageSettingEntry loadSettingEntry(Node parentElement) { - String settingKind = XmlUtil.determineAttributeValue(parentElement, ATTR_KIND); - String settingName = XmlUtil.determineAttributeValue(parentElement, ATTR_NAME); - - NodeList flagNodes = parentElement.getChildNodes(); - int flags = 0; - for (int i=0;i settings = new ArrayList(); - NodeList nodes = parentNode.getChildNodes(); - for (int i=0;i0) { - setSettingEntries(null, langId, settings); - } - } - - /** - * Load entries defined in resource element. - */ - private void loadResourceElement(Node parentNode, String cfgId, String langId) { - String rcProjectPath = XmlUtil.determineAttributeValue(parentNode, ATTR_PROJECT_PATH); - - List settings = new ArrayList(); - NodeList nodes = parentNode.getChildNodes(); - for (int i=0;i0) { - setSettingEntries(rcProjectPath, langId, settings); - } - } - - /** - * Returns the equal list of entries from the pool to conserve the memory. - * - * @param entries - list of entries to pool. - * @param copy - specify {@code true} to copy the list in order to prevent - * back-door modification on the original list changes. - * @return returns the list of entries from the pool. - */ - private static List getPooledList(List entries, boolean copy) { - if (entries == null) - return null; - - List pooledList = listPool.get(entries); - if (pooledList != null) { - return pooledList; - } - - if (entries.size() == 0) { - return getPooledEmptyList(); - } - - if (copy) { - entries = new ArrayList(entries); - } - pooledList = Collections.unmodifiableList(entries); - return listPool.add(pooledList); - } - - /** - * Returns the equal list of entries from the pool to conserve the memory. - * - * @param entries - list of entries to pool. - * @return returns the list of entries from the pool. - */ - public static List getPooledList(List entries) { - return getPooledList(entries, true); - } - - /** - * @return the empty immutable list which is pooled. Use this call rather than creating - * new empty array to ensure that operator '==' can be used instead of deep equals(). - */ - public static List getPooledEmptyList() { - List pooledEmptyList = Collections.emptyList(); - return listPool.add(pooledEmptyList); - } - - /** - * Clone storage for the entries. Copies references for lists of entries as a whole. - * Note that is OK as the lists kept in storage are unmodifiable. - */ - public LanguageSettingsStorage cloneStorage() { - LanguageSettingsStorage storageClone = new LanguageSettingsStorage(); - synchronized (fStorage) { - Set>>> entrySetLang = fStorage.entrySet(); - for (Entry>> entryLang : entrySetLang) { - String langId = entryLang.getKey(); - Map> mapRc = entryLang.getValue(); - Map> mapRcClone = new HashMap>(); - Set>> entrySetRc = mapRc.entrySet(); - for (Entry> entryRc : entrySetRc) { - String rcProjectPath = entryRc.getKey(); - List lsEntries = entryRc.getValue(); - // don't need to clone entries, they are from the LSE pool - mapRcClone.put(rcProjectPath, lsEntries); - } - storageClone.fStorage.put(langId, mapRcClone); - } - } - return storageClone; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((fStorage == null) ? 0 : fStorage.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - LanguageSettingsStorage other = (LanguageSettingsStorage) obj; - if (fStorage == null) { - if (other.fStorage != null) - return false; - } else if (!fStorage.equals(other.fStorage)) - return false; - return true; - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationSpecSettings.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationSpecSettings.java index a7c6d604840..6b140bba8ea 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationSpecSettings.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationSpecSettings.java @@ -23,9 +23,10 @@ import java.util.Map.Entry; import java.util.Set; import org.eclipse.cdt.core.CCorePlugin; +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.LanguageSettingsManager; -import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializableProvider; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsStorage; import org.eclipse.cdt.core.settings.model.CExternalSetting; import org.eclipse.cdt.core.settings.model.ICBuildSetting; import org.eclipse.cdt.core.settings.model.ICConfigExtensionReference; @@ -45,7 +46,6 @@ import org.eclipse.cdt.internal.core.cdtvariables.StorableCdtVariables; import org.eclipse.cdt.internal.core.envvar.EnvironmentVariableManager; import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsDelta; import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer; -import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsStorage; import org.eclipse.cdt.utils.envvar.StorableEnvironment; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.QualifiedName; @@ -193,11 +193,15 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ fOwner = base.fOwner; copyExtensionInfo(base); - + fLanguageSettingsProviders = LanguageSettingsProvidersSerializer.cloneProviders(base.getLanguageSettingProviders()); for (String providerId : base.lspPersistedState.keySet()) { - LanguageSettingsStorage clone = base.lspPersistedState.get(providerId).cloneStorage(); - lspPersistedState.put(providerId, clone); + try { + LanguageSettingsStorage clone = base.lspPersistedState.get(providerId).clone(); + lspPersistedState.put(providerId, clone); + } catch (CloneNotSupportedException e) { + CCorePlugin.log(e); + } } } @@ -997,11 +1001,11 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ public void updateExternalSettingsProviders(String[] ids){ ExtensionContainerFactory.updateReferencedProviderIds(fCfg, ids); } - + /** * Adds list of {@link ILanguageSettingsProvider} to the specs. * Note that only unique IDs are accepted. - * + * * @param providers - list of providers to keep in the specs. */ public void setLanguageSettingProviders(List providers) { @@ -1035,32 +1039,25 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ */ public LanguageSettingsDelta dropDelta() { LanguageSettingsDelta languageSettingsDelta = null; - // newState gets shallow map first - LinkedHashMap newStateShallow = new LinkedHashMap(); + LinkedHashMap newState = new LinkedHashMap(); for (ILanguageSettingsProvider provider : fLanguageSettingsProviders) { if (LanguageSettingsManager.isWorkspaceProvider(provider)) { provider = LanguageSettingsManager.getRawProvider(provider); } - if (provider instanceof LanguageSettingsSerializableProvider) { - LanguageSettingsStorage store = ((LanguageSettingsSerializableProvider) provider).getStorageInternal(); - if (!store.isEmpty()) { - newStateShallow.put(provider.getId(), store); + if (provider instanceof ILanguageSettingsBroadcastingProvider) { + LanguageSettingsStorage store = ((ILanguageSettingsBroadcastingProvider) provider).copyStorage(); + // avoid triggering event if empty provider was added + if (store != null && !store.isEmpty()) { + newState.put(provider.getId(), store); } } } - if (!newStateShallow.equals(lspPersistedState)) { - // do deep copy if the state needs to be saved - LinkedHashMap newStateDeep = new LinkedHashMap(); - for (Entry entry : newStateShallow.entrySet()) { - String providerId = entry.getKey(); - LanguageSettingsStorage store = entry.getValue(); - newStateDeep.put(providerId, store.cloneStorage()); - } - languageSettingsDelta = new LanguageSettingsDelta(lspPersistedState, newStateDeep); - lspPersistedState = newStateDeep; + if (!newState.equals(lspPersistedState)) { + languageSettingsDelta = new LanguageSettingsDelta(lspPersistedState, newState); + lspPersistedState = newState; } - + return languageSettingsDelta; } - + } From 45cc4634f1c4aa10bba25d65b17a635fe581cf6e Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Sun, 27 Nov 2011 14:55:24 -0500 Subject: [PATCH 072/120] JavaDoc mostly --- .../ILanguageSettingsEditableProvider.java | 7 ++- .../providers/ILanguageSettingsProvider.java | 22 ++++--- .../LanguageSettingsGenericProvider.java | 4 +- .../LanguageSettingsSerializableProvider.java | 57 +++++++++++-------- .../providers/LanguageSettingsStorage.java | 47 ++++++++------- .../ILanguageSettingsChangeEvent.java | 10 +++- .../ILanguageSettingsChangeListener.java | 10 ++-- .../providers/LanguageSettingsDelta.java | 23 +++++++- .../providers/LanguageSettingsLogger.java | 10 ++-- .../LanguageSettingsSerializableStorage.java | 43 +++++++------- 10 files changed, 143 insertions(+), 90 deletions(-) diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsEditableProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsEditableProvider.java index 2147b479101..3ba6e16d52c 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsEditableProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsEditableProvider.java @@ -35,9 +35,10 @@ public interface ILanguageSettingsEditableProvider extends ILanguageSettingsBroa * Sets language settings entries for the provider. * * @param cfgDescription - configuration description. - * @param rc - resource such as file or folder. - * @param languageId - language id. If {@code null}, then entries are considered to be defined for - * any language. + * @param rc - resource such as file or folder. If {@code null} the entries are + * considered to be being defined as default entries for resources. + * @param languageId - language id. If {@code null}, then entries are considered + * to be defined as default entries for languages. * @param entries - language settings entries to set. */ public void setSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId, List entries); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsProvider.java index 7fb46ce045b..fe428bee2dc 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsProvider.java @@ -27,12 +27,18 @@ import org.eclipse.core.resources.IResource; *

    * To define a provider like that use extension point * {@code org.eclipse.cdt.core.LanguageSettingsProvider} and implement this - * interface. CDT provides a few general use implementations such as - * {@link LanguageSettingsBaseProvider} or {@link LanguageSettingsSerializableProvider} - * or {@link LanguageSettingsGenericProvider} which could be used out of the box or - * extended. See also extension point schema description LanguageSettingsProvider.exsd. - * - * @since 6.0 + * interface. The recommended way of implementing is to extend + * {@link LanguageSettingsSerializableProvider} and implement {@link ILanguageSettingsEditableProvider}. + * That will give the ability to persist and edit/clean entries by user in UI. + * The clone methods defined by {@link ILanguageSettingsEditableProvider} should be + * chained as done for example by {@link LanguageSettingsGenericProvider}. + *

    + * CDT provides a few general use implementations in the core such as {@link LanguageSettingsBaseProvider} + * or {@link LanguageSettingsSerializableProvider} or {@link LanguageSettingsGenericProvider} + * which could be used out of the box or built upon. There are also abstract classes in build + * plugins {@code AbstractBuildCommandParser} and {@code AbstractBuiltinSpecsDetector} which + * serve as a base for output parsers and built-in compiler language settings detectors. + * See also extension point schema description LanguageSettingsProvider.exsd. */ public interface ILanguageSettingsProvider { /** @@ -65,7 +71,9 @@ public interface ILanguageSettingsProvider { * * @param cfgDescription - configuration description. * @param rc - resource such as file or folder. - * @param languageId - language id + * If {@code null}, the default entries for all resources are returned. + * @param languageId - language id. + * If {@code null}, the default entries for all languages are returned. * (see {@link LanguageManager#getLanguageForFile(org.eclipse.core.resources.IFile, ICConfigurationDescription)}). * * @return the list of setting entries or {@code null} if no settings defined. diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsGenericProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsGenericProvider.java index f920aa29d3f..8a7e8db180c 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsGenericProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsGenericProvider.java @@ -8,12 +8,14 @@ * Contributors: * Andrew Gvozdev - initial API and implementation *******************************************************************************/ - package org.eclipse.cdt.core.language.settings.providers; /** * Generic implementation of language settings provider which can be edited in UI * with entries persisted between eclipse sessions. + * The instances of this class can be used in plugin.xml to create a new provider + * but this class is not intended to be extended. For more details how to create a + * language settings provider see the description of {@link ILanguageSettingsProvider}. */ final public class LanguageSettingsGenericProvider extends LanguageSettingsSerializableProvider implements ILanguageSettingsEditableProvider { diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableProvider.java index 446173c43c5..2313ee731b7 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableProvider.java @@ -8,7 +8,6 @@ * Contributors: * Andrew Gvozdev - initial API and implementation *******************************************************************************/ - package org.eclipse.cdt.core.language.settings.providers; import java.util.ArrayList; @@ -17,24 +16,25 @@ import java.util.List; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; +import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.internal.core.XmlUtil; +import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer; import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsSerializableStorage; import org.eclipse.core.resources.IResource; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; - /** * This class is the base class for language settings providers able to serialize * into XML storage. - * Although this class has setter methods, it is not editable in UI by design. - * Implement {@link ILanguageSettingsEditableProvider} interface for that. - * - * TODO - more JavaDoc, info and hints about class hierarchy - * + * Although this class has setter methods, its instances are not editable in UI by + * design. Implement {@link ILanguageSettingsEditableProvider} interface for that. + * For more on the suggested way of extending this class see the description of + * {@link ILanguageSettingsProvider}. */ public class LanguageSettingsSerializableProvider extends LanguageSettingsBaseProvider implements ILanguageSettingsBroadcastingProvider { + /** This field is for internal use only */ public static final String ELEM_PROVIDER = "provider"; //$NON-NLS-1$ private static final String ATTR_ID = "id"; //$NON-NLS-1$ @@ -53,6 +53,7 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr /** * Default constructor. This constructor has to be always followed with setting id and name of the provider. + * This constructor is necessary to instantiate the class via the extension point in plugin.xml. */ public LanguageSettingsSerializableProvider() { super(); @@ -62,7 +63,7 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr * Constructor. * * @param id - id of the provider. - * @param name - name of the provider. Note that this name may show up in UI. + * @param name - name of the provider. Note that this name shows up in UI. */ public LanguageSettingsSerializableProvider(String id, String name) { super(id, name); @@ -153,12 +154,19 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr /** * Sets language settings entries for the provider. - * Note that the entries are not persisted at that point. To persist use TODO + * Note that the entries are not persisted at that point. Use this method to + * set the entries for all resources and then to persist use + * {@fixme FIXME - update references with API versions} + * {@link LanguageSettingsProvidersSerializer#serializeLanguageSettings(ICProjectDescription)} or + * {@link LanguageSettingsProvidersSerializer#serializeLanguageSettingsWorkspace()}. + * See for example {@code AbstractBuildCommandParser} and {@code AbstractBuiltinSpecsDetector} + * in build plugins. * * @param cfgDescription - configuration description. - * @param rc - resource such as file or folder. - * @param languageId - language id. If {@code null}, then entries are considered to be defined for - * the language scope. See {@link #getLanguageScope()} + * @param rc - resource such as file or folder. If {@code null} the entries are + * considered to be being defined as default entries for resources. + * @param languageId - language id. If {@code null}, then entries are considered + * to be defined for the language scope. See {@link #getLanguageScope()} * @param entries - language settings entries to set. */ public void setSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId, List entries) { @@ -171,17 +179,18 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr *
    * Note that this list is unmodifiable. To modify the list copy it, change and use * {@link #setSettingEntries(ICConfigurationDescription, IResource, String, List)}. - *
    + *

    * Note also that you can compare these lists with simple equality operator ==, - * as lists themselves are backed by WeakHashSet> where + * as the lists themselves are backed by WeakHashSet> where * identical copies (deep comparison is used) are replaced with the same one instance. */ @Override public List getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) { - List entries = fStorage.getSettingEntries(cfgDescription, rc, languageId); + String rcProjectPath = rc!=null ? rc.getProjectRelativePath().toString() : null; + List entries = fStorage.getSettingEntries(rcProjectPath, languageId); if (entries == null) { - if (languageId!=null && (languageScope==null || languageScope.contains(languageId))) { - entries = getSettingEntries(cfgDescription, rc, null); + if (languageId != null && (languageScope == null || languageScope.contains(languageId))) { + entries = fStorage.getSettingEntries(rcProjectPath, null); } } @@ -195,7 +204,7 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr * {@link #serializeEntries(Element)} instead. * * @param parentElement - element where to serialize. - * @return - newly created element. That element will already be + * @return - newly created "provider" element. That element will already be * attached to the parent element. */ final public Element serialize(Element parentElement) { @@ -219,7 +228,7 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr * equivalent to serializing everything (including language scope) except entries. * * @param parentElement - element where to serialize. - * @return - newly created element. That element will already be + * @return - newly created "provider" element. That element will already be * attached to the parent element. */ public Element serializeAttributes(Element parentElement) { @@ -253,7 +262,7 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr * Override {@link #loadAttributes(Element)} or * {@link #loadEntries(Element)} instead. * - * @param providerNode - XML element to load provider from. + * @param providerNode - XML element "provider" to load provider from. */ final public void load(Element providerNode) { fStorage.clear(); @@ -280,7 +289,7 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr /** * Load attributes from XML provider element. - * @param providerNode - XML element to load attributes from. + * @param providerNode - XML element "provider" to load attributes from. */ public void loadAttributes(Element providerNode) { String providerId = XmlUtil.determineAttributeValue(providerNode, ATTR_ID); @@ -308,15 +317,15 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr /** * Load provider entries from XML provider element. - * @param providerNode - parent XML element where entries are defined. + * @param providerNode - parent XML element "provider" where entries are defined. */ public void loadEntries(Element providerNode) { fStorage.loadEntries(providerNode); } /** - * See {@link #cloneShallow()}. This method is extracted - * to avoid expressing {@link #clone()} via {@link #cloneShallow()}. + * See {@link #cloneShallow()}. This method is extracted to avoid expressing + * {@link #clone()} via {@link #cloneShallow()}. Do not inline to "optimize"! */ private LanguageSettingsSerializableProvider cloneShallowInternal() throws CloneNotSupportedException { LanguageSettingsSerializableProvider clone = (LanguageSettingsSerializableProvider)super.clone(); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsStorage.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsStorage.java index bc5f077954d..7ed56cb75ae 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsStorage.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsStorage.java @@ -19,17 +19,15 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; -import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.internal.core.parser.util.WeakHashSet; -import org.eclipse.core.resources.IResource; +/** + * The class representing the (in-memory) storage for language settings entries {@link ICLanguageSettingEntry}. + */ public class LanguageSettingsStorage implements Cloneable { - /** - * Storage to keep settings entries. Note that it is not necessary to keep configuration in the maps - * as the configuration is always the one provider belongs to. - */ + /** Storage to keep settings entries. */ protected Map>> fStorage = new HashMap>>(); @@ -44,26 +42,28 @@ public class LanguageSettingsStorage implements Cloneable { public synchronized List add(List list) { return super.add(list); } - }; /** - * TODO + * Returns the list of setting entries for the given resource and language. *
    Note that this list is unmodifiable. * + * @param rcProjectPath - path to the resource relative to the project. + * @param languageId - language id. + * + * @return the list of setting entries or {@code null} if no settings defined. */ - public List getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) { + public List getSettingEntries(String rcProjectPath, String languageId) { List entries = null; Map> langMap = fStorage.get(languageId); if (langMap!=null) { - String rcProjectPath = rc!=null ? rc.getProjectRelativePath().toString() : null; entries = langMap.get(rcProjectPath); } return entries; } /** - * Some providers may collect entries in pretty much random order. For the purposes of + * Some providers may collect entries in pretty much random order. For the intent of * predictability, UI usability and efficient storage the entries are sorted by kinds * and secondary by name for kinds where the secondary order is not significant. * @@ -72,7 +72,7 @@ public class LanguageSettingsStorage implements Cloneable { */ private List sortEntries(List entries) { List sortedEntries = new ArrayList(entries); - Collections.sort(sortedEntries, new Comparator(){ + Collections.sort(sortedEntries, new Comparator() { /** * This comparator sorts by kinds first and the macros are sorted additionally by name. */ @@ -91,7 +91,11 @@ public class LanguageSettingsStorage implements Cloneable { } /** + * Sets language settings entries for the resource and language. * + * @param rcProjectPath - path to the resource relative to the project. + * @param languageId - language id. + * @param entries - language settings entries to set. */ public void setSettingEntries(String rcProjectPath, String languageId, List entries) { synchronized (fStorage) { @@ -104,7 +108,7 @@ public class LanguageSettingsStorage implements Cloneable { List sortedEntries = getPooledList(sortEntries(entries), false); langMap.put(rcProjectPath, sortedEntries); } else { - // do not keep nulls in the tables + // reduct the empty maps in the tables Map> langMap = fStorage.get(languageId); if (langMap!=null) { langMap.remove(rcProjectPath); @@ -117,14 +121,14 @@ public class LanguageSettingsStorage implements Cloneable { } /** - * @return {@code true} if the provider does not keep any settings yet or {@code false} if there are some. + * @return {@code true} if the storage is empty or {@code false} otherwise. */ public boolean isEmpty() { return fStorage.isEmpty(); } /** - * Clear all the entries for all configurations, all resources and all languages. + * Clear all the entries for all resources and all languages. */ public void clear() { synchronized (fStorage) { @@ -133,7 +137,7 @@ public class LanguageSettingsStorage implements Cloneable { } /** - * Returns the equal list of entries from the pool to conserve the memory. + * Find and return the equal list of entries from the pool. * * @param entries - list of entries to pool. * @param copy - specify {@code true} to copy the list in order to prevent @@ -161,7 +165,7 @@ public class LanguageSettingsStorage implements Cloneable { } /** - * Returns the equal list of entries from the pool to conserve the memory. + * Find and return the equal list of entries from the pool to conserve the memory. * * @param entries - list of entries to pool. * @return returns the list of entries from the pool. @@ -171,8 +175,9 @@ public class LanguageSettingsStorage implements Cloneable { } /** - * @return the empty immutable list which is pooled. Use this call rather than creating - * new empty array to ensure that operator '==' can be used instead of deep equals(). + * @return Returns the empty immutable list which is pooled. Use this call rather than creating + * new empty array to ensure that faster shallow operator '==' can be used instead of equals() + * which goes deep on HashMaps. */ public static List getPooledEmptyList() { List pooledEmptyList = Collections.emptyList(); @@ -181,7 +186,7 @@ public class LanguageSettingsStorage implements Cloneable { /** * Clone storage for the entries. Copies references for lists of entries as a whole. - * Note that is OK as the lists kept in storage are unmodifiable. + * Note that that is OK as the lists kept in storage are unmodifiable and pooled. */ @Override public LanguageSettingsStorage clone() throws CloneNotSupportedException { @@ -197,7 +202,7 @@ public class LanguageSettingsStorage implements Cloneable { for (Entry> entryRc : entrySetRc) { String rcProjectPath = entryRc.getKey(); List lsEntries = entryRc.getValue(); - // don't need to clone entries, they are from the LSE pool + // don't need to clone entries, they are from the LSE lists pool mapRcClone.put(rcProjectPath, lsEntries); } storageClone.fStorage.put(langId, mapRcClone); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/ILanguageSettingsChangeEvent.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/ILanguageSettingsChangeEvent.java index 63b07601810..b5df5b35840 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/ILanguageSettingsChangeEvent.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/ILanguageSettingsChangeEvent.java @@ -17,9 +17,13 @@ import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; * language settings entries {@link ICLanguageSettingEntry}. The event is * associated with a project. * - * API notes: this interface probably is not stable yet as it is not currently - * clear how it may need to be used in future. Only bare minimum is provided - * here at this point. + *

    + * EXPERIMENTAL. This class interface is not stable yet as + * it is not currently clear how it may need to be used in future. Only bare + * minimum is provided here at this point (CDT 9.0). + * There is no guarantee that this API will work or that it will remain the same. + * Please do not use this API without consulting with the CDT team. + *

    * * @noextend This interface is not intended to be extended by clients. * @noimplement This interface is not intended to be implemented by clients. diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/ILanguageSettingsChangeListener.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/ILanguageSettingsChangeListener.java index 3e0ae4d1a3b..8230200c5cd 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/ILanguageSettingsChangeListener.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/ILanguageSettingsChangeListener.java @@ -10,17 +10,19 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.language.settings.providers; +import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; + /** - * An interface for listeners to changes in language settings. - * + * An interface for listeners to changes in language settings {@link ICLanguageSettingEntry}. + * * @see LanguageSettingsProvidersSerializer#registerLanguageSettingsChangeListener(ILanguageSettingsChangeListener) * @see LanguageSettingsProvidersSerializer#unregisterLanguageSettingsChangeListener(ILanguageSettingsChangeListener) */ public interface ILanguageSettingsChangeListener { /** * Indicates that language settings have been changed. - * - * @param event - details of the event. + * + * @param event - details of the event. */ public void handleEvent(ILanguageSettingsChangeEvent event); } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsDelta.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsDelta.java index 317f545e14d..994597b69fb 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsDelta.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsDelta.java @@ -13,11 +13,24 @@ package org.eclipse.cdt.internal.core.language.settings.providers; import java.util.LinkedHashMap; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsStorage; +import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; /** - * This class currently is a placeholder holding old and new states. - * If more details need to be pulled out of delta, it could be elaborated further. + * Contains the delta of changes that occurred as a result of modifying + * language settings entries {@link ICLanguageSettingEntry}. The delta is + * associated with a configuration description. + * + *

    + * EXPERIMENTAL. This class interface is not stable yet as + * it is not currently clear how it may need to be used in future. Only bare + * minimum is provided here at this point (CDT 9.0). + * There is no guarantee that this API will work or that it will remain the same. + * Please do not use this API without consulting with the CDT team. + *

    + * + * @noextend This interface is not intended to be extended by clients. + * @noinstantiate This class is not intended to be instantiated by clients. */ public class LanguageSettingsDelta { // maps need to be ordered by providers @@ -28,6 +41,12 @@ public class LanguageSettingsDelta { private LinkedHashMap newLanguageSettingsState; + /** + * Constructor. + * + * @param oldState - old language settings storage state. + * @param newState - new language settings storage state. + */ public LanguageSettingsDelta(LinkedHashMap oldState, LinkedHashMap newState) { oldLanguageSettingsState = oldState; newLanguageSettingsState = newState; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsLogger.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsLogger.java index 40d7c54fcfa..ee98cfda988 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsLogger.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsLogger.java @@ -7,6 +7,10 @@ import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; +/** + * Temporary class for logging language settings providers development. + * + */ @Deprecated public class LanguageSettingsLogger { @@ -15,7 +19,6 @@ public class LanguageSettingsLogger { // return true; } - // AG FIXME /** * @param msg * @noreference This method is not intended to be referenced by clients. @@ -29,7 +32,6 @@ public class LanguageSettingsLogger { } } - // AG FIXME /** * @param msg * @noreference This method is not intended to be referenced by clients. @@ -43,7 +45,6 @@ public class LanguageSettingsLogger { } } - // AG FIXME /** * @param msg * @noreference This method is not intended to be referenced by clients. @@ -56,8 +57,7 @@ public class LanguageSettingsLogger { CCorePlugin.log(status); } } - - // AG FIXME + /** * @param rc * @param who - pass "this" (calling class instance) here diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsSerializableStorage.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsSerializableStorage.java index f2e05acd297..70c7904ed16 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsSerializableStorage.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsSerializableStorage.java @@ -25,6 +25,9 @@ import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; +/** + * The class representing persistent storage for language settings entries {@link ICLanguageSettingEntry}. + */ public class LanguageSettingsSerializableStorage extends LanguageSettingsStorage { private static final String ELEM_LANGUAGE = "language"; //$NON-NLS-1$ private static final String ATTR_LANGUAGE_ID = "id"; //$NON-NLS-1$ @@ -39,12 +42,13 @@ public class LanguageSettingsSerializableStorage extends LanguageSettingsStorage /** * Serialize the provider entries under parent XML element. + * * @param elementProvider - element where to serialize the entries. */ public void serializeEntries(Element elementProvider) { synchronized (fStorage) { for (Entry>> entryLang : fStorage.entrySet()) { - serializeLanguage(elementProvider, entryLang); + serializeLanguage(elementProvider, entryLang.getKey(), entryLang.getValue()); } } } @@ -52,27 +56,25 @@ public class LanguageSettingsSerializableStorage extends LanguageSettingsStorage /** * Serialize the provider entries for a given language list. */ - private void serializeLanguage(Element parentElement, Entry>> entryLang) { - String langId = entryLang.getKey(); + private void serializeLanguage(Element parentElement, String langId, Map> langMap) { if (langId!=null) { Element elementLanguage = XmlUtil.appendElement(parentElement, ELEM_LANGUAGE, new String[] {ATTR_LANGUAGE_ID, langId}); parentElement = elementLanguage; } - for (Entry> entryRc : entryLang.getValue().entrySet()) { - serializeResource(parentElement, entryRc); + for (Entry> entryRc : langMap.entrySet()) { + serializeResource(parentElement, entryRc.getKey(), entryRc.getValue()); } } /** * Serialize the provider entries for a given resource list. */ - private void serializeResource(Element parentElement, Entry> entryRc) { - String rcProjectPath = entryRc.getKey(); + private void serializeResource(Element parentElement, String rcProjectPath, List rcList) { if (rcProjectPath!=null) { Element elementRc = XmlUtil.appendElement(parentElement, ELEM_RESOURCE, new String[] {ATTR_PROJECT_PATH, rcProjectPath}); parentElement = elementRc; } - serializeSettingEntries(parentElement, entryRc.getValue()); + serializeSettingEntries(parentElement, rcList); } /** @@ -84,16 +86,16 @@ public class LanguageSettingsSerializableStorage extends LanguageSettingsStorage ATTR_KIND, LanguageSettingEntriesSerializer.kindToString(entry.getKind()), ATTR_NAME, entry.getName(), }); - switch(entry.getKind()) { + switch (entry.getKind()) { case ICSettingEntry.MACRO: elementSettingEntry.setAttribute(ATTR_VALUE, entry.getValue()); break; // case ICLanguageSettingEntry.LIBRARY_FILE: -// // TODO: sourceAttachment fields may need to be covered +// // YAGNI: sourceAttachment fields may need to be covered // break; } int flags = entry.getFlags(); - if (flags!=0) { + if (flags != 0) { // Element elementFlag = XmlUtil.appendElement(elementSettingEntry, ELEM_FLAG, new String[] { ATTR_VALUE, LanguageSettingEntriesSerializer.composeFlagsString(entry.getFlags()) @@ -104,14 +106,15 @@ public class LanguageSettingsSerializableStorage extends LanguageSettingsStorage /** * Load provider entries from XML provider element. - * @param providerNode - parent XML element where entries are defined. + * + * @param providerNode - parent XML element "provider" where entries are defined. */ public void loadEntries(Element providerNode) { List settings = new ArrayList(); NodeList nodes = providerNode.getChildNodes(); for (int i=0;i0) { + if (settings.size() > 0) { setSettingEntries(null, null, settings); } } @@ -142,7 +145,7 @@ public class LanguageSettingsSerializableStorage extends LanguageSettingsStorage int flags = 0; for (int i=0;i0) { + if (settings.size() > 0) { setSettingEntries(null, langId, settings); } } @@ -200,7 +203,7 @@ public class LanguageSettingsSerializableStorage extends LanguageSettingsStorage NodeList nodes = parentNode.getChildNodes(); for (int i=0;i0) { + if (settings.size() > 0) { setSettingEntries(rcProjectPath, langId, settings); } } From f6151d3a72d069b2f23d7d4c9c35eb4493b80096 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Sun, 27 Nov 2011 15:17:18 -0500 Subject: [PATCH 073/120] Reducting LanguageSettingsManager_TBD --- .../managedbuilder/core/ManagedBuildManager.java | 13 +++++++------ .../providers/LanguageSettingsExtensionsTests.java | 5 +++-- .../providers/LanguageSettingsManager_TBD.java | 5 ----- .../LanguageSettingsProvidersSerializer.java | 5 ++--- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java index 345492d08f3..fd2bceeeb25 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java @@ -51,7 +51,6 @@ import org.eclipse.cdt.core.AbstractCExtension; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; -import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager_TBD; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModelUtil; import org.eclipse.cdt.core.parser.IScannerInfo; @@ -151,8 +150,6 @@ import org.w3c.dom.ProcessingInstruction; * @noinstantiate This class is not intended to be instantiated by clients. */ public class ManagedBuildManager extends AbstractCExtension { - - public static final String MBS_LANGUAGE_SETTINGS_PROVIDER = "org.eclipse.cdt.managedbuilder.core.LanguageSettingsProvider"; // private static final QualifiedName buildInfoProperty = new QualifiedName(ManagedBuilderCorePlugin.PLUGIN_ID, "managedBuildInfo"); //$NON-NLS-1$ private static final String ROOT_NODE_NAME = "ManagedProjectBuildInfo"; //$NON-NLS-1$ public static final String SETTINGS_FILE_NAME = ".cdtbuild"; //$NON-NLS-1$ @@ -194,6 +191,10 @@ public class ManagedBuildManager extends AbstractCExtension { public static final String INTERNAL_BUILDER_ID = "org.eclipse.cdt.build.core.internal.builder"; //$NON-NLS-1$ + public static final String MBS_LANGUAGE_SETTINGS_PROVIDER = "org.eclipse.cdt.managedbuilder.core.LanguageSettingsProvider"; + private static final String UI_USER_LANGUAGE_SETTINGS_PROVIDER = "org.eclipse.cdt.ui.user.LanguageSettingsProvider"; + private static final String LANGUAGE_SETTINGS_PROVIDER_DELIMITER = ";"; + private static final String os = Platform.getOS(); private static final String arch = Platform.getOSArch(); private static final String ALL = "all"; //$NON-NLS-1$ @@ -4758,7 +4759,7 @@ public class ManagedBuildManager extends AbstractCExtension { } providersIdsStr = providersIdsStr.replaceAll("\\$\\{Toolchain\\}", toolchainProvidersIds); } - List providersIds = Arrays.asList(providersIdsStr.split(String.valueOf(LanguageSettingsManager_TBD.PROVIDER_DELIMITER))); + List providersIds = Arrays.asList(providersIdsStr.split(LANGUAGE_SETTINGS_PROVIDER_DELIMITER)); for (String id : providersIds) { id = id.trim(); ILanguageSettingsProvider provider = null; @@ -4790,8 +4791,8 @@ public class ManagedBuildManager extends AbstractCExtension { providers.add(provider); } - if (!isProviderThere(providers, LanguageSettingsManager_TBD.PROVIDER_UI_USER)) { - ILanguageSettingsProvider provider = LanguageSettingsManager.getExtensionProviderCopy(LanguageSettingsManager_TBD.PROVIDER_UI_USER); + if (!isProviderThere(providers, UI_USER_LANGUAGE_SETTINGS_PROVIDER)) { + ILanguageSettingsProvider provider = LanguageSettingsManager.getExtensionProviderCopy(UI_USER_LANGUAGE_SETTINGS_PROVIDER); providers.add(0, provider); } diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java index 79aaaa3056f..d2f792f2a29 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java @@ -48,6 +48,7 @@ public class LanguageSettingsExtensionsTests extends BaseTestCase { /*package*/ static final String EXTENSION_EDITABLE_PROVIDER_ID = "org.eclipse.cdt.core.tests.custom.editable.language.settings.provider"; /*package*/ static final String EXTENSION_EDITABLE_PROVIDER_NAME = "Test Plugin Mock Editable Language Settings Provider"; /*package*/ static final String EXTENSION_REGISTERER_PROVIDER_ID = "org.eclipse.cdt.core.tests.language.settings.listener.registerer.provider"; + /*package*/ static final String EXTENSION_USER_PROVIDER_ID = "org.eclipse.cdt.ui.user.LanguageSettingsProvider"; // These are made up private static final String PROVIDER_0 = "test.provider.0.id"; @@ -328,8 +329,8 @@ public class LanguageSettingsExtensionsTests extends BaseTestCase { * Check that LanguageSettingsGenericProvider extension defined in plugin.xml is accessible. */ public void testExtensionGenericProvider() throws Exception { - ILanguageSettingsProvider provider = LanguageSettingsExtensionManager.getExtensionProviderClone(LanguageSettingsManager_TBD.PROVIDER_UI_USER); - assertNotNull("extension " + LanguageSettingsManager_TBD.PROVIDER_UI_USER + " not found", provider); + ILanguageSettingsProvider provider = LanguageSettingsExtensionManager.getExtensionProviderClone(EXTENSION_USER_PROVIDER_ID); + assertNotNull("extension " + EXTENSION_USER_PROVIDER_ID + " not found", provider); assertTrue(provider instanceof LanguageSettingsGenericProvider); } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager_TBD.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager_TBD.java index bb62b5c17d8..a7054aaf9b9 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager_TBD.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager_TBD.java @@ -17,7 +17,6 @@ import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; 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.resources.IResource; @@ -25,10 +24,6 @@ import org.eclipse.core.resources.IResource; * This temporary class keeps the utility methods being looking for better home */ public class LanguageSettingsManager_TBD { - public static final String PROVIDER_UNKNOWN = "org.eclipse.cdt.projectmodel.4.0.0"; - public static final String PROVIDER_UI_USER = "org.eclipse.cdt.ui.user.LanguageSettingsProvider"; - public static final char PROVIDER_DELIMITER = LanguageSettingsProvidersSerializer.PROVIDER_DELIMITER; - public static boolean isCustomizedResource(ICConfigurationDescription cfgDescription, IResource rc) { if (rc instanceof IProject) return false; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java index 0e237ea0d21..6c6fa6bb28b 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java @@ -63,7 +63,6 @@ public class LanguageSettingsProvidersSerializer { 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_LANGUAGE_SETTINGS = "language.settings.xml"; //$NON-NLS-1$ - public static final char PROVIDER_DELIMITER = ';'; private static final String ELEM_PLUGIN = "plugin"; //$NON-NLS-1$ private static final String ELEM_EXTENSION = "extension"; //$NON-NLS-1$ private static final String ATTR_POINT = "point"; //$NON-NLS-1$ @@ -761,8 +760,8 @@ projects: for (ICConfigurationDescription cfgDescription : cfgDescriptions) { if (cfgDescription!=null) { List providers = new ArrayList(2); - ILanguageSettingsProvider userProvider = getWorkspaceProvider(ScannerDiscoveryLegacySupport.MBS_LANGUAGE_SETTINGS_PROVIDER); - providers.add(userProvider); + ILanguageSettingsProvider providerMBS = getWorkspaceProvider(ScannerDiscoveryLegacySupport.MBS_LANGUAGE_SETTINGS_PROVIDER); + providers.add(providerMBS); cfgDescription.setLanguageSettingProviders(providers); } } From 689c2a5f17c1b0aefadc10a1e58a090a802d7cc1 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Sun, 27 Nov 2011 20:02:02 -0500 Subject: [PATCH 074/120] Moved ILanguageSettingsChangeListener & ILanguageSettingsChangeEvent to API package, same for serializeLanguageSettings() & serializeLanguageSettingsWorkspace() --- .../AbstractBuildCommandParser.java | 35 ++-- .../AbstractBuiltinSpecsDetector.java | 90 ++++----- .../LanguageSettingsListenersTests.java | 29 ++- ...nguageSettingsPersistenceProjectTests.java | 2 +- ...ILanguageSettingsBroadcastingProvider.java | 1 - .../ILanguageSettingsChangeEvent.java | 2 +- .../ILanguageSettingsChangeListener.java | 6 +- .../providers/LanguageSettingsManager.java | 40 +++- .../LanguageSettingsManager_TBD.java | 2 +- .../LanguageSettingsSerializableProvider.java | 6 +- .../providers/LanguageSettingsLogger.java | 2 +- .../LanguageSettingsProvidersSerializer.java | 23 ++- .../model/CConfigurationSpecSettings.java | 7 +- .../model/SettingsModelMessages.properties | 1 - .../xml/XmlProjectDescriptionStorage.java | 3 +- .../pdom/LanguageSettingsChangeListener.java | 20 +- .../cdt/internal/core/pdom/PDOMManager.java | 180 +++++++++--------- 17 files changed, 243 insertions(+), 206 deletions(-) rename core/org.eclipse.cdt.core/model/org/eclipse/cdt/{internal => }/core/language/settings/providers/ILanguageSettingsChangeEvent.java (96%) rename core/org.eclipse.cdt.core/model/org/eclipse/cdt/{internal => }/core/language/settings/providers/ILanguageSettingsChangeListener.java (75%) diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java index b0dff614c2d..e3159346705 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java @@ -27,7 +27,6 @@ import org.eclipse.cdt.core.errorparsers.RegexErrorPattern; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.internal.core.ConsoleOutputSniffer; -import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer; import org.eclipse.cdt.make.core.MakeCorePlugin; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.ResourcesPlugin; @@ -40,7 +39,7 @@ import org.eclipse.core.runtime.jobs.Job; /** * TODO - class description - * + * * Note: IErrorParser interface is used here to work around {@link ConsoleOutputSniffer} having * no access from CDT core to build packages. TODO - elaborate? */ @@ -52,7 +51,7 @@ public abstract class AbstractBuildCommandParser extends AbstractLanguageSetting private static final String LEADING_PATH_PATTERN = "\\S+[/\\\\]"; //$NON-NLS-1$ private static final Pattern OPTIONS_PATTERN = Pattern.compile("-[^\\s\"']*(\\s*((\".*?\")|('.*?')|([^-\\s][^\\s]+)))?"); //$NON-NLS-1$ private static final int OPTION_GROUP = 0; - + /** * Note: design patterns to keep file group the same and matching {@link #FILE_GROUP} */ @@ -62,8 +61,8 @@ public abstract class AbstractBuildCommandParser extends AbstractLanguageSetting "${COMPILER_PATTERN}.*\\s" + "(['\"])(.*\\.${EXTENSIONS_PATTERN})\\${COMPILER_GROUPS+1}(\\s.*)?[\r\n]*" // compiling quoted file }; private static final int FILE_GROUP = 2; - - + + @SuppressWarnings("nls") private String getCompilerCommandPattern() { String parameter = getCustomParameter(); @@ -88,7 +87,7 @@ public abstract class AbstractBuildCommandParser extends AbstractLanguageSetting if (line==null) { return null; } - + for (String template : PATTERN_TEMPLATES) { String pattern = makePattern(template); Matcher fileMatcher = Pattern.compile(pattern).matcher(line); @@ -106,7 +105,7 @@ public abstract class AbstractBuildCommandParser extends AbstractLanguageSetting if (line==null || currentResource==null) { return null; } - + List options = new ArrayList(); Matcher optionMatcher = OPTIONS_PATTERN.matcher(line); while (optionMatcher.find()) { @@ -134,33 +133,23 @@ public abstract class AbstractBuildCommandParser extends AbstractLanguageSetting scheduleSerializingJob(currentCfgDescription); super.shutdown(); } - + private void scheduleSerializingJob(final ICConfigurationDescription cfgDescription) { Job job = new Job("Serialize CDT language settings entries") { @Override protected IStatus run(IProgressMonitor monitor) { - // FIXME - remove thread name reassigning - Thread thread = getThread(); - String oldName = thread.getName(); - thread.setName("CDT LSP Serializer,BOP"); - - IStatus status = null; + IStatus status = Status.OK_STATUS; try { if (cfgDescription != null) { - LanguageSettingsProvidersSerializer.serializeLanguageSettings(cfgDescription.getProjectDescription()); + LanguageSettingsManager.serializeLanguageSettings(cfgDescription.getProjectDescription()); } else { - LanguageSettingsProvidersSerializer.serializeLanguageSettingsWorkspace(); + LanguageSettingsManager.serializeLanguageSettingsWorkspace(); } } catch (CoreException e) { status = new Status(IStatus.ERROR, MakeCorePlugin.PLUGIN_ID, IStatus.ERROR, "Error serializing language settings", e); MakeCorePlugin.log(status); } - - if (status == null) - status = Status.OK_STATUS; - - thread.setName(oldName); return status; } @Override @@ -168,7 +157,7 @@ public abstract class AbstractBuildCommandParser extends AbstractLanguageSetting return family == JOB_FAMILY_BUILD_COMMAND_PARSER; } }; - + ISchedulingRule rule = null; if (currentProject != null) { IFolder settingsFolder = currentProject.getFolder(".settings"); @@ -193,7 +182,7 @@ public abstract class AbstractBuildCommandParser extends AbstractLanguageSetting * Trivial Error Parser which allows highlighting of output lines matching the patterns * of this parser. Intended for better troubleshooting experience. * Implementers are supposed to add the error parser as an extension. Initialize with - * build command parser extension ID. + * build command parser extension ID. */ protected static abstract class AbstractBuildCommandPatternHighlighter extends RegexErrorParser implements IErrorParser2 { public AbstractBuildCommandPatternHighlighter(String buildCommandParserPluginExtension) { diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java index 61a9c158ee6..2264e3f1af5 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java @@ -28,6 +28,7 @@ import org.eclipse.cdt.core.IMarkerGenerator; import org.eclipse.cdt.core.ProblemMarkerInfo; import org.eclipse.cdt.core.index.IIndexManager; import org.eclipse.cdt.core.language.settings.providers.ICListenerAgent; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICProject; @@ -41,7 +42,6 @@ import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.internal.core.ConsoleOutputSniffer; import org.eclipse.cdt.internal.core.XmlUtil; import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsLogger; -import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer; import org.eclipse.cdt.make.core.MakeCorePlugin; import org.eclipse.cdt.make.internal.core.MakeMessages; import org.eclipse.cdt.make.internal.core.StreamMonitor; @@ -99,7 +99,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti protected URI mappedRootURI = null; protected URI buildDirURI = null; - + private class SDMarkerGenerator implements IMarkerGenerator { protected static final String SCANNER_DISCOVERY_PROBLEM_MARKER = MakeCorePlugin.PLUGIN_ID + ".scanner.discovery.problem"; //$NON-NLS-1$ protected static final String PROVIDER = "provider"; //$NON-NLS-1$ @@ -135,14 +135,14 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti } catch (CoreException e) { return new Status(Status.ERROR, MakeCorePlugin.getUniqueIdentifier(), "Error removing markers.", e); } - + // add new marker try { IMarker marker = problemMarkerInfo.file.createMarker(SDMarkerGenerator.SCANNER_DISCOVERY_PROBLEM_MARKER); marker.setAttribute(IMarker.MESSAGE, problemMarkerInfo.description); marker.setAttribute(IMarker.SEVERITY, problemMarkerInfo.severity); marker.setAttribute(SDMarkerGenerator.PROVIDER, providerId); - + if (problemMarkerInfo.file instanceof IWorkspaceRoot) { marker.setAttribute(IMarker.LOCATION, "SD90 Providers, [" + providerName + "] options in Preferences"); } else { @@ -151,7 +151,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti } catch (CoreException e) { return new Status(Status.ERROR, MakeCorePlugin.getUniqueIdentifier(), "Error adding markers.", e); } - + return Status.OK_STATUS; } }; @@ -159,9 +159,9 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti markerJob.setRule(problemMarkerInfo.file); markerJob.schedule(); } - + } - + /** * This ICConsoleParser handles each individual run for one language from * {@link AbstractBuiltinSpecsDetector#runForEachLanguage(ICConfigurationDescription, IPath, String[], IProgressMonitor)} @@ -220,7 +220,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti // This works as if workspace-wide return null; } - + @Override protected String determineLanguage() { // language id is supposed to be set by run(), just return it @@ -234,7 +234,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti } return mappedRootURI; } - + @Override protected URI getBuildDirURI(URI mappedRootURI) { if (buildDirURI==null) { @@ -246,7 +246,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti @Override public void registerListener(ICConfigurationDescription cfgDescription) { LanguageSettingsLogger.logInfo(getPrefixForLog() + "registerListener [" + System.identityHashCode(this) + "] " + this); - + currentCfgDescription = cfgDescription; execute(); } @@ -264,7 +264,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti return; } isExecuted = true; - + Job job = new Job("Discover compiler's built-in language settings") { @Override protected IStatus run(IProgressMonitor monitor) { @@ -275,7 +275,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti return family == JOB_FAMILY_BUILTIN_SPECS_DETECTOR; } }; - + IProject ownerProject = null; if (currentCfgDescription != null) { ICProjectDescription prjDescription = currentCfgDescription.getProjectDescription(); @@ -292,7 +292,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti } job.setRule(rule); job.schedule(); - + // TODO - remove me LanguageSettingsLogger.logInfo(getPrefixForLog() + "Execution scheduled [" + System.identityHashCode(this) + "] " + this); } @@ -312,24 +312,24 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti } MultiStatus status = new MultiStatus(MakeCorePlugin.PLUGIN_ID, IStatus.OK, "Problem running CDT Scanner Discovery provider " + getId(), null); - + boolean isChanged = false; mappedRootURI = null; buildDirURI = null; - + if (monitor == null) { monitor = new NullProgressMonitor(); } try { - + List languageIds = getLanguageScope(); if (languageIds != null) { int totalWork = TICKS_CLEAN_MARKERS + languageIds.size()*TICKS_RUN_FOR_ONE_LANGUAGE + TICKS_SERIALIZATION; monitor.beginTask("CDT Scanner Discovery", totalWork * TICKS_SCALE); - + IResource markersResource = currentProject!= null ? currentProject : ResourcesPlugin.getWorkspace().getRoot(); - + // clear old markers monitor.subTask("Clearing stale markers"); try { @@ -342,19 +342,19 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti } catch (CoreException e) { MakeCorePlugin.log(e); } - + if (monitor.isCanceled()) throw new OperationCanceledException(); - + monitor.worked(TICKS_CLEAN_MARKERS * TICKS_SCALE); - + for (String languageId : languageIds) { List oldEntries = getSettingEntries(cfgDescription, null, languageId); try { startupForLanguage(languageId); if (monitor.isCanceled()) throw new OperationCanceledException(); - + runForLanguage(workingDirectory, env, new SubProgressMonitor(monitor, TICKS_RUN_FOR_ONE_LANGUAGE * TICKS_SCALE)); if (monitor.isCanceled()) throw new OperationCanceledException(); @@ -367,24 +367,24 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti } List newEntries = getSettingEntries(cfgDescription, null, languageId); isChanged = isChanged || newEntries != oldEntries; - + } } - + monitor.subTask("Serializing results"); if (isChanged) { // avoids resource and settings change notifications try { if (currentCfgDescription != null) { - LanguageSettingsProvidersSerializer.serializeLanguageSettings(currentCfgDescription.getProjectDescription()); + LanguageSettingsManager.serializeLanguageSettings(currentCfgDescription.getProjectDescription()); } else { - LanguageSettingsProvidersSerializer.serializeLanguageSettingsWorkspace(); + LanguageSettingsManager.serializeLanguageSettingsWorkspace(); } } catch (CoreException e) { IStatus s = new Status(IStatus.ERROR, MakeCorePlugin.PLUGIN_ID, IStatus.ERROR, "Error serializing language settings", e); MakeCorePlugin.log(s); status.merge(s); } - + // AG: FIXME - rather send event that ls settings changed if (currentCfgDescription != null) { ICProject icProject = CoreModel.getDefault().create(currentProject); @@ -402,7 +402,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti } if (monitor.isCanceled()) throw new OperationCanceledException(); - + monitor.worked(TICKS_SERIALIZATION * TICKS_SCALE); } catch (OperationCanceledException e) { if (!status.isOK()) { @@ -418,7 +418,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti shutdown(); currentCfgDescription = cfgDescription; // current description gets cleared in super.shutdown(), keep it } - + return status; } @@ -427,7 +427,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti specFile = null; // can get set in resolveCommand() currentCommandResolved = resolveCommand(currentLanguageId); - + detectedSettingEntries = new ArrayList(); collected = 0; } @@ -435,20 +435,20 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti protected void shutdownForLanguage() { if (detectedSettingEntries != null && detectedSettingEntries.size() > 0) { collected = detectedSettingEntries.size(); - + LanguageSettingsLogger.logInfo(getPrefixForLog() + getClass().getSimpleName() + " collected " + detectedSettingEntries.size() + " entries" + " for language " + currentLanguageId); - + setSettingEntries(currentCfgDescription, currentResource, currentLanguageId, detectedSettingEntries); } detectedSettingEntries = null; - + currentCommandResolved = null; if (specFile!=null && !preserveSpecFile) { specFile.delete(); specFile = null; } - + currentLanguageId = null; } @@ -473,21 +473,21 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti if (monitor == null) { monitor = new NullProgressMonitor(); } - + try { - // StreamMonitor will do monitor.beginTask(...) + // StreamMonitor will do monitor.beginTask(...) StreamMonitor streamMon = new StreamMonitor(monitor, errorParserManager, TICKS_STREAM_MONITOR); OutputStream stdout = streamMon; OutputStream stderr = streamMon; - + String msg = "Running scanner discovery: " + getName(); printLine(stdout, "**** " + msg + " ****" + NEWLINE); - + ConsoleParser consoleParser = new ConsoleParser(); ConsoleOutputSniffer sniffer = new ConsoleOutputSniffer(stdout, stderr, new IConsoleParser[] { consoleParser }, errorParserManager); OutputStream consoleOut = sniffer.getOutputStream(); OutputStream consoleErr = sniffer.getErrorStream(); - + boolean isSuccess = false; try { isSuccess = runProgram(currentCommandResolved, env, workingDirectory, monitor, consoleOut, consoleErr); @@ -519,7 +519,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti */ protected boolean runProgram(String command, String[] env, IPath workingDirectory, IProgressMonitor monitor, OutputStream consoleOut, OutputStream consoleErr) throws CoreException, IOException { - + if (command==null || command.trim().length()==0) { return false; } @@ -575,7 +575,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti } return false; } - + printLine(consoleOut, NEWLINE + "**** Collected " + detectedSettingEntries.size() + " entries. ****"); return true; } @@ -601,7 +601,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti String consoleId = MakeCorePlugin.PLUGIN_ID + '.' + getId() + '.' + currentLanguageId; String consoleName = getName() + ", " + ld.getName(); URL defaultIcon = Platform.getBundle(PLUGIN_CDT_MAKE_UI_ID).getEntry("icons/obj16/inspect_system.gif"); - + IConsole console = CCorePlugin.getDefault().getConsole(extConsoleId, consoleId, consoleName, defaultIcon); return console; } @@ -642,7 +642,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti if (specExt != null) { ext = '.' + specExt; } - + String specFileName = SPEC_FILE_BASE + ext; IPath workingLocation = MakeCorePlugin.getWorkingDirectory(); IPath fileLocation = workingLocation.append(specFileName); @@ -664,7 +664,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti /** * Determine file extension by language id. This implementation retrieves first extension * from the list as there could be multiple extensions associated with the given language. - * + * * @param languageId - given language ID. * @return file extension associated with the language or {@code null} if not found. */ @@ -680,7 +680,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti } } } - + if (ext == null) { MakeCorePlugin.log(new Status(IStatus.ERROR, MakeCorePlugin.PLUGIN_ID, "Unable to find file extension for language "+languageId)); } diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsListenersTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsListenersTests.java index 199fc827abd..0ccb02d6603 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsListenersTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsListenersTests.java @@ -23,9 +23,6 @@ import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.core.testplugin.ResourceHelper; import org.eclipse.cdt.core.testplugin.util.BaseTestCase; -import org.eclipse.cdt.internal.core.language.settings.providers.ILanguageSettingsChangeEvent; -import org.eclipse.cdt.internal.core.language.settings.providers.ILanguageSettingsChangeListener; -import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer; import org.eclipse.core.resources.IProject; /** @@ -83,7 +80,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase { @Override protected void tearDown() throws Exception { - LanguageSettingsProvidersSerializer.unregisterLanguageSettingsChangeListener(mockLseListener); + LanguageSettingsManager.unregisterLanguageSettingsChangeListener(mockLseListener); LanguageSettingsManager.setWorkspaceProviders(null); super.tearDown(); } @@ -547,7 +544,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase { } // register mock listener to inspect the notifications - LanguageSettingsProvidersSerializer.registerLanguageSettingsChangeListener(mockLseListener); + LanguageSettingsManager.registerLanguageSettingsChangeListener(mockLseListener); assertEquals(0, mockLseListener.getCount()); assertEquals(null, mockLseListener.getLastEvent()); @@ -601,7 +598,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase { } // register mock listener to inspect the notifications - LanguageSettingsProvidersSerializer.registerLanguageSettingsChangeListener(mockLseListener); + LanguageSettingsManager.registerLanguageSettingsChangeListener(mockLseListener); assertEquals(0, mockLseListener.getCount()); assertEquals(null, mockLseListener.getLastEvent()); @@ -666,7 +663,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase { } // register mock listener to inspect the notifications - LanguageSettingsProvidersSerializer.registerLanguageSettingsChangeListener(mockLseListener); + LanguageSettingsManager.registerLanguageSettingsChangeListener(mockLseListener); assertEquals(0, mockLseListener.getCount()); assertEquals(null, mockLseListener.getLastEvent()); @@ -692,7 +689,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase { assertEquals(null, mockLseListener.getLastEvent()); // Serialize settings - LanguageSettingsProvidersSerializer.serializeLanguageSettings(prjDescription); + LanguageSettingsManager.serializeLanguageSettings(prjDescription); // inspect event assertEquals(1, mockLseListener.getCount()); ILanguageSettingsChangeEvent event = mockLseListener.getLastEvent(); @@ -730,7 +727,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase { } // register mock listener to inspect the notifications - LanguageSettingsProvidersSerializer.registerLanguageSettingsChangeListener(mockLseListener); + LanguageSettingsManager.registerLanguageSettingsChangeListener(mockLseListener); assertEquals(0, mockLseListener.getCount()); assertEquals(null, mockLseListener.getLastEvent()); @@ -762,7 +759,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase { assertNull(mockLseListener.getLastEvent()); // Serialize settings - LanguageSettingsProvidersSerializer.serializeLanguageSettings(prjDescription_1); + LanguageSettingsManager.serializeLanguageSettings(prjDescription_1); // inspect event assertEquals(1, mockLseListener.getCount()); ILanguageSettingsChangeEvent event = mockLseListener.getLastEvent(); @@ -793,7 +790,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase { assertNull(mockLseListener.getLastEvent()); // Serialize settings - LanguageSettingsProvidersSerializer.serializeLanguageSettings(prjDescription_2); + LanguageSettingsManager.serializeLanguageSettings(prjDescription_2); // inspect event assertEquals(0, mockLseListener.getCount()); ILanguageSettingsChangeEvent event = mockLseListener.getLastEvent(); @@ -825,7 +822,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase { } // register mock listener to inspect the notifications - LanguageSettingsProvidersSerializer.registerLanguageSettingsChangeListener(mockLseListener); + LanguageSettingsManager.registerLanguageSettingsChangeListener(mockLseListener); assertEquals(0, mockLseListener.getCount()); assertEquals(null, mockLseListener.getLastEvent()); @@ -886,7 +883,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase { } // register mock listener to inspect the notifications - LanguageSettingsProvidersSerializer.registerLanguageSettingsChangeListener(mockLseListener); + LanguageSettingsManager.registerLanguageSettingsChangeListener(mockLseListener); assertEquals(0, mockLseListener.getCount()); assertEquals(null, mockLseListener.getLastEvent()); @@ -938,7 +935,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase { IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName()); // register mock listener to inspect the notifications - LanguageSettingsProvidersSerializer.registerLanguageSettingsChangeListener(mockLseListener); + LanguageSettingsManager.registerLanguageSettingsChangeListener(mockLseListener); // Add empty global provider { @@ -988,7 +985,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase { assertEquals(null, mockLseListener.getLastEvent()); // Serialize settings - LanguageSettingsProvidersSerializer.serializeLanguageSettingsWorkspace(); + LanguageSettingsManager.serializeLanguageSettingsWorkspace(); // get cfgDescriptionId ICProjectDescription prjDescription = CoreModel.getDefault().getProjectDescription(project, false); @@ -1023,7 +1020,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase { assertEquals(null, mockLseListener.getLastEvent()); // Serialize settings - LanguageSettingsProvidersSerializer.serializeLanguageSettingsWorkspace(); + LanguageSettingsManager.serializeLanguageSettingsWorkspace(); // get cfgDescriptionId ICProjectDescription prjDescription = CoreModel.getDefault().getProjectDescription(project, false); diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java index d50ce050a5f..8b130abe4b0 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java @@ -304,7 +304,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { assertEquals(entries.size(), actual.size()); // serialize language settings of workspace providers - LanguageSettingsProvidersSerializer.serializeLanguageSettingsWorkspace(); + LanguageSettingsManager.serializeLanguageSettingsWorkspace(); // clear the provider extProvider.setSettingEntries(null, null, null, null); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsBroadcastingProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsBroadcastingProvider.java index e4ec18493d5..5ab3297eab3 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsBroadcastingProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsBroadcastingProvider.java @@ -14,7 +14,6 @@ import java.util.List; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; -import org.eclipse.cdt.internal.core.language.settings.providers.ILanguageSettingsChangeEvent; import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer; import org.eclipse.core.resources.IResource; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/ILanguageSettingsChangeEvent.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsChangeEvent.java similarity index 96% rename from core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/ILanguageSettingsChangeEvent.java rename to core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsChangeEvent.java index b5df5b35840..15099441d9b 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/ILanguageSettingsChangeEvent.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsChangeEvent.java @@ -8,7 +8,7 @@ * Contributors: * Andrew Gvozdev - initial API and implementation *******************************************************************************/ -package org.eclipse.cdt.internal.core.language.settings.providers; +package org.eclipse.cdt.core.language.settings.providers; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/ILanguageSettingsChangeListener.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsChangeListener.java similarity index 75% rename from core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/ILanguageSettingsChangeListener.java rename to core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsChangeListener.java index 8230200c5cd..2c3ca4c7886 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/ILanguageSettingsChangeListener.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsChangeListener.java @@ -8,15 +8,15 @@ * Contributors: * Andrew Gvozdev - initial API and implementation *******************************************************************************/ -package org.eclipse.cdt.internal.core.language.settings.providers; +package org.eclipse.cdt.core.language.settings.providers; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; /** * An interface for listeners to changes in language settings {@link ICLanguageSettingEntry}. * - * @see LanguageSettingsProvidersSerializer#registerLanguageSettingsChangeListener(ILanguageSettingsChangeListener) - * @see LanguageSettingsProvidersSerializer#unregisterLanguageSettingsChangeListener(ILanguageSettingsChangeListener) + * @see LanguageSettingsManager#registerLanguageSettingsChangeListener(ILanguageSettingsChangeListener) + * @see LanguageSettingsManager#unregisterLanguageSettingsChangeListener(ILanguageSettingsChangeListener) */ public interface ILanguageSettingsChangeListener { /** diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java index 8122e0dffdf..4fa512496ad 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java @@ -22,6 +22,7 @@ import org.eclipse.cdt.core.settings.model.ICFileDescription; import org.eclipse.cdt.core.settings.model.ICFolderDescription; import org.eclipse.cdt.core.settings.model.ICLanguageSetting; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; +import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.core.settings.model.ICResourceDescription; import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsExtensionManager; @@ -35,8 +36,6 @@ import org.eclipse.core.runtime.IPath; /** * A collection of utility methods to manage language settings providers. * See {@link ILanguageSettingsProvider}. - * - * @since 6.0 */ public class LanguageSettingsManager { /** @@ -257,4 +256,41 @@ public class LanguageSettingsManager { return languageIds; } + /** + * Adds a listener that will be notified of changes in language settings. + * + * @param listener the listener to add + */ + public static void registerLanguageSettingsChangeListener(ILanguageSettingsChangeListener listener) { + LanguageSettingsProvidersSerializer.registerLanguageSettingsChangeListener(listener); + } + + /** + * Removes a language settings change listener. + * + * @param listener the listener to remove. + */ + public static void unregisterLanguageSettingsChangeListener(ILanguageSettingsChangeListener listener) { + LanguageSettingsProvidersSerializer.unregisterLanguageSettingsChangeListener(listener); + } + + /** + * Save language settings providers of a project to persistent storage. + * + * @param prjDescription - project description of the project. + * @throws CoreException if something goes wrong. + */ + public static void serializeLanguageSettings(ICProjectDescription prjDescription) throws CoreException { + LanguageSettingsProvidersSerializer.serializeLanguageSettings(prjDescription); + } + + /** + * Save language settings providers of the workspace (global providers) to persistent storage. + * + * @throws CoreException + */ + public static void serializeLanguageSettingsWorkspace() throws CoreException { + LanguageSettingsProvidersSerializer.serializeLanguageSettingsWorkspace(); + } + } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager_TBD.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager_TBD.java index a7054aaf9b9..d0ea6724b89 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager_TBD.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager_TBD.java @@ -51,7 +51,7 @@ public class LanguageSettingsManager_TBD { try { return ! LanguageSettingsExtensionManager.equalsExtensionProviderShallow((ILanguageSettingsEditableProvider) provider); } catch (Exception e) { - CCorePlugin.log("Internal Error: cannot clone provider "+provider.getId(), e); + CCorePlugin.log(e); } } return false; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableProvider.java index 2313ee731b7..27af0a2ca59 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableProvider.java @@ -18,7 +18,6 @@ import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.internal.core.XmlUtil; -import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer; import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsSerializableStorage; import org.eclipse.core.resources.IResource; import org.w3c.dom.Element; @@ -156,9 +155,8 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr * Sets language settings entries for the provider. * Note that the entries are not persisted at that point. Use this method to * set the entries for all resources and then to persist use - * {@fixme FIXME - update references with API versions} - * {@link LanguageSettingsProvidersSerializer#serializeLanguageSettings(ICProjectDescription)} or - * {@link LanguageSettingsProvidersSerializer#serializeLanguageSettingsWorkspace()}. + * {@link LanguageSettingsManager#serializeLanguageSettings(ICProjectDescription)} or + * {@link LanguageSettingsManager#serializeLanguageSettingsWorkspace()}. * See for example {@code AbstractBuildCommandParser} and {@code AbstractBuiltinSpecsDetector} * in build plugins. * diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsLogger.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsLogger.java index ee98cfda988..0f13e949067 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsLogger.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsLogger.java @@ -66,7 +66,7 @@ public class LanguageSettingsLogger { @Deprecated public static void logScannerInfoProvider(IResource rc, Object who) { if (isEnabled()) { - String msg = "rc="+rc+" <-- "+who.getClass().getSimpleName(); + String msg = "rc="+rc+" <-- "+who.getClass().getSimpleName(); //$NON-NLS-1$ //$NON-NLS-2$ if (rc instanceof IFile) { LanguageSettingsLogger.logInfo(msg); } else if (rc instanceof IProject) { diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java index 6c6fa6bb28b..864229a31f2 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java @@ -8,7 +8,6 @@ * Contributors: * Andrew Gvozdev - initial API and implementation *******************************************************************************/ - package org.eclipse.cdt.internal.core.language.settings.providers; import java.net.URI; @@ -20,6 +19,8 @@ import java.util.Map; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.language.settings.providers.ICListenerAgent; +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.ILanguageSettingsEditableProvider; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; @@ -58,8 +59,11 @@ import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; +/** + * Helper class handling serialization and notifications for language settings entries {@link ICLanguageSettingEntry}. + */ public class LanguageSettingsProvidersSerializer { - private static final String PREFERENCE_WORSPACE_PROVIDERS_SET = "language.settings.providers.set.for.workspace"; + private static final String PREFERENCE_WORSPACE_PROVIDERS_SET = "language.settings.providers.set.for.workspace"; //$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_LANGUAGE_SETTINGS = "language.settings.xml"; //$NON-NLS-1$ @@ -372,6 +376,11 @@ projects: return events; } + /** + * Save language settings providers of the workspace (global providers) to persistent storage. + * + * @throws CoreException + */ public static void serializeLanguageSettingsWorkspace() throws CoreException { LanguageSettingsLogger.logWarning("LanguageSettingsProvidersSerializer.serializeLanguageSettingsWorkspace()"); @@ -530,6 +539,12 @@ projects: } } + /** + * Save language settings providers of a project to persistent storage. + * + * @param prjDescription - project description of the project. + * @throws CoreException if something goes wrong. + */ public static void serializeLanguageSettings(ICProjectDescription prjDescription) throws CoreException { IProject project = prjDescription.getProject(); LanguageSettingsLogger.logWarning("LanguageSettingsProvidersSerializer.serializeLanguageSettings() for " + project); @@ -993,7 +1008,7 @@ projects: /** * Adds a listener that will be notified of changes in language settings. * - * @param listener the ILanguageMappingChangeListener to add + * @param listener the listener to add */ public static void registerLanguageSettingsChangeListener(ILanguageSettingsChangeListener listener) { fLanguageSettingsChangeListeners.add(listener); @@ -1002,7 +1017,7 @@ projects: /** * Removes a language settings change listener. * - * @param listener the ILanguageMappingChangeListener to remove. + * @param listener the listener to remove. */ public static void unregisterLanguageSettingsChangeListener(ILanguageSettingsChangeListener listener) { fLanguageSettingsChangeListeners.remove(listener); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationSpecSettings.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationSpecSettings.java index 6b140bba8ea..773244bc9ae 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationSpecSettings.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationSpecSettings.java @@ -49,7 +49,6 @@ import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSetting import org.eclipse.cdt.utils.envvar.StorableEnvironment; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.QualifiedName; -import org.eclipse.osgi.util.NLS; /** * CConfigurationSpecSettings impelements ICSettingsStorage @@ -1014,15 +1013,13 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ for (ILanguageSettingsProvider provider : providers) { String id = provider.getId(); if (provider==LanguageSettingsProvidersSerializer.getRawWorkspaceProvider(id)) { - String msg = "Error: Attempt to add to the configuration raw global provider " + id; - throw new IllegalArgumentException(msg); + throw new IllegalArgumentException("Error: Attempt to add to the configuration raw global provider " + id); //$NON-NLS-1$ } if (!ids.contains(id)) { fLanguageSettingsProviders.add(provider); ids.add(id); } else { - String msg = NLS.bind(SettingsModelMessages.getString("CConfigurationSpecSettings.MustHaveUniqueID"), id); //$NON-NLS-1$ - throw new IllegalArgumentException(msg); + throw new IllegalArgumentException("Language Settings Providers must have unique ID. Duplicate ID=" + id); //$NON-NLS-1$ } } fIsModified = true; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/SettingsModelMessages.properties b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/SettingsModelMessages.properties index 09dd9fd56cb..38f30f17a08 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/SettingsModelMessages.properties +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/SettingsModelMessages.properties @@ -16,7 +16,6 @@ CConfigurationDescription.1=expected proxy of type ICFileDescription, but was CConfigurationDescription.2=data was not created CConfigurationDescription.3=expected proxy of type ICFolderDescription, but was CConfigurationDescriptionCache.0=description is read only -CConfigurationSpecSettings.MustHaveUniqueID=Language Settings Providers must have unique ID. Duplicate ID={0} CConfigurationStatus.1=configurations settings invalid CProjectConverterDesciptor.0=illegal provider implementation CProjectConverterDesciptor.1=no provider defined diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/xml/XmlProjectDescriptionStorage.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/xml/XmlProjectDescriptionStorage.java index e5dca0d567a..823ae253da7 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/xml/XmlProjectDescriptionStorage.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/xml/XmlProjectDescriptionStorage.java @@ -34,6 +34,7 @@ import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager; import org.eclipse.cdt.core.settings.model.ICSettingsStorage; @@ -173,7 +174,7 @@ public class XmlProjectDescriptionStorage extends AbstractCProjectDescriptionSto serializingLock.acquire(); projectModificaitonStamp = serialize(fDes.getProject(), ICProjectDescriptionStorageType.STORAGE_FILE_NAME, fElement); ((ContributedEnvironment) CCorePlugin.getDefault().getBuildEnvironmentManager().getContributedEnvironment()).serialize(fDes); - LanguageSettingsProvidersSerializer.serializeLanguageSettings(fDes); + LanguageSettingsManager.serializeLanguageSettings(fDes); } finally { serializingLock.release(); Job.getJobManager().removeJobChangeListener(notifyJobCanceller); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/LanguageSettingsChangeListener.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/LanguageSettingsChangeListener.java index 67ccc3f082f..bed48f79a17 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/LanguageSettingsChangeListener.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/LanguageSettingsChangeListener.java @@ -11,10 +11,10 @@ package org.eclipse.cdt.internal.core.pdom; import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsChangeEvent; +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsChangeListener; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICProjectDescription; -import org.eclipse.cdt.internal.core.language.settings.providers.ILanguageSettingsChangeEvent; -import org.eclipse.cdt.internal.core.language.settings.providers.ILanguageSettingsChangeListener; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.ResourcesPlugin; @@ -24,21 +24,27 @@ import org.eclipse.core.resources.ResourcesPlugin; */ public class LanguageSettingsChangeListener implements ILanguageSettingsChangeListener { private PDOMManager fManager; - + + /** + * Constructor. + * + * @param manager - PDOM manager. + */ public LanguageSettingsChangeListener(PDOMManager manager) { fManager = manager; } - + + @Override public void handleEvent(ILanguageSettingsChangeEvent event) { IWorkspaceRoot wspRoot = ResourcesPlugin.getWorkspace().getRoot(); IProject project = wspRoot.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)) { fManager.handlePostBuildEvent(); @@ -47,7 +53,7 @@ public class LanguageSettingsChangeListener implements ILanguageSettingsChangeLi } } } - + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java index 425c2b95641..bdb1a16b36d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java @@ -48,6 +48,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; @@ -68,7 +69,6 @@ import org.eclipse.cdt.internal.core.index.IndexChangeEvent; import org.eclipse.cdt.internal.core.index.IndexFactory; import org.eclipse.cdt.internal.core.index.IndexerStateEvent; import org.eclipse.cdt.internal.core.index.provider.IndexProviderManager; -import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer; import org.eclipse.cdt.internal.core.pdom.PDOM.IListener; import org.eclipse.cdt.internal.core.pdom.db.ChunkCache; import org.eclipse.cdt.internal.core.pdom.dom.IPDOMLinkageFactory; @@ -147,12 +147,12 @@ public class PDOMManager implements IWritableIndexManager, IListener { private final PDOMIndexerJob fIndexerJob; private IPDOMIndexerTask fCurrentTask; private int fSourceCount, fHeaderCount, fTickCount; - + private final LinkedList fChangeEvents= new LinkedList(); private final Job fNotificationJob; - private final AtomicMultiSet fFilesIndexedUnconditionlly= new AtomicMultiSet(); - + private final AtomicMultiSet fFilesIndexedUnconditionlly= new AtomicMultiSet(); + /** * Stores mapping from pdom to project, used to serialize creation of new pdoms. */ @@ -160,7 +160,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { private Map fFileToProject= new HashMap(); private ListenerList fChangeListeners= new ListenerList(); private ListenerList fStateListeners= new ListenerList(); - + private IndexChangeEvent fIndexChangeEvent= new IndexChangeEvent(); private IndexerStateEvent fIndexerStateEvent= new IndexerStateEvent(); @@ -170,17 +170,17 @@ public class PDOMManager implements IWritableIndexManager, IListener { private final ICProjectDescriptionListener fProjectDescriptionListener; private final JobChangeListener fJobChangeListener; private final IPreferenceChangeListener fPreferenceChangeListener; - + private IndexFactory fIndexFactory= new IndexFactory(this); private IndexProviderManager fIndexProviderManager = new IndexProviderManager(); - + /** - * Serializes creation of new indexer, when acquiring the lock you are + * Serializes creation of new indexer, when acquiring the lock you are * not allowed to hold a lock on fPDOMs. */ private Map fUpdatePolicies= new HashMap(); private Set fClosingProjects= new HashSet(); - + private Map fPrefListeners= new HashMap(); private List fSetupParticipants= new ArrayList(); private Set fPostponedProjects= new HashSet(); @@ -188,7 +188,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { private boolean fInShutDown; boolean fTraceIndexerSetup; - + public PDOMManager() { PDOM.sDEBUG_LOCKS= "true".equals(Platform.getDebugOption(CCorePlugin.PLUGIN_ID + "/debug/index/locks")); //$NON-NLS-1$//$NON-NLS-2$ addIndexerSetupParticipant(new WaitForRefreshJobs()); @@ -204,7 +204,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { fIndexerJob= new PDOMIndexerJob(this); fNotificationJob= createNotifyJob(); } - + public Job startup() { fInShutDown= false; Job postStartupJob= new Job(CCorePlugin.getResourceString("CCorePlugin.startupJob")) { //$NON-NLS-1$ @@ -219,10 +219,10 @@ public class PDOMManager implements IWritableIndexManager, IListener { } }; postStartupJob.setSystem(true); - return postStartupJob; + return postStartupJob; } - /** + /** * Called from a job after plugin start. */ protected void postStartup() { @@ -234,13 +234,13 @@ public class PDOMManager implements IWritableIndexManager, IListener { adjustCacheSize(); updatePathCanonicalizationStrategy(); fIndexProviderManager.startup(); - + fTraceIndexerSetup= String.valueOf(true).equals(Platform.getDebugOption(TRACE_INDEXER_SETUP)); final CoreModel model = CoreModel.getDefault(); ResourcesPlugin.getWorkspace().addResourceChangeListener(fCModelListener, IResourceChangeEvent.POST_BUILD); model.addElementChangedListener(fCModelListener); LanguageManager.getInstance().registerLanguageChangeListener(fLanguageChangeListener); - LanguageSettingsProvidersSerializer.registerLanguageSettingsChangeListener(fLanguageSettingsChangeListener); + LanguageSettingsManager.registerLanguageSettingsChangeListener(fLanguageSettingsChangeListener); final int types= CProjectDescriptionEvent.DATA_APPLIED; CCorePlugin.getDefault().getProjectDescriptionManager().addCProjectDescriptionListener(fProjectDescriptionListener, types); @@ -261,14 +261,14 @@ public class PDOMManager implements IWritableIndexManager, IListener { final CoreModel model = CoreModel.getDefault(); model.removeElementChangedListener(fCModelListener); ResourcesPlugin.getWorkspace().removeResourceChangeListener(fCModelListener); - LanguageSettingsProvidersSerializer.unregisterLanguageSettingsChangeListener(fLanguageSettingsChangeListener); + LanguageSettingsManager.unregisterLanguageSettingsChangeListener(fLanguageSettingsChangeListener); LanguageManager.getInstance().unregisterLanguageChangeListener(fLanguageChangeListener); PDOMIndexerJob jobToCancel= null; synchronized (fTaskQueue) { fTaskQueue.clear(); jobToCancel= fIndexerJob; } - + if (jobToCancel != null) { assert !Thread.holdsLock(fTaskQueue); jobToCancel.cancelJobs(null, false); @@ -290,7 +290,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { reindexAll(); } } - + protected void adjustCacheSize() { IPreferencesService prefs = Platform.getPreferencesService(); int cachePct= prefs.getInt(CCorePlugin.PLUGIN_ID, CCorePreferenceConstants.INDEX_DB_CACHE_SIZE_PCT, 10, null); @@ -313,7 +313,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { } /** - * Returns the pdom for the project. + * Returns the pdom for the project. * @throws CoreException */ public IPDOM getPDOM(ICProject project) throws CoreException { @@ -327,9 +327,9 @@ public class PDOMManager implements IWritableIndexManager, IListener { return pdom; } } - + /** - * Returns the pdom for the project. The call to the method may cause + * Returns the pdom for the project. The call to the method may cause * opening the database. In case there is a version mismatch the data * base is cleared, in case it does not exist it is created. In any * case a pdom ready to use is returned. @@ -390,7 +390,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { } pdom.setASTFilePathResolver(new ProjectIndexerInputAdapter(project, false)); pdom.addListener(this); - + fFileToProject.put(dbFile, project); fProjectToPDOM.put(rproject, pdom); if (pdomProxy instanceof PDOMProxy) { @@ -438,7 +438,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { public void setDefaultIndexerId(String indexerId) { IndexerPreferences.setDefaultIndexerId(indexerId); } - + @Override public String getIndexerId(ICProject project) { IProject prj= project != null ? project.getProject() : null; @@ -451,7 +451,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { IndexerPreferences.set(prj, IndexerPreferences.KEY_INDEXER_ID, indexerId); CCoreInternals.savePreferences(prj, IndexerPreferences.getScope(prj) == IndexerPreferences.SCOPE_PROJECT_SHARED); } - + protected void onPreferenceChange(ICProject cproject, PreferenceChangeEvent event) { if (IndexerPreferences.KEY_UPDATE_POLICY.equals(event.getKey())) { changeUpdatePolicy(cproject); @@ -482,17 +482,17 @@ public class PDOMManager implements IWritableIndexManager, IListener { private void changeIndexer(ICProject cproject) throws CoreException { assert !Thread.holdsLock(fProjectToPDOM); - + // if there is no indexer, don't touch the preferences. IPDOMIndexer oldIndexer= getIndexer(cproject); if (oldIndexer == null) { return; } - + IProject prj= cproject.getProject(); String newid= IndexerPreferences.get(prj, IndexerPreferences.KEY_INDEXER_ID, IPDOMManager.ID_NO_INDEXER); Properties props= IndexerPreferences.getProperties(prj); - + // Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=359485 synchronized (new ProjectScope(prj).getNode(CCorePlugin.PLUGIN_ID)) { synchronized (fUpdatePolicies) { @@ -519,7 +519,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { enqueue(new PDOMRebuildTask(indexer)); } }} - + if (oldIndexer != null) { stopIndexer(oldIndexer); } @@ -546,26 +546,26 @@ public class PDOMManager implements IWritableIndexManager, IListener { void createIndexer(ICProject project, IProgressMonitor pm) throws InterruptedException { final IProject prj= project.getProject(); final String name = prj.getName(); - if (fTraceIndexerSetup) + if (fTraceIndexerSetup) System.out.println("Indexer: Creation for project " + name); //$NON-NLS-1$ - + assert !Thread.holdsLock(fProjectToPDOM); try { // Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=359485 synchronized (new ProjectScope(prj).getNode(CCorePlugin.PLUGIN_ID)) { synchronized (fUpdatePolicies) { if (fClosingProjects.contains(name)) { - if (fTraceIndexerSetup) + if (fTraceIndexerSetup) System.out.println("Indexer: Aborting setup (1) for closing project " + name + " [1]"); //$NON-NLS-1$ //$NON-NLS-2$ return; } - + WritablePDOM pdom= getOrCreatePDOM(project); Properties props= IndexerPreferences.getProperties(prj); IPDOMIndexer indexer= newIndexer(getIndexerId(project), props); IndexUpdatePolicy policy= createPolicy(project); - boolean rebuild= + boolean rebuild= pdom.isClearedBecauseOfVersionMismatch() || pdom.isCreatedFromScratch() || policy.isInitialRebuildRequested(); @@ -593,7 +593,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { pdom.releaseReadLock(); } if (resume) { - if (fTraceIndexerSetup) + if (fTraceIndexerSetup) System.out.println("Indexer: Resuming for project " + name); //$NON-NLS-1$ enqueue(new PDOMUpdateTask(indexer, @@ -612,7 +612,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { synchronized (new ProjectScope(prj).getNode(CCorePlugin.PLUGIN_ID)) { synchronized (fUpdatePolicies) { if (fClosingProjects.contains(name)) { - if (fTraceIndexerSetup) + if (fTraceIndexerSetup) System.out.println("Indexer: Aborting setup for closing project " + name + " [2]"); //$NON-NLS-1$ //$NON-NLS-2$ return; } @@ -626,13 +626,13 @@ public class PDOMManager implements IWritableIndexManager, IListener { IPDOMIndexerTask task= null; if (operation.wasSuccessful()) { - if (fTraceIndexerSetup) - System.out.println("Indexer: Imported shared index for project " + name); //$NON-NLS-1$ + if (fTraceIndexerSetup) + System.out.println("Indexer: Imported shared index for project " + name); //$NON-NLS-1$ task= new PDOMUpdateTask(indexer, IIndexManager.UPDATE_CHECK_TIMESTAMPS | IIndexManager.UPDATE_CHECK_CONTENTS_HASH); } else { - if (fTraceIndexerSetup) - System.out.println("Indexer: Rebuiding for project " + name); //$NON-NLS-1$ + if (fTraceIndexerSetup) + System.out.println("Indexer: Rebuiding for project " + name); //$NON-NLS-1$ task= new PDOMRebuildTask(indexer); } enqueue(task); @@ -644,7 +644,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { } } } - + private IPDOMIndexer newIndexer(String indexerId, Properties props) throws CoreException { IPDOMIndexer indexer = null; // Look up in extension point @@ -659,14 +659,14 @@ public class PDOMManager implements IWritableIndexManager, IListener { indexer.setProperties(props); } catch (CoreException e) { CCorePlugin.log(e); - } + } break; } } } // Unknown index, default to the null one - if (indexer == null) + if (indexer == null) indexer = new PDOMNullIndexer(); return indexer; @@ -700,7 +700,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { fIndexerJob.schedule(); } } - + private void getReferencingProjects(IProject prj, HashSet result) { LinkedList projectsToSearch= new LinkedList(); projectsToSearch.add(prj); @@ -731,7 +731,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { } return result; } - + void cancelledIndexerJob(boolean byManager) { synchronized (fTaskQueue) { fCurrentTask= null; @@ -743,7 +743,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { } } } - + @Override public boolean isIndexerIdle() { return Job.getJobManager().find(this).length == 0; @@ -753,19 +753,19 @@ public class PDOMManager implements IWritableIndexManager, IListener { final String name = cproject.getProject().getName(); if (fTraceIndexerSetup) { System.out.println("Indexer: Adding new project " + name); //$NON-NLS-1$ - } - + } + synchronized (fUpdatePolicies) { fClosingProjects.remove(name); } - + setupProject(cproject); } void setupProject(final ICProject cproject) { if (fInShutDown) return; - + synchronized (fProjectQueue) { fProjectQueue.add(cproject); } @@ -804,7 +804,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { if (indexer != null && indexer.getID().equals(IPDOMManager.ID_NO_INDEXER)) { return; } - + if (added.length > 0 || changed.length > 0 || removed.length > 0) { synchronized (fUpdatePolicies) { IndexUpdatePolicy policy= createPolicy(project); @@ -835,7 +835,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { } public void preDeleteProject(ICProject cproject) { - preRemoveProject(cproject, true); + preRemoveProject(cproject, true); } public void preCloseProject(ICProject cproject) { @@ -848,8 +848,8 @@ public class PDOMManager implements IWritableIndexManager, IListener { final IProject rproject= cproject.getProject(); final String name = rproject.getName(); - if (fTraceIndexerSetup) - System.out.println("Indexer: Removing project " + name + "; delete=" + delete); //$NON-NLS-1$ //$NON-NLS-2$ + if (fTraceIndexerSetup) + System.out.println("Indexer: Removing project " + name + "; delete=" + delete); //$NON-NLS-1$ //$NON-NLS-2$ IPDOMIndexer indexer; synchronized (fUpdatePolicies) { @@ -896,12 +896,12 @@ public class PDOMManager implements IWritableIndexManager, IListener { job.setSystem(true); job.schedule(); } - + synchronized (fUpdatePolicies) { fUpdatePolicies.remove(cproject); } } - + void removeProject(ICProject cproject, ICElementDelta delta) { synchronized (fProjectToPDOM) { IProject rproject= cproject.getProject(); @@ -921,7 +921,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { policy.clearTUs(); policy.setIndexer(null); } - } + } } cancelIndexerJobs(indexer); } @@ -937,13 +937,13 @@ public class PDOMManager implements IWritableIndexManager, IListener { } jobToCancel= fIndexerJob; } - + if (jobToCancel != null) { assert !Thread.holdsLock(fTaskQueue); jobToCancel.cancelJobs(indexer, true); } - } - + } + private void reindexAll() { ICProject[] cProjects; try { @@ -958,7 +958,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { @Override public void reindex(final ICProject project) { - Job job= new Job(Messages.PDOMManager_notifyJob_label) { + Job job= new Job(Messages.PDOMManager_notifyJob_label) { @Override protected IStatus run(IProgressMonitor monitor) { IPDOMIndexer indexer= null; @@ -999,7 +999,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { public void removeIndexChangeListener(IIndexChangeListener listener) { fChangeListeners.remove(listener); } - + @Override public void addIndexerStateListener(IIndexerStateListener listener) { fStateListeners.add(listener); @@ -1029,7 +1029,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { notify.setSystem(true); return notify; } - + private void scheduleNotification(Runnable notify) { if (fInShutDown) return; @@ -1079,12 +1079,12 @@ public class PDOMManager implements IWritableIndexManager, IListener { if (fChangeListeners.isEmpty()) { return; } - + ICProject project; synchronized (fProjectToPDOM) { project = fFileToProject.get(pdom.getPath()); - } - + } + if (project != null) { final ICProject finalProject= project; Runnable notify= new Runnable() { @@ -1145,10 +1145,10 @@ public class PDOMManager implements IWritableIndexManager, IListener { } } } - + int getMonitorMessage(PDOMIndexerJob job, int currentTicks, int base) { assert !Thread.holdsLock(fTaskQueue); - + int sourceCount, sourceEstimate, headerCount, tickCount, tickEstimate; String detail= null; synchronized (fTaskQueue) { @@ -1175,14 +1175,14 @@ public class PDOMManager implements IWritableIndexManager, IListener { detail= PDOMIndexerJob.sMonitorDetail; } } - - String msg= MessageFormat.format(Messages.PDOMManager_indexMonitorDetail, new Object[] { - new Integer(sourceCount), new Integer(sourceEstimate), - new Integer(headerCount)}); + + String msg= MessageFormat.format(Messages.PDOMManager_indexMonitorDetail, new Object[] { + new Integer(sourceCount), new Integer(sourceEstimate), + new Integer(headerCount)}); if (detail != null) { msg += ": " + detail; //$NON-NLS-1$ } - + job.subTask(msg); if (tickCount > 0 && tickCount <= tickEstimate) { int newTick= tickCount*base/tickEstimate; @@ -1218,7 +1218,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { public IIndex getIndex(ICProject[] projects, int options) throws CoreException { return fIndexFactory.getIndex(projects, options); } - + /** * Exports the project PDOM to the specified location, rewriting locations with * the specified location converter. @@ -1255,7 +1255,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { } // overwrite internal location representations - final WritablePDOM newPDOM = new WritablePDOM(targetLocation, pdom.getLocationConverter(), getLinkageFactories()); + final WritablePDOM newPDOM = new WritablePDOM(targetLocation, pdom.getLocationConverter(), getLinkageFactories()); newPDOM.acquireWriteLock(); try { newPDOM.rewriteLocations(newConverter); @@ -1275,7 +1275,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { } /** - * Resets the pdom for the project with the provided stream. + * Resets the pdom for the project with the provided stream. * @throws CoreException * @throws OperationCanceledException in case the thread was interrupted * @since 4.0 @@ -1294,11 +1294,11 @@ public class PDOMManager implements IWritableIndexManager, IListener { } if (version > PDOM.getMaxSupportedVersion()) { final IStatus status = new Status(IStatus.WARNING, CCorePlugin.PLUGIN_ID, 0, CCorePlugin.getResourceString("PDOMManager.unsupportedHigherVersion"), null); //$NON-NLS-1$ - throw new CoreException(status); + throw new CoreException(status); } if ( !PDOM.isSupportedVersion( version ) ) { final IStatus status = new Status(IStatus.WARNING, CCorePlugin.PLUGIN_ID, 0, CCorePlugin.getResourceString("PDOMManager.unsupportedVersion"), null); //$NON-NLS-1$ - throw new CoreException(status); + throw new CoreException(status); } byte[] buffer= new byte[2048]; int read; @@ -1308,7 +1308,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { } finally { out.close(); } - + WritablePDOM pdom= (WritablePDOM) getPDOM(project); try { pdom.acquireWriteLock(); @@ -1323,7 +1323,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { pdom.releaseWriteLock(); } } - + @Override public void export(ICProject project, String location, int options, IProgressMonitor monitor) throws CoreException { TeamPDOMExportOperation operation= new TeamPDOMExportOperation(project); @@ -1331,7 +1331,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { operation.setOptions(options); operation.run(monitor); } - + /** * Write metadata appropriate for a project pdom * @param pdom the pdom to write to @@ -1362,7 +1362,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { for (Map.Entry> entry : projectsToElements.entrySet()) { ICProject project = entry.getKey(); List filesAndFolders = entry.getValue(); - + update(project, filesAndFolders, options); } } @@ -1389,14 +1389,14 @@ public class PDOMManager implements IWritableIndexManager, IListener { } else if (contains(element, other)) { set.set(j, element); continue allElements; - } + } } set.add(element); } } return result; } - + private boolean contains(final ICElement a, ICElement b) { if (a.equals(b)) { return true; @@ -1493,7 +1493,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { if (fPostponedProjects.contains(project)) { setupProject(project); } - } + } } @Override @@ -1512,7 +1512,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { } } } - + /** * @param project * @return whether the specified project has been registered. If a project has @@ -1522,7 +1522,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { public boolean isProjectRegistered(ICProject project) { return getIndexer(project) != null; } - + /** * @param cproject the project to check * @return whether the content in the project fragment of the specified project's index @@ -1532,7 +1532,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { public boolean isProjectContentSynced(ICProject cproject) throws CoreException { if (!"true".equals(IndexerPreferences.get(cproject.getProject(), IndexerPreferences.KEY_INDEX_ALL_FILES, null))) //$NON-NLS-1$ return true; // no check performed in this case - + Set sources= new HashSet(); cproject.accept(new TranslationUnitCollector(sources, null, new NullProgressMonitor())); @@ -1558,7 +1558,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { return true; } - + private boolean isSubjectToIndexing(ILanguage language) { final int linkageID=language.getLinkageID(); for (int id : IDS_FOR_LINKAGES_TO_INDEX) { @@ -1580,7 +1580,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { private static boolean areSynchronized(Set trail, IIndex index, IResource resource, IIndexFileLocation location) throws CoreException { if (!trail.contains(location)) { trail.add(location); - + IIndexFile[] file= index.getFiles(location); // pre-includes may be listed twice (191989) @@ -1606,7 +1606,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { } } } - + return true; } From 349a2aa03639991f58e88615ee9a6efb18815f66 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Mon, 28 Nov 2011 15:43:29 -0500 Subject: [PATCH 075/120] Fixed a couple of warnings in the log --- .../internal/scannerconfig/MBSLanguageSettingsProvider.java | 3 +-- .../org/eclipse/cdt/managedbuilder/internal/ui/Messages.java | 1 - .../core/settings/model/CConfigurationSpecSettings.java | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/MBSLanguageSettingsProvider.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/MBSLanguageSettingsProvider.java index f324c2a6fc8..230a950c250 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/MBSLanguageSettingsProvider.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/MBSLanguageSettingsProvider.java @@ -135,8 +135,7 @@ public class MBSLanguageSettingsProvider extends AbstractExecutableExtensionBase } @Override public LanguageSettingsStorage clone() throws CloneNotSupportedException { - throw new CloneNotSupportedException(); -// return this; + return this; } @Override public boolean equals(Object obj) { diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/Messages.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/Messages.java index e848b5e4341..6d590040fcb 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/Messages.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/Messages.java @@ -212,7 +212,6 @@ public class Messages extends NLS { public static String PropertyPageDefsTab_9; public static String PropertyPageDefsTab_showIncludeFileTab; public static String PropertyPageDefsTab_showProvidersTab; - public static String RefreshPolicyExceptionDialog_addButtonLabel; public static String RefreshPolicyExceptionDialog_addDialogLabel; public static String RefreshPolicyExceptionDialog_AddExceptionInfoDialog_message; public static String RefreshPolicyExceptionDialog_AddExceptionInfoDialog_title; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationSpecSettings.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationSpecSettings.java index 773244bc9ae..064a72b184f 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationSpecSettings.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationSpecSettings.java @@ -199,7 +199,7 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ LanguageSettingsStorage clone = base.lspPersistedState.get(providerId).clone(); lspPersistedState.put(providerId, clone); } catch (CloneNotSupportedException e) { - CCorePlugin.log(e); + CCorePlugin.log("Not able to clone language settings storage:" + e); //$NON-NLS-1$ } } } From b04a172c1abf46384926e72ef379a81a726d44c4 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Mon, 5 Dec 2011 11:31:38 -0500 Subject: [PATCH 076/120] ILanguageSettingsProvidersKeeper --- .../core/ExternalBuildRunner.java | 45 +-- .../core/InternalBuildRunner.java | 26 +- .../ui/wizards/MBSWizardHandler.java | 266 +++++++------ .../ui/wizards/NewMakeProjFromExisting.java | 21 +- .../ui/wizards/STDWizardHandler.java | 39 +- .../LanguageSettingsListenersTests.java | 128 +++--- .../LanguageSettingsManagerTests.java | 34 +- ...nguageSettingsPersistenceProjectTests.java | 150 +++++-- ...guageSettingsScannerInfoProviderTests.java | 50 ++- .../model/CProjectDescriptionDeltaTests.java | 373 +++++++++--------- .../index/tests/IndexProviderManagerTest.java | 156 +++++--- .../cdt/core/testplugin/CModelMock.java | 96 ++++- .../ILanguageSettingsProvidersKeeper.java | 46 +++ .../LanguageSettingsManager_TBD.java | 25 +- .../ScannerDiscoveryLegacySupport.java | 10 +- .../model/ICConfigurationDescription.java | 29 -- .../LanguageSettingsProvidersSerializer.java | 82 ++-- .../model/CConfigurationDescription.java | 4 +- .../model/CConfigurationDescriptionCache.java | 3 +- .../model/CProjectDescriptionManager.java | 11 +- .../model/MultiConfigDescription.java | 15 - .../providers/LanguageSettingsEntriesTab.java | 35 +- .../LanguageSettingsProviderTab.java | 106 ++--- 23 files changed, 1034 insertions(+), 716 deletions(-) create mode 100644 core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsProvidersKeeper.java diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ExternalBuildRunner.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ExternalBuildRunner.java index 36e2fb59281..4e61b502624 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ExternalBuildRunner.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ExternalBuildRunner.java @@ -32,15 +32,14 @@ import org.eclipse.cdt.core.IMarkerGenerator; import org.eclipse.cdt.core.envvar.IEnvironmentVariable; import org.eclipse.cdt.core.envvar.IEnvironmentVariableManager; 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.ICModelMarker; import org.eclipse.cdt.core.resources.IConsole; import org.eclipse.cdt.core.resources.RefreshScopeManager; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; -import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.internal.core.ConsoleOutputSniffer; -import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer; import org.eclipse.cdt.make.core.scannerconfig.IScannerConfigBuilderInfo2; import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector; import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoConsoleParser; @@ -126,7 +125,7 @@ public class ExternalBuildRunner extends AbstractBuildRunner { if(pathFromURI == null) { throw new CoreException(new Status(IStatus.ERROR, ManagedBuilderCorePlugin.PLUGIN_ID, ManagedMakeMessages.getString("ManagedMakeBuilder.message.error"), null)); //$NON-NLS-1$ } - + IPath workingDirectory = new Path(pathFromURI); // Set the environment @@ -211,10 +210,10 @@ public class ExternalBuildRunner extends AbstractBuildRunner { // Do not allow the cancel of the refresh, since the builder is external // to Eclipse, files may have been created/modified and we will be out-of-sync. // The caveat is for huge projects, it may take sometimes at every build. - + // TODO should only refresh output folders //project.refreshLocal(IResource.DEPTH_INFINITE, null); - + // use the refresh scope manager to refresh RefreshScopeManager refreshManager = RefreshScopeManager.getInstance(); IWorkspaceRunnable runnable = refreshManager.getRefreshRunnable(project); @@ -247,7 +246,7 @@ public class ExternalBuildRunner extends AbstractBuildRunner { consoleErr.write(buf.toString().getBytes()); consoleErr.flush(); } - + buf = new StringBuffer(NEWLINE); buf.append(ManagedMakeMessages.getResourceString("ManagedMakeBuilder.message.build.finished")).append(NEWLINE); //$NON-NLS-1$ consoleOut.write(buf.toString().getBytes()); @@ -324,15 +323,15 @@ public class ExternalBuildRunner extends AbstractBuildRunner { envMap.put(var.getName(), var.getValue()); } } - + // Add variables from build info Map builderEnv = builder.getExpandedEnvironment(); if (builderEnv != null) envMap.putAll(builderEnv); - + return envMap; } - + protected static String[] getEnvStrings(Map env) { // Convert into env strings List strings= new ArrayList(env.size()); @@ -341,10 +340,10 @@ public class ExternalBuildRunner extends AbstractBuildRunner { buffer.append('=').append(entry.getValue()); strings.add(buffer.toString()); } - + return strings.toArray(new String[strings.size()]); } - + private ConsoleOutputSniffer createBuildOutputSniffer(OutputStream outputStream, OutputStream errorStream, IProject project, @@ -386,17 +385,19 @@ public class ExternalBuildRunner extends AbstractBuildRunner { } ICConfigurationDescription cfgDescription = ManagedBuildManager.getDescriptionForConfiguration(cfg); - List lsProviders = cfgDescription.getLanguageSettingProviders(); - for (ILanguageSettingsProvider lsProvider : lsProviders) { - ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(lsProvider); - if (rawProvider instanceof ICConsoleParser) { - ICConsoleParser consoleParser = (ICConsoleParser) rawProvider; - try { - consoleParser.startup(cfgDescription); - clParserList.add(consoleParser); - } catch (CoreException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + if (cfgDescription instanceof ILanguageSettingsProvidersKeeper) { + List lsProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); + for (ILanguageSettingsProvider lsProvider : lsProviders) { + ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(lsProvider); + if (rawProvider instanceof ICConsoleParser) { + ICConsoleParser consoleParser = (ICConsoleParser) rawProvider; + try { + consoleParser.startup(cfgDescription); + clParserList.add(consoleParser); + } catch (CoreException e) { + ManagedBuilderCorePlugin.log(new Status(IStatus.ERROR, ManagedBuilderCorePlugin.PLUGIN_ID, + "Language Settings Provider failed to start up", e)); //$NON-NLS-1$ + } } } } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/InternalBuildRunner.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/InternalBuildRunner.java index 0efc2b6724f..84c0d9c7d2b 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/InternalBuildRunner.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/InternalBuildRunner.java @@ -18,16 +18,14 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; -import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.ConsoleOutputStream; import org.eclipse.cdt.core.ErrorParserManager; import org.eclipse.cdt.core.IMarkerGenerator; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvidersKeeper; import org.eclipse.cdt.core.model.ICModelMarker; import org.eclipse.cdt.core.resources.IConsole; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; -import org.eclipse.cdt.core.settings.model.ICProjectDescription; -import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer; import org.eclipse.cdt.make.core.scannerconfig.AbstractBuildCommandParser; import org.eclipse.cdt.managedbuilder.buildmodel.BuildDescriptionManager; import org.eclipse.cdt.managedbuilder.buildmodel.IBuildDescription; @@ -52,7 +50,7 @@ import org.eclipse.core.runtime.NullProgressMonitor; /** * The build runner for the internal builder. - * + * * @author dschaefer * @since 8.0 */ @@ -160,16 +158,18 @@ public class InternalBuildRunner extends AbstractBuildRunner { if (kind!=IncrementalProjectBuilder.CLEAN_BUILD) { // TODO - AG - sanity check? elaborate ICConfigurationDescription cfgDescription = ManagedBuildManager.getDescriptionForConfiguration(configuration); - List providers = cfgDescription.getLanguageSettingProviders(); - for (ILanguageSettingsProvider provider : providers) { - if (provider instanceof AbstractBuildCommandParser) { - buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$ - String msg = ManagedMakeMessages.getFormattedString("BOP Language Settings Provider [{0}] is not supported by Internal Builder.", provider.getName()); - buf.append("**** "+msg+" ****"); - buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$ - buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$ + if (cfgDescription instanceof ILanguageSettingsProvidersKeeper) { + List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); + for (ILanguageSettingsProvider provider : providers) { + if (provider instanceof AbstractBuildCommandParser) { + buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$ + String msg = ManagedMakeMessages.getFormattedString("BOP Language Settings Provider [{0}] is not supported by Internal Builder.", provider.getName()); + buf.append("**** "+msg+" ****"); + buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$ + buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$ - ManagedBuilderCorePlugin.error(msg); + ManagedBuilderCorePlugin.error(msg); + } } } } diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/MBSWizardHandler.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/MBSWizardHandler.java index 1e3214e6d37..e8f532e79c6 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/MBSWizardHandler.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/MBSWizardHandler.java @@ -23,8 +23,8 @@ import java.util.SortedMap; import java.util.TreeMap; import java.util.TreeSet; -import org.eclipse.cdt.build.internal.core.scannerconfig2.CfgScannerConfigProfileManager; 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.CoreModel; @@ -77,10 +77,10 @@ import org.eclipse.ui.dialogs.WizardNewProjectCreationPage; /** * This object is created per each Project type - * + * * It is responsible for: * - corresponding line in left pane of 1st wizard page - * - whole view of right pane, including + * - whole view of right pane, including * * @noextend This class is not intended to be subclassed by clients. * @noinstantiate This class is not intended to be instantiated by clients. @@ -88,16 +88,16 @@ import org.eclipse.ui.dialogs.WizardNewProjectCreationPage; public class MBSWizardHandler extends CWizardHandler { public static final String ARTIFACT = "org.eclipse.cdt.build.core.buildArtefactType"; //$NON-NLS-1$ public static final String EMPTY_STR = ""; //$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 tooltip = - Messages.CWizardHandler_1 + - Messages.CWizardHandler_2 + - Messages.CWizardHandler_3 + - Messages.CWizardHandler_4 + - Messages.CWizardHandler_5; - + private static final String tooltip = + Messages.CWizardHandler_1 + + Messages.CWizardHandler_2 + + Messages.CWizardHandler_3 + + Messages.CWizardHandler_4 + + Messages.CWizardHandler_5; + protected SortedMap full_tcs = new TreeMap(); private String propertyId = null; private IProjectType pt = null; @@ -110,12 +110,12 @@ public class MBSWizardHandler extends CWizardHandler { private EntryInfo entryInfo; protected CfgHolder[] cfgs = null; protected IWizardPage[] customPages; - + /** * Current list of preferred toolchains */ private List preferredTCs = new ArrayList(); - + protected static final class EntryInfo { private SortedMap tcs; private EntryDescriptor entryDescriptor; @@ -128,12 +128,12 @@ public class MBSWizardHandler extends CWizardHandler { private IWizardPage predatingPage; private IWizardPage followingPage; private IWizard wizard; - + public EntryInfo(EntryDescriptor dr, SortedMap _tcs){ entryDescriptor = dr; tcs = _tcs; } - + /** * @since 5.1 */ @@ -141,7 +141,7 @@ public class MBSWizardHandler extends CWizardHandler { this(dr, _tcs); wizard = w; } - + public boolean isValid(){ initialize(); return isValid; @@ -151,7 +151,7 @@ public class MBSWizardHandler extends CWizardHandler { initialize(); return template; } - + public EntryDescriptor getDescriptor(){ return entryDescriptor; } @@ -159,19 +159,19 @@ public class MBSWizardHandler extends CWizardHandler { private void initialize(){ if(initialized) return; - + do { if(entryDescriptor == null) break; String path[] = entryDescriptor.getPathArray(); if(path == null || path.length == 0) break; - + projectTypeId = path[0]; - if(!entryDescriptor.isDefaultForCategory() && + if(!entryDescriptor.isDefaultForCategory() && path.length > 1 && (!path[0].equals(ManagedBuildWizard.OTHERS_LABEL))){ - templateId = path[path.length - 1]; - Template templates[] = null; + templateId = path[path.length - 1]; + Template templates[] = null; if(wizard instanceof ICDTCommonProjectWizard) { ICDTCommonProjectWizard wz = (ICDTCommonProjectWizard)wizard; String[] langIDs = wz.getLanguageIDs(); @@ -180,38 +180,38 @@ public class MBSWizardHandler extends CWizardHandler { for (String id : langIDs) { lstTemplates.addAll(Arrays.asList(TemplateEngineUI.getDefault(). getTemplates(projectTypeId, null, id))); - } + } templates = lstTemplates.toArray(new Template[lstTemplates.size()]); } - } + } if(null == templates) { templates = TemplateEngineUI.getDefault().getTemplates(projectTypeId); } if((null == templates) || (templates.length == 0)) break; - + for (Template t : templates) { if(t.getTemplateId().equals(templateId)){ template = t; break; } } - + if(template == null) break; } - + isValid = true; } while(false); initialized = true; } - + public Template getInitializedTemplate(IWizardPage predatingPage, IWizardPage followingPage, Map map){ getNextPage(predatingPage, followingPage); - + Template template = getTemplate(); - + if(template != null){ Map valueStore = template.getValueStore(); // valueStore.clear(); @@ -227,11 +227,11 @@ public class MBSWizardHandler extends CWizardHandler { } return template; } - + public IWizardPage getNextPage(IWizardPage predatingPage, IWizardPage followingPage) { initialize(); - if(this.templatePages == null - || this.predatingPage != predatingPage + if(this.templatePages == null + || this.predatingPage != predatingPage || this.followingPage != followingPage){ this.predatingPage = predatingPage; this.followingPage = followingPage; @@ -242,12 +242,12 @@ public class MBSWizardHandler extends CWizardHandler { followingPage.setPreviousPage(predatingPage); } } - + if(templatePages.length != 0) return templatePages[0]; return followingPage; } - + private boolean canFinish(IWizardPage predatingPage, IWizardPage followingPage){ getNextPage(predatingPage, followingPage); for(int i = 0; i < templatePages.length; i++){ @@ -256,47 +256,47 @@ public class MBSWizardHandler extends CWizardHandler { } return true; } - + /** - * Filters toolchains - * + * Filters toolchains + * * @return - set of compatible toolchain's IDs */ protected Set tc_filter() { Set full = tcs.keySet(); - if (entryDescriptor == null) + if (entryDescriptor == null) return full; Set out = new LinkedHashSet(full.size()); for (String s : full) - if (isToolChainAcceptable(s)) + if (isToolChainAcceptable(s)) out.add(s); return out; } /** * Checks whether given toolchain can be displayed - * + * * @param tcId - toolchain _NAME_ to check * @return - true if toolchain can be displayed */ public boolean isToolChainAcceptable(String tcId) { - if (template == null || template.getTemplateInfo() == null) + if (template == null || template.getTemplateInfo() == null) return true; - + String[] toolChainIds = template.getTemplateInfo().getToolChainIds(); - if (toolChainIds == null || toolChainIds.length == 0) + if (toolChainIds == null || toolChainIds.length == 0) return true; - + Object ob = tcs.get(tcId); if (ob == null) return true; // sic ! This can occur with Other Toolchain only if (!(ob instanceof IToolChain)) return false; - + String id1 = ((IToolChain)ob).getId(); IToolChain sup = ((IToolChain)ob).getSuperClass(); String id2 = sup == null ? null : sup.getId(); - + for (String id : toolChainIds) { if ((id != null && id.equals(id1)) || (id != null && id.equals(id2))) @@ -309,20 +309,20 @@ public class MBSWizardHandler extends CWizardHandler { return tc_filter().size(); } } - + public MBSWizardHandler(IProjectType _pt, Composite p, IWizard w) { - super(p, Messages.CWizardHandler_0, _pt.getName()); + super(p, Messages.CWizardHandler_0, _pt.getName()); pt = _pt; setWizard(w); } public MBSWizardHandler(String name, Composite p, IWizard w) { - super(p, Messages.CWizardHandler_0, name); + super(p, Messages.CWizardHandler_0, name); setWizard(w); } public MBSWizardHandler(IBuildPropertyValue val, Composite p, IWizard w) { - super(p, Messages.CWizardHandler_0, val.getName()); + super(p, Messages.CWizardHandler_0, val.getName()); propertyId = val.getId(); setWizard(w); } @@ -334,16 +334,16 @@ public class MBSWizardHandler extends CWizardHandler { startingPage = w.getStartingPage(); } } - + protected IWizardPage getStartingPage(){ return startingPage; } - + public Map getMainPageData() { WizardNewProjectCreationPage page = (WizardNewProjectCreationPage)getStartingPage(); Map data = new HashMap(); String projName = page.getProjectName(); - projName = projName != null ? projName.trim() : EMPTY_STR; + projName = projName != null ? projName.trim() : EMPTY_STR; data.put("projectName", projName); //$NON-NLS-1$ data.put("baseName", getBaseName(projName)); //$NON-NLS-1$ data.put("baseNameUpper", getBaseName(projName).toUpperCase() ); //$NON-NLS-1$ @@ -354,7 +354,7 @@ public class MBSWizardHandler extends CWizardHandler { data.put("location", location); //getProjectLocation().toPortableString()); //$NON-NLS-1$ return data; } - + private String getBaseName(String name) { String baseName = name; int dot = baseName.lastIndexOf('.'); @@ -367,11 +367,11 @@ public class MBSWizardHandler extends CWizardHandler { } return baseName; } - + @Override public void handleSelection() { List preferred = CDTPrefUtil.getPreferredTCs(); - + if (table == null) { table = new Table(parent, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER); table.getAccessible().addAccessibleListener( @@ -404,7 +404,7 @@ public class MBSWizardHandler extends CWizardHandler { counter++; } if (counter > 0) table.select(position); - } + } table.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { @@ -425,11 +425,11 @@ public class MBSWizardHandler extends CWizardHandler { if (listener != null) listener.toolChainListChanged(table.getSelectionCount()); } - + private void loadCustomPages() { - if (! (getWizard() instanceof ICDTCommonProjectWizard)) - return; // not probable - + if (! (getWizard() instanceof ICDTCommonProjectWizard)) + return; // not probable + ICDTCommonProjectWizard wz = (ICDTCommonProjectWizard)getWizard(); MBSCustomPageManager.init(); MBSCustomPageManager.addStockPage(getStartingPage(), CDTMainWizardPage.PAGE_ID); @@ -442,9 +442,9 @@ public class MBSWizardHandler extends CWizardHandler { customPages = MBSCustomPageManager.getCustomPages(); - if (customPages == null) + if (customPages == null) customPages = new IWizardPage[0]; - + for (IWizardPage customPage : customPages) customPage.setWizard(wz); setCustomPagesFilter(wz); @@ -467,13 +467,13 @@ public class MBSWizardHandler extends CWizardHandler { boolean ptIsNull = (getProjectType() == null); if (!ptIsNull) MBSCustomPageManager.addPageProperty( - MBSCustomPageManager.PAGE_ID, - MBSCustomPageManager.PROJECT_TYPE, + MBSCustomPageManager.PAGE_ID, + MBSCustomPageManager.PROJECT_TYPE, getProjectType().getId() ); IToolChain[] tcs = getSelectedToolChains(); - ArrayList x = new ArrayList(); + ArrayList x = new ArrayList(); TreeSet y = new TreeSet(); if (tcs!=null) { int n = tcs.length; @@ -481,7 +481,7 @@ public class MBSWizardHandler extends CWizardHandler { if (tcs[i] == null) // --- NO TOOLCHAIN --- continue; // has no custom pages. x.add(tcs[i]); - + IConfiguration cfg = tcs[i].getParent(); if (cfg == null) continue; @@ -491,24 +491,24 @@ public class MBSWizardHandler extends CWizardHandler { } } MBSCustomPageManager.addPageProperty( - MBSCustomPageManager.PAGE_ID, - MBSCustomPageManager.TOOLCHAIN, + MBSCustomPageManager.PAGE_ID, + MBSCustomPageManager.TOOLCHAIN, x); - + if (ptIsNull) { if (y.size() > 0) MBSCustomPageManager.addPageProperty( - MBSCustomPageManager.PAGE_ID, - MBSCustomPageManager.PROJECT_TYPE, + MBSCustomPageManager.PAGE_ID, + MBSCustomPageManager.PROJECT_TYPE, y); else MBSCustomPageManager.addPageProperty( - MBSCustomPageManager.PAGE_ID, - MBSCustomPageManager.PROJECT_TYPE, + MBSCustomPageManager.PAGE_ID, + MBSCustomPageManager.PROJECT_TYPE, null); } } - + @Override public void handleUnSelection() { if (table != null) { @@ -521,16 +521,16 @@ public class MBSWizardHandler extends CWizardHandler { if (tc.isAbstract() || tc.isSystemObject()) return; IConfiguration[] cfgs = null; // New style managed project type. Configurations are referenced via propertyId. - if (propertyId != null) { + if (propertyId != null) { cfgs = ManagedBuildManager.getExtensionConfigurations(tc, ARTIFACT, propertyId); // Old style managewd project type. Configs are obtained via projectType } else if (pt != null) { cfgs = ManagedBuildManager.getExtensionConfigurations(tc, pt); - } + } if (cfgs == null || cfgs.length == 0) return; full_tcs.put(tc.getUniqueRealName(), tc); } - + @Override public void createProject(IProject project, boolean defaults, boolean onFinish, IProgressMonitor monitor) throws CoreException { try { @@ -548,7 +548,7 @@ public class MBSWizardHandler extends CWizardHandler { public void convertProject(IProject proj, IProgressMonitor monitor) throws CoreException { setProjectDescription(proj, true, true, monitor); } - + private void setProjectDescription(IProject project, boolean defaults, boolean onFinish, IProgressMonitor monitor) throws CoreException { boolean isTryingNewSD = false; IWizardPage page = getStartingPage(); @@ -562,13 +562,13 @@ public class MBSWizardHandler extends CWizardHandler { ManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project); monitor.worked(10); cfgs = getCfgItems(false); - if (cfgs == null || cfgs.length == 0) + if (cfgs == null || cfgs.length == 0) cfgs = CDTConfigWizardPage.getDefaultCfgs(this); - + if (cfgs == null || cfgs.length == 0 || cfgs[0].getConfiguration() == null) { - throw new CoreException(new Status(IStatus.ERROR, + throw new CoreException(new Status(IStatus.ERROR, ManagedBuilderUIPlugin.getUniqueIdentifier(), - Messages.CWizardHandler_6)); + Messages.CWizardHandler_6)); } Configuration cf = (Configuration)cfgs[0].getConfiguration(); ManagedProject mProj = new ManagedProject(project, cf.getProjectType()); @@ -576,12 +576,12 @@ public class MBSWizardHandler extends CWizardHandler { monitor.worked(10); cfgs = CfgHolder.unique(cfgs); cfgs = CfgHolder.reorder(cfgs); - + ICConfigurationDescription cfgDebug = null; ICConfigurationDescription cfgFirst = null; - + int work = 50/cfgs.length; - + for (CfgHolder cfg : cfgs) { cf = (Configuration)cfg.getConfiguration(); String id = ManagedBuildManager.calculateChildId(cf.getId(), null); @@ -593,44 +593,48 @@ public class MBSWizardHandler extends CWizardHandler { IBuilder bld = config.getEditableBuilder(); if (bld != null) { bld.setManagedBuildOn(true); } - + config.setName(cfg.getName()); config.setArtifactName(mProj.getDefaultArtifactName()); - + IBuildProperty b = config.getBuildProperties().getProperty(PROPERTY); if (cfgDebug == null && b != null && b.getValue() != null && PROP_VAL.equals(b.getValue().getId())) cfgDebug = cfgDes; - if (cfgFirst == null) // select at least first configuration - cfgFirst = cfgDes; + if (cfgFirst == null) // select at least first configuration + cfgFirst = cfgDes; - ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, isTryingNewSD); - if (isTryingNewSD) { - List providers = ManagedBuildManager.getLanguageSettingsProviders(config); - cfgDes.setLanguageSettingProviders(providers); + if (cfgDes instanceof ILanguageSettingsProvidersKeeper) { + ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, isTryingNewSD); + if (isTryingNewSD) { + List providers = ManagedBuildManager.getLanguageSettingsProviders(config); + ((ILanguageSettingsProvidersKeeper) cfgDes).setLanguageSettingProviders(providers); + } else { + ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(ManagedBuildManager.MBS_LANGUAGE_SETTINGS_PROVIDER); + List providers = new ArrayList(); + providers.add(provider); + ((ILanguageSettingsProvidersKeeper) cfgDes).setLanguageSettingProviders(providers); + } } else { - ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(ManagedBuildManager.MBS_LANGUAGE_SETTINGS_PROVIDER); - List providers = new ArrayList(); - providers.add(provider); - cfgDes.setLanguageSettingProviders(providers); + ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, false); } monitor.worked(work); } mngr.setProjectDescription(project, des); } - + @Override protected void doTemplatesPostProcess(IProject prj) { if(entryInfo == null) return; - + Template template = entryInfo.getInitializedTemplate(getStartingPage(), getConfigPage(), getMainPageData()); if(template == null) return; List configs = new ArrayList(); for (CfgHolder cfg : cfgs) { - configs.add((IConfiguration)cfg.getConfiguration()); + configs.add(cfg.getConfiguration()); } template.getTemplateInfo().setConfigurations(configs); @@ -639,19 +643,19 @@ public class MBSWizardHandler extends CWizardHandler { TemplateEngineUIUtil.showError(statuses[0].getMessage(), statuses[0].getException()); } } - + protected CDTConfigWizardPage getConfigPage() { if (fConfigPage == null) { fConfigPage = new CDTConfigWizardPage(this); } return fConfigPage; } - + @Override public IWizardPage getSpecificPage() { return entryInfo.getNextPage(getStartingPage(), getConfigPage()); } - + /** * Mark preferred toolchains with specific images */ @@ -670,11 +674,11 @@ public class MBSWizardHandler extends CWizardHandler { } } } - + public List getPreferredTCNames() { return preferredTCs; } - + @Override public String getHeader() { return head; } public boolean isDummy() { return false; } @@ -682,11 +686,11 @@ public class MBSWizardHandler extends CWizardHandler { public boolean supportsPreferred() { return true; } @Override - public boolean isChanged() { + public boolean isChanged() { if (savedToolChains == null) return true; IToolChain[] tcs = getSelectedToolChains(); - if (savedToolChains.length != tcs.length) + if (savedToolChains.length != tcs.length) return true; for (IToolChain savedToolChain : savedToolChains) { boolean found = false; @@ -701,12 +705,12 @@ public class MBSWizardHandler extends CWizardHandler { } return false; } - + @Override public void saveState() { savedToolChains = getSelectedToolChains(); } - + // Methods specific for MBSWizardHandler public IToolChain[] getSelectedToolChains() { @@ -722,7 +726,7 @@ public class MBSWizardHandler extends CWizardHandler { public int getToolChainsCount() { if (entryInfo == null) return full_tcs.size(); - else + else return entryInfo.tc_filter().size(); } public String getPropertyId() { @@ -739,13 +743,13 @@ public class MBSWizardHandler extends CWizardHandler { return fConfigPage.getCfgItems(defaults); } @Override - public String getErrorMessage() { + public String getErrorMessage() { TableItem[] tis = table.getSelection(); if (tis == null || tis.length == 0) - return Messages.MBSWizardHandler_0; + return Messages.MBSWizardHandler_0; return null; } - + @Override protected void doCustom(IProject newProject) { IRunnableWithProgress[] operations = MBSCustomPageManager.getOperations(); @@ -759,7 +763,7 @@ public class MBSWizardHandler extends CWizardHandler { ManagedBuilderUIPlugin.log(e); } } - + @Override public void postProcess(IProject newProject, boolean created) { deleteExtraConfigs(newProject); @@ -770,17 +774,17 @@ public class MBSWizardHandler extends CWizardHandler { doCustom(newProject); } } - + /** - * Deletes configurations - * + * Deletes configurations + * * @param newProject - affected project */ private void deleteExtraConfigs(IProject newProject) { - if (isChanged()) return; // no need to delete + if (isChanged()) return; // no need to delete if (listener != null && listener.isCurrent()) return; // nothing to delete if (fConfigPage == null || !fConfigPage.pagesLoaded) return; - + ICProjectDescription prjd = CoreModel.getDefault().getProjectDescription(newProject, true); if (prjd == null) return; ICConfigurationDescription[] all = prjd.getConfigurations(); @@ -804,19 +808,19 @@ public class MBSWizardHandler extends CWizardHandler { CoreModel.getDefault().setProjectDescription(newProject, prjd); } catch (CoreException e) {} } - + @Override - public boolean isApplicable(EntryDescriptor data) { + public boolean isApplicable(EntryDescriptor data) { EntryInfo info = new EntryInfo(data, full_tcs, wizard); return info.isValid() && (info.getToolChainsCount() > 0); } - + @Override public void initialize(EntryDescriptor data) throws CoreException { EntryInfo info = new EntryInfo(data, full_tcs, wizard); if(!info.isValid()) throw new CoreException(new Status(IStatus.ERROR, ManagedBuilderUIPlugin.getUniqueIdentifier(), "inappropriate descriptor")); //$NON-NLS-1$ - + entryInfo = info; } @@ -842,20 +846,20 @@ public class MBSWizardHandler extends CWizardHandler { public boolean canFinish() { if(entryInfo == null) return false; - + if (!getConfigPage().isCustomPageComplete()) return false; - + if(!entryInfo.canFinish(startingPage, getConfigPage())) return false; - + if (customPages != null) for (int i=0; i providers = ManagedBuildManager.getLanguageSettingsProviders(config); - cfgDes.setLanguageSettingProviders(providers); + if (cfgDes instanceof ILanguageSettingsProvidersKeeper) { + ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, isTryingNewSD); + if (isTryingNewSD) { + List providers = ManagedBuildManager.getLanguageSettingsProviders(config); + ((ILanguageSettingsProvidersKeeper) cfgDes).setLanguageSettingProviders(providers); + } else { + ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(ManagedBuildManager.MBS_LANGUAGE_SETTINGS_PROVIDER); + List providers = new ArrayList(); + providers.add(provider); + ((ILanguageSettingsProvidersKeeper) cfgDes).setLanguageSettingProviders(providers); + } } else { - ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(ManagedBuildManager.MBS_LANGUAGE_SETTINGS_PROVIDER); - List providers = new ArrayList(); - providers.add(provider); - cfgDes.setLanguageSettingProviders(providers); + ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, false); } monitor.worked(1); diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/STDWizardHandler.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/STDWizardHandler.java index cb515055f89..6ac895391ed 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/STDWizardHandler.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/STDWizardHandler.java @@ -15,6 +15,7 @@ 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.ScannerDiscoveryLegacySupport; import org.eclipse.cdt.core.model.CoreModel; @@ -46,13 +47,13 @@ import org.eclipse.swt.widgets.Composite; public class STDWizardHandler extends MBSWizardHandler { public STDWizardHandler(Composite p, IWizard w) { - super(Messages.StdBuildWizard_0, p, w); + super(Messages.StdBuildWizard_0, p, w); } @Override public void addTc(IToolChain tc) { if (tc == null) { - full_tcs.put(Messages.StdProjectTypeHandler_0, null); + full_tcs.put(Messages.StdProjectTypeHandler_0, null); } else { if (tc.isAbstract() || tc.isSystemObject()) return; // unlike CWizardHandler, we don't check for configs @@ -67,9 +68,9 @@ public class STDWizardHandler extends MBSWizardHandler { public void createProject(IProject project, boolean defaults, boolean onFinish, IProgressMonitor monitor) throws CoreException { try { monitor.beginTask("", 100);//$NON-NLS-1$ - + setProjectDescription(project, defaults, onFinish, monitor); - + doTemplatesPostProcess(project); doCustom(project); monitor.worked(30); @@ -112,40 +113,44 @@ public class STDWizardHandler extends MBSWizardHandler { } bld.setManagedBuildOn(false); } else { - System.out.println(Messages.StdProjectTypeHandler_3); + System.out.println(Messages.StdProjectTypeHandler_3); } cfg.setArtifactName(mProj.getDefaultArtifactName()); CConfigurationData data = cfg.getConfigurationData(); ICConfigurationDescription cfgDes = des.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID, data); - ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, isTryingNewSD); - if (isTryingNewSD) { - List providers = ManagedBuildManager.getLanguageSettingsProviders(cfg); - cfgDes.setLanguageSettingProviders(providers); + if (cfgDes instanceof ILanguageSettingsProvidersKeeper) { + ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, isTryingNewSD); + if (isTryingNewSD) { + List providers = ManagedBuildManager.getLanguageSettingsProviders(cfg); + ((ILanguageSettingsProvidersKeeper) cfgDes).setLanguageSettingProviders(providers); + } else { + ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(ManagedBuildManager.MBS_LANGUAGE_SETTINGS_PROVIDER); + List providers = new ArrayList(); + providers.add(provider); + ((ILanguageSettingsProvidersKeeper) cfgDes).setLanguageSettingProviders(providers); + } } else { - ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(ManagedBuildManager.MBS_LANGUAGE_SETTINGS_PROVIDER); - List providers = new ArrayList(); - providers.add(provider); - cfgDes.setLanguageSettingProviders(providers); + ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, false); } monitor.worked(work); } mngr.setProjectDescription(project, des); } - public boolean canCreateWithoutToolchain() { return true; } - + public boolean canCreateWithoutToolchain() { return true; } + @Override public void convertProject(IProject proj, IProgressMonitor monitor) throws CoreException { setProjectDescription(proj, true, true, monitor); } - + /** * If no toolchains selected by user, use default toolchain */ @Override public IToolChain[] getSelectedToolChains() { - if (full_tcs.size() == 0 || table.getSelection().length == 0) + if (full_tcs.size() == 0 || table.getSelection().length == 0) return new IToolChain[] { null }; else return super.getSelectedToolChains(); diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsListenersTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsListenersTests.java index 0ccb02d6603..922cf8e2ed9 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsListenersTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsListenersTests.java @@ -124,13 +124,14 @@ public class LanguageSettingsListenersTests extends BaseTestCase { ICConfigurationDescription[] cfgDescriptions = writableProjDescription.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 providers = new ArrayList(); providers.add(mockProvider); - cfgDescription.setLanguageSettingProviders(providers); - List storedProviders = cfgDescription.getLanguageSettingProviders(); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); + List storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); assertEquals(1, storedProviders.size()); // write to project description @@ -170,14 +171,16 @@ public class LanguageSettingsListenersTests extends BaseTestCase { 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 providers = new ArrayList(); providers.add(mockProvider); - cfgDescription1.setLanguageSettingProviders(providers); - List storedProviders = cfgDescription1.getLanguageSettingProviders(); + ((ILanguageSettingsProvidersKeeper) cfgDescription1).setLanguageSettingProviders(providers); + List storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription1).getLanguageSettingProviders(); assertEquals(1, storedProviders.size()); } { @@ -185,8 +188,8 @@ public class LanguageSettingsListenersTests extends BaseTestCase { ILanguageSettingsProvider mockProvider = new MockListenerRegisterer(PROVIDER_1, PROVIDER_NAME_1); List providers = new ArrayList(); providers.add(mockProvider); - cfgDescription2.setLanguageSettingProviders(providers); - List storedProviders = cfgDescription2.getLanguageSettingProviders(); + ((ILanguageSettingsProvidersKeeper) cfgDescription2).setLanguageSettingProviders(providers); + List storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription2).getLanguageSettingProviders(); assertEquals(1, storedProviders.size()); } @@ -222,13 +225,14 @@ public class LanguageSettingsListenersTests extends BaseTestCase { ICConfigurationDescription[] cfgDescriptions = writableProjDescription.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 providers = new ArrayList(); providers.add(workspaceProvider); - cfgDescription.setLanguageSettingProviders(providers); - List storedProviders = cfgDescription.getLanguageSettingProviders(); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); + List storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); assertEquals(1, storedProviders.size()); // write to project description @@ -270,21 +274,23 @@ public class LanguageSettingsListenersTests extends BaseTestCase { 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 providers = new ArrayList(); providers.add(workspaceProvider); - cfgDescription1.setLanguageSettingProviders(providers); - List storedProviders = cfgDescription1.getLanguageSettingProviders(); + ((ILanguageSettingsProvidersKeeper) cfgDescription1).setLanguageSettingProviders(providers); + List storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription1).getLanguageSettingProviders(); assertEquals(1, storedProviders.size()); } { // add global provider to configuration 2 List providers = new ArrayList(); providers.add(workspaceProvider); - cfgDescription2.setLanguageSettingProviders(providers); - List storedProviders = cfgDescription2.getLanguageSettingProviders(); + ((ILanguageSettingsProvidersKeeper) cfgDescription2).setLanguageSettingProviders(providers); + List storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription2).getLanguageSettingProviders(); assertEquals(1, storedProviders.size()); } // write to project description @@ -325,21 +331,23 @@ public class LanguageSettingsListenersTests extends BaseTestCase { 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 providers = new ArrayList(); providers.add(workspaceProvider); - cfgDescription1.setLanguageSettingProviders(providers); - List storedProviders = cfgDescription1.getLanguageSettingProviders(); + ((ILanguageSettingsProvidersKeeper) cfgDescription1).setLanguageSettingProviders(providers); + List storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription1).getLanguageSettingProviders(); assertEquals(1, storedProviders.size()); } { // add global provider to configuration 2 List providers = new ArrayList(); providers.add(workspaceProvider); - cfgDescription2.setLanguageSettingProviders(providers); - List storedProviders = cfgDescription2.getLanguageSettingProviders(); + ((ILanguageSettingsProvidersKeeper) cfgDescription2).setLanguageSettingProviders(providers); + List storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription2).getLanguageSettingProviders(); assertEquals(1, storedProviders.size()); } // write to project description @@ -356,12 +364,14 @@ public class LanguageSettingsListenersTests extends BaseTestCase { 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 providers = new ArrayList(); - cfgDescription1.setLanguageSettingProviders(providers); - List storedProviders = cfgDescription1.getLanguageSettingProviders(); + ((ILanguageSettingsProvidersKeeper) cfgDescription1).setLanguageSettingProviders(providers); + List storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription1).getLanguageSettingProviders(); assertEquals(0, storedProviders.size()); } // write to project description @@ -387,13 +397,14 @@ public class LanguageSettingsListenersTests extends BaseTestCase { ICConfigurationDescription[] cfgDescriptions = writableProjDescription.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 providers = new ArrayList(); providers.add(workspaceProvider); - cfgDescription.setLanguageSettingProviders(providers); - List storedProviders = cfgDescription.getLanguageSettingProviders(); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); + List storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); assertEquals(1, storedProviders.size()); // write to project description @@ -410,13 +421,14 @@ public class LanguageSettingsListenersTests extends BaseTestCase { ICConfigurationDescription[] cfgDescriptions = writableProjDescription.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 providers = new ArrayList(); providers.add(workspaceProvider); - cfgDescription.setLanguageSettingProviders(providers); - List storedProviders = cfgDescription.getLanguageSettingProviders(); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); + List storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); assertEquals(1, storedProviders.size()); // write to project description @@ -484,12 +496,13 @@ public class LanguageSettingsListenersTests extends BaseTestCase { ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); // add global provider List providers = new ArrayList(); providers.add(workspaceProvider); - cfgDescription.setLanguageSettingProviders(providers); - List storedProviders = cfgDescription.getLanguageSettingProviders(); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); + List storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); assertEquals(1, storedProviders.size()); // write to project description @@ -532,11 +545,12 @@ public class LanguageSettingsListenersTests extends BaseTestCase { ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); // clear providers List providers = new ArrayList(); - cfgDescription.setLanguageSettingProviders(providers); - List storedProviders = cfgDescription.getLanguageSettingProviders(); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); + List storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); assertEquals(0, storedProviders.size()); // write to project description @@ -556,13 +570,14 @@ public class LanguageSettingsListenersTests extends BaseTestCase { ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); // create a provider and add to cfgDescription ILanguageSettingsProvider mockProvider = new MockLanguageSettingsEditableProvider(PROVIDER_1, PROVIDER_NAME_1); List providers = new ArrayList(); providers.add(mockProvider); - cfgDescription.setLanguageSettingProviders(providers); - List storedProviders = cfgDescription.getLanguageSettingProviders(); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); + List storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); assertEquals(1, storedProviders.size()); // write to project description @@ -586,11 +601,12 @@ public class LanguageSettingsListenersTests extends BaseTestCase { ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); // clear providers List providers = new ArrayList(); - cfgDescription.setLanguageSettingProviders(providers); - List storedProviders = cfgDescription.getLanguageSettingProviders(); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); + List storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); assertEquals(0, storedProviders.size()); // write to project description @@ -611,6 +627,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase { 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); @@ -619,8 +636,8 @@ public class LanguageSettingsListenersTests extends BaseTestCase { mockProvider.setSettingEntries(cfgDescription, project, null, entries); List providers = new ArrayList(); providers.add(mockProvider); - cfgDescription.setLanguageSettingProviders(providers); - List storedProviders = cfgDescription.getLanguageSettingProviders(); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); + List storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); assertEquals(1, storedProviders.size()); // write to project description @@ -650,12 +667,13 @@ public class LanguageSettingsListenersTests extends BaseTestCase { ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); // create a provider and add to cfgDescription List providers = new ArrayList(); providers.add(new MockLanguageSettingsEditableProvider(PROVIDER_1, PROVIDER_NAME_1)); - cfgDescription.setLanguageSettingProviders(providers); - List storedProviders = cfgDescription.getLanguageSettingProviders(); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); + List storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); assertEquals(1, storedProviders.size()); // write to project description @@ -675,12 +693,14 @@ public class LanguageSettingsListenersTests extends BaseTestCase { ICConfigurationDescription[] cfgDescriptions = prjDescription.getConfigurations(); assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); + String cfgDescriptionId = cfgDescription.getId(); // Add entries List entries = new ArrayList(); entries.add(SAMPLE_LSE); - List providers = cfgDescription.getLanguageSettingProviders(); + List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); assertEquals(1, providers.size()); assertTrue(providers.get(0) instanceof MockLanguageSettingsEditableProvider); MockLanguageSettingsEditableProvider mockProvider = (MockLanguageSettingsEditableProvider) providers.get(0); @@ -714,12 +734,13 @@ public class LanguageSettingsListenersTests extends BaseTestCase { ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); // create a provider and add to cfgDescription List providers = new ArrayList(); providers.add(new MockLanguageSettingsEditableProvider(PROVIDER_1, PROVIDER_NAME_1)); - cfgDescription.setLanguageSettingProviders(providers); - List storedProviders = cfgDescription.getLanguageSettingProviders(); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); + List storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); assertEquals(1, storedProviders.size()); // write to project description @@ -742,12 +763,14 @@ public class LanguageSettingsListenersTests extends BaseTestCase { ICConfigurationDescription[] cfgDescriptions = prjDescription_1.getConfigurations(); assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescriptionWritable = cfgDescriptions[0]; + assertTrue(cfgDescriptionWritable instanceof ILanguageSettingsProvidersKeeper); + String cfgDescriptionId = cfgDescriptionWritable.getId(); // Add entries List entries = new ArrayList(); entries.add(SAMPLE_LSE); - List providers = cfgDescriptionWritable.getLanguageSettingProviders(); + List providers = ((ILanguageSettingsProvidersKeeper) cfgDescriptionWritable).getLanguageSettingProviders(); assertEquals(1, providers.size()); assertTrue(providers.get(0) instanceof MockLanguageSettingsEditableProvider); MockLanguageSettingsEditableProvider mockProvider = (MockLanguageSettingsEditableProvider) providers.get(0); @@ -773,12 +796,13 @@ public class LanguageSettingsListenersTests extends BaseTestCase { ICConfigurationDescription[] cfgDescriptions = prjDescription_2.getConfigurations(); assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescriptionWritable = cfgDescriptions[0]; + assertTrue(cfgDescriptionWritable instanceof ILanguageSettingsProvidersKeeper); String cfgDescriptionId = cfgDescriptionWritable.getId(); // Add same entries List entries = new ArrayList(); entries.add(SAMPLE_LSE); - List providers = cfgDescriptionWritable.getLanguageSettingProviders(); + List providers = ((ILanguageSettingsProvidersKeeper) cfgDescriptionWritable).getLanguageSettingProviders(); assertEquals(1, providers.size()); assertTrue(providers.get(0) instanceof MockLanguageSettingsEditableProvider); MockLanguageSettingsEditableProvider mockProvider = (MockLanguageSettingsEditableProvider) providers.get(0); @@ -810,11 +834,12 @@ public class LanguageSettingsListenersTests extends BaseTestCase { ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); // clear providers List providers = new ArrayList(); - cfgDescription.setLanguageSettingProviders(providers); - List storedProviders = cfgDescription.getLanguageSettingProviders(); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); + List storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); assertEquals(0, storedProviders.size()); // write to project description @@ -834,6 +859,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase { ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); // retrieve a global provider ILanguageSettingsProvider wspProvider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_EDITABLE_PROVIDER_ID); @@ -846,8 +872,8 @@ public class LanguageSettingsListenersTests extends BaseTestCase { // add the provider to cfgDescription List providers = new ArrayList(); providers.add(wspProvider); - cfgDescription.setLanguageSettingProviders(providers); - List storedProviders = cfgDescription.getLanguageSettingProviders(); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); + List storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); assertEquals(1, storedProviders.size()); // write to project description @@ -871,11 +897,12 @@ public class LanguageSettingsListenersTests extends BaseTestCase { ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); // clear providers List providers = new ArrayList(); - cfgDescription.setLanguageSettingProviders(providers); - List storedProviders = cfgDescription.getLanguageSettingProviders(); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); + List storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); assertEquals(0, storedProviders.size()); // write to project description @@ -895,6 +922,8 @@ public class LanguageSettingsListenersTests extends BaseTestCase { ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); + String cfgDescriptionId = cfgDescription.getId(); // retrieve a global provider @@ -911,8 +940,8 @@ public class LanguageSettingsListenersTests extends BaseTestCase { // add the provider to cfgDescription List providers = new ArrayList(); providers.add(wspProvider); - cfgDescription.setLanguageSettingProviders(providers); - List storedProviders = cfgDescription.getLanguageSettingProviders(); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); + List storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); assertEquals(1, storedProviders.size()); // write to project description @@ -945,6 +974,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase { ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); // retrieve a global provider ILanguageSettingsProvider wspProvider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_EDITABLE_PROVIDER_ID); @@ -957,8 +987,8 @@ public class LanguageSettingsListenersTests extends BaseTestCase { // add the provider to cfgDescription List providers = new ArrayList(); providers.add(wspProvider); - cfgDescription.setLanguageSettingProviders(providers); - List storedProviders = cfgDescription.getLanguageSettingProviders(); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); + List storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); assertEquals(1, storedProviders.size()); // write to project description diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java index cde365d0471..16b286f145a 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java @@ -58,7 +58,7 @@ public class LanguageSettingsManagerTests extends BaseTestCase { private static final String PROVIDER_NAME_1 = "test.provider.1.name"; private static final String PROVIDER_NAME_2 = "test.provider.2.name"; - class MockConfigurationDescription extends CModelMock.DummyCConfigurationDescription { + class MockConfigurationDescription extends CModelMock.DummyCConfigurationDescription implements ILanguageSettingsProvidersKeeper { List providers = new ArrayList(); public MockConfigurationDescription(String id) { super(id); @@ -130,7 +130,7 @@ public class LanguageSettingsManagerTests extends BaseTestCase { * Test ICConfigurationDescription API (getters and setters). */ public void testConfigurationDescription_Providers() throws Exception { - ICConfigurationDescription cfgDescription = new MockConfigurationDescription(CFG_ID); + MockConfigurationDescription cfgDescription = new MockConfigurationDescription(CFG_ID); // set providers ILanguageSettingsProvider provider1 = new MockProvider(PROVIDER_1, PROVIDER_NAME_1, null); @@ -170,7 +170,7 @@ public class LanguageSettingsManagerTests extends BaseTestCase { providers.add(dupe2); try { - cfgDescription.setLanguageSettingProviders(providers); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); fail("cfgDescription.setLanguageSettingProviders() should not accept duplicate providers"); } catch (Exception e) { // Exception is welcome here @@ -181,7 +181,7 @@ public class LanguageSettingsManagerTests extends BaseTestCase { * Test various cases of ill-defined providers. */ public void testRudeProviders() throws Exception { - ICConfigurationDescription cfgDescription = new MockConfigurationDescription(CFG_ID); + MockConfigurationDescription cfgDescription = new MockConfigurationDescription(CFG_ID); // set impolite provider returning null by getSettingEntries() ILanguageSettingsProvider providerNull = new MockProvider(PROVIDER_1, PROVIDER_NAME_1, null); { @@ -257,7 +257,7 @@ public class LanguageSettingsManagerTests extends BaseTestCase { * Test simple use case. */ public void testProvider_Basic() throws Exception { - final ICConfigurationDescription modelCfgDescription = new MockConfigurationDescription(CFG_ID); + final MockConfigurationDescription modelCfgDescription = new MockConfigurationDescription(CFG_ID); final List entries = new ArrayList(); entries.add(new CIncludePathEntry("path0", 0)); @@ -309,7 +309,7 @@ public class LanguageSettingsManagerTests extends BaseTestCase { * Test regular functionality with a few providers. */ public void testProvider_Regular() throws Exception { - ICConfigurationDescription cfgDescription = new MockConfigurationDescription(CFG_ID); + MockConfigurationDescription cfgDescription = new MockConfigurationDescription(CFG_ID); // create couple of providers List entries1 = new ArrayList(); @@ -392,7 +392,7 @@ public class LanguageSettingsManagerTests extends BaseTestCase { }; providers.add(provider); - cfgDescription.setLanguageSettingProviders(providers); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); { // retrieve entries for a derived resource (in a subfolder) @@ -453,7 +453,7 @@ public class LanguageSettingsManagerTests extends BaseTestCase { }; providers.add(provider); - cfgDescription.setLanguageSettingProviders(providers); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); { // retrieve entries for a resource @@ -470,7 +470,7 @@ public class LanguageSettingsManagerTests extends BaseTestCase { * Test ability to get entries by kind. */ public void testEntriesByKind_Regular() throws Exception { - ICConfigurationDescription cfgDescription = new MockConfigurationDescription(CFG_ID); + MockConfigurationDescription cfgDescription = new MockConfigurationDescription(CFG_ID); // contribute the entries List entries = new ArrayList(); @@ -504,7 +504,7 @@ public class LanguageSettingsManagerTests extends BaseTestCase { * Test how conflicting entries are resolved. */ public void testEntriesByKind_ConflictingEntries() throws Exception { - ICConfigurationDescription cfgDescription = new MockConfigurationDescription(CFG_ID); + MockConfigurationDescription cfgDescription = new MockConfigurationDescription(CFG_ID); // contribute the entries List entries = new ArrayList(); @@ -528,7 +528,7 @@ public class LanguageSettingsManagerTests extends BaseTestCase { * Check handling of {@link ICSettingEntry#UNDEFINED} flag. */ public void testEntriesByKind_Undefined() throws Exception { - ICConfigurationDescription cfgDescription = new MockConfigurationDescription(CFG_ID); + MockConfigurationDescription cfgDescription = new MockConfigurationDescription(CFG_ID); // contribute the entries List entries = new ArrayList(); @@ -550,7 +550,7 @@ public class LanguageSettingsManagerTests extends BaseTestCase { * Check handling of local vs. system entries, see {@link ICSettingEntry#LOCAL} flag. */ public void testEntriesByKind_LocalAndSystem() throws Exception { - ICConfigurationDescription cfgDescription = new MockConfigurationDescription(CFG_ID); + MockConfigurationDescription cfgDescription = new MockConfigurationDescription(CFG_ID); // contribute the entries List entries = new ArrayList(); @@ -594,7 +594,7 @@ public class LanguageSettingsManagerTests extends BaseTestCase { * Test conflicting entries contributed by different providers. */ public void testEntriesByKind_ConflictingProviders() throws Exception { - ICConfigurationDescription cfgDescription = new MockConfigurationDescription(CFG_ID); + MockConfigurationDescription cfgDescription = new MockConfigurationDescription(CFG_ID); // contribute the entries List providers = new ArrayList(); @@ -648,18 +648,18 @@ public class LanguageSettingsManagerTests extends BaseTestCase { assertNotNull(workspaceProvider); { // ensure no test provider is set yet - List providers = cfgDescription.getLanguageSettingProviders(); + List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); assertEquals(0, providers.size()); } { // set test provider List providers = new ArrayList(); providers.add(workspaceProvider); - cfgDescription.setLanguageSettingProviders(providers); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); } { // check that test provider got there - List providers = cfgDescription.getLanguageSettingProviders(); + List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); assertEquals(workspaceProvider, providers.get(0)); } @@ -678,7 +678,7 @@ public class LanguageSettingsManagerTests extends BaseTestCase { ICConfigurationDescription loadedCfgDescription = loadedCfgDescriptions[0]; assertTrue(cfgDescription instanceof CConfigurationDescription); - List loadedProviders = loadedCfgDescription.getLanguageSettingProviders(); + List loadedProviders = ((ILanguageSettingsProvidersKeeper) loadedCfgDescription).getLanguageSettingProviders(); assertTrue(LanguageSettingsManager.isWorkspaceProvider(loadedProviders.get(0))); } diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java index 8b130abe4b0..1e95c8d6f4b 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java @@ -61,7 +61,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { private static CoreModel coreModel = CoreModel.getDefault(); - class MockConfigurationDescription extends CModelMock.DummyCConfigurationDescription { + class MockConfigurationDescription extends CModelMock.DummyCConfigurationDescription implements ILanguageSettingsProvidersKeeper { List providers; public MockConfigurationDescription(String id) { super(id); @@ -183,7 +183,10 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; - List originalProviders = cfgDescription.getLanguageSettingProviders(); + assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); + + List originalProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); int originalSize = originalProviders.size(); // create new provider list @@ -193,7 +196,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { assertTrue(originalSize != providers.size()); // changing providers shouldn't affect the original list - cfgDescription.setLanguageSettingProviders(providers); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); assertEquals(originalSize, originalProviders.size()); } @@ -209,11 +212,12 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); // try to write to it try { List providers = new ArrayList(); - cfgDescription.setLanguageSettingProviders(providers); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); fail("WriteAccessException was expected but it was not throw."); } catch (WriteAccessException e) { // exception is expected @@ -230,6 +234,8 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); // create a provider LanguageSettingsSerializableProvider mockProvider = new MockLanguageSettingsEditableProvider(PROVIDER_0, PROVIDER_NAME_0); @@ -237,8 +243,8 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { mockProvider.setSettingEntries(cfgDescription, null, null, entries); List providers = new ArrayList(); providers.add(mockProvider); - cfgDescription.setLanguageSettingProviders(providers); - List storedProviders = cfgDescription.getLanguageSettingProviders(); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); + List storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); assertEquals(1, storedProviders.size()); // apply new project description to the project model @@ -251,8 +257,10 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { ICConfigurationDescription[] cfgDescriptions = readOnlyProjDescription.getConfigurations(); assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); - List providers = cfgDescription.getLanguageSettingProviders(); + List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); assertEquals(1, providers.size()); ILanguageSettingsProvider loadedProvider = providers.get(0); assertTrue(loadedProvider instanceof MockLanguageSettingsEditableProvider); @@ -270,8 +278,10 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); - List providers = cfgDescription.getLanguageSettingProviders(); + List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); assertEquals(1, providers.size()); ILanguageSettingsProvider loadedProvider = providers.get(0); assertTrue(loadedProvider instanceof MockLanguageSettingsEditableProvider); @@ -436,6 +446,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations(); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); LanguageSettingsSerializableProvider serializableProvider = new LanguageSettingsSerializableProvider(PROVIDER_0, PROVIDER_NAME_0); serializableProvider.setSettingEntries(null, null, null, entries); @@ -443,13 +454,14 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { ArrayList providers = new ArrayList(); providers.add(serializableProvider); - cfgDescription.setLanguageSettingProviders(providers); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); // prepare DOM storage Document doc = XmlUtil.newDocument(); rootElement = XmlUtil.appendElement(doc, ELEM_TEST); // serialize language settings to the DOM LanguageSettingsProvidersSerializer.serializeLanguageSettingsInternal(rootElement, null, mockPrjDescription); + assertTrue(XmlUtil.toString(doc).contains(PROVIDER_0)); } { // re-load and check language settings of the newly loaded provider @@ -461,8 +473,9 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); - List providers = cfgDescription.getLanguageSettingProviders(); + List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); assertNotNull(providers); assertEquals(1, providers.size()); ILanguageSettingsProvider provider = providers.get(0); @@ -499,25 +512,29 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { // populate configuration 1 with provider ICConfigurationDescription cfgDescription1 = cfgDescriptions[0]; assertNotNull(cfgDescription1); + assertTrue(cfgDescription1 instanceof ILanguageSettingsProvidersKeeper); + assertEquals(CFG_ID, cfgDescription1.getId()); LanguageSettingsSerializableProvider provider1 = new LanguageSettingsSerializableProvider(PROVIDER_0, PROVIDER_NAME_0); provider1.setStoringEntriesInProjectArea(true); provider1.setSettingEntries(null, null, null, entries); ArrayList providers = new ArrayList(); providers.add(provider1); - cfgDescription1.setLanguageSettingProviders(providers); + ((ILanguageSettingsProvidersKeeper) cfgDescription1).setLanguageSettingProviders(providers); } { // populate configuration 2 with provider ICConfigurationDescription cfgDescription2 = cfgDescriptions[1]; assertNotNull(cfgDescription2); + assertTrue(cfgDescription2 instanceof ILanguageSettingsProvidersKeeper); + assertEquals(CFG_ID_2, cfgDescription2.getId()); LanguageSettingsSerializableProvider provider2 = new LanguageSettingsSerializableProvider(PROVIDER_0, PROVIDER_NAME_0); provider2.setStoringEntriesInProjectArea(true); provider2.setSettingEntries(null, null, null, entries2); ArrayList providers = new ArrayList(); providers.add(provider2); - cfgDescription2.setLanguageSettingProviders(providers); + ((ILanguageSettingsProvidersKeeper) cfgDescription2).setLanguageSettingProviders(providers); } } @@ -530,7 +547,9 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { // doublecheck configuration 1 ICConfigurationDescription cfgDescription1 = cfgDescriptions[0]; assertNotNull(cfgDescription1); - List providers = cfgDescription1.getLanguageSettingProviders(); + assertTrue(cfgDescription1 instanceof ILanguageSettingsProvidersKeeper); + List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription1).getLanguageSettingProviders(); + assertNotNull(providers); assertEquals(1, providers.size()); ILanguageSettingsProvider provider = providers.get(0); @@ -543,7 +562,9 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { // doublecheck configuration 2 ICConfigurationDescription cfgDescription2 = cfgDescriptions[1]; assertNotNull(cfgDescription2); - List providers = cfgDescription2.getLanguageSettingProviders(); + assertTrue(cfgDescription2 instanceof ILanguageSettingsProvidersKeeper); + + List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription2).getLanguageSettingProviders(); assertNotNull(providers); assertEquals(1, providers.size()); ILanguageSettingsProvider provider = providers.get(0); @@ -577,7 +598,9 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { // check configuration 1 ICConfigurationDescription cfgDescription1 = cfgDescriptions[0]; assertNotNull(cfgDescription1); - List providers = cfgDescription1.getLanguageSettingProviders(); + assertTrue(cfgDescription1 instanceof ILanguageSettingsProvidersKeeper); + + List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription1).getLanguageSettingProviders(); assertNotNull(providers); assertEquals(1, providers.size()); ILanguageSettingsProvider provider = providers.get(0); @@ -590,7 +613,9 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { // check configuration 2 ICConfigurationDescription cfgDescription2 = cfgDescriptions[1]; assertNotNull(cfgDescription2); - List providers = cfgDescription2.getLanguageSettingProviders(); + assertTrue(cfgDescription2 instanceof ILanguageSettingsProvidersKeeper); + List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription2).getLanguageSettingProviders(); + assertNotNull(providers); assertEquals(1, providers.size()); ILanguageSettingsProvider provider = providers.get(0); @@ -617,6 +642,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations(); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); LanguageSettingsSerializableProvider serializableProvider = new MockLanguageSettingsSerializableProvider(PROVIDER_0, PROVIDER_NAME_0); serializableProvider.setSettingEntries(null, null, null, entries); @@ -624,7 +650,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { ArrayList providers = new ArrayList(); providers.add(serializableProvider); - cfgDescription.setLanguageSettingProviders(providers); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); // prepare DOM storage Document doc = XmlUtil.newDocument(); @@ -642,8 +668,9 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); - List providers = cfgDescription.getLanguageSettingProviders(); + List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); assertNotNull(providers); assertEquals(1, providers.size()); ILanguageSettingsProvider provider = providers.get(0); @@ -669,11 +696,12 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations(); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); // populate with provider defined as extension List providers = new ArrayList(); providers.add(providerExt); - cfgDescription.setLanguageSettingProviders(providers); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); // prepare DOM storage Document doc = XmlUtil.newDocument(); @@ -691,9 +719,10 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); // and check the newly loaded provider which should be workspace provider - List providers = cfgDescription.getLanguageSettingProviders(); + List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); assertNotNull(providers); assertEquals(1, providers.size()); ILanguageSettingsProvider provider = providers.get(0); @@ -717,13 +746,14 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations(); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); // populate with provider overriding the extension (must be SerializableLanguageSettingsProvider or a class from another extension) MockLanguageSettingsSerializableProvider providerOverride = new MockLanguageSettingsSerializableProvider(idExt, PROVIDER_NAME_0); providerOverride.setStoringEntriesInProjectArea(true); List providers = new ArrayList(); providers.add(providerOverride); - cfgDescription.setLanguageSettingProviders(providers); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); // prepare DOM storage @@ -742,9 +772,10 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); // check the newly loaded provider - List providers = cfgDescription.getLanguageSettingProviders(); + List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); assertNotNull(providers); assertEquals(1, providers.size()); ILanguageSettingsProvider provider = providers.get(0); @@ -776,6 +807,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations(); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); // 1. Provider reference to extension from plugin.xml providerExt = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_BASE_PROVIDER_ID); @@ -796,7 +828,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { providers.add(providerExt); providers.add(mockProvider1); providers.add(mockProvider2); - cfgDescription.setLanguageSettingProviders(providers); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); } // prepare DOM storage @@ -815,8 +847,10 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { assertNotNull(cfgDescriptions); assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); - List providers = cfgDescription.getLanguageSettingProviders(); + List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); assertNotNull(providers); // 1. Provider reference to extension from plugin.xml ILanguageSettingsProvider provider0 = providers.get(0); @@ -862,6 +896,8 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); // create a provider LanguageSettingsSerializableProvider mockProvider = new LanguageSettingsSerializableProvider(PROVIDER_0, PROVIDER_NAME_0); @@ -869,8 +905,8 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { mockProvider.setSettingEntries(cfgDescription, null, null, entries); List providers = new ArrayList(); providers.add(mockProvider); - cfgDescription.setLanguageSettingProviders(providers); - List storedProviders = cfgDescription.getLanguageSettingProviders(); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); + List storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); assertEquals(1, storedProviders.size()); // write to project description @@ -882,7 +918,10 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { { coreModel.getProjectDescription(project); ICConfigurationDescription cfgDescription = getFirstConfigurationDescription(project); - List providers = cfgDescription.getLanguageSettingProviders(); + assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); + + List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); assertEquals(1, providers.size()); ILanguageSettingsProvider provider = providers.get(0); assertTrue(provider instanceof LanguageSettingsSerializableProvider); @@ -916,16 +955,20 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); - cfgDescription.setLanguageSettingProviders(new ArrayList()); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(new ArrayList()); coreModel.setProjectDescription(project, writableProjDescription); - List providers = cfgDescription.getLanguageSettingProviders(); + List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); assertEquals(0, providers.size()); } { // re-check if it really took it ICConfigurationDescription cfgDescription = getFirstConfigurationDescription(project); - List providers = cfgDescription.getLanguageSettingProviders(); + assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); + + List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); assertEquals(0, providers.size()); } { @@ -936,7 +979,10 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { // open to double-check the data is not kept in some other kind of cache project.open(null); ICConfigurationDescription cfgDescription = getFirstConfigurationDescription(project); - List providers = cfgDescription.getLanguageSettingProviders(); + assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); + + List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); assertEquals(0, providers.size()); // and close project.close(null); @@ -959,7 +1005,10 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { // open project and check if providers are loaded project.open(null); ICConfigurationDescription cfgDescription = getFirstConfigurationDescription(project); - List providers = cfgDescription.getLanguageSettingProviders(); + assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); + + List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); assertEquals(1, providers.size()); ILanguageSettingsProvider loadedProvider = providers.get(0); assertTrue(loadedProvider instanceof LanguageSettingsSerializableProvider); @@ -988,6 +1037,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations(); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); LanguageSettingsSerializableProvider serializableProvider = new LanguageSettingsSerializableProvider(PROVIDER_0, PROVIDER_NAME_0); serializableProvider.setSettingEntries(null, null, null, entries); @@ -996,7 +1046,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { ArrayList providers = new ArrayList(); providers.add(serializableProvider); - cfgDescription.setLanguageSettingProviders(providers); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); // prepare DOM storage Document prjDoc = XmlUtil.newDocument(); @@ -1016,8 +1066,9 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); - List providers = cfgDescription.getLanguageSettingProviders(); + List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); assertNotNull(providers); assertEquals(1, providers.size()); ILanguageSettingsProvider provider = providers.get(0); @@ -1059,6 +1110,8 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); // create a provider LanguageSettingsSerializableProvider mockProvider = new LanguageSettingsSerializableProvider(PROVIDER_0, PROVIDER_NAME_0); @@ -1066,8 +1119,8 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { mockProvider.setSettingEntries(cfgDescription, null, null, entries); List providers = new ArrayList(); providers.add(mockProvider); - cfgDescription.setLanguageSettingProviders(providers); - List storedProviders = cfgDescription.getLanguageSettingProviders(); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); + List storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); assertEquals(1, storedProviders.size()); // write to project description @@ -1083,7 +1136,10 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { { coreModel.getProjectDescription(project); ICConfigurationDescription cfgDescription = getFirstConfigurationDescription(project); - List providers = cfgDescription.getLanguageSettingProviders(); + assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); + + List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); assertEquals(1, providers.size()); ILanguageSettingsProvider provider = providers.get(0); assertTrue(provider instanceof LanguageSettingsSerializableProvider); @@ -1122,16 +1178,20 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { assertEquals(1, cfgDescriptions.length); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); - cfgDescription.setLanguageSettingProviders(new ArrayList()); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(new ArrayList()); coreModel.setProjectDescription(project, writableProjDescription); - List providers = cfgDescription.getLanguageSettingProviders(); + List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); assertEquals(0, providers.size()); } { // re-check if it really took it ICConfigurationDescription cfgDescription = getFirstConfigurationDescription(project); - List providers = cfgDescription.getLanguageSettingProviders(); + assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); + + List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); assertEquals(0, providers.size()); } { @@ -1142,7 +1202,10 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { // open to double-check the data is not kept in some other kind of cache project.open(null); ICConfigurationDescription cfgDescription = getFirstConfigurationDescription(project); - List providers = cfgDescription.getLanguageSettingProviders(); + assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); + + List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); assertEquals(0, providers.size()); // and close project.close(null); @@ -1177,7 +1240,10 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { // open project and check if providers are loaded project.open(null); ICConfigurationDescription cfgDescription = getFirstConfigurationDescription(project); - List providers = cfgDescription.getLanguageSettingProviders(); + assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); + + List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); assertEquals(1, providers.size()); ILanguageSettingsProvider loadedProvider = providers.get(0); assertTrue(loadedProvider instanceof LanguageSettingsSerializableProvider); diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsScannerInfoProviderTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsScannerInfoProviderTests.java index bdc83f649a2..ed178ac4982 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsScannerInfoProviderTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsScannerInfoProviderTests.java @@ -51,7 +51,7 @@ public class LanguageSettingsScannerInfoProviderTests extends BaseTestCase { private static final String PROVIDER_ID = "test.provider.id"; private static final String PROVIDER_ID_2 = "test.provider.id.2"; private static final String PROVIDER_NAME = "test.provider.name"; - + // constants for getProjectDescription() private static final boolean READ_ONLY = false; private static final boolean WRITEABLE = true; @@ -225,6 +225,7 @@ public class LanguageSettingsScannerInfoProviderTests extends BaseTestCase { assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); // sample file IFile file = ResourceHelper.createFile(project, "file.c"); @@ -256,7 +257,7 @@ public class LanguageSettingsScannerInfoProviderTests extends BaseTestCase { ILanguageSettingsProvider provider = new MockProvider(PROVIDER_ID, PROVIDER_NAME, entries); List providers = new ArrayList(); providers.add(provider); - cfgDescription.setLanguageSettingProviders(providers); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); // set project description CProjectDescriptionManager.getInstance().setProjectDescription(project, prjDescription); @@ -296,6 +297,7 @@ public class LanguageSettingsScannerInfoProviderTests extends BaseTestCase { assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); // sample file IFile file = ResourceHelper.createFile(project, "file.c"); @@ -319,7 +321,7 @@ public class LanguageSettingsScannerInfoProviderTests extends BaseTestCase { ILanguageSettingsProvider provider = new MockProvider(PROVIDER_ID, PROVIDER_NAME, entries); List providers = new ArrayList(); providers.add(provider); - cfgDescription.setLanguageSettingProviders(providers); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); // set project description CProjectDescriptionManager.getInstance().setProjectDescription(project, prjDescription); @@ -349,22 +351,23 @@ public class LanguageSettingsScannerInfoProviderTests extends BaseTestCase { assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); assertNotNull(cfgDescription); - + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); + // sample file IFile file = ResourceHelper.createFile(project, "file.c"); - + // contribute the entries IFolder frameworkFolder = ResourceHelper.createFolder(project, "Fmwk"); CIncludePathEntry frameworkPathEntry = new CIncludePathEntry(frameworkFolder, ICSettingEntry.FRAMEWORKS_MAC); - + List entries = new ArrayList(); entries.add(frameworkPathEntry); - + // add provider to the configuration ILanguageSettingsProvider provider = new MockProvider(PROVIDER_ID, PROVIDER_NAME, entries); List providers = new ArrayList(); providers.add(provider); - cfgDescription.setLanguageSettingProviders(providers); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); // set project description CProjectDescriptionManager.getInstance().setProjectDescription(project, prjDescription); @@ -380,7 +383,7 @@ public class LanguageSettingsScannerInfoProviderTests extends BaseTestCase { new Path(actualIncludePaths[1])); assertEquals(2, actualIncludePaths.length); } - + /** * Test duplicate entries. */ @@ -391,6 +394,7 @@ public class LanguageSettingsScannerInfoProviderTests extends BaseTestCase { assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); // sample file IFile file = ResourceHelper.createFile(project, "file.c"); @@ -412,7 +416,7 @@ public class LanguageSettingsScannerInfoProviderTests extends BaseTestCase { ILanguageSettingsProvider provider = new MockProvider(PROVIDER_ID, PROVIDER_NAME, entries); List providers = new ArrayList(); providers.add(provider); - cfgDescription.setLanguageSettingProviders(providers); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); // set project description CProjectDescriptionManager.getInstance().setProjectDescription(project, prjDescription); @@ -440,6 +444,7 @@ public class LanguageSettingsScannerInfoProviderTests extends BaseTestCase { assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); // create sample file IFile file = ResourceHelper.createFile(project, "file.c"); @@ -472,7 +477,7 @@ public class LanguageSettingsScannerInfoProviderTests extends BaseTestCase { ILanguageSettingsProvider provider = new MockProvider(PROVIDER_ID, PROVIDER_NAME, entries); List providers = new ArrayList(); providers.add(provider); - cfgDescription.setLanguageSettingProviders(providers); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); // set project description CProjectDescriptionManager.getInstance().setProjectDescription(project, prjDescription); @@ -508,6 +513,7 @@ public class LanguageSettingsScannerInfoProviderTests extends BaseTestCase { assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); // create sample file IFile file = ResourceHelper.createFile(project, "file.c"); @@ -523,7 +529,7 @@ public class LanguageSettingsScannerInfoProviderTests extends BaseTestCase { ILanguageSettingsProvider provider = new MockProvider(PROVIDER_ID, PROVIDER_NAME, entries); List providers = new ArrayList(); providers.add(provider); - cfgDescription.setLanguageSettingProviders(providers); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); // set project description CProjectDescriptionManager.getInstance().setProjectDescription(project, prjDescription); @@ -559,6 +565,7 @@ public class LanguageSettingsScannerInfoProviderTests extends BaseTestCase { assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); // create sample file IFile file = ResourceHelper.createFile(project, "file.c"); @@ -576,7 +583,7 @@ public class LanguageSettingsScannerInfoProviderTests extends BaseTestCase { ILanguageSettingsProvider provider = new MockProvider(PROVIDER_ID, PROVIDER_NAME, entries); List providers = new ArrayList(); providers.add(provider); - cfgDescription.setLanguageSettingProviders(providers); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); // set project description CProjectDescriptionManager.getInstance().setProjectDescription(project, prjDescription); @@ -628,6 +635,7 @@ public class LanguageSettingsScannerInfoProviderTests extends BaseTestCase { assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); // create sample file IFile file = ResourceHelper.createFile(project, "file.c"); @@ -655,7 +663,7 @@ public class LanguageSettingsScannerInfoProviderTests extends BaseTestCase { ILanguageSettingsProvider provider = new MockProvider(PROVIDER_ID, PROVIDER_NAME, entries); List providers = new ArrayList(); providers.add(provider); - cfgDescription.setLanguageSettingProviders(providers); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); // set project description CProjectDescriptionManager.getInstance().setProjectDescription(project, prjDescription); @@ -710,6 +718,7 @@ public class LanguageSettingsScannerInfoProviderTests extends BaseTestCase { assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); // create sample file IFile file = ResourceHelper.createFile(project, "file.c"); @@ -723,7 +732,7 @@ public class LanguageSettingsScannerInfoProviderTests extends BaseTestCase { ILanguageSettingsProvider provider = new MockProvider(PROVIDER_ID, PROVIDER_NAME, entries); List providers = new ArrayList(); providers.add(provider); - cfgDescription.setLanguageSettingProviders(providers); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); // set project description CProjectDescriptionManager.getInstance().setProjectDescription(project, prjDescription); @@ -765,6 +774,7 @@ public class LanguageSettingsScannerInfoProviderTests extends BaseTestCase { assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); // sample file IFolder parentFolder = ResourceHelper.createFolder(project, "ParentFolder"); @@ -784,7 +794,7 @@ public class LanguageSettingsScannerInfoProviderTests extends BaseTestCase { List providers = new ArrayList(); providers.add(provider); - cfgDescription.setLanguageSettingProviders(providers); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); // set project description CProjectDescriptionManager.getInstance().setProjectDescription(project, prjDescription); @@ -812,6 +822,7 @@ public class LanguageSettingsScannerInfoProviderTests extends BaseTestCase { assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); // create sample file IFile file = ResourceHelper.createFile(project, "file.c"); @@ -825,8 +836,8 @@ public class LanguageSettingsScannerInfoProviderTests extends BaseTestCase { ILanguageSettingsProvider provider = new MockProvider(PROVIDER_ID, PROVIDER_NAME, entries); List providers = new ArrayList(); providers.add(provider); - cfgDescription.setLanguageSettingProviders(providers); - + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); + // set project description CProjectDescriptionManager.getInstance().setProjectDescription(project, prjDescription); @@ -893,6 +904,7 @@ public class LanguageSettingsScannerInfoProviderTests extends BaseTestCase { assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); // find 2 languages applicable to the folder List languageIds = getLanguages(folder, cfgDescription); @@ -917,7 +929,7 @@ public class LanguageSettingsScannerInfoProviderTests extends BaseTestCase { List providers = new ArrayList(); providers.add(provider1); providers.add(provider2); - cfgDescription.setLanguageSettingProviders(providers); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); // set project description CProjectDescriptionManager.getInstance().setProjectDescription(project, prjDescription); diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/settings/model/CProjectDescriptionDeltaTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/settings/model/CProjectDescriptionDeltaTests.java index b2de9f3bef9..921b2256cb5 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/settings/model/CProjectDescriptionDeltaTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/settings/model/CProjectDescriptionDeltaTests.java @@ -20,6 +20,7 @@ import junit.framework.TestSuite; import org.eclipse.cdt.core.CCorePlugin; 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.LanguageSettingsSerializableProvider; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.settings.model.util.CDataUtil; @@ -31,25 +32,26 @@ import org.eclipse.core.resources.IProject; public class CProjectDescriptionDeltaTests extends BaseTestCase{ private MockListener listener; - + private class MockListener implements ICProjectDescriptionListener { private boolean fIsNotified; private String fProjName; private ICDescriptionDelta fDelta; - + public MockListener(String projName){ fProjName = projName; fIsNotified = false; fDelta = null; } - + + @Override public void handleEvent(CProjectDescriptionEvent event) { if(!event.getProject().getName().equals(fProjName)) return; fIsNotified = true; fDelta = event.getProjectDelta(); } - + boolean isNotified(){ return fIsNotified; } @@ -63,36 +65,38 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ return fDelta; } } - + public static TestSuite suite() { return suite(CProjectDescriptionDeltaTests.class, "_"); } + @Override protected void setUp() throws Exception { } - + + @Override protected void tearDown() throws Exception { ResourceHelper.cleanUp(); } - + private void initListener(String projName){ ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager(); if(listener != null) mngr.removeCProjectDescriptionListener(listener); listener = new MockListener(projName); mngr.addCProjectDescriptionListener(listener, CProjectDescriptionEvent.APPLIED); - + assertFalse(listener.isNotified()); } - + private static List findDeltas(ICDescriptionDelta delta, int type) { List list = new ArrayList(); if ((delta.getChangeFlags()&type)!=0) { list.add(delta); } - + ICDescriptionDelta[] children = delta.getChildren(); for (ICDescriptionDelta d : children) { list.addAll(findDeltas(d, type)); @@ -103,32 +107,32 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ public void testDelta_ACTIVE_CFG() throws Exception { String projName = getName(); ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager(); - + initListener(projName); IProject project = ResourceHelper.createCDTProject(projName, null, new String[] {"test.configuration.1", "test.configuration.2"}); - + // Get writable project description and its configurations ICProjectDescription prjDescription = mngr.getProjectDescription(project, true); assertNotNull(prjDescription); assertEquals(2, prjDescription.getConfigurations().length); - + ICConfigurationDescription cfgDescription0 = prjDescription.getConfigurations()[0]; assertNotNull(cfgDescription0); assertSame(cfgDescription0, prjDescription.getActiveConfiguration()); - + ICConfigurationDescription cfgDescription1 = prjDescription.getConfigurations()[1]; assertNotNull(cfgDescription1); assertNotSame(cfgDescription1, prjDescription.getActiveConfiguration()); - + // ACTIVE_CFG: Change active configuration prjDescription.setActiveConfiguration(cfgDescription1); - + // Write project description listener.clearNotified(); mngr.setProjectDescription(project, prjDescription); assertEquals(true, listener.isNotified()); - + // Analyze delta ICDescriptionDelta rootDelta = listener.getDelta(); assertNotNull(rootDelta); @@ -136,41 +140,41 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ assertEquals(1, deltas.size()); ICDescriptionDelta delta = deltas.get(0); assertNotNull(delta); - + // Check old setting assertTrue(delta.getOldSetting() instanceof ICProjectDescription); ICProjectDescription oldSetting = (ICProjectDescription)delta.getOldSetting(); assertEquals(cfgDescription0.getName(), oldSetting.getActiveConfiguration().getName()); - + // Check new setting assertTrue(delta.getNewSetting() instanceof ICProjectDescription); ICProjectDescription newSetting = (ICProjectDescription)delta.getNewSetting(); assertEquals(cfgDescription1.getName(), newSetting.getActiveConfiguration().getName()); } - + public void testDelta_NAME() throws Exception { String projName = getName(); ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager(); - + initListener(projName); IProject project = ResourceHelper.createCDTProjectWithConfig(projName); - + // Get writable project description and its configuration ICProjectDescription prjDescription = mngr.getProjectDescription(project, true); assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getConfigurations()[0]; assertNotNull(cfgDescription); String oldName = cfgDescription.getName(); - + // Modification ICDescriptionDelta.NAME String newName = "New name"; cfgDescription.setName(newName); - + // Write project description listener.clearNotified(); mngr.setProjectDescription(project, prjDescription); assertEquals(true, listener.isNotified()); - + // Analyze delta ICDescriptionDelta rootDelta = listener.getDelta(); assertNotNull(rootDelta); @@ -179,40 +183,40 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ ICDescriptionDelta delta = deltas.get(0); assertNotNull(delta); assertEquals(ICDescriptionDelta.NAME, delta.getChangeFlags()); - + // Check old setting assertTrue(delta.getOldSetting() instanceof ICConfigurationDescription); ICConfigurationDescription oldSetting = (ICConfigurationDescription)delta.getOldSetting(); assertEquals(oldName, oldSetting.getName()); - + // Check new setting assertTrue(delta.getNewSetting() instanceof ICConfigurationDescription); ICConfigurationDescription newSetting = (ICConfigurationDescription)delta.getNewSetting(); assertEquals(newName, newSetting.getName()); } - + public void testDelta_DESCRIPTION() throws Exception { String projName = getName(); ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager(); - + initListener(projName); IProject project = ResourceHelper.createCDTProjectWithConfig(projName); - + // Get writable project description and its configuration ICProjectDescription prjDescription = mngr.getProjectDescription(project, true); assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getConfigurations()[0]; assertNotNull(cfgDescription); String oldDescription = cfgDescription.getDescription(); - + // Modification ICDescriptionDelta.DESCRIPTION cfgDescription.setDescription("New description"); - + // Write project description listener.clearNotified(); mngr.setProjectDescription(project, prjDescription); assertEquals(true, listener.isNotified()); - + // Analyze delta ICDescriptionDelta rootDelta = listener.getDelta(); assertNotNull(rootDelta); @@ -221,45 +225,45 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ ICDescriptionDelta delta = deltas.get(0); assertNotNull(delta); assertEquals(ICDescriptionDelta.DESCRIPTION, delta.getChangeFlags()); - + // Check old setting assertTrue(delta.getOldSetting() instanceof ICConfigurationDescription); ICConfigurationDescription oldSetting = (ICConfigurationDescription)delta.getOldSetting(); assertEquals(oldDescription, oldSetting.getDescription()); - + // Check new setting assertTrue(delta.getNewSetting() instanceof ICConfigurationDescription); ICConfigurationDescription newSetting = (ICConfigurationDescription)delta.getNewSetting(); assertEquals(cfgDescription.getDescription(), newSetting.getDescription()); - + } public void testDelta_LANGUAGE_ID() throws Exception { String projName = getName(); ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager(); - + initListener(projName); IProject project = ResourceHelper.createCDTProjectWithConfig(projName); IFile file = ResourceHelper.createFile(project, "test.cpp"); - + // Get writable project description and its configuration ICProjectDescription prjDescription = mngr.getProjectDescription(project, true); assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getConfigurations()[0]; assertNotNull(cfgDescription); - + // Modification LANGUAGE_ID ICLanguageSetting langSetting = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), false); String oldLanguageId = langSetting.getLanguageId(); String newLanguageId = "test.language.id"; assertTrue(!newLanguageId.equals(oldLanguageId)); langSetting.setLanguageId(newLanguageId); - + // Write project description listener.clearNotified(); mngr.setProjectDescription(project, prjDescription); assertEquals(true, listener.isNotified()); - + // Analyze delta ICDescriptionDelta rootDelta = listener.getDelta(); assertNotNull(rootDelta); @@ -273,38 +277,38 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ assertTrue(delta.getOldSetting() instanceof ICLanguageSetting); ICLanguageSetting oldSetting = (ICLanguageSetting)delta.getOldSetting(); assertEquals(oldLanguageId, oldSetting.getLanguageId()); - + // Check new setting assertTrue(delta.getNewSetting() instanceof ICLanguageSetting); ICLanguageSetting newSetting = (ICLanguageSetting)delta.getNewSetting(); assertEquals(newLanguageId, newSetting.getLanguageId()); - + } - + public void testDelta_SOURCE_CONTENT_TYPE() throws Exception { String projName = getName(); ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager(); - + initListener(projName); IProject project = ResourceHelper.createCDTProjectWithConfig(projName); IFile file = ResourceHelper.createFile(project, "test.cpp"); - + // Get writable project description and its configuration ICProjectDescription prjDescription = mngr.getProjectDescription(project, true); assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getConfigurations()[0]; assertNotNull(cfgDescription); - + // Modification SOURCE_CONTENT_TYPE final String testContentType = "test.content.type"; ICLanguageSetting langSetting = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), false); langSetting.setSourceContentTypeIds(new String[] {testContentType}); - + // Write project description listener.clearNotified(); mngr.setProjectDescription(project, prjDescription); assertEquals(true, listener.isNotified()); - + // Analyze delta ICDescriptionDelta rootDelta = listener.getDelta(); assertNotNull(rootDelta); @@ -312,35 +316,35 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ assertEquals(1, deltas.size()); ICDescriptionDelta delta = deltas.get(0); assertNotNull(delta); - + // Check old setting assertTrue(delta.getOldSetting() instanceof ICLanguageSetting); ICLanguageSetting oldSetting = (ICLanguageSetting)delta.getOldSetting(); List oldContentTypes = Arrays.asList(oldSetting.getSourceContentTypeIds()); assertTrue(!oldContentTypes.contains(testContentType)); - + // Check new setting assertTrue(delta.getNewSetting() instanceof ICLanguageSetting); ICLanguageSetting newSetting = (ICLanguageSetting)delta.getNewSetting(); List newContentTypes = Arrays.asList(newSetting.getSourceContentTypeIds()); assertTrue(newContentTypes.contains(testContentType)); - + } - + public void testDelta_SOURCE_EXTENSIONS() throws Exception { String projName = getName(); ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager(); - + initListener(projName); IProject project = ResourceHelper.createCDTProjectWithConfig(projName); IFile file = ResourceHelper.createFile(project, "test.cpp"); - + // Get writable project description and its configuration ICProjectDescription prjDescription = mngr.getProjectDescription(project, true); assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getConfigurations()[0]; assertNotNull(cfgDescription); - + // Modification SOURCE_ENTENSIONS ICLanguageSetting langSetting = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), false); final String testContentType = CCorePlugin.CONTENT_TYPE_ASMSOURCE; @@ -349,12 +353,12 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ assertTrue(exts.length>0); final String testSourceExtension = exts[0]; - + // Write project description listener.clearNotified(); mngr.setProjectDescription(project, prjDescription); assertEquals(true, listener.isNotified()); - + // Analyze delta ICDescriptionDelta rootDelta = listener.getDelta(); assertNotNull(rootDelta); @@ -363,46 +367,46 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ ICDescriptionDelta delta = deltas.get(0); assertNotNull(delta); // assertEquals(ICDescriptionDelta.SOURCE_ENTENSIONS, delta.getChangeFlags()); - + // Check old setting assertTrue(delta.getOldSetting() instanceof ICLanguageSetting); ICLanguageSetting oldSetting = (ICLanguageSetting)delta.getOldSetting(); List oldSourceExtensions = Arrays.asList(oldSetting.getSourceExtensions()); assertTrue(!oldSourceExtensions.contains(testSourceExtension)); - + // Check new setting assertTrue(delta.getNewSetting() instanceof ICLanguageSetting); ICLanguageSetting newSetting = (ICLanguageSetting)delta.getNewSetting(); List newSourceExtensions = Arrays.asList(newSetting.getSourceExtensions()); assertTrue(newSourceExtensions.contains(testSourceExtension)); - + } - + public void testDelta_SETTING_ENTRIES() throws Exception { String projName = getName(); ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager(); - + initListener(projName); IProject project = ResourceHelper.createCDTProjectWithConfig(projName); IFile file = ResourceHelper.createFile(project, "test.cpp"); - + // Get writable project description and its configuration ICProjectDescription prjDescription = mngr.getProjectDescription(project, true); assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getConfigurations()[0]; assertNotNull(cfgDescription); - + // Modification SETTING_ENTRIES ICLanguageSettingEntry testSettingEntry = new CIncludePathEntry("/path", 0); ICLanguageSetting langSetting = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), false); ICLanguageSettingEntry[] entries = new ICLanguageSettingEntry[] {testSettingEntry}; langSetting.setSettingEntries(ICSettingEntry.INCLUDE_PATH, entries); - + // Write project description listener.clearNotified(); mngr.setProjectDescription(project, prjDescription); assertEquals(true, listener.isNotified()); - + // Analyze delta ICDescriptionDelta rootDelta = listener.getDelta(); assertNotNull(rootDelta); @@ -411,43 +415,43 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ ICDescriptionDelta delta = deltas.get(0); assertNotNull(delta); assertEquals(ICDescriptionDelta.SETTING_ENTRIES, delta.getChangeFlags()); - + // Check old setting assertTrue(delta.getOldSetting() instanceof ICLanguageSetting); ICLanguageSetting oldSetting = (ICLanguageSetting)delta.getOldSetting(); List oldSettingEntries = oldSetting.getSettingEntriesList(ICSettingEntry.INCLUDE_PATH); assertTrue(!oldSettingEntries.contains(testSettingEntry)); - + // Check new setting assertTrue(delta.getNewSetting() instanceof ICLanguageSetting); ICLanguageSetting newSetting = (ICLanguageSetting)delta.getNewSetting(); List newSettingEntries = newSetting.getSettingEntriesList(ICSettingEntry.INCLUDE_PATH); assertTrue(newSettingEntries.contains(testSettingEntry)); } - + public void testDelta_BINARY_PARSER_IDS() throws Exception { String projName = getName(); ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager(); - + initListener(projName); IProject project = ResourceHelper.createCDTProjectWithConfig(projName); - + // Get writable project description and its configuration ICProjectDescription prjDescription = mngr.getProjectDescription(project, true); assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getConfigurations()[0]; assertNotNull(cfgDescription); - - // Modification BINARY_PARSER_IDS + + // Modification BINARY_PARSER_IDS final String testBinaryParserId = "test.binary.parser.id"; ICTargetPlatformSetting targetPlatformSetting = cfgDescription.getTargetPlatformSetting(); targetPlatformSetting.setBinaryParserIds(new String[] {testBinaryParserId}); - + // Write project description listener.clearNotified(); mngr.setProjectDescription(project, prjDescription); assertEquals(true, listener.isNotified()); - + // Analyze delta ICDescriptionDelta rootDelta = listener.getDelta(); assertNotNull(rootDelta); @@ -456,43 +460,43 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ ICDescriptionDelta delta = deltas.get(0); assertNotNull(delta); assertEquals(ICDescriptionDelta.BINARY_PARSER_IDS, delta.getChangeFlags()); - + // Check old setting assertTrue(delta.getOldSetting() instanceof ICTargetPlatformSetting); ICTargetPlatformSetting oldSetting = (ICTargetPlatformSetting)delta.getOldSetting(); List oldBinaryParserIds = Arrays.asList(oldSetting.getBinaryParserIds()); assertTrue(!oldBinaryParserIds.contains(testBinaryParserId)); - + // Check new setting assertTrue(delta.getNewSetting() instanceof ICTargetPlatformSetting); ICTargetPlatformSetting newSetting = (ICTargetPlatformSetting)delta.getNewSetting(); List newBinaryParserIds = Arrays.asList(newSetting.getBinaryParserIds()); assertTrue(newBinaryParserIds.contains(testBinaryParserId)); - + } - + public void testDelta_ERROR_PARSER_IDS() throws Exception { String projName = getName(); ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager(); - + initListener(projName); IProject project = ResourceHelper.createCDTProjectWithConfig(projName); - + // Get writable project description and its configuration ICProjectDescription prjDescription = mngr.getProjectDescription(project, true); assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getConfigurations()[0]; assertNotNull(cfgDescription); - + // Modification ERROR_PARSER_IDS String testErrorParserId = "test.error.parser.id"; cfgDescription.getBuildSetting().setErrorParserIDs(new String[] {testErrorParserId}); - + // Write project description listener.clearNotified(); mngr.setProjectDescription(project, prjDescription); assertEquals(true, listener.isNotified()); - + // Analyze delta ICDescriptionDelta rootDelta = listener.getDelta(); assertNotNull(rootDelta); @@ -507,55 +511,55 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ ICBuildSetting oldSetting = (ICBuildSetting)delta.getOldSetting(); List oldErrorParserIds = Arrays.asList(oldSetting.getErrorParserIDs()); assertTrue(!oldErrorParserIds.contains(testErrorParserId)); - + // Check new setting assertTrue(delta.getNewSetting() instanceof ICBuildSetting); ICBuildSetting newSetting = (ICBuildSetting)delta.getNewSetting(); List newErrorParserIds = Arrays.asList(newSetting.getErrorParserIDs()); assertTrue(newErrorParserIds.contains(testErrorParserId)); - + } - + public void testDelta_EXCLUDE() throws Exception { String projName = getName(); ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager(); - + initListener(projName); IProject project = ResourceHelper.createCDTProjectWithConfig(projName); IFile file = ResourceHelper.createFile(project, "test.cpp"); - + { // Prepare file descriptions ICProjectDescription prjDescription = mngr.getProjectDescription(project, true); assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getConfigurations()[0]; assertNotNull(cfgDescription); - + cfgDescription.createFileDescription(file.getProjectRelativePath(),cfgDescription.getRootFolderDescription()); ICFileDescription[] fileDescriptions = cfgDescription.getFileDescriptions(); assertTrue(fileDescriptions.length>0); - + mngr.setProjectDescription(project, prjDescription); } - + { // Get writable project description and its configuration ICProjectDescription prjDescription = mngr.getProjectDescription(project, true); assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getConfigurations()[0]; assertNotNull(cfgDescription); - + // Modification EXCLUDE ICFileDescription[] fileDescriptions = cfgDescription.getFileDescriptions(); assertTrue(fileDescriptions.length>0); ICFileDescription fileDescription = fileDescriptions[0]; fileDescription.setExcluded(true); - + // Write project description listener.clearNotified(); mngr.setProjectDescription(project, prjDescription); assertEquals(true, listener.isNotified()); - + // Analyze delta ICDescriptionDelta rootDelta = listener.getDelta(); assertNotNull(rootDelta); @@ -569,39 +573,39 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ assertTrue(delta.getOldSetting() instanceof ICFileDescription); ICFileDescription oldSetting = (ICFileDescription)delta.getOldSetting(); assertTrue(!oldSetting.isExcluded()); - + // Check new setting assertTrue(delta.getNewSetting() instanceof ICFileDescription); ICFileDescription newSetting = (ICFileDescription)delta.getNewSetting(); assertTrue(newSetting.isExcluded()); } - + } - + public void testDelta_SOURCE_ADDED() throws Exception { String projName = getName(); ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager(); - + initListener(projName); IProject project = ResourceHelper.createCDTProjectWithConfig(projName); - + // Get writable project description and its configuration ICProjectDescription prjDescription = mngr.getProjectDescription(project, true); assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getConfigurations()[0]; assertNotNull(cfgDescription); - + // Modification SOURCE_ADDED List sourceEntries = new ArrayList(Arrays.asList(cfgDescription.getSourceEntries())); ICSourceEntry testSourceEntry = new CSourceEntry(project.getFullPath().append("test_src"), null, ICSettingEntry.RESOLVED); sourceEntries.add(testSourceEntry); cfgDescription.setSourceEntries(sourceEntries.toArray(new ICSourceEntry[0])); - + // Write project description listener.clearNotified(); mngr.setProjectDescription(project, prjDescription); assertEquals(true, listener.isNotified()); - + // Analyze delta ICDescriptionDelta rootDelta = listener.getDelta(); assertNotNull(rootDelta); @@ -610,27 +614,27 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ ICDescriptionDelta delta = deltas.get(0); assertNotNull(delta); // assertEquals(ICDescriptionDelta.SOURCE_ADDED, delta.getChangeFlags()); - + // Check old setting assertTrue(delta.getOldSetting() instanceof ICConfigurationDescription); ICConfigurationDescription oldSetting = (ICConfigurationDescription)delta.getOldSetting(); List oldSourceEntries = Arrays.asList(oldSetting.getSourceEntries()); assertTrue(!oldSourceEntries.contains(testSourceEntry)); - + // Check new setting assertTrue(delta.getNewSetting() instanceof ICConfigurationDescription); ICConfigurationDescription newSetting = (ICConfigurationDescription)delta.getNewSetting(); List newSourceEntries = Arrays.asList(newSetting.getSourceEntries()); assertTrue(newSourceEntries.contains(testSourceEntry)); } - + public void testDelta_SOURCE_REMOVED() throws Exception { String projName = getName(); ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager(); - + initListener(projName); IProject project = ResourceHelper.createCDTProjectWithConfig(projName); - + ICSourceEntry testSourceEntry = new CSourceEntry(project.getFullPath().append("test_src"), null, ICSettingEntry.RESOLVED); { // Add some source entry to remove it during the test @@ -638,29 +642,29 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getConfigurations()[0]; assertNotNull(cfgDescription); - + List sourceEntries = new ArrayList(Arrays.asList(cfgDescription.getSourceEntries())); sourceEntries.add(testSourceEntry); cfgDescription.setSourceEntries(sourceEntries.toArray(new ICSourceEntry[0])); - + mngr.setProjectDescription(project, prjDescription); } - + { // Get writable project description and its configuration ICProjectDescription prjDescription = mngr.getProjectDescription(project, true); assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getConfigurations()[0]; assertNotNull(cfgDescription); - + // Modification SOURCE_REMOVED cfgDescription.setSourceEntries(new ICSourceEntry[0]); - + // Write project description listener.clearNotified(); mngr.setProjectDescription(project, prjDescription); assertEquals(true, listener.isNotified()); - + // Analyze delta ICDescriptionDelta rootDelta = listener.getDelta(); assertNotNull(rootDelta); @@ -669,44 +673,44 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ ICDescriptionDelta delta = deltas.get(0); assertNotNull(delta); // assertEquals(ICDescriptionDelta.SOURCE_REMOVED, delta.getChangeFlags()); - + // Check old setting assertTrue(delta.getOldSetting() instanceof ICConfigurationDescription); ICConfigurationDescription oldSetting = (ICConfigurationDescription)delta.getOldSetting(); List oldSourceEntries = Arrays.asList(oldSetting.getSourceEntries()); assertTrue(oldSourceEntries.contains(testSourceEntry)); - + // Check new setting assertTrue(delta.getNewSetting() instanceof ICConfigurationDescription); ICConfigurationDescription newSetting = (ICConfigurationDescription)delta.getNewSetting(); List newSourceEntries = Arrays.asList(newSetting.getSourceEntries()); assertTrue(!newSourceEntries.contains(testSourceEntry)); } - + } - + public void testDelta_EXTERNAL_SETTINGS_ADDED() throws Exception { String projName = getName(); ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager(); - + initListener(projName); IProject project = ResourceHelper.createCDTProjectWithConfig(projName); - + // Get writable project description and its configuration ICProjectDescription prjDescription = mngr.getProjectDescription(project, true); assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getConfigurations()[0]; assertNotNull(cfgDescription); - + // Modification EXTERNAL_SETTINGS_ADDED ICSettingEntry testSettingEntry = new CIncludePathEntry("/path", 0); ICExternalSetting testExternalSetting = cfgDescription.createExternalSetting(null, null, null, new ICSettingEntry[] {testSettingEntry}); - + // Write project description listener.clearNotified(); mngr.setProjectDescription(project, prjDescription); assertEquals(true, listener.isNotified()); - + // Analyze delta ICDescriptionDelta rootDelta = listener.getDelta(); assertNotNull(rootDelta); @@ -715,13 +719,13 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ ICDescriptionDelta delta = deltas.get(0); assertNotNull(delta); assertEquals(ICDescriptionDelta.EXTERNAL_SETTINGS_ADDED, delta.getChangeFlags()); - + // Check old setting assertTrue(delta.getOldSetting() instanceof ICConfigurationDescription); ICConfigurationDescription oldSetting = (ICConfigurationDescription)delta.getOldSetting(); List oldExternalSettings = Arrays.asList(oldSetting.getExternalSettings()); assertEquals(0, oldExternalSettings.size()); - + // Check new setting assertTrue(delta.getNewSetting() instanceof ICConfigurationDescription); ICConfigurationDescription newSetting = (ICConfigurationDescription)delta.getNewSetting(); @@ -730,41 +734,41 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ List newSettingEntries = Arrays.asList(newExternalSettings.get(0).getEntries()); assertTrue(newSettingEntries.contains(testSettingEntry)); } - + public void testDelta_EXTERNAL_SETTINGS_REMOVED() throws Exception { String projName = getName(); ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager(); - + initListener(projName); IProject project = ResourceHelper.createCDTProjectWithConfig(projName); ICSettingEntry testSettingEntry = new CIncludePathEntry("/path", 0); - + { // Add some external setting to remove it during the test ICProjectDescription prjDescription = mngr.getProjectDescription(project, true); assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getConfigurations()[0]; assertNotNull(cfgDescription); - + ICExternalSetting testExternalSetting = cfgDescription.createExternalSetting(null, null, null, new ICSettingEntry[] {testSettingEntry}); mngr.setProjectDescription(project, prjDescription); } - + { // Get writable project description and its configuration ICProjectDescription prjDescription = mngr.getProjectDescription(project, true); assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getConfigurations()[0]; assertNotNull(cfgDescription); - + // Modification EXTERNAL_SETTINGS_REMOVED cfgDescription.removeExternalSettings(); - + // Write project description listener.clearNotified(); mngr.setProjectDescription(project, prjDescription); assertEquals(true, listener.isNotified()); - + // Analyze delta ICDescriptionDelta rootDelta = listener.getDelta(); assertNotNull(rootDelta); @@ -781,41 +785,41 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ assertEquals(1, oldExternalSettings.size()); List oldSettingEntries = Arrays.asList(oldExternalSettings.get(0).getEntries()); assertTrue(oldSettingEntries.contains(testSettingEntry)); - + // Check new setting assertTrue(delta.getNewSetting() instanceof ICConfigurationDescription); ICConfigurationDescription newSetting = (ICConfigurationDescription)delta.getNewSetting(); List newExternalSettings = Arrays.asList(newSetting.getExternalSettings()); assertEquals(0, newExternalSettings.size()); } - + } - + public void testDelta_CFG_REF_ADDED() throws Exception { String projName = getName(); ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager(); - + initListener(projName); IProject project = ResourceHelper.createCDTProjectWithConfig(projName); - + // Get writable project description and its configuration ICProjectDescription prjDescription = mngr.getProjectDescription(project, true); assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getConfigurations()[0]; assertNotNull(cfgDescription); - + // Modification CFG_REF_ADDED String testKey = "key"; String testValue = "value"; Map refs = new HashMap(); refs.put(testKey, testValue); cfgDescription.setReferenceInfo(refs); - + // Write project description listener.clearNotified(); mngr.setProjectDescription(project, prjDescription); assertEquals(true, listener.isNotified()); - + // Analyze delta ICDescriptionDelta rootDelta = listener.getDelta(); assertNotNull(rootDelta); @@ -824,13 +828,13 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ ICDescriptionDelta delta = deltas.get(0); assertNotNull(delta); assertEquals(ICDescriptionDelta.CFG_REF_ADDED, delta.getChangeFlags()); - + // Check old setting assertTrue(delta.getOldSetting() instanceof ICConfigurationDescription); ICConfigurationDescription oldSetting = (ICConfigurationDescription)delta.getOldSetting(); Map oldReferenceInfo = oldSetting.getReferenceInfo(); assertEquals(0, oldReferenceInfo.size()); - + // Check new setting assertTrue(delta.getNewSetting() instanceof ICConfigurationDescription); ICConfigurationDescription newSetting = (ICConfigurationDescription)delta.getNewSetting(); @@ -838,44 +842,44 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ assertEquals(1, newReferenceInfo.size()); assertEquals(testValue, newReferenceInfo.get(testKey)); } - + public void testDelta_CFG_REF_REMOVED() throws Exception { String projName = getName(); ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager(); - + initListener(projName); IProject project = ResourceHelper.createCDTProjectWithConfig(projName); String testKey = "key"; String testValue = "value"; - + { // Add some reference info to remove it during the test ICProjectDescription prjDescription = mngr.getProjectDescription(project, true); assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getConfigurations()[0]; assertNotNull(cfgDescription); - + Map refs = new HashMap(); refs.put(testKey, testValue); cfgDescription.setReferenceInfo(refs); mngr.setProjectDescription(project, prjDescription); } - + { // Get writable project description and its configuration ICProjectDescription prjDescription = mngr.getProjectDescription(project, true); assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getConfigurations()[0]; assertNotNull(cfgDescription); - + // Modification CFG_REF_REMOVED cfgDescription.setReferenceInfo(new HashMap()); - + // Write project description listener.clearNotified(); mngr.setProjectDescription(project, prjDescription); assertEquals(true, listener.isNotified()); - + // Analyze delta ICDescriptionDelta rootDelta = listener.getDelta(); assertNotNull(rootDelta); @@ -884,46 +888,46 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ ICDescriptionDelta delta = deltas.get(0); assertNotNull(delta); assertEquals(ICDescriptionDelta.CFG_REF_REMOVED, delta.getChangeFlags()); - + // Check old setting assertTrue(delta.getOldSetting() instanceof ICConfigurationDescription); ICConfigurationDescription oldSetting = (ICConfigurationDescription)delta.getOldSetting(); Map oldReferenceInfo = oldSetting.getReferenceInfo(); assertEquals(1, oldReferenceInfo.size()); assertEquals(testValue, oldReferenceInfo.get(testKey)); - + // Check new setting assertTrue(delta.getNewSetting() instanceof ICConfigurationDescription); ICConfigurationDescription newSetting = (ICConfigurationDescription)delta.getNewSetting(); Map newReferenceInfo = newSetting.getReferenceInfo(); assertEquals(0, newReferenceInfo.size()); } - + } - + public void testDelta_EXT_REF() throws Exception { String projName = getName(); ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager(); - + initListener(projName); IProject project = ResourceHelper.createCDTProjectWithConfig(projName); - + // Get writable project description and its configuration ICProjectDescription prjDescription = mngr.getProjectDescription(project, true); assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getConfigurations()[0]; assertNotNull(cfgDescription); - + // Modification EXT_REF, currently binary parsers are represented as CConfigExtensionReference final String testBinaryParserId = "test.binary.parser.id"; ICTargetPlatformSetting targetPlatformSetting = cfgDescription.getTargetPlatformSetting(); targetPlatformSetting.setBinaryParserIds(new String[] {testBinaryParserId}); - + // Write project description listener.clearNotified(); mngr.setProjectDescription(project, prjDescription); assertEquals(true, listener.isNotified()); - + // Analyze delta ICDescriptionDelta rootDelta = listener.getDelta(); assertNotNull(rootDelta); @@ -939,7 +943,7 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ ICTargetPlatformSetting oldTargetPlatformSetting = oldSetting.getTargetPlatformSetting(); List oldBinaryParserIds = Arrays.asList(oldTargetPlatformSetting.getBinaryParserIds()); assertTrue(!oldBinaryParserIds.contains(testBinaryParserId)); - + // Check new setting assertTrue(delta.getNewSetting() instanceof ICConfigurationDescription); ICConfigurationDescription newSetting = (ICConfigurationDescription)delta.getNewSetting(); @@ -947,36 +951,36 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ List newBinaryParserIds = Arrays.asList(newTargetPlatformSetting.getBinaryParserIds()); assertTrue(newBinaryParserIds.contains(testBinaryParserId)); } - + public void testDelta_INDEX_CFG() throws Exception { String projName = getName(); ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager(); - + initListener(projName); IProject project = ResourceHelper.createCDTProject(projName, null, new String[] {"test.configuration.1", "test.configuration.2"}); - + // Get writable project description and its configuration ICProjectDescription prjDescription = mngr.getProjectDescription(project, true); assertNotNull(prjDescription); assertEquals(2, prjDescription.getConfigurations().length); - + ICConfigurationDescription cfgDescription0 = prjDescription.getConfigurations()[0]; assertNotNull(cfgDescription0); assertSame(cfgDescription0, prjDescription.getDefaultSettingConfiguration()); - + ICConfigurationDescription cfgDescription1 = prjDescription.getConfigurations()[1]; assertNotNull(cfgDescription1); assertNotSame(cfgDescription1, prjDescription.getDefaultSettingConfiguration()); - + // Modification INDEX_CFG prjDescription.setDefaultSettingConfiguration(cfgDescription1); - + // Write project description listener.clearNotified(); mngr.setProjectDescription(project, prjDescription); assertEquals(true, listener.isNotified()); - + // Analyze delta ICDescriptionDelta rootDelta = listener.getDelta(); assertNotNull(rootDelta); @@ -990,38 +994,39 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ assertTrue(delta.getOldSetting() instanceof ICProjectDescription); ICProjectDescription oldSetting = (ICProjectDescription)delta.getOldSetting(); assertEquals(cfgDescription0.getName(), oldSetting.getDefaultSettingConfiguration().getName()); - + // Check new setting assertTrue(delta.getNewSetting() instanceof ICProjectDescription); ICProjectDescription newSetting = (ICProjectDescription)delta.getNewSetting(); assertEquals(cfgDescription1.getName(), newSetting.getDefaultSettingConfiguration().getName()); } - + public void testDelta_LANGUAGE_SETTINGS_PROVIDERS() throws Exception { String projName = getName(); ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager(); - + initListener(projName); IProject project = ResourceHelper.createCDTProjectWithConfig(projName); - + // Get writable project description and its configuration ICProjectDescription prjDescription = mngr.getProjectDescription(project, true); assertNotNull(prjDescription); ICConfigurationDescription cfgDescription = prjDescription.getConfigurations()[0]; assertNotNull(cfgDescription); - List originalProviders = cfgDescription.getLanguageSettingProviders(); - + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); + List originalProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); + // Modification LANGUAGE_SETTINGS_PROVIDERS ILanguageSettingsProvider provider = new LanguageSettingsSerializableProvider("id", "name"); List providers = new ArrayList(); providers.add(provider); - cfgDescription.setLanguageSettingProviders(providers); - + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); + // Write project description listener.clearNotified(); mngr.setProjectDescription(project, prjDescription); assertEquals(true, listener.isNotified()); - + // Analyze delta ICDescriptionDelta rootDelta = listener.getDelta(); assertNotNull(rootDelta); @@ -1030,16 +1035,18 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ ICDescriptionDelta delta = deltas.get(0); assertNotNull(delta); assertEquals(ICDescriptionDelta.LANGUAGE_SETTINGS_PROVIDERS, delta.getChangeFlags()); - + // Check old setting assertTrue(delta.getOldSetting() instanceof ICConfigurationDescription); - ICConfigurationDescription oldSetting = (ICConfigurationDescription)delta.getOldSetting(); + assertTrue(delta.getOldSetting() instanceof ILanguageSettingsProvidersKeeper); + ILanguageSettingsProvidersKeeper oldSetting = (ILanguageSettingsProvidersKeeper)delta.getOldSetting(); List oldProviders = oldSetting.getLanguageSettingProviders(); assertEquals(originalProviders, oldProviders); - + // Check new setting assertTrue(delta.getNewSetting() instanceof ICConfigurationDescription); - ICConfigurationDescription newSetting = (ICConfigurationDescription)delta.getNewSetting(); + assertTrue(delta.getNewSetting() instanceof ILanguageSettingsProvidersKeeper); + ILanguageSettingsProvidersKeeper newSetting = (ILanguageSettingsProvidersKeeper)delta.getNewSetting(); List newProviders = newSetting.getLanguageSettingProviders(); assertEquals(providers, newProviders); } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexProviderManagerTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexProviderManagerTest.java index e1a55874e49..4918c6d1873 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexProviderManagerTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexProviderManagerTest.java @@ -25,7 +25,6 @@ import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.index.provider.IIndexProvider; import org.eclipse.cdt.core.internal.index.provider.test.DummyProviderTraces; import org.eclipse.cdt.core.internal.index.provider.test.Providers; -import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.parser.util.ArrayUtil; @@ -76,7 +75,7 @@ public class IndexProviderManagerTest extends IndexTestBase { final static Class DP4= Providers.Dummy4.class; final static Class DP5= Providers.Dummy5.class; final static Class[] DPS= new Class[] {DP4, DP2, DP1, DP3, DP5}; - + /* * Fictional compatibility ranges for testing */ @@ -84,9 +83,9 @@ public class IndexProviderManagerTest extends IndexTestBase { final static VersionRange VERSION_401= new VersionRange("[36,37]"); final static VersionRange VERSION_405= new VersionRange("[37,39]"); final static VersionRange VERSION_502= new VersionRange("[89,91]"); - + final CCorePlugin core= CCorePlugin.getDefault(); - + public IndexProviderManagerTest() { super("IndexProviderManagerTest"); } @@ -107,11 +106,11 @@ public class IndexProviderManagerTest extends IndexTestBase { IndexProviderManager ipm= ((PDOMManager)CCorePlugin.getIndexManager()).getIndexProviderManager(); ipm.reset(); ipm.startup(); } - + public void testProvider_SimpleLifeCycle_200958() throws Exception { for (Class element : DPS) DPT.reset(element); - + List cprojects = new ArrayList(), expectedTrace = new ArrayList(); try { for(int i=0; i<3; i++) { @@ -138,7 +137,7 @@ public class IndexProviderManagerTest extends IndexTestBase { public void testProvider_OverDeleteAndAdd() throws Exception { DPT.reset(DP1); - + List expectedTrace = new ArrayList(); ICProject cproject = null; try { @@ -181,7 +180,7 @@ public class IndexProviderManagerTest extends IndexTestBase { File newLocation = CProjectHelper.freshDir(); IProjectDescription description = cproject.getProject().getDescription(); description.setLocationURI(newLocation.toURI()); - cproject.getProject().move(description, IResource.FORCE | IResource.SHALLOW, new NullProgressMonitor()); + cproject.getProject().move(description, IResource.FORCE | IResource.SHALLOW, new NullProgressMonitor()); index = CCorePlugin.getIndexManager().getIndex(cproject); assertEquals(expectedTrace, DPT.getProjectsTrace(DP1)); @@ -191,19 +190,19 @@ public class IndexProviderManagerTest extends IndexTestBase { } } } - + public void testVersioning_IncompatibleIgnored() throws Exception { IndexProviderManager ipm= ((PDOMManager)CCorePlugin.getIndexManager()).getIndexProviderManager(); - + ICProject cproject = null; try { cproject= CProjectHelper.createCCProject("IndexFactoryConfigurationUsageTest", IPDOMManager.ID_NO_INDEXER); IProject project= cproject.getProject(); - - + + MockState mockState = new MockState(cproject); mockState.setConfig(MockState.REL_V1_ID); - + IIndexProvider provider1= new IIndexFragmentProvider() { IIndexFragment[] fragments= new IIndexFragment[] { new MockPDOM("contentID.contentA", "36"), @@ -212,9 +211,11 @@ public class IndexProviderManagerTest extends IndexTestBase { new MockPDOM("contentID.bar", "91"), new MockPDOM("contentID.baz", "89") }; + @Override public IIndexFragment[] getIndexFragments(ICConfigurationDescription config) { return fragments; } + @Override public boolean providesFor(ICProject project) throws CoreException { return true; } @@ -224,20 +225,22 @@ public class IndexProviderManagerTest extends IndexTestBase { new MockPDOM("contentID.baz", "90"), new MockPDOM("contentID.contentA", "38"), }; + @Override public IIndexFragment[] getIndexFragments(ICConfigurationDescription config) { return fragments; } + @Override public boolean providesFor(ICProject project) throws CoreException { return true; } }; - + CCorePlugin.getIndexManager().joinIndexer(8000, npm()); // ensure IPM is called only once under test conditions setExpectedNumberOfLoggedNonOKStatusObjects(3); // foo, bar and baz have no compatible fragments available - + ipm.reset(VERSION_405); ipm.startup(); ipm.addIndexProvider(provider1); ipm.addIndexProvider(provider2); - + IIndexFragment[] actual = ipm.getProvidedIndexFragments(mockState.getCurrentConfig(), true); assertEquals(1, actual.length); assertFragmentPresent("contentID.contentA", "38", actual); @@ -247,19 +250,19 @@ public class IndexProviderManagerTest extends IndexTestBase { } } } - + public void testVersioning_NoCompatibleVersionsFound() throws Exception { IndexProviderManager ipm= ((PDOMManager)CCorePlugin.getIndexManager()).getIndexProviderManager(); - + ICProject cproject = null; try { cproject= CProjectHelper.createCCProject("IndexFactoryConfigurationUsageTest", IPDOMManager.ID_NO_INDEXER); IProject project= cproject.getProject(); - - + + MockState mockState = new MockState(cproject); mockState.setConfig(MockState.REL_V1_ID); - + IIndexProvider provider1= new IIndexFragmentProvider() { IIndexFragment[] fragments= new IIndexFragment[] { new MockPDOM("contentID.contentA", "36"), @@ -268,9 +271,11 @@ public class IndexProviderManagerTest extends IndexTestBase { new MockPDOM("contentID.bar", "91"), new MockPDOM("contentID.baz", "89") }; + @Override public IIndexFragment[] getIndexFragments(ICConfigurationDescription config) { return fragments; } + @Override public boolean providesFor(ICProject project) throws CoreException { return true; } @@ -279,20 +284,22 @@ public class IndexProviderManagerTest extends IndexTestBase { IIndexFragment[] fragments= new IIndexFragment[] { new MockPDOM("contentID.contentA", "41"), }; + @Override public IIndexFragment[] getIndexFragments(ICConfigurationDescription config) { return fragments; } + @Override public boolean providesFor(ICProject project) throws CoreException { return true; } }; - + CCorePlugin.getIndexManager().joinIndexer(8000, npm()); // ensure IPM is called only once under test conditions setExpectedNumberOfLoggedNonOKStatusObjects(1); // contentA has no compatible fragments available - + ipm.reset(VERSION_502); ipm.startup(); ipm.addIndexProvider(provider1); ipm.addIndexProvider(provider2); - + IIndexFragment[] actual = ipm.getProvidedIndexFragments(mockState.getCurrentConfig(), true); assertEquals(3, actual.length); assertFragmentPresent("contentID.foo", "90", actual); @@ -304,7 +311,7 @@ public class IndexProviderManagerTest extends IndexTestBase { } } } - + private void assertFragmentPresent(String id, String version, IIndexFragment[] fragments) throws Exception { for (IIndexFragment candidate : fragments) { String cid= null, csver= null; @@ -320,49 +327,49 @@ public class IndexProviderManagerTest extends IndexTestBase { } fail("Fragment matching (id="+id+",version="+version+") was not present"); } - + public void testIndexFactoryConfigurationUsage() throws Exception { IIndex index; - + ICProject cproject = null; // Modifying the .project file triggers an indexer job, suppress that: DeltaAnalyzer.sSuppressPotentialTUs= true; try { cproject = CProjectHelper.createCCProject("IndexFactoryConfigurationUsageTest", IPDOMManager.ID_NO_INDEXER); IProject project= cproject.getProject(); - + ICProjectDescription pd= core.getProjectDescription(project); ICConfigurationDescription cfg1= newCfg(pd, "project", "config1"); ICConfigurationDescription cfg2= newCfg(pd, "project", "config2"); core.setProjectDescription(project, pd); - + index= CCorePlugin.getIndexManager().getIndex(cproject); CCorePlugin.getIndexManager().joinIndexer(8000, npm()); - + DPT.reset(DP1); changeConfigRelations(project, ICProjectDescriptionPreferences.CONFIGS_LINK_SETTINGS_AND_ACTIVE); assertEquals(0, DPT.getProjectsTrace(DP1).size()); assertEquals(0, DPT.getCfgsTrace(DP1).size()); - + changeActiveConfiguration(project, cfg1); DPT.reset(DP1); index= CCorePlugin.getIndexManager().getIndex(cproject); assertEquals(0, DPT.getProjectsTrace(DP1).size()); assertEquals(1, DPT.getCfgsTrace(DP1).size()); assertEquals("project.config1", ((ICConfigurationDescription)DPT.getCfgsTrace(DP1).get(0)).getId()); - + changeActiveConfiguration(project, cfg2); DPT.reset(DP1); index= CCorePlugin.getIndexManager().getIndex(cproject); assertEquals(0, DPT.getProjectsTrace(DP1).size()); assertEquals(1, DPT.getCfgsTrace(DP1).size()); assertEquals("project.config2", ((ICConfigurationDescription)DPT.getCfgsTrace(DP1).get(0)).getId()); - + DPT.reset(DP1); changeConfigRelations(project, ICProjectDescriptionPreferences.CONFIGS_INDEPENDENT); assertEquals(0, DPT.getProjectsTrace(DP1).size()); assertEquals(0, DPT.getCfgsTrace(DP1).size()); - + changeActiveConfiguration(project, cfg1); DPT.reset(DP1); index= CCorePlugin.getIndexManager().getIndex(cproject); @@ -370,7 +377,7 @@ public class IndexProviderManagerTest extends IndexTestBase { assertEquals(1, DPT.getCfgsTrace(DP1).size()); // should still be config2, as the change in active configuration does not matter assertEquals("project.config2", ((ICConfigurationDescription)DPT.getCfgsTrace(DP1).get(0)).getId()); - + changeActiveConfiguration(project, cfg2); DPT.reset(DP1); index= CCorePlugin.getIndexManager().getIndex(cproject); @@ -385,7 +392,7 @@ public class IndexProviderManagerTest extends IndexTestBase { } } } - + public void testGetProvidedFragments() throws Exception { ICProject cproject= CProjectHelper.createCProject("IndexProviderManagerTest", "bin", IPDOMManager.ID_NO_INDEXER); @@ -492,20 +499,20 @@ public class IndexProviderManagerTest extends IndexTestBase { } } } - + private ICConfigurationDescription newCfg(ICProjectDescription des, String project, String config) throws CoreException { CDefaultConfigurationData data= new CDefaultConfigurationData(project+"."+config, project+" "+config+" name", null); data.initEmptyData(); - return des.createConfiguration(CCorePlugin.DEFAULT_PROVIDER_ID, data); + return des.createConfiguration(CCorePlugin.DEFAULT_PROVIDER_ID, data); } - + private void changeActiveConfiguration(IProject project, ICConfigurationDescription cfg) throws CoreException { ICProjectDescription pd= core.getProjectDescription(project); pd.setActiveConfiguration(pd.getConfigurationById(cfg.getId())); core.setProjectDescription(project, pd); CCorePlugin.getIndexManager().joinIndexer(8000, npm()); } - + private void changeConfigRelations(IProject project, int option) throws CoreException { ICProjectDescription pd= core.getProjectDescription(project); pd.setConfigurationRelations(option); @@ -521,6 +528,7 @@ class MockStateIndexProvider implements IIndexProvider { this.targetProject = cproject; } + @Override public boolean providesFor(ICProject cproject) throws CoreException { return this.targetProject.equals(cproject); } @@ -529,7 +537,7 @@ class MockStateIndexProvider implements IIndexProvider { class MockStateIndexFragmentProvider extends MockStateIndexProvider implements IIndexFragmentProvider { private boolean invert; final IIndexFragment[] fragments; - + public void invert() { invert = !invert; } @@ -543,6 +551,7 @@ class MockStateIndexFragmentProvider extends MockStateIndexProvider implements I } } + @Override public IIndexFragment[] getIndexFragments(ICConfigurationDescription config) throws CoreException { int index = MockState.states.indexOf(config.getId()); index = invert ? (fragments.length-1)-index : index; @@ -565,152 +574,201 @@ class MockConfig implements ICConfigurationDescription { this.project= project; } + @Override public String getId() { return id; } + @Override public ICConfigExtensionReference create(String extensionPoint, String extension) throws CoreException { return null; } + @Override public ICExternalSetting createExternalSetting(String[] languageIDs, String[] contentTypeIds, String[] extensions, ICSettingEntry[] entries) throws WriteAccessException { return null; } + @Override public ICFileDescription createFileDescription(IPath path, ICResourceDescription base) throws CoreException, WriteAccessException { return null; } + @Override public ICFolderDescription createFolderDescription(IPath path, ICFolderDescription base) throws CoreException, WriteAccessException { return null; } + @Override public ICConfigExtensionReference[] get(String extensionPointID) { return null; } + @Override public ICBuildSetting getBuildSetting() { return null; } + @Override public String getBuildSystemId() { return null; } + @Override public ICdtVariablesContributor getBuildVariablesContributor() { return null; } + @Override public CConfigurationData getConfigurationData() { return null; } + @Override public String getDescription() { return null; } + @Override public ICExternalSetting[] getExternalSettings() { return null; } + @Override public ICFileDescription[] getFileDescriptions() { return null; } + @Override public ICFolderDescription[] getFolderDescriptions() { return null; } + @Override public ICProjectDescription getProjectDescription() { return CoreModel.getDefault().getProjectDescription(project); } + @Override public Map getReferenceInfo() { return null; } + @Override public ICResourceDescription getResourceDescription(IPath path, boolean exactPath) { return null; } + @Override public ICResourceDescription[] getResourceDescriptions() { return null; } + @Override public ICFolderDescription getRootFolderDescription() {return null;} + @Override public Object getSessionProperty(QualifiedName name) {return null;} + @Override public ICSourceEntry[] getSourceEntries() {return null;} + @Override public ICTargetPlatformSetting getTargetPlatformSetting() {return null;} + @Override public boolean isActive() {return false;} + @Override public boolean isModified() {return false;} + @Override public boolean isPreferenceConfiguration() {return false;} + @Override public void remove(ICConfigExtensionReference ext) throws CoreException {} + @Override public void remove(String extensionPoint) throws CoreException {} + @Override public void removeExternalSetting(ICExternalSetting setting) throws WriteAccessException {} + @Override public void removeExternalSettings() throws WriteAccessException {} + @Override public void removeResourceDescription(ICResourceDescription des) throws CoreException, WriteAccessException {} + @Override public void setActive() throws WriteAccessException {} + @Override public void setConfigurationData(String buildSystemId, CConfigurationData data) throws WriteAccessException {} + @Override public void setDescription(String des) throws WriteAccessException {} + @Override public void setName(String name) throws WriteAccessException {} + @Override public void setReferenceInfo(Map refs) throws WriteAccessException {} + @Override public void setSessionProperty(QualifiedName name, Object value) {} + @Override public void setSourceEntries(ICSourceEntry[] entries) throws CoreException, WriteAccessException {} + @Override public ICSettingObject[] getChildSettings() {return null;} + @Override public ICConfigurationDescription getConfiguration() {return null;} + @Override public String getName() {return null;} + @Override public ICSettingContainer getParent() {return null;} + @Override public int getType() {return 0;} + @Override public boolean isReadOnly() {return false;} + @Override public boolean isValid() {return false;} + @Override public ICStorageElement getStorage(String id, boolean create) throws CoreException { return null; } + @Override public ICStorageElement importStorage(String id, ICStorageElement storage) { return null; } + @Override public void removeStorage(String id) throws CoreException { } + @Override public ICLanguageSetting getLanguageSettingForFile(IPath path, boolean ignoreExludeStatus) { return null; } + @Override public String[] getExternalSettingsProviderIds() { return null; } + @Override public void setExternalSettingsProviderIds(String[] ids) {} + @Override public void updateExternalSettingsProviders(String[] ids) {} + @Override public ICSourceEntry[] getResolvedSourceEntries() { return null; } + @Override public CConfigurationStatus getConfigurationStatus() { return CConfigurationStatus.CFG_STATUS_OK; } + @Override public void setReadOnly(boolean readOnly, boolean keepModify) {} - public void setLanguageSettingProviders(List providers) {} - - public List getLanguageSettingProviders() { - return null; - } } /* @@ -743,12 +801,12 @@ class MockState { class MockPDOM extends EmptyIndexFragment { String id; String version; - + MockPDOM(String id, String version) { this.id= id; this.version= version; } - + @Override public String getProperty(String propertyName) throws CoreException { if(IIndexFragment.PROPERTY_FRAGMENT_ID.equals(propertyName)) { @@ -762,7 +820,7 @@ class MockPDOM extends EmptyIndexFragment { } return null; } - + @Override public String toString() { return "[Mock index fragment "+id+"."+System.identityHashCode(this)+"]"; diff --git a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/CModelMock.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/CModelMock.java index 95ebf29149c..4b463573366 100644 --- a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/CModelMock.java +++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/CModelMock.java @@ -11,11 +11,9 @@ package org.eclipse.cdt.core.testplugin; -import java.util.List; import java.util.Map; import org.eclipse.cdt.core.cdtvariables.ICdtVariablesContributor; -import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.settings.model.CConfigurationStatus; import org.eclipse.cdt.core.settings.model.ICBuildSetting; import org.eclipse.cdt.core.settings.model.ICConfigExtensionReference; @@ -48,136 +46,169 @@ public class CModelMock { */ public static class DummyCProjectDescription implements ICProjectDescription { + @Override public ICSettingObject[] getChildSettings() { return null; } + @Override public String getId() { return null; } + @Override public String getName() { return null; } + @Override public int getType() { return 0; } + @Override public boolean isValid() { return false; } + @Override public ICConfigurationDescription getConfiguration() { return null; } + @Override public ICSettingContainer getParent() { return null; } + @Override public boolean isReadOnly() { return false; } + @Override public ICStorageElement getStorage(String id, boolean create) throws CoreException { return null; } + @Override public void removeStorage(String id) throws CoreException { } + @Override public ICStorageElement importStorage(String id, ICStorageElement el) throws UnsupportedOperationException, CoreException { return null; } + @Override public void setReadOnly(boolean readOnly, boolean keepModify) { } + @Override public int getConfigurationRelations() { return 0; } + @Override public void setConfigurationRelations(int status) { } + @Override public void useDefaultConfigurationRelations() { } + @Override public boolean isDefaultConfigurationRelations() { return false; } + @Override public ICConfigurationDescription[] getConfigurations() { return null; } + @Override public ICConfigurationDescription getActiveConfiguration() { return null; } + @Override public void setActiveConfiguration(ICConfigurationDescription cfg) throws WriteAccessException { } + @Override public ICConfigurationDescription createConfiguration(String id, String name, ICConfigurationDescription base) throws CoreException, WriteAccessException { return null; } + @Override public ICConfigurationDescription createConfiguration( String buildSystemId, CConfigurationData data) throws CoreException, WriteAccessException { return null; } + @Override public ICConfigurationDescription getConfigurationByName(String name) { return null; } + @Override public ICConfigurationDescription getConfigurationById(String id) { return null; } + @Override public void removeConfiguration(String name) throws WriteAccessException { } + @Override public void removeConfiguration(ICConfigurationDescription cfg) throws WriteAccessException { } + @Override public IProject getProject() { return null; } + @Override public boolean isModified() { return false; } + @Override public Object getSessionProperty(QualifiedName name) { return null; } + @Override public void setSessionProperty(QualifiedName name, Object value) { } + @Override public ICConfigurationDescription getDefaultSettingConfiguration() { return null; } + @Override public void setDefaultSettingConfiguration( ICConfigurationDescription cfg) { } + @Override public boolean isCdtProjectCreating() { return false; } + @Override public void setCdtProjectCreated() { } @@ -195,222 +226,269 @@ public class CModelMock { this.id = id; } + @Override public ICSettingObject[] getChildSettings() { return null; } + @Override public String getId() { return id; } + @Override public String getName() { return null; } + @Override public int getType() { return 0; } + @Override public boolean isValid() { return false; } + @Override public ICConfigurationDescription getConfiguration() { return null; } + @Override public ICSettingContainer getParent() { return null; } + @Override public boolean isReadOnly() { return false; } + @Override public ICStorageElement getStorage(String id, boolean create) throws CoreException { return null; } + @Override public void removeStorage(String id) throws CoreException { } + @Override public ICStorageElement importStorage(String id, ICStorageElement el) throws UnsupportedOperationException, CoreException { return null; } + @Override public void setReadOnly(boolean readOnly, boolean keepModify) { } + @Override public boolean isActive() { return false; } + @Override public String getDescription() { return null; } + @Override public void setDescription(String des) throws WriteAccessException { } + @Override public ICProjectDescription getProjectDescription() { return null; } + @Override public ICFolderDescription getRootFolderDescription() { return null; } + @Override public ICFolderDescription[] getFolderDescriptions() { return null; } + @Override public ICFileDescription[] getFileDescriptions() { return null; } + @Override public ICResourceDescription[] getResourceDescriptions() { return null; } + @Override public ICResourceDescription getResourceDescription(IPath path, boolean exactPath) { return null; } + @Override public void removeResourceDescription(ICResourceDescription des) throws CoreException, WriteAccessException { } + @Override public ICFileDescription createFileDescription(IPath path, ICResourceDescription base) throws CoreException, WriteAccessException { return null; } + @Override public ICFolderDescription createFolderDescription(IPath path, ICFolderDescription base) throws CoreException, WriteAccessException { return null; } + @Override public String getBuildSystemId() { return null; } + @Override public CConfigurationData getConfigurationData() { return null; } + @Override public void setActive() throws WriteAccessException { } + @Override public void setConfigurationData(String buildSystemId, CConfigurationData data) throws WriteAccessException { } + @Override public boolean isModified() { return false; } + @Override public ICTargetPlatformSetting getTargetPlatformSetting() { return null; } + @Override public ICSourceEntry[] getSourceEntries() { return null; } + @Override public ICSourceEntry[] getResolvedSourceEntries() { return null; } + @Override public void setSourceEntries(ICSourceEntry[] entries) throws CoreException, WriteAccessException { } + @Override public Map getReferenceInfo() { return null; } + @Override public void setReferenceInfo(Map refs) throws WriteAccessException { } + @Override public ICExternalSetting[] getExternalSettings() { return null; } + @Override public ICExternalSetting createExternalSetting(String[] languageIDs, String[] contentTypeIds, String[] extensions, ICSettingEntry[] entries) throws WriteAccessException { return null; } + @Override public void removeExternalSetting(ICExternalSetting setting) throws WriteAccessException { } + @Override public void removeExternalSettings() throws WriteAccessException { } + @Override public ICBuildSetting getBuildSetting() { return null; } + @Override public ICdtVariablesContributor getBuildVariablesContributor() { return null; } + @Override public Object getSessionProperty(QualifiedName name) { return null; } + @Override public void setSessionProperty(QualifiedName name, Object value) { } + @Override public void setName(String name) throws WriteAccessException { } + @Override public ICConfigExtensionReference[] get(String extensionPointID) { return null; } + @Override public ICConfigExtensionReference create(String extensionPoint, String extension) throws CoreException { return null; } + @Override public void remove(ICConfigExtensionReference ext) throws CoreException { } + @Override public void remove(String extensionPoint) throws CoreException { } + @Override public boolean isPreferenceConfiguration() { return false; } + @Override public ICLanguageSetting getLanguageSettingForFile(IPath path, boolean ignoreExludeStatus) { return null; } + @Override public void setExternalSettingsProviderIds(String[] ids) { } + @Override public String[] getExternalSettingsProviderIds() { return null; } + @Override public void updateExternalSettingsProviders(String[] ids) throws WriteAccessException { } + @Override public CConfigurationStatus getConfigurationStatus() { return null; } - public void setLanguageSettingProviders(List providers) { - } - - public List getLanguageSettingProviders() { - return null; - } - } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsProvidersKeeper.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsProvidersKeeper.java new file mode 100644 index 00000000000..76c2e28c72c --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsProvidersKeeper.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2011, 2011 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.core.language.settings.providers; + +import java.util.List; + +import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; +/** + * Interface to express ability (of a configuration description) to handle Language Settings + * Providers. + * @see ILanguageSettingsProvider + * + */ +public interface ILanguageSettingsProvidersKeeper { + /** + * Sets the list of language settings providers. Language settings providers are + * used to supply language settings {@link ICLanguageSettingEntry} such as include paths + * or preprocessor macros. + * + * @param providers the list of providers to assign to the owner (configuration description). + * This method clones the internal list or otherwise ensures immutability of the internal + * list before actual addition to the project model. + * That is due to TODO - very important reason but I forgot why by now. + */ + public void setLanguageSettingProviders(List providers); + + /** + * Returns the list of language settings providers. Language settings providers are + * used to supply language settings {@link ICLanguageSettingEntry} such as include paths + * or preprocessor macros. + * + * @return the list of providers to assign to the owner (configuration description). This + * returns immutable list. Use {@link #setLanguageSettingProviders(List)} to change. + * This method does not return {@code null}. + */ + public List getLanguageSettingProviders(); + +} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager_TBD.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager_TBD.java index d0ea6724b89..c8464960d7c 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager_TBD.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager_TBD.java @@ -21,23 +21,26 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; /** - * This temporary class keeps the utility methods being looking for better home + * This temporary class keeps the utility methods being looking for better home. + * Checking if any Language Settings Provider has custom entries for the resource. */ public class LanguageSettingsManager_TBD { public static boolean isCustomizedResource(ICConfigurationDescription cfgDescription, IResource rc) { if (rc instanceof IProject) return false; - for (ILanguageSettingsProvider provider: cfgDescription.getLanguageSettingProviders()) { - if (provider instanceof ILanguageSettingsBroadcastingProvider) { - for (String languageId : LanguageSettingsManager.getLanguages(rc, cfgDescription)) { - List list = provider.getSettingEntries(cfgDescription, rc, languageId); - if (list!=null) { - // TODO - check default or check parent? - List listDefault = provider.getSettingEntries(null, null, languageId); - // != is OK here due as the equal lists will have the same reference in WeakHashSet - if (list != listDefault) - return true; + if (cfgDescription instanceof ILanguageSettingsProvidersKeeper) { + for (ILanguageSettingsProvider provider: ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders()) { + if (provider instanceof ILanguageSettingsBroadcastingProvider) { + for (String languageId : LanguageSettingsManager.getLanguages(rc, cfgDescription)) { + List list = provider.getSettingEntries(cfgDescription, rc, languageId); + if (list!=null) { + // TODO - check default or check parent? + List listDefault = provider.getSettingEntries(null, null, languageId); + // != is OK here due as the equal lists will have the same reference in WeakHashSet + if (list != listDefault) + return true; + } } } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ScannerDiscoveryLegacySupport.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ScannerDiscoveryLegacySupport.java index be5c8f611cc..610db25b207 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ScannerDiscoveryLegacySupport.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ScannerDiscoveryLegacySupport.java @@ -86,10 +86,12 @@ public class ScannerDiscoveryLegacySupport { * which is not intended to be referenced by clients. */ public static boolean isMbsLanguageSettingsProviderOn(ICConfigurationDescription cfgDescription) { - List lsProviders = cfgDescription.getLanguageSettingProviders(); - for (ILanguageSettingsProvider lsp : lsProviders) { - if (MBS_LANGUAGE_SETTINGS_PROVIDER.equals(lsp.getId())) { - return true; + if (cfgDescription instanceof ILanguageSettingsProvidersKeeper) { + List lsProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); + for (ILanguageSettingsProvider lsp : lsProviders) { + if (MBS_LANGUAGE_SETTINGS_PROVIDER.equals(lsp.getId())) { + return true; + } } } return false; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICConfigurationDescription.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICConfigurationDescription.java index 8ca2a43140e..eac75d44021 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICConfigurationDescription.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICConfigurationDescription.java @@ -10,11 +10,9 @@ *******************************************************************************/ package org.eclipse.cdt.core.settings.model; -import java.util.List; import java.util.Map; import org.eclipse.cdt.core.cdtvariables.ICdtVariablesContributor; -import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.settings.model.extension.CConfigurationData; import org.eclipse.cdt.core.settings.model.extension.CConfigurationDataProvider; @@ -389,31 +387,4 @@ public interface ICConfigurationDescription extends ICSettingContainer, ICSettin void updateExternalSettingsProviders(String[] ids) throws WriteAccessException; CConfigurationStatus getConfigurationStatus(); - - /** - * Sets the list of language settings providers. Language settings providers are - * used to supply language settings {@link ICLanguageSettingEntry} such as include paths - * or preprocessor macros. - * - * @param providers the list of providers to assign to the configuration description. - * Warning: the providers will be cloned before actual addition to the project model - * due to TODO - very important reason but I forgot why by now. - * - * @since 6.0 - */ - public void setLanguageSettingProviders(List providers); - - /** - * Returns the list of language settings providers. Language settings providers are - * used to supply language settings {@link ICLanguageSettingEntry} such as include paths - * or preprocessor macros. - * - * @return the list of providers to assign to the configuration description. This - * returns immutable list. Use {@link #setLanguageSettingProviders(List)} to change. - * This method does not return {@code null}. - * - * @since 6.0 - */ - public List getLanguageSettingProviders(); - } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java index 864229a31f2..ae19d072285 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java @@ -23,6 +23,7 @@ import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsChangeE import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsChangeListener; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsEditableProvider; 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.LanguageSettingsSerializableProvider; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsStorage; @@ -358,13 +359,15 @@ projects: if (prjDescription != null) { ICConfigurationDescription[] cfgDescriptions = prjDescription.getConfigurations(); for (ICConfigurationDescription cfgDescription : cfgDescriptions) { - for (ILanguageSettingsProvider provider : cfgDescription.getLanguageSettingProviders()) { - if (isWorkspaceProvider(provider) && serializableIds.contains(provider.getId())) { - LanguageSettingsChangeEvent event = new LanguageSettingsChangeEvent(prjDescription); - if (event.getConfigurationDescriptionIds().length > 0) { - events.add(event); + if (cfgDescription instanceof ILanguageSettingsProvidersKeeper) { + for (ILanguageSettingsProvider provider : ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders()) { + if (isWorkspaceProvider(provider) && serializableIds.contains(provider.getId())) { + LanguageSettingsChangeEvent event = new LanguageSettingsChangeEvent(prjDescription); + if (event.getConfigurationDescriptionIds().length > 0) { + events.add(event); + } + continue projects; } - continue projects; } } } @@ -485,12 +488,15 @@ projects: ICConfigurationDescription[] cfgDescriptions = prjDescription.getConfigurations(); for (ICConfigurationDescription cfgDescription : cfgDescriptions) { + if (!(cfgDescription instanceof ILanguageSettingsProvidersKeeper)) + continue; + Element elementConfiguration = XmlUtil.appendElement(projectElementPrjStore, ELEM_CONFIGURATION, new String[] { LanguageSettingsExtensionManager.ATTR_ID, cfgDescription.getId(), LanguageSettingsExtensionManager.ATTR_NAME, cfgDescription.getName(), }); Element elementConfigurationWsp = null; - List providers = cfgDescription.getLanguageSettingProviders(); + List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); if (providers.size()>0) { Element elementExtension = XmlUtil.appendElement(elementConfiguration, ELEM_EXTENSION, new String[] { ATTR_POINT, LanguageSettingsExtensionManager.PROVIDER_EXTENSION_FULL_ID}); @@ -656,8 +662,8 @@ projects: } ICConfigurationDescription cfgDescription = prjDescription.getConfigurationById(cfgId); - if (cfgDescription!=null) { - cfgDescription.setLanguageSettingProviders(providers); + if (cfgDescription instanceof ILanguageSettingsProvidersKeeper) { + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); if (cfgDescription instanceof IInternalCCfgInfo) { try { ((IInternalCCfgInfo) cfgDescription).getSpecSettings().dropDelta(); @@ -773,11 +779,11 @@ projects: // Already existing legacy projects ICConfigurationDescription[] cfgDescriptions = prjDescription.getConfigurations(); for (ICConfigurationDescription cfgDescription : cfgDescriptions) { - if (cfgDescription!=null) { + if (cfgDescription instanceof ILanguageSettingsProvidersKeeper) { List providers = new ArrayList(2); ILanguageSettingsProvider providerMBS = getWorkspaceProvider(ScannerDiscoveryLegacySupport.MBS_LANGUAGE_SETTINGS_PROVIDER); providers.add(providerMBS); - cfgDescription.setLanguageSettingProviders(providers); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); } } @@ -840,17 +846,19 @@ projects: if (prjDescription != null) { List prjProviders = new ArrayList(); for (ICConfigurationDescription cfgDescription : prjDescription.getConfigurations()) { - List providers = cfgDescription.getLanguageSettingProviders(); - for (ILanguageSettingsProvider provider : providers) { - if (!LanguageSettingsManager.isWorkspaceProvider(provider)) { - if (isObjectInTheList(prjProviders, provider)) { - IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "Inconsistent state, duplicate LSP in project description " - + "[" + System.identityHashCode(provider) + "] " - + provider); - CoreException e = new CoreException(status); - CCorePlugin.log(e); + if (cfgDescription instanceof ILanguageSettingsProvidersKeeper) { + List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); + for (ILanguageSettingsProvider provider : providers) { + if (!LanguageSettingsManager.isWorkspaceProvider(provider)) { + if (isObjectInTheList(prjProviders, provider)) { + IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "Inconsistent state, duplicate LSP in project description " + + "[" + System.identityHashCode(provider) + "] " + + provider); + CoreException e = new CoreException(status); + CCorePlugin.log(e); + } + prjProviders.add(provider); } - prjProviders.add(provider); } } } @@ -883,12 +891,14 @@ projects: List listeners = new ArrayList(); if (prjDescription != null) { for (ICConfigurationDescription cfgDescription : prjDescription.getConfigurations()) { - List providers = cfgDescription.getLanguageSettingProviders(); - for (ILanguageSettingsProvider provider : providers) { - if (provider instanceof ICListenerAgent) { - ICListenerAgent listener = (ICListenerAgent) provider; - if (!isObjectInTheList(listeners, listener)) { - listeners.add(listener); + if (cfgDescription instanceof ILanguageSettingsProvidersKeeper) { + List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); + for (ILanguageSettingsProvider provider : providers) { + if (provider instanceof ICListenerAgent) { + ICListenerAgent listener = (ICListenerAgent) provider; + if (!isObjectInTheList(listeners, listener)) { + listeners.add(listener); + } } } } @@ -914,11 +924,13 @@ projects: List associations = new ArrayList(); if (prjDescription != null) { for (ICConfigurationDescription cfgDescription : prjDescription.getConfigurations()) { - List providers = cfgDescription.getLanguageSettingProviders(); - List listeners = selectListeners(providers); - for (ICListenerAgent listener : listeners) { - if (!isListenerInTheListOfAssociations(associations, listener)) { - associations.add(new ListenerAssociation(listener, cfgDescription)); + if (cfgDescription instanceof ILanguageSettingsProvidersKeeper) { + List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); + List listeners = selectListeners(providers); + for (ICListenerAgent listener : listeners) { + if (!isListenerInTheListOfAssociations(associations, listener)) { + associations.add(new ListenerAssociation(listener, cfgDescription)); + } } } } @@ -1210,10 +1222,14 @@ projects: private static List getSettingEntriesByKind(ICConfigurationDescription cfgDescription, IResource rc, String languageId, int kind, boolean checkLocality, boolean isLocal) { + if (!(cfgDescription instanceof ILanguageSettingsProvidersKeeper)) { + return null; + } + List entries = new ArrayList(); List alreadyAdded = new ArrayList(); - List providers = cfgDescription.getLanguageSettingProviders(); + List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); for (ILanguageSettingsProvider provider: providers) { List providerEntries = getSettingEntriesUpResourceTree(provider, cfgDescription, rc, languageId); for (ICLanguageSettingEntry entry : providerEntries) { diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationDescription.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationDescription.java index a068d9a0d39..771eb1280de 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationDescription.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationDescription.java @@ -19,6 +19,7 @@ import java.util.Map; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.cdtvariables.ICdtVariablesContributor; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvidersKeeper; import org.eclipse.cdt.core.settings.model.CConfigurationStatus; import org.eclipse.cdt.core.settings.model.ICBuildSetting; import org.eclipse.cdt.core.settings.model.ICConfigExtensionReference; @@ -51,7 +52,8 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.QualifiedName; -public class CConfigurationDescription extends CDataProxyContainer implements ICConfigurationDescription, IProxyFactory, IInternalCCfgInfo { +public class CConfigurationDescription extends CDataProxyContainer + implements ICConfigurationDescription, IProxyFactory, IInternalCCfgInfo, ILanguageSettingsProvidersKeeper { private CfgProxyCache fCache; // private ProxyProvider fFileProxyProvider; // private ProxyProvider fFolderProxyProvider; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationDescriptionCache.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationDescriptionCache.java index a58a4e717c0..42087ea7220 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationDescriptionCache.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationDescriptionCache.java @@ -17,6 +17,7 @@ import java.util.Map; import org.eclipse.cdt.core.cdtvariables.ICdtVariable; import org.eclipse.cdt.core.cdtvariables.ICdtVariablesContributor; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvidersKeeper; import org.eclipse.cdt.core.settings.model.CConfigurationStatus; import org.eclipse.cdt.core.settings.model.ICBuildSetting; import org.eclipse.cdt.core.settings.model.ICConfigExtensionReference; @@ -77,7 +78,7 @@ import org.eclipse.core.runtime.QualifiedName; * reference fBaseDescription gets set to null. */ public class CConfigurationDescriptionCache extends CDefaultConfigurationData - implements ICConfigurationDescription, IInternalCCfgInfo, ICachedData { + implements ICConfigurationDescription, IInternalCCfgInfo, ILanguageSettingsProvidersKeeper, ICachedData { private CProjectDescription fParent; private PathSettingsContainer fPathSettingContainer = PathSettingsContainer.createRootContainer(); private ResourceDescriptionHolder fRcHolder = new ResourceDescriptionHolder(fPathSettingContainer, true); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CProjectDescriptionManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CProjectDescriptionManager.java index 231694eb3f9..f119f6bffa5 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CProjectDescriptionManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CProjectDescriptionManager.java @@ -51,6 +51,7 @@ import javax.xml.transform.stream.StreamResult; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvidersKeeper; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElementDelta; @@ -1571,9 +1572,13 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager { CCorePlugin.log(e); } - List newLSProviders = newCfg.getLanguageSettingProviders(); - List oldLSProviders = oldCfg.getLanguageSettingProviders(); - if(!newLSProviders.equals(oldLSProviders)) + List newLSProviders = null; + if (newCfg instanceof ILanguageSettingsProvidersKeeper) + newLSProviders = ((ILanguageSettingsProvidersKeeper) newCfg).getLanguageSettingProviders(); + List oldLSProviders = null; + if (oldCfg instanceof ILanguageSettingsProvidersKeeper) + oldLSProviders = ((ILanguageSettingsProvidersKeeper) oldCfg).getLanguageSettingProviders(); + if(newLSProviders != oldLSProviders && (newLSProviders == null || !newLSProviders.equals(oldLSProviders))) delta.addChangeFlags(ICDescriptionDelta.LANGUAGE_SETTINGS_PROVIDERS); calculateCfgExtSettingsDelta(delta); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/MultiConfigDescription.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/MultiConfigDescription.java index 939161cdf2e..653b0c662bd 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/MultiConfigDescription.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/MultiConfigDescription.java @@ -14,11 +14,9 @@ package org.eclipse.cdt.internal.core.settings.model; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.List; import java.util.Map; import org.eclipse.cdt.core.cdtvariables.ICdtVariablesContributor; -import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.settings.model.CConfigurationStatus; import org.eclipse.cdt.core.settings.model.ICBuildSetting; import org.eclipse.cdt.core.settings.model.ICConfigExtensionReference; @@ -639,17 +637,4 @@ public class MultiConfigDescription extends MultiItemsHolder implements fCfgs[i].removeStorage(id); } - @Override - public void setLanguageSettingProviders(List providers) { - if (DEBUG) - System.out.println("Bad multi access: MultiConfigDescription.setLanguageSettingProviders()"); //$NON-NLS-1$ - } - - @Override - public List getLanguageSettingProviders() { - if (DEBUG) - System.out.println("Bad multi access: MultiConfigDescription.getLanguageSettingProviders()"); //$NON-NLS-1$ - return null; - } - } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java index 4f01895a27f..183a6df53db 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java @@ -45,6 +45,7 @@ import org.eclipse.swt.widgets.TreeItem; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsBroadcastingProvider; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsEditableProvider; 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.LanguageSettingsBaseProvider; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySupport; @@ -391,9 +392,9 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { if (!page.isForPrefs()) { ICConfigurationDescription[] cfgDescriptions = page.getCfgsEditable(); for (ICConfigurationDescription cfgDescription : cfgDescriptions) { - if (cfgDescription!=null) { + if (cfgDescription instanceof ILanguageSettingsProvidersKeeper) { String cfgId = cfgDescription.getId(); - List initialProviders = cfgDescription.getLanguageSettingProviders(); + List initialProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); initialProvidersMap.put(cfgId, initialProviders); } } @@ -740,13 +741,13 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { ICConfigurationDescription cfgDescription = getConfigurationDescription(); List initialProviders = initialProvidersMap.get(cfgDescription.getId()); if (initialProviders.contains(selectedProvider)) { - List providers = new ArrayList(cfgDescription.getLanguageSettingProviders()); + List providers = new ArrayList(((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders()); int pos = providers.indexOf(selectedProvider); if (pos>=0) { try { selectedProvider = selectedProvider.clone(); providers.set(pos, selectedProvider); - cfgDescription.setLanguageSettingProviders(providers); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); } catch (CloneNotSupportedException e) { CUIPlugin.log("Internal Error: cannot clone provider "+selectedProvider.getId(), e); } @@ -858,8 +859,8 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { if (currentLanguageId!=null) { IResource rc = getResource(); ICConfigurationDescription cfgDescription = getConfigurationDescription(); - if (rc!=null && cfgDescription!=null) { - List cfgProviders = cfgDescription.getLanguageSettingProviders(); + if (rc != null && cfgDescription instanceof ILanguageSettingsProvidersKeeper) { + List cfgProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); for (ILanguageSettingsProvider cfgProvider : cfgProviders) { ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(cfgProvider); if (rawProvider instanceof LanguageSettingsBaseProvider) { @@ -958,10 +959,13 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { // However for the performance reasons for resource decorators where the same logic is used // we use null for resetting file/folder resource which should be correct in most cases. // Count that as a feature. - boolean changed = false; ICConfigurationDescription cfgDescription = getConfigurationDescription(); + if (!(cfgDescription instanceof ILanguageSettingsProvidersKeeper)) + return; + + boolean changed = false; IResource rc = getResource(); - List oldProviders = cfgDescription.getLanguageSettingProviders(); + List oldProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); List newProviders = new ArrayList(oldProviders.size()); providers: for (ILanguageSettingsProvider provider : oldProviders) { @@ -992,7 +996,7 @@ providers: for (ILanguageSettingsProvider provider : oldProviders) { newProviders.add(provider); } if (changed) { - cfgDescription.setLanguageSettingProviders(newProviders); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(newProviders); // updateTreeEntries(); // updateData(getResDesc()); List tableItems = getProviders(currentLanguageId); @@ -1007,15 +1011,20 @@ providers: for (ILanguageSettingsProvider provider : oldProviders) { ICConfigurationDescription srcCfgDescription = srcRcDescription.getConfiguration(); ICConfigurationDescription destCfgDescription = destRcDescription.getConfiguration(); - List providers = srcCfgDescription.getLanguageSettingProviders(); - destCfgDescription.setLanguageSettingProviders(providers); + if (srcCfgDescription instanceof ILanguageSettingsProvidersKeeper + && destCfgDescription instanceof ILanguageSettingsProvidersKeeper) { + List providers = ((ILanguageSettingsProvidersKeeper) srcCfgDescription).getLanguageSettingProviders(); + ((ILanguageSettingsProvidersKeeper) destCfgDescription).setLanguageSettingProviders(providers); + } } if (!page.isForPrefs()) { ICConfigurationDescription sd = srcRcDescription.getConfiguration(); ICConfigurationDescription dd = destRcDescription.getConfiguration(); - List newProviders = sd.getLanguageSettingProviders(); - dd.setLanguageSettingProviders(newProviders); + if (sd instanceof ILanguageSettingsProvidersKeeper && dd instanceof ILanguageSettingsProvidersKeeper) { + List newProviders = ((ILanguageSettingsProvidersKeeper) sd).getLanguageSettingProviders(); + ((ILanguageSettingsProvidersKeeper) dd).setLanguageSettingProviders(newProviders); + } } performOK(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java index 99f0614f3b5..380a24ff353 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java @@ -47,6 +47,7 @@ import org.eclipse.ui.dialogs.PreferencesUtil; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsEditableProvider; 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_TBD; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializableProvider; @@ -195,8 +196,8 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { return null; ICConfigurationDescription cfgDescription = getResDesc().getConfiguration(); - return cfgDescription; - } + return cfgDescription; + } /** * Shortcut for getting the currently selected provider. @@ -216,9 +217,9 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { if (page.isForProject()) { ICConfigurationDescription[] cfgDescriptions = page.getCfgsEditable(); for (ICConfigurationDescription cfgDescription : cfgDescriptions) { - if (cfgDescription!=null) { + if (cfgDescription instanceof ILanguageSettingsProvidersKeeper) { String cfgId = cfgDescription.getId(); - List initialProviders = cfgDescription.getLanguageSettingProviders(); + List initialProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); initialProvidersByCfg.put(cfgId, initialProviders); } } @@ -371,11 +372,13 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { if (!page.isForPrefs()) { cfgDescription = getConfigurationDescription(); - List cfgProviders = new ArrayList(cfgDescription.getLanguageSettingProviders()); - pos = getProviderIndex(newProvider.getId(), cfgProviders); - cfgProviders.set(pos, newProvider); - cfgDescription.setLanguageSettingProviders(cfgProviders); - tableProvidersViewer.setCheckedElements(cfgProviders.toArray(new ILanguageSettingsProvider[0])); + if (cfgDescription instanceof ILanguageSettingsProvidersKeeper) { + List cfgProviders = new ArrayList(((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders()); + pos = getProviderIndex(newProvider.getId(), cfgProviders); + cfgProviders.set(pos, newProvider); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(cfgProviders); + tableProvidersViewer.setCheckedElements(cfgProviders.toArray(new ILanguageSettingsProvider[0])); + } } refreshItem(newProvider); } @@ -479,8 +482,8 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { tableProviders.setSelection(pos); ICConfigurationDescription cfgDescription = getConfigurationDescription(); - if (cfgDescription!=null) { - List cfgProviders = cfgDescription.getLanguageSettingProviders(); + if (cfgDescription instanceof ILanguageSettingsProvidersKeeper) { + List cfgProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); tableProvidersViewer.setCheckedElements(cfgProviders.toArray(new ILanguageSettingsProvider[0])); } @@ -509,8 +512,8 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { List providers; ICConfigurationDescription cfgDescription = getConfigurationDescription(); - if (cfgDescription!=null) { - providers = new ArrayList(cfgDescription.getLanguageSettingProviders()); + if (cfgDescription instanceof ILanguageSettingsProvidersKeeper) { + providers = new ArrayList(((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders()); for (ILanguageSettingsProvider provider : providers) { idsList.add(provider.getId()); } @@ -640,14 +643,16 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { providers.add(provider); } ICConfigurationDescription cfgDescription = getConfigurationDescription(); - cfgDescription.setLanguageSettingProviders(providers); + if (cfgDescription instanceof ILanguageSettingsProvidersKeeper) { + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); - if (selectedElement!=null) { - tableProvidersViewer.update(selectedElement, null); - if (selectedElement instanceof ILanguageSettingsProvider) { - ILanguageSettingsProvider selectedProvider = (ILanguageSettingsProvider) selectedElement; - initializeOptionsPage(selectedProvider, cfgDescription); - displaySelectedOptionPage(); + if (selectedElement!=null) { + tableProvidersViewer.update(selectedElement, null); + if (selectedElement instanceof ILanguageSettingsProvider) { + ILanguageSettingsProvider selectedProvider = (ILanguageSettingsProvider) selectedElement; + initializeOptionsPage(selectedProvider, cfgDescription); + displaySelectedOptionPage(); + } } } } @@ -865,18 +870,20 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { if (page.isForProject()) { ICConfigurationDescription cfgDescription = getConfigurationDescription(); - List cfgProviders = new ArrayList(cfgDescription.getLanguageSettingProviders()); - boolean atLeastOneChanged = false; - for (int i=0;i cfgProviders = new ArrayList(((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders()); + boolean atLeastOneChanged = false; + for (int i=0;i destProviders = new ArrayList(); + if (srcCfgDescription instanceof ILanguageSettingsProvidersKeeper + && destCfgDescription instanceof ILanguageSettingsProvidersKeeper) { - List srcProviders = srcCfgDescription.getLanguageSettingProviders(); - for (ILanguageSettingsProvider pro : srcProviders) { - // TODO: clone - destProviders.add(pro); + List destProviders = new ArrayList(); + List srcProviders = ((ILanguageSettingsProvidersKeeper) srcCfgDescription).getLanguageSettingProviders(); + for (ILanguageSettingsProvider pro : srcProviders) { + // TODO: clone + destProviders.add(pro); + } + ((ILanguageSettingsProvidersKeeper) destCfgDescription).setLanguageSettingProviders(destProviders); } - - destCfgDescription.setLanguageSettingProviders(destProviders); } if (!page.isForPrefs()) { ICConfigurationDescription sd = srcRcDescription.getConfiguration(); ICConfigurationDescription dd = destRcDescription.getConfiguration(); - List newProviders = sd.getLanguageSettingProviders(); - dd.setLanguageSettingProviders(newProviders); + if (sd instanceof ILanguageSettingsProvidersKeeper && dd instanceof ILanguageSettingsProvidersKeeper) { + List newProviders = ((ILanguageSettingsProvidersKeeper) sd).getLanguageSettingProviders(); + ((ILanguageSettingsProvidersKeeper) dd).setLanguageSettingProviders(newProviders); + } } performOK(); @@ -942,14 +953,15 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { ICResourceDescription rcDesc = getResDesc(); IResource rc = getResource(); ICConfigurationDescription cfgDescription = rcDesc.getConfiguration(); - - List destProviders = new ArrayList(); - List providers = cfgDescription.getLanguageSettingProviders(); - for (ILanguageSettingsProvider pro : providers) { - // TODO: clone - destProviders.add(pro); + if (cfgDescription instanceof ILanguageSettingsProvidersKeeper) { + List destProviders = new ArrayList(); + List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); + for (ILanguageSettingsProvider pro : providers) { + // TODO: clone + destProviders.add(pro); + } + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(destProviders); } - cfgDescription.setLanguageSettingProviders(destProviders); } // Build Settings page From 9a66dd7b79f2d352a987a0be42f503463f3ea95c Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Mon, 5 Dec 2011 14:13:16 -0500 Subject: [PATCH 077/120] Generalize properties for LanguageSettingsSerializableProvider, keep storeEntriesInProjectArea attribute in there --- ...nguageSettingsPersistenceProjectTests.java | 22 ++--- .../LanguageSettingsSerializableTests.java | 59 +++++++----- .../providers/LanguageSettingsManager.java | 23 +++++ .../LanguageSettingsSerializableProvider.java | 92 +++++++++++-------- .../LanguageSettingsProvidersSerializer.java | 33 ++++++- .../LanguageSettingsProviderTab.java | 6 +- 6 files changed, 158 insertions(+), 77 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java index 1e95c8d6f4b..6b994c49e4c 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java @@ -239,7 +239,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { // create a provider LanguageSettingsSerializableProvider mockProvider = new MockLanguageSettingsEditableProvider(PROVIDER_0, PROVIDER_NAME_0); - mockProvider.setStoringEntriesInProjectArea(true); + LanguageSettingsManager.setStoringEntriesInProjectArea(mockProvider, true); mockProvider.setSettingEntries(cfgDescription, null, null, entries); List providers = new ArrayList(); providers.add(mockProvider); @@ -450,7 +450,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { LanguageSettingsSerializableProvider serializableProvider = new LanguageSettingsSerializableProvider(PROVIDER_0, PROVIDER_NAME_0); serializableProvider.setSettingEntries(null, null, null, entries); - serializableProvider.setStoringEntriesInProjectArea(true); + LanguageSettingsManager.setStoringEntriesInProjectArea(serializableProvider, true); ArrayList providers = new ArrayList(); providers.add(serializableProvider); @@ -516,7 +516,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { assertEquals(CFG_ID, cfgDescription1.getId()); LanguageSettingsSerializableProvider provider1 = new LanguageSettingsSerializableProvider(PROVIDER_0, PROVIDER_NAME_0); - provider1.setStoringEntriesInProjectArea(true); + LanguageSettingsManager.setStoringEntriesInProjectArea(provider1, true); provider1.setSettingEntries(null, null, null, entries); ArrayList providers = new ArrayList(); providers.add(provider1); @@ -530,7 +530,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { assertEquals(CFG_ID_2, cfgDescription2.getId()); LanguageSettingsSerializableProvider provider2 = new LanguageSettingsSerializableProvider(PROVIDER_0, PROVIDER_NAME_0); - provider2.setStoringEntriesInProjectArea(true); + LanguageSettingsManager.setStoringEntriesInProjectArea(provider2, true); provider2.setSettingEntries(null, null, null, entries2); ArrayList providers = new ArrayList(); providers.add(provider2); @@ -646,7 +646,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { LanguageSettingsSerializableProvider serializableProvider = new MockLanguageSettingsSerializableProvider(PROVIDER_0, PROVIDER_NAME_0); serializableProvider.setSettingEntries(null, null, null, entries); - serializableProvider.setStoringEntriesInProjectArea(true); + LanguageSettingsManager.setStoringEntriesInProjectArea(serializableProvider, true); ArrayList providers = new ArrayList(); providers.add(serializableProvider); @@ -750,7 +750,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { // populate with provider overriding the extension (must be SerializableLanguageSettingsProvider or a class from another extension) MockLanguageSettingsSerializableProvider providerOverride = new MockLanguageSettingsSerializableProvider(idExt, PROVIDER_NAME_0); - providerOverride.setStoringEntriesInProjectArea(true); + LanguageSettingsManager.setStoringEntriesInProjectArea(providerOverride, true); List providers = new ArrayList(); providers.add(providerOverride); ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); @@ -817,11 +817,11 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { // 3. Providers defined in a configuration // 3.1 LanguageSettingsSerializableProvider mockProvider1 = new LanguageSettingsSerializableProvider(PROVIDER_0, PROVIDER_NAME_0); - mockProvider1.setStoringEntriesInProjectArea(true); + LanguageSettingsManager.setStoringEntriesInProjectArea(mockProvider1, true); mockProvider1.setSettingEntries(null, null, null, entries_31); // 3.2 LanguageSettingsSerializableProvider mockProvider2 = new MockLanguageSettingsSerializableProvider(PROVIDER_2, PROVIDER_NAME_2); - mockProvider2.setStoringEntriesInProjectArea(true); + LanguageSettingsManager.setStoringEntriesInProjectArea(mockProvider2, true); mockProvider2.setSettingEntries(null, null, null, entries_32); ArrayList providers = new ArrayList(); @@ -901,7 +901,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { // create a provider LanguageSettingsSerializableProvider mockProvider = new LanguageSettingsSerializableProvider(PROVIDER_0, PROVIDER_NAME_0); - mockProvider.setStoringEntriesInProjectArea(true); + LanguageSettingsManager.setStoringEntriesInProjectArea(mockProvider, true); mockProvider.setSettingEntries(cfgDescription, null, null, entries); List providers = new ArrayList(); providers.add(mockProvider); @@ -1042,7 +1042,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { LanguageSettingsSerializableProvider serializableProvider = new LanguageSettingsSerializableProvider(PROVIDER_0, PROVIDER_NAME_0); serializableProvider.setSettingEntries(null, null, null, entries); // do not store entries inside project - serializableProvider.setStoringEntriesInProjectArea(false); + LanguageSettingsManager.setStoringEntriesInProjectArea(serializableProvider, false); ArrayList providers = new ArrayList(); providers.add(serializableProvider); @@ -1115,7 +1115,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { // create a provider LanguageSettingsSerializableProvider mockProvider = new LanguageSettingsSerializableProvider(PROVIDER_0, PROVIDER_NAME_0); - mockProvider.setStoringEntriesInProjectArea(false); + LanguageSettingsManager.setStoringEntriesInProjectArea(mockProvider, false); mockProvider.setSettingEntries(cfgDescription, null, null, entries); List providers = new ArrayList(); providers.add(mockProvider); diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java index 53e28a72e2d..7b85ac4668d 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java @@ -116,9 +116,11 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { mockProvider.setCustomParameter(CUSTOM_PARAMETER); assertEquals(CUSTOM_PARAMETER, mockProvider.getCustomParameter()); - assertEquals(false, mockProvider.isStoringEntriesInProjectArea()); - mockProvider.setStoringEntriesInProjectArea(true); - assertEquals(true, mockProvider.isStoringEntriesInProjectArea()); + assertEquals(false, LanguageSettingsManager.isStoringEntriesInProjectArea(mockProvider)); + LanguageSettingsManager.setStoringEntriesInProjectArea(mockProvider, true); + assertEquals(true, LanguageSettingsManager.isStoringEntriesInProjectArea(mockProvider)); + LanguageSettingsManager.setStoringEntriesInProjectArea(mockProvider, false); + assertEquals(false, LanguageSettingsManager.isStoringEntriesInProjectArea(mockProvider)); mockProvider.setLanguageScope(languages); assertEquals(languages, mockProvider.getLanguageScope()); @@ -143,7 +145,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { { // create customized provider LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); - provider.setStoringEntriesInProjectArea(true); + LanguageSettingsManager.setStoringEntriesInProjectArea(provider, true); provider.setCustomParameter(CUSTOM_PARAMETER); List languageScope = new ArrayList(); @@ -170,7 +172,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { // re-load and check language settings of the newly loaded provider LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(elementProvider); assertEquals(PROVIDER_1, provider.getId()); - assertEquals(true, provider.isStoringEntriesInProjectArea()); + assertEquals(true, LanguageSettingsManager.isStoringEntriesInProjectArea(provider)); assertEquals(CUSTOM_PARAMETER, provider.getCustomParameter()); assertNotNull(provider.getLanguageScope()); assertTrue(provider.getLanguageScope().size()>0); @@ -190,7 +192,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { { // create customized provider LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); - provider.setStoringEntriesInProjectArea(true); + LanguageSettingsManager.setStoringEntriesInProjectArea(provider, true); provider.setCustomParameter(CUSTOM_PARAMETER); List languageScope = new ArrayList(); @@ -219,7 +221,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(); provider.loadAttributes(elementProvider); assertEquals(PROVIDER_1, provider.getId()); - assertEquals(true, provider.isStoringEntriesInProjectArea()); + assertEquals(true, LanguageSettingsManager.isStoringEntriesInProjectArea(provider)); assertEquals(CUSTOM_PARAMETER, provider.getCustomParameter()); assertNotNull(provider.getLanguageScope()); assertTrue(provider.getLanguageScope().size()>0); @@ -237,7 +239,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { { // create customized provider LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); - provider.setStoringEntriesInProjectArea(true); + LanguageSettingsManager.setStoringEntriesInProjectArea(provider, true); provider.setCustomParameter(CUSTOM_PARAMETER); List languageScope = new ArrayList(); @@ -271,7 +273,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { // no attributes should be loaded assertFalse(PROVIDER_1.equals(provider.getId())); assertFalse(PROVIDER_NAME_1.equals(provider.getName())); - assertFalse(true==provider.isStoringEntriesInProjectArea()); + assertFalse(true==LanguageSettingsManager.isStoringEntriesInProjectArea(provider)); assertFalse(CUSTOM_PARAMETER.equals(provider.getCustomParameter())); assertNull(provider.getLanguageScope()); // entries should be loaded @@ -337,11 +339,11 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { public void testStoreEntriesWithProjectDOM() throws Exception { Element elementProvider; { - // create provider with custom parameter + // create provider storing entries in project area LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); - assertEquals(false, provider.isStoringEntriesInProjectArea()); - provider.setStoringEntriesInProjectArea(true); - assertEquals(true, provider.isStoringEntriesInProjectArea()); + assertEquals(false, LanguageSettingsManager.isStoringEntriesInProjectArea(provider)); + LanguageSettingsManager.setStoringEntriesInProjectArea(provider, true); + assertEquals(true, LanguageSettingsManager.isStoringEntriesInProjectArea(provider)); Document doc = XmlUtil.newDocument(); Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST); @@ -351,9 +353,9 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { assertTrue(xmlString.contains(VALUE_PROJECT)); } { - // re-load and check custom parameter of the newly loaded provider + // re-load and check storing mode of the newly loaded provider LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(elementProvider); - assertEquals(true, provider.isStoringEntriesInProjectArea()); + assertEquals(true, LanguageSettingsManager.isStoringEntriesInProjectArea(provider)); } } @@ -1174,8 +1176,8 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { LanguageSettingsSerializableProvider provider1 = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); provider1.setLanguageScope(sampleLanguages); provider1.setCustomParameter(CUSTOM_PARAMETER); - assertEquals(false, provider1.isStoringEntriesInProjectArea()); - provider1.setStoringEntriesInProjectArea(true); + assertEquals(false, LanguageSettingsManager.isStoringEntriesInProjectArea(provider1)); + LanguageSettingsManager.setStoringEntriesInProjectArea(provider1, true); provider1.setSettingEntries(MOCK_CFG, MOCK_RC, LANG_ID, sampleEntries_1); provider1.setSettingEntries(null, null, LANG_ID, sampleEntries_2); @@ -1201,7 +1203,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { assertFalse(provider1.equals(provider2)); assertFalse(provider1.hashCode()==provider2.hashCode()); - provider2.setStoringEntriesInProjectArea(true); + LanguageSettingsManager.setStoringEntriesInProjectArea(provider2, true); // All set now, so they should be equal assertTrue(provider1.equals(provider2)); @@ -1251,8 +1253,8 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { MockSerializableProvider provider1 = new MockSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); provider1.setLanguageScope(sampleLanguages); provider1.setCustomParameter(CUSTOM_PARAMETER); - assertEquals(false, provider1.isStoringEntriesInProjectArea()); - provider1.setStoringEntriesInProjectArea(true); + assertEquals(false, LanguageSettingsManager.isStoringEntriesInProjectArea(provider1)); + LanguageSettingsManager.setStoringEntriesInProjectArea(provider1, true); provider1.setSettingEntries(MOCK_CFG, MOCK_RC, LANG_ID, sampleEntries_1); provider1.setSettingEntries(null, null, LANG_ID, sampleEntries_2); @@ -1261,8 +1263,17 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { assertNotSame(provider1, providerClone); assertTrue(provider1.equals(providerClone)); assertTrue(provider1.getClass()==providerClone.getClass()); + assertEquals(provider1.getCustomParameter(), providerClone.getCustomParameter()); - assertEquals(provider1.isStoringEntriesInProjectArea(), providerClone.isStoringEntriesInProjectArea()); + // ensure we did not clone reference + provider1.setCustomParameter(""); + assertFalse(provider1.getCustomParameter().equals(providerClone.getCustomParameter())); + + assertEquals(LanguageSettingsManager.isStoringEntriesInProjectArea(provider1), LanguageSettingsManager.isStoringEntriesInProjectArea(providerClone)); + // ensure we did not clone reference + LanguageSettingsManager.setStoringEntriesInProjectArea(provider1, !LanguageSettingsManager.isStoringEntriesInProjectArea(providerClone)); + assertFalse(LanguageSettingsManager.isStoringEntriesInProjectArea(provider1) == LanguageSettingsManager.isStoringEntriesInProjectArea(providerClone)); + assertEquals(provider1.getLanguageScope().get(0), providerClone.getLanguageScope().get(0)); List actual1 = providerClone.getSettingEntries(MOCK_CFG, MOCK_RC, LANG_ID); @@ -1299,8 +1310,8 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { MockSerializableProvider provider1 = new MockSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); provider1.setLanguageScope(sampleLanguages); provider1.setCustomParameter(CUSTOM_PARAMETER); - assertEquals(false, provider1.isStoringEntriesInProjectArea()); - provider1.setStoringEntriesInProjectArea(true); + assertEquals(false, LanguageSettingsManager.isStoringEntriesInProjectArea(provider1)); + LanguageSettingsManager.setStoringEntriesInProjectArea(provider1, true); List entries = new ArrayList(); entries.add(new CIncludePathEntry("path", 1)); @@ -1312,7 +1323,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { assertFalse(provider1.equals(providerClone)); assertTrue(provider1.getClass()==providerClone.getClass()); assertEquals(provider1.getCustomParameter(), providerClone.getCustomParameter()); - assertEquals(provider1.isStoringEntriesInProjectArea(), providerClone.isStoringEntriesInProjectArea()); + assertEquals(LanguageSettingsManager.isStoringEntriesInProjectArea(provider1), LanguageSettingsManager.isStoringEntriesInProjectArea(providerClone)); assertEquals(provider1.getLanguageScope().get(0), providerClone.getLanguageScope().get(0)); List actual = providerClone.getSettingEntries(null, null, null); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java index 4fa512496ad..d4e04c9657d 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java @@ -274,6 +274,29 @@ public class LanguageSettingsManager { LanguageSettingsProvidersSerializer.unregisterLanguageSettingsChangeListener(listener); } + /** + * 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 + * the entries migrate with the project. + * + * @param provider - provider to check the persistence mode. + * @return {@code true} if LSE persisted with the project or {@code false} if in the workspace. + */ + public static boolean isStoringEntriesInProjectArea(LanguageSettingsSerializableProvider provider) { + return LanguageSettingsProvidersSerializer.isStoringEntriesInProjectArea(provider); + } + + /** + * Define where language settings are persisted for the provider. + * + * @param provider - provider to set the persistence mode. + * @param storeEntriesWithProject - {@code true} if with the project, + * {@code false} if in workspace area. + */ + public static void setStoringEntriesInProjectArea(LanguageSettingsSerializableProvider provider, boolean storeEntriesWithProject) { + LanguageSettingsProvidersSerializer.setStoringEntriesInProjectArea(provider, storeEntriesWithProject); + } + /** * Save language settings providers of a project to persistent storage. * diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableProvider.java index 27af0a2ca59..b5f0f63d29a 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableProvider.java @@ -11,7 +11,10 @@ package org.eclipse.cdt.core.language.settings.providers; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.Map.Entry; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; @@ -21,6 +24,7 @@ import org.eclipse.cdt.internal.core.XmlUtil; import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsSerializableStorage; import org.eclipse.core.resources.IResource; import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -41,13 +45,8 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr private static final String ATTR_NAME = "name"; //$NON-NLS-1$ private static final String ATTR_CLASS = "class"; //$NON-NLS-1$ private static final String ATTR_PARAMETER = "parameter"; //$NON-NLS-1$ - private static final String ATTR_STORE_ENTRIES = "store-entries"; //$NON-NLS-1$ - private static final String VALUE_WORKSPACE = "workspace"; //$NON-NLS-1$ - private static final String VALUE_PROJECT = "project"; //$NON-NLS-1$ - - /** Tells if language settings entries are persisted with the project or in workspace area while serializing. */ - private boolean storeEntriesInProjectArea = false; + private Map properties = new HashMap(); private LanguageSettingsSerializableStorage fStorage = new LanguageSettingsSerializableStorage(); /** @@ -124,26 +123,6 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr this.customParameter = customParameter; } - /** - * Tells if language settings entries are persisted with the project (under .settings folder) - * or in workspace area. Persistence in the project area lets the entries migrate with the - * project. - * - * @return {@code true} if LSE persisted with the project or {@code false} if in the workspace. - */ - public boolean isStoringEntriesInProjectArea() { - return storeEntriesInProjectArea; - } - - /** - * Setter to define where language settings are persisted. - * @param storeEntriesWithProject - {@code true} if with the project, - * {@code false} if in workspace area. - */ - public void setStoringEntriesInProjectArea(boolean storeEntriesWithProject) { - this.storeEntriesInProjectArea = storeEntriesWithProject; - } - /** * Clear all the entries for all configurations, all resources and all languages. */ @@ -230,13 +209,23 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr * attached to the parent element. */ public Element serializeAttributes(Element parentElement) { - Element elementProvider = XmlUtil.appendElement(parentElement, ELEM_PROVIDER, new String[] { - ATTR_ID, getId(), - ATTR_NAME, getName(), - ATTR_CLASS, getClass().getCanonicalName(), - ATTR_PARAMETER, getCustomParameter(), - ATTR_STORE_ENTRIES, isStoringEntriesInProjectArea() ? VALUE_PROJECT : VALUE_WORKSPACE, - }); + // Keeps pairs: key, value. See JavaDoc XmlUtil.appendElement(Node, String, String[]). + List attributes = new ArrayList(); + + attributes.add(ATTR_ID); + attributes.add(getId()); + attributes.add(ATTR_NAME); + attributes.add(getName()); + attributes.add(ATTR_CLASS); + attributes.add(getClass().getCanonicalName()); + attributes.add(ATTR_PARAMETER); + attributes.add(getCustomParameter()); + for (Entry entry : properties.entrySet()) { + attributes.add(entry.getKey()); + attributes.add(entry.getValue()); + } + + Element elementProvider = XmlUtil.appendElement(parentElement, ELEM_PROVIDER, attributes.toArray(new String[0])); if (languageScope!=null) { for (String langId : languageScope) { @@ -293,12 +282,23 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr String providerId = XmlUtil.determineAttributeValue(providerNode, ATTR_ID); String providerName = XmlUtil.determineAttributeValue(providerNode, ATTR_NAME); String providerParameter = XmlUtil.determineAttributeValue(providerNode, ATTR_PARAMETER); - String providerStoreEntries = XmlUtil.determineAttributeValue(providerNode, ATTR_STORE_ENTRIES); + + properties.clear(); + NamedNodeMap attrs = providerNode.getAttributes(); + for (int i=0; i(languageScope); + clone.properties = new HashMap(properties); clone.fStorage = new LanguageSettingsSerializableStorage(); return clone; @@ -360,7 +375,7 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr result = prime * result + ((getName() == null) ? 0 : getName().hashCode()); result = prime * result + ((languageScope == null) ? 0 : languageScope.hashCode()); result = prime * result + ((customParameter == null) ? 0 : customParameter.hashCode()); - result = prime * result + (storeEntriesInProjectArea ? 0 : 1); + result = prime * result + ((properties == null) ? 0 : properties.hashCode()); result = prime * result + ((fStorage == null) ? 0 : fStorage.hashCode()); result = prime * result + getClass().hashCode(); return result; @@ -408,7 +423,10 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr } else if (!customParameter.equals(other.customParameter)) return false; - if (storeEntriesInProjectArea!=other.storeEntriesInProjectArea) + if (properties == null) { + if (other.properties != null) + return false; + } else if (!properties.equals(other.properties)) return false; if (fStorage == null) { diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java index ae19d072285..15fc6ccf4a9 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java @@ -76,6 +76,10 @@ public class LanguageSettingsProvidersSerializer { private static final String ELEM_PROVIDER = "provider"; //$NON-NLS-1$ private static final String ELEM_PROVIDER_REFERENCE = "provider-reference"; //$NON-NLS-1$ + private static final String ATTR_STORE_ENTRIES = "store-entries"; //$NON-NLS-1$ + private static final String VALUE_WORKSPACE = "workspace"; //$NON-NLS-1$ + private static final String VALUE_PROJECT = "project"; //$NON-NLS-1$ + private static ILock serializingLock = Job.getJobManager().newLock(); /** Cache of globally available providers to be consumed by calling clients */ @@ -512,7 +516,7 @@ projects: LanguageSettingsSerializableProvider lss = (LanguageSettingsSerializableProvider) provider; boolean useWsp = projectElementWspStore!=null && projectElementPrjStore!=projectElementWspStore; - if (lss.isStoringEntriesInProjectArea() || !useWsp) { + if (isStoringEntriesInProjectArea(lss) || !useWsp) { lss.serialize(elementExtension); } else { lss.serializeAttributes(elementExtension); @@ -649,7 +653,7 @@ projects: provider = loadProvider(providerNode); if (provider instanceof LanguageSettingsSerializableProvider) { LanguageSettingsSerializableProvider lss = (LanguageSettingsSerializableProvider) provider; - if (!lss.isStoringEntriesInProjectArea() && projectElementWsp!=null) { + if (!isStoringEntriesInProjectArea(lss) && projectElementWsp!=null) { loadProviderEntries(lss, cfgId, projectElementWsp); } } @@ -1316,4 +1320,29 @@ projects: return getSettingEntriesByKind(cfgDescription, rc, languageId, kind, /* checkLocality */ true, /* isLocal */ true); } + /** + * 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 + * the entries migrate with the project. + * + * @param provider - provider to check the persistence mode. + * @return {@code true} if LSE persisted with the project or {@code false} if in the workspace. + */ + public static boolean isStoringEntriesInProjectArea(LanguageSettingsSerializableProvider provider) { + String value = provider.getProperty(ATTR_STORE_ENTRIES); + return VALUE_PROJECT.equals(value); + } + + /** + * Define where language settings are persisted for the provider. + * + * @param provider - provider to set the persistence mode. + * @param storeEntriesWithProject - {@code true} if with the project, + * {@code false} if in workspace area. + */ + public static void setStoringEntriesInProjectArea(LanguageSettingsSerializableProvider provider, boolean storeEntriesWithProject) { + provider.setProperty(ATTR_STORE_ENTRIES, storeEntriesWithProject ? VALUE_PROJECT : VALUE_WORKSPACE); + } + + } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java index 380a24ff353..cacf3443028 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java @@ -406,7 +406,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { provider = toggleGlobalProvider(provider, isGlobal); } projectStorageCheckBox.setSelection(provider instanceof LanguageSettingsSerializableProvider - && ((LanguageSettingsSerializableProvider) provider).isStoringEntriesInProjectArea()); + && LanguageSettingsManager.isStoringEntriesInProjectArea((LanguageSettingsSerializableProvider) provider)); } @Override @@ -424,7 +424,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { boolean isWithProject = projectStorageCheckBox.getSelection(); ILanguageSettingsProvider provider = getWorkingCopy(getSelectedProvider().getId()); Assert.isTrue(provider instanceof LanguageSettingsSerializableProvider); - ((LanguageSettingsSerializableProvider)provider).setStoringEntriesInProjectArea(isWithProject); + LanguageSettingsManager.setStoringEntriesInProjectArea((LanguageSettingsSerializableProvider) provider, isWithProject); refreshItem(provider); } @@ -611,7 +611,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { projectStorageCheckBox.setEnabled(!isGlobal); projectStorageCheckBox.setVisible(rawProvider instanceof LanguageSettingsSerializableProvider); projectStorageCheckBox.setSelection(provider instanceof LanguageSettingsSerializableProvider - && ((LanguageSettingsSerializableProvider)provider).isStoringEntriesInProjectArea()); + && LanguageSettingsManager.isStoringEntriesInProjectArea((LanguageSettingsSerializableProvider) provider)); boolean needPreferencesLink=isGlobal && currentOptionsPage!=null; // TODO: message From c37cfaa6b4d54aee31214686fcc2df75c14461c2 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Mon, 5 Dec 2011 18:04:21 -0500 Subject: [PATCH 078/120] Move properties to LanguageSettingsBaseProvider, keep "parameter" attribute in properties --- .../BuiltinSpecsDetectorTest.java | 184 ++++++++++-------- .../GCCBuildCommandParserTest.java | 183 ++++++++++------- .../AbstractBuildCommandParser.java | 35 +++- .../AbstractBuiltinSpecsDetector.java | 27 ++- ...AbstractLanguageSettingsOutputScanner.java | 108 +++++----- .../GCCBuildCommandParserOptionPage.java | 8 +- .../BuiltinSpecsDetectorOptionPage.java | 8 +- .../tests/GCCBuiltinSpecsDetectorTest.java | 4 +- .../LanguageSettingsExtensionsTests.java | 5 +- ...nguageSettingsPersistenceProjectTests.java | 9 +- .../LanguageSettingsSerializableTests.java | 68 ++++--- .../MockLanguageSettingsBaseProvider.java | 16 +- .../LanguageSettingsBaseProvider.java | 46 +++-- .../LanguageSettingsSerializableProvider.java | 47 ++--- .../LanguageSettingsExtensionManager.java | 11 +- 15 files changed, 433 insertions(+), 326 deletions(-) diff --git a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/BuiltinSpecsDetectorTest.java b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/BuiltinSpecsDetectorTest.java index b51a80e0042..10db27a4541 100644 --- a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/BuiltinSpecsDetectorTest.java +++ b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/BuiltinSpecsDetectorTest.java @@ -13,7 +13,9 @@ import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.eclipse.cdt.core.ErrorParserManager; import org.eclipse.cdt.core.model.CoreModel; @@ -47,9 +49,11 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { private static final String PROVIDER_NAME = "provider name"; private static final String LANGUAGE_ID = "language.test.id"; private static final String CUSTOM_PARAMETER = "customParameter"; + private static final String CUSTOM_PARAMETER_2 = "customParameter2"; private static final String ELEM_TEST = "test"; // those attributes must match that in AbstractBuiltinSpecsDetector + private static final String ATTR_PARAMETER = "parameter"; //$NON-NLS-1$ private static final String ATTR_CONSOLE = "console"; //$NON-NLS-1$ private class MockBuiltinSpecsDetector extends AbstractBuiltinSpecsDetector { @@ -143,36 +147,46 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { public void testAbstractBuiltinSpecsDetector_GettersSetters() throws Exception { { // provider configured with null parameters - MockBuiltinSpecsDetectorExecutedFlag detector = new MockBuiltinSpecsDetectorExecutedFlag(); - detector.configureProvider(PROVIDER_ID, PROVIDER_NAME, null, null, null); + MockBuiltinSpecsDetectorExecutedFlag provider = new MockBuiltinSpecsDetectorExecutedFlag(); + provider.configureProvider(PROVIDER_ID, PROVIDER_NAME, null, null, null); - assertEquals(PROVIDER_ID, detector.getId()); - assertEquals(PROVIDER_NAME, detector.getName()); - assertEquals(null, detector.getLanguageScope()); - assertEquals(null, detector.getSettingEntries(null, null, null)); - assertEquals(null, detector.getCustomParameter()); - assertEquals(false, detector.isExecuted()); + assertEquals(PROVIDER_ID, provider.getId()); + assertEquals(PROVIDER_NAME, provider.getName()); + assertEquals(null, provider.getLanguageScope()); + assertEquals(null, provider.getSettingEntries(null, null, null)); + assertEquals(null, provider.getCommand()); + assertEquals(false, provider.isExecuted()); + assertEquals(false, provider.isConsoleEnabled()); } { // provider configured with non-null parameters - MockBuiltinSpecsDetectorExecutedFlag detector = new MockBuiltinSpecsDetectorExecutedFlag(); + MockBuiltinSpecsDetectorExecutedFlag provider = new MockBuiltinSpecsDetectorExecutedFlag(); List languages = new ArrayList(); languages.add(LANGUAGE_ID); + Map properties = new HashMap(); + properties.put(ATTR_PARAMETER, CUSTOM_PARAMETER); List entries = new ArrayList(); ICLanguageSettingEntry entry = new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); entries.add(entry); - detector.configureProvider(PROVIDER_ID, PROVIDER_NAME, languages, entries, CUSTOM_PARAMETER); - assertEquals(PROVIDER_ID, detector.getId()); - assertEquals(PROVIDER_NAME, detector.getName()); - assertEquals(languages, detector.getLanguageScope()); - assertEquals(entries, detector.getSettingEntries(null, null, null)); - assertEquals(CUSTOM_PARAMETER, detector.getCustomParameter()); - assertEquals(false, detector.isExecuted()); + provider.configureProvider(PROVIDER_ID, PROVIDER_NAME, languages, entries, properties); + assertEquals(PROVIDER_ID, provider.getId()); + assertEquals(PROVIDER_NAME, provider.getName()); + assertEquals(languages, provider.getLanguageScope()); + assertEquals(entries, provider.getSettingEntries(null, null, null)); + assertEquals(CUSTOM_PARAMETER, provider.getCommand()); + assertEquals(false, provider.isConsoleEnabled()); + assertEquals(false, provider.isExecuted()); - detector.execute(); - assertEquals(true, detector.isExecuted()); + // setters + provider.setCommand(CUSTOM_PARAMETER_2); + assertEquals(CUSTOM_PARAMETER_2, provider.getCommand()); + provider.setConsoleEnabled(true); + assertEquals(true, provider.isConsoleEnabled()); + + provider.execute(); + assertEquals(true, provider.isExecuted()); } } @@ -190,7 +204,7 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { } // create instance to compare to - MockDetectorCloneable detector = new MockDetectorCloneable(); + MockDetectorCloneable provider = new MockDetectorCloneable(); List languages = new ArrayList(); languages.add(LANGUAGE_ID); @@ -199,73 +213,75 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { entries.add(entry); // check clone after initialization - MockDetectorCloneable clone0 = detector.clone(); - assertTrue(detector.equals(clone0)); + MockDetectorCloneable clone0 = provider.clone(); + assertTrue(provider.equals(clone0)); // configure provider - detector.configureProvider(PROVIDER_ID, PROVIDER_NAME, languages, entries, CUSTOM_PARAMETER); - assertEquals(false, detector.isConsoleEnabled()); - detector.setConsoleEnabled(true); - detector.execute(); - assertEquals(true, detector.isExecuted()); - assertFalse(detector.equals(clone0)); + Map properties = new HashMap(); + properties.put(ATTR_PARAMETER, CUSTOM_PARAMETER); + provider.configureProvider(PROVIDER_ID, PROVIDER_NAME, languages, entries, properties); + assertEquals(false, provider.isConsoleEnabled()); + provider.setConsoleEnabled(true); + provider.execute(); + assertEquals(true, provider.isExecuted()); + assertFalse(provider.equals(clone0)); // check another clone after configuring { - MockDetectorCloneable clone = detector.clone(); - assertTrue(detector.equals(clone)); + MockDetectorCloneable clone = provider.clone(); + assertTrue(provider.equals(clone)); } // check custom parameter { - MockDetectorCloneable clone = detector.clone(); - clone.setCustomParameter("changed"); - assertFalse(detector.equals(clone)); + MockDetectorCloneable clone = provider.clone(); + clone.setCommand("changed"); + assertFalse(provider.equals(clone)); } // check language scope { - MockDetectorCloneable clone = detector.clone(); + MockDetectorCloneable clone = provider.clone(); clone.setLanguageScope(null); - assertFalse(detector.equals(clone)); + assertFalse(provider.equals(clone)); } // check console flag { - MockDetectorCloneable clone = detector.clone(); + MockDetectorCloneable clone = provider.clone(); boolean isConsoleEnabled = clone.isConsoleEnabled(); clone.setConsoleEnabled( ! isConsoleEnabled ); - assertFalse(detector.equals(clone)); + assertFalse(provider.equals(clone)); } // check isExecuted flag { - MockDetectorCloneable clone = detector.clone(); + MockDetectorCloneable clone = provider.clone(); assertEquals(true, clone.isExecuted()); clone.clear(); assertEquals(false, clone.isExecuted()); - assertFalse(detector.equals(clone)); + assertFalse(provider.equals(clone)); } // check entries { - MockDetectorCloneable clone = detector.clone(); + MockDetectorCloneable clone = provider.clone(); clone.setSettingEntries(null, null, null, null); - assertFalse(detector.equals(clone)); + assertFalse(provider.equals(clone)); } // check cloneShallow() { - MockDetectorCloneable detector2 = detector.clone(); - MockDetectorCloneable clone = detector2.cloneShallow(); + MockDetectorCloneable provider2 = provider.clone(); + MockDetectorCloneable clone = provider2.cloneShallow(); assertEquals(false, clone.isExecuted()); - assertFalse(detector2.equals(clone)); + assertFalse(provider2.equals(clone)); - detector2.setSettingEntries(null, null, null, null); - assertFalse(detector2.equals(clone)); + provider2.setSettingEntries(null, null, null, null); + assertFalse(provider2.equals(clone)); clone.execute(); - assertTrue(detector2.equals(clone)); + assertTrue(provider2.equals(clone)); } } @@ -278,54 +294,54 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST); // load it to new provider - MockBuiltinSpecsDetectorExecutedFlag detector = new MockBuiltinSpecsDetectorExecutedFlag(); - detector.load(rootElement); - assertEquals(false, detector.isConsoleEnabled()); + MockBuiltinSpecsDetectorExecutedFlag provider = new MockBuiltinSpecsDetectorExecutedFlag(); + provider.load(rootElement); + assertEquals(false, provider.isConsoleEnabled()); } Element elementProvider; { // define mock detector - MockBuiltinSpecsDetectorExecutedFlag detector = new MockBuiltinSpecsDetectorExecutedFlag(); - assertEquals(false, detector.isConsoleEnabled()); + MockBuiltinSpecsDetectorExecutedFlag provider = new MockBuiltinSpecsDetectorExecutedFlag(); + assertEquals(false, provider.isConsoleEnabled()); // redefine the settings - detector.setConsoleEnabled(true); - assertEquals(true, detector.isConsoleEnabled()); + provider.setConsoleEnabled(true); + assertEquals(true, provider.isConsoleEnabled()); // serialize in XML Document doc = XmlUtil.newDocument(); Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST); - elementProvider = detector.serialize(rootElement); + elementProvider = provider.serialize(rootElement); String xmlString = XmlUtil.toString(doc); assertTrue(xmlString.contains(ATTR_CONSOLE)); } { // create another instance of the provider - MockBuiltinSpecsDetectorExecutedFlag detector = new MockBuiltinSpecsDetectorExecutedFlag(); - assertEquals(false, detector.isConsoleEnabled()); + MockBuiltinSpecsDetectorExecutedFlag provider = new MockBuiltinSpecsDetectorExecutedFlag(); + assertEquals(false, provider.isConsoleEnabled()); // load element - detector.load(elementProvider); - assertEquals(true, detector.isConsoleEnabled()); + provider.load(elementProvider); + assertEquals(true, provider.isConsoleEnabled()); } } public void testAbstractBuiltinSpecsDetector_Nulls() throws Exception { { // test AbstractBuiltinSpecsDetector.processLine(...) flow - MockBuiltinSpecsDetector detector = new MockBuiltinSpecsDetector(); - detector.startup(null); - detector.startupForLanguage(null); - detector.processLine(null, null); - detector.shutdownForLanguage(); - detector.shutdown(); + MockBuiltinSpecsDetector provider = new MockBuiltinSpecsDetector(); + provider.startup(null); + provider.startupForLanguage(null); + provider.processLine(null, null); + provider.shutdownForLanguage(); + provider.shutdown(); } { // test AbstractBuiltinSpecsDetector.processLine(...) flow - MockConsoleBuiltinSpecsDetector detector = new MockConsoleBuiltinSpecsDetector(); - detector.runForEachLanguage(null, null, null, null); + MockConsoleBuiltinSpecsDetector provider = new MockConsoleBuiltinSpecsDetector(); + provider.runForEachLanguage(null, null, null, null); } } @@ -336,28 +352,28 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; - MockConsoleBuiltinSpecsDetector detector = new MockConsoleBuiltinSpecsDetector(); - detector.setLanguageScope(new ArrayList() {{add(LANGUAGE_ID);}}); + MockConsoleBuiltinSpecsDetector provider = new MockConsoleBuiltinSpecsDetector(); + provider.setLanguageScope(new ArrayList() {{add(LANGUAGE_ID);}}); - detector.runForEachLanguage(cfgDescription, null, null, null); - assertFalse(detector.isEmpty()); + provider.runForEachLanguage(cfgDescription, null, null, null); + assertFalse(provider.isEmpty()); - List noentries = detector.getSettingEntries(null, null, null); + List noentries = provider.getSettingEntries(null, null, null); assertNull(noentries); - List entries = detector.getSettingEntries(cfgDescription, null, LANGUAGE_ID); + List entries = provider.getSettingEntries(cfgDescription, null, LANGUAGE_ID); ICLanguageSettingEntry expected = new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); assertEquals(expected, entries.get(0)); } public void testAbstractBuiltinSpecsDetector_RunGlobal() throws Exception { - MockConsoleBuiltinSpecsDetector detector = new MockConsoleBuiltinSpecsDetector(); - detector.setLanguageScope(new ArrayList() {{add(LANGUAGE_ID);}}); + MockConsoleBuiltinSpecsDetector provider = new MockConsoleBuiltinSpecsDetector(); + provider.setLanguageScope(new ArrayList() {{add(LANGUAGE_ID);}}); - detector.runForEachLanguage(null, null, null, null); - assertFalse(detector.isEmpty()); + provider.runForEachLanguage(null, null, null, null); + assertFalse(provider.isEmpty()); - List entries = detector.getSettingEntries(null, null, LANGUAGE_ID); + List entries = provider.getSettingEntries(null, null, LANGUAGE_ID); ICLanguageSettingEntry expected = new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); assertEquals(expected, entries.get(0)); } @@ -378,7 +394,7 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { final CLibraryFileEntry libraryFile_2 = new CLibraryFileEntry("lib_2.a", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); // Define mock detector adding unorganized entries - MockBuiltinSpecsDetector detector = new MockBuiltinSpecsDetector() { + MockBuiltinSpecsDetector provider = new MockBuiltinSpecsDetector() { @Override public boolean processLine(String line, ErrorParserManager epm) { detectedSettingEntries.add(libraryFile_1); @@ -399,14 +415,14 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { }; // run specs detector - detector.startup(null); - detector.startupForLanguage(null); - detector.processLine("", null); - detector.shutdownForLanguage(); - detector.shutdown(); + provider.startup(null); + provider.startupForLanguage(null); + provider.processLine("", null); + provider.shutdownForLanguage(); + provider.shutdown(); // compare benchmarks, expected well-sorted - List entries = detector.getSettingEntries(null, null, null); + List entries = provider.getSettingEntries(null, null, null); int i=0; assertEquals(includePath_1, entries.get(i++)); diff --git a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java index e6f11f55714..08ef8035eb1 100644 --- a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java +++ b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java @@ -57,11 +57,17 @@ import org.w3c.dom.Element; public class GCCBuildCommandParserTest extends BaseTestCase { // ID of the parser taken from the extension point private static final String GCC_BUILD_COMMAND_PARSER_EXT = "org.eclipse.cdt.make.core.build.command.parser.gcc"; //$NON-NLS-1$ - + + private static final String PROVIDER_ID = "provider.id"; + private static final String PROVIDER_NAME = "provider name"; + private static final String LANGUAGE_ID = "language.test.id"; + private static final String CUSTOM_PARAMETER = "customParameter"; + private static final String CUSTOM_PARAMETER_2 = "customParameter2"; private static final String ELEM_TEST = "test"; private static final String LANG_CPP = GPPLanguage.ID; - // those attributes must match that in AbstractBuiltinSpecsDetector + // those attributes must match that in AbstractBuildCommandParser + private static final String ATTR_PARAMETER = "parameter"; //$NON-NLS-1$ private static final String ATTR_EXPAND_RELATIVE_PATHS = "expand-relative-paths"; //$NON-NLS-1$ private class MockBuildCommandParser extends AbstractBuildCommandParser implements Cloneable { @@ -140,12 +146,12 @@ public class GCCBuildCommandParserTest extends BaseTestCase { // configuration description ICConfigurationDescription[] cfgDescriptions = projectDescription.getConfigurations(); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; - + final ICConfigurationDescription cfgDescriptionReferenced = getConfigurationDescriptions(projectReferenced)[0]; cfgDescription.setReferenceInfo(new HashMap() {{ put(projectReferenced.getName(), cfgDescriptionReferenced.getId()); }}); coreModel.setProjectDescription(project, projectDescription); } - + { // doublecheck that it's set as expected ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); @@ -157,7 +163,44 @@ public class GCCBuildCommandParserTest extends BaseTestCase { } } - + + + public void testAbstractBuildCommandParser_GettersSetters() throws Exception { + { + // provider configured with null parameters + MockBuildCommandParser provider = new MockBuildCommandParser(); + provider.configureProvider(PROVIDER_ID, PROVIDER_NAME, null, null, null); + + assertEquals(PROVIDER_ID, provider.getId()); + assertEquals(PROVIDER_NAME, provider.getName()); + assertEquals(null, provider.getLanguageScope()); + assertEquals(null, provider.getSettingEntries(null, null, null)); + assertEquals(null, provider.getCompilerPattern()); + } + + { + // provider configured with non-null parameters + MockBuildCommandParser provider = new MockBuildCommandParser(); + List languages = new ArrayList(); + languages.add(LANGUAGE_ID); + Map properties = new HashMap(); + properties.put(ATTR_PARAMETER, CUSTOM_PARAMETER); + List entries = new ArrayList(); + ICLanguageSettingEntry entry = new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); + entries.add(entry); + + provider.configureProvider(PROVIDER_ID, PROVIDER_NAME, languages, entries, properties); + assertEquals(PROVIDER_ID, provider.getId()); + assertEquals(PROVIDER_NAME, provider.getName()); + assertEquals(languages, provider.getLanguageScope()); + assertEquals(entries, provider.getSettingEntries(null, null, null)); + assertEquals(CUSTOM_PARAMETER, provider.getCompilerPattern()); + + // setters + provider.setCompilerPattern(CUSTOM_PARAMETER_2); + assertEquals(CUSTOM_PARAMETER_2, provider.getCompilerPattern()); + } + } public void testAbstractBuildCommandParser_CloneAndEquals() throws Exception { // create instance to compare to @@ -824,7 +867,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { parser.startup(cfgDescription); parser.processLine("gcc -I/path0 missing.cpp"); parser.shutdown(); - + // check entries assertTrue(parser.isEmpty()); } @@ -838,13 +881,13 @@ public class GCCBuildCommandParserTest extends BaseTestCase { IFile file=ResourceHelper.createFile(project, "file.cpp"); ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; - + ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); String languageId = ls.getLanguageId(); - + // create GCCBuildCommandParser GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); - + // parse line parser.startup(cfgDescription); parser.processLine("gcc " @@ -852,7 +895,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { + "-I. " + file.getLocation().toOSString()); parser.shutdown(); - + // check entries IPath path0 = new Path("/path0").setDevice(project.getLocation().getDevice()); { @@ -861,7 +904,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { assertEquals(new CIncludePathEntry(project.getFullPath(), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(1)); } } - + /** */ public void testFileAbsolutePath_NoProject() throws Exception { @@ -871,13 +914,13 @@ public class GCCBuildCommandParserTest extends BaseTestCase { IFile file=ResourceHelper.createFile(project, "file.cpp"); ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; - + ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); String languageId = ls.getLanguageId(); - + // create GCCBuildCommandParser GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); - + // parse line parser.startup(null); parser.processLine("gcc " @@ -885,7 +928,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { + "-I. " + file.getLocation().toOSString()); parser.shutdown(); - + // check entries IPath path0 = new Path("/path0").setDevice(project.getLocation().getDevice()); { @@ -894,7 +937,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { assertEquals(new CIncludePathEntry(file.getParent().getFullPath(), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(1)); } } - + /** */ public void testFileWithSpaces() throws Exception { @@ -960,17 +1003,17 @@ public class GCCBuildCommandParserTest extends BaseTestCase { IFile file=ResourceHelper.createFile(project, "Folder1/Folder2/file.cpp"); ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; - + ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); String languageId = ls.getLanguageId(); - + // create GCCBuildCommandParser GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); ErrorParserManager epm = new ErrorParserManager(project, null); // Shift build directory, that could happen if Make Target from folder1 was run IFolder buildDir = folder1; epm.pushDirectoryURI(buildDir.getLocationURI()); - + // parse line parser.startup(cfgDescription); parser.processLine("gcc " @@ -979,7 +1022,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { + "Folder1/Folder2/file.cpp", epm); parser.shutdown(); - + // check entries IPath path0 = new Path("/path0").setDevice(project.getLocation().getDevice()); { @@ -989,7 +1032,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { assertEquals(new CIncludePathEntry(project.getFullPath(), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(1)); } } - + /** */ public void testEndOfLine() throws Exception { @@ -998,23 +1041,23 @@ public class GCCBuildCommandParserTest extends BaseTestCase { IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; - + IFile file0=ResourceHelper.createFile(project, "file0.cpp"); IFile file1=ResourceHelper.createFile(project, "file1.cpp"); IFile file2=ResourceHelper.createFile(project, "file2.cpp"); ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file0.getProjectRelativePath(), true); String languageId = ls.getLanguageId(); - + // create GCCBuildCommandParser GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); - + // parse line parser.startup(cfgDescription); parser.processLine("gcc -I/path0 file0.cpp"); parser.processLine("gcc -I/path0 file1.cpp\n"); parser.processLine("gcc -I/path0 file2.cpp\r\n"); parser.shutdown(); - + // check populated entries IPath path0 = new Path("/path0").setDevice(project.getLocation().getDevice()); { @@ -1043,33 +1086,33 @@ public class GCCBuildCommandParserTest extends BaseTestCase { // do not test on non-windows systems where drive letters are not supported if (! Platform.getOS().equals(Platform.OS_WIN32)) return; - + // Create model project and accompanied descriptions String projectName = getName(); IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; - + IFile file=ResourceHelper.createFile(project, "file.cpp"); ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); String languageId = ls.getLanguageId(); - + // create GCCBuildCommandParser GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); parser.setResolvingPaths(true); - + // parse line parser.startup(cfgDescription); parser.processLine("gcc " + " -IX:\\path" + " file.cpp"); parser.shutdown(); - + // check populated entries List entries = parser.getSettingEntries(cfgDescription, file, languageId); assertEquals(new CIncludePathEntry(new Path("X:\\path"), 0), entries.get(0)); } - + /** */ public void testPathEntry_ExpandRelativePath() throws Exception { @@ -1189,7 +1232,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; - + IFolder buildDir=ResourceHelper.createFolder(project, "BuildDir"); IFolder folder=ResourceHelper.createFolder(project, "BuildDir/Folder"); IFile file=ResourceHelper.createFile(project, "BuildDir/file.cpp"); @@ -1197,12 +1240,12 @@ public class GCCBuildCommandParserTest extends BaseTestCase { IFile fakeFile=ResourceHelper.createFile(project, "file.cpp"); ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); String languageId = ls.getLanguageId(); - + // create GCCBuildCommandParser GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); ErrorParserManager epm = new ErrorParserManager(project, null); epm.pushDirectoryURI(buildDir.getLocationURI()); - + // parse line parser.startup(cfgDescription); parser.processLine("gcc " @@ -1214,7 +1257,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { + " file.cpp", epm); parser.shutdown(); - + // check populated entries List entries = parser.getSettingEntries(cfgDescription, file, languageId); { @@ -1225,7 +1268,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { assertEquals(new CIncludePathEntry(buildDir.getFullPath().append("MissingFolder"), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(4)); } } - + /** */ public void testPathEntry_GuessCWD() throws Exception { @@ -1382,7 +1425,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { assertEquals(new CIncludePathEntry(buildDir.getFullPath().append("MissingFolder2"), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(4)); } } - + /** */ public void testPathEntry_MappedFolderInProject() throws Exception { @@ -1391,7 +1434,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; - + IFile file=ResourceHelper.createFile(project, "BuildDir/file.cpp"); IFolder mappedFolder=ResourceHelper.createFolder(project, "Mapped/Folder"); IFolder folder=ResourceHelper.createFolder(project, "Mapped/Folder/Subfolder"); @@ -1399,14 +1442,14 @@ public class GCCBuildCommandParserTest extends BaseTestCase { IFolder ambiguousFolder1=ResourceHelper.createFolder(project, "One/Ambiguous/Folder"); @SuppressWarnings("unused") IFolder ambiguousFolder2=ResourceHelper.createFolder(project, "Another/Ambiguous/Folder"); - + ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); String languageId = ls.getLanguageId(); - + // create GCCBuildCommandParser GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); ErrorParserManager epm = new ErrorParserManager(project, null); - + // parse line parser.startup(cfgDescription); parser.processLine("gcc " @@ -1417,7 +1460,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { + " file.cpp", epm); parser.shutdown(); - + // check populated entries List entries = parser.getSettingEntries(cfgDescription, file, languageId); { @@ -1442,7 +1485,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; - + // create files and folders IFile file=ResourceHelper.createFile(project, "file.cpp"); // another project @@ -1453,14 +1496,14 @@ public class GCCBuildCommandParserTest extends BaseTestCase { @SuppressWarnings("unused") IFolder ambiguousFolder2=ResourceHelper.createFolder(anotherProject, "Another/Ambiguous/Folder"); - + ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); String languageId = ls.getLanguageId(); // create GCCBuildCommandParser GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); ErrorParserManager epm = new ErrorParserManager(project, null); - + // parse line parser.startup(cfgDescription); parser.processLine("gcc " @@ -1470,7 +1513,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { + " file.cpp", epm); parser.shutdown(); - + // check populated entries List entries = parser.getSettingEntries(cfgDescription, file, languageId); { @@ -1485,22 +1528,22 @@ public class GCCBuildCommandParserTest extends BaseTestCase { assertEquals(new CIncludePathEntry(path, 0), entries.get(2)); } } - + /** */ public void testPathEntry_MappedFolderInReferencedProject() throws Exception { // Create model project and accompanied descriptions String projectName = getName(); - + // create main project IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); IFile file=ResourceHelper.createFile(project, "file.cpp"); - + // create another project (non-referenced) IProject anotherProject = ResourceHelper.createCDTProjectWithConfig(projectName+"-another"); @SuppressWarnings("unused") IFolder folderInAnotherProject=ResourceHelper.createFolder(anotherProject, "Mapped/Folder/Subfolder"); - + // create referenced project IProject referencedProject = ResourceHelper.createCDTProjectWithConfig(projectName+"-referenced"); IFolder folderInReferencedProject=ResourceHelper.createFolder(referencedProject, "Mapped/Folder/Subfolder"); @@ -1508,7 +1551,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { IFolder ambiguousFolder1=ResourceHelper.createFolder(referencedProject, "One/Ambiguous/Folder"); @SuppressWarnings("unused") IFolder ambiguousFolder2=ResourceHelper.createFolder(referencedProject, "Another/Ambiguous/Folder"); - + setReference(project, referencedProject); // get cfgDescription and language to work with @@ -1516,11 +1559,11 @@ public class GCCBuildCommandParserTest extends BaseTestCase { ICConfigurationDescription cfgDescription = cfgDescriptions[0]; ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); String languageId = ls.getLanguageId(); - + // create GCCBuildCommandParser GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); ErrorParserManager epm = new ErrorParserManager(project, null); - + // parse line parser.startup(cfgDescription); parser.processLine("gcc " @@ -1529,7 +1572,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { + " file.cpp", epm); parser.shutdown(); - + // check populated entries List entries = parser.getSettingEntries(cfgDescription, file, languageId); { @@ -1680,16 +1723,16 @@ public class GCCBuildCommandParserTest extends BaseTestCase { IFolder includeDir=ResourceHelper.createFolder(project, "BuildDir/include"); // Change build dir setBuilderCWD(project, buildDir.getLocation()); - + ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; - + ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); String languageId = ls.getLanguageId(); - + // create GCCBuildCommandParser GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); - + // parse line parser.startup(cfgDescription); parser.processLine("gcc " @@ -1698,16 +1741,16 @@ public class GCCBuildCommandParserTest extends BaseTestCase { + " " + file.getLocation().toOSString() ); parser.shutdown(); - + // check populated entries List entries = parser.getSettingEntries(cfgDescription, file, languageId); { assertEquals(new CIncludePathEntry(buildDir.getFullPath(), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(0)); assertEquals(new CIncludePathEntry(includeDir.getFullPath(), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(1)); } - + } - + public void testContentType_None() throws Exception { MockBuildCommandParser parser = new MockBuildCommandParser() { @Override @@ -1718,11 +1761,11 @@ public class GCCBuildCommandParserTest extends BaseTestCase { parser.startup(null); parser.processLine("gcc file.wrong-content-type"); parser.shutdown(); - + List entries = parser.getSettingEntries(null, null, null); assertNull(entries); } - + /** */ public void testContentType_Mismatch() throws Exception { @@ -1732,7 +1775,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; ResourceHelper.createFile(project, "file.c"); - + // create GCCBuildCommandParser GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); // restrict the parser's language scope to C++ only @@ -1742,7 +1785,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { parser.startup(cfgDescription); parser.processLine("gcc -I/path0 file.c"); parser.shutdown(); - + assertTrue(parser.isEmpty()); } @@ -1863,7 +1906,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; - + // create folder structure @SuppressWarnings("unused") IFolder buildDir=ResourceHelper.createEfsFolder(project, "BuildDir", new URI("mem:/EfsProject/BuildDir")); @@ -1902,7 +1945,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); ICConfigurationDescription cfgDescription = cfgDescriptions[0]; - + // create folder structure @SuppressWarnings("unused") IFolder buildDir=ResourceHelper.createEfsFolder(project, "BuildDir", new URI("mem:/MappedEfsProject/BuildDir")); @@ -1911,11 +1954,11 @@ public class GCCBuildCommandParserTest extends BaseTestCase { IFile file=ResourceHelper.createEfsFile(project, "BuildDir/file.cpp", new URI("mem:/MappedEfsProject/BuildDir/file.cpp")); ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); String languageId = ls.getLanguageId(); - + // create GCCBuildCommandParser GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); ErrorParserManager epm = new ErrorParserManager(project, null); - + // parse line parser.startup(cfgDescription); parser.processLine("gcc " @@ -1923,7 +1966,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { + " file.cpp", epm); parser.shutdown(); - + // check populated entries List entries = parser.getSettingEntries(cfgDescription, file, languageId); { diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java index e3159346705..59e256ed08e 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java @@ -45,8 +45,8 @@ import org.eclipse.core.runtime.jobs.Job; */ public abstract class AbstractBuildCommandParser extends AbstractLanguageSettingsOutputScanner implements ICConsoleParser, IErrorParser { - public static final Object JOB_FAMILY_BUILD_COMMAND_PARSER = "org.eclipse.cdt.make.core.scannerconfig.AbstractBuildCommandParser"; + private static final String ATTR_PARAMETER = "parameter"; //$NON-NLS-1$ private static final String LEADING_PATH_PATTERN = "\\S+[/\\\\]"; //$NON-NLS-1$ private static final Pattern OPTIONS_PATTERN = Pattern.compile("-[^\\s\"']*(\\s*((\".*?\")|('.*?')|([^-\\s][^\\s]+)))?"); //$NON-NLS-1$ @@ -63,22 +63,43 @@ public abstract class AbstractBuildCommandParser extends AbstractLanguageSetting private static final int FILE_GROUP = 2; + /** + * The compiler command pattern without specifying compiler options. + * The options are intended to be handled with option parsers, + * see {@link #getOptionParsers()}. + * This is regular expression pattern. + * + * @return the compiler command pattern. + */ + public String getCompilerPattern() { + return getProperty(ATTR_PARAMETER); + } + + /** + * Set compiler command pattern for the provider. See {@link #getCompilerPattern()}. + * @param commandPattern - value of the command pattern to set. + * This is regular expression pattern. + */ + public void setCompilerPattern(String commandPattern) { + setProperty(ATTR_PARAMETER, commandPattern); + } + @SuppressWarnings("nls") - private String getCompilerCommandPattern() { - String parameter = getCustomParameter(); - return "\\s*\"?("+LEADING_PATH_PATTERN+")?(" + parameter + ")\"?"; + private String getCompilerPatternExtended() { + String compilerPattern = getCompilerPattern(); + return "\\s*\"?("+LEADING_PATH_PATTERN+")?(" + compilerPattern + ")\"?"; } private int adjustFileGroup() { - return countGroups(getCompilerCommandPattern()) + FILE_GROUP; + return countGroups(getCompilerPatternExtended()) + FILE_GROUP; } private String makePattern(String template) { @SuppressWarnings("nls") String pattern = template - .replace("${COMPILER_PATTERN}", getCompilerCommandPattern()) + .replace("${COMPILER_PATTERN}", getCompilerPatternExtended()) .replace("${EXTENSIONS_PATTERN}", getPatternFileExtensions()) - .replace("${COMPILER_GROUPS+1}", new Integer(countGroups(getCompilerCommandPattern()) + 1).toString()); + .replace("${COMPILER_GROUPS+1}", new Integer(countGroups(getCompilerPatternExtended()) + 1).toString()); return pattern; } diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java index 2264e3f1af5..0022c02bf8e 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java @@ -80,6 +80,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti private static final String PLUGIN_CDT_MAKE_UI_ID = "org.eclipse.cdt.make.ui"; //$NON-NLS-1$ private static final String GMAKE_ERROR_PARSER_ID = "org.eclipse.cdt.core.GmakeErrorParser"; //$NON-NLS-1$ private static final String PATH_ENV = "PATH"; //$NON-NLS-1$ + private static final String ATTR_PARAMETER = "parameter"; //$NON-NLS-1$ private static final String ATTR_CONSOLE = "console"; //$NON-NLS-1$ protected static final String COMPILER_MACRO = "${COMMAND}"; //$NON-NLS-1$ @@ -182,6 +183,30 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti } } + /** + * The command to run. Some macros could be specified in there: + *
      + * ${COMMAND} - compiler command taken from the toolchain.
      + * ${INPUTS} - path to spec file which will be placed in workspace area.
      + * ${EXT} - file extension calculated from language ID. + *
    + * The parameter could be taken from the extension + * in {@code plugin.xml} or from property file. + * + * @return the command to run. + */ + public String getCommand() { + return getProperty(ATTR_PARAMETER); + } + + /** + * Set custom command for the provider. See {@link #getCommand()}. + * @param command - value of custom command to set. + */ + public void setCommand(String command) { + setProperty(ATTR_PARAMETER, command); + } + public void setConsoleEnabled(boolean enable) { isConsoleEnabled = enable; } @@ -191,7 +216,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti } protected String resolveCommand(String languageId) throws CoreException { - String cmd = getCustomParameter(); + String cmd = getCommand(); if (cmd!=null && (cmd.contains(COMPILER_MACRO) || cmd.contains(SPEC_FILE_MACRO) || cmd.contains(SPEC_EXT_MACRO))) { if (cmd.contains(COMPILER_MACRO)) { String compiler = getCompilerCommand(languageId); diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java index 652dcfc63da..0c373948d47 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java @@ -184,7 +184,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett /** * Parse the line returning the resource name as appears in the output. * This is the resource where {@link ICLanguageSettingEntry} list is being added. - * + * * @param line - one input line from the output stripped from end of line characters. * @return the resource name as appears in the output or {@code null}. * Note that {@code null} can have different semantics and can mean "no resource found" @@ -198,7 +198,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett * the option parsers. It is assumed that each substring presents one * {@link ICLanguageSettingEntry} (for example compiler options {@code -I/path} or * {@code -DMACRO=1}. - * + * * @param line - one input line from the output stripped from end of line characters. * @return list of substrings representing language settings entries. */ @@ -240,7 +240,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett errorParserManager = epm; parsedResourceName = parseForResourceName(line); currentResource = findResource(parsedResourceName); - + currentLanguageId = determineLanguage(); if (!isLanguageInScope(currentLanguageId)) return false; @@ -251,7 +251,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett * it can be different filesystem (and different URI schema). */ URI buildDirURI = null; - + /** * Where source tree starts if mapped. This kind of mapping is useful for example in cases when * the absolute path to the source file on the remote system is simulated inside a project in the @@ -260,14 +260,14 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett * (or even URI schema) does not have to match that of buildDirURI. */ URI mappedRootURI = null; - + if (isResolvingPaths) { mappedRootURI = getMappedRootURI(currentResource, parsedResourceName); buildDirURI = getBuildDirURI(mappedRootURI); } List entries = new ArrayList(); - + List options = parseForOptions(line); if (options!=null) { for (String option : options) { @@ -283,7 +283,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett } else { entry = optionParser.createEntry(optionParser.parsedName, optionParser.parsedValue, 0); } - + if (entry != null && !entries.contains(entry)) { entries.add(entry); break; @@ -319,7 +319,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett protected void setSettingEntries(List entries) { setSettingEntries(currentCfgDescription, currentResource, currentLanguageId, entries); - + LanguageSettingsLogger.logInfo(getPrefixForLog() + getClass().getSimpleName() + " collected " + (entries!=null ? ("" + entries.size()) : "null") + " entries for " + currentResource); } @@ -331,10 +331,10 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett // use handle; resource does not need to exist rc = currentProject.getFile("__" + fileName); } - + if (rc == null) return null; - + List languageIds = LanguageSettingsManager.getLanguages(rc, currentCfgDescription); if (languageIds.isEmpty()) return null; @@ -349,26 +349,26 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett protected String getPatternFileExtensions() { IContentTypeManager manager = Platform.getContentTypeManager(); - + Set fileExts = new HashSet(); - + IContentType contentTypeCpp = manager.getContentType("org.eclipse.cdt.core.cxxSource"); //$NON-NLS-1$ fileExts.addAll(Arrays.asList(contentTypeCpp.getFileSpecs(IContentType.FILE_EXTENSION_SPEC))); - + IContentType contentTypeC = manager.getContentType("org.eclipse.cdt.core.cSource"); //$NON-NLS-1$ fileExts.addAll(Arrays.asList(contentTypeC.getFileSpecs(IContentType.FILE_EXTENSION_SPEC))); - + String pattern = expressionLogicalOr(fileExts); - + return pattern; } private ICLanguageSettingEntry createResolvedPathEntry(AbstractOptionParser optionParser, String parsedPath, int flag, URI baseURI) { - + ICLanguageSettingEntry entry; String resolvedPath = null; - + URI uri = determineMappedURI(parsedPath, baseURI); IResource rc = null; if (uri != null && uri.isAbsolute()) { @@ -400,7 +400,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett resolvedPath = path.toString(); } } - + if (resolvedPath==null) { resolvedPath = parsedPath; } @@ -412,9 +412,9 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett private IResource findResource(String parsedResourceName) { if (parsedResourceName==null) return null; - + IResource sourceFile = null; - + // try ErrorParserManager if (errorParserManager != null) { sourceFile = errorParserManager.findFileName(parsedResourceName); @@ -442,7 +442,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett protected URI getBuildDirURI(URI mappedRootURI) { URI buildDirURI = null; - + URI cwdURI = null; if (currentResource!=null && parsedResourceName!=null && !new Path(parsedResourceName).isAbsolute()) { cwdURI = findBaseLocationURI(currentResource.getLocationURI(), parsedResourceName); @@ -450,14 +450,14 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett if (cwdURI == null && errorParserManager != null) { cwdURI = errorParserManager.getWorkingDirectoryURI(); } - + String cwdPath = cwdURI != null ? EFSExtensionManager.getDefault().getPathFromURI(cwdURI) : null; if (cwdPath != null && mappedRootURI != null) { buildDirURI = EFSExtensionManager.getDefault().append(mappedRootURI, cwdPath); } else { buildDirURI = cwdURI; } - + if (buildDirURI == null && currentCfgDescription != null) { IPath pathBuilderCWD = currentCfgDescription.getBuildSetting().getBuilderCWD(); if (pathBuilderCWD != null) { @@ -472,11 +472,11 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett buildDirURI = org.eclipse.core.filesystem.URIUtil.toURI(builderCWD); } } - + if (buildDirURI == null && currentProject != null) { buildDirURI = currentProject.getLocationURI(); } - + if (buildDirURI == null && currentResource != null) { IContainer container; if (currentResource instanceof IContainer) { @@ -491,14 +491,14 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett /** * Determine URI on the local filesystem considering possible mapping. - * + * * @param pathStr - path to the resource, can be absolute or relative * @param baseURI - base {@link URI} where path to the resource is rooted * @return {@link URI} of the resource */ private static URI determineMappedURI(String pathStr, URI baseURI) { URI uri = null; - + if (baseURI==null) { if (new Path(pathStr).isAbsolute()) { uri = resolvePathFromBaseLocation(pathStr, Path.ROOT); @@ -519,7 +519,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett } } } - + if (uri == null) { // if everything fails just wrap string to URI uri = org.eclipse.core.filesystem.URIUtil.toURI(pathStr); @@ -532,7 +532,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett if (path.equals(new Path(".")) || path.equals(new Path(".."))) { //$NON-NLS-1$ //$NON-NLS-2$ return null; } - + // prefer current project if (preferredProject!=null) { List result = findPathInFolder(path, preferredProject); @@ -543,9 +543,9 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett return null; } } - + IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); - + // then prefer referenced projects if (referencedProjectsNames.size() > 0) { IResource rc = null; @@ -567,7 +567,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett return rc; } } - + // then check all other projects in workspace IProject[] projects = root.getProjects(); if (projects.length > 0) { @@ -589,7 +589,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett return rc; } } - + // not found or ambiguous return null; } @@ -600,7 +600,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett if (resource != null) { paths.add(resource); } - + try { for (IResource res : folder.members()) { if (res instanceof IContainer) { @@ -610,7 +610,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett } catch (CoreException e) { // ignore } - + return paths; } @@ -637,9 +637,9 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett private static URI findBaseLocationURI(URI fileURI, String relativeFileName) { URI cwdURI = null; String path = fileURI.getPath(); - + String[] segments = relativeFileName.split("[/\\\\]"); //$NON-NLS-1$ - + // start removing segments from the end of the path for (int i = segments.length - 1; i >= 0; i--) { String lastSegment = segments[i]; @@ -659,7 +659,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett } } } - + try { cwdURI = new URI(fileURI.getScheme(), fileURI.getUserInfo(), fileURI.getHost(), fileURI.getPort(), path + '/', fileURI.getQuery(), fileURI.getFragment()); @@ -667,7 +667,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett // It should be valid URI here or something is wrong MakeCorePlugin.log(e); } - + return cwdURI; } @@ -676,7 +676,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett * this function will try to figure mapping and return "mapped root", * i.e URI where the root path would be mapped. The mapped root will be * used to prepend to other "absolute" paths where appropriate. - * + * * @param sourceFile - a resource referred by parsed path * @param parsedResourceName - path as appears in the output * @return mapped path as URI @@ -685,10 +685,10 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett if (currentResource==null) { return null; } - + URI fileURI = sourceFile.getLocationURI(); String mappedRoot = "/"; //$NON-NLS-1$ - + if (parsedResourceName!=null) { IPath parsedSrcPath = new Path(parsedResourceName); if (parsedSrcPath.isAbsolute()) { @@ -723,7 +723,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett if (device != null && device.length() > 0) { pathName = pathName.substring(device.length()); } - + baseLocation = baseLocation.addTrailingSeparator(); if (pathName.startsWith("/")) { //$NON-NLS-1$ pathName = pathName.substring(1); @@ -731,7 +731,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett pathName = baseLocation.toString() + pathName; } } - + try { File file = new File(pathName); file = file.getCanonicalFile(); @@ -739,7 +739,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett } catch (IOException e) { // if error just leave it as is } - + URI uri = org.eclipse.core.filesystem.URIUtil.toURI(pathName); return uri; } @@ -747,9 +747,9 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett private static IResource findResourceForLocationURI(URI uri, int kind, IProject preferredProject) { if (uri==null) return null; - + IResource resource = null; - + switch (kind) { case ICSettingEntry.INCLUDE_PATH: case ICSettingEntry.LIBRARY_PATH: @@ -760,7 +760,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett resource = findFileForLocationURI(uri, preferredProject); break; } - + return resource; } @@ -788,11 +788,11 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett private static IPath getFilesystemLocation(URI uri) { if (uri==null) return null; - + // EFSExtensionManager mapping String pathStr = EFSExtensionManager.getDefault().getMappedPath(uri); uri = org.eclipse.core.filesystem.URIUtil.toURI(pathStr); - + try { File file = new java.io.File(uri); String canonicalPathStr = file.getCanonicalPath(); @@ -818,7 +818,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett pattern += ")"; return pattern; } - + protected static int countGroups(String str) { @SuppressWarnings("nls") int count = str.replaceAll("[^\\(]", "").length(); @@ -831,16 +831,16 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett elementProvider.setAttribute(ATTR_EXPAND_RELATIVE_PATHS, Boolean.toString(isResolvingPaths)); return elementProvider; } - + @Override public void loadAttributes(Element providerNode) { super.loadAttributes(providerNode); - + String expandRelativePathsValue = XmlUtil.determineAttributeValue(providerNode, ATTR_EXPAND_RELATIVE_PATHS); if (expandRelativePathsValue!=null) isResolvingPaths = Boolean.parseBoolean(expandRelativePathsValue); } - + @Override public int hashCode() { final int prime = 31; diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/preferences/GCCBuildCommandParserOptionPage.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/preferences/GCCBuildCommandParserOptionPage.java index 982e2a023e6..b0739693219 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/preferences/GCCBuildCommandParserOptionPage.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/preferences/GCCBuildCommandParserOptionPage.java @@ -88,8 +88,8 @@ public final class GCCBuildCommandParserOptionPage extends AbstractLanguageSetti { inputCommand = ControlFactory.createTextField(composite, SWT.SINGLE | SWT.BORDER); - String customParameter = provider.getCustomParameter(); - inputCommand.setText(customParameter!=null ? customParameter : ""); + String compilerPattern = provider.getCompilerPattern(); + inputCommand.setText(compilerPattern!=null ? compilerPattern : ""); GridData gd = new GridData(); gd.horizontalSpan = 1; @@ -103,9 +103,9 @@ public final class GCCBuildCommandParserOptionPage extends AbstractLanguageSetti public void modifyText(ModifyEvent e) { String text = inputCommand.getText(); AbstractBuildCommandParser provider = getRawProvider(); - if (!text.equals(provider.getCustomParameter())) { + if (!text.equals(provider.getCompilerPattern())) { AbstractBuildCommandParser selectedProvider = getWorkingCopy(providerId); - selectedProvider.setCustomParameter(text); + selectedProvider.setCompilerPattern(text); providerTab.refreshItem(selectedProvider); } } diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/scannerconfig/BuiltinSpecsDetectorOptionPage.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/scannerconfig/BuiltinSpecsDetectorOptionPage.java index 581c9b8a5d3..12035759118 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/scannerconfig/BuiltinSpecsDetectorOptionPage.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/scannerconfig/BuiltinSpecsDetectorOptionPage.java @@ -84,17 +84,17 @@ public final class BuiltinSpecsDetectorOptionPage extends AbstractLanguageSettin { inputCommand = ControlFactory.createTextField(composite, SWT.SINGLE | SWT.BORDER); - String customParameter = provider.getCustomParameter(); - inputCommand.setText(customParameter!=null ? customParameter : ""); + String command = provider.getCommand(); + inputCommand.setText(command!=null ? command : ""); inputCommand.setEnabled(fEditable); inputCommand.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent e) { String text = inputCommand.getText(); AbstractBuiltinSpecsDetector provider = getRawProvider(); - if (!text.equals(provider.getCustomParameter())) { + if (!text.equals(provider.getCommand())) { AbstractBuiltinSpecsDetector selectedProvider = getWorkingCopy(providerId); - selectedProvider.setCustomParameter(text); + selectedProvider.setCommand(text); providerTab.refreshItem(selectedProvider); } } diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/GCCBuiltinSpecsDetectorTest.java b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/GCCBuiltinSpecsDetectorTest.java index da2257694e4..6a24a79e6aa 100644 --- a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/GCCBuiltinSpecsDetectorTest.java +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/GCCBuiltinSpecsDetectorTest.java @@ -88,7 +88,7 @@ public class GCCBuiltinSpecsDetectorTest extends BaseTestCase { { MockGCCBuiltinSpecsDetectorLocal detector = new MockGCCBuiltinSpecsDetectorLocal(); detector.setLanguageScope(new ArrayList() {{add(LANGUAGE_ID_C);}}); - detector.setCustomParameter("${COMMAND} -E -P -v -dD ${INPUTS}"); + detector.setCommand("${COMMAND} -E -P -v -dD ${INPUTS}"); String resolvedCommand = detector.resolveCommand(LANGUAGE_ID_C); assertTrue(resolvedCommand.startsWith("gcc -E -P -v -dD ")); @@ -97,7 +97,7 @@ public class GCCBuiltinSpecsDetectorTest extends BaseTestCase { { MockGCCBuiltinSpecsDetectorLocal detector = new MockGCCBuiltinSpecsDetectorLocal(); detector.setLanguageScope(new ArrayList() {{add(LANGUAGE_ID_C);}}); - detector.setCustomParameter("${COMMAND} -E -P -v -dD file.${EXT}"); + detector.setCommand("${COMMAND} -E -P -v -dD file.${EXT}"); String resolvedCommand = detector.resolveCommand(LANGUAGE_ID_C); assertTrue(resolvedCommand.startsWith("gcc -E -P -v -dD ")); diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java index d2f792f2a29..40dc2fc9439 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java @@ -39,6 +39,7 @@ public class LanguageSettingsExtensionsTests extends BaseTestCase { /*package*/ static final String EXTENSION_BASE_PROVIDER_NAME = "Test Plugin Mock Language Settings Base Provider"; /*package*/ static final String EXTENSION_BASE_PROVIDER_LANG_ID = "org.eclipse.cdt.core.tests.language.id"; /*package*/ static final String EXTENSION_BASE_PROVIDER_PARAMETER = "custom parameter"; + /*package*/ static final String EXTENSION_BASE_PROVIDER_ATTR_PARAMETER = "parameter"; /*package*/ static final String EXTENSION_CUSTOM_PROVIDER_ID = "org.eclipse.cdt.core.tests.custom.language.settings.provider"; /*package*/ static final String EXTENSION_CUSTOM_PROVIDER_NAME = "Test Plugin Mock Language Settings Provider"; /*package*/ static final String EXTENSION_BASE_SUBCLASS_PROVIDER_ID = "org.eclipse.cdt.core.tests.language.settings.base.provider.subclass"; @@ -122,7 +123,7 @@ public class LanguageSettingsExtensionsTests extends BaseTestCase { LanguageSettingsBaseProvider provider = (LanguageSettingsBaseProvider)rawProvider; assertEquals(EXTENSION_BASE_PROVIDER_ID, provider.getId()); assertEquals(EXTENSION_BASE_PROVIDER_NAME, provider.getName()); - assertEquals(EXTENSION_BASE_PROVIDER_PARAMETER, provider.getCustomParameter()); + assertEquals(EXTENSION_BASE_PROVIDER_PARAMETER, provider.getProperty(EXTENSION_BASE_PROVIDER_ATTR_PARAMETER)); // attempt to get entries for wrong language assertNull(provider.getSettingEntries(null, FILE_0, LANG_ID)); @@ -263,7 +264,7 @@ public class LanguageSettingsExtensionsTests extends BaseTestCase { LanguageSettingsSerializableProvider provider = (LanguageSettingsSerializableProvider) rawProvider; assertEquals(null, provider.getLanguageScope()); - assertEquals("", provider.getCustomParameter()); + assertEquals("", provider.getProperty(EXTENSION_BASE_PROVIDER_ATTR_PARAMETER)); List expected = new ArrayList(); expected.add(new CMacroEntry("MACRO", "value", 0)); diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java index 6b994c49e4c..d0c7a4c43a6 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java @@ -54,8 +54,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { 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_2 = "test.provider.2.name"; - private static final String PROVIDER_ID_WSP = "test.provider.workspace.id"; - private static final String PROVIDER_NAME_WSP = "test.provider.workspace.name"; + private static final String ATTR_PARAMETER = "parameter"; private static final String CUSTOM_PARAMETER = "custom parameter"; private static final String ELEM_TEST = "test"; @@ -349,8 +348,8 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { assertEquals(EXTENSION_SERIALIZABLE_PROVIDER_ID, rawProvider.getId()); // customize provider - rawProvider.setCustomParameter(CUSTOM_PARAMETER); - assertEquals(CUSTOM_PARAMETER, rawProvider.getCustomParameter()); + rawProvider.setProperty(ATTR_PARAMETER, CUSTOM_PARAMETER); + assertEquals(CUSTOM_PARAMETER, rawProvider.getProperty(ATTR_PARAMETER)); } { // save workspace provider (as opposed to raw provider) @@ -363,7 +362,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { // check that it has not cleared ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_SERIALIZABLE_PROVIDER_ID); LanguageSettingsSerializableProvider rawProvider = (LanguageSettingsSerializableProvider) LanguageSettingsManager.getRawProvider(provider); - assertEquals(CUSTOM_PARAMETER, rawProvider.getCustomParameter()); + assertEquals(CUSTOM_PARAMETER, rawProvider.getProperty(ATTR_PARAMETER)); } } diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java index 7b85ac4668d..1e26760efd7 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java @@ -54,7 +54,8 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { private static final String PROVIDER_NAME_NULL = "test.provider.null.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 CUSTOM_PARAMETER = "custom.parameter"; + private static final String ATTR_PARAMETER = "parameter"; + private static final String VALUE_PARAMETER = "custom.parameter"; private static final String ATTR_STORE_ENTRIES = "store-entries"; private static final String VALUE_PROJECT = "project"; private static final String ELEM_TEST = "test"; @@ -113,14 +114,8 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { assertEquals(PROVIDER_2, mockProvider.getId()); mockProvider.setName(PROVIDER_NAME_2); assertEquals(PROVIDER_NAME_2, mockProvider.getName()); - mockProvider.setCustomParameter(CUSTOM_PARAMETER); - assertEquals(CUSTOM_PARAMETER, mockProvider.getCustomParameter()); - - assertEquals(false, LanguageSettingsManager.isStoringEntriesInProjectArea(mockProvider)); - LanguageSettingsManager.setStoringEntriesInProjectArea(mockProvider, true); - assertEquals(true, LanguageSettingsManager.isStoringEntriesInProjectArea(mockProvider)); - LanguageSettingsManager.setStoringEntriesInProjectArea(mockProvider, false); - assertEquals(false, LanguageSettingsManager.isStoringEntriesInProjectArea(mockProvider)); + mockProvider.setProperty(ATTR_PARAMETER, VALUE_PARAMETER); + assertEquals(VALUE_PARAMETER, mockProvider.getProperty(ATTR_PARAMETER)); mockProvider.setLanguageScope(languages); assertEquals(languages, mockProvider.getLanguageScope()); @@ -138,6 +133,19 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { assertTrue(mockProvider.isEmpty()); } + /** + */ + public void testProvider_SetStoringEntriesInProjectArea() throws Exception { + // create a provider + LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); + + assertEquals(false, LanguageSettingsManager.isStoringEntriesInProjectArea(provider)); + LanguageSettingsManager.setStoringEntriesInProjectArea(provider, true); + assertEquals(true, LanguageSettingsManager.isStoringEntriesInProjectArea(provider)); + LanguageSettingsManager.setStoringEntriesInProjectArea(provider, false); + assertEquals(false, LanguageSettingsManager.isStoringEntriesInProjectArea(provider)); + } + /** */ public void testProvider_RegularDOM() throws Exception { @@ -146,7 +154,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { // create customized provider LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); LanguageSettingsManager.setStoringEntriesInProjectArea(provider, true); - provider.setCustomParameter(CUSTOM_PARAMETER); + provider.setProperty(ATTR_PARAMETER, VALUE_PARAMETER); List languageScope = new ArrayList(); languageScope.add(LANG_ID); @@ -164,7 +172,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { String xmlString = XmlUtil.toString(doc); assertTrue(xmlString.contains(PROVIDER_1)); assertTrue(xmlString.contains(PROVIDER_NAME_1)); - assertTrue(xmlString.contains(CUSTOM_PARAMETER)); + assertTrue(xmlString.contains(VALUE_PARAMETER)); assertTrue(xmlString.contains(LANG_ID)); assertTrue(xmlString.contains("path0")); } @@ -173,7 +181,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(elementProvider); assertEquals(PROVIDER_1, provider.getId()); assertEquals(true, LanguageSettingsManager.isStoringEntriesInProjectArea(provider)); - assertEquals(CUSTOM_PARAMETER, provider.getCustomParameter()); + assertEquals(VALUE_PARAMETER, provider.getProperty(ATTR_PARAMETER)); assertNotNull(provider.getLanguageScope()); assertTrue(provider.getLanguageScope().size()>0); assertEquals(LANG_ID, provider.getLanguageScope().get(0)); @@ -193,7 +201,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { // create customized provider LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); LanguageSettingsManager.setStoringEntriesInProjectArea(provider, true); - provider.setCustomParameter(CUSTOM_PARAMETER); + provider.setProperty(ATTR_PARAMETER, VALUE_PARAMETER); List languageScope = new ArrayList(); languageScope.add(LANG_ID); @@ -211,7 +219,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { String xmlString = XmlUtil.toString(doc); assertTrue(xmlString.contains(PROVIDER_1)); assertTrue(xmlString.contains(PROVIDER_NAME_1)); - assertTrue(xmlString.contains(CUSTOM_PARAMETER)); + assertTrue(xmlString.contains(VALUE_PARAMETER)); assertTrue(xmlString.contains(LANG_ID)); // no entries assertFalse(xmlString.contains("path0")); @@ -222,7 +230,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { provider.loadAttributes(elementProvider); assertEquals(PROVIDER_1, provider.getId()); assertEquals(true, LanguageSettingsManager.isStoringEntriesInProjectArea(provider)); - assertEquals(CUSTOM_PARAMETER, provider.getCustomParameter()); + assertEquals(VALUE_PARAMETER, provider.getProperty(ATTR_PARAMETER)); assertNotNull(provider.getLanguageScope()); assertTrue(provider.getLanguageScope().size()>0); assertEquals(LANG_ID, provider.getLanguageScope().get(0)); @@ -240,7 +248,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { // create customized provider LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); LanguageSettingsManager.setStoringEntriesInProjectArea(provider, true); - provider.setCustomParameter(CUSTOM_PARAMETER); + provider.setProperty(ATTR_PARAMETER, VALUE_PARAMETER); List languageScope = new ArrayList(); languageScope.add(LANG_ID); @@ -259,7 +267,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { // no attributes assertFalse(xmlString.contains(PROVIDER_1)); assertFalse(xmlString.contains(PROVIDER_NAME_1)); - assertFalse(xmlString.contains(CUSTOM_PARAMETER)); + assertFalse(xmlString.contains(VALUE_PARAMETER)); assertFalse(xmlString.contains(LANG_ID)); // entries should be present assertTrue(xmlString.contains("path0")); @@ -274,7 +282,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { assertFalse(PROVIDER_1.equals(provider.getId())); assertFalse(PROVIDER_NAME_1.equals(provider.getName())); assertFalse(true==LanguageSettingsManager.isStoringEntriesInProjectArea(provider)); - assertFalse(CUSTOM_PARAMETER.equals(provider.getCustomParameter())); + assertFalse(VALUE_PARAMETER.equals(provider.getProperty(ATTR_PARAMETER))); assertNull(provider.getLanguageScope()); // entries should be loaded List entries = provider.getSettingEntries(null, null, null); @@ -318,19 +326,19 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { { // create provider with custom parameter LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); - provider.setCustomParameter(CUSTOM_PARAMETER); - assertEquals(CUSTOM_PARAMETER, provider.getCustomParameter()); + provider.setProperty(ATTR_PARAMETER, VALUE_PARAMETER); + assertEquals(VALUE_PARAMETER, provider.getProperty(ATTR_PARAMETER)); Document doc = XmlUtil.newDocument(); Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST); elementProvider = provider.serialize(rootElement); String xmlString = XmlUtil.toString(doc); - assertTrue(xmlString.contains(CUSTOM_PARAMETER)); + assertTrue(xmlString.contains(VALUE_PARAMETER)); } { // re-load and check custom parameter of the newly loaded provider LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(elementProvider); - assertEquals(CUSTOM_PARAMETER, provider.getCustomParameter()); + assertEquals(VALUE_PARAMETER, provider.getProperty(ATTR_PARAMETER)); } } @@ -1175,7 +1183,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { // create a model provider LanguageSettingsSerializableProvider provider1 = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); provider1.setLanguageScope(sampleLanguages); - provider1.setCustomParameter(CUSTOM_PARAMETER); + provider1.setProperty(ATTR_PARAMETER, VALUE_PARAMETER); assertEquals(false, LanguageSettingsManager.isStoringEntriesInProjectArea(provider1)); LanguageSettingsManager.setStoringEntriesInProjectArea(provider1, true); provider1.setSettingEntries(MOCK_CFG, MOCK_RC, LANG_ID, sampleEntries_1); @@ -1199,7 +1207,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { assertFalse(provider1.equals(provider2)); assertFalse(provider1.hashCode()==provider2.hashCode()); - provider2.setCustomParameter(CUSTOM_PARAMETER); + provider2.setProperty(ATTR_PARAMETER, VALUE_PARAMETER); assertFalse(provider1.equals(provider2)); assertFalse(provider1.hashCode()==provider2.hashCode()); @@ -1252,7 +1260,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { } MockSerializableProvider provider1 = new MockSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); provider1.setLanguageScope(sampleLanguages); - provider1.setCustomParameter(CUSTOM_PARAMETER); + provider1.setProperty(ATTR_PARAMETER, VALUE_PARAMETER); assertEquals(false, LanguageSettingsManager.isStoringEntriesInProjectArea(provider1)); LanguageSettingsManager.setStoringEntriesInProjectArea(provider1, true); provider1.setSettingEntries(MOCK_CFG, MOCK_RC, LANG_ID, sampleEntries_1); @@ -1264,10 +1272,10 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { assertTrue(provider1.equals(providerClone)); assertTrue(provider1.getClass()==providerClone.getClass()); - assertEquals(provider1.getCustomParameter(), providerClone.getCustomParameter()); + assertEquals(provider1.getProperty(ATTR_PARAMETER), providerClone.getProperty(ATTR_PARAMETER)); // ensure we did not clone reference - provider1.setCustomParameter(""); - assertFalse(provider1.getCustomParameter().equals(providerClone.getCustomParameter())); + provider1.setProperty(ATTR_PARAMETER, ""); + assertFalse(provider1.getProperty(ATTR_PARAMETER).equals(providerClone.getProperty(ATTR_PARAMETER))); assertEquals(LanguageSettingsManager.isStoringEntriesInProjectArea(provider1), LanguageSettingsManager.isStoringEntriesInProjectArea(providerClone)); // ensure we did not clone reference @@ -1309,7 +1317,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { } MockSerializableProvider provider1 = new MockSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); provider1.setLanguageScope(sampleLanguages); - provider1.setCustomParameter(CUSTOM_PARAMETER); + provider1.setProperty(ATTR_PARAMETER, VALUE_PARAMETER); assertEquals(false, LanguageSettingsManager.isStoringEntriesInProjectArea(provider1)); LanguageSettingsManager.setStoringEntriesInProjectArea(provider1, true); @@ -1322,7 +1330,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { assertNotSame(provider1, providerClone); assertFalse(provider1.equals(providerClone)); assertTrue(provider1.getClass()==providerClone.getClass()); - assertEquals(provider1.getCustomParameter(), providerClone.getCustomParameter()); + assertEquals(provider1.getProperty(ATTR_PARAMETER), providerClone.getProperty(ATTR_PARAMETER)); assertEquals(LanguageSettingsManager.isStoringEntriesInProjectArea(provider1), LanguageSettingsManager.isStoringEntriesInProjectArea(providerClone)); assertEquals(provider1.getLanguageScope().get(0), providerClone.getLanguageScope().get(0)); diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockLanguageSettingsBaseProvider.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockLanguageSettingsBaseProvider.java index afae2a4cb50..ce5a88584d6 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockLanguageSettingsBaseProvider.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/MockLanguageSettingsBaseProvider.java @@ -1,19 +1,23 @@ /******************************************************************************* - * Copyright (c) 2009, 2009 Andrew Gvozdev (Quoin Inc.) and others. + * Copyright (c) 2009, 2011 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 (Quoin Inc.) - initial API and implementation + * Andrew Gvozdev - initial API and implementation *******************************************************************************/ - package org.eclipse.cdt.core.language.settings.providers; -import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsBaseProvider; - - public class MockLanguageSettingsBaseProvider extends LanguageSettingsBaseProvider { + private static final String ATTR_PARAMETER = "parameter"; //$NON-NLS-1$ + + /** + * @return the custom parameter defined in the extension in {@code plugin.xml}. + */ + public String getCustomParameter() { + return getProperty(ATTR_PARAMETER); + } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsBaseProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsBaseProvider.java index dad259c2584..21e2879b096 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsBaseProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsBaseProvider.java @@ -13,7 +13,9 @@ package org.eclipse.cdt.core.language.settings.providers; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.eclipse.cdt.core.AbstractExecutableExtensionBase; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; @@ -27,15 +29,13 @@ import org.eclipse.core.resources.IResource; * * This implementation supports "static" list of entries for languages specified in * the extension point. - * - * @since 6.0 */ public class LanguageSettingsBaseProvider extends AbstractExecutableExtensionBase implements ILanguageSettingsProvider { /** Language scope, i.e. list of languages the entries will be provided for. */ protected List languageScope = null; - /** Custom parameter. Intended for providers extending this class. */ - protected String customParameter = null; + /** Provider-specific properties */ + protected Map properties = new HashMap(); /** List of entries defined by this provider. */ private List entries = null; @@ -85,15 +85,15 @@ public class LanguageSettingsBaseProvider extends AbstractExecutableExtensionBas * are provided for any language. * @param entries - the list of language settings entries this provider provides. * If {@code null} is passed, the provider creates an empty list. - * @param customParameter - a custom parameter as the means to customize - * providers extending this class. + * @param properties - custom properties as the means to customize providers. */ public LanguageSettingsBaseProvider(String id, String name, List languages, - List entries, String customParameter) { + List entries, Map properties) { super(id, name); this.languageScope = languages!=null ? new ArrayList(languages) : null; this.entries = getPooledList(entries); - this.customParameter = customParameter; + if (properties != null) + this.properties = new HashMap(properties); } /** @@ -111,21 +111,34 @@ public class LanguageSettingsBaseProvider extends AbstractExecutableExtensionBas * are provided for any language. * @param entries - the list of language settings entries this provider provides. * If {@code null} is passed, the provider creates an empty list. - * @param customParameter - a custom parameter as the means to customize - * providers extending this class from extension definition in {@code plugin.xml}. + * @param properties - custom properties as the means to customize providers. * * @throws UnsupportedOperationException if an attempt to reconfigure provider is made. */ public void configureProvider(String id, String name, List languages, - List entries, String customParameter) { - if (this.entries!=null) + List entries, Map properties) { + if (this.entries!=null || !this.properties.isEmpty()) throw new UnsupportedOperationException(SettingsModelMessages.getString("LanguageSettingsBaseProvider.CanBeConfiguredOnlyOnce")); //$NON-NLS-1$ setId(id); setName(name); this.languageScope = languages!=null ? new ArrayList(languages) : null; this.entries = getPooledList(entries); - this.customParameter = customParameter; + if (properties != null) + this.properties = new HashMap(properties); + } + + /** + * {@code LanguageSettingsBaseProvider} keeps the list of key-value pairs + * so extenders of this class can customize the provider. The properties + * of {@code LanguageSettingsBaseProvider} come from the extension in plugin.xml + * although the extenders can provide their own method. + * + * @param key - property to check the value. + * @return value of the property. + */ + public String getProperty(String key) { + return properties.get(key); } private List getPooledList(List entries) { @@ -168,11 +181,4 @@ public class LanguageSettingsBaseProvider extends AbstractExecutableExtensionBas return null; return Collections.unmodifiableList(languageScope); } - - /** - * @return the custom parameter defined in the extension in {@code plugin.xml}. - */ - public String getCustomParameter() { - return customParameter; - } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableProvider.java index b5f0f63d29a..69698156d79 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableProvider.java @@ -44,9 +44,7 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr private static final String ELEM_LANGUAGE_SCOPE = "language-scope"; //$NON-NLS-1$ private static final String ATTR_NAME = "name"; //$NON-NLS-1$ private static final String ATTR_CLASS = "class"; //$NON-NLS-1$ - private static final String ATTR_PARAMETER = "parameter"; //$NON-NLS-1$ - private Map properties = new HashMap(); private LanguageSettingsSerializableStorage fStorage = new LanguageSettingsSerializableStorage(); /** @@ -78,9 +76,9 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr } @Override - public void configureProvider(String id, String name, List languages, List entries, String customParameter) { + public void configureProvider(String id, String name, List languages, List entries, Map properties) { // do not pass entries to super, keep them in local storage - super.configureProvider(id, name, languages, null, customParameter); + super.configureProvider(id, name, languages, null, properties); fStorage.clear(); @@ -113,16 +111,6 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr this.languageScope = new ArrayList(languages); } - /** - * Set custom parameter for the provider. - * Subclasses are free to define how their behavior depends on custom parameter. - * - * @param customParameter - */ - public void setCustomParameter(String customParameter) { - this.customParameter = customParameter; - } - /** * Clear all the entries for all configurations, all resources and all languages. */ @@ -218,8 +206,6 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr attributes.add(getName()); attributes.add(ATTR_CLASS); attributes.add(getClass().getCanonicalName()); - attributes.add(ATTR_PARAMETER); - attributes.add(getCustomParameter()); for (Entry entry : properties.entrySet()) { attributes.add(entry.getKey()); attributes.add(entry.getValue()); @@ -281,7 +267,6 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr public void loadAttributes(Element providerNode) { String providerId = XmlUtil.determineAttributeValue(providerNode, ATTR_ID); String providerName = XmlUtil.determineAttributeValue(providerNode, ATTR_NAME); - String providerParameter = XmlUtil.determineAttributeValue(providerNode, ATTR_PARAMETER); properties.clear(); NamedNodeMap attrs = providerNode.getAttributes(); @@ -298,7 +283,6 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr this.setId(providerId); this.setName(providerName); - this.setCustomParameter(providerParameter); NodeList nodes = providerNode.getChildNodes(); for (int i=0;i ceAttributes = new HashMap(); List languages = null; List entries = null; + for (String attr : ce.getAttributeNames()) { + ceAttributes.put(attr, determineAttributeValue(ce, attr)); + } + for (IConfigurationElement ceLang : ce.getChildren(ELEM_LANGUAGE_SCOPE)) { String langId = determineAttributeValue(ceLang, ATTR_ID); if (langId.length() > 0) { @@ -203,7 +208,7 @@ public class LanguageSettingsExtensionManager { } if (provider instanceof LanguageSettingsBaseProvider) { - ((LanguageSettingsBaseProvider) provider).configureProvider(ceId, ceName, languages, entries, ceParameter); + ((LanguageSettingsBaseProvider) provider).configureProvider(ceId, ceName, languages, entries, ceAttributes); } else if (provider instanceof AbstractExecutableExtensionBase) { ((AbstractExecutableExtensionBase) provider).setId(ceId); ((AbstractExecutableExtensionBase) provider).setName(ceName); From 540bcb255871150c882ae589829fca6d6544099b Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Tue, 6 Dec 2011 09:20:36 -0500 Subject: [PATCH 079/120] Unit test fixed --- .../settings/providers/LanguageSettingsExtensionsTests.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java index 40dc2fc9439..84c3131e254 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java @@ -46,6 +46,7 @@ public class LanguageSettingsExtensionsTests extends BaseTestCase { /*package*/ static final String EXTENSION_BASE_SUBCLASS_PROVIDER_PARAMETER = "custom parameter subclass"; /*package*/ static final String EXTENSION_SERIALIZABLE_PROVIDER_ID = "org.eclipse.cdt.core.tests.custom.serializable.language.settings.provider"; /*package*/ static final String EXTENSION_SERIALIZABLE_PROVIDER_NAME = "Test Plugin Mock Serializable Language Settings Provider"; + /*package*/ static final String EXTENSION_SERIALIZABLE_PROVIDER_MISSING_PARAMETER = "parameter"; /*package*/ static final String EXTENSION_EDITABLE_PROVIDER_ID = "org.eclipse.cdt.core.tests.custom.editable.language.settings.provider"; /*package*/ static final String EXTENSION_EDITABLE_PROVIDER_NAME = "Test Plugin Mock Editable Language Settings Provider"; /*package*/ static final String EXTENSION_REGISTERER_PROVIDER_ID = "org.eclipse.cdt.core.tests.language.settings.listener.registerer.provider"; @@ -264,7 +265,7 @@ public class LanguageSettingsExtensionsTests extends BaseTestCase { LanguageSettingsSerializableProvider provider = (LanguageSettingsSerializableProvider) rawProvider; assertEquals(null, provider.getLanguageScope()); - assertEquals("", provider.getProperty(EXTENSION_BASE_PROVIDER_ATTR_PARAMETER)); + assertEquals(null, provider.getProperty(EXTENSION_SERIALIZABLE_PROVIDER_MISSING_PARAMETER)); List expected = new ArrayList(); expected.add(new CMacroEntry("MACRO", "value", 0)); From 6c57d8f72e0dabbeb1758712d08c39396e1b4e47 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Tue, 6 Dec 2011 17:52:18 -0500 Subject: [PATCH 080/120] Renamed LanguageSettingsProviderAssociation -> LanguageSettingsProviderAssociationManager --- .../scannerconfig/ScannerDiscoveryConsole.java | 4 ++-- .../ScannerDiscoveryGlobalConsole.java | 4 ++-- ...guageSettingsProviderAssociationManager.java} | 16 ++++++++-------- .../providers/LanguageSettingsProviderTab.java | 2 +- .../LanguageSettingsProvidersLabelProvider.java | 4 ++-- 5 files changed, 15 insertions(+), 15 deletions(-) rename core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/{LanguageSettingsProviderAssociation.java => LanguageSettingsProviderAssociationManager.java} (93%) diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/scannerconfig/ScannerDiscoveryConsole.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/scannerconfig/ScannerDiscoveryConsole.java index e5590d9fd43..7b2b9627727 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/scannerconfig/ScannerDiscoveryConsole.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/scannerconfig/ScannerDiscoveryConsole.java @@ -14,7 +14,7 @@ package org.eclipse.cdt.make.internal.ui.scannerconfig; import java.net.URL; import org.eclipse.cdt.internal.ui.buildconsole.CBuildConsole; -import org.eclipse.cdt.internal.ui.language.settings.providers.LanguageSettingsProviderAssociation; +import org.eclipse.cdt.internal.ui.language.settings.providers.LanguageSettingsProviderAssociationManager; public class ScannerDiscoveryConsole extends CBuildConsole { @@ -27,7 +27,7 @@ public class ScannerDiscoveryConsole extends CBuildConsole { */ @Override public void init(String consoleId, String name, URL defaultIconUrl) { - URL iconUrl = LanguageSettingsProviderAssociation.getImageUrl(consoleId); + URL iconUrl = LanguageSettingsProviderAssociationManager.getImageUrl(consoleId); if (iconUrl==null) { iconUrl = defaultIconUrl; } diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/scannerconfig/ScannerDiscoveryGlobalConsole.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/scannerconfig/ScannerDiscoveryGlobalConsole.java index 4ccf5f183b8..ed415ca66e9 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/scannerconfig/ScannerDiscoveryGlobalConsole.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/scannerconfig/ScannerDiscoveryGlobalConsole.java @@ -16,7 +16,7 @@ import java.net.URL; import org.eclipse.cdt.core.ConsoleOutputStream; import org.eclipse.cdt.internal.core.ICConsole; -import org.eclipse.cdt.internal.ui.language.settings.providers.LanguageSettingsProviderAssociation; +import org.eclipse.cdt.internal.ui.language.settings.providers.LanguageSettingsProviderAssociationManager; import org.eclipse.cdt.ui.CDTSharedImages; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.Assert; @@ -91,7 +91,7 @@ public class ScannerDiscoveryGlobalConsole implements ICConsole { } if (console==null) { - URL iconUrl = LanguageSettingsProviderAssociation.getImageUrl(consoleId); + URL iconUrl = LanguageSettingsProviderAssociationManager.getImageUrl(consoleId); if (iconUrl==null) { iconUrl = defaultIconUrl; } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderAssociation.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderAssociationManager.java similarity index 93% rename from core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderAssociation.java rename to core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderAssociationManager.java index 76537635cd5..d936509f9c9 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderAssociation.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderAssociationManager.java @@ -20,7 +20,7 @@ import org.eclipse.cdt.ui.CDTSharedImages; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.dialogs.ICOptionPage; -public class LanguageSettingsProviderAssociation { +public class LanguageSettingsProviderAssociationManager { public static final String LANGUAGE_SETTINGS_PROVIDER_UI = "LanguageSettingsProviderAssociation"; //$NON-NLS-1$ private static final String ELEM_ID_ASSOCIATION = "id-association"; //$NON-NLS-1$ @@ -47,7 +47,7 @@ public class LanguageSettingsProviderAssociation { if (fRegisteredClasses==null) fRegisteredClasses = new ArrayList(); IExtensionRegistry registry = Platform.getExtensionRegistry(); - IExtensionPoint extension = registry.getExtensionPoint(CUIPlugin.PLUGIN_ID, LanguageSettingsProviderAssociation.LANGUAGE_SETTINGS_PROVIDER_UI); + IExtensionPoint extension = registry.getExtensionPoint(CUIPlugin.PLUGIN_ID, LANGUAGE_SETTINGS_PROVIDER_UI); if (extension != null) { IExtension[] extensions = extension.getExtensions(); for (IExtension ext : extensions) { @@ -85,12 +85,12 @@ public class LanguageSettingsProviderAssociation { return url; } } catch (MalformedURLException exception) {} - + loadedIcons.add(url); if (url!=null) { CDTSharedImages.register(url); } - + return url; } @@ -107,7 +107,7 @@ public class LanguageSettingsProviderAssociation { } if (fRegirestedIds.contains(providerId)) { IExtensionRegistry registry = Platform.getExtensionRegistry(); - IExtensionPoint extension = registry.getExtensionPoint(CUIPlugin.PLUGIN_ID, LanguageSettingsProviderAssociation.LANGUAGE_SETTINGS_PROVIDER_UI); + IExtensionPoint extension = registry.getExtensionPoint(CUIPlugin.PLUGIN_ID, LANGUAGE_SETTINGS_PROVIDER_UI); if (extension != null) { IExtension[] extensions = extension.getExtensions(); for (IExtension ext : extensions) { @@ -141,7 +141,7 @@ public class LanguageSettingsProviderAssociation { } if (fRegisteredClasses.contains(providerClassName)) { IExtensionRegistry registry = Platform.getExtensionRegistry(); - IExtensionPoint extension = registry.getExtensionPoint(CUIPlugin.PLUGIN_ID, LanguageSettingsProviderAssociation.LANGUAGE_SETTINGS_PROVIDER_UI); + IExtensionPoint extension = registry.getExtensionPoint(CUIPlugin.PLUGIN_ID, LANGUAGE_SETTINGS_PROVIDER_UI); if (extension != null) { IExtension[] extensions = extension.getExtensions(); for (IExtension ext : extensions) { @@ -178,12 +178,12 @@ public class LanguageSettingsProviderAssociation { */ public static URL getImage(Class clazz) { URL url = null; - + outer: for (Class cl=clazz;cl!=null;cl=cl.getSuperclass()) { url = getImageURL(cl); if (url!=null) break; - + // this does not check for superinterfaces, feel free to implement as needed for (Class in : cl.getInterfaces()) { url = getImageURL(in); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java index cacf3443028..7bb4f148bf7 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java @@ -558,7 +558,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { if (provider!=null) { ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); if (rawProvider!=null) { - optionsPage = LanguageSettingsProviderAssociation.createOptionsPage(rawProvider); + optionsPage = LanguageSettingsProviderAssociationManager.createOptionsPage(rawProvider); } if (optionsPage instanceof AbstractLanguageSettingProviderOptionPage) { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProvidersLabelProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProvidersLabelProvider.java index a64766e8811..829e23aea60 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProvidersLabelProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProvidersLabelProvider.java @@ -38,12 +38,12 @@ class LanguageSettingsProvidersLabelProvider extends LabelProvider { String imageKey = null; // try id-association String id = provider.getId(); - URL url = LanguageSettingsProviderAssociation.getImageUrl(id); + URL url = LanguageSettingsProviderAssociationManager.getImageUrl(id); // try class-association if (url==null) { ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); if (rawProvider!=null) { - url = LanguageSettingsProviderAssociation.getImage(rawProvider.getClass()); + url = LanguageSettingsProviderAssociationManager.getImage(rawProvider.getClass()); } } if (url!=null) { From 6a4136bf9670010d84ba3dfb7884e6048212e6cf Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Thu, 8 Dec 2011 11:36:48 -0500 Subject: [PATCH 081/120] Added "shared", "ui-edit-entries", "ui-clear-entries" to LanguageSettingsProviderAssociation extension point. Removed "Shared provider" checkbox from UI. --- build/org.eclipse.cdt.make.ui/plugin.xml | 6 +- .../plugin.xml | 3 +- core/org.eclipse.cdt.ui/plugin.xml | 3 +- .../LanguageSettingsProviderAssociation.exsd | 42 ++++++++ ...ageSettingsProviderAssociationManager.java | 101 ++++++++++++++++-- .../LanguageSettingsProviderTab.java | 92 ++++++---------- 6 files changed, 175 insertions(+), 72 deletions(-) diff --git a/build/org.eclipse.cdt.make.ui/plugin.xml b/build/org.eclipse.cdt.make.ui/plugin.xml index 3c02054c2da..e836c0d0e41 100644 --- a/build/org.eclipse.cdt.make.ui/plugin.xml +++ b/build/org.eclipse.cdt.make.ui/plugin.xml @@ -545,12 +545,14 @@ + page="org.eclipse.cdt.make.internal.ui.preferences.GCCBuildCommandParserOptionPage" + shared="false"> + page="org.eclipse.cdt.make.internal.ui.scannerconfig.BuiltinSpecsDetectorOptionPage" + shared="true">
    + icon="icons/obj16/mbs.gif" + shared="true"> diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml index 4cbf7d648df..82eb6ddbfff 100644 --- a/core/org.eclipse.cdt.ui/plugin.xml +++ b/core/org.eclipse.cdt.ui/plugin.xml @@ -3805,7 +3805,8 @@ + icon="icons/obj16/person-me.gif" + shared="false"> diff --git a/core/org.eclipse.cdt.ui/schema/LanguageSettingsProviderAssociation.exsd b/core/org.eclipse.cdt.ui/schema/LanguageSettingsProviderAssociation.exsd index 2c14696be15..fbb578b8b20 100644 --- a/core/org.eclipse.cdt.ui/schema/LanguageSettingsProviderAssociation.exsd +++ b/core/org.eclipse.cdt.ui/schema/LanguageSettingsProviderAssociation.exsd @@ -77,6 +77,27 @@
    + + + + + + + + + + + + + + + + + + + + +
    @@ -112,6 +133,27 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderAssociationManager.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderAssociationManager.java index d936509f9c9..b21baff9ce4 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderAssociationManager.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderAssociationManager.java @@ -29,12 +29,18 @@ public class LanguageSettingsProviderAssociationManager { 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_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_EDIT_ENTRIES = "ui-edit-entries"; //$NON-NLS-1$ - static private List loadedIcons = null; - static private Map fImagesUrlById = null; - static private Map fImagesUrlByClass = null; - static private List fRegirestedIds = null; - static private List fRegisteredClasses = null; + private static List loadedIcons = null; + private static Map fImagesUrlById = null; + private static Map fImagesUrlByClass = null; + private static List fRegirestedIds = null; + private static List fRegisteredClasses = null; + + private static Map> fAssociationsById = null; + private static Map> fAssociationsByClass = null; private static void loadExtensions() { if (loadedIcons!=null) { @@ -46,6 +52,9 @@ public class LanguageSettingsProviderAssociationManager { if (fRegirestedIds==null) fRegirestedIds = new ArrayList(); if (fRegisteredClasses==null) fRegisteredClasses = new ArrayList(); + if (fAssociationsById==null) fAssociationsById = new HashMap>(); + if (fAssociationsByClass==null) fAssociationsByClass = new HashMap>(); + IExtensionRegistry registry = Platform.getExtensionRegistry(); IExtensionPoint extension = registry.getExtensionPoint(CUIPlugin.PLUGIN_ID, LANGUAGE_SETTINGS_PROVIDER_UI); if (extension != null) { @@ -59,14 +68,28 @@ public class LanguageSettingsProviderAssociationManager { URL url = getIconUrl(cfgEl); fImagesUrlById.put(id, url); fRegirestedIds.add(id); + + Map properties = new HashMap(); + 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_EDIT_ENTRIES, cfgEl.getAttribute(ATTR_UI_EDIT_ENTRIES)); + fAssociationsById.put(id, properties); } else if (cfgEl.getName().equals(ELEM_CLASS_ASSOCIATION)) { String className = cfgEl.getAttribute(ATTR_CLASS); URL url = getIconUrl(cfgEl); fImagesUrlByClass.put(className, url); String pageClass = cfgEl.getAttribute(ATTR_PAGE); - if (pageClass!=null && pageClass.trim().length()>0) { + if (pageClass!=null && pageClass.length()>0) { fRegisteredClasses.add(className); } + + Map properties = new HashMap(); + 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_EDIT_ENTRIES, cfgEl.getAttribute(ATTR_UI_EDIT_ENTRIES)); + fAssociationsByClass.put(className, properties); } } } @@ -74,6 +97,11 @@ public class LanguageSettingsProviderAssociationManager { } + private static void sensiblePut(Map properties, String key, String value) { + if (value != null) + properties.put(key, value); + } + private static URL getIconUrl(IConfigurationElement config) { URL url = null; try { @@ -242,5 +270,66 @@ public class LanguageSettingsProviderAssociationManager { return optionsPage; } + /** + * Returns TODO for id or closest superclass. + * @param provider TODO + * @return TODO + */ + private static boolean getBooleanAttribute(ILanguageSettingsProvider provider, String attr) { + loadExtensions(); + + String id = provider.getId(); + + Map properties = fAssociationsById.get(id); + if (properties != null) { + return Boolean.parseBoolean(properties.get(attr)); + } + + for (Class clazz=provider.getClass();clazz!=null;clazz=clazz.getSuperclass()) { + String className = clazz.getCanonicalName(); + properties = fAssociationsByClass.get(className); + if (properties != null) { + return Boolean.parseBoolean(properties.get(attr)); + } + + // this does not check for superinterfaces, feel free to implement as needed + for (Class iface : clazz.getInterfaces()) { + String interfaceName = iface.getCanonicalName(); + properties = fAssociationsByClass.get(interfaceName); + if (properties != null) { + return Boolean.parseBoolean(properties.get(attr)); + } + } + } + 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. + * @param provider TODO + * @return TODO + */ + public static boolean isToClear(ILanguageSettingsProvider provider) { + return getBooleanAttribute(provider, ATTR_UI_CLEAR_ENTRIES); + } + + /** + * Returns TODO for id or closest superclass. + * @param provider TODO + * @return TODO + */ + public static boolean isToEditEntries(ILanguageSettingsProvider provider) { + return getBooleanAttribute(provider, ATTR_UI_EDIT_ENTRIES); + } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java index 7bb4f148bf7..186e4b4553b 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java @@ -118,7 +118,6 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { private Button enableProvidersCheckBox; private StatusMessageLine fStatusLine; - private Button globalProviderCheckBox = null; private Link linkWorkspacePreferences = null; private Button projectStorageCheckBox = null; @@ -303,9 +302,35 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { tableProvidersViewer.addCheckStateListener(new ICheckStateListener() { @Override - public void checkStateChanged(CheckStateChangedEvent e) { - saveCheckedProviders(e.getElement()); - tableProvidersViewer.update(e.getElement(), null); + public void checkStateChanged(CheckStateChangedEvent event) { + // TODO: clean-up - too many manipulations in this method + + ILanguageSettingsProvider provider = (ILanguageSettingsProvider) event.getElement(); + saveCheckedProviders(provider); + + int pos = presentedProviders.indexOf(provider); + tableProviders.setSelection(pos); + + if (event.getChecked() && LanguageSettingsManager.isWorkspaceProvider(provider)) { + ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); + if (!LanguageSettingsProviderAssociationManager.shouldBeShared(rawProvider)) { + // Switch to local provider instance + try { + if (rawProvider instanceof ILanguageSettingsEditableProvider) { + provider = ((ILanguageSettingsEditableProvider) rawProvider).cloneShallow(); + } + } catch (CloneNotSupportedException e) { + CUIPlugin.log("Error cloning provider " + provider.getId(), e); + } + + replaceSelectedProvider(provider); + ICConfigurationDescription cfgDescription = getConfigurationDescription(); + initializeOptionsPage(provider, cfgDescription); + displaySelectedOptionPage(); + } + } + + tableProvidersViewer.update(provider, null); }}); createOptionsControl(); @@ -331,37 +356,6 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { return link; } - // Called from globalProviderCheckBox listener - private ILanguageSettingsProvider toggleGlobalProvider(ILanguageSettingsProvider oldProvider, boolean toGlobal) { - ILanguageSettingsProvider newProvider = null; - - String id = oldProvider.getId(); - if (toGlobal) { - newProvider = LanguageSettingsManager.getWorkspaceProvider(id); - } else { - // Local provider instance chosen - try { - ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(oldProvider); - if (rawProvider instanceof ILanguageSettingsEditableProvider) { - newProvider = ((ILanguageSettingsEditableProvider) rawProvider).cloneShallow(); - } - } catch (CloneNotSupportedException e) { - CUIPlugin.log("Error cloning provider " + oldProvider.getId(), e); - } - } - if (newProvider!=null) { - replaceSelectedProvider(newProvider); - - ICConfigurationDescription cfgDescription = getConfigurationDescription(); - initializeOptionsPage(newProvider, cfgDescription); - displaySelectedOptionPage(); - } else { - newProvider = oldProvider; - } - - return newProvider; - } - private void replaceSelectedProvider(ILanguageSettingsProvider newProvider) { int pos = tableProviders.getSelectionIndex(); presentedProviders.set(pos, newProvider); @@ -394,28 +388,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { groupOptionsPage.setLayout(new GridLayout(2, false)); if (!page.isForPrefs()) { - if (globalProviderCheckBox==null) { - globalProviderCheckBox = new Button(groupOptionsPage, SWT.CHECK); - globalProviderCheckBox.setText("Share setting entries between projects (global provider)"); - globalProviderCheckBox.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - boolean isGlobal = globalProviderCheckBox.getSelection(); - ILanguageSettingsProvider provider = getSelectedProvider(); - if (isGlobal != LanguageSettingsManager.isWorkspaceProvider(provider)) { - provider = toggleGlobalProvider(provider, isGlobal); - } - projectStorageCheckBox.setSelection(provider instanceof LanguageSettingsSerializableProvider - && LanguageSettingsManager.isStoringEntriesInProjectArea((LanguageSettingsSerializableProvider) provider)); - } - - @Override - public void widgetDefaultSelected(SelectionEvent e) { - widgetSelected(e); - } - - }); - + if (projectStorageCheckBox == null) { projectStorageCheckBox = new Button(groupOptionsPage, SWT.CHECK); projectStorageCheckBox.setText("Store entries in project settings folder (supporting project miration)"); projectStorageCheckBox.addSelectionListener(new SelectionAdapter() { @@ -603,11 +576,6 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { boolean isChecked = tableProvidersViewer.getChecked(provider); if (!page.isForPrefs()) { - boolean isRawProviderEditable = rawProvider instanceof ILanguageSettingsEditableProvider; - globalProviderCheckBox.setSelection(isGlobal); - globalProviderCheckBox.setEnabled(isChecked && isRawProviderEditable); - globalProviderCheckBox.setVisible(provider!=null); - projectStorageCheckBox.setEnabled(!isGlobal); projectStorageCheckBox.setVisible(rawProvider instanceof LanguageSettingsSerializableProvider); projectStorageCheckBox.setSelection(provider instanceof LanguageSettingsSerializableProvider From c9b2608713729c5e8bf8ea23cbf6b1d5625ba26c Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Thu, 8 Dec 2011 12:23:29 -0500 Subject: [PATCH 082/120] Use "shared" attribute from LanguageSettingsProviderAssociation extension rather than star "*" in toolchain definition. --- .../core/ManagedBuildManager.java | 88 ------------- .../plugin.xml | 6 +- .../ui/wizards/MBSWizardHandler.java | 122 +++++++++++++++--- .../ui/wizards/NewMakeProjFromExisting.java | 11 +- .../ui/wizards/STDWizardHandler.java | 30 ++--- .../plugin.xml | 12 +- 6 files changed, 134 insertions(+), 135 deletions(-) diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java index fd2bceeeb25..12ad3f2750a 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java @@ -49,8 +49,6 @@ import javax.xml.transform.stream.StreamResult; import org.eclipse.cdt.core.AbstractCExtension; import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; -import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModelUtil; import org.eclipse.cdt.core.parser.IScannerInfo; @@ -191,10 +189,6 @@ public class ManagedBuildManager extends AbstractCExtension { public static final String INTERNAL_BUILDER_ID = "org.eclipse.cdt.build.core.internal.builder"; //$NON-NLS-1$ - public static final String MBS_LANGUAGE_SETTINGS_PROVIDER = "org.eclipse.cdt.managedbuilder.core.LanguageSettingsProvider"; - private static final String UI_USER_LANGUAGE_SETTINGS_PROVIDER = "org.eclipse.cdt.ui.user.LanguageSettingsProvider"; - private static final String LANGUAGE_SETTINGS_PROVIDER_DELIMITER = ";"; - private static final String os = Platform.getOS(); private static final String arch = Platform.getOSArch(); private static final String ALL = "all"; //$NON-NLS-1$ @@ -4726,86 +4720,4 @@ public class ManagedBuildManager extends AbstractCExtension { return true; // no target platform - nothing to check. } - 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 ""; - } - - public static List getLanguageSettingsProviders(IConfiguration cfg) { - List providers = new ArrayList(); - - String providersIdsStr = getLanguageSettingsProvidersStr(cfg); - if (providersIdsStr!=null) { - if (providersIdsStr.contains("${Toolchain}")) { - IToolChain toolchain = cfg.getToolChain(); - String toolchainProvidersIds = getLanguageSettingsProvidersStr(toolchain); - if (toolchainProvidersIds==null) { - toolchainProvidersIds=""; - } - providersIdsStr = providersIdsStr.replaceAll("\\$\\{Toolchain\\}", toolchainProvidersIds); - } - List providersIds = Arrays.asList(providersIdsStr.split(LANGUAGE_SETTINGS_PROVIDER_DELIMITER)); - for (String id : providersIds) { - id = id.trim(); - ILanguageSettingsProvider provider = null; - if (id.startsWith("*")) { - id = id.substring(1); - provider = LanguageSettingsManager.getWorkspaceProvider(id); - } else 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){ - provider = LanguageSettingsManager.getExtensionProviderCopy(id); - } - 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); - providers.add(0, provider); - } - - return providers; - } - - private static boolean isProviderThere(List providers, String id) { - for (ILanguageSettingsProvider provider : providers) { - if (provider.getId().equals(id)) { - return true; - } - } - return false; - } - } diff --git a/build/org.eclipse.cdt.managedbuilder.gnu.ui/plugin.xml b/build/org.eclipse.cdt.managedbuilder.gnu.ui/plugin.xml index fe404978003..7a0e84ae36e 100644 --- a/build/org.eclipse.cdt.managedbuilder.gnu.ui/plugin.xml +++ b/build/org.eclipse.cdt.managedbuilder.gnu.ui/plugin.xml @@ -1672,7 +1672,7 @@ @@ -1740,7 +1740,7 @@ configurationEnvironmentSupplier="org.eclipse.cdt.managedbuilder.gnu.cygwin.GnuCygwinConfigurationEnvironmentSupplier" id="cdt.managedbuild.toolchain.gnu.cygwin.base" isToolChainSupported="org.eclipse.cdt.managedbuilder.gnu.cygwin.IsGnuCygwinToolChainSupported" - languageSettingsProviders="org.eclipse.cdt.make.core.build.command.parser.gcc;*org.eclipse.cdt.managedbuilder.core.cygwin.gcc.specs.detector" + languageSettingsProviders="org.eclipse.cdt.make.core.build.command.parser.gcc;org.eclipse.cdt.managedbuilder.core.cygwin.gcc.specs.detector" name="%ToolChainName.Cygwin" osList="win32" targetTool="cdt.managedbuild.tool.gnu.cpp.linker.cygwin.base;cdt.managedbuild.tool.gnu.c.linker.cygwin.base;cdt.managedbuild.tool.gnu.archiver"> @@ -1810,7 +1810,7 @@ configurationEnvironmentSupplier="org.eclipse.cdt.managedbuilder.gnu.mingw.MingwEnvironmentVariableSupplier" id="cdt.managedbuild.toolchain.gnu.mingw.base" isToolChainSupported="org.eclipse.cdt.managedbuilder.gnu.mingw.MingwIsToolChainSupported" - languageSettingsProviders="org.eclipse.cdt.make.core.build.command.parser.gcc;*org.eclipse.cdt.managedbuilder.core.gcc.specs.detector" + languageSettingsProviders="org.eclipse.cdt.make.core.build.command.parser.gcc;org.eclipse.cdt.managedbuilder.core.gcc.specs.detector" name="%ToolChainName.MinGW" osList="win32" targetTool="cdt.managedbuild.tool.gnu.cpp.linker.mingw.base;cdt.managedbuild.tool.gnu.c.linker.mingw.base;cdt.managedbuild.tool.gnu.archiver"> diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/MBSWizardHandler.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/MBSWizardHandler.java index e8f532e79c6..5139b36cfbb 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/MBSWizardHandler.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/MBSWizardHandler.java @@ -33,6 +33,7 @@ import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager; import org.eclipse.cdt.core.settings.model.extension.CConfigurationData; import org.eclipse.cdt.core.templateengine.process.ProcessFailureException; +import org.eclipse.cdt.internal.ui.language.settings.providers.LanguageSettingsProviderAssociationManager; import org.eclipse.cdt.internal.ui.wizards.ICDTCommonProjectWizard; import org.eclipse.cdt.managedbuilder.buildproperties.IBuildProperty; import org.eclipse.cdt.managedbuilder.buildproperties.IBuildPropertyValue; @@ -91,6 +92,11 @@ public class MBSWizardHandler extends CWizardHandler { private static final String PROPERTY = "org.eclipse.cdt.build.core.buildType"; //$NON-NLS-1$ private static final String PROP_VAL = PROPERTY + ".debug"; //$NON-NLS-1$ + + private static final String UI_USER_LANGUAGE_SETTINGS_PROVIDER = "org.eclipse.cdt.ui.user.LanguageSettingsProvider"; + public static final String MBS_LANGUAGE_SETTINGS_PROVIDER = "org.eclipse.cdt.managedbuilder.core.LanguageSettingsProvider"; + private static final String LANGUAGE_SETTINGS_PROVIDER_DELIMITER = ";"; + private static final String tooltip = Messages.CWizardHandler_1 + Messages.CWizardHandler_2 + @@ -550,13 +556,6 @@ public class MBSWizardHandler extends CWizardHandler { } private void setProjectDescription(IProject project, boolean defaults, boolean onFinish, IProgressMonitor monitor) throws CoreException { - boolean isTryingNewSD = false; - IWizardPage page = getStartingPage(); - if (page instanceof CDTMainWizardPage) { - CDTMainWizardPage mainWizardPage = (CDTMainWizardPage)page; - isTryingNewSD = mainWizardPage.isTryingNewSD(); - } - ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager(); ICProjectDescription des = mngr.createProjectDescription(project, false, !onFinish); ManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project); @@ -604,16 +603,21 @@ public class MBSWizardHandler extends CWizardHandler { cfgFirst = cfgDes; if (cfgDes instanceof ILanguageSettingsProvidersKeeper) { - ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, isTryingNewSD); - if (isTryingNewSD) { - List providers = ManagedBuildManager.getLanguageSettingsProviders(config); - ((ILanguageSettingsProvidersKeeper) cfgDes).setLanguageSettingProviders(providers); - } else { - ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(ManagedBuildManager.MBS_LANGUAGE_SETTINGS_PROVIDER); - List providers = new ArrayList(); - providers.add(provider); - ((ILanguageSettingsProvidersKeeper) cfgDes).setLanguageSettingProviders(providers); + boolean isTryingNewSD = false; + IWizardPage page = getStartingPage(); + if (page instanceof CDTMainWizardPage) { + isTryingNewSD = ((CDTMainWizardPage)page).isTryingNewSD(); } + + ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, isTryingNewSD); + List providers; + if (isTryingNewSD) { + providers = MBSWizardHandler.getLanguageSettingsProviders(config); + } else { + providers = new ArrayList(); + providers.add(LanguageSettingsManager.getWorkspaceProvider(MBSWizardHandler.MBS_LANGUAGE_SETTINGS_PROVIDER)); + } + ((ILanguageSettingsProvidersKeeper) cfgDes).setLanguageSettingProviders(providers); } else { ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, false); } @@ -861,5 +865,91 @@ public class MBSWizardHandler extends CWizardHandler { return super.canFinish(); } + private static String getLanguageSettingsProvidersStr(IToolChain toolchain) { + for (;toolchain!=null;toolchain=toolchain.getSuperClass()) { + String providersIdsStr = toolchain.getDefaultLanguageSettingsProvidersIds(); + if (providersIdsStr!=null) { + return providersIdsStr; + } + } + return ""; + } + + private static String getLanguageSettingsProvidersStr(IConfiguration cfg) { + for (;cfg!=null;cfg=cfg.getParent()) { + String providersIdsStr = cfg.getDefaultLanguageSettingsProvidersIds(); + if (providersIdsStr!=null) { + return providersIdsStr; + } + } + return ""; + } + + public static List getLanguageSettingsProviders(IConfiguration cfg) { + List providers = new ArrayList(); + + String providersIdsStr = getLanguageSettingsProvidersStr(cfg); + if (providersIdsStr!=null) { + if (providersIdsStr.contains("${Toolchain}")) { + IToolChain toolchain = cfg.getToolChain(); + String toolchainProvidersIds = getLanguageSettingsProvidersStr(toolchain); + if (toolchainProvidersIds==null) { + toolchainProvidersIds=""; + } + providersIdsStr = providersIdsStr.replaceAll("\\$\\{Toolchain\\}", toolchainProvidersIds); + } + List providersIds = Arrays.asList(providersIdsStr.split(LANGUAGE_SETTINGS_PROVIDER_DELIMITER)); + for (String id : providersIds) { + id = id.trim(); + ILanguageSettingsProvider provider = null; + if (id.startsWith("-")) { + id = id.substring(1); + for (ILanguageSettingsProvider pr : providers) { + if (pr.getId().equals(id)) { + providers.remove(pr); + // Has to break as the collection is invalidated + // TODO: remove all elements or better use unique list + break; + } + } + } else if (id.length()>0){ + // TODO - look into saving on copying, need to figure out "shared" attribute from extension provider directly + ILanguageSettingsProvider providerExt = LanguageSettingsManager.getExtensionProviderCopy(id); + if (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); + providers.add(0, provider); + } + + return providers; + } + + private static boolean isProviderThere(List providers, String id) { + for (ILanguageSettingsProvider provider : providers) { + if (provider.getId().equals(id)) { + return true; + } + } + return false; + } + } diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/NewMakeProjFromExisting.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/NewMakeProjFromExisting.java index 19a71657fc4..cf44315d0c6 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/NewMakeProjFromExisting.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/NewMakeProjFromExisting.java @@ -122,15 +122,14 @@ public class NewMakeProjFromExisting extends Wizard implements IImportWizard, IN if (cfgDes instanceof ILanguageSettingsProvidersKeeper) { ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, isTryingNewSD); + List providers; if (isTryingNewSD) { - List providers = ManagedBuildManager.getLanguageSettingsProviders(config); - ((ILanguageSettingsProvidersKeeper) cfgDes).setLanguageSettingProviders(providers); + providers = MBSWizardHandler.getLanguageSettingsProviders(config); } else { - ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(ManagedBuildManager.MBS_LANGUAGE_SETTINGS_PROVIDER); - List providers = new ArrayList(); - providers.add(provider); - ((ILanguageSettingsProvidersKeeper) cfgDes).setLanguageSettingProviders(providers); + providers = new ArrayList(); + providers.add(LanguageSettingsManager.getWorkspaceProvider(MBSWizardHandler.MBS_LANGUAGE_SETTINGS_PROVIDER)); } + ((ILanguageSettingsProvidersKeeper) cfgDes).setLanguageSettingProviders(providers); } else { ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, false); } diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/STDWizardHandler.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/STDWizardHandler.java index 6ac895391ed..5232b3a0d7b 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/STDWizardHandler.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/STDWizardHandler.java @@ -82,13 +82,6 @@ public class STDWizardHandler extends MBSWizardHandler { private void setProjectDescription(IProject project, boolean defaults, boolean onFinish, IProgressMonitor monitor) throws CoreException { - boolean isTryingNewSD = false; - IWizardPage page = getStartingPage(); - if (page instanceof CDTMainWizardPage) { - CDTMainWizardPage mainWizardPage = (CDTMainWizardPage)page; - isTryingNewSD = mainWizardPage.isTryingNewSD(); - } - ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager(); ICProjectDescription des = mngr.createProjectDescription(project, false, !onFinish); ManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project); @@ -120,16 +113,21 @@ public class STDWizardHandler extends MBSWizardHandler { ICConfigurationDescription cfgDes = des.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID, data); if (cfgDes instanceof ILanguageSettingsProvidersKeeper) { - ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, isTryingNewSD); - if (isTryingNewSD) { - List providers = ManagedBuildManager.getLanguageSettingsProviders(cfg); - ((ILanguageSettingsProvidersKeeper) cfgDes).setLanguageSettingProviders(providers); - } else { - ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(ManagedBuildManager.MBS_LANGUAGE_SETTINGS_PROVIDER); - List providers = new ArrayList(); - providers.add(provider); - ((ILanguageSettingsProvidersKeeper) cfgDes).setLanguageSettingProviders(providers); + boolean isTryingNewSD = false; + IWizardPage page = getStartingPage(); + if (page instanceof CDTMainWizardPage) { + isTryingNewSD = ((CDTMainWizardPage)page).isTryingNewSD(); } + + ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, isTryingNewSD); + List providers; + if (isTryingNewSD) { + providers = MBSWizardHandler.getLanguageSettingsProviders(cfg); + } else { + providers = new ArrayList(); + providers.add(LanguageSettingsManager.getWorkspaceProvider(MBSWizardHandler.MBS_LANGUAGE_SETTINGS_PROVIDER)); + } + ((ILanguageSettingsProvidersKeeper) cfgDes).setLanguageSettingProviders(providers); } else { ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, false); } diff --git a/xlc/org.eclipse.cdt.managedbuilder.xlc.ui/plugin.xml b/xlc/org.eclipse.cdt.managedbuilder.xlc.ui/plugin.xml index 1a3575471fd..5b40309bd7c 100644 --- a/xlc/org.eclipse.cdt.managedbuilder.xlc.ui/plugin.xml +++ b/xlc/org.eclipse.cdt.managedbuilder.xlc.ui/plugin.xml @@ -534,7 +534,7 @@ id="cdt.managedbuild.toolchain.xlc.exe.debug" name="%ToolChainName.Dbg" osList="all" - languageSettingsProviders="org.eclipse.cdt.managedbuilder.xlc.core.xlc.build.command.parser;*org.eclipse.cdt.managedbuilder.xlc.core.xlc.specs.detector" + languageSettingsProviders="org.eclipse.cdt.managedbuilder.xlc.core.xlc.build.command.parser;org.eclipse.cdt.managedbuilder.xlc.core.xlc.specs.detector" targetTool="cdt.managedbuild.tool.xlc.c.linker.exe.debug;cdt.managedbuild.tool.xlc.cpp.linker.exe.debug"> Date: Thu, 8 Dec 2011 15:22:51 -0500 Subject: [PATCH 083/120] Disallow clearing and editing entries for specific providers in UI --- build/org.eclipse.cdt.make.ui/plugin.xml | 8 +++++-- .../plugin.xml | 4 +++- core/org.eclipse.cdt.ui/plugin.xml | 4 +++- .../providers/LanguageSettingsEntriesTab.java | 21 ++++++++++++------- .../LanguageSettingsProviderTab.java | 11 ++++------ 5 files changed, 29 insertions(+), 19 deletions(-) diff --git a/build/org.eclipse.cdt.make.ui/plugin.xml b/build/org.eclipse.cdt.make.ui/plugin.xml index e836c0d0e41..198ae158db7 100644 --- a/build/org.eclipse.cdt.make.ui/plugin.xml +++ b/build/org.eclipse.cdt.make.ui/plugin.xml @@ -546,13 +546,17 @@ class="org.eclipse.cdt.make.core.scannerconfig.AbstractBuildCommandParser" icon="icons/obj16/log_obj.gif" page="org.eclipse.cdt.make.internal.ui.preferences.GCCBuildCommandParserOptionPage" - shared="false"> + shared="false" + ui-clear-entries="true" + ui-edit-entries="false"> + shared="true" + ui-clear-entries="true" + ui-edit-entries="false"> + shared="true" + ui-clear-entries="false" + ui-edit-entries="false"> diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml index 82eb6ddbfff..c5edfdb366e 100644 --- a/core/org.eclipse.cdt.ui/plugin.xml +++ b/core/org.eclipse.cdt.ui/plugin.xml @@ -3806,7 +3806,9 @@ + shared="false" + ui-clear-entries="true" + ui-edit-entries="true"> diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java index 183a6df53db..323117a39b1 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java @@ -511,17 +511,20 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { boolean isEntrySelected = entry!=null; boolean isProviderSelected = !isEntrySelected && (provider!=null); - boolean isProviderEditable = provider instanceof ILanguageSettingsEditableProvider; -// boolean isUserProvider = provider instanceof UserLanguageSettingsProvider; + boolean isAllowedEditing = provider instanceof ILanguageSettingsEditableProvider + && LanguageSettingsProviderAssociationManager.isToEditEntries(provider); - boolean canAdd = isProviderEditable; - boolean canEdit = isProviderEditable && isEntrySelected; - boolean canDelete = isProviderEditable && isEntrySelected; - boolean canClear = isProviderEditable && isProviderSelected && entries!=null && entries.size()>0; + boolean isAllowedClearing = provider instanceof ILanguageSettingsEditableProvider + && LanguageSettingsProviderAssociationManager.isToClear(provider); + + boolean canAdd = isAllowedEditing; + boolean canEdit = isAllowedEditing && isEntrySelected; + boolean canDelete = isAllowedEditing && isEntrySelected; + boolean canClear = isAllowedClearing && isProviderSelected && entries!=null && entries.size()>0; boolean canMoveUp = false; boolean canMoveDown = false; - if (isProviderEditable && isEntrySelected && entries!=null) { + if (isAllowedEditing && isEntrySelected && entries!=null) { int last = entries.size()-1; int pos = getExactIndex(entries, entry); @@ -552,7 +555,9 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { } if (status==null || status==Status.OK_STATUS) { ILanguageSettingsProvider provider = getSelectedProvider(); - if (provider!=null && !(provider instanceof ILanguageSettingsBroadcastingProvider)) { + boolean isAllowedEditing = provider instanceof ILanguageSettingsEditableProvider + && LanguageSettingsProviderAssociationManager.isToEditEntries(provider); + if (!isAllowedEditing) { String msg = "Setting entries for this provider are supplied by system and are not editable."; status = new Status(IStatus.INFO, CUIPlugin.PLUGIN_ID, msg); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java index 186e4b4553b..b641d2c7c65 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java @@ -652,13 +652,10 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { boolean isRangeOk = pos >= 0 && pos <= last; ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); - boolean canClear = false; - if (rawProvider instanceof ILanguageSettingsEditableProvider) { - // TODO - commented out because we need the means to restart failed Spec Detectors -// if (!((ILanguageSettingsEditableProvider) rawProvider).isEmpty()) { - canClear = canForWorkspace || canForProject; -// } - } + boolean isAllowedClearing = rawProvider instanceof ILanguageSettingsEditableProvider + && LanguageSettingsProviderAssociationManager.isToClear(rawProvider); + + boolean canClear = isAllowedClearing && (canForWorkspace || canForProject); boolean canReset = false; if (rawProvider!=null && (canForWorkspace || canForProject)) { From 377cbf3b8a7d50369c9197a833911ca56fd7038e Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Thu, 8 Dec 2011 16:03:21 -0500 Subject: [PATCH 084/120] Disabled overly intrusive decorators, revised some wording --- .../providers/LanguageSettingsLogger.java | 3 +-- core/org.eclipse.cdt.ui/plugin.xml | 2 +- .../providers/LanguageSettingsProviderTab.java | 4 ++-- .../LanguageSettingsProvidersLabelProvider.java | 16 ++++++++++++---- .../cdt/internal/ui/newui/Messages.properties | 2 +- 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsLogger.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsLogger.java index 0f13e949067..37ab0530aa9 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsLogger.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsLogger.java @@ -13,8 +13,7 @@ import org.eclipse.core.runtime.Status; */ @Deprecated public class LanguageSettingsLogger { - - public static boolean isEnabled() { + private static boolean isEnabled() { return false; // return true; } diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml index c5edfdb366e..105406c2347 100644 --- a/core/org.eclipse.cdt.ui/plugin.xml +++ b/core/org.eclipse.cdt.ui/plugin.xml @@ -2891,7 +2891,7 @@
    diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java index b641d2c7c65..fd765d7baf6 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java @@ -390,7 +390,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { if (!page.isForPrefs()) { if (projectStorageCheckBox == null) { projectStorageCheckBox = new Button(groupOptionsPage, SWT.CHECK); - projectStorageCheckBox.setText("Store entries in project settings folder (supporting project miration)"); + projectStorageCheckBox.setText("Store entries in project settings folder (easing project miration)"); projectStorageCheckBox.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { @@ -583,7 +583,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { boolean needPreferencesLink=isGlobal && currentOptionsPage!=null; // TODO: message - final String linkMsg = needPreferencesLink ? "Options of global providers can be changed in Workspace Settings, Discovery Tab." : ""; + final String linkMsg = needPreferencesLink ? "Options of shared providers below can be changed in Workspace Settings, Discovery Tab." : ""; linkWorkspacePreferences.setText(linkMsg); linkWorkspacePreferences.pack(); linkWorkspacePreferences.setEnabled(isChecked); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProvidersLabelProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProvidersLabelProvider.java index 829e23aea60..e7164dbbde4 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProvidersLabelProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProvidersLabelProvider.java @@ -27,7 +27,7 @@ import org.eclipse.cdt.ui.CDTSharedImages; * Label provider for language settings providers. * */ -class LanguageSettingsProvidersLabelProvider extends LabelProvider { +public class LanguageSettingsProvidersLabelProvider extends LabelProvider { private static final String TEST_PLUGIN_ID_PATTERN = "org.eclipse.cdt.*.tests.*"; //$NON-NLS-1$ private static final String OOPS = "OOPS"; //$NON-NLS-1$ @@ -65,9 +65,8 @@ class LanguageSettingsProvidersLabelProvider extends LabelProvider { */ protected String[] getOverlayKeys(ILanguageSettingsProvider provider) { String[] overlayKeys = new String[5]; - { // TODO temporary for debugging -// boolean isSpecial = provider.getId().equals(LegacySupport.MBS_LANGUAGE_SETTINGS_PROVIDER); + if (isDebugging()) { // TODO temporary for debugging ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); if (rawProvider instanceof LanguageSettingsSerializableProvider) { if (((LanguageSettingsSerializableProvider)rawProvider).isEmpty()) { @@ -75,7 +74,7 @@ class LanguageSettingsProvidersLabelProvider extends LabelProvider { } } - if (LanguageSettingsManager.isWorkspaceProvider(provider) /*&& !isSpecial*/) { + if (LanguageSettingsManager.isWorkspaceProvider(provider)) { overlayKeys[IDecoration.TOP_LEFT] = CDTSharedImages.IMG_OVR_GLOBAL; // overlayKeys[IDecoration.TOP_LEFT] = CDTSharedImages.IMG_OVR_REFERENCE; // overlayKeys[IDecoration.TOP_RIGHT] = CDTSharedImages.IMG_OVR_PARENT; @@ -119,4 +118,13 @@ class LanguageSettingsProvidersLabelProvider extends LabelProvider { } return OOPS; } + + /** + * Temporary method for debugging only + */ + @Deprecated + private boolean isDebugging() { + return false; +// return true; + } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/Messages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/Messages.properties index e26bd03bb53..d556df81429 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/Messages.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/Messages.properties @@ -279,7 +279,7 @@ StringVariableSelectionDialog_message=&Choose a variable (? = any character, * = StringVariableSelectionDialog_columnDescription=&Variable Description: CDTMainWizardPage_0=Project name cannot contain '\#' symbol CDTMainWizardPage_1=Project category is selected. Expand the category and select a concrete project type. -CDTMainWizardPage_TrySD90=I want to try new upcoming version of Scanner Discovery in CDT 9.0 (v.0.1.0) +CDTMainWizardPage_TrySD90=I want to try new upcoming version of Scanner Discovery in CDT 9.0 (sd90 v.0.9.0) CProjectWizard_0=Add C Project Nature CCProjectWizard_0=Add CC Project Nature WorkingSetConfigAction_21=Building project From 2309ecabf02234c83f6dec74c4549a0becd5b613 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Sat, 10 Dec 2011 16:33:41 -0500 Subject: [PATCH 085/120] Cleaned getProviderCopy() API, got rid of LanguageSettingsManager_TBD --- .../GCCBuildCommandParserTest.java | 76 +++++------ .../AbstractBuildCommandParser.java | 14 +- .../internal/core/CommonBuilder.java | 2 - .../ui/wizards/MBSWizardHandler.java | 9 +- .../LanguageSettingsExtensionsTests.java | 52 ++++---- .../providers/LanguageSettingsManager.java | 35 +++-- .../LanguageSettingsManager_TBD.java | 66 ---------- .../LanguageSettingsExtensionManager.java | 103 ++++++++------- .../LanguageSettingsProvidersSerializer.java | 47 ++++--- .../providers/LanguageSettingsEntriesTab.java | 12 +- .../LanguageSettingsProviderTab.java | 74 +++++------ .../viewsupport/ProblemsLabelDecorator.java | 120 +++++++++++------- 12 files changed, 297 insertions(+), 313 deletions(-) delete mode 100644 core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager_TBD.java diff --git a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java index 08ef8035eb1..97f2c2aa706 100644 --- a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java +++ b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java @@ -353,7 +353,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { String languageId = ls.getLanguageId(); // create GCCBuildCommandParser - GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT, true); // parse line parser.startup(cfgDescription); @@ -395,7 +395,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { String languageId = ls.getLanguageId(); // create GCCBuildCommandParser - GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT, true); // parse line parser.startup(cfgDescription); @@ -459,7 +459,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { String languageId = ls.getLanguageId(); // create GCCBuildCommandParser - GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT, true); // parse line parser.startup(cfgDescription); @@ -531,7 +531,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { String languageId = ls.getLanguageId(); // create GCCBuildCommandParser - GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT, true); // parse line parser.startup(cfgDescription); @@ -609,7 +609,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { String languageId = ls.getLanguageId(); // create GCCBuildCommandParser - GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT, true); // parse line parser.startup(cfgDescription); @@ -639,7 +639,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { String languageId = ls.getLanguageId(); // create GCCBuildCommandParser - GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT, true); // parse line parser.startup(cfgDescription); @@ -690,7 +690,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { String languageId = ls.getLanguageId(); // create GCCBuildCommandParser - GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT, true); // parse line parser.startup(cfgDescription); @@ -735,7 +735,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { String languageId = ls.getLanguageId(); // create GCCBuildCommandParser - GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT, true); // parse line parser.startup(cfgDescription); @@ -779,7 +779,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { String languageId = ls.getLanguageId(); // create GCCBuildCommandParser - GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT, true); // parse line parser.startup(cfgDescription); @@ -811,7 +811,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { String languageId = ls.getLanguageId(); // create GCCBuildCommandParser - GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT, true); // parse line parser.startup(cfgDescription); @@ -861,7 +861,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { ICConfigurationDescription cfgDescription = cfgDescriptions[0]; // create GCCBuildCommandParser - GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT, true); // parse line parser.startup(cfgDescription); @@ -886,7 +886,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { String languageId = ls.getLanguageId(); // create GCCBuildCommandParser - GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT, true); // parse line parser.startup(cfgDescription); @@ -919,7 +919,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { String languageId = ls.getLanguageId(); // create GCCBuildCommandParser - GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT, true); // parse line parser.startup(null); @@ -955,7 +955,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { String languageId = ls.getLanguageId(); // create GCCBuildCommandParser - GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT, true); // parse line parser.startup(cfgDescription); @@ -1008,7 +1008,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { String languageId = ls.getLanguageId(); // create GCCBuildCommandParser - GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT, true); ErrorParserManager epm = new ErrorParserManager(project, null); // Shift build directory, that could happen if Make Target from folder1 was run IFolder buildDir = folder1; @@ -1049,7 +1049,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { String languageId = ls.getLanguageId(); // create GCCBuildCommandParser - GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT, true); // parse line parser.startup(cfgDescription); @@ -1098,7 +1098,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { String languageId = ls.getLanguageId(); // create GCCBuildCommandParser - GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT, true); parser.setResolvingPaths(true); // parse line @@ -1129,7 +1129,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { String languageId = ls.getLanguageId(); // create GCCBuildCommandParser - GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT, true); parser.setResolvingPaths(true); // parse line @@ -1169,7 +1169,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { String languageId = ls.getLanguageId(); // create GCCBuildCommandParser with expandRelativePaths=false - GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT, true); parser.setResolvingPaths(false); // parse line @@ -1205,7 +1205,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { String languageId = ls.getLanguageId(); // create GCCBuildCommandParser - GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT, true); parser.setResolvingPaths(true); // parse line @@ -1242,7 +1242,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { String languageId = ls.getLanguageId(); // create GCCBuildCommandParser - GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT, true); ErrorParserManager epm = new ErrorParserManager(project, null); epm.pushDirectoryURI(buildDir.getLocationURI()); @@ -1284,7 +1284,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { String languageId = ls.getLanguageId(); // create GCCBuildCommandParser - GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT, true); ErrorParserManager epm = new ErrorParserManager(project, null); @@ -1316,7 +1316,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { String languageId = ls.getLanguageId(); // create GCCBuildCommandParser - GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT, true); ErrorParserManager epm = new ErrorParserManager(project, null); epm.pushDirectoryURI(buildDir.getLocationURI()); @@ -1354,7 +1354,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { String languageId = ls.getLanguageId(); // create GCCBuildCommandParser - GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT, true); ErrorParserManager epm = new ErrorParserManager(project, null); URI uriBuildDir = new URI("file:/non-existing/path"); @@ -1397,7 +1397,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { String languageId = ls.getLanguageId(); // create GCCBuildCommandParser - GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT, true); ErrorParserManager epm = new ErrorParserManager(project, null); URI uriBuildDir = new URI("file:/BuildDir"); @@ -1447,7 +1447,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { String languageId = ls.getLanguageId(); // create GCCBuildCommandParser - GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT, true); ErrorParserManager epm = new ErrorParserManager(project, null); // parse line @@ -1501,7 +1501,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { String languageId = ls.getLanguageId(); // create GCCBuildCommandParser - GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT, true); ErrorParserManager epm = new ErrorParserManager(project, null); // parse line @@ -1561,7 +1561,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { String languageId = ls.getLanguageId(); // create GCCBuildCommandParser - GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT, true); ErrorParserManager epm = new ErrorParserManager(project, null); // parse line @@ -1606,7 +1606,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { ResourceHelper.createSymbolicLink(linkPath, dir2); // create GCCBuildCommandParser - GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT, true); ErrorParserManager epm = new ErrorParserManager(project, null); // parse line @@ -1646,7 +1646,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { ResourceHelper.createSymbolicLink(linkPath, subfolder.getLocation()); // create GCCBuildCommandParser - GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT, true); ErrorParserManager epm = new ErrorParserManager(project, null); // parse line @@ -1688,7 +1688,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { String languageId = ls.getLanguageId(); // create GCCBuildCommandParser - GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT, true); // parse line parser.startup(cfgDescription); @@ -1731,7 +1731,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { String languageId = ls.getLanguageId(); // create GCCBuildCommandParser - GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT, true); // parse line parser.startup(cfgDescription); @@ -1777,7 +1777,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { ResourceHelper.createFile(project, "file.c"); // create GCCBuildCommandParser - GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT, true); // restrict the parser's language scope to C++ only parser.setLanguageScope(new ArrayList() {{add(LANG_CPP);}}); @@ -1809,7 +1809,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { assertEquals(contentType, contentTypeX); // create GCCBuildCommandParser - GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT, true); // parse line parser.startup(cfgDescription); @@ -1839,7 +1839,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { IFile file=ResourceHelper.createFile(project, "file.cpp"); // create GCCBuildCommandParser - GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT, true); ErrorParserManager epm = new ErrorParserManager(project, null); // parse line @@ -1870,7 +1870,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { String languageId = ls.getLanguageId(); // create GCCBuildCommandParser - GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT, true); // parse line parser.startup(cfgDescription); @@ -1916,7 +1916,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { String languageId = ls.getLanguageId(); // create GCCBuildCommandParser - GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT, true); ErrorParserManager epm = new ErrorParserManager(project, null); // parse line @@ -1956,7 +1956,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { String languageId = ls.getLanguageId(); // create GCCBuildCommandParser - GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); + GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT, true); ErrorParserManager epm = new ErrorParserManager(project, null); // parse line diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java index 59e256ed08e..3243fe2c1c3 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java @@ -211,12 +211,14 @@ public abstract class AbstractBuildCommandParser extends AbstractLanguageSetting } protected void init(String buildCommandParserId) { - AbstractBuildCommandParser buildCommandParser = (AbstractBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(buildCommandParserId); - for (String template : PATTERN_TEMPLATES) { - String pattern = buildCommandParser.makePattern(template); - String fileExpr = "$"+buildCommandParser.adjustFileGroup(); //$NON-NLS-1$ - String descExpr = "$0"; //$NON-NLS-1$ - addPattern(new RegexErrorPattern(pattern, fileExpr, null, descExpr, null, IMarkerGenerator.SEVERITY_WARNING, true)); + AbstractBuildCommandParser buildCommandParser = (AbstractBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(buildCommandParserId, false); + if (buildCommandParser != null) { + for (String template : PATTERN_TEMPLATES) { + String pattern = buildCommandParser.makePattern(template); + String fileExpr = "$"+buildCommandParser.adjustFileGroup(); //$NON-NLS-1$ + String descExpr = "$0"; //$NON-NLS-1$ + addPattern(new RegexErrorPattern(pattern, fileExpr, null, descExpr, null, IMarkerGenerator.SEVERITY_WARNING, true)); + } } } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/CommonBuilder.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/CommonBuilder.java index 3142d88b458..df8e4642d52 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/CommonBuilder.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/CommonBuilder.java @@ -26,8 +26,6 @@ import java.util.Set; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.ConsoleOutputStream; import org.eclipse.cdt.core.ProblemMarkerInfo; -import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; -import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager_TBD; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.resources.ACBuilder; import org.eclipse.cdt.core.resources.IConsole; diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/MBSWizardHandler.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/MBSWizardHandler.java index 5139b36cfbb..d0b4433aa57 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/MBSWizardHandler.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/MBSWizardHandler.java @@ -912,10 +912,9 @@ public class MBSWizardHandler extends CWizardHandler { break; } } - } else if (id.length()>0){ - // TODO - look into saving on copying, need to figure out "shared" attribute from extension provider directly - ILanguageSettingsProvider providerExt = LanguageSettingsManager.getExtensionProviderCopy(id); - if (LanguageSettingsProviderAssociationManager.shouldBeShared(providerExt)) { + } else if (id.length()>0) { + ILanguageSettingsProvider providerExt = LanguageSettingsManager.getExtensionProviderCopy(id, false); + if (providerExt == null || LanguageSettingsProviderAssociationManager.shouldBeShared(providerExt)) { provider = LanguageSettingsManager.getWorkspaceProvider(id); } else { provider = providerExt; @@ -935,7 +934,7 @@ public class MBSWizardHandler extends CWizardHandler { } if (!isProviderThere(providers, UI_USER_LANGUAGE_SETTINGS_PROVIDER)) { - ILanguageSettingsProvider provider = LanguageSettingsManager.getExtensionProviderCopy(UI_USER_LANGUAGE_SETTINGS_PROVIDER); + ILanguageSettingsProvider provider = LanguageSettingsManager.getExtensionProviderCopy(UI_USER_LANGUAGE_SETTINGS_PROVIDER, true); providers.add(0, provider); } diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java index 84c3131e254..0d688223e9a 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java @@ -25,7 +25,6 @@ import org.eclipse.cdt.core.settings.model.CMacroFileEntry; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.core.testplugin.util.BaseTestCase; -import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsExtensionManager; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.Path; @@ -108,14 +107,14 @@ public class LanguageSettingsExtensionsTests extends BaseTestCase { { // test provider not in the list - ILanguageSettingsProvider providerExt = LanguageSettingsManager.getExtensionProviderCopy("missing.povider"); - assertTrue(LanguageSettingsManager.isWorkspaceProvider(providerExt)); - ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(providerExt); - assertNull(rawProvider); + ILanguageSettingsProvider providerExt = LanguageSettingsManager.getExtensionProviderCopy("missing.povider", true); + assertNull(providerExt); } // get test plugin extension provider - ILanguageSettingsProvider providerExt = LanguageSettingsManager.getExtensionProviderCopy(EXTENSION_BASE_PROVIDER_ID); + ILanguageSettingsProvider providerExtCopy = LanguageSettingsManager.getExtensionProviderCopy(EXTENSION_BASE_PROVIDER_ID, true); + assertNull(providerExtCopy); + ILanguageSettingsProvider providerExt = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_BASE_PROVIDER_ID); assertTrue(LanguageSettingsManager.isWorkspaceProvider(providerExt)); // get raw extension provider @@ -157,7 +156,9 @@ public class LanguageSettingsExtensionsTests extends BaseTestCase { */ public void testExtensionBaseProviderSubclass() throws Exception { // get test plugin extension provider - ILanguageSettingsProvider providerExt = LanguageSettingsManager.getExtensionProviderCopy(EXTENSION_BASE_SUBCLASS_PROVIDER_ID); + ILanguageSettingsProvider providerExtCopy = LanguageSettingsManager.getExtensionProviderCopy(EXTENSION_BASE_SUBCLASS_PROVIDER_ID, true); + assertNull(providerExtCopy); + ILanguageSettingsProvider providerExt = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_BASE_SUBCLASS_PROVIDER_ID); assertTrue(LanguageSettingsManager.isWorkspaceProvider(providerExt)); // get raw extension provider @@ -187,7 +188,9 @@ public class LanguageSettingsExtensionsTests extends BaseTestCase { */ public void testExtensionCustomProvider() throws Exception { // get test plugin extension non-default provider - ILanguageSettingsProvider providerExt = LanguageSettingsManager.getExtensionProviderCopy(EXTENSION_CUSTOM_PROVIDER_ID); + ILanguageSettingsProvider providerExtCopy = LanguageSettingsManager.getExtensionProviderCopy(EXTENSION_CUSTOM_PROVIDER_ID, true); + assertNull(providerExtCopy); + ILanguageSettingsProvider providerExt = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_CUSTOM_PROVIDER_ID); assertTrue(LanguageSettingsManager.isWorkspaceProvider(providerExt)); // get raw extension provider @@ -256,7 +259,9 @@ public class LanguageSettingsExtensionsTests extends BaseTestCase { */ public void testSerializableProvider() throws Exception { // get test plugin extension for serializable provider - ILanguageSettingsProvider providerExt = LanguageSettingsManager.getExtensionProviderCopy(EXTENSION_SERIALIZABLE_PROVIDER_ID); + ILanguageSettingsProvider providerExtCopy = LanguageSettingsManager.getExtensionProviderCopy(EXTENSION_SERIALIZABLE_PROVIDER_ID, true); + assertNull(providerExtCopy); + ILanguageSettingsProvider providerExt = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_SERIALIZABLE_PROVIDER_ID); assertTrue(LanguageSettingsManager.isWorkspaceProvider(providerExt)); // get raw extension provider @@ -279,28 +284,25 @@ public class LanguageSettingsExtensionsTests extends BaseTestCase { // Non-editable providers cannot be copied so they are singletons { // get test plugin extension for serializable provider - ILanguageSettingsProvider providerExt = LanguageSettingsManager.getExtensionProviderCopy(EXTENSION_SERIALIZABLE_PROVIDER_ID); + ILanguageSettingsProvider providerExtCopy = LanguageSettingsManager.getExtensionProviderCopy(EXTENSION_SERIALIZABLE_PROVIDER_ID, true); + assertNull(providerExtCopy); + ILanguageSettingsProvider providerExt = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_SERIALIZABLE_PROVIDER_ID); assertTrue(LanguageSettingsManager.isWorkspaceProvider(providerExt)); // get raw extension provider ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(providerExt); assertTrue(rawProvider instanceof LanguageSettingsSerializableProvider); - assertTrue(LanguageSettingsExtensionManager.equalsExtensionProvider(rawProvider)); - - // compare with workspace provider - ILanguageSettingsProvider providerWsp = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_SERIALIZABLE_PROVIDER_ID); - ILanguageSettingsProvider providerWspRaw = LanguageSettingsManager.getRawProvider(providerWsp); - assertSame(rawProvider, providerWspRaw); + assertTrue(LanguageSettingsManager.isEqualExtensionProvider(rawProvider, true)); } // Editable providers are retrieved by copy { - ILanguageSettingsProvider providerExt = LanguageSettingsManager.getExtensionProviderCopy(EXTENSION_EDITABLE_PROVIDER_ID); + ILanguageSettingsProvider providerExt = LanguageSettingsManager.getExtensionProviderCopy(EXTENSION_EDITABLE_PROVIDER_ID, true); assertFalse(LanguageSettingsManager.isWorkspaceProvider(providerExt)); assertTrue(providerExt instanceof ILanguageSettingsEditableProvider); - assertTrue(LanguageSettingsExtensionManager.equalsExtensionProvider(providerExt)); + assertTrue(LanguageSettingsManager.isEqualExtensionProvider(providerExt, true)); - ILanguageSettingsProvider providerExt2 = LanguageSettingsManager.getExtensionProviderCopy(EXTENSION_EDITABLE_PROVIDER_ID); + ILanguageSettingsProvider providerExt2 = LanguageSettingsManager.getExtensionProviderCopy(EXTENSION_EDITABLE_PROVIDER_ID, true); assertNotSame(providerExt, providerExt2); assertEquals(providerExt, providerExt2); @@ -308,22 +310,22 @@ public class LanguageSettingsExtensionsTests extends BaseTestCase { ILanguageSettingsProvider providerWspRaw = LanguageSettingsManager.getRawProvider(providerWsp); assertNotSame(providerExt, providerWspRaw); assertEquals(providerExt, providerWspRaw); - assertTrue(LanguageSettingsExtensionManager.equalsExtensionProvider(providerWspRaw)); + assertTrue(LanguageSettingsManager.isEqualExtensionProvider(providerWspRaw, true)); } // Test shallow copy { - ILanguageSettingsProvider provider = LanguageSettingsManager.getExtensionProviderCopy(EXTENSION_EDITABLE_PROVIDER_ID); + ILanguageSettingsProvider provider = LanguageSettingsManager.getExtensionProviderCopy(EXTENSION_EDITABLE_PROVIDER_ID, true); assertNotNull(provider); assertTrue(provider instanceof ILanguageSettingsEditableProvider); - ILanguageSettingsProvider providerShallow = LanguageSettingsExtensionManager.getExtensionProviderShallow(EXTENSION_EDITABLE_PROVIDER_ID); + ILanguageSettingsProvider providerShallow = LanguageSettingsManager.getExtensionProviderCopy(EXTENSION_EDITABLE_PROVIDER_ID, false); assertNotNull(providerShallow); assertTrue(providerShallow instanceof ILanguageSettingsEditableProvider); assertFalse(provider.equals(providerShallow)); - assertFalse(LanguageSettingsExtensionManager.equalsExtensionProvider(providerShallow)); - assertTrue(LanguageSettingsExtensionManager.equalsExtensionProviderShallow((ILanguageSettingsEditableProvider) providerShallow)); + assertFalse(LanguageSettingsManager.isEqualExtensionProvider(providerShallow, true)); + assertTrue(LanguageSettingsManager.isEqualExtensionProvider(providerShallow, false)); } } @@ -331,7 +333,7 @@ public class LanguageSettingsExtensionsTests extends BaseTestCase { * Check that LanguageSettingsGenericProvider extension defined in plugin.xml is accessible. */ public void testExtensionGenericProvider() throws Exception { - ILanguageSettingsProvider provider = LanguageSettingsExtensionManager.getExtensionProviderClone(EXTENSION_USER_PROVIDER_ID); + ILanguageSettingsProvider provider = LanguageSettingsManager.getExtensionProviderCopy(EXTENSION_USER_PROVIDER_ID, true); assertNotNull("extension " + EXTENSION_USER_PROVIDER_ID + " not found", provider); assertTrue(provider instanceof LanguageSettingsGenericProvider); } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java index d4e04c9657d..3cd135f41d6 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java @@ -60,7 +60,7 @@ public class LanguageSettingsManager { * Builds for the provider a nice looking resource tree to present hierarchical view to the user. * * TODO - Note that after using this method for a while for BOP parsers it appears that disadvantages - * outweight benefits. In particular, it doesn't result in saving memory as the language settings + * outweigh benefits. In particular, it doesn't result in saving memory as the language settings * (and the lists itself) are not duplicated in memory anyway but optimized with using WeakHashSet * and SafeStringInterner. * @@ -157,25 +157,38 @@ public class LanguageSettingsManager { LanguageSettingsProvidersSerializer.setWorkspaceProviders(providers); } + /** + * TODO + * @param deepCopy TODO + * @param id + * + * @return + */ + public static ILanguageSettingsEditableProvider getProviderCopy(ILanguageSettingsEditableProvider provider, boolean deep) { + return LanguageSettingsExtensionManager.getProviderCopy(provider, deep); + } + /** * Get Language Settings Provider defined via * {@code org.eclipse.cdt.core.LanguageSettingsProvider} extension point. * * @param id - ID of provider to find. + * @param deep TODO * @return the copy of the provider if possible (i.e. for {@link ILanguageSettingsEditableProvider}) * or workspace provider if provider is not copyable. */ - public static ILanguageSettingsProvider getExtensionProviderCopy(String id) { - ILanguageSettingsProvider provider = null; - try { - provider = LanguageSettingsExtensionManager.getExtensionProviderClone(id); - } catch (CloneNotSupportedException e) { - // from here falls to get workspace provider - } - if (provider==null) - provider = LanguageSettingsManager.getWorkspaceProvider(id); + public static ILanguageSettingsProvider getExtensionProviderCopy(String id, boolean deep) { + return LanguageSettingsExtensionManager.getExtensionProviderCopy(id, deep); + } - return provider; + /** + * TODO + * @param provider + * @param deep + * @return + */ + public static boolean isEqualExtensionProvider(ILanguageSettingsProvider provider, boolean deep) { + return LanguageSettingsExtensionManager.isEqualsExtensionProvider(provider, deep); } /** diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager_TBD.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager_TBD.java deleted file mode 100644 index c8464960d7c..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager_TBD.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 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.core.language.settings.providers; - -import java.util.List; - -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; -import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; -import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsExtensionManager; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; - -/** - * This temporary class keeps the utility methods being looking for better home. - * Checking if any Language Settings Provider has custom entries for the resource. - */ -public class LanguageSettingsManager_TBD { - public static boolean isCustomizedResource(ICConfigurationDescription cfgDescription, IResource rc) { - if (rc instanceof IProject) - return false; - - if (cfgDescription instanceof ILanguageSettingsProvidersKeeper) { - for (ILanguageSettingsProvider provider: ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders()) { - if (provider instanceof ILanguageSettingsBroadcastingProvider) { - for (String languageId : LanguageSettingsManager.getLanguages(rc, cfgDescription)) { - List list = provider.getSettingEntries(cfgDescription, rc, languageId); - if (list!=null) { - // TODO - check default or check parent? - List listDefault = provider.getSettingEntries(null, null, languageId); - // != is OK here due as the equal lists will have the same reference in WeakHashSet - if (list != listDefault) - return true; - } - } - } - } - } - - return false; - } - - public static boolean isReconfigured(ILanguageSettingsProvider provider) { - if (provider instanceof ILanguageSettingsEditableProvider) { - try { - return ! LanguageSettingsExtensionManager.equalsExtensionProviderShallow((ILanguageSettingsEditableProvider) provider); - } catch (Exception e) { - CCorePlugin.log(e); - } - } - return false; - } - - public static boolean isEqualExtensionProvider(ILanguageSettingsProvider provider) { - return LanguageSettingsExtensionManager.equalsExtensionProvider(provider); - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java index 60e7d05ade8..d47c6f78a4d 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java @@ -283,45 +283,6 @@ public class LanguageSettingsExtensionManager { return provider; } - /** - * Get Language Settings Provider defined via - * {@code org.eclipse.cdt.core.LanguageSettingsProvider} extension point. - * - * @param id - ID of provider to find. - * @return the clone of the provider or {@code null} if provider is not defined. - * @throws CloneNotSupportedException if the provider is not cloneable - */ - public static ILanguageSettingsProvider getExtensionProviderClone(String id) throws CloneNotSupportedException { - ILanguageSettingsProvider provider = fExtensionProviders.get(id); - if (provider!=null) { - if (!(provider instanceof ILanguageSettingsEditableProvider)) - throw new CloneNotSupportedException("Not able to clone provider " + provider.getClass()); - - provider = ((ILanguageSettingsEditableProvider) provider).clone(); - } - return provider; - } - - /** - * TODO - * - * @param id - * @return - */ - public static ILanguageSettingsProvider getExtensionProviderShallow(String id) { - ILanguageSettingsProvider provider = fExtensionProviders.get(id); - if (provider instanceof ILanguageSettingsEditableProvider) { - try { - return ((ILanguageSettingsEditableProvider) provider).cloneShallow(); - } catch (CloneNotSupportedException e) { - IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "Not able to clone provider " + provider.getClass()); - CCorePlugin.log(new CoreException(status)); - return null; - } - } - return provider; - } - /** * @return list of providers contributed by all extensions. Preferable copy but if not possible * will return raw provider. @@ -329,12 +290,7 @@ public class LanguageSettingsExtensionManager { /*package*/ static List getExtensionProvidersInternal() { ArrayList list = new ArrayList(fExtensionProviders.size()); for (String id : fExtensionProviders.keySet()) { - ILanguageSettingsProvider extensionProvider = null; - try { - extensionProvider = getExtensionProviderClone(id); - } catch (CloneNotSupportedException e) { - // from here falls to get raw extension provider - } + ILanguageSettingsProvider extensionProvider = getExtensionProviderCopy(id, true); if (extensionProvider==null) extensionProvider = fExtensionProviders.get(id); @@ -344,16 +300,59 @@ public class LanguageSettingsExtensionManager { return list; } - public static boolean equalsExtensionProviderShallow(ILanguageSettingsEditableProvider provider) throws CloneNotSupportedException { - String id = provider.getId(); - ILanguageSettingsProvider extensionProviderShallow = getExtensionProviderShallow(id); - return provider.cloneShallow().equals(extensionProviderShallow); + /** + * TODO + * @param provider + * @param deep + * @return + */ + public static ILanguageSettingsEditableProvider getProviderCopy(ILanguageSettingsEditableProvider provider, boolean deep) { + try { + if (deep) { + return provider.clone(); + } else { + return provider.cloneShallow(); + } + } catch (CloneNotSupportedException e) { + CCorePlugin.log("Error cloning provider " + provider.getId() + ", class " + provider.getClass(), e); //$NON-NLS-1$ //$NON-NLS-2$ + } + return null; } - public static boolean equalsExtensionProvider(ILanguageSettingsProvider provider) { + /** + * Get Language Settings Provider defined via + * {@code org.eclipse.cdt.core.LanguageSettingsProvider} extension point. + * + * @param id - ID of provider to find. + * @param deep TODO + * @return the clone of the provider or {@code null} TODO if provider is not defined. + */ + public static ILanguageSettingsProvider getExtensionProviderCopy(String id, boolean deep) { + ILanguageSettingsProvider provider = fExtensionProviders.get(id); + if (provider instanceof ILanguageSettingsEditableProvider) { + return getProviderCopy((ILanguageSettingsEditableProvider) provider, deep); + } + + return null; + } + + /** + * TODO + * @param provider + * @param deep + * @return + */ + public static boolean isEqualsExtensionProvider(ILanguageSettingsProvider provider, boolean deep) { String id = provider.getId(); - ILanguageSettingsProvider extensionProvider = fExtensionProviders.get(id); - return provider.equals(extensionProvider); + if (deep || !(provider instanceof ILanguageSettingsEditableProvider)) { + ILanguageSettingsProvider extensionProvider = fExtensionProviders.get(id); + return provider.equals(extensionProvider); + } else { + ILanguageSettingsEditableProvider providerShallow = getProviderCopy((ILanguageSettingsEditableProvider) provider, false); + ILanguageSettingsProvider extensionProviderShallow = getExtensionProviderCopy(id, false); + return providerShallow == extensionProviderShallow + || (providerShallow != null && providerShallow.equals(extensionProviderShallow)); + } } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java index 15fc6ccf4a9..25822dac944 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java @@ -203,7 +203,8 @@ public class LanguageSettingsProvidersSerializer { */ public LanguageSettingsChangeEvent(ICProjectDescription prjDescription) { if (!prjDescription.isReadOnly()) { - String msg = "Project description " + prjDescription.getName() + " is expected to be read-only"; + // The logic goes that we send notifications only for acting description but not for currently being prepared to set + String msg = "Project description " + prjDescription.getName() + " is expected to be read-only"; //$NON-NLS-1$ //$NON-NLS-2$ CCorePlugin.log(new Status(IStatus.WARNING, CCorePlugin.PLUGIN_ID, msg, new Exception(msg))); } @@ -222,7 +223,8 @@ public class LanguageSettingsProvidersSerializer { if (delta != null) deltaMap.put(cfgDescription.getId(), delta); } else { - IStatus ss = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "Internal error: Missing specSettings for " + cfgDescription.getClass().getSimpleName()); + IStatus ss = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "Internal error: Missing specSettings for " //$NON-NLS-1$ + + cfgDescription.getClass().getSimpleName()); CCorePlugin.log(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, ss.getMessage(), new CoreException(ss))); } } @@ -239,11 +241,11 @@ public class LanguageSettingsProvidersSerializer { return deltaMap.keySet().toArray(new String[deltaMap.size()]); } + @SuppressWarnings("nls") @Override public String toString() { return "LanguageSettingsChangeEvent for project=[" + getProjectName() + "]" - + ", configurations=" + deltaMap.keySet() - ; + + ", configurations=" + deltaMap.keySet(); } } @@ -257,6 +259,12 @@ public class LanguageSettingsProvidersSerializer { } } + /** + * Determine location of the project store of language settings providers in the plug-in state area. + * + * @param store - name of the store. + * @return location of the store in the plug-in state area. + */ private static IFile getStoreInProjectArea(IProject project) throws CoreException { IFolder folder = project.getFolder(SETTINGS_FOLDER_NAME); if (!folder.exists()) { @@ -267,10 +275,10 @@ public class LanguageSettingsProvidersSerializer { } /** - * TODO: refactor with ErrorParserManager ? + * Determine location of the store in the plug-in state area. * - * @param store - name of the store - * @return location of the store in the plug-in state area + * @param store - name of the store. + * @return location of the store in the plug-in state area. */ private static URI getStoreInWorkspaceArea(String store) { IPath location = CCorePlugin.getDefault().getStateLocation().append(store); @@ -434,9 +442,9 @@ projects: } } catch (Exception e) { - CCorePlugin.log("Internal error while trying to serialize language settings", e); //$NON-NLS-1$ - IStatus s = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "Internal error while trying to serialize language settings", e); - throw new CoreException(s); + String msg = "Internal error while trying to serialize language settings"; //$NON-NLS-1$ + CCorePlugin.log(msg, e); + throw new CoreException(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, msg, e)); } } @@ -464,7 +472,7 @@ projects: Node providerNode = providerNodes.item(i); String providerId = XmlUtil.determineAttributeValue(providerNode, LanguageSettingsExtensionManager.ATTR_ID); if (userDefinedProvidersIds.contains(providerId)) { - String msg = "Ignored repeatedly persisted duplicate language settings provider id=" + providerId; + String msg = "Ignored an attempt to persist duplicate language settings provider, id=" + providerId; //$NON-NLS-1$ CCorePlugin.log(new Status(IStatus.WARNING, CCorePlugin.PLUGIN_ID, msg, new Exception())); continue; } @@ -475,7 +483,7 @@ projects: if (providers==null) providers= new ArrayList(); - if (!LanguageSettingsExtensionManager.equalsExtensionProvider(provider)) { + if (!LanguageSettingsManager.isEqualExtensionProvider(provider, true)) { providers.add(provider); } } @@ -600,9 +608,9 @@ projects: } } catch (Exception e) { - IStatus s = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "Internal error while trying to serialize language settings", e); - CCorePlugin.log(s); - throw new CoreException(s); + String msg = "Internal error while trying to serialize language settings"; //$NON-NLS-1$ + CCorePlugin.log(msg, e); + throw new CoreException(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, msg, e)); } } @@ -1008,12 +1016,9 @@ projects: List newProviders = new ArrayList(); for (ILanguageSettingsProvider provider : baseProviders) { if (provider instanceof ILanguageSettingsEditableProvider) { - try { - provider = ((ILanguageSettingsEditableProvider) provider).clone(); - } catch (CloneNotSupportedException e) { - IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, Status.OK, - "Not able to clone provider " + provider.getClass(), e); - CCorePlugin.log(status); + ILanguageSettingsEditableProvider newProvider = LanguageSettingsManager.getProviderCopy((ILanguageSettingsEditableProvider) provider, true); + if (newProvider != null) { + provider = newProvider; } } newProviders.add(provider); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java index 323117a39b1..dc5baa346a4 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java @@ -980,16 +980,14 @@ providers: for (ILanguageSettingsProvider provider : oldProviders) { String langId = (String)langItems.getData(); if (langId!=null) { if (provider.getSettingEntries(cfgDescription, rc, langId)!=null) { - try { - // clone providers to be able to "Cancel" in UI - if (providerCopy==null) { - providerCopy = ((ILanguageSettingsEditableProvider) provider).clone(); + if (providerCopy == null) { + // copy providers to be able to "Cancel" in UI + providerCopy = LanguageSettingsManager.getProviderCopy((ILanguageSettingsEditableProvider) provider, true); + if (providerCopy == null) { + continue providers; } providerCopy.setSettingEntries(cfgDescription, rc, langId, null); changed = true; - } catch (CloneNotSupportedException e) { - CUIPlugin.log("Internal Error: cannot clone provider "+provider.getId(), e); - continue providers; } } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java index fd765d7baf6..21f7cbcebe9 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java @@ -49,7 +49,6 @@ import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsEditabl 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_TBD; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializableProvider; import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySupport; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; @@ -150,17 +149,19 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); Assert.isTrue(rawProvider instanceof ILanguageSettingsEditableProvider); - try { - ILanguageSettingsEditableProvider newProvider = ((ILanguageSettingsEditableProvider)rawProvider).clone(); + ILanguageSettingsEditableProvider newProvider = LanguageSettingsManager.getProviderCopy((ILanguageSettingsEditableProvider)rawProvider, true); + if (newProvider != null) { replaceSelectedProvider(newProvider); - return newProvider; - - } catch (CloneNotSupportedException e) { - CUIPlugin.log("Error cloning provider " + rawProvider.getId(), e); - // TODO warning dialog for user? } - return null; + return newProvider; + } + + private static boolean isReconfigured(ILanguageSettingsProvider provider) { + if (provider instanceof ILanguageSettingsEditableProvider) { + return ! LanguageSettingsManager.isEqualExtensionProvider(provider, false); + } + return false; } private class ProvidersTableLabelProvider extends LanguageSettingsProvidersLabelProvider { @@ -169,7 +170,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { String[] overlayKeys = super.getOverlayKeys(provider); ILanguageSettingsProvider rawProvider = page.isForPrefs() ? LanguageSettingsManager.getRawProvider(provider) : provider; - if (LanguageSettingsManager_TBD.isReconfigured(rawProvider)) { + if (isReconfigured(rawProvider)) { overlayKeys[IDecoration.TOP_RIGHT] = CDTSharedImages.IMG_OVR_SETTING; } @@ -315,18 +316,16 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); if (!LanguageSettingsProviderAssociationManager.shouldBeShared(rawProvider)) { // Switch to local provider instance - try { - if (rawProvider instanceof ILanguageSettingsEditableProvider) { - provider = ((ILanguageSettingsEditableProvider) rawProvider).cloneShallow(); + if (rawProvider instanceof ILanguageSettingsEditableProvider) { + ILanguageSettingsEditableProvider newProvider = LanguageSettingsManager.getProviderCopy((ILanguageSettingsEditableProvider) rawProvider, false); + if (newProvider != null) { + provider = newProvider; + replaceSelectedProvider(provider); + ICConfigurationDescription cfgDescription = getConfigurationDescription(); + initializeOptionsPage(provider, cfgDescription); + displaySelectedOptionPage(); } - } catch (CloneNotSupportedException e) { - CUIPlugin.log("Error cloning provider " + provider.getId(), e); } - - replaceSelectedProvider(provider); - ICConfigurationDescription cfgDescription = getConfigurationDescription(); - initializeOptionsPage(provider, cfgDescription); - displaySelectedOptionPage(); } } @@ -659,7 +658,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { boolean canReset = false; if (rawProvider!=null && (canForWorkspace || canForProject)) { - canReset = ! LanguageSettingsManager_TBD.isEqualExtensionProvider(rawProvider); + canReset = ! LanguageSettingsManager.isEqualExtensionProvider(rawProvider, true); } boolean canMoveUp = page.isForProject() && isProviderSelected && isRangeOk && pos!=0; @@ -721,28 +720,24 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { } else { ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(selectedProvider); if (rawProvider instanceof ILanguageSettingsEditableProvider) { - ILanguageSettingsEditableProvider editableProvider = (ILanguageSettingsEditableProvider) rawProvider; - - try { - ILanguageSettingsEditableProvider newProvider = editableProvider.cloneShallow(); + ILanguageSettingsEditableProvider newProvider = LanguageSettingsManager.getProviderCopy((ILanguageSettingsEditableProvider) rawProvider, false); + if (newProvider != null) { replaceSelectedProvider(newProvider); - ICConfigurationDescription cfgDescription = getConfigurationDescription(); initializeOptionsPage(newProvider, cfgDescription); displaySelectedOptionPage(); - - } catch (CloneNotSupportedException e) { - CUIPlugin.log("Error cloning provider " + editableProvider.getId(), e); - return; } } - } updateButtons(); } private void performReset(ILanguageSettingsProvider selectedProvider) { - ILanguageSettingsProvider newProvider = LanguageSettingsManager.getExtensionProviderCopy(selectedProvider.getId()); + String id = selectedProvider.getId(); + ILanguageSettingsProvider newProvider = LanguageSettingsManager.getExtensionProviderCopy(id, true); + if (newProvider == null) { + newProvider = LanguageSettingsManager.getWorkspaceProvider(id); + } replaceSelectedProvider(newProvider); ICConfigurationDescription cfgDescription = getConfigurationDescription(); @@ -840,8 +835,11 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { boolean atLeastOneChanged = false; for (int i=0;iIMarker.PROBLEM. *

    * Note: Only images for elements in Java projects are currently updated on marker changes. *

    - * + * * @since 2.0 */ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabelDecorator { - + /** - * This is a special LabelProviderChangedEvent carring additional + * This is a special LabelProviderChangedEvent carring additional * information whether the event orgins from a maker change. *

    * ProblemsLabelChangedEvents are only generated by @@ -77,12 +83,12 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe super(source, changedResource); fMarkerChange= isMarkerChange; } - + /** - * Returns whether this event origins from marker changes. If false an annotation - * model change is the origin. In this case viewers not displaying working copies can ignore these + * Returns whether this event origins from marker changes. If false an annotation + * model change is the origin. In this case viewers not displaying working copies can ignore these * events. - * + * * @return if this event origins from a marker change. */ public boolean isMarkerChange() { @@ -92,13 +98,13 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe } private static final int ERRORTICK_WARNING= CElementImageDescriptor.WARNING; - private static final int ERRORTICK_ERROR= CElementImageDescriptor.ERROR; - private static final int TICK_CONFIGURATION = CElementImageDescriptor.SETTINGS; - + private static final int ERRORTICK_ERROR= CElementImageDescriptor.ERROR; + private static final int TICK_CONFIGURATION = CElementImageDescriptor.SETTINGS; + private ImageDescriptorRegistry fRegistry; private boolean fUseNewRegistry= false; private IProblemChangedListener fProblemChangedListener; - + private ListenerList fListeners; /** @@ -108,10 +114,10 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe this(null); fUseNewRegistry= true; } - + /* * Creates decorator with a shared image registry. - * + * * @param registry The registry to use or null to use the Java plugin's * image registry. */ @@ -122,21 +128,21 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe fRegistry= registry; fProblemChangedListener= null; } - + private ImageDescriptorRegistry getRegistry() { if (fRegistry == null) { fRegistry= fUseNewRegistry ? new ImageDescriptorRegistry() : CUIPlugin.getImageDescriptorRegistry(); } return fRegistry; } - + /* (non-Javadoc) * @see ILabelDecorator#decorateText(String, Object) */ public String decorateText(String text, Object element) { return text; - } + } /* (non-Javadoc) * @see ILabelDecorator#decorateImage(Image, Object) @@ -189,7 +195,7 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe if (e.getStatus().getCode() == IResourceStatus.MARKER_NOT_FOUND) { return 0; } - + CUIPlugin.log(e); } return 0; @@ -200,7 +206,7 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe return 0; } int info= 0; - + IMarker[] markers= res.findMarkers(IMarker.PROBLEM, true, depth); if (markers != null) { for (int i= 0; i < markers.length && (info != ERRORTICK_ERROR); i++) { @@ -213,7 +219,7 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe info= ERRORTICK_ERROR; } } - } + } } return info; } @@ -228,12 +234,12 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe } } return isInside(pos, -1, sourceElement); - + } return false; } - - + + // private int getErrorTicksFromWorkingCopy(ITranslationUnit original, ISourceReference sourceElement) throws CoreException { // int info= 0; // FileEditorInput editorInput= new FileEditorInput((IFile) original.getResource()); @@ -255,7 +261,7 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe // } // return info; // } - + // private IMarker isAnnotationInRange(IAnnotationModel model, Annotation annot, ISourceReference sourceElement) throws CoreException { // if (annot instanceof MarkerAnnotation) { // IMarker marker= ((MarkerAnnotation) annot).getMarker(); @@ -268,17 +274,17 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe // } // return null; // } - + /** * Tests if a position is inside the source range of an element. Usually this is done - * by looking at the offset. In case the offset equals -1, the line is + * by looking at the offset. In case the offset equals -1, the line is * tested. * @param offSet offset to be tested * @param line line to be tested * @param sourceElement Source element (must be a ICElement) * @return boolean Return true if position is located inside the source element. * @throws CoreException Exception thrown if element range could not be accessed. - * + * * @since 2.1 */ protected boolean isInside(int offSet, int line, ISourceReference sourceElement) throws CoreException { @@ -288,11 +294,11 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe return (line >= range.getStartLine() && line <= range.getEndLine()); } int rangeOffset= range.getStartPos(); - return (rangeOffset <= offSet && rangeOffset + range.getLength() > offSet); + return (rangeOffset <= offSet && rangeOffset + range.getLength() > offSet); } return false; - } - + } + /* (non-Javadoc) * @see IBaseLabelProvider#dispose() */ @@ -312,7 +318,7 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe public boolean isLabelProperty(Object element, String property) { return true; } - + /* (non-Javadoc) * @see IBaseLabelProvider#addListener(ILabelProviderListener) */ @@ -329,7 +335,7 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe }; CUIPlugin.getDefault().getProblemMarkerManager().addListener(fProblemChangedListener); } - } + } /* (non-Javadoc) * @see IBaseLabelProvider#removeListener(ILabelProviderListener) @@ -343,7 +349,7 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe } } } - + protected void fireProblemsChanged(IResource[] changedResources, boolean isMarkerChange) { if (fListeners != null && !fListeners.isEmpty()) { LabelProviderChangedEvent event= new ProblemsLabelChangedEvent(this, changedResources, isMarkerChange); @@ -353,23 +359,52 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe } } } - + /* (non-Javadoc) * @see org.eclipse.jface.viewers.ILightweightLabelDecorator#decorate(java.lang.Object, org.eclipse.jface.viewers.IDecoration) */ - public void decorate(Object element, IDecoration decoration) { + public void decorate(Object element, IDecoration decoration) { int adornmentFlags= computeAdornmentFlags(element); if ((adornmentFlags & TICK_CONFIGURATION) != 0) { decoration.addOverlay(CPluginImages.DESC_OVR_SETTING); adornmentFlags &= ~TICK_CONFIGURATION; } - + if (adornmentFlags == ERRORTICK_ERROR) { decoration.addOverlay(CPluginImages.DESC_OVR_ERROR); } else if (adornmentFlags == ERRORTICK_WARNING) { decoration.addOverlay(CPluginImages.DESC_OVR_WARNING); - } + } + } + + public static boolean isCustomizedResource(ICConfigurationDescription cfgDescription, IResource rc) { + if (rc instanceof IProject) + return false; + + if (!ScannerDiscoveryLegacySupport.isLanguageSettingsProvidersFunctionalityEnabled(rc.getProject())) { + ICResourceDescription rcDescription = cfgDescription.getResourceDescription(rc.getProjectRelativePath(), true); + return rcDescription != null; + } + + if (cfgDescription instanceof ILanguageSettingsProvidersKeeper) { + for (ILanguageSettingsProvider provider: ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders()) { + if (provider instanceof ILanguageSettingsBroadcastingProvider) { + for (String languageId : LanguageSettingsManager.getLanguages(rc, cfgDescription)) { + List list = provider.getSettingEntries(cfgDescription, rc, languageId); + if (list!=null) { + // TODO - check default or check parent? + List listDefault = provider.getSettingEntries(null, null, languageId); + // != is OK here due as the equal lists will have the same reference in WeakHashSet + if (list != listDefault) + return true; + } + } + } + } + } + + return false; } /** @@ -386,10 +421,7 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe if (prjDescription != null) { ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); if (cfgDescription != null) { - IPath path = rc.getProjectRelativePath(); - ICResourceDescription rcDescription = cfgDescription.getResourceDescription(path, true); - boolean isLSCustomized = LanguageSettingsManager_TBD.isCustomizedResource(cfgDescription, rc); - if (rcDescription != null || isLSCustomized) + if (isCustomizedResource(cfgDescription, rc)) result |= TICK_CONFIGURATION; } } From 3713fcd0803074a802ae344d35c598bf7dd1eebb Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Sun, 11 Dec 2011 21:47:24 -0500 Subject: [PATCH 086/120] JavaDoc --- .../ILanguageSettingsProvidersKeeper.java | 8 ++- .../providers/LanguageSettingsManager.java | 54 +++++++++++------- .../LanguageSettingsExtensionManager.java | 47 +++++++++------ .../LanguageSettingsProvidersSerializer.java | 57 ++++++++++++++----- 4 files changed, 113 insertions(+), 53 deletions(-) diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsProvidersKeeper.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsProvidersKeeper.java index 76c2e28c72c..51dc65f05e5 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsProvidersKeeper.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsProvidersKeeper.java @@ -25,10 +25,12 @@ public interface ILanguageSettingsProvidersKeeper { * used to supply language settings {@link ICLanguageSettingEntry} such as include paths * or preprocessor macros. * - * @param providers the list of providers to assign to the owner (configuration description). + * @param providers - the list of providers to assign to the owner (configuration description). * This method clones the internal list or otherwise ensures immutability of the internal - * list before actual addition to the project model. - * That is due to TODO - very important reason but I forgot why by now. + * list before actual addition to the project model. That is to ensure that there is no + * back-door access and all changes in the list done by this method which fires notifications + * to the registered listeners about the accompanied changes in settings entries, see + * {@link LanguageSettingsManager#registerLanguageSettingsChangeListener(ILanguageSettingsChangeListener)}. */ public void setLanguageSettingProviders(List providers); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java index 3cd135f41d6..c51c0eab544 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java @@ -121,7 +121,10 @@ public class LanguageSettingsManager { } /** - * Checks if the provider is defined on the workspace level. + * Checks if the provider is a workspace level provider. + * This method is intended to check providers retrieved from a configuration. + * Raw providers from {@link #getRawProvider(ILanguageSettingsProvider)} + * are not considered as workspace providers. * * @param provider - provider to check. * @return {@code true} if the given provider is workspace provider, {@code false} otherwise. @@ -131,12 +134,16 @@ public class LanguageSettingsManager { } /** - * TODO - helper method for often used chunk of code - * @param provider - * @return ILanguageSettingsProvider + * Helper method to get to real underlying provider collecting entries as opposed to wrapper + * which is normally used for workspace provider. + * @see LanguageSettingsProvidersSerializer#isWorkspaceProvider(ILanguageSettingsProvider) + * + * @param provider - the provider to get raw provider for. Can be either workspace provider + * or regular one. + * @return raw underlying provider for workspace provider or provider itself if no wrapper is used. */ public static ILanguageSettingsProvider getRawProvider(ILanguageSettingsProvider provider) { - if (LanguageSettingsManager.isWorkspaceProvider(provider)){ + if (LanguageSettingsManager.isWorkspaceProvider(provider)) { provider = LanguageSettingsProvidersSerializer.getRawWorkspaceProvider(provider.getId()); } return provider; @@ -158,34 +165,43 @@ public class LanguageSettingsManager { } /** - * TODO - * @param deepCopy TODO - * @param id + * Copy language settings provider. It is different from clone() methods in that + * it does not throw {@code CloneNotSupportedException} but returns {@code null} + * instead. + * + * @param provider - language settings provider to copy. + * @param deep - {@code true} to request deep copy including copying settings entries + * or {@code false} to return shallow copy with no settings entries. * - * @return + * @return a copy of the provider or null if copying is not possible. */ public static ILanguageSettingsEditableProvider getProviderCopy(ILanguageSettingsEditableProvider provider, boolean deep) { return LanguageSettingsExtensionManager.getProviderCopy(provider, deep); } /** - * Get Language Settings Provider defined via - * {@code org.eclipse.cdt.core.LanguageSettingsProvider} extension point. + * Get language settings provider defined via extension point + * {@code org.eclipse.cdt.core.LanguageSettingsProvider}. + * A new copy of the extension provider is returned. * - * @param id - ID of provider to find. - * @param deep TODO - * @return the copy of the provider if possible (i.e. for {@link ILanguageSettingsEditableProvider}) - * or workspace provider if provider is not copyable. + * @param id - ID of the extension provider. + * @param deep - {@code true} to request deep copy including copying settings entries + * or {@code false} to return shallow copy with no settings entries. + * @return the copy of the extension provider if possible (i.e. for {@link ILanguageSettingsEditableProvider}) + * or {@code null} if provider is not copyable. */ public static ILanguageSettingsProvider getExtensionProviderCopy(String id, boolean deep) { return LanguageSettingsExtensionManager.getExtensionProviderCopy(id, deep); } /** - * TODO - * @param provider - * @param deep - * @return + * Test if the provider is equal to the one defined via extension point + * {@code org.eclipse.cdt.core.LanguageSettingsProvider}. + * + * @param provider - the provider to test. + * @param deep - {@code true} to check for deep equality testing also settings entries + * or {@code false} to test shallow copy with no settings entries. + * @return - {@code true} if the provider matches the extension or {@code false} otherwise. */ public static boolean isEqualExtensionProvider(ILanguageSettingsProvider provider, boolean deep) { return LanguageSettingsExtensionManager.isEqualsExtensionProvider(provider, deep); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java index d47c6f78a4d..848eb9d8a47 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java @@ -276,8 +276,8 @@ public class LanguageSettingsExtensionManager { } ILanguageSettingsProvider provider = createProviderCarcass(className, Platform.getExtensionRegistry()); - if (provider==null) { - IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "Not able to load provider class=" + className); + if (provider == null) { + IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "Not able to load provider class=" + className); //$NON-NLS-1$ CCorePlugin.log(new CoreException(status)); } return provider; @@ -291,20 +291,27 @@ public class LanguageSettingsExtensionManager { ArrayList list = new ArrayList(fExtensionProviders.size()); for (String id : fExtensionProviders.keySet()) { ILanguageSettingsProvider extensionProvider = getExtensionProviderCopy(id, true); - if (extensionProvider==null) + if (extensionProvider == null) { extensionProvider = fExtensionProviders.get(id); + } - if (extensionProvider!=null) + if (extensionProvider != null) { list.add(extensionProvider); + } } return list; } /** - * TODO - * @param provider - * @param deep - * @return + * Copy language settings provider. It is different from clone() methods in that + * it does not throw {@code CloneNotSupportedException} but returns {@code null} + * instead. + * + * @param provider - language settings provider to copy. + * @param deep - {@code true} to request deep copy including copying settings entries + * or {@code false} to return shallow copy with no settings entries. + * + * @return a copy of the provider or null if copying is not possible. */ public static ILanguageSettingsEditableProvider getProviderCopy(ILanguageSettingsEditableProvider provider, boolean deep) { try { @@ -320,12 +327,15 @@ public class LanguageSettingsExtensionManager { } /** - * Get Language Settings Provider defined via - * {@code org.eclipse.cdt.core.LanguageSettingsProvider} extension point. + * Get language settings provider defined via extension point + * {@code org.eclipse.cdt.core.LanguageSettingsProvider}. + * A new copy of the extension provider is returned. * - * @param id - ID of provider to find. - * @param deep TODO - * @return the clone of the provider or {@code null} TODO if provider is not defined. + * @param id - ID of the extension provider. + * @param deep - {@code true} to request deep copy including copying settings entries + * or {@code false} to return shallow copy with no settings entries. + * @return the copy of the extension provider if possible (i.e. for {@link ILanguageSettingsEditableProvider}) + * or {@code null} if provider is not copyable. */ public static ILanguageSettingsProvider getExtensionProviderCopy(String id, boolean deep) { ILanguageSettingsProvider provider = fExtensionProviders.get(id); @@ -337,10 +347,13 @@ public class LanguageSettingsExtensionManager { } /** - * TODO - * @param provider - * @param deep - * @return + * Test if the provider is equal to the one defined via extension point + * {@code org.eclipse.cdt.core.LanguageSettingsProvider}. + * + * @param provider - the provider to test. + * @param deep - {@code true} to check for deep equality testing also settings entries + * or {@code false} to test shallow copy with no settings entries. + * @return - {@code true} if the provider matches the extension or {@code false} otherwise. */ public static boolean isEqualsExtensionProvider(ILanguageSettingsProvider provider, boolean deep) { String id = provider.getId(); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java index 25822dac944..8f9b62edbdd 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java @@ -88,6 +88,9 @@ public class LanguageSettingsProvidersSerializer { private static ListenerList fLanguageSettingsChangeListeners = new ListenerList(ListenerList.IDENTITY); + /** + * language settings provider listener-cfgDescription association + */ private static class ListenerAssociation { private ICListenerAgent listener; private ICConfigurationDescription cfgDescription; @@ -98,6 +101,11 @@ public class LanguageSettingsProvidersSerializer { } } + /** + * Wrapper for workspace providers to ensure level of indirection. That way workspace providers + * can be changed/replaced without notifying/changing the configurations which keep the providers + * in their lists. + */ private static class LanguageSettingsWorkspaceProvider implements ILanguageSettingsProvider, ICListenerAgent { private String providerId; private int projectCount = 0; @@ -141,6 +149,7 @@ public class LanguageSettingsProvidersSerializer { } return false; } + /** * Method toString() for debugging purposes. */ @@ -171,7 +180,7 @@ public class LanguageSettingsProvidersSerializer { @Override public void registerListener(ICConfigurationDescription cfgDescription) { - // keep in mind that rawProvider can change + // keep in mind that rawProvider can change externally ILanguageSettingsProvider rawProvider = getRawProvider(); if (rawProvider instanceof ICListenerAgent) { ((ICListenerAgent) rawProvider).registerListener(null); @@ -180,7 +189,7 @@ public class LanguageSettingsProvidersSerializer { @Override public void unregisterListener() { - // keep in mind that rawProvider can change + // keep in mind that rawProvider can change externally ILanguageSettingsProvider rawProvider = getRawProvider(); if (rawProvider instanceof ICListenerAgent) { ((ICListenerAgent) rawProvider).unregisterListener(); @@ -190,7 +199,6 @@ public class LanguageSettingsProvidersSerializer { /** * Language Settings Change Event implementation. - * */ private static class LanguageSettingsChangeEvent implements ILanguageSettingsChangeEvent { private String projectName = null; @@ -287,7 +295,7 @@ public class LanguageSettingsProvidersSerializer { } /** - * Set and store in workspace area user defined providers. + * Set and store user defined providers in workspace area. * * @param providers - array of user defined providers * @throws CoreException in case of problems @@ -424,6 +432,7 @@ projects: Element elementExtension = XmlUtil.appendElement(rootElement, ELEM_EXTENSION, new String[] {ATTR_POINT, LanguageSettingsExtensionManager.PROVIDER_EXTENSION_FULL_ID}); for (LanguageSettingsSerializableProvider provider : serializableWorkspaceProviders) { + // TODO don't serialize if equals to extension provider provider.serialize(elementExtension); } @@ -448,14 +457,17 @@ projects: } } + /** + * Load language settings for workspace. + */ public static void loadLanguageSettingsWorkspace() throws CoreException { List providers = null; URI uriStoreWsp = getStoreInWorkspaceArea(STORAGE_WORKSPACE_LANGUAGE_SETTINGS); Document doc = null; - serializingLock.acquire(); try { + serializingLock.acquire(); doc = XmlUtil.loadXml(uriStoreWsp); } catch (Exception e) { CCorePlugin.log("Can't load preferences from file "+uriStoreWsp, e); //$NON-NLS-1$ @@ -463,12 +475,12 @@ projects: serializingLock.release(); } - if (doc!=null) { + if (doc != null) { Element rootElement = doc.getDocumentElement(); NodeList providerNodes = rootElement.getElementsByTagName(LanguageSettingsSerializableProvider.ELEM_PROVIDER); List userDefinedProvidersIds = new ArrayList(); - for (int i=0;i(); - + if (provider != null) { + if (providers == null) { + providers = new ArrayList(); + } if (!LanguageSettingsManager.isEqualExtensionProvider(provider, true)) { providers.add(provider); } @@ -615,6 +627,8 @@ projects: } /** + * Load language settings to the project description from XML. + * * @noreference This method is not intended to be referenced by clients. * It is public solely for benefit of JUnit testing. */ @@ -748,6 +762,10 @@ projects: return provider; } + /** + * Load language settings from workspace and project storages for the given project description. + * @param prjDescription - project description to load language settings. + */ public static void loadLanguageSettings(ICProjectDescription prjDescription) { IProject project = prjDescription.getProject(); IFile storePrj = project.getFile(SETTINGS_FOLDER_NAME+STORAGE_PROJECT_LANGUAGE_SETTINGS); @@ -766,8 +784,8 @@ projects: URI uriStoreWsp = getStoreInWorkspaceArea(project.getName()+'.'+STORAGE_WORKSPACE_LANGUAGE_SETTINGS); Document docWsp = null; - serializingLock.acquire(); try { + serializingLock.acquire(); docWsp = XmlUtil.loadXml(uriStoreWsp); } finally { serializingLock.release(); @@ -821,6 +839,14 @@ projects: return provider; } + /** + * Helper method to get to real underlying provider collecting entries as opposed to wrapper + * which is normally used for workspace provider. + * @see LanguageSettingsProvidersSerializer#isWorkspaceProvider(ILanguageSettingsProvider) + * + * @param id - ID of the provider. + * @return raw underlying provider. + */ public static ILanguageSettingsProvider getRawWorkspaceProvider(String id) { return rawGlobalWorkspaceProviders.get(id); } @@ -839,11 +865,13 @@ projects: } /** - * Checks if the provider is defined on the workspace level. + * Checks if the provider is a workspace level provider. + * This method is intended to check providers retrieved from a configuration. + * Raw providers from {@link #getRawWorkspaceProvider(String)} + * are not considered as workspace providers. * * @param provider - provider to check. * @return {@code true} if the given provider is workspace provider, {@code false} otherwise. - * */ public static boolean isWorkspaceProvider(ILanguageSettingsProvider provider) { return provider instanceof LanguageSettingsWorkspaceProvider; @@ -1066,6 +1094,7 @@ projects: return LanguageSettingsStorage.getPooledList(provider.getSettingEntries(cfgDescription, rc, languageId)); } catch (Throwable e) { String cfgId = cfgDescription!=null ? cfgDescription.getId() : null; + @SuppressWarnings("nls") String msg = "Exception in provider "+provider.getId()+": getSettingEntries("+cfgId+", "+rc+", "+languageId+")"; CCorePlugin.log(msg, e); // return empty list to prevent getting potentially non-empty list from up the resource tree From 8c7108d523c708d96d3642d846b7ca22531e1ed6 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Mon, 12 Dec 2011 14:31:07 -0500 Subject: [PATCH 087/120] Fixed decorators in PE showing incorrectly for legacy (MBS provider) --- .../MBSLanguageSettingsProvider.java | 2 +- .../providers/ILanguageSettingsProvider.java | 2 ++ .../viewsupport/ProblemsLabelDecorator.java | 19 +++++++------------ 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/MBSLanguageSettingsProvider.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/MBSLanguageSettingsProvider.java index 230a950c250..36577281e90 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/MBSLanguageSettingsProvider.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/MBSLanguageSettingsProvider.java @@ -69,7 +69,7 @@ public class MBSLanguageSettingsProvider extends AbstractExecutableExtensionBase } } } - return list; + return LanguageSettingsStorage.getPooledList(list); } private ICLanguageSetting[] getLanguageSettings(ICResourceDescription rcDescription) { diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsProvider.java index fe428bee2dc..1dee2448905 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsProvider.java @@ -77,6 +77,8 @@ public interface ILanguageSettingsProvider { * (see {@link LanguageManager#getLanguageForFile(org.eclipse.core.resources.IFile, ICConfigurationDescription)}). * * @return the list of setting entries or {@code null} if no settings defined. + * The list needs to be a pooled list created by {@link LanguageSettingsStorage#getPooledList(List)} + * to save memory and avoid deep equality comparisons. */ public List getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/ProblemsLabelDecorator.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/ProblemsLabelDecorator.java index 7e0a833d92b..f6c933f455d 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/ProblemsLabelDecorator.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/ProblemsLabelDecorator.java @@ -30,7 +30,6 @@ import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.ui.texteditor.MarkerUtilities; -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.ILanguageSettingsProvidersKeeper; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; @@ -397,21 +396,17 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe if (cfgDescription instanceof ILanguageSettingsProvidersKeeper) { for (ILanguageSettingsProvider provider: ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders()) { - if (provider instanceof ILanguageSettingsBroadcastingProvider) { - for (String languageId : LanguageSettingsManager.getLanguages(rc, cfgDescription)) { - List list = provider.getSettingEntries(cfgDescription, rc, languageId); - if (list!=null) { - // TODO - check default or check parent? - List listDefault = provider.getSettingEntries(null, null, languageId); - // != is OK here due as the equal lists will have the same reference in WeakHashSet - if (list != listDefault) - return true; - } + for (String languageId : LanguageSettingsManager.getLanguages(rc, cfgDescription)) { + List list = provider.getSettingEntries(cfgDescription, rc, languageId); + if (list!=null) { + List listDefault = provider.getSettingEntries(cfgDescription, rc.getParent(), languageId); + // != is OK here due as the equal lists will have the same reference in WeakHashSet + if (list != listDefault) + return true; } } } } - return false; } From a34ad0edcf6edabfd5865535385e650c470fe318 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Tue, 13 Dec 2011 04:44:07 -0500 Subject: [PATCH 088/120] Do not save attributes id/name/class in properties --- .../LanguageSettingsExtensionsTests.java | 21 +++++++++++++++---- .../LanguageSettingsExtensionManager.java | 4 +++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java index 0d688223e9a..5f30e376650 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java @@ -48,6 +48,7 @@ public class LanguageSettingsExtensionsTests extends BaseTestCase { /*package*/ static final String EXTENSION_SERIALIZABLE_PROVIDER_MISSING_PARAMETER = "parameter"; /*package*/ static final String EXTENSION_EDITABLE_PROVIDER_ID = "org.eclipse.cdt.core.tests.custom.editable.language.settings.provider"; /*package*/ static final String EXTENSION_EDITABLE_PROVIDER_NAME = "Test Plugin Mock Editable Language Settings Provider"; + /*package*/ static final ICLanguageSettingEntry EXTENSION_EDITABLE_PROVIDER_ENTRY = new CMacroEntry("MACRO", "value", 0); /*package*/ static final String EXTENSION_REGISTERER_PROVIDER_ID = "org.eclipse.cdt.core.tests.language.settings.listener.registerer.provider"; /*package*/ static final String EXTENSION_USER_PROVIDER_ID = "org.eclipse.cdt.ui.user.LanguageSettingsProvider"; @@ -57,6 +58,11 @@ public class LanguageSettingsExtensionsTests extends BaseTestCase { private static final String LANG_ID = "test.lang.id"; private static final IFile FILE_0 = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("/project/path0")); + // These must match constants used in LanguageSettingsSerializableProvider + private static final String ATTR_ID = "id"; //$NON-NLS-1$ + private static final String ATTR_NAME = "name"; //$NON-NLS-1$ + private static final String ATTR_CLASS = "class"; //$NON-NLS-1$ + /** * Constructor. * @param name - name of the test. @@ -111,19 +117,23 @@ public class LanguageSettingsExtensionsTests extends BaseTestCase { assertNull(providerExt); } - // get test plugin extension provider + // this extension provider is not copyable ILanguageSettingsProvider providerExtCopy = LanguageSettingsManager.getExtensionProviderCopy(EXTENSION_BASE_PROVIDER_ID, true); assertNull(providerExtCopy); + + // get raw extension provider - retrieve the only instance via workspace provider ILanguageSettingsProvider providerExt = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_BASE_PROVIDER_ID); assertTrue(LanguageSettingsManager.isWorkspaceProvider(providerExt)); - - // get raw extension provider ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(providerExt); assertTrue(rawProvider instanceof LanguageSettingsBaseProvider); LanguageSettingsBaseProvider provider = (LanguageSettingsBaseProvider)rawProvider; assertEquals(EXTENSION_BASE_PROVIDER_ID, provider.getId()); assertEquals(EXTENSION_BASE_PROVIDER_NAME, provider.getName()); assertEquals(EXTENSION_BASE_PROVIDER_PARAMETER, provider.getProperty(EXTENSION_BASE_PROVIDER_ATTR_PARAMETER)); + // these attributes are not exposed as properties + assertEquals(null, provider.getProperty(ATTR_ID)); + assertEquals(null, provider.getProperty(ATTR_NAME)); + assertEquals(null, provider.getProperty(ATTR_CLASS)); // attempt to get entries for wrong language assertNull(provider.getSettingEntries(null, FILE_0, LANG_ID)); @@ -273,7 +283,7 @@ public class LanguageSettingsExtensionsTests extends BaseTestCase { assertEquals(null, provider.getProperty(EXTENSION_SERIALIZABLE_PROVIDER_MISSING_PARAMETER)); List expected = new ArrayList(); - expected.add(new CMacroEntry("MACRO", "value", 0)); + expected.add(EXTENSION_EDITABLE_PROVIDER_ENTRY); assertEquals(expected, provider.getSettingEntries(null, null, null)); } @@ -297,15 +307,18 @@ public class LanguageSettingsExtensionsTests extends BaseTestCase { // Editable providers are retrieved by copy { + // get extension provider ILanguageSettingsProvider providerExt = LanguageSettingsManager.getExtensionProviderCopy(EXTENSION_EDITABLE_PROVIDER_ID, true); assertFalse(LanguageSettingsManager.isWorkspaceProvider(providerExt)); assertTrue(providerExt instanceof ILanguageSettingsEditableProvider); assertTrue(LanguageSettingsManager.isEqualExtensionProvider(providerExt, true)); + // test that different copies are not same ILanguageSettingsProvider providerExt2 = LanguageSettingsManager.getExtensionProviderCopy(EXTENSION_EDITABLE_PROVIDER_ID, true); assertNotSame(providerExt, providerExt2); assertEquals(providerExt, providerExt2); + // test that workspace provider is not the same as extension provider ILanguageSettingsProvider providerWsp = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_EDITABLE_PROVIDER_ID); ILanguageSettingsProvider providerWspRaw = LanguageSettingsManager.getRawProvider(providerWsp); assertNotSame(providerExt, providerWspRaw); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java index 848eb9d8a47..d8f74aa42c6 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java @@ -169,7 +169,9 @@ public class LanguageSettingsExtensionManager { List entries = null; for (String attr : ce.getAttributeNames()) { - ceAttributes.put(attr, determineAttributeValue(ce, attr)); + if (!attr.equals(ATTR_ID) && !attr.equals(ATTR_NAME) && !attr.equals(ATTR_CLASS)) { + ceAttributes.put(attr, determineAttributeValue(ce, attr)); + } } for (IConfigurationElement ceLang : ce.getChildren(ELEM_LANGUAGE_SCOPE)) { From e64c995ff0dfaa8ce8361563c1a0e94df6a55011 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Tue, 13 Dec 2011 18:23:04 -0500 Subject: [PATCH 089/120] Separate extension and workspace providers inside implementation --- .../LanguageSettingsExtensionsTests.java | 1 + ...nguageSettingsPersistenceProjectTests.java | 44 +++++++++++ .../LanguageSettingsExtensionManager.java | 75 ++++++++++--------- .../LanguageSettingsProvidersSerializer.java | 56 ++++++++------ 4 files changed, 118 insertions(+), 58 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java index 5f30e376650..2c380caf7a1 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java @@ -48,6 +48,7 @@ public class LanguageSettingsExtensionsTests extends BaseTestCase { /*package*/ static final String EXTENSION_SERIALIZABLE_PROVIDER_MISSING_PARAMETER = "parameter"; /*package*/ static final String EXTENSION_EDITABLE_PROVIDER_ID = "org.eclipse.cdt.core.tests.custom.editable.language.settings.provider"; /*package*/ static final String EXTENSION_EDITABLE_PROVIDER_NAME = "Test Plugin Mock Editable Language Settings Provider"; + /*package*/ static final ICLanguageSettingEntry EXTENSION_SERIALIZABLE_PROVIDER_ENTRY = new CMacroEntry("MACRO", "value", 0); /*package*/ static final ICLanguageSettingEntry EXTENSION_EDITABLE_PROVIDER_ENTRY = new CMacroEntry("MACRO", "value", 0); /*package*/ static final String EXTENSION_REGISTERER_PROVIDER_ID = "org.eclipse.cdt.core.tests.language.settings.listener.registerer.provider"; /*package*/ static final String EXTENSION_USER_PROVIDER_ID = "org.eclipse.cdt.ui.user.LanguageSettingsProvider"; diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java index d0c7a4c43a6..30b58b92a16 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java @@ -44,6 +44,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { private static final String EXTENSION_BASE_PROVIDER_ID = LanguageSettingsExtensionsTests.EXTENSION_BASE_PROVIDER_ID; private static final String EXTENSION_BASE_PROVIDER_NAME = LanguageSettingsExtensionsTests.EXTENSION_BASE_PROVIDER_NAME; private static final String EXTENSION_SERIALIZABLE_PROVIDER_ID = LanguageSettingsExtensionsTests.EXTENSION_SERIALIZABLE_PROVIDER_ID; + private static final ICLanguageSettingEntry EXTENSION_SERIALIZABLE_PROVIDER_ENTRY = LanguageSettingsExtensionsTests.EXTENSION_SERIALIZABLE_PROVIDER_ENTRY; private static final String LANGUAGE_SETTINGS_PROJECT_XML = ".settings/language.settings.xml"; private static final String LANGUAGE_SETTINGS_WORKSPACE_XML = "language.settings.xml"; @@ -337,6 +338,49 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { } } + /** + */ + public void testWorkspacePersistence_UnmodifiedExtensionProvider() throws Exception { + List extensionEntries = new ArrayList(); + extensionEntries.add(EXTENSION_SERIALIZABLE_PROVIDER_ENTRY); + { + // test initial state of the extension provider + ILanguageSettingsProvider extProvider = LanguageSettingsManager.getExtensionProviderCopy(EXTENSION_SERIALIZABLE_PROVIDER_ID, true); + assertNull(extProvider); + } + { + // get the workspace provider + ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_SERIALIZABLE_PROVIDER_ID); + // check that entries match that of extension provider + assertEquals(extensionEntries, provider.getSettingEntries(null, null, null)); + ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); + assertTrue(LanguageSettingsManager.isEqualExtensionProvider(rawProvider, true)); + + // serialize language settings of workspace providers + LanguageSettingsManager.serializeLanguageSettingsWorkspace(); + } + { + // re-load + LanguageSettingsProvidersSerializer.loadLanguageSettingsWorkspace(); + + // ensure the workspace provider still matches extension + ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_SERIALIZABLE_PROVIDER_ID); + assertEquals(EXTENSION_SERIALIZABLE_PROVIDER_ID, provider.getId()); + assertEquals(extensionEntries, provider.getSettingEntries(null, null, null)); + ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); + assertTrue(LanguageSettingsManager.isEqualExtensionProvider(rawProvider, true)); + + // replace entries + assertTrue(rawProvider instanceof LanguageSettingsSerializableProvider); + List entries = new ArrayList(); + entries.add(new CIncludePathEntry("path0", 0)); + ((LanguageSettingsSerializableProvider)rawProvider).setSettingEntries(null, null, null, entries); + + // check that the extension provider is not affected + assertTrue(!LanguageSettingsManager.isEqualExtensionProvider(rawProvider, true)); + } + } + /** */ public void testWorkspacePersistence_GlobalProvider() throws Exception { diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java index d8f74aa42c6..8ba43ae9cf1 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java @@ -218,33 +218,28 @@ public class LanguageSettingsExtensionManager { } /** - * Creates empty non-configured provider from extension point definition. The method will - * inspect extension registry for extension point "org.eclipse.cdt.core.LanguageSettingsProvider" + * Creates provider from extension point definition which matches value of the given attribute. + * The method will inspect extension registry for extension point "org.eclipse.cdt.core.LanguageSettingsProvider" * to determine bundle and instantiate the class. - * ID and name of provider are assigned from the first encountered extension point specifying the class. * - * @param className - full qualified class name of provider. - * @param registry - extension registry - * @return new non-configured provider + * @param attr - attribute to match. + * @param attrValue - value of the attribute to match. + * @param registry - extension registry. + * @param configure - flag which indicates if provider needs to be configured. + * @return new instance of the provider */ - private static ILanguageSettingsProvider createProviderCarcass(String className, IExtensionRegistry registry) { - if (className==null || className.length()==0) { - return new LanguageSettingsBaseProvider(); - } - + private static ILanguageSettingsProvider loadProviderFromRegistry(String attr, String attrValue, + IExtensionRegistry registry, boolean configure) { try { IExtensionPoint extension = registry.getExtensionPoint(CCorePlugin.PLUGIN_ID, PROVIDER_EXTENSION_SIMPLE_ID); if (extension != null) { IExtension[] extensions = extension.getExtensions(); for (IExtension ext : extensions) { for (IConfigurationElement cfgEl : ext.getConfigurationElements()) { - if (cfgEl.getName().equals(ELEM_PROVIDER) && className.equals(cfgEl.getAttribute(ATTR_CLASS))) { + if (cfgEl.getName().equals(ELEM_PROVIDER) && attrValue.equals(cfgEl.getAttribute(attr))) { ILanguageSettingsProvider provider = createExecutableExtension(cfgEl); - if (provider instanceof AbstractExecutableExtensionBase) { - String ceId = determineAttributeValue(cfgEl, ATTR_ID); - String ceName = determineAttributeValue(cfgEl, ATTR_NAME); - ((AbstractExecutableExtensionBase) provider).setId(ceId); - ((AbstractExecutableExtensionBase) provider).setName(ceName); + if (configure) { + configureExecutableProvider(provider, cfgEl); } return provider; } @@ -258,12 +253,13 @@ public class LanguageSettingsExtensionManager { } /** - * Create an instance of language settings provider of given class name. + * Create an instance of non-configured language settings provider of given class name. + * The class should be known or registered with the extension point. * * @param className - class name to instantiate. * @return new instance of language settings provider. */ - /*package*/ static ILanguageSettingsProvider getProviderInstance(String className) { + /*package*/ static ILanguageSettingsProvider instantiateProviderClass(String className) { if (className==null || className.equals(LanguageSettingsSerializableProvider.class.getName())) { return new LanguageSettingsSerializableProvider(); } @@ -277,7 +273,8 @@ public class LanguageSettingsExtensionManager { return new LanguageSettingsGenericProvider(); } - ILanguageSettingsProvider provider = createProviderCarcass(className, Platform.getExtensionRegistry()); + // Create it as executable extension from the extension registry. + ILanguageSettingsProvider provider = loadProviderFromRegistry(ATTR_CLASS, className, Platform.getExtensionRegistry(), false); if (provider == null) { IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "Not able to load provider class=" + className); //$NON-NLS-1$ CCorePlugin.log(new CoreException(status)); @@ -286,22 +283,32 @@ public class LanguageSettingsExtensionManager { } /** - * @return list of providers contributed by all extensions. Preferable copy but if not possible - * will return raw provider. + * Load an instance of language settings provider of given id from the extension point. + * The class should be registered with the extension point. + * + * @param id - class name to instantiate. + * @return new instance of language settings provider. */ - /*package*/ static List getExtensionProvidersInternal() { - ArrayList list = new ArrayList(fExtensionProviders.size()); - for (String id : fExtensionProviders.keySet()) { - ILanguageSettingsProvider extensionProvider = getExtensionProviderCopy(id, true); - if (extensionProvider == null) { - extensionProvider = fExtensionProviders.get(id); - } - - if (extensionProvider != null) { - list.add(extensionProvider); - } + /*package*/ static ILanguageSettingsProvider loadProvider(String id) { + if (id==null) { + return null; } - return list; + + // Create it as executable extension from the extension registry. + ILanguageSettingsProvider provider = loadProviderFromRegistry(ATTR_ID, id, Platform.getExtensionRegistry(), true); + if (provider == null) { + IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "Not able to load provider id=" + id); //$NON-NLS-1$ + CCorePlugin.log(new CoreException(status)); + } + return provider; + } + + /** + * Returns list of provider id-s contributed by all extensions. + * @return list of provider id-s contributed by all extensions. + */ + public static Set getExtensionProviderIds() { + return fExtensionProviders.keySet(); } /** diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java index 8f9b62edbdd..4786a6260cc 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java @@ -295,18 +295,18 @@ public class LanguageSettingsProvidersSerializer { } /** - * Set and store user defined providers in workspace area. - * - * @param providers - array of user defined providers - * @throws CoreException in case of problems - */ - public static void setWorkspaceProviders(List providers) throws CoreException { - setWorkspaceProvidersInternal(providers); - serializeLanguageSettingsWorkspace(); - // generate preference change event - IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(CCorePlugin.PLUGIN_ID); - prefs.putBoolean(PREFERENCE_WORSPACE_PROVIDERS_SET, ! prefs.getBoolean(PREFERENCE_WORSPACE_PROVIDERS_SET, false)); - } + * Set and store user defined providers in workspace area. + * + * @param providers - array of user defined providers + * @throws CoreException in case of problems + */ + public static void setWorkspaceProviders(List providers) throws CoreException { + setWorkspaceProvidersInternal(providers); + serializeLanguageSettingsWorkspace(); + // generate preference change event + IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(CCorePlugin.PLUGIN_ID); + prefs.putBoolean(PREFERENCE_WORSPACE_PROVIDERS_SET, ! prefs.getBoolean(PREFERENCE_WORSPACE_PROVIDERS_SET, false)); + } /** * Internal method to set user defined providers in memory. @@ -316,13 +316,8 @@ public class LanguageSettingsProvidersSerializer { */ private static void setWorkspaceProvidersInternal(List providers) { Map rawWorkspaceProviders = new HashMap(); - List extensionProviders = new ArrayList(LanguageSettingsExtensionManager.getExtensionProvidersInternal()); - for (ILanguageSettingsProvider rawExtensionProvider : extensionProviders) { - if (rawExtensionProvider!=null) { - rawWorkspaceProviders.put(rawExtensionProvider.getId(), rawExtensionProvider); - } - } + // given providers List rawProviders = new ArrayList(); if (providers!=null) { for (ILanguageSettingsProvider provider : providers) { @@ -338,6 +333,20 @@ public class LanguageSettingsProvidersSerializer { } } + // fill the rest from extension registry + // this list is independent from the internal list of extensions in LanguageSettingsExtensionManager + for (String id : LanguageSettingsExtensionManager.getExtensionProviderIds()) { + if (!rawWorkspaceProviders.containsKey(id)) { + ILanguageSettingsProvider provider = LanguageSettingsExtensionManager.getExtensionProviderCopy(id, true); + if (provider == null) { + provider = LanguageSettingsExtensionManager.loadProvider(id); + } + if (provider != null) { + rawWorkspaceProviders.put(provider.getId(), provider); + } + } + } + List oldListeners = selectListeners(rawGlobalWorkspaceProviders.values()); List newListeners = selectListeners(rawProviders); @@ -432,8 +441,9 @@ projects: Element elementExtension = XmlUtil.appendElement(rootElement, ELEM_EXTENSION, new String[] {ATTR_POINT, LanguageSettingsExtensionManager.PROVIDER_EXTENSION_FULL_ID}); for (LanguageSettingsSerializableProvider provider : serializableWorkspaceProviders) { - // TODO don't serialize if equals to extension provider - provider.serialize(elementExtension); + if (!LanguageSettingsManager.isEqualExtensionProvider(provider, true)) { + provider.serialize(elementExtension); + } } try { @@ -495,9 +505,7 @@ projects: if (providers == null) { providers = new ArrayList(); } - if (!LanguageSettingsManager.isEqualExtensionProvider(provider, true)) { - providers.add(provider); - } + providers.add(provider); } } } @@ -754,7 +762,7 @@ projects: private static ILanguageSettingsProvider loadProvider(Node providerNode) { String attrClass = XmlUtil.determineAttributeValue(providerNode, LanguageSettingsExtensionManager.ATTR_CLASS); - ILanguageSettingsProvider provider = LanguageSettingsExtensionManager.getProviderInstance(attrClass); + ILanguageSettingsProvider provider = LanguageSettingsExtensionManager.instantiateProviderClass(attrClass); if (provider instanceof LanguageSettingsSerializableProvider) ((LanguageSettingsSerializableProvider)provider).load((Element) providerNode); From 8715c43cde77796d1efb0c5e5c8885cb43e2aba2 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Wed, 14 Dec 2011 14:37:27 -0500 Subject: [PATCH 090/120] Consolidate usage of constants --- .../AbstractBuiltinSpecsDetector.java | 6 +- .../LanguageSettingsExtensionsTests.java | 13 +- .../LanguageSettingsSerializableTests.java | 8 +- .../model/CProjectDescriptionDeltaTests.java | 2 +- .../LanguageSettingsSerializableProvider.java | 13 +- .../LanguageSettingsExtensionManager.java | 24 ++-- .../LanguageSettingsProvidersSerializer.java | 116 ++++++++++-------- .../LanguageSettingsSerializableStorage.java | 30 ++--- 8 files changed, 112 insertions(+), 100 deletions(-) diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java index 0022c02bf8e..332fc2a11c6 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java @@ -103,7 +103,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti private class SDMarkerGenerator implements IMarkerGenerator { protected static final String SCANNER_DISCOVERY_PROBLEM_MARKER = MakeCorePlugin.PLUGIN_ID + ".scanner.discovery.problem"; //$NON-NLS-1$ - protected static final String PROVIDER = "provider"; //$NON-NLS-1$ + protected static final String ATTR_PROVIDER = "provider"; //$NON-NLS-1$ @Override public void addMarker(IResource file, int lineNumber, String errorDesc, int severity, String errorVar) { @@ -142,7 +142,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti IMarker marker = problemMarkerInfo.file.createMarker(SDMarkerGenerator.SCANNER_DISCOVERY_PROBLEM_MARKER); marker.setAttribute(IMarker.MESSAGE, problemMarkerInfo.description); marker.setAttribute(IMarker.SEVERITY, problemMarkerInfo.severity); - marker.setAttribute(SDMarkerGenerator.PROVIDER, providerId); + marker.setAttribute(SDMarkerGenerator.ATTR_PROVIDER, providerId); if (problemMarkerInfo.file instanceof IWorkspaceRoot) { marker.setAttribute(IMarker.LOCATION, "SD90 Providers, [" + providerName + "] options in Preferences"); @@ -360,7 +360,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti try { IMarker[] cur = markersResource.findMarkers(SDMarkerGenerator.SCANNER_DISCOVERY_PROBLEM_MARKER, false, IResource.DEPTH_ZERO); for (IMarker marker : cur) { - if (getId().equals(marker.getAttribute(SDMarkerGenerator.PROVIDER))) { + if (getId().equals(marker.getAttribute(SDMarkerGenerator.ATTR_PROVIDER))) { marker.delete(); } } diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java index 2c380caf7a1..e3bf7ecf40b 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java @@ -25,6 +25,7 @@ import org.eclipse.cdt.core.settings.model.CMacroFileEntry; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.core.testplugin.util.BaseTestCase; +import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.Path; @@ -59,10 +60,10 @@ public class LanguageSettingsExtensionsTests extends BaseTestCase { private static final String LANG_ID = "test.lang.id"; private static final IFile FILE_0 = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("/project/path0")); - // These must match constants used in LanguageSettingsSerializableProvider - private static final String ATTR_ID = "id"; //$NON-NLS-1$ - private static final String ATTR_NAME = "name"; //$NON-NLS-1$ - private static final String ATTR_CLASS = "class"; //$NON-NLS-1$ + // Constants used in LanguageSettingsSerializableProvider + private static final String ATTR_ID = LanguageSettingsProvidersSerializer.ATTR_ID; + private static final String ATTR_NAME = LanguageSettingsProvidersSerializer.ATTR_NAME; + private static final String ATTR_CLASS = LanguageSettingsProvidersSerializer.ATTR_CLASS; /** * Constructor. @@ -255,11 +256,11 @@ public class LanguageSettingsExtensionsTests extends BaseTestCase { List entries = new ArrayList(); entries.add(new CIncludePathEntry("/usr/include/", 0)); // configure it - provider.configureProvider("id", "name", null, entries, null); + provider.configureProvider("test.id", "test.name", null, entries, null); try { // attempt to configure it twice should fail - provider.configureProvider("id", "name", null, entries, null); + provider.configureProvider("test.id", "test.name", null, entries, null); fail("LanguageSettingsBaseProvider is not allowed to be configured twice"); } catch (UnsupportedOperationException e) { } diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java index 1e26760efd7..b8554871730 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java @@ -810,7 +810,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { public void testCIncludeFileEntryDOM() throws Exception { Element elementProvider; List entries = new ArrayList(); - entries.add(new CIncludeFileEntry("name", 1)); + entries.add(new CIncludeFileEntry("a-path", 1)); { // create a provider and serialize its settings LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); @@ -874,7 +874,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { public void testCMacroFileEntryDOM() throws Exception { Element elementProvider; List entries = new ArrayList(); - entries.add(new CMacroFileEntry("name", 1)); + entries.add(new CMacroFileEntry("a-path", 1)); { // create a provider and serialize its settings LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); @@ -906,7 +906,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { public void testCLibraryPathEntryDOM() throws Exception { Element elementProvider; List entries = new ArrayList(); - entries.add(new CLibraryPathEntry("name", 1)); + entries.add(new CLibraryPathEntry("a-path", 1)); { // create a provider and serialize its settings LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); @@ -938,7 +938,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { public void testCLibraryFileEntryDOM() throws Exception { Element elementProvider; List entries = new ArrayList(); - entries.add(new CLibraryFileEntry("name", 1)); + entries.add(new CLibraryFileEntry("a-path", 1)); { // create a provider and serialize its settings LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/settings/model/CProjectDescriptionDeltaTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/settings/model/CProjectDescriptionDeltaTests.java index 921b2256cb5..6ce8cab4a87 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/settings/model/CProjectDescriptionDeltaTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/settings/model/CProjectDescriptionDeltaTests.java @@ -1017,7 +1017,7 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase{ List originalProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); // Modification LANGUAGE_SETTINGS_PROVIDERS - ILanguageSettingsProvider provider = new LanguageSettingsSerializableProvider("id", "name"); + ILanguageSettingsProvider provider = new LanguageSettingsSerializableProvider("test.id", "test.name"); List providers = new ArrayList(); providers.add(provider); ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableProvider.java index 69698156d79..1924c37e144 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableProvider.java @@ -21,6 +21,7 @@ import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.internal.core.XmlUtil; +import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer; import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsSerializableStorage; import org.eclipse.core.resources.IResource; import org.w3c.dom.Element; @@ -37,13 +38,11 @@ import org.w3c.dom.NodeList; * {@link ILanguageSettingsProvider}. */ public class LanguageSettingsSerializableProvider extends LanguageSettingsBaseProvider implements ILanguageSettingsBroadcastingProvider { - /** This field is for internal use only */ - public static final String ELEM_PROVIDER = "provider"; //$NON-NLS-1$ - private static final String ATTR_ID = "id"; //$NON-NLS-1$ - - private static final String ELEM_LANGUAGE_SCOPE = "language-scope"; //$NON-NLS-1$ - private static final String ATTR_NAME = "name"; //$NON-NLS-1$ - private static final String ATTR_CLASS = "class"; //$NON-NLS-1$ + protected static final String ATTR_ID = LanguageSettingsProvidersSerializer.ATTR_ID; + protected static final String ATTR_NAME = LanguageSettingsProvidersSerializer.ATTR_NAME; + protected static final String ATTR_CLASS = LanguageSettingsProvidersSerializer.ATTR_CLASS; + protected static final String ELEM_PROVIDER = LanguageSettingsProvidersSerializer.ELEM_PROVIDER; + protected static final String ELEM_LANGUAGE_SCOPE = LanguageSettingsProvidersSerializer.ELEM_LANGUAGE_SCOPE; private LanguageSettingsSerializableStorage fStorage = new LanguageSettingsSerializableStorage(); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java index 8ba43ae9cf1..3cd33be7b40 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java @@ -44,20 +44,20 @@ import org.eclipse.core.runtime.Status; */ public class LanguageSettingsExtensionManager { /** Name of the extension point for contributing language settings */ - static final String PROVIDER_EXTENSION_FULL_ID = "org.eclipse.cdt.core.LanguageSettingsProvider"; //$NON-NLS-1$ + static final String PROVIDER_EXTENSION_POINT_ID = "org.eclipse.cdt.core.LanguageSettingsProvider"; //$NON-NLS-1$ static final String PROVIDER_EXTENSION_SIMPLE_ID = "LanguageSettingsProvider"; //$NON-NLS-1$ - - static final String ELEM_PROVIDER = "provider"; //$NON-NLS-1$ - static final String ATTR_CLASS = "class"; //$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_CLASS = "class"; //$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_ENTRY = "entry"; //$NON-NLS-1$ - static final String ELEM_FLAG = "flag"; //$NON-NLS-1$ - static final String ATTR_KIND = "kind"; //$NON-NLS-1$ - static final String ATTR_VALUE = "value"; //$NON-NLS-1$ + static final String ATTR_ENTRY_NAME = "name"; //$NON-NLS-1$ + static final String ATTR_ENTRY_KIND = "kind"; //$NON-NLS-1$ + static final String ATTR_ENTRY_VALUE = "value"; //$NON-NLS-1$ + static final String ELEM_ENTRY_FLAG = "flag"; //$NON-NLS-1$ /** * Extension providers loaded once. If the provider is editable (read cloneable) @@ -186,13 +186,13 @@ public class LanguageSettingsExtensionManager { for (IConfigurationElement ceEntry : ce.getChildren(ELEM_ENTRY)) { try { - int entryKind = LanguageSettingEntriesSerializer.stringToKind(determineAttributeValue(ceEntry, ATTR_KIND)); - String entryName = determineAttributeValue(ceEntry, ATTR_NAME); - String entryValue = determineAttributeValue(ceEntry, ATTR_VALUE); + int entryKind = LanguageSettingEntriesSerializer.stringToKind(determineAttributeValue(ceEntry, ATTR_ENTRY_KIND)); + String entryName = determineAttributeValue(ceEntry, ATTR_ENTRY_NAME); + String entryValue = determineAttributeValue(ceEntry, ATTR_ENTRY_VALUE); int flags = 0; - for (IConfigurationElement ceFlags : ceEntry.getChildren(ELEM_FLAG)) { - int bitFlag = LanguageSettingEntriesSerializer.composeFlags(determineAttributeValue(ceFlags, ATTR_VALUE)); + for (IConfigurationElement ceFlags : ceEntry.getChildren(ELEM_ENTRY_FLAG)) { + int bitFlag = LanguageSettingEntriesSerializer.composeFlags(determineAttributeValue(ceFlags, ATTR_ENTRY_VALUE)); flags |= bitFlag; } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java index 4786a6260cc..b25eabb3b19 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java @@ -64,16 +64,23 @@ import org.w3c.dom.NodeList; * Helper class handling serialization and notifications for language settings entries {@link ICLanguageSettingEntry}. */ public class LanguageSettingsProvidersSerializer { + public static final String PROVIDER_EXTENSION_POINT_ID = LanguageSettingsExtensionManager.PROVIDER_EXTENSION_POINT_ID; + public static final String ATTR_ID = LanguageSettingsExtensionManager.ATTR_ID; + public static final String ATTR_NAME = LanguageSettingsExtensionManager.ATTR_NAME; + public static final String ATTR_CLASS = LanguageSettingsExtensionManager.ATTR_CLASS; + public static final String ELEM_PROVIDER = LanguageSettingsExtensionManager.ELEM_PROVIDER; + public static final String ELEM_LANGUAGE_SCOPE = LanguageSettingsExtensionManager.ELEM_LANGUAGE_SCOPE; + private static final String PREFERENCE_WORSPACE_PROVIDERS_SET = "language.settings.providers.set.for.workspace"; //$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_LANGUAGE_SETTINGS = "language.settings.xml"; //$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 ATTR_POINT = "point"; //$NON-NLS-1$ + private static final String ATTR_EXTENSION_POINT = "point"; //$NON-NLS-1$ private static final String ELEM_PROJECT = "project"; //$NON-NLS-1$ private static final String ELEM_CONFIGURATION = "configuration"; //$NON-NLS-1$ - private static final String ELEM_PROVIDER = "provider"; //$NON-NLS-1$ private static final String ELEM_PROVIDER_REFERENCE = "provider-reference"; //$NON-NLS-1$ private static final String ATTR_STORE_ENTRIES = "store-entries"; //$NON-NLS-1$ @@ -290,8 +297,7 @@ public class LanguageSettingsProvidersSerializer { */ private static URI getStoreInWorkspaceArea(String store) { IPath location = CCorePlugin.getDefault().getStateLocation().append(store); - URI uri = URIUtil.toURI(location); - return uri; + return URIUtil.toURI(location); } /** @@ -315,43 +321,40 @@ public class LanguageSettingsProvidersSerializer { * is passed user defined providers are cleared. */ private static void setWorkspaceProvidersInternal(List providers) { - Map rawWorkspaceProviders = new HashMap(); + Map rawNewProviders = new HashMap(); - // given providers - List rawProviders = new ArrayList(); - if (providers!=null) { + // add given providers + if (providers != null) { for (ILanguageSettingsProvider provider : providers) { if (isWorkspaceProvider(provider)) { provider = rawGlobalWorkspaceProviders.get(provider.getId()); } - if (provider!=null) { - rawProviders.add(provider); + if (provider != null) { + rawNewProviders.put(provider.getId(), provider); } } - for (ILanguageSettingsProvider provider : rawProviders) { - rawWorkspaceProviders.put(provider.getId(), provider); - } } // fill the rest from extension registry // this list is independent from the internal list of extensions in LanguageSettingsExtensionManager for (String id : LanguageSettingsExtensionManager.getExtensionProviderIds()) { - if (!rawWorkspaceProviders.containsKey(id)) { + if (!rawNewProviders.containsKey(id)) { ILanguageSettingsProvider provider = LanguageSettingsExtensionManager.getExtensionProviderCopy(id, true); if (provider == null) { provider = LanguageSettingsExtensionManager.loadProvider(id); } if (provider != null) { - rawWorkspaceProviders.put(provider.getId(), provider); + rawNewProviders.put(provider.getId(), provider); } } } + // register listeners List oldListeners = selectListeners(rawGlobalWorkspaceProviders.values()); - List newListeners = selectListeners(rawProviders); + List newListeners = selectListeners(rawNewProviders.values()); for (ICListenerAgent oldListener : oldListeners) { - if (!isObjectInTheList(newListeners, oldListener)) { + if (!isInList(newListeners, oldListener)) { LanguageSettingsWorkspaceProvider wspProvider = (LanguageSettingsWorkspaceProvider) globalWorkspaceProviders.get(((ILanguageSettingsProvider)oldListener).getId()); if (wspProvider != null && wspProvider.getProjectCount() > 0) { oldListener.unregisterListener(); @@ -360,7 +363,7 @@ public class LanguageSettingsProvidersSerializer { } for (ICListenerAgent newListener : newListeners) { - if (!isObjectInTheList(oldListeners, newListener)) { + if (!isInList(oldListeners, newListener)) { LanguageSettingsWorkspaceProvider wspProvider = (LanguageSettingsWorkspaceProvider) globalWorkspaceProviders.get(((ILanguageSettingsProvider)newListener).getId()); if (wspProvider != null && wspProvider.getProjectCount() > 0) { newListener.registerListener(null); @@ -368,7 +371,7 @@ public class LanguageSettingsProvidersSerializer { } } - rawGlobalWorkspaceProviders = rawWorkspaceProviders; + rawGlobalWorkspaceProviders = rawNewProviders; } private static List createLanguageSettingsChangeEvents(List serializableProviders) { @@ -410,10 +413,10 @@ projects: /** * Save language settings providers of the workspace (global providers) to persistent storage. - * * @throws CoreException */ public static void serializeLanguageSettingsWorkspace() throws CoreException { + // FIXME - temporary log to remove before CDT 9.0 release LanguageSettingsLogger.logWarning("LanguageSettingsProvidersSerializer.serializeLanguageSettingsWorkspace()"); URI uriStoreWsp = getStoreInWorkspaceArea(STORAGE_WORKSPACE_LANGUAGE_SETTINGS); @@ -438,7 +441,8 @@ projects: } else { Document doc = XmlUtil.newDocument(); Element rootElement = XmlUtil.appendElement(doc, ELEM_PLUGIN); - Element elementExtension = XmlUtil.appendElement(rootElement, ELEM_EXTENSION, new String[] {ATTR_POINT, LanguageSettingsExtensionManager.PROVIDER_EXTENSION_FULL_ID}); + Element elementExtension = XmlUtil.appendElement(rootElement, ELEM_EXTENSION, + new String[] {ATTR_EXTENSION_POINT, PROVIDER_EXTENSION_POINT_ID}); for (LanguageSettingsSerializableProvider provider : serializableWorkspaceProviders) { if (!LanguageSettingsManager.isEqualExtensionProvider(provider, true)) { @@ -480,19 +484,21 @@ projects: serializingLock.acquire(); doc = XmlUtil.loadXml(uriStoreWsp); } catch (Exception e) { - CCorePlugin.log("Can't load preferences from file "+uriStoreWsp, e); //$NON-NLS-1$ + CCorePlugin.log("Can't load preferences from file " + uriStoreWsp, e); //$NON-NLS-1$ } finally { serializingLock.release(); } if (doc != null) { Element rootElement = doc.getDocumentElement(); - NodeList providerNodes = rootElement.getElementsByTagName(LanguageSettingsSerializableProvider.ELEM_PROVIDER); + NodeList providerNodes = rootElement.getElementsByTagName(ELEM_PROVIDER); + + List userDefinedProvidersIds = new ArrayList(providerNodes.getLength()); + providers = new ArrayList(providerNodes.getLength()); - List userDefinedProvidersIds = new ArrayList(); for (int i = 0; i < providerNodes.getLength(); i++) { Node providerNode = providerNodes.item(i); - String providerId = XmlUtil.determineAttributeValue(providerNode, LanguageSettingsExtensionManager.ATTR_ID); + String providerId = XmlUtil.determineAttributeValue(providerNode, ATTR_ID); if (userDefinedProvidersIds.contains(providerId)) { String msg = "Ignored an attempt to persist duplicate language settings provider, id=" + providerId; //$NON-NLS-1$ CCorePlugin.log(new Status(IStatus.WARNING, CCorePlugin.PLUGIN_ID, msg, new Exception())); @@ -502,9 +508,6 @@ projects: ILanguageSettingsProvider provider = loadProvider(providerNode); if (provider != null) { - if (providers == null) { - providers = new ArrayList(); - } providers.add(provider); } } @@ -524,20 +527,20 @@ projects: continue; Element elementConfiguration = XmlUtil.appendElement(projectElementPrjStore, ELEM_CONFIGURATION, new String[] { - LanguageSettingsExtensionManager.ATTR_ID, cfgDescription.getId(), - LanguageSettingsExtensionManager.ATTR_NAME, cfgDescription.getName(), + ATTR_ID, cfgDescription.getId(), + ATTR_NAME, cfgDescription.getName(), }); Element elementConfigurationWsp = null; List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); if (providers.size()>0) { Element elementExtension = XmlUtil.appendElement(elementConfiguration, ELEM_EXTENSION, new String[] { - ATTR_POINT, LanguageSettingsExtensionManager.PROVIDER_EXTENSION_FULL_ID}); + ATTR_EXTENSION_POINT, PROVIDER_EXTENSION_POINT_ID}); Element elementExtensionWsp = null; for (ILanguageSettingsProvider provider : providers) { if (isWorkspaceProvider(provider)) { // Element elementProviderReference = XmlUtil.appendElement(elementExtension, ELEM_PROVIDER_REFERENCE, new String[] { - LanguageSettingsExtensionManager.ATTR_ID, provider.getId()}); + ATTR_ID, provider.getId()}); continue; } if (provider instanceof LanguageSettingsSerializableProvider) { @@ -553,23 +556,23 @@ projects: if (elementExtensionWsp==null) { if (elementConfigurationWsp==null) { elementConfigurationWsp = XmlUtil.appendElement(projectElementWspStore, ELEM_CONFIGURATION, new String[] { - LanguageSettingsExtensionManager.ATTR_ID, cfgDescription.getId(), - LanguageSettingsExtensionManager.ATTR_NAME, cfgDescription.getName(), + ATTR_ID, cfgDescription.getId(), + ATTR_NAME, cfgDescription.getName(), }); } elementExtensionWsp = XmlUtil.appendElement(elementConfigurationWsp, ELEM_EXTENSION, new String[] { - ATTR_POINT, LanguageSettingsExtensionManager.PROVIDER_EXTENSION_FULL_ID}); + ATTR_EXTENSION_POINT, PROVIDER_EXTENSION_POINT_ID}); } Element elementProviderWsp = XmlUtil.appendElement(elementExtensionWsp, ELEM_PROVIDER, new String[] { - LanguageSettingsExtensionManager.ATTR_ID, provider.getId()}); + ATTR_ID, provider.getId()}); lss.serializeEntries(elementProviderWsp); } } else { // Element elementProvider = - XmlUtil.appendElement(elementExtension, LanguageSettingsExtensionManager.ELEM_PROVIDER, new String[] { - LanguageSettingsExtensionManager.ATTR_ID, provider.getId(), - LanguageSettingsExtensionManager.ATTR_NAME, provider.getName(), - LanguageSettingsExtensionManager.ATTR_CLASS, provider.getClass().getCanonicalName(), + XmlUtil.appendElement(elementExtension, ELEM_PROVIDER, new String[] { + ATTR_ID, provider.getId(), + ATTR_NAME, provider.getName(), + ATTR_CLASS, provider.getClass().getCanonicalName(), }); } } @@ -657,9 +660,9 @@ projects: if (!(cfgNode instanceof Element && cfgNode.getNodeName().equals(ELEM_CONFIGURATION)) ) continue; List providers = new ArrayList(); - String cfgId = XmlUtil.determineAttributeValue(cfgNode, LanguageSettingsExtensionManager.ATTR_ID); + String cfgId = XmlUtil.determineAttributeValue(cfgNode, ATTR_ID); @SuppressWarnings("unused") - String cfgName = XmlUtil.determineAttributeValue(cfgNode, LanguageSettingsExtensionManager.ATTR_NAME); + String cfgName = XmlUtil.determineAttributeValue(cfgNode, ATTR_NAME); NodeList extensionAndReferenceNodes = cfgNode.getChildNodes(); for (int ie=0;ie providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); for (ILanguageSettingsProvider provider : providers) { if (!LanguageSettingsManager.isWorkspaceProvider(provider)) { - if (isObjectInTheList(prjProviders, provider)) { + if (isInList(prjProviders, provider)) { IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "Inconsistent state, duplicate LSP in project description " + "[" + System.identityHashCode(provider) + "] " + provider); @@ -913,7 +916,10 @@ projects: } } - private static boolean isObjectInTheList(Collection list, T element) { + /** + * Check that this particular element is in the list. + */ + private static boolean isInList(Collection list, T element) { // list.contains(element) won't do it as we are interested in exact object, not in equal object for (T elem : list) { if (elem == element) @@ -922,6 +928,9 @@ projects: return false; } + /** + * Check that this particular element is in the association list. + */ private static boolean isListenerInTheListOfAssociations(Collection list, ICListenerAgent element) { // list.contains(element) won't do it as we are interested in exact object, not in equal object for (ListenerAssociation la : list) { @@ -944,7 +953,7 @@ projects: for (ILanguageSettingsProvider provider : providers) { if (provider instanceof ICListenerAgent) { ICListenerAgent listener = (ICListenerAgent) provider; - if (!isObjectInTheList(listeners, listener)) { + if (!isInList(listeners, listener)) { listeners.add(listener); } } @@ -955,6 +964,9 @@ projects: return listeners; } + /** + * Pick from the list providers which are listeners, i.e. instances of type {@link ICListenerAgent}. + */ private static List selectListeners(Collection values) { List listeners = new ArrayList(); for (ILanguageSettingsProvider provider : values) { @@ -1024,7 +1036,7 @@ projects: for (ListenerAssociation newListenerAssociation : newAssociations) { ICListenerAgent newListener = newListenerAssociation.listener; - if (!isObjectInTheList(oldListeners, newListener)) { + if (!isInList(oldListeners, newListener)) { int count = 1; if (newListener instanceof LanguageSettingsWorkspaceProvider) { count = ((LanguageSettingsWorkspaceProvider) newListener).incrementProjectCount(); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsSerializableStorage.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsSerializableStorage.java index 70c7904ed16..c8fe2a73a99 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsSerializableStorage.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsSerializableStorage.java @@ -34,11 +34,11 @@ public class LanguageSettingsSerializableStorage extends LanguageSettingsStorage private static final String ELEM_RESOURCE = "resource"; //$NON-NLS-1$ private static final String ATTR_PROJECT_PATH = "project-relative-path"; //$NON-NLS-1$ - private static final String ELEM_ENTRY = "entry"; //$NON-NLS-1$ - private static final String ATTR_KIND = "kind"; //$NON-NLS-1$ - private static final String ATTR_NAME = "name"; //$NON-NLS-1$ - private static final String ATTR_VALUE = "value"; //$NON-NLS-1$ - private static final String ELEM_FLAG = "flag"; //$NON-NLS-1$ + private static final String ELEM_ENTRY = LanguageSettingsExtensionManager.ELEM_ENTRY; + private static final String ATTR_ENTRY_KIND = LanguageSettingsExtensionManager.ATTR_ENTRY_KIND; + private static final String ATTR_ENTRY_NAME = LanguageSettingsExtensionManager.ATTR_ENTRY_NAME; + private static final String ATTR_ENTRY_VALUE = LanguageSettingsExtensionManager.ATTR_ENTRY_VALUE; + private static final String ELEM_ENTRY_FLAG = LanguageSettingsExtensionManager.ELEM_ENTRY_FLAG; /** * Serialize the provider entries under parent XML element. @@ -83,12 +83,12 @@ public class LanguageSettingsSerializableStorage extends LanguageSettingsStorage private void serializeSettingEntries(Element parentElement, List settingEntries) { for (ICLanguageSettingEntry entry : settingEntries) { Element elementSettingEntry = XmlUtil.appendElement(parentElement, ELEM_ENTRY, new String[] { - ATTR_KIND, LanguageSettingEntriesSerializer.kindToString(entry.getKind()), - ATTR_NAME, entry.getName(), + ATTR_ENTRY_KIND, LanguageSettingEntriesSerializer.kindToString(entry.getKind()), + ATTR_ENTRY_NAME, entry.getName(), }); switch (entry.getKind()) { case ICSettingEntry.MACRO: - elementSettingEntry.setAttribute(ATTR_VALUE, entry.getValue()); + elementSettingEntry.setAttribute(ATTR_ENTRY_VALUE, entry.getValue()); break; // case ICLanguageSettingEntry.LIBRARY_FILE: // // YAGNI: sourceAttachment fields may need to be covered @@ -97,8 +97,8 @@ public class LanguageSettingsSerializableStorage extends LanguageSettingsStorage int flags = entry.getFlags(); if (flags != 0) { // Element elementFlag = - XmlUtil.appendElement(elementSettingEntry, ELEM_FLAG, new String[] { - ATTR_VALUE, LanguageSettingEntriesSerializer.composeFlagsString(entry.getFlags()) + XmlUtil.appendElement(elementSettingEntry, ELEM_ENTRY_FLAG, new String[] { + ATTR_ENTRY_VALUE, LanguageSettingEntriesSerializer.composeFlagsString(entry.getFlags()) }); } } @@ -138,17 +138,17 @@ public class LanguageSettingsSerializableStorage extends LanguageSettingsStorage * Load a setting entry from XML element. */ private ICLanguageSettingEntry loadSettingEntry(Node parentElement) { - String settingKind = XmlUtil.determineAttributeValue(parentElement, ATTR_KIND); - String settingName = XmlUtil.determineAttributeValue(parentElement, ATTR_NAME); + String settingKind = XmlUtil.determineAttributeValue(parentElement, ATTR_ENTRY_KIND); + String settingName = XmlUtil.determineAttributeValue(parentElement, ATTR_ENTRY_NAME); NodeList flagNodes = parentElement.getChildNodes(); int flags = 0; for (int i=0;i Date: Wed, 14 Dec 2011 15:18:22 -0500 Subject: [PATCH 091/120] JavaDoc and one more unit test --- ...nguageSettingsPersistenceProjectTests.java | 59 +++++++++++++++++++ .../LanguageSettingsExtensionManager.java | 21 +++---- 2 files changed, 67 insertions(+), 13 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java index 30b58b92a16..44c65c77c25 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java @@ -44,6 +44,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { private static final String EXTENSION_BASE_PROVIDER_ID = LanguageSettingsExtensionsTests.EXTENSION_BASE_PROVIDER_ID; private static final String EXTENSION_BASE_PROVIDER_NAME = LanguageSettingsExtensionsTests.EXTENSION_BASE_PROVIDER_NAME; private static final String EXTENSION_SERIALIZABLE_PROVIDER_ID = LanguageSettingsExtensionsTests.EXTENSION_SERIALIZABLE_PROVIDER_ID; + private static final String EXTENSION_USER_PROVIDER_ID = LanguageSettingsExtensionsTests.EXTENSION_USER_PROVIDER_ID; private static final ICLanguageSettingEntry EXTENSION_SERIALIZABLE_PROVIDER_ENTRY = LanguageSettingsExtensionsTests.EXTENSION_SERIALIZABLE_PROVIDER_ENTRY; private static final String LANGUAGE_SETTINGS_PROJECT_XML = ".settings/language.settings.xml"; @@ -530,6 +531,64 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { } } + /** + */ + public void testProjectPersistence_UserProviderDOM() throws Exception { + Element rootElement = null; + + List entries = new ArrayList(); + entries.add(new CIncludePathEntry("path0", 0)); + + { + // 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); + + ILanguageSettingsProvider provider = LanguageSettingsManager.getExtensionProviderCopy(EXTENSION_USER_PROVIDER_ID, false); + assertTrue(provider instanceof LanguageSettingsGenericProvider); + LanguageSettingsGenericProvider serializableProvider = (LanguageSettingsGenericProvider) provider; + serializableProvider.setSettingEntries(null, null, null, entries); + LanguageSettingsManager.setStoringEntriesInProjectArea(serializableProvider, true); + + ArrayList providers = new ArrayList(); + providers.add(serializableProvider); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); + + // prepare DOM storage + Document doc = XmlUtil.newDocument(); + rootElement = XmlUtil.appendElement(doc, ELEM_TEST); + // serialize language settings to the DOM + LanguageSettingsProvidersSerializer.serializeLanguageSettingsInternal(rootElement, null, mockPrjDescription); + assertTrue(XmlUtil.toString(doc).contains(EXTENSION_USER_PROVIDER_ID)); + assertTrue(XmlUtil.toString(doc).contains(LanguageSettingsGenericProvider.class.getName())); + } + { + // re-load and check language settings of the newly loaded provider + MockProjectDescription mockPrjDescription = new MockProjectDescription(new MockConfigurationDescription(CFG_ID)); + LanguageSettingsProvidersSerializer.loadLanguageSettingsInternal(rootElement, null, mockPrjDescription); + + ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations(); + assertNotNull(cfgDescriptions); + assertEquals(1, cfgDescriptions.length); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); + + List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); + assertNotNull(providers); + assertEquals(1, providers.size()); + ILanguageSettingsProvider provider = providers.get(0); + assertTrue(provider instanceof LanguageSettingsGenericProvider); + + List actual = provider.getSettingEntries(null, null, null); + assertEquals(entries.get(0), actual.get(0)); + assertEquals(entries.size(), actual.size()); + } + } + /** */ public void testProjectPersistence_TwoConfigurationsDOM() throws Exception { diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java index 3cd33be7b40..e6339342f14 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java @@ -60,8 +60,8 @@ public class LanguageSettingsExtensionManager { static final String ELEM_ENTRY_FLAG = "flag"; //$NON-NLS-1$ /** - * Extension providers loaded once. If the provider is editable (read cloneable) - * external callers get copy rather than real instance. + * Extension providers loaded once and used for equality only. + * Those who request extension provider will get copy rather than real instance. */ private static final LinkedHashMap fExtensionProviders = new LinkedHashMap(); @@ -80,7 +80,7 @@ public class LanguageSettingsExtensionManager { * Load language settings providers contributed via the extension point. */ synchronized private static void loadProviderExtensions() { - // sort by name - the providers defined via extensions are kept in separate list sorted + // sort by name - the providers defined via extensions are kept in separate list sorted by name Set sortedProviders = new TreeSet( new Comparator() { @Override @@ -131,7 +131,7 @@ public class LanguageSettingsExtensionManager { private static String determineAttributeValue(IConfigurationElement ce, String attr) { String value = ce.getAttribute(attr); - return value!=null ? value : ""; //$NON-NLS-1$ + return value != null ? value : ""; //$NON-NLS-1$ } /** @@ -254,7 +254,7 @@ public class LanguageSettingsExtensionManager { /** * Create an instance of non-configured language settings provider of given class name. - * The class should be known or registered with the extension point. + * The class should be known to this method or registered with the extension point. * * @param className - class name to instantiate. * @return new instance of language settings provider. @@ -263,15 +263,9 @@ public class LanguageSettingsExtensionManager { if (className==null || className.equals(LanguageSettingsSerializableProvider.class.getName())) { return new LanguageSettingsSerializableProvider(); } - - // TODO unit test case for this if (className.equals(LanguageSettingsGenericProvider.class.getName())) { return new LanguageSettingsGenericProvider(); } - // FIXME - older usage, will fade it out - if (className.equals("org.eclipse.cdt.internal.ui.language.settings.providers.UserLanguageSettingsProvider")) { - return new LanguageSettingsGenericProvider(); - } // Create it as executable extension from the extension registry. ILanguageSettingsProvider provider = loadProviderFromRegistry(ATTR_CLASS, className, Platform.getExtensionRegistry(), false); @@ -305,7 +299,7 @@ public class LanguageSettingsExtensionManager { /** * Returns list of provider id-s contributed by all extensions. - * @return list of provider id-s contributed by all extensions. + * @return the provider id-s. */ public static Set getExtensionProviderIds() { return fExtensionProviders.keySet(); @@ -320,7 +314,7 @@ public class LanguageSettingsExtensionManager { * @param deep - {@code true} to request deep copy including copying settings entries * or {@code false} to return shallow copy with no settings entries. * - * @return a copy of the provider or null if copying is not possible. + * @return a copy of the provider or {@code null} if copying is not possible. */ public static ILanguageSettingsEditableProvider getProviderCopy(ILanguageSettingsEditableProvider provider, boolean deep) { try { @@ -362,6 +356,7 @@ public class LanguageSettingsExtensionManager { * @param provider - the provider to test. * @param deep - {@code true} to check for deep equality testing also settings entries * or {@code false} to test shallow copy with no settings entries. + * Shallow equality is applicable only for {@link ILanguageSettingsEditableProvider}. * @return - {@code true} if the provider matches the extension or {@code false} otherwise. */ public static boolean isEqualsExtensionProvider(ILanguageSettingsProvider provider, boolean deep) { From 271e78c6a0946f0264e76d25da643a21948776b3 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Wed, 14 Dec 2011 15:51:34 -0500 Subject: [PATCH 092/120] JavaDoc --- .../AbstractBuiltinSpecsDetector.java | 5 +- ...AbstractLanguageSettingsOutputScanner.java | 1 + .../model/util/PathEntryTranslator.java | 12 ++-- .../providers/LanguageSettingsLogger.java | 3 +- .../LanguageSettingsProvidersSerializer.java | 64 +++++++++++++------ .../LanguageSettingsScannerInfoProvider.java | 3 +- .../model/DescriptionScannerInfoProvider.java | 4 +- .../cdt/core/resources/ScannerProvider.java | 2 +- 8 files changed, 62 insertions(+), 32 deletions(-) diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java index 332fc2a11c6..b0df7f9e374 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java @@ -270,6 +270,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti @Override public void registerListener(ICConfigurationDescription cfgDescription) { + // AG FIXME - temporary log to remove before CDT 9.0 release LanguageSettingsLogger.logInfo(getPrefixForLog() + "registerListener [" + System.identityHashCode(this) + "] " + this); currentCfgDescription = cfgDescription; @@ -278,6 +279,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti @Override public void unregisterListener() { + // AG FIXME - temporary log to remove before CDT 9.0 release LanguageSettingsLogger.logInfo(getPrefixForLog() + "unregisterListener [" + System.identityHashCode(this) + "] " + this); } @@ -318,7 +320,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti job.setRule(rule); job.schedule(); - // TODO - remove me + // AG FIXME - temporary log to remove before CDT 9.0 release LanguageSettingsLogger.logInfo(getPrefixForLog() + "Execution scheduled [" + System.identityHashCode(this) + "] " + this); } @@ -461,6 +463,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti if (detectedSettingEntries != null && detectedSettingEntries.size() > 0) { collected = detectedSettingEntries.size(); + // AG FIXME - temporary log to remove before CDT 9.0 release LanguageSettingsLogger.logInfo(getPrefixForLog() + getClass().getSimpleName() + " collected " + detectedSettingEntries.size() + " entries" + " for language " + currentLanguageId); diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java index 0c373948d47..96588e50935 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java @@ -320,6 +320,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett protected void setSettingEntries(List entries) { setSettingEntries(currentCfgDescription, currentResource, currentLanguageId, entries); + // AG FIXME - temporary log to remove before CDT 9.0 release LanguageSettingsLogger.logInfo(getPrefixForLog() + getClass().getSimpleName() + " collected " + (entries!=null ? ("" + entries.size()) : "null") + " entries for " + currentResource); } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/PathEntryTranslator.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/PathEntryTranslator.java index 1f197a9da03..8a29a9ab166 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/PathEntryTranslator.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/PathEntryTranslator.java @@ -2041,7 +2041,8 @@ public class PathEntryTranslator { public boolean visit(PathSettingsContainer container) { CResourceData data = (CResourceData)container.getValue(); if (data != null) { - AG_log(des, kinds, data); // AG FIXME REMOVEME + // AG FIXME - temporary log to remove before CDT 9.0 release + temporaryLog(des, kinds, data); PathEntryCollector child = cr.createChild(container.getPath()); for (int kind : kinds) { @@ -2055,8 +2056,9 @@ public class PathEntryTranslator { return true; } - // AG FIXME REMOVEME - private void AG_log(final ICConfigurationDescription des, final int[] kinds, CResourceData data) { + // AG FIXME - temporary log to remove before CDT 9.0 release + @Deprecated + private void temporaryLog(final ICConfigurationDescription des, final int[] kinds, CResourceData data) { String kindsStr=""; for (int kind : kinds) { String kstr = LanguageSettingEntriesSerializer.kindToString(kind); @@ -2092,7 +2094,7 @@ public class PathEntryTranslator { return false; } - + IProject project = des.getProjectDescription().getProject(); if (ScannerDiscoveryLegacySupport.isLanguageSettingsProvidersFunctionalityEnabled(project)) { IResource rc = getResource(project, data.getPath()); @@ -2100,7 +2102,7 @@ public class PathEntryTranslator { list.addAll(LanguageSettingsManager.getSettingEntriesByKind(des, rc, lData.getLanguageId(), kind)); } return list.size()>0; - + } // Legacy logic boolean supported = false; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsLogger.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsLogger.java index 37ab0530aa9..8babc9e1605 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsLogger.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsLogger.java @@ -8,7 +8,8 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; /** - * Temporary class for logging language settings providers development. + * AG FIXME -Temporary class for logging language settings providers development. + * To remove before CDT 9.0 release * */ @Deprecated diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java index b25eabb3b19..55082c1fb3a 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java @@ -374,34 +374,55 @@ public class LanguageSettingsProvidersSerializer { rawGlobalWorkspaceProviders = rawNewProviders; } - private static List createLanguageSettingsChangeEvents(List serializableProviders) { + /** + * Create event for language settings changes of workspace providers in a project. + */ + private static LanguageSettingsChangeEvent createEvent(ICProjectDescription prjDescription, List providerIds) { + ICConfigurationDescription[] cfgDescriptions = prjDescription.getConfigurations(); + for (ICConfigurationDescription cfgDescription : cfgDescriptions) { + if (cfgDescription instanceof ILanguageSettingsProvidersKeeper) { + for (ILanguageSettingsProvider provider : ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders()) { + if (isWorkspaceProvider(provider) && providerIds.contains(provider.getId())) { + LanguageSettingsChangeEvent event = new LanguageSettingsChangeEvent(prjDescription); + if (event.getConfigurationDescriptionIds().length > 0) { + return event; + } + return null; + } + } + } + } + + return null; + } + + /** + * Compute events for language settings changes in workspace. + */ + private static List createLanguageSettingsChangeEvents(List providers) { List events = new ArrayList(); - List serializableIds = new ArrayList(); - for (LanguageSettingsSerializableProvider provider : serializableProviders) { - serializableIds.add(provider.getId()); + List providerIds = new ArrayList(); + for (LanguageSettingsSerializableProvider provider : providers) { + providerIds.add(provider.getId()); } IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IProject[] projects = root.getProjects(); -projects: + for (IProject project : projects) { if (project.isAccessible()) { ICProjectDescription prjDescription = CCorePlugin.getDefault().getProjectDescription(project, false); if (prjDescription != null) { - ICConfigurationDescription[] cfgDescriptions = prjDescription.getConfigurations(); - for (ICConfigurationDescription cfgDescription : cfgDescriptions) { - if (cfgDescription instanceof ILanguageSettingsProvidersKeeper) { - for (ILanguageSettingsProvider provider : ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders()) { - if (isWorkspaceProvider(provider) && serializableIds.contains(provider.getId())) { - LanguageSettingsChangeEvent event = new LanguageSettingsChangeEvent(prjDescription); - if (event.getConfigurationDescriptionIds().length > 0) { - events.add(event); - } - continue projects; - } - } + try { + LanguageSettingsChangeEvent event = createEvent(prjDescription, providerIds); + if (event != null) { + events.add(event); } + } catch (Throwable e) { + // log and swallow any exception + CCorePlugin.log("Error creating event about changes in workspace language settings providers, " //$NON-NLS-1$ + + "project=" + project.getName(), e); //$NON-NLS-1$ } } } @@ -416,7 +437,7 @@ projects: * @throws CoreException */ public static void serializeLanguageSettingsWorkspace() throws CoreException { - // FIXME - temporary log to remove before CDT 9.0 release + // AG FIXME - temporary log to remove before CDT 9.0 release LanguageSettingsLogger.logWarning("LanguageSettingsProvidersSerializer.serializeLanguageSettingsWorkspace()"); URI uriStoreWsp = getStoreInWorkspaceArea(STORAGE_WORKSPACE_LANGUAGE_SETTINGS); @@ -588,6 +609,7 @@ projects: */ public static void serializeLanguageSettings(ICProjectDescription prjDescription) throws CoreException { IProject project = prjDescription.getProject(); + // AG FIXME - temporary log to remove before CDT 9.0 release LanguageSettingsLogger.logWarning("LanguageSettingsProvidersSerializer.serializeLanguageSettings() for " + project); try { @@ -1098,12 +1120,12 @@ projects: * @param event the ILanguageSettingsChangeEvent event to be broadcast. */ public static void notifyLanguageSettingsChangeListeners(ILanguageSettingsChangeEvent event) { + // AG FIXME - temporary log to remove before CDT 9.0 release LanguageSettingsLogger.logWarning("Firing " + event); Object[] listeners = fLanguageSettingsChangeListeners.getListeners(); - for (Object obj : listeners) { - ILanguageSettingsChangeListener listener = (ILanguageSettingsChangeListener) obj; - listener.handleEvent(event); + for (Object listener : listeners) { + ((ILanguageSettingsChangeListener) listener).handleEvent(event); } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsScannerInfoProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsScannerInfoProvider.java index d34a52176b3..ece845d9b5e 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsScannerInfoProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsScannerInfoProvider.java @@ -52,8 +52,9 @@ public class LanguageSettingsScannerInfoProvider implements IScannerInfoProvider @Override public ExtendedScannerInfo getScannerInformation(IResource rc) { + // AG FIXME - temporary log to remove before CDT 9.0 release LanguageSettingsLogger.logScannerInfoProvider(rc, this); - + IProject project = rc.getProject(); if (project==null) return DUMMY_SCANNER_INFO; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/DescriptionScannerInfoProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/DescriptionScannerInfoProvider.java index 25def77a37c..087656f76c6 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/DescriptionScannerInfoProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/DescriptionScannerInfoProvider.java @@ -78,9 +78,9 @@ public class DescriptionScannerInfoProvider implements IScannerInfoProvider, ICP @Override public IScannerInfo getScannerInformation(IResource resource) { - // AG FIXME + // AG FIXME - temporary log to remove before CDT 9.0 release LanguageSettingsLogger.logScannerInfoProvider(resource, this); - + if(!fInited) updateProjCfgInfo(CProjectDescriptionManager.getInstance().getProjectDescription(fProject, false)); diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/ScannerProvider.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/ScannerProvider.java index 091ba1e09b8..7a87ec34f65 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/ScannerProvider.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/ScannerProvider.java @@ -98,7 +98,7 @@ public class ScannerProvider extends AbstractCExtension implements IScannerInfoP */ @Override public IScannerInfo getScannerInformation(IResource resource) { - // AG FIXME + // AG FIXME - temporary log to remove before CDT 9.0 release if (resource instanceof IFile) { LanguageSettingsLogger.logInfo("rc="+resource+" (ScannerProvider.getScannerInformation())"); } else { From 60239b57cabe8a751393d33e0c4c7e76cc99d961 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Fri, 16 Dec 2011 12:07:36 -0500 Subject: [PATCH 093/120] Some clean-up and JavaDoc --- .../AbstractBuiltinSpecsDetector.java | 8 +- ...AbstractLanguageSettingsOutputScanner.java | 2 +- .../LanguageSettingsManagerTests.java | 25 +- ...ILanguageSettingsBroadcastingProvider.java | 3 +- .../ILanguageSettingsChangeEvent.java | 7 +- .../providers/LanguageSettingsManager.java | 72 +-- .../model/util/PathEntryTranslator.java | 8 +- .../providers/LanguageSettingsDelta.java | 2 +- .../providers/LanguageSettingsLogger.java | 2 +- .../LanguageSettingsProvidersSerializer.java | 563 +++++++++--------- .../LanguageSettingsScannerInfoProvider.java | 2 +- .../model/DescriptionScannerInfoProvider.java | 2 +- .../cdt/core/resources/ScannerProvider.java | 2 +- 13 files changed, 343 insertions(+), 355 deletions(-) diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java index b0df7f9e374..d5106cfabdf 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java @@ -270,7 +270,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti @Override public void registerListener(ICConfigurationDescription cfgDescription) { - // AG FIXME - temporary log to remove before CDT 9.0 release + // AG FIXME - temporary log to remove before CDT Juno release LanguageSettingsLogger.logInfo(getPrefixForLog() + "registerListener [" + System.identityHashCode(this) + "] " + this); currentCfgDescription = cfgDescription; @@ -279,7 +279,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti @Override public void unregisterListener() { - // AG FIXME - temporary log to remove before CDT 9.0 release + // AG FIXME - temporary log to remove before CDT Juno release LanguageSettingsLogger.logInfo(getPrefixForLog() + "unregisterListener [" + System.identityHashCode(this) + "] " + this); } @@ -320,7 +320,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti job.setRule(rule); job.schedule(); - // AG FIXME - temporary log to remove before CDT 9.0 release + // AG FIXME - temporary log to remove before CDT Juno release LanguageSettingsLogger.logInfo(getPrefixForLog() + "Execution scheduled [" + System.identityHashCode(this) + "] " + this); } @@ -463,7 +463,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti if (detectedSettingEntries != null && detectedSettingEntries.size() > 0) { collected = detectedSettingEntries.size(); - // AG FIXME - temporary log to remove before CDT 9.0 release + // AG FIXME - temporary log to remove before CDT Juno release LanguageSettingsLogger.logInfo(getPrefixForLog() + getClass().getSimpleName() + " collected " + detectedSettingEntries.size() + " entries" + " for language " + currentLanguageId); diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java index 96588e50935..848f9307861 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java @@ -320,7 +320,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett protected void setSettingEntries(List entries) { setSettingEntries(currentCfgDescription, currentResource, currentLanguageId, entries); - // AG FIXME - temporary log to remove before CDT 9.0 release + // AG FIXME - temporary log to remove before CDT Juno release LanguageSettingsLogger.logInfo(getPrefixForLog() + getClass().getSimpleName() + " collected " + (entries!=null ? ("" + entries.size()) : "null") + " entries for " + currentResource); } diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java index 16b286f145a..66855fae87a 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java @@ -198,7 +198,7 @@ public class LanguageSettingsManagerTests extends BaseTestCase { assertEquals(0, actual.size()); } { - List actual = LanguageSettingsManager + List actual = LanguageSettingsProvidersSerializer .getSettingEntriesByKind(cfgDescription, FILE_0, LANG_ID, 0); assertNotNull(actual); assertEquals(0, actual.size()); @@ -226,7 +226,7 @@ public class LanguageSettingsManagerTests extends BaseTestCase { assertEquals(1, actual.size()); } { - List actual = LanguageSettingsManager + List actual = LanguageSettingsProvidersSerializer .getSettingEntriesByKind(cfgDescription, FILE_0, LANG_ID, 0); assertNotNull(actual); assertEquals(0, actual.size()); @@ -486,14 +486,14 @@ public class LanguageSettingsManagerTests extends BaseTestCase { cfgDescription.setLanguageSettingProviders(providers); // retrieve entries by kind - List includes = LanguageSettingsManager + List includes = LanguageSettingsProvidersSerializer .getSettingEntriesByKind(cfgDescription, FILE_0, LANG_ID, ICSettingEntry.INCLUDE_PATH); assertEquals(new CIncludePathEntry("path0", 0),includes.get(0)); assertEquals(new CIncludePathEntry("path1", 0),includes.get(1)); assertEquals(new CIncludePathEntry("path2", 0),includes.get(2)); assertEquals(3, includes.size()); - List macros = LanguageSettingsManager + List macros = LanguageSettingsProvidersSerializer .getSettingEntriesByKind(cfgDescription, FILE_0, LANG_ID, ICSettingEntry.MACRO); assertEquals(new CMacroEntry("MACRO0", "value0",0), macros.get(0)); assertEquals(new CMacroEntry("MACRO1", "value1",0), macros.get(1)); @@ -518,8 +518,7 @@ public class LanguageSettingsManagerTests extends BaseTestCase { cfgDescription.setLanguageSettingProviders(providers); // retrieve entries by kind, only first entry should be returned - List includes = LanguageSettingsManager - .getSettingEntriesByKind(cfgDescription, FILE_0, LANG_ID, ICSettingEntry.INCLUDE_PATH); + List includes = LanguageSettingsProvidersSerializer.getSettingEntriesByKind(cfgDescription, FILE_0, LANG_ID, ICSettingEntry.INCLUDE_PATH); assertEquals(1, includes.size()); assertEquals(entries.get(0),includes.get(0)); } @@ -541,7 +540,7 @@ public class LanguageSettingsManagerTests extends BaseTestCase { cfgDescription.setLanguageSettingProviders(providers); // retrieve entries by kind, no entries should be returned - List includes = LanguageSettingsManager + List includes = LanguageSettingsProvidersSerializer .getSettingEntriesByKind(cfgDescription, FILE_0, LANG_ID, ICSettingEntry.INCLUDE_PATH); assertEquals(0, includes.size()); } @@ -619,7 +618,7 @@ public class LanguageSettingsManagerTests extends BaseTestCase { cfgDescription.setLanguageSettingProviders(providers); // retrieve entries by kind - List includes = LanguageSettingsManager + List includes = LanguageSettingsProvidersSerializer .getSettingEntriesByKind(cfgDescription, FILE_0, LANG_ID, ICSettingEntry.INCLUDE_PATH); // path0 is taken from higher priority provider assertEquals(entriesHigh.get(0),includes.get(0)); @@ -828,7 +827,7 @@ public class LanguageSettingsManagerTests extends BaseTestCase { LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); provider.setSettingEntries(null, file, null, entries); // build the hierarchy - LanguageSettingsManager.buildResourceTree(provider, null, null, project); + LanguageSettingsProvidersSerializer.buildResourceTree(provider, null, null, project); // check that entries go to highest possible level assertEquals(entries, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file, null)); @@ -857,7 +856,7 @@ public class LanguageSettingsManagerTests extends BaseTestCase { provider.setSettingEntries(null, file1, null, entries1); provider.setSettingEntries(null, file2, null, entries2); // build the hierarchy - LanguageSettingsManager.buildResourceTree(provider, null, null, project); + LanguageSettingsProvidersSerializer.buildResourceTree(provider, null, null, project); // check that entries go to highest possible level assertEquals(entries1, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file1, null)); @@ -891,7 +890,7 @@ public class LanguageSettingsManagerTests extends BaseTestCase { provider.setSettingEntries(null, file1, null, entries1); provider.setSettingEntries(null, file2, null, entries1); // build the hierarchy - LanguageSettingsManager.buildResourceTree(provider, null, null, project); + LanguageSettingsProvidersSerializer.buildResourceTree(provider, null, null, project); // double-check where the entries go assertEquals(entries1, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file1, null)); assertEquals(entries1, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file2, null)); @@ -901,7 +900,7 @@ public class LanguageSettingsManagerTests extends BaseTestCase { provider.setSettingEntries(null, file2, null, entries2); provider.setSettingEntries(null, file3, null, entries2); // build the hierarchy - LanguageSettingsManager.buildResourceTree(provider, null, null, project); + LanguageSettingsProvidersSerializer.buildResourceTree(provider, null, null, project); // check where the entries go, it should not lose entries for the first file assertEquals(entries1, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file1, null)); assertEquals(entries2, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file2, null)); @@ -926,7 +925,7 @@ public class LanguageSettingsManagerTests extends BaseTestCase { LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); provider.setSettingEntries(null, file, LANG_CPP, entries); // build the hierarchy - LanguageSettingsManager.buildResourceTree(provider, null, LANG_CPP, project); + LanguageSettingsProvidersSerializer.buildResourceTree(provider, null, LANG_CPP, project); // check that entries go to highest possible level assertEquals(entries, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file, LANG_CPP)); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsBroadcastingProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsBroadcastingProvider.java index 5ab3297eab3..68a1b95da54 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsBroadcastingProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsBroadcastingProvider.java @@ -14,12 +14,11 @@ import java.util.List; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; -import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer; import org.eclipse.core.resources.IResource; /** * This interface is to be implemented by providers which want to broadcast the changes in their setting entries - * by {@link LanguageSettingsProvidersSerializer#notifyLanguageSettingsChangeListeners(ILanguageSettingsChangeEvent)} + * with {@link ILanguageSettingsChangeEvent}. */ public interface ILanguageSettingsBroadcastingProvider extends ILanguageSettingsProvider { @Override diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsChangeEvent.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsChangeEvent.java index 15099441d9b..fca6b4a60ef 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsChangeEvent.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsChangeEvent.java @@ -14,13 +14,14 @@ import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; /** * Contains the details of changes that occurred as a result of modifying - * language settings entries {@link ICLanguageSettingEntry}. The event is - * associated with a project. + * language settings entries {@link ICLanguageSettingEntry}. This event is + * intended to be fired for changes in entries, not necessarily providers. + * The event is associated with a project. * *

    * EXPERIMENTAL. This class interface is not stable yet as * it is not currently clear how it may need to be used in future. Only bare - * minimum is provided here at this point (CDT 9.0). + * minimum is provided here at this point (CDT 9.0, Juno). * There is no guarantee that this API will work or that it will remain the same. * Please do not use this API without consulting with the CDT team. *

    diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java index c51c0eab544..4aa43ae7290 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java @@ -24,11 +24,9 @@ import org.eclipse.cdt.core.settings.model.ICLanguageSetting; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.core.settings.model.ICResourceDescription; -import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsExtensionManager; import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer; import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; @@ -42,7 +40,7 @@ public class LanguageSettingsManager { * Returns the list of setting entries of the given provider * for the given configuration description, resource and language. * This method reaches to the parent folder of the resource recursively - * in case the resource does not define the entries for the given provider. + * if the resource does not define the entries for the given provider. * * @param provider - language settings provider. * @param cfgDescription - configuration description. @@ -56,52 +54,9 @@ public class LanguageSettingsManager { return LanguageSettingsProvidersSerializer.getSettingEntriesUpResourceTree(provider, cfgDescription, rc, languageId); } - /** - * Builds for the provider a nice looking resource tree to present hierarchical view to the user. - * - * TODO - Note that after using this method for a while for BOP parsers it appears that disadvantages - * outweigh benefits. In particular, it doesn't result in saving memory as the language settings - * (and the lists itself) are not duplicated in memory anyway but optimized with using WeakHashSet - * and SafeStringInterner. - * - * @param provider - language settings provider to build the tree for. - * @param cfgDescription - configuration description. - * @param languageId - language ID. - * @param project - the project which is considered the root of the resource tree. - */ - public static void buildResourceTree(LanguageSettingsSerializableProvider provider, - ICConfigurationDescription cfgDescription, String languageId, IProject project) { - LanguageSettingsProvidersSerializer.buildResourceTree(provider, cfgDescription, languageId, project); - } - - - /** - * Returns the list of setting entries of a certain kind (such as include paths) - * for the given configuration description, resource and language. This is a - * combined list for all providers taking into account settings of parent folder - * if settings for the given resource are not defined. - * - * @param cfgDescription - configuration description. - * @param rc - resource such as file or folder. - * @param languageId - language id. - * @param kind - kind of language settings entries, such as - * {@link ICSettingEntry#INCLUDE_PATH} etc. This is a binary flag - * and it is possible to specify composite kind. - * Use {@link ICSettingEntry#ALL} to get all kinds. - * - * @return the list of setting entries. - */ - // FIXME: get rid of callers PathEntryTranslator and DescriptionScannerInfoProvider - public static List getSettingEntriesByKind(ICConfigurationDescription cfgDescription, IResource rc, String languageId, int kind) { - return LanguageSettingsProvidersSerializer.getSettingEntriesByKind(cfgDescription, rc, languageId, kind); - } - - /** - * Get Language Settings Provider defined in the workspace. That includes user-defined - * providers and after that providers defined as extensions via - * {@code org.eclipse.cdt.core.LanguageSettingsProvider} extension point. - * That returns actual object, any modifications will affect any configuration - * referring to the provider. +/** + * Get Language Settings Provider from the list of workspace providers, + * see {@link #getWorkspaceProviders()}. * * @param id - id of provider to find. * @return the provider or {@code null} if provider is not defined. @@ -111,10 +66,14 @@ public class LanguageSettingsManager { } /** - * @return a list of language settings providers defined on workspace level. - * That includes user-defined providers and after that providers defined as - * extensions via {@code org.eclipse.cdt.core.LanguageSettingsProvider} - * extension point. + * Get Language Settings Providers defined in the workspace. That includes + * user-defined providers and after that providers defined as extensions via + * {@code org.eclipse.cdt.core.LanguageSettingsProvider} extension point. + * Note that this returns wrappers around workspace provider so underlying + * provider could be replaced internally without need to change configuration. + * See also {@link #getRawProvider(ILanguageSettingsProvider)}. + * + * @return list of workspace providers. */ public static List getWorkspaceProviders() { return LanguageSettingsProvidersSerializer.getWorkspaceProviders(); @@ -137,7 +96,7 @@ public class LanguageSettingsManager { * Helper method to get to real underlying provider collecting entries as opposed to wrapper * which is normally used for workspace provider. * @see LanguageSettingsProvidersSerializer#isWorkspaceProvider(ILanguageSettingsProvider) - * + * * @param provider - the provider to get raw provider for. Can be either workspace provider * or regular one. * @return raw underlying provider for workspace provider or provider itself if no wrapper is used. @@ -168,7 +127,7 @@ public class LanguageSettingsManager { * Copy language settings provider. It is different from clone() methods in that * it does not throw {@code CloneNotSupportedException} but returns {@code null} * instead. - * + * * @param provider - language settings provider to copy. * @param deep - {@code true} to request deep copy including copying settings entries * or {@code false} to return shallow copy with no settings entries. @@ -197,7 +156,7 @@ public class LanguageSettingsManager { /** * Test if the provider is equal to the one defined via extension point * {@code org.eclipse.cdt.core.LanguageSettingsProvider}. - * + * * @param provider - the provider to test. * @param deep - {@code true} to check for deep equality testing also settings entries * or {@code false} to test shallow copy with no settings entries. @@ -344,5 +303,4 @@ public class LanguageSettingsManager { public static void serializeLanguageSettingsWorkspace() throws CoreException { LanguageSettingsProvidersSerializer.serializeLanguageSettingsWorkspace(); } - } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/PathEntryTranslator.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/PathEntryTranslator.java index 8a29a9ab166..b347ac81b3a 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/PathEntryTranslator.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/PathEntryTranslator.java @@ -26,7 +26,6 @@ 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.LanguageSettingsManager; import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySupport; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CoreModel; @@ -71,6 +70,7 @@ 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.LanguageSettingsLogger; +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; @@ -2041,7 +2041,7 @@ public class PathEntryTranslator { public boolean visit(PathSettingsContainer container) { CResourceData data = (CResourceData)container.getValue(); if (data != null) { - // AG FIXME - temporary log to remove before CDT 9.0 release + // AG FIXME - temporary log to remove before CDT Juno release temporaryLog(des, kinds, data); PathEntryCollector child = cr.createChild(container.getPath()); @@ -2056,7 +2056,7 @@ public class PathEntryTranslator { return true; } - // AG FIXME - temporary log to remove before CDT 9.0 release + // AG FIXME - temporary log to remove before CDT Juno release @Deprecated private void temporaryLog(final ICConfigurationDescription des, final int[] kinds, CResourceData data) { String kindsStr=""; @@ -2099,7 +2099,7 @@ public class PathEntryTranslator { if (ScannerDiscoveryLegacySupport.isLanguageSettingsProvidersFunctionalityEnabled(project)) { IResource rc = getResource(project, data.getPath()); for (CLanguageData lData : lDatas) { - list.addAll(LanguageSettingsManager.getSettingEntriesByKind(des, rc, lData.getLanguageId(), kind)); + list.addAll(LanguageSettingsProvidersSerializer.getSettingEntriesByKind(des, rc, lData.getLanguageId(), kind)); } return list.size()>0; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsDelta.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsDelta.java index 994597b69fb..ab21380266d 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsDelta.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsDelta.java @@ -24,7 +24,7 @@ import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; *

    * EXPERIMENTAL. This class interface is not stable yet as * it is not currently clear how it may need to be used in future. Only bare - * minimum is provided here at this point (CDT 9.0). + * minimum is provided here at this point (CDT 9.0, Juno). * There is no guarantee that this API will work or that it will remain the same. * Please do not use this API without consulting with the CDT team. *

    diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsLogger.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsLogger.java index 8babc9e1605..d5b0d6aebd6 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsLogger.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsLogger.java @@ -9,7 +9,7 @@ import org.eclipse.core.runtime.Status; /** * AG FIXME -Temporary class for logging language settings providers development. - * To remove before CDT 9.0 release + * To remove before CDT Juno release * */ @Deprecated diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java index 55082c1fb3a..3dcbf5713fc 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java @@ -71,7 +71,7 @@ public class LanguageSettingsProvidersSerializer { public static final String ELEM_PROVIDER = LanguageSettingsExtensionManager.ELEM_PROVIDER; public static final String ELEM_LANGUAGE_SCOPE = LanguageSettingsExtensionManager.ELEM_LANGUAGE_SCOPE; - private static final String PREFERENCE_WORSPACE_PROVIDERS_SET = "language.settings.providers.set.for.workspace"; //$NON-NLS-1$ + private static final String PREFERENCE_WORSPACE_PROVIDERS_SET = "language.settings.providers.workspace.prefs.toggle"; //$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_LANGUAGE_SETTINGS = "language.settings.xml"; //$NON-NLS-1$ @@ -87,13 +87,13 @@ public class LanguageSettingsProvidersSerializer { private static final String VALUE_WORKSPACE = "workspace"; //$NON-NLS-1$ private static final String VALUE_PROJECT = "project"; //$NON-NLS-1$ - private static ILock serializingLock = Job.getJobManager().newLock(); - - /** Cache of globally available providers to be consumed by calling clients */ + /** Cache of true (raw) workspace providers */ private static Map rawGlobalWorkspaceProviders = new HashMap(); + /** Cache of workspace providers wrappers */ private static Map globalWorkspaceProviders = new HashMap(); private static ListenerList fLanguageSettingsChangeListeners = new ListenerList(ListenerList.IDENTITY); + private static ILock serializingLock = Job.getJobManager().newLock(); /** * language settings provider listener-cfgDescription association @@ -269,11 +269,35 @@ public class LanguageSettingsProvidersSerializer { try { loadLanguageSettingsWorkspace(); } catch (Throwable e) { - // log and swallow any exception + // log but swallow any exception CCorePlugin.log("Error loading workspace language settings providers", e); //$NON-NLS-1$ } } + /** + * 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 + * the entries migrate with the project. + * + * @param provider - provider to check the persistence mode. + * @return {@code true} if LSE persisted with the project or {@code false} if in the workspace. + */ + public static boolean isStoringEntriesInProjectArea(LanguageSettingsSerializableProvider provider) { + String value = provider.getProperty(ATTR_STORE_ENTRIES); + return VALUE_PROJECT.equals(value); + } + + /** + * Define where language settings are persisted for the provider. + * + * @param provider - provider to set the persistence mode. + * @param storeEntriesWithProject - {@code true} if with the project, + * {@code false} if in workspace area. + */ + public static void setStoringEntriesInProjectArea(LanguageSettingsSerializableProvider provider, boolean storeEntriesWithProject) { + provider.setProperty(ATTR_STORE_ENTRIES, storeEntriesWithProject ? VALUE_PROJECT : VALUE_WORKSPACE); + } + /** * Determine location of the project store of language settings providers in the plug-in state area. * @@ -309,7 +333,7 @@ public class LanguageSettingsProvidersSerializer { public static void setWorkspaceProviders(List providers) throws CoreException { setWorkspaceProvidersInternal(providers); serializeLanguageSettingsWorkspace(); - // generate preference change event + // generate preference change event for preference change listeners (value is not intended to be used) IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(CCorePlugin.PLUGIN_ID); prefs.putBoolean(PREFERENCE_WORSPACE_PROVIDERS_SET, ! prefs.getBoolean(PREFERENCE_WORSPACE_PROVIDERS_SET, false)); } @@ -437,7 +461,7 @@ public class LanguageSettingsProvidersSerializer { * @throws CoreException */ public static void serializeLanguageSettingsWorkspace() throws CoreException { - // AG FIXME - temporary log to remove before CDT 9.0 release + // AG FIXME - temporary log to remove before CDT Juno release LanguageSettingsLogger.logWarning("LanguageSettingsProvidersSerializer.serializeLanguageSettingsWorkspace()"); URI uriStoreWsp = getStoreInWorkspaceArea(STORAGE_WORKSPACE_LANGUAGE_SETTINGS); @@ -540,8 +564,7 @@ public class LanguageSettingsProvidersSerializer { * @noreference This method is not intended to be referenced by clients. * It is public solely for benefit of JUnit testing. */ - public static void serializeLanguageSettingsInternal(Element projectElementPrjStore, Element projectElementWspStore, ICProjectDescription prjDescription) throws CoreException { - + public static void serializeLanguageSettingsInternal(Element projectElementPrjStore, Element projectElementWspStore, ICProjectDescription prjDescription) { ICConfigurationDescription[] cfgDescriptions = prjDescription.getConfigurations(); for (ICConfigurationDescription cfgDescription : cfgDescriptions) { if (!(cfgDescription instanceof ILanguageSettingsProvidersKeeper)) @@ -552,11 +575,13 @@ public class LanguageSettingsProvidersSerializer { ATTR_NAME, cfgDescription.getName(), }); Element elementConfigurationWsp = null; + List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); if (providers.size()>0) { Element elementExtension = XmlUtil.appendElement(elementConfiguration, ELEM_EXTENSION, new String[] { ATTR_EXTENSION_POINT, PROVIDER_EXTENSION_POINT_ID}); Element elementExtensionWsp = null; + for (ILanguageSettingsProvider provider : providers) { if (isWorkspaceProvider(provider)) { // Element elementProviderReference = @@ -565,28 +590,34 @@ public class LanguageSettingsProvidersSerializer { continue; } if (provider instanceof LanguageSettingsSerializableProvider) { - LanguageSettingsSerializableProvider lss = (LanguageSettingsSerializableProvider) provider; + try { + LanguageSettingsSerializableProvider lss = (LanguageSettingsSerializableProvider) provider; - boolean useWsp = projectElementWspStore!=null && projectElementPrjStore!=projectElementWspStore; - if (isStoringEntriesInProjectArea(lss) || !useWsp) { - lss.serialize(elementExtension); - } else { - lss.serializeAttributes(elementExtension); - - // lazy initialization of elements - to avoid serialization of no-data file - if (elementExtensionWsp==null) { - if (elementConfigurationWsp==null) { - elementConfigurationWsp = XmlUtil.appendElement(projectElementWspStore, ELEM_CONFIGURATION, new String[] { - ATTR_ID, cfgDescription.getId(), - ATTR_NAME, cfgDescription.getName(), - }); + boolean isWspStorageAvailable = (projectElementWspStore != null) && (projectElementPrjStore != projectElementWspStore); + if (isStoringEntriesInProjectArea(lss) || !isWspStorageAvailable) { + lss.serialize(elementExtension); + } else { + // lazy initialization of wsp storage elements - to avoid serialization of no-data file + if (elementExtensionWsp == null) { + if (elementConfigurationWsp == null) { + elementConfigurationWsp = XmlUtil.appendElement(projectElementWspStore, ELEM_CONFIGURATION, new String[] { + ATTR_ID, cfgDescription.getId(), + ATTR_NAME, cfgDescription.getName(), + }); + } + elementExtensionWsp = XmlUtil.appendElement(elementConfigurationWsp, ELEM_EXTENSION, new String[] { + ATTR_EXTENSION_POINT, PROVIDER_EXTENSION_POINT_ID}); } - elementExtensionWsp = XmlUtil.appendElement(elementConfigurationWsp, ELEM_EXTENSION, new String[] { - ATTR_EXTENSION_POINT, PROVIDER_EXTENSION_POINT_ID}); + Element elementProviderWsp = XmlUtil.appendElement(elementExtensionWsp, ELEM_PROVIDER, new String[] { + ATTR_ID, provider.getId()}); + + // split storage + lss.serializeAttributes(elementExtension); + lss.serializeEntries(elementProviderWsp); } - Element elementProviderWsp = XmlUtil.appendElement(elementExtensionWsp, ELEM_PROVIDER, new String[] { - ATTR_ID, provider.getId()}); - lss.serializeEntries(elementProviderWsp); + } catch (Throwable e) { + // protect from any exceptions from implementers + CCorePlugin.log("Exception trying serialize provider "+provider.getId(), e); //$NON-NLS-1$ } } else { // Element elementProvider = @@ -609,10 +640,13 @@ public class LanguageSettingsProvidersSerializer { */ public static void serializeLanguageSettings(ICProjectDescription prjDescription) throws CoreException { IProject project = prjDescription.getProject(); - // AG FIXME - temporary log to remove before CDT 9.0 release + // AG FIXME - temporary log to remove before CDT Juno release LanguageSettingsLogger.logWarning("LanguageSettingsProvidersSerializer.serializeLanguageSettings() for " + project); try { + // The storage could be split in two, one for provider properties, another one for entries, + // depending on provider flag + // Document to store in project area Document docStorePrj = XmlUtil.newDocument(); Element projectElementStorePrj = XmlUtil.appendElement(docStorePrj, ELEM_PROJECT); @@ -620,7 +654,7 @@ public class LanguageSettingsProvidersSerializer { Document docStoreWsp = XmlUtil.newDocument(); Element projectElementStoreWsp = XmlUtil.appendElement(docStoreWsp, ELEM_PROJECT); - // The project store should not be absent. Absent store means legacy project, not 0 providers. + // 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); @@ -629,17 +663,17 @@ public class LanguageSettingsProvidersSerializer { try { serializingLock.acquire(); - // Note that need for serialization may exist even if LSE event delta is empty, - // as number or properties of providers may differ + // Note that need for serialization may exist even if LS *entries* event delta is empty, + // as set of providers or their properties may differ serializeLanguageSettingsInternal(projectElementStorePrj, projectElementStoreWsp, prjDescription); XmlUtil.serializeXml(docStorePrj, fileStorePrj); // project-specific location in workspace area boolean isWorkspaceStoreEmpty = projectElementStoreWsp.getChildNodes().getLength() == 0; - if (!isWorkspaceStoreEmpty) { - XmlUtil.serializeXml(docStoreWsp, uriStoreWsp); - } else { + if (isWorkspaceStoreEmpty) { new java.io.File(uriStoreWsp).delete(); + } else { + XmlUtil.serializeXml(docStoreWsp, uriStoreWsp); } // manufacture the event only if serialization was successful @@ -677,45 +711,41 @@ public class LanguageSettingsProvidersSerializer { */ NodeList configurationNodes = projectElementPrj.getChildNodes(); - for (int ic=0;ic providers = new ArrayList(); String cfgId = XmlUtil.determineAttributeValue(cfgNode, ATTR_ID); - @SuppressWarnings("unused") - String cfgName = XmlUtil.determineAttributeValue(cfgNode, ATTR_NAME); - NodeList extensionAndReferenceNodes = cfgNode.getChildNodes(); - for (int ie=0;ie @@ -746,52 +786,51 @@ public class LanguageSettingsProvidersSerializer { */ - NodeList configurationNodes = projectElementWsp.getChildNodes(); - for (int ic=0;ic + doc = XmlUtil.loadXml(storeInPrjArea); + Element rootElementPrj = doc.getDocumentElement(); // URI uriStoreWsp = getStoreInWorkspaceArea(project.getName()+'.'+STORAGE_WORKSPACE_LANGUAGE_SETTINGS); Document docWsp = null; @@ -824,18 +864,14 @@ public class LanguageSettingsProvidersSerializer { serializingLock.release(); } - Element rootElementWsp = null; // - if (docWsp!=null) { + Element rootElementWsp = null; // + if (docWsp != null) { rootElementWsp = docWsp.getDocumentElement(); } - loadLanguageSettingsInternal(rootElementPrj, rootElementWsp, prjDescription); } catch (Exception e) { - CCorePlugin.log("Can't load preferences from file "+storePrj.getLocation(), e); //$NON-NLS-1$ - } - - if (doc!=null) { + CCorePlugin.log("Can't load preferences from file " + storeInPrjArea.getLocation(), e); //$NON-NLS-1$ } } else { @@ -854,11 +890,8 @@ public class LanguageSettingsProvidersSerializer { } /** - * FIXME Get Language Settings Provider defined in the workspace. That includes user-defined - * providers and after that providers defined as extensions via - * {@code org.eclipse.cdt.core.LanguageSettingsProvider} extension point. - * That returns actual object, any modifications will affect any configuration - * referring to the provider. + * Get Language Settings Provider from the list of workspace providers, + * see {@link #getWorkspaceProviders()}. * * @param id - ID of provider to find. * @return the provider or {@code null} if provider is not defined. @@ -873,9 +906,9 @@ public class LanguageSettingsProvidersSerializer { } /** - * Helper method to get to real underlying provider collecting entries as opposed to wrapper - * which is normally used for workspace provider. - * @see LanguageSettingsProvidersSerializer#isWorkspaceProvider(ILanguageSettingsProvider) + * Helper method to get to real underlying provider collecting entries as opposed + * to wrapper which is normally used for workspace provider. + * @see #isWorkspaceProvider(ILanguageSettingsProvider) * * @param id - ID of the provider. * @return raw underlying provider. @@ -885,9 +918,14 @@ public class LanguageSettingsProvidersSerializer { } /** - * TODO - * @return ordered set of providers defined in the workspace which include contributed through extension + user defined ones + * Get Language Settings Providers defined in the workspace. That includes + * user-defined providers and after that providers defined as extensions via + * {@code org.eclipse.cdt.core.LanguageSettingsProvider} extension point. + * Note that this returns wrappers around workspace provider so underlying + * provider could be replaced internally without need to change configuration. + * See also {@link #getRawWorkspaceProvider(String)}. * + * @return list of workspace providers. */ public static List getWorkspaceProviders() { ArrayList workspaceProviders = new ArrayList(); @@ -911,9 +949,10 @@ public class LanguageSettingsProvidersSerializer { } /** - * TODO - remove me - * Temporary method to report inconsistency in log. + * Reports inconsistency in log. + * AG FIXME - temporary method to remove before CDT Juno release */ + @SuppressWarnings("nls") @Deprecated public static void assertConsistency(ICProjectDescription prjDescription) { if (prjDescription != null) { @@ -1029,33 +1068,35 @@ public class LanguageSettingsProvidersSerializer { */ public static void reRegisterListeners(ICProjectDescription oldPrjDescription, ICProjectDescription newPrjDescription) { if (oldPrjDescription == newPrjDescription) { - assertConsistency(oldPrjDescription); // TODO - remove me + assertConsistency(oldPrjDescription); return; } - assertConsistency(oldPrjDescription); // TODO - remove me - assertConsistency(newPrjDescription); // TODO - remove me + assertConsistency(oldPrjDescription); + assertConsistency(newPrjDescription); List oldListeners = getListeners(oldPrjDescription); List newAssociations = getListenersAssociations(newPrjDescription); + // unregister old listeners for (ICListenerAgent oldListener : oldListeners) { if (!isListenerInTheListOfAssociations(newAssociations, oldListener)) { int count = 0; if (oldListener instanceof LanguageSettingsWorkspaceProvider) { count = ((LanguageSettingsWorkspaceProvider) oldListener).decrementProjectCount(); } - if (count == 0) { + if (count <= 0) { try { oldListener.unregisterListener(); } catch (Throwable e) { // protect from any exceptions from implementers - CCorePlugin.log(e); + CCorePlugin.log("Exception trying unregister listener "+((ILanguageSettingsProvider) oldListener).getId(), e); //$NON-NLS-1$ } } } } + // register new listeners for (ListenerAssociation newListenerAssociation : newAssociations) { ICListenerAgent newListener = newListenerAssociation.listener; if (!isInList(oldListeners, newListener)) { @@ -1068,7 +1109,7 @@ public class LanguageSettingsProvidersSerializer { newListener.registerListener(newListenerAssociation.cfgDescription); } catch (Throwable e) { // protect from any exceptions from implementers - CCorePlugin.log(e); + CCorePlugin.log("Exception trying register listener "+((ILanguageSettingsProvider) newListener).getId(), e); //$NON-NLS-1$ } } } @@ -1076,30 +1117,10 @@ public class LanguageSettingsProvidersSerializer { } - /** - * Deep clone of a list of language settings providers. - * - * @param baseProviders - list of providers to clone. - * @return newly cloned list. - */ - public static List cloneProviders(List baseProviders) { - List newProviders = new ArrayList(); - for (ILanguageSettingsProvider provider : baseProviders) { - if (provider instanceof ILanguageSettingsEditableProvider) { - ILanguageSettingsEditableProvider newProvider = LanguageSettingsManager.getProviderCopy((ILanguageSettingsEditableProvider) provider, true); - if (newProvider != null) { - provider = newProvider; - } - } - newProviders.add(provider); - } - return new ArrayList(newProviders); - } - /** * Adds a listener that will be notified of changes in language settings. * - * @param listener the listener to add + * @param listener - the listener to add */ public static void registerLanguageSettingsChangeListener(ILanguageSettingsChangeListener listener) { fLanguageSettingsChangeListeners.add(listener); @@ -1108,30 +1129,31 @@ public class LanguageSettingsProvidersSerializer { /** * Removes a language settings change listener. * - * @param listener the listener to remove. + * @param listener - the listener to remove. */ public static void unregisterLanguageSettingsChangeListener(ILanguageSettingsChangeListener listener) { fLanguageSettingsChangeListeners.remove(listener); } /** - * Notifies all language settings change listeners of a change. + * Notifies all language settings change listeners of a change in language settings entries. * - * @param event the ILanguageSettingsChangeEvent event to be broadcast. + * @param event - the {@link ILanguageSettingsChangeEvent} event to be broadcast. */ - public static void notifyLanguageSettingsChangeListeners(ILanguageSettingsChangeEvent event) { - // AG FIXME - temporary log to remove before CDT 9.0 release + private static void notifyLanguageSettingsChangeListeners(ILanguageSettingsChangeEvent event) { + // AG FIXME - temporary log to remove before CDT Juno release LanguageSettingsLogger.logWarning("Firing " + event); - Object[] listeners = fLanguageSettingsChangeListeners.getListeners(); - for (Object listener : listeners) { + for (Object listener : fLanguageSettingsChangeListeners.getListeners()) { ((ILanguageSettingsChangeListener) listener).handleEvent(event); } } + /** + * Get list of setting entries from the pool in {@link LanguageSettingsStorage}. + */ private static List getSettingEntriesPooled(ILanguageSettingsProvider provider, ICConfigurationDescription cfgDescription, IResource rc, String languageId) { - try { return LanguageSettingsStorage.getPooledList(provider.getSettingEntries(cfgDescription, rc, languageId)); } catch (Throwable e) { @@ -1148,7 +1170,7 @@ public class LanguageSettingsProvidersSerializer { * Returns the list of setting entries of the given provider * for the given configuration description, resource and language. * This method reaches to the parent folder of the resource recursively - * in case the resource does not define the entries for the given provider. + * if the resource does not define the entries for the given provider. * * @param provider - language settings provider. * @param cfgDescription - configuration description. @@ -1160,19 +1182,19 @@ public class LanguageSettingsProvidersSerializer { */ public static List getSettingEntriesUpResourceTree(ILanguageSettingsProvider provider, ICConfigurationDescription cfgDescription, IResource rc, String languageId) { Assert.isTrue( !(rc instanceof IWorkspaceRoot) ); - if (provider!=null) { + if (provider != null) { List entries = getSettingEntriesPooled(provider, cfgDescription, rc, languageId); - if (entries!=null) { + if (entries != null) { return entries; } - if (rc!=null) { + if (rc != null) { IResource parentFolder = (rc instanceof IProject) ? null : rc.getParent(); - if (parentFolder!=null) { + if (parentFolder != null) { return getSettingEntriesUpResourceTree(provider, cfgDescription, parentFolder, languageId); } - // if out of parent resources - get default entries for the applicable language scope + // if out of parent resources - get default entries entries = getSettingEntriesPooled(provider, null, null, languageId); - if (entries!=null) { + if (entries != null) { return entries; } } @@ -1182,99 +1204,8 @@ public class LanguageSettingsProvidersSerializer { } /** - * Builds for the provider a nice looking resource tree to present hierarchical view to the user. - * Note that it is not advisable to "compact" the tree because of potential loss of information - * which is especially important during partial or incremental builds. - * - * @param provider - language settings provider to build the tree for. - * @param cfgDescription - configuration description. - * @param languageId - language ID. - * @param folder - container where the tree roots. + * Test if the binary flag contains a particular bit. */ - public static void buildResourceTree(LanguageSettingsSerializableProvider provider, - ICConfigurationDescription cfgDescription, String languageId, IContainer folder) { - IResource[] members = null; - try { - members = folder.members(); - } catch (Exception e) { - CCorePlugin.log(e); - } - if (members==null) - return; - - for (IResource rc : members) { - if (rc instanceof IContainer) { - buildResourceTree(provider, cfgDescription, languageId, (IContainer) rc); - } - } - - int rcNumber = members.length; - - Map, Integer> listMap = new HashMap, Integer>(); - - // on the first pass find majority entries - List majorityEntries = null; - List candidate = null; - int candidateCount = 0; - for (IResource rc : members) { - if (!isLanguageInScope(rc, cfgDescription, languageId)) { - rcNumber--; - } else { - List entries = provider.getSettingEntries(null, rc, languageId); - if (entries==null && rc instanceof IContainer) { - rcNumber--; - } else { - Integer count = listMap.get(entries); - if (count==null) { - count = 0; - } - count++; - - if (count>candidateCount) { - candidateCount = count; - candidate = entries; - } - - listMap.put(entries, count); - } - } - - if (candidateCount > rcNumber/2) { - majorityEntries = candidate; - break; - } - } - - if (majorityEntries!=null) { - provider.setSettingEntries(cfgDescription, folder, languageId, majorityEntries); - } - - // second pass - assign the entries to the folders - for (IResource rc : members) { - List entries = provider.getSettingEntries(null, rc, languageId); - if (entries!=null && entries==majorityEntries) { - if (!(rc instanceof IFile)) { // preserve information which files were collected - provider.setSettingEntries(cfgDescription, rc, languageId, null); - } - } - } - } - - private static boolean isLanguageInScope(IResource rc, ICConfigurationDescription cfgDescription, String languageId) { - if (rc instanceof IFile) { - ILanguage lang = null; - try { - lang = LanguageManager.getInstance().getLanguageForFile((IFile) rc, cfgDescription); - } catch (CoreException e) { - CCorePlugin.log("Error loading language settings providers extensions", e); //$NON-NLS-1$ - } - if (lang==null || (languageId!=null && !languageId.equals(lang.getId()))) { - return false; - } - } - return true; - } - private static boolean checkBit(int flags, int bit) { return (flags & bit) == bit; } @@ -1313,9 +1244,9 @@ public class LanguageSettingsProvidersSerializer { for (ILanguageSettingsProvider provider: providers) { List providerEntries = getSettingEntriesUpResourceTree(provider, cfgDescription, rc, languageId); for (ICLanguageSettingEntry entry : providerEntries) { - if (entry!=null) { + if (entry != null) { String entryName = entry.getName(); - boolean isRightKind = (entry.getKind() & kind) != 0; + boolean isRightKind = checkBit(entry.getKind(), kind); // Only first entry is considered // Entry flagged as "UNDEFINED" prevents adding entry with the same name down the line if (isRightKind && !alreadyAdded.contains(entryName)) { @@ -1397,28 +1328,128 @@ public class LanguageSettingsProvidersSerializer { } /** - * 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 - * the entries migrate with the project. + * Deep clone of a list of language settings providers. * - * @param provider - provider to check the persistence mode. - * @return {@code true} if LSE persisted with the project or {@code false} if in the workspace. + * @param baseProviders - list of providers to clone. + * @return newly cloned list. */ - public static boolean isStoringEntriesInProjectArea(LanguageSettingsSerializableProvider provider) { - String value = provider.getProperty(ATTR_STORE_ENTRIES); - return VALUE_PROJECT.equals(value); + public static List cloneProviders(List baseProviders) { + List newProviders = new ArrayList(); + for (ILanguageSettingsProvider provider : baseProviders) { + if (provider instanceof ILanguageSettingsEditableProvider) { + ILanguageSettingsEditableProvider newProvider = LanguageSettingsManager.getProviderCopy((ILanguageSettingsEditableProvider) provider, true); + if (newProvider != null) { + provider = newProvider; + } + } + newProviders.add(provider); + } + return new ArrayList(newProviders); } /** - * Define where language settings are persisted for the provider. - * - * @param provider - provider to set the persistence mode. - * @param storeEntriesWithProject - {@code true} if with the project, - * {@code false} if in workspace area. + * Check if the language is applicable for the file. */ - public static void setStoringEntriesInProjectArea(LanguageSettingsSerializableProvider provider, boolean storeEntriesWithProject) { - provider.setProperty(ATTR_STORE_ENTRIES, storeEntriesWithProject ? VALUE_PROJECT : VALUE_WORKSPACE); + private static boolean isLanguageInScope(IResource rc, ICConfigurationDescription cfgDescription, String languageId) { + if (rc instanceof IFile) { + ILanguage lang = null; + try { + lang = LanguageManager.getInstance().getLanguageForFile((IFile) rc, cfgDescription); + } catch (CoreException e) { + CCorePlugin.log("Error while determining language for a file", e); //$NON-NLS-1$ + } + if (lang == null || (languageId != null && !languageId.equals(lang.getId()))) { + return false; + } + } + return true; } + /** + * Builds for the provider a nicer-looking resource tree to present hierarchical view to the user. + * + * Note that it is not advisable to "compact" the tree because of potential loss of information + * which is especially important during partial or incremental builds. + * + * Note also that after using this method for a while for BOP parsers it appears that disadvantages + * outweigh benefits. In particular, it doesn't result in saving memory as the language settings + * (and the lists itself) are not duplicated in memory anyway but optimized with using WeakHashSet + * and SafeStringInterner. + * + * This method is a candidate for removal. + * + * @param provider - language settings provider to build the tree for. + * @param cfgDescription - configuration description. + * @param languageId - language ID. + * @param folder - container where the tree roots. + */ + public static void buildResourceTree(LanguageSettingsSerializableProvider provider, + ICConfigurationDescription cfgDescription, String languageId, IContainer folder) { + IResource[] members = null; + try { + members = folder.members(); + } catch (Exception e) { + CCorePlugin.log(e); + } + if (members==null) + return; + + for (IResource rc : members) { + if (rc instanceof IContainer) { + buildResourceTree(provider, cfgDescription, languageId, (IContainer) rc); + } + } + + int rcNumber = members.length; + + Map, Integer> listMap = new HashMap, Integer>(); + + // on the first pass find majority entry list, i.e. list present most often + List majorityEntries = null; + List candidate = null; + int candidateCount = 0; + for (IResource rc : members) { + if (!isLanguageInScope(rc, cfgDescription, languageId)) { + rcNumber--; + } else { + List entries = provider.getSettingEntries(null, rc, languageId); + if (entries==null && rc instanceof IContainer) { + rcNumber--; + } else { + Integer count = listMap.get(entries); + if (count==null) { + count = 0; + } + count++; + + if (count>candidateCount) { + candidateCount = count; + candidate = entries; + } + + listMap.put(entries, count); + } + } + + if (candidateCount > rcNumber/2) { + majorityEntries = candidate; + break; + } + } + + if (majorityEntries!=null) { + provider.setSettingEntries(cfgDescription, folder, languageId, majorityEntries); + } + + // second pass - assign the entries to the folders + for (IResource rc : members) { + List entries = provider.getSettingEntries(null, rc, languageId); + if (entries!=null && entries==majorityEntries) { + if (!(rc instanceof IFile)) { // preserve information which files were collected + provider.setSettingEntries(cfgDescription, rc, languageId, null); + } + } + } + } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsScannerInfoProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsScannerInfoProvider.java index ece845d9b5e..56016322ae1 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsScannerInfoProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsScannerInfoProvider.java @@ -52,7 +52,7 @@ public class LanguageSettingsScannerInfoProvider implements IScannerInfoProvider @Override public ExtendedScannerInfo getScannerInformation(IResource rc) { - // AG FIXME - temporary log to remove before CDT 9.0 release + // AG FIXME - temporary log to remove before CDT Juno release LanguageSettingsLogger.logScannerInfoProvider(rc, this); IProject project = rc.getProject(); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/DescriptionScannerInfoProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/DescriptionScannerInfoProvider.java index 087656f76c6..b662f38c14e 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/DescriptionScannerInfoProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/DescriptionScannerInfoProvider.java @@ -78,7 +78,7 @@ public class DescriptionScannerInfoProvider implements IScannerInfoProvider, ICP @Override public IScannerInfo getScannerInformation(IResource resource) { - // AG FIXME - temporary log to remove before CDT 9.0 release + // AG FIXME - temporary log to remove before CDT Juno release LanguageSettingsLogger.logScannerInfoProvider(resource, this); if(!fInited) diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/ScannerProvider.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/ScannerProvider.java index 7a87ec34f65..3ab88b851cc 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/ScannerProvider.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/ScannerProvider.java @@ -98,7 +98,7 @@ public class ScannerProvider extends AbstractCExtension implements IScannerInfoP */ @Override public IScannerInfo getScannerInformation(IResource resource) { - // AG FIXME - temporary log to remove before CDT 9.0 release + // AG FIXME - temporary log to remove before CDT Juno release if (resource instanceof IFile) { LanguageSettingsLogger.logInfo("rc="+resource+" (ScannerProvider.getScannerInformation())"); } else { From 115f78f7aa1f306a48d40df9150c3cf57917ca9d Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Fri, 16 Dec 2011 12:48:53 -0500 Subject: [PATCH 094/120] LanguageSettingsSerializableProvider.serializeLanguageSettings(ICConfigurationDescription) --- .../AbstractBuildCommandParser.java | 15 +------- .../AbstractBuiltinSpecsDetector.java | 20 +++------- .../LanguageSettingsSerializableProvider.java | 38 ++++++++++++++++--- 3 files changed, 39 insertions(+), 34 deletions(-) diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java index 3243fe2c1c3..e9bf2571aef 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java @@ -27,13 +27,11 @@ import org.eclipse.cdt.core.errorparsers.RegexErrorPattern; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.internal.core.ConsoleOutputSniffer; -import org.eclipse.cdt.make.core.MakeCorePlugin; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.ISchedulingRule; import org.eclipse.core.runtime.jobs.Job; @@ -160,18 +158,7 @@ public abstract class AbstractBuildCommandParser extends AbstractLanguageSetting Job job = new Job("Serialize CDT language settings entries") { @Override protected IStatus run(IProgressMonitor monitor) { - IStatus status = Status.OK_STATUS; - try { - if (cfgDescription != null) { - LanguageSettingsManager.serializeLanguageSettings(cfgDescription.getProjectDescription()); - } else { - LanguageSettingsManager.serializeLanguageSettingsWorkspace(); - } - } catch (CoreException e) { - status = new Status(IStatus.ERROR, MakeCorePlugin.PLUGIN_ID, IStatus.ERROR, "Error serializing language settings", e); - MakeCorePlugin.log(status); - } - return status; + return serializeLanguageSettings(cfgDescription); } @Override public boolean belongsTo(Object family) { diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java index d5106cfabdf..9230eff9c4b 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java @@ -28,7 +28,6 @@ import org.eclipse.cdt.core.IMarkerGenerator; import org.eclipse.cdt.core.ProblemMarkerInfo; import org.eclipse.cdt.core.index.IIndexManager; import org.eclipse.cdt.core.language.settings.providers.ICListenerAgent; -import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICProject; @@ -400,17 +399,8 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti monitor.subTask("Serializing results"); if (isChanged) { // avoids resource and settings change notifications - try { - if (currentCfgDescription != null) { - LanguageSettingsManager.serializeLanguageSettings(currentCfgDescription.getProjectDescription()); - } else { - LanguageSettingsManager.serializeLanguageSettingsWorkspace(); - } - } catch (CoreException e) { - IStatus s = new Status(IStatus.ERROR, MakeCorePlugin.PLUGIN_ID, IStatus.ERROR, "Error serializing language settings", e); - MakeCorePlugin.log(s); - status.merge(s); - } + IStatus s = serializeLanguageSettings(currentCfgDescription); + status.merge(s); // AG: FIXME - rather send event that ls settings changed if (currentCfgDescription != null) { @@ -419,9 +409,9 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti try { CCorePlugin.getIndexManager().update(tuSelection, IIndexManager.UPDATE_ALL | IIndexManager.UPDATE_EXTERNAL_FILES_FOR_PROJECT); } catch (CoreException e) { - IStatus s = new Status(IStatus.ERROR, MakeCorePlugin.PLUGIN_ID, IStatus.ERROR, "Error updating CDT index", e); - MakeCorePlugin.log(s); - status.merge(s); + IStatus s2 = new Status(IStatus.ERROR, MakeCorePlugin.PLUGIN_ID, IStatus.ERROR, "Error updating CDT index", e); + MakeCorePlugin.log(s2); + status.merge(s2); } } else { // TODO diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableProvider.java index 1924c37e144..936429c73e1 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableProvider.java @@ -19,11 +19,13 @@ import java.util.Map.Entry; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; -import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.internal.core.XmlUtil; import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer; import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsSerializableStorage; import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; @@ -119,10 +121,9 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr /** * Sets language settings entries for the provider. - * Note that the entries are not persisted at that point. Use this method to - * set the entries for all resources and then to persist use - * {@link LanguageSettingsManager#serializeLanguageSettings(ICProjectDescription)} or - * {@link LanguageSettingsManager#serializeLanguageSettingsWorkspace()}. + * Note that the entries are not persisted at that point. Use this method to set + * the entries for all resources one by one and after all done persist in one shot + * using {@link #serializeLanguageSettings(ICConfigurationDescription)}. * See for example {@code AbstractBuildCommandParser} and {@code AbstractBuiltinSpecsDetector} * in build plugins. * @@ -228,6 +229,33 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr fStorage.serializeEntries(elementProvider); } + /** + * Convenience method to persist language settings entries for the project or + * workspace as often-used operation. + * Note that configuration description is passed as an argument but the + * current implementation saves all configurations. + * + * @param cfgDescription - configuration description. + * If not {@code null}, all providers of the project are serialized. + * If {@code null}, global workspace providers are serialized. + * + * @return - status of operation. + */ + public IStatus serializeLanguageSettings(ICConfigurationDescription cfgDescription) { + IStatus status = Status.OK_STATUS; + try { + if (cfgDescription != null) { + LanguageSettingsManager.serializeLanguageSettings(cfgDescription.getProjectDescription()); + } else { + LanguageSettingsManager.serializeLanguageSettingsWorkspace(); + } + } catch (CoreException e) { + status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, IStatus.ERROR, "Error serializing language settings", e); //$NON-NLS-1$ + CCorePlugin.log(status); + } + return status; + } + /** * Load provider from XML provider element. * This is convenience method not intended to be overridden on purpose. From 090af63d32dee610cbe77e8271621fdc553ecf73 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Fri, 16 Dec 2011 14:21:20 -0500 Subject: [PATCH 095/120] Fixed outer scope rule bug --- .../LanguageSettingsProvidersSerializer.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java index 3dcbf5713fc..2d372443911 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java @@ -52,6 +52,7 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.ListenerList; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.ILock; +import org.eclipse.core.runtime.jobs.ISchedulingRule; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.core.runtime.preferences.InstanceScope; @@ -841,13 +842,15 @@ public class LanguageSettingsProvidersSerializer { public static void loadLanguageSettings(ICProjectDescription prjDescription) { IProject project = prjDescription.getProject(); IFile storeInPrjArea = project.getFile(SETTINGS_FOLDER_NAME + STORAGE_PROJECT_LANGUAGE_SETTINGS); - // AG: FIXME investigate this one - // Causes java.lang.IllegalArgumentException: Attempted to beginRule: P/cdt312, does not match outer scope rule: org.eclipse.cdt.internal.ui.text.c.hover.CSourceHover$SingletonRule@6f34fb try { - storeInPrjArea.refreshLocal(IResource.DEPTH_ZERO, null); - } catch (CoreException e) { + Job currentJob = Job.getJobManager().currentJob(); + ISchedulingRule currentRule = (currentJob != null) ? currentJob.getRule() : null; + if (currentRule == null || currentRule.contains(storeInPrjArea)) { + storeInPrjArea.refreshLocal(IResource.DEPTH_ZERO, null); + } + } catch (Throwable e) { // ignore failure - CCorePlugin.log(e); + CCorePlugin.log("Internal Error trying to call IResourse.refreshLocal()", e); //$NON-NLS-1$ } if (storeInPrjArea.exists()) { Document doc = null; From 7aacae478080bca996656224190929085eda0e48 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Fri, 16 Dec 2011 18:31:53 -0500 Subject: [PATCH 096/120] Nicer error log --- .../providers/LanguageSettingsExtensionManager.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java index e6339342f14..630c821cbeb 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsExtensionManager.java @@ -270,8 +270,8 @@ public class LanguageSettingsExtensionManager { // Create it as executable extension from the extension registry. ILanguageSettingsProvider provider = loadProviderFromRegistry(ATTR_CLASS, className, Platform.getExtensionRegistry(), false); if (provider == null) { - IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "Not able to load provider class=" + className); //$NON-NLS-1$ - CCorePlugin.log(new CoreException(status)); + String msg = "Not able to load provider class=" + className; //$NON-NLS-1$ + CCorePlugin.log(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, msg, new Exception(msg))); } return provider; } @@ -291,8 +291,8 @@ public class LanguageSettingsExtensionManager { // Create it as executable extension from the extension registry. ILanguageSettingsProvider provider = loadProviderFromRegistry(ATTR_ID, id, Platform.getExtensionRegistry(), true); if (provider == null) { - IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "Not able to load provider id=" + id); //$NON-NLS-1$ - CCorePlugin.log(new CoreException(status)); + String msg = "Not able to load provider id=" + id; //$NON-NLS-1$ + CCorePlugin.log(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, msg, new Exception(msg))); } return provider; } From 2559c118ec3e991cc635188f28b9d03cee5b968b Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Sat, 17 Dec 2011 07:03:20 -0500 Subject: [PATCH 097/120] Removed unnecessary changes against master --- .../index/tests/IndexProviderManagerTest.java | 153 +++++---------- .../cdt/internal/core/pdom/PDOMManager.java | 174 +++++++++--------- core/org.eclipse.cdt.core/plugin.xml | 4 +- .../eclipse/cdt/core/ErrorParserManager.java | 2 +- 4 files changed, 134 insertions(+), 199 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexProviderManagerTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexProviderManagerTest.java index 4918c6d1873..34a600877e2 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexProviderManagerTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexProviderManagerTest.java @@ -75,7 +75,7 @@ public class IndexProviderManagerTest extends IndexTestBase { final static Class DP4= Providers.Dummy4.class; final static Class DP5= Providers.Dummy5.class; final static Class[] DPS= new Class[] {DP4, DP2, DP1, DP3, DP5}; - + /* * Fictional compatibility ranges for testing */ @@ -83,9 +83,9 @@ public class IndexProviderManagerTest extends IndexTestBase { final static VersionRange VERSION_401= new VersionRange("[36,37]"); final static VersionRange VERSION_405= new VersionRange("[37,39]"); final static VersionRange VERSION_502= new VersionRange("[89,91]"); - + final CCorePlugin core= CCorePlugin.getDefault(); - + public IndexProviderManagerTest() { super("IndexProviderManagerTest"); } @@ -106,11 +106,11 @@ public class IndexProviderManagerTest extends IndexTestBase { IndexProviderManager ipm= ((PDOMManager)CCorePlugin.getIndexManager()).getIndexProviderManager(); ipm.reset(); ipm.startup(); } - + public void testProvider_SimpleLifeCycle_200958() throws Exception { for (Class element : DPS) DPT.reset(element); - + List cprojects = new ArrayList(), expectedTrace = new ArrayList(); try { for(int i=0; i<3; i++) { @@ -137,7 +137,7 @@ public class IndexProviderManagerTest extends IndexTestBase { public void testProvider_OverDeleteAndAdd() throws Exception { DPT.reset(DP1); - + List expectedTrace = new ArrayList(); ICProject cproject = null; try { @@ -180,7 +180,7 @@ public class IndexProviderManagerTest extends IndexTestBase { File newLocation = CProjectHelper.freshDir(); IProjectDescription description = cproject.getProject().getDescription(); description.setLocationURI(newLocation.toURI()); - cproject.getProject().move(description, IResource.FORCE | IResource.SHALLOW, new NullProgressMonitor()); + cproject.getProject().move(description, IResource.FORCE | IResource.SHALLOW, new NullProgressMonitor()); index = CCorePlugin.getIndexManager().getIndex(cproject); assertEquals(expectedTrace, DPT.getProjectsTrace(DP1)); @@ -190,19 +190,19 @@ public class IndexProviderManagerTest extends IndexTestBase { } } } - + public void testVersioning_IncompatibleIgnored() throws Exception { IndexProviderManager ipm= ((PDOMManager)CCorePlugin.getIndexManager()).getIndexProviderManager(); - + ICProject cproject = null; try { cproject= CProjectHelper.createCCProject("IndexFactoryConfigurationUsageTest", IPDOMManager.ID_NO_INDEXER); IProject project= cproject.getProject(); - - + + MockState mockState = new MockState(cproject); mockState.setConfig(MockState.REL_V1_ID); - + IIndexProvider provider1= new IIndexFragmentProvider() { IIndexFragment[] fragments= new IIndexFragment[] { new MockPDOM("contentID.contentA", "36"), @@ -211,11 +211,9 @@ public class IndexProviderManagerTest extends IndexTestBase { new MockPDOM("contentID.bar", "91"), new MockPDOM("contentID.baz", "89") }; - @Override public IIndexFragment[] getIndexFragments(ICConfigurationDescription config) { return fragments; } - @Override public boolean providesFor(ICProject project) throws CoreException { return true; } @@ -225,22 +223,20 @@ public class IndexProviderManagerTest extends IndexTestBase { new MockPDOM("contentID.baz", "90"), new MockPDOM("contentID.contentA", "38"), }; - @Override public IIndexFragment[] getIndexFragments(ICConfigurationDescription config) { return fragments; } - @Override public boolean providesFor(ICProject project) throws CoreException { return true; } }; - + CCorePlugin.getIndexManager().joinIndexer(8000, npm()); // ensure IPM is called only once under test conditions setExpectedNumberOfLoggedNonOKStatusObjects(3); // foo, bar and baz have no compatible fragments available - + ipm.reset(VERSION_405); ipm.startup(); ipm.addIndexProvider(provider1); ipm.addIndexProvider(provider2); - + IIndexFragment[] actual = ipm.getProvidedIndexFragments(mockState.getCurrentConfig(), true); assertEquals(1, actual.length); assertFragmentPresent("contentID.contentA", "38", actual); @@ -250,19 +246,19 @@ public class IndexProviderManagerTest extends IndexTestBase { } } } - + public void testVersioning_NoCompatibleVersionsFound() throws Exception { IndexProviderManager ipm= ((PDOMManager)CCorePlugin.getIndexManager()).getIndexProviderManager(); - + ICProject cproject = null; try { cproject= CProjectHelper.createCCProject("IndexFactoryConfigurationUsageTest", IPDOMManager.ID_NO_INDEXER); IProject project= cproject.getProject(); - - + + MockState mockState = new MockState(cproject); mockState.setConfig(MockState.REL_V1_ID); - + IIndexProvider provider1= new IIndexFragmentProvider() { IIndexFragment[] fragments= new IIndexFragment[] { new MockPDOM("contentID.contentA", "36"), @@ -271,11 +267,9 @@ public class IndexProviderManagerTest extends IndexTestBase { new MockPDOM("contentID.bar", "91"), new MockPDOM("contentID.baz", "89") }; - @Override public IIndexFragment[] getIndexFragments(ICConfigurationDescription config) { return fragments; } - @Override public boolean providesFor(ICProject project) throws CoreException { return true; } @@ -284,22 +278,20 @@ public class IndexProviderManagerTest extends IndexTestBase { IIndexFragment[] fragments= new IIndexFragment[] { new MockPDOM("contentID.contentA", "41"), }; - @Override public IIndexFragment[] getIndexFragments(ICConfigurationDescription config) { return fragments; } - @Override public boolean providesFor(ICProject project) throws CoreException { return true; } }; - + CCorePlugin.getIndexManager().joinIndexer(8000, npm()); // ensure IPM is called only once under test conditions setExpectedNumberOfLoggedNonOKStatusObjects(1); // contentA has no compatible fragments available - + ipm.reset(VERSION_502); ipm.startup(); ipm.addIndexProvider(provider1); ipm.addIndexProvider(provider2); - + IIndexFragment[] actual = ipm.getProvidedIndexFragments(mockState.getCurrentConfig(), true); assertEquals(3, actual.length); assertFragmentPresent("contentID.foo", "90", actual); @@ -311,7 +303,7 @@ public class IndexProviderManagerTest extends IndexTestBase { } } } - + private void assertFragmentPresent(String id, String version, IIndexFragment[] fragments) throws Exception { for (IIndexFragment candidate : fragments) { String cid= null, csver= null; @@ -327,49 +319,49 @@ public class IndexProviderManagerTest extends IndexTestBase { } fail("Fragment matching (id="+id+",version="+version+") was not present"); } - + public void testIndexFactoryConfigurationUsage() throws Exception { IIndex index; - + ICProject cproject = null; // Modifying the .project file triggers an indexer job, suppress that: DeltaAnalyzer.sSuppressPotentialTUs= true; try { cproject = CProjectHelper.createCCProject("IndexFactoryConfigurationUsageTest", IPDOMManager.ID_NO_INDEXER); IProject project= cproject.getProject(); - + ICProjectDescription pd= core.getProjectDescription(project); ICConfigurationDescription cfg1= newCfg(pd, "project", "config1"); ICConfigurationDescription cfg2= newCfg(pd, "project", "config2"); core.setProjectDescription(project, pd); - + index= CCorePlugin.getIndexManager().getIndex(cproject); CCorePlugin.getIndexManager().joinIndexer(8000, npm()); - + DPT.reset(DP1); changeConfigRelations(project, ICProjectDescriptionPreferences.CONFIGS_LINK_SETTINGS_AND_ACTIVE); assertEquals(0, DPT.getProjectsTrace(DP1).size()); assertEquals(0, DPT.getCfgsTrace(DP1).size()); - + changeActiveConfiguration(project, cfg1); DPT.reset(DP1); index= CCorePlugin.getIndexManager().getIndex(cproject); assertEquals(0, DPT.getProjectsTrace(DP1).size()); assertEquals(1, DPT.getCfgsTrace(DP1).size()); assertEquals("project.config1", ((ICConfigurationDescription)DPT.getCfgsTrace(DP1).get(0)).getId()); - + changeActiveConfiguration(project, cfg2); DPT.reset(DP1); index= CCorePlugin.getIndexManager().getIndex(cproject); assertEquals(0, DPT.getProjectsTrace(DP1).size()); assertEquals(1, DPT.getCfgsTrace(DP1).size()); assertEquals("project.config2", ((ICConfigurationDescription)DPT.getCfgsTrace(DP1).get(0)).getId()); - + DPT.reset(DP1); changeConfigRelations(project, ICProjectDescriptionPreferences.CONFIGS_INDEPENDENT); assertEquals(0, DPT.getProjectsTrace(DP1).size()); assertEquals(0, DPT.getCfgsTrace(DP1).size()); - + changeActiveConfiguration(project, cfg1); DPT.reset(DP1); index= CCorePlugin.getIndexManager().getIndex(cproject); @@ -377,7 +369,7 @@ public class IndexProviderManagerTest extends IndexTestBase { assertEquals(1, DPT.getCfgsTrace(DP1).size()); // should still be config2, as the change in active configuration does not matter assertEquals("project.config2", ((ICConfigurationDescription)DPT.getCfgsTrace(DP1).get(0)).getId()); - + changeActiveConfiguration(project, cfg2); DPT.reset(DP1); index= CCorePlugin.getIndexManager().getIndex(cproject); @@ -392,7 +384,7 @@ public class IndexProviderManagerTest extends IndexTestBase { } } } - + public void testGetProvidedFragments() throws Exception { ICProject cproject= CProjectHelper.createCProject("IndexProviderManagerTest", "bin", IPDOMManager.ID_NO_INDEXER); @@ -499,20 +491,20 @@ public class IndexProviderManagerTest extends IndexTestBase { } } } - + private ICConfigurationDescription newCfg(ICProjectDescription des, String project, String config) throws CoreException { CDefaultConfigurationData data= new CDefaultConfigurationData(project+"."+config, project+" "+config+" name", null); data.initEmptyData(); - return des.createConfiguration(CCorePlugin.DEFAULT_PROVIDER_ID, data); + return des.createConfiguration(CCorePlugin.DEFAULT_PROVIDER_ID, data); } - + private void changeActiveConfiguration(IProject project, ICConfigurationDescription cfg) throws CoreException { ICProjectDescription pd= core.getProjectDescription(project); pd.setActiveConfiguration(pd.getConfigurationById(cfg.getId())); core.setProjectDescription(project, pd); CCorePlugin.getIndexManager().joinIndexer(8000, npm()); } - + private void changeConfigRelations(IProject project, int option) throws CoreException { ICProjectDescription pd= core.getProjectDescription(project); pd.setConfigurationRelations(option); @@ -528,7 +520,6 @@ class MockStateIndexProvider implements IIndexProvider { this.targetProject = cproject; } - @Override public boolean providesFor(ICProject cproject) throws CoreException { return this.targetProject.equals(cproject); } @@ -537,7 +528,7 @@ class MockStateIndexProvider implements IIndexProvider { class MockStateIndexFragmentProvider extends MockStateIndexProvider implements IIndexFragmentProvider { private boolean invert; final IIndexFragment[] fragments; - + public void invert() { invert = !invert; } @@ -551,7 +542,6 @@ class MockStateIndexFragmentProvider extends MockStateIndexProvider implements I } } - @Override public IIndexFragment[] getIndexFragments(ICConfigurationDescription config) throws CoreException { int index = MockState.states.indexOf(config.getId()); index = invert ? (fragments.length-1)-index : index; @@ -574,201 +564,146 @@ class MockConfig implements ICConfigurationDescription { this.project= project; } - @Override public String getId() { return id; } - @Override public ICConfigExtensionReference create(String extensionPoint, String extension) throws CoreException { return null; } - @Override public ICExternalSetting createExternalSetting(String[] languageIDs, String[] contentTypeIds, String[] extensions, ICSettingEntry[] entries) throws WriteAccessException { return null; } - @Override public ICFileDescription createFileDescription(IPath path, ICResourceDescription base) throws CoreException, WriteAccessException { return null; } - @Override public ICFolderDescription createFolderDescription(IPath path, ICFolderDescription base) throws CoreException, WriteAccessException { return null; } - @Override public ICConfigExtensionReference[] get(String extensionPointID) { return null; } - @Override public ICBuildSetting getBuildSetting() { return null; } - @Override public String getBuildSystemId() { return null; } - @Override public ICdtVariablesContributor getBuildVariablesContributor() { return null; } - @Override public CConfigurationData getConfigurationData() { return null; } - @Override public String getDescription() { return null; } - @Override public ICExternalSetting[] getExternalSettings() { return null; } - @Override public ICFileDescription[] getFileDescriptions() { return null; } - @Override public ICFolderDescription[] getFolderDescriptions() { return null; } - @Override public ICProjectDescription getProjectDescription() { return CoreModel.getDefault().getProjectDescription(project); } - @Override public Map getReferenceInfo() { return null; } - @Override public ICResourceDescription getResourceDescription(IPath path, boolean exactPath) { return null; } - @Override public ICResourceDescription[] getResourceDescriptions() { return null; } - @Override public ICFolderDescription getRootFolderDescription() {return null;} - @Override public Object getSessionProperty(QualifiedName name) {return null;} - @Override public ICSourceEntry[] getSourceEntries() {return null;} - @Override public ICTargetPlatformSetting getTargetPlatformSetting() {return null;} - @Override public boolean isActive() {return false;} - @Override public boolean isModified() {return false;} - @Override public boolean isPreferenceConfiguration() {return false;} - @Override public void remove(ICConfigExtensionReference ext) throws CoreException {} - @Override public void remove(String extensionPoint) throws CoreException {} - @Override public void removeExternalSetting(ICExternalSetting setting) throws WriteAccessException {} - @Override public void removeExternalSettings() throws WriteAccessException {} - @Override public void removeResourceDescription(ICResourceDescription des) throws CoreException, WriteAccessException {} - @Override public void setActive() throws WriteAccessException {} - @Override public void setConfigurationData(String buildSystemId, CConfigurationData data) throws WriteAccessException {} - @Override public void setDescription(String des) throws WriteAccessException {} - @Override public void setName(String name) throws WriteAccessException {} - @Override public void setReferenceInfo(Map refs) throws WriteAccessException {} - @Override public void setSessionProperty(QualifiedName name, Object value) {} - @Override public void setSourceEntries(ICSourceEntry[] entries) throws CoreException, WriteAccessException {} - @Override public ICSettingObject[] getChildSettings() {return null;} - @Override public ICConfigurationDescription getConfiguration() {return null;} - @Override public String getName() {return null;} - @Override public ICSettingContainer getParent() {return null;} - @Override public int getType() {return 0;} - @Override public boolean isReadOnly() {return false;} - @Override public boolean isValid() {return false;} - @Override public ICStorageElement getStorage(String id, boolean create) throws CoreException { return null; } - @Override public ICStorageElement importStorage(String id, ICStorageElement storage) { return null; } - @Override public void removeStorage(String id) throws CoreException { } - @Override public ICLanguageSetting getLanguageSettingForFile(IPath path, boolean ignoreExludeStatus) { return null; } - @Override public String[] getExternalSettingsProviderIds() { return null; } - @Override public void setExternalSettingsProviderIds(String[] ids) {} - @Override public void updateExternalSettingsProviders(String[] ids) {} - @Override public ICSourceEntry[] getResolvedSourceEntries() { return null; } - @Override public CConfigurationStatus getConfigurationStatus() { return CConfigurationStatus.CFG_STATUS_OK; } - @Override public void setReadOnly(boolean readOnly, boolean keepModify) {} - } /* @@ -801,12 +736,12 @@ class MockState { class MockPDOM extends EmptyIndexFragment { String id; String version; - + MockPDOM(String id, String version) { this.id= id; this.version= version; } - + @Override public String getProperty(String propertyName) throws CoreException { if(IIndexFragment.PROPERTY_FRAGMENT_ID.equals(propertyName)) { @@ -820,9 +755,9 @@ class MockPDOM extends EmptyIndexFragment { } return null; } - + @Override public String toString() { return "[Mock index fragment "+id+"."+System.identityHashCode(this)+"]"; } -} +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java index bdb1a16b36d..782173d66ef 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java @@ -147,12 +147,12 @@ public class PDOMManager implements IWritableIndexManager, IListener { private final PDOMIndexerJob fIndexerJob; private IPDOMIndexerTask fCurrentTask; private int fSourceCount, fHeaderCount, fTickCount; - + private final LinkedList fChangeEvents= new LinkedList(); private final Job fNotificationJob; - private final AtomicMultiSet fFilesIndexedUnconditionlly= new AtomicMultiSet(); - + private final AtomicMultiSet fFilesIndexedUnconditionlly= new AtomicMultiSet(); + /** * Stores mapping from pdom to project, used to serialize creation of new pdoms. */ @@ -160,7 +160,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { private Map fFileToProject= new HashMap(); private ListenerList fChangeListeners= new ListenerList(); private ListenerList fStateListeners= new ListenerList(); - + private IndexChangeEvent fIndexChangeEvent= new IndexChangeEvent(); private IndexerStateEvent fIndexerStateEvent= new IndexerStateEvent(); @@ -170,17 +170,17 @@ public class PDOMManager implements IWritableIndexManager, IListener { private final ICProjectDescriptionListener fProjectDescriptionListener; private final JobChangeListener fJobChangeListener; private final IPreferenceChangeListener fPreferenceChangeListener; - + private IndexFactory fIndexFactory= new IndexFactory(this); private IndexProviderManager fIndexProviderManager = new IndexProviderManager(); - + /** - * Serializes creation of new indexer, when acquiring the lock you are + * Serializes creation of new indexer, when acquiring the lock you are * not allowed to hold a lock on fPDOMs. */ private Map fUpdatePolicies= new HashMap(); private Set fClosingProjects= new HashSet(); - + private Map fPrefListeners= new HashMap(); private List fSetupParticipants= new ArrayList(); private Set fPostponedProjects= new HashSet(); @@ -188,7 +188,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { private boolean fInShutDown; boolean fTraceIndexerSetup; - + public PDOMManager() { PDOM.sDEBUG_LOCKS= "true".equals(Platform.getDebugOption(CCorePlugin.PLUGIN_ID + "/debug/index/locks")); //$NON-NLS-1$//$NON-NLS-2$ addIndexerSetupParticipant(new WaitForRefreshJobs()); @@ -204,7 +204,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { fIndexerJob= new PDOMIndexerJob(this); fNotificationJob= createNotifyJob(); } - + public Job startup() { fInShutDown= false; Job postStartupJob= new Job(CCorePlugin.getResourceString("CCorePlugin.startupJob")) { //$NON-NLS-1$ @@ -219,10 +219,10 @@ public class PDOMManager implements IWritableIndexManager, IListener { } }; postStartupJob.setSystem(true); - return postStartupJob; + return postStartupJob; } - /** + /** * Called from a job after plugin start. */ protected void postStartup() { @@ -234,7 +234,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { adjustCacheSize(); updatePathCanonicalizationStrategy(); fIndexProviderManager.startup(); - + fTraceIndexerSetup= String.valueOf(true).equals(Platform.getDebugOption(TRACE_INDEXER_SETUP)); final CoreModel model = CoreModel.getDefault(); ResourcesPlugin.getWorkspace().addResourceChangeListener(fCModelListener, IResourceChangeEvent.POST_BUILD); @@ -268,7 +268,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { fTaskQueue.clear(); jobToCancel= fIndexerJob; } - + if (jobToCancel != null) { assert !Thread.holdsLock(fTaskQueue); jobToCancel.cancelJobs(null, false); @@ -290,7 +290,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { reindexAll(); } } - + protected void adjustCacheSize() { IPreferencesService prefs = Platform.getPreferencesService(); int cachePct= prefs.getInt(CCorePlugin.PLUGIN_ID, CCorePreferenceConstants.INDEX_DB_CACHE_SIZE_PCT, 10, null); @@ -313,7 +313,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { } /** - * Returns the pdom for the project. + * Returns the pdom for the project. * @throws CoreException */ public IPDOM getPDOM(ICProject project) throws CoreException { @@ -327,9 +327,9 @@ public class PDOMManager implements IWritableIndexManager, IListener { return pdom; } } - + /** - * Returns the pdom for the project. The call to the method may cause + * Returns the pdom for the project. The call to the method may cause * opening the database. In case there is a version mismatch the data * base is cleared, in case it does not exist it is created. In any * case a pdom ready to use is returned. @@ -390,7 +390,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { } pdom.setASTFilePathResolver(new ProjectIndexerInputAdapter(project, false)); pdom.addListener(this); - + fFileToProject.put(dbFile, project); fProjectToPDOM.put(rproject, pdom); if (pdomProxy instanceof PDOMProxy) { @@ -438,7 +438,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { public void setDefaultIndexerId(String indexerId) { IndexerPreferences.setDefaultIndexerId(indexerId); } - + @Override public String getIndexerId(ICProject project) { IProject prj= project != null ? project.getProject() : null; @@ -451,7 +451,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { IndexerPreferences.set(prj, IndexerPreferences.KEY_INDEXER_ID, indexerId); CCoreInternals.savePreferences(prj, IndexerPreferences.getScope(prj) == IndexerPreferences.SCOPE_PROJECT_SHARED); } - + protected void onPreferenceChange(ICProject cproject, PreferenceChangeEvent event) { if (IndexerPreferences.KEY_UPDATE_POLICY.equals(event.getKey())) { changeUpdatePolicy(cproject); @@ -482,17 +482,17 @@ public class PDOMManager implements IWritableIndexManager, IListener { private void changeIndexer(ICProject cproject) throws CoreException { assert !Thread.holdsLock(fProjectToPDOM); - + // if there is no indexer, don't touch the preferences. IPDOMIndexer oldIndexer= getIndexer(cproject); if (oldIndexer == null) { return; } - + IProject prj= cproject.getProject(); String newid= IndexerPreferences.get(prj, IndexerPreferences.KEY_INDEXER_ID, IPDOMManager.ID_NO_INDEXER); Properties props= IndexerPreferences.getProperties(prj); - + // Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=359485 synchronized (new ProjectScope(prj).getNode(CCorePlugin.PLUGIN_ID)) { synchronized (fUpdatePolicies) { @@ -519,7 +519,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { enqueue(new PDOMRebuildTask(indexer)); } }} - + if (oldIndexer != null) { stopIndexer(oldIndexer); } @@ -546,26 +546,26 @@ public class PDOMManager implements IWritableIndexManager, IListener { void createIndexer(ICProject project, IProgressMonitor pm) throws InterruptedException { final IProject prj= project.getProject(); final String name = prj.getName(); - if (fTraceIndexerSetup) + if (fTraceIndexerSetup) System.out.println("Indexer: Creation for project " + name); //$NON-NLS-1$ - + assert !Thread.holdsLock(fProjectToPDOM); try { // Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=359485 synchronized (new ProjectScope(prj).getNode(CCorePlugin.PLUGIN_ID)) { synchronized (fUpdatePolicies) { if (fClosingProjects.contains(name)) { - if (fTraceIndexerSetup) + if (fTraceIndexerSetup) System.out.println("Indexer: Aborting setup (1) for closing project " + name + " [1]"); //$NON-NLS-1$ //$NON-NLS-2$ return; } - + WritablePDOM pdom= getOrCreatePDOM(project); Properties props= IndexerPreferences.getProperties(prj); IPDOMIndexer indexer= newIndexer(getIndexerId(project), props); IndexUpdatePolicy policy= createPolicy(project); - boolean rebuild= + boolean rebuild= pdom.isClearedBecauseOfVersionMismatch() || pdom.isCreatedFromScratch() || policy.isInitialRebuildRequested(); @@ -593,7 +593,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { pdom.releaseReadLock(); } if (resume) { - if (fTraceIndexerSetup) + if (fTraceIndexerSetup) System.out.println("Indexer: Resuming for project " + name); //$NON-NLS-1$ enqueue(new PDOMUpdateTask(indexer, @@ -612,7 +612,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { synchronized (new ProjectScope(prj).getNode(CCorePlugin.PLUGIN_ID)) { synchronized (fUpdatePolicies) { if (fClosingProjects.contains(name)) { - if (fTraceIndexerSetup) + if (fTraceIndexerSetup) System.out.println("Indexer: Aborting setup for closing project " + name + " [2]"); //$NON-NLS-1$ //$NON-NLS-2$ return; } @@ -626,13 +626,13 @@ public class PDOMManager implements IWritableIndexManager, IListener { IPDOMIndexerTask task= null; if (operation.wasSuccessful()) { - if (fTraceIndexerSetup) - System.out.println("Indexer: Imported shared index for project " + name); //$NON-NLS-1$ + if (fTraceIndexerSetup) + System.out.println("Indexer: Imported shared index for project " + name); //$NON-NLS-1$ task= new PDOMUpdateTask(indexer, IIndexManager.UPDATE_CHECK_TIMESTAMPS | IIndexManager.UPDATE_CHECK_CONTENTS_HASH); } else { - if (fTraceIndexerSetup) - System.out.println("Indexer: Rebuiding for project " + name); //$NON-NLS-1$ + if (fTraceIndexerSetup) + System.out.println("Indexer: Rebuiding for project " + name); //$NON-NLS-1$ task= new PDOMRebuildTask(indexer); } enqueue(task); @@ -644,7 +644,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { } } } - + private IPDOMIndexer newIndexer(String indexerId, Properties props) throws CoreException { IPDOMIndexer indexer = null; // Look up in extension point @@ -659,14 +659,14 @@ public class PDOMManager implements IWritableIndexManager, IListener { indexer.setProperties(props); } catch (CoreException e) { CCorePlugin.log(e); - } + } break; } } } // Unknown index, default to the null one - if (indexer == null) + if (indexer == null) indexer = new PDOMNullIndexer(); return indexer; @@ -700,7 +700,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { fIndexerJob.schedule(); } } - + private void getReferencingProjects(IProject prj, HashSet result) { LinkedList projectsToSearch= new LinkedList(); projectsToSearch.add(prj); @@ -731,7 +731,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { } return result; } - + void cancelledIndexerJob(boolean byManager) { synchronized (fTaskQueue) { fCurrentTask= null; @@ -743,7 +743,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { } } } - + @Override public boolean isIndexerIdle() { return Job.getJobManager().find(this).length == 0; @@ -753,19 +753,19 @@ public class PDOMManager implements IWritableIndexManager, IListener { final String name = cproject.getProject().getName(); if (fTraceIndexerSetup) { System.out.println("Indexer: Adding new project " + name); //$NON-NLS-1$ - } - + } + synchronized (fUpdatePolicies) { fClosingProjects.remove(name); } - + setupProject(cproject); } void setupProject(final ICProject cproject) { if (fInShutDown) return; - + synchronized (fProjectQueue) { fProjectQueue.add(cproject); } @@ -804,7 +804,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { if (indexer != null && indexer.getID().equals(IPDOMManager.ID_NO_INDEXER)) { return; } - + if (added.length > 0 || changed.length > 0 || removed.length > 0) { synchronized (fUpdatePolicies) { IndexUpdatePolicy policy= createPolicy(project); @@ -835,7 +835,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { } public void preDeleteProject(ICProject cproject) { - preRemoveProject(cproject, true); + preRemoveProject(cproject, true); } public void preCloseProject(ICProject cproject) { @@ -848,8 +848,8 @@ public class PDOMManager implements IWritableIndexManager, IListener { final IProject rproject= cproject.getProject(); final String name = rproject.getName(); - if (fTraceIndexerSetup) - System.out.println("Indexer: Removing project " + name + "; delete=" + delete); //$NON-NLS-1$ //$NON-NLS-2$ + if (fTraceIndexerSetup) + System.out.println("Indexer: Removing project " + name + "; delete=" + delete); //$NON-NLS-1$ //$NON-NLS-2$ IPDOMIndexer indexer; synchronized (fUpdatePolicies) { @@ -896,12 +896,12 @@ public class PDOMManager implements IWritableIndexManager, IListener { job.setSystem(true); job.schedule(); } - + synchronized (fUpdatePolicies) { fUpdatePolicies.remove(cproject); } } - + void removeProject(ICProject cproject, ICElementDelta delta) { synchronized (fProjectToPDOM) { IProject rproject= cproject.getProject(); @@ -921,7 +921,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { policy.clearTUs(); policy.setIndexer(null); } - } + } } cancelIndexerJobs(indexer); } @@ -937,13 +937,13 @@ public class PDOMManager implements IWritableIndexManager, IListener { } jobToCancel= fIndexerJob; } - + if (jobToCancel != null) { assert !Thread.holdsLock(fTaskQueue); jobToCancel.cancelJobs(indexer, true); } - } - + } + private void reindexAll() { ICProject[] cProjects; try { @@ -958,7 +958,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { @Override public void reindex(final ICProject project) { - Job job= new Job(Messages.PDOMManager_notifyJob_label) { + Job job= new Job(Messages.PDOMManager_notifyJob_label) { @Override protected IStatus run(IProgressMonitor monitor) { IPDOMIndexer indexer= null; @@ -999,7 +999,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { public void removeIndexChangeListener(IIndexChangeListener listener) { fChangeListeners.remove(listener); } - + @Override public void addIndexerStateListener(IIndexerStateListener listener) { fStateListeners.add(listener); @@ -1029,7 +1029,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { notify.setSystem(true); return notify; } - + private void scheduleNotification(Runnable notify) { if (fInShutDown) return; @@ -1079,12 +1079,12 @@ public class PDOMManager implements IWritableIndexManager, IListener { if (fChangeListeners.isEmpty()) { return; } - + ICProject project; synchronized (fProjectToPDOM) { project = fFileToProject.get(pdom.getPath()); - } - + } + if (project != null) { final ICProject finalProject= project; Runnable notify= new Runnable() { @@ -1145,10 +1145,10 @@ public class PDOMManager implements IWritableIndexManager, IListener { } } } - + int getMonitorMessage(PDOMIndexerJob job, int currentTicks, int base) { assert !Thread.holdsLock(fTaskQueue); - + int sourceCount, sourceEstimate, headerCount, tickCount, tickEstimate; String detail= null; synchronized (fTaskQueue) { @@ -1175,14 +1175,14 @@ public class PDOMManager implements IWritableIndexManager, IListener { detail= PDOMIndexerJob.sMonitorDetail; } } - - String msg= MessageFormat.format(Messages.PDOMManager_indexMonitorDetail, new Object[] { - new Integer(sourceCount), new Integer(sourceEstimate), - new Integer(headerCount)}); + + String msg= MessageFormat.format(Messages.PDOMManager_indexMonitorDetail, new Object[] { + new Integer(sourceCount), new Integer(sourceEstimate), + new Integer(headerCount)}); if (detail != null) { msg += ": " + detail; //$NON-NLS-1$ } - + job.subTask(msg); if (tickCount > 0 && tickCount <= tickEstimate) { int newTick= tickCount*base/tickEstimate; @@ -1218,7 +1218,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { public IIndex getIndex(ICProject[] projects, int options) throws CoreException { return fIndexFactory.getIndex(projects, options); } - + /** * Exports the project PDOM to the specified location, rewriting locations with * the specified location converter. @@ -1255,7 +1255,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { } // overwrite internal location representations - final WritablePDOM newPDOM = new WritablePDOM(targetLocation, pdom.getLocationConverter(), getLinkageFactories()); + final WritablePDOM newPDOM = new WritablePDOM(targetLocation, pdom.getLocationConverter(), getLinkageFactories()); newPDOM.acquireWriteLock(); try { newPDOM.rewriteLocations(newConverter); @@ -1275,7 +1275,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { } /** - * Resets the pdom for the project with the provided stream. + * Resets the pdom for the project with the provided stream. * @throws CoreException * @throws OperationCanceledException in case the thread was interrupted * @since 4.0 @@ -1294,11 +1294,11 @@ public class PDOMManager implements IWritableIndexManager, IListener { } if (version > PDOM.getMaxSupportedVersion()) { final IStatus status = new Status(IStatus.WARNING, CCorePlugin.PLUGIN_ID, 0, CCorePlugin.getResourceString("PDOMManager.unsupportedHigherVersion"), null); //$NON-NLS-1$ - throw new CoreException(status); + throw new CoreException(status); } if ( !PDOM.isSupportedVersion( version ) ) { final IStatus status = new Status(IStatus.WARNING, CCorePlugin.PLUGIN_ID, 0, CCorePlugin.getResourceString("PDOMManager.unsupportedVersion"), null); //$NON-NLS-1$ - throw new CoreException(status); + throw new CoreException(status); } byte[] buffer= new byte[2048]; int read; @@ -1308,7 +1308,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { } finally { out.close(); } - + WritablePDOM pdom= (WritablePDOM) getPDOM(project); try { pdom.acquireWriteLock(); @@ -1323,7 +1323,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { pdom.releaseWriteLock(); } } - + @Override public void export(ICProject project, String location, int options, IProgressMonitor monitor) throws CoreException { TeamPDOMExportOperation operation= new TeamPDOMExportOperation(project); @@ -1331,7 +1331,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { operation.setOptions(options); operation.run(monitor); } - + /** * Write metadata appropriate for a project pdom * @param pdom the pdom to write to @@ -1362,7 +1362,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { for (Map.Entry> entry : projectsToElements.entrySet()) { ICProject project = entry.getKey(); List filesAndFolders = entry.getValue(); - + update(project, filesAndFolders, options); } } @@ -1389,14 +1389,14 @@ public class PDOMManager implements IWritableIndexManager, IListener { } else if (contains(element, other)) { set.set(j, element); continue allElements; - } + } } set.add(element); } } return result; } - + private boolean contains(final ICElement a, ICElement b) { if (a.equals(b)) { return true; @@ -1493,7 +1493,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { if (fPostponedProjects.contains(project)) { setupProject(project); } - } + } } @Override @@ -1512,7 +1512,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { } } } - + /** * @param project * @return whether the specified project has been registered. If a project has @@ -1522,7 +1522,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { public boolean isProjectRegistered(ICProject project) { return getIndexer(project) != null; } - + /** * @param cproject the project to check * @return whether the content in the project fragment of the specified project's index @@ -1532,7 +1532,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { public boolean isProjectContentSynced(ICProject cproject) throws CoreException { if (!"true".equals(IndexerPreferences.get(cproject.getProject(), IndexerPreferences.KEY_INDEX_ALL_FILES, null))) //$NON-NLS-1$ return true; // no check performed in this case - + Set sources= new HashSet(); cproject.accept(new TranslationUnitCollector(sources, null, new NullProgressMonitor())); @@ -1558,7 +1558,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { return true; } - + private boolean isSubjectToIndexing(ILanguage language) { final int linkageID=language.getLinkageID(); for (int id : IDS_FOR_LINKAGES_TO_INDEX) { @@ -1580,7 +1580,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { private static boolean areSynchronized(Set trail, IIndex index, IResource resource, IIndexFileLocation location) throws CoreException { if (!trail.contains(location)) { trail.add(location); - + IIndexFile[] file= index.getFiles(location); // pre-includes may be listed twice (191989) @@ -1606,7 +1606,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { } } } - + return true; } diff --git a/core/org.eclipse.cdt.core/plugin.xml b/core/org.eclipse.cdt.core/plugin.xml index 9dbdb0cbde7..c22d57744da 100644 --- a/core/org.eclipse.cdt.core/plugin.xml +++ b/core/org.eclipse.cdt.core/plugin.xml @@ -653,9 +653,9 @@ - + + - Date: Sat, 17 Dec 2011 11:18:35 -0500 Subject: [PATCH 098/120] Fixed API tooling errors. --- .../AbstractBuildCommandParser.java | 2 + .../AbstractBuiltinSpecsDetector.java | 3 + ...AbstractLanguageSettingsOutputScanner.java | 3 + .../managedbuilder/core/IConfiguration.java | 412 +++++++++--------- .../cdt/managedbuilder/core/IToolChain.java | 197 ++++----- .../ToolchainBuiltinSpecsDetector.java | 5 +- .../ui/wizards/MBSWizardHandler.java | 4 + .../wizards/NewMakeProjFromExistingPage.java | 6 +- .../.settings/.api_filters | 17 + .../settings/providers/ICListenerAgent.java | 2 + ...ILanguageSettingsBroadcastingProvider.java | 2 + .../ILanguageSettingsChangeEvent.java | 2 + .../ILanguageSettingsChangeListener.java | 2 + .../ILanguageSettingsEditableProvider.java | 2 + .../providers/ILanguageSettingsProvider.java | 2 + .../ILanguageSettingsProvidersKeeper.java | 2 + .../LanguageSettingsBaseProvider.java | 2 + .../LanguageSettingsGenericProvider.java | 2 + .../providers/LanguageSettingsManager.java | 2 + .../LanguageSettingsSerializableProvider.java | 2 + .../providers/LanguageSettingsStorage.java | 2 + .../ScannerDiscoveryLegacySupport.java | 2 + .../model/ACExclusionFilterEntry.java | 4 +- .../cdt/core/settings/model/ACPathEntry.java | 4 +- .../settings/model/ICDescriptionDelta.java | 45 +- .../core/settings/model/ICSettingEntry.java | 11 +- .../LanguageSettingEntriesSerializer.java | 55 +-- .../core/AbstractExecutableExtensionBase.java | 2 + .../src/org/eclipse/cdt/core/CCorePlugin.java | 2 + .../org/eclipse/cdt/core/ICConsoleParser.java | 2 + .../org/eclipse/cdt/ui/CDTSharedImages.java | 29 +- .../cdt/ui/newui/AbstractCPropertyTab.java | 219 +++++----- .../org/eclipse/cdt/ui/newui/CDTPrefUtil.java | 96 ++-- .../cdt/ui/wizards/CDTMainWizardPage.java | 4 + 34 files changed, 632 insertions(+), 516 deletions(-) create mode 100644 core/org.eclipse.cdt.core/.settings/.api_filters diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java index e9bf2571aef..42ee4cf01ee 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java @@ -40,6 +40,8 @@ import org.eclipse.core.runtime.jobs.Job; * * Note: IErrorParser interface is used here to work around {@link ConsoleOutputSniffer} having * no access from CDT core to build packages. TODO - elaborate? + * + * @since 7.2 */ public abstract class AbstractBuildCommandParser extends AbstractLanguageSettingsOutputScanner implements ICConsoleParser, IErrorParser { diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java index 9230eff9c4b..d2c7b7b994f 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java @@ -67,6 +67,9 @@ import org.eclipse.core.runtime.jobs.ISchedulingRule; import org.eclipse.core.runtime.jobs.Job; import org.w3c.dom.Element; +/** + * @since 7.2 + */ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSettingsOutputScanner implements ICListenerAgent { public static final Object JOB_FAMILY_BUILTIN_SPECS_DETECTOR = "org.eclipse.cdt.make.core.scannerconfig.AbstractBuiltinSpecsDetector"; diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java index 848f9307861..05ea657cea3 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java @@ -54,6 +54,9 @@ import org.eclipse.core.runtime.content.IContentType; import org.eclipse.core.runtime.content.IContentTypeManager; import org.w3c.dom.Element; +/** + * @since 7.2 + */ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSettingsSerializableProvider { protected static final String ATTR_EXPAND_RELATIVE_PATHS = "expand-relative-paths"; //$NON-NLS-1$ diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IConfiguration.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IConfiguration.java index 3ab54cf1ec7..b6227d36b36 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IConfiguration.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IConfiguration.java @@ -24,14 +24,14 @@ import org.eclipse.core.runtime.IPath; /** * A tool-integrator defines default configurations as children of the project type. - * These provide a template for the configurations added to the user's project, - * which are stored in the project's .cproject file. + * These provide a template for the configurations added to the user's project, + * which are stored in the project's .cproject file. *

    - * The configuration contains one child of type tool-chain. This describes how the + * The configuration contains one child of type tool-chain. This describes how the * project's resources are transformed into the build artifact. The configuration can * contain one or more children of type resourceConfiguration. These describe build * settings of individual resources that are different from the configuration as a whole. - * + * * @since 2.1 * @noextend This class is not intended to be subclassed by clients. * @noimplement This interface is not intended to be implemented by clients. @@ -39,34 +39,35 @@ import org.eclipse.core.runtime.IPath; public interface IConfiguration extends IBuildObject, IBuildObjectPropertiesContainer { public static final String ARTIFACT_NAME = "artifactName"; //$NON-NLS-1$ public static final String CLEAN_COMMAND = "cleanCommand"; //$NON-NLS-1$ - public static final String PREBUILD_STEP = "prebuildStep"; //$NON-NLS-1$ - public static final String POSTBUILD_STEP = "postbuildStep"; //$NON-NLS-1$ - public static final String PREANNOUNCEBUILD_STEP = "preannouncebuildStep"; //$NON-NLS-1$ - public static final String POSTANNOUNCEBUILD_STEP = "postannouncebuildStep"; //$NON-NLS-1$ + public static final String PREBUILD_STEP = "prebuildStep"; //$NON-NLS-1$ + public static final String POSTBUILD_STEP = "postbuildStep"; //$NON-NLS-1$ + public static final String PREANNOUNCEBUILD_STEP = "preannouncebuildStep"; //$NON-NLS-1$ + public static final String POSTANNOUNCEBUILD_STEP = "postannouncebuildStep"; //$NON-NLS-1$ // Schema element names public static final String CONFIGURATION_ELEMENT_NAME = "configuration"; //$NON-NLS-1$ public static final String ERROR_PARSERS = "errorParsers"; //$NON-NLS-1$ + /** @since 8.1 */ public static final String LANGUAGE_SETTINGS_PROVIDERS = "languageSettingsProviders"; public static final String EXTENSION = "artifactExtension"; //$NON-NLS-1$ public static final String PARENT = "parent"; //$NON-NLS-1$ - + public static final String DESCRIPTION = "description"; //$NON-NLS-1$ - + public static final String BUILD_PROPERTIES = "buildProperties"; //$NON-NLS-1$ public static final String BUILD_ARTEFACT_TYPE = "buildArtefactType"; //$NON-NLS-1$ public static final String IS_SYSTEM = "isSystem"; //$NON-NLS-1$ public static final String SOURCE_ENTRIES = "sourceEntries"; //$NON-NLS-1$ - - + + /** * Returns the description of the configuration. - * + * * @return String */ public String getDescription(); - + /** * Sets the description of the receiver to the value specified in the argument */ @@ -85,206 +86,207 @@ public interface IConfiguration extends IBuildObject, IBuildObjectPropertiesCont * @param name - The name for the new tool chain * @param isExtensionElement - set {@code true} if the toolchain being created * represents extension point toolchain - * + * * @return IToolChain */ public IToolChain createToolChain(IToolChain superClass, String Id, String name, boolean isExtensionElement); - + /** - * Returns the extension that should be applied to build artifacts created by + * Returns the extension that should be applied to build artifacts created by * this configuration. - * + * * @return String */ - public String getArtifactExtension(); + public String getArtifactExtension(); /** * Returns the name of the final build artifact. - * + * * @return String */ public String getArtifactName(); /** - * Returns the build arguments from this configuration's builder - * + * Returns the build arguments from this configuration's builder + * * @return String */ public String getBuildArguments(); /** - * Returns the build command from this configuration's builder - * + * Returns the build command from this configuration's builder + * * @return String */ public String getBuildCommand(); - + /** * Returns the prebuild step command - * - * @return String - */ - public String getPrebuildStep(); - - /** - * Returns the postbuild step command - * - * @return String - */ - public String getPostbuildStep(); - - /** - * Returns the display string associated with the prebuild step - * - * @return String - */ - public String getPreannouncebuildStep(); - - /** - * Returns the display string associated with the postbuild step - * - * @return String - */ - public String getPostannouncebuildStep(); - - /** + * + * @return String + */ + public String getPrebuildStep(); + + /** + * Returns the postbuild step command + * + * @return String + */ + public String getPostbuildStep(); + + /** + * Returns the display string associated with the prebuild step + * + * @return String + */ + public String getPreannouncebuildStep(); + + /** + * Returns the display string associated with the postbuild step + * + * @return String + */ + public String getPostannouncebuildStep(); + + /** * Answers the OS-specific command to remove files created by the build * of this configuration. - * + * * @return String */ public String getCleanCommand(); /** - * Answers the semicolon separated list of unique IDs of the error parsers associated + * Answers the semicolon separated list of unique IDs of the error parsers associated * with this configuration. - * + * * @return String */ public String getErrorParserIds(); /** - * Answers the ordered list of unique IDs of the error parsers associated + * Answers the ordered list of unique IDs of the error parsers associated * with this configuration. - * + * * @return String[] */ public String[] getErrorParserList(); - + + /** @since 8.1 */ public String getDefaultLanguageSettingsProvidersIds(); /** - * Projects have C or CC natures. Tools can specify a filter so they are not - * misapplied to a project. This method allows the caller to retrieve a list - * of tools from a project that are correct for a project's nature. - * - * @return an array of ITools that have compatible filters + * Projects have C or CC natures. Tools can specify a filter so they are not + * misapplied to a project. This method allows the caller to retrieve a list + * of tools from a project that are correct for a project's nature. + * + * @return an array of ITools that have compatible filters * for this configuration. */ ITool[] getFilteredTools(); - + /** * Returns the managed-project parent of this configuration, if this is a * project configuration. Otherwise, returns null. - * + * * @return IManagedProject */ public IManagedProject getManagedProject(); - + /** * Returns the Eclipse project that owns the configuration. - * + * * @return IResource */ public IResource getOwner(); - + /** - * Returns the configuration that this configuration is based on. - * + * Returns the configuration that this configuration is based on. + * * @return IConfiguration */ public IConfiguration getParent(); - + /** * Returns the project-type parent of this configuration, if this is an * extension configuration. Otherwise, returns null. - * + * * @return IProjectType */ public IProjectType getProjectType(); - + /** * @param path - path of the resource - * + * * @return the resource configuration child of this configuration * that is associated with the project resource, or null if none. */ public IResourceConfiguration getResourceConfiguration(String path); - + /** * Returns the resource configuration children of this configuration. - * + * * @return IResourceConfigurations[] */ public IResourceConfiguration[] getResourceConfigurations(); - + /** * Returns the ITool in this configuration's tool-chain with - * the same id as the argument, or null. - * + * the same id as the argument, or null. + * * @param id unique identifier to search for * @return ITool */ public ITool getTool(String id); /** - * Returns the ITool in this configuration's tool-chain with - * the specified ID, or the tool(s) with a superclass with this id. - * - *

    If the tool-chain does not have a tool with that ID, the method - * returns an empty array. It is the responsibility of the caller to - * verify the return value. - * + * Returns the ITool in this configuration's tool-chain with + * the specified ID, or the tool(s) with a superclass with this id. + * + *

    If the tool-chain does not have a tool with that ID, the method + * returns an empty array. It is the responsibility of the caller to + * verify the return value. + * * @param id unique identifier of the tool to search for * @return ITool[] * @since 3.0.2 */ public ITool[] getToolsBySuperClassId(String id); - + /** * Returns the IToolChain child of this configuration. - * + * * @return IToolChain */ public IToolChain getToolChain(); - + /** * Returns the command-line invocation command for the specified tool. - * + * * @param tool The tool that will have its command retrieved. * @return String The command */ public String getToolCommand(ITool tool); - + /** * Returns the tools that are used in this configuration's tool-chain. - * + * * @return ITool[] */ public ITool[] getTools(); /** - * Returns the tool in this configuration specified with + * Returns the tool in this configuration specified with * the toolChain#targetTool attribute that creates the build artifact - * - * NOTE: This method returns null in case the toolChain definition + * + * NOTE: This method returns null in case the toolChain definition * does not have the targetTool attribute or if the attribute does not * refer to the appropriate tool. * For the target tool calculation the IConfiguration#calculateTargetTool() * method should be used - * + * * @see IConfiguration#calculateTargetTool() - * + * * @return ITool */ public ITool getTargetTool(); @@ -292,42 +294,42 @@ public interface IConfiguration extends IBuildObject, IBuildObjectPropertiesCont /** * Returns true if this configuration has overridden the default build * build command in this configuration, otherwise false. - * - * @return boolean + * + * @return boolean */ public boolean hasOverriddenBuildCommand(); - + /** - * Returns true if the extension matches one of the special - * file extensions the tools for the configuration consider to be a header file. - * + * Returns true if the extension matches one of the special + * file extensions the tools for the configuration consider to be a header file. + * * @param ext the file extension of the resource * @return boolean */ public boolean isHeaderFile(String ext); - + /** - * Returns true if this configuration has changes that need to - * be saved in the project file, else false. + * Returns true if this configuration has changes that need to + * be saved in the project file, else false. * Should not be called for an extension configuration. - * - * @return boolean + * + * @return boolean */ public boolean isDirty(); - + /** * Returns true if this configuration was loaded from a manifest file, * and false if it was loaded from a project (.cdtbuild) file. - * - * @return boolean + * + * @return boolean */ public boolean isExtensionElement(); /** - * Returns whether this configuration has been changed and requires the + * Returns whether this configuration has been changed and requires the * project to be rebuilt. - * - * @return true if the configuration contains a change + * + * @return true if the configuration contains a change * that needs the project to be rebuilt. * Should not be called for an extension configuration. */ @@ -335,13 +337,13 @@ public interface IConfiguration extends IBuildObject, IBuildObjectPropertiesCont /** * Removes a resource configuration from the configuration's list. - * + * * @param resConfig - resource configuration to remove */ public void removeResourceConfiguration(IResourceInfo resConfig); - + public void removeResourceInfo(IPath path); - + /** * Set (override) the extension that should be appended to the build artifact * for the receiver. @@ -355,7 +357,7 @@ public interface IConfiguration extends IBuildObject, IBuildObjectPropertiesCont public void setArtifactName(String name); /** - * Sets the arguments to be passed to the build utility used by the + * Sets the arguments to be passed to the build utility used by the * receiver to produce a build goal. */ public void setBuildArguments(String makeArgs); @@ -366,26 +368,26 @@ public interface IConfiguration extends IBuildObject, IBuildObjectPropertiesCont public void setBuildCommand(String command); /** - * Sets the prebuild step for the receiver to the value in the argument. - */ - public void setPrebuildStep(String step); - - /** - * Sets the postbuild step for the receiver to the value in the argument. - */ - public void setPostbuildStep(String step); - - /** - * Sets the prebuild step display string for the receiver to the value in the argument. - */ - public void setPreannouncebuildStep(String announceStep); - - /** - * Sets the postbuild step display string for the receiver to the value in the argument. - */ - public void setPostannouncebuildStep(String announceStep); - - /** + * Sets the prebuild step for the receiver to the value in the argument. + */ + public void setPrebuildStep(String step); + + /** + * Sets the postbuild step for the receiver to the value in the argument. + */ + public void setPostbuildStep(String step); + + /** + * Sets the prebuild step display string for the receiver to the value in the argument. + */ + public void setPreannouncebuildStep(String announceStep); + + /** + * Sets the postbuild step display string for the receiver to the value in the argument. + */ + public void setPostannouncebuildStep(String announceStep); + + /** * Sets the command used to clean the outputs of this configuration. * @param command - the command to clean outputs */ @@ -407,46 +409,46 @@ public interface IConfiguration extends IBuildObject, IBuildObjectPropertiesCont * Sets the name of the receiver to the value specified in the argument */ public void setName(String name); - + /** * Sets the value of a boolean option for this configuration. - * + * * @param parent The holder/parent of the option. * @param option The option to change. * @param value The value to apply to the option. - * + * * @return IOption The modified option. This can be the same option or a newly created option. - * + * * @since 3.0 - The type of parent has changed from ITool to IHoldsOptions. * Code assuming ITool as type, will continue to work unchanged. */ - public IOption setOption(IHoldsOptions parent, IOption option, boolean value) - throws BuildException; + public IOption setOption(IHoldsOptions parent, IOption option, boolean value) + throws BuildException; /** * Sets the value of a string option for this configuration. - * + * * @param parent The holder/parent of the option. * @param option The option that will be effected by change. * @param value The value to apply to the option. - * + * * @return IOption The modified option. This can be the same option or a newly created option. - * + * * @since 3.0 - The type of parent has changed from ITool to IHoldsOptions. * Code assuming ITool as type, will continue to work unchanged. */ public IOption setOption(IHoldsOptions parent, IOption option, String value) throws BuildException; - + /** * Sets the value of a list option for this configuration. - * + * * @param parent The holder/parent of the option. * @param option The option to change. * @param value The values to apply to the option. - * + * * @return IOption The modified option. This can be the same option or a newly created option. - * + * * @since 3.0 - The type of parent has changed from ITool to IHoldsOptions. * Code assuming ITool as type, will continue to work unchanged. */ @@ -455,7 +457,7 @@ public interface IConfiguration extends IBuildObject, IBuildObjectPropertiesCont /** * Sets the rebuild state in this configuration. - * + * * @param rebuild true will force a rebuild the next time the project builds * @see org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo#setRebuildState(boolean) */ @@ -463,93 +465,93 @@ public interface IConfiguration extends IBuildObject, IBuildObjectPropertiesCont /** * Overrides the tool command for a tool defined in this configuration's tool-chain. - * + * * @param tool The tool that will have its command modified. * @param command The command */ public void setToolCommand(ITool tool, String command); - + /** * Returns true if the configuration's tool-chain is supported on the system * otherwise returns false - * - * @return boolean - */ + * + * @return boolean + */ public boolean isSupported(); - + /** * Returns the implementation of the IConfigurationEnvironmentVariableSupplier provided * by the tool-integrator or null if none. - * - * @return IConfigurationEnvironmentVariableSupplier - */ + * + * @return IConfigurationEnvironmentVariableSupplier + */ public IConfigurationEnvironmentVariableSupplier getEnvironmentVariableSupplier(); - + /** * Returns the tool-integrator provided implementation of the configuration build macro supplier - * or null if none. - * + * or null if none. + * * @return IConfigurationBuildMacroSupplier */ public IConfigurationBuildMacroSupplier getBuildMacroSupplier(); - + /** * answers true if the configuration is temporary, otherwise - false * @return boolean */ public boolean isTemporary(); - + /** * Returns whether this configuration requires a full rebuild - * + * * @return boolean */ public boolean needsFullRebuild(); /** * Calculates the configuration target tool. - * + * * @return ITool or null if not found - * + * * @since 3.1 */ public ITool calculateTargetTool(); - + /** - * Returns a ITool for the tool associated with the + * Returns a ITool for the tool associated with the * output extension. - * + * * @param extension the file extension of the output file * @return ITool - * + * * @since 3.1 */ public ITool getToolFromOutputExtension(String extension); - + /** - * Returns a ITool for the tool associated with the + * Returns a ITool for the tool associated with the * input extension. - * + * * @param sourceExtension the file extension of the input file * @return ITool - * + * * @since 3.1 */ public ITool getToolFromInputExtension(String sourceExtension); - + IResourceInfo getResourceInfo(IPath path, boolean exactPath); - + IResourceInfo[] getResourceInfos(); - + IResourceInfo getResourceInfoById(String id); - - IFolderInfo getRootFolderInfo(); - + + IFolderInfo getRootFolderInfo(); + IFileInfo createFileInfo(IPath path); IFileInfo createFileInfo(IPath path, String id, String name); - + IFileInfo createFileInfo(IPath path, IFolderInfo base, ITool baseTool, String id, String name); IFileInfo createFileInfo(IPath path, IFileInfo base, String id, String name); @@ -557,49 +559,49 @@ public interface IConfiguration extends IBuildObject, IBuildObjectPropertiesCont IFolderInfo createFolderInfo(IPath path); IFolderInfo createFolderInfo(IPath path, String id, String name); - + IFolderInfo createFolderInfo(IPath path, IFolderInfo base, String id, String name); - + CConfigurationData getConfigurationData(); - + ICSourceEntry[] getSourceEntries(); void setSourceEntries(ICSourceEntry[] entries); - + CBuildData getBuildData(); - + IBuilder getBuilder(); - + IBuilder getEditableBuilder(); - + String getOutputPrefix(String outputExtension); - + boolean isSystemObject(); - + String getOutputExtension(String resourceExtension); - + String getOutputFlag(String outputExt); - - IManagedCommandLineInfo generateToolCommandLineInfo( String sourceExtension, String[] flags, + + IManagedCommandLineInfo generateToolCommandLineInfo( String sourceExtension, String[] flags, String outputFlag, String outputPrefix, String outputName, String[] inputResources, IPath inputLocation, IPath outputLocation ); - + String[] getUserObjects(String extension); - + String[] getLibs(String extension); - + boolean buildsFileType(String srcExt); - + boolean supportsBuild(boolean managed); - + boolean isManagedBuildOn(); void setManagedBuildOn(boolean on) throws BuildException; - + boolean isBuilderCompatible(IBuilder builder); - + void changeBuilder(IBuilder newBuilder, String id, String name); - + IBuildPropertyValue getBuildArtefactType(); - + void setBuildArtefactType(String id) throws BuildException; } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IToolChain.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IToolChain.java index 34a1a4331b7..2757a06b134 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IToolChain.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IToolChain.java @@ -16,19 +16,19 @@ import org.eclipse.cdt.managedbuilder.macros.IConfigurationBuildMacroSupplier; /** - * This interface represents a tool-integrator-defined, ordered set of tools - * that transform the project's input into the project's outputs. A - * tool-chain can be defined as part of a configuration, or as an + * This interface represents a tool-integrator-defined, ordered set of tools + * that transform the project's input into the project's outputs. A + * tool-chain can be defined as part of a configuration, or as an * independent specification that is referenced in a separate configuration * via the toolChain superclass attribute. *

    * The toolChain contains one or more children of type tool. These define - * the tools used in the tool-chain. The toolChain contains one child of + * the tools used in the tool-chain. The toolChain contains one child of * type targetPlatform. This defines the architecture/os combination where - * the outputs of the project can be deployed. The toolChain contains one + * the outputs of the project can be deployed. The toolChain contains one * child of type builder. This defines the "build" or "make" utility that * is used to drive the transformation of the inputs into outputs. - * + * * @since 2.1 * @noextend This class is not intended to be subclassed by clients. * @noimplement This interface is not intended to be implemented by clients. @@ -49,15 +49,16 @@ public interface IToolChain extends IBuildObject, IHoldsOptions { public static final String IS_SYSTEM= "isSystem"; //$NON-NLS-1$ public static final String NON_INTERNAL_BUILDER_ID = "nonInternalBuilderId"; //$NON-NLS-1$ public static final String RESOURCE_TYPE_BASED_DISCOVERY = "resourceTypeBasedDiscovery"; //$NON-NLS-1$ - + // The attribute name for the scanner info collector public static final String SCANNER_CONFIG_PROFILE_ID = "scannerConfigDiscoveryProfileId"; //$NON-NLS-1$ + /** @since 8.1 */ public static final String LANGUAGE_SETTINGS_PROVIDERS = "languageSettingsProviders"; /** * Returns the configuration that is the parent of this tool-chain. - * + * * @return IConfiguration */ public IConfiguration getParent(); @@ -69,14 +70,14 @@ public interface IToolChain extends IBuildObject, IHoldsOptions { * @param Id The id for the new tool chain * @param name The name for the new tool chain * @param isExtensionElement Indicates whether this is an extension element or a managed project element - * + * * @return ITargetPlatform */ public ITargetPlatform createTargetPlatform(ITargetPlatform superClass, String Id, String name, boolean isExtensionElement); /** * Returns the target-platform child of this tool-chain - * + * * @return ITargetPlatform */ public ITargetPlatform getTargetPlatform(); @@ -89,30 +90,30 @@ public interface IToolChain extends IBuildObject, IHoldsOptions { /** * Returns the 'versionsSupported' of this tool-chain - * + * * @return String */ public String getVersionsSupported(); /** * Returns the 'convertToId' of this tool-chain - * + * * @return String */ public String getConvertToId(); - + /** - * Sets the 'versionsSupported' attribute of the tool-chain. + * Sets the 'versionsSupported' attribute of the tool-chain. */ - + public void setVersionsSupported(String versionsSupported); - + /** - * Sets the 'convertToId' attribute of the tool-chain. + * Sets the 'convertToId' attribute of the tool-chain. */ public void setConvertToId(String convertToId); - + /** * Creates the Builder child of this tool-chain. * @@ -120,7 +121,7 @@ public interface IToolChain extends IBuildObject, IHoldsOptions { * @param Id The id for the new tool chain * @param name The name for the new tool chain * @param isExtensionElement Indicates whether this is an extension element or a managed project element - * + * * @return IBuilder */ public IBuilder createBuilder(IBuilder superClass, String Id, String name, boolean isExtensionElement); @@ -133,7 +134,7 @@ public interface IToolChain extends IBuildObject, IHoldsOptions { /** * Returns the builder child of this tool-chain. - * + * * @return IBuilder */ public IBuilder getBuilder(); @@ -145,35 +146,35 @@ public interface IToolChain extends IBuildObject, IHoldsOptions { * @param Id The id for the new tool chain * @param name The name for the new tool chain * @param isExtensionElement Indicates whether this is an extension element or a managed project element - * + * * @return ITool */ public ITool createTool(ITool superClass, String Id, String name, boolean isExtensionElement); /** * Returns an array of tool children of this tool-chain - * + * * @return ITool[] */ public ITool[] getTools(); /** - * Returns the tool in this tool-chain with the ID specified in the argument, - * or null - * + * Returns the tool in this tool-chain with the ID specified in the argument, + * or null + * * @param id The ID of the requested tool * @return ITool */ public ITool getTool(String id); /** - * Returns the ITool in the tool-chain with the specified - * ID, or the tool(s) with a superclass with this id. - * - *

    If the tool-chain does not have a tool with that ID, the method - * returns an empty array. It is the responsibility of the caller to - * verify the return value. - * + * Returns the ITool in the tool-chain with the specified + * ID, or the tool(s) with a superclass with this id. + * + *

    If the tool-chain does not have a tool with that ID, the method + * returns an empty array. It is the responsibility of the caller to + * verify the return value. + * * @param id unique identifier of the tool to search for * @return ITool[] * @since 3.0.2 @@ -183,55 +184,55 @@ public interface IToolChain extends IBuildObject, IHoldsOptions { /** * Returns the IToolChain that is the superclass of this * tool-chain, or null if the attribute was not specified. - * + * * @return IToolChain */ public IToolChain getSuperClass(); - + /** * Returns whether this element is abstract. Returns false * if the attribute was not specified. - * @return boolean + * @return boolean */ public boolean isAbstract(); /** - * Sets the isAbstract attribute of the tool-chain. + * Sets the isAbstract attribute of the tool-chain. */ public void setIsAbstract(boolean b); - + /** * Returns a semi-colon delimited list of child Ids of the superclass' * children that should not be automatically inherited by this element. - * Returns an empty string if the attribute was not specified. - * @return String + * Returns an empty string if the attribute was not specified. + * @return String */ public String getUnusedChildren(); - + /** * Returns an array of operating systems the tool-chain outputs can run on. - * + * * @return String[] */ public String[] getOSList(); /** * Sets the OS list. - * + * * @param OSs The list of OS names */ public void setOSList(String[] OSs); - + /** * Returns an array of architectures the tool-chain outputs can run on. - * + * * @return String[] */ public String[] getArchList(); - + /** * Sets the architecture list. - * + * * @param archs The list of architecture names */ public void setArchList(String[] archs); @@ -239,7 +240,7 @@ public interface IToolChain extends IBuildObject, IHoldsOptions { /** * Returns the semicolon separated list of unique IDs of the error parsers associated * with the tool-chain. - * + * * @return String */ public String getErrorParserIds(); @@ -251,9 +252,9 @@ public interface IToolChain extends IBuildObject, IHoldsOptions { public String getErrorParserIds(IConfiguration config); /** - * Returns the ordered list of unique IDs of the error parsers associated with the + * Returns the ordered list of unique IDs of the error parsers associated with the * tool-chain. - * + * * @return String[] */ public String[] getErrorParserList(); @@ -267,12 +268,14 @@ public interface IToolChain extends IBuildObject, IHoldsOptions { * Returns the default language settings providers IDs. * * @return the default language settings providers IDs separated by semicolon or {@code null} if none. + * + * @since 8.1 */ public String getDefaultLanguageSettingsProvidersIds(); /** - * Returns the scanner config discovery profile id or null if none. - * + * Returns the scanner config discovery profile id or null if none. + * * @return String */ public String getScannerConfigDiscoveryProfileId(); @@ -283,93 +286,93 @@ public interface IToolChain extends IBuildObject, IHoldsOptions { public void setScannerConfigDiscoveryProfileId(String profileId); /** - * Returns the sem-colon separated list of Tool ids containing each - * tool that can create the final build artifact (the end target of - * the build). MBS will use the first ID in the list that matches - * a Tool in the ToolChain. One reason for specifying a list, is - * that different versions of a tool can be selected based upon the + * Returns the sem-colon separated list of Tool ids containing each + * tool that can create the final build artifact (the end target of + * the build). MBS will use the first ID in the list that matches + * a Tool in the ToolChain. One reason for specifying a list, is + * that different versions of a tool can be selected based upon the * project nature (e.g. different tool definitions for a linker for C vs. C++). - * + * * @return String */ public String getTargetToolIds(); /** - * Sets the sem-colon separated list of Tool ids containing each - * tool that can create the final build artifact (the end target of - * the build). + * Sets the sem-colon separated list of Tool ids containing each + * tool that can create the final build artifact (the end target of + * the build). */ public void setTargetToolIds(String targetToolIds); /** - * Returns the list of Tool ids containing each - * tool that can create the final build artifact (the end target of - * the build). MBS will use the first ID in the list that matches - * a Tool in the ToolChain. One reason for specifying a list, is - * that different versions of a tool can be selected based upon the + * Returns the list of Tool ids containing each + * tool that can create the final build artifact (the end target of + * the build). MBS will use the first ID in the list that matches + * a Tool in the ToolChain. One reason for specifying a list, is + * that different versions of a tool can be selected based upon the * project nature (e.g. different tool definitions for a linker for C vs. C++). - * + * * @return String[] */ public String[] getTargetToolList(); - + /** - * Returns the OutputTypes in this tool-chain, besides the primary - * output of the targetTool, that are also considered to be build - * artifacts. - * + * Returns the OutputTypes in this tool-chain, besides the primary + * output of the targetTool, that are also considered to be build + * artifacts. + * * @return IOutputType[] */ public IOutputType[] getSecondaryOutputs(); - + /** - * Sets the semicolon separated list of OutputType identifiers in + * Sets the semicolon separated list of OutputType identifiers in * this tool-chain, besides the primary output of the targetTool, - * that are also considered to be build artifacts. + * that are also considered to be build artifacts. */ public void setSecondaryOutputs(String ids); /** - * Returns true if this tool-chain has changes that need to + * Returns true if this tool-chain has changes that need to * be saved in the project file, else false. - * - * @return boolean + * + * @return boolean */ public boolean isDirty(); - + /** * Sets the element's "dirty" (have I been modified?) flag. */ public void setDirty(boolean isDirty); - + /** * Returns true if this tool-chain was loaded from a manifest file, * and false if it was loaded from a project (.cdtbuild) file. - * - * @return boolean + * + * @return boolean */ public boolean isExtensionElement(); - + /** * Returns true if the tool-chain support is installed on the system * otherwise returns false - * - * @return boolean - */ + * + * @return boolean + */ public boolean isSupported(); - + /** * Returns the tool-integrator provided implementation of the configuration environment variable supplier - * or null if none. - * + * or null if none. + * * @return IConfigurationEnvironmentVariableSupplier */ public IConfigurationEnvironmentVariableSupplier getEnvironmentVariableSupplier(); - + /** * Returns the tool-integrator provided implementation of the configuration build macro supplier - * or null if none. - * + * or null if none. + * * @return IConfigurationBuildMacroSupplier */ public IConfigurationBuildMacroSupplier getBuildMacroSupplier(); @@ -379,16 +382,16 @@ public interface IToolChain extends IBuildObject, IHoldsOptions { * or null, if no conversion is required */ public IOptionPathConverter getOptionPathConverter() ; - + IFolderInfo getParentFolderInfo(); - + CTargetPlatformData getTargetPlatformData(); - + boolean supportsBuild(boolean managed); - + boolean isSystemObject(); - + boolean matches(IToolChain tc); - + String getUniqueRealName(); } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/scannerconfig/ToolchainBuiltinSpecsDetector.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/scannerconfig/ToolchainBuiltinSpecsDetector.java index c8fb17ca9be..802f4551f7f 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/scannerconfig/ToolchainBuiltinSpecsDetector.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/scannerconfig/ToolchainBuiltinSpecsDetector.java @@ -21,6 +21,9 @@ import org.eclipse.cdt.managedbuilder.core.IToolChain; import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin; +/** + * @since 8.1 + */ public abstract class ToolchainBuiltinSpecsDetector extends AbstractBuiltinSpecsDetector { private Map toolMap = new HashMap(); /** @@ -33,7 +36,7 @@ public abstract class ToolchainBuiltinSpecsDetector extends AbstractBuiltinSpecs if (langTool != null) { return langTool; } - + String toolchainId = getToolchainId(); IToolChain toolchain = ManagedBuildManager.getExtensionToolChain(toolchainId); if (toolchain != null) { diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/MBSWizardHandler.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/MBSWizardHandler.java index d0b4433aa57..2968615327e 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/MBSWizardHandler.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/MBSWizardHandler.java @@ -94,6 +94,7 @@ public class MBSWizardHandler extends CWizardHandler { 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 = ";"; @@ -885,6 +886,9 @@ public class MBSWizardHandler extends CWizardHandler { return ""; } + /** + * @since 8.1 + */ public static List getLanguageSettingsProviders(IConfiguration cfg) { List providers = new ArrayList(); diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/NewMakeProjFromExistingPage.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/NewMakeProjFromExistingPage.java index 22a07ea68ba..2ac6b45746b 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/NewMakeProjFromExistingPage.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/NewMakeProjFromExistingPage.java @@ -53,7 +53,7 @@ public class NewMakeProjFromExistingPage extends WizardPage { IWorkspaceRoot root; List tcList; Map tcMap = new HashMap(); - + private Button checkBoxTryNewSD; @@ -233,6 +233,10 @@ public class NewMakeProjFromExistingPage extends WizardPage { return selection.length != 0 ? tcMap.get(selection[0]) : null; } + /** + * AG FIXME temporary method to be removed before CDT Juno release. + * @since 8.1 + */ public boolean isTryingNewSD() { return checkBoxTryNewSD.getSelection(); } diff --git a/core/org.eclipse.cdt.core/.settings/.api_filters b/core/org.eclipse.cdt.core/.settings/.api_filters new file mode 100644 index 00000000000..10c87060341 --- /dev/null +++ b/core/org.eclipse.cdt.core/.settings/.api_filters @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ICListenerAgent.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ICListenerAgent.java index 087992c1d21..ca5368fbf5b 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ICListenerAgent.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ICListenerAgent.java @@ -25,6 +25,8 @@ import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; * Implementers are to create a specific listener and register it to * appropriate event manager in {@link #registerListener(ICConfigurationDescription)} * then unregister and dispose in {@link #unregisterListener()}. + * + * @since 5.4 */ public interface ICListenerAgent { /** diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsBroadcastingProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsBroadcastingProvider.java index 68a1b95da54..143be533f12 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsBroadcastingProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsBroadcastingProvider.java @@ -19,6 +19,8 @@ import org.eclipse.core.resources.IResource; /** * This interface is to be implemented by providers which want to broadcast the changes in their setting entries * with {@link ILanguageSettingsChangeEvent}. + * + * @since 5.4 */ public interface ILanguageSettingsBroadcastingProvider extends ILanguageSettingsProvider { @Override diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsChangeEvent.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsChangeEvent.java index fca6b4a60ef..8bcb1046571 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsChangeEvent.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsChangeEvent.java @@ -28,6 +28,8 @@ import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; * * @noextend This interface is not intended to be extended by clients. * @noimplement This interface is not intended to be implemented by clients. + * + * @since 5.4 */ public interface ILanguageSettingsChangeEvent { /** diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsChangeListener.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsChangeListener.java index 2c3ca4c7886..4f5d5697efe 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsChangeListener.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsChangeListener.java @@ -17,6 +17,8 @@ import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; * * @see LanguageSettingsManager#registerLanguageSettingsChangeListener(ILanguageSettingsChangeListener) * @see LanguageSettingsManager#unregisterLanguageSettingsChangeListener(ILanguageSettingsChangeListener) + * + * @since 5.4 */ public interface ILanguageSettingsChangeListener { /** diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsEditableProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsEditableProvider.java index 3ba6e16d52c..fe282cb6360 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsEditableProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsEditableProvider.java @@ -22,6 +22,8 @@ import org.eclipse.core.resources.IResource; * contrary to some subclasses of {@link LanguageSettingsSerializableProvider} managing * their settings themselves and not providing such option to the user. * + * @since 5.4 + * */ public interface ILanguageSettingsEditableProvider extends ILanguageSettingsBroadcastingProvider, Cloneable { @Override diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsProvider.java index 1dee2448905..f60b313bd6e 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsProvider.java @@ -39,6 +39,8 @@ import org.eclipse.core.resources.IResource; * plugins {@code AbstractBuildCommandParser} and {@code AbstractBuiltinSpecsDetector} which * serve as a base for output parsers and built-in compiler language settings detectors. * See also extension point schema description LanguageSettingsProvider.exsd. + * + * @since 5.4 */ public interface ILanguageSettingsProvider { /** diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsProvidersKeeper.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsProvidersKeeper.java index 51dc65f05e5..c25e3922af6 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsProvidersKeeper.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ILanguageSettingsProvidersKeeper.java @@ -18,6 +18,8 @@ import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; * Providers. * @see ILanguageSettingsProvider * + * @since 5.4 + * */ public interface ILanguageSettingsProvidersKeeper { /** diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsBaseProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsBaseProvider.java index 21e2879b096..048523fc461 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsBaseProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsBaseProvider.java @@ -29,6 +29,8 @@ import org.eclipse.core.resources.IResource; * * This implementation supports "static" list of entries for languages specified in * the extension point. + * + * @since 5.4 */ public class LanguageSettingsBaseProvider extends AbstractExecutableExtensionBase implements ILanguageSettingsProvider { /** Language scope, i.e. list of languages the entries will be provided for. */ diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsGenericProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsGenericProvider.java index 8a7e8db180c..74f2bfc12ce 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsGenericProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsGenericProvider.java @@ -16,6 +16,8 @@ package org.eclipse.cdt.core.language.settings.providers; * The instances of this class can be used in plugin.xml to create a new provider * but this class is not intended to be extended. For more details how to create a * language settings provider see the description of {@link ILanguageSettingsProvider}. + * + * @since 5.4 */ final public class LanguageSettingsGenericProvider extends LanguageSettingsSerializableProvider implements ILanguageSettingsEditableProvider { diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java index 4aa43ae7290..64554799e38 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java @@ -34,6 +34,8 @@ import org.eclipse.core.runtime.IPath; /** * A collection of utility methods to manage language settings providers. * See {@link ILanguageSettingsProvider}. + * + * @since 5.4 */ public class LanguageSettingsManager { /** diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableProvider.java index 936429c73e1..577de48e4a7 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableProvider.java @@ -38,6 +38,8 @@ import org.w3c.dom.NodeList; * design. Implement {@link ILanguageSettingsEditableProvider} interface for that. * For more on the suggested way of extending this class see the description of * {@link ILanguageSettingsProvider}. + * + * @since 5.4 */ public class LanguageSettingsSerializableProvider extends LanguageSettingsBaseProvider implements ILanguageSettingsBroadcastingProvider { protected static final String ATTR_ID = LanguageSettingsProvidersSerializer.ATTR_ID; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsStorage.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsStorage.java index 7ed56cb75ae..72f72333e41 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsStorage.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsStorage.java @@ -25,6 +25,8 @@ import org.eclipse.cdt.internal.core.parser.util.WeakHashSet; /** * The class representing the (in-memory) storage for language settings entries {@link ICLanguageSettingEntry}. + * + * @since 5.4 */ public class LanguageSettingsStorage implements Cloneable { /** Storage to keep settings entries. */ diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ScannerDiscoveryLegacySupport.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ScannerDiscoveryLegacySupport.java index 610db25b207..730c311e2e5 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ScannerDiscoveryLegacySupport.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ScannerDiscoveryLegacySupport.java @@ -29,6 +29,8 @@ import org.osgi.service.prefs.Preferences; * * @noextend This class is not intended to be subclassed by clients. * @noinstantiate This class is not intended to be instantiated by clients. + * + * @since 5.4 */ public class ScannerDiscoveryLegacySupport { /** Name of MBS language settings provider (from org.eclipse.cdt.managedbuilder.core) */ diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ACExclusionFilterEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ACExclusionFilterEntry.java index e6db0464024..fb5909ff556 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ACExclusionFilterEntry.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ACExclusionFilterEntry.java @@ -36,7 +36,9 @@ public abstract class ACExclusionFilterEntry extends ACPathEntry implements ICEx this.exclusionPatterns = exclusionPatterns != null ? (IPath[])exclusionPatterns.clone() : new IPath[0]; } - /** @since 5.3 */ + /** + * @since 5.4 + */ @Override public final boolean isFile() { return false; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ACPathEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ACPathEntry.java index 4fbb27a953c..bf67bc52176 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ACPathEntry.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ACPathEntry.java @@ -66,9 +66,9 @@ public abstract class ACPathEntry extends ACSettingEntry implements ICPathEntry return rcs[0].getFullPath(); return null; } - + /** - * @since 5.3 + * @since 5.4 */ public abstract boolean isFile(); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICDescriptionDelta.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICDescriptionDelta.java index 11172d5d99d..a38e6595eca 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICDescriptionDelta.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICDescriptionDelta.java @@ -10,7 +10,10 @@ *******************************************************************************/ package org.eclipse.cdt.core.settings.model; - +/** + * @noextend This interface is not intended to be extended by clients. + * @noimplement This interface is not intended to be implemented by clients. + */ public interface ICDescriptionDelta { /* * delta kinds @@ -18,8 +21,8 @@ public interface ICDescriptionDelta { /** * kind specifying that the setting object returned by * the {@link #getSetting()} was removed - * the {@link #getNewSetting()} returns null - * the {@link #getOldSetting()} returns the same object as {@link #getSetting()} + * the {@link #getNewSetting()} returns null + * the {@link #getOldSetting()} returns the same object as {@link #getSetting()} */ int REMOVED = 1; @@ -27,28 +30,29 @@ public interface ICDescriptionDelta { * kind specifying that the setting object returned by * the {@link #getSetting()} was added * the {@link #getNewSetting()} returns the same object as {@link #getSetting()} - * the {@link #getOldSetting()} returns null + * the {@link #getOldSetting()} returns null */ int ADDED = 2; /** * kind specifying that the setting object was changed - * the {@link #getNewSetting()} returns new object - * the {@link #getOldSetting()} returns old object + * the {@link #getNewSetting()} returns new object + * the {@link #getOldSetting()} returns old object * the {@link #getSetting()} returns the same object as {@link #getNewSetting()} */ int CHANGED = 3; - + /* * delta change flags */ - + int ACTIVE_CFG = 1; int NAME = 1 << 1; int DESCRIPTION = 1 << 2; // int PATH = 1 << 3; int LANGUAGE_ID = 1 << 4; int SOURCE_CONTENT_TYPE = 1 << 5; + /** @since 5.4 */ int SOURCE_EXTENSIONS = 1 << 6; /** @deprecated Use ICDescriptionDelta.SOURCE_EXTENSIONS */ @Deprecated @@ -69,18 +73,19 @@ public interface ICDescriptionDelta { int OWNER = 1 << 20; int INDEX_CFG = 1 << 21; int SETTING_CFG = INDEX_CFG; + /** @since 5.4 */ int LANGUAGE_SETTINGS_PROVIDERS = 1 << 22; - + /** * specifies that the project "isCdtProjectCreating" state was set to false * the PROJECT_CREAION_COMPLETED delta gets notified ONLY in case - * the project previously contained the project description with + * the project previously contained the project description with * the true "isCdtProjectCreating" state - * + * * in case the initial project description does NOT contain the true "isCdtProjectCreating" - * the project is considered as initialized from the very beginning + * the project is considered as initialized from the very beginning * and the PROJECT_CREAION_COMPLETED delta is NOT notified - * + * * @see ICProjectDescription#isCdtProjectCreating() * @see ICProjectDescription#setCdtProjectCreated() * @see ICProjectDescriptionManager#createProjectDescription(org.eclipse.core.resources.IProject, boolean, boolean) @@ -89,19 +94,19 @@ public interface ICDescriptionDelta { /** * returns the kind - * @see #ADDED - * @see #REMOVED + * @see #ADDED + * @see #REMOVED * @see #CHANGED - * + * * @return int */ int getDeltaKind(); - + /** * @return ored delta flags */ int getChangeFlags(); - + int getSettingType(); int getAddedEntriesKinds(); @@ -115,8 +120,8 @@ public interface ICDescriptionDelta { ICSettingObject getNewSetting(); ICSettingObject getSetting(); - + ICSettingObject getOldSetting(); - + ICDescriptionDelta getParent(); } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICSettingEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICSettingEntry.java index 4cef66d3750..af776d96bc0 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICSettingEntry.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICSettingEntry.java @@ -12,6 +12,10 @@ package org.eclipse.cdt.core.settings.model; import org.eclipse.cdt.core.model.IIncludeEntry; +/** + * @noextend This interface is not intended to be extended by clients. + * @noimplement This interface is not intended to be implemented by clients. + */ public interface ICSettingEntry { /** * Flag {@code BUILTIN} indicates settings built in a tool (compiler) itself. @@ -49,15 +53,16 @@ public interface ICSettingEntry { /** * Flag {@code UNDEFINED} indicates that the entry should not be defined. * It's main purpose to provide the means to negate entries defined elsewhere. - * - * @since 6.0 + * + * @since 5.4 */ int UNDEFINED = 1 << 5; /** * Flag {@code FRAMEWORKS_MAC} applies for path entries. Such a path entry will be treated * in a special way to imitate resolving paths by Apple's version of gcc, see bug 69529. - * . + * + * @since 5.4 */ int FRAMEWORKS_MAC = 1 << 6; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/LanguageSettingEntriesSerializer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/LanguageSettingEntriesSerializer.java index 7047e40fd55..150b01a967b 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/LanguageSettingEntriesSerializer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/LanguageSettingEntriesSerializer.java @@ -40,10 +40,10 @@ public class LanguageSettingEntriesSerializer { public static final String ATTRIBUTE_SOURCE_ATTACHMENT_PATH = "srcPath"; //$NON-NLS-1$ public static final String ATTRIBUTE_SOURCE_ATTACHMENT_ROOT_PATH = "srcRootPath"; //$NON-NLS-1$ public static final String ATTRIBUTE_SOURCE_ATTACHMENT_PREFIX_MAPPING = "srcPrefixMapping"; //$NON-NLS-1$ - + // public static final String ATTRIBUTE_FULL_PATH = "fullPath"; //$NON-NLS-1$ // public static final String ATTRIBUTE_LOCATION = "location"; //$NON-NLS-1$ - + public static final String INCLUDE_PATH = "includePath"; //$NON-NLS-1$ public static final String INCLUDE_FILE = "includeFile"; //$NON-NLS-1$ @@ -61,7 +61,7 @@ public class LanguageSettingEntriesSerializer { public static final String RESOLVED = "RESOLVED"; //$NON-NLS-1$ private static final String UNDEFINED = "UNDEFINED"; //$NON-NLS-1$ private static final String FRAMEWORK = "FRAMEWORK"; //$NON-NLS-1$ - + public static final String FLAGS_SEPARATOR = "|"; //$NON-NLS-1$ public static ICSettingEntry[] loadEntries(ICStorageElement el){ @@ -86,7 +86,7 @@ public class LanguageSettingEntriesSerializer { child = children[i]; if(ELEMENT_ENTRY.equals(child.getName())){ entry = loadEntry(child); - if(entry != null + if(entry != null && (kindFilter == 0 || (kindFilter & entry.getKind()) != 0)) list.add(entry); @@ -99,11 +99,11 @@ public class LanguageSettingEntriesSerializer { int kind = stringToKind(el.getAttribute(ATTRIBUTE_KIND)); if(kind == 0) return null; - + int flags = composeFlags(el.getAttribute(ATTRIBUTE_FLAGS)); String name = el.getAttribute(ATTRIBUTE_NAME); - + switch(kind){ case ICLanguageSettingEntry.INCLUDE_PATH: return new CIncludePathEntry(name, flags); @@ -128,7 +128,7 @@ public class LanguageSettingEntriesSerializer { } return null; } - + private static IPath loadPath(ICStorageElement el, String attr){ String value = el.getAttribute(attr); if(value != null) @@ -151,18 +151,18 @@ public class LanguageSettingEntriesSerializer { } return paths; } - return null; + return null; } private static void storeExclusions(ICStorageElement el, IPath[] paths){ if(paths == null || paths.length == 0) return; - + String[] strs = new String[paths.length]; for(int i = 0; i < strs.length; i++){ strs[i] = paths[i].toString(); } - + String attr = CDataUtil.arrayToString(strs, FLAGS_SEPARATOR); el.setAttribute(ATTRIBUTE_EXCLUDING, attr); } @@ -176,7 +176,7 @@ public class LanguageSettingEntriesSerializer { } } } - + public static void serializeEntry(ICSettingEntry entry, ICStorageElement element){ String kind = kindToString(entry.getKind()); String flags = composeFlagsString(entry.getFlags()); @@ -199,7 +199,7 @@ public class LanguageSettingEntriesSerializer { IPath path = libFile.getSourceAttachmentPath(); if(path != null) element.setAttribute(ATTRIBUTE_SOURCE_ATTACHMENT_PATH, path.toString()); - + path = libFile.getSourceAttachmentRootPath(); if(path != null) element.setAttribute(ATTRIBUTE_SOURCE_ATTACHMENT_ROOT_PATH, path.toString()); @@ -209,7 +209,7 @@ public class LanguageSettingEntriesSerializer { element.setAttribute(ATTRIBUTE_SOURCE_ATTACHMENT_PREFIX_MAPPING, path.toString()); } } - + public static String kindToString(int kind){ switch(kind){ case ICLanguageSettingEntry.INCLUDE_PATH: @@ -261,25 +261,25 @@ public class LanguageSettingEntriesSerializer { if((flags & ICLanguageSettingEntry.READONLY) != 0){ if(buf.length() != 0) buf.append(FLAGS_SEPARATOR); - + buf.append(READONLY); } if((flags & ICLanguageSettingEntry.LOCAL) != 0){ if(buf.length() != 0) buf.append(FLAGS_SEPARATOR); - + buf.append(LOCAL); } if((flags & ICLanguageSettingEntry.VALUE_WORKSPACE_PATH) != 0){ if(buf.length() != 0) buf.append(FLAGS_SEPARATOR); - + buf.append(VALUE_WORKSPACE_PATH); } if((flags & ICLanguageSettingEntry.RESOLVED) != 0){ if(buf.length() != 0) buf.append(FLAGS_SEPARATOR); - + buf.append(RESOLVED); } if((flags & ICLanguageSettingEntry.UNDEFINED) != 0){ @@ -291,37 +291,40 @@ public class LanguageSettingEntriesSerializer { if((flags & ICLanguageSettingEntry.FRAMEWORKS_MAC) != 0){ if(buf.length() != 0) buf.append(FLAGS_SEPARATOR); - + buf.append(FRAMEWORK); } return buf.toString(); } - + + /** + * @since 5.4 + */ public static int composeFlags(String flagsString){ if(flagsString == null || flagsString.length() == 0) return 0; - + StringTokenizer tokenizer = new StringTokenizer(flagsString, FLAGS_SEPARATOR); int flags = 0; String f; while(tokenizer.hasMoreElements()){ f = tokenizer.nextToken(); if(BUILTIN.equals(f)) - flags |= ICLanguageSettingEntry.BUILTIN; + flags |= ICLanguageSettingEntry.BUILTIN; if(READONLY.equals(f)) - flags |= ICLanguageSettingEntry.READONLY; + flags |= ICLanguageSettingEntry.READONLY; if(LOCAL.equals(f)) - flags |= ICLanguageSettingEntry.LOCAL; + flags |= ICLanguageSettingEntry.LOCAL; if(VALUE_WORKSPACE_PATH.equals(f)) - flags |= ICLanguageSettingEntry.VALUE_WORKSPACE_PATH; + flags |= ICLanguageSettingEntry.VALUE_WORKSPACE_PATH; if(RESOLVED.equals(f)) - flags |= ICLanguageSettingEntry.RESOLVED; + flags |= ICLanguageSettingEntry.RESOLVED; if(UNDEFINED.equals(f)) flags |= ICLanguageSettingEntry.UNDEFINED; if(FRAMEWORK.equals(f)) flags |= ICLanguageSettingEntry.FRAMEWORKS_MAC; } - + return flags; } diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/AbstractExecutableExtensionBase.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/AbstractExecutableExtensionBase.java index f371e85d1d0..0da0d9629ca 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/AbstractExecutableExtensionBase.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/AbstractExecutableExtensionBase.java @@ -15,6 +15,8 @@ package org.eclipse.cdt.core; * Helper abstract class serving as a base for creating a frame of executable class * defined as an extension in plugin.xml. * + * @since 5.4 + * */ public abstract class AbstractExecutableExtensionBase { private String fId; diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java index 83100d58ca2..1fc3c62b8c5 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java @@ -529,6 +529,8 @@ public class CCorePlugin extends Plugin { * * * @return CDT console adapter. + * + * @since 5.4 */ public IConsole getConsole(String extConsoleId, String contextId, String name, URL iconUrl) { try { diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICConsoleParser.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICConsoleParser.java index 44b216124bc..dd55807a4f8 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICConsoleParser.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICConsoleParser.java @@ -19,6 +19,8 @@ import org.eclipse.core.runtime.CoreException; * can be without configurations, in that case IProject should be passed * to startup somehow. Perhaps another interface "IPConsoleParser" could * be created when needed? + * + * @since 5.4 */ public interface ICConsoleParser extends IConsoleParser { public void startup(ICConfigurationDescription cfgDescription) throws CoreException; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CDTSharedImages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CDTSharedImages.java index 95c5d4618d5..7460041ac4a 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CDTSharedImages.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CDTSharedImages.java @@ -47,7 +47,7 @@ import org.eclipse.swt.graphics.Image; * * @noextend This class is not intended to be subclassed by clients. * @noinstantiate This class is not intended to be instantiated by clients. - * + * * @since 5.3 */ public class CDTSharedImages { @@ -116,6 +116,7 @@ public class CDTSharedImages { public static final String IMG_OBJS_INCLUDES_FOLDER_WORKSPACE = "icons/obj16/wsp_includefolder.gif"; //$NON-NLS-1$ public static final String IMG_OBJS_QUOTE_INCLUDES_FOLDER = "icons/obj16/hfolder_quote_obj.gif"; //$NON-NLS-1$ public static final String IMG_OBJS_INCLUDES_FOLDER_SYSTEM = "icons/obj16/fldr_sys_obj.gif"; //$NON-NLS-1$ + /** @since 5.4 */ public static final String IMG_OBJS_FRAMEWORKS_FOLDER = "icons/obj16/frameworks.gif"; //$NON-NLS-1$ public static final String IMG_OBJS_MACROS_FILE= "icons/obj16/macros_file.gif"; //$NON-NLS-1$ public static final String IMG_OBJS_LIBRARY_FOLDER= "icons/obj16/fldr_lib_obj.gif"; // $NON-NLS-1$ //$NON-NLS-1$ @@ -185,21 +186,21 @@ public class CDTSharedImages { public static final String IMG_OVR_ERROR = "icons/ovr16/error_co.gif"; //$NON-NLS-1$ public static final String IMG_OVR_SETTING = "icons/ovr16/setting_nav.gif"; //$NON-NLS-1$ public static final String IMG_OVR_INACTIVE = "icons/ovr16/inactive_co.gif"; //$NON-NLS-1$ - + // Pin & Clone public static final String IMG_THREAD_SUSPENDED_R_PINNED = "icons/obj16/threads_obj_r.gif"; //$NON-NLS-1$ public static final String IMG_THREAD_SUSPENDED_G_PINNED = "icons/obj16/threads_obj_g.gif"; //$NON-NLS-1$ public static final String IMG_THREAD_SUSPENDED_B_PINNED = "icons/obj16/threads_obj_b.gif"; //$NON-NLS-1$ - + public static final String IMG_THREAD_RUNNING_R_PINNED = "icons/obj16/thread_obj_r.gif"; //$NON-NLS-1$ public static final String IMG_THREAD_RUNNING_G_PINNED = "icons/obj16/thread_obj_g.gif"; //$NON-NLS-1$ - public static final String IMG_THREAD_RUNNING_B_PINNED = "icons/obj16/thread_obj_b.gif"; //$NON-NLS-1$ - + public static final String IMG_THREAD_RUNNING_B_PINNED = "icons/obj16/thread_obj_b.gif"; //$NON-NLS-1$ + public static final String IMG_CONTAINER_SUSPENDED_R_PINNED = "icons/obj16/debugts_obj_r.gif"; //$NON-NLS-1$ public static final String IMG_CONTAINER_SUSPENDED_G_PINNED = "icons/obj16/debugts_obj_g.gif"; //$NON-NLS-1$ public static final String IMG_CONTAINER_SUSPENDED_B_PINNED = "icons/obj16/debugts_obj_b.gif"; //$NON-NLS-1$ - - public static final String IMG_CONTAINER_RUNNING_R_PINNED = "icons/obj16/debugt_obj_r.gif"; //$NON-NLS-1$ + + public static final String IMG_CONTAINER_RUNNING_R_PINNED = "icons/obj16/debugt_obj_r.gif"; //$NON-NLS-1$ public static final String IMG_CONTAINER_RUNNING_G_PINNED = "icons/obj16/debugt_obj_g.gif"; //$NON-NLS-1$ public static final String IMG_CONTAINER_RUNNING_B_PINNED = "icons/obj16/debugt_obj_b.gif"; //$NON-NLS-1$ @@ -210,20 +211,34 @@ public class CDTSharedImages { public static final String IMG_VIEW_PIN_ACTION_MULTI = "icons/obj16/toolbar_pinned_multi.gif"; //$NON-NLS-1$ // Language Settings Images + /** @since 5.4 */ public static final String IMG_OBJS_LANG_SETTINGS_PROVIDER = "icons/obj16/ls_entries_provider.gif"; //$NON-NLS-1$ + /** @since 5.4 */ public static final String IMG_ETOOL_PROJECT = "icons/etool16/prj_obj.gif"; //$NON-NLS-1$ + /** @since 5.4 */ public static final String IMG_OVR_GLOBAL = "icons/ovr16/global_ovr.gif"; //$NON-NLS-1$ + /** @since 5.4 */ public static final String IMG_OVR_IMPORT = "icons/ovr16/import_co.gif"; //$NON-NLS-1$ + /** @since 5.4 */ public static final String IMG_OVR_LINK = "icons/ovr16/link_ovr.gif"; //$NON-NLS-1$ + /** @since 5.4 */ public static final String IMG_OVR_CONFIGURATION = "icons/ovr16/cfg_ovr.gif"; //$NON-NLS-1$ + /** @since 5.4 */ public static final String IMG_OVR_PARENT = "icons/ovr16/path_inherit_co.gif"; //$NON-NLS-1$ + /** @since 5.4 */ public static final String IMG_OVR_INDEXED = "icons/ovr16/indexedFile.gif"; //$NON-NLS-1$ + /** @since 5.4 */ public static final String IMG_OVR_REFERENCE = "icons/ovr16/referencedby_co.gif"; //$NON-NLS-1$ + /** @since 5.4 */ public static final String IMG_OVR_PROJECT = "icons/ovr16/project_co.gif"; //$NON-NLS-1$ + /** @since 5.4 */ public static final String IMG_OVR_CONTEXT = "icons/ovr16/overlay-has-context.gif"; //$NON-NLS-1$ + /** @since 5.4 */ public static final String IMG_OVR_LOCK = "icons/ovr16/lock_ovr.gif"; //$NON-NLS-1$ + /** @since 5.4 */ public static final String IMG_OVR_EDITED = "icons/ovr16/edited_ov.gif"; //$NON-NLS-1$ + /** @since 5.4 */ public static final String IMG_OVR_EMPTY = "icons/ovr16/empty_ovr.png"; //$NON-NLS-1$ /** diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/AbstractCPropertyTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/AbstractCPropertyTab.java index 412011c2196..ddd9791406d 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/AbstractCPropertyTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/AbstractCPropertyTab.java @@ -64,71 +64,72 @@ import org.eclipse.cdt.internal.ui.dialogs.StatusInfo; import org.eclipse.cdt.internal.ui.newui.Messages; /** - * It is a parent for all standard property tabs + * It is a parent for all standard property tabs * in new CDT model. - * + * * Although it's enough for new tabs to implement - * ICPropertyTab interface only, it would be better + * ICPropertyTab interface only, it would be better * to extend them from this class. * * In this case, we'll able to use: * - a lot of utility methods via "provider" link. * In particular, it allows to get current project, - * configuration etc. See ICPropertyProvider interface. + * configuration etc. See ICPropertyProvider interface. * - a standard way to create buttons (ins/edit/del etc) * and to handle their events (see buttonPressed(int)) * - several utility methods to create widgets in the - * uniform manner (setupLabel(), setupText() etc). + * uniform manner (setupLabel(), setupText() etc). * - means to handle control messages which are the main - * communication way for new CDT model pages and tabs. + * communication way for new CDT model pages and tabs. */ public abstract class AbstractCPropertyTab implements ICPropertyTab { - + public static final Method GRAY_METHOD = getGrayEnabled(); public static final int BUTTON_WIDTH = 120; // used as hint for all push buttons // commonly used button names public static final String EMPTY_STR = ""; //$NON-NLS-1$ - public static final String ADD_STR = Messages.FileListControl_add; - public static final String DEL_STR = Messages.FileListControl_delete; - public static final String EDIT_STR = Messages.FileListControl_edit; - public static final String MOVEUP_STR = Messages.FileListControl_moveup; - public static final String MOVEDOWN_STR = Messages.FileListControl_movedown; - public static final String PROJECTBUTTON_NAME = "Project..."; - public static final String WORKSPACEBUTTON_NAME = Messages.FileListControl_button_workspace; - public static final String FILESYSTEMBUTTON_NAME = Messages.FileListControl_button_fs; - public static final String VARIABLESBUTTON_NAME = Messages.AbstractCPropertyTab_1; - public static final String FILESYSTEM_DIR_DIALOG_MSG = Messages.BrowseEntryDialog_fs_dir_dlg_msg; - public static final String FILESYSTEM_FILE_DIALOG_TITLE = EMPTY_STR; - public static final String WORKSPACE_DIR_DIALOG_TITLE = Messages.BrowseEntryDialog_wsp_dir_dlg_title; - public static final String WORKSPACE_FILE_DIALOG_TITLE = Messages.BrowseEntryDialog_wsp_file_dlg_title; - public static final String WORKSPACE_DIR_DIALOG_MSG = Messages.BrowseEntryDialog_wsp_dir_dlg_msg; - public static final String WORKSPACE_FILE_DIALOG_MSG = Messages.BrowseEntryDialog_wsp_file_dlg_msg; - public static final String WORKSPACE_FILE_DIALOG_ERR = Messages.BrowseEntryDialog_wsp_file_dlg_err; - public static final String WORKSPACE_DIR_DIALOG_ERR = Messages.BrowseEntryDialog_wsp_dir_dlg_err; - public static final String BACKGROUND_TEXT_DEFAULT = Messages.AbstractCPropertyTab_2; + public static final String ADD_STR = Messages.FileListControl_add; + public static final String DEL_STR = Messages.FileListControl_delete; + public static final String EDIT_STR = Messages.FileListControl_edit; + public static final String MOVEUP_STR = Messages.FileListControl_moveup; + public static final String MOVEDOWN_STR = Messages.FileListControl_movedown; + /** @since 5.4 */ + public static final String PROJECTBUTTON_NAME = "Project..."; + public static final String WORKSPACEBUTTON_NAME = Messages.FileListControl_button_workspace; + public static final String FILESYSTEMBUTTON_NAME = Messages.FileListControl_button_fs; + public static final String VARIABLESBUTTON_NAME = Messages.AbstractCPropertyTab_1; + public static final String FILESYSTEM_DIR_DIALOG_MSG = Messages.BrowseEntryDialog_fs_dir_dlg_msg; + public static final String FILESYSTEM_FILE_DIALOG_TITLE = EMPTY_STR; + public static final String WORKSPACE_DIR_DIALOG_TITLE = Messages.BrowseEntryDialog_wsp_dir_dlg_title; + public static final String WORKSPACE_FILE_DIALOG_TITLE = Messages.BrowseEntryDialog_wsp_file_dlg_title; + public static final String WORKSPACE_DIR_DIALOG_MSG = Messages.BrowseEntryDialog_wsp_dir_dlg_msg; + public static final String WORKSPACE_FILE_DIALOG_MSG = Messages.BrowseEntryDialog_wsp_file_dlg_msg; + public static final String WORKSPACE_FILE_DIALOG_ERR = Messages.BrowseEntryDialog_wsp_file_dlg_err; + public static final String WORKSPACE_DIR_DIALOG_ERR = Messages.BrowseEntryDialog_wsp_dir_dlg_err; + public static final String BACKGROUND_TEXT_DEFAULT = Messages.AbstractCPropertyTab_2; public static final Color BACKGROUND_FOR_USER_VAR = new Color(Display.getDefault(), 255, 255, 200); // light yellow private static final String PREFIX = "org.eclipse.cdt.ui."; //$NON-NLS-1$ - + public static final int TRI_UNKNOWN = 2; public static final int TRI_YES = 1; public static final int TRI_NO = 0; protected static final String ENUM = "enum"; //$NON-NLS-1$ protected static final String SSET = "set"; //$NON-NLS-1$ - + private PageBook pageBook; // to select between background and usercomp. private CLabel background; private Composite userdata; - - protected Composite usercomp; // space where user can create widgets + + protected Composite usercomp; // space where user can create widgets protected Composite buttoncomp; // space for buttons on the right private Button[] buttons; // buttons in buttoncomp public ICPropertyProvider page; - protected Image icon = null; - private String helpId = EMPTY_STR; - + protected Image icon = null; + private String helpId = EMPTY_STR; + protected boolean visible; @Override @@ -140,8 +141,8 @@ public abstract class AbstractCPropertyTab implements ICPropertyTab { /** * Creates basic widgets for property tab. * Descendants should, normally, override - * this method but call super.createControls(). - * + * this method but call super.createControls(). + * * @param parent */ protected void createControls(Composite parent) { @@ -154,27 +155,27 @@ public abstract class AbstractCPropertyTab implements ICPropertyTab { GridData gd; userdata= new Composite(pageBook, SWT.NONE); userdata.setLayout(new GridLayout(2, false)); - + usercomp = new Composite(userdata, SWT.NONE); usercomp.setLayoutData(gd= new GridData(GridData.FILL_BOTH)); gd.widthHint= 150; - + buttoncomp = new Composite(userdata, SWT.NONE); buttoncomp.setLayoutData(gd= new GridData(GridData.END)); // width hint must be set to one, otherwise subclasses that do not have buttons // don't look pretty, bug 242408 gd.widthHint= 1; - + pageBook.showPage(userdata); - + PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, helpId); } - + /** * The common way to create buttons cluster * on the right of tab workspace. * @param names : array of button names - * null instead of name means "skip place" + * null instead of name means "skip place" */ protected void initButtons(String[] names) { initButtons(buttoncomp, names, 80); @@ -182,7 +183,7 @@ public abstract class AbstractCPropertyTab implements ICPropertyTab { protected void initButtons(String[] names, int width) { initButtons(buttoncomp, names, width); } - + /** * Ability to create standard button on any composite. * @param c @@ -202,15 +203,15 @@ public abstract class AbstractCPropertyTab implements ICPropertyTab { gdb.grabExcessHorizontalSpace = false; gdb.horizontalAlignment = SWT.FILL; gdb.minimumWidth = width; - + if (names[i] != null) buttons[i].setText(names[i]); - else { // no button, but placeholder ! + else { // no button, but placeholder ! buttons[i].setVisible(false); buttons[i].setEnabled(false); gdb.heightHint = 10; } - + buttons[i].setLayoutData(gdb); buttons[i].addSelectionListener(new SelectionAdapter() { @Override @@ -220,15 +221,15 @@ public abstract class AbstractCPropertyTab implements ICPropertyTab { }); } } - + /** - * Called when user changes + * Called when user changes * @param cfg - selected configuration */ private void configChanged(ICResourceDescription cfg) { if (visible) updateData(cfg); } - + /** * Disposes the SWT resources allocated by this dialog page. */ @@ -245,13 +246,13 @@ public abstract class AbstractCPropertyTab implements ICPropertyTab { visible = _visible; if (visible) updateData(page.getResDesc()); } - + /** - * Descendant tabs should implement this method so - * that it copies it's data from one description + * Descendant tabs should implement this method so + * that it copies it's data from one description * to another. Only data affected by given tab * should be copied. - * + * * @param src * @param dst */ @@ -273,32 +274,32 @@ public abstract class AbstractCPropertyTab implements ICPropertyTab { } } } - + /** - * Method should be rewritten to handle button presses + * Method should be rewritten to handle button presses * @param i : number of button pressed - * - * Does nothing by default. + * + * Does nothing by default. * May (but not must) be overridden. */ protected void buttonPressed(int i) {} - + /** * Checks state of existing button. - * + * * @param i - button index - * @return - true if button exists and enabled + * @return - true if button exists and enabled */ protected boolean buttonIsEnabled(int i) { - if (buttons == null || buttons.length <= i ) + if (buttons == null || buttons.length <= i ) return false; return buttons[i].isEnabled(); } - + /** * Changes state of existing button. * Does nothing if index is invalid - * + * * @param i - button index * @param state - required state */ @@ -306,11 +307,11 @@ public abstract class AbstractCPropertyTab implements ICPropertyTab { if (buttons == null || buttons.length <= i ) return; buttons[i].setEnabled(state); } - + /** * Changes text of existing button * Does nothing if index is invalid - * + * * @param i - button index * @param text - text to display */ @@ -346,13 +347,13 @@ public abstract class AbstractCPropertyTab implements ICPropertyTab { b.setLayoutData(g); return b; } - + protected Text setupText(Composite c, int span, int mode) { Text t = new Text(c, SWT.SINGLE | SWT.BORDER); setupControl(t, span, mode); return t; } - + protected Group setupGroup(Composite c, String name, int cols, int mode) { Group g = new Group(c, SWT.NONE); g.setText(name); @@ -360,7 +361,7 @@ public abstract class AbstractCPropertyTab implements ICPropertyTab { setupControl(g, 1, mode); return g; } - + protected Button setupCheck(Composite c, String name, int span, int mode) { Button b = new Button(c, SWT.CHECK); b.setText(name); @@ -376,23 +377,23 @@ public abstract class AbstractCPropertyTab implements ICPropertyTab { } /** - * Selection handler for checkbox created - * by methods "setupCheck()" or "setupTri()" - * Descendants should override this method - * if they use "setupCheck". + * Selection handler for checkbox created + * by methods "setupCheck()" or "setupTri()" + * Descendants should override this method + * if they use "setupCheck". * Usually the method body will look like: - * { + * { * Control b = (Control)e.widget; - * if (b.equals(myFirstCheckbox) { ... } + * if (b.equals(myFirstCheckbox) { ... } * else if (b.equals(mySecondCheckbox) { ... } - * ... } + * ... } */ protected void checkPressed(SelectionEvent e) { } protected void setupControl(Control c, int span, int mode) { // although we use GridLayout usually, - // exceptions can occur: do nothing. + // exceptions can occur: do nothing. if (c != null) { if (span != 0) { GridData gd = new GridData(mode); @@ -403,11 +404,11 @@ public abstract class AbstractCPropertyTab implements ICPropertyTab { c.setFont(p.getFont()); } } - + /* - * A set of methods providing selection dialogs for files or dirs. + * A set of methods providing selection dialogs for files or dirs. */ - + public static String getFileSystemDirDialog(Shell shell, String text) { DirectoryDialog dialog = new DirectoryDialog(shell, SWT.OPEN|SWT.APPLICATION_MODAL); if(text != null && text.trim().length() != 0) dialog.setFilterPath(text); @@ -432,12 +433,12 @@ public abstract class AbstractCPropertyTab implements ICPropertyTab { dialog.setText(FILESYSTEM_FILE_DIALOG_TITLE); return dialog.open(); } - + public static String getVariableDialog(Shell shell, ICConfigurationDescription cfgd) { - + ICdtVariableManager vm = CCorePlugin.getDefault().getCdtVariableManager(); BuildVarListDialog dialog = new BuildVarListDialog(shell, vm.getVariables(cfgd)); - dialog.setTitle(Messages.AbstractCPropertyTab_0); + dialog.setTitle(Messages.AbstractCPropertyTab_0); if (dialog.open() == Window.OK) { Object[] selected = dialog.getResult(); if (selected.length > 0) { @@ -454,13 +455,19 @@ public abstract class AbstractCPropertyTab implements ICPropertyTab { public static String getWorkspaceFileDialog(Shell shell, String text) { return getWorkspaceDialog(shell, text, false, null); } + /** + * @since 5.4 + */ public static String getProjectDirDialog(Shell shell, String text, IProject prj) { return getWorkspaceDialog(shell, text, true, prj); } + /** + * @since 5.4 + */ public static String getProjectFileDialog(Shell shell, String text, IProject prj) { return getWorkspaceDialog(shell, text, false, prj); } - + private static String getWorkspaceDialog(Shell shell, String text, boolean dir, IProject prj) { String currentPathText; IPath path; @@ -468,7 +475,7 @@ public abstract class AbstractCPropertyTab implements ICPropertyTab { /* Remove double quotes */ currentPathText = currentPathText.replaceAll("\"", ""); //$NON-NLS-1$ //$NON-NLS-2$ path = new Path(currentPathText); - + ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(shell, new WorkbenchLabelProvider(), new WorkbenchContentProvider()); @@ -477,7 +484,7 @@ public abstract class AbstractCPropertyTab implements ICPropertyTab { else dialog.setInput(prj); dialog.setComparator(new ResourceComparator(ResourceComparator.NAME)); - + if (dir) { IResource container = null; if(path.isAbsolute()){ @@ -519,14 +526,14 @@ public abstract class AbstractCPropertyTab implements ICPropertyTab { } if (dialog.open() == Window.OK) { IResource resource = (IResource) dialog.getFirstResult(); - if (resource != null) { + if (resource != null) { StringBuffer buf = new StringBuffer(); return buf.append("${").append("workspace_loc:").append(resource.getFullPath()).append("}").toString(); //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$ } } return null; } - + // shortcut to frequently-used method public ICResourceDescription getResDesc() { return page.getResDesc(); @@ -560,19 +567,19 @@ public abstract class AbstractCPropertyTab implements ICPropertyTab { dispose(); break; case ICPropertyTab.VISIBLE: - if (canBeVisible()) + if (canBeVisible()) setVisible(data != null); - else + else setVisible(false); break; case ICPropertyTab.SET_ICON: - icon = (Image)data; + icon = (Image)data; break; default: break; } } - + // By default, returns true (no visibility restriction) // But several pages should rewrite this functionality. @Override @@ -594,20 +601,20 @@ public abstract class AbstractCPropertyTab implements ICPropertyTab { } /** - * Sets checkbox to appropriate state: + * Sets checkbox to appropriate state: * unchecked or checked * @param b - checkbox to set - * @param state + * @param state */ public static void setTriSelection(Button b, boolean state) { setTriSelection(b, state ? TRI_YES : TRI_NO); } - + /** - * Sets checkbox to appropriate state: + * Sets checkbox to appropriate state: * unchecked, checked or unknown (grayed) * @param b - checkbox to set - * @param state + * @param state */ public static void setTriSelection(Button b, int state) { switch (state) { @@ -630,7 +637,7 @@ public abstract class AbstractCPropertyTab implements ICPropertyTab { * This method will be simplified after M5 release, * when Button.setGrayed() method will be accessible. * In this case, reflection will not be required. - * + * * @param b * @param value * @deprecated call {@link Button#setGrayed(boolean)} instead @@ -643,7 +650,7 @@ public abstract class AbstractCPropertyTab implements ICPropertyTab { /** * This method will be removed after M5 release, * when Button.setGrayed() will be officially accessible. - * + * * @return reference to Button.setGrayed() method */ private static Method getGrayEnabled() { @@ -659,8 +666,8 @@ public abstract class AbstractCPropertyTab implements ICPropertyTab { /** * Utility method to show/hide working panes - * When panes are hidden, message becomes visible - * + * When panes are hidden, message becomes visible + * * @param visible - true or false * @param msg - text to be shown instead of panes */ @@ -680,21 +687,21 @@ public abstract class AbstractCPropertyTab implements ICPropertyTab { b.setVisible(visible); } } - + /** * Allows changing message on background pane, * which becomes visible after usercomp hidden - * - * @param s - text to display or null for default + * + * @param s - text to display or null for default */ protected void setBackgroundText(String s) { background.setText(s == null ? BACKGROUND_TEXT_DEFAULT : s); } - + /** * Used to display double-clickable buttons for multiple configurations * string list mode (see Multiple Configurations Edit Preference page). - * + * * @deprecated as of CDT 8.0. This functionality is presented as links * to the preference page, see {@link AbstractLangsListTab#updateStringListModeControl()} */ @@ -721,7 +728,7 @@ public abstract class AbstractCPropertyTab implements ICPropertyTab { * The writing mode for multiple configurations edits (configuration drop-down list * in project properties). This mode applies to lists of entries. * See preference Multiple Configurations Edit, String List Write Mode. - * + * * @return * {@code true} if each list should be replaced as a whole with the * list user is currently working with in UI
    @@ -736,12 +743,12 @@ public abstract class AbstractCPropertyTab implements ICPropertyTab { public String getHelpContextId() { return helpId; } - + public void setHelpContextId(String id) { helpId = PREFIX + id; } - /** + /** * Allows subclasses to inform the container about changes relevant to the indexer. * The tab will be asked before the apply is performed. As a consequence of returning * true the user will be asked whether she wants to rebuild the index. diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/CDTPrefUtil.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/CDTPrefUtil.java index 58594cf3146..063f3470a8d 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/CDTPrefUtil.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/CDTPrefUtil.java @@ -33,12 +33,14 @@ import org.eclipse.cdt.internal.ui.workingsets.WorkingSetConfigurationManager; public class CDTPrefUtil { // boolean keys (KEY_NO-s are to be inverted !) public static final String KEY_NOSUPP = "wizard.show.unsupported.disable"; //$NON-NLS-1$ + /** @since 5.4 */ // AG FIXME - remove before CDT Juno release public static final String KEY_NEWSD = "wizard.try.new.sd.enable"; //$NON-NLS-1$ public static final String KEY_OTHERS = "wizard.group.others.enable"; //$NON-NLS-1$ public static final String KEY_NOMNG = "properties.manage.config.disable"; //$NON-NLS-1$ public static final String KEY_DTREE = "properties.data.hierarchy.enable"; //$NON-NLS-1$ public static final String KEY_NOTOOLM = "properties.toolchain.modification.disable"; //$NON-NLS-1$ public static final String KEY_EXPORT = "properties.export.page.enable"; //$NON-NLS-1$ + /** @since 5.4 */ public static final String KEY_NO_SHOW_PROVIDERS = "properties.providers.tab.disable"; //$NON-NLS-1$ /** @since 5.2 Show the "Include Files" settings entry tab */ public static final String KEY_SHOW_INC_FILES = "properties.includefiles.page.enable"; //$NON-NLS-1$ @@ -52,34 +54,34 @@ public class CDTPrefUtil { public static final int POSITION_SAVE_SIZE = 0; public static final int POSITION_SAVE_NONE = 2; public static final int POSITION_SAVE_BOTH = 3; - + public static final String KEY_DISC_NAMES = "properties.discovery.naming"; //$NON-NLS-1$ public static final int DISC_NAMING_UNIQUE_OR_BOTH = 0; public static final int DISC_NAMING_UNIQUE_OR_IDS = 1; public static final int DISC_NAMING_ALWAYS_BOTH = 2; public static final int DISC_NAMING_ALWAYS_IDS = 3; public static final int DISC_NAMING_DEFAULT = DISC_NAMING_UNIQUE_OR_BOTH; - + /** Property key used for string list display mode for multi-configuration edits (conjunction/disjunction) */ public static final String KEY_DMODE = "properties.multi.displ.mode"; //$NON-NLS-1$ /** Conjunction implies showing only common elements (intersection) */ public static final int DMODE_CONJUNCTION = 1; /** Disjunction implies showing all elements (union) */ public static final int DMODE_DISJUNCTION = 2; - + /** Property key used for string list write mode for multi-configuration edits (modify/replace) */ public static final String KEY_WMODE = "properties.multi.write.mode"; //$NON-NLS-1$ /** Modify implies changing only given elements and not changing any others */ public static final int WMODE_MODIFY = 4; /** Replace implies replacing the whole list with the given one, overwriting old entries */ public static final int WMODE_REPLACE = 8; - + public static final String NULL = "NULL"; //$NON-NLS-1$ private static final IPreferenceStore pref = CUIPlugin.getDefault().getPreferenceStore(); private static final String DELIMITER = " "; //$NON-NLS-1$ public static final String CONFSETDEL = "\f"; //$NON-NLS-1$ private static LinkedList preferredTCs = null; - + public static final Object[] EMPTY_ARRAY = new Object[0]; // low-level methods @@ -95,40 +97,40 @@ public class CDTPrefUtil { preferredTCs = new LinkedList(Arrays.asList(getStr(KEY_PREFTC).split(DELIMITER))); } public static List getPreferredTCs() { - if (preferredTCs == null) readPreferredTCs(); - return preferredTCs; + if (preferredTCs == null) readPreferredTCs(); + return preferredTCs; } - public static void delPreferredTC(String s) { - if (preferredTCs == null) readPreferredTCs(); - preferredTCs.remove(s); + public static void delPreferredTC(String s) { + if (preferredTCs == null) readPreferredTCs(); + preferredTCs.remove(s); } public static void addPreferredTC(String s) { - if (preferredTCs == null) readPreferredTCs(); - if (!preferredTCs.contains(s)) preferredTCs.add(s); + if (preferredTCs == null) readPreferredTCs(); + if (!preferredTCs.contains(s)) preferredTCs.add(s); } public static void cleanPreferredTCs() { setStr(KEY_PREFTC, IPreferenceStore.STRING_DEFAULT_DEFAULT); - readPreferredTCs(); + readPreferredTCs(); } public static void savePreferredTCs() { - if (preferredTCs == null) return; + if (preferredTCs == null) return; Iterator it = preferredTCs.iterator(); - StringBuilder b = new StringBuilder(); + StringBuilder b = new StringBuilder(); while (it.hasNext()) { String s = it.next(); - if (s == null) continue; + if (s == null) continue; b.append(s); b.append(DELIMITER); } setStr(KEY_PREFTC, b.toString().trim()); } - + /** * Returns string list display mode for multi-configuration edits (conjunction/disjunction). - * + * * @return the mode which can be either {@link CDTPrefUtil#DMODE_CONJUNCTION} (default value) * or else {@link CDTPrefUtil#DMODE_DISJUNCTION}. - * + * * @since 5.3 */ public static int getMultiCfgStringListDisplayMode() { @@ -138,25 +140,25 @@ public class CDTPrefUtil { } return mode; } - + /** * Sets string list display mode for multi-configuration edits (conjunction/disjunction). - * + * * @param mode must be either {@link CDTPrefUtil#DMODE_CONJUNCTION} * or {@link CDTPrefUtil#DMODE_DISJUNCTION}. - * + * * @since 5.3 */ public static void setMultiCfgStringListDisplayMode(int mode) { setInt(KEY_DMODE, mode); } - + /** * Returns string list write mode for multi-configuration edits (modify/replace). - * + * * @return the mode which can be either {@link CDTPrefUtil#WMODE_MODIFY} (default value) * or else {@link CDTPrefUtil#WMODE_REPLACE}. - * + * * @since 5.3 */ public static int getMultiCfgStringListWriteMode() { @@ -166,19 +168,19 @@ public class CDTPrefUtil { } return mode; } - + /** * Sets string list write mode for multi-configuration edits (modify/replace). - * + * * @param mode must be either {@link CDTPrefUtil#WMODE_MODIFY} * or {@link CDTPrefUtil#WMODE_REPLACE}. - * + * * @since 5.3 */ public static void setMultiCfgStringListWriteMode(int mode) { setInt(KEY_WMODE, mode); } - + /** * @deprecated as of CDT 8.0. Use {@link StringListModeControl} to display string list modes. */ @@ -187,15 +189,15 @@ public class CDTPrefUtil { String s = null; switch(getMultiCfgStringListDisplayMode()) { case DMODE_CONJUNCTION: - s = Messages.EnvironmentTab_17; + s = Messages.EnvironmentTab_17; break; case DMODE_DISJUNCTION: - s = Messages.EnvironmentTab_18; + s = Messages.EnvironmentTab_18; break; } - return Messages.EnvironmentTab_19 + s; + return Messages.EnvironmentTab_19 + s; } - + /** * @deprecated as of CDT 8.0. Use {@link StringListModeControl} to display string list modes. */ @@ -204,15 +206,15 @@ public class CDTPrefUtil { String s = null; switch(getMultiCfgStringListWriteMode()) { case WMODE_MODIFY: - s = Messages.EnvironmentTab_24; + s = Messages.EnvironmentTab_24; break; case WMODE_REPLACE: - s = Messages.EnvironmentTab_21; + s = Messages.EnvironmentTab_21; break; } - return Messages.EnvironmentTab_22 + s; + return Messages.EnvironmentTab_22 + s; } - + /** * Toggle string list display mode: conjunction <-> disjunction. */ @@ -242,21 +244,21 @@ public class CDTPrefUtil { public static final String[] getStrListForDisplay(String[][] input) { return getStrListForDisplay(input, getMultiCfgStringListDisplayMode()); } - + private static final String[] getStrListForDisplay(String[][] input, int mode) { Object[] ob = getListForDisplay(input, getMultiCfgStringListDisplayMode(), null); String[] ss = new String[ob.length]; System.arraycopy(ob, 0, ss, 0, ob.length); return ss; } - + public static final Object[] getListForDisplay(Object[][] input, Comparator cmp) { return getListForDisplay(input, getMultiCfgStringListDisplayMode(), cmp); } /** * Utility method forms string list * according to current list display mode - * + * * @param input - array of string arrays * @return */ @@ -270,11 +272,11 @@ public class CDTPrefUtil { } Object[] s1 = input[0]; - if (s1 == null || + if (s1 == null || s1.length == 0) return EMPTY_ARRAY; - if (getMultiCfgStringListDisplayMode() == DMODE_CONJUNCTION) - { + if (getMultiCfgStringListDisplayMode() == DMODE_CONJUNCTION) + { ArrayList lst = new ArrayList(); for (int i=0; i readConfigSets() { return new LinkedList(Arrays.asList(getStr(KEY_CONFSET).split(CONFSETDEL))); } - + /** * @deprecated Use the {@link WorkingSetConfigurationManager} class, instead. */ @Deprecated public static void saveConfigSets(List out) { - StringBuilder b = new StringBuilder(); + StringBuilder b = new StringBuilder(); for (String s : out) { - if (s == null) continue; + if (s == null) continue; b.append(s); b.append(CONFSETDEL); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/CDTMainWizardPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/CDTMainWizardPage.java index bfbd7649fc6..fb7f9e0ce77 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/CDTMainWizardPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/CDTMainWizardPage.java @@ -497,6 +497,10 @@ import org.eclipse.cdt.internal.ui.newui.Messages; return items; } + /** + * AG FIXME - remove before CDT Juno release. + * @since 5.4 + */ public boolean isTryingNewSD() { return checkBoxTryNewSD.getSelection(); } From afa71216dd7978ed25e1b578579f7685c5287a8b Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Sat, 17 Dec 2011 11:59:20 -0500 Subject: [PATCH 099/120] JavaDoc ICConfigurationDescription --- .../model/CProjectDescriptionEvent.java | 52 ++++++++++--------- .../model/ICConfigurationDescription.java | 20 ++++++- .../model/CConfigurationDescription.java | 8 +++ .../model/CConfigurationDescriptionCache.java | 45 ++++++++++------ 4 files changed, 82 insertions(+), 43 deletions(-) diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/CProjectDescriptionEvent.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/CProjectDescriptionEvent.java index 1744c26e494..92cd751417f 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/CProjectDescriptionEvent.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/CProjectDescriptionEvent.java @@ -10,27 +10,29 @@ *******************************************************************************/ package org.eclipse.cdt.core.settings.model; +import org.eclipse.cdt.internal.core.settings.model.CConfigurationDescription; +import org.eclipse.cdt.internal.core.settings.model.CConfigurationDescriptionCache; import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionDelta; import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager; import org.eclipse.core.resources.IProject; /** - * Events fired for the project delats. - * The ProjectDescription lifecycle looks like: + * Events fired for the project deltas. + * The ProjectDescription life-cycle looks like: *
      - *
    • - * - {@link #LOADED} - configuration is loaded and read-only - *
    • - * - {@link #COPY_CREATED} - Indicates new writable description has been created from - * the read-only description backing store - *
    • - * - {@link #ABOUT_TO_APPLY} - First event in the setProjectDescription flow. New description - * writable, old description represents the cache - *
    • - * - {@link #DATA_APPLIED} - Event indicating that configuration data has been applied by the build system - *
    • - * - {@link #APPLIED} - setProjectDescription finished, newDescription is read-only + *
    • {@link #LOADED} - configuration is loaded and read-only. + *
    • {@link #COPY_CREATED} - Indicates new writable description has been created + * from the read-only description backing store. + *
    • {@link #ABOUT_TO_APPLY} - First event in the setProjectDescription flow. + * New description writable, old description represents the cache. + *
    • {@link #DATA_APPLIED} - Event indicating that configuration data has been applied + * by the build system. + *
    • {@link #APPLIED} - setProjectDescription finished, newDescription is read-only. *
    + * + * @see ICConfigurationDescription + * @see CConfigurationDescription + * @see CConfigurationDescriptionCache */ public final class CProjectDescriptionEvent { @@ -44,8 +46,8 @@ public final class CProjectDescriptionEvent { public static final int DATA_APPLIED = 1 << 4; /** Event kind encapsulated ALL events */ public static final int ALL = LOADED | ABOUT_TO_APPLY | APPLIED | COPY_CREATED | DATA_APPLIED; - - /** The type of event this corresponds to */ + + /** The type of event this corresponds to */ private final int fType; /** A *writable* new description */ private final ICProjectDescription fNewDescription; @@ -56,7 +58,7 @@ public final class CProjectDescriptionEvent { private ICDescriptionDelta fActiveCfgDelta; private ICDescriptionDelta fIndexCfgDelta; private final IProject fProject; - + public CProjectDescriptionEvent(int type, ICDescriptionDelta delta, ICProjectDescription newDes, @@ -75,7 +77,7 @@ public final class CProjectDescriptionEvent { fProject = null; } } - + public IProject getProject() { return fProject; } @@ -83,11 +85,11 @@ public final class CProjectDescriptionEvent { public int getEventType() { return fType; } - + public ICDescriptionDelta getProjectDelta() { return fProjDelta; } - + public ICDescriptionDelta getActiveCfgDelta() { if (fActiveCfgDelta == null) { fActiveCfgDelta = getDelta(true); @@ -101,7 +103,7 @@ public final class CProjectDescriptionEvent { } return fIndexCfgDelta; } - + private ICDescriptionDelta getDelta(boolean active) { ICDescriptionDelta delta = null; switch(getEventType()) { @@ -139,17 +141,17 @@ public final class CProjectDescriptionEvent { } } break; - + case COPY_CREATED: break; } return delta; } - + private ICConfigurationDescription getCfg(ICProjectDescription des, boolean active) { - return active ? des.getActiveConfiguration() : des.getDefaultSettingConfiguration(); + return active ? des.getActiveConfiguration() : des.getDefaultSettingConfiguration(); } - + private ICDescriptionDelta findCfgDelta(ICDescriptionDelta delta, String id) { if (delta == null) return null; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICConfigurationDescription.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICConfigurationDescription.java index eac75d44021..cc53679e3d1 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICConfigurationDescription.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICConfigurationDescription.java @@ -16,13 +16,29 @@ import org.eclipse.cdt.core.cdtvariables.ICdtVariablesContributor; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.settings.model.extension.CConfigurationData; import org.eclipse.cdt.core.settings.model.extension.CConfigurationDataProvider; +import org.eclipse.cdt.internal.core.settings.model.CConfigurationDescription; +import org.eclipse.cdt.internal.core.settings.model.CConfigurationDescriptionCache; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.QualifiedName; /** - * This is the element representing configuration and thus this is the root element - * for configuration-specific settings + * This is the class representing configuration and thus this is the root element + * for configuration-specific settings. + *

    + * A typical (simplified) life-cycle of configuration description in CDT is as following: + *
    1. A project is created or opened. A new read-only configuration description is loaded. + *
    2. If a description needs to be changed, a client gets a copy as a writable configuration + * description first. Then, that instance can be edited. + *
    3. The changed writable configuration description gets applied to the model and becomes + * read-only. + *
    4. The project gets closed or removed. The configuration description gets disposed. + *

    + * Typically read-only configuration description would be represented by {@link CConfigurationDescriptionCache} + * and writable one by {@link CConfigurationDescription}. + * + * @see CProjectDescriptionEvent + * @see CConfigurationDescriptionCache */ public interface ICConfigurationDescription extends ICSettingContainer, ICSettingObject, ICSettingsStorage { /** diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationDescription.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationDescription.java index 771eb1280de..d3e4a2e36a4 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationDescription.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationDescription.java @@ -21,6 +21,7 @@ import org.eclipse.cdt.core.cdtvariables.ICdtVariablesContributor; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvidersKeeper; import org.eclipse.cdt.core.settings.model.CConfigurationStatus; +import org.eclipse.cdt.core.settings.model.CProjectDescriptionEvent; import org.eclipse.cdt.core.settings.model.ICBuildSetting; import org.eclipse.cdt.core.settings.model.ICConfigExtensionReference; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; @@ -52,6 +53,13 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.QualifiedName; +/** + * The writable configuration description. + * + * @see ICConfigurationDescription + * @see CConfigurationDescriptionCache + * @see CProjectDescriptionEvent + */ public class CConfigurationDescription extends CDataProxyContainer implements ICConfigurationDescription, IProxyFactory, IInternalCCfgInfo, ILanguageSettingsProvidersKeeper { private CfgProxyCache fCache; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationDescriptionCache.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationDescriptionCache.java index 42087ea7220..d66b85bd1f1 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationDescriptionCache.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationDescriptionCache.java @@ -19,6 +19,7 @@ import org.eclipse.cdt.core.cdtvariables.ICdtVariablesContributor; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvidersKeeper; import org.eclipse.cdt.core.settings.model.CConfigurationStatus; +import org.eclipse.cdt.core.settings.model.CProjectDescriptionEvent; import org.eclipse.cdt.core.settings.model.ICBuildSetting; import org.eclipse.cdt.core.settings.model.ICConfigExtensionReference; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; @@ -60,22 +61,34 @@ import org.eclipse.core.runtime.QualifiedName; * * An inspection of the scenario where user changes project properties and saves it yields * following sequence of events: - * - Initialization: - * - After eclipse started a project is being opened. A new CConfigurationDescriptionCache is created - * with CConfigurationDescriptionCache(ICStorageElement storage, CProjectDescription parent) constructor. - * - Any clients needed ICConfigurationDescription get CConfigurationDescription using constructor - * CConfigurationDescription(CConfigurationData data, String buildSystemId, ICDataProxyContainer cr) - * where the CConfigurationDescriptionCache is passed as data. The reference to cache is kept in field fCfgCache. - * - fCfgCache is used to getSpecSettings() CConfigurationSpecSettings, after that fCfgCache is set to null. - * - User enters project properties/settings: - * - another CConfigurationDescription (settings configuration) created using the same constructor setting fCfgCache - * to the CConfigurationDescriptionCache. - * - User changes settings (in the settings configuration CConfigurationDescription) and saves it: - * - new CConfigurationDescriptionCache is created from the CConfigurationDescription via constructor - * CConfigurationDescriptionCache(ICConfigurationDescription baseDescription, ...) where - * baseDescription is saved as fBaseDescription. - * - CConfigurationDescriptionCache.applyData(...) is used to persist the data. at that point - * reference fBaseDescription gets set to null. + *
      + *
    1. Initialization: + *
        + *
      • After eclipse started a project is being opened. A new CConfigurationDescriptionCache is created + * with CConfigurationDescriptionCache(ICStorageElement storage, CProjectDescription parent) constructor. + *
      • Any clients needed ICConfigurationDescription get CConfigurationDescription using constructor + * CConfigurationDescription(CConfigurationData data, String buildSystemId, ICDataProxyContainer cr) + * where the CConfigurationDescriptionCache is passed as data. The reference to cache is kept in field fCfgCache. + *
      • fCfgCache is used to getSpecSettings() CConfigurationSpecSettings, after that fCfgCache is set to null. + *
      + *
    2. User enters project properties/settings: + *
        + *
      • another CConfigurationDescription (settings configuration) created using the same constructor setting fCfgCache + * to the CConfigurationDescriptionCache. + *
      + *
    3. User changes settings (in the settings configuration CConfigurationDescription) and saves it: + *
        + *
      • new CConfigurationDescriptionCache is created from the CConfigurationDescription via constructor + * CConfigurationDescriptionCache(ICConfigurationDescription baseDescription, ...) where + * baseDescription is saved as fBaseDescription. + *
      • CConfigurationDescriptionCache.applyData(...) is used to persist the data. at that point + * reference fBaseDescription gets set to null. + *
      + *
    + * + * @see ICConfigurationDescription + * @see CConfigurationDescription + * @see CProjectDescriptionEvent */ public class CConfigurationDescriptionCache extends CDefaultConfigurationData implements ICConfigurationDescription, IInternalCCfgInfo, ILanguageSettingsProvidersKeeper, ICachedData { From 3429983cb4bbfb2512472e57531de23a898b08b6 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Sat, 17 Dec 2011 12:14:36 -0500 Subject: [PATCH 100/120] JavaDoc --- .../model/ScannerInfoProviderProxy.java | 4 ---- .../org/eclipse/cdt/core/ICConsoleParser.java | 17 +++++++++++++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/ScannerInfoProviderProxy.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/ScannerInfoProviderProxy.java index ec753f5d9bb..21f7f3d2937 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/ScannerInfoProviderProxy.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/ScannerInfoProviderProxy.java @@ -25,10 +25,6 @@ import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSetting import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; -/** - * TODO fProvider is going to be deprecated in favor of {@link LanguageSettingsScannerInfoProvider}. - * - */ public class ScannerInfoProviderProxy extends AbstractCExtensionProxy implements IScannerInfoProvider, IScannerInfoChangeListener{ private Map> listeners; private IScannerInfoProvider fProvider; diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICConsoleParser.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICConsoleParser.java index dd55807a4f8..85c54e5f8a0 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICConsoleParser.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICConsoleParser.java @@ -15,13 +15,22 @@ import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.core.runtime.CoreException; /** - * TODO - this interface assumes configuration description. CDT project - * can be without configurations, in that case IProject should be passed - * to startup somehow. Perhaps another interface "IPConsoleParser" could - * be created when needed? + * Console parser interface extended to support configurations. * * @since 5.4 */ public interface ICConsoleParser extends IConsoleParser { + /** + * Initialize console parser. + * + * @param cfgDescription - configuration description for the parser. + * @throws CoreException if anything goes wrong. + */ public void startup(ICConfigurationDescription cfgDescription) throws CoreException; + + @Override + public boolean processLine(String line); + @Override + public void shutdown(); + } From bde0e7a154a04e56b10a94ed71b2aa15afebcbbb Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Sat, 17 Dec 2011 20:40:28 -0500 Subject: [PATCH 101/120] JavaDoc, high level descriptions for language settings providers in build plugins --- .../AbstractBuildCommandParser.java | 5 ++-- .../AbstractBuiltinSpecsDetector.java | 3 ++ ...AbstractLanguageSettingsOutputScanner.java | 2 ++ .../GCCBuiltinSpecsDetector.java | 16 +++++----- .../ToolchainBuiltinSpecsDetector.java | 4 +++ .../xlc/core/XlcBuiltinSpecsDetector.java | 30 +++++++++---------- 6 files changed, 33 insertions(+), 27 deletions(-) diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java index 42ee4cf01ee..fe813006ef2 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuildCommandParser.java @@ -36,11 +36,12 @@ import org.eclipse.core.runtime.jobs.ISchedulingRule; import org.eclipse.core.runtime.jobs.Job; /** - * TODO - class description + * Abstract class for providers parsing compiler option from build command when it + * is present in build output. * * Note: IErrorParser interface is used here to work around {@link ConsoleOutputSniffer} having * no access from CDT core to build packages. TODO - elaborate? - * + * * @since 7.2 */ public abstract class AbstractBuildCommandParser extends AbstractLanguageSettingsOutputScanner diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java index d2c7b7b994f..276513466a1 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractBuiltinSpecsDetector.java @@ -68,6 +68,9 @@ import org.eclipse.core.runtime.jobs.Job; import org.w3c.dom.Element; /** + * Abstract parser capable to execute compiler command printing built-in compiler + * specs and parse built-in language settings out of it. + * * @since 7.2 */ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSettingsOutputScanner implements ICListenerAgent { diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java index 05ea657cea3..074b1016438 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java @@ -55,6 +55,8 @@ import org.eclipse.core.runtime.content.IContentTypeManager; import org.w3c.dom.Element; /** + * Abstract class for providers capable to parse build output. + * * @since 7.2 */ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSettingsSerializableProvider { diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/GCCBuiltinSpecsDetector.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/GCCBuiltinSpecsDetector.java index 0fe79bb509f..dc21039200f 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/GCCBuiltinSpecsDetector.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/GCCBuiltinSpecsDetector.java @@ -21,17 +21,15 @@ import org.eclipse.cdt.managedbuilder.scannerconfig.ToolchainBuiltinSpecsDetecto import org.eclipse.core.runtime.CoreException; /** - * Class to detect built-in compiler settings. Note that currently this class is hardwired - * to GCC toolchain {@code cdt.managedbuild.toolchain.gnu.base}. - * + * Language settings provider to detect built-in compiler settings for GCC compiler. */ public class GCCBuiltinSpecsDetector extends ToolchainBuiltinSpecsDetector implements ILanguageSettingsEditableProvider { // ID must match the toolchain definition in org.eclipse.cdt.managedbuilder.core.buildDefinitions extension point private static final String GCC_TOOLCHAIN_ID = "cdt.managedbuild.toolchain.gnu.base"; //$NON-NLS-1$ - + private enum State {NONE, EXPECTING_LOCAL_INCLUDE, EXPECTING_SYSTEM_INCLUDE, EXPECTING_FRAMEWORKS} private State state = State.NONE; - + @SuppressWarnings("nls") private static final AbstractOptionParser[] optionParsers = { new IncludePathOptionParser("#include \"(\\S.*)\"", "$1", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY | ICSettingEntry.LOCAL), @@ -54,7 +52,7 @@ public class GCCBuiltinSpecsDetector extends ToolchainBuiltinSpecsDetector imple private List makeList(final String line) { return new ArrayList() {{ add(line); }}; } - + @Override protected List parseForOptions(String line) { line = line.trim(); @@ -102,10 +100,10 @@ public class GCCBuiltinSpecsDetector extends ToolchainBuiltinSpecsDetector imple @Override public void startup(ICConfigurationDescription cfgDescription) throws CoreException { super.startup(cfgDescription); - + state = State.NONE; } - + @Override public void shutdown() { state = State.NONE; @@ -123,5 +121,5 @@ public class GCCBuiltinSpecsDetector extends ToolchainBuiltinSpecsDetector imple return (GCCBuiltinSpecsDetector) super.clone(); } - + } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/scannerconfig/ToolchainBuiltinSpecsDetector.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/scannerconfig/ToolchainBuiltinSpecsDetector.java index 802f4551f7f..eec392dee85 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/scannerconfig/ToolchainBuiltinSpecsDetector.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/scannerconfig/ToolchainBuiltinSpecsDetector.java @@ -22,6 +22,10 @@ import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin; /** + * Abstract parser capable to execute compiler command printing built-in compiler + * specs and parse built-in language settings out of it. The compiler to be used + * is taken from MBS tool-chain definition. + * * @since 8.1 */ public abstract class ToolchainBuiltinSpecsDetector extends AbstractBuiltinSpecsDetector { diff --git a/xlc/org.eclipse.cdt.managedbuilder.xlc.core/src/org/eclipse/cdt/managedbuilder/xlc/core/XlcBuiltinSpecsDetector.java b/xlc/org.eclipse.cdt.managedbuilder.xlc.core/src/org/eclipse/cdt/managedbuilder/xlc/core/XlcBuiltinSpecsDetector.java index b2fc7ca939d..45849a122ca 100644 --- a/xlc/org.eclipse.cdt.managedbuilder.xlc.core/src/org/eclipse/cdt/managedbuilder/xlc/core/XlcBuiltinSpecsDetector.java +++ b/xlc/org.eclipse.cdt.managedbuilder.xlc.core/src/org/eclipse/cdt/managedbuilder/xlc/core/XlcBuiltinSpecsDetector.java @@ -21,32 +21,30 @@ import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.managedbuilder.scannerconfig.ToolchainBuiltinSpecsDetector; -/** - * - -> xlC -E -V -P -w ~/tmp/spec.C -export XL_CONFIG=/etc/vac.cfg:xlC -/usr/vac/exe/xlCcpp /home/me/tmp/spec.C - -qc++=/usr/vacpp/include -D_AIX -D_AIX32 -D_AIX41 -D_AIX43 -D_AIX50 -D_AIX51 -D_AIX52 -D_IBMR2 -D_POWER -E -P -w -qlanglvl=ansi -qansialias -rm /tmp/xlcW0lt4Jia -rm /tmp/xlcW1lt4Jib -rm /tmp/xlcW2lt4Jic - - */ /** - * Class to detect built-in compiler settings. Note that currently this class is hardwired - * to GCC toolchain {@code cdt.managedbuild.toolchain.gnu.base}. - * + * Language settings provider to detect built-in compiler settings for IBM XLC compiler. + * Note that currently this class is hardwired to GCC toolchain + * {@code cdt.managedbuild.toolchain.gnu.base}. */ public class XlcBuiltinSpecsDetector extends ToolchainBuiltinSpecsDetector implements ILanguageSettingsEditableProvider { // must match the toolchain definition in org.eclipse.cdt.managedbuilder.core.buildDefinitions extension point // FIXME - ill defined XLC toolchain // private static final String XLC_TOOLCHAIN_ID = "cdt.managedbuild.toolchain.xlc.exe.debug"; //$NON-NLS-1$ private static final String GCC_TOOLCHAIN_ID = "cdt.managedbuild.toolchain.gnu.base"; //$NON-NLS-1$ - + private static final Pattern OPTIONS_PATTERN = Pattern.compile("-[^\\s\"']*(\\s*((\".*?\")|('.*?')|([^-\\s][^\\s]+)))?"); //$NON-NLS-1$ private static final int OPTION_GROUP = 0; + /* Sample output: + + > xlC -E -V -P -w ~/tmp/spec.C + export XL_CONFIG=/etc/vac.cfg:xlC + /usr/vac/exe/xlCcpp /home/me/tmp/spec.C - -qc++=/usr/vacpp/include -D_AIX -D_AIX32 -D_AIX41 -D_AIX43 -D_AIX50 -D_AIX51 -D_AIX52 -D_IBMR2 -D_POWER -E -P -w -qlanglvl=ansi -qansialias + rm /tmp/xlcW0lt4Jia + rm /tmp/xlcW1lt4Jib + rm /tmp/xlcW2lt4Jic + */ @SuppressWarnings("nls") private static final AbstractOptionParser[] optionParsers = { new IncludePathOptionParser("-I\\s*([\"'])(.*)\\1", "$2", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY | ICSettingEntry.LOCAL), @@ -93,5 +91,5 @@ public class XlcBuiltinSpecsDetector extends ToolchainBuiltinSpecsDetector imple return (XlcBuiltinSpecsDetector) super.clone(); } - + } From 5793dcd405c03e71af31d620e3ed0f35a3f8901d Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Mon, 19 Dec 2011 13:08:40 -0500 Subject: [PATCH 102/120] Special handling of properties in equals() to account for default values --- .../LanguageSettingsSerializableTests.java | 160 ++++++++++++++---- .../LanguageSettingsBaseProvider.java | 97 +++++++++++ .../LanguageSettingsSerializableProvider.java | 116 ++++++------- .../LanguageSettingsProvidersSerializer.java | 10 +- 4 files changed, 280 insertions(+), 103 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java index b8554871730..ff506fafcda 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableTests.java @@ -56,9 +56,13 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { private static final String PROVIDER_NAME_2 = "test.provider.2.name"; private static final String ATTR_PARAMETER = "parameter"; private static final String VALUE_PARAMETER = "custom.parameter"; - private static final String ATTR_STORE_ENTRIES = "store-entries"; - private static final String VALUE_PROJECT = "project"; private static final String ELEM_TEST = "test"; + private static final String ATTR_PROPERTY = "custom-property"; + private static final String ATTR_PROPERTY_BOOL = "custom-property-bool"; + private static final String VALUE_PROPERTY = "custom.property"; + + // This value must match that of LanguageSettingsProvidersSerializer.ATTR_STORE_ENTRIES_WITH_PROJECT + private static final String ATTR_STORE_ENTRIES_WITH_PROJECT = "store-entries-with-project"; /** * Constructor. @@ -357,8 +361,8 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST); elementProvider = provider.serialize(rootElement); String xmlString = XmlUtil.toString(doc); - assertTrue(xmlString.contains(ATTR_STORE_ENTRIES)); - assertTrue(xmlString.contains(VALUE_PROJECT)); + assertTrue(xmlString.contains(ATTR_STORE_ENTRIES_WITH_PROJECT)); + assertTrue(xmlString.contains(ATTR_STORE_ENTRIES_WITH_PROJECT+"=\"true\"")); } { // re-load and check storing mode of the newly loaded provider @@ -1189,46 +1193,144 @@ public class LanguageSettingsSerializableTests extends BaseTestCase { provider1.setSettingEntries(MOCK_CFG, MOCK_RC, LANG_ID, sampleEntries_1); provider1.setSettingEntries(null, null, LANG_ID, sampleEntries_2); + // create another provider with the same data + LanguageSettingsSerializableProvider provider2 = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); { - // create another provider with the same data - LanguageSettingsSerializableProvider provider2 = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); - assertFalse(provider1.equals(provider2)); - assertFalse(provider1.hashCode()==provider2.hashCode()); - - provider2.setSettingEntries(MOCK_CFG, MOCK_RC, LANG_ID, sampleEntries_1); - assertFalse(provider1.equals(provider2)); - assertFalse(provider1.hashCode()==provider2.hashCode()); - - provider2.setSettingEntries(null, null, LANG_ID, sampleEntries_2); - assertFalse(provider1.equals(provider2)); - assertFalse(provider1.hashCode()==provider2.hashCode()); - provider2.setLanguageScope(sampleLanguages); - assertFalse(provider1.equals(provider2)); - assertFalse(provider1.hashCode()==provider2.hashCode()); - provider2.setProperty(ATTR_PARAMETER, VALUE_PARAMETER); - assertFalse(provider1.equals(provider2)); - assertFalse(provider1.hashCode()==provider2.hashCode()); - LanguageSettingsManager.setStoringEntriesInProjectArea(provider2, true); - + provider2.setSettingEntries(MOCK_CFG, MOCK_RC, LANG_ID, sampleEntries_1); + provider2.setSettingEntries(null, null, LANG_ID, sampleEntries_2); // All set now, so they should be equal - assertTrue(provider1.equals(provider2)); assertTrue(provider1.hashCode()==provider2.hashCode()); + assertTrue(provider1.equals(provider2)); + } - // check different ID - provider2.setId(PROVIDER_2); - assertFalse(provider1.equals(provider2)); + { + // start with provider with the same data + assertTrue(provider1.hashCode()==provider2.hashCode()); + assertTrue(provider1.equals(provider2)); + // replace languages + List sampleLanguages2 = new ArrayList(); + sampleLanguages2.add(LANG_ID_1); + provider2.setLanguageScope(sampleLanguages2); assertFalse(provider1.hashCode()==provider2.hashCode()); + assertFalse(provider1.equals(provider2)); + // restore provider + provider2.setLanguageScope(sampleLanguages); + assertTrue(provider1.hashCode()==provider2.hashCode()); + assertTrue(provider1.equals(provider2)); + } + + { + // start with provider with the same data + assertTrue(provider1.hashCode()==provider2.hashCode()); + assertTrue(provider1.equals(provider2)); + // replace property + provider2.setProperty(ATTR_PARAMETER, "changed-parameter"); + // hash is not calculated for properties + assertFalse(provider1.equals(provider2)); + // restore provider + provider2.setProperty(ATTR_PARAMETER, VALUE_PARAMETER); + assertTrue(provider1.hashCode()==provider2.hashCode()); + assertTrue(provider1.equals(provider2)); + } + { + // start with provider with the same data + assertTrue(provider1.hashCode()==provider2.hashCode()); + assertTrue(provider1.equals(provider2)); + // replace property + LanguageSettingsManager.setStoringEntriesInProjectArea(provider2, false); + // hash is not calculated for properties + assertFalse(provider1.equals(provider2)); + // restore provider + LanguageSettingsManager.setStoringEntriesInProjectArea(provider2, true); + assertTrue(provider1.hashCode()==provider2.hashCode()); + assertTrue(provider1.equals(provider2)); + } + { + // start with provider with the same data + assertTrue(provider1.hashCode()==provider2.hashCode()); + assertTrue(provider1.equals(provider2)); + // replace entries + List changedEntries = new ArrayList(); + changedEntries.add(new CMacroEntry("MACROX", "valueX",1)); + provider2.setSettingEntries(MOCK_CFG, MOCK_RC, LANG_ID, changedEntries); + assertFalse(provider1.hashCode()==provider2.hashCode()); + assertFalse(provider1.equals(provider2)); + // restore provider + provider2.setSettingEntries(MOCK_CFG, MOCK_RC, LANG_ID, sampleEntries_1); + assertTrue(provider1.hashCode()==provider2.hashCode()); + assertTrue(provider1.equals(provider2)); + } + { + // start with provider with the same data + assertTrue(provider1.hashCode()==provider2.hashCode()); + assertTrue(provider1.equals(provider2)); + // replace default entries + List changedEntries = new ArrayList(); + changedEntries.add(new CIncludePathEntry("pathX", 1)); + provider2.setSettingEntries(null, null, LANG_ID, changedEntries); + assertFalse(provider1.hashCode()==provider2.hashCode()); + assertFalse(provider1.equals(provider2)); + // restore provider + provider2.setSettingEntries(null, null, LANG_ID, sampleEntries_2); + assertTrue(provider1.hashCode()==provider2.hashCode()); + assertTrue(provider1.equals(provider2)); } { // check that subclasses are not equal LanguageSettingsSerializableProvider providerSub1 = new LanguageSettingsSerializableProvider() {}; LanguageSettingsSerializableProvider providerSub2 = new LanguageSettingsSerializableProvider() {}; - assertFalse(providerSub1.equals(providerSub2)); assertFalse(providerSub1.hashCode()==providerSub2.hashCode()); + assertFalse(providerSub1.equals(providerSub2)); + } + } + + /** + */ + public void testEquals_DefaultProperties() throws Exception { + // create model providers + LanguageSettingsSerializableProvider provider1 = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); + LanguageSettingsSerializableProvider provider2 = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); + + // equality for setProperty(String, String) + { + // equality for missing property + assertTrue(provider1.equals(provider2)); + // equality for default empty value (missing in provider2) + provider1.setProperty(ATTR_PROPERTY, ""); + assertTrue(provider1.equals(provider2)); + // just for kicks disturb equality + provider1.setProperty(ATTR_PROPERTY, VALUE_PROPERTY); + assertFalse(provider1.equals(provider2)); + // equality for default null value (missing in provider2) + provider1.setProperty(ATTR_PROPERTY, null); + assertTrue(provider1.equals(provider2)); + } + + // equality for setPropertyBool(String, boolean) + { + // equality for missing property + assertEquals(false, provider1.getPropertyBool(ATTR_PROPERTY_BOOL)); + assertTrue(provider1.equals(provider2)); + // equality for default empty value (missing in provider2) + provider1.setPropertyBool(ATTR_PROPERTY_BOOL, false); + assertEquals(false, provider1.getPropertyBool(ATTR_PROPERTY_BOOL)); + assertTrue(provider1.equals(provider2)); + // just for kicks disturb equality + provider1.setPropertyBool(ATTR_PROPERTY_BOOL, true); + assertEquals(true, provider1.getPropertyBool(ATTR_PROPERTY_BOOL)); + assertFalse(provider1.equals(provider2)); + // equality for true value in both + provider2.setPropertyBool(ATTR_PROPERTY_BOOL, true); + assertEquals(true, provider2.getPropertyBool(ATTR_PROPERTY_BOOL)); + assertTrue(provider1.equals(provider2)); + // switch provider1 back to false + provider1.setPropertyBool(ATTR_PROPERTY_BOOL, false); + provider1.setPropertyBool(ATTR_PROPERTY_BOOL, false); + assertFalse(provider1.equals(provider2)); } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsBaseProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsBaseProvider.java index 048523fc461..76a1b3fc8e7 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsBaseProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsBaseProvider.java @@ -14,8 +14,10 @@ package org.eclipse.cdt.core.language.settings.providers; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import org.eclipse.cdt.core.AbstractExecutableExtensionBase; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; @@ -135,6 +137,10 @@ public class LanguageSettingsBaseProvider extends AbstractExecutableExtensionBas * so extenders of this class can customize the provider. The properties * of {@code LanguageSettingsBaseProvider} come from the extension in plugin.xml * although the extenders can provide their own method. + *

    + * Please note that empty string value is treated as "default" value and + * the same as {@code null} and the same as missing property, which allows + * {@link #equals(Object)} evaluate the property as equal while comparing providers. * * @param key - property to check the value. * @return value of the property. @@ -143,6 +149,17 @@ public class LanguageSettingsBaseProvider extends AbstractExecutableExtensionBas return properties.get(key); } + /** + * Convenience method to get boolean property. + * @see #getProperty(String) + * + * @param key - property to check the value. + * @return boolean value of the property. + */ + public boolean getPropertyBool(String key) { + return Boolean.parseBoolean(properties.get(key)); + } + private List getPooledList(List entries) { if (entries != null) { return LanguageSettingsStorage.getPooledList(entries); @@ -183,4 +200,84 @@ public class LanguageSettingsBaseProvider extends AbstractExecutableExtensionBas return null; return Collections.unmodifiableList(languageScope); } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((getId() == null) ? 0 : getId().hashCode()); + result = prime * result + ((getName() == null) ? 0 : getName().hashCode()); + result = prime * result + ((entries == null) ? 0 : entries.hashCode()); + result = prime * result + ((languageScope == null) ? 0 : languageScope.hashCode()); + // exclude field "properties" because of special rules for equals() + result = prime * result + getClass().hashCode(); + return result; + } + + /** + * @return {@code true} if the objects are equal, {@code false } otherwise. + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + LanguageSettingsBaseProvider other = (LanguageSettingsBaseProvider) obj; + + String id = getId(); + String otherId = other.getId(); + if (id == null) { + if (otherId != null) + return false; + } else if (!id.equals(otherId)) + return false; + + String name = getName(); + String otherName = other.getName(); + if (name == null) { + if (otherName != null) + return false; + } else if (!name.equals(otherName)) + return false; + + if (entries == null) { + if (other.entries != null) + return false; + } else if (!entries.equals(other.entries)) + return false; + + if (languageScope == null) { + if (other.languageScope != null) + return false; + } else if (!languageScope.equals(other.languageScope)) + return false; + + if (properties == null) { + if (other.properties != null) + return false; + } else if (other.properties == null) { + return false; + } else { + // The trouble to ensure default properties are equal to missing ones. + Set keys = new HashSet(properties.keySet()); + keys.addAll(other.properties.keySet()); + for (String key : keys) { + String value = properties.get(key); + if (value == null) + value = ""; //$NON-NLS-1$ + String otherValue = other.properties.get(key); + if (otherValue == null) + otherValue = ""; //$NON-NLS-1$ + if (!value.equals(otherValue)) + return false; + } + } + + return true; + } + } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableProvider.java index 577de48e4a7..4181602f573 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableProvider.java @@ -306,9 +306,9 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr if (!key.equals(ATTR_ID) && !key.equals(ATTR_NAME) && !key.equals(ATTR_CLASS)) { String value = attr.getNodeValue(); properties.put(key, value); + } } } - } this.setId(providerId); this.setName(providerName); @@ -336,6 +336,12 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr /** * Set a custom property of the provider. + *

    + * A note of caution - do not use default values for a provider which are different + * from empty or {@code null} value. When providers are checked for equality + * (during internal operations in core) the missing properties are evaluated as + * empty ones. + * * @see LanguageSettingsBaseProvider#getProperty(String) * * @param key - name of the property. @@ -343,10 +349,23 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr * If value is {@code null} the property is removed from the list. */ public void setProperty(String key, String value) { - if (value != null) { - properties.put(key, value); + properties.put(key, value); + } + + /** + * Set a custom boolean property of the provider. + *
    Please, note that default value is always {@code false}. + * @see LanguageSettingsBaseProvider#getProperty(String) + * + * @param key - name of the property. + * @param value - {@code boolean} value of the property. + */ + public void setPropertyBool(String key, boolean value) { + if (value == true) { + properties.put(key, Boolean.TRUE.toString()); } else { - properties.remove(key); + // Keep "false" values in default representation and preserve the key in the list + properties.put(key, null); } } @@ -382,69 +401,6 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr return clone; } - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((getId() == null) ? 0 : getId().hashCode()); - result = prime * result + ((getName() == null) ? 0 : getName().hashCode()); - result = prime * result + ((languageScope == null) ? 0 : languageScope.hashCode()); - result = prime * result + ((properties == null) ? 0 : properties.hashCode()); - result = prime * result + ((fStorage == null) ? 0 : fStorage.hashCode()); - result = prime * result + getClass().hashCode(); - return result; - } - - /** - * @return {@code true} if the objects are equal, {@code false } otherwise. - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - LanguageSettingsSerializableProvider other = (LanguageSettingsSerializableProvider) obj; - - String id = getId(); - String otherId = other.getId(); - if (id == null) { - if (otherId != null) - return false; - } else if (!id.equals(otherId)) - return false; - - String name = getName(); - String otherName = other.getName(); - if (name == null) { - if (otherName != null) - return false; - } else if (!name.equals(otherName)) - return false; - - if (languageScope == null) { - if (other.languageScope != null) - return false; - } else if (!languageScope.equals(other.languageScope)) - return false; - - if (properties == null) { - if (other.properties != null) - return false; - } else if (!properties.equals(other.properties)) - return false; - - if (fStorage == null) { - if (other.fStorage != null) - return false; - } else if (!fStorage.equals(other.fStorage)) - return false; - return true; - } - @Override public LanguageSettingsStorage copyStorage() { try { @@ -454,4 +410,30 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr } return null; } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((fStorage == null) ? 0 : fStorage.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + LanguageSettingsSerializableProvider other = (LanguageSettingsSerializableProvider) obj; + + if (fStorage == null) { + if (other.fStorage != null) + return false; + } else if (!fStorage.equals(other.fStorage)) + return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java index 2d372443911..2919a0153f8 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java @@ -83,10 +83,7 @@ public class LanguageSettingsProvidersSerializer { private static final String ELEM_PROJECT = "project"; //$NON-NLS-1$ private static final String ELEM_CONFIGURATION = "configuration"; //$NON-NLS-1$ private static final String ELEM_PROVIDER_REFERENCE = "provider-reference"; //$NON-NLS-1$ - - private static final String ATTR_STORE_ENTRIES = "store-entries"; //$NON-NLS-1$ - private static final String VALUE_WORKSPACE = "workspace"; //$NON-NLS-1$ - private static final String VALUE_PROJECT = "project"; //$NON-NLS-1$ + private static final String ATTR_STORE_ENTRIES_WITH_PROJECT = "store-entries-with-project"; //$NON-NLS-1$ /** Cache of true (raw) workspace providers */ private static Map rawGlobalWorkspaceProviders = new HashMap(); @@ -284,8 +281,7 @@ public class LanguageSettingsProvidersSerializer { * @return {@code true} if LSE persisted with the project or {@code false} if in the workspace. */ public static boolean isStoringEntriesInProjectArea(LanguageSettingsSerializableProvider provider) { - String value = provider.getProperty(ATTR_STORE_ENTRIES); - return VALUE_PROJECT.equals(value); + return provider.getPropertyBool(ATTR_STORE_ENTRIES_WITH_PROJECT); } /** @@ -296,7 +292,7 @@ public class LanguageSettingsProvidersSerializer { * {@code false} if in workspace area. */ public static void setStoringEntriesInProjectArea(LanguageSettingsSerializableProvider provider, boolean storeEntriesWithProject) { - provider.setProperty(ATTR_STORE_ENTRIES, storeEntriesWithProject ? VALUE_PROJECT : VALUE_WORKSPACE); + provider.setPropertyBool(ATTR_STORE_ENTRIES_WITH_PROJECT, storeEntriesWithProject); } /** From 70d4b2a2a824a351aa4a0c90139ef773b8471609 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Mon, 19 Dec 2011 18:11:44 -0500 Subject: [PATCH 103/120] relative paths attribute changed to boolean ("keep-relative-paths") --- .../make/scannerdiscovery/GCCBuildCommandParserTest.java | 4 ++-- .../AbstractLanguageSettingsOutputScanner.java | 8 ++++---- .../settings/providers/LanguageSettingsBaseProvider.java | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java index 97f2c2aa706..2311d864dfa 100644 --- a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java +++ b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java @@ -68,7 +68,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { // those attributes must match that in AbstractBuildCommandParser private static final String ATTR_PARAMETER = "parameter"; //$NON-NLS-1$ - private static final String ATTR_EXPAND_RELATIVE_PATHS = "expand-relative-paths"; //$NON-NLS-1$ + private static final String ATTR_KEEP_RELATIVE_PATHS = "keep-relative-paths"; //$NON-NLS-1$ private class MockBuildCommandParser extends AbstractBuildCommandParser implements Cloneable { @Override @@ -266,7 +266,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { elementProvider = parser.serialize(rootElement); String xmlString = XmlUtil.toString(doc); - assertTrue(xmlString.contains(ATTR_EXPAND_RELATIVE_PATHS)); + assertTrue(xmlString.contains(ATTR_KEEP_RELATIVE_PATHS)); } { // create another instance of the provider diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java index 074b1016438..9bdd97718cf 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java @@ -61,7 +61,7 @@ import org.w3c.dom.Element; */ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSettingsSerializableProvider { - protected static final String ATTR_EXPAND_RELATIVE_PATHS = "expand-relative-paths"; //$NON-NLS-1$ + protected static final String ATTR_KEEP_RELATIVE_PATHS = "keep-relative-paths"; //$NON-NLS-1$ protected ICConfigurationDescription currentCfgDescription = null; protected IProject currentProject = null; @@ -834,7 +834,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett @Override public Element serializeAttributes(Element parentElement) { Element elementProvider = super.serializeAttributes(parentElement); - elementProvider.setAttribute(ATTR_EXPAND_RELATIVE_PATHS, Boolean.toString(isResolvingPaths)); + elementProvider.setAttribute(ATTR_KEEP_RELATIVE_PATHS, Boolean.toString( ! isResolvingPaths )); return elementProvider; } @@ -842,9 +842,9 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett public void loadAttributes(Element providerNode) { super.loadAttributes(providerNode); - String expandRelativePathsValue = XmlUtil.determineAttributeValue(providerNode, ATTR_EXPAND_RELATIVE_PATHS); + String expandRelativePathsValue = XmlUtil.determineAttributeValue(providerNode, ATTR_KEEP_RELATIVE_PATHS); if (expandRelativePathsValue!=null) - isResolvingPaths = Boolean.parseBoolean(expandRelativePathsValue); + isResolvingPaths = ! Boolean.parseBoolean(expandRelativePathsValue); } @Override diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsBaseProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsBaseProvider.java index 76a1b3fc8e7..f0c5c5181cb 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsBaseProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsBaseProvider.java @@ -164,7 +164,7 @@ public class LanguageSettingsBaseProvider extends AbstractExecutableExtensionBas if (entries != null) { return LanguageSettingsStorage.getPooledList(entries); } - return LanguageSettingsStorage.getPooledEmptyList(); + return null; } /** From 424d15432eca8a0fe1985d5d497affcc49363e63 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Mon, 19 Dec 2011 18:38:11 -0500 Subject: [PATCH 104/120] Got rid of spurious wrench overlay for workspace provider when no such extension exist. --- .../settings/providers/LanguageSettingsManager.java | 9 +++++++++ .../settings/providers/LanguageSettingsProviderTab.java | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java index 64554799e38..e5e91863565 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.core.language.settings.providers; import java.util.ArrayList; import java.util.List; +import java.util.Set; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.model.ILanguage; @@ -140,6 +141,14 @@ public class LanguageSettingsManager { return LanguageSettingsExtensionManager.getProviderCopy(provider, deep); } + /** + * Returns list of provider id-s contributed by all extensions. + * @return the provider id-s. + */ + public static Set getExtensionProviderIds() { + return LanguageSettingsExtensionManager.getExtensionProviderIds(); + } + /** * Get language settings provider defined via extension point * {@code org.eclipse.cdt.core.LanguageSettingsProvider}. diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java index 21f7cbcebe9..81086f767c1 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java @@ -159,7 +159,8 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { private static boolean isReconfigured(ILanguageSettingsProvider provider) { if (provider instanceof ILanguageSettingsEditableProvider) { - return ! LanguageSettingsManager.isEqualExtensionProvider(provider, false); + return (LanguageSettingsManager.getExtensionProviderIds().contains(provider.getId()) && + ! LanguageSettingsManager.isEqualExtensionProvider(provider, false)); } return false; } From aa67c9cce30fe915fd8ac793aaafaa3cf51b4801 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Mon, 19 Dec 2011 23:26:18 -0500 Subject: [PATCH 105/120] Count "false" as a default value for boolean properties --- .../BuiltinSpecsDetectorTest.java | 2 +- .../GCCBuildCommandParserTest.java | 2 +- .../LanguageSettingsExtensionsTests.java | 59 +++++++++++++++++-- .../LanguageSettingsBaseProvider.java | 15 +++-- .../LanguageSettingsSerializableProvider.java | 7 +-- 5 files changed, 68 insertions(+), 17 deletions(-) diff --git a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/BuiltinSpecsDetectorTest.java b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/BuiltinSpecsDetectorTest.java index 10db27a4541..9df20514395 100644 --- a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/BuiltinSpecsDetectorTest.java +++ b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/BuiltinSpecsDetectorTest.java @@ -154,7 +154,7 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { assertEquals(PROVIDER_NAME, provider.getName()); assertEquals(null, provider.getLanguageScope()); assertEquals(null, provider.getSettingEntries(null, null, null)); - assertEquals(null, provider.getCommand()); + assertEquals("", provider.getCommand()); assertEquals(false, provider.isExecuted()); assertEquals(false, provider.isConsoleEnabled()); } diff --git a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java index 2311d864dfa..295916b3fbf 100644 --- a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java +++ b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCBuildCommandParserTest.java @@ -175,7 +175,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { assertEquals(PROVIDER_NAME, provider.getName()); assertEquals(null, provider.getLanguageScope()); assertEquals(null, provider.getSettingEntries(null, null, null)); - assertEquals(null, provider.getCompilerPattern()); + assertEquals("", provider.getCompilerPattern()); } { diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java index e3bf7ecf40b..e3d52720616 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java @@ -12,7 +12,9 @@ package org.eclipse.cdt.core.language.settings.providers; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import junit.framework.TestSuite; @@ -133,9 +135,9 @@ public class LanguageSettingsExtensionsTests extends BaseTestCase { assertEquals(EXTENSION_BASE_PROVIDER_NAME, provider.getName()); assertEquals(EXTENSION_BASE_PROVIDER_PARAMETER, provider.getProperty(EXTENSION_BASE_PROVIDER_ATTR_PARAMETER)); // these attributes are not exposed as properties - assertEquals(null, provider.getProperty(ATTR_ID)); - assertEquals(null, provider.getProperty(ATTR_NAME)); - assertEquals(null, provider.getProperty(ATTR_CLASS)); + assertEquals("", provider.getProperty(ATTR_ID)); + assertEquals("", provider.getProperty(ATTR_NAME)); + assertEquals("", provider.getProperty(ATTR_CLASS)); // attempt to get entries for wrong language assertNull(provider.getSettingEntries(null, FILE_0, LANG_ID)); @@ -247,6 +249,55 @@ public class LanguageSettingsExtensionsTests extends BaseTestCase { } } + /** + * TODO + */ + public void testBaseProviderConfigure() throws Exception { + // sample entries + List entries = new ArrayList(); + entries.add(new CIncludePathEntry("/usr/include/", 0)); + List languages = new ArrayList(); + languages.add(LANG_ID); + // create LanguageSettingsBaseProvider + LanguageSettingsBaseProvider provider1 = new LanguageSettingsBaseProvider(); + LanguageSettingsBaseProvider provider2 = new LanguageSettingsBaseProvider(); + { + // configure provider1 + Map properties = new HashMap(); + properties.put("key1", "value1"); + properties.put("key2", null); + properties.put("key3", ""); + properties.put("key4", "false"); + provider1.configureProvider(PROVIDER_0, PROVIDER_NAME_0, languages, entries, properties); + assertEquals(PROVIDER_0, provider1.getId()); + assertEquals(PROVIDER_NAME_0, provider1.getName()); + assertEquals(languages, provider1.getLanguageScope()); + assertEquals(entries, provider1.getSettingEntries(null, null, LANG_ID)); + assertEquals("value1", provider1.getProperty("key1")); + assertEquals("", provider1.getProperty("key2")); + assertEquals("", provider1.getProperty("key3")); + assertEquals("false", provider1.getProperty("key4")); + assertEquals(false, provider1.getPropertyBool("key4")); + assertEquals("", provider1.getProperty("keyX")); + assertEquals(false, provider1.getPropertyBool("keyX")); + } + { + // configure provider2 + Map properties = new HashMap(); + properties.put("key1", "value1"); + provider2.configureProvider(PROVIDER_0, PROVIDER_NAME_0, languages, entries, properties); + assertEquals(PROVIDER_0, provider2.getId()); + assertEquals(PROVIDER_NAME_0, provider2.getName()); + assertEquals(languages, provider2.getLanguageScope()); + assertEquals(entries, provider2.getSettingEntries(null, null, LANG_ID)); + assertEquals("value1", provider2.getProperty("key1")); + assertEquals("", provider2.getProperty("keyX")); + assertEquals(false, provider2.getPropertyBool("keyX")); + } + // test equality + assertTrue(provider1.equals(provider2)); + } + /** * LanguageSettingsBaseProvider is not allowed to be configured twice. */ @@ -282,7 +333,7 @@ public class LanguageSettingsExtensionsTests extends BaseTestCase { LanguageSettingsSerializableProvider provider = (LanguageSettingsSerializableProvider) rawProvider; assertEquals(null, provider.getLanguageScope()); - assertEquals(null, provider.getProperty(EXTENSION_SERIALIZABLE_PROVIDER_MISSING_PARAMETER)); + assertEquals("", provider.getProperty(EXTENSION_SERIALIZABLE_PROVIDER_MISSING_PARAMETER)); List expected = new ArrayList(); expected.add(EXTENSION_EDITABLE_PROVIDER_ENTRY); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsBaseProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsBaseProvider.java index f0c5c5181cb..b66cafff9ff 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsBaseProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsBaseProvider.java @@ -143,10 +143,14 @@ public class LanguageSettingsBaseProvider extends AbstractExecutableExtensionBas * {@link #equals(Object)} evaluate the property as equal while comparing providers. * * @param key - property to check the value. - * @return value of the property. + * @return value of the property. If the property is missing returns empty string. */ public String getProperty(String key) { - return properties.get(key); + String value = properties.get(key); + if (value == null) { + value = ""; //$NON-NLS-1$ + } + return value; } /** @@ -154,7 +158,8 @@ public class LanguageSettingsBaseProvider extends AbstractExecutableExtensionBas * @see #getProperty(String) * * @param key - property to check the value. - * @return boolean value of the property. + * @return boolean value of the property. If the property is missing or cannot be + * interpreted as boolean returns {@code false}. */ public boolean getPropertyBool(String key) { return Boolean.parseBoolean(properties.get(key)); @@ -267,10 +272,10 @@ public class LanguageSettingsBaseProvider extends AbstractExecutableExtensionBas keys.addAll(other.properties.keySet()); for (String key : keys) { String value = properties.get(key); - if (value == null) + if (value == null || value.equals(Boolean.FALSE.toString())) value = ""; //$NON-NLS-1$ String otherValue = other.properties.get(key); - if (otherValue == null) + if (otherValue == null || otherValue.equals(Boolean.FALSE.toString())) otherValue = ""; //$NON-NLS-1$ if (!value.equals(otherValue)) return false; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableProvider.java index 4181602f573..235a1288e07 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsSerializableProvider.java @@ -361,12 +361,7 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr * @param value - {@code boolean} value of the property. */ public void setPropertyBool(String key, boolean value) { - if (value == true) { - properties.put(key, Boolean.TRUE.toString()); - } else { - // Keep "false" values in default representation and preserve the key in the list - properties.put(key, null); - } + properties.put(key, Boolean.toString(value)); } /** From 0847bf37d816467467bebf70013b7fbfd001184b Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Tue, 20 Dec 2011 09:59:13 -0500 Subject: [PATCH 106/120] More accurate check for resource existence accounting for variables. --- .../ui/newui/LanguageSettingsImages.java | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/LanguageSettingsImages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/LanguageSettingsImages.java index 32f06aad27a..dfe021368e6 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/LanguageSettingsImages.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/LanguageSettingsImages.java @@ -21,9 +21,9 @@ import org.eclipse.jface.viewers.IDecoration; import org.eclipse.swt.graphics.Image; import org.eclipse.cdt.core.settings.model.ACPathEntry; -import org.eclipse.cdt.core.settings.model.CMacroEntry; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICSettingEntry; +import org.eclipse.cdt.core.settings.model.util.CDataUtil; import org.eclipse.cdt.ui.CDTSharedImages; import org.eclipse.cdt.ui.CUIPlugin; @@ -47,18 +47,18 @@ public class LanguageSettingsImages { * Returns image for the given entry from internally managed repository including * necessary overlays. This method is shortcut for {@link #getImage(ICLanguageSettingEntry, String)} * when no project is available. - * + * * @param entry - language settings entry to get an image for. * @return the image for the entry with appropriate overlays. */ public static Image getImage(ICLanguageSettingEntry entry) { return getImage(entry, null); } - + /** * Returns image for the given entry from internally managed repository including * necessary overlays. - * + * * @param entry - language settings entry to get an image for. * @param projectName - pass project name if available. That lets to put "project" metaphor * on the image. Pass {@code null} if no project name is available. @@ -76,7 +76,7 @@ public class LanguageSettingsImages { if (imageKey!=null) { if ((entry.getFlags()&ICSettingEntry.UNDEFINED) == ICSettingEntry.UNDEFINED) return CDTSharedImages.getImageOverlaid(imageKey, CDTSharedImages.IMG_OVR_INACTIVE, IDecoration.BOTTOM_LEFT); - + if (entry instanceof ACPathEntry) { String overlayKey=null; IStatus status = getStatus(entry); @@ -105,7 +105,7 @@ public class LanguageSettingsImages { // have to trust paths which contain variables if (entry.getName().contains("${")) //$NON-NLS-1$ return true; - + boolean exists = true; boolean isWorkspacePath = (entry.getFlags() & ICSettingEntry.VALUE_WORKSPACE_PATH) != 0; if (isWorkspacePath) { @@ -119,17 +119,25 @@ public class LanguageSettingsImages { } return exists; } - + /** * Defines status object for the status message line. - * + * * @param entry - the entry to check status on. * @return a status object defining severity and message. */ public static IStatus getStatus(ICLanguageSettingEntry entry) { if (entry instanceof ACPathEntry) { + if (!entry.isResolved()) { + ICLanguageSettingEntry[] entries = CDataUtil.resolveEntries(new ICLanguageSettingEntry[] {entry}, null); + if (entries != null && entries.length > 0) { + entry = entries[0]; + } + + } ACPathEntry acEntry = (ACPathEntry)entry; - IPath path = new Path(acEntry.getName()); + String acEntryName = acEntry.getName(); + IPath path = new Path(acEntryName); if (!path.isAbsolute()) { String msg = "Using relative paths is ambiguous and not recommended. It can cause unexpected side-effects."; return new Status(IStatus.INFO, CUIPlugin.PLUGIN_ID, msg); @@ -142,7 +150,7 @@ public class LanguageSettingsImages { msg = "The selected folder does not exist or not accessible."; return new Status(IStatus.WARNING, CUIPlugin.PLUGIN_ID, msg); } - + } return Status.OK_STATUS; } From 8b235273b5d85dd4eeeaf4bde01931b89e9ec885 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Tue, 20 Dec 2011 11:35:36 -0500 Subject: [PATCH 107/120] Scanner info provider to supply scanner info for headers --- .../settings/providers/LanguageSettingsManager.java | 11 ++++++++--- .../LanguageSettingsScannerInfoProvider.java | 4 ++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java index e5e91863565..9307b98b811 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java @@ -229,14 +229,19 @@ public class LanguageSettingsManager { if (resource instanceof IFile) { String langId = null; if (cfgDescription != null) { + // Inquire MBS ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(prjRelPath, true); if (ls != null) { langId = ls.getLanguageId(); } - } else { + } + if (langId == null) { + // Try getting language from content types try { - ILanguage lang = LanguageManager.getInstance().getLanguageForFile((IFile) resource, null); - langId = lang.getId(); + ILanguage lang = LanguageManager.getInstance().getLanguageForFile((IFile) resource, cfgDescription); + if (lang != null) { + langId = lang.getId(); + } } catch (CoreException e) { CCorePlugin.log(e); } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsScannerInfoProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsScannerInfoProvider.java index 56016322ae1..537353c0c3f 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsScannerInfoProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsScannerInfoProvider.java @@ -34,7 +34,6 @@ 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.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; @@ -70,7 +69,8 @@ public class LanguageSettingsScannerInfoProvider implements IScannerInfoProvider List languageIds = LanguageSettingsManager.getLanguages(rc, cfgDescription); if (languageIds.isEmpty()) { String msg = NLS.bind(SettingsModelMessages.getString("LanguageSettingsScannerInfoProvider.UnableToDetermineLanguage"), rc.toString()); //$NON-NLS-1$ - CCorePlugin.log(new CoreException(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, msg))); + IStatus status = new Status(IStatus.WARNING, CCorePlugin.PLUGIN_ID, msg, new Exception()); + CCorePlugin.log(status); return DUMMY_SCANNER_INFO; } From 00e199b8e755d74d273c56cca8ad85284513f869 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Tue, 20 Dec 2011 14:17:34 -0500 Subject: [PATCH 108/120] Fixed spurious wrench decorations on headers in Project Explorer --- .../internal/scannerconfig/MBSLanguageSettingsProvider.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/MBSLanguageSettingsProvider.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/MBSLanguageSettingsProvider.java index 36577281e90..5540b00958f 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/MBSLanguageSettingsProvider.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/MBSLanguageSettingsProvider.java @@ -42,6 +42,8 @@ public class MBSLanguageSettingsProvider extends AbstractExecutableExtensionBase ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(projectPath, true); if (ls != null) { languageSettings = new ICLanguageSetting[] {ls}; + } else { + return getSettingEntries(cfgDescription, rc.getParent(), languageId); } } else { ICResourceDescription rcDescription = cfgDescription.getResourceDescription(projectPath, false); From ae99178c470ff71830cb2b5dd70f94e535c8f139 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Fri, 23 Dec 2011 12:48:40 -0500 Subject: [PATCH 109/120] Revert "Removed "Shared provider" checkbox from UI." --- .../LanguageSettingsProviderTab.java | 62 ++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java index 81086f767c1..fb56c8fb081 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java @@ -117,6 +117,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { private Button enableProvidersCheckBox; private StatusMessageLine fStatusLine; + private Button globalProviderCheckBox = null; private Link linkWorkspacePreferences = null; private Button projectStorageCheckBox = null; @@ -356,6 +357,37 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { return link; } + // Called from globalProviderCheckBox listener + private ILanguageSettingsProvider toggleGlobalProvider(ILanguageSettingsProvider oldProvider, boolean toGlobal) { + ILanguageSettingsProvider newProvider = null; + + String id = oldProvider.getId(); + if (toGlobal) { + newProvider = LanguageSettingsManager.getWorkspaceProvider(id); + } else { + // Local provider instance chosen + try { + ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(oldProvider); + if (rawProvider instanceof ILanguageSettingsEditableProvider) { + newProvider = ((ILanguageSettingsEditableProvider) rawProvider).cloneShallow(); + } + } catch (CloneNotSupportedException e) { + CUIPlugin.log("Error cloning provider " + oldProvider.getId(), e); + } + } + if (newProvider!=null) { + replaceSelectedProvider(newProvider); + + ICConfigurationDescription cfgDescription = getConfigurationDescription(); + initializeOptionsPage(newProvider, cfgDescription); + displaySelectedOptionPage(); + } else { + newProvider = oldProvider; + } + + return newProvider; + } + private void replaceSelectedProvider(ILanguageSettingsProvider newProvider) { int pos = tableProviders.getSelectionIndex(); presentedProviders.set(pos, newProvider); @@ -388,6 +420,29 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { groupOptionsPage.setLayout(new GridLayout(2, false)); if (!page.isForPrefs()) { + if (globalProviderCheckBox==null) { + globalProviderCheckBox = new Button(groupOptionsPage, SWT.CHECK); + globalProviderCheckBox.setText("Share setting entries between projects (global provider)"); + globalProviderCheckBox.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + boolean isGlobal = globalProviderCheckBox.getSelection(); + ILanguageSettingsProvider provider = getSelectedProvider(); + if (isGlobal != LanguageSettingsManager.isWorkspaceProvider(provider)) { + provider = toggleGlobalProvider(provider, isGlobal); + } + projectStorageCheckBox.setSelection(provider instanceof LanguageSettingsSerializableProvider + && LanguageSettingsManager.isStoringEntriesInProjectArea((LanguageSettingsSerializableProvider) provider)); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + widgetSelected(e); + } + + }); + } + if (projectStorageCheckBox == null) { projectStorageCheckBox = new Button(groupOptionsPage, SWT.CHECK); projectStorageCheckBox.setText("Store entries in project settings folder (easing project miration)"); @@ -576,6 +631,11 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { boolean isChecked = tableProvidersViewer.getChecked(provider); if (!page.isForPrefs()) { + boolean isRawProviderEditable = rawProvider instanceof ILanguageSettingsEditableProvider; + globalProviderCheckBox.setSelection(isGlobal); + globalProviderCheckBox.setEnabled(isChecked && isRawProviderEditable); + globalProviderCheckBox.setVisible(provider!=null); + projectStorageCheckBox.setEnabled(!isGlobal); projectStorageCheckBox.setVisible(rawProvider instanceof LanguageSettingsSerializableProvider); projectStorageCheckBox.setSelection(provider instanceof LanguageSettingsSerializableProvider @@ -583,7 +643,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { boolean needPreferencesLink=isGlobal && currentOptionsPage!=null; // TODO: message - final String linkMsg = needPreferencesLink ? "Options of shared providers below can be changed in Workspace Settings, Discovery Tab." : ""; + final String linkMsg = needPreferencesLink ? "Options of global providers below can be changed in Workspace Settings, Discovery Tab." : ""; linkWorkspacePreferences.setText(linkMsg); linkWorkspacePreferences.pack(); linkWorkspacePreferences.setEnabled(isChecked); From a1309d817da06a999c08ce86129e974c31f98aef Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Fri, 6 Jan 2012 12:38:16 -0500 Subject: [PATCH 110/120] remove obsolete image --- .../org.eclipse.cdt.ui/icons/obj16/frameworks.gif | Bin 904 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 core/org.eclipse.cdt.ui/icons/obj16/frameworks.gif diff --git a/core/org.eclipse.cdt.ui/icons/obj16/frameworks.gif b/core/org.eclipse.cdt.ui/icons/obj16/frameworks.gif deleted file mode 100644 index 82261154cd7c7ceed81927f8628ba401f6b531af..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 904 zcmcK3)k0bU007X7q9PWGEe5vO-Hn8b-Q8k$H`v|X-HF{|w_^96_OKtAFLU!FcK+dD z@faOle;5D*e*OUd0f9htbaeFe^k6WUfq{XMk&%gs2?BvIGc!Y>P!<*zR#sLvHa2#4 zb`A~>7!1bA$;rjV1&71Axw(0GczAhv`S|$w`S}F|1Ox>Ig@l9<2!yb(u!x9=sHmuz zm>3d?6c-nlkdTm+l$4T^l9ra1k&%&=m6el|L!nUe^70A_3W|z~N=iz~%E~G#Dypig zYHDig>gpOA8k(A#T3TA#+S)ogI=Z^LdU|^L`uYY228M=)Mn*=)#>OTlCZ?vQW@cvQ z=H_TL+QPyDgTY|2SR4+A$Kx$6Ev>AqtgWpH1cHr?jjgS%ot>S%y}g5jgQKIPlarIP zv$Knfi>s@vo12@vySs;nho`5fmzS5fx3`avkFT$+3kweqkBEqfjEszmii(boj){qhjg5_qi;ItsPe@2eOiWBlN=i;nPDx2g zO-)TpOG{5r&&bHg%*@Qn%F52p&dJHi&CSir%OjCUWHLEFKfj=$ps=v8sHmv8xVWUG zq_niOtgNiOyu6~KqO!8Gs;a8Gy1J&Orna`WuCA`WzP_QMp|P>Csi~>Cxw)mKrM0!S zt*x!Sy}hHOqqDQKtE;QKySt~Sr?+5S8jdpW$b9;MxcXxMxfB*3C@c8)n^z`)n{QUCr^7{Jv_V)Jv{{Hdt z@%29;KfxdX_yQEZCw!j(Ai=;FGXgi=y-kL|QC`25YpFPvUnX$KgpC>Il0Pg69nps& zm2np$h&ZGoseqA0qs|VT Date: Sun, 8 Jan 2012 16:13:45 -0500 Subject: [PATCH 111/120] bug 312165: Viewers should clearly indicate whether a folder is excluded from build Conflicts: core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/ExcludedFileDecorator.java --- core/org.eclipse.cdt.ui/plugin.properties | 4 ++-- core/org.eclipse.cdt.ui/plugin.xml | 5 +++- .../ui/viewsupport/ExcludedFileDecorator.java | 23 +++++++++++-------- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/core/org.eclipse.cdt.ui/plugin.properties b/core/org.eclipse.cdt.ui/plugin.properties index 141eebb83c7..e6800126b9e 100644 --- a/core/org.eclipse.cdt.ui/plugin.properties +++ b/core/org.eclipse.cdt.ui/plugin.properties @@ -598,8 +598,8 @@ ShiftLeftAction.label= S&hift Left # Decorators indexedFilesDecorator.label = C/C++ Indexed Files indexedFilesDecorator.description = Decorates files indexed by C/C++ Indexer. -excludedFile.name = C/C++ Files Excluded from Build -excludedFile.description = Decorates source files excluded from C/C++ build. +excludedFile.name = C/C++ Files and Folders Excluded from Build +excludedFile.description = Decorates source files and folders excluded from C/C++ build. includeFolderDecorator.name = C/C++ Missing Include Folders includeFolderDecorator.description = Decorates missing include folders with error/warning indicator. diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml index 920a027106d..1638e390596 100644 --- a/core/org.eclipse.cdt.ui/plugin.xml +++ b/core/org.eclipse.cdt.ui/plugin.xml @@ -4072,7 +4072,10 @@ state="true"> %excludedFile.description - + + + + Date: Mon, 23 Jan 2012 17:42:11 -0500 Subject: [PATCH 112/120] Serialization of default providers --- build/org.eclipse.cdt.make.core/plugin.xml | 3 +- build/org.eclipse.cdt.make.ui/plugin.xml | 2 - .../tests/suite/AllManagedBuildTests.java | 8 +- .../AllLanguageSettingsProvidersMBSTests.java | 3 +- .../LanguageSettingsProvidersMBSTest.java | 173 ++++++++++++ .../META-INF/MANIFEST.MF | 1 + .../managedbuilder/core/IConfiguration.java | 9 +- .../internal/core/Configuration.java | 69 ++++- .../internal/core/MultiConfiguration.java | 2 +- .../internal/core/ToolChain.java | 9 +- .../ConfigurationDataProvider.java | 72 ++++- .../ui/tests/util/TestConfiguration.java | 2 +- .../plugin.xml | 1 - .../ui/wizards/MBSWizardHandler.java | 102 +------ .../ui/wizards/NewMakeProjFromExisting.java | 10 +- .../ui/wizards/STDWizardHandler.java | 15 +- .../LanguageSettingsExtensionsTests.java | 3 + .../LanguageSettingsManagerTests.java | 21 +- ...nguageSettingsPersistenceProjectTests.java | 229 ++++++++++++++- core/org.eclipse.cdt.core.tests/plugin.xml | 6 +- .../cdt/core/testplugin/ResourceHelper.java | 67 ++++- .../ILanguageSettingsProvidersKeeper.java | 21 +- .../providers/LanguageSettingsManager.java | 22 +- .../LanguageSettingsSerializableProvider.java | 2 +- .../ScannerDiscoveryLegacySupport.java | 8 +- .../LanguageSettingsExtensionManager.java | 21 +- .../LanguageSettingsProvidersSerializer.java | 266 ++++++++++++++---- .../model/CConfigurationDescription.java | 22 +- .../model/CConfigurationDescriptionCache.java | 12 + .../model/CConfigurationSpecSettings.java | 21 +- .../xml/XmlProjectDescriptionStorage.java | 2 +- .../schema/LanguageSettingsProvider.exsd | 8 + core/org.eclipse.cdt.ui/plugin.xml | 4 +- .../LanguageSettingsProviderAssociation.exsd | 14 - ...ageSettingsProviderAssociationManager.java | 13 - .../LanguageSettingsProviderTab.java | 6 +- .../plugin.xml | 3 +- 37 files changed, 974 insertions(+), 278 deletions(-) create mode 100644 build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/LanguageSettingsProvidersMBSTest.java diff --git a/build/org.eclipse.cdt.make.core/plugin.xml b/build/org.eclipse.cdt.make.core/plugin.xml index ecdb0eb306f..9082042153d 100644 --- a/build/org.eclipse.cdt.make.core/plugin.xml +++ b/build/org.eclipse.cdt.make.core/plugin.xml @@ -188,7 +188,8 @@ class="org.eclipse.cdt.make.internal.core.scannerconfig.GCCBuildCommandParser" id="org.eclipse.cdt.make.core.build.command.parser.gcc" name="CDT GCC Build Output Parser" - parameter="(gcc)|([gc]\+\+)"> + parameter="(gcc)|([gc]\+\+)" + prefer-non-shared="true"> diff --git a/build/org.eclipse.cdt.make.ui/plugin.xml b/build/org.eclipse.cdt.make.ui/plugin.xml index 198ae158db7..df3f6cc3161 100644 --- a/build/org.eclipse.cdt.make.ui/plugin.xml +++ b/build/org.eclipse.cdt.make.ui/plugin.xml @@ -546,7 +546,6 @@ class="org.eclipse.cdt.make.core.scannerconfig.AbstractBuildCommandParser" icon="icons/obj16/log_obj.gif" page="org.eclipse.cdt.make.internal.ui.preferences.GCCBuildCommandParserOptionPage" - shared="false" ui-clear-entries="true" ui-edit-entries="false"> @@ -554,7 +553,6 @@ class="org.eclipse.cdt.make.core.scannerconfig.AbstractBuiltinSpecsDetector" icon="icons/obj16/inspect_system.gif" page="org.eclipse.cdt.make.internal.ui.scannerconfig.BuiltinSpecsDetectorOptionPage" - shared="true" ui-clear-entries="true" ui-edit-entries="false"> diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/tests/suite/AllManagedBuildTests.java b/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/tests/suite/AllManagedBuildTests.java index 72153c409f0..d777ca64be8 100644 --- a/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/tests/suite/AllManagedBuildTests.java +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/tests/suite/AllManagedBuildTests.java @@ -4,7 +4,7 @@ * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html - * + * * Contributors: * IBM - Initial API and implementation * Markus Schorn (Wind River Systems) @@ -15,8 +15,8 @@ package org.eclipse.cdt.managedbuilder.tests.suite; import junit.framework.Test; import junit.framework.TestSuite; +import org.eclipse.cdt.build.core.scannerconfig.tests.AllLanguageSettingsProvidersMBSTests; import org.eclipse.cdt.build.core.scannerconfig.tests.CfgScannerConfigProfileManagerTests; -import org.eclipse.cdt.build.core.scannerconfig.tests.GCCBuiltinSpecsDetectorTest; import org.eclipse.cdt.build.core.scannerconfig.tests.GCCSpecsConsoleParserTest; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.IPDOMManager; @@ -61,7 +61,9 @@ public class AllManagedBuildTests { // build.core.scannerconfig.tests suite.addTest(CfgScannerConfigProfileManagerTests.suite()); suite.addTestSuite(GCCSpecsConsoleParserTest.class); - suite.addTestSuite(GCCBuiltinSpecsDetectorTest.class); + + // language settings providers tests + suite.addTest(AllLanguageSettingsProvidersMBSTests.suite()); // managedbuilder.core.tests suite.addTest(ManagedBuildDependencyLibsTests.suite()); diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/AllLanguageSettingsProvidersMBSTests.java b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/AllLanguageSettingsProvidersMBSTests.java index c521b01d261..943ce675ad9 100644 --- a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/AllLanguageSettingsProvidersMBSTests.java +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/AllLanguageSettingsProvidersMBSTests.java @@ -11,8 +11,6 @@ package org.eclipse.cdt.build.core.scannerconfig.tests; -import org.eclipse.cdt.build.core.scannerconfig.tests.GCCBuiltinSpecsDetectorTest; - import junit.framework.TestSuite; public class AllLanguageSettingsProvidersMBSTests extends TestSuite { @@ -24,6 +22,7 @@ public class AllLanguageSettingsProvidersMBSTests extends TestSuite { public AllLanguageSettingsProvidersMBSTests() { super(AllLanguageSettingsProvidersMBSTests.class.getName()); + addTestSuite(LanguageSettingsProvidersMBSTest.class); addTestSuite(GCCBuiltinSpecsDetectorTest.class); } } diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/LanguageSettingsProvidersMBSTest.java b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/LanguageSettingsProvidersMBSTest.java new file mode 100644 index 00000000000..40e95796671 --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/LanguageSettingsProvidersMBSTest.java @@ -0,0 +1,173 @@ +/******************************************************************************* + * Copyright (c) 2010, 2012 Andrew Gvozdev and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andrew Gvozdev - Initial API and implementation + *******************************************************************************/ + package org.eclipse.cdt.build.core.scannerconfig.tests; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvidersKeeper; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsPersistenceProjectTests; +import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySupport; +import org.eclipse.cdt.core.model.CoreModel; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICProjectDescription; +import org.eclipse.cdt.core.testplugin.util.BaseTestCase; +import org.eclipse.cdt.managedbuilder.core.IConfiguration; +import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; +import org.eclipse.cdt.managedbuilder.internal.dataprovider.ConfigurationDataProvider; +import org.eclipse.cdt.managedbuilder.testplugin.ManagedBuildTestHelper; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; + +public class LanguageSettingsProvidersMBSTest extends BaseTestCase { + private static final String MBS_LANGUAGE_SETTINGS_PROVIDER_ID = ScannerDiscoveryLegacySupport.MBS_LANGUAGE_SETTINGS_PROVIDER_ID; + private static final String USER_LANGUAGE_SETTINGS_PROVIDER_ID = ScannerDiscoveryLegacySupport.USER_LANGUAGE_SETTINGS_PROVIDER_ID; + private static final String GCC_SPECS_DETECTOR_ID = "org.eclipse.cdt.managedbuilder.core.gcc.specs.detector"; + private static final String PROJECT_TYPE_EXECUTABLE_GNU = "cdt.managedbuild.target.gnu.exe"; + private static final String LANGUAGE_SETTINGS_PROJECT_XML = LanguageSettingsPersistenceProjectTests.LANGUAGE_SETTINGS_PROJECT_XML; + private static final String LANGUAGE_SETTINGS_WORKSPACE_XML = LanguageSettingsPersistenceProjectTests.LANGUAGE_SETTINGS_WORKSPACE_XML; + + @Override + protected void setUp() throws Exception { + super.setUp(); + } + + @Override + protected void tearDown() throws Exception { + ManagedBuildTestHelper.removeProject(this.getName()); + super.tearDown(); + } + + /** + * New Project Wizards do all these things + */ + private static IProject imitateNewProjectWizard(String name, String projectTypeId) throws CoreException { + IProject project = ManagedBuildTestHelper.createProject(name, projectTypeId); + ManagedBuildTestHelper.addManagedBuildNature(project); + + ICProjectDescription prjDescription = CoreModel.getDefault().getProjectDescription(project, true); + assertNotNull(prjDescription); + ICConfigurationDescription[] cfgDescriptions = prjDescription.getConfigurations(); + for (ICConfigurationDescription cfgDescription : cfgDescriptions) { + assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); + + ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, true); + IConfiguration cfg = ManagedBuildManager.getConfigurationForDescription(cfgDescription); + ConfigurationDataProvider.setDefaultLanguageSettingsProviders(cfg, cfgDescription); + + assertTrue(((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders().size() > 0); + } + + CoreModel.getDefault().setProjectDescription(project, prjDescription); + + return project; + } + + /** + */ + public void testGnuToolchainProviders() throws Exception { + IProject project = imitateNewProjectWizard(this.getName(), PROJECT_TYPE_EXECUTABLE_GNU); + + ICProjectDescription prjDescription = CoreModel.getDefault().getProjectDescription(project, false); + assertNotNull(prjDescription); + ICConfigurationDescription[] cfgDescriptions = prjDescription.getConfigurations(); + for (ICConfigurationDescription cfgDescription : cfgDescriptions) { + assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); + + List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); + { + ILanguageSettingsProvider provider = providers.get(0); + String id = provider.getId(); + assertEquals(USER_LANGUAGE_SETTINGS_PROVIDER_ID, id); + assertEquals(false, LanguageSettingsManager.isPreferShared(id)); + assertEquals(false, LanguageSettingsManager.isWorkspaceProvider(provider)); + } + { + ILanguageSettingsProvider provider = providers.get(1); + String id = provider.getId(); + assertEquals(MBS_LANGUAGE_SETTINGS_PROVIDER_ID, id); + assertEquals(true, LanguageSettingsManager.isPreferShared(id)); + assertEquals(true, LanguageSettingsManager.isWorkspaceProvider(provider)); + } + { + ILanguageSettingsProvider provider = providers.get(2); + String id = provider.getId(); + assertEquals(GCC_SPECS_DETECTOR_ID, id); + assertEquals(true, LanguageSettingsManager.isPreferShared(id)); + assertEquals(true, LanguageSettingsManager.isWorkspaceProvider(provider)); + } + assertEquals(3, providers.size()); + } + } + + /** + */ + public void testProjectPersistence_NoProviders() throws Exception { + IProject project = imitateNewProjectWizard(this.getName(), PROJECT_TYPE_EXECUTABLE_GNU); + + ICProjectDescription prjDescription = CoreModel.getDefault().getProjectDescription(project, true); + assertNotNull(prjDescription); + ICConfigurationDescription[] cfgDescriptions = prjDescription.getConfigurations(); + for (ICConfigurationDescription cfgDescription : cfgDescriptions) { + assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); + + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(new ArrayList()); + assertTrue(((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders().size() == 0); + } + + CoreModel.getDefault().setProjectDescription(project, prjDescription); + + IFile xmlStorageFile = project.getFile(LANGUAGE_SETTINGS_PROJECT_XML); + assertEquals(true, xmlStorageFile.exists()); + + String xmlPrjWspStorageFileLocation = LanguageSettingsPersistenceProjectTests.getStoreLocationInWorkspaceArea(project.getName()+'.'+LANGUAGE_SETTINGS_WORKSPACE_XML); + java.io.File xmlStorageFilePrjWsp = new java.io.File(xmlPrjWspStorageFileLocation); + assertEquals(false, xmlStorageFilePrjWsp.exists()); + + } + + /** + */ + public void testProjectPersistence_Defaults() throws Exception { + IProject project = imitateNewProjectWizard(this.getName(), PROJECT_TYPE_EXECUTABLE_GNU); + + ICProjectDescription prjDescription = CoreModel.getDefault().getProjectDescription(project, false); + assertNotNull(prjDescription); + ICConfigurationDescription[] cfgDescriptions = prjDescription.getConfigurations(); + for (ICConfigurationDescription cfgDescription : cfgDescriptions) { + assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); + + String[] defaultIds = ((ILanguageSettingsProvidersKeeper) cfgDescription).getDefaultLanguageSettingsProvidersIds(); + List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); + assertEquals(defaultIds.length, providers.size()); + for (int i = 0; i < defaultIds.length; i++) { + assertEquals(providers.get(i).getId(), defaultIds[i]); + } + assertTrue(defaultIds.length > 0); + } + + IFile xmlStorageFile = project.getFile(LANGUAGE_SETTINGS_PROJECT_XML); + assertEquals(false, xmlStorageFile.exists()); + assertEquals(false, xmlStorageFile.getParent().exists()); // .settings folder + + String xmlPrjWspStorageFileLocation = LanguageSettingsPersistenceProjectTests.getStoreLocationInWorkspaceArea(project.getName()+'.'+LANGUAGE_SETTINGS_WORKSPACE_XML); + java.io.File xmlStorageFilePrjWsp = new java.io.File(xmlPrjWspStorageFileLocation); + assertEquals(false, xmlStorageFilePrjWsp.exists()); + } + +} diff --git a/build/org.eclipse.cdt.managedbuilder.core/META-INF/MANIFEST.MF b/build/org.eclipse.cdt.managedbuilder.core/META-INF/MANIFEST.MF index 363db3a759e..13c80711101 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/META-INF/MANIFEST.MF +++ b/build/org.eclipse.cdt.managedbuilder.core/META-INF/MANIFEST.MF @@ -15,6 +15,7 @@ Export-Package: org.eclipse.cdt.build.core.scannerconfig, org.eclipse.cdt.managedbuilder.envvar, org.eclipse.cdt.managedbuilder.internal.buildmodel;x-friends:="org.eclipse.cdt.managedbuilder.ui", org.eclipse.cdt.managedbuilder.internal.core;x-friends:="org.eclipse.cdt.managedbuilder.ui", + org.eclipse.cdt.managedbuilder.internal.dataprovider;x-internal:=true, org.eclipse.cdt.managedbuilder.internal.envvar;x-internal:=true, org.eclipse.cdt.managedbuilder.internal.macros;x-friends:="org.eclipse.cdt.managedbuilder.ui", org.eclipse.cdt.managedbuilder.internal.scannerconfig;x-internal:=true, diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IConfiguration.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IConfiguration.java index b6227d36b36..8aba30dbfe9 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IConfiguration.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IConfiguration.java @@ -172,8 +172,13 @@ public interface IConfiguration extends IBuildObject, IBuildObjectPropertiesCont */ public String[] getErrorParserList(); - /** @since 8.1 */ - public String getDefaultLanguageSettingsProvidersIds(); + /** + * Returns default language settings providers IDs specified for the configuration. + * @return default language settings providers IDs. + * + * @since 8.1 + */ + public String[] getDefaultLanguageSettingsProvidersIds(); /** * Projects have C or CC natures. Tools can specify a filter so they are not diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java index c9316856981..7c2bb2ef3e0 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2011 IBM Corporation and others. + * Copyright (c) 2003, 2012 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -26,6 +26,7 @@ import java.util.Vector; import org.eclipse.cdt.build.core.scannerconfig.ICfgScannerConfigBuilderInfo2Set; import org.eclipse.cdt.build.internal.core.scannerconfig.CfgDiscoveredPathManager.PathInfoCache; +import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.ErrorParserManager; import org.eclipse.cdt.core.settings.model.CIncludePathEntry; import org.eclipse.cdt.core.settings.model.CLibraryFileEntry; @@ -86,8 +87,10 @@ import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResourceDelta; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; import org.eclipse.osgi.util.NLS; import org.osgi.framework.Version; @@ -95,6 +98,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild private static final String EMPTY_STRING = ""; //$NON-NLS-1$ private static final String EMPTY_CFG_ID = "org.eclipse.cdt.build.core.emptycfg"; //$NON-NLS-1$ + private static final String LANGUAGE_SETTINGS_PROVIDER_DELIMITER = ";"; //$NON-NLS-1$ // Parent and children private String parentId; @@ -105,7 +109,8 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild private String cleanCommand; private String artifactExtension; private String errorParserIds; - private String defaultLanguageSettingsProvidersIds; + private String defaultLanguageSettingsProvidersAttribute; + private String[] defaultLanguageSettingsProvidersIds; private String prebuildStep; private String postbuildStep; private String preannouncebuildStep; @@ -338,8 +343,8 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild if (parentConfig != null) { name = parentConfig.getName(); - // If this constructor is called to clone an existing - // configuration, the parent of the parent should be stored. + // If this constructor is called to clone an existing + // configuration, the parent of the parent should be stored. // As of 2.1, there is still one single level of inheritance to // worry about parent = parentConfig.getParent() == null ? parentConfig : parentConfig.getParent(); @@ -486,8 +491,8 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild // if(!baseCfg.isExtensionConfig) // cloneChildren = true; - // If this constructor is called to clone an existing - // configuration, the parent of the cloning config should be stored. + // If this constructor is called to clone an existing + // configuration, the parent of the cloning config should be stored. parent = baseCfg.isExtensionConfig || baseCfg.getParent() == null ? baseCfg : baseCfg.getParent(); // Copy the remaining attributes @@ -634,8 +639,8 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild if(!cloneConfig.isExtensionConfig) cloneChildren = true; - // If this constructor is called to clone an existing - // configuration, the parent of the cloning config should be stored. + // If this constructor is called to clone an existing + // configuration, the parent of the cloning config should be stored. parent = cloneConfig.isExtensionConfig || cloneConfig.getParent() == null ? cloneConfig : cloneConfig.getParent(); parentId = parent.getId(); @@ -786,7 +791,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild errorParserIds = SafeStringInterner.safeIntern(element.getAttribute(ERROR_PARSERS)); // Get the initial/default language setttings providers IDs - defaultLanguageSettingsProvidersIds = SafeStringInterner.safeIntern(element.getAttribute(LANGUAGE_SETTINGS_PROVIDERS)); + defaultLanguageSettingsProvidersAttribute = SafeStringInterner.safeIntern(element.getAttribute(LANGUAGE_SETTINGS_PROVIDERS)); // Get the artifact extension artifactExtension = SafeStringInterner.safeIntern(element.getAttribute(EXTENSION)); @@ -1460,8 +1465,52 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild return set; } + private String getDefaultLanguageSettingsProvidersAttribute() { + if (defaultLanguageSettingsProvidersAttribute == null && parent instanceof Configuration) { + defaultLanguageSettingsProvidersAttribute = ((Configuration) parent).getDefaultLanguageSettingsProvidersAttribute(); + } + + return defaultLanguageSettingsProvidersAttribute; + } + @Override - public String getDefaultLanguageSettingsProvidersIds() { + public String[] getDefaultLanguageSettingsProvidersIds() { + defaultLanguageSettingsProvidersIds = null; + if (defaultLanguageSettingsProvidersIds == null) { + getDefaultLanguageSettingsProvidersAttribute(); + if (defaultLanguageSettingsProvidersAttribute != null) { + List ids = new ArrayList(); + String[] defaultIds = defaultLanguageSettingsProvidersAttribute.split(LANGUAGE_SETTINGS_PROVIDER_DELIMITER); + for (String id : defaultIds) { + if (id != null && !id.isEmpty()) { + if (id.startsWith("-")) { + id = id.substring(1); + ids.remove(id); + } else if (!ids.contains(id)){ + if (id.contains("${Toolchain}")) { + IToolChain toolchain = getToolChain(); + if (toolchain != null) { + String toolchainProvidersIds = toolchain.getDefaultLanguageSettingsProvidersIds(); + if (toolchainProvidersIds != null) { + ids.addAll(Arrays.asList(toolchainProvidersIds.split(LANGUAGE_SETTINGS_PROVIDER_DELIMITER))); + } else { + String message = "Invalid use of ${Toolchain} tag, toolchain does not specify language settings providers. cfg=" + getId(); + ManagedBuilderCorePlugin.log(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, IStatus.ERROR, message, new Exception())); + } + } + } else { + ids.add(id); + } + } + } + + } + defaultLanguageSettingsProvidersIds = ids.toArray(new String[ids.size()]); + } else if (parent != null) { + defaultLanguageSettingsProvidersIds = parent.getDefaultLanguageSettingsProvidersIds(); + } + } + return defaultLanguageSettingsProvidersIds; } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/MultiConfiguration.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/MultiConfiguration.java index df67d68d2b4..3ce6f992212 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/MultiConfiguration.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/MultiConfiguration.java @@ -441,7 +441,7 @@ public class MultiConfiguration extends MultiItemsHolder implements } @Override - public String getDefaultLanguageSettingsProvidersIds() { + public String[] getDefaultLanguageSettingsProvidersIds() { ManagedBuilderCorePlugin.error("Default Language Settings Providers are not supported in multiconfiguration mode"); return null; } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolChain.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolChain.java index 83fddb4c70c..7bcbd388135 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolChain.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolChain.java @@ -1538,6 +1538,11 @@ public class ToolChain extends HoldsOptions implements IToolChain, IMatchKeyProv @Override public String getDefaultLanguageSettingsProvidersIds() { + if (defaultLanguageSettingsProvidersIds == null) { + if (superClass instanceof IToolChain) { + defaultLanguageSettingsProvidersIds = ((IToolChain) superClass).getDefaultLanguageSettingsProvidersIds(); + } + } return defaultLanguageSettingsProvidersIds; } @@ -1577,7 +1582,7 @@ public class ToolChain extends HoldsOptions implements IToolChain, IMatchKeyProv /* * (non-Javadoc) - * + * * @see org.eclipse.cdt.managedbuilder.core.IToolChain#getScannerConfigDiscoveryProfileId() */ @Override @@ -1597,7 +1602,7 @@ public class ToolChain extends HoldsOptions implements IToolChain, IMatchKeyProv } return scannerConfigDiscoveryProfileId; } - + /* (non-Javadoc) * @see org.eclipse.cdt.managedbuilder.core.IToolChain#setScannerConfigDiscoveryProfileId(java.lang.String) */ diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/dataprovider/ConfigurationDataProvider.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/dataprovider/ConfigurationDataProvider.java index 97d11966389..72657a9471a 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/dataprovider/ConfigurationDataProvider.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/dataprovider/ConfigurationDataProvider.java @@ -19,6 +19,10 @@ import java.util.Map; import java.util.Set; import org.eclipse.cdt.build.internal.core.scannerconfig2.CfgScannerConfigInfoFactory2; +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvidersKeeper; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; +import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySupport; import org.eclipse.cdt.core.model.ILanguageDescriptor; import org.eclipse.cdt.core.model.LanguageManager; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; @@ -532,28 +536,74 @@ public class ConfigurationDataProvider extends CConfigurationDataProvider implem } @Override - public CConfigurationData loadConfiguration(ICConfigurationDescription des, - IProgressMonitor monitor) - throws CoreException { - if(des.isPreferenceConfiguration()) - return loadPreferences(des); + public CConfigurationData loadConfiguration(ICConfigurationDescription cfgDescription, IProgressMonitor monitor) throws CoreException { + if(cfgDescription.isPreferenceConfiguration()) + return loadPreferences(cfgDescription); - IManagedBuildInfo info = getBuildInfo(des); - Configuration cfg = load(des, (ManagedProject)info.getManagedProject(), false); + IManagedBuildInfo info = getBuildInfo(cfgDescription); + Configuration cfg = load(cfgDescription, (ManagedProject)info.getManagedProject(), false); if(cfg != null){ - cfg.setConfigurationDescription(des); + cfg.setConfigurationDescription(cfgDescription); info.setValid(true); - setPersistedFlag(des); - cacheNaturesIdsUsedOnCache(des); + setPersistedFlag(cfgDescription); + cacheNaturesIdsUsedOnCache(cfgDescription); // Update the ManagedBuildInfo in the ManagedBuildManager map. Doing this creates a barrier for subsequent // ManagedBuildManager#getBuildInfo(...) see Bug 305146 for more - ManagedBuildManager.setLoaddedBuildInfo(des.getProjectDescription().getProject(), info); + ManagedBuildManager.setLoaddedBuildInfo(cfgDescription.getProjectDescription().getProject(), info); + setDefaultLanguageSettingsProvidersIds(cfg, cfgDescription); return cfg.getConfigurationData(); } return null; } + private static List getDefaultLanguageSettingsProviders(IConfiguration cfg) { + List providers = new ArrayList(); + String[] ids = cfg.getDefaultLanguageSettingsProvidersIds(); + if (ids != null) { + for (String id : ids) { + ILanguageSettingsProvider provider = null; + if (!LanguageSettingsManager.isPreferShared(id)) { + provider = LanguageSettingsManager.getExtensionProviderCopy(id, false); + } + if (provider == null) { + provider = LanguageSettingsManager.getWorkspaceProvider(id); + } + providers.add(provider); + } + } + + if (providers.isEmpty()) { + // Add MBS and User provider for unsuspecting toolchains (backward compatibility) + ILanguageSettingsProvider userProvider = LanguageSettingsManager.getExtensionProviderCopy(ScannerDiscoveryLegacySupport.USER_LANGUAGE_SETTINGS_PROVIDER_ID, true); + ILanguageSettingsProvider mbsProvider = LanguageSettingsManager.getWorkspaceProvider(ScannerDiscoveryLegacySupport.MBS_LANGUAGE_SETTINGS_PROVIDER_ID); + providers.add(userProvider); + providers.add(mbsProvider); + } + + return providers; + } + + private static void setDefaultLanguageSettingsProvidersIds(IConfiguration cfg, ICConfigurationDescription cfgDescription) { + if (cfgDescription instanceof ILanguageSettingsProvidersKeeper) { + List providers = getDefaultLanguageSettingsProviders(cfg); + String[] ids = new String[providers.size()]; + for (int i = 0; i < ids.length; i++) { + ILanguageSettingsProvider provider = providers.get(i); + ids[i] = provider.getId(); + } + ((ILanguageSettingsProvidersKeeper) cfgDescription).setDefaultLanguageSettingsProvidersIds(ids); + } + + } + + public static void setDefaultLanguageSettingsProviders(IConfiguration cfg, ICConfigurationDescription cfgDescription) { + setDefaultLanguageSettingsProvidersIds(cfg, cfgDescription); + List providers = getDefaultLanguageSettingsProviders(cfg); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); + } + + private boolean isPersistedCfg(ICConfigurationDescription cfgDes){ return cfgDes.getSessionProperty(CFG_PERSISTED_PROPERTY) != null; } diff --git a/build/org.eclipse.cdt.managedbuilder.ui.tests/src/org/eclipse/cdt/managedbuilder/ui/tests/util/TestConfiguration.java b/build/org.eclipse.cdt.managedbuilder.ui.tests/src/org/eclipse/cdt/managedbuilder/ui/tests/util/TestConfiguration.java index 038df9d297a..f09d0f26b2c 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui.tests/src/org/eclipse/cdt/managedbuilder/ui/tests/util/TestConfiguration.java +++ b/build/org.eclipse.cdt.managedbuilder.ui.tests/src/org/eclipse/cdt/managedbuilder/ui/tests/util/TestConfiguration.java @@ -208,7 +208,7 @@ public class TestConfiguration implements IConfiguration { } @Override - public String getDefaultLanguageSettingsProvidersIds() { + public String[] getDefaultLanguageSettingsProvidersIds() { // TODO Auto-generated method stub return null; } diff --git a/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml b/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml index 0d557ef995e..b82b03c7a7e 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml +++ b/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml @@ -653,7 +653,6 @@ diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/MBSWizardHandler.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/MBSWizardHandler.java index 2968615327e..832ce2bc40b 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/MBSWizardHandler.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/MBSWizardHandler.java @@ -33,7 +33,6 @@ import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager; import org.eclipse.cdt.core.settings.model.extension.CConfigurationData; import org.eclipse.cdt.core.templateengine.process.ProcessFailureException; -import org.eclipse.cdt.internal.ui.language.settings.providers.LanguageSettingsProviderAssociationManager; import org.eclipse.cdt.internal.ui.wizards.ICDTCommonProjectWizard; import org.eclipse.cdt.managedbuilder.buildproperties.IBuildProperty; import org.eclipse.cdt.managedbuilder.buildproperties.IBuildPropertyValue; @@ -46,6 +45,7 @@ import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; import org.eclipse.cdt.managedbuilder.internal.core.Configuration; import org.eclipse.cdt.managedbuilder.internal.core.ManagedBuildInfo; import org.eclipse.cdt.managedbuilder.internal.core.ManagedProject; +import org.eclipse.cdt.managedbuilder.internal.dataprovider.ConfigurationDataProvider; import org.eclipse.cdt.managedbuilder.internal.ui.Messages; import org.eclipse.cdt.managedbuilder.ui.properties.ManagedBuilderUIPlugin; import org.eclipse.cdt.ui.newui.CDTPrefUtil; @@ -93,11 +93,6 @@ public class MBSWizardHandler extends CWizardHandler { private static final String PROPERTY = "org.eclipse.cdt.build.core.buildType"; //$NON-NLS-1$ private static final String PROP_VAL = PROPERTY + ".debug"; //$NON-NLS-1$ - private static final String UI_USER_LANGUAGE_SETTINGS_PROVIDER = "org.eclipse.cdt.ui.user.LanguageSettingsProvider"; - /** @since 8.1 */ - public static final String MBS_LANGUAGE_SETTINGS_PROVIDER = "org.eclipse.cdt.managedbuilder.core.LanguageSettingsProvider"; - private static final String LANGUAGE_SETTINGS_PROVIDER_DELIMITER = ";"; - private static final String tooltip = Messages.CWizardHandler_1 + Messages.CWizardHandler_2 + @@ -613,12 +608,12 @@ public class MBSWizardHandler extends CWizardHandler { ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, isTryingNewSD); List providers; if (isTryingNewSD) { - providers = MBSWizardHandler.getLanguageSettingsProviders(config); + ConfigurationDataProvider.setDefaultLanguageSettingsProviders(config, cfgDes); } else { providers = new ArrayList(); - providers.add(LanguageSettingsManager.getWorkspaceProvider(MBSWizardHandler.MBS_LANGUAGE_SETTINGS_PROVIDER)); + providers.add(LanguageSettingsManager.getWorkspaceProvider(ScannerDiscoveryLegacySupport.MBS_LANGUAGE_SETTINGS_PROVIDER_ID)); + ((ILanguageSettingsProvidersKeeper) cfgDes).setLanguageSettingProviders(providers); } - ((ILanguageSettingsProvidersKeeper) cfgDes).setLanguageSettingProviders(providers); } else { ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, false); } @@ -866,93 +861,4 @@ public class MBSWizardHandler extends CWizardHandler { return super.canFinish(); } - private static String getLanguageSettingsProvidersStr(IToolChain toolchain) { - for (;toolchain!=null;toolchain=toolchain.getSuperClass()) { - String providersIdsStr = toolchain.getDefaultLanguageSettingsProvidersIds(); - if (providersIdsStr!=null) { - return providersIdsStr; - } - } - return ""; - } - - private static String getLanguageSettingsProvidersStr(IConfiguration cfg) { - for (;cfg!=null;cfg=cfg.getParent()) { - String providersIdsStr = cfg.getDefaultLanguageSettingsProvidersIds(); - if (providersIdsStr!=null) { - return providersIdsStr; - } - } - return ""; - } - - /** - * @since 8.1 - */ - public static List getLanguageSettingsProviders(IConfiguration cfg) { - List providers = new ArrayList(); - - String providersIdsStr = getLanguageSettingsProvidersStr(cfg); - if (providersIdsStr!=null) { - if (providersIdsStr.contains("${Toolchain}")) { - IToolChain toolchain = cfg.getToolChain(); - String toolchainProvidersIds = getLanguageSettingsProvidersStr(toolchain); - if (toolchainProvidersIds==null) { - toolchainProvidersIds=""; - } - providersIdsStr = providersIdsStr.replaceAll("\\$\\{Toolchain\\}", toolchainProvidersIds); - } - List providersIds = Arrays.asList(providersIdsStr.split(LANGUAGE_SETTINGS_PROVIDER_DELIMITER)); - for (String id : providersIds) { - id = id.trim(); - ILanguageSettingsProvider provider = null; - if (id.startsWith("-")) { - id = id.substring(1); - for (ILanguageSettingsProvider pr : providers) { - if (pr.getId().equals(id)) { - providers.remove(pr); - // Has to break as the collection is invalidated - // TODO: remove all elements or better use unique list - break; - } - } - } else if (id.length()>0) { - ILanguageSettingsProvider providerExt = LanguageSettingsManager.getExtensionProviderCopy(id, false); - if (providerExt == null || LanguageSettingsProviderAssociationManager.shouldBeShared(providerExt)) { - provider = LanguageSettingsManager.getWorkspaceProvider(id); - } else { - provider = providerExt; - } - } - if (provider!=null) { - providers.add(provider); - } - } - } - - - if (providers.isEmpty()) { - // Add MBS provider for unsuspecting toolchains (backward compatibility) - ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(MBS_LANGUAGE_SETTINGS_PROVIDER); - providers.add(provider); - } - - if (!isProviderThere(providers, UI_USER_LANGUAGE_SETTINGS_PROVIDER)) { - ILanguageSettingsProvider provider = LanguageSettingsManager.getExtensionProviderCopy(UI_USER_LANGUAGE_SETTINGS_PROVIDER, true); - providers.add(0, provider); - } - - return providers; - } - - private static boolean isProviderThere(List providers, String id) { - for (ILanguageSettingsProvider provider : providers) { - if (provider.getId().equals(id)) { - return true; - } - } - return false; - } - - } diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/NewMakeProjFromExisting.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/NewMakeProjFromExisting.java index cf44315d0c6..f94ad593132 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/NewMakeProjFromExisting.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/NewMakeProjFromExisting.java @@ -32,6 +32,7 @@ import org.eclipse.cdt.managedbuilder.internal.core.Configuration; import org.eclipse.cdt.managedbuilder.internal.core.ManagedBuildInfo; import org.eclipse.cdt.managedbuilder.internal.core.ManagedProject; import org.eclipse.cdt.managedbuilder.internal.core.ToolChain; +import org.eclipse.cdt.managedbuilder.internal.dataprovider.ConfigurationDataProvider; import org.eclipse.cdt.managedbuilder.internal.ui.Messages; import org.eclipse.cdt.managedbuilder.ui.properties.ManagedBuilderUIPlugin; import org.eclipse.core.resources.IProject; @@ -122,14 +123,13 @@ public class NewMakeProjFromExisting extends Wizard implements IImportWizard, IN if (cfgDes instanceof ILanguageSettingsProvidersKeeper) { ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, isTryingNewSD); - List providers; if (isTryingNewSD) { - providers = MBSWizardHandler.getLanguageSettingsProviders(config); + ConfigurationDataProvider.setDefaultLanguageSettingsProviders(config, cfgDes); } else { - providers = new ArrayList(); - providers.add(LanguageSettingsManager.getWorkspaceProvider(MBSWizardHandler.MBS_LANGUAGE_SETTINGS_PROVIDER)); + List providers = new ArrayList(); + providers.add(LanguageSettingsManager.getWorkspaceProvider(ScannerDiscoveryLegacySupport.MBS_LANGUAGE_SETTINGS_PROVIDER_ID)); + ((ILanguageSettingsProvidersKeeper) cfgDes).setLanguageSettingProviders(providers); } - ((ILanguageSettingsProvidersKeeper) cfgDes).setLanguageSettingProviders(providers); } else { ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, false); } diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/STDWizardHandler.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/STDWizardHandler.java index 5232b3a0d7b..d9d2049db7c 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/STDWizardHandler.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/STDWizardHandler.java @@ -31,6 +31,7 @@ import org.eclipse.cdt.managedbuilder.internal.core.Configuration; import org.eclipse.cdt.managedbuilder.internal.core.ManagedBuildInfo; import org.eclipse.cdt.managedbuilder.internal.core.ManagedProject; import org.eclipse.cdt.managedbuilder.internal.core.ToolChain; +import org.eclipse.cdt.managedbuilder.internal.dataprovider.ConfigurationDataProvider; import org.eclipse.cdt.managedbuilder.internal.ui.Messages; import org.eclipse.cdt.ui.wizards.CDTMainWizardPage; import org.eclipse.core.resources.IProject; @@ -120,14 +121,13 @@ public class STDWizardHandler extends MBSWizardHandler { } ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, isTryingNewSD); - List providers; if (isTryingNewSD) { - providers = MBSWizardHandler.getLanguageSettingsProviders(cfg); + ConfigurationDataProvider.setDefaultLanguageSettingsProviders(cfg, cfgDes); } else { - providers = new ArrayList(); - providers.add(LanguageSettingsManager.getWorkspaceProvider(MBSWizardHandler.MBS_LANGUAGE_SETTINGS_PROVIDER)); + List providers = new ArrayList(); + providers.add(LanguageSettingsManager.getWorkspaceProvider(ScannerDiscoveryLegacySupport.MBS_LANGUAGE_SETTINGS_PROVIDER_ID)); + ((ILanguageSettingsProvidersKeeper) cfgDes).setLanguageSettingProviders(providers); } - ((ILanguageSettingsProvidersKeeper) cfgDes).setLanguageSettingProviders(providers); } else { ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, false); } @@ -136,7 +136,10 @@ public class STDWizardHandler extends MBSWizardHandler { } mngr.setProjectDescription(project, des); } - public boolean canCreateWithoutToolchain() { return true; } + + public boolean canCreateWithoutToolchain() { + return true; + } @Override public void convertProject(IProject proj, IProgressMonitor monitor) throws CoreException { diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java index e3d52720616..f3efdacf527 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsExtensionsTests.java @@ -27,6 +27,7 @@ import org.eclipse.cdt.core.settings.model.CMacroFileEntry; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.core.testplugin.util.BaseTestCase; +import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsExtensionManager; import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.ResourcesPlugin; @@ -356,6 +357,7 @@ public class LanguageSettingsExtensionsTests extends BaseTestCase { ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(providerExt); assertTrue(rawProvider instanceof LanguageSettingsSerializableProvider); assertTrue(LanguageSettingsManager.isEqualExtensionProvider(rawProvider, true)); + assertEquals(true, LanguageSettingsExtensionManager.isPreferShared(EXTENSION_SERIALIZABLE_PROVIDER_ID)); } // Editable providers are retrieved by copy @@ -365,6 +367,7 @@ public class LanguageSettingsExtensionsTests extends BaseTestCase { assertFalse(LanguageSettingsManager.isWorkspaceProvider(providerExt)); assertTrue(providerExt instanceof ILanguageSettingsEditableProvider); assertTrue(LanguageSettingsManager.isEqualExtensionProvider(providerExt, true)); + assertEquals(LanguageSettingsExtensionManager.isPreferShared(EXTENSION_EDITABLE_PROVIDER_ID), false); // test that different copies are not same ILanguageSettingsProvider providerExt2 = LanguageSettingsManager.getExtensionProviderCopy(EXTENSION_EDITABLE_PROVIDER_ID, true); diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java index 66855fae87a..37ab92f213c 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java @@ -60,6 +60,8 @@ public class LanguageSettingsManagerTests extends BaseTestCase { class MockConfigurationDescription extends CModelMock.DummyCConfigurationDescription implements ILanguageSettingsProvidersKeeper { List providers = new ArrayList(); + String[] defaultProvidersIds = null; + public MockConfigurationDescription(String id) { super(id); } @@ -73,6 +75,16 @@ public class LanguageSettingsManagerTests extends BaseTestCase { public List getLanguageSettingProviders() { return providers; } + + @Override + public void setDefaultLanguageSettingsProvidersIds(String[] ids) { + defaultProvidersIds = ids; + } + + @Override + public String[] getDefaultLanguageSettingsProvidersIds() { + return defaultProvidersIds; + } } private class MockProvider extends AbstractExecutableExtensionBase implements ILanguageSettingsProvider { @@ -127,7 +139,7 @@ public class LanguageSettingsManagerTests extends BaseTestCase { } /** - * Test ICConfigurationDescription API (getters and setters). + * Test ILanguageSettingsProvidersKeeper API (getters and setters). */ public void testConfigurationDescription_Providers() throws Exception { MockConfigurationDescription cfgDescription = new MockConfigurationDescription(CFG_ID); @@ -146,6 +158,13 @@ public class LanguageSettingsManagerTests extends BaseTestCase { assertEquals(provider2, actual.get(1)); assertEquals(providers.size(), actual.size()); assertNotSame(actual, providers); + + // set default providers + String[] defaultProviders = { PROVIDER_0, PROVIDER_1 }; + cfgDescription.setDefaultLanguageSettingsProvidersIds(defaultProviders); + + // get default providers + assertEquals(defaultProviders, cfgDescription.getDefaultLanguageSettingsProvidersIds()); } /** diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java index 44c65c77c25..3cf74ffaab2 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java @@ -12,6 +12,7 @@ package org.eclipse.cdt.core.language.settings.providers; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import junit.framework.TestSuite; @@ -44,21 +45,26 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { private static final String EXTENSION_BASE_PROVIDER_ID = LanguageSettingsExtensionsTests.EXTENSION_BASE_PROVIDER_ID; private static final String EXTENSION_BASE_PROVIDER_NAME = LanguageSettingsExtensionsTests.EXTENSION_BASE_PROVIDER_NAME; private static final String EXTENSION_SERIALIZABLE_PROVIDER_ID = LanguageSettingsExtensionsTests.EXTENSION_SERIALIZABLE_PROVIDER_ID; + private static final String EXTENSION_EDITABLE_PROVIDER_ID = LanguageSettingsExtensionsTests.EXTENSION_EDITABLE_PROVIDER_ID; private static final String EXTENSION_USER_PROVIDER_ID = LanguageSettingsExtensionsTests.EXTENSION_USER_PROVIDER_ID; private static final ICLanguageSettingEntry EXTENSION_SERIALIZABLE_PROVIDER_ENTRY = LanguageSettingsExtensionsTests.EXTENSION_SERIALIZABLE_PROVIDER_ENTRY; - private static final String LANGUAGE_SETTINGS_PROJECT_XML = ".settings/language.settings.xml"; - private static final String LANGUAGE_SETTINGS_WORKSPACE_XML = "language.settings.xml"; + public static final String LANGUAGE_SETTINGS_PROJECT_XML = ".settings/language.settings.xml"; + public static final String LANGUAGE_SETTINGS_WORKSPACE_XML = "language.settings.xml"; private static final String CFG_ID = "test.configuration.id.0"; private static final String CFG_ID_2 = "test.configuration.id.2"; private static final String PROVIDER_0 = "test.provider.0.id"; + private static final String PROVIDER_1 = "test.provider.1.id"; private static final String PROVIDER_2 = "test.provider.2.id"; private static final String PROVIDER_NAME_0 = "test.provider.0.name"; + private static final String PROVIDER_NAME_1 = "test.provider.1.name"; private static final String PROVIDER_NAME_2 = "test.provider.2.name"; private static final String ATTR_PARAMETER = "parameter"; private static final String CUSTOM_PARAMETER = "custom parameter"; private static final String ELEM_TEST = "test"; + private static final String ELEM_PROVIDER = "provider "; // keep space for more reliable comparison + private static final String ELEM_PROVIDER_REFERENCE = "provider-reference"; private static CoreModel coreModel = CoreModel.getDefault(); @@ -77,6 +83,15 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { public List getLanguageSettingProviders() { return providers; } + + @Override + public void setDefaultLanguageSettingsProvidersIds(String[] ids) { + } + + @Override + public String[] getDefaultLanguageSettingsProvidersIds() { + return null; + } } class MockProjectDescription extends CModelMock.DummyCProjectDescription { ICConfigurationDescription[] cfgDescriptions; @@ -215,7 +230,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { assertNotNull(cfgDescription); assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); - // try to write to it + // try to write to it providers try { List providers = new ArrayList(); ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); @@ -223,6 +238,14 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { } catch (WriteAccessException e) { // exception is expected } + + // try to write to it default providers ids + try { + ((ILanguageSettingsProvidersKeeper) cfgDescription).setDefaultLanguageSettingsProvidersIds(new String[] { PROVIDER_0 }); + fail("WriteAccessException was expected but it was not throw."); + } catch (WriteAccessException e) { + // exception is expected + } } List entries = new ArrayList(); @@ -238,8 +261,8 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { assertNotNull(cfgDescription); assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); - // create a provider - LanguageSettingsSerializableProvider mockProvider = new MockLanguageSettingsEditableProvider(PROVIDER_0, PROVIDER_NAME_0); + // create a provider and write to cfgDescription + LanguageSettingsSerializableProvider mockProvider = new MockLanguageSettingsEditableProvider(PROVIDER_1, PROVIDER_NAME_1); LanguageSettingsManager.setStoringEntriesInProjectArea(mockProvider, true); mockProvider.setSettingEntries(cfgDescription, null, null, entries); List providers = new ArrayList(); @@ -248,6 +271,9 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { List storedProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); assertEquals(1, storedProviders.size()); + // write to cfgDescription default providers ids + ((ILanguageSettingsProvidersKeeper) cfgDescription).setDefaultLanguageSettingsProvidersIds(new String[] { PROVIDER_0 }); + // apply new project description to the project model coreModel.setProjectDescription(project, writableProjDescription); } @@ -261,16 +287,21 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { assertNotNull(cfgDescription); assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); + // double-check providers List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); assertEquals(1, providers.size()); ILanguageSettingsProvider loadedProvider = providers.get(0); assertTrue(loadedProvider instanceof MockLanguageSettingsEditableProvider); - assertEquals(PROVIDER_0, loadedProvider.getId()); - assertEquals(PROVIDER_NAME_0, loadedProvider.getName()); - + assertEquals(PROVIDER_1, loadedProvider.getId()); + assertEquals(PROVIDER_NAME_1, loadedProvider.getName()); + // double-check provider's setting entries List actual = loadedProvider.getSettingEntries(cfgDescription, null, null); assertEquals(entries.get(0), actual.get(0)); assertEquals(entries.size(), actual.size()); + + // double-check default providers ids + String[] actualDefaultProvidersIds = ((ILanguageSettingsProvidersKeeper) cfgDescription).getDefaultLanguageSettingsProvidersIds(); + assertTrue(Arrays.equals(new String[] { PROVIDER_0 }, actualDefaultProvidersIds)); } { // get writable project descriptions @@ -282,16 +313,21 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { assertNotNull(cfgDescription); assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); + // check providers List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); assertEquals(1, providers.size()); ILanguageSettingsProvider loadedProvider = providers.get(0); assertTrue(loadedProvider instanceof MockLanguageSettingsEditableProvider); - assertEquals(PROVIDER_0, loadedProvider.getId()); - assertEquals(PROVIDER_NAME_0, loadedProvider.getName()); - + assertEquals(PROVIDER_1, loadedProvider.getId()); + assertEquals(PROVIDER_NAME_1, loadedProvider.getName()); + // check provider's setting entries List actual = loadedProvider.getSettingEntries(cfgDescription, null, null); assertEquals(entries.get(0), actual.get(0)); assertEquals(entries.size(), actual.size()); + + // check default providers ids + String[] actualDefaultProvidersIds = ((ILanguageSettingsProvidersKeeper) cfgDescription).getDefaultLanguageSettingsProvidersIds(); + assertTrue(Arrays.equals(new String[] { PROVIDER_0 }, actualDefaultProvidersIds)); } } @@ -1188,7 +1224,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { * @param store - name of the store * @return location of the store in the plug-in state area */ - private static String getStoreLocationInWorkspaceArea(String store) { + public static String getStoreLocationInWorkspaceArea(String store) { IPath location = CCorePlugin.getDefault().getStateLocation().append(store); return location.toString(); } @@ -1358,5 +1394,174 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase { } } + /** + */ + public void testProjectPersistence_ProviderExtensionReferenceDOM() throws Exception { + Document doc = XmlUtil.newDocument(); + Element storageElement = XmlUtil.appendElement(doc, ELEM_TEST); + + ILanguageSettingsProvider providerExt = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_BASE_PROVIDER_ID); + assertNotNull(providerExt); + + { + // create a provider + MockProjectDescription mockPrjDescription = new MockProjectDescription(new MockConfigurationDescription(CFG_ID)); + + ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations(); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); + + + ArrayList providers = new ArrayList(); + providers.add(providerExt); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); + + // prepare DOM storage + LanguageSettingsProvidersSerializer.serializeLanguageSettingsInternal(storageElement, null, mockPrjDescription); + + String xml = XmlUtil.toString(doc); + assertTrue(xml.contains(ELEM_PROVIDER_REFERENCE)); + assertTrue(xml.contains(EXTENSION_BASE_PROVIDER_ID)); + assertTrue(xml.contains(LanguageSettingsProvidersSerializer.ATTR_ID)); + assertFalse(xml.contains(LanguageSettingsProvidersSerializer.ATTR_CLASS)); + } + { + // re-load and check language settings of the newly loaded provider + MockProjectDescription mockPrjDescription = new MockProjectDescription(new MockConfigurationDescription(CFG_ID)); + LanguageSettingsProvidersSerializer.loadLanguageSettingsInternal(storageElement, null, mockPrjDescription); + + ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations(); + assertNotNull(cfgDescriptions); + assertEquals(1, cfgDescriptions.length); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); + + List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); + assertNotNull(providers); + assertEquals(1, providers.size()); + ILanguageSettingsProvider provider = providers.get(0); + assertEquals(providerExt, provider); + } + } + + /** + */ + public void testProjectPersistence_ProviderExtensionCopyDOM() throws Exception { + Document doc = XmlUtil.newDocument(); + Element storageElement = XmlUtil.appendElement(doc, ELEM_TEST); + + ILanguageSettingsProvider providerExt = LanguageSettingsManager.getExtensionProviderCopy(EXTENSION_EDITABLE_PROVIDER_ID, true); + assertNotNull(providerExt); + + { + // create a provider + MockProjectDescription mockPrjDescription = new MockProjectDescription(new MockConfigurationDescription(CFG_ID)); + + ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations(); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); + + + ArrayList providers = new ArrayList(); + providers.add(providerExt); + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); + + // prepare DOM storage + LanguageSettingsProvidersSerializer.serializeLanguageSettingsInternal(storageElement, null, mockPrjDescription); + + String xml = XmlUtil.toString(doc); + assertTrue(xml.contains(ELEM_PROVIDER)); + assertTrue(xml.contains(EXTENSION_EDITABLE_PROVIDER_ID)); + assertTrue(xml.contains(LanguageSettingsProvidersSerializer.ATTR_ID)); + assertFalse(xml.contains(LanguageSettingsProvidersSerializer.ATTR_CLASS)); + } + { + // re-load and check language settings of the newly loaded provider + MockProjectDescription mockPrjDescription = new MockProjectDescription(new MockConfigurationDescription(CFG_ID)); + LanguageSettingsProvidersSerializer.loadLanguageSettingsInternal(storageElement, null, mockPrjDescription); + + ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations(); + assertNotNull(cfgDescriptions); + assertEquals(1, cfgDescriptions.length); + ICConfigurationDescription cfgDescription = cfgDescriptions[0]; + assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); + + List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); + assertNotNull(providers); + assertEquals(1, providers.size()); + ILanguageSettingsProvider provider = providers.get(0); + assertEquals(providerExt, provider); + } + } + + /** + */ + public void testProjectPersistence_Defaults() throws Exception { + // AG TODO - create and check real MBS projects with some providers + IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName()); + IFile xmlStorageFile = project.getFile(LANGUAGE_SETTINGS_PROJECT_XML); + assertFalse(xmlStorageFile.exists()); + + String xmlPrjWspStorageFileLocation = getStoreLocationInWorkspaceArea(project.getName()+'.'+LANGUAGE_SETTINGS_WORKSPACE_XML); + java.io.File xmlStorageFilePrjWsp = new java.io.File(xmlPrjWspStorageFileLocation); + assertFalse(xmlStorageFilePrjWsp.exists()); + } + + /** + */ + public void testWorkspacePersistence_ProviderExtensionCopy() throws Exception { + List entries = new ArrayList(); + List providers = new ArrayList(); + entries.add(new CIncludePathEntry("path0", 0)); + { + // get extension provider + ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_EDITABLE_PROVIDER_ID); + LanguageSettingsSerializableProvider rawProvider = (LanguageSettingsSerializableProvider) LanguageSettingsManager.getRawProvider(provider); + assertNotNull(rawProvider); + assertEquals(EXTENSION_EDITABLE_PROVIDER_ID, rawProvider.getId()); + + // add non-modified provider to the list + providers.add(provider); + } + { + // get another extension provider + ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_SERIALIZABLE_PROVIDER_ID); + LanguageSettingsSerializableProvider rawProvider = (LanguageSettingsSerializableProvider) LanguageSettingsManager.getRawProvider(provider); + assertNotNull(rawProvider); + assertEquals(EXTENSION_SERIALIZABLE_PROVIDER_ID, rawProvider.getId()); + // modify it and add it to the list + rawProvider.setSettingEntries(null, null, null, entries); + providers.add(rawProvider); + + // set and serialize language settings of workspace providers + LanguageSettingsManager.setWorkspaceProviders(providers); + LanguageSettingsManager.serializeLanguageSettingsWorkspace(); + } + { + String xmlWspStorageFileLocation = getStoreLocationInWorkspaceArea(LANGUAGE_SETTINGS_WORKSPACE_XML); + String xml = ResourceHelper.getContents(xmlWspStorageFileLocation); + // provider matching extension is not saved (extensions added automatically during loading providers) + assertFalse(xml.contains(EXTENSION_EDITABLE_PROVIDER_ID)); + // provider that differs is saved + assertTrue(xml.contains(EXTENSION_SERIALIZABLE_PROVIDER_ID)); + } + } + + /** + */ + public void testWorkspacePersistence_Defaults() throws Exception { + // reset and serialize workspace providers + LanguageSettingsManager.setWorkspaceProviders(null); + LanguageSettingsManager.serializeLanguageSettingsWorkspace(); + + // check that XML file is not created + String xmlWspStorageFileLocation = getStoreLocationInWorkspaceArea(LANGUAGE_SETTINGS_WORKSPACE_XML); + java.io.File xmlStorageFileWsp = new java.io.File(xmlWspStorageFileLocation); + assertFalse(xmlStorageFileWsp.exists()); + } } diff --git a/core/org.eclipse.cdt.core.tests/plugin.xml b/core/org.eclipse.cdt.core.tests/plugin.xml index c8588c34993..ad800c1705b 100644 --- a/core/org.eclipse.cdt.core.tests/plugin.xml +++ b/core/org.eclipse.cdt.core.tests/plugin.xml @@ -192,7 +192,8 @@ - +