1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-10 01:35:39 +02:00

Work for C14, add the ability to inherit a tool description via a tool

reference.
	
	Changed the schema to allow a tool reference to belong to a target.
	* schema/ManagedBuildTools.exsd
	
	Changed the manifest logic in the managed build manager to load and 
	retrieve tool definitions as well as target definitions. The schema 
	allowed for this, but the logic was missing.
	* src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java

	Made some bookeeping additions to the target so that it can store references 
	to tools. First, the target loads any tool references it has. Then it loads 
	tools and configurations. The target also has to consider the presence of tool 
	references when it determines how many tools it has, so the logic that counted 
	and returned the number of tools in the target was updated. Some key changes in 
	this regard relate to how the target looks up the tool references it has. It 
	now has to ask the managed build info if it has a tool definition for the reference 
	if there are no tools defined for the target level for a given reference.
	* src/org/eclipse/cdt/managedbuilder/internal/core/Target.java
	
	Tool references now have the potential to be owned by either a target or a 
	configuration. Changed the owner to the superclass of both and figure out 
	which the parent is at runtime to perform the proper registration and information 
	look-up. Also removed the reference to a target from a tool and the interface to 
	extract the target from ITool.
	* src/org/eclipse/cdt/managedbuilder/core/ITool.java
	* src/org/eclipse/cdt/managedbuilder/internal/core/Tool.java
	* src/org/eclipse/cdt/managedbuilder/internal/core/ToolReference.java
	
	An unrelated bug had to do with a problem my testing uncovered with nested 
	categories. The manifest reader was looking at the wrong field to determine 
	the parent, but for the manifests we have created, this has not proven to be 
	a problem so far.
	* src/org/eclipse/cdt/managedbuilder/core/IOptionCategory.java
	* src/org/eclipse/cdt/managedbuilder/core/IOptionCategory.java
This commit is contained in:
Sean Evoy 2004-02-26 20:53:54 +00:00
parent b9e2f84b0c
commit 72991c1d3e
11 changed files with 609 additions and 348 deletions

View file

@ -1,3 +1,41 @@
2004-02-26
Work for C14, add the ability to inherit a tool description via a tool
reference.
Changed the schema to allow a tool reference to belong to a target.
* schema/ManagedBuildTools.exsd
Changed the manifest logic in the managed build manager to load and
retrieve tool definitions as well as target definitions. The schema
allowed for this, but the logic was missing.
* src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java
Made some bookeeping additions to the target so that it can store references
to tools. First, the target loads any tool references it has. Then it loads
tools and configurations. The target also has to consider the presence of tool
references when it determines how many tools it has, so the logic that counted
and returned the number of tools in the target was updated. Some key changes in
this regard relate to how the target looks up the tool references it has. It
now has to ask the managed build info if it has a tool definition for the reference
if there are no tools defined for the target level for a given reference.
* src/org/eclipse/cdt/managedbuilder/internal/core/Target.java
Tool references now have the potential to be owned by either a target or a
configuration. Changed the owner to the superclass of both and figure out
which the parent is at runtime to perform the proper registration and information
look-up. Also removed the reference to a target from a tool and the interface to
extract the target from ITool.
* src/org/eclipse/cdt/managedbuilder/core/ITool.java
* src/org/eclipse/cdt/managedbuilder/internal/core/Tool.java
* src/org/eclipse/cdt/managedbuilder/internal/core/ToolReference.java
An unrelated bug had to do with a problem my testing uncovered with nested
categories. The manifest reader was looking at the wrong field to determine
the parent, but for the manifests we have created, this has not proven to be
a problem so far.
* src/org/eclipse/cdt/managedbuilder/core/IOptionCategory.java
* src/org/eclipse/cdt/managedbuilder/core/IOptionCategory.java
2004-02-24 Sean Evoy
Changed the makefile generator to escape any whitespace it finds in a dependency
path. Now it is possible to build a project in a location with spaces but

View file

