diff --git a/core/org.eclipse.cdt.core/builder/org/eclipse/cdt/core/builder/CIncrementalBuilder.java b/core/org.eclipse.cdt.core/builder/org/eclipse/cdt/core/builder/CIncrementalBuilder.java
index 6e28ae54d50..a39ef6d6865 100644
--- a/core/org.eclipse.cdt.core/builder/org/eclipse/cdt/core/builder/CIncrementalBuilder.java
+++ b/core/org.eclipse.cdt.core/builder/org/eclipse/cdt/core/builder/CIncrementalBuilder.java
@@ -2,6 +2,7 @@ package org.eclipse.cdt.core.builder;
import java.util.Map;
+import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.resources.IConsole;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IncrementalProjectBuilder;
@@ -26,6 +27,8 @@ public class CIncrementalBuilder extends IncrementalProjectBuilder {
Map args;
IProgressMonitor monitor;
+ private ICBuilder fCurrentBuilder;
+
public int getkind() {
return kind;
}
@@ -38,11 +41,9 @@ public class CIncrementalBuilder extends IncrementalProjectBuilder {
return monitor;
}
- //FIXME: Not implemented
public IConsole getConsole() {
- ICBuilder builder = getCBuilder();
- String id = builder.getID();
- return null;
+ String id = fCurrentBuilder.getID();
+ return CCorePlugin.getDefault().getConsole(id);
}
//FIXME: Not implemented
@@ -63,14 +64,15 @@ public class CIncrementalBuilder extends IncrementalProjectBuilder {
this.monitor = monitor;
// Get the ICBuilder
- ICBuilder cbuilder = getCBuilder();
+ ICBuilder cbuilder[] = getCBuilder();
// FIXME: Check preference for non-modal builds
- return cbuilder.build(this);
+ fCurrentBuilder = cbuilder[0];
+ return fCurrentBuilder.build(this);
}
//FIXME: Not implemented
- private ICBuilder getCBuilder () {
- return null;
+ private ICBuilder[] getCBuilder () throws CoreException {
+ return CCorePlugin.getDefault().getBuilders(getProject());
}
}
diff --git a/core/org.eclipse.cdt.core/plugin.properties b/core/org.eclipse.cdt.core/plugin.properties
index ffab16382d0..25990122465 100644
--- a/core/org.eclipse.cdt.core/plugin.properties
+++ b/core/org.eclipse.cdt.core/plugin.properties
@@ -8,5 +8,8 @@ CProblemMarker.name=C Problem
CBuildCommand.name=C Builder Command
CBuildConsole.name=C Builder Console
CProjectInfo.name=C Project Info
-projectinfo.name=Core Make Project
+CBuilder.name=C Build Model
+
+makeprojectowner.name=Make Project
genericmake.name=Generic Make
+makebuildmodel.name=Make Builder
diff --git a/core/org.eclipse.cdt.core/plugin.xml b/core/org.eclipse.cdt.core/plugin.xml
index 88412f81287..604a6e88b50 100644
--- a/core/org.eclipse.cdt.core/plugin.xml
+++ b/core/org.eclipse.cdt.core/plugin.xml
@@ -29,6 +29,7 @@
+
+
+
+
+
+
+
+
-
-
-
+ id="make"
+ name="%makeprojectowner.name"
+ point="org.eclipse.cdt.core.CProjectOwner">
+
+
+
+
+
+
+
+
+
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/AbstractCExtension.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/AbstractCExtension.java
new file mode 100644
index 00000000000..100e1fc7f0f
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/AbstractCExtension.java
@@ -0,0 +1,24 @@
+/*
+ * (c) Copyright QNX Software System Ltd. 2002.
+ * All Rights Reserved.
+ */
+package org.eclipse.cdt.core;
+
+import org.eclipse.cdt.internal.core.InternalCExtension;
+import org.eclipse.core.resources.IProject;
+
+public abstract class AbstractCExtension extends InternalCExtension implements ICExtension {
+
+ /**
+ * Returns the project for which this extrension is defined.
+ *
+ * @return the project
+ */
+ public final IProject getProject() {
+ return super.getProject();
+ }
+
+ public final ICExtensionReference getExtensionReference() {
+ return super.getExtensionReference();
+ }
+}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java
index 95ea0d31b43..ffd3fe3d6e0 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java
@@ -9,10 +9,11 @@ import java.text.MessageFormat;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
+import org.eclipse.cdt.core.builder.ICBuilder;
import org.eclipse.cdt.core.index.IndexModel;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.resources.IConsole;
-import org.eclipse.cdt.internal.core.CProjectDescriptor;
+import org.eclipse.cdt.internal.core.CDescriptorManager;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IWorkspace;
@@ -34,13 +35,17 @@ import org.eclipse.core.runtime.SubProgressMonitor;
public class CCorePlugin extends Plugin {
public static final int STATUS_CDTPROJECT_EXISTS = 1;
+ public static final int STATUS_CDTPROJECT_MISMATCH = 2;
public static final String PLUGIN_ID= "org.eclipse.cdt.core";
- public static final String BUILDER_ID= PLUGIN_ID + ".cbuilder";
-
+
+ public static final String BUILDER_MODEL_ID= PLUGIN_ID + ".CBuildModel";
+
private static CCorePlugin fgCPlugin;
private static ResourceBundle fgResourceBundle;
+ private CDescriptorManager fDescriptorManager;
+
// -------- static methods --------
static {
@@ -101,6 +106,7 @@ public class CCorePlugin extends Plugin {
*/
public void shutdown() throws CoreException {
super.shutdown();
+ fDescriptorManager.shutdown();
}
/**
@@ -113,31 +119,43 @@ public class CCorePlugin extends Plugin {
getCoreModel();
// Fired up the indexer. It should delay itself for 10 seconds
getIndexModel();
+ fDescriptorManager = new CDescriptorManager();
+ fDescriptorManager.startup();
+ }
+
+ public IConsole getConsole(String id) {
+ IConsole consoleDocument = null;
+
+ try {
+ IExtensionPoint extension = getDescriptor().getExtensionPoint("CBuildConsole");
+ if (extension != null) {
+ IExtension[] extensions = extension.getExtensions();
+ for(int i = 0; i < extensions.length; i++){
+ IConfigurationElement [] configElements = extensions[i].getConfigurationElements();
+ for( int j = 0; j < configElements.length; j++ ) {
+ String builderID = configElements[j].getAttribute("builderID");
+ if ( (id == null && builderID == null) ||
+ ( id != null && builderID.equals(id))) {
+ return consoleDocument = (IConsole)configElements[j].createExecutableExtension("class");
+ }
+ }
+ }
+ }
+ } catch (CoreException e) {
+ }
+ return new IConsole() {
+ public void clear() {
+ }
+ public void start(IProject project) {
+ }
+ public ConsoleOutputStream getOutputStream() {
+ return new ConsoleOutputStream();
+ }
+ };
}
public IConsole getConsole() throws CoreException {
- IConsole consoleDocument = null;
-
- IExtensionPoint extension = getDescriptor().getExtensionPoint("CBuildConsole");
- if (extension != null) {
- IExtension[] extensions = extension.getExtensions();
- for(int i = 0; i < extensions.length; i++){
- IConfigurationElement [] configElements = extensions[i].getConfigurationElements();
- consoleDocument = (IConsole)configElements[0].createExecutableExtension("class");
- }
- }
- if ( consoleDocument == null ) {
- return new IConsole() {
- public void clear() {
- }
- public void start(IProject project) {
- }
- public ConsoleOutputStream getOutputStream() {
- return new ConsoleOutputStream();
- }
- };
- }
- return consoleDocument;
+ return getConsole(null);
}
public CoreModel getCoreModel() {
@@ -148,12 +166,12 @@ public class CCorePlugin extends Plugin {
return IndexModel.getDefault();
}
- public ICProjectDescriptor getCProjectDescription(IProject project) throws CoreException {
- return CProjectDescriptor.getDescription(project);
+ public ICDescriptor getCProjectDescription(IProject project) throws CoreException {
+ return fDescriptorManager.getDescriptor(project);
}
public void mapCProjectOwner(IProject project, String id) throws CoreException {
- CProjectDescriptor.configure(project, id);
+ fDescriptorManager.configure(project, id);
}
/**
@@ -295,4 +313,11 @@ public class CCorePlugin extends Plugin {
convertProjectFromCtoCC(projectHandle, monitor);
addDefaultCBuilder(projectHandle, monitor);
}
+
+ public ICBuilder[] getBuilders(IProject project) throws CoreException {
+ ICExtension extensions[] = fDescriptorManager.createExtensions(BUILDER_MODEL_ID, project);
+ ICBuilder builders[] = new ICBuilder[extensions.length];
+ System.arraycopy(extensions, 0, builders, 0, extensions.length);
+ return builders;
+ }
}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICDescriptor.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICDescriptor.java
new file mode 100644
index 00000000000..dcbd6a5dcff
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICDescriptor.java
@@ -0,0 +1,16 @@
+/*
+ * (c) Copyright QNX Software System Ltd. 2002.
+ * All Rights Reserved.
+ */
+package org.eclipse.cdt.core;
+
+import org.eclipse.core.resources.IProject;
+
+public interface ICDescriptor {
+ public ICOwnerInfo getProjectOwner();
+ public String getPlatform();
+ public IProject getProject();
+ public ICExtensionReference[] get(String name);
+ public ICExtensionReference create(String name, String id);
+ public void remove(ICExtensionReference extension);
+}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICExtension.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICExtension.java
new file mode 100644
index 00000000000..af2e358afde
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICExtension.java
@@ -0,0 +1,12 @@
+/*
+ * (c) Copyright QNX Software System Ltd. 2002.
+ * All Rights Reserved.
+ */
+package org.eclipse.cdt.core;
+
+import org.eclipse.core.resources.IProject;
+
+public interface ICExtension {
+ public IProject getProject();
+ public ICExtensionReference getExtensionReference();
+}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICExtensionReference.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICExtensionReference.java
new file mode 100644
index 00000000000..0293a346133
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICExtensionReference.java
@@ -0,0 +1,12 @@
+/*
+ * (c) Copyright QNX Software System Ltd. 2002.
+ * All Rights Reserved.
+ */
+package org.eclipse.cdt.core;
+
+public interface ICExtensionReference {
+ public String getExtension();
+ public String getID();
+ public void setExtensionData(String key, String value);
+ public String getExtensionData(String key);
+}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICOwner.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICOwner.java
new file mode 100644
index 00000000000..eeb56d49717
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICOwner.java
@@ -0,0 +1,10 @@
+/*
+ * (c) Copyright QNX Software System Ltd. 2002.
+ * All Rights Reserved.
+ */
+package org.eclipse.cdt.core;
+
+public interface ICOwner {
+ public void configure(ICDescriptor cproject);
+ public void update(ICDescriptor cproject);
+}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICProjectOwnerInfo.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICOwnerInfo.java
similarity index 86%
rename from core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICProjectOwnerInfo.java
rename to core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICOwnerInfo.java
index cf34e6064c4..204d32fae1b 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICProjectOwnerInfo.java
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICOwnerInfo.java
@@ -4,7 +4,7 @@
*/
package org.eclipse.cdt.core;
-public interface ICProjectOwnerInfo {
+public interface ICOwnerInfo {
public String getID();
public String getName();
public String[] getPlatforms();
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICProjectDescriptor.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICProjectDescriptor.java
deleted file mode 100644
index b45da330335..00000000000
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICProjectDescriptor.java
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * (c) Copyright QNX Software System Ltd. 2002.
- * All Rights Reserved.
- */
-package org.eclipse.cdt.core;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.CoreException;
-
-public interface ICProjectDescriptor {
- public static final String DESCRIPTION_FILE_NAME = ".cdtproject";
-
- public ICProjectOwnerInfo getProjectOwner();
- public String getPlatform();
- public IProject getProject();
-// public IBuilderInfo getBuilderInfo();
-// public setBuilder(String id) or should this be add... ?
- public void saveInfo() throws CoreException;
-}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICProjectOwner.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICProjectOwner.java
deleted file mode 100644
index 367533f47f0..00000000000
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICProjectOwner.java
+++ /dev/null
@@ -1,9 +0,0 @@
-/*
- * (c) Copyright QNX Software System Ltd. 2002.
- * All Rights Reserved.
- */
-package org.eclipse.cdt.core;
-
-public interface ICProjectOwner {
- public void configure(ICProjectDescriptor cproject);
-}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CDescriptor.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CDescriptor.java
new file mode 100644
index 00000000000..b756f08d701
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CDescriptor.java
@@ -0,0 +1,309 @@
+/*
+ * (c) Copyright QNX Software System Ltd. 2002.
+ * All Rights Reserved.
+ */
+package org.eclipse.cdt.internal.core;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStreamWriter;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map.Entry;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.xerces.dom.DocumentImpl;
+import org.apache.xml.serialize.Method;
+import org.apache.xml.serialize.OutputFormat;
+import org.apache.xml.serialize.Serializer;
+import org.apache.xml.serialize.SerializerFactory;
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.ICDescriptor;
+import org.eclipse.cdt.core.ICExtensionReference;
+import org.eclipse.cdt.core.ICOwnerInfo;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+public class CDescriptor implements ICDescriptor {
+ /* constants */
+ private static final String[] EMPTY_STRING_ARRAY = new String[0];
+ private ICOwnerInfo fOwner;
+ private IProject fProject;
+ private String fPlatform = "*";
+ private HashMap extMap = new HashMap(4);
+ private HashMap extInfoMap = new HashMap(4);
+
+ private final String DESCRIPTION_FILE_NAME = ".cdtproject";
+ private final String PROJECT_DESCRIPTION = "cdtproject";
+ private final String PROJECT_PLATFORM = "platform";
+ private final String PROJECT_EXTENSION = "extension";
+ private final String PROJECT_EXTENSION_ATTRIBUTE = "attribute";
+
+ 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 {
+ 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;
+ readCDTProject(descriptionPath);
+ if ( fOwner.getID().equals(id)) {
+ status = new Status(IStatus.WARNING, CCorePlugin.getDefault().PLUGIN_ID, CCorePlugin.STATUS_CDTPROJECT_EXISTS, "CDTProject already exisits", (Throwable)null);
+ } else {
+ status = new Status(IStatus.ERROR, CCorePlugin.getDefault().PLUGIN_ID, CCorePlugin.STATUS_CDTPROJECT_MISMATCH, "CDTProject already exisits but does not match owner ID of creator", (Throwable)null);
+ }
+ throw new CoreException(status);
+ }
+ fOwner = new COwner(id);
+ }
+
+ protected CDescriptor(IProject project) 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.getDefault().PLUGIN_ID, -1, "CDTProject file not found", (Throwable)null);
+ throw new CoreException(status);
+ }
+ readCDTProject(descriptionPath);
+ }
+
+ protected IPath getProjectDefaultLocation(IProject project) {
+ return Platform.getLocation().append(project.getFullPath());
+ }
+
+ public ICOwnerInfo getProjectOwner() {
+ return fOwner;
+ }
+
+ public String getPlatform() {
+ return fPlatform;
+ }
+
+ public IProject getProject() {
+ return fProject;
+ }
+
+ public ICExtensionReference[] get(String name) {
+ return (CExtensionReference[]) extMap.get(name);
+ }
+
+ public ICExtensionReference create(String name, String id) {
+ CExtensionReference extensions[] = (CExtensionReference[]) extMap.get(name);
+ if ( extensions == null ) {
+ extensions = new CExtensionReference[1];
+ extMap.put(name, extensions);
+ } else {
+ CExtensionReference[] newExtensions = new CExtensionReference[extensions.length + 1];
+ System.arraycopy(extensions, 0, newExtensions, 0, extensions.length);
+ extensions = newExtensions;
+ extMap.put(name, extensions);
+ }
+ extensions[extensions.length-1] = new CExtensionReference(this, name, id);
+ return extensions[extensions.length-1];
+ }
+
+ public void remove(ICExtensionReference ext) {
+ CExtensionReference extensions[] = (CExtensionReference[]) extMap.get(ext.getExtension());
+ for( int i = 0; i < extensions.length; i++ ) {
+ if ( extensions[i] == ext ) {
+ System.arraycopy(extensions, i, extensions, i+1, extensions.length - 1 - i);
+ CExtensionReference[] newExtensions = new CExtensionReference[extensions.length - 1];
+ System.arraycopy(extensions, 0, newExtensions, 0, extensions.length);
+ extensions = newExtensions;
+ if ( extensions.length == 0 ) {
+ extMap.put(ext.getExtension(), null);
+ } else {
+ extMap.put(ext.getExtension(), extensions);
+ }
+ }
+ }
+ }
+
+ public CExtensionInfo getInfo(CExtensionReference cProjectExtension) {
+ CExtensionInfo info = (CExtensionInfo) extInfoMap.get(cProjectExtension);
+ if ( info == null ) {
+ info = new CExtensionInfo();
+ extInfoMap.put(cProjectExtension, info);
+ }
+ return info;
+ }
+
+ protected Node searchNode(Node target, String tagName) {
+ NodeList list = target.getChildNodes();
+ for (int i = 0; i < list.getLength(); i++) {
+ if (list.item(i).getNodeName().equals(tagName))
+ return list.item(i);
+ }
+ return null;
+ }
+
+ protected String getString(Node target, String tagName) {
+ Node node = searchNode(target, tagName);
+ return node != null ? (node.getFirstChild() == null ? null : node.getFirstChild().getNodeValue()) : null;
+ }
+
+ private ICOwnerInfo readProjectDescription(Node node) {
+ ICOwnerInfo owner = null;
+ NamedNodeMap attrib = node.getAttributes();
+ try {
+ owner = new COwner(attrib.getNamedItem("id").getNodeValue());
+ }
+ catch (CoreException e) {
+ return null;
+ }
+ fPlatform = getString(node, PROJECT_PLATFORM);
+ if ( fPlatform == null )
+ fPlatform = "*";
+ readProjectExtensions(node);
+ return owner;
+ }
+
+ private void readProjectExtensions(Node node) {
+ NodeList list = node.getChildNodes();
+ for (int i = 0; i < list.getLength(); i++) {
+ if ( list.item(i).getNodeName().equals(PROJECT_EXTENSION) ) {
+ NamedNodeMap attrib = list.item(i).getAttributes();
+ ICExtensionReference ext = create(attrib.getNamedItem("point").getNodeValue(), attrib.getNamedItem("id").getNodeValue());
+ NodeList extAttrib = list.item(i).getChildNodes();
+ for( int j = 0; j < extAttrib.getLength(); j++) {
+ if ( extAttrib.item(j).getNodeName().equals(PROJECT_EXTENSION_ATTRIBUTE) ) {
+ attrib = extAttrib.item(j).getAttributes();
+ ext.setExtensionData(attrib.getNamedItem("key").getNodeValue(), attrib.getNamedItem("value").getNodeValue());
+ }
+ }
+ }
+ }
+ }
+
+ protected void saveInfo() throws CoreException {
+ String xml;
+ if ( !isDirty() ) {
+ return;
+ }
+ try {
+ xml = getAsXML();
+ }
+ catch (IOException e) {
+ IStatus s= new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, e.getMessage(), e);
+ throw new CoreException(s);
+ }
+
+ IFile rscFile = getProject().getFile(DESCRIPTION_FILE_NAME);
+ 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);
+ }
+ }
+
+ private boolean isDirty() {
+ return true;
+ }
+
+ protected String serializeDocument(Document doc) throws IOException {
+ ByteArrayOutputStream s= new ByteArrayOutputStream();
+ OutputFormat format = new OutputFormat();
+ format.setIndenting(true);
+ format.setLineSeparator(System.getProperty("line.separator")); //$NON-NLS-1$
+
+ Serializer serializer =
+ SerializerFactory.getSerializerFactory(Method.XML).makeSerializer(
+ new OutputStreamWriter(s, "UTF8"), //$NON-NLS-1$
+ format);
+ serializer.asDOMSerializer().serialize(doc);
+ return s.toString("UTF8"); //$NON-NLS-1$
+ }
+
+ protected String getAsXML() throws IOException {
+ Element element;
+ Document doc = new DocumentImpl();
+ Element configRootElement = doc.createElement(PROJECT_DESCRIPTION);
+ doc.appendChild(configRootElement);
+ configRootElement.setAttribute("id", fOwner.getID()); //$NON-NLS-1$
+ element= doc.createElement(PROJECT_PLATFORM);
+ element.appendChild(doc.createTextNode(fPlatform));
+ if ( element != null )
+ configRootElement.appendChild(element);
+ Iterator extIterator = extMap.values().iterator();
+ while( extIterator.hasNext() ) {
+ CExtensionReference extension[] = (CExtensionReference[]) extIterator.next();
+ for( int i = 0; i < extension.length; i ++ ) {
+ configRootElement.appendChild(element = doc.createElement(PROJECT_EXTENSION));
+ element.setAttribute("point", extension[i].getExtension());
+ element.setAttribute("id", extension[i].getID());
+ CExtensionInfo info = (CExtensionInfo) extInfoMap.get(extension[i]);
+ if ( info != null ) {
+ Iterator attribIterator = info.getAttributes().entrySet().iterator();
+ while( attribIterator.hasNext() ) {
+ Entry entry = (Entry) attribIterator.next();
+ Element extAttributes = doc.createElement(PROJECT_EXTENSION_ATTRIBUTE);
+ extAttributes.setAttribute("key", (String)entry.getKey());
+ extAttributes.setAttribute("value", (String)entry.getValue());
+ element.appendChild(extAttributes);
+ }
+ }
+ }
+ }
+ return serializeDocument(doc);
+ }
+}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CDescriptorManager.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CDescriptorManager.java
new file mode 100644
index 00000000000..db84fb99d2c
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CDescriptorManager.java
@@ -0,0 +1,128 @@
+/*
+ * (c) Copyright QNX Software System Ltd. 2002.
+ * All Rights Reserved.
+ */
+package org.eclipse.cdt.internal.core;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.ICDescriptor;
+import org.eclipse.cdt.core.ICExtension;
+import org.eclipse.cdt.core.ICExtensionReference;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceChangeEvent;
+import org.eclipse.core.resources.IResourceChangeListener;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.resources.IWorkspace;
+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.IPluginRegistry;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+
+public class CDescriptorManager implements IResourceChangeListener {
+ private static HashMap fDescriptorMap;
+
+ private IWorkspace getWorkspace() {
+ return ResourcesPlugin.getWorkspace();
+ }
+
+ public void shutdown() {
+ getWorkspace().removeResourceChangeListener(this);
+ }
+
+ public void startup() {
+ getWorkspace().addResourceChangeListener(this);
+ }
+
+ /**
+ * Traverses the delta looking for added/removed/changed launch
+ * configuration files.
+ *
+ * @see IResourceChangeListener#resourceChanged(IResourceChangeEvent)
+ */
+ public void resourceChanged(IResourceChangeEvent event) {
+ if ( fDescriptorMap == null ) {
+ return;
+ }
+ IResource resource = event.getResource();
+ IResourceDelta delta = event.getDelta();
+ if ( event.getType() == IResourceChangeEvent.PRE_DELETE ) {
+ if(resource.getType() == IResource.PROJECT ) {
+ fDescriptorMap.remove(resource);
+ }
+ }
+ }
+
+
+ public synchronized ICDescriptor getDescriptor(IProject project) throws CoreException {
+ if ( fDescriptorMap == null ) {
+ fDescriptorMap = new HashMap();
+ }
+ CDescriptor cproject;
+ cproject = (CDescriptor)fDescriptorMap.get(project) ;
+ if ( cproject == null ) {
+ cproject = new CDescriptor(project);
+ fDescriptorMap.put(project, cproject);
+ }
+ return cproject;
+ }
+
+ public synchronized void configure(IProject project, String id) throws CoreException {
+ CDescriptor cproject;
+ if ( fDescriptorMap == null ) {
+ fDescriptorMap = new HashMap();
+ }
+ if ( fDescriptorMap.get(project) != null ) {
+ IStatus status = new Status(IStatus.ERROR, CCorePlugin.getDefault().PLUGIN_ID, CCorePlugin.STATUS_CDTPROJECT_EXISTS, "CDTProject already configured", (Throwable)null);
+ throw new CoreException(status);
+ }
+ try {
+ cproject = new CDescriptor(project, id);
+ }
+ catch (CoreException e) { // if .cdtproject already exists will use that
+ IStatus status = e.getStatus();
+ if ( status.getCode() == CCorePlugin.STATUS_CDTPROJECT_EXISTS ) {
+ cproject = new CDescriptor(project);
+ fDescriptorMap.put(project, cproject);
+ return;
+ }
+ else
+ throw e;
+ }
+ COwner cowner = new COwner(id);
+ cowner.configure(project, cproject);
+ cproject.saveInfo();
+ fDescriptorMap.put(project, cproject);
+ }
+
+
+ public ICExtension[] createExtensions(String extensionID, IProject project) throws CoreException {
+ ArrayList extensionList = new ArrayList(1);
+ ICDescriptor cDescriptor = getDescriptor(project);
+ ICExtensionReference ext[] = cDescriptor.get(extensionID);
+ 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;
+ }
+ }
+ }
+ return (ICExtension[]) extensionList.toArray(new ICExtension[extensionList.size()]);
+ }
+}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CExtensionInfo.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CExtensionInfo.java
new file mode 100644
index 00000000000..ec133c3b0e9
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CExtensionInfo.java
@@ -0,0 +1,24 @@
+/*
+ * (c) Copyright QNX Software System Ltd. 2002.
+ * All Rights Reserved.
+ */package org.eclipse.cdt.internal.core;
+
+import java.util.HashMap;
+
+public class CExtensionInfo {
+
+ protected HashMap attribMap = new HashMap(4);
+
+ protected HashMap getAttributes() {
+ return attribMap;
+ }
+
+ public void setAttribute(String key, String value) {
+ attribMap.put(key, value);
+ }
+
+ public String getAttribute(String key) {
+ return (String) attribMap.get(key);
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CExtensionReference.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CExtensionReference.java
new file mode 100644
index 00000000000..f3d00d43829
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CExtensionReference.java
@@ -0,0 +1,40 @@
+/*
+ * (c) Copyright QNX Software System Ltd. 2002.
+ * All Rights Reserved.
+ */
+package org.eclipse.cdt.internal.core;
+
+import org.eclipse.cdt.core.ICExtensionReference;
+
+public class CExtensionReference implements ICExtensionReference {
+ private CDescriptor fDescriptor;
+ private String fName;
+ private String fId;
+
+ public CExtensionReference(CDescriptor descriptor, String name, String id) {
+ fDescriptor = descriptor;
+ fName = name;
+ fId = id;
+ }
+
+ public String getExtension() {
+ return fName;
+ }
+
+ public String getID() {
+ return fId;
+ }
+
+ private CExtensionInfo getInfo() {
+ return fDescriptor.getInfo(this);
+ }
+
+ public void setExtensionData(String key, String value) {
+ getInfo().setAttribute(key, value);
+ }
+
+ public String getExtensionData(String key) {
+ return getInfo().getAttribute(key);
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CProjectOwner.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/COwner.java
similarity index 71%
rename from core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CProjectOwner.java
rename to core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/COwner.java
index 84fe08f9912..8e3c9045fe3 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CProjectOwner.java
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/COwner.java
@@ -7,9 +7,9 @@ package org.eclipse.cdt.internal.core;
import java.util.StringTokenizer;
import org.eclipse.cdt.core.CCorePlugin;
-import org.eclipse.cdt.core.ICProjectDescriptor;
-import org.eclipse.cdt.core.ICProjectOwner;
-import org.eclipse.cdt.core.ICProjectOwnerInfo;
+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;
@@ -18,15 +18,15 @@ import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
-public class CProjectOwner implements ICProjectOwnerInfo {
- String pluginId;
+public class COwner implements ICOwnerInfo {
+ String ownerID;
IExtension extension;
- public CProjectOwner(String id) throws CoreException {
- pluginId = id;
+ public COwner(String id) throws CoreException {
+ ownerID = id;
IExtensionPoint extpoint = CCorePlugin.getDefault().getDescriptor().getExtensionPoint("CProjectOwner");
if (extpoint != null) {
- extension = extpoint.getExtension(pluginId);
+ extension = extpoint.getExtension(ownerID);
} else {
IStatus status = new Status(IStatus.ERROR, CCorePlugin.getDefault().PLUGIN_ID, -1, "Invalid CDTProject owner ID", (Throwable)null);
throw new CoreException(status);
@@ -34,7 +34,7 @@ public class CProjectOwner implements ICProjectOwnerInfo {
}
public String getID() {
- return pluginId;
+ return ownerID;
}
public String getName() {
@@ -76,11 +76,11 @@ public class CProjectOwner implements ICProjectOwnerInfo {
return new String[0];
}
- void configure(IProject project, ICProjectDescriptor cproject) throws CoreException {
+ void configure(IProject project, ICDescriptor cproject) throws CoreException {
IConfigurationElement element[] = extension.getConfigurationElements();
for( int i = 0; i < element.length; i++ ) {
if ( element[i].getName().equalsIgnoreCase("run") ) {
- ICProjectOwner owner = (ICProjectOwner) element[i].createExecutableExtension("class");
+ ICOwner owner = (ICOwner) element[i].createExecutableExtension("class");
owner.configure(cproject);
return;
}
@@ -88,4 +88,18 @@ public class CProjectOwner implements ICProjectOwnerInfo {
IStatus status = new Status(IStatus.ERROR, CCorePlugin.getDefault().PLUGIN_ID, -1, "Invalid CDTProject owner extension", (Throwable)null);
throw new CoreException(status);
}
+
+ void update(IProject project, ICDescriptor cproject) throws CoreException {
+ IConfigurationElement element[] = extension.getConfigurationElements();
+ for( int i = 0; i < element.length; i++ ) {
+ if ( element[i].getName().equalsIgnoreCase("run") ) {
+ ICOwner owner = (ICOwner) element[i].createExecutableExtension("class");
+ owner.update(cproject);
+ return;
+ }
+ }
+ IStatus status = new Status(IStatus.ERROR, CCorePlugin.getDefault().PLUGIN_ID, -1, "Invalid CDTProject owner extension", (Throwable)null);
+ throw new CoreException(status);
+ }
+
}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CProjectDescriptor.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CProjectDescriptor.java
deleted file mode 100644
index 1632ce46dd9..00000000000
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CProjectDescriptor.java
+++ /dev/null
@@ -1,270 +0,0 @@
-/*
- * (c) Copyright QNX Software System Ltd. 2002.
- * All Rights Reserved.
- */
-package org.eclipse.cdt.internal.core;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStreamWriter;
-import java.io.UnsupportedEncodingException;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
-import org.apache.xerces.dom.DocumentImpl;
-import org.apache.xml.serialize.Method;
-import org.apache.xml.serialize.OutputFormat;
-import org.apache.xml.serialize.Serializer;
-import org.apache.xml.serialize.SerializerFactory;
-import org.eclipse.cdt.core.CCorePlugin;
-import org.eclipse.cdt.core.ICProjectDescriptor;
-import org.eclipse.cdt.core.ICProjectOwner;
-import org.eclipse.cdt.core.ICProjectOwnerInfo;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IProjectDescription;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.Status;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xml.sax.SAXException;
-
-public class CProjectDescriptor implements ICProjectDescriptor {
- /** constants */
- private static final String[] EMPTY_STRING_ARRAY = new String[0];
- private ICProjectOwnerInfo fOwner;
- private IProject fProject;
- private String fPlatform = "*";
-
- private static final String PROJECT_DESCRIPTION = "cdtproject";
- private static final String PROJECT_PLATFORM = "platform";
-
- private CProjectDescriptor(IProject project, String id) throws CoreException {
- fProject = project;
- fOwner = new CProjectOwner(id);
- IPath projectLocation = project.getDescription().getLocation();
-
- final boolean isDefaultLocation = projectLocation == null;
- if (isDefaultLocation) {
- projectLocation = getProjectDefaultLocation(project);
- }
- IPath descriptionPath = projectLocation.append(ICProjectDescriptor.DESCRIPTION_FILE_NAME);
-
- if (descriptionPath.toFile().exists()) {
- IStatus status = new Status(IStatus.WARNING, CCorePlugin.getDefault().PLUGIN_ID, CCorePlugin.STATUS_CDTPROJECT_EXISTS, "CDTProject already exisits", (Throwable)null);
- throw new CoreException(status);
- }
- }
-
- private CProjectDescriptor(IProject project) throws CoreException {
- fProject = project;
- FileInputStream file = null;
- IPath projectLocation = project.getDescription().getLocation();
-
- final boolean isDefaultLocation = projectLocation == null;
- if (isDefaultLocation) {
- projectLocation = getProjectDefaultLocation(project);
- }
- IPath descriptionPath = projectLocation.append(ICProjectDescriptor.DESCRIPTION_FILE_NAME);
-
- if (!descriptionPath.toFile().exists()) {
- IStatus status = new Status(IStatus.ERROR, CCorePlugin.getDefault().PLUGIN_ID, -1, "CDTProject file not found", (Throwable)null);
- throw new CoreException(status);
- }
- 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 IPath getProjectDefaultLocation(IProject project) {
- return Platform.getLocation().append(project.getFullPath());
- }
-
- public ICProjectOwnerInfo getProjectOwner() {
- return fOwner;
- }
-
- public String getPlatform() {
- return fPlatform;
- }
-
- protected String getString(Node target, String tagName) {
- Node node = searchNode(target, tagName);
- return node != null ? (node.getFirstChild() == null ? null : node.getFirstChild().getNodeValue()) : null;
- }
-
- protected String[] getStrings(Node target) {
- if (target == null)
- return null;
- NodeList list = target.getChildNodes();
- if (list.getLength() == 0)
- return EMPTY_STRING_ARRAY;
- List result = new ArrayList(list.getLength());
- for (int i = 0; i < list.getLength(); i++) {
- Node node = list.item(i);
- if (node.getNodeType() == Node.ELEMENT_NODE)
- result.add((String) read(node.getChildNodes().item(0)));
- }
- return (String[]) result.toArray(new String[result.size()]);
- }
-
- protected Object read(Node node) {
- if (node == null)
- return null;
- switch (node.getNodeType()) {
- case Node.ELEMENT_NODE :
-/*
- if (node.getNodeName().equals(BUILDER))
- return readBuildSpec(node);
- if (node.getNodeName().equals(DEBUGGER)
- return readProjectDescription(node);
-*/
- case Node.TEXT_NODE :
- String value = node.getNodeValue();
- return value == null ? null : value.trim();
- default :
- return node.toString();
- }
- }
-
- private ICProjectOwnerInfo readProjectDescription(Node node) {
- ICProjectOwnerInfo owner = null;
- NamedNodeMap attrib = node.getAttributes();
- try {
- owner = new CProjectOwner(attrib.getNamedItem("id").getNodeValue());
- }
- catch (CoreException e) {
- return null;
- }
- fPlatform = getString(node, PROJECT_PLATFORM);
- return owner;
- }
-
-
- protected Node searchNode(Node target, String tagName) {
- NodeList list = target.getChildNodes();
- for (int i = 0; i < list.getLength(); i++) {
- if (list.item(i).getNodeName().equals(tagName))
- return list.item(i);
- }
- return null;
- }
-
- public IProject getProject() {
- return fProject;
- }
-
- public void saveInfo() throws CoreException {
- String xml;
- try {
- xml = getAsXML();
- }
- catch (IOException e) {
- IStatus s= new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, e.getMessage(), e);
- throw new CoreException(s);
- }
-
- IFile rscFile = getProject().getFile(ICProjectDescriptor.DESCRIPTION_FILE_NAME);
- 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);
- }
- }
-
- protected String serializeDocument(Document doc) throws IOException {
- ByteArrayOutputStream s= new ByteArrayOutputStream();
- OutputFormat format = new OutputFormat();
- format.setIndenting(true);
- format.setLineSeparator(System.getProperty("line.separator")); //$NON-NLS-1$
-
- Serializer serializer =
- SerializerFactory.getSerializerFactory(Method.XML).makeSerializer(
- new OutputStreamWriter(s, "UTF8"), //$NON-NLS-1$
- format);
- serializer.asDOMSerializer().serialize(doc);
- return s.toString("UTF8"); //$NON-NLS-1$
- }
-
- protected String getAsXML() throws IOException {
- Element element;
- Document doc = new DocumentImpl();
- Element configRootElement = doc.createElement(PROJECT_DESCRIPTION);
- doc.appendChild(configRootElement);
- configRootElement.setAttribute("id", fOwner.getID()); //$NON-NLS-1$
- element= createBuilderElement(doc);
- if ( element != null )
- configRootElement.appendChild(element);
- return serializeDocument(doc);
- }
-
-
- protected Element createBuilderElement(Document doc) {
-/*
- if ( builderID != null ) {
- Element element = doc.createElement("cdtBuilder");
- element.setAttribute("id", builderID);
- return element;
- }
-*/
- return null;
- }
-
- public static synchronized ICProjectDescriptor getDescription(IProject project) throws CoreException {
- return new CProjectDescriptor(project);
- }
-
- public static synchronized void configure(IProject project, String id) throws CoreException {
- CProjectDescriptor cproject;
- try {
- cproject = new CProjectDescriptor(project, id);
- }
- catch (CoreException e) { // if .cdtproject already exists will use that
- IStatus status = e.getStatus();
- if ( status.getCode() == CCorePlugin.STATUS_CDTPROJECT_EXISTS )
- return;
- else
- throw e;
- }
- CProjectOwner cowner = new CProjectOwner(id);
- cowner.configure(project, cproject);
- cproject.saveInfo();
- }
-
-}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CommonMkInfo.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CommonMkInfo.java
deleted file mode 100644
index bae4aa2b03b..00000000000
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CommonMkInfo.java
+++ /dev/null
@@ -1,233 +0,0 @@
-package org.eclipse.cdt.internal.core;
-
-/*
- * (c) Copyright QNX Software Systems Ltd. 2002.
- * All Rights Reserved.
- */
-
-import java.io.File;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.DataOutputStream;
-import java.io.OutputStream;
-import java.io.FileOutputStream;
-import java.io.InputStreamReader;
-import java.util.StringTokenizer;
-import java.util.Properties;
-import java.util.ArrayList;
-import java.util.Enumeration;
-
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-
-import org.eclipse.cdt.utils.spawner.EnvironmentReader;
-import org.eclipse.cdt.utils.spawner.ProcessFactory;
-
-public class CommonMkInfo {
-
- public final static String COMMON_MK = "common.mk";
-
- IPath dir;
- long modification;
- IPath[] includePaths = new IPath[0];
- IPath[] libs = new IPath[0];
- IPath[] libPaths = new IPath[0];
-
- public CommonMkInfo(IPath dir) {
- this.dir = dir;
- modification = 0;
- }
-
- public CommonMkInfo () {
- dir = new Path("");
- String def = EnvironmentReader.getEnvVar("QNX_TARGET");
- if (def != null) {
- IPath defaultPath = new Path(def);
- includePaths = new IPath[] {defaultPath.append("/usr/include")};
- libPaths = new IPath[] {defaultPath.append("/usr/lib"),
- defaultPath.append("/x86/usr/lib")};
- }
- libs = new IPath[] {new Path("libc.so")};
- }
-
- public IPath[] getIncludePaths() {
- parse();
- return includePaths;
- }
-
- public IPath[] getLibs() {
- boolean hasLibC = false;
- parse();
- for (int i = 0; i < libs.length; i++) {
- String name = libs[i].toOSString();
- if (!(name.indexOf(IPath.SEPARATOR) != -1
- || name.indexOf(IPath.DEVICE_SEPARATOR) != -1
- || name.indexOf('.') != -1)) {
- if (!name.startsWith("lib")) {
- libs[i] = new Path("lib" + name + ".so");
- }
- }
- if (libs[i].toOSString().equals("libc.so"))
- hasLibC = true;
- }
- if (!hasLibC) {
- IPath[] newlibs = new IPath[libs.length + 1];
- int i = 0;;
- for (; i < libs.length; i++) {
- newlibs[i] = libs[i];
- }
- newlibs[i] = new Path("libc.so");
- libs = newlibs;
- }
- return libs;
- }
-
- public IPath[] getLibPaths() {
- parse();
- return libPaths;
- }
-
- public boolean hasChanged() {
- File prj = new File(dir.toOSString());
- File common = new File(prj, COMMON_MK);
- if (!prj.exists() || prj.isFile() || !common.exists())
- return false;
- long modif = common.lastModified();
- return (modif > modification);
- }
-
- void parse() {
- File makefile = null;
- try {
- if (hasChanged()) {
- File prj = new File(dir.toOSString());
- File common = new File(prj, COMMON_MK);
- modification = common.lastModified();
- makefile = File.createTempFile("QMakefile", null, prj);
- OutputStream fout = new FileOutputStream(makefile);
- DataOutputStream out = new DataOutputStream(fout);
-
- out.writeBytes("LIST=OS CPU VARIANT\n");
- out.writeBytes("include common.mk\n");
- out.writeBytes("\n");
-
- out.writeBytes("LIBS:\n");
- out.writeBytes("\t@echo $(LIBS)\n");
- out.writeBytes("\n");
-
- out.writeBytes("INCVPATH:\n");
- out.writeBytes("\t@echo $(INCVPATH)\n");
- out.writeBytes("\n");
-
- out.writeBytes("SRCVPATH:\n");
- out.writeBytes("\t@echo $(SRCVPATH)\n");
- out.writeBytes("\n");
-
- out.writeBytes("LIBVPATH:\n");
- out.writeBytes("\t@echo $(LIBVPATH)\n");
- out.writeBytes("\n");
-
- out.flush();
- out.close();
-
- // FIXME: Use the proper os and CPU
- Properties envp = EnvironmentReader.getEnvVars();
- envp.setProperty("OS", "nto");
- envp.setProperty("CPU", "x86");
- IPath[] incVPath = spawn("INCVPATH", envp, makefile, prj);
- parseIncVPath(incVPath);
- IPath[] libNames = spawn("LIBS", envp, makefile, prj);
- parseLibs(libNames);
- IPath[] libVPath = spawn("LIBVPATH", envp, makefile, prj);
- parseLibVPath(libVPath);
- }
- } catch (IllegalArgumentException e) {
- } catch (IOException e) {
- } finally {
- try {
- if (makefile != null)
- makefile.delete();
- } catch (SecurityException e) {
- }
- }
- }
-
- IPath[] spawn (String target, Properties envp, File makefile, File dir) {
- // FIXME: Use the proper MakeCommand from the builder.
- String[] args = new String[] {"make", "-f", makefile.getName(), target};
- BufferedReader stdout = null;
- Process make = null;
- StringBuffer buffer = new StringBuffer();
-
- try {
- ArrayList envList = new ArrayList();
-
- // Turn the environment Property to an Array.
- Enumeration names = envp.propertyNames();
- if (names != null) {
- while (names.hasMoreElements()) {
- String key = (String) names.nextElement();
- envList.add(key + "=" + envp.getProperty(key));
- }
- }
-
- String[] env = (String[]) envList.toArray(new String[envList.size()]);
- make = ProcessFactory.getFactory().exec(args, env, dir);
- stdout = new BufferedReader(new InputStreamReader(make.getInputStream()));
- String s;
- while ((s = stdout.readLine ()) != null) {
- buffer.append(s);
- }
- stdout.close();
- } catch (SecurityException e) {
- } catch (IndexOutOfBoundsException e) {
- } catch (NullPointerException e) {
- } catch (IOException e) {
- } finally {
- if (make != null) {
- make.destroy();
- }
- }
-
- // FIXME: This not quite right some of the include may contains
- // things like double quotes with spaces.
- StringTokenizer st = new StringTokenizer(buffer.toString());
- IPath[] p = new IPath[st.countTokens()];
-
- for(int i = 0; st.hasMoreTokens(); i++) {
- p[i] = new Path((String)st.nextToken());
- }
-
- return p;
- }
-
- void parseLibVPath(IPath[] array) {
- ArrayList list = new ArrayList(array.length);
- for (int i = 0; i < array.length; i++) {
- if (array[i].toString().charAt(0) != '-') {
- list.add (array[i]);
- }
- }
- libPaths = (IPath[])list.toArray(new IPath[list.size()]);
- }
-
- void parseIncVPath(IPath[] array){
- ArrayList list = new ArrayList(array.length);
- for (int i = 0; i < array.length; i++) {
- if (array[i].toString().charAt(0) != '-') {
- list.add (array[i]);
- }
- }
- includePaths = (IPath[])list.toArray(new IPath[list.size()]);
- }
-
- void parseLibs(IPath[] array){
- ArrayList list = new ArrayList(array.length);
- for (int i = 0; i < array.length; i++) {
- if (array[i].toString().charAt(0) != '-') {
- list.add (array[i]);
- }
- }
- libs = (IPath[])list.toArray(new IPath[list.size()]);
- }
-}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/InternalCExtension.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/InternalCExtension.java
new file mode 100644
index 00000000000..f77e2da88bc
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/InternalCExtension.java
@@ -0,0 +1,30 @@
+/*
+ * (c) Copyright QNX Software System Ltd. 2002.
+ * All Rights Reserved.
+ */
+package org.eclipse.cdt.internal.core;
+
+import org.eclipse.cdt.core.ICExtensionReference;
+import org.eclipse.core.resources.IProject;
+
+public abstract class InternalCExtension {
+
+ private IProject project;
+ private ICExtensionReference extensionRef;
+
+ void setProject(IProject project) {
+ this.project = project;
+ }
+
+ void setExtenionReference(ICExtensionReference extReference) {
+ extensionRef = extReference;
+ }
+
+ protected IProject getProject() {
+ return project;
+ }
+
+ protected ICExtensionReference getExtensionReference() {
+ return extensionRef;
+ }
+}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/make/MakeBuilder.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/make/MakeBuilder.java
new file mode 100644
index 00000000000..783b9ffcef9
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/make/MakeBuilder.java
@@ -0,0 +1,56 @@
+/*
+ * (c) Copyright QNX Software System Ltd. 2002.
+ * All Rights Reserved.
+ */
+package org.eclipse.cdt.internal.core.make;
+
+import org.eclipse.cdt.core.AbstractCExtension;
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.ICExtensionReference;
+import org.eclipse.cdt.core.builder.CIncrementalBuilder;
+import org.eclipse.cdt.core.builder.ICBuilder;
+import org.eclipse.cdt.core.builder.IOptimization;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IPath;
+
+public class MakeBuilder extends AbstractCExtension implements ICBuilder {
+
+ public IPath[] getIncludePaths() {
+ return new IPath[0];
+ }
+
+ public void setIncludePaths(IPath[] incPaths) {
+ }
+
+ public IPath[] getLibraryPaths() {
+ return new IPath[0];
+ }
+
+ public void setLibraryPaths(IPath[] libPaths) {
+ }
+
+ public String[] getLibraries() {
+ return new String[0];
+ }
+
+ public void setLibraries(String[] libs) {
+ }
+
+ public IOptimization getOptimization() {
+ return null;
+ }
+
+ public void setOptimization() {
+ }
+
+ public IProject[] build(CIncrementalBuilder cbuilder) {
+ ICExtensionReference ref = getExtensionReference();
+ System.out.println("MakeBuilder!!!!\n Command is:" + ref.getExtensionData("command"));
+ return null;
+ }
+
+ public String getID() {
+ return CCorePlugin.getDefault().PLUGIN_ID + ".makeBuilder";
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/make/MakeProject.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/make/MakeProject.java
index 5a4fc380385..dda857f06d3 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/make/MakeProject.java
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/make/MakeProject.java
@@ -4,12 +4,18 @@
*/
package org.eclipse.cdt.internal.core.make;
-import org.eclipse.cdt.core.ICProjectDescriptor;
-import org.eclipse.cdt.core.ICProjectOwner;
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.ICDescriptor;
+import org.eclipse.cdt.core.ICExtensionReference;
+import org.eclipse.cdt.core.ICOwner;
-public class MakeProject implements ICProjectOwner {
+public class MakeProject implements ICOwner {
- public void configure(ICProjectDescriptor cproject) {
+ public void configure(ICDescriptor cproject) {
+ ICExtensionReference ext = cproject.create(CCorePlugin.BUILDER_MODEL_ID, CCorePlugin.getDefault().PLUGIN_ID + ".makeBuilder");
+ ext.setExtensionData("command", "make");
}
+ public void update(ICDescriptor cproject) {
+ }
}