mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-09-08 19:13:27 +02:00
fixed unessesary writes to .cdtproject
This commit is contained in:
parent
bf5f9acb67
commit
4c924a5283
2 changed files with 51 additions and 42 deletions
|
@ -86,6 +86,7 @@ public class CDescriptor implements ICDescriptor {
|
||||||
|
|
||||||
boolean fUpdating;
|
boolean fUpdating;
|
||||||
boolean isInitializing = true;
|
boolean isInitializing = true;
|
||||||
|
boolean bDirty = false;
|
||||||
|
|
||||||
protected CDescriptor(CDescriptorManager manager, IProject project, String id) throws CoreException {
|
protected CDescriptor(CDescriptorManager manager, IProject project, String id) throws CoreException {
|
||||||
fProject = project;
|
fProject = project;
|
||||||
|
@ -102,10 +103,10 @@ public class CDescriptor implements ICDescriptor {
|
||||||
String ownerID = readCDTProjectFile(descriptionPath);
|
String ownerID = readCDTProjectFile(descriptionPath);
|
||||||
if (ownerID.equals(id)) {
|
if (ownerID.equals(id)) {
|
||||||
status = new Status(IStatus.WARNING, CCorePlugin.PLUGIN_ID, CCorePlugin.STATUS_CDTPROJECT_EXISTS,
|
status = new Status(IStatus.WARNING, CCorePlugin.PLUGIN_ID, CCorePlugin.STATUS_CDTPROJECT_EXISTS,
|
||||||
CCorePlugin.getResourceString("CDescriptor.exception.projectAlreadyExists"), (Throwable) null); //$NON-NLS-1$
|
CCorePlugin.getResourceString("CDescriptor.exception.projectAlreadyExists"), (Throwable)null); //$NON-NLS-1$
|
||||||
} else {
|
} else {
|
||||||
status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, CCorePlugin.STATUS_CDTPROJECT_MISMATCH,
|
status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, CCorePlugin.STATUS_CDTPROJECT_MISMATCH,
|
||||||
CCorePlugin.getResourceString("CDescriptor.exception.unmatchedOwnerId"), (Throwable) null); //$NON-NLS-1$
|
CCorePlugin.getResourceString("CDescriptor.exception.unmatchedOwnerId"), (Throwable)null); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
throw new CoreException(status);
|
throw new CoreException(status);
|
||||||
}
|
}
|
||||||
|
@ -195,7 +196,7 @@ public class CDescriptor implements ICDescriptor {
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized public ICExtensionReference[] get(String extensionID) {
|
synchronized public ICExtensionReference[] get(String extensionID) {
|
||||||
CExtensionReference[] refs = (CExtensionReference[]) extMap.get(extensionID);
|
CExtensionReference[] refs = (CExtensionReference[])extMap.get(extensionID);
|
||||||
if (refs == null)
|
if (refs == null)
|
||||||
return new ICExtensionReference[0];
|
return new ICExtensionReference[0];
|
||||||
return refs;
|
return refs;
|
||||||
|
@ -209,9 +210,7 @@ public class CDescriptor implements ICDescriptor {
|
||||||
isInitializing = true;
|
isInitializing = true;
|
||||||
fOwner.update(fProject, this, extensionID);
|
fOwner.update(fProject, this, extensionID);
|
||||||
isInitializing = oldIsInitializing;
|
isInitializing = oldIsInitializing;
|
||||||
if (!isInitializing) {
|
updateIfDirty();
|
||||||
updateOnDisk();
|
|
||||||
}
|
|
||||||
refs = get(extensionID);
|
refs = get(extensionID);
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
}
|
}
|
||||||
|
@ -220,7 +219,7 @@ public class CDescriptor implements ICDescriptor {
|
||||||
}
|
}
|
||||||
|
|
||||||
private CExtensionReference createRef(String extensionPoint, String extension) {
|
private CExtensionReference createRef(String extensionPoint, String extension) {
|
||||||
CExtensionReference extensions[] = (CExtensionReference[]) extMap.get(extensionPoint);
|
CExtensionReference extensions[] = (CExtensionReference[])extMap.get(extensionPoint);
|
||||||
if (extensions == null) {
|
if (extensions == null) {
|
||||||
extensions = new CExtensionReference[1];
|
extensions = new CExtensionReference[1];
|
||||||
extMap.put(extensionPoint, extensions);
|
extMap.put(extensionPoint, extensions);
|
||||||
|
@ -239,8 +238,8 @@ public class CDescriptor implements ICDescriptor {
|
||||||
CExtensionReference extRef;
|
CExtensionReference extRef;
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
extRef = createRef(extensionPoint, extension);
|
extRef = createRef(extensionPoint, extension);
|
||||||
|
updateOnDisk();
|
||||||
if (!isInitializing) {
|
if (!isInitializing) {
|
||||||
updateOnDisk();
|
|
||||||
fireEvent = true;
|
fireEvent = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -253,38 +252,37 @@ public class CDescriptor implements ICDescriptor {
|
||||||
synchronized public void remove(ICExtensionReference ext) throws CoreException {
|
synchronized public void remove(ICExtensionReference ext) throws CoreException {
|
||||||
boolean fireEvent = false;
|
boolean fireEvent = false;
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
CExtensionReference extensions[] = (CExtensionReference[]) extMap.get(ext.getExtension());
|
CExtensionReference extensions[] = (CExtensionReference[])extMap.get(ext.getExtension());
|
||||||
for (int i = 0; i < extensions.length; i++) {
|
for (int i = 0; i < extensions.length; i++) {
|
||||||
if (extensions[i] == ext) {
|
if (extensions[i] == ext) {
|
||||||
System.arraycopy(extensions, i, extensions, i + 1, extensions.length - 1 - i);
|
System.arraycopy(extensions, i, extensions, i + 1, extensions.length - 1 - i);
|
||||||
if (extensions.length > 1) {
|
if (extensions.length > 1) {
|
||||||
CExtensionReference[] newExtensions = new CExtensionReference[extensions.length - 1];
|
CExtensionReference[] newExtensions = new CExtensionReference[extensions.length - 1];
|
||||||
System.arraycopy(extensions, 0, newExtensions, 0, newExtensions.length);
|
System.arraycopy(extensions, 0, newExtensions, 0, newExtensions.length);
|
||||||
extMap.put(ext.getExtension(), newExtensions);
|
extMap.put(ext.getExtension(), newExtensions);
|
||||||
} else {
|
} else {
|
||||||
extMap.remove(ext.getExtension());
|
extMap.remove(ext.getExtension());
|
||||||
}
|
}
|
||||||
if (!isInitializing) {
|
|
||||||
updateOnDisk();
|
updateOnDisk();
|
||||||
fireEvent = true;
|
if (!isInitializing) {
|
||||||
|
fireEvent = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (fireEvent) {
|
if (fireEvent) {
|
||||||
fManager.fireEvent(new CDescriptorEvent(this, CDescriptorEvent.CDTPROJECT_CHANGED,
|
fManager.fireEvent(new CDescriptorEvent(this, CDescriptorEvent.CDTPROJECT_CHANGED, CDescriptorEvent.EXTENSION_CHANGED));
|
||||||
CDescriptorEvent.EXTENSION_CHANGED));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(String extensionPoint) throws CoreException {
|
public void remove(String extensionPoint) throws CoreException {
|
||||||
boolean fireEvent = false;
|
boolean fireEvent = false;
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
CExtensionReference extensions[] = (CExtensionReference[]) extMap.get(extensionPoint);
|
CExtensionReference extensions[] = (CExtensionReference[])extMap.get(extensionPoint);
|
||||||
if (extensions != null) {
|
if (extensions != null) {
|
||||||
extMap.remove(extensionPoint);
|
extMap.remove(extensionPoint);
|
||||||
|
updateOnDisk();
|
||||||
if (!isInitializing) {
|
if (!isInitializing) {
|
||||||
updateOnDisk();
|
|
||||||
fireEvent = true;
|
fireEvent = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -295,7 +293,7 @@ public class CDescriptor implements ICDescriptor {
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized CExtensionInfo getInfo(CExtensionReference cProjectExtension) {
|
synchronized CExtensionInfo getInfo(CExtensionReference cProjectExtension) {
|
||||||
CExtensionInfo info = (CExtensionInfo) extInfoMap.get(cProjectExtension);
|
CExtensionInfo info = (CExtensionInfo)extInfoMap.get(cProjectExtension);
|
||||||
if (info == null) {
|
if (info == null) {
|
||||||
info = new CExtensionInfo();
|
info = new CExtensionInfo();
|
||||||
extInfoMap.put(cProjectExtension, info);
|
extInfoMap.put(cProjectExtension, info);
|
||||||
|
@ -312,6 +310,7 @@ public class CDescriptor implements ICDescriptor {
|
||||||
|
|
||||||
public void run(IProgressMonitor mon) throws CoreException {
|
public void run(IProgressMonitor mon) throws CoreException {
|
||||||
String xml;
|
String xml;
|
||||||
|
bDirty = false;
|
||||||
if (!fProject.isAccessible()) {
|
if (!fProject.isAccessible()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -356,10 +355,20 @@ public class CDescriptor implements ICDescriptor {
|
||||||
return fUpdating;
|
return fUpdating;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void updateIfDirty() {
|
||||||
|
if ( bDirty ) {
|
||||||
|
updateOnDisk();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
synchronized void updateOnDisk() {
|
synchronized void updateOnDisk() {
|
||||||
if (isUpdating()) {
|
if (isUpdating()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (isInitializing) {
|
||||||
|
bDirty = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
fUpdating = true;
|
fUpdating = true;
|
||||||
fManager.updateDescriptor(this);
|
fManager.updateDescriptor(this);
|
||||||
}
|
}
|
||||||
|
@ -409,13 +418,13 @@ public class CDescriptor implements ICDescriptor {
|
||||||
extChanges = false;
|
extChanges = false;
|
||||||
Iterator entries = extMap.entrySet().iterator();
|
Iterator entries = extMap.entrySet().iterator();
|
||||||
while (entries.hasNext()) {
|
while (entries.hasNext()) {
|
||||||
Entry entry = (Entry) entries.next();
|
Entry entry = (Entry)entries.next();
|
||||||
if (!origExtMap.containsKey(entry.getKey())) {
|
if (!origExtMap.containsKey(entry.getKey())) {
|
||||||
extChanges = true;
|
extChanges = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
CExtensionReference origExt[] = (CExtensionReference[]) origExtMap.get(entry.getKey());
|
CExtensionReference origExt[] = (CExtensionReference[])origExtMap.get(entry.getKey());
|
||||||
CExtensionReference newExt[] = (CExtensionReference[]) entry.getValue();
|
CExtensionReference newExt[] = (CExtensionReference[])entry.getValue();
|
||||||
if (!Arrays.equals(origExt, newExt)) {
|
if (!Arrays.equals(origExt, newExt)) {
|
||||||
extChanges = true;
|
extChanges = true;
|
||||||
break;
|
break;
|
||||||
|
@ -439,13 +448,13 @@ public class CDescriptor implements ICDescriptor {
|
||||||
if (childNode.getNodeType() == Node.ELEMENT_NODE) {
|
if (childNode.getNodeType() == Node.ELEMENT_NODE) {
|
||||||
if (childNode.getNodeName().equals(PROJECT_EXTENSION)) {
|
if (childNode.getNodeName().equals(PROJECT_EXTENSION)) {
|
||||||
try {
|
try {
|
||||||
decodeProjectExtension((Element) childNode);
|
decodeProjectExtension((Element)childNode);
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
CCorePlugin.log(e);
|
CCorePlugin.log(e);
|
||||||
}
|
}
|
||||||
} else if (childNode.getNodeName().equals(PROJECT_DATA)) {
|
} else if (childNode.getNodeName().equals(PROJECT_DATA)) {
|
||||||
try {
|
try {
|
||||||
decodeProjectData((Element) childNode);
|
decodeProjectData((Element)childNode);
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
CCorePlugin.log(e);
|
CCorePlugin.log(e);
|
||||||
}
|
}
|
||||||
|
@ -472,19 +481,19 @@ public class CDescriptor implements ICDescriptor {
|
||||||
Element element;
|
Element element;
|
||||||
Iterator extIterator = extMap.values().iterator();
|
Iterator extIterator = extMap.values().iterator();
|
||||||
while (extIterator.hasNext()) {
|
while (extIterator.hasNext()) {
|
||||||
CExtensionReference extension[] = (CExtensionReference[]) extIterator.next();
|
CExtensionReference extension[] = (CExtensionReference[])extIterator.next();
|
||||||
for (int i = 0; i < extension.length; i++) {
|
for (int i = 0; i < extension.length; i++) {
|
||||||
configRootElement.appendChild(element = doc.createElement(PROJECT_EXTENSION));
|
configRootElement.appendChild(element = doc.createElement(PROJECT_EXTENSION));
|
||||||
element.setAttribute(PROJECT_EXTENSION_ATTR_POINT, extension[i].getExtension());
|
element.setAttribute(PROJECT_EXTENSION_ATTR_POINT, extension[i].getExtension());
|
||||||
element.setAttribute(PROJECT_EXTENSION_ATTR_ID, extension[i].getID());
|
element.setAttribute(PROJECT_EXTENSION_ATTR_ID, extension[i].getID());
|
||||||
CExtensionInfo info = (CExtensionInfo) extInfoMap.get(extension[i]);
|
CExtensionInfo info = (CExtensionInfo)extInfoMap.get(extension[i]);
|
||||||
if (info != null) {
|
if (info != null) {
|
||||||
Iterator attribIterator = info.getAttributes().entrySet().iterator();
|
Iterator attribIterator = info.getAttributes().entrySet().iterator();
|
||||||
while (attribIterator.hasNext()) {
|
while (attribIterator.hasNext()) {
|
||||||
Entry entry = (Entry) attribIterator.next();
|
Entry entry = (Entry)attribIterator.next();
|
||||||
Element extAttributes = doc.createElement(PROJECT_EXTENSION_ATTRIBUTE);
|
Element extAttributes = doc.createElement(PROJECT_EXTENSION_ATTRIBUTE);
|
||||||
extAttributes.setAttribute(PROJECT_EXTENSION_ATTRIBUTE_KEY, (String) entry.getKey());
|
extAttributes.setAttribute(PROJECT_EXTENSION_ATTRIBUTE_KEY, (String)entry.getKey());
|
||||||
extAttributes.setAttribute(PROJECT_EXTENSION_ATTRIBUTE_VALUE, (String) entry.getValue());
|
extAttributes.setAttribute(PROJECT_EXTENSION_ATTRIBUTE_VALUE, (String)entry.getValue());
|
||||||
element.appendChild(extAttributes);
|
element.appendChild(extAttributes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -520,13 +529,13 @@ public class CDescriptor implements ICDescriptor {
|
||||||
IConfigurationElement element[] = extension.getConfigurationElements();
|
IConfigurationElement element[] = extension.getConfigurationElements();
|
||||||
for (int i = 0; i < element.length; i++) {
|
for (int i = 0; i < element.length; i++) {
|
||||||
if (element[i].getName().equalsIgnoreCase("cextension")) { //$NON-NLS-1$
|
if (element[i].getName().equalsIgnoreCase("cextension")) { //$NON-NLS-1$
|
||||||
cExtension = (InternalCExtension) element[i].createExecutableExtension("run"); //$NON-NLS-1$
|
cExtension = (InternalCExtension)element[i].createExecutableExtension("run"); //$NON-NLS-1$
|
||||||
cExtension.setExtenionReference(ext);
|
cExtension.setExtenionReference(ext);
|
||||||
cExtension.setProject(fProject);
|
cExtension.setProject(fProject);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (ICExtension) cExtension;
|
return (ICExtension)cExtension;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected IConfigurationElement[] getConfigurationElement(ICExtensionReference ext) throws CoreException {
|
protected IConfigurationElement[] getConfigurationElement(ICExtensionReference ext) throws CoreException {
|
||||||
|
@ -549,7 +558,7 @@ public class CDescriptor implements ICDescriptor {
|
||||||
public Element getProjectData(String id) throws CoreException {
|
public Element getProjectData(String id) throws CoreException {
|
||||||
NodeList nodes = getProjectDataDoc().getDocumentElement().getElementsByTagName(PROJECT_DATA_ITEM);
|
NodeList nodes = getProjectDataDoc().getDocumentElement().getElementsByTagName(PROJECT_DATA_ITEM);
|
||||||
for (int i = 0; i < nodes.getLength(); ++i) {
|
for (int i = 0; i < nodes.getLength(); ++i) {
|
||||||
Element element = (Element) nodes.item(i);
|
Element element = (Element)nodes.item(i);
|
||||||
if (element.getAttribute(PROJECT_DATA_ID).equals(id))
|
if (element.getAttribute(PROJECT_DATA_ID).equals(id))
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
@ -593,7 +602,7 @@ public class CDescriptor implements ICDescriptor {
|
||||||
Element dataElements = dataDoc.getDocumentElement();
|
Element dataElements = dataDoc.getDocumentElement();
|
||||||
NodeList nodes = dataElements.getElementsByTagName(PROJECT_DATA_ITEM);
|
NodeList nodes = dataElements.getElementsByTagName(PROJECT_DATA_ITEM);
|
||||||
for (int i = 0; i < nodes.getLength(); ++i) {
|
for (int i = 0; i < nodes.getLength(); ++i) {
|
||||||
Element item = (Element) nodes.item(i);
|
Element item = (Element)nodes.item(i);
|
||||||
if (!item.hasChildNodes()) { // remove any empty item tags
|
if (!item.hasChildNodes()) { // remove any empty item tags
|
||||||
dataElements.removeChild(item);
|
dataElements.removeChild(item);
|
||||||
i--; //nodeList is live.... removeal changes nodelist
|
i--; //nodeList is live.... removeal changes nodelist
|
||||||
|
|
|
@ -57,8 +57,8 @@ public class CExtensionReference implements ICExtensionReference {
|
||||||
|
|
||||||
public void setExtensionData(String key, String value) throws CoreException {
|
public void setExtensionData(String key, String value) throws CoreException {
|
||||||
getInfo().setAttribute(key, value);
|
getInfo().setAttribute(key, value);
|
||||||
|
fDescriptor.updateOnDisk();
|
||||||
if (!fDescriptor.isInitializing) {
|
if (!fDescriptor.isInitializing) {
|
||||||
fDescriptor.updateOnDisk();
|
|
||||||
fDescriptor.fManager.fireEvent(new CDescriptorEvent(fDescriptor, CDescriptorEvent.CDTPROJECT_CHANGED, 0));
|
fDescriptor.fManager.fireEvent(new CDescriptorEvent(fDescriptor, CDescriptorEvent.CDTPROJECT_CHANGED, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue