1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Fic for [Bug 194460] NPE while manipulating with ICDescriptor object

This commit is contained in:
Mikhail Sennikovsky 2007-08-10 14:37:04 +00:00
parent 868b714c51
commit 3b9217b9ca
4 changed files with 97 additions and 17 deletions

View file

@ -18,6 +18,8 @@ import java.util.Set;
import junit.framework.TestSuite;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ICDescriptor;
import org.eclipse.cdt.core.dom.IPDOMManager;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICProject;
@ -28,10 +30,11 @@ 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.w3c.dom.Element;
public class BackwardCompatibilityTests extends BaseTestCase {
private static final String PROJ_NAME_PREFIX = "BackwardCompatibilityTests_";
ICProject p1, p2;
ICProject p1, p2, p3;
public static TestSuite suite() {
return suite(BackwardCompatibilityTests.class, "_");
@ -46,6 +49,14 @@ public class BackwardCompatibilityTests extends BaseTestCase {
p1.getProject().delete(true, null);
p1 = null;
}
if(p2 != null){
p2.getProject().delete(true, null);
p2 = null;
}
if(p3 != null){
p3.getProject().delete(true, null);
p3 = null;
}
} catch (CoreException e){
}
}
@ -194,6 +205,25 @@ public class BackwardCompatibilityTests extends BaseTestCase {
checkCEntriesMatch(expectedOutputEntries, oEntries);
}
public void testICDescriptorGetProjectData() throws Exception {
p3 = CProjectHelper.createCCProject(PROJ_NAME_PREFIX + "c", null, IPDOMManager.ID_NO_INDEXER);
IProject proj = p3.getProject();
doTestRm(proj);
doTestRm(proj);
doTestRm(proj);
doTestRm(proj);
doTestRm(proj);
}
private void doTestRm(IProject proj) throws CoreException{
final String DATA_ID = "testICDescriptorGetProjectData";
ICDescriptor dr = CCorePlugin.getDefault().getCProjectDescription(proj, false);
Element dataEl = dr.getProjectData(DATA_ID);
dataEl.getParentNode().removeChild(dataEl);
dr.saveProjectData();
}
public static IPathEntry[] concatEntries(IPathEntry[] entries1, IPathEntry[] entries2){
List list = new ArrayList(entries1.length + entries2.length);
list.addAll(Arrays.asList(entries1));

View file

@ -113,6 +113,9 @@ public class CStorage implements ICSettingsStorage{
xmlEl = (Element)fElement.appendChild(xmlEl);
xmlEl.setAttribute(MODULE_ID_ATTRIBUTE, id);
fIsDirty = true;
return createAddStorageElement(id, xmlEl);
}
@ -126,14 +129,20 @@ public class CStorage implements ICSettingsStorage{
fIsDirty = true;
Document doc = fElement.getOwnerDocument();
Element child = doc.createElement(MODULE_ELEMENT_NAME);
child.setAttribute(MODULE_ID_ATTRIBUTE, id);
Element child = createStorageXmlElement(doc, id);
fElement.appendChild(child);
se = createAddStorageElement(id, child);
}
return se;
}
public static Element createStorageXmlElement(Document doc, String storageId){
Element child = doc.createElement(MODULE_ELEMENT_NAME);
child.setAttribute(MODULE_ID_ATTRIBUTE, storageId);
return child;
}
public void removeStorage(String id){
initChildren();
InternalXmlStorageElement se = (InternalXmlStorageElement)fStorageElementMap.remove(id);

View file

@ -15,6 +15,10 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.eclipse.cdt.core.ICDescriptor;
import org.eclipse.cdt.core.ICExtension;
import org.eclipse.cdt.core.ICExtensionReference;
@ -27,11 +31,14 @@ import org.eclipse.cdt.core.settings.model.util.CExtensionUtil;
import org.eclipse.cdt.internal.core.settings.model.CConfigurationDescriptionCache;
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.CStorage;
import org.eclipse.cdt.internal.core.settings.model.ExceptionFactory;
import org.eclipse.cdt.internal.core.settings.model.IInternalCCfgInfo;
import org.eclipse.cdt.internal.core.settings.model.InternalXmlStorageElement;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
public class CConfigBasedDescriptor implements ICDescriptor {
@ -262,9 +269,20 @@ public class CConfigBasedDescriptor implements ICDescriptor {
public Element getProjectData(String id) throws CoreException {
synchronized(CProjectDescriptionManager.getInstance()){
Element el = (Element)fStorageDataElMap.get(id);
if(el == null){
InternalXmlStorageElement storageEl = (InternalXmlStorageElement)fCfgDes.getStorage(id, true);
el = CProjectDescriptionManager.getInstance().createXmlElementCopy(storageEl);
if(el == null || el.getParentNode() == null){
InternalXmlStorageElement storageEl = (InternalXmlStorageElement)fCfgDes.getStorage(id, false);
if(storageEl == null){
try {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.newDocument();
el = CStorage.createStorageXmlElement(doc, id);
doc.appendChild(el);
} catch (ParserConfigurationException e) {
throw ExceptionFactory.createCoreException(e);
}
} else {
el = CProjectDescriptionManager.getInstance().createXmlElementCopy(storageEl);
}
fStorageDataElMap.put(id, el);
}
return el;

View file

@ -304,13 +304,22 @@ public class CConfigBasedDescriptorManager implements ICDescriptorManager {
return dr;
}
private CProjectDescription createProjDescriptionForDescriptor(IProject project) throws CoreException{
CProjectDescriptionManager mngr = CProjectDescriptionManager.getInstance();
CProjectDescription des = (CProjectDescription)mngr.createProjectDescription(project, false, true);
private CProjectDescription createProjDescriptionForDescriptor(final IProject project) throws CoreException{
final CProjectDescriptionManager mngr = CProjectDescriptionManager.getInstance();
final CProjectDescription des = (CProjectDescription)mngr.createProjectDescription(project, false, true);
CConfigurationData data = mngr.createDefaultConfigData(project, PathEntryConfigurationDataProvider.getDataFactory());
des.createConfiguration(CCorePlugin.DEFAULT_PROVIDER_ID, data);
// mngr.runWspModification(new IWorkspaceRunnable() {
//
// public void run(IProgressMonitor monitor) throws CoreException {
// if(mngr.getProjectDescription(project, false) == null){
// mngr.setProjectDescription(project, des);
// }
// }
//
// }, null);
return des;
}
@ -544,7 +553,7 @@ public class CConfigBasedDescriptorManager implements ICDescriptorManager {
Map.Entry entry = (Map.Entry)iter.next();
String id = (String)entry.getKey();
Element el = (Element)entry.getValue();
if(reconsile(id, el, des))
if(reconsile(id, el.getParentNode() != null ? el : null, des))
reconsiled = true;
}
}
@ -570,13 +579,27 @@ public class CConfigBasedDescriptorManager implements ICDescriptorManager {
private boolean reconsile(String id, Element el, ICConfigurationDescription cfg) throws CoreException{
CConfigurationSpecSettings setting = ((IInternalCCfgInfo)cfg).getSpecSettings();
InternalXmlStorageElement storEl = (InternalXmlStorageElement)setting.getStorage(id, false);
InternalXmlStorageElement newStorEl = CStorage.createStorageElement(el, false);
if(storEl == null
|| (!storEl.isDirty() && !newStorEl.matches(storEl))){
setting.importStorage(id, newStorEl);
return true;
InternalXmlStorageElement newStorEl = el != null ? CStorage.createStorageElement(el, false) : null;
boolean modified = false;
if(storEl != null){
if(newStorEl == null){
setting.removeStorage(id);
modified = true;
} else {
if(!newStorEl.matches(storEl)){
setting.importStorage(id, newStorEl);
modified = true;
}
}
} else {
if(newStorEl != null){
setting.importStorage(id, newStorEl);
modified = true;
}
}
return false;
return modified;
}
private CConfigBasedDescriptor getApplyingDescriptor(IProject project){