mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 10:16:03 +02:00
[242955] applied patch for "new configurations are bad or not saved"
This commit is contained in:
parent
c2436fcb02
commit
4d48a99d44
5 changed files with 117 additions and 7 deletions
|
@ -22,6 +22,7 @@ import org.eclipse.cdt.core.testplugin.CTestPlugin;
|
||||||
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
|
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.IWorkspace;
|
import org.eclipse.core.resources.IWorkspace;
|
||||||
|
import org.eclipse.core.resources.IWorkspaceDescription;
|
||||||
import org.eclipse.core.resources.IWorkspaceRoot;
|
import org.eclipse.core.resources.IWorkspaceRoot;
|
||||||
import org.eclipse.core.resources.ResourcesPlugin;
|
import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
@ -189,6 +190,89 @@ public class CProjectDescriptionBasicTests extends BaseTestCase{
|
||||||
assertTrue(failed);
|
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 {
|
protected void tearDown() throws Exception {
|
||||||
try {
|
try {
|
||||||
if(p1 != null)
|
if(p1 != null)
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Intel Corporation - Initial API and implementation
|
* Intel Corporation - Initial API and implementation
|
||||||
|
* James Blackburn (Broadcom Corp.)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.settings.model;
|
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 id
|
||||||
* @param name
|
* @param name
|
||||||
|
@ -94,9 +95,7 @@ public class CConfigurationDescription extends CDataProxyContainer implements IC
|
||||||
|
|
||||||
CConfigurationSpecSettings baseSettings = ((CConfigurationDescription)base).getSpecSettings();
|
CConfigurationSpecSettings baseSettings = ((CConfigurationDescription)base).getSpecSettings();
|
||||||
InternalXmlStorageElement baseRootEl = (InternalXmlStorageElement)baseSettings.getRootStorageElement();
|
InternalXmlStorageElement baseRootEl = (InternalXmlStorageElement)baseSettings.getRootStorageElement();
|
||||||
InternalXmlStorageElement newRootEl = CProjectDescriptionManager.getInstance().copyConfigurationElement(baseRootEl, id, false);
|
ICStorageElement newRootEl = CProjectDescriptionManager.getInstance().createStorage(projectDes.getStorageBase(), id, baseRootEl);
|
||||||
ICStorageElement parentEl = baseRootEl.getParent();
|
|
||||||
newRootEl = (InternalXmlStorageElement)parentEl.importChild(newRootEl);
|
|
||||||
|
|
||||||
fCfgSpecSettings = new CConfigurationSpecSettings(this, baseSettings, newRootEl);
|
fCfgSpecSettings = new CConfigurationSpecSettings(this, baseSettings, newRootEl);
|
||||||
fCfgSpecSettings.setId(id);
|
fCfgSpecSettings.setId(id);
|
||||||
|
|
|
@ -460,7 +460,7 @@ public class CProjectDescription implements ICProjectDescription, ICDataProxyCon
|
||||||
return fRootStorageElement;
|
return fRootStorageElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ICSettingsStorage getStorageBase() throws CoreException{
|
ICSettingsStorage getStorageBase() throws CoreException{
|
||||||
if(fStorage == null)
|
if(fStorage == null)
|
||||||
fStorage = new CStorage((InternalXmlStorageElement)getRootStorageElement());
|
fStorage = new CStorage((InternalXmlStorageElement)getRootStorageElement());
|
||||||
return fStorage;
|
return fStorage;
|
||||||
|
|
|
@ -22,6 +22,7 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.text.MessageFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -1623,6 +1624,31 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
|
||||||
return element;
|
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{
|
void removeStorage(ICSettingsStorage storage, String cfgId) throws CoreException{
|
||||||
ICStorageElement rootElement = storage.getStorage(MODULE_ID, false);
|
ICStorageElement rootElement = storage.getStorage(MODULE_ID, false);
|
||||||
if(rootElement != null){
|
if(rootElement != null){
|
||||||
|
|
|
@ -37,6 +37,7 @@ CProjectDescriptionManager.14=workspace info element does not exist
|
||||||
CProjectDescriptionManager.15=Preference Configuration
|
CProjectDescriptionManager.15=Preference Configuration
|
||||||
CProjectDescriptionManager.16=attempt to set description for the non-openned project
|
CProjectDescriptionManager.16=attempt to set description for the non-openned project
|
||||||
CProjectDescriptionManager.17=unable to apply the invalid project description for 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.0=data was not created
|
||||||
CFolderDescription.1=expected proxy of type ICLanguageSetting, but was
|
CFolderDescription.1=expected proxy of type ICLanguageSetting, but was
|
||||||
CFolderDescription.2=data was not created
|
CFolderDescription.2=data was not created
|
||||||
|
|
Loading…
Add table
Reference in a new issue