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

update to allow non-owned project

This commit is contained in:
David Inglis 2004-03-25 20:00:40 +00:00
parent b2b554c440
commit 1c0c1dbe99
7 changed files with 251 additions and 157 deletions

View file

@ -1,3 +1,14 @@
2004-03-25 David Inglis
Update to allow non-owned projects and added better recovery of deleted .cdtprojects via nature id
* src/org/eclipse/cdt/core/ICDescriptorManager.java
* src/org/eclipse/cdt/internal/core/CCorePluginResources.properties
* src/org/eclipse/cdt/internal/core/CDescriptor.java
* src/org/eclipse/cdt/internal/core/CDescriptorManager.java
* src/org/eclipse/cdt/internal/core/COwner.java
* src/org/eclipse/cdt/internal/core/COwnerConfiguration.java
2004-03-25 David Inglis 2004-03-25 David Inglis
Fixed up getProcessList to filter on platform. Fixed up getProcessList to filter on platform.

View file

@ -14,6 +14,9 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
public interface ICDescriptorManager { public interface ICDescriptorManager {
public void configure(IProject project, String id) throws CoreException;
public void convert(IProject project, String id) throws CoreException;
public ICDescriptor getDescriptor(IProject project) throws CoreException; public ICDescriptor getDescriptor(IProject project) throws CoreException;
public void runDescriptorOperation(IProject project, ICDescriptorOperation op, IProgressMonitor monitor) throws CoreException; public void runDescriptorOperation(IProject project, ICDescriptorOperation op, IProgressMonitor monitor) throws CoreException;

View file

@ -20,11 +20,12 @@ CCProjectNature.exception.noNature=Project must have a cnature
CCorePlugin.exception.noBinaryFormat=No Binary Format CCorePlugin.exception.noBinaryFormat=No Binary Format
CDescriptorManager.exception.alreadyConfigured=CDTProject already configured CDescriptorManager.exception.invalid_ownerID=Invalid CDT Project owner ID
CDescriptorManager.exception.notAC/C++Project=Not a C/C++ Project CDescriptorManager.exception.alreadyConfigured=CDT Project already configured
CDescriptorManager.exception.listenerError=An exception occurred during descriptor notification CDescriptorManager.exception.listenerError=An exception occurred during descriptor notification
COwner.exception.invalidOwnerID=Invalid CDTProject owner ID CDescriptorManager.internal_owner=No CDT Project owner
COwner.exception.invalidOwnerExtension=Invalid CDTProject owner extension CDescriptorManager.async_updater=CDT Project async save
CDescriptorManager.owner_not_Installed=CDT Project owner not installed
CDescriptor.exception.projectAlreadyExists=CDTProject already exisits CDescriptor.exception.projectAlreadyExists=CDTProject already exisits
CDescriptor.exception.unmatchedOwnerId=CDTProject already exisits but does not match owner ID of creator CDescriptor.exception.unmatchedOwnerId=CDTProject already exisits but does not match owner ID of creator

View file

@ -60,7 +60,7 @@ import org.w3c.dom.ProcessingInstruction;
public class CDescriptor implements ICDescriptor { public class CDescriptor implements ICDescriptor {
final CDescriptorManager fManager; final CDescriptorManager fManager;
private final IProject fProject; final IProject fProject;
private COwner fOwner; private COwner fOwner;
private HashMap extMap = new HashMap(4); private HashMap extMap = new HashMap(4);
@ -84,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_ITEM = "item"; //$NON-NLS-1$
private static final String PROJECT_DATA_ID = "id"; //$NON-NLS-1$ private static final String PROJECT_DATA_ID = "id"; //$NON-NLS-1$
private boolean fUpdating; boolean fUpdating;
boolean isInitializing = false; boolean isInitializing = true;
protected CDescriptor(CDescriptorManager manager, IProject project, String id) throws CoreException { protected CDescriptor(CDescriptorManager manager, IProject project, String id) throws CoreException {
fProject = project; fProject = project;
@ -101,7 +101,6 @@ public class CDescriptor implements ICDescriptor {
IStatus status; IStatus status;
String ownerID = readCDTProjectFile(descriptionPath); String ownerID = readCDTProjectFile(descriptionPath);
if (ownerID.equals(id)) { if (ownerID.equals(id)) {
fOwner = new COwner(ownerID);
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 {
@ -110,8 +109,7 @@ public class CDescriptor implements ICDescriptor {
} }
throw new CoreException(status); throw new CoreException(status);
} }
fOwner = new COwner(id); fOwner = new COwner(manager.getOwnerConfiguration(id));
isInitializing = true;
fOwner.configure(project, this); fOwner.configure(project, this);
isInitializing = false; isInitializing = false;
save(); save();
@ -128,11 +126,14 @@ public class CDescriptor implements ICDescriptor {
IPath descriptionPath = projectLocation.append(DESCRIPTION_FILE_NAME); IPath descriptionPath = projectLocation.append(DESCRIPTION_FILE_NAME);
if (!descriptionPath.toFile().exists()) { if (!descriptionPath.toFile().exists()) {
IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, fOwner = new COwner(manager.getOwnerConfiguration(project));
CCorePlugin.getResourceString("CDescriptor.exception.fileNotFound"), (Throwable) null); //$NON-NLS-1$ fOwner.configure(project, this);
throw new CoreException(status); isInitializing = false;
fManager.updateDescriptor(this);
} else {
String ownerId = readCDTProjectFile(descriptionPath);
fOwner = new COwner(manager.getOwnerConfiguration(ownerId));
} }
fOwner = new COwner(readCDTProjectFile(descriptionPath));
} }
protected CDescriptor(CDescriptorManager manager, IProject project, COwner owner) throws CoreException { protected CDescriptor(CDescriptorManager manager, IProject project, COwner owner) throws CoreException {
@ -145,14 +146,10 @@ public class CDescriptor implements ICDescriptor {
} }
IPath descriptionPath = projectLocation.append(DESCRIPTION_FILE_NAME); IPath descriptionPath = projectLocation.append(DESCRIPTION_FILE_NAME);
if (!descriptionPath.toFile().exists()) { if (descriptionPath.toFile().exists()) {
IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, readCDTProjectFile(descriptionPath);
CCorePlugin.getResourceString("CDescriptor.exception.fileNotFound"), (Throwable) null); //$NON-NLS-1$
throw new CoreException(status);
} }
readCDTProjectFile(descriptionPath);
fOwner = owner; fOwner = owner;
isInitializing = true;
fOwner.configure(project, this); fOwner.configure(project, this);
isInitializing = false; isInitializing = false;
save(); save();
@ -160,6 +157,7 @@ public class CDescriptor implements ICDescriptor {
private String readCDTProjectFile(IPath descriptionPath) throws CoreException { private String readCDTProjectFile(IPath descriptionPath) throws CoreException {
FileInputStream file = null; FileInputStream file = null;
String ownerID = ""; //$NON-NLS-1$
try { try {
file = new FileInputStream(descriptionPath.toFile()); file = new FileInputStream(descriptionPath.toFile());
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder(); DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
@ -167,14 +165,11 @@ public class CDescriptor implements ICDescriptor {
NodeList nodeList = document.getElementsByTagName(PROJECT_DESCRIPTION); NodeList nodeList = document.getElementsByTagName(PROJECT_DESCRIPTION);
if (nodeList != null && nodeList.getLength() > 0) { if (nodeList != null && nodeList.getLength() > 0) {
Node node = nodeList.item(0); Node node = nodeList.item(0);
String ownerID = node.getAttributes().getNamedItem(PROJECT_OWNER_ID).getNodeValue(); if (node.hasAttributes()) {
if (ownerID != null) { ownerID = node.getAttributes().getNamedItem(PROJECT_OWNER_ID).getNodeValue();
readProjectDescription(node);
return ownerID;
} }
IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, readProjectDescription(node);
CCorePlugin.getResourceString("CDescriptor.exception.missingOwnerId"), null); //$NON-NLS-1$ return ownerID;
throw new CoreException(status);
} }
IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1,
CCorePlugin.getResourceString("CDescriptor.exception.missingElement"), null); //$NON-NLS-1$ CCorePlugin.getResourceString("CDescriptor.exception.missingElement"), null); //$NON-NLS-1$
@ -192,7 +187,7 @@ public class CDescriptor implements ICDescriptor {
} }
} }
private IPath getProjectDefaultLocation(IProject project) { private static IPath getProjectDefaultLocation(IProject project) {
return Platform.getLocation().append(project.getFullPath()); return Platform.getLocation().append(project.getFullPath());
} }
@ -216,8 +211,8 @@ public class CDescriptor implements ICDescriptor {
} }
synchronized public ICExtensionReference[] get(String extensionID, boolean update) { synchronized public ICExtensionReference[] get(String extensionID, boolean update) {
ICExtensionReference[] ext = get(extensionID); ICExtensionReference[] refs = get(extensionID);
if (ext.length == 0 && update) { if (refs.length == 0 && update) {
try { try {
boolean oldIsInitializing = isInitializing; boolean oldIsInitializing = isInitializing;
isInitializing = true; isInitializing = true;
@ -226,11 +221,11 @@ public class CDescriptor implements ICDescriptor {
if (!isInitializing) { if (!isInitializing) {
updateOnDisk(); updateOnDisk();
} }
ext = get(extensionID); refs = get(extensionID);
} catch (CoreException e) { } catch (CoreException e) {
} }
} }
return ext; return refs;
} }
private CExtensionReference createRef(String extensionPoint, String extension) { private CExtensionReference createRef(String extensionPoint, String extension) {
@ -303,35 +298,44 @@ public class CDescriptor implements ICDescriptor {
return getProject().getFile(DESCRIPTION_FILE_NAME); return getProject().getFile(DESCRIPTION_FILE_NAME);
} }
synchronized void save() throws CoreException { void save() throws CoreException {
String xml; fManager.getWorkspace().run(new IWorkspaceRunnable() {
if (!fProject.isAccessible()) {
return;
}
fUpdating = true;
try { public void run(IProgressMonitor mon) throws CoreException {
xml = getAsXML(); String xml;
} catch (IOException e) { if (!fProject.isAccessible()) {
IStatus s = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, e.getMessage(), e); return;
throw new CoreException(s); }
} catch (TransformerException e) { fUpdating = true;
IStatus s = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, e.getMessage(), e);
throw new CoreException(s);
} catch (ParserConfigurationException e) {
IStatus s = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, e.getMessage(), e);
throw new CoreException(s);
}
IFile rscFile = getFile(); try {
InputStream inputStream = new ByteArrayInputStream(xml.getBytes()); xml = getAsXML();
// update the resource content } catch (IOException e) {
if (rscFile.exists()) { IStatus s = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, e.getMessage(), e);
rscFile.setContents(inputStream, IResource.FORCE, null); throw new CoreException(s);
} else { } catch (TransformerException e) {
rscFile.create(inputStream, IResource.FORCE, null); IStatus s = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, e.getMessage(), e);
} throw new CoreException(s);
fUpdating = false; } catch (ParserConfigurationException e) {
IStatus s = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, e.getMessage(), e);
throw new CoreException(s);
}
IFile rscFile = getFile();
InputStream inputStream = new ByteArrayInputStream(xml.getBytes());
// update the resource content
if (rscFile.exists()) {
if (rscFile.isReadOnly()) {
// provide opportunity to checkout read-only .cdtproject file
fManager.getWorkspace().validateEdit(new IFile[]{rscFile}, null);
}
rscFile.setContents(inputStream, IResource.FORCE, null);
} else {
rscFile.create(inputStream, IResource.FORCE, null);
}
fUpdating = false;
}
}, fProject, IWorkspace.AVOID_UPDATE, null);
} }
boolean isUpdating() { boolean isUpdating() {
@ -367,7 +371,8 @@ public class CDescriptor implements ICDescriptor {
dataDoc = null; dataDoc = null;
try { try {
fOwner = new COwner(readCDTProjectFile(descriptionPath)); String ownerId = readCDTProjectFile(descriptionPath);
fOwner = new COwner(fManager.getOwnerConfiguration(ownerId));
} catch (CoreException e) { } catch (CoreException e) {
CCorePlugin.log(e); CCorePlugin.log(e);
fOwner = origOwner; fOwner = origOwner;
@ -466,7 +471,7 @@ public class CDescriptor implements ICDescriptor {
} }
} }
private String getAsXML() throws IOException, TransformerException, ParserConfigurationException { String getAsXML() throws IOException, TransformerException, ParserConfigurationException {
DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance(); DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = dfactory.newDocumentBuilder(); DocumentBuilder docBuilder = dfactory.newDocumentBuilder();
Document doc = docBuilder.newDocument(); Document doc = docBuilder.newDocument();
@ -474,7 +479,9 @@ public class CDescriptor implements ICDescriptor {
doc.appendChild(version); doc.appendChild(version);
Element configRootElement = doc.createElement(PROJECT_DESCRIPTION); Element configRootElement = doc.createElement(PROJECT_DESCRIPTION);
doc.appendChild(configRootElement); doc.appendChild(configRootElement);
configRootElement.setAttribute(PROJECT_OWNER_ID, fOwner.getID()); if (fOwner.getID().length() > 0) {
configRootElement.setAttribute(PROJECT_OWNER_ID, fOwner.getID());
}
encodeProjectExtensions(doc, configRootElement); encodeProjectExtensions(doc, configRootElement);
encodeProjectData(doc, configRootElement); encodeProjectData(doc, configRootElement);
return serializeDocument(doc); return serializeDocument(doc);
@ -534,12 +541,7 @@ public class CDescriptor implements ICDescriptor {
} }
public void saveProjectData() throws CoreException { public void saveProjectData() throws CoreException {
fManager.getWorkspace().run(new IWorkspaceRunnable() { save();
public void run(IProgressMonitor mon) throws CoreException {
save();
}
}, fProject, IWorkspace.AVOID_UPDATE, null);
fManager.fireEvent(new CDescriptorEvent(this, CDescriptorEvent.CDTPROJECT_CHANGED, 0)); fManager.fireEvent(new CDescriptorEvent(this, CDescriptorEvent.CDTPROJECT_CHANGED, 0));
} }

View file

@ -9,10 +9,13 @@
******************************************************************************/ ******************************************************************************/
package org.eclipse.cdt.internal.core; package org.eclipse.cdt.internal.core;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Vector; import java.util.Vector;
import java.util.Map.Entry;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.CDescriptorEvent; import org.eclipse.cdt.core.CDescriptorEvent;
@ -22,6 +25,7 @@ import org.eclipse.cdt.core.ICDescriptorListener;
import org.eclipse.cdt.core.ICDescriptorManager; import org.eclipse.cdt.core.ICDescriptorManager;
import org.eclipse.cdt.core.ICDescriptorOperation; import org.eclipse.cdt.core.ICDescriptorOperation;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceChangeEvent; import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener; import org.eclipse.core.resources.IResourceChangeListener;
@ -29,9 +33,11 @@ import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.IResourceDeltaVisitor; import org.eclipse.core.resources.IResourceDeltaVisitor;
import org.eclipse.core.resources.IResourceVisitor; import org.eclipse.core.resources.IResourceVisitor;
import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRunnable;
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.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.ISafeRunnable; import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.IStatus;
@ -41,10 +47,14 @@ import org.eclipse.core.runtime.jobs.Job;
public class CDescriptorManager implements ICDescriptorManager, IResourceChangeListener { public class CDescriptorManager implements ICDescriptorManager, IResourceChangeListener {
HashMap fOperationMap = new HashMap(); Map fOperationMap = new HashMap(1);
HashMap fDescriptorMap = new HashMap(); Map fDescriptorMap = new HashMap();
Map fOwnerConfigMap = null;
List listeners = new Vector(); List listeners = new Vector();
private static final COwnerConfiguration NULLCOwner = new COwnerConfiguration("", //$NON-NLS-1$
CCorePlugin.getResourceString("CDescriptorManager.internal_owner")); //$NON-NLS-1$
class CDescriptorUpdater extends Job { class CDescriptorUpdater extends Job {
CDescriptor fDescriptor; CDescriptor fDescriptor;
@ -59,13 +69,7 @@ public class CDescriptorManager implements ICDescriptorManager, IResourceChangeL
protected IStatus run(IProgressMonitor monitor) { protected IStatus run(IProgressMonitor monitor) {
try { try {
getWorkspace().run(new IWorkspaceRunnable() { fDescriptor.save();
public void run(IProgressMonitor mon) throws CoreException {
fDescriptor.save();
}
}, getRule(), IWorkspace.AVOID_UPDATE, monitor);
} catch (CoreException e) { } catch (CoreException e) {
return e.getStatus(); return e.getStatus();
} }
@ -156,8 +160,7 @@ public class CDescriptorManager implements ICDescriptorManager, IResourceChangeL
CDescriptor descriptor = (CDescriptor) fDescriptorMap.get(dResource.getProject()); CDescriptor descriptor = (CDescriptor) fDescriptorMap.get(dResource.getProject());
if (descriptor != null) { if (descriptor != null) {
if ((delta.getKind() & IResourceDelta.REMOVED) != 0) { if ((delta.getKind() & IResourceDelta.REMOVED) != 0) {
// the file got deleted lets // the file got deleted lets try
// try
// and restore for memory. // and restore for memory.
descriptor.updateOnDisk(); descriptor.updateOnDisk();
} else if ((delta.getFlags() & IResourceDelta.CONTENT) != 0) { } else if ((delta.getFlags() & IResourceDelta.CONTENT) != 0) {
@ -181,7 +184,56 @@ public class CDescriptorManager implements ICDescriptorManager, IResourceChangeL
} }
} }
public /*synchronized */ ICDescriptor getDescriptor(IProject project) throws CoreException { private void initializeOwnerConfiguration() {
IExtensionPoint extpoint = CCorePlugin.getDefault().getDescriptor().getExtensionPoint("CProject"); //$NON-NLS-1$
IExtension extension[] = extpoint.getExtensions();
fOwnerConfigMap = new HashMap(extension.length);
for (int i = 0; i < extension.length; i++) {
IConfigurationElement element[] = extension[i].getConfigurationElements();
for (int j = 0; j < element.length; j++) {
if (element[j].getName().equalsIgnoreCase("cproject")) { //$NON-NLS-1$
fOwnerConfigMap.put(extension[i].getUniqueIdentifier(), new COwnerConfiguration(element[j]));
break;
}
}
}
}
COwnerConfiguration getOwnerConfiguration(String id) {
if (id.equals(NULLCOwner.getOwnerID())) { //$NON-NLS-1$
return NULLCOwner;
}
if (fOwnerConfigMap == null) {
initializeOwnerConfiguration();
}
COwnerConfiguration config = (COwnerConfiguration) fOwnerConfigMap.get(id);
if (config == null) { // no install owner, lets create place holder config for it.
config = new COwnerConfiguration(id, CCorePlugin.getResourceString("CDescriptorManager.owner_not_Installed")); //$NON-NLS-1$
fOwnerConfigMap.put(id, config);
}
return config;
}
COwnerConfiguration getOwnerConfiguration(IProject project) throws CoreException {
if (fOwnerConfigMap == null) {
initializeOwnerConfiguration();
}
IProjectDescription description = project.getDescription();
String natureIDs[] = description.getNatureIds();
Iterator configs = fOwnerConfigMap.entrySet().iterator();
while (configs.hasNext()) {
Entry entry = (Entry) configs.next();
COwnerConfiguration config = (COwnerConfiguration) entry.getValue();
if (config.getNature() != null) {
if (Arrays.asList(natureIDs).lastIndexOf(config.getNature()) != -1) {
return config;
}
}
}
return NULLCOwner;
}
synchronized public ICDescriptor getDescriptor(IProject project) throws CoreException {
CDescriptor descriptor = (CDescriptor) fDescriptorMap.get(project); CDescriptor descriptor = (CDescriptor) fDescriptorMap.get(project);
if (descriptor == null) { if (descriptor == null) {
descriptor = new CDescriptor(this, project); descriptor = new CDescriptor(this, project);
@ -192,26 +244,36 @@ public class CDescriptorManager implements ICDescriptorManager, IResourceChangeL
public void configure(IProject project, String id) throws CoreException { public void configure(IProject project, String id) throws CoreException {
CDescriptor descriptor; CDescriptor descriptor;
if (id.equals(NULLCOwner.getOwnerID())) { //$NON-NLS-1$
IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1,
CCorePlugin.getResourceString("CDescriptorManager.exception.invalid_ownerID"), //$NON-NLS-1$
(Throwable) null);
throw new CoreException(status);
}
synchronized (this) { synchronized (this) {
descriptor = (CDescriptor) fDescriptorMap.get(project); descriptor = (CDescriptor) fDescriptorMap.get(project);
if (descriptor != null) { if (descriptor != null) {
if (!descriptor.getProjectOwner().getID().equals(id)) { if (descriptor.getProjectOwner().getID().equals(NULLCOwner.getOwnerID())) { //$NON-NLS-1$
// non owned descriptors are simply configure to the new owner no questions ask!
descriptor = new CDescriptor(this, project, new COwner(getOwnerConfiguration(id)));
} else if (!descriptor.getProjectOwner().getID().equals(id)) {
IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, CCorePlugin.STATUS_CDTPROJECT_EXISTS, IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, CCorePlugin.STATUS_CDTPROJECT_EXISTS,
CCorePlugin.getResourceString("CDescriptorManager.exception.alreadyConfigured"), //$NON-NLS-1$ CCorePlugin.getResourceString("CDescriptorManager.exception.alreadyConfigured"), //$NON-NLS-1$
(Throwable) null); (Throwable) null);
throw new CoreException(status); throw new CoreException(status);
} else {
return; // already configured with same owner.
}
} else {
try {
descriptor = new CDescriptor(this, project, id);
} catch (CoreException e) { // if .cdtproject already exists we'll use that
IStatus status = e.getStatus();
if (status.getCode() == CCorePlugin.STATUS_CDTPROJECT_EXISTS) {
descriptor = new CDescriptor(this, project);
} else
throw e;
} }
return;
}
try {
descriptor = new CDescriptor(this, project, id);
} catch (CoreException e) { // if .cdtproject already exists will
// use that
IStatus status = e.getStatus();
if (status.getCode() == CCorePlugin.STATUS_CDTPROJECT_EXISTS) {
descriptor = new CDescriptor(this, project);
} else
throw e;
} }
fDescriptorMap.put(project, descriptor); fDescriptorMap.put(project, descriptor);
} }
@ -221,7 +283,7 @@ public class CDescriptorManager implements ICDescriptorManager, IResourceChangeL
public void convert(IProject project, String id) throws CoreException { public void convert(IProject project, String id) throws CoreException {
CDescriptor descriptor; CDescriptor descriptor;
synchronized (this) { synchronized (this) {
descriptor = new CDescriptor(this, project, new COwner(id)); descriptor = new CDescriptor(this, project, new COwner(getOwnerConfiguration(id)));
fDescriptorMap.put(project, descriptor); fDescriptorMap.put(project, descriptor);
} }
fireEvent(new CDescriptorEvent(descriptor, CDescriptorEvent.CDTPROJECT_CHANGED, CDescriptorEvent.OWNER_CHANGED)); fireEvent(new CDescriptorEvent(descriptor, CDescriptorEvent.CDTPROJECT_CHANGED, CDescriptorEvent.OWNER_CHANGED));
@ -238,7 +300,7 @@ public class CDescriptorManager implements ICDescriptorManager, IResourceChangeL
protected void fireEvent(final CDescriptorEvent event) { protected void fireEvent(final CDescriptorEvent event) {
if (fOperationMap.containsKey(event.getDescriptor())) { if (fOperationMap.containsKey(event.getDescriptor())) {
// lets just hold on to the important event in order of; // lets just hold on to the important event in order of;
// ADD/REMOVE shouldn' every receive the remove but.... // ADD/REMOVE should not receive the remove but....
// OWNER_CHANGED // OWNER_CHANGED
// EXT_CHANGED // EXT_CHANGED
// other // other
@ -299,11 +361,9 @@ public class CDescriptorManager implements ICDescriptorManager, IResourceChangeL
} }
/* /*
* Perform a update of the ondisk .cdtproject file. This is nessecary to * Perform a update of the ondisk .cdtproject file. This is nessecary to avoid deadlocking when the descriptor has change from a
* avoid deadlocking when the descriptor has change from a call to * call to ICDescriptor.get(project, true) which may update the descriptor via the owner update method, while the workspace is
* ICDescriptor.get(project, true) which may update the descriptor via the * locked (ie during a resourceChange event).
* owner update method, while the workspace is locked (ie during a
* resourceChange event).
*/ */
protected void updateDescriptor(CDescriptor descriptor) { protected void updateDescriptor(CDescriptor descriptor) {
new CDescriptorUpdater(descriptor).schedule(); new CDescriptorUpdater(descriptor).schedule();

View file

@ -9,85 +9,43 @@
******************************************************************************/ ******************************************************************************/
package org.eclipse.cdt.internal.core; package org.eclipse.cdt.internal.core;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ICDescriptor; import org.eclipse.cdt.core.ICDescriptor;
import org.eclipse.cdt.core.ICOwner; import org.eclipse.cdt.core.ICOwner;
import org.eclipse.cdt.core.ICOwnerInfo; import org.eclipse.cdt.core.ICOwnerInfo;
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.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
public class COwner implements ICOwnerInfo { public class COwner implements ICOwnerInfo {
String ownerID; final COwnerConfiguration fConfig;
String fPlatform;
IExtension extension;
public COwner(String id) throws CoreException { public COwner(COwnerConfiguration config) throws CoreException {
ownerID = id; fConfig = config;
IExtensionPoint extpoint = CCorePlugin.getDefault().getDescriptor().getExtensionPoint("CProject"); //$NON-NLS-1$
extension = extpoint.getExtension(ownerID);
} }
public String getID() { public String getID() {
return ownerID; return fConfig.getOwnerID();
} }
public String getName() { public String getName() {
return extension == null ? "Unknown" : extension.getLabel(); //$NON-NLS-1$ return fConfig.getName();
} }
public String getPlatform() { public String getPlatform() {
if (fPlatform == null && extension != null) { return fConfig.getPlatform();
IConfigurationElement element[] = extension.getConfigurationElements();
for (int i = 0; i < element.length; i++) {
if (element[i].getName().equalsIgnoreCase("cproject")) { //$NON-NLS-1$
fPlatform = element[i].getAttribute("platform"); //$NON-NLS-1$
break;
}
}
}
return fPlatform == null ? "*" : fPlatform; //$NON-NLS-1$
} }
void configure(IProject project, ICDescriptor cproject) throws CoreException { void configure(IProject project, ICDescriptor cproject) throws CoreException {
if (extension == null) { ICOwner owner = fConfig.createOwner();
IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, if (owner != null) {
CCorePlugin.getResourceString("COwner.exception.invalidOwnerID"), (Throwable) null); //$NON-NLS-1$ owner.configure(cproject);
throw new CoreException(status);
} }
IConfigurationElement element[] = extension.getConfigurationElements();
for (int i = 0; i < element.length; i++) {
if (element[i].getName().equalsIgnoreCase("cproject")) { //$NON-NLS-1$
ICOwner owner = (ICOwner) element[i].createExecutableExtension("class"); //$NON-NLS-1$
owner.configure(cproject);
return;
}
}
IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1,
CCorePlugin.getResourceString("COwner.exception.invalidOwnerExtension"), //$NON-NLS-1$
(Throwable) null);
throw new CoreException(status);
} }
void update(IProject project, ICDescriptor cproject, String extensionID) throws CoreException { void update(IProject project, ICDescriptor cproject, String extensionID) throws CoreException {
if (extension != null) { ICOwner owner = fConfig.createOwner();
IConfigurationElement element[] = extension.getConfigurationElements(); if (owner != null) {
for (int i = 0; i < element.length; i++) { owner.update(cproject, extensionID);
if (element[i].getName().equalsIgnoreCase("cproject")) { //$NON-NLS-1$
ICOwner owner = (ICOwner) element[i].createExecutableExtension("class"); //$NON-NLS-1$
owner.update(cproject, extensionID);
return;
}
}
IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1,
CCorePlugin.getResourceString("COwner.exception.invalidOwnerExtension"), //$NON-NLS-1$
(Throwable) null);
throw new CoreException(status);
} }
} }
@ -95,8 +53,8 @@ public class COwner implements ICOwnerInfo {
if (obj == this) { if (obj == this) {
return true; return true;
} }
if ( obj instanceof COwner) { if (obj instanceof COwner) {
return ((COwner)obj).ownerID.equals(ownerID); return ((COwner) obj).getID().equals(getID());
} }
return false; return false;
} }

View file

@ -0,0 +1,59 @@
/*
* Created on Mar 24, 2004
*
* Copyright (c) 2002,2003 QNX Software Systems Ltd.
*
* Contributors:
* QNX Software Systems - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.internal.core;
import org.eclipse.cdt.core.ICOwner;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
public class COwnerConfiguration {
final IConfigurationElement fElement;
final String fOwnerID, fName;
public COwnerConfiguration(IConfigurationElement element) {
fElement = element;
fOwnerID = fElement.getDeclaringExtension().getUniqueIdentifier();
fName = fElement.getDeclaringExtension().getLabel();
}
public COwnerConfiguration(String id, String name) {
fElement = null;
fOwnerID = id;
fName = name;
}
public String getOwnerID() {
return fOwnerID;
}
public String getName() {
return fName;
}
public String getPlatform() {
String platform = null;
if (fElement != null) {
platform = fElement.getAttribute("platform"); //$NON-NLS-1$
}
return platform == null ? "*" : platform; //$NON-NLS-1$
}
public ICOwner createOwner() throws CoreException {
if (fElement != null) {
return (ICOwner) fElement.createExecutableExtension("class"); //$NON-NLS-1$
}
return null;
}
public String getNature() {
return fElement != null ? fElement.getAttribute("natureID") : null; //$NON-NLS-1$
}
}