mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
update cdescriptor (see changelog)
This commit is contained in:
parent
001891858b
commit
0114d4cd78
10 changed files with 257 additions and 213 deletions
|
@ -1,3 +1,22 @@
|
|||
2004-03-19 David Inglis
|
||||
|
||||
* model/org/eclipse/cdt/core/model/CoreModel.java
|
||||
* model/org/eclipse/cdt/internal/core/model/CModelManager.java
|
||||
Removed deprecated method and now use descriptor change events for binary parser change.
|
||||
|
||||
* model/org/eclipse/cdt/internal/core/model/PathEntryManager.java
|
||||
Fixed setting raw paths entries to not clear cached until after raw set.
|
||||
|
||||
* src/org/eclipse/cdt/core/CCorePlugin.java
|
||||
* src/org/eclipse/cdt/core/ICDescriptorManager.java
|
||||
* src/org/eclipse/cdt/core/ICDescriptorOperation.java
|
||||
* src/org/eclipse/cdt/internal/core/CDescriptor.java
|
||||
* src/org/eclipse/cdt/internal/core/CDescriptorManager.java
|
||||
* src/org/eclipse/cdt/internal/core/CExtensionReference.java
|
||||
Fixed decriptor file updating to be handling as a job when extensions change.
|
||||
Update operation runnable to take project and IProgress.
|
||||
Suppress events and saves on initialization.
|
||||
|
||||
2004-03-19 Hoda Amer
|
||||
The CModelBuilder sets TranslationUnit.isStructureKnown() based on
|
||||
both parser errors and IProblems sent to the callback.
|
||||
|
|
|
@ -652,16 +652,6 @@ public class CoreModel implements ICDescriptorListener {
|
|||
return pathEntryManager.getPathEntryContainerInitializer(containerID);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: this is a temporary hack until, the CDescriptor manager is in
|
||||
* place and could fire deltas of Parser change.
|
||||
*
|
||||
* @deprecated this function will be removed shortly.
|
||||
*/
|
||||
public void resetBinaryParser(IProject project) {
|
||||
manager.resetBinaryParser(project);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the singleton.
|
||||
*/
|
||||
|
|
|
@ -141,6 +141,10 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
|
|||
| IResourceChangeEvent.POST_CHANGE
|
||||
| IResourceChangeEvent.PRE_DELETE
|
||||
| IResourceChangeEvent.PRE_CLOSE);
|
||||
|
||||
// Register the Core Model on the Descriptor
|
||||
// Manager, it needs to know about changes.
|
||||
CCorePlugin.getDefault().getCDescriptorManager().addDescriptorListener(factory);
|
||||
}
|
||||
return factory;
|
||||
}
|
||||
|
@ -544,7 +548,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
|
|||
binaryParsersMap.remove(project);
|
||||
celement = create(project);
|
||||
Parent parent = (Parent)celement.getParent();
|
||||
CElementInfo info = (CElementInfo)parent.getElementInfo();
|
||||
CElementInfo info = parent.getElementInfo();
|
||||
info.addChild(celement);
|
||||
|
||||
// Fired and ICElementDelta.PARSER_CHANGED
|
||||
|
@ -831,7 +835,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
|
|||
* @see org.eclipse.cdt.core.ICDescriptorListener#descriptorChanged(org.eclipse.cdt.core.CDescriptorEvent)
|
||||
*/
|
||||
public void descriptorChanged(CDescriptorEvent event) {
|
||||
/* int flags = event.getFlags();
|
||||
int flags = event.getFlags();
|
||||
if ((flags & CDescriptorEvent.EXTENSION_CHANGED) != 0) {
|
||||
ICDescriptor cdesc = event.getDescriptor();
|
||||
if (cdesc != null) {
|
||||
|
@ -845,7 +849,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
|
|||
} else { // may reorder
|
||||
for (int i = 0; i < newIds.length; i++) {
|
||||
String id = newIds[i];
|
||||
if (!id.equals(currentConfigs)) {
|
||||
if (!id.equals(currentConfigs[i].getId())) {
|
||||
resetBinaryParser(project);
|
||||
break;
|
||||
}
|
||||
|
@ -856,7 +860,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
|
|||
}
|
||||
}
|
||||
}
|
||||
*/ }
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire C Model deltas, flushing them after the fact.
|
||||
|
|
|
@ -130,7 +130,6 @@ public class PathEntryManager {
|
|||
public void setRawPathEntries(ICProject cproject, IPathEntry[] newEntries, IProgressMonitor monitor) throws CModelException {
|
||||
try {
|
||||
IPathEntry[] oldResolvedEntries = (IPathEntry[]) resolvedMap.get(cproject);
|
||||
resolvedMap.put(cproject, null);
|
||||
SetPathEntriesOperation op = new SetPathEntriesOperation(cproject, oldResolvedEntries, newEntries);
|
||||
CModelManager.getDefault().runOperation(op, monitor);
|
||||
} catch (CoreException e) {
|
||||
|
@ -410,6 +409,7 @@ public class PathEntryManager {
|
|||
encodePathEntries(cproject.getPath(), doc, rootElement, newRawEntries);
|
||||
}
|
||||
descriptor.saveProjectData();
|
||||
resolvedMap.put(cproject, null);
|
||||
} catch (CoreException e) {
|
||||
throw new CModelException(e);
|
||||
}
|
||||
|
|
|
@ -120,7 +120,8 @@ public class CCorePlugin extends Plugin {
|
|||
private static CCorePlugin fgCPlugin;
|
||||
private static ResourceBundle fgResourceBundle;
|
||||
|
||||
private CDescriptorManager fDescriptorManager;
|
||||
private CDescriptorManager fDescriptorManager = new CDescriptorManager();
|
||||
|
||||
private CoreModel fCoreModel;
|
||||
|
||||
// -------- static methods --------
|
||||
|
@ -230,6 +231,8 @@ public class CCorePlugin extends Plugin {
|
|||
//Set debug tracing options
|
||||
CCorePlugin.getDefault().configurePluginDebugOptions();
|
||||
|
||||
fDescriptorManager.startup();
|
||||
|
||||
// Fired up the model.
|
||||
fCoreModel = CoreModel.getDefault();
|
||||
fCoreModel.startup();
|
||||
|
@ -237,13 +240,6 @@ public class CCorePlugin extends Plugin {
|
|||
//Fired up the indexer
|
||||
fCoreModel.startIndexing();
|
||||
|
||||
fDescriptorManager = new CDescriptorManager();
|
||||
fDescriptorManager.startup();
|
||||
|
||||
// Register the Core Model on the Descriptor
|
||||
// Manager, it needs to know about changes.
|
||||
fDescriptorManager.addDescriptorListener(fCoreModel);
|
||||
|
||||
// Set the default for using the structual parse mode to build the CModel
|
||||
getPluginPreferences().setDefault(PREF_USE_STRUCTURAL_PARSE_MODE, false);
|
||||
|
||||
|
@ -819,7 +815,7 @@ public class CCorePlugin extends Plugin {
|
|||
if (extensions.length > 0)
|
||||
provider = (IScannerInfoProvider) extensions[0].createExtension();
|
||||
} catch (CoreException e) {
|
||||
log(e);
|
||||
// log(e);
|
||||
}
|
||||
}
|
||||
return provider;
|
||||
|
|
|
@ -11,11 +11,12 @@ package org.eclipse.cdt.core;
|
|||
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
|
||||
public interface ICDescriptorManager {
|
||||
public ICDescriptor getDescriptor(IProject project) throws CoreException;
|
||||
|
||||
public void runDescriptorOperation(ICDescriptor descriptor, ICDescriptorOperation op) throws CoreException;
|
||||
public void runDescriptorOperation(IProject project, ICDescriptorOperation op, IProgressMonitor monitor) throws CoreException;
|
||||
|
||||
public void addDescriptorListener(ICDescriptorListener listener);
|
||||
public void removeDescriptorListener(ICDescriptorListener listener);
|
||||
|
|
|
@ -10,9 +10,10 @@
|
|||
package org.eclipse.cdt.core;
|
||||
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
|
||||
public interface ICDescriptorOperation {
|
||||
|
||||
void execute(ICDescriptor descriptor) throws CoreException;
|
||||
void execute(ICDescriptor descriptor, IProgressMonitor monitor) throws CoreException;
|
||||
|
||||
}
|
||||
|
|
|
@ -38,12 +38,15 @@ import org.eclipse.cdt.core.ICOwnerInfo;
|
|||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IWorkspace;
|
||||
import org.eclipse.core.resources.IWorkspaceRunnable;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IConfigurationElement;
|
||||
import org.eclipse.core.runtime.IExtension;
|
||||
import org.eclipse.core.runtime.IExtensionPoint;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IPluginRegistry;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
|
@ -58,7 +61,6 @@ public class CDescriptor implements ICDescriptor {
|
|||
|
||||
final CDescriptorManager fManager;
|
||||
private final IProject fProject;
|
||||
|
||||
private COwner fOwner;
|
||||
|
||||
private HashMap extMap = new HashMap(4);
|
||||
|
@ -82,8 +84,8 @@ public class CDescriptor implements ICDescriptor {
|
|||
private static final String PROJECT_DATA_ITEM = "item"; //$NON-NLS-1$
|
||||
private static final String PROJECT_DATA_ID = "id"; //$NON-NLS-1$
|
||||
|
||||
private boolean fDirty;
|
||||
private boolean fAutoSave;
|
||||
private boolean fUpdating;
|
||||
boolean isInitializing = false;
|
||||
|
||||
protected CDescriptor(CDescriptorManager manager, IProject project, String id) throws CoreException {
|
||||
fProject = project;
|
||||
|
@ -109,6 +111,10 @@ public class CDescriptor implements ICDescriptor {
|
|||
throw new CoreException(status);
|
||||
}
|
||||
fOwner = new COwner(id);
|
||||
isInitializing = true;
|
||||
fOwner.configure(project, this);
|
||||
isInitializing = false;
|
||||
save();
|
||||
}
|
||||
|
||||
protected CDescriptor(CDescriptorManager manager, IProject project) throws CoreException {
|
||||
|
@ -146,11 +152,10 @@ public class CDescriptor implements ICDescriptor {
|
|||
}
|
||||
readCDTProjectFile(descriptionPath);
|
||||
fOwner = owner;
|
||||
setDirty();
|
||||
}
|
||||
|
||||
protected COwner getOwner() {
|
||||
return fOwner;
|
||||
isInitializing = true;
|
||||
fOwner.configure(project, this);
|
||||
isInitializing = false;
|
||||
save();
|
||||
}
|
||||
|
||||
private String readCDTProjectFile(IPath descriptionPath) throws CoreException {
|
||||
|
@ -214,8 +219,13 @@ public class CDescriptor implements ICDescriptor {
|
|||
ICExtensionReference[] ext = get(extensionID);
|
||||
if (ext.length == 0 && update) {
|
||||
try {
|
||||
boolean oldIsInitializing = isInitializing;
|
||||
isInitializing = true;
|
||||
fOwner.update(fProject, this, extensionID);
|
||||
setDirty();
|
||||
isInitializing = oldIsInitializing;
|
||||
if (!isInitializing) {
|
||||
updateOnDisk();
|
||||
}
|
||||
ext = get(extensionID);
|
||||
} catch (CoreException e) {
|
||||
}
|
||||
|
@ -223,7 +233,7 @@ public class CDescriptor implements ICDescriptor {
|
|||
return ext;
|
||||
}
|
||||
|
||||
synchronized public ICExtensionReference create(String extensionPoint, String extensionID) throws CoreException {
|
||||
private CExtensionReference createRef(String extensionPoint, String extension) {
|
||||
CExtensionReference extensions[] = (CExtensionReference[]) extMap.get(extensionPoint);
|
||||
if (extensions == null) {
|
||||
extensions = new CExtensionReference[1];
|
||||
|
@ -234,12 +244,19 @@ public class CDescriptor implements ICDescriptor {
|
|||
extensions = newExtensions;
|
||||
extMap.put(extensionPoint, extensions);
|
||||
}
|
||||
extensions[extensions.length - 1] = new CExtensionReference(this, extensionPoint, extensionID);
|
||||
setDirty();
|
||||
fManager.fireEvent(new CDescriptorEvent(this, CDescriptorEvent.CDTPROJECT_CHANGED, CDescriptorEvent.EXTENSION_CHANGED));
|
||||
extensions[extensions.length - 1] = new CExtensionReference(this, extensionPoint, extension);
|
||||
return extensions[extensions.length - 1];
|
||||
}
|
||||
|
||||
synchronized public ICExtensionReference create(String extensionPoint, String extension) throws CoreException {
|
||||
CExtensionReference extRef = createRef(extensionPoint, extension);
|
||||
if (!isInitializing) {
|
||||
updateOnDisk();
|
||||
fManager.fireEvent(new CDescriptorEvent(this, CDescriptorEvent.CDTPROJECT_CHANGED, CDescriptorEvent.EXTENSION_CHANGED));
|
||||
}
|
||||
return extRef;
|
||||
}
|
||||
|
||||
synchronized public void remove(ICExtensionReference ext) throws CoreException {
|
||||
CExtensionReference extensions[] = (CExtensionReference[]) extMap.get(ext.getExtension());
|
||||
for (int i = 0; i < extensions.length; i++) {
|
||||
|
@ -252,19 +269,25 @@ public class CDescriptor implements ICDescriptor {
|
|||
} else {
|
||||
extMap.remove(ext.getExtension());
|
||||
}
|
||||
setDirty();
|
||||
if (!isInitializing) {
|
||||
updateOnDisk();
|
||||
fManager.fireEvent(new CDescriptorEvent(this, CDescriptorEvent.CDTPROJECT_CHANGED,
|
||||
CDescriptorEvent.EXTENSION_CHANGED));
|
||||
}
|
||||
}
|
||||
}
|
||||
fManager.fireEvent(new CDescriptorEvent(this, CDescriptorEvent.CDTPROJECT_CHANGED, CDescriptorEvent.EXTENSION_CHANGED));
|
||||
}
|
||||
|
||||
synchronized public void remove(String extensionPoint) throws CoreException {
|
||||
CExtensionReference extensions[] = (CExtensionReference[]) extMap.get(extensionPoint);
|
||||
if (extensions != null) {
|
||||
extMap.remove(extensionPoint);
|
||||
setDirty();
|
||||
if (!isInitializing) {
|
||||
updateOnDisk();
|
||||
fManager.fireEvent(new CDescriptorEvent(this, CDescriptorEvent.CDTPROJECT_CHANGED,
|
||||
CDescriptorEvent.EXTENSION_CHANGED));
|
||||
}
|
||||
}
|
||||
fManager.fireEvent(new CDescriptorEvent(this, CDescriptorEvent.CDTPROJECT_CHANGED, CDescriptorEvent.EXTENSION_CHANGED));
|
||||
}
|
||||
|
||||
synchronized CExtensionInfo getInfo(CExtensionReference cProjectExtension) {
|
||||
|
@ -276,11 +299,17 @@ public class CDescriptor implements ICDescriptor {
|
|||
return info;
|
||||
}
|
||||
|
||||
synchronized protected void saveInfo() throws CoreException {
|
||||
protected IFile getFile() {
|
||||
return getProject().getFile(DESCRIPTION_FILE_NAME);
|
||||
}
|
||||
|
||||
synchronized void save() throws CoreException {
|
||||
String xml;
|
||||
if (!isDirty()) {
|
||||
if (!fProject.isAccessible()) {
|
||||
return;
|
||||
}
|
||||
fUpdating = true;
|
||||
|
||||
try {
|
||||
xml = getAsXML();
|
||||
} catch (IOException e) {
|
||||
|
@ -302,48 +331,22 @@ public class CDescriptor implements ICDescriptor {
|
|||
} else {
|
||||
rscFile.create(inputStream, IResource.FORCE, null);
|
||||
}
|
||||
fDirty = false;
|
||||
fUpdating = false;
|
||||
}
|
||||
|
||||
protected IFile getFile() {
|
||||
return getProject().getFile(DESCRIPTION_FILE_NAME);
|
||||
boolean isUpdating() {
|
||||
return fUpdating;
|
||||
}
|
||||
|
||||
public boolean isAutoSave() {
|
||||
return fAutoSave;
|
||||
synchronized void updateOnDisk() {
|
||||
if (isUpdating()) {
|
||||
return;
|
||||
}
|
||||
|
||||
public void setAutoSave(boolean autoSave) {
|
||||
fAutoSave = autoSave;
|
||||
}
|
||||
|
||||
protected void setDirty() throws CoreException {
|
||||
fDirty = true;
|
||||
if (isAutoSave())
|
||||
fUpdating = true;
|
||||
fManager.updateDescriptor(this);
|
||||
}
|
||||
|
||||
protected boolean isDirty() {
|
||||
return fDirty;
|
||||
}
|
||||
|
||||
protected String serializeDocument(Document doc) throws IOException, TransformerException {
|
||||
ByteArrayOutputStream s = new ByteArrayOutputStream();
|
||||
|
||||
TransformerFactory factory = TransformerFactory.newInstance();
|
||||
Transformer transformer = factory.newTransformer();
|
||||
transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$
|
||||
transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
|
||||
|
||||
DOMSource source = new DOMSource(doc);
|
||||
StreamResult outputTarget = new StreamResult(s);
|
||||
transformer.transform(source, outputTarget);
|
||||
|
||||
return s.toString("UTF8"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
void updateFromDisk() throws CoreException {
|
||||
synchronized (this) {
|
||||
synchronized void updateFromDisk() throws CoreException {
|
||||
IPath projectLocation = fProject.getDescription().getLocation();
|
||||
|
||||
if (projectLocation == null) {
|
||||
|
@ -351,7 +354,7 @@ public class CDescriptor implements ICDescriptor {
|
|||
}
|
||||
IPath descriptionPath = projectLocation.append(DESCRIPTION_FILE_NAME);
|
||||
if (!descriptionPath.toFile().exists()) {
|
||||
setDirty();
|
||||
updateOnDisk();
|
||||
return;
|
||||
}
|
||||
COwner origOwner = fOwner;
|
||||
|
@ -372,7 +375,6 @@ public class CDescriptor implements ICDescriptor {
|
|||
extInfoMap = origExtInfoMap;
|
||||
dataDoc = origDataDoc;
|
||||
}
|
||||
setDirty();
|
||||
if (!fOwner.equals(origOwner)) {
|
||||
fManager.fireEvent(new CDescriptorEvent(this, CDescriptorEvent.CDTPROJECT_CHANGED, CDescriptorEvent.OWNER_CHANGED));
|
||||
} else {
|
||||
|
@ -402,7 +404,6 @@ public class CDescriptor implements ICDescriptor {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void readProjectDescription(Node node) {
|
||||
Node childNode;
|
||||
|
@ -430,31 +431,17 @@ public class CDescriptor implements ICDescriptor {
|
|||
private void decodeProjectExtension(Element element) throws CoreException {
|
||||
String point = element.getAttribute(PROJECT_EXTENSION_ATTR_POINT);
|
||||
String id = element.getAttribute(PROJECT_EXTENSION_ATTR_ID);
|
||||
ICExtensionReference ext = create(point, id);
|
||||
CExtensionReference ext = createRef(point, id);
|
||||
NodeList extAttrib = element.getChildNodes();
|
||||
for (int j = 0; j < extAttrib.getLength(); j++) {
|
||||
if (extAttrib.item(j).getNodeName().equals(PROJECT_EXTENSION_ATTRIBUTE)) {
|
||||
NamedNodeMap attrib = extAttrib.item(j).getAttributes();
|
||||
ext.setExtensionData(attrib.getNamedItem(PROJECT_EXTENSION_ATTRIBUTE_KEY).getNodeValue(), attrib.getNamedItem(
|
||||
PROJECT_EXTENSION_ATTRIBUTE_VALUE).getNodeValue()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
getInfo(ext).setAttribute(attrib.getNamedItem(PROJECT_EXTENSION_ATTRIBUTE_KEY).getNodeValue(),
|
||||
attrib.getNamedItem(PROJECT_EXTENSION_ATTRIBUTE_VALUE).getNodeValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected String getAsXML() throws IOException, TransformerException, ParserConfigurationException {
|
||||
DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder docBuilder = dfactory.newDocumentBuilder();
|
||||
Document doc = docBuilder.newDocument();
|
||||
ProcessingInstruction version = doc.createProcessingInstruction("eclipse-cdt", "version=\"2.0\""); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
doc.appendChild(version);
|
||||
Element configRootElement = doc.createElement(PROJECT_DESCRIPTION);
|
||||
doc.appendChild(configRootElement);
|
||||
configRootElement.setAttribute(PROJECT_OWNER_ID, fOwner.getID());
|
||||
encodeProjectExtensions(doc, configRootElement);
|
||||
encodeProjectData(doc, configRootElement);
|
||||
return serializeDocument(doc);
|
||||
}
|
||||
|
||||
private void encodeProjectExtensions(Document doc, Element configRootElement) {
|
||||
Element element;
|
||||
Iterator extIterator = extMap.values().iterator();
|
||||
|
@ -479,6 +466,20 @@ public class CDescriptor implements ICDescriptor {
|
|||
}
|
||||
}
|
||||
|
||||
private String getAsXML() throws IOException, TransformerException, ParserConfigurationException {
|
||||
DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder docBuilder = dfactory.newDocumentBuilder();
|
||||
Document doc = docBuilder.newDocument();
|
||||
ProcessingInstruction version = doc.createProcessingInstruction("eclipse-cdt", "version=\"2.0\""); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
doc.appendChild(version);
|
||||
Element configRootElement = doc.createElement(PROJECT_DESCRIPTION);
|
||||
doc.appendChild(configRootElement);
|
||||
configRootElement.setAttribute(PROJECT_OWNER_ID, fOwner.getID());
|
||||
encodeProjectExtensions(doc, configRootElement);
|
||||
encodeProjectData(doc, configRootElement);
|
||||
return serializeDocument(doc);
|
||||
}
|
||||
|
||||
protected ICExtension createExtensions(ICExtensionReference ext) throws CoreException {
|
||||
InternalCExtension cExtension = null;
|
||||
IPluginRegistry pluginRegistry = Platform.getPluginRegistry();
|
||||
|
@ -486,7 +487,7 @@ public class CDescriptor implements ICDescriptor {
|
|||
IExtension extension = extensionPoint.getExtension(ext.getID());
|
||||
if (extension == null) {
|
||||
throw new CoreException(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1,
|
||||
CCorePlugin.getResourceString("CDescriptor.exception.providerNotFound"), null)); //$NON-NLS-1$
|
||||
CCorePlugin.getResourceString("CDescriptor.exception.providerNotFound" + ":" + ext.getID()), null)); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
IConfigurationElement element[] = extension.getConfigurationElements();
|
||||
for (int i = 0; i < element.length; i++) {
|
||||
|
@ -517,6 +518,31 @@ public class CDescriptor implements ICDescriptor {
|
|||
return new IConfigurationElement[0];
|
||||
}
|
||||
|
||||
public Element getProjectData(String id) throws CoreException {
|
||||
NodeList nodes = getProjectDataDoc().getDocumentElement().getElementsByTagName(PROJECT_DATA_ITEM);
|
||||
for (int i = 0; i < nodes.getLength(); ++i) {
|
||||
Element element = (Element) nodes.item(i);
|
||||
if (element.getAttribute(PROJECT_DATA_ID).equals(id))
|
||||
return element;
|
||||
}
|
||||
|
||||
// Not found, make a new one
|
||||
Element element = dataDoc.createElement(PROJECT_DATA_ITEM);
|
||||
element.setAttribute(PROJECT_DATA_ID, id);
|
||||
dataDoc.getDocumentElement().appendChild(element);
|
||||
return element;
|
||||
}
|
||||
|
||||
public void saveProjectData() throws CoreException {
|
||||
fManager.getWorkspace().run(new IWorkspaceRunnable() {
|
||||
|
||||
public void run(IProgressMonitor mon) throws CoreException {
|
||||
save();
|
||||
}
|
||||
}, fProject, IWorkspace.AVOID_UPDATE, null);
|
||||
fManager.fireEvent(new CDescriptorEvent(this, CDescriptorEvent.CDTPROJECT_CHANGED, 0));
|
||||
}
|
||||
|
||||
// The project data allows for the storage of any structured information
|
||||
// into the cdtproject file.
|
||||
synchronized private Document getProjectDataDoc() throws CoreException {
|
||||
|
@ -538,26 +564,6 @@ public class CDescriptor implements ICDescriptor {
|
|||
doc.replaceChild(doc.importNode(data, true), doc.getDocumentElement());
|
||||
}
|
||||
|
||||
public Element getProjectData(String id) throws CoreException {
|
||||
NodeList nodes = getProjectDataDoc().getDocumentElement().getElementsByTagName(PROJECT_DATA_ITEM);
|
||||
for (int i = 0; i < nodes.getLength(); ++i) {
|
||||
Element element = (Element) nodes.item(i);
|
||||
if (element.getAttribute(PROJECT_DATA_ID).equals(id))
|
||||
return element;
|
||||
}
|
||||
|
||||
// Not found, make a new one
|
||||
Element element = dataDoc.createElement(PROJECT_DATA_ITEM);
|
||||
element.setAttribute(PROJECT_DATA_ID, id);
|
||||
dataDoc.getDocumentElement().appendChild(element);
|
||||
return element;
|
||||
}
|
||||
|
||||
public void saveProjectData() throws CoreException {
|
||||
setDirty();
|
||||
fManager.fireEvent(new CDescriptorEvent(this, CDescriptorEvent.CDTPROJECT_CHANGED, 0));
|
||||
}
|
||||
|
||||
private void encodeProjectData(Document doc, Element root) {
|
||||
// Don't create or encode the doc if it isn't there already
|
||||
if (dataDoc != null) {
|
||||
|
@ -573,4 +579,19 @@ public class CDescriptor implements ICDescriptor {
|
|||
root.appendChild(doc.importNode(dataDoc.getDocumentElement(), true));
|
||||
}
|
||||
}
|
||||
|
||||
private String serializeDocument(Document doc) throws IOException, TransformerException {
|
||||
ByteArrayOutputStream s = new ByteArrayOutputStream();
|
||||
|
||||
TransformerFactory factory = TransformerFactory.newInstance();
|
||||
Transformer transformer = factory.newTransformer();
|
||||
transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$
|
||||
transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
|
||||
|
||||
DOMSource source = new DOMSource(doc);
|
||||
StreamResult outputTarget = new StreamResult(s);
|
||||
transformer.transform(source, outputTarget);
|
||||
|
||||
return s.toString("UTF8"); //$NON-NLS-1$
|
||||
}
|
||||
}
|
|
@ -37,6 +37,7 @@ import org.eclipse.core.runtime.ISafeRunnable;
|
|||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
|
||||
public class CDescriptorManager implements ICDescriptorManager, IResourceChangeListener {
|
||||
|
||||
|
@ -44,7 +45,36 @@ public class CDescriptorManager implements ICDescriptorManager, IResourceChangeL
|
|||
HashMap fDescriptorMap = new HashMap();
|
||||
List listeners = new Vector();
|
||||
|
||||
private IWorkspace getWorkspace() {
|
||||
class CDescriptorUpdater extends Job {
|
||||
|
||||
CDescriptor fDescriptor;
|
||||
|
||||
public CDescriptorUpdater(CDescriptor descriptor) {
|
||||
super(CCorePlugin.getResourceString("CDescriptorManager.async_updater")); //$NON-NLS-1$
|
||||
fDescriptor = descriptor;
|
||||
setPriority(Job.INTERACTIVE);
|
||||
setSystem(true);
|
||||
setRule(descriptor.getProject());
|
||||
}
|
||||
|
||||
protected IStatus run(IProgressMonitor monitor) {
|
||||
try {
|
||||
getWorkspace().run(new IWorkspaceRunnable() {
|
||||
|
||||
public void run(IProgressMonitor mon) throws CoreException {
|
||||
fDescriptor.save();
|
||||
}
|
||||
}, getRule(), IWorkspace.AVOID_UPDATE, monitor);
|
||||
|
||||
} catch (CoreException e) {
|
||||
return e.getStatus();
|
||||
}
|
||||
return Status.OK_STATUS;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
IWorkspace getWorkspace() {
|
||||
return ResourcesPlugin.getWorkspace();
|
||||
}
|
||||
|
||||
|
@ -59,11 +89,9 @@ public class CDescriptorManager implements ICDescriptorManager, IResourceChangeL
|
|||
if (resource.getType() == IResource.PROJECT) {
|
||||
IProject project = (IProject) resource;
|
||||
try {
|
||||
if (project.hasNature(CProjectNature.C_NATURE_ID)) {
|
||||
if (project.isOpen()) {
|
||||
if (project.isAccessible() && project.hasNature(CProjectNature.C_NATURE_ID)) {
|
||||
getDescriptor(project);
|
||||
}
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
}
|
||||
|
@ -86,8 +114,8 @@ public class CDescriptorManager implements ICDescriptorManager, IResourceChangeL
|
|||
IResource resource = event.getResource();
|
||||
|
||||
switch (event.getType()) {
|
||||
case IResourceChangeEvent.PRE_DELETE:
|
||||
case IResourceChangeEvent.PRE_CLOSE:
|
||||
case IResourceChangeEvent.PRE_DELETE :
|
||||
case IResourceChangeEvent.PRE_CLOSE :
|
||||
try {
|
||||
if (resource.getType() == IResource.PROJECT && ((IProject) resource).hasNature(CProjectNature.C_NATURE_ID)) {
|
||||
CDescriptor descriptor = (CDescriptor) fDescriptorMap.remove(resource);
|
||||
|
@ -99,7 +127,7 @@ public class CDescriptorManager implements ICDescriptorManager, IResourceChangeL
|
|||
CCorePlugin.log(e);
|
||||
}
|
||||
break;
|
||||
case IResourceChangeEvent.PRE_AUTO_BUILD:
|
||||
case IResourceChangeEvent.PRE_AUTO_BUILD :
|
||||
IResourceDelta resDelta = event.getDelta();
|
||||
if (resDelta == null) {
|
||||
break;
|
||||
|
@ -112,15 +140,12 @@ public class CDescriptorManager implements ICDescriptorManager, IResourceChangeL
|
|||
if (dResource.getType() == IResource.PROJECT) {
|
||||
if (0 != (delta.getFlags() & IResourceDelta.OPEN)) {
|
||||
IProject project = (IProject) dResource;
|
||||
if (project.hasNature(CProjectNature.C_NATURE_ID)) {
|
||||
if (project.isOpen()) {
|
||||
if (project.isAccessible() && project.hasNature(CProjectNature.C_NATURE_ID)) {
|
||||
getDescriptor(project);
|
||||
} else {
|
||||
CDescriptor descriptor = (CDescriptor) fDescriptorMap.remove(project);
|
||||
if (descriptor != null) {
|
||||
fireEvent(new CDescriptorEvent(descriptor, CDescriptorEvent.CDTPROJECT_REMOVED,
|
||||
0));
|
||||
}
|
||||
fireEvent(new CDescriptorEvent(descriptor, CDescriptorEvent.CDTPROJECT_REMOVED, 0));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
@ -134,7 +159,7 @@ public class CDescriptorManager implements ICDescriptorManager, IResourceChangeL
|
|||
// the file got deleted lets
|
||||
// try
|
||||
// and restore for memory.
|
||||
updateDescriptor(descriptor);
|
||||
descriptor.updateOnDisk();
|
||||
} else if ((delta.getFlags() & IResourceDelta.CONTENT) != 0) {
|
||||
// content change lets try to
|
||||
// read and update
|
||||
|
@ -160,7 +185,6 @@ public class CDescriptorManager implements ICDescriptorManager, IResourceChangeL
|
|||
CDescriptor descriptor = (CDescriptor) fDescriptorMap.get(project);
|
||||
if (descriptor == null) {
|
||||
descriptor = new CDescriptor(this, project);
|
||||
descriptor.setAutoSave(true);
|
||||
fDescriptorMap.put(project, descriptor);
|
||||
}
|
||||
return descriptor;
|
||||
|
@ -171,7 +195,7 @@ public class CDescriptorManager implements ICDescriptorManager, IResourceChangeL
|
|||
synchronized (this) {
|
||||
descriptor = (CDescriptor) fDescriptorMap.get(project);
|
||||
if (descriptor != null) {
|
||||
if (!descriptor.getOwner().getID().equals(id)) {
|
||||
if (!descriptor.getProjectOwner().getID().equals(id)) {
|
||||
IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, CCorePlugin.STATUS_CDTPROJECT_EXISTS,
|
||||
CCorePlugin.getResourceString("CDescriptorManager.exception.alreadyConfigured"), //$NON-NLS-1$
|
||||
(Throwable) null);
|
||||
|
@ -181,7 +205,6 @@ public class CDescriptorManager implements ICDescriptorManager, IResourceChangeL
|
|||
}
|
||||
try {
|
||||
descriptor = new CDescriptor(this, project, id);
|
||||
descriptor.getOwner().configure(project, descriptor);
|
||||
} catch (CoreException e) { // if .cdtproject already exists will
|
||||
// use that
|
||||
IStatus status = e.getStatus();
|
||||
|
@ -193,8 +216,6 @@ public class CDescriptorManager implements ICDescriptorManager, IResourceChangeL
|
|||
fDescriptorMap.put(project, descriptor);
|
||||
}
|
||||
fireEvent(new CDescriptorEvent(descriptor, CDescriptorEvent.CDTPROJECT_ADDED, 0));
|
||||
descriptor.setAutoSave(true);
|
||||
updateDescriptor(descriptor);
|
||||
}
|
||||
|
||||
public void convert(IProject project, String id) throws CoreException {
|
||||
|
@ -202,11 +223,8 @@ public class CDescriptorManager implements ICDescriptorManager, IResourceChangeL
|
|||
synchronized (this) {
|
||||
descriptor = new CDescriptor(this, project, new COwner(id));
|
||||
fDescriptorMap.put(project, descriptor);
|
||||
descriptor.getOwner().configure(project, descriptor);
|
||||
}
|
||||
fireEvent(new CDescriptorEvent(descriptor, CDescriptorEvent.CDTPROJECT_CHANGED, CDescriptorEvent.OWNER_CHANGED));
|
||||
descriptor.setAutoSave(true);
|
||||
updateDescriptor(descriptor);
|
||||
}
|
||||
|
||||
public void addDescriptorListener(ICDescriptorListener listener) {
|
||||
|
@ -257,11 +275,12 @@ public class CDescriptorManager implements ICDescriptorManager, IResourceChangeL
|
|||
}
|
||||
}
|
||||
|
||||
public void runDescriptorOperation(ICDescriptor descriptor, ICDescriptorOperation op) throws CoreException {
|
||||
public void runDescriptorOperation(IProject project, ICDescriptorOperation op, IProgressMonitor monitor) throws CoreException {
|
||||
ICDescriptor descriptor = getDescriptor(project);
|
||||
synchronized (descriptor) {
|
||||
beginOperation(descriptor);
|
||||
try {
|
||||
op.execute(descriptor);
|
||||
op.execute(descriptor, monitor);
|
||||
} finally {
|
||||
endOperation(descriptor);
|
||||
}
|
||||
|
@ -286,15 +305,7 @@ public class CDescriptorManager implements ICDescriptorManager, IResourceChangeL
|
|||
* owner update method, while the workspace is locked (ie during a
|
||||
* resourceChange event).
|
||||
*/
|
||||
protected void updateDescriptor(final CDescriptor descriptor) throws CoreException {
|
||||
if (fOperationMap.containsKey(descriptor)) {
|
||||
return;
|
||||
}
|
||||
getWorkspace().run(new IWorkspaceRunnable() {
|
||||
|
||||
public void run(IProgressMonitor monitor) throws CoreException {
|
||||
descriptor.saveInfo();
|
||||
}
|
||||
}, descriptor.getProject(), IWorkspace.AVOID_UPDATE, null);
|
||||
protected void updateDescriptor(CDescriptor descriptor) {
|
||||
new CDescriptorUpdater(descriptor).schedule();
|
||||
}
|
||||
}
|
|
@ -53,9 +53,10 @@ public class CExtensionReference implements ICExtensionReference {
|
|||
|
||||
public void setExtensionData(String key, String value) throws CoreException {
|
||||
getInfo().setAttribute(key, value);
|
||||
fDescriptor.setDirty();
|
||||
if (!fDescriptor.isInitializing) {
|
||||
fDescriptor.updateOnDisk();
|
||||
fDescriptor.fManager.fireEvent(new CDescriptorEvent(fDescriptor, CDescriptorEvent.CDTPROJECT_CHANGED, 0));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public String getExtensionData(String key) {
|
||||
|
|
Loading…
Add table
Reference in a new issue