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 index 335c2239c7e..1cce486b013 100644 --- 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 @@ -16,10 +16,6 @@ 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 5f03a2d9808..da26cb1afeb 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 @@ -37,4 +37,19 @@ public interface IConfiguration extends IBuildObject { */ public ITool[] getTools(); + /** + * Sets an option value for this configuration. + * + * @param option + * @param value + */ + public void setOption(IOption option, String value) + throws BuildException; + + /** + * Sets an option value for this configuration. + * @param option + */ + public void setOption(IOption option, String[] value) + throws BuildException; } 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 e3fa082a65c..7926ed79cb8 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 @@ -33,13 +33,6 @@ public interface IOption extends IBuildObject { */ public IOptionCategory getCategory(); - /** - * Set the option category for this option. - * - * @param category - */ - public void setCategory(IOptionCategory category); - /** * Returns the name of this option. * @@ -68,35 +61,13 @@ public interface IOption extends IBuildObject { * * @return */ - public String getStringValue(); + public String getStringValue() throws BuildException; /** * Returns the current value for this option if it is a List of Strings. * * @return */ - public String [] getStringListValue(); + public String [] getStringListValue() throws BuildException; - /** - * Sets the value for this option in a given configuration. - * A new instance of the option for the configuration may be created. - * The appropriate new option is returned. - * - * @param config - * @param value - */ - public IOption setValue(IConfiguration config, String value) - throws BuildException; - - /** - * Sets the value for this option in a given configuration. - * A new instance of the option for the configuration may be created. - * The appropriate new option is returned. - * - * @param config - * @param value - */ - public IOption setValue(IConfiguration config, String[] value) - throws BuildException; - } 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 cb2c9dd479c..c1afcc8a8e3 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 @@ -45,4 +45,24 @@ public interface ITarget extends IBuildObject { */ public IConfiguration[] getConfigurations(); + /** + * Creates a new configuration for the target. It is populated with + * the tools defined for that target and options set at their defaults. + * + * @param id id for this configuration. + * @return + */ + public IConfiguration createConfiguration(String id); + + /** + * Creates a configuration for the target populated with the tools and + * options settings from the parent configuration. As options and tools + * change in the parent, unoverridden values are updated in the child + * config as well. + * + * @param parent + * @param id + * @return + */ + public IConfiguration createConfiguration(IConfiguration parent, String id); } 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 e98142f39a8..25605d1648d 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 @@ -123,7 +123,7 @@ public class ManagedBuildManager { } /** - * Adds a new target to the resource based on the parentTarget. + * Creates a new target for the resource based on the parentTarget. * * @param resource * @param parentTarget @@ -155,6 +155,26 @@ public class ManagedBuildManager { return new Target(resource, parentTarget); } + /** + * Set the string value for an option for a given config. + * + * @param config + * @param option + * @param value + */ + public static void setOption(IConfiguration config, IOption option, String value) { + } + + /** + * Set the string array value for an option for a given config. + * + * @param config + * @param option + * @param value + */ + public static void setOption(IConfiguration config, IOption option, String[] value) { + + } /** * Saves the build information associated with a project and all resources * in the project to the build info file. 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 4b3cd43176b..5978512cefb 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 @@ -13,11 +13,15 @@ package org.eclipse.cdt.internal.core.build.managed; import java.util.ArrayList; import java.util.List; +import org.eclipse.cdt.core.build.managed.BuildException; import org.eclipse.cdt.core.build.managed.IConfiguration; +import org.eclipse.cdt.core.build.managed.IOption; import org.eclipse.cdt.core.build.managed.ITarget; import org.eclipse.cdt.core.build.managed.ITool; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IConfigurationElement; +import org.w3c.dom.Document; +import org.w3c.dom.Element; /** * @@ -27,17 +31,29 @@ public class Configuration extends BuildObject implements IConfiguration { private ITarget target; private IConfiguration parent; private List toolReferences; - - public Configuration(Target target) { + + /** + * A fresh new configuration for a target. + * @param target + * @param id + */ + public Configuration(Target target, String id) { + this.id = id; this.target = target; + + target.addConfiguration(this); } - public Configuration(IConfiguration parent) { + public Configuration(Target target, IConfiguration parent, String id) { + this.id = id; + this.target = target; this.parent = parent; + + target.addConfiguration(this); } public Configuration(Target target, IConfigurationElement element) { - this(target); + this.target = target; // id setId(element.getAttribute("id")); @@ -57,6 +73,20 @@ public class Configuration extends BuildObject implements IConfiguration { } } + public void serealize(Document doc, Element element) { + element.setAttribute("id", id); + element.setAttribute("name", name); + if (parent != null) + element.setAttribute("parent", parent.getId()); + + if (toolReferences != null) + for (int i = 0; i < toolReferences.size(); ++i) { + ToolReference toolRef = (ToolReference)toolReferences.get(i); + Element toolRefElement = doc.createElement("toolRef"); + toolRef.serealize(doc, toolRefElement); + } + } + /* (non-Javadoc) * @see org.eclipse.cdt.core.build.managed.IConfiguration#getName() */ @@ -124,4 +154,37 @@ public class Configuration extends BuildObject implements IConfiguration { toolReferences = new ArrayList(); toolReferences.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); + } + } else { + ToolReference toolRef = getToolReference(option.getTool()); + if (toolRef == null) + toolRef = new ToolReference(this, option.getTool()); + return toolRef.createOptionReference(option); + } + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.build.managed.IConfiguration#setOption(org.eclipse.cdt.core.build.managed.IOption, java.lang.String) + */ + public void setOption(IOption option, String value) throws BuildException { + createOptionReference(option).setValue(value); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.build.managed.IConfiguration#setOption(org.eclipse.cdt.core.build.managed.IOption, java.lang.String[]) + */ + public void setOption(IOption option, String[] value) throws BuildException { + createOptionReference(option).setValue(value); + } + } diff --git a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/OptionReference.java b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/OptionReference.java index 16e4b7b715a..9043afcb529 100644 --- a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/OptionReference.java +++ b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/OptionReference.java @@ -10,11 +10,13 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.build.managed; -import org.eclipse.cdt.core.build.managed.IConfiguration; +import org.eclipse.cdt.core.build.managed.BuildException; import org.eclipse.cdt.core.build.managed.IOption; import org.eclipse.cdt.core.build.managed.IOptionCategory; import org.eclipse.cdt.core.build.managed.ITool; import org.eclipse.core.runtime.IConfigurationElement; +import org.w3c.dom.Document; +import org.w3c.dom.Element; /** * @@ -22,121 +24,127 @@ import org.eclipse.core.runtime.IConfigurationElement; public class OptionReference implements IOption { private IOption option; - private ITool tool; + private ToolReference owner; + private Object value; - public OptionReference(IOption option, ITool tool) { + /** + * Created internally. + * + * @param owner + * @param option + */ + public OptionReference(ToolReference owner, IOption option) { + this.owner = owner; this.option = option; - this.tool = tool; - } - - public OptionReference(ToolReference owner, IConfigurationElement element) { - this.tool = owner; - option = tool.getOption(element.getAttribute("id")); + owner.addOptionReference(this); } + /** + * Created from extension. + * + * @param owner + * @param element + */ + public OptionReference(ToolReference owner, IConfigurationElement element) { + this.owner = owner; + option = owner.getOption(element.getAttribute("id")); + + owner.addOptionReference(this); + } + + /** + * Created from project file. + * + * @param owner + * @param element + */ + public OptionReference(ToolReference owner, Element element) { + this.owner = owner; + option = owner.getOption(element.getAttribute("id")); + + owner.addOptionReference(this); + } + + /** + * Write out to project file. + * + * @param doc + * @param element + */ + public void serealize(Document doc, Element element) { + element.setAttribute("id", option.getId()); + option = owner.getOption(element.getAttribute("id")); + } + /* (non-Javadoc) * @see org.eclipse.cdt.core.build.managed.IOption#getApplicableValues() */ public String[] getApplicableValues() { - // TODO Auto-generated method stub - return null; + return option.getApplicableValues(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.build.managed.IOption#getCategory() */ public IOptionCategory getCategory() { - // TODO Auto-generated method stub - return null; + return option.getCategory(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.build.managed.IBuildObject#getName() */ public String getName() { - // TODO Auto-generated method stub - return null; + return option.getName(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.build.managed.IOption#getStringListValue() */ - public String[] getStringListValue() { - // TODO Auto-generated method stub - return null; + public String[] getStringListValue() throws BuildException { + if (value == null) + return option.getStringListValue(); + else if (getValueType() == IOption.STRING_LIST) + return (String[])value; + else + throw new BuildException("bad value type"); } /* (non-Javadoc) * @see org.eclipse.cdt.core.build.managed.IOption#getStringValue() */ - public String getStringValue() { - // TODO Auto-generated method stub - return null; + public String getStringValue() throws BuildException { + if (value == null) + return option.getStringValue(); + else if (getValueType() == IOption.STRING) + return (String)value; + else + throw new BuildException("bad value type"); } /* (non-Javadoc) * @see org.eclipse.cdt.core.build.managed.IOption#getTool() */ public ITool getTool() { - // TODO Auto-generated method stub - return null; + return owner; } + public ToolReference getToolReference() { + return owner; + } + /* (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#setCategory(org.eclipse.cdt.core.build.managed.IOptionCategory) - */ - public void setCategory(IOptionCategory category) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.build.managed.IOption#setStringValue(org.eclipse.cdt.core.build.managed.IConfiguration, java.lang.String) - */ - public IOption setValue(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 setValue(IConfiguration config, String[] value) { - // TODO Auto-generated method stub - return null; + return option.getValueType(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.build.managed.IBuildObject#getId() */ public String getId() { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.build.managed.IBuildObject#setId(java.lang.String) - */ - public void setId(String id) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.build.managed.IBuildObject#setName(java.lang.String) - */ - public void setName(String name) { - // TODO Auto-generated method stub - + return option.getId(); } public boolean references(IOption target) { @@ -151,4 +159,17 @@ public class OptionReference implements IOption { return option.equals(target); } + public void setValue(String value) throws BuildException { + if (getValueType() == IOption.STRING) + this.value = value; + else + throw new BuildException("bad value type"); + } + + public void setValue(String [] value) throws BuildException { + if (getValueType() == IOption.STRING_LIST) + this.value = value; + else + throw new BuildException("bad value type"); + } } 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 3eab91f50f6..4799b0dc6d5 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 @@ -15,12 +15,10 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -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; import org.eclipse.core.runtime.IConfigurationElement; import org.w3c.dom.Document; @@ -45,15 +43,15 @@ public class Target extends BuildObject implements ITarget { } /** - * Create a target owned by a resource based on a parent target + * Create a target owned by a resource based on a parent target + * + * @param owner * @param parent */ public Target(IResource owner, ITarget parent) { this(owner); this.parent = parent; - inheritConfigs(); - // Copy the parent's identity setId(parent.getId()); setName(parent.getName()); @@ -80,13 +78,9 @@ public class Target extends BuildObject implements ITarget { // parent String parentId = element.getAttribute("parent"); - if (parentId != null) { + if (parentId != null) parent = ManagedBuildManager.getTarget(null, parentId); - // Inherit the configs from the parent - inheritConfigs(); - } - // isAbstract if ("true".equals(element.getAttribute("isAbstract"))) isAbstract = true; @@ -103,6 +97,12 @@ public class Target extends BuildObject implements ITarget { } + /** + * Create target from project file + * + * @param buildInfo + * @param element + */ public Target(ResourceBuildInfo buildInfo, Element element) { this(buildInfo.getOwner()); @@ -117,27 +117,30 @@ public class Target extends BuildObject implements ITarget { // parent String parentId = element.getAttribute("parent"); - if (parentId != null) { + if (parentId != null) parent = ManagedBuildManager.getTarget(null, parentId); - // Inherit the configs from the parent - inheritConfigs(); - } - // isAbstract if ("true".equals(element.getAttribute("isAbstract"))) isAbstract = true; - } - private void inheritConfigs() { - IConfiguration[] parentConfigs = parent.getConfigurations(); - if (parentConfigs.length > 0) - configurations = new ArrayList(parentConfigs.length); - for (int i = 0; i < parentConfigs.length; ++i) - configurations.add(new Configuration(parentConfigs[i])); - } + public void serialize(Document doc, Element element) { + element.setAttribute("id", getId()); + element.setAttribute("name", getName()); + if (parent != null) + element.setAttribute("parent", parent.getId()); + element.setAttribute("isAbstract", isAbstract ? "true" : "false"); + + if (configurations != null) + for (int i = 0; i < configurations.size(); ++i) { + Configuration config = (Configuration)configurations.get(i); + Element configElement = doc.createElement("configuration"); + config.serealize(doc, configElement); + } + } + public String getName() { return (name == null && parent != null) ? parent.getName() : name; } @@ -209,47 +212,25 @@ public class Target extends BuildObject implements ITarget { configurations.add(configuration); } - public IConfiguration createConfiguration() - throws BuildException - { - IConfiguration config = new Configuration(this); - addLocalConfiguration(config); - return config; - } - - public IConfiguration createConfiguration(IConfiguration parentConfig) - throws BuildException - { - IResource parentOwner = parentConfig.getOwner(); - - if (owner instanceof IProject) { - // parent must be owned by the same project - if (!owner.equals(parentOwner)) - throw new BuildException("addConfiguration: parent must be in same project"); - } else { - // parent must be owned by the project - if (!owner.getProject().equals(parentOwner)) - throw new BuildException("addConfiguration: parent must be in owning project"); - } - - // Validation passed - IConfiguration config = new Configuration(parentConfig); - addLocalConfiguration(config); - return config; - } - /* (non-Javadoc) * @see org.eclipse.cdt.core.build.managed.ITarget#isAbstract() */ public boolean isAbstract() { return isAbstract; } - - public void serialize(Document doc, Element element) { - element.setAttribute("id", getId()); - element.setAttribute("name", getName()); - if (parent != null) - element.setAttribute("parent", parent.getId()); + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.build.managed.ITarget#createConfiguration() + */ + public IConfiguration createConfiguration(String id) { + return new Configuration(this, id); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.build.managed.ITarget#createConfiguration(org.eclipse.cdt.core.build.managed.IConfiguration) + */ + public IConfiguration createConfiguration(IConfiguration parent, String id) { + return new Configuration(this, parent, id); } } diff --git a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/ToolReference.java b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/ToolReference.java index f261c89cdd6..ff1efc8761f 100644 --- a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/ToolReference.java +++ b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/ToolReference.java @@ -20,6 +20,8 @@ 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.core.runtime.IConfigurationElement; +import org.w3c.dom.Document; +import org.w3c.dom.Element; /** * @@ -31,11 +33,25 @@ public class ToolReference implements ITool { private List optionReferences; private Map optionRefMap; - public ToolReference(ITool parent, IConfiguration owner) { - this.parent = parent; + /** + * Created on the fly. + * + * @param owner + * @param parent + */ + public ToolReference(Configuration owner, ITool parent) { this.owner = owner; + this.parent = parent; + + owner.addToolReference(this); } + /** + * Created from extension. + * + * @param owner + * @param element + */ public ToolReference(Configuration owner, IConfigurationElement element) { this.owner = owner; @@ -51,6 +67,24 @@ public class ToolReference implements ITool { } } } + + public ToolReference(Configuration owner, Element element) { + } + + public void serealize(Document doc, Element element) { + element.setAttribute("id", parent.getId()); + + if (optionReferences != null) + for (int i = 0; i < optionReferences.size(); ++i) { + OptionReference optionRef = (OptionReference)optionReferences.get(i); + Element optionRefElement = doc.createElement("optionRef"); + optionRef.serealize(doc, optionRefElement); + } + } + + public IConfiguration getConfiguration() { + return owner; + } public ITool getTool() { return parent; @@ -144,6 +178,10 @@ public class ToolReference implements ITool { return null; } + public OptionReference createOptionReference(IOption option) { + return new OptionReference(this, option); + } + public void addOptionReference(OptionReference optionRef) { if (optionReferences == null) optionReferences = new ArrayList(); @@ -158,12 +196,4 @@ public class ToolReference implements ITool { return null; } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.build.managed.ITool#createOption(org.eclipse.cdt.core.build.managed.IConfiguration) - */ - public IOption createOption(IConfiguration config) { - // TODO Auto-generated method stub - return null; - } - }