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:
parent
b2b554c440
commit
1c0c1dbe99
7 changed files with 251 additions and 157 deletions
|
@ -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
|
||||
|
||||
Fixed up getProcessList to filter on platform.
|
||||
|
|
|
@ -14,6 +14,9 @@ import org.eclipse.core.runtime.CoreException;
|
|||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
|
||||
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 void runDescriptorOperation(IProject project, ICDescriptorOperation op, IProgressMonitor monitor) throws CoreException;
|
||||
|
|
|
@ -20,11 +20,12 @@ CCProjectNature.exception.noNature=Project must have a cnature
|
|||
|
||||
CCorePlugin.exception.noBinaryFormat=No Binary Format
|
||||
|
||||
CDescriptorManager.exception.alreadyConfigured=CDTProject already configured
|
||||
CDescriptorManager.exception.notAC/C++Project=Not a C/C++ Project
|
||||
CDescriptorManager.exception.invalid_ownerID=Invalid CDT Project owner ID
|
||||
CDescriptorManager.exception.alreadyConfigured=CDT Project already configured
|
||||
CDescriptorManager.exception.listenerError=An exception occurred during descriptor notification
|
||||
COwner.exception.invalidOwnerID=Invalid CDTProject owner ID
|
||||
COwner.exception.invalidOwnerExtension=Invalid CDTProject owner extension
|
||||
CDescriptorManager.internal_owner=No CDT Project owner
|
||||
CDescriptorManager.async_updater=CDT Project async save
|
||||
CDescriptorManager.owner_not_Installed=CDT Project owner not installed
|
||||
|
||||
CDescriptor.exception.projectAlreadyExists=CDTProject already exisits
|
||||
CDescriptor.exception.unmatchedOwnerId=CDTProject already exisits but does not match owner ID of creator
|
||||
|
|
|
@ -60,7 +60,7 @@ import org.w3c.dom.ProcessingInstruction;
|
|||
public class CDescriptor implements ICDescriptor {
|
||||
|
||||
final CDescriptorManager fManager;
|
||||
private final IProject fProject;
|
||||
final IProject fProject;
|
||||
private COwner fOwner;
|
||||
|
||||
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_ID = "id"; //$NON-NLS-1$
|
||||
|
||||
private boolean fUpdating;
|
||||
boolean isInitializing = false;
|
||||
boolean fUpdating;
|
||||
boolean isInitializing = true;
|
||||
|
||||
protected CDescriptor(CDescriptorManager manager, IProject project, String id) throws CoreException {
|
||||
fProject = project;
|
||||
|
@ -101,7 +101,6 @@ public class CDescriptor implements ICDescriptor {
|
|||
IStatus status;
|
||||
String ownerID = readCDTProjectFile(descriptionPath);
|
||||
if (ownerID.equals(id)) {
|
||||
fOwner = new COwner(ownerID);
|
||||
status = new Status(IStatus.WARNING, CCorePlugin.PLUGIN_ID, CCorePlugin.STATUS_CDTPROJECT_EXISTS,
|
||||
CCorePlugin.getResourceString("CDescriptor.exception.projectAlreadyExists"), (Throwable) null); //$NON-NLS-1$
|
||||
} else {
|
||||
|
@ -110,8 +109,7 @@ public class CDescriptor implements ICDescriptor {
|
|||
}
|
||||
throw new CoreException(status);
|
||||
}
|
||||
fOwner = new COwner(id);
|
||||
isInitializing = true;
|
||||
fOwner = new COwner(manager.getOwnerConfiguration(id));
|
||||
fOwner.configure(project, this);
|
||||
isInitializing = false;
|
||||
save();
|
||||
|
@ -128,11 +126,14 @@ public class CDescriptor implements ICDescriptor {
|
|||
IPath descriptionPath = projectLocation.append(DESCRIPTION_FILE_NAME);
|
||||
|
||||
if (!descriptionPath.toFile().exists()) {
|
||||
IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1,
|
||||
CCorePlugin.getResourceString("CDescriptor.exception.fileNotFound"), (Throwable) null); //$NON-NLS-1$
|
||||
throw new CoreException(status);
|
||||
fOwner = new COwner(manager.getOwnerConfiguration(project));
|
||||
fOwner.configure(project, this);
|
||||
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 {
|
||||
|
@ -145,14 +146,10 @@ public class CDescriptor implements ICDescriptor {
|
|||
}
|
||||
IPath descriptionPath = projectLocation.append(DESCRIPTION_FILE_NAME);
|
||||
|
||||
if (!descriptionPath.toFile().exists()) {
|
||||
IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1,
|
||||
CCorePlugin.getResourceString("CDescriptor.exception.fileNotFound"), (Throwable) null); //$NON-NLS-1$
|
||||
throw new CoreException(status);
|
||||
if (descriptionPath.toFile().exists()) {
|
||||
readCDTProjectFile(descriptionPath);
|
||||
}
|
||||
readCDTProjectFile(descriptionPath);
|
||||
fOwner = owner;
|
||||
isInitializing = true;
|
||||
fOwner.configure(project, this);
|
||||
isInitializing = false;
|
||||
save();
|
||||
|
@ -160,6 +157,7 @@ public class CDescriptor implements ICDescriptor {
|
|||
|
||||
private String readCDTProjectFile(IPath descriptionPath) throws CoreException {
|
||||
FileInputStream file = null;
|
||||
String ownerID = ""; //$NON-NLS-1$
|
||||
try {
|
||||
file = new FileInputStream(descriptionPath.toFile());
|
||||
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||
|
@ -167,14 +165,11 @@ public class CDescriptor implements ICDescriptor {
|
|||
NodeList nodeList = document.getElementsByTagName(PROJECT_DESCRIPTION);
|
||||
if (nodeList != null && nodeList.getLength() > 0) {
|
||||
Node node = nodeList.item(0);
|
||||
String ownerID = node.getAttributes().getNamedItem(PROJECT_OWNER_ID).getNodeValue();
|
||||
if (ownerID != null) {
|
||||
readProjectDescription(node);
|
||||
return ownerID;
|
||||
if (node.hasAttributes()) {
|
||||
ownerID = node.getAttributes().getNamedItem(PROJECT_OWNER_ID).getNodeValue();
|
||||
}
|
||||
IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1,
|
||||
CCorePlugin.getResourceString("CDescriptor.exception.missingOwnerId"), null); //$NON-NLS-1$
|
||||
throw new CoreException(status);
|
||||
readProjectDescription(node);
|
||||
return ownerID;
|
||||
}
|
||||
IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -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());
|
||||
}
|
||||
|
||||
|
@ -216,8 +211,8 @@ public class CDescriptor implements ICDescriptor {
|
|||
}
|
||||
|
||||
synchronized public ICExtensionReference[] get(String extensionID, boolean update) {
|
||||
ICExtensionReference[] ext = get(extensionID);
|
||||
if (ext.length == 0 && update) {
|
||||
ICExtensionReference[] refs = get(extensionID);
|
||||
if (refs.length == 0 && update) {
|
||||
try {
|
||||
boolean oldIsInitializing = isInitializing;
|
||||
isInitializing = true;
|
||||
|
@ -226,11 +221,11 @@ public class CDescriptor implements ICDescriptor {
|
|||
if (!isInitializing) {
|
||||
updateOnDisk();
|
||||
}
|
||||
ext = get(extensionID);
|
||||
refs = get(extensionID);
|
||||
} catch (CoreException e) {
|
||||
}
|
||||
}
|
||||
return ext;
|
||||
return refs;
|
||||
}
|
||||
|
||||
private CExtensionReference createRef(String extensionPoint, String extension) {
|
||||
|
@ -303,35 +298,44 @@ public class CDescriptor implements ICDescriptor {
|
|||
return getProject().getFile(DESCRIPTION_FILE_NAME);
|
||||
}
|
||||
|
||||
synchronized void save() throws CoreException {
|
||||
String xml;
|
||||
if (!fProject.isAccessible()) {
|
||||
return;
|
||||
}
|
||||
fUpdating = true;
|
||||
void save() throws CoreException {
|
||||
fManager.getWorkspace().run(new IWorkspaceRunnable() {
|
||||
|
||||
try {
|
||||
xml = getAsXML();
|
||||
} catch (IOException e) {
|
||||
IStatus s = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, e.getMessage(), e);
|
||||
throw new CoreException(s);
|
||||
} catch (TransformerException e) {
|
||||
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);
|
||||
}
|
||||
public void run(IProgressMonitor mon) throws CoreException {
|
||||
String xml;
|
||||
if (!fProject.isAccessible()) {
|
||||
return;
|
||||
}
|
||||
fUpdating = true;
|
||||
|
||||
IFile rscFile = getFile();
|
||||
InputStream inputStream = new ByteArrayInputStream(xml.getBytes());
|
||||
// update the resource content
|
||||
if (rscFile.exists()) {
|
||||
rscFile.setContents(inputStream, IResource.FORCE, null);
|
||||
} else {
|
||||
rscFile.create(inputStream, IResource.FORCE, null);
|
||||
}
|
||||
fUpdating = false;
|
||||
try {
|
||||
xml = getAsXML();
|
||||
} catch (IOException e) {
|
||||
IStatus s = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, e.getMessage(), e);
|
||||
throw new CoreException(s);
|
||||
} catch (TransformerException e) {
|
||||
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();
|
||||
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() {
|
||||
|
@ -367,7 +371,8 @@ public class CDescriptor implements ICDescriptor {
|
|||
dataDoc = null;
|
||||
|
||||
try {
|
||||
fOwner = new COwner(readCDTProjectFile(descriptionPath));
|
||||
String ownerId = readCDTProjectFile(descriptionPath);
|
||||
fOwner = new COwner(fManager.getOwnerConfiguration(ownerId));
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
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();
|
||||
DocumentBuilder docBuilder = dfactory.newDocumentBuilder();
|
||||
Document doc = docBuilder.newDocument();
|
||||
|
@ -474,7 +479,9 @@ public class CDescriptor implements ICDescriptor {
|
|||
doc.appendChild(version);
|
||||
Element configRootElement = doc.createElement(PROJECT_DESCRIPTION);
|
||||
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);
|
||||
encodeProjectData(doc, configRootElement);
|
||||
return serializeDocument(doc);
|
||||
|
@ -534,12 +541,7 @@ public class CDescriptor implements ICDescriptor {
|
|||
}
|
||||
|
||||
public void saveProjectData() throws CoreException {
|
||||
fManager.getWorkspace().run(new IWorkspaceRunnable() {
|
||||
|
||||
public void run(IProgressMonitor mon) throws CoreException {
|
||||
save();
|
||||
}
|
||||
}, fProject, IWorkspace.AVOID_UPDATE, null);
|
||||
save();
|
||||
fManager.fireEvent(new CDescriptorEvent(this, CDescriptorEvent.CDTPROJECT_CHANGED, 0));
|
||||
}
|
||||
|
||||
|
|
|
@ -9,10 +9,13 @@
|
|||
******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Vector;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
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.ICDescriptorOperation;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IProjectDescription;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IResourceChangeEvent;
|
||||
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.IResourceVisitor;
|
||||
import org.eclipse.core.resources.IWorkspace;
|
||||
import org.eclipse.core.resources.IWorkspaceRunnable;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
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.ISafeRunnable;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
|
@ -41,10 +47,14 @@ import org.eclipse.core.runtime.jobs.Job;
|
|||
|
||||
public class CDescriptorManager implements ICDescriptorManager, IResourceChangeListener {
|
||||
|
||||
HashMap fOperationMap = new HashMap();
|
||||
HashMap fDescriptorMap = new HashMap();
|
||||
Map fOperationMap = new HashMap(1);
|
||||
Map fDescriptorMap = new HashMap();
|
||||
Map fOwnerConfigMap = null;
|
||||
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 {
|
||||
|
||||
CDescriptor fDescriptor;
|
||||
|
@ -59,13 +69,7 @@ public class CDescriptorManager implements ICDescriptorManager, IResourceChangeL
|
|||
|
||||
protected IStatus run(IProgressMonitor monitor) {
|
||||
try {
|
||||
getWorkspace().run(new IWorkspaceRunnable() {
|
||||
|
||||
public void run(IProgressMonitor mon) throws CoreException {
|
||||
fDescriptor.save();
|
||||
}
|
||||
}, getRule(), IWorkspace.AVOID_UPDATE, monitor);
|
||||
|
||||
fDescriptor.save();
|
||||
} catch (CoreException e) {
|
||||
return e.getStatus();
|
||||
}
|
||||
|
@ -156,8 +160,7 @@ public class CDescriptorManager implements ICDescriptorManager, IResourceChangeL
|
|||
CDescriptor descriptor = (CDescriptor) fDescriptorMap.get(dResource.getProject());
|
||||
if (descriptor != null) {
|
||||
if ((delta.getKind() & IResourceDelta.REMOVED) != 0) {
|
||||
// the file got deleted lets
|
||||
// try
|
||||
// the file got deleted lets try
|
||||
// and restore for memory.
|
||||
descriptor.updateOnDisk();
|
||||
} 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);
|
||||
if (descriptor == null) {
|
||||
descriptor = new CDescriptor(this, project);
|
||||
|
@ -192,26 +244,36 @@ public class CDescriptorManager implements ICDescriptorManager, IResourceChangeL
|
|||
|
||||
public void configure(IProject project, String id) throws CoreException {
|
||||
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) {
|
||||
descriptor = (CDescriptor) fDescriptorMap.get(project);
|
||||
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,
|
||||
CCorePlugin.getResourceString("CDescriptorManager.exception.alreadyConfigured"), //$NON-NLS-1$
|
||||
(Throwable) null);
|
||||
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);
|
||||
}
|
||||
|
@ -221,7 +283,7 @@ public class CDescriptorManager implements ICDescriptorManager, IResourceChangeL
|
|||
public void convert(IProject project, String id) throws CoreException {
|
||||
CDescriptor descriptor;
|
||||
synchronized (this) {
|
||||
descriptor = new CDescriptor(this, project, new COwner(id));
|
||||
descriptor = new CDescriptor(this, project, new COwner(getOwnerConfiguration(id)));
|
||||
fDescriptorMap.put(project, descriptor);
|
||||
}
|
||||
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) {
|
||||
if (fOperationMap.containsKey(event.getDescriptor())) {
|
||||
// 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
|
||||
// EXT_CHANGED
|
||||
// other
|
||||
|
@ -299,11 +361,9 @@ public class CDescriptorManager implements ICDescriptorManager, IResourceChangeL
|
|||
}
|
||||
|
||||
/*
|
||||
* Perform a update of the ondisk .cdtproject file. This is nessecary to
|
||||
* avoid deadlocking when the descriptor has change from a call to
|
||||
* ICDescriptor.get(project, true) which may update the descriptor via the
|
||||
* owner update method, while the workspace is locked (ie during a
|
||||
* resourceChange event).
|
||||
* Perform a update of the ondisk .cdtproject file. This is nessecary to avoid deadlocking when the descriptor has change from a
|
||||
* call to ICDescriptor.get(project, true) which may update the descriptor via the owner update method, while the workspace is
|
||||
* locked (ie during a resourceChange event).
|
||||
*/
|
||||
protected void updateDescriptor(CDescriptor descriptor) {
|
||||
new CDescriptorUpdater(descriptor).schedule();
|
||||
|
|
|
@ -9,85 +9,43 @@
|
|||
******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.ICDescriptor;
|
||||
import org.eclipse.cdt.core.ICOwner;
|
||||
import org.eclipse.cdt.core.ICOwnerInfo;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
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 {
|
||||
|
||||
String ownerID;
|
||||
String fPlatform;
|
||||
IExtension extension;
|
||||
final COwnerConfiguration fConfig;
|
||||
|
||||
public COwner(String id) throws CoreException {
|
||||
ownerID = id;
|
||||
IExtensionPoint extpoint = CCorePlugin.getDefault().getDescriptor().getExtensionPoint("CProject"); //$NON-NLS-1$
|
||||
extension = extpoint.getExtension(ownerID);
|
||||
public COwner(COwnerConfiguration config) throws CoreException {
|
||||
fConfig = config;
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
return ownerID;
|
||||
return fConfig.getOwnerID();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return extension == null ? "Unknown" : extension.getLabel(); //$NON-NLS-1$
|
||||
return fConfig.getName();
|
||||
}
|
||||
|
||||
public String getPlatform() {
|
||||
if (fPlatform == null && extension != null) {
|
||||
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$
|
||||
return fConfig.getPlatform();
|
||||
}
|
||||
|
||||
void configure(IProject project, ICDescriptor cproject) throws CoreException {
|
||||
if (extension == null) {
|
||||
IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1,
|
||||
CCorePlugin.getResourceString("COwner.exception.invalidOwnerID"), (Throwable) null); //$NON-NLS-1$
|
||||
throw new CoreException(status);
|
||||
ICOwner owner = fConfig.createOwner();
|
||||
if (owner != null) {
|
||||
owner.configure(cproject);
|
||||
}
|
||||
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 {
|
||||
if (extension != null) {
|
||||
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.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);
|
||||
ICOwner owner = fConfig.createOwner();
|
||||
if (owner != null) {
|
||||
owner.update(cproject, extensionID);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -95,8 +53,8 @@ public class COwner implements ICOwnerInfo {
|
|||
if (obj == this) {
|
||||
return true;
|
||||
}
|
||||
if ( obj instanceof COwner) {
|
||||
return ((COwner)obj).ownerID.equals(ownerID);
|
||||
if (obj instanceof COwner) {
|
||||
return ((COwner) obj).getID().equals(getID());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -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$
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue