From 547d7800c0256d52311454307fc139009d252703 Mon Sep 17 00:00:00 2001 From: David Inglis Date: Fri, 9 Aug 2002 20:35:48 +0000 Subject: [PATCH] update of .cdtproject management --- .../org/eclipse/cdt/core/ICProjectOwner.java | 8 --- .../cdt/internal/core/CProjectDescriptor.java | 49 +++++++++++++------ .../cdt/internal/core/CProjectOwner.java | 18 +++++-- .../cdt/internal/core/make/MakeProject.java | 15 ++++++ 4 files changed, 63 insertions(+), 27 deletions(-) create mode 100644 core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/make/MakeProject.java 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 index 547d09ef622..367533f47f0 100644 --- 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 @@ -4,14 +4,6 @@ */ package org.eclipse.cdt.core; -/** - * @author DInglis - * - * To change this generated comment edit the template variable "typecomment": - * Window>Preferences>Java>Templates. - * To enable and disable the creation of type comments go to - * Window>Preferences>Java>Code Generation. - */ public interface ICProjectOwner { public void configure(ICProjectDescriptor cproject); } 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 index 4e06e51eb4b..1632ce46dd9 100644 --- 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 @@ -25,6 +25,7 @@ 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; @@ -37,6 +38,7 @@ 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; @@ -44,16 +46,16 @@ import org.xml.sax.SAXException; public class CProjectDescriptor implements ICProjectDescriptor { /** constants */ private static final String[] EMPTY_STRING_ARRAY = new String[0]; - private String ownerId; - private IProject project; - - private String builderID; + private ICProjectOwnerInfo fOwner; + private IProject fProject; + private String fPlatform = "*"; - private static final String PROJECT_DESCRIPTION = ".cdtproject"; + private static final String PROJECT_DESCRIPTION = "cdtproject"; + private static final String PROJECT_PLATFORM = "platform"; private CProjectDescriptor(IProject project, String id) throws CoreException { - this.project = project; - ownerId = id; + fProject = project; + fOwner = new CProjectOwner(id); IPath projectLocation = project.getDescription().getLocation(); final boolean isDefaultLocation = projectLocation == null; @@ -69,7 +71,7 @@ public class CProjectDescriptor implements ICProjectDescriptor { } private CProjectDescriptor(IProject project) throws CoreException { - this.project = project; + fProject = project; FileInputStream file = null; IPath projectLocation = project.getDescription().getLocation(); @@ -87,8 +89,9 @@ public class CProjectDescriptor implements ICProjectDescriptor { file = new FileInputStream(projectLocation.toFile()); DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document document = parser.parse(file); - Node attrib = (Node) read(document.getFirstChild()); - ownerId = searchNode(attrib, "id").getNodeValue(); + Node node = document.getFirstChild(); + if (node.getNodeName().equals(PROJECT_DESCRIPTION)) + fOwner = readProjectDescription(node); } catch (IOException e) { } @@ -112,11 +115,11 @@ public class CProjectDescriptor implements ICProjectDescriptor { } public ICProjectOwnerInfo getProjectOwner() { - return new CProjectOwner(ownerId); + return fOwner; } public String getPlatform() { - return ""; + return fPlatform; } protected String getString(Node target, String tagName) { @@ -144,8 +147,6 @@ public class CProjectDescriptor implements ICProjectDescriptor { return null; switch (node.getNodeType()) { case Node.ELEMENT_NODE : - if (node.getNodeName().equals(PROJECT_DESCRIPTION)) - return node.getAttributes(); /* if (node.getNodeName().equals(BUILDER)) return readBuildSpec(node); @@ -160,6 +161,20 @@ public class CProjectDescriptor implements ICProjectDescriptor { } } + 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++) { @@ -170,7 +185,7 @@ public class CProjectDescriptor implements ICProjectDescriptor { } public IProject getProject() { - return project; + return fProject; } public void saveInfo() throws CoreException { @@ -212,7 +227,7 @@ public class CProjectDescriptor implements ICProjectDescriptor { Document doc = new DocumentImpl(); Element configRootElement = doc.createElement(PROJECT_DESCRIPTION); doc.appendChild(configRootElement); - configRootElement.setAttribute("id", ownerId); //$NON-NLS-1$ + configRootElement.setAttribute("id", fOwner.getID()); //$NON-NLS-1$ element= createBuilderElement(doc); if ( element != null ) configRootElement.appendChild(element); @@ -221,11 +236,13 @@ public class CProjectDescriptor implements ICProjectDescriptor { protected Element createBuilderElement(Document doc) { +/* if ( builderID != null ) { Element element = doc.createElement("cdtBuilder"); element.setAttribute("id", builderID); return element; } +*/ return null; } 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/CProjectOwner.java index 5464c7968df..84fe08f9912 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/CProjectOwner.java @@ -15,16 +15,21 @@ 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 CProjectOwner implements ICProjectOwnerInfo { String pluginId; IExtension extension; - public CProjectOwner(String id) { + public CProjectOwner(String id) throws CoreException { pluginId = id; IExtensionPoint extpoint = CCorePlugin.getDefault().getDescriptor().getExtensionPoint("CProjectOwner"); if (extpoint != null) { extension = extpoint.getExtension(pluginId); + } else { + IStatus status = new Status(IStatus.ERROR, CCorePlugin.getDefault().PLUGIN_ID, -1, "Invalid CDTProject owner ID", (Throwable)null); + throw new CoreException(status); } } @@ -73,7 +78,14 @@ public class CProjectOwner implements ICProjectOwnerInfo { void configure(IProject project, ICProjectDescriptor cproject) throws CoreException { IConfigurationElement element[] = extension.getConfigurationElements(); - ICProjectOwner owner = (ICProjectOwner) element[0].createExecutableExtension("class"); - owner.configure(cproject); + for( int i = 0; i < element.length; i++ ) { + if ( element[i].getName().equalsIgnoreCase("run") ) { + ICProjectOwner owner = (ICProjectOwner) element[i].createExecutableExtension("class"); + owner.configure(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/make/MakeProject.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/make/MakeProject.java new file mode 100644 index 00000000000..5a4fc380385 --- /dev/null +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/make/MakeProject.java @@ -0,0 +1,15 @@ +/* + * (c) Copyright QNX Software System Ltd. 2002. + * All Rights Reserved. + */ +package org.eclipse.cdt.internal.core.make; + +import org.eclipse.cdt.core.ICProjectDescriptor; +import org.eclipse.cdt.core.ICProjectOwner; + +public class MakeProject implements ICProjectOwner { + + public void configure(ICProjectDescriptor cproject) { + } + +}