From 663cef492f28489a2302caa2bef28bf8b72e9e29 Mon Sep 17 00:00:00 2001 From: Doug Schaefer Date: Wed, 9 Apr 2003 20:56:21 +0000 Subject: [PATCH] Fleshing out the build model. --- .../cdt/core/build/managed/IBuildObject.java | 25 +++++ .../core/build/managed/IConfiguration.java | 18 +--- .../cdt/core/build/managed/IOption.java | 9 +- .../core/build/managed/IOptionCategory.java | 42 +++++--- .../cdt/core/build/managed/ITarget.java | 34 +++---- .../eclipse/cdt/core/build/managed/ITool.java | 23 ++--- .../build/managed/ManagedBuildManager.java | 50 +++++++++- .../core/build/managed/BuildObject.java | 50 ++++++++++ .../core/build/managed/Configuration.java | 10 +- .../internal/core/build/managed/Option.java | 83 +++++++++++++++- .../core/build/managed/OptionCategory.java | 72 +++++++++++++- .../internal/core/build/managed/Target.java | 46 +++++---- .../cdt/internal/core/build/managed/Tool.java | 96 +++++++++++++++---- .../schema/ManagedBuildTools.exsd | 7 ++ .../build/managed/tests/AllBuildTests.java | 62 +++++++++++- core/org.eclipse.cdt.ui.tests/plugin.xml | 36 +++++++ 16 files changed, 538 insertions(+), 125 deletions(-) create mode 100644 core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/IBuildObject.java create mode 100644 core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/BuildObject.java diff --git a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/IBuildObject.java b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/IBuildObject.java new file mode 100644 index 00000000000..335c2239c7e --- /dev/null +++ b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/IBuildObject.java @@ -0,0 +1,25 @@ +/* + * Created on Apr 9, 2003 + * + * To change the template for this generated file go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +package org.eclipse.cdt.core.build.managed; + +/** + * @author dschaefe + * + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public interface IBuildObject { + + public String getId(); + + public void setId(String id); + + public String getName(); + + public void setName(String name); + +} diff --git a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/IConfiguration.java b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/IConfiguration.java index 9fef24e56bf..5f03a2d9808 100644 --- a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/IConfiguration.java +++ b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/IConfiguration.java @@ -15,16 +15,10 @@ import org.eclipse.core.resources.IResource; /** * */ -public interface IConfiguration { +public interface IConfiguration extends IBuildObject { /** - * Returns the name of this configuration - * @return - */ - public String getName(); - - /** - * Returns the platform for this configuration. + * Returns the target for this configuration. * * @return */ @@ -36,14 +30,6 @@ public interface IConfiguration { */ public IResource getOwner(); - /** - * Returns the configuration from which this configuration inherits - * properties. - * - * @return - */ - public IConfiguration getParent(); - /** * Returns the tools that are used in this configuration. * diff --git a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/IOption.java b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/IOption.java index c9496aab0bc..6ce56a5adde 100644 --- a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/IOption.java +++ b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/IOption.java @@ -13,7 +13,7 @@ package org.eclipse.cdt.core.build.managed; /** * */ -public interface IOption { +public interface IOption extends IBuildObject { // Type for the value of the option public static final int STRING = 0; @@ -33,6 +33,13 @@ public interface IOption { */ public IOptionCategory getCategory(); + /** + * Set the option category for this option. + * + * @param category + */ + public void setCategory(IOptionCategory category); + /** * Returns the name of this option. * diff --git a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/IOptionCategory.java b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/IOptionCategory.java index 8d66327e806..780286266e2 100644 --- a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/IOptionCategory.java +++ b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/IOptionCategory.java @@ -13,22 +13,8 @@ package org.eclipse.cdt.core.build.managed; /** * */ -public interface IOptionCategory { +public interface IOptionCategory extends IBuildObject { - /** - * Returns the name of the option category. - * - * @return - */ - public String getName(); - - /** - * Returns the options that have been assigned to this category. - * - * @return - */ - public IOption[] getOptions(); - /** * Returns the list of children of this node in the option category tree * @@ -36,7 +22,33 @@ public interface IOptionCategory { */ public IOptionCategory[] getChildCategories(); + /** + * Returns a new child category for this category. + * + * @return + */ + public IOptionCategory createChildCategory(); + + /** + * Returns the options in this category for a given tool. + * + * @param tool + * @return + */ + public IOption[] getOptions(ITool tool); + + /** + * Returns the category that owns this category, or null if this is the + * top category for a tool. + * + * @return + */ public IOptionCategory getOwner(); + /** + * Returns the tool that ultimately owns this category. + * + * @return + */ public ITool getTool(); } diff --git a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/ITarget.java b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/ITarget.java index eb4f682ac52..f8d1125d252 100644 --- a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/ITarget.java +++ b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/ITarget.java @@ -16,22 +16,8 @@ import org.eclipse.core.resources.IResource; * This class represents targets for the managed build process. A target * is some type of resource built using a given collection of tools. */ -public interface ITarget { +public interface ITarget extends IBuildObject { - /** - * Gets the name for the target. - * - * @return - */ - public String getName(); - - /** - * Gets the parent for the target. - * - * @return - */ - public ITarget getParent(); - /** * Gets the resource that this target is applied to. * @@ -47,6 +33,13 @@ public interface ITarget { */ public ITool[] getTools(); + /** + * Creates a new tool. + * + * @return + */ + public ITool createTool(); + /** * Returns all of the configurations defined by this target. * @return @@ -54,21 +47,20 @@ public interface ITarget { public IConfiguration[] getConfigurations(); /** - * Creates a new configuration for the given resource. + * Creates a new configuration for this target. * - * @param resource * @return */ - public IConfiguration addConfiguration(IResource resource) + public IConfiguration createConfiguration() throws BuildException; /** - * Creates a new configuration for the given resource based on the parent config - * @param resource + * Creates a new configuration based on the parent config for this target. + * * @param parentConfig * @return */ - public IConfiguration addConfiguration(IResource resource, IConfiguration parentConfig) + public IConfiguration createConfiguration(IConfiguration parentConfig) throws BuildException; } diff --git a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/ITool.java b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/ITool.java index 881048f9f16..cd336f98d91 100644 --- a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/ITool.java +++ b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/ITool.java @@ -13,32 +13,27 @@ package org.eclipse.cdt.core.build.managed; /** * */ -public interface ITool { +public interface ITool extends IBuildObject { - /** - * Returns the name of the tool. - * - * @return - */ - public String getName(); - /** * Return the target that defines this tool, if applicable * @return */ public ITarget getTarget(); - /** - * Returns the tool that this tool inherits properties from. - * @return - */ - public ITool getParent(); - /** * Returns the options that may be customized for this tool. */ public IOption[] getOptions(); + /** + * Creates a new option for this tool. Generally, this should only be + * done by the extension and project data loaders. + * + * @return + */ + public IOption createOption(); + /** * Options are organized into categories for UI purposes. * These categories are organized into a tree. This is the root diff --git a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/ManagedBuildManager.java b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/ManagedBuildManager.java index ec0c2fae021..92689e7281a 100644 --- a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/ManagedBuildManager.java +++ b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/ManagedBuildManager.java @@ -11,7 +11,9 @@ package org.eclipse.cdt.core.build.managed; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.internal.core.build.managed.Configuration; @@ -138,6 +140,15 @@ public class ManagedBuildManager { return newTarget; } + /** + * Saves the build information associated with a project and all resources + * in the project to the build info file. + * + * @param project + */ + public static void saveBuildInfo(IProject project) { + } + // Private stuff private static List extensionTargets; @@ -147,6 +158,7 @@ public class ManagedBuildManager { return; extensionTargets = new ArrayList(); + Map targetMap = new HashMap(); IExtensionPoint extensionPoint = CCorePlugin.getDefault().getDescriptor().getExtensionPoint("ManagedBuildInfo"); @@ -157,17 +169,49 @@ public class ManagedBuildManager { for (int j = 0; j < elements.length; ++j) { IConfigurationElement element = elements[j]; if (element.getName().equals("target")) { - Target target = new Target(null); + String parentId = element.getAttribute("parent"); + Target target = null; + if (parentId != null) + target = new Target(null, (Target)targetMap.get(parentId)); + else + target = new Target(null); target.setName(element.getAttribute("name")); extensionTargets.add(target); + targetMap.put(element.getAttribute("id"), target); IConfigurationElement[] targetElements = element.getChildren(); for (int k = 0; k < targetElements.length; ++k) { IConfigurationElement targetElement = targetElements[k]; if (targetElement.getName().equals("tool")) { - Tool tool = new Tool(targetElement.getAttribute("name"), target); + ITool tool = target.createTool(); + tool.setName(targetElement.getAttribute("name")); + + Map categoryMap = new HashMap(); + categoryMap.put(targetElement.getAttribute("id"), tool.getTopOptionCategory()); + IConfigurationElement[] toolElements = targetElement.getChildren(); + for (int l = 0; l < toolElements.length; ++l) { + IConfigurationElement toolElement = toolElements[l]; + if (toolElement.getName().equals("option")) { + IOption option = tool.createOption(); + option.setName(toolElement.getAttribute("name")); + + String categoryId = toolElement.getAttribute("category"); + if (categoryId != null) + option.setCategory((IOptionCategory)categoryMap.get(categoryId)); + } else if (toolElement.getName().equals("optionCategory")) { + IOptionCategory owner = (IOptionCategory)categoryMap.get(toolElement.getAttribute("owner")); + IOptionCategory category = owner.createChildCategory(); + category.setName(toolElement.getAttribute("name")); + categoryMap.put(toolElement.getAttribute("id"), category); + } + } } else if (targetElement.getName().equals("configuration")) { - target.addConfiguration(new Configuration(target)); + try { + IConfiguration config = target.createConfiguration(); + config.setName(targetElement.getAttribute("name")); + } catch (BuildException e) { + // Not sure what to do here. + } } } } diff --git a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/BuildObject.java b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/BuildObject.java new file mode 100644 index 00000000000..97c8f9a0c9f --- /dev/null +++ b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/BuildObject.java @@ -0,0 +1,50 @@ +/* + * Created on Apr 9, 2003 + * + * To change the template for this generated file go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +package org.eclipse.cdt.internal.core.build.managed; + +import org.eclipse.cdt.core.build.managed.IBuildObject; + +/** + * @author dschaefe + * + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public class BuildObject implements IBuildObject { + + protected String id; + protected String name; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.build.managed.IBuildObject#getId() + */ + public String getId() { + return id; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.build.managed.IBuildObject#setId(java.lang.String) + */ + public void setId(String id) { + this.id = id; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.build.managed.IBuildObject#getName() + */ + public String getName() { + return name; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.build.managed.IBuildObject#setName(java.lang.String) + */ + public void setName(String name) { + this.name = name; + } + +} diff --git a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Configuration.java b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Configuration.java index 5835b12b698..fb30338428f 100644 --- a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Configuration.java +++ b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Configuration.java @@ -20,9 +20,8 @@ import org.eclipse.core.resources.IResource; /** * */ -public class Configuration implements IConfiguration { +public class Configuration extends BuildObject implements IConfiguration { - private String name; private ITarget target; private IConfiguration parent; private List toolReference; @@ -42,13 +41,6 @@ public class Configuration implements IConfiguration { return (name == null && parent != null) ? parent.getName() : name; } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.build.managed.IConfiguration#setName(java.lang.String) - */ - public void setName(String name) { - this.name = name; - } - /* (non-Javadoc) * @see org.eclipse.cdt.core.build.managed.IConfiguration#getTools() */ diff --git a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Option.java b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Option.java index d8f8234f355..44e0cb3d423 100644 --- a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Option.java +++ b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Option.java @@ -10,9 +10,90 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.build.managed; +import org.eclipse.cdt.core.build.managed.IConfiguration; +import org.eclipse.cdt.core.build.managed.IOption; +import org.eclipse.cdt.core.build.managed.IOptionCategory; +import org.eclipse.cdt.core.build.managed.ITool; + /** * */ -public class Option { +public class Option extends BuildObject implements IOption { + + private ITool tool; + private IOptionCategory category; + + public Option(ITool tool) { + this.tool = tool; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.build.managed.IOption#getApplicableValues() + */ + public String[] getApplicableValues() { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.build.managed.IOption#getCategory() + */ + public IOptionCategory getCategory() { + return (category != null) ? category : getTool().getTopOptionCategory(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.build.managed.IOption#getStringListValue() + */ + public String[] getStringListValue() { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.build.managed.IOption#getStringValue() + */ + public String getStringValue() { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.build.managed.IOption#getTool() + */ + public ITool getTool() { + return tool; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.build.managed.IOption#getValueType() + */ + public int getValueType() { + // TODO Auto-generated method stub + return 0; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.build.managed.IOption#setStringValue(org.eclipse.cdt.core.build.managed.IConfiguration, java.lang.String) + */ + public IOption setStringValue(IConfiguration config, String value) { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.build.managed.IOption#setStringValue(org.eclipse.cdt.core.build.managed.IConfiguration, java.lang.String[]) + */ + public IOption setStringValue(IConfiguration config, String[] value) { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.build.managed.IOption#setCategory(org.eclipse.cdt.core.build.managed.IOptionCategory) + */ + public void setCategory(IOptionCategory category) { + this.category = category; + } } diff --git a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/OptionCategory.java b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/OptionCategory.java index 5909e1acc10..fe6f5125a5b 100644 --- a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/OptionCategory.java +++ b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/OptionCategory.java @@ -10,9 +10,79 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.build.managed; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.cdt.core.build.managed.IOption; +import org.eclipse.cdt.core.build.managed.IOptionCategory; +import org.eclipse.cdt.core.build.managed.ITool; + /** * */ -public class OptionCategory { +public class OptionCategory extends BuildObject implements IOptionCategory { + + private IOptionCategory owner; + private List children; + + private static final IOptionCategory[] emtpyCategories = new IOptionCategory[0]; + + public OptionCategory(IOptionCategory owner) { + this.owner = owner; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.build.managed.IOptionCategory#getChildCategories() + */ + public IOptionCategory[] getChildCategories() { + if (children != null) + return (IOptionCategory[])children.toArray(new IOptionCategory[children.size()]); + else + return emtpyCategories; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.build.managed.IOptionCategory#createChildCategory() + */ + public IOptionCategory createChildCategory() { + IOptionCategory category = new OptionCategory(this); + + if (children == null) + children = new ArrayList(); + children.add(category); + + return category; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.build.managed.IOptionCategory#getOwner() + */ + public IOptionCategory getOwner() { + return owner; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.build.managed.IOptionCategory#getTool() + */ + public ITool getTool() { + // This will stop at the Tool's top category + return owner.getTool(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.build.managed.IOptionCategory#getOptions(org.eclipse.cdt.core.build.managed.ITool) + */ + public IOption[] getOptions(ITool tool) { + List myOptions = new ArrayList(); + IOption[] allOptions = tool.getOptions(); + + for (int i = 0; i < allOptions.length; ++i) { + IOption option = allOptions[i]; + if (option.getCategory().equals(this)) + myOptions.add(option); + } + + return (IOption[])myOptions.toArray(new IOption[myOptions.size()]); + } } diff --git a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Target.java b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Target.java index 300fade816d..1163de980ca 100644 --- a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Target.java +++ b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Target.java @@ -17,21 +17,21 @@ import org.eclipse.cdt.core.build.managed.BuildException; import org.eclipse.cdt.core.build.managed.IConfiguration; import org.eclipse.cdt.core.build.managed.ITarget; import org.eclipse.cdt.core.build.managed.ITool; -import org.eclipse.cdt.core.build.managed.ManagedBuildManager; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; /** * */ -public class Target implements ITarget { +public class Target extends BuildObject implements ITarget { - private String name; private ITarget parent; private IResource owner; private List tools; private List configurations; + private static final IConfiguration[] emptyConfigs = new IConfiguration[0]; + public Target(IResource owner) { this.owner = owner; } @@ -61,10 +61,6 @@ public class Target implements ITarget { return parent; } - public void setName(String name) { - this.name = name; - } - public IResource getOwner() { return owner; } @@ -95,53 +91,55 @@ public class Target implements ITarget { return toolArray; } - public void addTool(ITool tool){ + public ITool createTool() { + ITool tool = new Tool(this); + if (tools == null) tools = new ArrayList(); tools.add(tool); + + return tool; } public IConfiguration[] getConfigurations() { - return (IConfiguration[])configurations.toArray(new IConfiguration[configurations.size()]); + if (configurations != null) + return (IConfiguration[])configurations.toArray(new IConfiguration[configurations.size()]); + else + return emptyConfigs; } - public void addConfiguration(IConfiguration configuration) { + private void addLocalConfiguration(IConfiguration configuration) { if (configurations == null) configurations = new ArrayList(); configurations.add(configuration); } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.build.managed.ITarget#addConfiguration(org.eclipse.core.resources.IResource) - */ - public IConfiguration addConfiguration(IResource resource) + public IConfiguration createConfiguration() throws BuildException { - Target target = (Target)ManagedBuildManager.addTarget(resource, this); - IConfiguration config = new Configuration(target); - target.addConfiguration(config); - return null; + IConfiguration config = new Configuration(this); + addLocalConfiguration(config); + return config; } - public IConfiguration addConfiguration(IResource resource, IConfiguration parentConfig) + public IConfiguration createConfiguration(IConfiguration parentConfig) throws BuildException { IResource parentOwner = parentConfig.getOwner(); - if (resource instanceof IProject) { + if (owner instanceof IProject) { // parent must be owned by the same project - if (!resource.equals(parentOwner)) + if (!owner.equals(parentOwner)) throw new BuildException("addConfiguration: parent must be in same project"); } else { // parent must be owned by the project - if (!resource.getProject().equals(parentOwner)) + if (!owner.getProject().equals(parentOwner)) throw new BuildException("addConfiguration: parent must be in owning project"); } // Validation passed - Target target = (Target)ManagedBuildManager.addTarget(resource, this); IConfiguration config = new Configuration(parentConfig); - target.addConfiguration(config); + addLocalConfiguration(config); return config; } diff --git a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Tool.java b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Tool.java index 4462a9b2925..7be57edd7cf 100644 --- a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Tool.java +++ b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Tool.java @@ -10,50 +10,112 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.build.managed; +import java.util.ArrayList; +import java.util.List; + import org.eclipse.cdt.core.build.managed.IOption; import org.eclipse.cdt.core.build.managed.IOptionCategory; import org.eclipse.cdt.core.build.managed.ITarget; import org.eclipse.cdt.core.build.managed.ITool; /** - * + * Represents a tool that can be invoked during a build. + * Note that this class implements IOptionCategory to represent the top + * category. */ -public class Tool implements ITool { +public class Tool extends BuildObject implements ITool, IOptionCategory { - private String name; private ITarget target; + private List options; + private IOptionCategory topOptionCategory; + private List childOptionCategories; - public Tool(String name) { - this.name = name; - } + private static IOption[] emptyOptions = new IOption[0]; + private static IOptionCategory[] emptyCategories = new IOptionCategory[0]; - public Tool(String name, Target target) { - this(name); + public Tool(Target target) { this.target = target; } - public String getName() { - return name; - } - public ITarget getTarget() { return target; } public IOption[] getOptions() { - return null; + if (options != null) + return (IOption[])options.toArray(new IOption[options.size()]); + else + return emptyOptions; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.build.managed.ITool#createOption() + */ + public IOption createOption() { + IOption option = new Option(this); + + if (options == null) + options = new ArrayList(); + options.add(option); + + return option; } public IOptionCategory getTopOptionCategory() { + return this; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.build.managed.IOptionCategory#getChildCategories() + */ + public IOptionCategory[] getChildCategories() { + if (childOptionCategories != null) + return (IOptionCategory[])childOptionCategories.toArray(new IOptionCategory[childOptionCategories.size()]); + else + return emptyCategories; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.build.managed.IOptionCategory#createChildCategory() + */ + public IOptionCategory createChildCategory() { + IOptionCategory category = new OptionCategory(this); + + if (childOptionCategories == null) + childOptionCategories = new ArrayList(); + childOptionCategories.add(category); + + return category; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.build.managed.IOptionCategory#getOwner() + */ + public IOptionCategory getOwner() { return null; } /* (non-Javadoc) - * @see org.eclipse.cdt.core.build.managed.ITool#getParent() + * @see org.eclipse.cdt.core.build.managed.IOptionCategory#getTool() */ - public ITool getParent() { - // TODO Auto-generated method stub - return null; + public ITool getTool() { + return this; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.build.managed.IOptionCategory#getOptions(org.eclipse.cdt.core.build.managed.ITool) + */ + public IOption[] getOptions(ITool tool) { + List myOptions = new ArrayList(); + IOption[] allOptions = tool.getOptions(); + + for (int i = 0; i < allOptions.length; ++i) { + IOption option = allOptions[i]; + if (option.getCategory() == null || option.getCategory().equals(this)) + myOptions.add(option); + } + + return (IOption[])myOptions.toArray(new IOption[myOptions.size()]); } } diff --git a/core/org.eclipse.cdt.core/schema/ManagedBuildTools.exsd b/core/org.eclipse.cdt.core/schema/ManagedBuildTools.exsd index adc0e8c298b..3f80815b64b 100644 --- a/core/org.eclipse.cdt.core/schema/ManagedBuildTools.exsd +++ b/core/org.eclipse.cdt.core/schema/ManagedBuildTools.exsd @@ -272,6 +272,13 @@ + + + + + + + diff --git a/core/org.eclipse.cdt.ui.tests/build/org/eclipse/cdt/core/build/managed/tests/AllBuildTests.java b/core/org.eclipse.cdt.ui.tests/build/org/eclipse/cdt/core/build/managed/tests/AllBuildTests.java index b53451b2028..c26b084f1a4 100644 --- a/core/org.eclipse.cdt.ui.tests/build/org/eclipse/cdt/core/build/managed/tests/AllBuildTests.java +++ b/core/org.eclipse.cdt.ui.tests/build/org/eclipse/cdt/core/build/managed/tests/AllBuildTests.java @@ -14,7 +14,11 @@ import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; +import org.eclipse.cdt.core.build.managed.IConfiguration; +import org.eclipse.cdt.core.build.managed.IOption; +import org.eclipse.cdt.core.build.managed.IOptionCategory; import org.eclipse.cdt.core.build.managed.ITarget; +import org.eclipse.cdt.core.build.managed.ITool; import org.eclipse.cdt.core.build.managed.ManagedBuildManager; /** @@ -43,7 +47,8 @@ public class AllBuildTests extends TestCase { * defined in this plugin */ public void testExtensions() { - boolean testRootFound = false; + ITarget testRoot = null; + ITarget testSub = null; // Note secret null parameter which means just extensions ITarget[] targets = ManagedBuildManager.getDefinedTargets(null); @@ -52,10 +57,61 @@ public class AllBuildTests extends TestCase { ITarget target = targets[i]; if (target.getName().equals("Test Root")) { - testRootFound = true; + testRoot = target; + + // Tools + ITool[] tools = testRoot.getTools(); + // Root Tool + ITool rootTool = tools[0]; + assertEquals("Root Tool", rootTool.getName()); + // Options + IOption[] options = rootTool.getOptions(); + assertEquals(2, options.length); + assertEquals("Option in Top", options[0].getName()); + assertEquals("Option in Category", options[1].getName()); + // Option Categories + IOptionCategory topCategory = rootTool.getTopOptionCategory(); + assertEquals("Root Tool", topCategory.getName()); + options = topCategory.getOptions(rootTool); + assertEquals(1, options.length); + assertEquals("Option in Top", options[0].getName()); + IOptionCategory[] categories = topCategory.getChildCategories(); + assertEquals(1, categories.length); + assertEquals("Category", categories[0].getName()); + options = categories[0].getOptions(rootTool); + assertEquals(1, options.length); + assertEquals("Option in Category", options[0].getName()); + + // Configs + IConfiguration[] configs = testRoot.getConfigurations(); + // Root Config + IConfiguration rootConfig = configs[0]; + assertEquals("Root Config", rootConfig.getName()); + + } else if (target.getName().equals("Test Sub")) { + testSub = target; + + // Tools + ITool[] tools = testSub.getTools(); + // Root Tool + ITool rootTool = tools[0]; + assertEquals("Root Tool", rootTool.getName()); + // Sub Tool + ITool subTool = tools[1]; + assertEquals("Sub Tool", subTool.getName()); + + // Configs + IConfiguration[] configs = testSub.getConfigurations(); + // Root Config + IConfiguration rootConfig = configs[0]; + assertEquals("Root Config", rootConfig.getName()); + // Sub Config + IConfiguration subConfig = configs[1]; + assertEquals("Sub Config", subConfig.getName()); } } - assertTrue(testRootFound); + assertNotNull(testRoot); + assertNotNull(testSub); } } diff --git a/core/org.eclipse.cdt.ui.tests/plugin.xml b/core/org.eclipse.cdt.ui.tests/plugin.xml index ebc14a6db37..761724ee109 100644 --- a/core/org.eclipse.cdt.ui.tests/plugin.xml +++ b/core/org.eclipse.cdt.ui.tests/plugin.xml @@ -36,6 +36,7 @@ name="Compiler" id="linux.compiler"> @@ -94,6 +95,41 @@ + + + + + + + + + + + + + +