1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-08 02:53:12 +02:00

bug 298590: Restore Defaults does not quite restore Folder Settings

This commit is contained in:
Andrew Gvozdev 2010-02-16 02:50:58 +00:00
parent b9eb1cba13
commit 9893d467ce
2 changed files with 76 additions and 17 deletions

View file

@ -18,8 +18,10 @@ import junit.framework.TestSuite;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICFolderDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager; import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager;
import org.eclipse.cdt.core.settings.model.ICResourceDescription;
import org.eclipse.cdt.core.settings.model.extension.CConfigurationData; import org.eclipse.cdt.core.settings.model.extension.CConfigurationData;
import org.eclipse.cdt.make.core.MakeCorePlugin; import org.eclipse.cdt.make.core.MakeCorePlugin;
import org.eclipse.cdt.managedbuilder.core.IConfiguration; import org.eclipse.cdt.managedbuilder.core.IConfiguration;
@ -30,12 +32,15 @@ import org.eclipse.cdt.managedbuilder.internal.core.Configuration;
import org.eclipse.cdt.managedbuilder.internal.core.ManagedBuildInfo; import org.eclipse.cdt.managedbuilder.internal.core.ManagedBuildInfo;
import org.eclipse.cdt.managedbuilder.internal.core.ManagedProject; import org.eclipse.cdt.managedbuilder.internal.core.ManagedProject;
import org.eclipse.cdt.managedbuilder.testplugin.BuildSystemTestHelper; import org.eclipse.cdt.managedbuilder.testplugin.BuildSystemTestHelper;
import org.eclipse.cdt.managedbuilder.testplugin.ManagedBuildTestHelper;
import org.eclipse.core.resources.IFolder;
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.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;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.QualifiedName; import org.eclipse.core.runtime.QualifiedName;
/** /**
* Creates a project in a loop and checks that it is created with appropriate number * Creates a project in a loop and checks that it is created with appropriate number
@ -206,4 +211,60 @@ public class CProjectDescriptionSerializationTests extends TestCase {
} }
} }
public void testResetDefaultSetings_Bug298590() throws Exception {
String pluginProjectTypeId = "cdt.managedbuild.target.gnu.cygwin.exe";
CoreModel coreModel = CoreModel.getDefault();
ICProjectDescriptionManager mngr = coreModel.getProjectDescriptionManager();
String projectName = getName();
String folderName = "Folder";
// Create a managed project and a folder
IProject project = ManagedBuildTestHelper.createProject(projectName, pluginProjectTypeId);
IFolder folder = ManagedBuildTestHelper.createFolder(project, folderName);
IPath folderPath = folder.getProjectRelativePath();
// Initial project description after creating the project
ICProjectDescription initialProjectDescription = mngr.getProjectDescription(project);
assertNotNull("createDescription returned null!", initialProjectDescription);
assertEquals(2, initialProjectDescription.getConfigurations().length);
{
// No folder description initially as it does not have any custom settings
ICConfigurationDescription cfgDescription = initialProjectDescription.getConfigurations()[0];
ICResourceDescription rcDescription = cfgDescription.getResourceDescription(folderPath, true);
assertNull(rcDescription);
}
// Properties window: get project description: prjd
ICProjectDescription propertyProjectDescription = CoreModel.getDefault().getProjectDescription(project);
{
// Still no folder description
ICConfigurationDescription cfgDescription = propertyProjectDescription.getConfigurations()[0];
ICResourceDescription rcDescription = cfgDescription.getResourceDescription(folderPath, true);
assertNull(rcDescription);
// getResDesc() creates default folder description
ICFolderDescription parentDescription = (ICFolderDescription)cfgDescription.getResourceDescription(folderPath, false);
assertEquals("/", parentDescription.toString());
ICFolderDescription folderDescription = cfgDescription.createFolderDescription(folderPath, parentDescription);
assertEquals(folderPath,folderDescription.getPath());
}
// OK button, persist the property project description prjd.
coreModel.setProjectDescription(project, propertyProjectDescription);
{
// Folder description should be null as no custom settings were defined
ICProjectDescription prjDescription = mngr.getProjectDescription(project);
ICConfigurationDescription cfgDescription = prjDescription.getConfigurations()[0];
ICResourceDescription rcDescription = cfgDescription.getResourceDescription(folderPath, true);
assertNull(rcDescription);
}
// Close project
project.close(null);
}
} }

View file

@ -2493,7 +2493,7 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
parent = parent.getParentContainer()) { parent = parent.getParentContainer()) {
// no body, this loop is to find the parent // no body, this loop is to find the parent
} }
if(!settingsCustomized(project, (CFolderData)parentRcData, (CFolderData)childRcData)){ if(!settingsCustomized(project, (CFolderData)parentRcData, (CFolderData)childRcData, parent.isRoot())){
try { try {
data.removeResourceData(childRcData); data.removeResourceData(childRcData);
child.remove(); child.remove();
@ -2519,35 +2519,33 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
return modified; return modified;
} }
static boolean settingsCustomized(IProject project, CFolderData parent, CFolderData child){ static private boolean settingsCustomized(IProject project, CFolderData parent, CFolderData child, boolean isParentRoot){
if(baseSettingsCustomized(parent, child)) if(baseSettingsCustomized(parent, child))
return true; return true;
CLanguageData[] childLDatas = child.getLanguageDatas(); CLanguageData[] childLDatas = child.getLanguageDatas();
CLanguageData[] parentLDatas = parent.getLanguageDatas(); CLanguageData[] parentLDatas = parent.getLanguageDatas();
if(childLDatas.length != parentLDatas.length) // Note that parent-root can define more languages than regular folder where tools are filtered
if(!isParentRoot && childLDatas.length != parentLDatas.length)
return true; return true;
if(childLDatas.length != 0){ HashMap<HashSet<String>, CLanguageData> parentMap = createExtSetToLDataMap(project, parentLDatas);
HashMap<HashSet<String>, CLanguageData> parentMap = createExtSetToLDataMap(project, parentLDatas); HashMap<HashSet<String>, CLanguageData> childMap = createExtSetToLDataMap(project, childLDatas);
HashMap<HashSet<String>, CLanguageData> childMap = createExtSetToLDataMap(project, childLDatas); for (Map.Entry<HashSet<String>, CLanguageData> childEntry : childMap.entrySet()) {
CLanguageData parentLData, childLData; CLanguageData parentLData = parentMap.get(childEntry.getKey());
for (Map.Entry<HashSet<String>, CLanguageData> entry : parentMap.entrySet()) { if(parentLData == null)
childLData = childMap.get(entry.getKey()); return true;
if(childLData == null)
return true;
parentLData = entry.getValue(); CLanguageData childLData = childEntry.getValue();
if(!langDatasEqual(parentLData, childLData)) if(!langDatasEqual(parentLData, childLData))
return true; return true;
}
} }
return false; return false;
} }
static boolean settingsCustomized(IProject project, CResourceData parent, CFileData child){ static private boolean settingsCustomized(IProject project, CResourceData parent, CFileData child){
if(baseSettingsCustomized(parent, child)) if(baseSettingsCustomized(parent, child))
return true; return true;