From 115f78f7aa1f306a48d40df9150c3cf57917ca9d Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Fri, 16 Dec 2011 12:48:53 -0500 Subject: [PATCH] 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.