@ -166,8 +166,8 @@
<attribute name="valueType" use="default" value="string">
<annotation>
<documentation>
General options can be one of the following types; &apos;string&apos; for catch-all entries for options that cannot be easily defined any other way, &apos;string list&apos; for entries that consist of a list of values such as defined symbols or paths, &apos;boolean&apos; for options that have two values, and &apos;enumerated&apos; for options that are one-of a list of values.
General options can be one of the following types; &apos;string&apos; for catch-all entries for options that cannot be easily defined any other way, &apos;string list&apos; for entries that consist of a list of values such as defined symbols or paths, &apos;boolean&apos; for options that have two values, and &apos;enumerated&apos; for options that are one-of a list of values.
Additional special types exist to flag options of special relevance to the build model; &apos;include&apos;, &apos;libs&apos;, &apos;userObjs&apos; and &apos;definedSymbols&apos;. You can pre-populate with optionValues, and they will display in the UI the same way the &apos;stringList&apos; options do. The build model will look specifically for these value types when clients query for include paths and preprocessor defines. The makefile generator will treat the libs and userObjs entries differently than other stringLists.
</documentation>
</annotation>
@ -298,6 +298,13 @@ Additional special types exist to flag options of special relevance to the build
</documentation>
</annotation>
</attribute>
<attribute name="command" type="string">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
</complexType>
</element>
@ -342,6 +349,7 @@ Additional special types exist to flag options of special relevance to the build
<sequence>
<element ref="tool"/>
<element ref="configuration"/>
<element ref="toolReference"/>
</sequence>
<attribute name="id" type="string" use="required">
<annotation>
@ -437,7 +445,7 @@ Additional special types exist to flag options of special relevance to the build
</documentation>
</annotation>
<complexType>
<attribute name="id" type="string">
<attribute name="id" type="string" use="required">
<annotation>
<documentation>
Used by the build model to uniquely identify the option category.
@ -499,48 +507,48 @@ Additional special types exist to flag options of special relevance to the build
<meta.section type="examples"/>
</appInfo>
<documentation>
The following is an example of the extension point usage:
&lt;p&gt;
&lt;pre&gt;
&lt;extension
id=&quot;buildExample&quot;
name=&quot;Tools for Build Example&quot;
point=&quot;org.eclipse.cdt.core.ManagedBuildInfo&quot;&gt;
&lt;target
makeFlags=&quot;-k&quot;
isTest=&quot;false&quot;
cleanCommand=&quot;rm -rf&quot;
name=&quot;Executable&quot;
defaultExtension=&quot;.exe&quot;
isAbstract=&quot;false&quot;
makeCommand=&quot;make&quot;
id=&quot;example.target.executable&quot;&gt;
&lt;tool
sources=&quot;C&quot;
name=&quot;Compiler&quot;
outputFlag=&quot;-o&quot;
outputs=&quot;exe&quot;
command=&quot;g++&quot;
id=&quot;executable.compiler&quot;&gt;
&lt;optionCategory
owner=&quot;executable.compiler&quot;
name=&quot;Flags&quot;
id=&quot;compiler.category.flags&quot;&gt;
&lt;/optionCategory&gt;
&lt;option
defaultValue=&quot;-c&quot;
name=&quot;Compiler Flags&quot;
category=&quot;compiler.category.flags&quot;
valueType=&quot;string&quot;
id=&quot;category.flags.comp_flags&quot;&gt;
&lt;/option&gt;
&lt;/tool&gt;
&lt;configuration
name=&quot;Default&quot;
id=&quot;example.config.default&quot;&gt;
&lt;/configuration&gt;
&lt;/target&gt;
&lt;/extension&gt;
The following is an example of the extension point usage:
&lt;p&gt;
&lt;pre&gt;
&lt;extension
id=&quot;buildExample&quot;
name=&quot;Tools for Build Example&quot;
point=&quot;org.eclipse.cdt.core.ManagedBuildInfo&quot;&gt;
&lt;target
makeFlags=&quot;-k&quot;
isTest=&quot;false&quot;
cleanCommand=&quot;rm -rf&quot;
name=&quot;Executable&quot;
defaultExtension=&quot;.exe&quot;
isAbstract=&quot;false&quot;
makeCommand=&quot;make&quot;
id=&quot;example.target.executable&quot;&gt;
&lt;tool
sources=&quot;C&quot;
name=&quot;Compiler&quot;
outputFlag=&quot;-o&quot;
outputs=&quot;exe&quot;
command=&quot;g++&quot;
id=&quot;executable.compiler&quot;&gt;
&lt;optionCategory
owner=&quot;executable.compiler&quot;
name=&quot;Flags&quot;
id=&quot;compiler.category.flags&quot;&gt;
&lt;/optionCategory&gt;
&lt;option
defaultValue=&quot;-c&quot;
name=&quot;Compiler Flags&quot;
category=&quot;compiler.category.flags&quot;
valueType=&quot;string&quot;
id=&quot;category.flags.comp_flags&quot;&gt;
&lt;/option&gt;
&lt;/tool&gt;
&lt;configuration
name=&quot;Default&quot;
id=&quot;example.config.default&quot;&gt;
&lt;/configuration&gt;
&lt;/target&gt;
&lt;/extension&gt;
&lt;/pre&gt;
</documentation>
</annotation>
@ -568,7 +576,7 @@ Additional special types exist to flag options of special relevance to the build
<meta.section type="copyright"/>
</appInfo>
<documentation>
Copyright (c) 2003 IBM Corporation and others.
Copyright (c) 2003 IBM Corporation and others.
All rights reserved. This program and the accompanying materials are made available under the terms of the Common Public License v1.0 which accompanies this distribution, and is available on the &lt;a href=&quot;http://www.eclipse.org/legal/cpl-v10.html&quot;&gt; Eclipse&lt;/a&gt; website.
</documentation>
</annotation>

View file

@ -15,7 +15,7 @@ import org.eclipse.core.resources.IResource;
public interface IConfiguration extends IBuildObject {
// Schema element names
public static final String CONFIGURATION_ELEMENT_NAME = "configuration"; //$NON-NLS-1$
public static final String TOOL_REF = "toolReference"; //$NON-NLS-1$
public static final String TOOLREF_ELEMENT_NAME = "toolReference"; //$NON-NLS-1$
public static final String PARENT = "parent"; //$NON-NLS-1$
/**

View file

@ -16,7 +16,7 @@ package org.eclipse.cdt.managedbuilder.core;
public interface IOptionCategory extends IBuildObject {
// Schema element names
public static final String PARENT = "parent";
public static final String OWNER = "owner";
/**
* Returns the list of children of this node in the option category tree

View file

@ -104,7 +104,7 @@ public interface ITool extends IBuildObject {
* Return the target that defines this tool, if applicable
* @return ITarget
*/
public ITarget getTarget();
// public ITarget getTarget();
/**
* Answers the command-line invocation defined for the receiver.

View file

@ -35,6 +35,7 @@ import org.eclipse.cdt.core.parser.IScannerInfoProvider;
import org.eclipse.cdt.managedbuilder.internal.core.Configuration;
import org.eclipse.cdt.managedbuilder.internal.core.ManagedBuildInfo;
import org.eclipse.cdt.managedbuilder.internal.core.Target;
import org.eclipse.cdt.managedbuilder.internal.core.Tool;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
@ -42,6 +43,7 @@ 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.IPluginDescriptor;
import org.eclipse.core.runtime.QualifiedName;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@ -60,10 +62,12 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI
public static final String INTERFACE_IDENTITY = ManagedBuilderCorePlugin.getUniqueIdentifier() + "." + "ManagedBuildManager"; //$NON-NLS-1$
public static final String EXTENSION_POINT_ID = "ManagedBuildInfo"; //$NON-NLS-1$
// Targets defined by extensions (i.e., not associated with a resource)
// This is the version of the manifest and project files that
private static final String buildInfoVersion = "2.0.0";
private static boolean extensionTargetsLoaded = false;
private static List extensionTargets;
private static Map extensionTargetMap;
private static List extensionTargets;
private static Map extensionToolMap;
// Listeners interested in build model changes
private static Map buildModelListeners;
@ -102,6 +106,8 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI
}
/* (non-Javadoc)
* Safe accessor for the map of IDs to Targets
*
* @return
*/
protected static Map getExtensionTargetMap() {
@ -111,6 +117,18 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI
return extensionTargetMap;
}
/* (non-Javadoc)
* Safe accessor for the map of IDs to Tools
*
* @return
*/
protected static Map getExtensionToolMap() {
if (extensionToolMap == null) {
extensionToolMap = new HashMap();
}
return extensionToolMap;
}
/**
* Returns the targets owned by this project. If none are owned,
* an empty array is returned.
@ -129,6 +147,15 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI
}
}
/**
* Answers the tool with the ID specified in the argument or <code>null</code>.
*
* @param id
* @return
*/
public static ITool getTool(String id) {
return (ITool) getExtensionToolMap().get(id);
}
/**
* Answers the result of a best-effort search to find a target with the
@ -153,39 +180,6 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI
return target;
}
/**
* Creates a new target for the resource based on the parentTarget.
*
* @param resource
* @param parentTarget
* @return new <code>ITarget</code> with settings based on the parent passed in the arguments
* @throws BuildException
*/
public static ITarget createTarget(IResource resource, ITarget parentTarget)
throws BuildException
{
IResource owner = parentTarget.getOwner();
if (owner != null && owner.equals(resource))
// Already added
return parentTarget;
if (resource instanceof IProject) {
// Must be an extension target (why?)
if (owner != null)
throw new BuildException("addTarget: owner not null");
} else {
// Owner must be owned by the project containing this resource
if (owner == null)
throw new BuildException("addTarget: null owner");
if (!owner.equals(resource.getProject()))
throw new BuildException("addTarget: owner not project");
}
// Passed validation
return new Target(resource, parentTarget);
}
/**
* Sets the default configuration for the project. Note that this will also
* update the default target if needed.
@ -384,7 +378,50 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI
getExtensionTargetMap().put(target.getId(), target);
}
// Private stuff
/**
* @param tool
*/
public static void addExtensionTool(Tool tool) {
getExtensionToolMap().put(tool.getId(), tool);
}
/**
* Creates a new target for the resource based on the parentTarget.
*
* @param resource
* @param parentTarget
* @return new <code>ITarget</code> with settings based on the parent passed in the arguments
* @throws BuildException
*/
public static ITarget createTarget(IResource resource, ITarget parentTarget)
throws BuildException
{
IResource owner = parentTarget.getOwner();
if (owner != null && owner.equals(resource))
// Already added
return parentTarget;
if (resource instanceof IProject) {
// Must be an extension target (why?)
if (owner != null)
throw new BuildException("addTarget: owner not null");
} else {
// Owner must be owned by the project containing this resource
if (owner == null)
throw new BuildException("addTarget: null owner");
if (!owner.equals(resource.getProject()))
throw new BuildException("addTarget: owner not project");
}
// Passed validation
return new Target(resource, parentTarget);
}
/* (non-Javadoc)
* Load the build information for the specified resource from its project
* file. Pay attention to the version number too.
*/
private static ManagedBuildInfo loadBuildInfo(IProject project) {
ManagedBuildInfo buildInfo = null;
IFile file = project.getFile(FILE_NAME);
@ -408,26 +445,44 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI
}
/* (non-Javadoc)
* Since the class does not have a constructor, but all public methods
* Since the class does not have a constructor but all public methods
* call this method first, it is effectively a startup method
*/
private static void loadExtensions() {
if (extensionTargetsLoaded)
return;
extensionTargetsLoaded = true;
IExtensionPoint extensionPoint = ManagedBuilderCorePlugin.getDefault().getDescriptor().getExtensionPoint(EXTENSION_POINT_ID);
// Get those extensions
IPluginDescriptor descriptor = ManagedBuilderCorePlugin.getDefault().getDescriptor();
// Get the version of the manifest
/* PluginVersionIdentifier version = descriptor.getVersionIdentifier();
if (version.isGreaterThan(new PluginVersionIdentifier(buildInfoVersion))) {
//TODO: The version of the Plug-in is greater than what the manager thinks it understands
}
*/ // We can read the manifest
IExtensionPoint extensionPoint = descriptor.getExtensionPoint(EXTENSION_POINT_ID);
IExtension[] extensions = extensionPoint.getExtensions();
for (int i = 0; i < extensions.length; ++i) {
IExtension extension = extensions[i];
IConfigurationElement[] elements = extension.getConfigurationElements();
for (int j = 0; j < elements.length; ++j) {
IConfigurationElement element = elements[j];
// Load the tools first
for (int toolIndex = 0; toolIndex < elements.length; ++toolIndex) {
IConfigurationElement element = elements[toolIndex];
// Load the targets
if (element.getName().equals(ITool.TOOL_ELEMENT_NAME)) {
new Tool(element);
}
}
for (int targetIndex = 0; targetIndex < elements.length; ++targetIndex) {
IConfigurationElement element = elements[targetIndex];
// Load the targets
if (element.getName().equals(ITarget.TARGET_ELEMENT_NAME)) {
new Target(element);
}
}
}
// Let's never do that again
extensionTargetsLoaded = true;
}
/**
@ -518,6 +573,10 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI
return (IManagedBuildInfo) findBuildInfo(resource, false);
}
public static String getBuildInfoVersion() {
return buildInfoVersion;
}
/*
* @return
*/
@ -582,4 +641,5 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI
map.put(project, list);
}
}
}

View file

@ -41,16 +41,44 @@ public class Configuration extends BuildObject implements IConfiguration {
private List toolReferences;
/**
* A fresh new configuration for a target.
* Build a configuration from the project manifest file.
*
* @param target
* @param id
*/
public Configuration(Target target, String id) {
this.id = id;
* @param target The <code>Target</code> the configuration belongs to.
* @param element The element from the manifest that contains the overridden configuration information.
*/
public Configuration(Target target, Element element) {
this.target = target;
// id
setId(element.getAttribute(IConfiguration.ID));
// hook me up
target.addConfiguration(this);
// name
if (element.hasAttribute(IConfiguration.NAME))
setName(element.getAttribute(IConfiguration.NAME));
if (element.hasAttribute(IConfiguration.PARENT)) {
// See if the target has a parent
ITarget targetParent = target.getParent();
// If so, then get my parent from it
if (targetParent != null) {
parent = targetParent.getConfiguration(element.getAttribute(IConfiguration.PARENT));
}
else {
parent = null;
}
}
NodeList configElements = element.getChildNodes();
for (int i = 0; i < configElements.getLength(); ++i) {
Node configElement = configElements.item(i);
if (configElement.getNodeName().equals(IConfiguration.TOOLREF_ELEMENT_NAME)) {
new ToolReference(this, (Element)configElement);
}
}
}
/**
@ -139,78 +167,56 @@ public class Configuration extends BuildObject implements IConfiguration {
IConfigurationElement[] configElements = element.getChildren();
for (int l = 0; l < configElements.length; ++l) {
IConfigurationElement configElement = configElements[l];
if (configElement.getName().equals(IConfiguration.TOOL_REF)) {
if (configElement.getName().equals(IConfiguration.TOOLREF_ELEMENT_NAME)) {
new ToolReference(this, configElement);
}
}
}
/**
* Build a configuration from the project manifest file.
* A fresh new configuration for a target.
*
* @param target The <code>Target</code> the configuration belongs to.
* @param element The element from the manifest that contains the overridden configuration information.
*/
public Configuration(Target target, Element element) {
* @param target
* @param id
*/
public Configuration(Target target, String id) {
this.id = id;
this.target = target;
// id
setId(element.getAttribute(IConfiguration.ID));
// hook me up
target.addConfiguration(this);
// name
if (element.hasAttribute(IConfiguration.NAME))
setName(element.getAttribute(IConfiguration.NAME));
if (element.hasAttribute(IConfiguration.PARENT)) {
// See if the target has a parent
ITarget targetParent = target.getParent();
// If so, then get my parent from it
if (targetParent != null) {
parent = targetParent.getConfiguration(element.getAttribute(IConfiguration.PARENT));
}
else {
parent = null;
}
}
NodeList configElements = element.getChildNodes();
for (int i = 0; i < configElements.getLength(); ++i) {
Node configElement = configElements.item(i);
if (configElement.getNodeName().equals(IConfiguration.TOOL_REF)) {
new ToolReference(this, (Element)configElement);
}
}
}
/**
* Adds a tool reference to the receiver.
*
* @param toolRef
*/
public void addToolReference(ToolReference toolRef) {
getLocalToolReferences().add(toolRef);
}
/**
* Persist receiver to project file.
*
* @param doc
* @param element
* @param option
* @return
*/
public void serialize(Document doc, Element element) {
element.setAttribute(IConfiguration.ID, id);
if (name != null)
element.setAttribute(IConfiguration.NAME, name);
if (parent != null)
element.setAttribute(IConfiguration.PARENT, parent.getId());
// Serialize only the tool references defined in the configuration
Iterator iter = getLocalToolReferences().listIterator();
while (iter.hasNext()) {
ToolReference toolRef = (ToolReference) iter.next();
Element toolRefElement = doc.createElement(IConfiguration.TOOL_REF);
element.appendChild(toolRefElement);
toolRef.serialize(doc, toolRefElement);
public OptionReference createOptionReference(IOption option) {
if (option instanceof OptionReference) {
OptionReference optionRef = (OptionReference)option;
ToolReference toolRef = optionRef.getToolReference();
if (toolRef.ownedByConfiguration(this))
return optionRef;
else {
toolRef = new ToolReference(this, toolRef);
return toolRef.createOptionReference(option);
}
} else {
ToolReference toolRef = getToolReference(option.getTool());
if (toolRef == null)
toolRef = new ToolReference(this, option.getTool());
return toolRef.createOptionReference(option);
}
}
/* (non-javadoc)
* A safety method to avoid NPEs. It answers the tool reference list in the
* receiver. It does not look at the tool references defined in the parent.
@ -278,11 +284,6 @@ public class Configuration extends BuildObject implements IConfiguration {
// Replace tools with local overrides
for (int i = 0; i < tools.length; ++i) {
ITool tool = tools[i];
if (tool == null) {
// May have been filtered out
continue;
}
ToolReference ref = getToolReference(tools[i]);
if (ref != null)
tools[i] = ref;
@ -291,21 +292,6 @@ public class Configuration extends BuildObject implements IConfiguration {
return tools;
}
/**
* @param targetElement
*/
public void reset(IConfigurationElement element) {
// I just need to reset the tool references
getLocalToolReferences().clear();
IConfigurationElement[] configElements = element.getChildren();
for (int l = 0; l < configElements.length; ++l) {
IConfigurationElement configElement = configElements[l];
if (configElement.getName().equals(IConfiguration.TOOL_REF)) {
new ToolReference(this, configElement);
}
}
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.build.managed.IConfiguration#getParent()
*/
@ -356,7 +342,7 @@ public class Configuration extends BuildObject implements IConfiguration {
return getTarget().getOwner();
}
/**
/* (non-Javadoc)
* Returns the reference for a given tool or <code>null</code> if one is not
* found.
*
@ -366,6 +352,7 @@ public class Configuration extends BuildObject implements IConfiguration {
private ToolReference getToolReference(ITool tool) {
// See if the receiver has a reference to the tool
ToolReference ref = null;
if (tool == null) return ref;
Iterator iter = getLocalToolReferences().listIterator();
while (iter.hasNext()) {
ToolReference temp = (ToolReference)iter.next();
@ -374,32 +361,49 @@ public class Configuration extends BuildObject implements IConfiguration {
break;
}
}
return ref;
}
public void addToolReference(ToolReference toolRef) {
getLocalToolReferences().add(toolRef);
}
public OptionReference createOptionReference(IOption option) {
if (option instanceof OptionReference) {
OptionReference optionRef = (OptionReference)option;
ToolReference toolRef = optionRef.getToolReference();
if (toolRef.getConfiguration().equals(this))
return optionRef;
else {
toolRef = new ToolReference(this, toolRef);
return toolRef.createOptionReference(option);
/**
* @param targetElement
*/
public void reset(IConfigurationElement element) {
// I just need to reset the tool references
getLocalToolReferences().clear();
IConfigurationElement[] configElements = element.getChildren();
for (int l = 0; l < configElements.length; ++l) {
IConfigurationElement configElement = configElements[l];
if (configElement.getName().equals(IConfiguration.TOOLREF_ELEMENT_NAME)) {
new ToolReference(this, configElement);
}
} else {
ToolReference toolRef = getToolReference(option.getTool());
if (toolRef == null)
toolRef = new ToolReference(this, option.getTool());
return toolRef.createOptionReference(option);
}
}
/**
* Persist receiver to project file.
*
* @param doc
* @param element
*/
public void serialize(Document doc, Element element) {
element.setAttribute(IConfiguration.ID, id);
if (name != null)
element.setAttribute(IConfiguration.NAME, name);
if (parent != null)
element.setAttribute(IConfiguration.PARENT, parent.getId());
// Serialize only the tool references defined in the configuration
Iterator iter = getLocalToolReferences().listIterator();
while (iter.hasNext()) {
ToolReference toolRef = (ToolReference) iter.next();
Element toolRefElement = doc.createElement(IConfiguration.TOOLREF_ELEMENT_NAME);
element.appendChild(toolRefElement);
toolRef.serialize(doc, toolRefElement);
}
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.build.managed.IConfiguration#setOption(org.eclipse.cdt.core.build.managed.IOption, boolean)
*/
@ -454,6 +458,11 @@ public class Configuration extends BuildObject implements IConfiguration {
if(!Arrays.equals(value, oldValue))
createOptionReference(option).setValue(value);
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
public String toString() {
return new String("Configuration: ") + getName();
}
}

View file

@ -34,9 +34,9 @@ public class OptionCategory extends BuildObject implements IOptionCategory {
}
public OptionCategory(Tool tool, IConfigurationElement element) {
String parentId = element.getAttribute(IOptionCategory.PARENT);
String parentId = element.getAttribute(IOptionCategory.OWNER);
if (parentId != null)
owner = tool.getOptionCategory(element.getAttribute(IOptionCategory.PARENT));
owner = tool.getOptionCategory(parentId);
else
owner = tool;

View file

@ -24,6 +24,7 @@ import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
import org.eclipse.cdt.managedbuilder.core.ITarget;
import org.eclipse.cdt.managedbuilder.core.ITool;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.core.boot.BootLoader;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IConfigurationElement;
import org.w3c.dom.Document;
@ -49,16 +50,23 @@ public class Target extends BuildObject implements ITarget {
private List targetOSList;
private Map toolMap;
private List toolList;
private List toolReferences;
private static final IConfiguration[] emptyConfigs = new IConfiguration[0];
private static final String EMPTY_STRING = new String();
public Target(IResource owner) {
/* (non-Javadoc)
* Set the resource that owns the target.
*
* @param owner
*/
protected Target(IResource owner) {
this.owner = owner;
}
/**
* Create a target owned by a resource based on a parent target
* Create a copy of the target specified in the argument,
* that is owned by the owned by the specified resource.
*
* @param owner
* @param parent
@ -132,17 +140,9 @@ public class Target extends BuildObject implements ITarget {
// Get the clean command
cleanCommand = element.getAttribute(CLEAN_COMMAND);
if (cleanCommand == null) {
// See if it defined in the parent
cleanCommand = parent.getCleanCommand();
}
// Get the make command
makeCommand = element.getAttribute(MAKE_COMMAND);
if (makeCommand == null) {
// See if it defined in the parent
makeCommand = parent.getMakeCommand();
}
// Get the comma-separated list of valid OS
String os = element.getAttribute(OS_LIST);
@ -154,23 +154,21 @@ public class Target extends BuildObject implements ITarget {
}
}
IConfigurationElement[] targetElements = element.getChildren();
int k;
// Load the tools first
for (k = 0; k < targetElements.length; ++k) {
IConfigurationElement targetElement = targetElements[k];
if (targetElement.getName().equals(ITool.TOOL_ELEMENT_NAME)) {
new Tool(this, targetElement);
}
// Load any tool references we might have
IConfigurationElement[] toolRefs = element.getChildren(IConfiguration.TOOLREF_ELEMENT_NAME);
for (int i=0; i < toolRefs.length; ++i) {
new ToolReference(this, toolRefs[i]);
}
// Then load any tools defined for the target
IConfigurationElement[] tools = element.getChildren(ITool.TOOL_ELEMENT_NAME);
for (int j = 0; j < tools.length; ++j) {
new Tool(this, tools[j]);
}
// Then load the configurations which may have tool references
for (k = 0; k < targetElements.length; ++k) {
IConfigurationElement targetElement = targetElements[k];
if (targetElement.getName().equals(IConfiguration.CONFIGURATION_ELEMENT_NAME)) {
new Configuration(this, targetElement);
}
IConfigurationElement[] configs = element.getChildren(IConfiguration.CONFIGURATION_ELEMENT_NAME);
for (int k = 0; k < configs.length; ++k) {
new Configuration(this, configs[k]);
}
}
/**
@ -290,6 +288,20 @@ public class Target extends BuildObject implements ITarget {
}
}
/* (non-javadoc)
* A safe accesor method. It answers the tool reference list in the
* receiver.
*
* @return List
*/
protected List getLocalToolReferences() {
if (toolReferences == null) {
toolReferences = new ArrayList();
toolReferences.clear();
}
return toolReferences;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.managedbuilder.core.ITarget#getMakeArguments()
*/
@ -311,7 +323,17 @@ public class Target extends BuildObject implements ITarget {
*/
public String getMakeCommand() {
// Return the name of the make utility
return (makeCommand == null) ? parent.getMakeCommand() : makeCommand;
if (makeCommand == null) {
// If I have a parent, ask it
if (parent != null) {
return parent.getMakeCommand();
} else {
// The user has forgotten to specify a command in the plugin manifets.
return new String("make");
}
} else {
return makeCommand;
}
}
/* (non-Javadoc)
@ -351,14 +373,26 @@ public class Target extends BuildObject implements ITarget {
return owner;
}
private int getNumTools() {
private int getToolCount() {
// Count the tools that belong to the target
int n = getToolList().size();
// Count the references the target has
n += getLocalToolReferences().size();
// Count the tools in the parent
if (parent != null)
n += ((Target)parent).getNumTools();
n += ((Target)parent).getToolCount();
return n;
}
/* (non-Javadoc)
* Tail-recursion method that creates a lits of tools and tool reference
* walking the receiver's parent hierarchy.
*
* @param toolArray
* @param start
* @return
*/
private int addToolsToArray(ITool[] toolArray, int start) {
int n = start;
if (parent != null)
@ -367,10 +401,20 @@ public class Target extends BuildObject implements ITarget {
for (int i = 0; i < getToolList().size(); ++i) {
toolArray[n++] = (ITool)getToolList().get(i);
}
// Add local tool references
for (int j = 0; j < getLocalToolReferences().size(); ++j) {
toolArray[n++] = (ITool)getLocalToolReferences().get(j);
}
return n;
}
/* (non-Javadoc)
* A safe accessor method for the list of tools maintained by the
* target
*
*/
private List getToolList() {
if (toolList == null) {
toolList = new ArrayList();
@ -379,6 +423,10 @@ public class Target extends BuildObject implements ITarget {
return toolList;
}
/* (non-Javadoc)
* A safe accessor for the tool map
*
*/
private Map getToolMap() {
if (toolMap == null) {
toolMap = new HashMap();
@ -387,11 +435,33 @@ public class Target extends BuildObject implements ITarget {
return toolMap;
}
/* (non-Javadoc)
* Returns the reference for a given tool or <code>null</code> if one is not
* found.
*
* @param tool
* @return ToolReference
*/
private ToolReference getToolReference(ITool tool) {
// See if the receiver has a reference to the tool
ToolReference ref = null;
if (tool == null) return ref;
Iterator iter = getLocalToolReferences().listIterator();
while (iter.hasNext()) {
ToolReference temp = (ToolReference)iter.next();
if (temp.references(tool)) {
ref = temp;
break;
}
}
return ref;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.managedbuilder.core.ITarget#getTools()
*/
public ITool[] getTools() {
ITool[] toolArray = new ITool[getNumTools()];
ITool[] toolArray = new ITool[getToolCount()];
addToolsToArray(toolArray, 0);
return toolArray;
}
@ -413,12 +483,17 @@ public class Target extends BuildObject implements ITarget {
ITool result = null;
// See if receiver has it in list
result = (ITool) getToolMap().get(id);
result = (ITool) getToolMap().get(id);
// If not, check if parent has it
if (result == null && parent != null) {
result = ((Target)parent).getTool(id);
}
// If not defined in parents, check if defined at all
if (result == null) {
result = ManagedBuildManager.getTool(id);
}
return result;
}
@ -454,7 +529,21 @@ public class Target extends BuildObject implements ITarget {
*/
public String getCleanCommand() {
// Return the command used to remove files
return cleanCommand == null ? EMPTY_STRING : cleanCommand;
if (cleanCommand == null) {
if (parent != null) {
return parent.getCleanCommand();
} else {
// User forgot to specify it. Guess based on OS.
if (BootLoader.getOS().equals("OS_WIN32")) {
return new String("del");
} else {
return new String("rm");
}
}
} else {
// This was spec'd in the manifest
return cleanCommand;
}
}
/* (non-Javadoc)
@ -559,6 +648,15 @@ public class Target extends BuildObject implements ITarget {
return new Configuration(this, parent, id);
}
/**
* Adds a tool reference to the receiver.
*
* @param toolRef
*/
public void addToolReference(ToolReference toolRef) {
getLocalToolReferences().add(toolRef);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.managedbuilder.core.ITarget#setArtifactExtension(java.lang.String)
*/
@ -595,6 +693,13 @@ public class Target extends BuildObject implements ITarget {
}
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
public String toString() {
return new String("Target: ") + getName();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.managedbuilder.core.ITarget#updateOwner(org.eclipse.core.resources.IResource)
*/

View file

@ -21,8 +21,8 @@ import org.eclipse.cdt.managedbuilder.core.BuildException;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IOption;
import org.eclipse.cdt.managedbuilder.core.IOptionCategory;
import org.eclipse.cdt.managedbuilder.core.ITarget;
import org.eclipse.cdt.managedbuilder.core.ITool;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.core.runtime.IConfigurationElement;
/**
@ -47,96 +47,27 @@ public class Tool extends BuildObject implements ITool, IOptionCategory {
private String outputExtension;
private String outputFlag;
private String outputPrefix;
private ITarget target;
public Tool(Target target) {
this.target = target;
public Tool(IConfigurationElement element) {
loadFromManifest(element);
// hook me up
ManagedBuildManager.addExtensionTool(this);
}
/**
* Constructor to create a new tool in the build model based on the information
* Constructor to create a new tool for a target based on the information
* defined in the plugin.xml manifest.
*
* @param target The target the receiver will belong to.
* @param element The element containing the information.
*/
public Tool(Target target, IConfigurationElement element) {
this(target);
// id
setId(element.getAttribute(ITool.ID));
loadFromManifest(element);
// hook me up
target.addTool(this);
// name
setName(element.getAttribute(ITool.NAME));
// Get the nature filter
String nature = element.getAttribute(NATURE);
if (nature == null || "both".equals(nature)) {
natureFilter = FILTER_BOTH;
} else if ("cnature".equals(nature)) {
natureFilter = FILTER_C;
} else if ("ccnature".equals(nature)) {
natureFilter = FILTER_CC;
} else {
natureFilter = FILTER_BOTH;
}
// Get the supported input file extension
String inputs = element.getAttribute(ITool.SOURCES) == null ?
new String() :
element.getAttribute(ITool.SOURCES);
StringTokenizer tokenizer = new StringTokenizer(inputs, DEFAULT_SEPARATOR);
while (tokenizer.hasMoreElements()) {
getInputExtensions().add(tokenizer.nextElement());
}
// Get the interface (header file) extensions
String headers = element.getAttribute(INTERFACE_EXTS);
if (headers == null) {
headers = new String();
}
tokenizer = new StringTokenizer(headers, DEFAULT_SEPARATOR);
while (tokenizer.hasMoreElements()) {
getInterfaceExtensions().add(tokenizer.nextElement());
}
// Get the output extension
outputExtension = element.getAttribute(ITool.OUTPUTS) == null ?
new String() :
element.getAttribute(ITool.OUTPUTS);
// Get the tool invocation
command = element.getAttribute(ITool.COMMAND) == null ?
new String() :
element.getAttribute(ITool.COMMAND);
// Get the flag to control output
outputFlag = element.getAttribute(ITool.OUTPUT_FLAG) == null ?
new String() :
element.getAttribute(ITool.OUTPUT_FLAG);
// Get the output prefix
outputPrefix = element.getAttribute(ITool.OUTPUT_PREFIX) == null ?
new String() :
element.getAttribute(ITool.OUTPUT_PREFIX);
// set up the category map
categoryMap = new HashMap();
addOptionCategory(this);
// Check for options
IConfigurationElement[] toolElements = element.getChildren();
for (int l = 0; l < toolElements.length; ++l) {
IConfigurationElement toolElement = toolElements[l];
if (toolElement.getName().equals(ITool.OPTION)) {
new Option(this, toolElement);
} else if (toolElement.getName().equals(ITool.OPTION_CAT)) {
new OptionCategory(this, toolElement);
}
}
}
public IOptionCategory getOptionCategory(String id) {
@ -247,10 +178,10 @@ public class Tool extends BuildObject implements ITool, IOptionCategory {
return null;
}
public ITarget getTarget() {
/* public ITarget getTarget() {
return target;
}
*/
/* (non-Javadoc)
* @see org.eclipse.cdt.core.build.managed.IOptionCategory#getTool()
*/
@ -401,6 +332,80 @@ public class Tool extends BuildObject implements ITool, IOptionCategory {
return getInterfaceExtensions().contains(ext);
}
protected void loadFromManifest(IConfigurationElement element) {
// id
setId(element.getAttribute(ITool.ID));
// name
setName(element.getAttribute(ITool.NAME));
// Get the nature filter
String nature = element.getAttribute(NATURE);
if (nature == null || "both".equals(nature)) {
natureFilter = FILTER_BOTH;
} else if ("cnature".equals(nature)) {
natureFilter = FILTER_C;
} else if ("ccnature".equals(nature)) {
natureFilter = FILTER_CC;
} else {
natureFilter = FILTER_BOTH;
}
// Get the supported input file extension
String inputs = element.getAttribute(ITool.SOURCES) == null ?
new String() :
element.getAttribute(ITool.SOURCES);
StringTokenizer tokenizer = new StringTokenizer(inputs, DEFAULT_SEPARATOR);
while (tokenizer.hasMoreElements()) {
getInputExtensions().add(tokenizer.nextElement());
}
// Get the interface (header file) extensions
String headers = element.getAttribute(INTERFACE_EXTS);
if (headers == null) {
headers = new String();
}
tokenizer = new StringTokenizer(headers, DEFAULT_SEPARATOR);
while (tokenizer.hasMoreElements()) {
getInterfaceExtensions().add(tokenizer.nextElement());
}
// Get the output extension
outputExtension = element.getAttribute(ITool.OUTPUTS) == null ?
new String() :
element.getAttribute(ITool.OUTPUTS);
// Get the tool invocation
command = element.getAttribute(ITool.COMMAND) == null ?
new String() :
element.getAttribute(ITool.COMMAND);
// Get the flag to control output
outputFlag = element.getAttribute(ITool.OUTPUT_FLAG) == null ?
new String() :
element.getAttribute(ITool.OUTPUT_FLAG);
// Get the output prefix
outputPrefix = element.getAttribute(ITool.OUTPUT_PREFIX) == null ?
new String() :
element.getAttribute(ITool.OUTPUT_PREFIX);
// set up the category map
categoryMap = new HashMap();
addOptionCategory(this);
// Check for options
IConfigurationElement[] toolElements = element.getChildren();
for (int l = 0; l < toolElements.length; ++l) {
IConfigurationElement toolElement = toolElements[l];
if (toolElement.getName().equals(ITool.OPTION)) {
new Option(this, toolElement);
} else if (toolElement.getName().equals(ITool.OPTION_CAT)) {
new OptionCategory(this, toolElement);
}
}
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.build.managed.ITool#producesFileType(java.lang.String)
*/

View file

@ -16,10 +16,10 @@ import java.util.List;
import java.util.Map;
import org.eclipse.cdt.managedbuilder.core.BuildException;
import org.eclipse.cdt.managedbuilder.core.IBuildObject;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IOption;
import org.eclipse.cdt.managedbuilder.core.IOptionCategory;
import org.eclipse.cdt.managedbuilder.core.ITarget;
import org.eclipse.cdt.managedbuilder.core.ITool;
import org.eclipse.core.runtime.IConfigurationElement;
import org.w3c.dom.Document;
@ -31,25 +31,29 @@ import org.w3c.dom.NodeList;
*
*/
public class ToolReference implements ITool {
private ITool parent;
private IConfiguration owner;
private String command;
private List optionReferences;
private Map optionRefMap;
private IBuildObject owner;
private ITool parent;
/**
* Created a tool reference on the fly based on an existing tool.
*
* @param owner The <code>Configuration</code> the receiver will be added to.
* @param owner The <code>BuildObject</code> the receiver will be added to.
* @param parent The <code>ITool</code>tool the reference will be based on.
*/
public ToolReference(Configuration owner, ITool parent) {
public ToolReference(BuildObject owner, ITool parent) {
this.owner = owner;
this.parent = parent;
owner.addToolReference(this);
if (owner instanceof Configuration) {
((Configuration)owner).addToolReference(this);
} else if (owner instanceof Target) {
((Target)owner).addToolReference(this);
}
}
/**
* Adds the option reference specified in the argument to the receiver.
*
@ -62,15 +66,19 @@ public class ToolReference implements ITool {
/**
* Created tool reference from an extension defined in a plugin manifest.
*
* @param owner The <code>Configuration</code> the receiver will be added to.
* @param owner The <code>BuildObject</code> the receiver will be added to.
* @param element The element containing build information for the reference.
*/
public ToolReference(Configuration owner, IConfigurationElement element) {
public ToolReference(BuildObject owner, IConfigurationElement element) {
this.owner = owner;
parent = ((Target)owner.getTarget()).getTool(element.getAttribute(ID));
owner.addToolReference(this);
if (owner instanceof Configuration) {
Target target = (Target) ((Configuration)owner).getTarget();
parent = target.getTool(element.getAttribute(ID));
((Configuration)owner).addToolReference(this);
} else if (owner instanceof Target) {
parent = ((Target)owner).getTool(element.getAttribute(ID));
((Target)owner).addToolReference(this);
}
IConfigurationElement[] toolElements = element.getChildren();
for (int m = 0; m < toolElements.length; ++m) {
@ -88,13 +96,17 @@ public class ToolReference implements ITool {
* @param element The element defined in the project file containing build information
* for the receiver.
*/
public ToolReference(Configuration owner, Element element) {
public ToolReference(BuildObject owner, Element element) {
this.owner = owner;
Target parentTarget = (Target)owner.getTarget();
parent = ((Target)parentTarget.getParent()).getTool(element.getAttribute("id"));
owner.addToolReference(this);
if (owner instanceof Configuration) {
Target parentTarget = (Target) ((Configuration)owner).getTarget();
parent = ((Target)parentTarget.getParent()).getTool(element.getAttribute(ID));
((Configuration)owner).addToolReference(this);
} else if (owner instanceof Target) {
parent = ((Target)((Target)owner).getParent()).getTool(element.getAttribute(ID));
((Target)owner).addToolReference(this);
}
NodeList configElements = element.getChildNodes();
for (int i = 0; i < configElements.getLength(); ++i) {
@ -105,28 +117,14 @@ public class ToolReference implements ITool {
}
}
/**
* Persist receiver to project file.
*
* @param doc The persistent store for the reference information.
* @param element The root element in the store the receiver must use
* to persist settings.
*/
public void serialize(Document doc, Element element) {
element.setAttribute(ITool.ID, parent.getId());
Iterator iter = getLocalOptionRefs().listIterator();
while (iter.hasNext()) {
OptionReference optionRef = (OptionReference) iter.next();
Element optionRefElement = doc.createElement(ITool.OPTION_REF);
element.appendChild(optionRefElement);
optionRef.serialize(doc, optionRefElement);
public boolean ownedByConfiguration(IConfiguration config) {
if (owner instanceof Configuration) {
return ((IConfiguration)owner).equals(config);
} else {
return false;
}
}
public IConfiguration getConfiguration() {
return owner;
}
public ITool getTool() {
return parent;
}
@ -247,10 +245,14 @@ public class ToolReference implements ITool {
/* (non-Javadoc)
* @see org.eclipse.cdt.core.build.managed.ITool#getTarget()
*/
public ITarget getTarget() {
return owner.getTarget();
/* public ITarget getTarget() {
if (owner instanceof IConfiguration) {
return ((IConfiguration)owner).getTarget();
} else {
return (ITarget)owner;
}
}
*/
/* (non-Javadoc)
* @see org.eclipse.cdt.core.build.managed.ITool#getTopOptionCategory()
*/
@ -395,4 +397,38 @@ public class ToolReference implements ITool {
return parent.getOutputExtension(inputExtension);
}
/**
* Persist receiver to project file.
*
* @param doc The persistent store for the reference information.
* @param element The root element in the store the receiver must use
* to persist settings.
*/
public void serialize(Document doc, Element element) {
element.setAttribute(ITool.ID, parent.getId());
Iterator iter = getLocalOptionRefs().listIterator();
while (iter.hasNext()) {
OptionReference optionRef = (OptionReference) iter.next();
Element optionRefElement = doc.createElement(ITool.OPTION_REF);
element.appendChild(optionRefElement);
optionRef.serialize(doc, optionRefElement);
}
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
public String toString() {
String answer = new String();
if (parent != null) {
answer += "Reference to tool: " + parent.getName(); //$NON-NLS-1$
}
if (answer.length() > 0) {
return answer;
} else {
return super.toString();
}
}
}