From 4d48a99d44989b7b3f75f4639da01ea5b2f340ef Mon Sep 17 00:00:00 2001 From: Alena Laskavaia Date: Fri, 16 Jan 2009 14:58:56 +0000 Subject: [PATCH] [242955] applied patch for "new configurations are bad or not saved" --- .../model/CProjectDescriptionBasicTests.java | 84 +++++++++++++++++++ .../model/CConfigurationDescription.java | 11 ++- .../settings/model/CProjectDescription.java | 2 +- .../model/CProjectDescriptionManager.java | 26 ++++++ .../model/SettingsModelMessages.properties | 1 + 5 files changed, 117 insertions(+), 7 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/settings/model/CProjectDescriptionBasicTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/settings/model/CProjectDescriptionBasicTests.java index dfd1be0e12e..3b972cc29d4 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/settings/model/CProjectDescriptionBasicTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/settings/model/CProjectDescriptionBasicTests.java @@ -22,6 +22,7 @@ import org.eclipse.cdt.core.testplugin.CTestPlugin; import org.eclipse.cdt.core.testplugin.util.BaseTestCase; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IWorkspaceDescription; import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; @@ -189,6 +190,89 @@ public class CProjectDescriptionBasicTests extends BaseTestCase{ assertTrue(failed); } + public void testBug242955() throws Exception { + CoreModel coreModel = CoreModel.getDefault(); + ICProjectDescriptionManager mngr = coreModel.getProjectDescriptionManager(); + + String projectName = "testBug242955"; + + String defaultConfigurationName = "Default"; + String newConfigurationName = "NEW-NAME"; + + // Emulate entering Eclipse first time + { + // Create model project and accompanied descriptions + ICProject cproject = CProjectHelper.createNewStileCProject(projectName, IPDOMManager.ID_NO_INDEXER); + IProject project = cproject.getProject(); + + // Initial project description after opening a project + ICProjectDescription initialProjectDescription = mngr.getProjectDescription(project); + assertNotNull("createDescription returned null!", initialProjectDescription); + assertEquals(1, initialProjectDescription.getConfigurations().length); + + // Initial configuration description + ICConfigurationDescription initialDefaultConfigurationDescription = initialProjectDescription.getConfigurations()[0]; + initialDefaultConfigurationDescription.setName(defaultConfigurationName); + assertEquals(defaultConfigurationName, initialDefaultConfigurationDescription.getName()); + mngr.setProjectDescription(project, initialProjectDescription); + + // Properties window: get project description: prjd + ICProjectDescription propertyProjectDescription = CoreModel.getDefault().getProjectDescription(project); + + // Dialog Manage-configurations-New-"NEW-NAME", from "Default" configuration + final String newConfigurationId = newConfigurationName + ".id"; + ICConfigurationDescription propertyDefaultConfigurationDescription = propertyProjectDescription.getConfigurations()[0]; + // creating new configuration in "Property" project description + ICConfigurationDescription propertyNewConfigurationDescription = propertyProjectDescription + .createConfiguration(newConfigurationId, newConfigurationName, propertyDefaultConfigurationDescription); + assertNotNull(propertyNewConfigurationDescription); + assertEquals(2,propertyProjectDescription.getConfigurations().length); + assertEquals(defaultConfigurationName,propertyProjectDescription.getConfigurations()[0].getName()); + assertEquals(newConfigurationName,propertyProjectDescription.getConfigurations()[1].getName()); + + // Apply button, local_prjd: copy "Property" new configuration description to "Applied" project description + ICProjectDescription applyButtonProjectDescription = coreModel.getProjectDescription(project); + ICConfigurationDescription applyButtonNewConfigurationDescription = applyButtonProjectDescription + .createConfiguration( + propertyNewConfigurationDescription.getId(), + propertyNewConfigurationDescription.getName(), + propertyNewConfigurationDescription); + + // OK button, persist the property project description prjd. + coreModel.setProjectDescription(project, propertyProjectDescription); + assertEquals(2,propertyProjectDescription.getConfigurations().length); + assertEquals(defaultConfigurationName,propertyProjectDescription.getConfigurations()[0].getName()); + assertEquals(newConfigurationName,propertyProjectDescription.getConfigurations()[1].getName()); + + // Close project + project.close(null); + } + + // Emulate re-entering Eclipse + { + // Re-open project and re-load project description + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + IWorkspaceRoot root = workspace.getRoot(); + + IWorkspaceDescription workspaceDesc = workspace.getDescription(); + workspaceDesc.setAutoBuilding(false); + workspace.setDescription(workspaceDesc); + + IProject project = root.getProject(projectName); + project.open(null); + assertEquals(true, project.isOpen()); + + // project description after reopening the project + ICProjectDescription reopenedProjectDescription = coreModel.getProjectDescription(project, false); + assertEquals(2,reopenedProjectDescription.getConfigurations().length); + assertEquals(defaultConfigurationName,reopenedProjectDescription.getConfigurations()[0].getName()); + assertEquals(newConfigurationName,reopenedProjectDescription.getConfigurations()[1].getName()); + + project.close(null); + } + } + + @Override protected void tearDown() throws Exception { try { if(p1 != null) 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 9da0f59bb74..7dfefa60250 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 @@ -7,6 +7,7 @@ * * Contributors: * Intel Corporation - Initial API and implementation + * James Blackburn (Broadcom Corp.) *******************************************************************************/ package org.eclipse.cdt.internal.core.settings.model; @@ -78,7 +79,7 @@ public class CConfigurationDescription extends CDataProxyContainer implements IC } /** - * creating a new configuration + * Creating a new configuration as a copy of an existing base CConfigurationDescription * * @param id * @param name @@ -91,13 +92,11 @@ public class CConfigurationDescription extends CDataProxyContainer implements IC setConfiguration(this); internalSetId(id); - + CConfigurationSpecSettings baseSettings = ((CConfigurationDescription)base).getSpecSettings(); InternalXmlStorageElement baseRootEl = (InternalXmlStorageElement)baseSettings.getRootStorageElement(); - InternalXmlStorageElement newRootEl = CProjectDescriptionManager.getInstance().copyConfigurationElement(baseRootEl, id, false); - ICStorageElement parentEl = baseRootEl.getParent(); - newRootEl = (InternalXmlStorageElement)parentEl.importChild(newRootEl); - + ICStorageElement newRootEl = CProjectDescriptionManager.getInstance().createStorage(projectDes.getStorageBase(), id, baseRootEl); + fCfgSpecSettings = new CConfigurationSpecSettings(this, baseSettings, newRootEl); fCfgSpecSettings.setId(id); fCfgSpecSettings.setName(name); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CProjectDescription.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CProjectDescription.java index bf88e5f9f41..f4f7926fe17 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CProjectDescription.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CProjectDescription.java @@ -460,7 +460,7 @@ public class CProjectDescription implements ICProjectDescription, ICDataProxyCon return fRootStorageElement; } - private ICSettingsStorage getStorageBase() throws CoreException{ + ICSettingsStorage getStorageBase() throws CoreException{ if(fStorage == null) fStorage = new CStorage((InternalXmlStorageElement)getRootStorageElement()); return fStorage; 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 bb4ea049e27..4d6c25c2063 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 @@ -22,6 +22,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.net.URI; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -1622,6 +1623,31 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager { return element; } + + /** + * Creates a new configuration storage based on an existing 'base' storage. + * If a configuration with the new ID already exists in the passed in project storage + * a CoreException is thrown. + * @param storage the setting storage of the current project description + * @param cfgId configID of the new configuration - must be unique in + * @param base the base (spec settings) storage element from which settings should be copied. + * @return ICStorageElement representing the new configuration + * @throws CoreException on failure + */ + ICStorageElement createStorage(ICSettingsStorage storage, String cfgId, ICStorageElement base) throws CoreException{ + ICStorageElement rootElement = storage.getStorage(MODULE_ID, true); + ICStorageElement children[] = rootElement.getChildren(); + for (ICStorageElement child : children) { + if(CONFIGURATION.equals(child.getName()) + && cfgId.equals(child.getAttribute(CConfigurationSpecSettings.ID))) + throw ExceptionFactory.createCoreException(MessageFormat + .format(SettingsModelMessages.getString("CProjectDescriptionManager.cfgIDAlreadyExists"), //$NON-NLS-1$ + cfgId)); + } + ICStorageElement config = rootElement.importChild(base); + config.setAttribute(CConfigurationSpecSettings.ID, cfgId); + return config; + } void removeStorage(ICSettingsStorage storage, String cfgId) throws CoreException{ ICStorageElement rootElement = storage.getStorage(MODULE_ID, false); 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 b4505ec2e78..32ae6e2344c 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 @@ -37,6 +37,7 @@ CProjectDescriptionManager.14=workspace info element does not exist CProjectDescriptionManager.15=Preference Configuration CProjectDescriptionManager.16=attempt to set description for the non-openned project CProjectDescriptionManager.17=unable to apply the invalid project description for project +CProjectDescriptionManager.cfgIDAlreadyExists=Configuration with ID: {0} already exists in passed in settings storage CFolderDescription.0=data was not created CFolderDescription.1=expected proxy of type ICLanguageSetting, but was CFolderDescription.2=data was not created