diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/plugin.xml b/build/org.eclipse.cdt.managedbuilder.core.tests/plugin.xml index dc00361aaa6..0e896fce1d2 100644 --- a/build/org.eclipse.cdt.managedbuilder.core.tests/plugin.xml +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/plugin.xml @@ -38,7 +38,7 @@ name="String in Free" category="indy.cat.free" valueType="string" - id="org.eclipse.cdt.core.tests.option1"> + id="indy.cat.free.string"> + id="indy.cat.chained.boolean"> + + IOption from - * the receiver based on an ID. It is preferred that you use the newer method - * @see org.eclipse.cdt.core.build.managed.ITool#getOption(java.lang.String) + * the receiver based on an ID. It is preferred that you use the newer method + * getOptionById + * @see org.eclipse.cdt.core.build.managed.ITool#getOptionById(java.lang.String) * * @param id unique identifier of the option to search for * @return IOption diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java index e1f0ac094e7..4b2d76b3371 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java @@ -104,9 +104,10 @@ public class Configuration extends BuildObject implements IConfiguration { // Check that the tool and the project match IProject project = (IProject) target.getOwner(); - // Get the tool references from the parent - List parentToolRefs = ((Configuration)parentConfig).getLocalToolReferences(); - Iterator iter = parentToolRefs.listIterator(); + // Get the tool references from the target and parent + List allToolRefs = new Vector(target.getLocalToolReferences()); + allToolRefs.addAll(((Configuration)parentConfig).getLocalToolReferences()); + Iterator iter = allToolRefs.listIterator(); while (iter.hasNext()) { ToolReference toolRef = (ToolReference)iter.next(); @@ -231,35 +232,60 @@ public class Configuration extends BuildObject implements IConfiguration { * @return */ private OptionReference createOptionReference(IOption option) { + ToolReference searchRef = null; + ToolReference answer = null; // The option may already be a reference created to hold user settings if (option instanceof OptionReference) { // The option reference belongs to an existing tool reference OptionReference optionRef = (OptionReference)option; - ToolReference toolRef = optionRef.getToolReference(); + searchRef = optionRef.getToolReference(); + // That tool reference may belong to a target or to the configuration - if (toolRef.ownedByConfiguration(this)) + if (searchRef.ownedByConfiguration(this)) return optionRef; else { - // Make a copy so the settings can be saved - toolRef = new ToolReference(this, toolRef); - return toolRef.createOptionReference(option); + // All this means is that the tool ref does not belong to the receiver. + // The receiver may also have a reference to the tool + if ((answer = findLocalReference(searchRef)) == null) { + // Otherwise, create one and save the option setting in it + answer = new ToolReference(this, searchRef); + } + return answer.createOptionReference(option); } } else { // Find out if a tool reference already exists - ToolReference toolRef = (ToolReference) getToolReference(option.getTool()); - if (toolRef == null) { - toolRef = new ToolReference(this, option.getTool()); + searchRef = (ToolReference) getToolReference(option.getTool()); + if (searchRef == null) { + answer = new ToolReference(this, option.getTool()); } else { // The reference may belong to the target - if (!toolRef.ownedByConfiguration(this)) { - toolRef = new ToolReference(this, toolRef); + if (!searchRef.ownedByConfiguration(this)) { + answer = new ToolReference(this, searchRef); + } else { + answer = searchRef; } } - - return toolRef.createOptionReference(option); + return answer.createOptionReference(option); } } + /* (non-Javadoc) + * @param toolRef + * @return + */ + private ToolReference findLocalReference(ToolReference toolRef) { + Iterator iter = getLocalToolReferences().iterator(); + + while (iter.hasNext()) { + ToolReference ref = (ToolReference)iter.next(); + if (toolRef.getTool().equals(ref.getTool())) { + return ref; + } + } + + return null; + } + /* (non-Javadoc) * @see org.eclipse.cdt.managedbuilder.core.IConfiguration#getFilteredTools(org.eclipse.core.resources.IProject) */ diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Target.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Target.java index cfadb475490..d02ee97bf90 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Target.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Target.java @@ -502,7 +502,7 @@ public class Target extends BuildObject implements ITarget { * * @return List */ - private List getLocalToolReferences() { + protected List getLocalToolReferences() { if (toolReferences == null) { toolReferences = new ArrayList(); } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolReference.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolReference.java index 37c59a48a6f..f36cb2a77d7 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolReference.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolReference.java @@ -24,6 +24,7 @@ import org.eclipse.cdt.managedbuilder.core.IOptionCategory; import org.eclipse.cdt.managedbuilder.core.ITool; import org.eclipse.cdt.managedbuilder.core.IToolReference; import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; +import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -149,15 +150,19 @@ public class ToolReference implements IToolReference { * Created a tool reference on the fly based on an existing tool or tool reference. * * @param owner The BuildObject the receiver will be added to. - * @param parent The ITooltool the reference will be based on. + * @param tool The ITooltool the reference will be based on. */ - public ToolReference(BuildObject owner, ITool parent) { - this.parent = parent; + public ToolReference(BuildObject owner, ITool tool) { this.owner = owner; - command = parent.getToolCommand(); - outputFlag = parent.getOutputFlag(); - outputPrefix = parent.getOutputPrefix(); - String[] extensions = parent.getOutputExtensions(); + if (tool instanceof ToolReference) { + parent = ((ToolReference)tool).getTool(); + } else { + parent = tool; + } + command = tool.getToolCommand(); + outputFlag = tool.getOutputFlag(); + outputPrefix = tool.getOutputPrefix(); + String[] extensions = tool.getOutputExtensions(); outputExtensions = new String(); if (extensions != null) { for (int index = 0; index < extensions.length; ++index) { @@ -169,6 +174,34 @@ public class ToolReference implements IToolReference { } } + // Create a copy of the option references of the parent in the receiver + if (tool instanceof ToolReference) { + List parentRefs = ((ToolReference)tool).getOptionReferenceList(); + Iterator iter = parentRefs.iterator(); + while (iter.hasNext()) { + IOption parent = (IOption)iter.next(); + OptionReference clone = createOptionReference(parent); + try { + switch (parent.getValueType()) { + case IOption.BOOLEAN: + clone.setValue(parent.getBooleanValue()); + break; + case IOption.STRING: + clone.setValue(parent.getStringValue()); + case IOption.ENUMERATED: + clone.setValue(parent.getSelectedEnum()); + break; + default: + clone.setValue(parent.getStringListValue()); + break; + } + } catch (BuildException e) { + ManagedBuilderCorePlugin.log(e); + continue; + } + } + } + if (owner instanceof Configuration) { ((Configuration)owner).addToolReference(this); } else if (owner instanceof Target) { @@ -250,7 +283,14 @@ public class ToolReference implements IToolReference { public OptionReference createOptionReference(IOption option) { // Check if the option reference already exists OptionReference ref = getOptionReference(option); - if (ref == null) { + // It is possible that the search will return an option reference + // that is supplied by another element of the build model, not the caller. + // For example, if the search is starated by a configuration and the target + // the caller belongs to has an option reference for the option, it + // will be returned. While this is correct behaviour for a search, the + // caller will need to create a clone for itself, so make sure the tool + // reference of the search result is owned by the caller + if (ref == null || !ref.getToolReference().owner.equals(this.owner)) { ref = new OptionReference(this, option); } return ref; @@ -504,7 +544,6 @@ public class ToolReference implements IToolReference { public List getOptionReferenceList() { if (optionReferences == null) { optionReferences = new ArrayList(); - optionReferences.clear(); } return optionReferences; } diff --git a/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml b/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml index 9273f5ea98b..a1cc72c849e 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml +++ b/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml @@ -222,7 +222,7 @@ @@ -307,7 +307,7 @@ @@ -348,7 +348,7 @@ @@ -438,6 +438,27 @@ name="%Option.Posix.UndefSym" id="gnu.windres.option.preprocessor.undefined.symbols"/> + + + + +