From 0119b876950a205bdddabaad5e05a45b2a4dc387 Mon Sep 17 00:00:00 2001 From: Leo Treggiari Date: Mon, 6 Jun 2005 15:52:19 +0000 Subject: [PATCH] Apply Symbian (Lars & Bala) patch for Shared Tool Options support --- .../schema/buildDefinitions.exsd | 37 +- .../managedbuilder/core/IConfiguration.java | 21 +- .../managedbuilder/core/IHoldsOptions.java | 144 +++++ .../core/IManagedConfigElement.java | 2 +- .../core/IManagedOptionValueHandler.java | 110 ++++ .../cdt/managedbuilder/core/IOption.java | 48 +- .../core/IOptionApplicability.java | 38 +- .../managedbuilder/core/IOptionCategory.java | 30 +- .../core/IResourceConfiguration.java | 24 +- .../cdt/managedbuilder/core/ITool.java | 82 +-- .../cdt/managedbuilder/core/IToolChain.java | 4 +- .../core/ManagedBuildManager.java | 289 +++++++++- .../core/ManagedOptionValueHandler.java | 117 ++++ .../internal/core/Configuration.java | 45 +- .../internal/core/ConfigurationV2.java | 10 +- .../core/DefaultManagedConfigElement.java | 23 +- .../internal/core/HoldsOptions.java | 507 ++++++++++++++++++ .../internal/core/ManagedBuildInfo.java | 4 +- .../internal/core/ManagedProject.java | 4 + .../managedbuilder/internal/core/Option.java | 278 ++++++++-- .../internal/core/OptionCategory.java | 219 ++++++-- .../internal/core/OptionReference.java | 47 +- .../internal/core/PluginResources.properties | 4 + .../internal/core/ProjectType.java | 2 + .../internal/core/ResourceConfiguration.java | 35 +- .../managedbuilder/internal/core/Tool.java | 495 ++++++----------- .../internal/core/ToolChain.java | 377 +++++++------ .../internal/core/ToolReference.java | 155 +++--- .../internal/macros/MbsMacroSupplier.java | 16 +- .../internal/ui/ToolsSettingsBlock.java | 123 ++++- .../properties/BuildOptionSettingsPage.java | 132 +++-- .../ui/properties/BuildToolSettingsPage.java | 35 +- .../properties/BuildToolsSettingsStore.java | 33 +- .../properties/ToolListContentProvider.java | 40 +- .../ui/properties/ToolListLabelProvider.java | 68 ++- 35 files changed, 2675 insertions(+), 923 deletions(-) create mode 100644 build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IHoldsOptions.java create mode 100644 build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IManagedOptionValueHandler.java create mode 100644 build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedOptionValueHandler.java create mode 100644 build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/HoldsOptions.java diff --git a/build/org.eclipse.cdt.managedbuilder.core/schema/buildDefinitions.exsd b/build/org.eclipse.cdt.managedbuilder.core/schema/buildDefinitions.exsd index 51d9c2bdd40..a309483eeab 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/schema/buildDefinitions.exsd +++ b/build/org.eclipse.cdt.managedbuilder.core/schema/buildDefinitions.exsd @@ -267,6 +267,8 @@ + + @@ -594,6 +596,13 @@ + + + + Path to a 16x16 pixel big icon that is to be displayed instead of the default icon. The path is relative to the plug-in directory which defines .buildDefinitions. + + + @@ -912,7 +921,15 @@ - Option categories can belong to a tool or be nested inside other option categories. This is the ID of the owner of the category. + Option categories can belong to a tool, a toolChain or be nested inside other option categories. This is the ID of the owner of the category. + + + + + + + Path to a 16x16 pixel big icon that is to be displayed instead of the default icon. +The path is relative to the plug-in directory which defines .buildDefinitions. @@ -923,6 +940,7 @@ An option is associated with a tool. Options can contain boolean values, a simple text string, a selection from an enumerated list, or a list of values. Options also map the value they contain to a command-line flag, such as '-g' in the case of debugging symbol information for compilers. +Options can also be associated with a toolchain. However in such a case the option must be contained in a optionCategory. @@ -1080,6 +1098,23 @@ Additional special types exist to flag options of special relevance to the build + + + + The id of a class that implements the IManagedOptionValueHandler interface + + + + + + + + + + An optional extra text string that is passed into the valueHandler + + + diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IConfiguration.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IConfiguration.java index 8aa56652ce1..0ed711747f6 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IConfiguration.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IConfiguration.java @@ -383,43 +383,52 @@ public interface IConfiguration extends IBuildObject { /** * Sets the value of a boolean option for this configuration. * - * @param tool The Tool parent of the option. + * @param parent The holder/parent of the option. * @param option The option to change. * @param value The value to apply to the option. * * @return IOption The modified option. This can be the same option or a newly created option. * * @throws BuildException + * + * @since 3.0 - The type of parent has changed from ITool to IHoldsOptions. + * Code assuming ITool as type, will continue to work unchanged. */ - public IOption setOption(ITool tool, IOption option, boolean value) + public IOption setOption(IHoldsOptions parent, IOption option, boolean value) throws BuildException; /** * Sets the value of a string option for this configuration. * - * @param tool The Tool parent of the option. + * @param parent The holder/parent of the option. * @param option The option that will be effected by change. * @param value The value to apply to the option. * * @return IOption The modified option. This can be the same option or a newly created option. * * @throws BuildException + * + * @since 3.0 - The type of parent has changed from ITool to IHoldsOptions. + * Code assuming ITool as type, will continue to work unchanged. */ - public IOption setOption(ITool tool, IOption option, String value) + public IOption setOption(IHoldsOptions parent, IOption option, String value) throws BuildException; /** * Sets the value of a list option for this configuration. * - * @param tool The Tool parent of the option. + * @param parent The holder/parent of the option. * @param option The option to change. * @param value The values to apply to the option. * * @return IOption The modified option. This can be the same option or a newly created option. * * @throws BuildException + * + * @since 3.0 - The type of parent has changed from ITool to IHoldsOptions. + * Code assuming ITool as type, will continue to work unchanged. */ - public IOption setOption(ITool tool, IOption option, String[] value) + public IOption setOption(IHoldsOptions parent, IOption option, String[] value) throws BuildException; /** diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IHoldsOptions.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IHoldsOptions.java new file mode 100644 index 00000000000..00233ce04db --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IHoldsOptions.java @@ -0,0 +1,144 @@ +/********************************************************************** + * Copyright (c) 2005 Symbian Ltd and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Symbian Ltd - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.managedbuilder.core; + +/** + * Implements the functionality that is needed to hold options and option + * categories. The functionality has been moved from ITool to here in CDT 3.0. + * Backwards compatibility of interfaces has been maintained because ITool + * extends IHoldOptions. + * + * @since 3.0 + */ +public interface IHoldsOptions extends IBuildObject { + + public static final String OPTION = "option"; //$NON-NLS-1$ + public static final String OPTION_CAT = "optionCategory"; //$NON-NLS-1$ + public static final String OPTION_REF = "optionReference"; //$NON-NLS-1$ + /* + * M E T H O D S M O V E D F R O M I T O O L I N 3 . 0 + */ + + /** + * Creates a child Option + * + * @param Option The superClass, if any + * @param String The id for the new option + * @param String The name for the new option + * @param boolean Indicates whether this is an extension element or a managed project element + * + * @return IOption + */ + public IOption createOption(IOption superClass, String Id, String name, boolean isExtensionElement); + + /** + * Removes an option. + * + * @param option + */ + public void removeOption(IOption option); + + /** + * This is a deprecated method for retrieving an IOption from + * the receiver based on an ID. It is preferred that you use the newer method + * getOptionById + * @see org.eclipse.cdt.core.build.managed.IHoldsOptions#getOptionById(java.lang.String) + * + * @param id unique identifier of the option to search for + * @return IOption + * @deprecated use getOptionById() instead + */ + public IOption getOption(String id); + + /** + * Get the IOption in the receiver with the specified + * ID. This is an efficient search in the receiver. + * + *

If the receiver does not have an option with that ID, the method + * returns null. It is the responsibility of the caller to + * verify the return value. + * + * @param id unique identifier of the option to search for + * @return IOption + * @since 2.0 + */ + public IOption getOptionById(String id); + + /** + * Get the IOption in the receiver with the specified + * ID, or an option with a superclass with this id. + * + *

If the receiver does not have an option with that ID, the method + * returns null. It is the responsibility of the caller to + * verify the return value. + * + * @param id unique identifier of the option to search for + * @return IOption + * @since 3.0 + */ + public IOption getOptionBySuperClassId(String id); + + /** + * Returns the complete list of options that are available for this object. + * The list is a merging of the options specified for this object with the + * options of its superclasses. The lowest option instance in the hierarchy + * takes precedence. + * + * @return IOption[] + */ + public IOption[] getOptions(); + + /** + * Returns the option category children of this tool. + * + * @return IOptionCategory[] + */ + public IOptionCategory[] getChildCategories(); + + /* + * M E T H O D S M O V E D F R O M T O O L I N 3 . 0 + */ + + /** + * Adds the IOptionCategory to this Option Holder's + * list of Option Categories. + * + * @param category The option category to be added + * @return + */ + public void addOptionCategory(IOptionCategory category); + + /* + * N E W M E T H O D S A D D E D I N 3 . 0 + */ + + /** + * Answers the IOptionCategory that has the unique identifier + * specified in the argument. + * + * @param id The unique identifier of the option category + * @return IOptionCategory with the id specified in the argument + * @since 3.0 + */ + public IOptionCategory getOptionCategory(String id); + + /** + * Creates options from the superclass and adds it to this class. + * Each individual option in superclass, will become the superclass for + * the new option. + * + * @param IHoldsOptions The superClass + * @return + * @since 3.0 + */ + public void createOptions(IHoldsOptions superClass); + +} diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IManagedConfigElement.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IManagedConfigElement.java index 73c2873593c..20f11bf2084 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IManagedConfigElement.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IManagedConfigElement.java @@ -1,5 +1,5 @@ /********************************************************************** - * Copyright (c) 2004 TimeSys Corporation and others. + * Copyright (c) 2004, 2005 TimeSys Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IManagedOptionValueHandler.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IManagedOptionValueHandler.java new file mode 100644 index 00000000000..7917a411815 --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IManagedOptionValueHandler.java @@ -0,0 +1,110 @@ +/********************************************************************** + * Copyright (c) 2005 Symbian Ltd and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Symbian Ltd - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.managedbuilder.core; + +/** + * This interface represents an option value handler in the managed build + * system. It is used to enable a tool integrator to use the MBS configuration + * GUI, while linking to an alternative back-end. + * + * @since 3.0 + */ +public interface IManagedOptionValueHandler{ + + public final int EVENT_OPEN = 1; /** The option is opened, i.e. its UI element + * is created. The valueHandler can override + * the value of the option. If it does not, + * the last persisted value is used. */ + public final int EVENT_CLOSE = 2; /** The option is closed. i.e. its value has been + * destroyed when a configuration/resource gets deleted. + * The valuehandler can do various things assocaited with + * destroying the option such as freeing the memory + * associated with this option callback, if needed. */ + public final int EVENT_SETDEFAULT = 3; /** The default value option::defaultValue has + * been set. The handleValue callback is called + * afterwards to give the handler a chance to + * override the value or to update the value in + * its back-end. Typically this event will be called + * when the Restore Defaults button is pressed. */ + public final int EVENT_APPLY = 4; /** The option has been set by pressing the Apply + * button (or the OK button). The valueHandler can + * transfer the value of the option to its own + * back-end. */ + +/** + * Handles transfer between values between UI element and + * back-end in different circumstances. + * + * @param configuration build configuration of option + * (may be IConfiguration or IResourceConfiguration) + * @param holder contains the holder of the option + * @param option the option that is handled + * @param extraArgument extra argument for handler + * @param event event to be handled + * + * @return True when the event was handled, false otherwise. + * This enables default event handling can take place. + */ +boolean handleValue(IBuildObject configuration, + IHoldsOptions holder, + IOption option, + String extraArgument, + int event); + +/** + * Checks whether the value of an option is its default value. + * + * @param configuration build configuration of option + * (may be IConfiguration or IResourceConfiguration) + * @param holder contains the holder of the option + * @param option the option that is handled + * @param extraArgument extra argument for handler + * + * The additional options besides configuration are supplied to + * provide enough information for querying the default value from + * a potential data storage back-end. + * + * @return True if the options value is its default value and + * False otherwise. This enables that default event handling can + * take place. + */ +boolean isDefaultValue(IBuildObject configuration, + IHoldsOptions holder, + IOption option, + String extraArgument); + +/** + * Checks whether an enumeration value of an option is currently a + * valid choice. The use-case for this method is the case, where + * the set of valid enumerations in the plugin.xml file changes. + * The UI will remove entries from selection lists if the value + * returns false. + * + * @param configuration build configuration of option + * (may be IConfiguration or IResourceConfiguration) + * @param holder contains the holder of the option + * @param option the option that is handled + * @param extraArgument extra argument for handler + * @param enumValue enumeration value that is to be checked + * + * The additional options besides configuration are supplied to + * provide enough information for querying information from a + * a potential data storage back-end. + * + * @return True if the enumeration value is valid and False + * otherwise. + */ +boolean isEnumValueAppropriate(IBuildObject configuration, + IHoldsOptions holder, + IOption option, + String extraArgument, + String enumValue); +} diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IOption.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IOption.java index 601ad4f1ac9..28ecdcfb881 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IOption.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IOption.java @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.cdt.managedbuilder.core; + /** * */ @@ -60,17 +61,31 @@ public interface IOption extends IBuildObject { public static final String TYPE_DEFINED_SYMBOLS = "definedSymbols"; //$NON-NLS-1$ public static final String VALUE = "value"; //$NON-NLS-1$ public static final String VALUE_TYPE = "valueType"; //$NON-NLS-1$ + public static final String VALUE_HANDLER = "valueHandler"; //$NON-NLS-1$ + public static final String VALUE_HANDLER_EXTRA_ARGUMENT = "valueHandlerExtraArgument"; //$NON-NLS-1$ // Schema attribute names for listOptionValue elements public static final String LIST_ITEM_VALUE = "value"; //$NON-NLS-1$ public static final String LIST_ITEM_BUILTIN = "builtIn"; //$NON-NLS-1$ /** - * Returns the tool defining this option. - * - * @return ITool + * Returns the parent of this option. This is an object implementing ITool + * or IToolChain. + * + * @return IBuildObject + * @since 3.0 - changed return type from ITool to IBuildObject. The method returns + * the same object as getOptionHolder(). It is included as a convenience for clients. */ - public ITool getParent(); + public IBuildObject getParent(); + + /** + * Returns the holder (parent) of this option. This may be an object + * implenting ITool or IToolChain, which both extend IHoldsOptions + * + * @return IHoldsOptions + * @since 3.0 + */ + public IHoldsOptions getOptionHolder(); /** * Returns the IOption that is the superclass of this @@ -346,6 +361,20 @@ public interface IOption extends IBuildObject { */ public void setValueType(int type); + /** + * Returns the value handler specified for this tool. + * @return IManagedOptionValueHandler + * @since 3.0 + */ + public IManagedOptionValueHandler getValueHandler(); + + /** + * Returns the value handlers extra argument specified for this tool + * @return String + * @since 3.0 + */ + public String getValueHandlerExtraArgument(); + /** * Returns true if this option was loaded from a manifest file, * and false if it was loaded from a project (.cdtbuild) file. @@ -361,4 +390,15 @@ public interface IOption extends IBuildObject { * @return boolean */ public boolean overridesOnlyValue(); + + /** + * Returns true if this option is valid and false + * if the option cannot be safely used due to an error in the MBS grammar. + * + * @return boolean + * @since 3.0 + * + * @pre Can only be used after Ids in MBS grammar have been resolved by pointers. + */ + public boolean isValid(); } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IOptionApplicability.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IOptionApplicability.java index 8559c5171df..3c2c10f3389 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IOptionApplicability.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IOptionApplicability.java @@ -20,22 +20,34 @@ public interface IOptionApplicability { * generated which uses this option, and in the C/C++ Build property * pages when displaying the current command line. * - * @param toolParent The parent tool for this option. This provides - * a context for obtaining other information from the MBS - * @return true if this this option is to be used in command line + * @param configuration build configuration of option + * (may be IConfiguration or IResourceConfiguration) + * @param holder contains the holder of the option + * @param option the option itself + * + * @return true if this option is to be used in command line * generation, false otherwise */ - public boolean isOptionUsedInCommandLine(ITool toolParent); + public boolean isOptionUsedInCommandLine( + IBuildObject configuration, + IHoldsOptions holder, + IOption option); /** * This method is queried whenever a new option category is displayed. * - * @param toolParent The parent tool for this option. This provides - * a context for obtaining other information from the MBS + * @param configuration build configuration of option + * (may be IConfiguration or IResourceConfiguration) + * @param holder contains the holder of the option + * @param option the option itself + * * @return true if this option should be visible in the build options page, * false otherwise */ - public boolean isOptionVisible(ITool toolParent); + public boolean isOptionVisible( + IBuildObject configuration, + IHoldsOptions holder, + IOption option); /** * Whenever the value of an option changes in the GUI, this method is @@ -43,11 +55,17 @@ public interface IOptionApplicability { * this occurs when the GUI changes - the user may opt to cancel these * changes. * - * @param toolParent The parent tool for this option. This provides - * a context for obtaining other information from the MBS + * @param configuration build configuration of option + * (may be IConfiguration or IResourceConfiguration) + * @param holder contains the holder of the option + * @param option the option itself + * * @return true if this option should be enabled in the build options page, * or false if it should be disabled (grayed out) */ - public boolean isOptionEnabled(ITool toolParent); + public boolean isOptionEnabled( + IBuildObject configuration, + IHoldsOptions holder, + IOption option); } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IOptionCategory.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IOptionCategory.java index f8bd5a00b9d..5c55a26d14a 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IOptionCategory.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IOptionCategory.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2004 IBM Corporation and others. + * Copyright (c) 2003, 2005 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at @@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.cdt.managedbuilder.core; +import java.net.URL; + /** * */ @@ -17,6 +19,7 @@ public interface IOptionCategory extends IBuildObject { // Schema element names public static final String OWNER = "owner"; //$NON-NLS-1$ + public static final String ICON = "icon"; //$NON-NLS-1$ // Resource Filter type public static final int FILTER_ALL = 0; @@ -52,11 +55,36 @@ public interface IOptionCategory extends IBuildObject { /** * Returns the tool that ultimately owns this category. + * If owned by a toolChain return null. * * @return + * @deprecated since 3.0 - use getOptionHolder() instead */ public ITool getTool(); + /** + * Returns the holder (parent) of this category. This may be an object + * implementing ITool or IToolChain, which both extend IHoldsOptions. + * The call can return null, for example the top option category of a tool + * will return null. + * + * Note that the name getOptionHolder() has been choosen, because Tool implements + * both ITool and IOptionCategory and ITool.getParent() exists already. + * + * @return IHoldsOptions + * @since 3.0 + */ + public IHoldsOptions getOptionHolder(); + + /** + * Get the path name of an alternative icon for the option group. + * Or null if no alternative icon was defined. + * + * @return URL + * @since 3.0 + */ + public URL getIconPath(); + /** * Returns true if this element has changes that need to * be saved in the project file, else false. diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IResourceConfiguration.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IResourceConfiguration.java index 431a5af65ec..a26ba57a70b 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IResourceConfiguration.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IResourceConfiguration.java @@ -1,5 +1,5 @@ /********************************************************************** - * Copyright (c) 2004 Intel Corporation and others. + * Copyright (c) 2004, 2005 Intel Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at @@ -118,46 +118,56 @@ public interface IResourceConfiguration extends IBuildObject { * @param command The command */ public void setToolCommand(ITool tool, String command); + /** * Sets the value of a boolean option for this resource configuration. * - * @param tool The Tool parent of the option. + * @param parent The holder/parent of the option. * @param option The option to change. * @param value The value to apply to the option. * * @return IOption The modified option. This can be the same option or a newly created option. * * @throws BuildException + * + * @since 3.0 - The type of parent has changed from ITool to IHoldsOptions. + * Code assuming ITool as type, will continue to work unchanged. */ - public IOption setOption(ITool tool, IOption option, boolean value) + public IOption setOption(IHoldsOptions parent, IOption option, boolean value) throws BuildException; /** * Sets the value of a string option for this resource configuration. * - * @param tool The Tool parent of the option. + * @param parent The holder/parent of the option. * @param option The option that will be effected by change. * @param value The value to apply to the option. * * @return IOption The modified option. This can be the same option or a newly created option. * * @throws BuildException + * + * @since 3.0 - The type of parent has changed from ITool to IHoldsOptions. + * Code assuming ITool as type, will continue to work unchanged. */ - public IOption setOption(ITool tool, IOption option, String value) + public IOption setOption(IHoldsOptions parent, IOption option, String value) throws BuildException; /** * Sets the value of a list option for this resource configuration. * - * @param tool The Tool parent of the option. + * @param parent The holder/parent of the option. * @param option The option to change. * @param value The values to apply to the option. * * @return IOption The modified option. This can be the same option or a newly created option. * * @throws BuildException + * + * @since 3.0 - The type of parent has changed from ITool to IHoldsOptions. + * Code assuming ITool as type, will continue to work unchanged. */ - public IOption setOption(ITool tool, IOption option, String[] value) + public IOption setOption(IHoldsOptions parent, IOption option, String[] value) throws BuildException; diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ITool.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ITool.java index 3017afa4684..bbd4f065223 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ITool.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ITool.java @@ -22,7 +22,7 @@ import org.eclipse.cdt.managedbuilder.makegen.IManagedDependencyGenerator; * A tool will generally process one or more resources to produce output resources. * Most tools have a set of options that can be used to modify the behavior of the tool. */ -public interface ITool extends IBuildObject { +public interface ITool extends IBuildObject, IHoldsOptions { // Schema element names public static final String COMMAND = "command"; //$NON-NLS-1$ public static final String COMMAND_LINE_PATTERN = "commandLinePattern"; //$NON-NLS-1$ @@ -30,9 +30,6 @@ public interface ITool extends IBuildObject { public static final String DEP_CALC_ID ="dependencyCalculator"; //$NON-NLS-1$ public static final String INTERFACE_EXTS = "headerExtensions"; //$NON-NLS-1$ public static final String NATURE = "natureFilter"; //$NON-NLS-1$ - public static final String OPTION = "option"; //$NON-NLS-1$ - public static final String OPTION_CAT = "optionCategory"; //$NON-NLS-1$ - public static final String OPTION_REF = "optionReference"; //$NON-NLS-1$ public static final String OUTPUT_FLAG = "outputFlag"; //$NON-NLS-1$ public static final String INPUT_TYPE = "inputType"; //$NON-NLS-1$ public static final String OUTPUT_TYPE = "outputType"; //$NON-NLS-1$ @@ -60,74 +57,6 @@ public interface ITool extends IBuildObject { */ public IBuildObject getParent(); - /** - * Creates a child Option for this tool. - * - * @param Option The superClass, if any - * @param String The id for the new option - * @param String The name for the new option - * @param boolean Indicates whether this is an extension element or a managed project element - * - * @return IOption - */ - public IOption createOption(IOption superClass, String Id, String name, boolean isExtensionElement); - - /** - * Removes an option from the tool's list. - * - * @param option - */ - public void removeOption(IOption option); - - /** - * This is a deprecated method for retrieving an IOption from - * 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 - */ - public IOption getOption(String id); - - /** - * Get the IOption in the receiver with the specified - * ID. This is an efficient search in the receiver. - * - *

If the receiver does not have an option with that ID, the method - * returns null. It is the responsibility of the caller to - * verify the return value. - * - * @param id unique identifier of the option to search for - * @return IOption - * @since 2.0 - */ - public IOption getOptionById(String id); - - /** - * Get the IOption in the receiver with the specified - * ID, or an option with a superclass with this id. - * - *

If the receiver does not have an option with that ID, the method - * returns null. It is the responsibility of the caller to - * verify the return value. - * - * @param id unique identifier of the option to search for - * @return IOption - * @since 3.0 - */ - public IOption getOptionBySuperClassId(String id); - - /** - * Returns the complete list of options that are available for this tool. - * The list is a merging of the options specified for this tool with the - * options of its superclasses. The lowest option instance in the hierarchy - * takes precedence. - * - * @return IOption[] - */ - public IOption[] getOptions(); - /** * Creates a child InputType for this tool. * @@ -696,14 +625,7 @@ public interface ITool extends IBuildObject { * * @return IOptionCategory */ - public IOptionCategory getTopOptionCategory(); - - /** - * Returns the option category children of this tool. - * - * @return IOptionCategory[] - */ - public IOptionCategory[] getChildCategories(); + public IOptionCategory getTopOptionCategory(); /** * Return true if the receiver builds files with the diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IToolChain.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IToolChain.java index 1011e74a34a..b0076c00dc5 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IToolChain.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IToolChain.java @@ -30,7 +30,7 @@ import org.eclipse.cdt.managedbuilder.macros.IConfigurationBuildMacroSupplier; * * @since 2.1 */ -public interface IToolChain extends IBuildObject { +public interface IToolChain extends IBuildObject, IHoldsOptions { public static final String TOOL_CHAIN_ELEMENT_NAME = "toolChain"; //$NON-NLS-1$ public static final String OS_LIST = "osList"; //$NON-NLS-1$ public static final String ARCH_LIST = "archList"; //$NON-NLS-1$ @@ -354,7 +354,7 @@ public interface IToolChain extends IBuildObject { * @return IConfigurationEnvironmentVariableSupplier */ public IConfigurationEnvironmentVariableSupplier getEnvironmentVariableSupplier(); - + /** * Returns the tool-integrator provided implementation of the configuration build macro supplier * or null if none. diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java index 6187937d7dd..a245368246c 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java @@ -24,6 +24,7 @@ import java.util.List; import java.util.ListIterator; import java.util.Map; import java.util.Random; +import java.net.URL; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -77,6 +78,7 @@ import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtension; import org.eclipse.core.runtime.IExtensionPoint; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.PluginVersionIdentifier; @@ -88,6 +90,7 @@ import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; +import org.osgi.framework.Bundle; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -114,6 +117,14 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI private static final String MANIFEST_ERROR_HEADER = "ManagedBuildManager.error.manifest.header"; //$NON-NLS-1$ public static final String MANIFEST_ERROR_RESOLVING = "ManagedBuildManager.error.manifest.resolving"; //$NON-NLS-1$ public static final String MANIFEST_ERROR_DUPLICATE = "ManagedBuildManager.error.manifest.duplicate"; //$NON-NLS-1$ + public static final String MANIFEST_ERROR_ICON = "ManagedBuildManager.error.manifest.icon"; //$NON-NLS-1$ + private static final String MANIFEST_ERROR_OPTION_CATEGORY = "ManagedBuildManager.error.manifest.option.category"; //$NON-NLS-1$ + private static final String MANIFEST_ERROR_OPTION_FILTER = "ManagedBuildManager.error.manifest.option.filter"; //$NON-NLS-1$ + private static final String MANIFEST_ERROR_OPTION_VALUEHANDLER = "ManagedBuildManager.error.manifest.option.valuehandler"; //$NON-NLS-1$ + // Error ID's for OptionValidError() + public static final int ERROR_CATEGORY = 0; + public static final int ERROR_FILTER = 1; + private static final String NEWLINE = System.getProperty("line.separator"); //$NON-NLS-1$ // This is the version of the manifest and project files @@ -707,19 +718,24 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI } /** - * Set the string value for an option for a given config. + * Set the boolean value for an option for a given config. * * @param config The configuration the option belongs to. + * @param holder The holder/parent of the option. * @param option The option to set the value for. * @param value The boolean that the option should contain after the change. * * @return IOption The modified option. This can be the same option or a newly created option. + * + * @since 3.0 - The type and name of the ITool tool parameter + * has changed to IHoldsOptions holder. Client code + * assuming ITool as type, will continue to work unchanged. */ - public static IOption setOption(IConfiguration config, ITool tool, IOption option, boolean value) { + public static IOption setOption(IConfiguration config, IHoldsOptions holder, IOption option, boolean value) { IOption retOpt; try { // Request a value change and set dirty if real change results - retOpt = config.setOption(tool, option, value); + retOpt = config.setOption(holder, option, value); notifyListeners(config, option); } catch (BuildException e) { return null; @@ -727,11 +743,25 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI return retOpt; } - public static IOption setOption(IResourceConfiguration resConfig, ITool tool, IOption option, boolean value) { + /** + * Set the boolean value for an option for a given config. + * + * @param resConfig The resource configuration the option belongs to. + * @param holder The holder/parent of the option. + * @param option The option to set the value for. + * @param value The boolean that the option should contain after the change. + * + * @return IOption The modified option. This can be the same option or a newly created option. + * + * @since 3.0 - The type and name of the ITool tool parameter + * has changed to IHoldsOptions holder. Client code + * assuming ITool as type, will continue to work unchanged. + */ + public static IOption setOption(IResourceConfiguration resConfig, IHoldsOptions holder, IOption option, boolean value) { IOption retOpt; try { // Request a value change and set dirty if real change results - retOpt = resConfig.setOption(tool, option, value); + retOpt = resConfig.setOption(holder, option, value); notifyListeners(resConfig, option); } catch (BuildException e) { return null; @@ -742,15 +772,20 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI * Set the string value for an option for a given config. * * @param config The configuration the option belongs to. + * @param holder The holder/parent of the option. * @param option The option to set the value for. * @param value The value that the option should contain after the change. * * @return IOption The modified option. This can be the same option or a newly created option. + * + * @since 3.0 - The type and name of the ITool tool parameter + * has changed to IHoldsOptions holder. Client code + * assuming ITool as type, will continue to work unchanged. */ - public static IOption setOption(IConfiguration config, ITool tool, IOption option, String value) { + public static IOption setOption(IConfiguration config, IHoldsOptions holder, IOption option, String value) { IOption retOpt; try { - retOpt = config.setOption(tool, option, value); + retOpt = config.setOption(holder, option, value); notifyListeners(config, option); } catch (BuildException e) { return null; @@ -762,15 +797,20 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI * Set the string value for an option for a given resource config. * * @param resConfig The resource configuration the option belongs to. + * @param holder The holder/parent of the option. * @param option The option to set the value for. * @param value The value that the option should contain after the change. * * @return IOption The modified option. This can be the same option or a newly created option. + * + * @since 3.0 - The type and name of the ITool tool parameter + * has changed to IHoldsOptions holder. Client code + * assuming ITool as type, will continue to work unchanged. */ - public static IOption setOption(IResourceConfiguration resConfig, ITool tool, IOption option, String value) { + public static IOption setOption(IResourceConfiguration resConfig, IHoldsOptions holder, IOption option, String value) { IOption retOpt; try { - retOpt = resConfig.setOption(tool, option, value); + retOpt = resConfig.setOption(holder, option, value); notifyListeners(resConfig, option); } catch (BuildException e) { return null; @@ -781,15 +821,20 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI * Set the string array value for an option for a given config. * * @param config The configuration the option belongs to. + * @param holder The holder/parent of the option. * @param option The option to set the value for. * @param value The values the option should contain after the change. * * @return IOption The modified option. This can be the same option or a newly created option. + * + * @since 3.0 - The type and name of the ITool tool parameter + * has changed to IHoldsOptions holder. Client code + * assuming ITool as type, will continue to work unchanged. */ - public static IOption setOption(IConfiguration config, ITool tool, IOption option, String[] value) { + public static IOption setOption(IConfiguration config, IHoldsOptions holder, IOption option, String[] value) { IOption retOpt; try { - retOpt = config.setOption(tool, option, value); + retOpt = config.setOption(holder, option, value); notifyListeners(config, option); } catch (BuildException e) { return null; @@ -801,15 +846,20 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI * Set the string array value for an option for a given resource config. * * @param resConfig The resource configuration the option belongs to. + * @param holder The holder/parent of the option. * @param option The option to set the value for. * @param value The values the option should contain after the change. * * @return IOption The modified option. This can be the same option or a newly created option. + * + * @since 3.0 - The type and name of the ITool tool parameter + * has changed to IHoldsOptions holder. Client code + * assuming ITool as type, will continue to work unchanged. */ - public static IOption setOption(IResourceConfiguration resConfig, ITool tool, IOption option, String[] value) { + public static IOption setOption(IResourceConfiguration resConfig, IHoldsOptions holder, IOption option, String[] value) { IOption retOpt; try { - retOpt = resConfig.setOption(tool, option, value); + retOpt = resConfig.setOption(holder, option, value); notifyListeners(resConfig, option); } catch (BuildException e) { return null; @@ -831,7 +881,7 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI config.setToolCommand(tool, command); } } - + public static void setToolCommand(IResourceConfiguration resConfig, ITool tool, String command) { // The tool may be a reference. if (tool instanceof IToolReference) { @@ -1340,6 +1390,11 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI throw new Exception(ManagedMakeMessages.getFormattedString("ManagedBuildManager.error.id.nomatch", project.getName())); //$NON-NLS-1$ } project.setSessionProperty(buildInfoProperty, buildInfo); + IConfiguration[] configs = buildInfo.getManagedProject().getConfigurations(); + // Send an event to each configuration and if they exist, its resource configurations + for (int i=0; i < configs.length; ++i) { + ManagedBuildManager.performValueHandlerEvent(configs[i], IManagedOptionValueHandler.EVENT_OPEN); + } } } catch (Exception e) { throw e; @@ -1421,8 +1476,8 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI } } - // Get the value of 'ManagedBuilRevision' attribute - loadConfigElements(DefaultManagedConfigElement.convertArray(elements), revision); + // Get the value of 'ManagedBuildRevision' attribute + loadConfigElements(DefaultManagedConfigElement.convertArray(elements, extension), revision); } } // Then call resolve. @@ -1567,7 +1622,7 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI // If the "fileVersion" attribute is missing, then default revision is "1.2.0" if (revision == null) revision = "1.2.0"; //$NON-NLS-1$ - loadConfigElementsV2(DefaultManagedConfigElement.convertArray(elements), revision); + loadConfigElementsV2(DefaultManagedConfigElement.convertArray(elements, extension), revision); } // Resolve references Iterator targetIter = getExtensionTargetMap().values().iterator(); @@ -1937,6 +1992,57 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI return buildInfoVersion; } + /** + * Get the full URL for a path that is relative to the plug-in + * in which .buildDefinitions are defined + * + * @return the full URL for a path relative to the .buildDefinitions + * plugin + */ + public static URL getURLInBuildDefinitions(DefaultManagedConfigElement element, IPath path) { + + IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(EXTENSION_POINT_ID); + if( extensionPoint != null) { + IExtension[] extensions = extensionPoint.getExtensions(); + if (extensions != null) { + + // Iterate over all extensions that contribute to .buildDefinitions + for (int i = 0; i < extensions.length; ++i) { + IExtension extension = extensions[i]; + + // Determine whether the configuration element that is + // associated with the path, is valid for the extension that + // we are currently processing. + // + // Note: If not done, icon file names would have to be unique + // across several plug-ins. + if (element.getExtension().getExtensionPointUniqueIdentifier() + == extension.getExtensionPointUniqueIdentifier()) + { + // Get the path-name + Bundle bundle = Platform.getBundle( extension.getNamespace() ); + URL url = Platform.find(bundle, path); + if ( url != null ) + { + try { + return Platform.asLocalURL(url); + } catch (IOException e) { + // Ignore the exception + return null; + } + } + else + { + // Print a warning + OutputIconError(path.toString()); + } + } + } + } + } + return null; + } + /* * @return */ @@ -2032,6 +2138,29 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI return (IManagedConfigElement)getConfigElementMap().get(buildObj); } + public static void OptionValidError(int errorId, String id) { + String[] msgs = new String[1]; + msgs[0] = id; + switch (errorId) { + case ERROR_CATEGORY: + ManagedBuildManager.OutputManifestError( + ManagedMakeMessages.getFormattedString(ManagedBuildManager.MANIFEST_ERROR_OPTION_CATEGORY, msgs)); + break; + case ERROR_FILTER: + ManagedBuildManager.OutputManifestError( + ManagedMakeMessages.getFormattedString(ManagedBuildManager.MANIFEST_ERROR_OPTION_FILTER, msgs)); + break; + } + } + + public static void OptionValueHandlerError(String attribute, String id) { + String[] msgs = new String[2]; + msgs[0] = attribute; + msgs[1] = id; + ManagedBuildManager.OutputManifestError( + ManagedMakeMessages.getFormattedString(ManagedBuildManager.MANIFEST_ERROR_OPTION_VALUEHANDLER, msgs)); + } + public static void OutputResolveError(String attribute, String lookupId, String type, String id) { String[] msgs = new String[4]; msgs[0] = attribute; @@ -2054,6 +2183,13 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI System.err.println(ManagedMakeMessages.getResourceString(MANIFEST_ERROR_HEADER) + message + NEWLINE); } + public static void OutputIconError(String iconLocation) { + String[] msgs = new String[1]; + msgs[0]= iconLocation; + ManagedBuildManager.OutputManifestError( + ManagedMakeMessages.getFormattedString(ManagedBuildManager.MANIFEST_ERROR_ICON, msgs)); + } + /** * Returns the instance of the Environment Variable Provider * @@ -2119,4 +2255,123 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI public static IBuildMacroProvider getBuildMacroProvider(){ return BuildMacroProvider.getDefault(); } + + /** + * Send event to value handlers of relevant configuration including + * all its child resource configurations, if they exist. + * + * @param IConfiguration configuration for which to send the event + * @param event to be sent + * + * @since 3.0 + */ + public static void performValueHandlerEvent(IConfiguration config, int event) { + performValueHandlerEvent(config, event, true); + } + + /** + * Send event to value handlers of relevant configuration. + * + * @param IConfiguration configuration for which to send the event + * @param event to be sent + * @param doChildren - if true, also perform the event for all + * resource configurations that are children if this configuration. + * + * @since 3.0 + */ + public static void performValueHandlerEvent(IConfiguration config, int event, boolean doChildren) { + + IToolChain toolChain = config.getToolChain(); + if (toolChain == null) + return; + + IOption[] options = toolChain.getOptions(); + // Get global options directly under Toolchain (not associated with a particular tool) + // This has to be sent to all the Options associated with this configuration. + for (int i = 0; i < options.length; ++i) { + // Ignore invalid options + if (options[i].isValid()) { + // Call the handler + if (options[i].getValueHandler().handleValue( + config, + options[i].getOptionHolder(), + options[i], + options[i].getValueHandlerExtraArgument(), + event)) { + // TODO : Event is handled successfully and returned true. + // May need to do something here say logging a message. + } else { + // Event handling Failed. + } + } + } + + // Get options associated with tools under toolChain + ITool[] tools = toolChain.getTools(); + for (int i = 0; i < tools.length; ++i) { + IOption[] toolOptions = tools[i].getOptions(); + for (int j = 0; j < toolOptions.length; ++j) { + // Ignore invalid options + if (toolOptions[j].isValid()) { + // Call the handler + if (toolOptions[j].getValueHandler().handleValue( + config, + toolOptions[j].getOptionHolder(), + toolOptions[j], + toolOptions[j].getValueHandlerExtraArgument(), + event)) { + // TODO : Event is handled successfully and returned true. + // May need to do something here say logging a message. + } else { + // Event handling Failed. + } + } + } + } + + // Call backs for Resource Configurations associated with this config. + if (doChildren == true) { + IResourceConfiguration[] resConfigs = config.getResourceConfigurations(); + for (int j=0; j < resConfigs.length; ++j) { + ManagedBuildManager.performValueHandlerEvent(resConfigs[j], event); + } + } + } + + /** + * Send event to value handlers of relevant configuration. + * + * @param IResourceConfiguration configuration for which to send the event + * @param event to be sent + * + * @since 3.0 + */ + public static void performValueHandlerEvent(IResourceConfiguration config, int event) { + + // Note: Resource configurations have no toolchain options + + // Get options associated with the resource configuration + ITool[] tools = config.getTools(); + for (int i = 0; i < tools.length; ++i) { + IOption[] toolOptions = tools[i].getOptions(); + for (int j = 0; j < toolOptions.length; ++j) { + // Ignore invalid options + if (toolOptions[j].isValid()) { + // Call the handler + if (toolOptions[j].getValueHandler().handleValue( + config, + toolOptions[j].getOptionHolder(), + toolOptions[j], + toolOptions[j].getValueHandlerExtraArgument(), + event)) { + // TODO : Event is handled successfully and returned true. + // May need to do something here say logging a message. + } else { + // Event handling Failed. + } + } + } + } + } + } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedOptionValueHandler.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedOptionValueHandler.java new file mode 100644 index 00000000000..13048f27a08 --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedOptionValueHandler.java @@ -0,0 +1,117 @@ +/********************************************************************** + * Copyright (c) 2005 Symbian Ltd and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Symbian Ltd - Initial API and implementation + **********************************************************************/ + +package org.eclipse.cdt.managedbuilder.core; + + +/** + * This class implements the default managed option value handler for MBS. + * It is also be intended to be used as a base class for other value handlers. + */ +public class ManagedOptionValueHandler implements + IManagedOptionValueHandler { + + /* + * E N A B L E U S E A S B A S E C L A S S A N D + * D E F A U L T I M P L E M E N T A T I O N + */ + + private static ManagedOptionValueHandler mbsValueHandler; + + protected ManagedOptionValueHandler() { + mbsValueHandler = null; + } + + public static ManagedOptionValueHandler getManagedOptionValueHandler() { + if( mbsValueHandler == null ) { + mbsValueHandler = new ManagedOptionValueHandler(); + } + return mbsValueHandler; + } + + /* + * D E F A U L T I M P L E M E N T A T I O N S O F I N T E R F A C E + */ + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.core.IManagedOptionValueHandler#handleValue(IConfiguration,IToolChain,IOption,String,int) + */ + public boolean handleValue(IBuildObject configuration, + IHoldsOptions holder, + IOption option, + String extraArgument, int event) + { + /* + // The following is for debug purposes and thus normally commented out + String configLabel = "???"; //$NON-NLS-1$ + String holderLabel = "???"; //$NON-NLS-1$ + String eventLabel = "???"; //$NON-NLS-1$ + + if (configuration instanceof IConfiguration) { + configLabel = "IConfiguration"; //$NON-NLS-1$ + } else if (configuration instanceof IResourceConfiguration) { + configLabel = "IResourceConfiguration"; //$NON-NLS-1$ + } + + if (holder instanceof IToolChain) { + holderLabel = "IToolChain"; //$NON-NLS-1$ + } else if (holder instanceof ITool) { + holderLabel = "ITool"; //$NON-NLS-1$ + } + + switch (event) { + case EVENT_OPEN: eventLabel = "EVENT_OPEN"; break; //$NON-NLS-1$ + case EVENT_APPLY: eventLabel = "EVENT_APPLY"; break; //$NON-NLS-1$ + case EVENT_SETDEFAULT: eventLabel = "EVENT_SETDEFAULT"; break; //$NON-NLS-1$ + case EVENT_CLOSE: eventLabel = "EVENT_CLOSE"; break; //$NON-NLS-1$ + } + + // Print the event + System.out.println(eventLabel + "(" + //$NON-NLS-1$ + configLabel + " = " + //$NON-NLS-1$ + configuration.getId() + ", " + //$NON-NLS-1$ + holderLabel + " = " + //$NON-NLS-1$ + holder.getId() + ", " + //$NON-NLS-1$ + "IOption = " + //$NON-NLS-1$ + option.getId() + ", " + //$NON-NLS-1$ + "String = " + //$NON-NLS-1$ + extraArgument + ")"); //$NON-NLS-1$ + */ + // The event was not handled, thus return false + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.core.IManagedOptionValueHandler#isDefaultValue(IConfiguration,IToolChain,IOption,String) + */ + public boolean isDefaultValue(IBuildObject configuration, + IHoldsOptions holder, + IOption option, String extraArgument) { + // Implement default behavior + if (option.getDefaultValue() == option.getValue()) { + return true; + } else { + return false; + } + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.core.IManagedOptionValueHandler#isEnumValueAppropriate(IConfiguration,IToolChain,IOption,String,String) + */ + public boolean isEnumValueAppropriate(IBuildObject configuration, + IHoldsOptions holder, + IOption option, + String extraArgument, String enumValue) + { + // By default return true for all the enum values. + return true; + } +} 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 46b6a1418b3..ffef1e7ff35 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 @@ -24,7 +24,9 @@ import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CProjectNature; import org.eclipse.cdt.managedbuilder.core.BuildException; import org.eclipse.cdt.managedbuilder.core.IConfiguration; +import org.eclipse.cdt.managedbuilder.core.IHoldsOptions; import org.eclipse.cdt.managedbuilder.core.IManagedConfigElement; +import org.eclipse.cdt.managedbuilder.core.IManagedOptionValueHandler; import org.eclipse.cdt.managedbuilder.core.IOption; import org.eclipse.cdt.managedbuilder.core.IProjectType; import org.eclipse.cdt.managedbuilder.core.IManagedProject; @@ -218,9 +220,9 @@ public class Configuration extends BuildObject implements IConfiguration { * @param managedProject The ManagedProject the configuration will be added to. * @param cloneConfig The IConfiguration to copy the settings from. * @param id A unique ID for the new configuration. - * @param cloneTools If true, the configuration's tools are cloned + * @param cloneChildren If true, the configuration's tools are cloned */ - public Configuration(ManagedProject managedProject, Configuration cloneConfig, String id, boolean cloneTools) { + public Configuration(ManagedProject managedProject, Configuration cloneConfig, String id, boolean cloneChildren) { setId(id); setName(cloneConfig.getName()); this.managedProject = managedProject; @@ -274,7 +276,7 @@ public class Configuration extends BuildObject implements IConfiguration { tmpId = cloneConfig.getToolChain().getId(); subName = cloneConfig.getToolChain().getName(); } - + String version = ManagedBuildManager.getVersionFromIdAndVersion(tmpId); if ( version != null) { // If the 'tmpId' contains version information subId = ManagedBuildManager.getIdFromIdAndVersion(tmpId) + "." + nnn + "_" + version; //$NON-NLS-1$ //$NON-NLS-2$ @@ -282,7 +284,7 @@ public class Configuration extends BuildObject implements IConfiguration { subId = tmpId + "." + nnn; //$NON-NLS-1$ } - if (cloneTools) { + if (cloneChildren) { toolChain = new ToolChain(this, subId, subName, (ToolChain)cloneConfig.getToolChain()); } else { // Add a tool-chain element that specifies as its superClass the @@ -297,6 +299,12 @@ public class Configuration extends BuildObject implements IConfiguration { } IToolChain newChain = createToolChain(superChain, subId, superChain.getName(), false); + // For each option/option category child of the tool-chain that is + // the child of the selected configuration element, create an option/ + // option category child of the cloned configuration's tool-chain element + // that specifies the original tool element as its superClass. + newChain.createOptions(superChain); + // For each tool element child of the tool-chain that is the child of // the selected configuration element, create a tool element child of // the cloned configuration's tool-chain element that specifies the @@ -691,7 +699,7 @@ public class Configuration extends BuildObject implements IConfiguration { /* (non-Javadoc) * @see org.eclipse.cdt.core.build.managed.IConfiguration#setOption(org.eclipse.cdt.core.build.managed.IOption, boolean) */ - public IOption setOption(ITool tool, IOption option, boolean value) throws BuildException { + public IOption setOption(IHoldsOptions holder, IOption option, boolean value) throws BuildException { // Is there a change? IOption retOpt = option; if (option.getBooleanValue() != value) { @@ -709,7 +717,7 @@ public class Configuration extends BuildObject implements IConfiguration { String subId; int nnn = ManagedBuildManager.getRandomNumber(); subId = newSuperClass.getId() + "." + nnn; //$NON-NLS-1$ - retOpt = tool.createOption(newSuperClass, subId, null, false); + retOpt = holder.createOption(newSuperClass, subId, null, false); retOpt.setValueType(option.getValueType()); retOpt.setValue(value); setDirty(true); @@ -724,7 +732,7 @@ public class Configuration extends BuildObject implements IConfiguration { /* (non-Javadoc) * @see org.eclipse.cdt.core.build.managed.IConfiguration#setOption(org.eclipse.cdt.core.build.managed.IOption, java.lang.String) */ - public IOption setOption(ITool tool, IOption option, String value) throws BuildException { + public IOption setOption(IHoldsOptions holder, IOption option, String value) throws BuildException { IOption retOpt = option; String oldValue; oldValue = option.getStringValue(); @@ -743,7 +751,7 @@ public class Configuration extends BuildObject implements IConfiguration { String subId; int nnn = ManagedBuildManager.getRandomNumber(); subId = newSuperClass.getId() + "." + nnn; //$NON-NLS-1$ - retOpt = tool.createOption(newSuperClass, subId, null, false); + retOpt = holder.createOption(newSuperClass, subId, null, false); retOpt.setValueType(option.getValueType()); retOpt.setValue(value); setDirty(true); @@ -758,7 +766,7 @@ public class Configuration extends BuildObject implements IConfiguration { /* (non-Javadoc) * @see org.eclipse.cdt.core.build.managed.IConfiguration#setOption(org.eclipse.cdt.core.build.managed.IOption, java.lang.String[]) */ - public IOption setOption(ITool tool, IOption option, String[] value) throws BuildException { + public IOption setOption(IHoldsOptions holder, IOption option, String[] value) throws BuildException { IOption retOpt = option; // Is there a change? String[] oldValue; @@ -797,7 +805,7 @@ public class Configuration extends BuildObject implements IConfiguration { String subId; int nnn = ManagedBuildManager.getRandomNumber(); subId = newSuperClass.getId() + "." + nnn; //$NON-NLS-1$ - retOpt = tool.createOption(newSuperClass, subId, null, false); + retOpt = holder.createOption(newSuperClass, subId, null, false); retOpt.setValueType(option.getValueType()); retOpt.setValue(value); setDirty(true); @@ -1344,13 +1352,25 @@ public class Configuration extends BuildObject implements IConfiguration { public void reset() { // We just need to remove all Options ITool[] tools = getTools(); + IToolChain toolChain = getToolChain(); + IOption[] opts; + + // Send out the event to notify the options that they are about to be removed. + // Do not do this for the child resource configurations as they are handled when + // the configuration itself is destroyed. + ManagedBuildManager.performValueHandlerEvent(this, IManagedOptionValueHandler.EVENT_CLOSE, false); + // Remove the configurations for (int i = 0; i < tools.length; i++) { ITool tool = tools[i]; - IOption[] opts = tool.getOptions(); + opts = tool.getOptions(); for (int j = 0; j < opts.length; j++) { tool.removeOption(opts[j]); } } + opts = toolChain.getOptions(); + for (int j = 0; j < opts.length; j++) { + toolChain.removeOption(opts[j]); + } } /* @@ -1378,6 +1398,8 @@ public class Configuration extends BuildObject implements IConfiguration { // Add this resource to the list. addResourceConfiguration(resConfig); + ManagedBuildManager.performValueHandlerEvent(resConfig, IManagedOptionValueHandler.EVENT_OPEN); + return resConfig; } @@ -1419,5 +1441,4 @@ public class Configuration extends BuildObject implements IConfiguration { return null; } - } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ConfigurationV2.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ConfigurationV2.java index ad401d1eb1d..ad35b0039af 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ConfigurationV2.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ConfigurationV2.java @@ -1,5 +1,5 @@ /********************************************************************** - * Copyright (c) 2003,2004 IBM Rational Software and others. + * Copyright (c) 2003,2005 IBM Rational Software and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at @@ -268,10 +268,12 @@ public class ConfigurationV2 extends BuildObject implements IConfigurationV2 { return answer.createOptionReference(option); } } else { - // Find out if a tool reference already exists - searchRef = (ToolReference) getToolReference(option.getParent()); + // Find out if a tool reference already exists. + // Note: as in MBS 2.0 the ITool == IHoldsOptions was always + // true, just up-cast the pointers. + searchRef = (ToolReference) getToolReference((ITool)option.getOptionHolder()); if (searchRef == null) { - answer = new ToolReference(this, option.getParent()); + answer = new ToolReference(this, (ITool)option.getOptionHolder()); } else { // The reference may belong to the target if (!searchRef.ownedByConfiguration(this)) { diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/DefaultManagedConfigElement.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/DefaultManagedConfigElement.java index fea746f5e30..2784fe0b2e3 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/DefaultManagedConfigElement.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/DefaultManagedConfigElement.java @@ -1,5 +1,5 @@ /********************************************************************** - * Copyright (c) 2004 TimeSys Corporation and others. + * Copyright (c) 2004, 2005 TimeSys Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at @@ -12,6 +12,7 @@ package org.eclipse.cdt.managedbuilder.internal.core; import org.eclipse.cdt.managedbuilder.core.IManagedConfigElement; import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtension; /** * Implements the ManagedConfigElement by delegate all calls to an @@ -21,12 +22,14 @@ import org.eclipse.core.runtime.IConfigurationElement; public class DefaultManagedConfigElement implements IManagedConfigElement { private IConfigurationElement element; + private IExtension extension; /** * @param element */ - public DefaultManagedConfigElement(IConfigurationElement element) { + public DefaultManagedConfigElement(IConfigurationElement element, IExtension extension) { this.element = element; + this.extension = extension; } /* (non-Javadoc) @@ -47,16 +50,23 @@ public class DefaultManagedConfigElement implements IManagedConfigElement { * @see org.eclipse.cdt.managedbuilder.core.IManagedConfigElement#getChildren() */ public IManagedConfigElement[] getChildren() { - return convertArray(element.getChildren()); + return convertArray(element.getChildren(), extension); } /* (non-Javadoc) * @see org.eclipse.cdt.managedbuilder.core.IManagedConfigElement#getChildren(java.lang.String) */ public IManagedConfigElement[] getChildren(String elementName) { - return convertArray(element.getChildren(elementName)); + return convertArray(element.getChildren(elementName), extension); } + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.core.IManagedConfigElement#getExtension(java.lang.String) + */ + public IExtension getExtension() { + return extension; + } + /** * @return */ @@ -69,11 +79,12 @@ public class DefaultManagedConfigElement implements IManagedConfigElement { * into an array of IManagedConfigElements. */ public static IManagedConfigElement[] convertArray( - IConfigurationElement[] elements) { + IConfigurationElement[] elements, + IExtension extension) { IManagedConfigElement[] ret = new IManagedConfigElement[elements.length]; for (int i = 0; i < elements.length; i++) { - ret[i] = new DefaultManagedConfigElement(elements[i]); + ret[i] = new DefaultManagedConfigElement(elements[i], extension); } return ret; } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/HoldsOptions.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/HoldsOptions.java new file mode 100644 index 00000000000..4d2078b363e --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/HoldsOptions.java @@ -0,0 +1,507 @@ +/********************************************************************** + * Copyright (c) 2005 Symbian Ltd and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Symbian Ltd - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.managedbuilder.internal.core; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Vector; + +import org.eclipse.cdt.managedbuilder.core.BuildException; +import org.eclipse.cdt.managedbuilder.core.IHoldsOptions; +import org.eclipse.cdt.managedbuilder.core.IManagedConfigElement; +import org.eclipse.cdt.managedbuilder.core.IOption; +import org.eclipse.cdt.managedbuilder.core.IOptionCategory; +import org.eclipse.cdt.managedbuilder.core.ITool; +import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; +import org.eclipse.cdt.managedbuilder.internal.core.Option; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +/** + * Implements the functionality that is needed to hold options and option + * categories. In CDT 3.0, the functionality has been moved from ITool and + * Tool to this class. + * + * This class is intended to be used as base class for all MBS grammar + * elements that can hold Options and Option Categories. These are currently + * Tool and ToolChain. + * + * Note that the member superClass must be shared with the + * derived class. This requires to wrap this member by access functions + * in the derived class or frequent casts, because the type of superClass + * in HoldsOptions must be IHoldOptions. Further + * note that the member resolved must inherit the value of its + * derived class. This achieved through the constructor. + * + * @since 3.0 + */ +public class HoldsOptions extends BuildObject implements IHoldsOptions { + + private static final IOptionCategory[] EMPTY_CATEGORIES = new IOptionCategory[0]; + + // Members that are to be shared with the derived class + protected IHoldsOptions superClass; + // Members that must have the same values on creation as the derived class + private boolean resolved; + // Parent and children + private Vector categoryIds; + private Map categoryMap; + private List childOptionCategories; + private Vector optionList; + private Map optionMap; + // Miscellaneous + private boolean isDirty = false; + + /* + * C O N S T R U C T O R S + */ + + private HoldsOptions() { + // prevent accidental construction of class without setting up + // resolved + } + + protected HoldsOptions(boolean resolved) { + this.resolved = resolved; + } + + /** + * Copies children of HoldsOptions. Helper function for + * derived constructors. + * + * @param source The children of the source will be cloned and added + * to the class itself. + */ + protected void copyChildren(HoldsOptions source) { + + // Note: This function ignores OptionCategories since they should not be + // found on an non-extension tools + if (source.optionList != null) { + Iterator iter = source.getOptionList().listIterator(); + while (iter.hasNext()) { + Option option = (Option) iter.next(); + int nnn = ManagedBuildManager.getRandomNumber(); + String subId; + String subName; + if (option.getSuperClass() != null) { + subId = option.getSuperClass().getId() + "." + nnn; //$NON-NLS-1$ + subName = option.getSuperClass().getName(); + } else { + subId = option.getId() + "." + nnn; //$NON-NLS-1$ + subName = option.getName(); + } + Option newOption = new Option(this, subId, subName, option); + addOption(newOption); + } + } + } + + /* + * E L E M E N T A T T R I B U T E R E A D E R S A N D W R I T E R S + */ + + /** + * Load child element from XML element if it is of the correct type + * + * @param element which is loaded as child only iff it is of the correct type + * @return true when a child has been loaded, false otherwise + */ + protected boolean loadChild(Node element) { + if (element.getNodeName().equals(ITool.OPTION)) { + Option option = new Option(this, (Element)element); + addOption(option); + return true; + } else if (element.getNodeName().equals(ITool.OPTION_CAT)) { + new OptionCategory(this, (Element)element); + return true; + } + return false; + } + + /** + * Load child element from configuration element if it is of the correct type + * + * @param element which is loaded as child only iff it is of the correct type + * @return true when a child has been loaded, false otherwise + */ + protected boolean loadChild(IManagedConfigElement element) { + if (element.getName().equals(ITool.OPTION)) { + Option option = new Option(this, element); + addOption(option); + return true; + } else if (element.getName().equals(ITool.OPTION_CAT)) { + new OptionCategory(this, element); + return true; + } + return false; + } + + /** + * Persist the tool to the project file. Intended to be called by derived + * class only, thus do not handle exceptions. + * + * @param doc + * @param element + * @throws BuildException + */ + protected void serialize(Document doc, Element element) throws BuildException { + + Iterator iter; + + if (childOptionCategories != null) { + iter = childOptionCategories.listIterator(); + while (iter.hasNext()) { + OptionCategory optCat = (OptionCategory)iter.next(); + Element optCatElement = doc.createElement(OPTION); + element.appendChild(optCatElement); + optCat.serialize(doc, optCatElement); + } + } + + List optionElements = getOptionList(); + iter = optionElements.listIterator(); + while (iter.hasNext()) { + Option option = (Option) iter.next(); + Element optionElement = doc.createElement(OPTION); + element.appendChild(optionElement); + option.serialize(doc, optionElement); + } +} + + /* + * M E T H O D S M O V E D F R O M I T O O L I N 3 . 0 + */ + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.core.IHoldsOptions#createOption(IOption, String, String, boolean) + */ + public IOption createOption(IOption superClass, String Id, String name, boolean isExtensionElement) { + Option option = new Option(this, superClass, Id, name, isExtensionElement); + addOption(option); + setDirty(true); + return option; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.core.IHoldsOptions#createOptions(IHoldsOptions) + */ + public void createOptions(IHoldsOptions superClass) { + Iterator iter = ((HoldsOptions)superClass).getOptionList().listIterator(); + while (iter.hasNext()) { + Option optionChild = (Option) iter.next(); + int nnn = ManagedBuildManager.getRandomNumber(); + String subId = optionChild.getId() + "." + nnn; //$NON-NLS-1$ + createOption(optionChild, subId, optionChild.getName(), false); + } + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.core.IHoldsOptions#removeOption(IOption) + */ + public void removeOption(IOption option) { + getOptionList().remove(option); + getOptionMap().remove(option.getId()); + setDirty(true); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.core.IHoldsOptions#getOptions() + */ + public IOption[] getOptions() { + IOption[] options = null; + // Merge our options with our superclass' options. + if (superClass != null) { + options = superClass.getOptions(); + } + // Our options take precedence. + Vector ourOpts = getOptionList(); + if (options != null) { + for (int i = 0; i < ourOpts.size(); i++) { + IOption ourOpt = (IOption)ourOpts.get(i); + int j; + for (j = 0; j < options.length; j++) { + if (options[j].overridesOnlyValue()) { + if (ourOpt.getSuperClass() != null // Remove assumption that ALL options must have superclasses + && ourOpt.getSuperClass().getId().equals(options[j].getSuperClass().getId())) { + options[j] = ourOpt; + break; + } + } else { + if (ourOpt.getSuperClass() != null // Remove assumption that ALL options must have superclasses + && ourOpt.getSuperClass().getId().equals(options[j].getId())) { + options[j] = ourOpt; + break; + } + } + } + // No Match? Add it. + if (j == options.length) { + IOption[] newOptions = new IOption[options.length + 1]; + for (int k = 0; k < options.length; k++) { + newOptions[k] = options[k]; + } + newOptions[j] = ourOpt; + options = newOptions; + } + } + } else { + options = (IOption[])ourOpts.toArray(new IOption[ourOpts.size()]); + } + // Check for any invalid options. + int numInvalidOptions = 0; + int i; + for (i=0; i < options.length; i++) { + if (options[i].isValid() == false) { + numInvalidOptions++; + } + } + // Take invalid options out of the array, if there are any + if (numInvalidOptions > 0) { + int j = 0; + IOption[] newOptions = new IOption[options.length - numInvalidOptions]; + for (i=0; i < options.length; i++) { + if (options[i].isValid() == true) { + newOptions[j] = options[i]; + j++; + } + } + options = newOptions; + } + return options; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.core.IHoldsOptions#getOption(java.lang.String) + */ + public IOption getOption(String id) { + return getOptionById(id); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.core.IHoldsOptions#getOptionById(java.lang.String) + */ + public IOption getOptionById(String id) { + IOption opt = (IOption)getOptionMap().get(id); + if (opt == null) { + if (superClass != null) { + return superClass.getOptionById(id); + } + } + return opt.isValid() ? opt : null; + } + + /* (non-Javadoc) + * org.eclipse.cdt.managedbuilder.core.IHoldsOptions#getOptionBySuperClassId(java.lang.String) + */ + public IOption getOptionBySuperClassId(String optionId) { + if (optionId == null) return null; + + // Look for an option with this ID, or an option with a superclass with this id + IOption[] options = getOptions(); + for (int i = 0; i < options.length; i++) { + IOption targetOption = options[i]; + IOption option = targetOption; + do { + if (optionId.equals(option.getId())) { + return targetOption.isValid() ? targetOption : null; + } + option = option.getSuperClass(); + } while (option != null); + } + + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.core.IHoldsOptions#getChildCategories() + */ + public IOptionCategory[] getChildCategories() { + IOptionCategory[] superCats = EMPTY_CATEGORIES; + IOptionCategory[] ourCats = EMPTY_CATEGORIES; + // Merge our option categories with our superclass' option categories. + // Note that these are two disjoint sets of categories because + // categories do not use derivation AND object Id's are unique. Thus + // they are merely sequentially added. + if (superClass != null) { + superCats = superClass.getChildCategories(); + } + if ( childOptionCategories != null ) { + ourCats = (IOptionCategory[])childOptionCategories.toArray(new IOptionCategory[childOptionCategories.size()]); + } + // Add the two arrays together; + if (superCats.length > 0 || ourCats.length > 0) { + IOptionCategory[] allCats = new IOptionCategory[superCats.length + ourCats.length]; + int j; + for (j=0; j < superCats.length; j++) + allCats[j] = superCats[j]; + for (j=0; j < ourCats.length; j++) + allCats[j+superCats.length] = ourCats[j]; + return allCats; + } + // Nothing found, return EMPTY_CATEGORIES + return EMPTY_CATEGORIES; + } + + /* + * M E T H O D S M O V E D F R O M T O O L I N 3 . 0 + */ + + /* (non-Javadoc) + * Memory-safe way to access the vector of category IDs + */ + private Vector getCategoryIds() { + if (categoryIds == null) { + categoryIds = new Vector(); + } + return categoryIds; + } + + /** + * @param category + */ + public void addChildCategory(IOptionCategory category) { + if (childOptionCategories == null) + childOptionCategories = new ArrayList(); + childOptionCategories.add(category); + } + + /** + * @param option + */ + public void addOption(Option option) { + getOptionList().add(option); + getOptionMap().put(option.getId(), option); + } + /* (non-Javadoc) + * Memeory-safe way to access the map of category IDs to categories + */ + private Map getCategoryMap() { + if (categoryMap == null) { + categoryMap = new HashMap(); + } + return categoryMap; + } + + /* (non-Javadoc) + * Memory-safe way to access the list of options + */ + private Vector getOptionList() { + if (optionList == null) { + optionList = new Vector(); + } + return optionList; + } + + /* (non-Javadoc) + * Memory-safe way to access the list of IDs to options + */ + private Map getOptionMap() { + if (optionMap == null) { + optionMap = new HashMap(); + } + return optionMap; + } + + /* (non-Javadoc) + * org.eclipse.cdt.managedbuilder.core.IHoldsOptions#addOptionCategory() + */ + public void addOptionCategory(IOptionCategory category) { + // To preserve the order of the categories, record the ids in the order they are read + getCategoryIds().add(category.getId()); + // Map the categories by ID for resolution later + getCategoryMap().put(category.getId(), category); + } + + /* (non-Javadoc) + * org.eclipse.cdt.managedbuilder.core.IHoldsOptions#getOptionCategory() + */ + public IOptionCategory getOptionCategory(String id) { + IOptionCategory cat = (IOptionCategory)getCategoryMap().get(id); + if (cat == null && superClass != null) { + // Look up the holders superclasses to find the category + return superClass.getOptionCategory(id); + } + return cat; + } + + /* + * O B J E C T S T A T E M A I N T E N A N C E + */ + + /* (non-Javadoc) + * Implements isDirty() for children of HoldsOptions. Intended to be + * called by derived class. + */ + protected boolean isDirty() { + // If I need saving, just say yes + if (isDirty) return true; + + // Otherwise see if any options need saving + List optionElements = getOptionList(); + Iterator iter = optionElements.listIterator(); + while (iter.hasNext()) { + Option option = (Option) iter.next(); + if (option.isDirty()) return true; + } + + return isDirty; + } + + /* (non-Javadoc) + * Implements setDirty() for children of HoldsOptions. Intended to be + * called by derived class. + */ + protected void setDirty(boolean isDirty) { + this.isDirty = isDirty; + // Propagate "false" to the children + if (!isDirty) { + List optionElements = getOptionList(); + Iterator iter = optionElements.listIterator(); + while (iter.hasNext()) { + Option option = (Option) iter.next(); + option.setDirty(false); + } + } + } + + /* (non-Javadoc) + * Resolve the element IDs to interface references. Intended to be + * called by derived class. + */ + protected void resolveReferences() { + if (!resolved) { + resolved = true; + // Call resolveReferences on our children + Iterator optionIter = getOptionList().iterator(); + while (optionIter.hasNext()) { + Option current = (Option)optionIter.next(); + current.resolveReferences(); + } + // Somewhat wasteful, but use the vector to retrieve the categories in proper order + Iterator catIter = getCategoryIds().iterator(); + while (catIter.hasNext()) { + String id = (String)catIter.next(); + IOptionCategory current = (IOptionCategory)getCategoryMap().get(id); + if (current instanceof Tool) { + ((Tool)current).resolveReferences(); + } else if (current instanceof ToolChain) { + ((ToolChain)current).resolveReferences(); + } else if (current instanceof OptionCategory) { + ((OptionCategory)current).resolveReferences(); + } + } + } + } +} diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedBuildInfo.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedBuildInfo.java index e1514d49798..6b64aa8ff06 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedBuildInfo.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedBuildInfo.java @@ -448,7 +448,7 @@ public class ManagedBuildInfo implements IManagedBuildInfo, IScannerInfo { .getApplicabilityCalculator(); if (applicabilityCalculator == null - || applicabilityCalculator.isOptionUsedInCommandLine(tool)) { + || applicabilityCalculator.isOptionUsedInCommandLine(config, tool, option)) { // Get all the user-defined paths from the // option as absolute paths @@ -500,7 +500,7 @@ public class ManagedBuildInfo implements IManagedBuildInfo, IScannerInfo { IOptionApplicability applicabilitytCalculator = option.getApplicabilityCalculator(); if (applicabilitytCalculator == null - || applicabilitytCalculator.isOptionUsedInCommandLine(tool)) { + || applicabilitytCalculator.isOptionUsedInCommandLine(getDefaultConfiguration(), tool, option)) { String command = option.getCommand(); String[] allLibs = option.getLibraries(); for (int j = 0; j < allLibs.length; j++) diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedProject.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedProject.java index 5606e82136c..6bfd090af40 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedProject.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedProject.java @@ -17,6 +17,7 @@ import java.util.List; import java.util.Map; import org.eclipse.cdt.managedbuilder.core.IBuildObject; +import org.eclipse.cdt.managedbuilder.core.IManagedOptionValueHandler; import org.eclipse.cdt.managedbuilder.core.IProjectType; import org.eclipse.cdt.managedbuilder.core.IManagedProject; import org.eclipse.cdt.managedbuilder.core.IConfiguration; @@ -225,6 +226,7 @@ public class ManagedProject extends BuildObject implements IManagedProject { */ public IConfiguration createConfiguration(IConfiguration parent, String id) { Configuration config = new Configuration(this, (Configuration)parent, id, false); + ManagedBuildManager.performValueHandlerEvent(config, IManagedOptionValueHandler.EVENT_OPEN); return (IConfiguration)config; } @@ -233,6 +235,8 @@ public class ManagedProject extends BuildObject implements IManagedProject { */ public IConfiguration createConfigurationClone(IConfiguration parent, String id) { Configuration config = new Configuration(this, (Configuration)parent, id, true); + // Inform all options in the configuration and all its resource configurations + ManagedBuildManager.performValueHandlerEvent(config, IManagedOptionValueHandler.EVENT_OPEN); return (IConfiguration)config; } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Option.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Option.java index aa849cdd3fc..9cf90ccd4f1 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Option.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Option.java @@ -21,12 +21,16 @@ import java.util.Set; import org.eclipse.cdt.managedbuilder.core.BuildException; import org.eclipse.cdt.managedbuilder.core.IBuildObject; +import org.eclipse.cdt.managedbuilder.core.IHoldsOptions; import org.eclipse.cdt.managedbuilder.core.IOptionApplicability; import org.eclipse.cdt.managedbuilder.core.IManagedConfigElement; +import org.eclipse.cdt.managedbuilder.core.IManagedOptionValueHandler; import org.eclipse.cdt.managedbuilder.core.IOption; import org.eclipse.cdt.managedbuilder.core.IOptionCategory; import org.eclipse.cdt.managedbuilder.core.IProjectType; import org.eclipse.cdt.managedbuilder.core.ITool; +import org.eclipse.cdt.managedbuilder.core.IToolChain; +import org.eclipse.cdt.managedbuilder.core.ManagedOptionValueHandler; import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; @@ -45,7 +49,7 @@ public class Option extends BuildObject implements IOption { private IOption superClass; private String superClassId; // Parent and children - private ITool tool; + private IHoldsOptions holder; // Managed Build model attributes private String unusedChildren; private Integer browseType; @@ -62,12 +66,19 @@ public class Option extends BuildObject implements IOption { private Integer valueType; private Boolean isAbstract; private Integer resourceFilter; + private IConfigurationElement valueHandlerElement = null; + private IManagedOptionValueHandler valueHandler = null; + private String valueHandlerExtraArgument; private IConfigurationElement applicabilityCalculatorElement = null; private IOptionApplicability applicabilityCalculator = null; // Miscellaneous private boolean isExtensionOption = false; private boolean isDirty = false; private boolean resolved = true; + private boolean verified = false; + private boolean isValid = true; /** False for options which are invalid. getOption() + * routines will ignore invalid options. */ + /* * C O N S T R U C T O R S */ @@ -76,13 +87,13 @@ public class Option extends BuildObject implements IOption { * This constructor is called to create an option defined by an extension point in * a plugin manifest file, or returned by a dynamic element provider * - * @param parent The ITool parent of this option, or null if + * @param parent The IHoldsOptions parent of this option, or null if * defined at the top level * @param element The option definition from the manifest file or a dynamic element * provider */ - public Option(Tool parent, IManagedConfigElement element) { - this.tool = parent; + public Option(IHoldsOptions parent, IManagedConfigElement element) { + this.holder = parent; isExtensionOption = true; // setup for resolving @@ -98,14 +109,14 @@ public class Option extends BuildObject implements IOption { * This constructor is called to create an Option whose attributes and children will be * added by separate calls. * - * @param Tool The parent of the tool, if any + * @param IHoldsOptions The parent of the option, if any * @param Option The superClass, if any * @param String The id for the new option * @param String The name for the new option * @param boolean Indicates whether this is an extension element or a managed project element */ - public Option(Tool parent, IOption superClass, String Id, String name, boolean isExtensionElement) { - this.tool = parent; + public Option(IHoldsOptions parent, IOption superClass, String Id, String name, boolean isExtensionElement) { + this.holder = parent; this.superClass = superClass; if (this.superClass != null) { superClassId = this.superClass.getId(); @@ -125,11 +136,11 @@ public class Option extends BuildObject implements IOption { * Create an Option based on the specification stored in the * project file (.cdtbuild). * - * @param parent The ITool the option will be added to. + * @param parent The IHoldsOptions the option will be added to. * @param element The XML element that contains the option settings. */ - public Option(Tool parent, Element element) { - this.tool = parent; + public Option(IHoldsOptions parent, Element element) { + this.holder = parent; isExtensionOption = false; // Initialize from the XML attributes @@ -139,11 +150,13 @@ public class Option extends BuildObject implements IOption { /** * Create an Option based upon an existing option. * - * @param parent The ITool the option will be added to. - * @param tool The existing option to clone. + * @param parent The IHoldsOptions the option will be added to. + * @param Id New ID for the option. + * @param name New name for the option. + * @param option The existing option to clone, except for the above fields. */ - public Option(ITool parent, String Id, String name, Option option){ - this.tool = parent; + public Option(IHoldsOptions parent, String Id, String name, Option option){ + this.holder = parent; superClass = option.superClass; if (superClass != null) { superClassId = option.superClass.getId(); @@ -221,6 +234,14 @@ public class Option extends BuildObject implements IOption { applicabilityCalculatorElement = option.applicabilityCalculatorElement; applicabilityCalculator = option.applicabilityCalculator; + if (option.valueHandlerElement != null) { + valueHandlerElement = option.valueHandlerElement; + valueHandler = option.valueHandler; + } + if (option.valueHandlerExtraArgument != null) { + valueHandlerExtraArgument = new String(option.valueHandlerExtraArgument); + } + setDirty(true); } @@ -298,8 +319,14 @@ public class Option extends BuildObject implements IOption { if (applicabilityCalculatorStr != null && element instanceof DefaultManagedConfigElement) { applicabilityCalculatorElement = ((DefaultManagedConfigElement)element).getConfigurationElement(); } - - + // valueHandler + // Store the configuration element IFF there is a value handler defined + String valueHandler = element.getAttribute(VALUE_HANDLER); + if (valueHandler != null && element instanceof DefaultManagedConfigElement) { + valueHandlerElement = ((DefaultManagedConfigElement)element).getConfigurationElement(); + } + // valueHandlerExtraArgument + valueHandlerExtraArgument = element.getAttribute(VALUE_HANDLER_EXTRA_ARGUMENT); } /* (non-Javadoc) @@ -472,7 +499,7 @@ public class Option extends BuildObject implements IOption { if (element.hasAttribute(CATEGORY)) { categoryId = element.getAttribute(CATEGORY); if (categoryId != null) { - category = ((Tool)tool).getOptionCategory(categoryId); + category = holder.getOptionCategory(categoryId); } } @@ -487,6 +514,14 @@ public class Option extends BuildObject implements IOption { resourceFilter = new Integer(FILTER_PROJECT); } } + + // Note: valueHandlerElement and VALUE_HANDLER are not restored, + // as they are not saved. See note in serialize(). + + // valueHandlerExtraArgument + if (element.hasAttribute(VALUE_HANDLER_EXTRA_ARGUMENT)) { + valueHandlerExtraArgument = element.getAttribute(VALUE_HANDLER_EXTRA_ARGUMENT); + } } private int ValueTypeStrToInt(String valueTypeStr) { @@ -693,6 +728,16 @@ public class Option extends BuildObject implements IOption { // TODO: issue warning? } + // Note: a value handler cannot be specified in a project file because + // an IConfigurationElement is needed to load it! + if (valueHandlerElement != null) { + // TODO: Issue warning? Stuck with behavior of this elsewhere in + // CDT, e.g. the implementation of Tool + } + if (valueHandlerExtraArgument != null) { + element.setAttribute(VALUE_HANDLER_EXTRA_ARGUMENT, valueHandlerExtraArgument); + } + // I am clean now isDirty = false; } @@ -702,10 +747,18 @@ public class Option extends BuildObject implements IOption { */ /* (non-Javadoc) - * @see org.eclipse.cdt.core.build.managed.IOption#getParent() + * @see org.eclipse.cdt.managedbuilder.core.IOption#getParent() */ - public ITool getParent() { - return tool; + public IBuildObject getParent() { + return holder; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.core.IOption#getOptionHolder() + */ + public IHoldsOptions getOptionHolder() { + // Do not take superclasses into account + return holder; } /* @@ -720,14 +773,14 @@ public class Option extends BuildObject implements IOption { } /* (non-Javadoc) - * @see org.eclipse.cdt.core.build.managed.IOption#getName() + * @see org.eclipse.cdt.managedbuilder.core.IOption#getName() */ public String getName() { return (name == null && superClass != null) ? superClass.getName() : name; } /* (non-Javadoc) - * @see org.eclipse.cdt.core.build.managed.IOption#getApplicableValues() + * @see org.eclipse.cdt.managedbuilder.core.IOption#getApplicableValues() */ public String[] getApplicableValues() { // Does this option instance have the list of values? @@ -823,7 +876,7 @@ public class Option extends BuildObject implements IOption { } /* (non-Javadoc) - * @see org.eclipse.cdt.core.build.managed.IOption#getBuiltIns() + * @see org.eclipse.cdt.managedbuilder.core.IOption#getBuiltIns() */ public String[] getBuiltIns() { // Return the list of built-ins as an array @@ -838,21 +891,25 @@ public class Option extends BuildObject implements IOption { } /* (non-Javadoc) - * @see org.eclipse.cdt.core.build.managed.IOption#getCategory() + * @see org.eclipse.cdt.managedbuilder.core.IOption#getCategory() */ public IOptionCategory getCategory() { if (category == null) { if (superClass != null) { return superClass.getCategory(); } else { - return getParent().getTopOptionCategory(); + if (getOptionHolder() instanceof ITool) { + return ((ITool)getOptionHolder()).getTopOptionCategory(); + } else { + return null; + } } } return category; } /* (non-Javadoc) - * @see org.eclipse.cdt.core.build.managed.IOption#getCommand() + * @see org.eclipse.cdt.managedbuilder.core.IOption#getCommand() */ public String getCommand() { if (command == null) { @@ -866,7 +923,7 @@ public class Option extends BuildObject implements IOption { } /* (non-Javadoc) - * @see org.eclipse.cdt.core.build.managed.IOption#getCommandFalse() + * @see org.eclipse.cdt.managedbuilder.core.IOption#getCommandFalse() */ public String getCommandFalse() { if (commandFalse == null) { @@ -880,7 +937,7 @@ public class Option extends BuildObject implements IOption { } /* (non-Javadoc) - * @see org.eclipse.cdt.core.build.managed.IOption#getDefinedSymbols() + * @see org.eclipse.cdt.managedbuilder.core.IOption#getDefinedSymbols() */ public String[] getDefinedSymbols() throws BuildException { if (getValueType() != PREPROCESSOR_SYMBOLS) { @@ -896,7 +953,7 @@ public class Option extends BuildObject implements IOption { } /* (non-Javadoc) - * @see org.eclipse.cdt.core.build.managed.IOption#getEnumCommand(java.lang.String) + * @see org.eclipse.cdt.managedbuilder.core.IOption#getEnumCommand(java.lang.String) */ public String getEnumCommand(String id) throws BuildException { // Sanity @@ -934,7 +991,7 @@ public class Option extends BuildObject implements IOption { } /* (non-Javadoc) - * @see org.eclipse.cdt.core.build.managed.IOption#getEnumName(java.lang.String) + * @see org.eclipse.cdt.managedbuilder.core.IOption#getEnumName(java.lang.String) */ public String getEnumName(String id) throws BuildException { // Sanity @@ -1018,7 +1075,7 @@ public class Option extends BuildObject implements IOption { } /* (non-Javadoc) - * @see org.eclipse.cdt.core.build.managed.IOption#getIncludePaths() + * @see org.eclipse.cdt.managedbuilder.core.IOption#getIncludePaths() */ public String[] getIncludePaths() throws BuildException { if (getValueType() != INCLUDE_PATH) { @@ -1034,7 +1091,7 @@ public class Option extends BuildObject implements IOption { } /* (non-Javadoc) - * @see org.eclipse.cdt.core.build.managed.IOption#getLibraries() + * @see org.eclipse.cdt.managedbuilder.core.IOption#getLibraries() */ public String[] getLibraries() throws BuildException { if (getValueType() != LIBRARIES) { @@ -1050,7 +1107,7 @@ public class Option extends BuildObject implements IOption { } /* (non-Javadoc) - * @see org.eclipse.cdt.core.build.managed.IOption#getDefaultEnumValue() + * @see org.eclipse.cdt.managedbuilder.core.IOption#getDefaultEnumValue() */ public String getSelectedEnum() throws BuildException { if (getValueType() != ENUMERATED) { @@ -1060,7 +1117,7 @@ public class Option extends BuildObject implements IOption { } /* (non-Javadoc) - * @see org.eclipse.cdt.core.build.managed.IOption#getStringListValue() + * @see org.eclipse.cdt.managedbuilder.core.IOption#getStringListValue() */ public String[] getStringListValue() throws BuildException { if (getValueType() != STRING_LIST) { @@ -1076,7 +1133,7 @@ public class Option extends BuildObject implements IOption { } /* (non-Javadoc) - * @see org.eclipse.cdt.core.build.managed.IOption#getStringValue() + * @see org.eclipse.cdt.managedbuilder.core.IOption#getStringValue() */ public String getStringValue() throws BuildException { if (getValueType() != STRING && getValueType() != ENUMERATED) { @@ -1103,7 +1160,7 @@ public class Option extends BuildObject implements IOption { } /* (non-Javadoc) - * @see org.eclipse.cdt.core.build.managed.IOption#getValueType() + * @see org.eclipse.cdt.managedbuilder.core.IOption#getValueType() */ public int getValueType() throws BuildException { if (valueType == null) { @@ -1196,7 +1253,7 @@ public class Option extends BuildObject implements IOption { } /* (non-Javadoc) - * @see org.eclipse.cdt.core.build.managed.IOption#setValue(Object) + * @see org.eclipse.cdt.managedbuilder.core.IOption#setValue(Object) */ public void setDefaultValue(Object v) { defaultValue = v; @@ -1204,7 +1261,7 @@ public class Option extends BuildObject implements IOption { } /* (non-Javadoc) - * @see org.eclipse.cdt.core.build.managed.IOption#setCategory(org.eclipse.cdt.core.build.managed.IOptionCategory) + * @see org.eclipse.cdt.managedbuilder.core.IOption#setCategory(org.eclipse.cdt.managedbuilder.core.IOptionCategory) */ public void setCategory(IOptionCategory category) { if (this.category != category) { @@ -1219,7 +1276,7 @@ public class Option extends BuildObject implements IOption { } /* (non-Javadoc) - * @see org.eclipse.cdt.core.build.managed.IOption#setCommand(String) + * @see org.eclipse.cdt.managedbuilder.core.IOption#setCommand(String) */ public void setCommand(String cmd) { if (cmd == null && command == null) return; @@ -1230,7 +1287,7 @@ public class Option extends BuildObject implements IOption { } /* (non-Javadoc) - * @see org.eclipse.cdt.core.build.managed.IOption#setCommandFalse(String) + * @see org.eclipse.cdt.managedbuilder.core.IOption#setCommandFalse(String) */ public void setCommandFalse(String cmd) { if (cmd == null && commandFalse == null) return; @@ -1261,7 +1318,7 @@ public class Option extends BuildObject implements IOption { } /* (non-Javadoc) - * @see org.eclipse.cdt.core.build.managed.IOption#setValue(boolean) + * @see org.eclipse.cdt.managedbuilder.core.IOption#setValue(boolean) */ public void setValue(boolean value) throws BuildException { if (!isExtensionElement() && getValueType() == BOOLEAN) @@ -1274,7 +1331,7 @@ public class Option extends BuildObject implements IOption { /* (non-Javadoc) - * @see org.eclipse.cdt.core.build.managed.IOption#setValue(String) + * @see org.eclipse.cdt.managedbuilder.core.IOption#setValue(String) */ public void setValue(String value) throws BuildException { // Note that we can still set the human-readable value here @@ -1288,7 +1345,7 @@ public class Option extends BuildObject implements IOption { /* (non-Javadoc) - * @see org.eclipse.cdt.core.build.managed.IOption#setValue(String []) + * @see org.eclipse.cdt.managedbuilder.core.IOption#setValue(String []) */ public void setValue(String [] value) throws BuildException { if (!isExtensionElement() && @@ -1307,7 +1364,7 @@ public class Option extends BuildObject implements IOption { } /* (non-Javadoc) - * @see org.eclipse.cdt.core.build.managed.IOption#setValue(Object) + * @see org.eclipse.cdt.managedbuilder.core.IOption#setValue(Object) */ public void setValue(Object v) { value = v; @@ -1315,7 +1372,7 @@ public class Option extends BuildObject implements IOption { } /* (non-Javadoc) - * @see org.eclipse.cdt.core.build.managed.IOption#setValueType() + * @see org.eclipse.cdt.managedbuilder.core.IOption#setValueType() */ public void setValueType(int type) { // TODO: Verify that this is a valid type @@ -1325,6 +1382,63 @@ public class Option extends BuildObject implements IOption { } } + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.core.IOption#getValueHandlerElement() + */ + public IConfigurationElement getValueHandlerElement() { + if (valueHandlerElement == null) { + if (superClass != null) { + return ((Option)superClass).getValueHandlerElement(); + } + } + return valueHandlerElement; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.core.IOption#setValueHandlerElement(IConfigurationElement) + */ + public void setValueHandlerElement(IConfigurationElement element) { + valueHandlerElement = element; + setDirty(true); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.core.IOption#getValueHandler() + */ + public IManagedOptionValueHandler getValueHandler() { + if (valueHandler != null) { + return valueHandler; + } + IConfigurationElement element = getValueHandlerElement(); + if (element != null) { + try { + if (element.getAttribute(VALUE_HANDLER) != null) { + valueHandler = (IManagedOptionValueHandler) element.createExecutableExtension(VALUE_HANDLER); + return valueHandler; + } + } catch (CoreException e) { + ManagedBuildManager.OptionValueHandlerError(element.getAttribute(VALUE_HANDLER), getId()); + // Assign the default handler to avoid further error messages + valueHandler = ManagedOptionValueHandler.getManagedOptionValueHandler(); + return valueHandler; + } + } + // If no handler is provided, then use the default handler + return ManagedOptionValueHandler.getManagedOptionValueHandler(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.core.IOption#getValueHandlerExtraArgument()) + */ + public String getValueHandlerExtraArgument() { + if (valueHandlerExtraArgument == null) { + if (superClass != null) { + return superClass.getValueHandlerExtraArgument(); + } + } + return valueHandlerExtraArgument; + } + /* * O B J E C T S T A T E M A I N T E N A N C E */ @@ -1391,7 +1505,7 @@ public class Option extends BuildObject implements IOption { } } if (categoryId != null) { - category = ((Tool)tool).getOptionCategory(categoryId); + category = holder.getOptionCategory(categoryId); if (category == null) { // Report error ManagedBuildManager.OutputResolveError( @@ -1494,6 +1608,78 @@ public class Option extends BuildObject implements IOption { return managedBuildRevision; } + /* (non-Javadoc) + * For now implement this method just as a utility to make code + * within the Option class cleaner. + * TODO: In future we may want to move this to IOption + */ + protected boolean isAbstract() { + if (isAbstract != null) { + return isAbstract.booleanValue(); + } else { + return false; // Note: no inheritance from superClass + } + } + + /** + * Verifies whether the option is valid and handles + * any errors for the option. The following errors + * can occur: + * (a) Options that are children of a ToolChain must + * ALWAYS have a category + * (b) Options that are children of a ToolChain must + * NEVER have a resourceFilter of "file". + * If an error occurs, the option is set to being invalid. + * + * @pre All references have been resolved. + */ + private void verify() { + if (verified) return; + verified = true; + // Ignore elements that are superclasses + if ( getOptionHolder() instanceof IToolChain && isAbstract() == false ) { + // Check for error (a) + if (getCategory() == null) { + ManagedBuildManager.OptionValidError(ManagedBuildManager.ERROR_CATEGORY, getId()); + // Object becomes invalid + isValid = false; + } + // Check for error (b). Not specifying an attribute is OK. + // Do not use getResourceFilter as it does not allow + // differentiating between "all" and no attribute specified. + if ( resourceFilter != null ) + { + switch (getResourceFilter()) { + case Option.FILTER_FILE: + // TODO: Cannot differentiate between "all" and attribute not + // specified. Thus do not produce an error. We can argue that "all" + // means all valid resource configurations. + ManagedBuildManager.OptionValidError(ManagedBuildManager.ERROR_FILTER, getId()); + // Object becomes invalid + isValid = false; + } + } + } + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.core.IOption#isValid() + */ + public boolean isValid() { + // We use a lazy scheme to check whether the option is valid. + // Note that by default an option is valid. verify() is only called if + // the option has been resolved. This gets us around having to deal with + // ordering problems during a resolve, or introducing another global + // stage to verify the configuration after a resolve. + // The trade-off is that errors in the MBS grammar may not be + // detected on load, but only when a particular grammar element + // is used, say in the GUI. + if (verified == false && resolved == true) { + verify(); + } + return isValid; + } + /** * @return Returns the version. */ diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/OptionCategory.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/OptionCategory.java index 434c0f7fef3..2f55f97b77d 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/OptionCategory.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/OptionCategory.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2004 IBM Corporation and others. + * Copyright (c) 2003, 2005 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at @@ -10,18 +10,23 @@ *******************************************************************************/ package org.eclipse.cdt.managedbuilder.internal.core; +import java.net.MalformedURLException; +import java.net.URL; import java.util.ArrayList; import java.util.List; import org.eclipse.cdt.managedbuilder.core.IBuildObject; import org.eclipse.cdt.managedbuilder.core.IConfiguration; +import org.eclipse.cdt.managedbuilder.core.IHoldsOptions; import org.eclipse.cdt.managedbuilder.core.IManagedConfigElement; import org.eclipse.cdt.managedbuilder.core.IOption; import org.eclipse.cdt.managedbuilder.core.IOptionCategory; import org.eclipse.cdt.managedbuilder.core.IResourceConfiguration; import org.eclipse.cdt.managedbuilder.core.ITool; +import org.eclipse.cdt.managedbuilder.core.IToolChain; import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; -// import org.eclipse.core.runtime.PluginVersionIdentifier; // uncomment this line after 'parent' is available +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.PluginVersionIdentifier; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -33,11 +38,12 @@ public class OptionCategory extends BuildObject implements IOptionCategory { private static final IOptionCategory[] emtpyCategories = new IOptionCategory[0]; // Parent and children - private Tool tool; + private IHoldsOptions holder; private List children; // Note: These are logical Option Category children, not "model" children // Managed Build model attributes private IOptionCategory owner; // The logical Option Category parent private String ownerId; + private URL iconPathURL; // Miscellaneous private boolean isExtensionOptionCategory = false; private boolean isDirty = false; @@ -55,13 +61,13 @@ public class OptionCategory extends BuildObject implements IOptionCategory { * This constructor is called to create an option category defined by an extension point in * a plugin manifest file, or returned by a dynamic element provider * - * @param parent The IToolChain parent of this builder, or null if + * @param parent The IHoldsOptions parent of this catgeory, or null if * defined at the top level - * @param element The builder definition from the manifest file or a dynamic element + * @param element The category definition from the manifest file or a dynamic element * provider */ - public OptionCategory(Tool parent, IManagedConfigElement element) { - this.tool = parent; + public OptionCategory(IHoldsOptions parent, IManagedConfigElement element) { + this.holder = parent; isExtensionOptionCategory = true; // setup for resolving @@ -72,26 +78,26 @@ public class OptionCategory extends BuildObject implements IOptionCategory { // Hook me up to the Managed Build Manager ManagedBuildManager.addExtensionOptionCategory(this); - // Add the category to the tool - tool.addOptionCategory(this); + // Add the category to the parent + parent.addOptionCategory(this); } /** * Create an based on the specification stored in the * project file (.cdtbuild). * - * @param parent The Tool the OptionCategory will be added to. + * @param parent The IHoldsOptions object the OptionCategory will be added to. * @param element The XML element that contains the OptionCategory settings. */ - public OptionCategory(Tool parent, Element element) { - tool = parent; + public OptionCategory(IHoldsOptions parent, Element element) { + this.holder = parent; isExtensionOptionCategory = false; // Initialize from the XML attributes loadFromProject(element); - // Add the category to the tool - tool.addOptionCategory(this); + // Add the category to the parent + parent.addOptionCategory(this); } /* @@ -109,6 +115,13 @@ public class OptionCategory extends BuildObject implements IOptionCategory { // owner ownerId = element.getAttribute(IOptionCategory.OWNER); + + // icon + if ( element.getAttribute(IOptionCategory.ICON) != null && element instanceof DefaultManagedConfigElement) + { + String icon = element.getAttribute(IOptionCategory.ICON); + iconPathURL = ManagedBuildManager.getURLInBuildDefinitions( (DefaultManagedConfigElement)element, new Path(icon) ); + } } /* (non-Javadoc) @@ -132,18 +145,42 @@ public class OptionCategory extends BuildObject implements IOptionCategory { ownerId = element.getAttribute(IOptionCategory.OWNER); } if (ownerId != null) { - owner = tool.getOptionCategory(ownerId); + owner = holder.getOptionCategory(ownerId); } else { - owner = tool; + owner = getNullOptionCategory(); } + // icon - was saved as URL in string form + if (element.hasAttribute(IOptionCategory.ICON)) { + String iconPath = element.getAttribute(IOptionCategory.ICON); + try { + iconPathURL = new URL(iconPath); + } catch (MalformedURLException e) { + // Print a warning + ManagedBuildManager.OutputIconError(iconPath); + iconPathURL = null; + } + } + // Hook me in - if (owner instanceof Tool) + if (owner == null) + ((HoldsOptions)holder).addChildCategory(this); + else if (owner instanceof Tool) ((Tool)owner).addChildCategory(this); else ((OptionCategory)owner).addChildCategory(this); } + private IOptionCategory getNullOptionCategory() { + // Handle difference between Tool and others by using + // the fact that Tool implements IOptionCategory. If so, + // the holder is in fact a parent category to this category. + if (holder instanceof IOptionCategory) { + return (IOptionCategory)holder; + } + return null; + } + /** * Persist the OptionCategory to the project file. * @@ -160,6 +197,11 @@ public class OptionCategory extends BuildObject implements IOptionCategory { if (owner != null) element.setAttribute(IOptionCategory.OWNER, owner.getId()); + if (iconPathURL != null) { + // Save as URL in string form + element.setAttribute(IOptionCategory.ICON, iconPathURL.toString()); + } + // I am clean now isDirty = false; } @@ -188,46 +230,76 @@ public class OptionCategory extends BuildObject implements IOptionCategory { * @see org.eclipse.cdt.core.build.managed.IOptionCategory#getOptions(org.eclipse.cdt.core.build.managed.ITool) */ public Object[][] getOptions(IConfiguration configuration) { - ITool[] tools = null; + IHoldsOptions[] optionHolders = null; if (configuration != null) { - tools = configuration.getTools(); + IHoldsOptions optionHolder = getOptionHolder(); + if (optionHolder instanceof ITool) { + optionHolders = configuration.getTools(); + } else if (optionHolder instanceof IToolChain) { + // Get the toolchain of this configuration, which is + // the holder equivalent for this option + optionHolders = new IHoldsOptions[1]; + optionHolders[0] = configuration.getToolChain(); + } + // TODO: if further option holders were to be added in future, + // this function needs to be extended } - return getOptions(tools, FILTER_PROJECT); + return getOptions(optionHolders, FILTER_PROJECT); } public Object[][] getOptions(IResourceConfiguration resConfig) { - ITool[] tools = null; + IHoldsOptions[] optionHolders = null; if (resConfig != null) { - tools = resConfig.getTools(); + IHoldsOptions optionHolder = getOptionHolder(); + if (optionHolder instanceof ITool) { + optionHolders = resConfig.getTools(); + } else if (optionHolder instanceof IToolChain) { + // Resource configurations do not support categories that are children + // of toolchains. The reason for this is that options in such categories + // are intended to be global. Thus return nothing. + // TODO: Remove this restriction in future? + optionHolders = new IHoldsOptions[1]; + optionHolders[0] = null; + } + // TODO: if further option holders were to be added in future, + // this function needs to be extended } - return getOptions(tools, FILTER_FILE); + return getOptions(optionHolders, FILTER_FILE); } - private Object[][] getOptions(ITool[] tools, int filterValue) { - ITool catTool = getTool(); - ITool tool = null; + private IHoldsOptions getOptionHoldersSuperClass(IHoldsOptions optionHolder) { + if (optionHolder instanceof ITool) + return ((ITool)optionHolder).getSuperClass(); + else if (optionHolder instanceof IToolChain) + return ((IToolChain)optionHolder).getSuperClass(); + return null; + } + + private Object[][] getOptions(IHoldsOptions[] optionHolders, int filterValue) { + IHoldsOptions catHolder = getOptionHolder(); + IHoldsOptions optionHolder = null; - if (tools != null) { + if (optionHolders != null) { // Find the child of the configuration/resource configuration that represents the same tool. // It could the tool itself, or a "sub-class" of the tool. - for (int i = 0; i < tools.length; ++i) { - ITool current = tools[i]; + for (int i = 0; i < optionHolders.length; ++i) { + IHoldsOptions current = optionHolders[i]; do { - if (catTool == current) { - tool = tools[i]; + if (catHolder == current) { + optionHolder = optionHolders[i]; break; } - } while ((current = current.getSuperClass()) != null); - if (tool != null) break; + } while ((current = getOptionHoldersSuperClass(current)) != null); + if (optionHolder != null) break; } } - if (tool == null) { - tool = catTool; + if (optionHolder == null) { + optionHolder = catHolder; } // Get all of the tool's options and see which ones are part of // this category. - IOption[] allOptions = tool.getOptions(); + IOption[] allOptions = optionHolder.getOptions(); Object[][] myOptions = new Object[allOptions.length][2]; int index = 0; for (int i = 0; i < allOptions.length; ++i) { @@ -237,7 +309,7 @@ public class OptionCategory extends BuildObject implements IOptionCategory { // Check whether this option can be displayed for a specific resource type. if( (option.getResourceFilter() == FILTER_ALL) || (option.getResourceFilter() == filterValue) ) { myOptions[index] = new Object[2]; - myOptions[index][0] = tool; + myOptions[index][0] = optionHolder; myOptions[index][1] = option; index++; } @@ -257,14 +329,36 @@ public class OptionCategory extends BuildObject implements IOptionCategory { return owner; } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.build.managed.IOptionCategory#getOptionHolder() + */ + public IHoldsOptions getOptionHolder() { + // This will stop at the parent's top category + if (owner != null) + return owner.getOptionHolder(); + return holder; + } + /* (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(); + // This will stop at the tool's top category + IHoldsOptions parent = owner.getOptionHolder(); + if (parent instanceof ITool) + { + return (ITool)parent; + } + return null; } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.build.managed.IOptionCategory#getIconPath() + */ + public URL getIconPath() { + return iconPathURL; + } + /* * O B J E C T S T A T E M A I N T E N A N C E */ @@ -293,39 +387,53 @@ public class OptionCategory extends BuildObject implements IOptionCategory { } public void resolveReferences() { + boolean error = false; if (!resolved) { resolved = true; if (ownerId != null) { - owner = tool.getOptionCategory(ownerId); + owner = holder.getOptionCategory(ownerId); if (owner == null) { - // Report error - ManagedBuildManager.OutputResolveError( - "owner", //$NON-NLS-1$ - ownerId, - "optionCategory", //$NON-NLS-1$ - getId()); + if (holder instanceof IOptionCategory) { + // Report error, only if the parent is a tool and thus also + // an option category. + ManagedBuildManager.OutputResolveError( + "owner", //$NON-NLS-1$ + ownerId, + "optionCategory", //$NON-NLS-1$ + getId()); + error = true; + } else if ( false == holder.getId().equals(ownerId) ) { + // Report error, if the holder ID does not match the owner's ID. + ManagedBuildManager.OutputResolveError( + "owner", //$NON-NLS-1$ + ownerId, + "optionCategory", //$NON-NLS-1$ + getId()); + error = true; + } } } if (owner == null) { - owner = tool; + owner = getNullOptionCategory(); } // Hook me in - if (owner instanceof Tool) + if (owner == null && error == false) + ((HoldsOptions)holder).addChildCategory(this); + else if (owner instanceof Tool) ((Tool)owner).addChildCategory(this); else ((OptionCategory)owner).addChildCategory(this); } } - // Uncomment this code after the 'parent' is available /** * @return Returns the managedBuildRevision. - * + */ public String getManagedBuildRevision() { if ( managedBuildRevision == null) { - if ( getParent() != null) { - return getParent().getManagedBuildRevision(); + if ( getOptionHolder() != null) { + return getOptionHolder().getManagedBuildRevision(); } } return managedBuildRevision; @@ -333,11 +441,11 @@ public class OptionCategory extends BuildObject implements IOptionCategory { /** * @return Returns the version. - * + */ public PluginVersionIdentifier getVersion() { if ( version == null) { - if ( getParent() != null) { - return getParent().getVersion(); + if ( getOptionHolder() != null) { + return getOptionHolder().getVersion(); } } return version; @@ -346,6 +454,5 @@ public class OptionCategory extends BuildObject implements IOptionCategory { public void setVersion(PluginVersionIdentifier version) { // Do nothing } -*/ } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/OptionReference.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/OptionReference.java index 0e1e404574f..f7b39c2782b 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/OptionReference.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/OptionReference.java @@ -16,12 +16,15 @@ import java.util.List; import java.util.ListIterator; import org.eclipse.cdt.managedbuilder.core.BuildException; +import org.eclipse.cdt.managedbuilder.core.IHoldsOptions; import org.eclipse.cdt.managedbuilder.core.IOptionApplicability; import org.eclipse.cdt.managedbuilder.core.IManagedConfigElement; +import org.eclipse.cdt.managedbuilder.core.IManagedOptionValueHandler; import org.eclipse.cdt.managedbuilder.core.IOption; import org.eclipse.cdt.managedbuilder.core.IOptionCategory; -import org.eclipse.cdt.managedbuilder.core.ITool; +import org.eclipse.cdt.managedbuilder.core.IBuildObject; import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; +import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.PluginVersionIdentifier; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -503,10 +506,17 @@ public class OptionReference implements IOption { /* (non-Javadoc) * @see org.eclipse.cdt.core.build.managed.IOption#getParent() */ - public ITool getParent() { + public IBuildObject getParent() { return owner; } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.build.managed.IOption#getOptionHolder() + */ + public IHoldsOptions getOptionHolder() { + return owner; + } + /** * Answers the tool reference that contains the receiver. * @@ -744,4 +754,37 @@ public class OptionReference implements IOption { return option.getManagedBuildRevision(); } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.build.managed.IOption#getValueHandlerElement() + */ + public IConfigurationElement getValueHandlerElement() { + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.build.managed.IOption#setValueHandlerElement(IConfigurationElement) + */ + public void setValueHandlerElement(IConfigurationElement element) { + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.build.managed.IOption#getValueHandler() + */ + public IManagedOptionValueHandler getValueHandler() { + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.build.managed.IOption#getValueHandlerExtraArgument()) + */ + public String getValueHandlerExtraArgument() { + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.core.IOption#isValid() + */ + public boolean isValid() { + return option.isValid(); + } } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/PluginResources.properties b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/PluginResources.properties index 4a59fd107bc..247cfa8af8f 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/PluginResources.properties +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/PluginResources.properties @@ -43,6 +43,10 @@ ManagedBuildManager.error.manifest.version.error=The version number defined in t ManagedBuildManager.error.manifest.header=Managed Build system manifest file error: ManagedBuildManager.error.manifest.resolving=Unable to resolve the {0} identifier {1} in the {2} {3}. ManagedBuildManager.error.manifest.duplicate=Duplicate identifier {1} for element type {0}. +ManagedBuildManager.error.manifest.icon=Could not load icon "{0}". +ManagedBuildManager.error.manifest.option.category=Option {0} uses a null category that is invalid in its context. The option was ignored. +ManagedBuildManager.error.manifest.option.filter=Option {0} uses an unsupported resourceFilter attribute value. The option was ignored. +ManagedBuildManager.error.manifest.option.valuehandler=Could not load value handler {0} in option {1}. ManagedBuildManager.error.open_failed_title=Managed Make Project File Error ManagedBuildManager.error.open_failed=The Managed Make project file could not be read because of the following error.\n\n{0}\n\nManaged Make functionality will not be available for this project. ManagedBuildManager.error.project.version.error=The version number of the project {0} is greater than the Managed Build System version number. diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ProjectType.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ProjectType.java index 111a2e94af1..21968f19e3d 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ProjectType.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ProjectType.java @@ -17,6 +17,7 @@ import java.util.List; import java.util.Map; import org.eclipse.cdt.managedbuilder.core.IConfigurationNameProvider; +import org.eclipse.cdt.managedbuilder.core.IManagedOptionValueHandler; import org.eclipse.cdt.managedbuilder.core.IProjectType; import org.eclipse.cdt.managedbuilder.core.IConfiguration; import org.eclipse.cdt.managedbuilder.core.IManagedConfigElement; @@ -191,6 +192,7 @@ public class ProjectType extends BuildObject implements IProjectType { */ public IConfiguration createConfiguration(IConfiguration parent, String id, String name) { Configuration config = new Configuration(this, parent, id, name); + ManagedBuildManager.performValueHandlerEvent(config, IManagedOptionValueHandler.EVENT_OPEN); return (IConfiguration)config; } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ResourceConfiguration.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ResourceConfiguration.java index da8f3506bee..88e9731dadb 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ResourceConfiguration.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ResourceConfiguration.java @@ -20,10 +20,13 @@ import java.util.Map; import org.eclipse.cdt.managedbuilder.core.BuildException; import org.eclipse.cdt.managedbuilder.core.IBuildObject; import org.eclipse.cdt.managedbuilder.core.IConfiguration; +import org.eclipse.cdt.managedbuilder.core.IHoldsOptions; +import org.eclipse.cdt.managedbuilder.core.IManagedOptionValueHandler; import org.eclipse.cdt.managedbuilder.core.IOption; import org.eclipse.cdt.managedbuilder.core.IResourceConfiguration; import org.eclipse.cdt.managedbuilder.core.ITool; import org.eclipse.cdt.managedbuilder.core.IManagedConfigElement; +import org.eclipse.cdt.managedbuilder.core.IToolChain; import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.PluginVersionIdentifier; @@ -477,6 +480,9 @@ public class ResourceConfiguration extends BuildObject implements IResourceConfi public void reset() { // We just need to remove all Options ITool[] tools = getTools(); + // Send out the event to notify the options that they are about to be removed + ManagedBuildManager.performValueHandlerEvent(this, IManagedOptionValueHandler.EVENT_CLOSE); + // Remove the configurations for (int i = 0; i < tools.length; i++) { ITool tool = tools[i]; IOption[] opts = tool.getOptions(); @@ -495,13 +501,23 @@ public class ResourceConfiguration extends BuildObject implements IResourceConfi tool.setToolCommand(command); } - public IOption setOption(ITool tool, IOption option, boolean value) throws BuildException { + private IBuildObject getHoldersParent(IOption option) { + IHoldsOptions holder = option.getOptionHolder(); + if (holder instanceof ITool) { + return ((ITool)holder).getParent(); + } else if (holder instanceof IToolChain) { + return ((IToolChain)holder).getParent(); + } + return null; + } + + public IOption setOption(IHoldsOptions holder, IOption option, boolean value) throws BuildException { // Is there a change? IOption retOpt = option; if (option.getBooleanValue() != value) { // If this resource config does not already override this option, then we need to // create a new option - if (option.getParent().getParent() != this) { + if (getHoldersParent(option) != this) { IOption newSuperClass = option; if (!newSuperClass.isExtensionElement()) { newSuperClass = newSuperClass.getSuperClass(); @@ -520,7 +536,7 @@ public class ResourceConfiguration extends BuildObject implements IResourceConfi String subId; int nnn = ManagedBuildManager.getRandomNumber(); subId = newSuperClass.getId() + "." + nnn; //$NON-NLS-1$ - retOpt = tool.createOption(newSuperClass, subId, null, false); + retOpt = holder.createOption(newSuperClass, subId, null, false); retOpt.setValueType(option.getValueType()); retOpt.setValue(value); setDirty(true); @@ -534,14 +550,14 @@ public class ResourceConfiguration extends BuildObject implements IResourceConfi return retOpt; } - public IOption setOption(ITool tool, IOption option, String value) throws BuildException { + public IOption setOption(IHoldsOptions holder, IOption option, String value) throws BuildException { IOption retOpt = option; String oldValue; oldValue = option.getStringValue(); if (oldValue != null && !oldValue.equals(value)) { // If this resource config does not already override this option, then we need to // create a new option - if (option.getParent().getParent() != this) { + if (getHoldersParent(option) != this) { IOption newSuperClass = option; if (!newSuperClass.isExtensionElement()) { newSuperClass = newSuperClass.getSuperClass(); @@ -560,7 +576,7 @@ public class ResourceConfiguration extends BuildObject implements IResourceConfi String subId; int nnn = ManagedBuildManager.getRandomNumber(); subId = newSuperClass.getId() + "." + nnn; //$NON-NLS-1$ - retOpt = tool.createOption(newSuperClass, subId, null, false); + retOpt = holder.createOption(newSuperClass, subId, null, false); retOpt.setValueType(option.getValueType()); retOpt.setValue(value); setDirty(true); @@ -577,7 +593,7 @@ public class ResourceConfiguration extends BuildObject implements IResourceConfi /* (non-Javadoc) * @see org.eclipse.cdt.core.build.managed.IConfiguration#setOption(org.eclipse.cdt.core.build.managed.IOption, java.lang.String[]) */ - public IOption setOption(ITool tool, IOption option, String[] value) throws BuildException { + public IOption setOption(IHoldsOptions holder, IOption option, String[] value) throws BuildException { IOption retOpt = option; // Is there a change? String[] oldValue; @@ -604,7 +620,7 @@ public class ResourceConfiguration extends BuildObject implements IResourceConfi if(!Arrays.equals(value, oldValue)) { // If this resource config does not already override this option, then we need to // create a new option - if (option.getParent().getParent() != this) { + if (getHoldersParent(option) != this) { IOption newSuperClass = option; if (!newSuperClass.isExtensionElement()) { newSuperClass = newSuperClass.getSuperClass(); @@ -623,7 +639,7 @@ public class ResourceConfiguration extends BuildObject implements IResourceConfi String subId; int nnn = ManagedBuildManager.getRandomNumber(); subId = newSuperClass.getId() + "." + nnn; //$NON-NLS-1$ - retOpt = tool.createOption(newSuperClass, subId, null, false); + retOpt = holder.createOption(newSuperClass, subId, null, false); retOpt.setValueType(option.getValueType()); retOpt.setValue(value); setDirty(true); @@ -641,7 +657,6 @@ public class ResourceConfiguration extends BuildObject implements IResourceConfi return getParent().getOwner(); } - /** * @return Returns the version. */ diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Tool.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Tool.java index 8e27db57e1b..964fb7b5a82 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Tool.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Tool.java @@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.cdt.managedbuilder.internal.core; +import java.net.MalformedURLException; +import java.net.URL; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -22,6 +24,7 @@ import org.eclipse.cdt.managedbuilder.core.BuildException; import org.eclipse.cdt.managedbuilder.core.IBuildObject; import org.eclipse.cdt.managedbuilder.core.IConfiguration; import org.eclipse.cdt.managedbuilder.core.IEnvVarBuildPath; +import org.eclipse.cdt.managedbuilder.core.IHoldsOptions; import org.eclipse.cdt.managedbuilder.core.IOptionApplicability; import org.eclipse.cdt.managedbuilder.core.IInputType; import org.eclipse.cdt.managedbuilder.core.IManagedCommandLineGenerator; @@ -55,7 +58,7 @@ import org.w3c.dom.NodeList; * Note that this class implements IOptionCategory to represent the top * category. */ -public class Tool extends BuildObject implements ITool, IOptionCategory { +public class Tool extends HoldsOptions implements ITool, IOptionCategory { public static final String DEFAULT_PATTERN = "${COMMAND} ${FLAGS} ${OUTPUT_FLAG}${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}"; //$NON-NLS-1$ public static final String DEFAULT_CBS_PATTERN = "${COMMAND}"; //$NON-NLS-1$ @@ -68,16 +71,15 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { private static final String DEFAULT_ANNOUNCEMENT_PREFIX = "Tool.default.announcement"; //$NON-NLS-1$ private static final String WHITESPACE = " "; //$NON-NLS-1$ + private static final boolean resolvedDefault = true; + // Superclass - private ITool superClass; + // Note that superClass itself is defined in the base and that the methods + // getSuperClass() and setSuperClass(), defined in Tool must be used to + // access it. This avoids widespread casts from IHoldsOptions to ITool. private String superClassId; // Parent and children private IBuildObject parent; - private Vector categoryIds; - private Map categoryMap; - private List childOptionCategories; - private Vector optionList; - private Map optionMap; private Vector inputTypeList; private Map inputTypeMap; private Vector outputTypeList; @@ -104,10 +106,11 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { private IManagedCommandLineGenerator commandLineGenerator = null; private IConfigurationElement dependencyGeneratorElement = null; private IManagedDependencyGenerator dependencyGenerator = null; + private URL iconPathURL; // Miscellaneous private boolean isExtensionTool = false; private boolean isDirty = false; - private boolean resolved = true; + private boolean resolved = resolvedDefault; /* * C O N S T R U C T O R S @@ -121,11 +124,12 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { * @param managedBuildRevision the fileVersion of Managed Build System */ public Tool(IManagedConfigElement element, String managedBuildRevision) { - isExtensionTool = true; - // setup for resolving + super(false); resolved = false; + isExtensionTool = true; + // Set the managedBuildRevision setManagedBuildRevision(managedBuildRevision); @@ -141,11 +145,8 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { IManagedConfigElement[] toolElements = element.getChildren(); for (int l = 0; l < toolElements.length; ++l) { IManagedConfigElement toolElement = toolElements[l]; - if (toolElement.getName().equals(ITool.OPTION)) { - Option option = new Option(this, toolElement); - addOption(option); - } else if (toolElement.getName().equals(ITool.OPTION_CAT)) { - new OptionCategory(this, toolElement); + if (loadChild(toolElement)) { + // do nothing } else if (toolElement.getName().equals(ITool.INPUT_TYPE)) { InputType inputType = new InputType(this, toolElement); addInputType(inputType); @@ -183,11 +184,12 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { * @param boolean Indicates whether this is an extension element or a managed project element */ public Tool(ToolChain parent, ITool superClass, String Id, String name, boolean isExtensionElement) { + super(resolvedDefault); this.parent = parent; - this.superClass = superClass; + setSuperClass(superClass); setManagedBuildRevision(parent.getManagedBuildRevision()); - if (this.superClass != null) { - superClassId = this.superClass.getId(); + if (getSuperClass() != null) { + superClassId = getSuperClass().getId(); } setId(Id); @@ -215,11 +217,12 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { */ public Tool(ResourceConfiguration parent, ITool superClass, String Id, String name, boolean isExtensionElement) { + super(resolvedDefault); this.parent = parent; - this.superClass = superClass; + setSuperClass( superClass ); setManagedBuildRevision(parent.getManagedBuildRevision()); - if (this.superClass != null) { - superClassId = this.superClass.getId(); + if (getSuperClass() != null) { + superClassId = getSuperClass().getId(); } setId(Id); setName(name); @@ -244,6 +247,7 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { * @param managedBuildRevision the fileVersion of Managed Build System */ public Tool(IBuildObject parent, Element element, String managedBuildRevision) { + super(resolvedDefault); this.parent = parent; isExtensionTool = false; @@ -260,11 +264,8 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { NodeList toolElements = element.getChildNodes(); for (int i = 0; i < toolElements.getLength(); ++i) { Node toolElement = toolElements.item(i); - if (toolElement.getNodeName().equals(ITool.OPTION)) { - Option option = new Option(this, (Element)toolElement); - addOption(option); - } else if (toolElement.getNodeName().equals(ITool.OPTION_CAT)) { - new OptionCategory(this, (Element)toolElement); + if (loadChild(toolElement)) { + // do nothing } else if (toolElement.getNodeName().equals(ITool.INPUT_TYPE)) { InputType inputType = new InputType(this, (Element)toolElement); addInputType(inputType); @@ -283,14 +284,15 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { * @param tool The existing tool to clone. */ public Tool(IBuildObject parent, ITool toolSuperClass, String Id, String name, Tool tool){ + super(resolvedDefault); this.parent = parent; if (toolSuperClass != null) { - superClass = toolSuperClass; + setSuperClass( toolSuperClass ); } else { - superClass = tool.superClass; + setSuperClass( tool.getSuperClass() ); } - if (superClass != null) { - superClassId = superClass.getId(); + if (getSuperClass() != null) { + superClassId = getSuperClass().getId(); } setId(Id); setName(name); @@ -356,27 +358,9 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { if(tool.envVarBuildPathList != null) envVarBuildPathList = new ArrayList(tool.envVarBuildPathList); + // Clone the children in superclass + super.copyChildren(tool); // Clone the children - // Note: This constructor ignores OptionCategories since they should not be - // found on an non-extension tool - TODO: This may need to change! - if (tool.optionList != null) { - Iterator iter = tool.getOptionList().listIterator(); - while (iter.hasNext()) { - Option option = (Option) iter.next(); - int nnn = ManagedBuildManager.getRandomNumber(); - String subId; - String subName; - if (option.getSuperClass() != null) { - subId = option.getSuperClass().getId() + "." + nnn; //$NON-NLS-1$ - subName = option.getSuperClass().getName(); - } else { - subId = option.getId() + "." + nnn; //$NON-NLS-1$ - subName = option.getName(); - } - Option newOption = new Option(this, subId, subName, option); - addOption(newOption); - } - } if (tool.inputTypeList != null) { Iterator iter = tool.getInputTypeList().listIterator(); while (iter.hasNext()) { @@ -414,6 +398,11 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { } } + // icon + if ( tool.iconPathURL != null ) { + iconPathURL = tool.iconPathURL; + } + setDirty(true); } @@ -533,6 +522,13 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { if (depGenerator != null && element instanceof DefaultManagedConfigElement) { dependencyGeneratorElement = ((DefaultManagedConfigElement)element).getConfigurationElement(); } + + // icon + if ( element.getAttribute(IOptionCategory.ICON) != null && element instanceof DefaultManagedConfigElement) + { + String icon = element.getAttribute(IOptionCategory.ICON); + iconPathURL = ManagedBuildManager.getURLInBuildDefinitions( (DefaultManagedConfigElement)element, new Path(icon) ); + } } /* (non-Javadoc) @@ -559,11 +555,11 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { if (superClassId != null && superClassId.length() > 0) { if( getParent() instanceof IResourceConfiguration ) { IResourceConfiguration resConfig = (IResourceConfiguration) getParent(); - superClass = resConfig.getParent().getTool(superClassId); + setSuperClass( resConfig.getParent().getTool(superClassId) ); } else { - superClass = ManagedBuildManager.getExtensionTool(superClassId); + setSuperClass( ManagedBuildManager.getExtensionTool(superClassId) ); } - if (superClass == null) { + if (getSuperClass() == null) { // TODO: Report error } } @@ -679,6 +675,18 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { if (element.hasAttribute(ITool.ANNOUNCEMENT)) { announcement = element.getAttribute(ITool.ANNOUNCEMENT); } + + // icon - was saved as URL in string form + if (element.hasAttribute(IOptionCategory.ICON)) { + String iconPath = element.getAttribute(IOptionCategory.ICON); + try { + iconPathURL = new URL(iconPath); + } catch (MalformedURLException e) { + // Print a warning + ManagedBuildManager.OutputIconError(iconPath); + iconPathURL = null; + } + } } /** @@ -689,8 +697,8 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { */ public void serialize(Document doc, Element element) { try { - if (superClass != null) - element.setAttribute(IProjectType.SUPERCLASS, superClass.getId()); + if (getSuperClass() != null) + element.setAttribute(IProjectType.SUPERCLASS, getSuperClass().getId()); // id element.setAttribute(IBuildObject.ID, id); @@ -804,24 +812,11 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { element.setAttribute(ITool.ANNOUNCEMENT, announcement); } + // Serialize elements from my super class + super.serialize(doc, element); + // Serialize my children - if (childOptionCategories != null) { - Iterator iter = childOptionCategories.listIterator(); - while (iter.hasNext()) { - OptionCategory optCat = (OptionCategory)iter.next(); - Element optCatElement = doc.createElement(OPTION); - element.appendChild(optCatElement); - optCat.serialize(doc, optCatElement); - } - } - List optionElements = getOptionList(); - Iterator iter = optionElements.listIterator(); - while (iter.hasNext()) { - Option option = (Option) iter.next(); - Element optionElement = doc.createElement(OPTION); - element.appendChild(optionElement); - option.serialize(doc, optionElement); - } + Iterator iter; List typeElements = getInputTypeList(); iter = typeElements.listIterator(); while (iter.hasNext()) { @@ -851,6 +846,11 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { // TODO: issue warning? } + if (iconPathURL != null) { + // Save as URL in string form + element.setAttribute(IOptionCategory.ICON, iconPathURL.toString()); + } + // I am clean now isDirty = false; } catch (Exception e) { @@ -876,69 +876,6 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { this.parent = newParent; } - /* (non-Javadoc) - * @see org.eclipse.cdt.managedbuilder.core.ITool#createOption(IOption, String, String, boolean) - */ - public IOption createOption(IOption superClass, String Id, String name, boolean isExtensionElement) { - Option option = new Option(this, superClass, Id, name, isExtensionElement); - addOption(option); - setDirty(true); - return option; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.managedbuilder.core.ITool#removeOption(IOption) - */ - public void removeOption(IOption option) { - getOptionList().remove(option); - getOptionMap().remove(option.getId()); - setDirty(true); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.managedbuilder.core.ITool#getOptions() - */ - public IOption[] getOptions() { - IOption[] options = null; - // Merge our options with our superclass' options. - if (superClass != null) { - options = superClass.getOptions(); - } - // Our options take precedence. - Vector ourOpts = getOptionList(); - if (options != null) { - for (int i = 0; i < ourOpts.size(); i++) { - IOption ourOpt = (IOption)ourOpts.get(i); - int j; - for (j = 0; j < options.length; j++) { - if (options[j].overridesOnlyValue()) { - if (ourOpt.getSuperClass().getId().equals(options[j].getSuperClass().getId())) { - options[j] = ourOpt; - break; - } - } else { - if (ourOpt.getSuperClass().getId().equals(options[j].getId())) { - options[j] = ourOpt; - break; - } - } - } - // No Match? Add it. - if (j == options.length) { - IOption[] newOptions = new IOption[options.length + 1]; - for (int k = 0; k < options.length; k++) { - newOptions[k] = options[k]; - } - newOptions[j] = ourOpt; - options = newOptions; - } - } - } else { - options = (IOption[])ourOpts.toArray(new IOption[ourOpts.size()]); - } - return options; - } - /* (non-Javadoc) * @see org.eclipse.cdt.managedbuilder.core.ITool#getTopOptionCategory() */ @@ -946,63 +883,6 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { return this; } - /* (non-Javadoc) - * @see org.eclipse.cdt.managedbuilder.core.ITool#getOption(java.lang.String) - */ - public IOption getOption(String id) { - return getOptionById(id); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.build.managed.ITool#getOptionById(java.lang.String) - */ - public IOption getOptionById(String id) { - IOption opt = (IOption)getOptionMap().get(id); - if (opt == null) { - if (superClass != null) { - return superClass.getOptionById(id); - } - } - return opt; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.build.managed.ITool#getOptionBySuperClassId(java.lang.String) - */ - public IOption getOptionBySuperClassId(String optionId) { - if (optionId == null) return null; - - // Look for an option with this ID, or an option with a superclass with this id - IOption[] options = getOptions(); - for (int i = 0; i < options.length; i++) { - IOption targetOption = options[i]; - IOption option = targetOption; - do { - if (optionId.equals(option.getId())) { - return targetOption; - } - option = option.getSuperClass(); - } while (option != null); - } - - return null; - } - - /* (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 { - if (superClass != null) { - return superClass.getChildCategories(); - } else { - return EMPTY_CATEGORIES; - } - } - } - /* (non-Javadoc) * @see org.eclipse.cdt.managedbuilder.core.ITool#createInputType(IInputType, String, String, boolean) */ @@ -1028,8 +908,8 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { public IInputType[] getInputTypes() { IInputType[] types = null; // Merge our input types with our superclass' input types. - if (superClass != null) { - types = superClass.getInputTypes(); + if (getSuperClass() != null) { + types = getSuperClass().getInputTypes(); } // Our options take precedence. Vector ourTypes = getInputTypeList(); @@ -1069,8 +949,8 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { public IInputType getInputTypeById(String id) { IInputType type = (IInputType)getInputTypeMap().get(id); if (type == null) { - if (superClass != null) { - return superClass.getInputTypeById(id); + if (getSuperClass() != null) { + return getSuperClass().getInputTypeById(id); } } return type; @@ -1101,8 +981,8 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { public IOutputType[] getOutputTypes() { IOutputType[] types = null; // Merge our output types with our superclass' output types. - if (superClass != null) { - types = superClass.getOutputTypes(); + if (getSuperClass() != null) { + types = getSuperClass().getOutputTypes(); } // Our options take precedence. Vector ourTypes = getOutputTypeList(); @@ -1157,8 +1037,8 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { public IOutputType getOutputTypeById(String id) { IOutputType type = (IOutputType)getOutputTypeMap().get(id); if (type == null) { - if (superClass != null) { - return superClass.getOutputTypeById(id); + if (getSuperClass() != null) { + return getSuperClass().getOutputTypeById(id); } } return type; @@ -1171,6 +1051,16 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { return null; } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.build.managed.IOptionCategory#getIconPath() + */ + public URL getIconPath() { + if (iconPathURL == null && getSuperClass() != null) { + return getSuperClass().getTopOptionCategory().getIconPath(); + } + return iconPathURL; + } + /* (non-Javadoc) * @see org.eclipse.cdt.core.build.managed.IOptionCategory#getOptions(org.eclipse.cdt.core.build.managed.ITool) */ @@ -1248,83 +1138,12 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { } /* (non-Javadoc) - * Memory-safe way to access the vector of category IDs + * @see org.eclipse.cdt.core.build.managed.IOptionCategory#getOptionHolder() */ - private Vector getCategoryIds() { - if (categoryIds == null) { - categoryIds = new Vector(); - } - return categoryIds; - } - - /** - * @param category - */ - public void addChildCategory(IOptionCategory category) { - if (childOptionCategories == null) - childOptionCategories = new ArrayList(); - childOptionCategories.add(category); - } - - /** - * @param option - */ - public void addOption(Option option) { - getOptionList().add(option); - getOptionMap().put(option.getId(), option); - } - - /** - * @param category - */ - protected void addOptionCategory(IOptionCategory category) { - // To preserve the order of the categories, record the ids in the order they are read - getCategoryIds().add(category.getId()); - // Map the categories by ID for resolution later - getCategoryMap().put(category.getId(), category); + public IHoldsOptions getOptionHolder() { + return this; } - /** - * Answers the IOptionCategory that has the unique identifier - * specified in the argument. - * - * @param id The unique identifier of the option category - * @return IOptionCategory with the id specified in the argument - */ - public IOptionCategory getOptionCategory(String id) { - return (IOptionCategory)getCategoryMap().get(id); - } - - /* (non-Javadoc) - * Memeory-safe way to access the map of category IDs to categories - */ - private Map getCategoryMap() { - if (categoryMap == null) { - categoryMap = new HashMap(); - } - return categoryMap; - } - - /* (non-Javadoc) - * Memory-safe way to access the list of options - */ - private Vector getOptionList() { - if (optionList == null) { - optionList = new Vector(); - } - return optionList; - } - - /* (non-Javadoc) - * Memory-safe way to access the list of IDs to options - */ - private Map getOptionMap() { - if (optionMap == null) { - optionMap = new HashMap(); - } - return optionMap; - } - /* (non-Javadoc) * Memory-safe way to access the list of input types */ @@ -1389,14 +1208,22 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { * @see org.eclipse.cdt.managedbuilder.core.ITool#getSuperClass() */ public ITool getSuperClass() { - return superClass; + return (ITool)superClass; + } + + /* (non-Javadoc) + * Access function to set the superclass element that is defined in + * the base class. + */ + private void setSuperClass(ITool superClass) { + this.superClass = superClass; } /* (non-Javadoc) * @see org.eclipse.cdt.core.build.managed.ITool#getName() */ public String getName() { - return (name == null && superClass != null) ? superClass.getName() : name; + return (name == null && getSuperClass() != null) ? getSuperClass().getName() : name; } /* (non-Javadoc) @@ -1435,8 +1262,8 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { String ids = errorParserIds; if (ids == null) { // If I have a superClass, ask it - if (superClass != null) { - ids = superClass.getErrorParserIds(); + if (getSuperClass() != null) { + ids = getSuperClass().getErrorParserIds(); } } return ids; @@ -1483,8 +1310,8 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { private List getInputExtensionsAttribute() { if( (inputExtensions == null) || ( inputExtensions.size() == 0) ) { // If I have a superClass, ask it - if (superClass != null) { - return ((Tool)superClass).getInputExtensionsAttribute(); + if (getSuperClass() != null) { + return ((Tool)getSuperClass()).getInputExtensionsAttribute(); } else { inputExtensions = new ArrayList(); } @@ -1699,8 +1526,8 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { private List getHeaderExtensionsAttribute() { if (interfaceExtensions == null || interfaceExtensions.size() == 0) { // If I have a superClass, ask it - if (superClass != null) { - return ((Tool)superClass).getHeaderExtensionsAttribute(); + if (getSuperClass() != null) { + return ((Tool)getSuperClass()).getHeaderExtensionsAttribute(); } else { if (interfaceExtensions == null) { interfaceExtensions = new ArrayList(); @@ -1723,8 +1550,8 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { public String getOutputFlag() { if (outputFlag == null) { // If I have a superClass, ask it - if (superClass != null) { - return superClass.getOutputFlag(); + if (getSuperClass() != null) { + return getSuperClass().getOutputFlag(); } else { return EMPTY_STRING; } @@ -1755,8 +1582,8 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { // If there are no OutputTypes, use the deprecated Tool attribute if (outputPrefix == null) { // If I have a superClass, ask it - if (superClass != null) { - return superClass.getOutputPrefix(); + if (getSuperClass() != null) { + return getSuperClass().getOutputPrefix(); } else { return EMPTY_STRING; } @@ -1770,8 +1597,8 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { public String getToolCommand() { if (command == null) { // If I have a superClass, ask it - if (superClass != null) { - return superClass.getToolCommand(); + if (getSuperClass() != null) { + return getSuperClass().getToolCommand(); } else { return EMPTY_STRING; } @@ -1784,8 +1611,8 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { */ public String getCommandLinePattern() { if (commandLinePattern == null) { - if (superClass != null) { - return superClass.getCommandLinePattern(); + if (getSuperClass() != null) { + return getSuperClass().getCommandLinePattern(); } else { if (getCustomBuildStep()) { return new String(DEFAULT_CBS_PATTERN); // Default pattern @@ -1802,8 +1629,8 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { */ public boolean getAdvancedInputCategory() { if (advancedInputCategory == null) { - if (superClass != null) { - return superClass.getAdvancedInputCategory(); + if (getSuperClass() != null) { + return getSuperClass().getAdvancedInputCategory(); } else { return false; // default is false } @@ -1816,8 +1643,8 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { */ public boolean getCustomBuildStep() { if (customBuildStep == null) { - if (superClass != null) { - return superClass.getCustomBuildStep(); + if (getSuperClass() != null) { + return getSuperClass().getCustomBuildStep(); } else { return false; // default is false } @@ -1830,8 +1657,8 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { */ public String getAnnouncement() { if (announcement == null) { - if (superClass != null) { - return superClass.getAnnouncement(); + if (getSuperClass() != null) { + return getSuperClass().getAnnouncement(); } else { // Generate the default announcement string for the Tool String defaultAnnouncement = ManagedMakeMessages.getResourceString(DEFAULT_ANNOUNCEMENT_PREFIX) + @@ -1847,8 +1674,8 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { */ public IConfigurationElement getCommandLineGeneratorElement() { if (commandLineGeneratorElement == null) { - if (superClass != null) { - return ((Tool)superClass).getCommandLineGeneratorElement(); + if (getSuperClass() != null) { + return ((Tool)getSuperClass()).getCommandLineGeneratorElement(); } } return commandLineGeneratorElement; @@ -1917,8 +1744,8 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { private IConfigurationElement getToolDependencyGeneratorElement() { if (dependencyGeneratorElement == null) { - if (superClass != null) { - return ((Tool)superClass).getToolDependencyGeneratorElement(); + if (getSuperClass() != null) { + return ((Tool)getSuperClass()).getToolDependencyGeneratorElement(); } } return dependencyGeneratorElement; @@ -1978,8 +1805,8 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { public int getNatureFilter() { if (natureFilter == null) { // If I have a superClass, ask it - if (superClass != null) { - return superClass.getNatureFilter(); + if (getSuperClass() != null) { + return getSuperClass().getNatureFilter(); } else { return FILTER_BOTH; } @@ -2028,8 +1855,8 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { public String[] getOutputsAttribute() { // TODO: Why is this treated differently than inputExtensions? if (outputExtensions == null) { - if (superClass != null) { - return superClass.getOutputsAttribute(); + if (getSuperClass() != null) { + return getSuperClass().getOutputsAttribute(); } else { return null; } @@ -2232,7 +2059,14 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { // check to see if the option has an applicability calculator IOptionApplicability applicabilityCalculator = option.getApplicabilityCalculator(); - if (applicabilityCalculator == null || applicabilityCalculator.isOptionUsedInCommandLine(this)) { + IBuildObject config = null; + IBuildObject parent = getParent(); + if ( parent instanceof IResourceConfiguration ) { + config = parent; + } else if ( parent instanceof IToolChain ){ + config = ((IToolChain)parent).getParent(); + } + if (applicabilityCalculator == null || applicabilityCalculator.isOptionUsedInCommandLine(config, this, option)) { try{ switch (option.getValueType()) { case IOption.BOOLEAN : @@ -2424,11 +2258,8 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { if (isDirty) return true; // Otherwise see if any options need saving - List optionElements = getOptionList(); - Iterator iter = optionElements.listIterator(); - while (iter.hasNext()) { - Option option = (Option) iter.next(); - if (option.isDirty()) return true; + if (super.isDirty()) { + return true; } return isDirty; @@ -2439,16 +2270,12 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { */ public void setDirty(boolean isDirty) { this.isDirty = isDirty; + // Propagate "false" to options + super.setDirty(isDirty); // Propagate "false" to the children if (!isDirty) { - List optionElements = getOptionList(); - Iterator iter = optionElements.listIterator(); - while (iter.hasNext()) { - Option option = (Option) iter.next(); - option.setDirty(false); - } List typeElements = getInputTypeList(); - iter = typeElements.listIterator(); + Iterator iter = typeElements.listIterator(); while (iter.hasNext()) { InputType type = (InputType) iter.next(); type.setDirty(false); @@ -2470,8 +2297,8 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { resolved = true; // Resolve superClass if (superClassId != null && superClassId.length() > 0) { - superClass = ManagedBuildManager.getExtensionTool(superClassId); - if (superClass == null) { + setSuperClass( ManagedBuildManager.getExtensionTool(superClassId) ); + if (getSuperClass() == null) { // Report error ManagedBuildManager.OutputResolveError( "superClass", //$NON-NLS-1$ @@ -2480,12 +2307,9 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { getId()); } } + // Resolve HoldsOptions + super.resolveReferences(); // Call resolveReferences on our children - Iterator optionIter = getOptionList().iterator(); - while (optionIter.hasNext()) { - Option current = (Option)optionIter.next(); - current.resolveReferences(); - } Iterator typeIter = getInputTypeList().iterator(); while (typeIter.hasNext()) { InputType current = (InputType)typeIter.next(); @@ -2496,17 +2320,6 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { OutputType current = (OutputType)typeIter.next(); current.resolveReferences(); } - // Somewhat wasteful, but use the vector to retrieve the categories in proper order - Iterator catIter = getCategoryIds().iterator(); - while (catIter.hasNext()) { - String id = (String)catIter.next(); - IOptionCategory current = (IOptionCategory)getCategoryMap().get(id); - if (current instanceof Tool) { - ((Tool)current).resolveReferences(); - } else if (current instanceof OptionCategory) { - ((OptionCategory)current).resolveReferences(); - } - } } } @@ -2526,8 +2339,8 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { public String getConvertToId() { if (convertToId == null) { // If I have a superClass, ask it - if (superClass != null) { - return superClass.getConvertToId(); + if (getSuperClass() != null) { + return getSuperClass().getConvertToId(); } else { return EMPTY_STRING; } @@ -2553,8 +2366,8 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { public String getVersionsSupported() { if (versionsSupported == null) { // If I have a superClass, ask it - if (superClass != null) { - return superClass.getVersionsSupported(); + if (getSuperClass() != null) { + return getSuperClass().getVersionsSupported(); } else { return EMPTY_STRING; } @@ -2582,8 +2395,8 @@ public class Tool extends BuildObject implements ITool, IOptionCategory { return (IEnvVarBuildPath[])envVarBuildPathList.toArray( new IEnvVarBuildPath[envVarBuildPathList.size()]); } - else if(superClass != null) - return superClass.getEnvVarBuildPaths(); + else if(getSuperClass() != null) + return getSuperClass().getEnvVarBuildPaths(); return null; } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolChain.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolChain.java index 6195f6a6416..47e4c116c54 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolChain.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolChain.java @@ -38,12 +38,16 @@ import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; -public class ToolChain extends BuildObject implements IToolChain { +public class ToolChain extends HoldsOptions implements IToolChain { private static final String EMPTY_STRING = new String(); + private static final boolean resolvedDefault = true; + // Superclass - private IToolChain superClass; + // Note that superClass itself is defined in the base and that the methods + // getSuperClass() and setSuperClass(), defined in ToolChain must be used + // to access it. This avoids widespread casts from IHoldsOptions to IToolChain. private String superClassId; // Parent and children private IConfiguration parent; @@ -72,8 +76,8 @@ public class ToolChain extends BuildObject implements IToolChain { // Miscellaneous private boolean isExtensionToolChain = false; private boolean isDirty = false; - private boolean resolved = true; - //holds the user-defined macros + private boolean resolved = resolvedDefault; + //holds the user-defined macros private StorableMacros userDefinedMacros; /* @@ -91,12 +95,13 @@ public class ToolChain extends BuildObject implements IToolChain { * @param managedBuildRevision the fileVersion of Managed Build System */ public ToolChain(IConfiguration parent, IManagedConfigElement element, String managedBuildRevision) { + // setup for resolving + super(false); + resolved = false; + this.parent = parent; isExtensionToolChain = true; - // setup for resolving - resolved = false; - // Set the managedBuildRevision setManagedBuildRevision(managedBuildRevision); @@ -125,12 +130,17 @@ public class ToolChain extends BuildObject implements IToolChain { builder = new Builder(this, builders[0], managedBuildRevision); } - // Load the tool children - IManagedConfigElement[] tools = element.getChildren(ITool.TOOL_ELEMENT_NAME); - for (int n = 0; n < tools.length; ++n) { - Tool toolChild = new Tool(this, tools[n], managedBuildRevision); - addTool(toolChild); - } + // Load children + IManagedConfigElement[] toolChainElements = element.getChildren(); + for (int l = 0; l < toolChainElements.length; ++l) { + IManagedConfigElement toolChainElement = toolChainElements[l]; + if (loadChild(toolChainElement)) { + // do nothing + } else if (toolChainElement.getName().equals(ITool.TOOL_ELEMENT_NAME)) { + Tool toolChild = new Tool(this, toolChainElement, managedBuildRevision); + addTool(toolChild); + } + } } /** @@ -144,12 +154,13 @@ public class ToolChain extends BuildObject implements IToolChain { * @param boolean Indicates whether this is an extension element or a managed project element */ public ToolChain(Configuration parent, IToolChain superClass, String Id, String name, boolean isExtensionElement) { + super(resolvedDefault); this.parent = parent; - this.superClass = superClass; + setSuperClass(superClass); setManagedBuildRevision(parent.getManagedBuildRevision()); - if (this.superClass != null) { - superClassId = this.superClass.getId(); + if (getSuperClass() != null) { + superClassId = getSuperClass().getId(); } setId(Id); setName(name); @@ -173,6 +184,7 @@ public class ToolChain extends BuildObject implements IToolChain { * @param managedBuildRevision the fileVersion of Managed Build System */ public ToolChain(IConfiguration parent, Element element, String managedBuildRevision) { + super(resolvedDefault); this.parent = parent; isExtensionToolChain = false; @@ -186,7 +198,9 @@ public class ToolChain extends BuildObject implements IToolChain { NodeList configElements = element.getChildNodes(); for (int i = 0; i < configElements.getLength(); ++i) { Node configElement = configElements.item(i); - if (configElement.getNodeName().equals(ITool.TOOL_ELEMENT_NAME)) { + if (loadChild(configElement)) { + // do nothing + } else if (configElement.getNodeName().equals(ITool.TOOL_ELEMENT_NAME)) { Tool tool = new Tool(this, (Element)configElement, managedBuildRevision); addTool(tool); }else if (configElement.getNodeName().equals(ITargetPlatform.TARGET_PLATFORM_ELEMENT_NAME)) { @@ -214,9 +228,10 @@ public class ToolChain extends BuildObject implements IToolChain { * @param toolChain The existing tool-chain to clone. */ public ToolChain(IConfiguration parent, String Id, String name, ToolChain toolChain) { + super(resolvedDefault); this.parent = parent; - superClass = toolChain.superClass; - if (superClass != null) { + setSuperClass(toolChain.getSuperClass()); + if (getSuperClass() != null) { if (toolChain.superClassId != null) { superClassId = new String(toolChain.superClassId); } @@ -271,6 +286,8 @@ public class ToolChain extends BuildObject implements IToolChain { buildMacroSupplierElement = toolChain.buildMacroSupplierElement; buildMacroSupplier = toolChain.buildMacroSupplier; + // Clone the children in superclass + super.copyChildren(toolChain); // Clone the children if (toolChain.builder != null) { int nnn = ManagedBuildManager.getRandomNumber(); @@ -455,8 +472,8 @@ public class ToolChain extends BuildObject implements IToolChain { // superClass superClassId = element.getAttribute(IProjectType.SUPERCLASS); if (superClassId != null && superClassId.length() > 0) { - superClass = ManagedBuildManager.getExtensionToolChain(superClassId); - if (superClass == null) { + setSuperClass( ManagedBuildManager.getExtensionToolChain(superClassId) ); + if (getSuperClass() == null) { // TODO: Report error } } @@ -536,124 +553,130 @@ public class ToolChain extends BuildObject implements IToolChain { * @param element */ public void serialize(Document doc, Element element) { - if (superClass != null) - element.setAttribute(IProjectType.SUPERCLASS, superClass.getId()); - - element.setAttribute(IBuildObject.ID, id); - - if (name != null) { - element.setAttribute(IBuildObject.NAME, name); - } - - if (unusedChildren != null) { - element.setAttribute(IProjectType.UNUSED_CHILDREN, unusedChildren); - } - - if (isAbstract != null) { - element.setAttribute(IProjectType.IS_ABSTRACT, isAbstract.toString()); - } - - if (errorParserIds != null) { - element.setAttribute(ERROR_PARSERS, errorParserIds); - } - - if (secondaryOutputIds != null) { - element.setAttribute(SECONDARY_OUTPUTS, secondaryOutputIds); - } - - if (targetToolIds != null) { - element.setAttribute(TARGET_TOOL, targetToolIds); - } - - if (scannerConfigDiscoveryProfileId != null) { - element.setAttribute(SCANNER_CONFIG_PROFILE_ID, scannerConfigDiscoveryProfileId); - } - - // versionsSupported - if (versionsSupported != null) { - element.setAttribute(VERSIONS_SUPPORTED, versionsSupported); - } - - // convertToId - if (convertToId != null) { - element.setAttribute(CONVERT_TO_ID, convertToId); - } - - if (osList != null) { - Iterator osIter = osList.listIterator(); - String listValue = EMPTY_STRING; - while (osIter.hasNext()) { - String current = (String) osIter.next(); - listValue += current; - if ((osIter.hasNext())) { - listValue += ","; //$NON-NLS-1$ - } + try { + if (getSuperClass() != null) + element.setAttribute(IProjectType.SUPERCLASS, getSuperClass().getId()); + + element.setAttribute(IBuildObject.ID, id); + + if (name != null) { + element.setAttribute(IBuildObject.NAME, name); } - element.setAttribute(OS_LIST, listValue); - } - - if (archList != null) { - Iterator archIter = archList.listIterator(); - String listValue = EMPTY_STRING; - while (archIter.hasNext()) { - String current = (String) archIter.next(); - listValue += current; - if ((archIter.hasNext())) { - listValue += ","; //$NON-NLS-1$ - } + + if (unusedChildren != null) { + element.setAttribute(IProjectType.UNUSED_CHILDREN, unusedChildren); } - element.setAttribute(ARCH_LIST, listValue); - } + + if (isAbstract != null) { + element.setAttribute(IProjectType.IS_ABSTRACT, isAbstract.toString()); + } + + if (errorParserIds != null) { + element.setAttribute(ERROR_PARSERS, errorParserIds); + } + + if (secondaryOutputIds != null) { + element.setAttribute(SECONDARY_OUTPUTS, secondaryOutputIds); + } + + if (targetToolIds != null) { + element.setAttribute(TARGET_TOOL, targetToolIds); + } + + if (scannerConfigDiscoveryProfileId != null) { + element.setAttribute(SCANNER_CONFIG_PROFILE_ID, scannerConfigDiscoveryProfileId); + } + + // versionsSupported + if (versionsSupported != null) { + element.setAttribute(VERSIONS_SUPPORTED, versionsSupported); + } + + // convertToId + if (convertToId != null) { + element.setAttribute(CONVERT_TO_ID, convertToId); + } + + if (osList != null) { + Iterator osIter = osList.listIterator(); + String listValue = EMPTY_STRING; + while (osIter.hasNext()) { + String current = (String) osIter.next(); + listValue += current; + if ((osIter.hasNext())) { + listValue += ","; //$NON-NLS-1$ + } + } + element.setAttribute(OS_LIST, listValue); + } + + if (archList != null) { + Iterator archIter = archList.listIterator(); + String listValue = EMPTY_STRING; + while (archIter.hasNext()) { + String current = (String) archIter.next(); + listValue += current; + if ((archIter.hasNext())) { + listValue += ","; //$NON-NLS-1$ + } + } + element.setAttribute(ARCH_LIST, listValue); + } + + // Serialize elements from my super class + super.serialize(doc, element); + + // Serialize my children + if (targetPlatform != null) { + Element targetPlatformElement = doc.createElement(ITargetPlatform.TARGET_PLATFORM_ELEMENT_NAME); + element.appendChild(targetPlatformElement); + targetPlatform.serialize(doc, targetPlatformElement); + } + if (builder != null) { + Element builderElement = doc.createElement(IBuilder.BUILDER_ELEMENT_NAME); + element.appendChild(builderElement); + builder.serialize(doc, builderElement); + } + List toolElements = getToolList(); + Iterator iter = toolElements.listIterator(); + while (iter.hasNext()) { + Tool tool = (Tool) iter.next(); + Element toolElement = doc.createElement(ITool.TOOL_ELEMENT_NAME); + element.appendChild(toolElement); + tool.serialize(doc, toolElement); + } + + // Note: isToolChainSupported cannot be specified in a project file because + // an IConfigurationElement is needed to load it! + if (managedIsToolChainSupportedElement != null) { + // TODO: issue warning? + } + + // Note: environmentVariableSupplier cannot be specified in a project file because + // an IConfigurationElement is needed to load it! + if(environmentVariableSupplierElement != null) { + // TODO: issue warning? + } + + // Note: buildMacroSupplier cannot be specified in a project file because + // an IConfigurationElement is needed to load it! + if(buildMacroSupplierElement != null) { + // TODO: issue warning? + } + + //serialize user-defined macros + if(userDefinedMacros != null){ + Element macrosElement = doc.createElement(StorableMacros.MACROS_ELEMENT_NAME); + element.appendChild(macrosElement); + userDefinedMacros.serialize(doc,macrosElement); + } - // Serialize my children - if (targetPlatform != null) { - Element targetPlatformElement = doc.createElement(ITargetPlatform.TARGET_PLATFORM_ELEMENT_NAME); - element.appendChild(targetPlatformElement); - targetPlatform.serialize(doc, targetPlatformElement); + // I am clean now + isDirty = false; + } catch (Exception e) { + // TODO: issue an error message } - if (builder != null) { - Element builderElement = doc.createElement(IBuilder.BUILDER_ELEMENT_NAME); - element.appendChild(builderElement); - builder.serialize(doc, builderElement); - } - List toolElements = getToolList(); - Iterator iter = toolElements.listIterator(); - while (iter.hasNext()) { - Tool tool = (Tool) iter.next(); - Element toolElement = doc.createElement(ITool.TOOL_ELEMENT_NAME); - element.appendChild(toolElement); - tool.serialize(doc, toolElement); - } - - // Note: isToolChainSupported cannot be specified in a project file because - // an IConfigurationElement is needed to load it! - if (managedIsToolChainSupportedElement != null) { - // TODO: issue warning? - } - - // Note: environmentVariableSupplier cannot be specified in a project file because - // an IConfigurationElement is needed to load it! - if(environmentVariableSupplierElement != null) { - // TODO: issue warning? - } - - - // Note: buildMacroSupplier cannot be specified in a project file because - // an IConfigurationElement is needed to load it! - if(buildMacroSupplierElement != null) { - // TODO: issue warning? - } - - //serialize user-defined macros - if(userDefinedMacros != null){ - Element macrosElement = doc.createElement(StorableMacros.MACROS_ELEMENT_NAME); - element.appendChild(macrosElement); - userDefinedMacros.serialize(doc,macrosElement); - } - - // I am clean now - isDirty = false; - } +} /* * P A R E N T A N D C H I L D H A N D L I N G @@ -680,8 +703,8 @@ public class ToolChain extends BuildObject implements IToolChain { */ public ITargetPlatform getTargetPlatform() { if (targetPlatform == null) { - if (superClass != null) { - return superClass.getTargetPlatform(); + if (getSuperClass() != null) { + return getSuperClass().getTargetPlatform(); } } return (ITargetPlatform)targetPlatform; @@ -710,8 +733,8 @@ public class ToolChain extends BuildObject implements IToolChain { */ public IBuilder getBuilder() { if (builder == null) { - if (superClass != null) { - return superClass.getBuilder(); + if (getSuperClass() != null) { + return getSuperClass().getBuilder(); } } return (IBuilder)builder; @@ -742,8 +765,8 @@ public class ToolChain extends BuildObject implements IToolChain { public ITool[] getTools() { ITool[] tools = null; // Merge our tools with our superclass' tools - if (superClass != null) { - tools = superClass.getTools(); + if (getSuperClass() != null) { + tools = getSuperClass().getTools(); } // Our tools take precedence if (tools != null) { @@ -752,12 +775,13 @@ public class ToolChain extends BuildObject implements IToolChain { Tool tool = (Tool)iter.next(); int j; for (j = 0; j < tools.length; j++) { - if (tool.getSuperClass().getId().equals(tools[j].getId())) { + if (tool.getSuperClass() != null // Remove assumption that ALL tools must have superclasses + && tool.getSuperClass().getId().equals(tools[j].getId())) { tools[j] = tool; break; } } - // No Match? Add it. + // No Match? Insert it (may be re-ordered) if (j == tools.length) { ITool[] newTools = new ITool[tools.length + 1]; for (int k = 0; k < tools.length; k++) { @@ -829,14 +853,22 @@ public class ToolChain extends BuildObject implements IToolChain { * @see org.eclipse.cdt.managedbuilder.core.IToolChain#getSuperClass() */ public IToolChain getSuperClass() { - return superClass; + return (IToolChain)superClass; + } + + /* (non-Javadoc) + * Access function to set the superclass element that is defined in + * the base class. + */ + private void setSuperClass(IToolChain superClass) { + this.superClass = superClass; } /* (non-Javadoc) * @see org.eclipse.cdt.core.build.managed.IToolChain#getName() */ public String getName() { - return (name == null && superClass != null) ? superClass.getName() : name; + return (name == null && getSuperClass() != null) ? getSuperClass().getName() : name; } /* (non-Javadoc) @@ -867,8 +899,8 @@ public class ToolChain extends BuildObject implements IToolChain { String ids = errorParserIds; if (ids == null) { // If I have a superClass, ask it - if (superClass != null) { - ids = superClass.getErrorParserIds(); + if (getSuperClass() != null) { + ids = getSuperClass().getErrorParserIds(); } } if (ids == null) { @@ -898,8 +930,8 @@ public class ToolChain extends BuildObject implements IToolChain { IOutputType[] types = null; String ids = secondaryOutputIds; if (ids == null) { - if (superClass != null) { - return superClass.getSecondaryOutputs(); + if (getSuperClass() != null) { + return getSuperClass().getSecondaryOutputs(); } else { return new IOutputType[0]; @@ -929,8 +961,8 @@ public class ToolChain extends BuildObject implements IToolChain { public String getTargetToolIds() { if (targetToolIds == null) { // Ask superClass for its list - if (superClass != null) { - return superClass.getTargetToolIds(); + if (getSuperClass() != null) { + return getSuperClass().getTargetToolIds(); } else { return null; } @@ -970,8 +1002,8 @@ public class ToolChain extends BuildObject implements IToolChain { String ids = errorParserIds; if (ids == null) { // If I have a superClass, ask it - if (superClass != null) { - ids = superClass.getErrorParserIds(config); + if (getSuperClass() != null) { + ids = getSuperClass().getErrorParserIds(config); } } if (ids == null) { @@ -1027,8 +1059,8 @@ public class ToolChain extends BuildObject implements IToolChain { public String[] getArchList() { if (archList == null) { // Ask superClass for its list - if (superClass != null) { - return superClass.getArchList(); + if (getSuperClass() != null) { + return getSuperClass().getArchList(); } else { // I have no superClass and no defined list return new String[] {"all"}; //$NON-NLS-1$ @@ -1043,8 +1075,8 @@ public class ToolChain extends BuildObject implements IToolChain { public String[] getOSList() { if (osList == null) { // Ask superClass for its list - if (superClass != null) { - return superClass.getOSList(); + if (getSuperClass() != null) { + return getSuperClass().getOSList(); } else { // I have no superClass and no defined filter list return new String[] {"all"}; //$NON-NLS-1$ @@ -1130,8 +1162,8 @@ public class ToolChain extends BuildObject implements IToolChain { */ public String getScannerConfigDiscoveryProfileId() { if (scannerConfigDiscoveryProfileId == null) { - if (superClass != null) { - return superClass.getScannerConfigDiscoveryProfileId(); + if (getSuperClass() != null) { + return getSuperClass().getScannerConfigDiscoveryProfileId(); } } return scannerConfigDiscoveryProfileId; @@ -1181,6 +1213,11 @@ public class ToolChain extends BuildObject implements IToolChain { if (toolChild.isDirty()) return true; } + // Otherwise see if any options need saving + if (super.isDirty()) { + return true; + } + return isDirty; } @@ -1189,6 +1226,8 @@ public class ToolChain extends BuildObject implements IToolChain { */ public void setDirty(boolean isDirty) { this.isDirty = isDirty; + // Propagate "false" to options + super.setDirty(isDirty); // Propagate "false" to the children if (!isDirty) { Iterator iter = getToolList().listIterator(); @@ -1207,8 +1246,8 @@ public class ToolChain extends BuildObject implements IToolChain { resolved = true; // Resolve superClass if (superClassId != null && superClassId.length() > 0) { - superClass = ManagedBuildManager.getExtensionToolChain(superClassId); - if (superClass == null) { + setSuperClass(ManagedBuildManager.getExtensionToolChain(superClassId)); + if (getSuperClass() == null) { // Report error ManagedBuildManager.OutputResolveError( "superClass", //$NON-NLS-1$ @@ -1217,6 +1256,8 @@ public class ToolChain extends BuildObject implements IToolChain { getId()); } } + // Resolve HoldsOptions + super.resolveReferences(); // Call resolveReferences on our children if (targetPlatform != null) { targetPlatform.resolveReferences(); @@ -1262,8 +1303,8 @@ public class ToolChain extends BuildObject implements IToolChain { public String getConvertToId() { if (convertToId == null) { // If I have a superClass, ask it - if (superClass != null) { - return superClass.getConvertToId(); + if (getSuperClass() != null) { + return getSuperClass().getConvertToId(); } else { return EMPTY_STRING; } @@ -1289,8 +1330,8 @@ public class ToolChain extends BuildObject implements IToolChain { public String getVersionsSupported() { if (versionsSupported == null) { // If I have a superClass, ask it - if (superClass != null) { - return superClass.getVersionsSupported(); + if (getSuperClass() != null) { + return getSuperClass().getVersionsSupported(); } else { return EMPTY_STRING; } @@ -1333,7 +1374,7 @@ public class ToolChain extends BuildObject implements IToolChain { } catch (CoreException e) {} } } - + if(managedIsToolChainSupported != null) return managedIsToolChainSupported.isSupported(this,null,null); return true; @@ -1346,8 +1387,8 @@ public class ToolChain extends BuildObject implements IToolChain { */ public IConfigurationElement getEnvironmentVariableSupplierElement(){ if (environmentVariableSupplierElement == null) { - if (superClass != null && superClass instanceof ToolChain) { - return ((ToolChain)superClass).getEnvironmentVariableSupplierElement(); + if (getSuperClass() != null && getSuperClass() instanceof ToolChain) { + return ((ToolChain)getSuperClass()).getEnvironmentVariableSupplierElement(); } } return environmentVariableSupplierElement; 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 240cbe476bc..91f5e7bce37 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 @@ -18,6 +18,7 @@ import java.util.List; import org.eclipse.cdt.managedbuilder.core.BuildException; import org.eclipse.cdt.managedbuilder.core.IBuildObject; import org.eclipse.cdt.managedbuilder.core.IConfigurationV2; +import org.eclipse.cdt.managedbuilder.core.IHoldsOptions; import org.eclipse.cdt.managedbuilder.core.IInputType; import org.eclipse.cdt.managedbuilder.core.IEnvVarBuildPath; import org.eclipse.cdt.managedbuilder.core.IOptionApplicability; @@ -25,7 +26,9 @@ import org.eclipse.cdt.managedbuilder.core.IManagedConfigElement; import org.eclipse.cdt.managedbuilder.core.IOption; import org.eclipse.cdt.managedbuilder.core.IOptionCategory; import org.eclipse.cdt.managedbuilder.core.IOutputType; +import org.eclipse.cdt.managedbuilder.core.IResourceConfiguration; import org.eclipse.cdt.managedbuilder.core.ITool; +import org.eclipse.cdt.managedbuilder.core.IToolChain; import org.eclipse.cdt.managedbuilder.core.IToolReference; import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; import org.eclipse.cdt.managedbuilder.core.IManagedCommandLineGenerator; @@ -446,71 +449,81 @@ public class ToolReference implements IToolReference { // check to see if the option has an applicability calculator IOptionApplicability applicabilityCalculator = option.getApplicabilityCalculator(); - if (applicabilityCalculator == null - || applicabilityCalculator.isOptionUsedInCommandLine(getTool())) { - switch (option.getValueType()) { - case IOption.BOOLEAN : - String boolCmd; - if (option.getBooleanValue()) { - boolCmd = option.getCommand(); - } else { - // Note: getCommandFalse is new with CDT 2.0 - boolCmd = option.getCommandFalse(); - } - if (boolCmd != null && boolCmd.length() > 0) { - buf.append(boolCmd + WHITE_SPACE); - } - break; - - case IOption.ENUMERATED : - String enumVal = option.getEnumCommand(option.getSelectedEnum()); - if (enumVal.length() > 0) { - buf.append(enumVal + WHITE_SPACE); - } - break; - - case IOption.STRING : - String strCmd = option.getCommand(); - String val = option.getStringValue(); - if (val.length() > 0) { - if (strCmd != null) buf.append(strCmd); - buf.append(val + WHITE_SPACE); - } - break; - - case IOption.STRING_LIST : - String cmd = option.getCommand(); - String[] list = option.getStringListValue(); - for (int j = 0; j < list.length; j++) { - String temp = list[j]; - if (cmd != null) buf.append(cmd); - buf.append(temp + WHITE_SPACE); - } - break; - - case IOption.INCLUDE_PATH : - String incCmd = option.getCommand(); - String[] paths = option.getIncludePaths(); - for (int j = 0; j < paths.length; j++) { - String temp = paths[j]; - buf.append(incCmd + temp + WHITE_SPACE); - } - break; - - case IOption.PREPROCESSOR_SYMBOLS : - String defCmd = option.getCommand(); - String[] symbols = option.getDefinedSymbols(); - for (int j = 0; j < symbols.length; j++) { - String temp = symbols[j]; - buf.append(defCmd + temp + WHITE_SPACE); - } - break; - - default : - break; + boolean optionIsApplicable = true; + if (applicabilityCalculator != null) { + ITool tool = getTool(); + IBuildObject config; + if( tool.getParent() instanceof IResourceConfiguration ) { + config = tool.getParent(); + } else { + config = ((IToolChain)tool.getParent()).getParent(); + } + optionIsApplicable = + applicabilityCalculator.isOptionUsedInCommandLine(config, tool, option); + } + if (optionIsApplicable) { + switch (option.getValueType()) { + case IOption.BOOLEAN : + String boolCmd; + if (option.getBooleanValue()) { + boolCmd = option.getCommand(); + } else { + // Note: getCommandFalse is new with CDT 2.0 + boolCmd = option.getCommandFalse(); + } + if (boolCmd != null && boolCmd.length() > 0) { + buf.append(boolCmd + WHITE_SPACE); + } + break; + + case IOption.ENUMERATED : + String enumVal = option.getEnumCommand(option.getSelectedEnum()); + if (enumVal.length() > 0) { + buf.append(enumVal + WHITE_SPACE); + } + break; + + case IOption.STRING : + String strCmd = option.getCommand(); + String val = option.getStringValue(); + if (val.length() > 0) { + if (strCmd != null) buf.append(strCmd); + buf.append(val + WHITE_SPACE); + } + break; + + case IOption.STRING_LIST : + String cmd = option.getCommand(); + String[] list = option.getStringListValue(); + for (int j = 0; j < list.length; j++) { + String temp = list[j]; + if (cmd != null) buf.append(cmd); + buf.append(temp + WHITE_SPACE); + } + break; + + case IOption.INCLUDE_PATH : + String incCmd = option.getCommand(); + String[] paths = option.getIncludePaths(); + for (int j = 0; j < paths.length; j++) { + String temp = paths[j]; + buf.append(incCmd + temp + WHITE_SPACE); + } + break; + + case IOption.PREPROCESSOR_SYMBOLS : + String defCmd = option.getCommand(); + String[] symbols = option.getDefinedSymbols(); + for (int j = 0; j < symbols.length; j++) { + String temp = symbols[j]; + buf.append(defCmd + temp + WHITE_SPACE); + } + break; + + default : + break; + } } - - } } return buf.toString().trim(); @@ -918,6 +931,12 @@ public class ToolReference implements IToolReference { return null; } + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.core.IHoldsOptions#createOptions() + */ + public void createOptions(IHoldsOptions options) { + } + /* (non-Javadoc) * @see org.eclipse.cdt.managedbuilder.core.ITool#removeOption() */ @@ -1088,7 +1107,15 @@ public class ToolReference implements IToolReference { public IOption getOptionBySuperClassId(String id) { return null; } + + public IOptionCategory getOptionCategory(String id) { + // return null as class is deprecated + return null; + } + public void addOptionCategory(IOptionCategory category) { + } + /* * The following methods are added to allow the converter from ToolReference -> Tool * to retrieve the actual value of attributes. These routines do not go to the diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/macros/MbsMacroSupplier.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/macros/MbsMacroSupplier.java index 11f69b53714..2fea7ee20a4 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/macros/MbsMacroSupplier.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/macros/MbsMacroSupplier.java @@ -798,7 +798,13 @@ public class MbsMacroSupplier implements IBuildMacroSupplier { return null; IOption parentOption = null; - ITool tool = option.getParent(); + // TODO: In CDT 3.0. Option.getParent can return a Tool or ToolChain + // We need to decide what to do with the ToolChain case + IBuildObject parent = option.getParent(); + ITool tool = null; + if (parent instanceof ITool) { + tool = (ITool)parent; + } IBuildObject bo = optionContext.getParent(); if(tool != null && bo instanceof IResourceConfiguration){ @@ -861,8 +867,14 @@ public class MbsMacroSupplier implements IBuildMacroSupplier { } if(parentOption != null){ + // TODO: In CDT 3.0. Option.getParent can return a Tool or ToolChain + // We need to decide what to do with the ToolChain case IBuildObject parentObject = null; - ITool t = parentOption.getParent(); + ITool t = null; + IBuildObject parentParent = parentOption.getParent(); + if (parentParent instanceof ITool) { + t = (ITool)parentParent; + } if(t != null) parentObject = t.getParent(); return new OptionContextData(parentOption,parentObject); diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/ToolsSettingsBlock.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/ToolsSettingsBlock.java index e6d32b608a3..b18c1926970 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/ToolsSettingsBlock.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/ToolsSettingsBlock.java @@ -19,9 +19,11 @@ import java.util.Map; import org.eclipse.cdt.managedbuilder.core.IBuildObject; import org.eclipse.cdt.managedbuilder.core.IConfiguration; +import org.eclipse.cdt.managedbuilder.core.IManagedOptionValueHandler; import org.eclipse.cdt.managedbuilder.core.IOptionCategory; import org.eclipse.cdt.managedbuilder.core.IResourceConfiguration; import org.eclipse.cdt.managedbuilder.core.ITool; +import org.eclipse.cdt.managedbuilder.core.IToolChain; import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; import org.eclipse.cdt.managedbuilder.internal.macros.BuildMacroProvider; import org.eclipse.cdt.managedbuilder.ui.properties.BuildOptionSettingsPage; @@ -436,37 +438,25 @@ public class ToolsSettingsBlock extends AbstractCOptionPage { // There is a selected option or category. // See if it matches any category in the current config (by name) ITool[] tools = null; + IToolChain toolChain = null; + if ( element instanceof IProject ) { tools = config.getFilteredTools(); + toolChain = config.getToolChain(); } else if ( element instanceof IFile){ tools = resConfig.getTools(); } - String matchName = EMPTY_STRING; IBuildObject catOrTool = selectedCategory; - do { - matchName = catOrTool.getName() + matchName; - if (catOrTool instanceof ITool) break; - else if (catOrTool instanceof IOptionCategory) { - catOrTool = ((IOptionCategory)catOrTool).getOwner(); - } else break; - } while (catOrTool != null); - for (int i=0; iCat1->Cat2 + * maps onto the string "Tool|Cat1|Cat2|" + * + * @param category or tool for which to build the match name + * @return match name + */ + private String makeMatchName(IBuildObject catOrTool) { + String catName = EMPTY_STRING; + + // Build the match name. + do { + catName = catOrTool.getName() + "|" + catName; + if (catOrTool instanceof ITool) break; + else if (catOrTool instanceof IOptionCategory) { + catOrTool = ((IOptionCategory)catOrTool).getOwner(); + } else + break; + } while (catOrTool != null); + + return catName; + } + + /** + * Finds an option category from an array of categories by comparing against + * a match name. The match name is a concatenation of the tool and categories, + * e.g. Tool->Cat1->Cat2 maps onto the string "Tool|Cat1|Cat2|" + * + * @param matchName an identifier to search + * @param categories as returned by getChildCategories(), i.e. non-flattened + * @return category or tool, if found and null otherwise + */ + private Object findOptionCategoryByMatchName(String matchName, IOptionCategory[] cats) { + Object primary = null; + + for (int j=0; j 0) ? enumId : enumVal); } else { - setOption = ManagedBuildManager.setOption(configuration, tool, option, + setOption = ManagedBuildManager.setOption(configuration, holder, option, (enumId != null && enumId.length() > 0) ? enumId : enumVal); } // Reset the preference store since the Id may have changed @@ -276,9 +312,9 @@ public class BuildOptionSettingsPage extends BuildSettingsPage { case IOption.STRING : String strVal = getToolSettingsPreferenceStore().getString(option.getId()); if(isItResourceConfigPage){ - setOption = ManagedBuildManager.setOption(resConfig, tool, option, strVal); + setOption = ManagedBuildManager.setOption(resConfig, holder, option, strVal); } else { - setOption = ManagedBuildManager.setOption(configuration, tool, option, strVal); + setOption = ManagedBuildManager.setOption(configuration, holder, option, strVal); } // Reset the preference store since the Id may have changed @@ -296,9 +332,9 @@ public class BuildOptionSettingsPage extends BuildSettingsPage { String listStr = getToolSettingsPreferenceStore().getString(option.getId()); String[] listVal = BuildToolsSettingsStore.parseString(listStr); if( isItResourceConfigPage){ - setOption = ManagedBuildManager.setOption(resConfig, tool, option, listVal); + setOption = ManagedBuildManager.setOption(resConfig, holder, option, listVal); }else { - setOption = ManagedBuildManager.setOption(configuration, tool, option, listVal); + setOption = ManagedBuildManager.setOption(configuration, holder, option, listVal); } // Reset the preference store since the Id may have changed @@ -311,7 +347,25 @@ public class BuildOptionSettingsPage extends BuildSettingsPage { default : break; } + + // Call an MBS CallBack function to inform that Settings related to Apply/OK button + // press have been applied. + if (setOption == null) + setOption = option; + + if (setOption.getValueHandler().handleValue( + getConfigurationHandle(), + setOption.getOptionHolder(), + setOption, + setOption.getValueHandlerExtraArgument(), + IManagedOptionValueHandler.EVENT_APPLY)) { + // TODO : Event is handled successfully and returned true. + // May need to do something here say log a message. + } else { + // Event handling Failed. + } } catch (BuildException e) {} + } return ok; } @@ -338,17 +392,23 @@ public class BuildOptionSettingsPage extends BuildSettingsPage { super.performOk(); } - private void setFieldEditorEnablement(ITool tool, IOptionApplicability optionApplicability, - FieldEditor fieldEditor, Composite parent) { + private void setFieldEditorEnablement(IHoldsOptions holder, IOption option, + IOptionApplicability optionApplicability, FieldEditor fieldEditor, Composite parent) { if (optionApplicability == null) return; // if the option is not enabled then disable it - if (!optionApplicability.isOptionEnabled(tool)) { - fieldEditor.setEnabled(false, parent); + IBuildObject config; + if ( isItResourceConfigPage ) { + config = resConfig; } else { - fieldEditor.setEnabled(true, parent); + config = configuration; } + //if (!optionApplicability.isOptionEnabled(config, holder, )) { + // fieldEditor.setEnabled(false, parent); + //} else { + // fieldEditor.setEnabled(true, parent); + //} } /* (non-Javadoc) @@ -369,8 +429,8 @@ public class BuildOptionSettingsPage extends BuildSettingsPage { for (int index = 0; index < options.length; ++index) { // Get the option - ITool tool = (ITool) options[index][0]; - if (tool == null) + IHoldsOptions holder = (IHoldsOptions) options[index][0]; + if (holder == null) break; // The array may not be full IOption opt = (IOption) options[index][1]; @@ -382,7 +442,7 @@ public class BuildOptionSettingsPage extends BuildSettingsPage { if (applicabilityCalculator != null) { FieldEditor fieldEditor = (FieldEditor) fieldsMap.get(opt.getId()); Composite parent = (Composite) fieldEditorsToParentMap.get(fieldEditor); - setFieldEditorEnablement(tool, applicabilityCalculator, fieldEditor, parent); + setFieldEditorEnablement(holder, opt, applicabilityCalculator, fieldEditor, parent); } } diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/BuildToolSettingsPage.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/BuildToolSettingsPage.java index ab2eb71fa1d..ebaaeb59a8b 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/BuildToolSettingsPage.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/BuildToolSettingsPage.java @@ -21,6 +21,7 @@ import java.util.Vector; import org.eclipse.cdt.managedbuilder.core.BuildException; import org.eclipse.cdt.managedbuilder.core.IBuildObject; import org.eclipse.cdt.managedbuilder.core.IConfiguration; +import org.eclipse.cdt.managedbuilder.core.IManagedOptionValueHandler; import org.eclipse.cdt.managedbuilder.core.IOptionApplicability; import org.eclipse.cdt.managedbuilder.core.IManagedCommandLineGenerator; import org.eclipse.cdt.managedbuilder.core.IManagedCommandLineInfo; @@ -136,6 +137,17 @@ public class BuildToolSettingsPage extends BuildSettingsPage { public Point computeSize() { return super.computeSize(); } + /* (non-Javadoc) + * Private access function which returns the correct configuration + * argument for valueHandler call-backs. + */ + private IBuildObject getConfigurationHandle() { + if ( isItResourceConfigPage ) { + return resConfig; + } else { + return configuration; + } + } /* * (non-Javadoc) @@ -257,6 +269,7 @@ public class BuildToolSettingsPage extends BuildSettingsPage { String listStr = ""; //$NON-NLS-1$ String[] listVal = null; IBuildObject parent = configuration != null ? (IBuildObject)configuration.getToolChain() : (IBuildObject)resConfig; + IBuildObject config = configuration != null ? (IBuildObject)configuration : (IBuildObject)resConfig; IMacroSubstitutor macroSubstitutor = new UIMacroSubstitutor(0,null,EMPTY_STRING,WHITESPACE,fProvider); for (int k = 0; k < options.length; k++) { IOption option = options[k]; @@ -264,7 +277,7 @@ public class BuildToolSettingsPage extends BuildSettingsPage { // check to see if the option has an applicability calculator IOptionApplicability applicabilityCalculator = option.getApplicabilityCalculator(); - if (applicabilityCalculator == null || applicabilityCalculator.isOptionUsedInCommandLine(tool)) { + if (applicabilityCalculator == null || applicabilityCalculator.isOptionUsedInCommandLine(config, tool, option)) { try{ switch (option.getValueType()) { @@ -581,9 +594,10 @@ public class BuildToolSettingsPage extends BuildSettingsPage { ITool tool = (ITool)options[i][0]; if (tool == null) break; // The array may not be full IOption option = (IOption)options[i][1]; + try { // Transfer value from preference store to options - IOption setOption; + IOption setOption = null; switch (option.getValueType()) { case IOption.BOOLEAN : boolean boolVal = getToolSettingsPreferenceStore().getBoolean(option.getId()); @@ -627,6 +641,23 @@ public class BuildToolSettingsPage extends BuildSettingsPage { default : break; } + + // Call an MBS CallBack function to inform that Settings related to Apply/OK button + // press have been applied. + if (setOption == null) + setOption = option; + + if (setOption.getValueHandler().handleValue( + getConfigurationHandle(), + setOption.getOptionHolder(), + setOption, + setOption.getValueHandlerExtraArgument(), + IManagedOptionValueHandler.EVENT_APPLY)) { + // TODO : Event is handled successfully and returned true. + // May need to do something here say log a message. + } else { + // Event handling Failed. + } } catch (BuildException e) {} } diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/BuildToolsSettingsStore.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/BuildToolsSettingsStore.java index 1aa7a628db2..fd9028249ab 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/BuildToolsSettingsStore.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/BuildToolsSettingsStore.java @@ -1,5 +1,5 @@ /********************************************************************** - * Copyright (c) 2002,2004 IBM Corporation and others. + * Copyright (c) 2002,2005 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v0.5 * which accompanies this distribution, and is available at @@ -15,10 +15,12 @@ import java.util.Map; import org.eclipse.cdt.managedbuilder.core.BuildException; import org.eclipse.cdt.managedbuilder.core.IConfiguration; +import org.eclipse.cdt.managedbuilder.core.IHoldsOptions; import org.eclipse.cdt.managedbuilder.core.IOption; import org.eclipse.cdt.managedbuilder.core.IOptionCategory; import org.eclipse.cdt.managedbuilder.core.IResourceConfiguration; import org.eclipse.cdt.managedbuilder.core.ITool; +import org.eclipse.cdt.managedbuilder.core.IToolChain; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.ListenerList; @@ -237,8 +239,8 @@ public class BuildToolsSettingsStore implements IPreferenceStore { if ( options == null) return; for (int j = 0; j < options.length; ++j) { - ITool tool = (ITool)options[j][0]; - if (tool == null) break; // The array may not be full + IHoldsOptions optionHolder = (IHoldsOptions)options[j][0]; + if (optionHolder == null) break; // The array may not be full IOption opt = (IOption)options[j][1]; String name = opt.getId(); Object value; @@ -367,24 +369,41 @@ public class BuildToolsSettingsStore implements IPreferenceStore { private void populateSettingsMap() { // Each configuration has a list of tools ITool [] tools; + IOptionCategory [] toolChainsCategories; + int index; - // If resConfigOwner is not null, get the resource specific tools. - + // If resConfigOwner is not null, get the resource specific tools. if ( resConfigOwner != null) { tools = resConfigOwner.getTools(); + // Resource configurations do not support categories that + // are children of toolchains. The reason for this is that + // options in such categories are intended to be global. + // TODO: Remove this restriction in future? + toolChainsCategories = new IOptionCategory[0]; } else { + // Get the tools tools = owner.getFilteredTools(); + // Get the the option categories of the toolChain + IToolChain toolChain = owner.getToolChain(); + toolChainsCategories = toolChain.getChildCategories(); } - for (int index = 0; index < tools.length; ++index) { + // Add the tools options to the map + for (index = 0; index < tools.length; ++index) { // Add the tool to the map ITool tool = tools[index]; getSettingsMap().put(tool.getId(), tool.getToolCommand()); - + // Add the options defined for the tool IOptionCategory cat = tool.getTopOptionCategory(); getOptionsForCategory(cat); } + + // Add the tool chain options to the map + for (index = 0; index < toolChainsCategories.length; ++index) { + // Add the options defined for the category + getOptionsForCategory(toolChainsCategories[index]); + } } /* (non-Javadoc) diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/ToolListContentProvider.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/ToolListContentProvider.java index f67a93c39e2..13f74c6f5b0 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/ToolListContentProvider.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/ToolListContentProvider.java @@ -1,5 +1,5 @@ /********************************************************************** - * Copyright (c) 2002,2003 IBM Corporation and others. + * Copyright (c) 2002,2005 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v0.5 * which accompanies this distribution, and is available at @@ -15,6 +15,7 @@ import org.eclipse.cdt.managedbuilder.core.IConfiguration; import org.eclipse.cdt.managedbuilder.core.IResourceConfiguration; import org.eclipse.cdt.managedbuilder.core.IOptionCategory; import org.eclipse.cdt.managedbuilder.core.ITool; +import org.eclipse.cdt.managedbuilder.core.IToolChain; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.Viewer; @@ -35,6 +36,33 @@ public class ToolListContentProvider implements ITreeContentProvider{ public ToolListContentProvider(int elementType) { this.elementType = elementType; } + + /** + * Gets the top level contents to be displayed in the tool list. + * If defined, first display the toolChain's option categories (unfiltered). + * Then display the the tools which are relevant for the project's nature. + */ + private Object[] getToplevelContent(IConfiguration config) { + Object toolChainsCategories[]; + Object filteredTools[]; + Object all[]; + // Get the the option categories of the toolChain + IToolChain toolChain = config.getToolChain(); + toolChainsCategories = toolChain.getChildCategories(); + // Get the tools to be displayed + filteredTools = config.getFilteredTools(); + // Add up both arrays and return + int i; + int len = toolChainsCategories.length+filteredTools.length; + all = new Object[len]; + for (i=0; i < toolChainsCategories.length; i++) + all[i] = toolChainsCategories[i]; + for (; i < len; i++) + all[i] = filteredTools[i-toolChainsCategories.length]; + + return all; + } + /** * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object) */ @@ -42,10 +70,14 @@ public class ToolListContentProvider implements ITreeContentProvider{ // If parent is configuration, return a list of its option categories if (parentElement instanceof IConfiguration) { IConfiguration config = (IConfiguration)parentElement; - // the categories are all accessed through the tools - return config.getFilteredTools(); + // Get the contents to be displayed for the configuration + return getToplevelContent(config); } else if( parentElement instanceof IResourceConfiguration) { - // If parent is a resource configuration, return a list of its tools + // If parent is a resource configuration, return a list of its tools. + // Resource configurations do not support categories that are children + // of toolchains. The reason for this is that options in such categories + // are intended to be global. + // TODO: Remove this restriction in future? Requires getToplevelContent() variant IResourceConfiguration resConfig = (IResourceConfiguration)parentElement; return resConfig.getTools(); } else if (parentElement instanceof ITool) { diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/ToolListLabelProvider.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/ToolListLabelProvider.java index e9d00a093d0..2217101c505 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/ToolListLabelProvider.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/ToolListLabelProvider.java @@ -1,5 +1,5 @@ /********************************************************************** - * Copyright (c) 2002,2004 IBM Corporation and others. + * Copyright (c) 2002,2005 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v0.5 * which accompanies this distribution, and is available at @@ -10,12 +10,19 @@ * **********************************************************************/ package org.eclipse.cdt.managedbuilder.ui.properties; +import java.net.URL; + import org.eclipse.cdt.managedbuilder.core.IOptionCategory; import org.eclipse.cdt.managedbuilder.core.ITool; import org.eclipse.cdt.managedbuilder.internal.ui.ManagedBuilderUIImages; import org.eclipse.cdt.managedbuilder.internal.ui.ManagedBuilderUIMessages; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.resource.ResourceManager; +import org.eclipse.jface.util.Assert; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; public class ToolListLabelProvider extends LabelProvider { private final Image IMG_TOOL = ManagedBuilderUIImages.get(ManagedBuilderUIImages.IMG_BUILD_TOOL); @@ -23,17 +30,59 @@ public class ToolListLabelProvider extends LabelProvider { private static final String TREE_LABEL = "BuildPropertyPage.label.ToolTree"; //$NON-NLS-1$ private static final String ERROR_UNKNOWN_ELEMENT = "BuildPropertyPage.error.Unknown_tree_element"; //$NON-NLS-1$ + private ImageDescriptor descriptor = null; + private ResourceManager manager = null; + + /* (non-Javadoc) + * Returns the Image associated with the icon information retrieved out of OptionCategory. + */ + private Image getIconFromOptionCategory(IOptionCategory cat) { + + Image img = null; + URL url = cat.getIconPath(); + + // Get the image from the URL. + if (url != null) { + descriptor = ImageDescriptor.createFromURL(url); + manager = JFaceResources.getResources(Display.getCurrent()); + Assert.isNotNull(manager); + img = manager.createImageWithDefault(descriptor); + if (img == null) { + // Report error by displaying a warning message + System.err.println("Couldn't create image from URL \"" + url + "\", to display icon for Tool Options." ); //$NON-NLS-1$ + } + } + return img; + } + public Image getImage(Object element) { // Return a tool image for a tool or tool reference if (element instanceof ITool) { + if (element instanceof IOptionCategory) { + // Retrieve the Image from Icon information included + IOptionCategory cat = (IOptionCategory)element; + Image img = getIconFromOptionCategory(cat); + + if (img != null) { + return img; + } + } + // Use default icon for display return IMG_TOOL; - } - else if (element instanceof IOptionCategory) { + + } else if (element instanceof IOptionCategory) { + // Return a OptionCategory image for an OptionCategory reference + IOptionCategory cat = (IOptionCategory)element; + Image img = getIconFromOptionCategory(cat); + + if (img != null) { + return img; + } + // Use default icon for display return IMG_CAT; } else { throw unknownElement(element); } - } /* (non-Javadoc) @@ -57,4 +106,15 @@ public class ToolListLabelProvider extends LabelProvider { protected RuntimeException unknownElement(Object element) { return new RuntimeException(ManagedBuilderUIMessages.getFormattedString(ERROR_UNKNOWN_ELEMENT, element.getClass().getName())); } + + /** + * Disposing any images that were allocated for it. + * + * @since 3.0 + */ + public void dispose() { + if (descriptor != null && manager != null) { + manager.destroyImage(descriptor); + } + }; } \ No newline at end of file