mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-09 01:05:38 +02:00
update of .cdtproject management
This commit is contained in:
parent
284a65e273
commit
547d7800c0
4 changed files with 63 additions and 27 deletions
|
@ -4,14 +4,6 @@
|
||||||
*/
|
*/
|
||||||
package org.eclipse.cdt.core;
|
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 interface ICProjectOwner {
|
||||||
public void configure(ICProjectDescriptor cproject);
|
public void configure(ICProjectDescriptor cproject);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ 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.ICProjectDescriptor;
|
import org.eclipse.cdt.core.ICProjectDescriptor;
|
||||||
|
import org.eclipse.cdt.core.ICProjectOwner;
|
||||||
import org.eclipse.cdt.core.ICProjectOwnerInfo;
|
import org.eclipse.cdt.core.ICProjectOwnerInfo;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
|
@ -37,6 +38,7 @@ import org.eclipse.core.runtime.Platform;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
|
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;
|
import org.xml.sax.SAXException;
|
||||||
|
@ -44,16 +46,16 @@ import org.xml.sax.SAXException;
|
||||||
public class CProjectDescriptor implements ICProjectDescriptor {
|
public class CProjectDescriptor implements ICProjectDescriptor {
|
||||||
/** constants */
|
/** constants */
|
||||||
private static final String[] EMPTY_STRING_ARRAY = new String[0];
|
private static final String[] EMPTY_STRING_ARRAY = new String[0];
|
||||||
private String ownerId;
|
private ICProjectOwnerInfo fOwner;
|
||||||
private IProject project;
|
private IProject fProject;
|
||||||
|
private String fPlatform = "*";
|
||||||
|
|
||||||
private String builderID;
|
private static final String PROJECT_DESCRIPTION = "cdtproject";
|
||||||
|
private static final String PROJECT_PLATFORM = "platform";
|
||||||
private static final String PROJECT_DESCRIPTION = ".cdtproject";
|
|
||||||
|
|
||||||
private CProjectDescriptor(IProject project, String id) throws CoreException {
|
private CProjectDescriptor(IProject project, String id) throws CoreException {
|
||||||
this.project = project;
|
fProject = project;
|
||||||
ownerId = id;
|
fOwner = new CProjectOwner(id);
|
||||||
IPath projectLocation = project.getDescription().getLocation();
|
IPath projectLocation = project.getDescription().getLocation();
|
||||||
|
|
||||||
final boolean isDefaultLocation = projectLocation == null;
|
final boolean isDefaultLocation = projectLocation == null;
|
||||||
|
@ -69,7 +71,7 @@ public class CProjectDescriptor implements ICProjectDescriptor {
|
||||||
}
|
}
|
||||||
|
|
||||||
private CProjectDescriptor(IProject project) throws CoreException {
|
private CProjectDescriptor(IProject project) throws CoreException {
|
||||||
this.project = project;
|
fProject = project;
|
||||||
FileInputStream file = null;
|
FileInputStream file = null;
|
||||||
IPath projectLocation = project.getDescription().getLocation();
|
IPath projectLocation = project.getDescription().getLocation();
|
||||||
|
|
||||||
|
@ -87,8 +89,9 @@ public class CProjectDescriptor implements ICProjectDescriptor {
|
||||||
file = new FileInputStream(projectLocation.toFile());
|
file = new FileInputStream(projectLocation.toFile());
|
||||||
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||||
Document document = parser.parse(file);
|
Document document = parser.parse(file);
|
||||||
Node attrib = (Node) read(document.getFirstChild());
|
Node node = document.getFirstChild();
|
||||||
ownerId = searchNode(attrib, "id").getNodeValue();
|
if (node.getNodeName().equals(PROJECT_DESCRIPTION))
|
||||||
|
fOwner = readProjectDescription(node);
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
}
|
}
|
||||||
|
@ -112,11 +115,11 @@ public class CProjectDescriptor implements ICProjectDescriptor {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ICProjectOwnerInfo getProjectOwner() {
|
public ICProjectOwnerInfo getProjectOwner() {
|
||||||
return new CProjectOwner(ownerId);
|
return fOwner;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPlatform() {
|
public String getPlatform() {
|
||||||
return "";
|
return fPlatform;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getString(Node target, String tagName) {
|
protected String getString(Node target, String tagName) {
|
||||||
|
@ -144,8 +147,6 @@ public class CProjectDescriptor implements ICProjectDescriptor {
|
||||||
return null;
|
return null;
|
||||||
switch (node.getNodeType()) {
|
switch (node.getNodeType()) {
|
||||||
case Node.ELEMENT_NODE :
|
case Node.ELEMENT_NODE :
|
||||||
if (node.getNodeName().equals(PROJECT_DESCRIPTION))
|
|
||||||
return node.getAttributes();
|
|
||||||
/*
|
/*
|
||||||
if (node.getNodeName().equals(BUILDER))
|
if (node.getNodeName().equals(BUILDER))
|
||||||
return readBuildSpec(node);
|
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) {
|
protected Node searchNode(Node target, String tagName) {
|
||||||
NodeList list = target.getChildNodes();
|
NodeList list = target.getChildNodes();
|
||||||
for (int i = 0; i < list.getLength(); i++) {
|
for (int i = 0; i < list.getLength(); i++) {
|
||||||
|
@ -170,7 +185,7 @@ public class CProjectDescriptor implements ICProjectDescriptor {
|
||||||
}
|
}
|
||||||
|
|
||||||
public IProject getProject() {
|
public IProject getProject() {
|
||||||
return project;
|
return fProject;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveInfo() throws CoreException {
|
public void saveInfo() throws CoreException {
|
||||||
|
@ -212,7 +227,7 @@ public class CProjectDescriptor implements ICProjectDescriptor {
|
||||||
Document doc = new DocumentImpl();
|
Document doc = new DocumentImpl();
|
||||||
Element configRootElement = doc.createElement(PROJECT_DESCRIPTION);
|
Element configRootElement = doc.createElement(PROJECT_DESCRIPTION);
|
||||||
doc.appendChild(configRootElement);
|
doc.appendChild(configRootElement);
|
||||||
configRootElement.setAttribute("id", ownerId); //$NON-NLS-1$
|
configRootElement.setAttribute("id", fOwner.getID()); //$NON-NLS-1$
|
||||||
element= createBuilderElement(doc);
|
element= createBuilderElement(doc);
|
||||||
if ( element != null )
|
if ( element != null )
|
||||||
configRootElement.appendChild(element);
|
configRootElement.appendChild(element);
|
||||||
|
@ -221,11 +236,13 @@ public class CProjectDescriptor implements ICProjectDescriptor {
|
||||||
|
|
||||||
|
|
||||||
protected Element createBuilderElement(Document doc) {
|
protected Element createBuilderElement(Document doc) {
|
||||||
|
/*
|
||||||
if ( builderID != null ) {
|
if ( builderID != null ) {
|
||||||
Element element = doc.createElement("cdtBuilder");
|
Element element = doc.createElement("cdtBuilder");
|
||||||
element.setAttribute("id", builderID);
|
element.setAttribute("id", builderID);
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,16 +15,21 @@ import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IConfigurationElement;
|
import org.eclipse.core.runtime.IConfigurationElement;
|
||||||
import org.eclipse.core.runtime.IExtension;
|
import org.eclipse.core.runtime.IExtension;
|
||||||
import org.eclipse.core.runtime.IExtensionPoint;
|
import org.eclipse.core.runtime.IExtensionPoint;
|
||||||
|
import org.eclipse.core.runtime.IStatus;
|
||||||
|
import org.eclipse.core.runtime.Status;
|
||||||
|
|
||||||
public class CProjectOwner implements ICProjectOwnerInfo {
|
public class CProjectOwner implements ICProjectOwnerInfo {
|
||||||
String pluginId;
|
String pluginId;
|
||||||
IExtension extension;
|
IExtension extension;
|
||||||
|
|
||||||
public CProjectOwner(String id) {
|
public CProjectOwner(String id) throws CoreException {
|
||||||
pluginId = id;
|
pluginId = id;
|
||||||
IExtensionPoint extpoint = CCorePlugin.getDefault().getDescriptor().getExtensionPoint("CProjectOwner");
|
IExtensionPoint extpoint = CCorePlugin.getDefault().getDescriptor().getExtensionPoint("CProjectOwner");
|
||||||
if (extpoint != null) {
|
if (extpoint != null) {
|
||||||
extension = extpoint.getExtension(pluginId);
|
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 {
|
void configure(IProject project, ICProjectDescriptor cproject) throws CoreException {
|
||||||
IConfigurationElement element[] = extension.getConfigurationElements();
|
IConfigurationElement element[] = extension.getConfigurationElements();
|
||||||
ICProjectOwner owner = (ICProjectOwner) element[0].createExecutableExtension("class");
|
for( int i = 0; i < element.length; i++ ) {
|
||||||
owner.configure(cproject);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue