1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-04 14:55:41 +02:00

Commit for Jeremiah Lott.

Allows the managed build system to resolve "forward references" within its extensions. In practice this is necessary to allow references between extensions in different plugins.	
Partial fix for bugzilla 54202:
No longer use the cdtbuild file for persisting the default target and configuration settings for a project. This is assumed to be an individual workspace level setting so the choices are persisted in the project's persistent settings store.
This commit is contained in:
Sean Evoy 2004-03-12 19:11:53 +00:00
parent ea9c355889
commit fbf82be3cd
10 changed files with 495 additions and 145 deletions

View file

@ -1,3 +1,15 @@
2004-03-12 Sean Evoy
Commit for Jeremiah Lott.
Allows the managed build system to resolve "forward references" within its
extensions. In practice this is necessary to allow references between
extensions in different plugins.
Partial fix for bugzilla 54202:
No longer use the cdtbuild file for persisting the default target and
configuration settings for a project. This is assumed to be an individual
workspace level setting so the choices are persisted in the project's
persistent settings store.
2004-03-09 Sean Evoy 2004-03-09 Sean Evoy
Fix for bugzilla 45311: "CVS tries to check in contents of build output" Fix for bugzilla 45311: "CVS tries to check in contents of build output"

View file

@ -16,6 +16,7 @@ import java.io.InputStream;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.ListIterator; import java.util.ListIterator;
import java.util.Map; import java.util.Map;
@ -69,6 +70,7 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI
private static Map extensionTargetMap; private static Map extensionTargetMap;
private static List extensionTargets; private static List extensionTargets;
private static Map extensionToolMap; private static Map extensionToolMap;
private static Map configElementMap;
// Listeners interested in build model changes // Listeners interested in build model changes
private static Map buildModelListeners; private static Map buildModelListeners;
@ -338,32 +340,12 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI
// Find out the parent of the configuration // Find out the parent of the configuration
IConfiguration parentConfig = configuration.getParent(); IConfiguration parentConfig = configuration.getParent();
// Find the parent target the configuration
ITarget parentTarget = parentConfig.getTarget();
// Get the extension point information // Get the config element for the parent from the map
IExtensionPoint extensionPoint = ManagedBuilderCorePlugin.getDefault().getDescriptor().getExtensionPoint(EXTENSION_POINT_ID); IConfigurationElement configElement = getConfigElement(parentConfig);
IExtension[] extensions = extensionPoint.getExtensions();
for (int i = 0; i < extensions.length; ++i) { // reset the configuration
IExtension extension = extensions[i]; ((Configuration)configuration).reset(configElement);
IConfigurationElement[] elements = extension.getConfigurationElements();
for (int j = 0; j < elements.length; ++j) {
IConfigurationElement element = elements[j];
if (element.getName().equals(ITarget.TARGET_ELEMENT_NAME) &&
element.getAttribute(ITarget.ID).equals(parentTarget.getId())) {
// We have the parent target so get the definition for the parent config
IConfigurationElement[] targetElements = element.getChildren();
for (int k = 0; k < targetElements.length; ++k) {
IConfigurationElement targetElement = targetElements[k];
if (targetElement.getName().equals(IConfiguration.CONFIGURATION_ELEMENT_NAME) &&
targetElement.getAttribute(IConfiguration.ID).equals(parentConfig.getId())) {
// We now have the plugin element the target was originally based on
((Configuration)configuration).reset(targetElement);
}
}
}
}
}
} }
@ -463,23 +445,44 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI
*/ // We can read the manifest */ // We can read the manifest
IExtensionPoint extensionPoint = descriptor.getExtensionPoint(EXTENSION_POINT_ID); IExtensionPoint extensionPoint = descriptor.getExtensionPoint(EXTENSION_POINT_ID);
IExtension[] extensions = extensionPoint.getExtensions(); IExtension[] extensions = extensionPoint.getExtensions();
// First call the constructors
for (int i = 0; i < extensions.length; ++i) { for (int i = 0; i < extensions.length; ++i) {
IExtension extension = extensions[i]; IExtension extension = extensions[i];
IConfigurationElement[] elements = extension.getConfigurationElements(); IConfigurationElement[] elements = extension.getConfigurationElements();
// Load the tools first
for (int toolIndex = 0; toolIndex < elements.length; ++toolIndex) { for (int toolIndex = 0; toolIndex < elements.length; ++toolIndex) {
IConfigurationElement element = elements[toolIndex]; try {
// Load the targets IConfigurationElement element = elements[toolIndex];
if (element.getName().equals(ITool.TOOL_ELEMENT_NAME)) { // Load the targets
new Tool(element); if (element.getName().equals(ITool.TOOL_ELEMENT_NAME)) {
new Tool(element);
} else if (element.getName().equals(ITarget.TARGET_ELEMENT_NAME)) {
new Target(element);
}
} catch (Exception ex) {
// TODO: log
ex.printStackTrace();
} }
} }
for (int targetIndex = 0; targetIndex < elements.length; ++targetIndex) { }
IConfigurationElement element = elements[targetIndex]; // Then call resolve.
// Load the targets Iterator toolIter = getExtensionToolMap().values().iterator();
if (element.getName().equals(ITarget.TARGET_ELEMENT_NAME)) { while (toolIter.hasNext()) {
new Target(element); try {
} Tool tool = (Tool)toolIter.next();
tool.resolveReferences();
} catch (Exception ex) {
// TODO: log
ex.printStackTrace();
}
}
Iterator targetIter = getExtensionTargetMap().values().iterator();
while (targetIter.hasNext()) {
try {
Target target = (Target)targetIter.next();
target.resolveReferences();
} catch (Exception ex) {
// TODO: log
ex.printStackTrace();
} }
} }
// Let's never do that again // Let's never do that again
@ -643,4 +646,27 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI
} }
} }
private static Map getConfigElementMap() {
if (configElementMap == null) {
configElementMap = new HashMap();
}
return configElementMap;
}
/**
* This method public for implementation reasons. Not intended for use
* by clients.
*/
public static void putConfigElement(IBuildObject buildObj, IConfigurationElement configElement) {
getConfigElementMap().put(buildObj, configElement);
}
/**
* This method public for implementation reasons. Not intended for use
* by clients.
*/
public static IConfigurationElement getConfigElement(IBuildObject buildObj) {
return (IConfigurationElement)getConfigElementMap().get(buildObj);
}
} }

View file

@ -22,6 +22,7 @@ import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IOption; import org.eclipse.cdt.managedbuilder.core.IOption;
import org.eclipse.cdt.managedbuilder.core.ITarget; import org.eclipse.cdt.managedbuilder.core.ITarget;
import org.eclipse.cdt.managedbuilder.core.ITool; import org.eclipse.cdt.managedbuilder.core.ITool;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
@ -36,6 +37,7 @@ public class Configuration extends BuildObject implements IConfiguration {
private ITarget target; private ITarget target;
private IConfiguration parent; private IConfiguration parent;
private List toolReferences; private List toolReferences;
private boolean resolved = true;
/** /**
* Build a configuration from the project manifest file. * Build a configuration from the project manifest file.
@ -152,6 +154,10 @@ public class Configuration extends BuildObject implements IConfiguration {
public Configuration(Target target, IConfigurationElement element) { public Configuration(Target target, IConfigurationElement element) {
this.target = target; this.target = target;
// setup for resolving
ManagedBuildManager.putConfigElement(this, element);
resolved = false;
// id // id
setId(element.getAttribute(IConfiguration.ID)); setId(element.getAttribute(IConfiguration.ID));
@ -183,6 +189,18 @@ public class Configuration extends BuildObject implements IConfiguration {
target.addConfiguration(this); target.addConfiguration(this);
} }
public void resolveReferences() {
if (!resolved) {
resolved = true;
// IConfigurationElement element = ManagedBuildManager.getConfigElement(this);
Iterator refIter = getLocalToolReferences().iterator();
while (refIter.hasNext()) {
ToolReference ref = (ToolReference)refIter.next();
ref.resolveReferences();
}
}
}
/** /**
* Adds a tool reference to the receiver. * Adds a tool reference to the receiver.
* *
@ -371,7 +389,8 @@ public class Configuration extends BuildObject implements IConfiguration {
for (int l = 0; l < configElements.length; ++l) { for (int l = 0; l < configElements.length; ++l) {
IConfigurationElement configElement = configElements[l]; IConfigurationElement configElement = configElements[l];
if (configElement.getName().equals(IConfiguration.TOOLREF_ELEMENT_NAME)) { if (configElement.getName().equals(IConfiguration.TOOLREF_ELEMENT_NAME)) {
new ToolReference(this, configElement); ToolReference ref = new ToolReference(this, configElement);
ref.resolveReferences();
} }
} }
} }

View file

@ -16,7 +16,6 @@ import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.ListIterator;
import java.util.Map; import java.util.Map;
import org.eclipse.cdt.core.CCProjectNature; import org.eclipse.cdt.core.CCProjectNature;
@ -28,11 +27,13 @@ import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
import org.eclipse.cdt.managedbuilder.core.IOption; import org.eclipse.cdt.managedbuilder.core.IOption;
import org.eclipse.cdt.managedbuilder.core.ITarget; import org.eclipse.cdt.managedbuilder.core.ITarget;
import org.eclipse.cdt.managedbuilder.core.ITool; import org.eclipse.cdt.managedbuilder.core.ITool;
import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.QualifiedName;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.w3c.dom.Node; import org.w3c.dom.Node;
@ -40,12 +41,16 @@ import org.w3c.dom.Node;
public class ManagedBuildInfo implements IManagedBuildInfo, IScannerInfo { public class ManagedBuildInfo implements IManagedBuildInfo, IScannerInfo {
// Local variables // Local variables
public static final String MAJOR_SEPERATOR = ";"; //$NON-NLS-1$
public static final String MINOR_SEPERATOR = "::"; //$NON-NLS-1$
private static final QualifiedName defaultConfigProperty = new QualifiedName(ManagedBuilderCorePlugin.getUniqueIdentifier(), "defaultConfig"); //$NON-NLS-1$
private static final QualifiedName defaultTargetProperty = new QualifiedName(ManagedBuilderCorePlugin.getUniqueIdentifier(), "defaultTarget"); //$NON-NLS-1$
private Map defaultConfigMap;
private ITarget defaultTarget;
private boolean isDirty; private boolean isDirty;
private IResource owner; private IResource owner;
private Map targetMap; private Map targetMap;
private List targets; private List targetList;
private Map defaultConfigurations;
private ITarget defaultTarget;
/** /**
* Create a new managed build information for the IResource specified in the argument * Create a new managed build information for the IResource specified in the argument
@ -53,9 +58,7 @@ public class ManagedBuildInfo implements IManagedBuildInfo, IScannerInfo {
* @param owner * @param owner
*/ */
public ManagedBuildInfo(IResource owner) { public ManagedBuildInfo(IResource owner) {
targetMap = new HashMap(); targetList = new ArrayList();
targets = new ArrayList();
defaultConfigurations = new HashMap();
this.owner = owner; this.owner = owner;
} }
@ -67,47 +70,81 @@ public class ManagedBuildInfo implements IManagedBuildInfo, IScannerInfo {
* @param element * @param element
*/ */
public ManagedBuildInfo(IResource owner, Element element) { public ManagedBuildInfo(IResource owner, Element element) {
// Store the IProject the info is for
this(owner); this(owner);
Node child = element.getFirstChild();
// The id of the default configuration // Read in the top-level info objects
String defaultTargetId = null; Node child = element.getFirstChild();
List configIds = new ArrayList();
while (child != null) { while (child != null) {
if (child.getNodeName().equals(ITarget.TARGET_ELEMENT_NAME)) { if (child.getNodeName().equals(ITarget.TARGET_ELEMENT_NAME)) {
new Target(this, (Element)child); new Target(this, (Element)child);
} else if (child.getNodeName().equals(DEFAULT_CONFIGURATION)) {
// We may not have read the config in yet, so just cache it
configIds.add(((Element)child).getAttribute(IConfiguration.ID));
} else if (child.getNodeName().equals(DEFAULT_TARGET)) {
defaultTargetId = ((Element)child).getAttribute(ITarget.ID);
} }
child = child.getNextSibling(); child = child.getNextSibling();
} }
// All the available targets have been read in
defaultTarget = (ITarget) targetMap.get(defaultTargetId); // The id of the default configuration from the persistent store
// Now we have a miserable O(N^2) operation (oh well, the data sets are small) IProject project = (IProject)getOwner();
String defaultTargetId = null;
try {
defaultTargetId = project.getPersistentProperty(defaultTargetProperty);
} catch (CoreException e) {
// We have all the build elements so we can stop if this occurs
return;
}
// All targets have been read in so set the default from the persisted ID
if (defaultTargetId != null) {
defaultTarget = (ITarget) getTargetMap().get(defaultTargetId);
}
// Get the string of all default config IDs from the store
String defaultIds = null;
try {
defaultIds = project.getPersistentProperty(defaultConfigProperty);
} catch (CoreException e1) {
// Again, hitting this error just means the default config is not set
return;
}
if (defaultIds != null) {
String[] majorTokens = defaultIds.split(MAJOR_SEPERATOR);
for (int index = majorTokens.length - 1; index >= 0; --index) {
// Now split each token into the target and config id component
String idToken = majorTokens[index];
if (idToken != null) {
String[] minorTokens = idToken.split(MINOR_SEPERATOR);
// The first token is the target ID
ITarget target = getTarget(minorTokens[0]);
// The second is the configuration ID
IConfiguration config = target.getConfiguration(minorTokens[1]);
if (config != null) {
getDefaultConfigMap().put(target.getId(), config);
}
}
}
}
/* // Now we have a miserable O(N^2) operation (oh well, the data sets are small)
ListIterator stringIter = configIds.listIterator(); ListIterator stringIter = configIds.listIterator();
while (stringIter.hasNext()){ while (stringIter.hasNext()){
String confId = (String) stringIter.next(); String confId = (String) stringIter.next();
ListIterator targIter = targets.listIterator(); ListIterator targIter = targetList.listIterator();
while (targIter.hasNext()) { while (targIter.hasNext()) {
Target targ = (Target) targIter.next(); Target targ = (Target) targIter.next();
IConfiguration conf = targ.getConfiguration(confId); IConfiguration conf = targ.getConfiguration(confId);
if (conf != null) { if (conf != null) {
defaultConfigurations.put(targ.getId(), conf); defaultConfigMap.put(targ.getId(), conf);
break; break;
} }
} }
} }
} */ }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.build.managed.IManagedBuildInfo#addTarget(org.eclipse.cdt.core.build.managed.ITarget) * @see org.eclipse.cdt.core.build.managed.IManagedBuildInfo#addTarget(org.eclipse.cdt.core.build.managed.ITarget)
*/ */
public void addTarget(ITarget target) { public void addTarget(ITarget target) {
targetMap.put(target.getId(), target); getTargetMap().put(target.getId(), target);
targets.add(target); targetList.add(target);
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -206,12 +243,23 @@ public class ManagedBuildInfo implements IManagedBuildInfo, IScannerInfo {
return (String[])configNames.toArray(new String[configNames.size()]); return (String[])configNames.toArray(new String[configNames.size()]);
} }
/* (non-Javadoc)
*
* @return Returns the map of ITarget ids to IConfigurations.
*/
private Map getDefaultConfigMap() {
if (defaultConfigMap == null) {
defaultConfigMap = new HashMap();
}
return defaultConfigMap;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.build.managed.IManagedBuildInfo#getDefaultConfiguration() * @see org.eclipse.cdt.core.build.managed.IManagedBuildInfo#getDefaultConfiguration()
*/ */
public IConfiguration getDefaultConfiguration(ITarget target) { public IConfiguration getDefaultConfiguration(ITarget target) {
// Get the default config associated with the defalt target // Get the default config associated with the defalt target
IConfiguration config = (IConfiguration) defaultConfigurations.get(target.getId()); IConfiguration config = (IConfiguration) getDefaultConfigMap().get(target.getId());
// If null, look up the first configuration associated with the target // If null, look up the first configuration associated with the target
if (config == null) { if (config == null) {
@ -228,7 +276,7 @@ public class ManagedBuildInfo implements IManagedBuildInfo, IScannerInfo {
*/ */
public ITarget getDefaultTarget() { public ITarget getDefaultTarget() {
if (defaultTarget == null) { if (defaultTarget == null) {
defaultTarget = (ITarget) targets.get(0); defaultTarget = (ITarget) targetList.get(0);
} }
return defaultTarget; return defaultTarget;
} }
@ -631,6 +679,9 @@ public class ManagedBuildInfo implements IManagedBuildInfo, IScannerInfo {
return flags; return flags;
} }
/**
* @return
*/
public IResource getOwner() { public IResource getOwner() {
return owner; return owner;
} }
@ -639,14 +690,26 @@ public class ManagedBuildInfo implements IManagedBuildInfo, IScannerInfo {
* @see org.eclipse.cdt.core.build.managed.IManagedBuildInfo#getTarget(org.eclipse.cdt.core.build.managed.IConfiguration) * @see org.eclipse.cdt.core.build.managed.IManagedBuildInfo#getTarget(org.eclipse.cdt.core.build.managed.IConfiguration)
*/ */
public ITarget getTarget(String id) { public ITarget getTarget(String id) {
return (ITarget) targetMap.get(id); return (ITarget) getTargetMap().get(id);
}
/* (non-Javadoc)
* Safe accessor.
*
* @return Returns the map of IDs to ITargets.
*/
private Map getTargetMap() {
if (targetMap == null) {
targetMap = new HashMap();
}
return targetMap;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.build.managed.IManagedBuildInfo#getTargets(org.eclipse.cdt.core.build.managed.IConfiguration) * @see org.eclipse.cdt.core.build.managed.IManagedBuildInfo#getTargets(org.eclipse.cdt.core.build.managed.IConfiguration)
*/ */
public List getTargets() { public List getTargets() {
return targets; return targetList;
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -822,8 +885,29 @@ public class ManagedBuildInfo implements IManagedBuildInfo, IScannerInfo {
* @param element * @param element
*/ */
public void serialize(Document doc, Element element) { public void serialize(Document doc, Element element) {
// Create a buffer of the default configuration IDs
StringBuffer defaultConfigs = new StringBuffer();
// Write out each target and their default config // Write out each target and their default config
for (int i = 0; i < targets.size(); ++i) { Iterator iter = targetList.listIterator();
while (iter.hasNext()) {
// Get the target
Target targ = (Target)iter.next();
// Create an XML element to hold the target settings
Element targetElement = doc.createElement(ITarget.TARGET_ELEMENT_NAME);
element.appendChild(targetElement);
targ.serialize(doc, targetElement);
// Persist the default target configuration pair as <targ_ID>::<conf_ID>
IConfiguration config = getDefaultConfiguration((ITarget)targ);
if (config != null) {
defaultConfigs.append(targ.getId());
defaultConfigs.append(MINOR_SEPERATOR);
defaultConfigs.append(config.getId());
defaultConfigs.append(MAJOR_SEPERATOR);
}
}
/* for (int i = 0; i < targets.size(); ++i) {
Element targetElement = doc.createElement(ITarget.TARGET_ELEMENT_NAME); Element targetElement = doc.createElement(ITarget.TARGET_ELEMENT_NAME);
element.appendChild(targetElement); element.appendChild(targetElement);
((Target)targets.get(i)).serialize(doc, targetElement); ((Target)targets.get(i)).serialize(doc, targetElement);
@ -834,12 +918,25 @@ public class ManagedBuildInfo implements IManagedBuildInfo, IScannerInfo {
configEl.setAttribute(IConfiguration.ID, config.getId()); configEl.setAttribute(IConfiguration.ID, config.getId());
} }
} }
// Persist the default target */ // Persist the default target as a project setting
if (getDefaultTarget() != null){ IProject project = (IProject) getOwner();
Element targEl = doc.createElement(DEFAULT_TARGET); ITarget defTarget = getDefaultTarget();
element.appendChild(targEl); if (defTarget != null){
targEl.setAttribute(ITarget.ID, getDefaultTarget().getId()); try {
project.setPersistentProperty(defaultTargetProperty, defTarget.getId());
} catch (CoreException e) {
// There is no point in storing the default configurations
return;
}
} }
try {
// Persist the default configurations
project.setPersistentProperty(defaultConfigProperty, defaultConfigs.toString().trim());
} catch (CoreException e) {
// Too bad
}
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -850,7 +947,7 @@ public class ManagedBuildInfo implements IManagedBuildInfo, IScannerInfo {
ITarget target = configuration.getTarget(); ITarget target = configuration.getTarget();
// Make sure it is the default // Make sure it is the default
setDefaultTarget(target); setDefaultTarget(target);
defaultConfigurations.put(target.getId(), configuration); getDefaultConfigMap().put(target.getId(), configuration);
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -871,6 +968,9 @@ public class ManagedBuildInfo implements IManagedBuildInfo, IScannerInfo {
} }
/** /**
* Sets the owner of the receiver to be the <code>IResource</code> specified
* in the argument.
*
* @param resource * @param resource
*/ */
public void updateOwner(IResource resource) { public void updateOwner(IResource resource) {
@ -879,7 +979,7 @@ public class ManagedBuildInfo implements IManagedBuildInfo, IScannerInfo {
if (!owner.equals(resource)) { if (!owner.equals(resource)) {
owner = resource; owner = resource;
// Do the same for the targets // Do the same for the targets
Iterator iter = targets.listIterator(); Iterator iter = targetList.listIterator();
while(iter.hasNext()) { while(iter.hasNext()) {
ITarget target = (ITarget) iter.next(); ITarget target = (ITarget) iter.next();
target.updateOwner(resource); target.updateOwner(resource);

View file

@ -20,6 +20,7 @@ import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IOption; import org.eclipse.cdt.managedbuilder.core.IOption;
import org.eclipse.cdt.managedbuilder.core.IOptionCategory; import org.eclipse.cdt.managedbuilder.core.IOptionCategory;
import org.eclipse.cdt.managedbuilder.core.ITool; import org.eclipse.cdt.managedbuilder.core.ITool;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin; import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin;
import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IConfigurationElement;
@ -37,7 +38,7 @@ public class Option extends BuildObject implements IOption {
private ITool tool; private ITool tool;
private Object value; private Object value;
private int valueType; private int valueType;
private boolean resolved = true;
public Option(ITool tool) { public Option(ITool tool) {
this.tool = tool; this.tool = tool;
@ -45,6 +46,9 @@ public class Option extends BuildObject implements IOption {
public Option(Tool tool, IConfigurationElement element) { public Option(Tool tool, IConfigurationElement element) {
this(tool); this(tool);
// setup for resolving
ManagedBuildManager.putConfigElement(this, element);
resolved = false;
// Get the unique id of the option // Get the unique id of the option
setId(element.getAttribute(ID)); setId(element.getAttribute(ID));
@ -55,11 +59,6 @@ public class Option extends BuildObject implements IOption {
// Get the option Name (this is what the user will see in the UI) // Get the option Name (this is what the user will see in the UI)
setName(element.getAttribute(NAME)); setName(element.getAttribute(NAME));
// Options can be grouped into categories
String categoryId = element.getAttribute(CATEGORY);
if (categoryId != null)
setCategory(tool.getOptionCategory(categoryId));
// Get the command defined for the option // Get the command defined for the option
command = element.getAttribute(COMMAND); command = element.getAttribute(COMMAND);
@ -135,6 +134,17 @@ public class Option extends BuildObject implements IOption {
} }
} }
public void resolveReferences() {
if (!resolved) {
resolved = true;
IConfigurationElement element = ManagedBuildManager.getConfigElement(this);
// Options can be grouped into categories
String categoryId = element.getAttribute(CATEGORY);
if (categoryId != null)
setCategory(((Tool)tool).getOptionCategory(categoryId));
}
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.build.managed.IOption#getApplicableValues() * @see org.eclipse.cdt.core.build.managed.IOption#getApplicableValues()
*/ */

View file

@ -18,6 +18,7 @@ import org.eclipse.cdt.managedbuilder.core.IOption;
import org.eclipse.cdt.managedbuilder.core.IOptionCategory; import org.eclipse.cdt.managedbuilder.core.IOptionCategory;
import org.eclipse.cdt.managedbuilder.core.ITool; import org.eclipse.cdt.managedbuilder.core.ITool;
import org.eclipse.cdt.managedbuilder.core.IToolReference; import org.eclipse.cdt.managedbuilder.core.IToolReference;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IConfigurationElement;
/** /**
@ -27,6 +28,8 @@ public class OptionCategory extends BuildObject implements IOptionCategory {
private IOptionCategory owner; private IOptionCategory owner;
private List children; private List children;
private Tool tool;
private boolean resolved = true;
private static final IOptionCategory[] emtpyCategories = new IOptionCategory[0]; private static final IOptionCategory[] emtpyCategories = new IOptionCategory[0];
@ -35,11 +38,10 @@ public class OptionCategory extends BuildObject implements IOptionCategory {
} }
public OptionCategory(Tool tool, IConfigurationElement element) { public OptionCategory(Tool tool, IConfigurationElement element) {
String parentId = element.getAttribute(IOptionCategory.OWNER); // setup for resolving
if (parentId != null) ManagedBuildManager.putConfigElement(this, element);
owner = tool.getOptionCategory(parentId); resolved = false;
else this.tool = tool;
owner = tool;
// id // id
setId(element.getAttribute(IOptionCategory.ID)); setId(element.getAttribute(IOptionCategory.ID));
@ -47,15 +49,28 @@ public class OptionCategory extends BuildObject implements IOptionCategory {
// Name // Name
setName(element.getAttribute(IOptionCategory.NAME)); setName(element.getAttribute(IOptionCategory.NAME));
// Hook me in
if (owner instanceof Tool)
((Tool)owner).addChildCategory(this);
else
((OptionCategory)owner).addChildCategory(this);
tool.addOptionCategory(this); tool.addOptionCategory(this);
} }
public void resolveReferences() {
if (!resolved) {
resolved = true;
IConfigurationElement element = ManagedBuildManager.getConfigElement(this);
String parentId = element.getAttribute(IOptionCategory.OWNER);
if (parentId != null)
owner = tool.getOptionCategory(parentId);
else
owner = tool;
// Hook me in
if (owner instanceof Tool)
((Tool)owner).addChildCategory(this);
else
((OptionCategory)owner).addChildCategory(this);
}
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.build.managed.IOptionCategory#getChildCategories() * @see org.eclipse.cdt.core.build.managed.IOptionCategory#getChildCategories()
*/ */

View file

@ -19,6 +19,7 @@ import org.eclipse.cdt.managedbuilder.core.BuildException;
import org.eclipse.cdt.managedbuilder.core.IOption; import org.eclipse.cdt.managedbuilder.core.IOption;
import org.eclipse.cdt.managedbuilder.core.IOptionCategory; import org.eclipse.cdt.managedbuilder.core.IOptionCategory;
import org.eclipse.cdt.managedbuilder.core.ITool; import org.eclipse.cdt.managedbuilder.core.ITool;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin; import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin;
import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IConfigurationElement;
import org.w3c.dom.Document; import org.w3c.dom.Document;
@ -41,6 +42,7 @@ public class OptionReference implements IOption {
private ToolReference owner; private ToolReference owner;
// The actual value of the reference // The actual value of the reference
private Object value; private Object value;
private boolean resolved = true;
/** /**
* This constructor will be called when the receiver is created from * This constructor will be called when the receiver is created from
@ -50,49 +52,14 @@ public class OptionReference implements IOption {
* @param element * @param element
*/ */
public OptionReference(ToolReference owner, IConfigurationElement element) { public OptionReference(ToolReference owner, IConfigurationElement element) {
// setup for resolving
ManagedBuildManager.putConfigElement(this, element);
resolved = false;
this.owner = owner; this.owner = owner;
option = owner.getTool().getOption(element.getAttribute(ID));
owner.addOptionReference(this); owner.addOptionReference(this);
// value
switch (option.getValueType()) {
case BOOLEAN:
value = new Boolean(element.getAttribute(DEFAULT_VALUE));
break;
case STRING:
value = element.getAttribute(DEFAULT_VALUE);
break;
case ENUMERATED:
String temp = element.getAttribute(DEFAULT_VALUE);
if (temp == null) {
try {
temp = option.getSelectedEnum();
} catch (BuildException e) {
temp = new String();
}
}
value = temp;
break;
case STRING_LIST:
case INCLUDE_PATH:
case PREPROCESSOR_SYMBOLS:
case LIBRARIES:
case OBJECTS:
List valueList = new ArrayList();
IConfigurationElement[] valueElements = element.getChildren(LIST_VALUE);
for (int i = 0; i < valueElements.length; ++i) {
IConfigurationElement valueElement = valueElements[i];
Boolean isBuiltIn = new Boolean(valueElement.getAttribute(LIST_ITEM_BUILTIN));
if (isBuiltIn.booleanValue()) {
getBuiltInList().add(valueElement.getAttribute(LIST_ITEM_VALUE));
}
else {
valueList.add(valueElement.getAttribute(LIST_ITEM_VALUE));
} }
value = valueList;
break;
}
} }
/** /**
@ -161,6 +128,60 @@ public class OptionReference implements IOption {
} }
public void resolveReferences() {
if (!resolved) {
resolved = true;
IConfigurationElement element = ManagedBuildManager.getConfigElement(this);
// resolve parent (recursively) before calling methods on it.
option = owner.getTool().getOption(element.getAttribute(ID));
if (option instanceof Option) {
((Option)option).resolveReferences();
} else if (option instanceof OptionReference) {
((OptionReference)option).resolveReferences();
}
// value
switch (option.getValueType()) {
case BOOLEAN:
value = new Boolean(element.getAttribute(DEFAULT_VALUE));
break;
case STRING:
value = element.getAttribute(DEFAULT_VALUE);
break;
case ENUMERATED:
String temp = element.getAttribute(DEFAULT_VALUE);
if (temp == null) {
try {
temp = option.getSelectedEnum();
} catch (BuildException e) {
temp = new String();
}
}
value = temp;
break;
case STRING_LIST:
case INCLUDE_PATH:
case PREPROCESSOR_SYMBOLS:
case LIBRARIES:
case OBJECTS:
List valueList = new ArrayList();
IConfigurationElement[] valueElements = element.getChildren(LIST_VALUE);
for (int i = 0; i < valueElements.length; ++i) {
IConfigurationElement valueElement = valueElements[i];
Boolean isBuiltIn = new Boolean(valueElement.getAttribute(LIST_ITEM_BUILTIN));
if (isBuiltIn.booleanValue()) {
getBuiltInList().add(valueElement.getAttribute(LIST_ITEM_VALUE));
}
else {
valueList.add(valueElement.getAttribute(LIST_ITEM_VALUE));
} }
value = valueList;
break;
}
}
}
/** /**
* Persist receiver to project file. * Persist receiver to project file.
* *

View file

@ -51,6 +51,7 @@ public class Target extends BuildObject implements ITarget {
private Map toolMap; private Map toolMap;
private List toolList; private List toolList;
private List toolReferences; private List toolReferences;
private boolean resolved = true;
private static final IConfiguration[] emptyConfigs = new IConfiguration[0]; private static final IConfiguration[] emptyConfigs = new IConfiguration[0];
private static final String EMPTY_STRING = new String(); private static final String EMPTY_STRING = new String();
@ -103,6 +104,10 @@ public class Target extends BuildObject implements ITarget {
* @param element * @param element
*/ */
public Target(IConfigurationElement element) { public Target(IConfigurationElement element) {
// setup for resolving
ManagedBuildManager.putConfigElement(this, element);
resolved = false;
// id // id
setId(element.getAttribute(ID)); setId(element.getAttribute(ID));
@ -122,16 +127,6 @@ public class Target extends BuildObject implements ITarget {
// Get the default extension // Get the default extension
defaultExtension = element.getAttribute(DEFAULT_EXTENSION); defaultExtension = element.getAttribute(DEFAULT_EXTENSION);
// parent
String parentId = element.getAttribute(PARENT);
if (parentId != null) {
parent = ManagedBuildManager.getTarget(null, parentId);
// copy over the parents configs
IConfiguration[] parentConfigs = parent.getConfigurations();
for (int i = 0; i < parentConfigs.length; ++i)
addConfiguration(parentConfigs[i]);
}
// isAbstract // isAbstract
isAbstract = ("true".equals(element.getAttribute(IS_ABSTRACT))); //$NON-NLS-1$ isAbstract = ("true".equals(element.getAttribute(IS_ABSTRACT))); //$NON-NLS-1$
@ -230,6 +225,43 @@ public class Target extends BuildObject implements ITarget {
} }
} }
public void resolveReferences() {
if (!resolved) {
resolved = true;
IConfigurationElement element = ManagedBuildManager.getConfigElement(this);
// parent
String parentId = element.getAttribute(PARENT);
if (parentId != null) {
parent = ManagedBuildManager.getTarget(null, parentId);
// should resolve before calling methods on it
((Target)parent).resolveReferences();
// copy over the parents configs
IConfiguration[] parentConfigs = parent.getConfigurations();
for (int i = 0; i < parentConfigs.length; ++i)
addConfiguration(parentConfigs[i]);
}
// call resolve references on any children
Iterator toolIter = getToolList().iterator();
while (toolIter.hasNext()) {
Tool current = (Tool)toolIter.next();
current.resolveReferences();
}
Iterator refIter = getLocalToolReferences().iterator();
while (refIter.hasNext()) {
ToolReference current = (ToolReference)refIter.next();
current.resolveReferences();
}
if (configurations != null) {
Iterator configIter = configurations.iterator();
while (configIter.hasNext()) {
Configuration current = (Configuration)configIter.next();
current.resolveReferences();
}
}
}
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.managedbuilder.core.ITarget#removeConfiguration(java.lang.String) * @see org.eclipse.cdt.managedbuilder.core.ITarget#removeConfiguration(java.lang.String)
*/ */
@ -302,6 +334,35 @@ public class Target extends BuildObject implements ITarget {
return toolReferences; return toolReferences;
} }
/* (non-javadoc)
*
* @param tool
* @return List
*/
protected List getOptionReferences(ITool tool) {
List references = new ArrayList();
// Get all the option references I add for this tool
ToolReference toolRef = getToolReference(tool);
if (toolRef != null) {
references.addAll(toolRef.getOptionReferenceList());
}
// See if there is anything that my parents add that I don't
if (parent != null) {
List temp = ((Target)parent).getOptionReferences(tool);
Iterator iter = temp.listIterator();
while (iter.hasNext()) {
OptionReference ref = (OptionReference) iter.next();
if (!references.contains(ref)) {
references.add(ref);
}
}
}
return references;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.managedbuilder.core.ITarget#getMakeArguments() * @see org.eclipse.cdt.managedbuilder.core.ITarget#getMakeArguments()
*/ */

View file

@ -12,6 +12,7 @@ package org.eclipse.cdt.managedbuilder.internal.core;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.ListIterator; import java.util.ListIterator;
import java.util.Map; import java.util.Map;
@ -48,6 +49,7 @@ public class Tool extends BuildObject implements ITool, IOptionCategory {
private String outputExtension; private String outputExtension;
private String outputFlag; private String outputFlag;
private String outputPrefix; private String outputPrefix;
private boolean resolved = true;
public Tool(IConfigurationElement element) { public Tool(IConfigurationElement element) {
@ -330,6 +332,10 @@ public class Tool extends BuildObject implements ITool, IOptionCategory {
} }
protected void loadFromManifest(IConfigurationElement element) { protected void loadFromManifest(IConfigurationElement element) {
// setup for resolving
ManagedBuildManager.putConfigElement(this, element);
this.resolved = false;
// id // id
setId(element.getAttribute(ITool.ID)); setId(element.getAttribute(ITool.ID));
@ -403,6 +409,29 @@ public class Tool extends BuildObject implements ITool, IOptionCategory {
} }
} }
public void resolveReferences() {
if (!resolved) {
resolved = true;
// IConfigurationElement element = ManagedBuildManager.getConfigElement(this);
// Tool doesn't have any references, but children might
Iterator optionIter = options.iterator();
while (optionIter.hasNext()) {
Option current = (Option)optionIter.next();
current.resolveReferences();
}
Iterator catIter = categoryMap.values().iterator();
while (catIter.hasNext()) {
IOptionCategory current = (IOptionCategory)catIter.next();
if (current instanceof Tool) {
((Tool)current).resolveReferences();
} else if (current instanceof OptionCategory) {
((OptionCategory)current).resolveReferences();
}
}
}
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.build.managed.ITool#producesFileType(java.lang.String) * @see org.eclipse.cdt.core.build.managed.ITool#producesFileType(java.lang.String)
*/ */

View file

@ -20,6 +20,7 @@ import org.eclipse.cdt.managedbuilder.core.IBuildObject;
import org.eclipse.cdt.managedbuilder.core.IConfiguration; import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IOption; import org.eclipse.cdt.managedbuilder.core.IOption;
import org.eclipse.cdt.managedbuilder.core.ITool; import org.eclipse.cdt.managedbuilder.core.ITool;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IConfigurationElement;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
@ -30,6 +31,7 @@ public class ToolReference extends AbstractToolReference {
private String command; private String command;
private List optionReferences; private List optionReferences;
private IBuildObject owner; private IBuildObject owner;
private boolean resolved = true;
/** /**
* Create a new tool reference based on information contained in * Create a new tool reference based on information contained in
@ -76,16 +78,21 @@ public class ToolReference extends AbstractToolReference {
* @param element The element containing build information for the reference. * @param element The element containing build information for the reference.
*/ */
public ToolReference(BuildObject owner, IConfigurationElement element) { public ToolReference(BuildObject owner, IConfigurationElement element) {
// setup for resolving
ManagedBuildManager.putConfigElement(this, element);
resolved = false;
this.owner = owner; this.owner = owner;
// hook me up
if (owner instanceof Configuration) { if (owner instanceof Configuration) {
Target target = (Target) ((Configuration)owner).getTarget();
parent = target.getTool(element.getAttribute(ID));
((Configuration)owner).addToolReference(this); ((Configuration)owner).addToolReference(this);
} else if (owner instanceof Target) { } else if (owner instanceof Target) {
parent = ((Target)owner).getTool(element.getAttribute(ID));
((Target)owner).addToolReference(this); ((Target)owner).addToolReference(this);
} }
IConfigurationElement[] toolElements = element.getChildren(); IConfigurationElement[] toolElements = element.getChildren();
for (int m = 0; m < toolElements.length; ++m) { for (int m = 0; m < toolElements.length; ++m) {
IConfigurationElement toolElement = toolElements[m]; IConfigurationElement toolElement = toolElements[m];
@ -112,6 +119,32 @@ public class ToolReference extends AbstractToolReference {
} }
} }
public void resolveReferences() {
if (!resolved) {
resolved = true;
IConfigurationElement element = ManagedBuildManager.getConfigElement(this);
// resolve my parent
if (owner instanceof Configuration) {
Target target = (Target) ((Configuration)owner).getTarget();
parent = target.getTool(element.getAttribute(ID));
} else if (owner instanceof Target) {
parent = ((Target)owner).getTool(element.getAttribute(ID));
}
// recursively resolve my parent
if (parent instanceof Tool) {
((Tool)parent).resolveReferences();
} else if (parent instanceof ToolReference) {
((ToolReference)parent).resolveReferences();
}
Iterator it = getOptionReferenceList().iterator();
while (it.hasNext()) {
OptionReference optRef = (OptionReference)it.next();
optRef.resolveReferences();
}
}
}
/** /**
* Adds the option reference specified in the argument to the receiver. * Adds the option reference specified in the argument to the receiver.
* *
@ -121,6 +154,17 @@ public class ToolReference extends AbstractToolReference {
getOptionReferenceList().add(optionRef); getOptionReferenceList().add(optionRef);
} }
private OptionReference getOptionReference(String id) {
Iterator it = getOptionReferenceList().iterator();
while (it.hasNext()) {
OptionReference current = (OptionReference)it.next();
if (current.getId().equals(id)) {
return current;
}
}
return null;
}
/** /**
* Answers a reference to the option. If the reference does not exist, * Answers a reference to the option. If the reference does not exist,
* a new reference is created. * a new reference is created.
@ -228,7 +272,14 @@ public class ToolReference extends AbstractToolReference {
protected List getAllOptionRefs() { protected List getAllOptionRefs() {
// First get all the option references this tool reference contains // First get all the option references this tool reference contains
return ((Configuration)owner).getOptionReferences(parent); if (owner instanceof Configuration) {
return ((Configuration)owner).getOptionReferences(parent);
} else if (owner instanceof Target) {
return ((Target)owner).getOptionReferences(parent);
} else {
// this shouldn't happen
return null;
}
} }
/* (non-javadoc) /* (non-javadoc)
@ -262,7 +313,13 @@ public class ToolReference extends AbstractToolReference {
* @see org.eclipse.cdt.core.build.managed.ITool#getOption(java.lang.String) * @see org.eclipse.cdt.core.build.managed.ITool#getOption(java.lang.String)
*/ */
public IOption getOption(String id) { public IOption getOption(String id) {
//TODO Implement this IOption[] options = getOptions();
for (int i = 0; i < options.length; i++) {
IOption current = options[i];
if (current.getId().equals(id)) {
return current;
}
}
return null; return null;
} }