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:
parent
868b714c51
commit
3b9217b9ca
4 changed files with 97 additions and 17 deletions
|
@ -18,6 +18,8 @@ import java.util.Set;
|
||||||
|
|
||||||
import junit.framework.TestSuite;
|
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.dom.IPDOMManager;
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
import org.eclipse.cdt.core.model.ICProject;
|
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.CoreException;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
public class BackwardCompatibilityTests extends BaseTestCase {
|
public class BackwardCompatibilityTests extends BaseTestCase {
|
||||||
private static final String PROJ_NAME_PREFIX = "BackwardCompatibilityTests_";
|
private static final String PROJ_NAME_PREFIX = "BackwardCompatibilityTests_";
|
||||||
ICProject p1, p2;
|
ICProject p1, p2, p3;
|
||||||
|
|
||||||
public static TestSuite suite() {
|
public static TestSuite suite() {
|
||||||
return suite(BackwardCompatibilityTests.class, "_");
|
return suite(BackwardCompatibilityTests.class, "_");
|
||||||
|
@ -46,6 +49,14 @@ public class BackwardCompatibilityTests extends BaseTestCase {
|
||||||
p1.getProject().delete(true, null);
|
p1.getProject().delete(true, null);
|
||||||
p1 = 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){
|
} catch (CoreException e){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -194,6 +205,25 @@ public class BackwardCompatibilityTests extends BaseTestCase {
|
||||||
checkCEntriesMatch(expectedOutputEntries, oEntries);
|
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){
|
public static IPathEntry[] concatEntries(IPathEntry[] entries1, IPathEntry[] entries2){
|
||||||
List list = new ArrayList(entries1.length + entries2.length);
|
List list = new ArrayList(entries1.length + entries2.length);
|
||||||
list.addAll(Arrays.asList(entries1));
|
list.addAll(Arrays.asList(entries1));
|
||||||
|
|
|
@ -113,6 +113,9 @@ public class CStorage implements ICSettingsStorage{
|
||||||
|
|
||||||
xmlEl = (Element)fElement.appendChild(xmlEl);
|
xmlEl = (Element)fElement.appendChild(xmlEl);
|
||||||
xmlEl.setAttribute(MODULE_ID_ATTRIBUTE, id);
|
xmlEl.setAttribute(MODULE_ID_ATTRIBUTE, id);
|
||||||
|
|
||||||
|
fIsDirty = true;
|
||||||
|
|
||||||
return createAddStorageElement(id, xmlEl);
|
return createAddStorageElement(id, xmlEl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,14 +129,20 @@ public class CStorage implements ICSettingsStorage{
|
||||||
|
|
||||||
fIsDirty = true;
|
fIsDirty = true;
|
||||||
Document doc = fElement.getOwnerDocument();
|
Document doc = fElement.getOwnerDocument();
|
||||||
Element child = doc.createElement(MODULE_ELEMENT_NAME);
|
Element child = createStorageXmlElement(doc, id);
|
||||||
child.setAttribute(MODULE_ID_ATTRIBUTE, id);
|
|
||||||
fElement.appendChild(child);
|
fElement.appendChild(child);
|
||||||
se = createAddStorageElement(id, child);
|
se = createAddStorageElement(id, child);
|
||||||
}
|
}
|
||||||
return se;
|
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){
|
public void removeStorage(String id){
|
||||||
initChildren();
|
initChildren();
|
||||||
InternalXmlStorageElement se = (InternalXmlStorageElement)fStorageElementMap.remove(id);
|
InternalXmlStorageElement se = (InternalXmlStorageElement)fStorageElementMap.remove(id);
|
||||||
|
|
|
@ -15,6 +15,10 @@ import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
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.ICDescriptor;
|
||||||
import org.eclipse.cdt.core.ICExtension;
|
import org.eclipse.cdt.core.ICExtension;
|
||||||
import org.eclipse.cdt.core.ICExtensionReference;
|
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.CConfigurationDescriptionCache;
|
||||||
import org.eclipse.cdt.internal.core.settings.model.CConfigurationSpecSettings;
|
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.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.IInternalCCfgInfo;
|
||||||
import org.eclipse.cdt.internal.core.settings.model.InternalXmlStorageElement;
|
import org.eclipse.cdt.internal.core.settings.model.InternalXmlStorageElement;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IConfigurationElement;
|
import org.eclipse.core.runtime.IConfigurationElement;
|
||||||
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
public class CConfigBasedDescriptor implements ICDescriptor {
|
public class CConfigBasedDescriptor implements ICDescriptor {
|
||||||
|
@ -262,9 +269,20 @@ public class CConfigBasedDescriptor implements ICDescriptor {
|
||||||
public Element getProjectData(String id) throws CoreException {
|
public Element getProjectData(String id) throws CoreException {
|
||||||
synchronized(CProjectDescriptionManager.getInstance()){
|
synchronized(CProjectDescriptionManager.getInstance()){
|
||||||
Element el = (Element)fStorageDataElMap.get(id);
|
Element el = (Element)fStorageDataElMap.get(id);
|
||||||
if(el == null){
|
if(el == null || el.getParentNode() == null){
|
||||||
InternalXmlStorageElement storageEl = (InternalXmlStorageElement)fCfgDes.getStorage(id, true);
|
InternalXmlStorageElement storageEl = (InternalXmlStorageElement)fCfgDes.getStorage(id, false);
|
||||||
el = CProjectDescriptionManager.getInstance().createXmlElementCopy(storageEl);
|
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);
|
fStorageDataElMap.put(id, el);
|
||||||
}
|
}
|
||||||
return el;
|
return el;
|
||||||
|
|
|
@ -304,13 +304,22 @@ public class CConfigBasedDescriptorManager implements ICDescriptorManager {
|
||||||
return dr;
|
return dr;
|
||||||
}
|
}
|
||||||
|
|
||||||
private CProjectDescription createProjDescriptionForDescriptor(IProject project) throws CoreException{
|
private CProjectDescription createProjDescriptionForDescriptor(final IProject project) throws CoreException{
|
||||||
CProjectDescriptionManager mngr = CProjectDescriptionManager.getInstance();
|
final CProjectDescriptionManager mngr = CProjectDescriptionManager.getInstance();
|
||||||
CProjectDescription des = (CProjectDescription)mngr.createProjectDescription(project, false, true);
|
final CProjectDescription des = (CProjectDescription)mngr.createProjectDescription(project, false, true);
|
||||||
|
|
||||||
CConfigurationData data = mngr.createDefaultConfigData(project, PathEntryConfigurationDataProvider.getDataFactory());
|
CConfigurationData data = mngr.createDefaultConfigData(project, PathEntryConfigurationDataProvider.getDataFactory());
|
||||||
des.createConfiguration(CCorePlugin.DEFAULT_PROVIDER_ID, data);
|
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;
|
return des;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -544,7 +553,7 @@ public class CConfigBasedDescriptorManager implements ICDescriptorManager {
|
||||||
Map.Entry entry = (Map.Entry)iter.next();
|
Map.Entry entry = (Map.Entry)iter.next();
|
||||||
String id = (String)entry.getKey();
|
String id = (String)entry.getKey();
|
||||||
Element el = (Element)entry.getValue();
|
Element el = (Element)entry.getValue();
|
||||||
if(reconsile(id, el, des))
|
if(reconsile(id, el.getParentNode() != null ? el : null, des))
|
||||||
reconsiled = true;
|
reconsiled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -570,13 +579,27 @@ public class CConfigBasedDescriptorManager implements ICDescriptorManager {
|
||||||
private boolean reconsile(String id, Element el, ICConfigurationDescription cfg) throws CoreException{
|
private boolean reconsile(String id, Element el, ICConfigurationDescription cfg) throws CoreException{
|
||||||
CConfigurationSpecSettings setting = ((IInternalCCfgInfo)cfg).getSpecSettings();
|
CConfigurationSpecSettings setting = ((IInternalCCfgInfo)cfg).getSpecSettings();
|
||||||
InternalXmlStorageElement storEl = (InternalXmlStorageElement)setting.getStorage(id, false);
|
InternalXmlStorageElement storEl = (InternalXmlStorageElement)setting.getStorage(id, false);
|
||||||
InternalXmlStorageElement newStorEl = CStorage.createStorageElement(el, false);
|
InternalXmlStorageElement newStorEl = el != null ? CStorage.createStorageElement(el, false) : null;
|
||||||
if(storEl == null
|
|
||||||
|| (!storEl.isDirty() && !newStorEl.matches(storEl))){
|
boolean modified = false;
|
||||||
setting.importStorage(id, newStorEl);
|
|
||||||
return true;
|
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){
|
private CConfigBasedDescriptor getApplyingDescriptor(IProject project){
|
||||||
|
|
Loading…
Add table
Reference in a new issue