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 e91f41fd4ba..1bac02f438d 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
@@ -337,7 +337,7 @@ public class Configuration extends BuildObject implements IConfiguration {
Iterator iter = resElements.listIterator();
while (iter.hasNext()) {
ResourceConfiguration resConfig = (ResourceConfiguration) iter.next();
- subId = getId() + "." + ManagedBuildManager.getRandomNumber(); //$NON-NLS-1$
+ subId = ManagedBuildManager.calculateChildId(getId(), resConfig.getResourcePath());
ResourceConfiguration newResConfig = new ResourceConfiguration(this, resConfig, subId);
addResourceConfiguration(newResConfig);
}
@@ -974,7 +974,7 @@ public class Configuration extends BuildObject implements IConfiguration {
return parent.getCleanCommand();
} else {
// User forgot to specify it. Guess based on OS.
- if (Platform.getOS().equals("OS_WIN32")) { //$NON-NLS-1$
+ if (Platform.getOS().equals(Platform.OS_WIN32)) {
return new String("del"); //$NON-NLS-1$
} else {
return new String("rm"); //$NON-NLS-1$
@@ -1486,5 +1486,4 @@ public class Configuration extends BuildObject implements IConfiguration {
setDirty(true);
}
}
-
}
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
index 539155c01a8..a8792781bbc 100644
--- 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
@@ -1,563 +1,568 @@
-/*******************************************************************************
- * Copyright (c) 2005 Symbian Ltd and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-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.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);
- if(!isExtensionElement)
- 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++) {
- int j = options.length;
- IOption ourOpt = (IOption)ourOpts.get(i);
- if (ourOpt.getSuperClass() != null) {
- String matchId = ourOpt.getSuperClass().getId();
- search:
- for (j = 0; j < options.length; j++) {
- IOption superHolderOption = options[j];
- if (((Option)superHolderOption).wasOptRef()) {
- superHolderOption = superHolderOption.getSuperClass();
- }
- while (superHolderOption != null) {
- if (matchId.equals(superHolderOption.getId())) {
- options[j] = ourOpt;
- break search;
- }
- superHolderOption = superHolderOption.getSuperClass();
- }
- }
- }
- // 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);
- }
- }
- if (opt == null) return null;
- 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();
- if(!option.isExtensionElement())
- 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();
- }
- }
- }
- }
-
- public IOption getOptionToSet(IOption option, boolean adjustExtension) throws BuildException{
- IOption setOption = null;
- if(option.getOptionHolder() != this)
- option = getOptionBySuperClassId(option.getId());
-
- if(adjustExtension){
- for(; option != null && !option.isExtensionElement(); option=option.getSuperClass()){}
-
- if(option != null){
- IHoldsOptions holder = option.getOptionHolder();
- if(holder == this)
- setOption = option;
- else {
- IOption newSuperClass = option;
- if (((Option)option).wasOptRef()) {
- newSuperClass = option.getSuperClass();
- }
- // Create a new extension Option element
- String subId;
- subId = newSuperClass.getId() + ".adjusted." + new Integer(ManagedBuildManager.getRandomNumber()); //$NON-NLS-1$ //$NON-NLS-2$
- setOption = createOption(newSuperClass, subId, null, true);
- ((Option)setOption).setAdjusted(true);
- setOption.setValueType(option.getValueType());
- }
- }
- } else {
- if(option.getOptionHolder() == this && !option.isExtensionElement()){
- setOption = option;
- } else {
- IOption newSuperClass = option;
- for(;
- newSuperClass != null && !newSuperClass.isExtensionElement();
- newSuperClass = newSuperClass.getSuperClass()){}
-
- if (((Option)newSuperClass).wasOptRef()) {
- newSuperClass = newSuperClass.getSuperClass();
- }
-
- if(((Option)newSuperClass).isAdjustedExtension()){
- newSuperClass = newSuperClass.getSuperClass();
- }
- // Create an Option element for the managed build project file (.CDTBUILD)
- String subId;
- int nnn = ManagedBuildManager.getRandomNumber();
- subId = newSuperClass.getId() + "." + nnn; //$NON-NLS-1$
- setOption = createOption(newSuperClass, subId, null, false);
- setOption.setValueType(option.getValueType());
- }
- }
- return setOption;
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2005 Symbian Ltd and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-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.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);
+ if(!isExtensionElement)
+ 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++) {
+ int j = options.length;
+ IOption ourOpt = (IOption)ourOpts.get(i);
+ if (ourOpt.getSuperClass() != null) {
+ String matchId = ourOpt.getSuperClass().getId();
+ search:
+ for (j = 0; j < options.length; j++) {
+ IOption superHolderOption = options[j];
+ if (((Option)superHolderOption).wasOptRef()) {
+ superHolderOption = superHolderOption.getSuperClass();
+ }
+ while (superHolderOption != null) {
+ if (matchId.equals(superHolderOption.getId())) {
+ options[j] = ourOpt;
+ break search;
+ }
+ superHolderOption = superHolderOption.getSuperClass();
+ }
+ }
+ }
+ // 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);
+ }
+ }
+ if (opt == null) return null;
+ 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();
+ if(!option.isExtensionElement())
+ 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();
+ }
+ }
+ }
+ }
+
+ public IOption getOptionToSet(IOption option, boolean adjustExtension) throws BuildException{
+ IOption setOption = null;
+ if(option.getOptionHolder() != this)
+ option = getOptionBySuperClassId(option.getId());
+
+ if(adjustExtension){
+ for(; option != null && !option.isExtensionElement(); option=option.getSuperClass()){}
+
+ if(option != null){
+ IHoldsOptions holder = option.getOptionHolder();
+ if(holder == this)
+ setOption = option;
+ else {
+ IOption newSuperClass = option;
+ if (((Option)option).wasOptRef()) {
+ newSuperClass = option.getSuperClass();
+ }
+ // Create a new extension Option element
+ String subId;
+ String version = ManagedBuildManager.getVersionFromIdAndVersion(newSuperClass.getId());
+ String baseId = ManagedBuildManager.getIdFromIdAndVersion(newSuperClass.getId());
+ if ( version != null) {
+ subId = baseId + ".adjusted." + new Integer(ManagedBuildManager.getRandomNumber()) + "_" + version; //$NON-NLS-1$ //$NON-NLS-2$
+ } else {
+ subId = baseId + ".adjusted." + new Integer(ManagedBuildManager.getRandomNumber()); //$NON-NLS-1$
+ }
+ setOption = createOption(newSuperClass, subId, null, true);
+ ((Option)setOption).setAdjusted(true);
+ setOption.setValueType(option.getValueType());
+ }
+ }
+ } else {
+ if(option.getOptionHolder() == this && !option.isExtensionElement()){
+ setOption = option;
+ } else {
+ IOption newSuperClass = option;
+ for(;
+ newSuperClass != null && !newSuperClass.isExtensionElement();
+ newSuperClass = newSuperClass.getSuperClass()){}
+
+ if (((Option)newSuperClass).wasOptRef()) {
+ newSuperClass = newSuperClass.getSuperClass();
+ }
+
+ if(((Option)newSuperClass).isAdjustedExtension()){
+ newSuperClass = newSuperClass.getSuperClass();
+ }
+ // Create an Option element for the managed build project file (.CDTBUILD)
+ String subId;
+ subId = ManagedBuildManager.calculateChildId(newSuperClass.getId(), null);
+ setOption = createOption(newSuperClass, subId, null, false);
+ setOption.setValueType(option.getValueType());
+ }
+ }
+ return setOption;
+ }
+}
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Target.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Target.java
index faec831b34a..d2b9737e946 100644
--- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Target.java
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Target.java
@@ -1,1180 +1,1180 @@
-/*******************************************************************************
- * 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 Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - 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.StringTokenizer;
-import java.util.Vector;
-
-import org.eclipse.cdt.core.CCorePlugin;
-import org.eclipse.cdt.managedbuilder.core.IBuilder;
-import org.eclipse.cdt.managedbuilder.core.IConfiguration;
-import org.eclipse.cdt.managedbuilder.core.IConfigurationV2;
-import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
-import org.eclipse.cdt.managedbuilder.core.IManagedConfigElement;
-import org.eclipse.cdt.managedbuilder.core.IOption;
-import org.eclipse.cdt.managedbuilder.core.ITarget;
-import org.eclipse.cdt.managedbuilder.core.ITargetPlatform;
-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.internal.scannerconfig.ManagedBuildCPathEntryContainer;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.PluginVersionIdentifier;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-
-public class Target extends BuildObject implements ITarget {
- private static final String EMPTY_STRING = new String();
- private static final IConfigurationV2[] emptyConfigs = new IConfigurationV2[0];
- private String artifactName;
- private String binaryParserId;
- private String cleanCommand;
- private List configList;
- private Map configMap;
- private String defaultExtension;
- private Map depCalculatorsMap;
- private String errorParserIds;
- private String extension;
- private boolean isAbstract = false;
- private boolean isDirty = false;
- private boolean isTest = false;
- private String makeArguments;
- private String makeCommand;
- private IResource owner;
- private ITarget parent;
- private boolean resolved = true;
- private List targetArchList;
- private List targetOSList;
- private List toolList;
- private Map toolMap;
- private List toolReferences;
- private ProjectType createdProjectType;
- private String scannerInfoCollectorId;
-
- /**
- * This constructor is called to create a target defined by an extension point in
- * a plugin manifest file.
- *
- * @param element
- * @param managedBuildRevision the fileVersion of Managed Build System
- */
- public Target(IManagedConfigElement element, String managedBuildRevision) {
- // setup for resolving
- ManagedBuildManager.putConfigElement(this, element);
- resolved = false;
-
- // id
- setId(element.getAttribute(ID));
-
- // managedBuildRevision
- setManagedBuildRevision(managedBuildRevision);
-
- // hook me up
- ManagedBuildManager.addExtensionTarget(this);
-
- // Get the target name
- setName(element.getAttribute(NAME));
-
- // Get the name of the build artifact associated with target (usually
- // in the plugin specification).
- artifactName = element.getAttribute(ARTIFACT_NAME);
-
- // Get the ID of the binary parser
- binaryParserId = element.getAttribute(BINARY_PARSER);
-
- // Get the semicolon separated list of IDs of the error parsers
- errorParserIds = element.getAttribute(ERROR_PARSERS);
-
- // Get the default extension
- defaultExtension = element.getAttribute(DEFAULT_EXTENSION);
-
- // isAbstract
- isAbstract = ("true".equals(element.getAttribute(IS_ABSTRACT))); //$NON-NLS-1$
-
- // Is this a test target
- isTest = ("true".equals(element.getAttribute(IS_TEST))); //$NON-NLS-1$
-
- // Get the clean command
- cleanCommand = element.getAttribute(CLEAN_COMMAND);
-
- // Get the make command
- makeCommand = element.getAttribute(MAKE_COMMAND);
-
- // Get the make arguments
- makeArguments = element.getAttribute(MAKE_ARGS);
-
- // Get scannerInfoCollectorId
- scannerInfoCollectorId = element.getAttribute(SCANNER_INFO_COLLECTOR_ID);
-
- // Get the comma-separated list of valid OS
- String os = element.getAttribute(OS_LIST);
- if (os != null) {
- targetOSList = new ArrayList();
- String[] osTokens = os.split(","); //$NON-NLS-1$
- for (int i = 0; i < osTokens.length; ++i) {
- targetOSList.add(osTokens[i].trim());
- }
- }
-
- // Get the comma-separated list of valid Architectures
- String arch = element.getAttribute(ARCH_LIST);
- if (arch != null) {
- targetArchList = new ArrayList();
- String[] archTokens = arch.split(","); //$NON-NLS-1$
- for (int j = 0; j < archTokens.length; ++j) {
- targetArchList.add(archTokens[j].trim());
- }
- }
-
- // Load any tool references we might have
- IManagedConfigElement[] toolRefs = element.getChildren(IConfigurationV2.TOOLREF_ELEMENT_NAME);
- for (int k = 0; k < toolRefs.length; ++k) {
- new ToolReference(this, toolRefs[k]);
- }
- // Then load any tools defined for the target
- IManagedConfigElement[] tools = element.getChildren(ITool.TOOL_ELEMENT_NAME);
- for (int m = 0; m < tools.length; ++m) {
- ITool newTool = new Tool(this, tools[m], managedBuildRevision);
- // Add this tool to the target, as this is not done in the constructor
- this.addTool(newTool);
- }
- // Then load the configurations which may have tool references
- IManagedConfigElement[] configs = element.getChildren(IConfigurationV2.CONFIGURATION_ELEMENT_NAME);
- for (int n = 0; n < configs.length; ++n) {
- new ConfigurationV2(this, configs[n]);
- }
- }
-
- /* (non-Javadoc)
- * Set the resource that owns the target.
- *
- * @param owner
- */
- protected Target(IResource owner) {
- this.owner = owner;
- }
-
- /**
- * Create a copy of the target specified in the argument,
- * that is owned by the owned by the specified resource.
- *
- * @param owner
- * @param parent
- */
- public Target(IResource owner, ITarget parent) {
- // Make the owner of the target the project resource
- this(owner);
-
- // Copy the parent's identity
- this.parent = parent;
- int id = ManagedBuildManager.getRandomNumber();
- setId(owner.getName() + "." + parent.getId() + "." + id); //$NON-NLS-1$ //$NON-NLS-2$
- setName(parent.getName());
-
- setManagedBuildRevision(parent.getManagedBuildRevision());
-
- setArtifactName(parent.getArtifactName());
- this.binaryParserId = parent.getBinaryParserId();
- this.errorParserIds = parent.getErrorParserIds();
- this.defaultExtension = parent.getArtifactExtension();
- this.isTest = parent.isTestTarget();
- this.cleanCommand = parent.getCleanCommand();
- this.scannerInfoCollectorId = ((Target)parent).scannerInfoCollectorId;
-
- // Hook me up
- IManagedBuildInfo buildInfo = ManagedBuildManager.getBuildInfo(owner);
- buildInfo.addTarget(this);
- }
-
- /**
- * Create target from project file.
- *
- * @param buildInfo
- * @param element
- */
- public Target(ManagedBuildInfo buildInfo, Element element) {
- this(buildInfo.getOwner());
-
- // id
- setId(element.getAttribute(ID));
-
- // hook me up
- buildInfo.addTarget(this);
-
- // name
- setName(element.getAttribute(NAME));
-
- // Get the name of the build artifact associated with target (should
- // contain what the user entered in the UI).
- artifactName = element.getAttribute(ARTIFACT_NAME);
-
- // Get the overridden extension
- if (element.hasAttribute(EXTENSION)) {
- extension = element.getAttribute(EXTENSION);
- }
-
- // parent
- String parentId = element.getAttribute(PARENT);
- if (parentId != null)
- parent = ManagedBuildManager.getTarget(null, parentId);
-
- // isAbstract
- if ("true".equals(element.getAttribute(IS_ABSTRACT))) //$NON-NLS-1$
- isAbstract = true;
-
- // Is this a test target
- isTest = ("true".equals(element.getAttribute(IS_TEST))); //$NON-NLS-1$
-
- // Get the clean command
- if (element.hasAttribute(CLEAN_COMMAND)) {
- cleanCommand = element.getAttribute(CLEAN_COMMAND);
- }
-
- // Get the semicolon separated list of IDs of the error parsers
- if (element.hasAttribute(ERROR_PARSERS)) {
- errorParserIds = element.getAttribute(ERROR_PARSERS);
- }
-
- // Get the make command and arguments
- if (element.hasAttribute(MAKE_COMMAND)) {
- makeCommand = element.getAttribute(MAKE_COMMAND);
- }
- if(element.hasAttribute(MAKE_ARGS)) {
- makeArguments = element.getAttribute(MAKE_ARGS);
- }
-
- Node child = element.getFirstChild();
- while (child != null) {
- if (child.getNodeName().equals(IConfigurationV2.CONFIGURATION_ELEMENT_NAME)) {
- new ConfigurationV2(this, (Element)child);
- }
- child = child.getNextSibling();
- }
- }
-
- /**
- * @param configuration
- */
- public void addConfiguration(IConfigurationV2 configuration) {
- getConfigurationList().add(configuration);
- getConfigurationMap().put(configuration.getId(), configuration);
- }
-
- /**
- * Adds a tool specification to the receiver. This tool is defined
- * only for the receiver, and cannot be shared by other targets.
- *
- * @param tool
- */
- public void addTool(ITool tool) {
- getToolList().add(tool);
- getToolMap().put(tool.getId(), tool);
- }
-
- /**
- * Adds a tool reference to the receiver.
- *
- * @param toolRef
- */
- public void addToolReference(ToolReference toolRef) {
- getLocalToolReferences().add(toolRef);
- }
-
-
- /* (non-Javadoc)
- * Tail-recursion method that creates a lits of tools and tool reference
- * walking the receiver's parent hierarchy.
- *
- * @param toolArray
- */
- private void addToolsToArray(Vector toolArray) {
- if (parent != null) {
- ((Target)parent).addToolsToArray(toolArray);
- }
-
- // Add the tools from out own list
- toolArray.addAll(getToolList());
-
- // Add local tool references
- toolArray.addAll(getLocalToolReferences());
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.build.managed.ITarget#createConfiguration(org.eclipse.cdt.core.build.managed.IConfigurationV2)
- */
- public IConfigurationV2 createConfiguration(IConfigurationV2 parent, String id) {
- isDirty = true;
- return new ConfigurationV2(this, parent, id);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.build.managed.ITarget#createConfiguration()
- */
- public IConfigurationV2 createConfiguration(String id) {
- return new ConfigurationV2(this, id);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.managedbuilder.core.ITarget#getArtifactExtension()
- */
- public String getArtifactExtension() {
- // Has the user changed the extension for this target
- if (extension != null) {
- return extension;
- }
- // If not, then go through the default extension lookup
- if (defaultExtension == null) {
- // Ask my parent first
- if (parent != null) {
- return parent.getArtifactExtension();
- } else {
- return EMPTY_STRING;
- }
- } else {
- return defaultExtension;
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.build.managed.ITarget#getArtifactName()
- */
- public String getArtifactName() {
- if (artifactName == null) {
- // If I have a parent, ask it
- if (parent != null) {
- return parent.getArtifactName();
- } else {
- // I'm it and this is not good!
- return EMPTY_STRING;
- }
- } else {
- return artifactName;
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.managedbuilder.core.ITarget#getBinaryParserId()
- */
- public String getBinaryParserId() {
- if (binaryParserId == null) {
- // If I have a parent, ask it
- if (parent != null) {
- return parent.getBinaryParserId();
- } else {
- // I'm it and this is not good!
- return EMPTY_STRING;
- }
- }
- return binaryParserId;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.build.managed.ITarget#getCleanCommand()
- */
- public String getCleanCommand() {
- // Return the command used to remove files
- if (cleanCommand == null) {
- if (parent != null) {
- return parent.getCleanCommand();
- } else {
- // User forgot to specify it. Guess based on OS.
- if (Platform.getOS().equals("OS_WIN32")) { //$NON-NLS-1$
- return new String("del"); //$NON-NLS-1$
- } else {
- return new String("rm"); //$NON-NLS-1$
- }
- }
- } else {
- // This was spec'd in the manifest
- return cleanCommand;
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.build.managed.ITarget#getConfiguration()
- */
- public IConfigurationV2 getConfiguration(String id) {
- return (IConfigurationV2)getConfigurationMap().get(id);
- }
-
- /* (non-Javadoc)
- * Safe accessor for the list of configurations.
- *
- * @return List containing the configurations
- */
- private List getConfigurationList() {
- if (configList == null) {
- configList = new ArrayList();
- }
- return configList;
- }
-
- /* (non-Javadoc)
- * Safe accessor for the map of configuration ids to configurations
- *
- * @return
- */
- private Map getConfigurationMap() {
- if (configMap == null) {
- configMap = new HashMap();
- }
- return configMap;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.managedbuilder.core.ITarget#getConfigurations()
- */
- public IConfigurationV2[] getConfigurations() {
- return (IConfigurationV2[])getConfigurationList().toArray(new IConfigurationV2[getConfigurationList().size()]);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.managedbuilder.core.ITarget#getDefaultExtension()
- */
- public String getDefaultExtension() {
- return defaultExtension == null ? EMPTY_STRING : defaultExtension;
- }
-
- private Map getDepCalcMap() {
- if (depCalculatorsMap == null) {
- depCalculatorsMap = new HashMap();
- }
- return depCalculatorsMap;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.managedbuilder.core.ITarget#getErrorParserIds()
- */
- public String getErrorParserIds() {
- if (errorParserIds == null) {
- // If I have a parent, ask it
- if (parent != null) {
- return parent.getErrorParserIds();
- }
- }
- return errorParserIds;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.managedbuilder.core.ITarget#getErrorParserList()
- */
- public String[] getErrorParserList() {
- String parserIDs = getErrorParserIds();
- String[] errorParsers = null;
- if (parserIDs != null) {
- // Check for an empty string
- if (parserIDs.length() == 0) {
- errorParsers = new String[0];
- } else {
- StringTokenizer tok = new StringTokenizer(parserIDs, ";"); //$NON-NLS-1$
- List list = new ArrayList(tok.countTokens());
- while (tok.hasMoreElements()) {
- list.add(tok.nextToken());
- }
- String[] strArr = {""}; //$NON-NLS-1$
- errorParsers = (String[]) list.toArray(strArr);
- }
- } else {
- // If no error parsers are specified by the target, the default is
- // all error parsers
- errorParsers = CCorePlugin.getDefault().getAllErrorParsersIDs();
- }
- return errorParsers;
- }
-
- /* (non-javadoc)
- * A safe accesor method. It answers the tool reference list in the
- * receiver.
- *
- * @return List
- */
- protected List getLocalToolReferences() {
- if (toolReferences == null) {
- toolReferences = new ArrayList();
- }
- return toolReferences;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.managedbuilder.core.ITarget#getMakeArguments()
- */
- public String getMakeArguments() {
- if (makeArguments == null) {
- // See if it is defined in my parent
- if (parent != null) {
- return parent.getMakeArguments();
- } else {
- // No parent and no user setting
- return new String(""); //$NON-NLS-1$
- }
- }
- return makeArguments;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.build.managed.ITarget#getMakeCommand()
- */
- public String getMakeCommand() {
- // Return the name of the make utility
- if (makeCommand == null) {
- // If I have a parent, ask it
- if (parent != null) {
- return parent.getMakeCommand();
- } else {
- // The user has forgotten to specify a command in the plugin manifest
- return new String("make"); //$NON-NLS-1$
- }
- } else {
- return makeCommand;
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.managedbuilder.core.IBuildObject#getName()
- */
- public String getName() {
- // If I am unnamed, see if I can inherit one from my parent
- if (name == null) {
- if (parent != null) {
- return parent.getName();
- } else {
- return new String(""); //$NON-NLS-1$
- }
- } else {
- return name;
- }
- }
-
- /* (non-javadoc)
- *
- * @param tool
- * @return List
- */
- protected List getOptionReferences(ITool tool) {
- List references = new ArrayList();
-
- // Get all the option references I add for this tool
- ToolReference toolRef = getToolReference(tool);
- if (toolRef != null) {
- references.addAll(toolRef.getOptionReferenceList());
- }
-
- // See if there is anything that my parents add that I don't
- if (parent != null) {
- List temp = ((Target)parent).getOptionReferences(tool);
- Iterator iter = temp.listIterator();
- while (iter.hasNext()) {
- OptionReference ref = (OptionReference) iter.next();
- if (!references.contains(ref)) {
- references.add(ref);
- }
- }
- }
-
- return references;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.managedbuilder.core.ITarget#getOwner()
- */
- public IResource getOwner() {
- return owner;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.managedbuilder.core.ITarget#getParent()
- */
- public ITarget getParent() {
- return parent;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.managedbuilder.core.ITarget#getTargetArchList()
- */
- public String[] getTargetArchList() {
- if (targetArchList == null) {
- // Ask parent for its list
- if (parent != null) {
- return parent.getTargetArchList();
- } else {
- // I have no parent and no defined list
- return new String[] {"all"}; //$NON-NLS-1$
- }
- }
- return (String[]) targetArchList.toArray(new String[targetArchList.size()]);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.managedbuilder.core.ITarget#getTargetOSList()
- */
- public String[] getTargetOSList() {
- if (targetOSList == null) {
- // Ask parent for its list
- if (parent != null) {
- return parent.getTargetOSList();
- } else {
- // I have no parent and no defined filter list
- return new String[] {"all"}; //$NON-NLS-1$
- }
- }
- return (String[]) targetOSList.toArray(new String[targetOSList.size()]);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.managedbuilder.core.ITarget#getTool(java.lang.String)
- */
- public ITool getTool(String id) {
- ITool result = null;
-
- // See if receiver has it in list
- result = (ITool) getToolMap().get(id);
-
- // If not, check if parent has it
- if (result == null && parent != null) {
- result = ((Target)parent).getTool(id);
- }
-
- // If not defined in parents, check if defined at all
- if (result == null) {
- result = ManagedBuildManager.getExtensionTool(id);
- }
-
- return result;
- }
-
- /* (non-Javadoc)
- * A safe accessor method for the list of tools maintained by the
- * target
- *
- */
- private List getToolList() {
- if (toolList == null) {
- toolList = new ArrayList();
- }
- return toolList;
- }
-
- /* (non-Javadoc)
- * A safe accessor for the tool map
- *
- */
- private Map getToolMap() {
- if (toolMap == null) {
- toolMap = new HashMap();
- }
- return toolMap;
- }
-
- /* (non-Javadoc)
- * Returns the reference for a given tool or null
if one is not
- * found.
- *
- * @param tool
- * @return ToolReference
- */
- private ToolReference getToolReference(ITool tool) {
- // See if the receiver has a reference to the tool
- ToolReference ref = null;
- if (tool == null) return ref;
- Iterator iter = getLocalToolReferences().listIterator();
- while (iter.hasNext()) {
- ToolReference temp = (ToolReference)iter.next();
- if (temp.references(tool)) {
- ref = temp;
- break;
- }
- }
- return ref;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.managedbuilder.core.ITarget#getTools()
- */
- public ITool[] getTools() {
- Vector toolArray = new Vector();
- addToolsToArray(toolArray);
- return (ITool[]) toolArray.toArray(new ITool[toolArray.size()]);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.managedbuilder.core.ITarget#hasMakeCommandOverride()
- */
- public boolean hasOverridenMakeCommand() {
- // We answer true if the make command or the flags are different
- return ((makeCommand != null && !makeCommand.equals(parent.getMakeCommand()))
- || (makeArguments != null && !makeArguments.equals(parent.getMakeArguments())));
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.build.managed.ITarget#isAbstract()
- */
- public boolean isAbstract() {
- return isAbstract;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.managedbuilder.core.ITarget#isDirty()
- */
- public boolean isDirty() {
- // If I need saving, just say yes
- if (isDirty) {
- return true;
- }
-
- // Iterate over the configurations and ask them if they need saving
- Iterator iter = getConfigurationList().listIterator();
- while (iter.hasNext()) {
- if (((IConfigurationV2)iter.next()).isDirty()) {
- return true;
- }
- }
-
- return false;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.build.managed.ITarget#isTestTarget()
- */
- public boolean isTestTarget() {
- return isTest;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.managedbuilder.core.ITarget#needsRebuild()
- */
- public boolean needsRebuild(){
- // Iterate over the configurations and ask them if they need saving
- Iterator iter = getConfigurationList().listIterator();
- while (iter.hasNext()) {
- if (((IConfigurationV2)iter.next()).needsRebuild()) {
- return true;
- }
- }
- return false;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.managedbuilder.core.ITarget#removeConfiguration(java.lang.String)
- */
- public void removeConfiguration(String id) {
- // Remove the specified configuration from the list and map
- Iterator iter = getConfigurationList().listIterator();
- while (iter.hasNext()) {
- IConfigurationV2 config = (IConfigurationV2)iter.next();
- if (config.getId().equals(id)) {
- getConfigurationList().remove(config);
- getConfigurationMap().remove(id);
- isDirty = true;
- break;
- }
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.managedbuilder.core.ITarget#resetMakeCommand()
- */
- public void resetMakeCommand() {
- // Flag target as dirty if the reset actually changes something
- if (makeCommand != null) {
- setDirty(true);
- }
- makeCommand = null;
- makeArguments = null;
- }
-
- /**
- *
- */
- public void resolveReferences() {
- if (!resolved) {
- resolved = true;
- IManagedConfigElement element = ManagedBuildManager.getConfigElement(this);
- // parent
- String parentId = element.getAttribute(PARENT);
- if (parentId != null) {
- parent = ManagedBuildManager.getTarget(null, parentId);
- // should resolve before calling methods on it
- ((Target)parent).resolveReferences();
- // copy over the parents configs
- IConfigurationV2[] parentConfigs = parent.getConfigurations();
- for (int i = 0; i < parentConfigs.length; ++i)
- addConfiguration(parentConfigs[i]);
- }
-
- // call resolve references on any children
- Iterator toolIter = getToolList().iterator();
- while (toolIter.hasNext()) {
- Tool current = (Tool)toolIter.next();
- current.resolveReferences();
- }
- Iterator refIter = getLocalToolReferences().iterator();
- while (refIter.hasNext()) {
- ToolReference current = (ToolReference)refIter.next();
- current.resolveReferences();
- }
- Iterator configIter = getConfigurationList().iterator();
- while (configIter.hasNext()) {
- ConfigurationV2 current = (ConfigurationV2)configIter.next();
- current.resolveReferences();
- }
- }
- }
-
- /**
- * Persist receiver to project file.
- *
- * @param doc
- * @param element
- */
- public void serialize(Document doc, Element element) {
- element.setAttribute(ID, getId());
- element.setAttribute(NAME, getName());
- if (parent != null)
- element.setAttribute(PARENT, parent.getId());
- element.setAttribute(IS_ABSTRACT, isAbstract ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$
- element.setAttribute(ARTIFACT_NAME, getArtifactName());
- if (extension != null) {
- element.setAttribute(EXTENSION, extension);
- }
- element.setAttribute(IS_TEST, isTest ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$
-
- if (makeCommand != null) {
- element.setAttribute(MAKE_COMMAND, makeCommand);
- } else {
- // Make sure we use the default
- }
-
- if (makeArguments != null) {
- element.setAttribute(MAKE_ARGS, makeArguments);
- }
- if (errorParserIds != null) {
- element.setAttribute(ERROR_PARSERS, errorParserIds);
- }
-
- // Serialize the configuration settings
- Iterator iter = getConfigurationList().listIterator();
- while (iter.hasNext()) {
- ConfigurationV2 config = (ConfigurationV2) iter.next();
- Element configElement = doc.createElement(IConfigurationV2.CONFIGURATION_ELEMENT_NAME);
- element.appendChild(configElement);
- config.serialize(doc, configElement);
- }
-
- // I am clean now
- isDirty = false;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.managedbuilder.core.ITarget#setArtifactExtension(java.lang.String)
- */
- public void setArtifactExtension(String extension) {
- if (extension != null) {
- this.extension = extension;
- isDirty = true;
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.build.managed.ITarget#setArtifactName(java.lang.String)
- */
- public void setArtifactName(String name) {
- if (name != null) {
- artifactName = name;
- setRebuildState(true);
- isDirty = true;
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.managedbuilder.core.ITarget#setDirty(boolean)
- */
- public void setDirty(boolean isDirty) {
- // Override the dirty flag here
- this.isDirty = isDirty;
- // and in the configurations
- Iterator iter = getConfigurationList().listIterator();
- while (iter.hasNext()) {
- IConfigurationV2 config = (IConfigurationV2)iter.next();
- config.setDirty(isDirty);
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.managedbuilder.core.ITarget#setErrorParserIds()
- */
- public void setErrorParserIds(String ids) {
- if (ids == null) return;
- String currentIds = getErrorParserIds();
- if (currentIds == null || !(currentIds.equals(ids))) {
- errorParserIds = ids;
- isDirty = true;
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.managedbuilder.core.ITarget#setMakeArguments(java.lang.String)
- */
- public void setMakeArguments(String makeArgs) {
- if (makeArgs != null && !getMakeArguments().equals(makeArgs)) {
- makeArguments = makeArgs;
- setRebuildState(true);
- isDirty = true;
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.managedbuilder.core.ITarget#setMakeCommand(java.lang.String)
- */
- public void setMakeCommand(String command) {
- if (command != null && !getMakeCommand().equals(command)) {
- makeCommand = command;
- setRebuildState(true);
- isDirty = true;
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.managedbuilder.core.ITarget#setRebuildState(boolean)
- */
- public void setRebuildState(boolean rebuild) {
- Iterator iter = getConfigurationList().listIterator();
- while (iter.hasNext()) {
- ((IConfigurationV2)iter.next()).setRebuildState(rebuild);
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.managedbuilder.core.ITarget#updateOwner(org.eclipse.core.resources.IResource)
- */
- public void updateOwner(IResource resource) {
- if (!resource.equals(owner)) {
- // Set the owner correctly
- owner = resource;
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.managedbuilder.core.ITarget#convertToProjectType()
- */
- public void convertToProjectType(String managedBuildRevision) {
- // Create a ProjectType + Configuration + Toolchain + Builder + TargetPlatform
- // from the Target
-
- // The "parent" needs to have been converted already.
- // Do it now if necessary.
- ProjectType parentProj = null;
- if (parent != null) {
- parentProj = parent.getCreatedProjectType();
- if (parentProj == null) {
- parent.convertToProjectType(managedBuildRevision);
- parentProj = parent.getCreatedProjectType();
- }
- }
- ProjectType projectType = new ProjectType(parentProj, getId(), getName(), managedBuildRevision);
- createdProjectType = projectType;
- // Set the project type attributes
- projectType.setIsAbstract(isAbstract);
- projectType.setIsTest(isTest);
- // Add children
- // Add configurations (Configuration -> ToolChain -> Builder -> TargetPlatform)
- Iterator iter = getConfigurationList().listIterator();
- while (iter.hasNext()) {
- IConfigurationV2 configV2 = (IConfigurationV2)iter.next();
- if (configV2.getCreatedConfig() != null) continue;
- // The new config's superClass needs to be the
- // Configuration created from the ConfigurationV2 parent...
- IConfiguration configSuperClass = null;
- IConfigurationV2 parentV2 = configV2.getParent();
- if (parentV2 != null) {
- configSuperClass = parentV2.getCreatedConfig();
- }
- String id = configV2.getId();
- String name = configV2.getName();
- IConfiguration config = projectType.createConfiguration(configSuperClass, id, name);
- configV2.setCreatedConfig(config);
- // Set the configuration attributes
- config.setArtifactName(getArtifactName());
- config.setArtifactExtension(getArtifactExtension());
- config.setCleanCommand(getCleanCommand());
- config.setErrorParserIds(getErrorParserIds());
- // Create the Tool-chain
- String subId;
- String subName;
- subId = id + ".toolchain"; //$NON-NLS-1$
- subName = name + ".toolchain"; //$NON-NLS-1$
- IToolChain toolChain = config.createToolChain(null, subId, subName, true);
- // Set the tool chain attributes
- toolChain.setIsAbstract(isAbstract);
- toolChain.setOSList(getTargetOSList());
- toolChain.setArchList(getTargetArchList());
- // In target element had a scannerInfoCollector element here which
- // is now replaced with scanner config discovery profile id.
- // Using the default per project profile for managed make
- if(scannerInfoCollectorId != null && scannerInfoCollectorId.equals("org.eclipse.cdt.managedbuilder.internal.scannerconfig.DefaultGCCScannerInfoCollector")) //$NON-NLS-1$
- toolChain.setScannerConfigDiscoveryProfileId(ManagedBuildCPathEntryContainer.MM_PP_DISCOVERY_PROFILE_ID);
- // Create the Builder
- subId = id + ".builder"; //$NON-NLS-1$
- subName = name + ".builder"; //$NON-NLS-1$
- IBuilder builder = toolChain.createBuilder(null, subId, subName, true);
- // Set the builder attributes
- builder.setIsAbstract(isAbstract);
- builder.setCommand(getMakeCommand());
- builder.setArguments(getMakeArguments());
- IManagedConfigElement element = ManagedBuildManager.getConfigElement(this);
- if (element instanceof DefaultManagedConfigElement) {
- ((Builder)builder).setBuildFileGeneratorElement(((DefaultManagedConfigElement)element).getConfigurationElement());
- }
- // Create the TargetPlatform
- subId = id + ".targetplatform"; //$NON-NLS-1$
- subName = name + ".targetplatform"; //$NON-NLS-1$
- ITargetPlatform targetPlatform = toolChain.createTargetPlatform(null, subId, subName, true);
- // Set the target platform attributes
- targetPlatform.setIsAbstract(isAbstract);
- targetPlatform.setOSList(getTargetOSList());
- targetPlatform.setArchList(getTargetArchList());
- targetPlatform.setBinaryParserList(new String[]{getBinaryParserId()}); // Older projects will always have only one binary parser set.
-
- // Handle ConfigurationV2 children (ToolReference)
- // The tools references fetched here are strictly local to the configuration,
- // so additional work is required to fetch the tool references from the target
- IToolReference[] configToolRefs = configV2.getToolReferences();
- // Add the "local" tool references (they are direct children of the target and
- // its parent targets)
- Vector targetToolRefs = new Vector();
- addTargetToolReferences(targetToolRefs);
- IToolReference[] toolRefs;
- if (targetToolRefs.size() > 0) {
- toolRefs = new IToolReference[targetToolRefs.size() + configToolRefs.length];
- int i;
- for (i = 0; i < configToolRefs.length; ++i) {
- toolRefs[i] = configToolRefs[i];
- }
- Iterator localToolRefIter = targetToolRefs.iterator();
- while (localToolRefIter.hasNext()) {
- toolRefs[i++] = (IToolReference)localToolRefIter.next();
- }
- } else {
- toolRefs = configToolRefs;
- }
- for (int i = 0; i < toolRefs.length; ++i) {
- IToolReference toolRef = toolRefs[i];
- subId = id + "." + toolRef.getId(); //$NON-NLS-1$
- // The ToolReference's Tool becomes the newTool's SuperClass
- ITool newTool = toolChain.createTool(toolRef.getTool(), subId, toolRef.getName(), true);
- // Set the tool attributes
- newTool.setToolCommand(toolRef.getRawToolCommand());
- newTool.setOutputPrefix(toolRef.getRawOutputPrefix());
- newTool.setOutputFlag(toolRef.getRawOutputFlag());
- newTool.setOutputsAttribute(toolRef.getRawOutputExtensions());
- // Handle ToolReference children (OptionReference)
- Iterator optRefIter = toolRef.getOptionReferenceList().listIterator();
- while (optRefIter.hasNext()) {
- OptionReference optRef = (OptionReference)optRefIter.next();
- subId = id + "." + optRef.getId(); //$NON-NLS-1$
- IOption newOption = newTool.createOption(optRef.getOption(), subId, optRef.getName(), true);
- // Set the option attributes
- newOption.setValue(optRef.getValue());
- newOption.setValueType(optRef.getValueType());
- ((Option)newOption).setWasOptRef(true);
- }
- }
-
- // Process the tools in the configuration, adding them to the toolchain
- // Tools for a configuration are stored in the enclosing target, so getting
- // the tools for the configuration ultimately gets them from the enclosing target
- ITool[] configTools = configV2.getTools();
- for (int i = 0; i < configTools.length; ++i) {
- ITool tool = configTools[i];
- // If tool references encountered, they have already been processed, above,
- // so ignore them now
- if (!(tool instanceof ToolReference)) {
- // See if the toolchain already has a tool with a SuperClass that has an id
- // equal to the tool that we are considering adding to the toolchain; if so,
- // don't add it
- // This case arises when we have added a tool to the toolchain because
- // we processed a ToolReference (above) that references this tool
- // The original tool referenced in the ToolReference becomes the SuperClass
- // of the tool that is created because of the ToolReference
- boolean found = false;
- ITool[] tools = toolChain.getTools();
- ITool currentTool;
- ITool supercurrentTool;
- for (int j = 0; j < tools.length; ++j) {
- currentTool = tools[j];
- supercurrentTool = currentTool.getSuperClass();
- if (supercurrentTool != null) {
- if (supercurrentTool.getId() == tool.getId()) {
- found = true;
- // If this tool was already added to the toolchain because of a
- // ToolReference, then we disconnent this redundant
- // tool from the target by setting the parent to null
- ((Tool)tool).setToolParent(null);
- break;
- }
- }
- }
-
- if (!found)
- // This tool is not in the toolchain yet, so add it to the toolchain
- ((ToolChain)toolChain).addTool((Tool)tool);
-
- }
- }
- // Normalize the outputextensions list by adding an empty string for each tool
- // which did not have an explicit output file extension specified
- ((ToolChain)toolChain).normalizeOutputExtensions();
- }
- }
-
- /*
- * A target element may contain toolReference elements. These get applied to all of the configurations
- * of the target. The method adds the list of this target's local tool references to the passed in vector.
- */
- public void addTargetToolReferences(Vector toolRefs) {
- toolRefs.addAll(getLocalToolReferences());
- if (parent != null) {
- Target targetParent = (Target)parent;
- targetParent.addTargetToolReferences(toolRefs);
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.managedbuilder.core.ITarget#getCreatedProjectType()
- */
- public ProjectType getCreatedProjectType() {
- return createdProjectType;
- }
-
- /**
- * @return Returns the version.
- */
- public PluginVersionIdentifier getVersion() {
- if ( version == null) {
- if ( getParent() != null) {
- return getParent().getVersion();
- }
- }
- return version;
- }
-
- public void setVersion(PluginVersionIdentifier version) {
- // Do nothing
- }
-
-}
+/*******************************************************************************
+ * 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 Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM - 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.StringTokenizer;
+import java.util.Vector;
+
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.managedbuilder.core.IBuilder;
+import org.eclipse.cdt.managedbuilder.core.IConfiguration;
+import org.eclipse.cdt.managedbuilder.core.IConfigurationV2;
+import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
+import org.eclipse.cdt.managedbuilder.core.IManagedConfigElement;
+import org.eclipse.cdt.managedbuilder.core.IOption;
+import org.eclipse.cdt.managedbuilder.core.ITarget;
+import org.eclipse.cdt.managedbuilder.core.ITargetPlatform;
+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.internal.scannerconfig.ManagedBuildCPathEntryContainer;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.PluginVersionIdentifier;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+public class Target extends BuildObject implements ITarget {
+ private static final String EMPTY_STRING = new String();
+ private static final IConfigurationV2[] emptyConfigs = new IConfigurationV2[0];
+ private String artifactName;
+ private String binaryParserId;
+ private String cleanCommand;
+ private List configList;
+ private Map configMap;
+ private String defaultExtension;
+ private Map depCalculatorsMap;
+ private String errorParserIds;
+ private String extension;
+ private boolean isAbstract = false;
+ private boolean isDirty = false;
+ private boolean isTest = false;
+ private String makeArguments;
+ private String makeCommand;
+ private IResource owner;
+ private ITarget parent;
+ private boolean resolved = true;
+ private List targetArchList;
+ private List targetOSList;
+ private List toolList;
+ private Map toolMap;
+ private List toolReferences;
+ private ProjectType createdProjectType;
+ private String scannerInfoCollectorId;
+
+ /**
+ * This constructor is called to create a target defined by an extension point in
+ * a plugin manifest file.
+ *
+ * @param element
+ * @param managedBuildRevision the fileVersion of Managed Build System
+ */
+ public Target(IManagedConfigElement element, String managedBuildRevision) {
+ // setup for resolving
+ ManagedBuildManager.putConfigElement(this, element);
+ resolved = false;
+
+ // id
+ setId(element.getAttribute(ID));
+
+ // managedBuildRevision
+ setManagedBuildRevision(managedBuildRevision);
+
+ // hook me up
+ ManagedBuildManager.addExtensionTarget(this);
+
+ // Get the target name
+ setName(element.getAttribute(NAME));
+
+ // Get the name of the build artifact associated with target (usually
+ // in the plugin specification).
+ artifactName = element.getAttribute(ARTIFACT_NAME);
+
+ // Get the ID of the binary parser
+ binaryParserId = element.getAttribute(BINARY_PARSER);
+
+ // Get the semicolon separated list of IDs of the error parsers
+ errorParserIds = element.getAttribute(ERROR_PARSERS);
+
+ // Get the default extension
+ defaultExtension = element.getAttribute(DEFAULT_EXTENSION);
+
+ // isAbstract
+ isAbstract = ("true".equals(element.getAttribute(IS_ABSTRACT))); //$NON-NLS-1$
+
+ // Is this a test target
+ isTest = ("true".equals(element.getAttribute(IS_TEST))); //$NON-NLS-1$
+
+ // Get the clean command
+ cleanCommand = element.getAttribute(CLEAN_COMMAND);
+
+ // Get the make command
+ makeCommand = element.getAttribute(MAKE_COMMAND);
+
+ // Get the make arguments
+ makeArguments = element.getAttribute(MAKE_ARGS);
+
+ // Get scannerInfoCollectorId
+ scannerInfoCollectorId = element.getAttribute(SCANNER_INFO_COLLECTOR_ID);
+
+ // Get the comma-separated list of valid OS
+ String os = element.getAttribute(OS_LIST);
+ if (os != null) {
+ targetOSList = new ArrayList();
+ String[] osTokens = os.split(","); //$NON-NLS-1$
+ for (int i = 0; i < osTokens.length; ++i) {
+ targetOSList.add(osTokens[i].trim());
+ }
+ }
+
+ // Get the comma-separated list of valid Architectures
+ String arch = element.getAttribute(ARCH_LIST);
+ if (arch != null) {
+ targetArchList = new ArrayList();
+ String[] archTokens = arch.split(","); //$NON-NLS-1$
+ for (int j = 0; j < archTokens.length; ++j) {
+ targetArchList.add(archTokens[j].trim());
+ }
+ }
+
+ // Load any tool references we might have
+ IManagedConfigElement[] toolRefs = element.getChildren(IConfigurationV2.TOOLREF_ELEMENT_NAME);
+ for (int k = 0; k < toolRefs.length; ++k) {
+ new ToolReference(this, toolRefs[k]);
+ }
+ // Then load any tools defined for the target
+ IManagedConfigElement[] tools = element.getChildren(ITool.TOOL_ELEMENT_NAME);
+ for (int m = 0; m < tools.length; ++m) {
+ ITool newTool = new Tool(this, tools[m], managedBuildRevision);
+ // Add this tool to the target, as this is not done in the constructor
+ this.addTool(newTool);
+ }
+ // Then load the configurations which may have tool references
+ IManagedConfigElement[] configs = element.getChildren(IConfigurationV2.CONFIGURATION_ELEMENT_NAME);
+ for (int n = 0; n < configs.length; ++n) {
+ new ConfigurationV2(this, configs[n]);
+ }
+ }
+
+ /* (non-Javadoc)
+ * Set the resource that owns the target.
+ *
+ * @param owner
+ */
+ protected Target(IResource owner) {
+ this.owner = owner;
+ }
+
+ /**
+ * Create a copy of the target specified in the argument,
+ * that is owned by the owned by the specified resource.
+ *
+ * @param owner
+ * @param parent
+ */
+ public Target(IResource owner, ITarget parent) {
+ // Make the owner of the target the project resource
+ this(owner);
+
+ // Copy the parent's identity
+ this.parent = parent;
+ int id = ManagedBuildManager.getRandomNumber();
+ setId(owner.getName() + "." + parent.getId() + "." + id); //$NON-NLS-1$ //$NON-NLS-2$
+ setName(parent.getName());
+
+ setManagedBuildRevision(parent.getManagedBuildRevision());
+
+ setArtifactName(parent.getArtifactName());
+ this.binaryParserId = parent.getBinaryParserId();
+ this.errorParserIds = parent.getErrorParserIds();
+ this.defaultExtension = parent.getArtifactExtension();
+ this.isTest = parent.isTestTarget();
+ this.cleanCommand = parent.getCleanCommand();
+ this.scannerInfoCollectorId = ((Target)parent).scannerInfoCollectorId;
+
+ // Hook me up
+ IManagedBuildInfo buildInfo = ManagedBuildManager.getBuildInfo(owner);
+ buildInfo.addTarget(this);
+ }
+
+ /**
+ * Create target from project file.
+ *
+ * @param buildInfo
+ * @param element
+ */
+ public Target(ManagedBuildInfo buildInfo, Element element) {
+ this(buildInfo.getOwner());
+
+ // id
+ setId(element.getAttribute(ID));
+
+ // hook me up
+ buildInfo.addTarget(this);
+
+ // name
+ setName(element.getAttribute(NAME));
+
+ // Get the name of the build artifact associated with target (should
+ // contain what the user entered in the UI).
+ artifactName = element.getAttribute(ARTIFACT_NAME);
+
+ // Get the overridden extension
+ if (element.hasAttribute(EXTENSION)) {
+ extension = element.getAttribute(EXTENSION);
+ }
+
+ // parent
+ String parentId = element.getAttribute(PARENT);
+ if (parentId != null)
+ parent = ManagedBuildManager.getTarget(null, parentId);
+
+ // isAbstract
+ if ("true".equals(element.getAttribute(IS_ABSTRACT))) //$NON-NLS-1$
+ isAbstract = true;
+
+ // Is this a test target
+ isTest = ("true".equals(element.getAttribute(IS_TEST))); //$NON-NLS-1$
+
+ // Get the clean command
+ if (element.hasAttribute(CLEAN_COMMAND)) {
+ cleanCommand = element.getAttribute(CLEAN_COMMAND);
+ }
+
+ // Get the semicolon separated list of IDs of the error parsers
+ if (element.hasAttribute(ERROR_PARSERS)) {
+ errorParserIds = element.getAttribute(ERROR_PARSERS);
+ }
+
+ // Get the make command and arguments
+ if (element.hasAttribute(MAKE_COMMAND)) {
+ makeCommand = element.getAttribute(MAKE_COMMAND);
+ }
+ if(element.hasAttribute(MAKE_ARGS)) {
+ makeArguments = element.getAttribute(MAKE_ARGS);
+ }
+
+ Node child = element.getFirstChild();
+ while (child != null) {
+ if (child.getNodeName().equals(IConfigurationV2.CONFIGURATION_ELEMENT_NAME)) {
+ new ConfigurationV2(this, (Element)child);
+ }
+ child = child.getNextSibling();
+ }
+ }
+
+ /**
+ * @param configuration
+ */
+ public void addConfiguration(IConfigurationV2 configuration) {
+ getConfigurationList().add(configuration);
+ getConfigurationMap().put(configuration.getId(), configuration);
+ }
+
+ /**
+ * Adds a tool specification to the receiver. This tool is defined
+ * only for the receiver, and cannot be shared by other targets.
+ *
+ * @param tool
+ */
+ public void addTool(ITool tool) {
+ getToolList().add(tool);
+ getToolMap().put(tool.getId(), tool);
+ }
+
+ /**
+ * Adds a tool reference to the receiver.
+ *
+ * @param toolRef
+ */
+ public void addToolReference(ToolReference toolRef) {
+ getLocalToolReferences().add(toolRef);
+ }
+
+
+ /* (non-Javadoc)
+ * Tail-recursion method that creates a lits of tools and tool reference
+ * walking the receiver's parent hierarchy.
+ *
+ * @param toolArray
+ */
+ private void addToolsToArray(Vector toolArray) {
+ if (parent != null) {
+ ((Target)parent).addToolsToArray(toolArray);
+ }
+
+ // Add the tools from out own list
+ toolArray.addAll(getToolList());
+
+ // Add local tool references
+ toolArray.addAll(getLocalToolReferences());
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.build.managed.ITarget#createConfiguration(org.eclipse.cdt.core.build.managed.IConfigurationV2)
+ */
+ public IConfigurationV2 createConfiguration(IConfigurationV2 parent, String id) {
+ isDirty = true;
+ return new ConfigurationV2(this, parent, id);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.build.managed.ITarget#createConfiguration()
+ */
+ public IConfigurationV2 createConfiguration(String id) {
+ return new ConfigurationV2(this, id);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.core.ITarget#getArtifactExtension()
+ */
+ public String getArtifactExtension() {
+ // Has the user changed the extension for this target
+ if (extension != null) {
+ return extension;
+ }
+ // If not, then go through the default extension lookup
+ if (defaultExtension == null) {
+ // Ask my parent first
+ if (parent != null) {
+ return parent.getArtifactExtension();
+ } else {
+ return EMPTY_STRING;
+ }
+ } else {
+ return defaultExtension;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.build.managed.ITarget#getArtifactName()
+ */
+ public String getArtifactName() {
+ if (artifactName == null) {
+ // If I have a parent, ask it
+ if (parent != null) {
+ return parent.getArtifactName();
+ } else {
+ // I'm it and this is not good!
+ return EMPTY_STRING;
+ }
+ } else {
+ return artifactName;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.core.ITarget#getBinaryParserId()
+ */
+ public String getBinaryParserId() {
+ if (binaryParserId == null) {
+ // If I have a parent, ask it
+ if (parent != null) {
+ return parent.getBinaryParserId();
+ } else {
+ // I'm it and this is not good!
+ return EMPTY_STRING;
+ }
+ }
+ return binaryParserId;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.build.managed.ITarget#getCleanCommand()
+ */
+ public String getCleanCommand() {
+ // Return the command used to remove files
+ if (cleanCommand == null) {
+ if (parent != null) {
+ return parent.getCleanCommand();
+ } else {
+ // User forgot to specify it. Guess based on OS.
+ if (Platform.getOS().equals(Platform.OS_WIN32)) {
+ return new String("del"); //$NON-NLS-1$
+ } else {
+ return new String("rm"); //$NON-NLS-1$
+ }
+ }
+ } else {
+ // This was spec'd in the manifest
+ return cleanCommand;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.build.managed.ITarget#getConfiguration()
+ */
+ public IConfigurationV2 getConfiguration(String id) {
+ return (IConfigurationV2)getConfigurationMap().get(id);
+ }
+
+ /* (non-Javadoc)
+ * Safe accessor for the list of configurations.
+ *
+ * @return List containing the configurations
+ */
+ private List getConfigurationList() {
+ if (configList == null) {
+ configList = new ArrayList();
+ }
+ return configList;
+ }
+
+ /* (non-Javadoc)
+ * Safe accessor for the map of configuration ids to configurations
+ *
+ * @return
+ */
+ private Map getConfigurationMap() {
+ if (configMap == null) {
+ configMap = new HashMap();
+ }
+ return configMap;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.core.ITarget#getConfigurations()
+ */
+ public IConfigurationV2[] getConfigurations() {
+ return (IConfigurationV2[])getConfigurationList().toArray(new IConfigurationV2[getConfigurationList().size()]);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.core.ITarget#getDefaultExtension()
+ */
+ public String getDefaultExtension() {
+ return defaultExtension == null ? EMPTY_STRING : defaultExtension;
+ }
+
+ private Map getDepCalcMap() {
+ if (depCalculatorsMap == null) {
+ depCalculatorsMap = new HashMap();
+ }
+ return depCalculatorsMap;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.core.ITarget#getErrorParserIds()
+ */
+ public String getErrorParserIds() {
+ if (errorParserIds == null) {
+ // If I have a parent, ask it
+ if (parent != null) {
+ return parent.getErrorParserIds();
+ }
+ }
+ return errorParserIds;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.core.ITarget#getErrorParserList()
+ */
+ public String[] getErrorParserList() {
+ String parserIDs = getErrorParserIds();
+ String[] errorParsers = null;
+ if (parserIDs != null) {
+ // Check for an empty string
+ if (parserIDs.length() == 0) {
+ errorParsers = new String[0];
+ } else {
+ StringTokenizer tok = new StringTokenizer(parserIDs, ";"); //$NON-NLS-1$
+ List list = new ArrayList(tok.countTokens());
+ while (tok.hasMoreElements()) {
+ list.add(tok.nextToken());
+ }
+ String[] strArr = {""}; //$NON-NLS-1$
+ errorParsers = (String[]) list.toArray(strArr);
+ }
+ } else {
+ // If no error parsers are specified by the target, the default is
+ // all error parsers
+ errorParsers = CCorePlugin.getDefault().getAllErrorParsersIDs();
+ }
+ return errorParsers;
+ }
+
+ /* (non-javadoc)
+ * A safe accesor method. It answers the tool reference list in the
+ * receiver.
+ *
+ * @return List
+ */
+ protected List getLocalToolReferences() {
+ if (toolReferences == null) {
+ toolReferences = new ArrayList();
+ }
+ return toolReferences;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.core.ITarget#getMakeArguments()
+ */
+ public String getMakeArguments() {
+ if (makeArguments == null) {
+ // See if it is defined in my parent
+ if (parent != null) {
+ return parent.getMakeArguments();
+ } else {
+ // No parent and no user setting
+ return new String(""); //$NON-NLS-1$
+ }
+ }
+ return makeArguments;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.build.managed.ITarget#getMakeCommand()
+ */
+ public String getMakeCommand() {
+ // Return the name of the make utility
+ if (makeCommand == null) {
+ // If I have a parent, ask it
+ if (parent != null) {
+ return parent.getMakeCommand();
+ } else {
+ // The user has forgotten to specify a command in the plugin manifest
+ return new String("make"); //$NON-NLS-1$
+ }
+ } else {
+ return makeCommand;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.core.IBuildObject#getName()
+ */
+ public String getName() {
+ // If I am unnamed, see if I can inherit one from my parent
+ if (name == null) {
+ if (parent != null) {
+ return parent.getName();
+ } else {
+ return new String(""); //$NON-NLS-1$
+ }
+ } else {
+ return name;
+ }
+ }
+
+ /* (non-javadoc)
+ *
+ * @param tool
+ * @return List
+ */
+ protected List getOptionReferences(ITool tool) {
+ List references = new ArrayList();
+
+ // Get all the option references I add for this tool
+ ToolReference toolRef = getToolReference(tool);
+ if (toolRef != null) {
+ references.addAll(toolRef.getOptionReferenceList());
+ }
+
+ // See if there is anything that my parents add that I don't
+ if (parent != null) {
+ List temp = ((Target)parent).getOptionReferences(tool);
+ Iterator iter = temp.listIterator();
+ while (iter.hasNext()) {
+ OptionReference ref = (OptionReference) iter.next();
+ if (!references.contains(ref)) {
+ references.add(ref);
+ }
+ }
+ }
+
+ return references;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.core.ITarget#getOwner()
+ */
+ public IResource getOwner() {
+ return owner;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.core.ITarget#getParent()
+ */
+ public ITarget getParent() {
+ return parent;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.core.ITarget#getTargetArchList()
+ */
+ public String[] getTargetArchList() {
+ if (targetArchList == null) {
+ // Ask parent for its list
+ if (parent != null) {
+ return parent.getTargetArchList();
+ } else {
+ // I have no parent and no defined list
+ return new String[] {"all"}; //$NON-NLS-1$
+ }
+ }
+ return (String[]) targetArchList.toArray(new String[targetArchList.size()]);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.core.ITarget#getTargetOSList()
+ */
+ public String[] getTargetOSList() {
+ if (targetOSList == null) {
+ // Ask parent for its list
+ if (parent != null) {
+ return parent.getTargetOSList();
+ } else {
+ // I have no parent and no defined filter list
+ return new String[] {"all"}; //$NON-NLS-1$
+ }
+ }
+ return (String[]) targetOSList.toArray(new String[targetOSList.size()]);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.core.ITarget#getTool(java.lang.String)
+ */
+ public ITool getTool(String id) {
+ ITool result = null;
+
+ // See if receiver has it in list
+ result = (ITool) getToolMap().get(id);
+
+ // If not, check if parent has it
+ if (result == null && parent != null) {
+ result = ((Target)parent).getTool(id);
+ }
+
+ // If not defined in parents, check if defined at all
+ if (result == null) {
+ result = ManagedBuildManager.getExtensionTool(id);
+ }
+
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * A safe accessor method for the list of tools maintained by the
+ * target
+ *
+ */
+ private List getToolList() {
+ if (toolList == null) {
+ toolList = new ArrayList();
+ }
+ return toolList;
+ }
+
+ /* (non-Javadoc)
+ * A safe accessor for the tool map
+ *
+ */
+ private Map getToolMap() {
+ if (toolMap == null) {
+ toolMap = new HashMap();
+ }
+ return toolMap;
+ }
+
+ /* (non-Javadoc)
+ * Returns the reference for a given tool or null
if one is not
+ * found.
+ *
+ * @param tool
+ * @return ToolReference
+ */
+ private ToolReference getToolReference(ITool tool) {
+ // See if the receiver has a reference to the tool
+ ToolReference ref = null;
+ if (tool == null) return ref;
+ Iterator iter = getLocalToolReferences().listIterator();
+ while (iter.hasNext()) {
+ ToolReference temp = (ToolReference)iter.next();
+ if (temp.references(tool)) {
+ ref = temp;
+ break;
+ }
+ }
+ return ref;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.core.ITarget#getTools()
+ */
+ public ITool[] getTools() {
+ Vector toolArray = new Vector();
+ addToolsToArray(toolArray);
+ return (ITool[]) toolArray.toArray(new ITool[toolArray.size()]);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.core.ITarget#hasMakeCommandOverride()
+ */
+ public boolean hasOverridenMakeCommand() {
+ // We answer true if the make command or the flags are different
+ return ((makeCommand != null && !makeCommand.equals(parent.getMakeCommand()))
+ || (makeArguments != null && !makeArguments.equals(parent.getMakeArguments())));
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.build.managed.ITarget#isAbstract()
+ */
+ public boolean isAbstract() {
+ return isAbstract;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.core.ITarget#isDirty()
+ */
+ public boolean isDirty() {
+ // If I need saving, just say yes
+ if (isDirty) {
+ return true;
+ }
+
+ // Iterate over the configurations and ask them if they need saving
+ Iterator iter = getConfigurationList().listIterator();
+ while (iter.hasNext()) {
+ if (((IConfigurationV2)iter.next()).isDirty()) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.build.managed.ITarget#isTestTarget()
+ */
+ public boolean isTestTarget() {
+ return isTest;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.core.ITarget#needsRebuild()
+ */
+ public boolean needsRebuild(){
+ // Iterate over the configurations and ask them if they need saving
+ Iterator iter = getConfigurationList().listIterator();
+ while (iter.hasNext()) {
+ if (((IConfigurationV2)iter.next()).needsRebuild()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.core.ITarget#removeConfiguration(java.lang.String)
+ */
+ public void removeConfiguration(String id) {
+ // Remove the specified configuration from the list and map
+ Iterator iter = getConfigurationList().listIterator();
+ while (iter.hasNext()) {
+ IConfigurationV2 config = (IConfigurationV2)iter.next();
+ if (config.getId().equals(id)) {
+ getConfigurationList().remove(config);
+ getConfigurationMap().remove(id);
+ isDirty = true;
+ break;
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.core.ITarget#resetMakeCommand()
+ */
+ public void resetMakeCommand() {
+ // Flag target as dirty if the reset actually changes something
+ if (makeCommand != null) {
+ setDirty(true);
+ }
+ makeCommand = null;
+ makeArguments = null;
+ }
+
+ /**
+ *
+ */
+ public void resolveReferences() {
+ if (!resolved) {
+ resolved = true;
+ IManagedConfigElement element = ManagedBuildManager.getConfigElement(this);
+ // parent
+ String parentId = element.getAttribute(PARENT);
+ if (parentId != null) {
+ parent = ManagedBuildManager.getTarget(null, parentId);
+ // should resolve before calling methods on it
+ ((Target)parent).resolveReferences();
+ // copy over the parents configs
+ IConfigurationV2[] parentConfigs = parent.getConfigurations();
+ for (int i = 0; i < parentConfigs.length; ++i)
+ addConfiguration(parentConfigs[i]);
+ }
+
+ // call resolve references on any children
+ Iterator toolIter = getToolList().iterator();
+ while (toolIter.hasNext()) {
+ Tool current = (Tool)toolIter.next();
+ current.resolveReferences();
+ }
+ Iterator refIter = getLocalToolReferences().iterator();
+ while (refIter.hasNext()) {
+ ToolReference current = (ToolReference)refIter.next();
+ current.resolveReferences();
+ }
+ Iterator configIter = getConfigurationList().iterator();
+ while (configIter.hasNext()) {
+ ConfigurationV2 current = (ConfigurationV2)configIter.next();
+ current.resolveReferences();
+ }
+ }
+ }
+
+ /**
+ * Persist receiver to project file.
+ *
+ * @param doc
+ * @param element
+ */
+ public void serialize(Document doc, Element element) {
+ element.setAttribute(ID, getId());
+ element.setAttribute(NAME, getName());
+ if (parent != null)
+ element.setAttribute(PARENT, parent.getId());
+ element.setAttribute(IS_ABSTRACT, isAbstract ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$
+ element.setAttribute(ARTIFACT_NAME, getArtifactName());
+ if (extension != null) {
+ element.setAttribute(EXTENSION, extension);
+ }
+ element.setAttribute(IS_TEST, isTest ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$
+
+ if (makeCommand != null) {
+ element.setAttribute(MAKE_COMMAND, makeCommand);
+ } else {
+ // Make sure we use the default
+ }
+
+ if (makeArguments != null) {
+ element.setAttribute(MAKE_ARGS, makeArguments);
+ }
+ if (errorParserIds != null) {
+ element.setAttribute(ERROR_PARSERS, errorParserIds);
+ }
+
+ // Serialize the configuration settings
+ Iterator iter = getConfigurationList().listIterator();
+ while (iter.hasNext()) {
+ ConfigurationV2 config = (ConfigurationV2) iter.next();
+ Element configElement = doc.createElement(IConfigurationV2.CONFIGURATION_ELEMENT_NAME);
+ element.appendChild(configElement);
+ config.serialize(doc, configElement);
+ }
+
+ // I am clean now
+ isDirty = false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.core.ITarget#setArtifactExtension(java.lang.String)
+ */
+ public void setArtifactExtension(String extension) {
+ if (extension != null) {
+ this.extension = extension;
+ isDirty = true;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.build.managed.ITarget#setArtifactName(java.lang.String)
+ */
+ public void setArtifactName(String name) {
+ if (name != null) {
+ artifactName = name;
+ setRebuildState(true);
+ isDirty = true;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.core.ITarget#setDirty(boolean)
+ */
+ public void setDirty(boolean isDirty) {
+ // Override the dirty flag here
+ this.isDirty = isDirty;
+ // and in the configurations
+ Iterator iter = getConfigurationList().listIterator();
+ while (iter.hasNext()) {
+ IConfigurationV2 config = (IConfigurationV2)iter.next();
+ config.setDirty(isDirty);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.core.ITarget#setErrorParserIds()
+ */
+ public void setErrorParserIds(String ids) {
+ if (ids == null) return;
+ String currentIds = getErrorParserIds();
+ if (currentIds == null || !(currentIds.equals(ids))) {
+ errorParserIds = ids;
+ isDirty = true;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.core.ITarget#setMakeArguments(java.lang.String)
+ */
+ public void setMakeArguments(String makeArgs) {
+ if (makeArgs != null && !getMakeArguments().equals(makeArgs)) {
+ makeArguments = makeArgs;
+ setRebuildState(true);
+ isDirty = true;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.core.ITarget#setMakeCommand(java.lang.String)
+ */
+ public void setMakeCommand(String command) {
+ if (command != null && !getMakeCommand().equals(command)) {
+ makeCommand = command;
+ setRebuildState(true);
+ isDirty = true;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.core.ITarget#setRebuildState(boolean)
+ */
+ public void setRebuildState(boolean rebuild) {
+ Iterator iter = getConfigurationList().listIterator();
+ while (iter.hasNext()) {
+ ((IConfigurationV2)iter.next()).setRebuildState(rebuild);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.core.ITarget#updateOwner(org.eclipse.core.resources.IResource)
+ */
+ public void updateOwner(IResource resource) {
+ if (!resource.equals(owner)) {
+ // Set the owner correctly
+ owner = resource;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.core.ITarget#convertToProjectType()
+ */
+ public void convertToProjectType(String managedBuildRevision) {
+ // Create a ProjectType + Configuration + Toolchain + Builder + TargetPlatform
+ // from the Target
+
+ // The "parent" needs to have been converted already.
+ // Do it now if necessary.
+ ProjectType parentProj = null;
+ if (parent != null) {
+ parentProj = parent.getCreatedProjectType();
+ if (parentProj == null) {
+ parent.convertToProjectType(managedBuildRevision);
+ parentProj = parent.getCreatedProjectType();
+ }
+ }
+ ProjectType projectType = new ProjectType(parentProj, getId(), getName(), managedBuildRevision);
+ createdProjectType = projectType;
+ // Set the project type attributes
+ projectType.setIsAbstract(isAbstract);
+ projectType.setIsTest(isTest);
+ // Add children
+ // Add configurations (Configuration -> ToolChain -> Builder -> TargetPlatform)
+ Iterator iter = getConfigurationList().listIterator();
+ while (iter.hasNext()) {
+ IConfigurationV2 configV2 = (IConfigurationV2)iter.next();
+ if (configV2.getCreatedConfig() != null) continue;
+ // The new config's superClass needs to be the
+ // Configuration created from the ConfigurationV2 parent...
+ IConfiguration configSuperClass = null;
+ IConfigurationV2 parentV2 = configV2.getParent();
+ if (parentV2 != null) {
+ configSuperClass = parentV2.getCreatedConfig();
+ }
+ String id = configV2.getId();
+ String name = configV2.getName();
+ IConfiguration config = projectType.createConfiguration(configSuperClass, id, name);
+ configV2.setCreatedConfig(config);
+ // Set the configuration attributes
+ config.setArtifactName(getArtifactName());
+ config.setArtifactExtension(getArtifactExtension());
+ config.setCleanCommand(getCleanCommand());
+ config.setErrorParserIds(getErrorParserIds());
+ // Create the Tool-chain
+ String subId;
+ String subName;
+ subId = id + ".toolchain"; //$NON-NLS-1$
+ subName = name + ".toolchain"; //$NON-NLS-1$
+ IToolChain toolChain = config.createToolChain(null, subId, subName, true);
+ // Set the tool chain attributes
+ toolChain.setIsAbstract(isAbstract);
+ toolChain.setOSList(getTargetOSList());
+ toolChain.setArchList(getTargetArchList());
+ // In target element had a scannerInfoCollector element here which
+ // is now replaced with scanner config discovery profile id.
+ // Using the default per project profile for managed make
+ if(scannerInfoCollectorId != null && scannerInfoCollectorId.equals("org.eclipse.cdt.managedbuilder.internal.scannerconfig.DefaultGCCScannerInfoCollector")) //$NON-NLS-1$
+ toolChain.setScannerConfigDiscoveryProfileId(ManagedBuildCPathEntryContainer.MM_PP_DISCOVERY_PROFILE_ID);
+ // Create the Builder
+ subId = id + ".builder"; //$NON-NLS-1$
+ subName = name + ".builder"; //$NON-NLS-1$
+ IBuilder builder = toolChain.createBuilder(null, subId, subName, true);
+ // Set the builder attributes
+ builder.setIsAbstract(isAbstract);
+ builder.setCommand(getMakeCommand());
+ builder.setArguments(getMakeArguments());
+ IManagedConfigElement element = ManagedBuildManager.getConfigElement(this);
+ if (element instanceof DefaultManagedConfigElement) {
+ ((Builder)builder).setBuildFileGeneratorElement(((DefaultManagedConfigElement)element).getConfigurationElement());
+ }
+ // Create the TargetPlatform
+ subId = id + ".targetplatform"; //$NON-NLS-1$
+ subName = name + ".targetplatform"; //$NON-NLS-1$
+ ITargetPlatform targetPlatform = toolChain.createTargetPlatform(null, subId, subName, true);
+ // Set the target platform attributes
+ targetPlatform.setIsAbstract(isAbstract);
+ targetPlatform.setOSList(getTargetOSList());
+ targetPlatform.setArchList(getTargetArchList());
+ targetPlatform.setBinaryParserList(new String[]{getBinaryParserId()}); // Older projects will always have only one binary parser set.
+
+ // Handle ConfigurationV2 children (ToolReference)
+ // The tools references fetched here are strictly local to the configuration,
+ // so additional work is required to fetch the tool references from the target
+ IToolReference[] configToolRefs = configV2.getToolReferences();
+ // Add the "local" tool references (they are direct children of the target and
+ // its parent targets)
+ Vector targetToolRefs = new Vector();
+ addTargetToolReferences(targetToolRefs);
+ IToolReference[] toolRefs;
+ if (targetToolRefs.size() > 0) {
+ toolRefs = new IToolReference[targetToolRefs.size() + configToolRefs.length];
+ int i;
+ for (i = 0; i < configToolRefs.length; ++i) {
+ toolRefs[i] = configToolRefs[i];
+ }
+ Iterator localToolRefIter = targetToolRefs.iterator();
+ while (localToolRefIter.hasNext()) {
+ toolRefs[i++] = (IToolReference)localToolRefIter.next();
+ }
+ } else {
+ toolRefs = configToolRefs;
+ }
+ for (int i = 0; i < toolRefs.length; ++i) {
+ IToolReference toolRef = toolRefs[i];
+ subId = id + "." + toolRef.getId(); //$NON-NLS-1$
+ // The ToolReference's Tool becomes the newTool's SuperClass
+ ITool newTool = toolChain.createTool(toolRef.getTool(), subId, toolRef.getName(), true);
+ // Set the tool attributes
+ newTool.setToolCommand(toolRef.getRawToolCommand());
+ newTool.setOutputPrefix(toolRef.getRawOutputPrefix());
+ newTool.setOutputFlag(toolRef.getRawOutputFlag());
+ newTool.setOutputsAttribute(toolRef.getRawOutputExtensions());
+ // Handle ToolReference children (OptionReference)
+ Iterator optRefIter = toolRef.getOptionReferenceList().listIterator();
+ while (optRefIter.hasNext()) {
+ OptionReference optRef = (OptionReference)optRefIter.next();
+ subId = id + "." + optRef.getId(); //$NON-NLS-1$
+ IOption newOption = newTool.createOption(optRef.getOption(), subId, optRef.getName(), true);
+ // Set the option attributes
+ newOption.setValue(optRef.getValue());
+ newOption.setValueType(optRef.getValueType());
+ ((Option)newOption).setWasOptRef(true);
+ }
+ }
+
+ // Process the tools in the configuration, adding them to the toolchain
+ // Tools for a configuration are stored in the enclosing target, so getting
+ // the tools for the configuration ultimately gets them from the enclosing target
+ ITool[] configTools = configV2.getTools();
+ for (int i = 0; i < configTools.length; ++i) {
+ ITool tool = configTools[i];
+ // If tool references encountered, they have already been processed, above,
+ // so ignore them now
+ if (!(tool instanceof ToolReference)) {
+ // See if the toolchain already has a tool with a SuperClass that has an id
+ // equal to the tool that we are considering adding to the toolchain; if so,
+ // don't add it
+ // This case arises when we have added a tool to the toolchain because
+ // we processed a ToolReference (above) that references this tool
+ // The original tool referenced in the ToolReference becomes the SuperClass
+ // of the tool that is created because of the ToolReference
+ boolean found = false;
+ ITool[] tools = toolChain.getTools();
+ ITool currentTool;
+ ITool supercurrentTool;
+ for (int j = 0; j < tools.length; ++j) {
+ currentTool = tools[j];
+ supercurrentTool = currentTool.getSuperClass();
+ if (supercurrentTool != null) {
+ if (supercurrentTool.getId() == tool.getId()) {
+ found = true;
+ // If this tool was already added to the toolchain because of a
+ // ToolReference, then we disconnent this redundant
+ // tool from the target by setting the parent to null
+ ((Tool)tool).setToolParent(null);
+ break;
+ }
+ }
+ }
+
+ if (!found)
+ // This tool is not in the toolchain yet, so add it to the toolchain
+ ((ToolChain)toolChain).addTool((Tool)tool);
+
+ }
+ }
+ // Normalize the outputextensions list by adding an empty string for each tool
+ // which did not have an explicit output file extension specified
+ ((ToolChain)toolChain).normalizeOutputExtensions();
+ }
+ }
+
+ /*
+ * A target element may contain toolReference elements. These get applied to all of the configurations
+ * of the target. The method adds the list of this target's local tool references to the passed in vector.
+ */
+ public void addTargetToolReferences(Vector toolRefs) {
+ toolRefs.addAll(getLocalToolReferences());
+ if (parent != null) {
+ Target targetParent = (Target)parent;
+ targetParent.addTargetToolReferences(toolRefs);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.core.ITarget#getCreatedProjectType()
+ */
+ public ProjectType getCreatedProjectType() {
+ return createdProjectType;
+ }
+
+ /**
+ * @return Returns the version.
+ */
+ public PluginVersionIdentifier getVersion() {
+ if ( version == null) {
+ if ( getParent() != null) {
+ return getParent().getVersion();
+ }
+ }
+ return version;
+ }
+
+ public void setVersion(PluginVersionIdentifier version) {
+ // Do nothing
+ }
+
+}
diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/NewConfigurationDialog.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/NewConfigurationDialog.java
index 5f7c1caeadc..49e21bee17f 100644
--- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/NewConfigurationDialog.java
+++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/NewConfigurationDialog.java
@@ -1,578 +1,572 @@
-/*******************************************************************************
- * 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 Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Rational Software - Initial API and implementation
- *******************************************************************************/
-package org.eclipse.cdt.managedbuilder.ui.properties;
-
-import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
-import org.eclipse.cdt.managedbuilder.core.IProjectType;
-import org.eclipse.cdt.managedbuilder.core.IManagedProject;
-import org.eclipse.cdt.managedbuilder.core.IToolChain;
-import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import org.eclipse.cdt.internal.ui.dialogs.StatusDialog;
-import org.eclipse.cdt.internal.ui.dialogs.StatusInfo;
-import org.eclipse.cdt.managedbuilder.core.IConfiguration;
-import org.eclipse.cdt.managedbuilder.internal.ui.ManagedBuilderUIMessages;
-import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Combo;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Text;
-
-public class NewConfigurationDialog extends StatusDialog {
- // String constants
- private static final String PREFIX = "NewConfiguration"; //$NON-NLS-1$
- private static final String LABEL = PREFIX + ".label"; //$NON-NLS-1$
- private static final String ERROR = PREFIX + ".error"; //$NON-NLS-1$
- private static final String NAME = LABEL + ".name"; //$NON-NLS-1$
- private static final String GROUP = LABEL + ".group"; //$NON-NLS-1$
- private static final String COPY = LABEL + ".copy"; //$NON-NLS-1$
- private static final String CLONE = LABEL + ".clone"; //$NON-NLS-1$
- private static final String SHOWALL = LABEL + ".showall"; //$NON-NLS-1$
- private static final String DUPLICATE = ERROR + ".duplicateName"; //$NON-NLS-1$
- private static final String CASE = ERROR + ".caseName"; //$NON-NLS-1$
- private static final String INVALID = ERROR + ".invalidName"; //$NON-NLS-1$
- private static final String DESCRIPTION = LABEL + ".description"; //$NON-NLS-1$
-
- private static final String ID_SEPARATOR = "."; //$NON-NLS-1$
-
- // Widgets
- private Button btnClone;
- private Button btnCopy;
- private Text configName;
- private Text configDescription;
- private Combo copyConfigSelector;
- private Combo cloneConfigSelector;
- private Button btnShowAll;
-
- // Bookeeping
- private boolean clone;
- /** Default configurations defined in the toolchain description */
- private IConfiguration[] defaultConfigs;
- /** Configurations defined in the target */
- private IConfiguration[] definedConfigs;
- private IConfiguration parentConfig;
- private IManagedProject managedProject;
- private String newName;
- private String newDescription;
- /** A list containing config names that have been defined but not added to the target */
- final private ArrayList reservedNames;
- final private String title;
-
-
- /**
- * @param parentShell
- * @param managedTarget
- * @param nameList A list of names (Strings) that have been added by the user but have not yet been added to the target
- * @param title The title of the dialog
- */
- protected NewConfigurationDialog(Shell parentShell, IManagedProject managedProject, String title) {
- super(parentShell);
- this.title = title;
- setShellStyle(getShellStyle()|SWT.RESIZE);
- newName = new String();
- newDescription = new String();
- parentConfig = null;
- this.managedProject = managedProject;
- reservedNames = new ArrayList();
- // The default behaviour is to clone the settings
- clone = true;
-
- // Populate the list of default and defined configurations
- definedConfigs = managedProject.getConfigurations();
- IProjectType projectType = managedProject.getProjectType();
- defaultConfigs = projectType.getConfigurations();
-
- // Get the defined configuration names
- for (int i = 0; i < definedConfigs.length; i++) {
- reservedNames.add(definedConfigs[i].getName());
- }
-
- }
-
- /* (non-Javadoc)
- * Method declared on Dialog. Cache the name and base config selections.
- * We don't have to worry that the index or name is wrong because we
- * enable the OK button IFF those conditions are met.
- */
- protected void buttonPressed(int buttonId) {
- if (buttonId == IDialogConstants.OK_ID) {
- String description = new String();
- String nameAndDescription = new String();
- String baseConfigNameAndDescription = new String();
-
- newName = configName.getText().trim();
- newDescription = configDescription.getText().trim();
-
- if (clone) {
- baseConfigNameAndDescription = cloneConfigSelector.getItem(cloneConfigSelector.getSelectionIndex());
- for (int i = 0; i < definedConfigs.length; i++) {
- IConfiguration config = definedConfigs[i];
- description = config.getDescription();
-
- if( (description == null) || (description.equals("")) ){ //$NON-NLS-1$
- nameAndDescription = config.getName();
- } else {
- nameAndDescription = config.getName() + "( " + description + " )"; //$NON-NLS-1$ //$NON-NLS-2$
- }
- if (nameAndDescription.equals(baseConfigNameAndDescription)) {
- parentConfig = config;
- break;
- }
- }
- } else {
- // Get the parent config out of the default config list
- baseConfigNameAndDescription = copyConfigSelector.getItem(copyConfigSelector.getSelectionIndex());
- for (int i = 0; i < defaultConfigs.length; i++) {
- IConfiguration config = defaultConfigs[i];
- description = config.getDescription();
-
- if( (description == null) || (description.equals("")) ) { //$NON-NLS-1$
- nameAndDescription = config.getName();
- } else {
- nameAndDescription = config.getName() + "( " + description + " )"; //$NON-NLS-1$ //$NON-NLS-2$
- }
- if (nameAndDescription.equals(baseConfigNameAndDescription)) {
- parentConfig = config;
- break;
- }
- }
- }
- } else {
- newName = null;
- newDescription = null;
- parentConfig = null;
- }
- super.buttonPressed(buttonId);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
- */
- protected void configureShell(Shell shell) {
- super.configureShell(shell);
- if (title != null)
- shell.setText(title);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
- */
- protected void createButtonsForButtonBar(Composite parent) {
- super.createButtonsForButtonBar(parent);
- configName.setFocus();
- if (configName != null) {
- configName.setText(newName);
- }
- validateState();
- }
-
- protected Control createDialogArea(Composite parent) {
-
- Composite composite = new Composite(parent, SWT.NULL);
- composite.setFont(parent.getFont());
- composite.setLayout(new GridLayout(3, false));
- composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
-
- // Create a group for the name & description
-
- final Group group1 = new Group(composite, SWT.NONE);
- group1.setFont(composite.getFont());
- GridLayout layout1 = new GridLayout(3, false);
- group1.setLayout(layout1);
- GridData gd = new GridData(GridData.FILL_HORIZONTAL);
- gd.horizontalSpan = 3;
- group1.setLayoutData(gd);
-
- // Add a label and a text widget for Configuration's name
- final Label nameLabel = new Label(group1, SWT.LEFT);
- nameLabel.setFont(parent.getFont());
- nameLabel.setText(ManagedBuilderUIMessages.getResourceString(NAME));
-
- gd = new GridData(GridData.FILL_HORIZONTAL);
- gd.horizontalSpan = 1;
- gd.grabExcessHorizontalSpace = false;
- nameLabel.setLayoutData(gd);
-
- configName = new Text(group1, SWT.SINGLE | SWT.BORDER);
- configName.setFont(group1.getFont());
- configName.setText(getNewName());
- configName.setFocus();
- gd = new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL);
- gd.horizontalSpan = 2;
- gd.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
- configName.setLayoutData(gd);
- configName.addModifyListener(new ModifyListener() {
- public void modifyText(ModifyEvent e) {
- validateState();
- }
- });
-
-// Add a label and a text widget for Configuration's description
- final Label descriptionLabel = new Label(group1, SWT.LEFT);
- descriptionLabel.setFont(parent.getFont());
- descriptionLabel.setText(ManagedBuilderUIMessages.getResourceString(DESCRIPTION));
-
- gd = new GridData(GridData.FILL_HORIZONTAL);
- gd.horizontalSpan = 1;
- gd.grabExcessHorizontalSpace = false;
- descriptionLabel.setLayoutData(gd);
- configDescription = new Text(group1, SWT.SINGLE | SWT.BORDER);
- configDescription.setFont(group1.getFont());
- configDescription.setText(getNewDescription());
- configDescription.setFocus();
-
- gd = new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL);
- gd.horizontalSpan = 2;
- gd.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
- configDescription.setLayoutData(gd);
-
- // Create a group for the radio buttons
-
- final Group group = new Group(composite, SWT.NONE);
- group.setFont(composite.getFont());
- group.setText(ManagedBuilderUIMessages.getResourceString(GROUP));
- GridLayout layout = new GridLayout(3, false);
- group.setLayout(layout);
- gd = new GridData(GridData.FILL_HORIZONTAL);
- gd.horizontalSpan = 3;
- group.setLayoutData(gd);
-
- SelectionListener radioListener = new SelectionAdapter() {
- public void widgetSelected(SelectionEvent event) {
- clone = btnClone.getSelection();
- updateComboState();
- }
- };
- // Add a radio button and combo box to copy from default config
- btnCopy = new Button(group, SWT.RADIO);
- btnCopy.setFont(group.getFont());
- btnCopy.setText(ManagedBuilderUIMessages.getResourceString(COPY));
- setButtonLayoutData(btnCopy);
- btnCopy.addSelectionListener(radioListener);
-
- copyConfigSelector = new Combo(group, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER);
- copyConfigSelector.setFont(group.getFont());
- int index = copyConfigSelector.indexOf(newName);
- copyConfigSelector.select(index < 0 ? 0 : index);
- gd = new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL);
- gd.horizontalSpan = 2;
- gd.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
- copyConfigSelector.setLayoutData(gd);
- copyConfigSelector.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- validateState();
- }
- });
- copyConfigSelector.setEnabled(false);
-
- // Create a radio button and combo for clonable configs
- btnClone = new Button(group, SWT.RADIO);
- btnClone.setFont(group.getFont());
- btnClone.setText(ManagedBuilderUIMessages.getResourceString(CLONE));
- setButtonLayoutData(btnClone);
- btnClone.addSelectionListener(radioListener);
- btnClone.setSelection(true);
-
- cloneConfigSelector = new Combo(group, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER);
- cloneConfigSelector.setFont(group.getFont());
- cloneConfigSelector.setItems(getDefinedConfigNamesAndDescriptions());
- index = cloneConfigSelector.indexOf(newName);
- cloneConfigSelector.select(index < 0 ? 0 : index);
- gd = new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL);
- gd.horizontalSpan = 2;
- gd.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
- cloneConfigSelector.setLayoutData(gd);
- cloneConfigSelector.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- validateState();
- }
- });
-
- // Create a "show all configurations" button
- btnShowAll = new Button(composite, SWT.CHECK);
- btnShowAll.setFont(composite.getFont());
- btnShowAll.setText(ManagedBuilderUIMessages.getResourceString(SHOWALL));
- gd = new GridData(GridData.FILL_HORIZONTAL);
- gd.horizontalSpan = 1;
- btnShowAll.setLayoutData(gd);
- btnShowAll.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- updateDefaultConfigs();
- }
- });
-
- updateComboState();
- updateDefaultConfigs();
-
- return composite;
- }
-
-
- /**
- * @return the IConfiguration
the user selected as
- * the parent of the new configuration.
- */
- public IConfiguration getParentConfiguration() {
- return parentConfig;
- }
-
- /**
- * updates the list of default configurations
- */
- private void updateDefaultConfigs(){
- IConfiguration cfgs[] = managedProject.getProjectType().getConfigurations();
- boolean showAll = btnShowAll != null ? btnShowAll.getSelection() : false;
-
- if(showAll)
- defaultConfigs = cfgs;
- else {
- ArrayList list = new ArrayList();
- for (int i = 0; i < cfgs.length; i++) {
- if (cfgs[i].isSupported()) {
- IToolChain tc = cfgs[i].getToolChain();
-
- // Determine if the tool-chain has 'convertToId' attribute.
- // If so, do not add this configuration to the list.
- if (!tc.getConvertToId().equals(""))
- continue;
- list.add(cfgs[i]);
- }
- }
- defaultConfigs = (IConfiguration[]) list
- .toArray(new IConfiguration[list.size()]);
- }
-
- if(defaultConfigs.length != 0){
- String namesAndDescriptions[] = new String[defaultConfigs.length];
- for (int i = 0; i < defaultConfigs.length; ++i) {
- if ( (defaultConfigs[i].getDescription() == null) || defaultConfigs[i].getDescription().equals("")) //$NON-NLS-1$
- namesAndDescriptions[i] = defaultConfigs[i].getName();
- else
- namesAndDescriptions[i] = defaultConfigs[i].getName() + "( " + defaultConfigs[i].getDescription() + " )"; //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- int selectionIndex = copyConfigSelector.getSelectionIndex();
- String oldSelection = null;
- if(selectionIndex != -1)
- oldSelection = copyConfigSelector.getItem(selectionIndex);
-
- copyConfigSelector.setItems(namesAndDescriptions);
- if(oldSelection != null)
- selectionIndex = copyConfigSelector.indexOf(oldSelection);
- if(selectionIndex == -1)
- selectionIndex = 0;
- copyConfigSelector.select(selectionIndex);
- }
- else{
- copyConfigSelector.removeAll();
- }
- validateState();
- }
-
- /*
- * Returns the array of configuration names defined for this managed project.
- * This list will be used to populate the list of configurations to
- * clone.
- */
- private String [] getDefinedConfigNamesAndDescriptions() {
- String [] namesAndDescriptions = new String[definedConfigs.length];
- for (int index = 0; index < definedConfigs.length; ++index) {
- IConfiguration config = definedConfigs[index];
- if ( (config.getDescription() == null) || config.getDescription().equals("")) //$NON-NLS-1$
- namesAndDescriptions[index] = config.getName();
- else
- namesAndDescriptions[index] = config.getName() + "( " + config.getDescription() +" )"; //$NON-NLS-1$ //$NON-NLS-2$
- }
- return namesAndDescriptions;
- }
-
- /**
- * @return String
containing the name chosen by the user for the
- * new configuration.
- */
- public String getNewName() {
- return newName;
- }
-
- /* (non-Javadoc)
- * Answers true
if the name entered by the user clashes
- * with an existing configuration name.
- *
- * @param newName
- * @return
- */
- protected boolean isDuplicateName(String newName) {
- // Return true if there is already a config of that name defined
- for (int index = 0; index < definedConfigs.length; index++) {
- IConfiguration configuration = definedConfigs[index];
- if (configuration.getName().equals(newName)) {
- return true;
- }
- }
- if (reservedNames.contains(newName)) {
- return true;
- }
- return false;
- }
-
- /* (non-Javadoc)
- * Answers true
if the name entered by the user differs
- * only in case from an existing name.
- *
- * @param newName
- * @return
- */
- protected boolean isSimilarName(String newName) {
- // Return true if there is already a config of that name defined on the target
- for (int index = 0; index < definedConfigs.length; index++) {
- IConfiguration configuration = definedConfigs[index];
- if (configuration.getName().equalsIgnoreCase(newName)) {
- return true;
- }
- }
- Iterator iter = reservedNames.listIterator();
- while (iter.hasNext()) {
- if (((String)iter.next()).equalsIgnoreCase(newName)) {
- return true;
- }
- }
- return false;
- }
-
- /* (non-Javadoc)
- * Radio button selection event handler calls this helper method to
- * enable or disable the radio buttons.
- */
- protected void updateComboState() {
- cloneConfigSelector.setEnabled(clone);
- copyConfigSelector.setEnabled(!clone);
- btnShowAll.setVisible(!clone);
- validateState();
- }
-
- /* (non-Javadoc)
- * Checks the argument for leading whitespaces and invalid directory name characters.
- * @param name
- * @return true is the name is a valid directory name with no whitespaces
- */
- private boolean validateName(String name) {
- // Names must be at least one character in length
- if (name.trim().length() == 0)
- return false;
-
- // Iterate over the name checking for bad characters
- char[] chars = name.toCharArray();
- // No whitespaces at the start of a name
- if (Character.isWhitespace(chars[0])) {
- return false;
- }
- for (int index = 0; index < chars.length; ++index) {
- // Config name must be a valid dir name too, so we ban "\ / : * ? " < >" in the names
- if (!Character.isLetterOrDigit(chars[index])) {
- switch (chars[index]) {
- case '/':
- case '\\':
- case ':':
- case '*':
- case '?':
- case '\"':
- case '<':
- case '>':
- return false;
- default:
- break;
- }
- }
- }
- return true;
- }
- /* (non-Javadoc)
- * Update the status message and button state based on the input selected
- * by the user
- *
- */
- private void validateState() {
- StatusInfo status= new StatusInfo();
- String currentName = configName.getText();
- // Trim trailing whitespace
- while (currentName.length() > 0 && Character.isWhitespace(currentName.charAt(currentName.length()-1))) {
- currentName = currentName.substring(0, currentName.length()-1);
- }
- // Make sure that the name is at least one character in length
- if (currentName.length() == 0) {
- // No error message, but cannot select OK
- status.setError(""); //$NON-NLS-1$
- } else if(clone ? definedConfigs.length == 0 : defaultConfigs.length == 0) {
- // Not an error
- status.setError(""); //$NON-NLS-1$
- // Make sure the name is not a duplicate
- } else if (isDuplicateName(currentName)) {
- status.setError(ManagedBuilderUIMessages.getFormattedString(DUPLICATE, currentName));
- } else if (isSimilarName(currentName)) {
- status.setError(ManagedBuilderUIMessages.getFormattedString(CASE, currentName));
- } else if (!validateName(currentName)) {
- // TODO Create a decent I18N string to describe this problem
- status.setError(ManagedBuilderUIMessages.getFormattedString(INVALID, currentName));
- }
-
- updateStatus(status);
- return;
- }
- public String getNewDescription() {
- return newDescription;
- }
-
- /**
- * Create a new configuration, using the values currently set in
- * the dialog.
- */
- public IConfiguration newConfiguration(IManagedBuildInfo info) {
- int id = ManagedBuildManager.getRandomNumber();
-
- // Create ID for the new component based on the parent ID and random component
- String newId = parentConfig.getId();
- int index = newId.lastIndexOf(ID_SEPARATOR);
- if (index > 0) {
- String lastComponent = newId.substring(index + 1, newId.length());
- if (Character.isDigit(lastComponent.charAt(0))) {
- // Strip the last component
- newId = newId.substring(0, index);
- }
- }
- newId += ID_SEPARATOR + id;
- IConfiguration newConfig;
- if (parentConfig.isExtensionElement()) {
- newConfig = info.getManagedProject().createConfiguration(parentConfig, newId);
- } else {
- newConfig = info.getManagedProject().createConfigurationClone(parentConfig, newId);
- }
-
- newConfig.setName(newName);
- newConfig.setDescription(newDescription);
- newConfig.setArtifactName(info.getManagedProject().getDefaultArtifactName());
- return newConfig;
- }
-
-}
+/*******************************************************************************
+ * 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 Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Rational Software - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.managedbuilder.ui.properties;
+
+import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
+import org.eclipse.cdt.managedbuilder.core.IProjectType;
+import org.eclipse.cdt.managedbuilder.core.IManagedProject;
+import org.eclipse.cdt.managedbuilder.core.IToolChain;
+import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import org.eclipse.cdt.internal.ui.dialogs.StatusDialog;
+import org.eclipse.cdt.internal.ui.dialogs.StatusInfo;
+import org.eclipse.cdt.managedbuilder.core.IConfiguration;
+import org.eclipse.cdt.managedbuilder.internal.ui.ManagedBuilderUIMessages;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+public class NewConfigurationDialog extends StatusDialog {
+ // String constants
+ private static final String PREFIX = "NewConfiguration"; //$NON-NLS-1$
+ private static final String LABEL = PREFIX + ".label"; //$NON-NLS-1$
+ private static final String ERROR = PREFIX + ".error"; //$NON-NLS-1$
+ private static final String NAME = LABEL + ".name"; //$NON-NLS-1$
+ private static final String GROUP = LABEL + ".group"; //$NON-NLS-1$
+ private static final String COPY = LABEL + ".copy"; //$NON-NLS-1$
+ private static final String CLONE = LABEL + ".clone"; //$NON-NLS-1$
+ private static final String SHOWALL = LABEL + ".showall"; //$NON-NLS-1$
+ private static final String DUPLICATE = ERROR + ".duplicateName"; //$NON-NLS-1$
+ private static final String CASE = ERROR + ".caseName"; //$NON-NLS-1$
+ private static final String INVALID = ERROR + ".invalidName"; //$NON-NLS-1$
+ private static final String DESCRIPTION = LABEL + ".description"; //$NON-NLS-1$
+
+ // Widgets
+ private Button btnClone;
+ private Button btnCopy;
+ private Text configName;
+ private Text configDescription;
+ private Combo copyConfigSelector;
+ private Combo cloneConfigSelector;
+ private Button btnShowAll;
+
+ // Bookeeping
+ private boolean clone;
+ /** Default configurations defined in the toolchain description */
+ private IConfiguration[] defaultConfigs;
+ /** Configurations defined in the target */
+ private IConfiguration[] definedConfigs;
+ private IConfiguration parentConfig;
+ private IManagedProject managedProject;
+ private String newName;
+ private String newDescription;
+ /** A list containing config names that have been defined but not added to the target */
+ final private ArrayList reservedNames;
+ final private String title;
+
+
+ /**
+ * @param parentShell
+ * @param managedTarget
+ * @param nameList A list of names (Strings) that have been added by the user but have not yet been added to the target
+ * @param title The title of the dialog
+ */
+ protected NewConfigurationDialog(Shell parentShell, IManagedProject managedProject, String title) {
+ super(parentShell);
+ this.title = title;
+ setShellStyle(getShellStyle()|SWT.RESIZE);
+ newName = new String();
+ newDescription = new String();
+ parentConfig = null;
+ this.managedProject = managedProject;
+ reservedNames = new ArrayList();
+ // The default behaviour is to clone the settings
+ clone = true;
+
+ // Populate the list of default and defined configurations
+ definedConfigs = managedProject.getConfigurations();
+ IProjectType projectType = managedProject.getProjectType();
+ defaultConfigs = projectType.getConfigurations();
+
+ // Get the defined configuration names
+ for (int i = 0; i < definedConfigs.length; i++) {
+ reservedNames.add(definedConfigs[i].getName());
+ }
+
+ }
+
+ /* (non-Javadoc)
+ * Method declared on Dialog. Cache the name and base config selections.
+ * We don't have to worry that the index or name is wrong because we
+ * enable the OK button IFF those conditions are met.
+ */
+ protected void buttonPressed(int buttonId) {
+ if (buttonId == IDialogConstants.OK_ID) {
+ String description = new String();
+ String nameAndDescription = new String();
+ String baseConfigNameAndDescription = new String();
+
+ newName = configName.getText().trim();
+ newDescription = configDescription.getText().trim();
+
+ if (clone) {
+ baseConfigNameAndDescription = cloneConfigSelector.getItem(cloneConfigSelector.getSelectionIndex());
+ for (int i = 0; i < definedConfigs.length; i++) {
+ IConfiguration config = definedConfigs[i];
+ description = config.getDescription();
+
+ if( (description == null) || (description.equals("")) ){ //$NON-NLS-1$
+ nameAndDescription = config.getName();
+ } else {
+ nameAndDescription = config.getName() + "( " + description + " )"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ if (nameAndDescription.equals(baseConfigNameAndDescription)) {
+ parentConfig = config;
+ break;
+ }
+ }
+ } else {
+ // Get the parent config out of the default config list
+ baseConfigNameAndDescription = copyConfigSelector.getItem(copyConfigSelector.getSelectionIndex());
+ for (int i = 0; i < defaultConfigs.length; i++) {
+ IConfiguration config = defaultConfigs[i];
+ description = config.getDescription();
+
+ if( (description == null) || (description.equals("")) ) { //$NON-NLS-1$
+ nameAndDescription = config.getName();
+ } else {
+ nameAndDescription = config.getName() + "( " + description + " )"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ if (nameAndDescription.equals(baseConfigNameAndDescription)) {
+ parentConfig = config;
+ break;
+ }
+ }
+ }
+ } else {
+ newName = null;
+ newDescription = null;
+ parentConfig = null;
+ }
+ super.buttonPressed(buttonId);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
+ */
+ protected void configureShell(Shell shell) {
+ super.configureShell(shell);
+ if (title != null)
+ shell.setText(title);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
+ */
+ protected void createButtonsForButtonBar(Composite parent) {
+ super.createButtonsForButtonBar(parent);
+ configName.setFocus();
+ if (configName != null) {
+ configName.setText(newName);
+ }
+ validateState();
+ }
+
+ protected Control createDialogArea(Composite parent) {
+
+ Composite composite = new Composite(parent, SWT.NULL);
+ composite.setFont(parent.getFont());
+ composite.setLayout(new GridLayout(3, false));
+ composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ // Create a group for the name & description
+
+ final Group group1 = new Group(composite, SWT.NONE);
+ group1.setFont(composite.getFont());
+ GridLayout layout1 = new GridLayout(3, false);
+ group1.setLayout(layout1);
+ GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+ gd.horizontalSpan = 3;
+ group1.setLayoutData(gd);
+
+ // Add a label and a text widget for Configuration's name
+ final Label nameLabel = new Label(group1, SWT.LEFT);
+ nameLabel.setFont(parent.getFont());
+ nameLabel.setText(ManagedBuilderUIMessages.getResourceString(NAME));
+
+ gd = new GridData(GridData.FILL_HORIZONTAL);
+ gd.horizontalSpan = 1;
+ gd.grabExcessHorizontalSpace = false;
+ nameLabel.setLayoutData(gd);
+
+ configName = new Text(group1, SWT.SINGLE | SWT.BORDER);
+ configName.setFont(group1.getFont());
+ configName.setText(getNewName());
+ configName.setFocus();
+ gd = new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL);
+ gd.horizontalSpan = 2;
+ gd.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
+ configName.setLayoutData(gd);
+ configName.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ validateState();
+ }
+ });
+
+// Add a label and a text widget for Configuration's description
+ final Label descriptionLabel = new Label(group1, SWT.LEFT);
+ descriptionLabel.setFont(parent.getFont());
+ descriptionLabel.setText(ManagedBuilderUIMessages.getResourceString(DESCRIPTION));
+
+ gd = new GridData(GridData.FILL_HORIZONTAL);
+ gd.horizontalSpan = 1;
+ gd.grabExcessHorizontalSpace = false;
+ descriptionLabel.setLayoutData(gd);
+ configDescription = new Text(group1, SWT.SINGLE | SWT.BORDER);
+ configDescription.setFont(group1.getFont());
+ configDescription.setText(getNewDescription());
+ configDescription.setFocus();
+
+ gd = new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL);
+ gd.horizontalSpan = 2;
+ gd.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
+ configDescription.setLayoutData(gd);
+
+ // Create a group for the radio buttons
+
+ final Group group = new Group(composite, SWT.NONE);
+ group.setFont(composite.getFont());
+ group.setText(ManagedBuilderUIMessages.getResourceString(GROUP));
+ GridLayout layout = new GridLayout(3, false);
+ group.setLayout(layout);
+ gd = new GridData(GridData.FILL_HORIZONTAL);
+ gd.horizontalSpan = 3;
+ group.setLayoutData(gd);
+
+ SelectionListener radioListener = new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ clone = btnClone.getSelection();
+ updateComboState();
+ }
+ };
+ // Add a radio button and combo box to copy from default config
+ btnCopy = new Button(group, SWT.RADIO);
+ btnCopy.setFont(group.getFont());
+ btnCopy.setText(ManagedBuilderUIMessages.getResourceString(COPY));
+ setButtonLayoutData(btnCopy);
+ btnCopy.addSelectionListener(radioListener);
+
+ copyConfigSelector = new Combo(group, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER);
+ copyConfigSelector.setFont(group.getFont());
+ int index = copyConfigSelector.indexOf(newName);
+ copyConfigSelector.select(index < 0 ? 0 : index);
+ gd = new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL);
+ gd.horizontalSpan = 2;
+ gd.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
+ copyConfigSelector.setLayoutData(gd);
+ copyConfigSelector.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ validateState();
+ }
+ });
+ copyConfigSelector.setEnabled(false);
+
+ // Create a radio button and combo for clonable configs
+ btnClone = new Button(group, SWT.RADIO);
+ btnClone.setFont(group.getFont());
+ btnClone.setText(ManagedBuilderUIMessages.getResourceString(CLONE));
+ setButtonLayoutData(btnClone);
+ btnClone.addSelectionListener(radioListener);
+ btnClone.setSelection(true);
+
+ cloneConfigSelector = new Combo(group, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER);
+ cloneConfigSelector.setFont(group.getFont());
+ cloneConfigSelector.setItems(getDefinedConfigNamesAndDescriptions());
+ index = cloneConfigSelector.indexOf(newName);
+ cloneConfigSelector.select(index < 0 ? 0 : index);
+ gd = new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL);
+ gd.horizontalSpan = 2;
+ gd.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
+ cloneConfigSelector.setLayoutData(gd);
+ cloneConfigSelector.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ validateState();
+ }
+ });
+
+ // Create a "show all configurations" button
+ btnShowAll = new Button(composite, SWT.CHECK);
+ btnShowAll.setFont(composite.getFont());
+ btnShowAll.setText(ManagedBuilderUIMessages.getResourceString(SHOWALL));
+ gd = new GridData(GridData.FILL_HORIZONTAL);
+ gd.horizontalSpan = 1;
+ btnShowAll.setLayoutData(gd);
+ btnShowAll.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ updateDefaultConfigs();
+ }
+ });
+
+ updateComboState();
+ updateDefaultConfigs();
+
+ return composite;
+ }
+
+
+ /**
+ * @return the IConfiguration
the user selected as
+ * the parent of the new configuration.
+ */
+ public IConfiguration getParentConfiguration() {
+ return parentConfig;
+ }
+
+ /**
+ * updates the list of default configurations
+ */
+ private void updateDefaultConfigs(){
+ IConfiguration cfgs[] = managedProject.getProjectType().getConfigurations();
+ boolean showAll = btnShowAll != null ? btnShowAll.getSelection() : false;
+
+ if(showAll)
+ defaultConfigs = cfgs;
+ else {
+ ArrayList list = new ArrayList();
+ for (int i = 0; i < cfgs.length; i++) {
+ if (cfgs[i].isSupported()) {
+ IToolChain tc = cfgs[i].getToolChain();
+
+ // Determine if the tool-chain has 'convertToId' attribute.
+ // If so, do not add this configuration to the list.
+ if (!tc.getConvertToId().equals(""))
+ continue;
+ list.add(cfgs[i]);
+ }
+ }
+ defaultConfigs = (IConfiguration[]) list
+ .toArray(new IConfiguration[list.size()]);
+ }
+
+ if(defaultConfigs.length != 0){
+ String namesAndDescriptions[] = new String[defaultConfigs.length];
+ for (int i = 0; i < defaultConfigs.length; ++i) {
+ if ( (defaultConfigs[i].getDescription() == null) || defaultConfigs[i].getDescription().equals("")) //$NON-NLS-1$
+ namesAndDescriptions[i] = defaultConfigs[i].getName();
+ else
+ namesAndDescriptions[i] = defaultConfigs[i].getName() + "( " + defaultConfigs[i].getDescription() + " )"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ int selectionIndex = copyConfigSelector.getSelectionIndex();
+ String oldSelection = null;
+ if(selectionIndex != -1)
+ oldSelection = copyConfigSelector.getItem(selectionIndex);
+
+ copyConfigSelector.setItems(namesAndDescriptions);
+ if(oldSelection != null)
+ selectionIndex = copyConfigSelector.indexOf(oldSelection);
+ if(selectionIndex == -1)
+ selectionIndex = 0;
+ copyConfigSelector.select(selectionIndex);
+ }
+ else{
+ copyConfigSelector.removeAll();
+ }
+ validateState();
+ }
+
+ /*
+ * Returns the array of configuration names defined for this managed project.
+ * This list will be used to populate the list of configurations to
+ * clone.
+ */
+ private String [] getDefinedConfigNamesAndDescriptions() {
+ String [] namesAndDescriptions = new String[definedConfigs.length];
+ for (int index = 0; index < definedConfigs.length; ++index) {
+ IConfiguration config = definedConfigs[index];
+ if ( (config.getDescription() == null) || config.getDescription().equals("")) //$NON-NLS-1$
+ namesAndDescriptions[index] = config.getName();
+ else
+ namesAndDescriptions[index] = config.getName() + "( " + config.getDescription() +" )"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ return namesAndDescriptions;
+ }
+
+ /**
+ * @return String
containing the name chosen by the user for the
+ * new configuration.
+ */
+ public String getNewName() {
+ return newName;
+ }
+
+ /* (non-Javadoc)
+ * Answers true
if the name entered by the user clashes
+ * with an existing configuration name.
+ *
+ * @param newName
+ * @return
+ */
+ protected boolean isDuplicateName(String newName) {
+ // Return true if there is already a config of that name defined
+ for (int index = 0; index < definedConfigs.length; index++) {
+ IConfiguration configuration = definedConfigs[index];
+ if (configuration.getName().equals(newName)) {
+ return true;
+ }
+ }
+ if (reservedNames.contains(newName)) {
+ return true;
+ }
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * Answers true
if the name entered by the user differs
+ * only in case from an existing name.
+ *
+ * @param newName
+ * @return
+ */
+ protected boolean isSimilarName(String newName) {
+ // Return true if there is already a config of that name defined on the target
+ for (int index = 0; index < definedConfigs.length; index++) {
+ IConfiguration configuration = definedConfigs[index];
+ if (configuration.getName().equalsIgnoreCase(newName)) {
+ return true;
+ }
+ }
+ Iterator iter = reservedNames.listIterator();
+ while (iter.hasNext()) {
+ if (((String)iter.next()).equalsIgnoreCase(newName)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * Radio button selection event handler calls this helper method to
+ * enable or disable the radio buttons.
+ */
+ protected void updateComboState() {
+ cloneConfigSelector.setEnabled(clone);
+ copyConfigSelector.setEnabled(!clone);
+ btnShowAll.setVisible(!clone);
+ validateState();
+ }
+
+ /* (non-Javadoc)
+ * Checks the argument for leading whitespaces and invalid directory name characters.
+ * @param name
+ * @return true is the name is a valid directory name with no whitespaces
+ */
+ private boolean validateName(String name) {
+ // Names must be at least one character in length
+ if (name.trim().length() == 0)
+ return false;
+
+ // Iterate over the name checking for bad characters
+ char[] chars = name.toCharArray();
+ // No whitespaces at the start of a name
+ if (Character.isWhitespace(chars[0])) {
+ return false;
+ }
+ for (int index = 0; index < chars.length; ++index) {
+ // Config name must be a valid dir name too, so we ban "\ / : * ? " < >" in the names
+ if (!Character.isLetterOrDigit(chars[index])) {
+ switch (chars[index]) {
+ case '/':
+ case '\\':
+ case ':':
+ case '*':
+ case '?':
+ case '\"':
+ case '<':
+ case '>':
+ return false;
+ default:
+ break;
+ }
+ }
+ }
+ return true;
+ }
+ /* (non-Javadoc)
+ * Update the status message and button state based on the input selected
+ * by the user
+ *
+ */
+ private void validateState() {
+ StatusInfo status= new StatusInfo();
+ String currentName = configName.getText();
+ // Trim trailing whitespace
+ while (currentName.length() > 0 && Character.isWhitespace(currentName.charAt(currentName.length()-1))) {
+ currentName = currentName.substring(0, currentName.length()-1);
+ }
+ // Make sure that the name is at least one character in length
+ if (currentName.length() == 0) {
+ // No error message, but cannot select OK
+ status.setError(""); //$NON-NLS-1$
+ } else if(clone ? definedConfigs.length == 0 : defaultConfigs.length == 0) {
+ // Not an error
+ status.setError(""); //$NON-NLS-1$
+ // Make sure the name is not a duplicate
+ } else if (isDuplicateName(currentName)) {
+ status.setError(ManagedBuilderUIMessages.getFormattedString(DUPLICATE, currentName));
+ } else if (isSimilarName(currentName)) {
+ status.setError(ManagedBuilderUIMessages.getFormattedString(CASE, currentName));
+ } else if (!validateName(currentName)) {
+ // TODO Create a decent I18N string to describe this problem
+ status.setError(ManagedBuilderUIMessages.getFormattedString(INVALID, currentName));
+ }
+
+ updateStatus(status);
+ return;
+ }
+ public String getNewDescription() {
+ return newDescription;
+ }
+
+ /**
+ * Create a new configuration, using the values currently set in
+ * the dialog.
+ */
+ public IConfiguration newConfiguration(IManagedBuildInfo info) {
+
+ String newId = null;
+ IConfiguration newConfig;
+
+ if (parentConfig.isExtensionElement()) {
+ // If parent config is an extension element,
+ // Create ID for the new component based on the parentConfig's id and random component
+ newId = ManagedBuildManager.calculateChildId(parentConfig.getId(), null);
+ newConfig = info.getManagedProject().createConfiguration(parentConfig, newId);
+ } else {
+ // If parent config is not an extension element, then
+ // Create ID for the new component based on the parentConfig's parent id and random component
+ newId = ManagedBuildManager.calculateChildId(parentConfig.getParent().getId(), null);
+ newConfig = info.getManagedProject().createConfigurationClone(parentConfig, newId);
+ }
+
+ newConfig.setName(newName);
+ newConfig.setDescription(newDescription);
+ newConfig.setArtifactName(info.getManagedProject().getDefaultArtifactName());
+ return newConfig;
+ }
+
+}