mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 18:26:01 +02:00
cleanup CDT extensions interfaces
This commit is contained in:
parent
03dea5e8ec
commit
0099e3903e
12 changed files with 270 additions and 161 deletions
|
@ -1,3 +1,15 @@
|
||||||
|
2003-02-19 David Inglis
|
||||||
|
|
||||||
|
* src/org/eclipse/cdt/core/CCorePlugin.java
|
||||||
|
* src/org/eclipse/cdt/core/ICDescriptor.java
|
||||||
|
* src/org/eclipse/cdt/core/ICExtensionReference.java
|
||||||
|
* src/org/eclipse/cdt/core/ICOwner.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
|
||||||
|
* src/org/eclipse/cdt/internal/core/make/MakeProject.java
|
||||||
|
General cleanup of CDT extensions interfaces from review with Alain.
|
||||||
|
|
||||||
2003-02-17 Doug Schaefer
|
2003-02-17 Doug Schaefer
|
||||||
|
|
||||||
Merged in Sam Robb's source for the build model. The source can be
|
Merged in Sam Robb's source for the build model. The source can be
|
||||||
|
|
|
@ -207,8 +207,12 @@ public class CCorePlugin extends Plugin {
|
||||||
return fDescriptorManager.getDescriptor(project);
|
return fDescriptorManager.getDescriptor(project);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void mapCProjectOwner(IProject project, String id) throws CoreException {
|
public void mapCProjectOwner(IProject project, String id, boolean override) throws CoreException {
|
||||||
|
if ( !override ) {
|
||||||
fDescriptorManager.configure(project, id);
|
fDescriptorManager.configure(project, id);
|
||||||
|
} else {
|
||||||
|
fDescriptorManager.convert(project, id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -242,7 +246,7 @@ public class CCorePlugin extends Plugin {
|
||||||
|
|
||||||
// Add C Nature ... does not add duplicates
|
// Add C Nature ... does not add duplicates
|
||||||
CProjectNature.addCNature(projectHandle, new SubProgressMonitor(monitor, 1));
|
CProjectNature.addCNature(projectHandle, new SubProgressMonitor(monitor, 1));
|
||||||
mapCProjectOwner(projectHandle, projectID);
|
mapCProjectOwner(projectHandle, projectID, false);
|
||||||
} finally {
|
} finally {
|
||||||
//monitor.done();
|
//monitor.done();
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,13 +5,17 @@
|
||||||
package org.eclipse.cdt.core;
|
package org.eclipse.cdt.core;
|
||||||
|
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
|
||||||
public interface ICDescriptor {
|
public interface ICDescriptor {
|
||||||
public ICOwnerInfo getProjectOwner();
|
public ICOwnerInfo getProjectOwner();
|
||||||
public String getPlatform();
|
public String getPlatform();
|
||||||
public IProject getProject();
|
public IProject getProject();
|
||||||
public ICExtensionReference[] get(String name);
|
|
||||||
public ICExtensionReference[] get(String name, boolean update);
|
public ICExtensionReference[] get(String extensionPoint);
|
||||||
public ICExtensionReference create(String name, String id);
|
public ICExtensionReference[] get(String extensionPoint, boolean update) throws CoreException;
|
||||||
public void remove(ICExtensionReference extension);
|
public ICExtensionReference create(String extensionPoint, String id) throws CoreException;
|
||||||
|
|
||||||
|
public void remove(ICExtensionReference extension) throws CoreException;
|
||||||
|
public void remove(String extensionPoint) throws CoreException;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,34 @@
|
||||||
*/
|
*/
|
||||||
package org.eclipse.cdt.core;
|
package org.eclipse.cdt.core;
|
||||||
|
|
||||||
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
|
||||||
public interface ICExtensionReference {
|
public interface ICExtensionReference {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the extension point of this reference.
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
public String getExtension();
|
public String getExtension();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the extension ID of this reference.
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
public String getID();
|
public String getID();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a name/value data pair on this reference in the .cdtproject file
|
||||||
|
*/
|
||||||
public void setExtensionData(String key, String value);
|
public void setExtensionData(String key, String value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a value of the key from the .cdtproject file set by setExtensionData()
|
||||||
|
*/
|
||||||
public String getExtensionData(String key);
|
public String getExtensionData(String key);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the executable extension for the reference.
|
||||||
|
*/
|
||||||
|
public ICExtension createExtension() throws CoreException;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,9 @@
|
||||||
*/
|
*/
|
||||||
package org.eclipse.cdt.core;
|
package org.eclipse.cdt.core;
|
||||||
|
|
||||||
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
|
||||||
public interface ICOwner {
|
public interface ICOwner {
|
||||||
public void configure(ICDescriptor cproject);
|
public void configure(ICDescriptor cproject) throws CoreException;
|
||||||
public void update(ICDescriptor cproject, String extensionID);
|
public void update(ICDescriptor cproject, String extensionID) throws CoreException;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,6 @@ import java.util.Map.Entry;
|
||||||
|
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
|
||||||
|
|
||||||
import org.apache.xerces.dom.DocumentImpl;
|
import org.apache.xerces.dom.DocumentImpl;
|
||||||
import org.apache.xml.serialize.Method;
|
import org.apache.xml.serialize.Method;
|
||||||
|
@ -25,13 +24,18 @@ import org.apache.xml.serialize.Serializer;
|
||||||
import org.apache.xml.serialize.SerializerFactory;
|
import org.apache.xml.serialize.SerializerFactory;
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.ICDescriptor;
|
import org.eclipse.cdt.core.ICDescriptor;
|
||||||
|
import org.eclipse.cdt.core.ICExtension;
|
||||||
import org.eclipse.cdt.core.ICExtensionReference;
|
import org.eclipse.cdt.core.ICExtensionReference;
|
||||||
import org.eclipse.cdt.core.ICOwnerInfo;
|
import org.eclipse.cdt.core.ICOwnerInfo;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
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.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
|
import org.eclipse.core.runtime.IPluginRegistry;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.Platform;
|
import org.eclipse.core.runtime.Platform;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
|
@ -40,7 +44,6 @@ import org.w3c.dom.Element;
|
||||||
import org.w3c.dom.NamedNodeMap;
|
import org.w3c.dom.NamedNodeMap;
|
||||||
import org.w3c.dom.Node;
|
import org.w3c.dom.Node;
|
||||||
import org.w3c.dom.NodeList;
|
import org.w3c.dom.NodeList;
|
||||||
import org.xml.sax.SAXException;
|
|
||||||
|
|
||||||
public class CDescriptor implements ICDescriptor {
|
public class CDescriptor implements ICDescriptor {
|
||||||
/* constants */
|
/* constants */
|
||||||
|
@ -56,34 +59,7 @@ public class CDescriptor implements ICDescriptor {
|
||||||
private final static String PROJECT_EXTENSION_ATTRIBUTE = "attribute";
|
private final static String PROJECT_EXTENSION_ATTRIBUTE = "attribute";
|
||||||
|
|
||||||
private boolean fDirty;
|
private boolean fDirty;
|
||||||
|
private boolean autoSave;
|
||||||
protected void readCDTProject(IPath projectLocation) {
|
|
||||||
FileInputStream file = null;
|
|
||||||
try {
|
|
||||||
file = new FileInputStream(projectLocation.toFile());
|
|
||||||
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
|
||||||
Document document = parser.parse(file);
|
|
||||||
Node node = document.getFirstChild();
|
|
||||||
if (node.getNodeName().equals(PROJECT_DESCRIPTION))
|
|
||||||
fOwner = readProjectDescription(node);
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
}
|
|
||||||
catch (SAXException e) {
|
|
||||||
}
|
|
||||||
catch (ParserConfigurationException e) {
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
if (file != null) {
|
|
||||||
try {
|
|
||||||
file.close();
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected CDescriptor(IProject project, String id) throws CoreException {
|
protected CDescriptor(IProject project, String id) throws CoreException {
|
||||||
fProject = project;
|
fProject = project;
|
||||||
|
@ -98,10 +74,22 @@ public class CDescriptor implements ICDescriptor {
|
||||||
if (descriptionPath.toFile().exists()) {
|
if (descriptionPath.toFile().exists()) {
|
||||||
IStatus status;
|
IStatus status;
|
||||||
readCDTProject(descriptionPath);
|
readCDTProject(descriptionPath);
|
||||||
if ( fOwner.getID().equals(id)) {
|
if (fOwner.getID().equals(id)) {
|
||||||
status = new Status(IStatus.WARNING, CCorePlugin.PLUGIN_ID, CCorePlugin.STATUS_CDTPROJECT_EXISTS, "CDTProject already exisits", (Throwable)null);
|
status =
|
||||||
|
new Status(
|
||||||
|
IStatus.WARNING,
|
||||||
|
CCorePlugin.PLUGIN_ID,
|
||||||
|
CCorePlugin.STATUS_CDTPROJECT_EXISTS,
|
||||||
|
"CDTProject already exisits",
|
||||||
|
(Throwable) null);
|
||||||
} else {
|
} else {
|
||||||
status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, CCorePlugin.STATUS_CDTPROJECT_MISMATCH, "CDTProject already exisits but does not match owner ID of creator", (Throwable)null);
|
status =
|
||||||
|
new Status(
|
||||||
|
IStatus.ERROR,
|
||||||
|
CCorePlugin.PLUGIN_ID,
|
||||||
|
CCorePlugin.STATUS_CDTPROJECT_MISMATCH,
|
||||||
|
"CDTProject already exisits but does not match owner ID of creator",
|
||||||
|
(Throwable) null);
|
||||||
}
|
}
|
||||||
throw new CoreException(status);
|
throw new CoreException(status);
|
||||||
}
|
}
|
||||||
|
@ -119,12 +107,59 @@ 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, "CDTProject file not found", (Throwable)null);
|
IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, "CDTProject file not found", (Throwable) null);
|
||||||
throw new CoreException(status);
|
throw new CoreException(status);
|
||||||
}
|
}
|
||||||
readCDTProject(descriptionPath);
|
readCDTProject(descriptionPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected CDescriptor(IProject project, COwner owner) throws CoreException {
|
||||||
|
fProject = project;
|
||||||
|
IPath projectLocation = project.getDescription().getLocation();
|
||||||
|
|
||||||
|
final boolean isDefaultLocation = projectLocation == null;
|
||||||
|
if (isDefaultLocation) {
|
||||||
|
projectLocation = getProjectDefaultLocation(project);
|
||||||
|
}
|
||||||
|
IPath descriptionPath = projectLocation.append(DESCRIPTION_FILE_NAME);
|
||||||
|
|
||||||
|
if (!descriptionPath.toFile().exists()) {
|
||||||
|
IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, "CDTProject file not found", (Throwable) null);
|
||||||
|
throw new CoreException(status);
|
||||||
|
}
|
||||||
|
fOwner = owner;
|
||||||
|
readProjectExtensions(getCDTProjectNode(descriptionPath));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Node getCDTProjectNode(IPath descriptionPath) throws CoreException {
|
||||||
|
FileInputStream file = null;
|
||||||
|
try {
|
||||||
|
file = new FileInputStream(descriptionPath.toFile());
|
||||||
|
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||||
|
Document document = parser.parse(file);
|
||||||
|
Node node = document.getFirstChild();
|
||||||
|
if (node.getNodeName().equals(PROJECT_DESCRIPTION))
|
||||||
|
return node;
|
||||||
|
IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, "Missing cdtproject element", null);
|
||||||
|
throw new CoreException(status);
|
||||||
|
} catch (Exception e) {
|
||||||
|
IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, e.getLocalizedMessage(), e);
|
||||||
|
throw new CoreException(status);
|
||||||
|
} finally {
|
||||||
|
if (file != null) {
|
||||||
|
try {
|
||||||
|
file.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void readCDTProject(IPath projectLocation) throws CoreException {
|
||||||
|
Node node = getCDTProjectNode(projectLocation);
|
||||||
|
fOwner = readProjectDescription(node);
|
||||||
|
}
|
||||||
|
|
||||||
protected IPath getProjectDefaultLocation(IProject project) {
|
protected IPath getProjectDefaultLocation(IProject project) {
|
||||||
return Platform.getLocation().append(project.getFullPath());
|
return Platform.getLocation().append(project.getFullPath());
|
||||||
}
|
}
|
||||||
|
@ -147,43 +182,42 @@ public class CDescriptor implements ICDescriptor {
|
||||||
|
|
||||||
public ICExtensionReference[] get(String extensionID, boolean update) {
|
public ICExtensionReference[] get(String extensionID, boolean update) {
|
||||||
ICExtensionReference[] ext = get(extensionID);
|
ICExtensionReference[] ext = get(extensionID);
|
||||||
if ( (ext == null || ext.length == 0) && update) {
|
if ((ext == null || ext.length == 0) && update) {
|
||||||
try {
|
try {
|
||||||
fOwner.update(fProject, this, extensionID);
|
fOwner.update(fProject, this, extensionID);
|
||||||
saveInfo();
|
saveInfo();
|
||||||
ext = get(extensionID);
|
ext = get(extensionID);
|
||||||
}
|
} catch (CoreException e) {
|
||||||
catch (CoreException e) {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ext;
|
return ext;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ICExtensionReference create(String name, String id) {
|
public ICExtensionReference create(String extensionPoint, String extensionID) throws CoreException {
|
||||||
CExtensionReference extensions[] = (CExtensionReference[]) extMap.get(name);
|
CExtensionReference extensions[] = (CExtensionReference[]) extMap.get(extensionPoint);
|
||||||
if ( extensions == null ) {
|
if (extensions == null) {
|
||||||
extensions = new CExtensionReference[1];
|
extensions = new CExtensionReference[1];
|
||||||
extMap.put(name, extensions);
|
extMap.put(extensionPoint, extensions);
|
||||||
} else {
|
} else {
|
||||||
CExtensionReference[] newExtensions = new CExtensionReference[extensions.length + 1];
|
CExtensionReference[] newExtensions = new CExtensionReference[extensions.length + 1];
|
||||||
System.arraycopy(extensions, 0, newExtensions, 0, extensions.length);
|
System.arraycopy(extensions, 0, newExtensions, 0, extensions.length);
|
||||||
extensions = newExtensions;
|
extensions = newExtensions;
|
||||||
extMap.put(name, extensions);
|
extMap.put(extensionPoint, extensions);
|
||||||
}
|
}
|
||||||
setDirty();
|
setDirty();
|
||||||
extensions[extensions.length-1] = new CExtensionReference(this, name, id);
|
extensions[extensions.length - 1] = new CExtensionReference(this, extensionPoint, extensionID);
|
||||||
return extensions[extensions.length-1];
|
return extensions[extensions.length - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(ICExtensionReference ext) {
|
public void remove(ICExtensionReference ext) throws CoreException {
|
||||||
CExtensionReference extensions[] = (CExtensionReference[]) extMap.get(ext.getExtension());
|
CExtensionReference extensions[] = (CExtensionReference[]) extMap.get(ext.getExtension());
|
||||||
for( int i = 0; i < extensions.length; i++ ) {
|
for (int i = 0; i < extensions.length; i++) {
|
||||||
if ( extensions[i] == ext ) {
|
if (extensions[i] == ext) {
|
||||||
System.arraycopy(extensions, i, extensions, i+1, extensions.length - 1 - i);
|
System.arraycopy(extensions, i, extensions, i + 1, extensions.length - 1 - i);
|
||||||
CExtensionReference[] newExtensions = new CExtensionReference[extensions.length - 1];
|
CExtensionReference[] newExtensions = new CExtensionReference[extensions.length - 1];
|
||||||
System.arraycopy(extensions, 0, newExtensions, 0, extensions.length);
|
System.arraycopy(extensions, 0, newExtensions, 0, extensions.length);
|
||||||
extensions = newExtensions;
|
extensions = newExtensions;
|
||||||
if ( extensions.length == 0 ) {
|
if (extensions.length == 0) {
|
||||||
extMap.put(ext.getExtension(), null);
|
extMap.put(ext.getExtension(), null);
|
||||||
} else {
|
} else {
|
||||||
extMap.put(ext.getExtension(), extensions);
|
extMap.put(ext.getExtension(), extensions);
|
||||||
|
@ -193,9 +227,17 @@ public class CDescriptor implements ICDescriptor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void remove(String extensionPoint) throws CoreException {
|
||||||
|
CExtensionReference extensions[] = (CExtensionReference[]) extMap.get(extensionPoint);
|
||||||
|
if (extensions != null) {
|
||||||
|
extMap.put(extensionPoint, null);
|
||||||
|
setDirty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public CExtensionInfo getInfo(CExtensionReference cProjectExtension) {
|
public CExtensionInfo getInfo(CExtensionReference cProjectExtension) {
|
||||||
CExtensionInfo info = (CExtensionInfo) extInfoMap.get(cProjectExtension);
|
CExtensionInfo info = (CExtensionInfo) extInfoMap.get(cProjectExtension);
|
||||||
if ( info == null ) {
|
if (info == null) {
|
||||||
info = new CExtensionInfo();
|
info = new CExtensionInfo();
|
||||||
extInfoMap.put(cProjectExtension, info);
|
extInfoMap.put(cProjectExtension, info);
|
||||||
}
|
}
|
||||||
|
@ -216,30 +258,28 @@ public class CDescriptor implements ICDescriptor {
|
||||||
return node != null ? (node.getFirstChild() == null ? null : node.getFirstChild().getNodeValue()) : null;
|
return node != null ? (node.getFirstChild() == null ? null : node.getFirstChild().getNodeValue()) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private COwner readProjectDescription(Node node) {
|
private COwner readProjectDescription(Node node) throws CoreException {
|
||||||
COwner owner = null;
|
COwner owner = null;
|
||||||
NamedNodeMap attrib = node.getAttributes();
|
NamedNodeMap attrib = node.getAttributes();
|
||||||
try {
|
|
||||||
owner = new COwner(attrib.getNamedItem("id").getNodeValue());
|
owner = new COwner(attrib.getNamedItem("id").getNodeValue());
|
||||||
}
|
|
||||||
catch (CoreException e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
readProjectExtensions(node);
|
readProjectExtensions(node);
|
||||||
return owner;
|
return owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readProjectExtensions(Node node) {
|
private void readProjectExtensions(Node node) throws CoreException {
|
||||||
NodeList list = node.getChildNodes();
|
NodeList list = node.getChildNodes();
|
||||||
for (int i = 0; i < list.getLength(); i++) {
|
for (int i = 0; i < list.getLength(); i++) {
|
||||||
if ( list.item(i).getNodeName().equals(PROJECT_EXTENSION) ) {
|
if (list.item(i).getNodeName().equals(PROJECT_EXTENSION)) {
|
||||||
NamedNodeMap attrib = list.item(i).getAttributes();
|
NamedNodeMap attrib = list.item(i).getAttributes();
|
||||||
ICExtensionReference ext = create(attrib.getNamedItem("point").getNodeValue(), attrib.getNamedItem("id").getNodeValue());
|
ICExtensionReference ext =
|
||||||
|
create(attrib.getNamedItem("point").getNodeValue(), attrib.getNamedItem("id").getNodeValue());
|
||||||
NodeList extAttrib = list.item(i).getChildNodes();
|
NodeList extAttrib = list.item(i).getChildNodes();
|
||||||
for( int j = 0; j < extAttrib.getLength(); j++) {
|
for (int j = 0; j < extAttrib.getLength(); j++) {
|
||||||
if ( extAttrib.item(j).getNodeName().equals(PROJECT_EXTENSION_ATTRIBUTE) ) {
|
if (extAttrib.item(j).getNodeName().equals(PROJECT_EXTENSION_ATTRIBUTE)) {
|
||||||
attrib = extAttrib.item(j).getAttributes();
|
attrib = extAttrib.item(j).getAttributes();
|
||||||
ext.setExtensionData(attrib.getNamedItem("key").getNodeValue(), attrib.getNamedItem("value").getNodeValue());
|
ext.setExtensionData(
|
||||||
|
attrib.getNamedItem("key").getNodeValue(),
|
||||||
|
attrib.getNamedItem("value").getNodeValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -248,14 +288,13 @@ public class CDescriptor implements ICDescriptor {
|
||||||
|
|
||||||
protected void saveInfo() throws CoreException {
|
protected void saveInfo() throws CoreException {
|
||||||
String xml;
|
String xml;
|
||||||
if ( !isDirty() ) {
|
if (!isDirty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
xml = getAsXML();
|
xml = getAsXML();
|
||||||
}
|
} catch (IOException e) {
|
||||||
catch (IOException e) {
|
IStatus s = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, e.getMessage(), e);
|
||||||
IStatus s= new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, e.getMessage(), e);
|
|
||||||
throw new CoreException(s);
|
throw new CoreException(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,8 +309,10 @@ public class CDescriptor implements ICDescriptor {
|
||||||
fDirty = false;
|
fDirty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setDirty() {
|
protected void setDirty() throws CoreException {
|
||||||
fDirty = true;
|
fDirty = true;
|
||||||
|
if (isAutoSave())
|
||||||
|
saveInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isDirty() {
|
protected boolean isDirty() {
|
||||||
|
@ -279,14 +320,12 @@ public class CDescriptor implements ICDescriptor {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String serializeDocument(Document doc) throws IOException {
|
protected String serializeDocument(Document doc) throws IOException {
|
||||||
ByteArrayOutputStream s= new ByteArrayOutputStream();
|
ByteArrayOutputStream s = new ByteArrayOutputStream();
|
||||||
OutputFormat format = new OutputFormat();
|
OutputFormat format = new OutputFormat();
|
||||||
format.setIndenting(true);
|
format.setIndenting(true);
|
||||||
format.setLineSeparator(System.getProperty("line.separator")); //$NON-NLS-1$
|
format.setLineSeparator(System.getProperty("line.separator")); //$NON-NLS-1$
|
||||||
|
|
||||||
Serializer serializer =
|
Serializer serializer = SerializerFactory.getSerializerFactory(Method.XML).makeSerializer(new OutputStreamWriter(s, "UTF8"), //$NON-NLS-1$
|
||||||
SerializerFactory.getSerializerFactory(Method.XML).makeSerializer(
|
|
||||||
new OutputStreamWriter(s, "UTF8"), //$NON-NLS-1$
|
|
||||||
format);
|
format);
|
||||||
serializer.asDOMSerializer().serialize(doc);
|
serializer.asDOMSerializer().serialize(doc);
|
||||||
return s.toString("UTF8"); //$NON-NLS-1$
|
return s.toString("UTF8"); //$NON-NLS-1$
|
||||||
|
@ -299,20 +338,20 @@ public class CDescriptor implements ICDescriptor {
|
||||||
doc.appendChild(configRootElement);
|
doc.appendChild(configRootElement);
|
||||||
configRootElement.setAttribute("id", fOwner.getID()); //$NON-NLS-1$
|
configRootElement.setAttribute("id", fOwner.getID()); //$NON-NLS-1$
|
||||||
Iterator extIterator = extMap.values().iterator();
|
Iterator extIterator = extMap.values().iterator();
|
||||||
while( extIterator.hasNext() ) {
|
while (extIterator.hasNext()) {
|
||||||
CExtensionReference extension[] = (CExtensionReference[]) extIterator.next();
|
CExtensionReference extension[] = (CExtensionReference[]) extIterator.next();
|
||||||
for( int i = 0; i < extension.length; i ++ ) {
|
for (int i = 0; i < extension.length; i++) {
|
||||||
configRootElement.appendChild(element = doc.createElement(PROJECT_EXTENSION));
|
configRootElement.appendChild(element = doc.createElement(PROJECT_EXTENSION));
|
||||||
element.setAttribute("point", extension[i].getExtension());
|
element.setAttribute("point", extension[i].getExtension());
|
||||||
element.setAttribute("id", extension[i].getID());
|
element.setAttribute("id", extension[i].getID());
|
||||||
CExtensionInfo info = (CExtensionInfo) extInfoMap.get(extension[i]);
|
CExtensionInfo info = (CExtensionInfo) extInfoMap.get(extension[i]);
|
||||||
if ( info != null ) {
|
if (info != null) {
|
||||||
Iterator attribIterator = info.getAttributes().entrySet().iterator();
|
Iterator attribIterator = info.getAttributes().entrySet().iterator();
|
||||||
while( attribIterator.hasNext() ) {
|
while (attribIterator.hasNext()) {
|
||||||
Entry entry = (Entry) attribIterator.next();
|
Entry entry = (Entry) attribIterator.next();
|
||||||
Element extAttributes = doc.createElement(PROJECT_EXTENSION_ATTRIBUTE);
|
Element extAttributes = doc.createElement(PROJECT_EXTENSION_ATTRIBUTE);
|
||||||
extAttributes.setAttribute("key", (String)entry.getKey());
|
extAttributes.setAttribute("key", (String) entry.getKey());
|
||||||
extAttributes.setAttribute("value", (String)entry.getValue());
|
extAttributes.setAttribute("value", (String) entry.getValue());
|
||||||
element.appendChild(extAttributes);
|
element.appendChild(extAttributes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -320,4 +359,29 @@ public class CDescriptor implements ICDescriptor {
|
||||||
}
|
}
|
||||||
return serializeDocument(doc);
|
return serializeDocument(doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isAutoSave() {
|
||||||
|
return autoSave;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAutoSave(boolean autoSave) {
|
||||||
|
this.autoSave = autoSave;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ICExtension createExtensions(ICExtensionReference ext) throws CoreException {
|
||||||
|
InternalCExtension cExtension = null;
|
||||||
|
IPluginRegistry pluginRegistry = Platform.getPluginRegistry();
|
||||||
|
IExtensionPoint extensionPoint = pluginRegistry.getExtensionPoint(ext.getExtension());
|
||||||
|
IExtension extension = extensionPoint.getExtension(ext.getID());
|
||||||
|
IConfigurationElement element[] = extension.getConfigurationElements();
|
||||||
|
for (int i = 0; i < element.length; i++) {
|
||||||
|
if (element[i].getName().equalsIgnoreCase("cextension")) {
|
||||||
|
cExtension = (InternalCExtension) element[i].createExecutableExtension("run");
|
||||||
|
cExtension.setExtenionReference(ext);
|
||||||
|
cExtension.setProject(fProject);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (ICExtension) cExtension;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,13 +4,10 @@
|
||||||
*/
|
*/
|
||||||
package org.eclipse.cdt.internal.core;
|
package org.eclipse.cdt.internal.core;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.ICDescriptor;
|
import org.eclipse.cdt.core.ICDescriptor;
|
||||||
import org.eclipse.cdt.core.ICExtension;
|
|
||||||
import org.eclipse.cdt.core.ICExtensionReference;
|
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
|
@ -20,14 +17,7 @@ import org.eclipse.core.resources.IResourceDelta;
|
||||||
import org.eclipse.core.resources.IWorkspace;
|
import org.eclipse.core.resources.IWorkspace;
|
||||||
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.IPluginRegistry;
|
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
|
||||||
import org.eclipse.core.runtime.Platform;
|
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
|
|
||||||
public class CDescriptorManager implements IResourceChangeListener {
|
public class CDescriptorManager implements IResourceChangeListener {
|
||||||
|
@ -128,52 +118,43 @@ public class CDescriptorManager implements IResourceChangeListener {
|
||||||
COwner cowner = new COwner(id);
|
COwner cowner = new COwner(id);
|
||||||
cowner.configure(project, cproject);
|
cowner.configure(project, cproject);
|
||||||
cproject.saveInfo();
|
cproject.saveInfo();
|
||||||
|
cproject.setAutoSave(true);
|
||||||
fDescriptorMap.put(project, cproject);
|
fDescriptorMap.put(project, cproject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public synchronized void convert(IProject project, String id) throws CoreException {
|
||||||
public ICExtension[] createExtensions(String extensionID, IProject project) throws CoreException {
|
CDescriptor cproject;
|
||||||
ArrayList extensionList = new ArrayList(1);
|
if ( fDescriptorMap == null ) {
|
||||||
ICDescriptor cDescriptor = getDescriptor(project);
|
fDescriptorMap = new HashMap();
|
||||||
ICExtensionReference ext[] = cDescriptor.get(extensionID, true);
|
|
||||||
IPluginRegistry pluginRegistry = Platform.getPluginRegistry();
|
|
||||||
for( int i = 0; i < ext.length; i++ ) {
|
|
||||||
IExtensionPoint extensionPoint = pluginRegistry.getExtensionPoint(ext[i].getExtension());
|
|
||||||
IExtension extension = extensionPoint.getExtension(ext[i].getID());
|
|
||||||
IConfigurationElement element[] = extension.getConfigurationElements();
|
|
||||||
for( int j = 0; j < element.length; j++ ) {
|
|
||||||
if ( element[j].getName().equalsIgnoreCase("run") ) {
|
|
||||||
InternalCExtension cExtension = (InternalCExtension) element[i].createExecutableExtension("class");
|
|
||||||
cExtension.setExtenionReference(ext[i]);
|
|
||||||
cExtension.setProject(project);
|
|
||||||
extensionList.add(cExtension);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
COwner cowner = new COwner(id);
|
||||||
}
|
cproject = new CDescriptor(project, cowner);
|
||||||
return (ICExtension[]) extensionList.toArray(new ICExtension[extensionList.size()]);
|
cowner.configure(project, cproject);
|
||||||
|
cproject.saveInfo();
|
||||||
|
cproject.setAutoSave(true);
|
||||||
|
fDescriptorMap.put(project, cproject);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Must remove an existing .cdtproject file before we generate a new one when converting
|
* Must remove an existing .cdtproject file before we generate a new one when converting
|
||||||
*/
|
*/
|
||||||
public static void removeExistingCdtProjectFile(IProject project){
|
// public static void removeExistingCdtProjectFile(IProject project){
|
||||||
IFile file = project.getFile(CDescriptor.DESCRIPTION_FILE_NAME);
|
// IFile file = project.getFile(CDescriptor.DESCRIPTION_FILE_NAME);
|
||||||
IProgressMonitor monitor = new NullProgressMonitor();
|
// IProgressMonitor monitor = new NullProgressMonitor();
|
||||||
|
//
|
||||||
// update the resource content
|
// // update the resource content
|
||||||
if ((file != null) && file.exists()) {
|
// if ((file != null) && file.exists()) {
|
||||||
try{
|
// try{
|
||||||
file.delete(true, monitor);
|
// file.delete(true, monitor);
|
||||||
// remove reference from the fDescriptorMap
|
// // remove reference from the fDescriptorMap
|
||||||
if (fDescriptorMap != null){
|
// if (fDescriptorMap != null){
|
||||||
fDescriptorMap.remove(project);
|
// fDescriptorMap.remove(project);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
project.refreshLocal(1, monitor);
|
// project.refreshLocal(1, monitor);
|
||||||
}catch(CoreException ce){
|
// }catch(CoreException ce){
|
||||||
CCorePlugin.log(ce);
|
// CCorePlugin.log(ce);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,9 @@
|
||||||
*/
|
*/
|
||||||
package org.eclipse.cdt.internal.core;
|
package org.eclipse.cdt.internal.core;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.ICExtension;
|
||||||
import org.eclipse.cdt.core.ICExtensionReference;
|
import org.eclipse.cdt.core.ICExtensionReference;
|
||||||
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
|
||||||
public class CExtensionReference implements ICExtensionReference {
|
public class CExtensionReference implements ICExtensionReference {
|
||||||
private CDescriptor fDescriptor;
|
private CDescriptor fDescriptor;
|
||||||
|
@ -37,4 +39,8 @@ public class CExtensionReference implements ICExtensionReference {
|
||||||
return getInfo().getAttribute(key);
|
return getInfo().getAttribute(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ICExtension createExtension() throws CoreException {
|
||||||
|
return fDescriptor.createExtensions(this);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,15 +8,17 @@ import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.ICDescriptor;
|
import org.eclipse.cdt.core.ICDescriptor;
|
||||||
import org.eclipse.cdt.core.ICExtensionReference;
|
import org.eclipse.cdt.core.ICExtensionReference;
|
||||||
import org.eclipse.cdt.core.ICOwner;
|
import org.eclipse.cdt.core.ICOwner;
|
||||||
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
|
||||||
public class MakeProject implements ICOwner {
|
public class MakeProject implements ICOwner {
|
||||||
|
|
||||||
public void configure(ICDescriptor cproject) {
|
public void configure(ICDescriptor cproject) throws CoreException {
|
||||||
|
cproject.remove(CCorePlugin.BUILDER_MODEL_ID);
|
||||||
ICExtensionReference ext = cproject.create(CCorePlugin.BUILDER_MODEL_ID, CCorePlugin.PLUGIN_ID + ".makeBuilder");
|
ICExtensionReference ext = cproject.create(CCorePlugin.BUILDER_MODEL_ID, CCorePlugin.PLUGIN_ID + ".makeBuilder");
|
||||||
ext.setExtensionData("command", "make");
|
ext.setExtensionData("command", "make");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(ICDescriptor cproject, String extensionID) {
|
public void update(ICDescriptor cproject, String extensionID) throws CoreException {
|
||||||
if ( extensionID.equals(CCorePlugin.BUILDER_MODEL_ID ) ) {
|
if ( extensionID.equals(CCorePlugin.BUILDER_MODEL_ID ) ) {
|
||||||
ICExtensionReference ext = cproject.create(CCorePlugin.BUILDER_MODEL_ID, CCorePlugin.PLUGIN_ID + ".makeBuilder");
|
ICExtensionReference ext = cproject.create(CCorePlugin.BUILDER_MODEL_ID, CCorePlugin.PLUGIN_ID + ".makeBuilder");
|
||||||
ext.setExtensionData("command", "make");
|
ext.setExtensionData("command", "make");
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
|
2003-02-19 David Inglis
|
||||||
|
* src/org/eclipse/cdt/ui/wizards/conversion/ConversionWizard.java
|
||||||
|
* src/org/eclipse/cdt/ui/wizards/conversion/ConvertToStdMakeConversionWizard.java
|
||||||
|
Due to CDT extensions interface cleanup.
|
||||||
|
|
||||||
2003-02-17 Doug Schaefer
|
2003-02-17 Doug Schaefer
|
||||||
|
|
||||||
Merged in Sam Robb's source for the build model. The source can be
|
Merged in Sam Robb's source for the build model. The source can be
|
||||||
|
|
|
@ -124,11 +124,12 @@ public abstract class ConversionWizard
|
||||||
*
|
*
|
||||||
* @see org.eclipse.cdt.ui.wizards.CProjectWizard#doRun(IProgressMonitor)
|
* @see org.eclipse.cdt.ui.wizards.CProjectWizard#doRun(IProgressMonitor)
|
||||||
*/
|
*/
|
||||||
protected void doRun(IProgressMonitor monitor) {
|
protected void doRun(IProgressMonitor monitor) throws CoreException {
|
||||||
try{
|
try{
|
||||||
mainPage.doRun(monitor, getProjectID());
|
mainPage.doRun(monitor, getProjectID());
|
||||||
} catch (CoreException ce){
|
} catch (CoreException ce){
|
||||||
CCorePlugin.log(ce);
|
CCorePlugin.log(ce);
|
||||||
|
throw ce;
|
||||||
} finally{
|
} finally{
|
||||||
doRunEpilogue(monitor);
|
doRunEpilogue(monitor);
|
||||||
monitor.isCanceled();
|
monitor.isCanceled();
|
||||||
|
@ -138,9 +139,7 @@ public abstract class ConversionWizard
|
||||||
* Return the type of project that it is being converted to
|
* Return the type of project that it is being converted to
|
||||||
* The default if a make project
|
* The default if a make project
|
||||||
*/
|
*/
|
||||||
public String getProjectID() {
|
public abstract String getProjectID();
|
||||||
return CCorePlugin.PLUGIN_ID + ".make";//$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method addPages allows subclasses to add as many pages as they need. Overwrite
|
* Method addPages allows subclasses to add as many pages as they need. Overwrite
|
||||||
|
|
|
@ -5,6 +5,7 @@ package org.eclipse.cdt.ui.wizards.conversion;
|
||||||
* All Rights Reserved.
|
* All Rights Reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -85,4 +86,8 @@ public class ConvertToStdMakeConversionWizard extends ConversionWizard {
|
||||||
|
|
||||||
addPage(mainPage);
|
addPage(mainPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getProjectID() {
|
||||||
|
return CCorePlugin.PLUGIN_ID + ".make";//$NON-NLS-1$
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue