/// <summary> /// Removes a Choose block from the list. This method does nothing to manipulate /// the project's XML content. /// </summary> /// <remarks> /// </remarks> /// <owner>DavidLe</owner> /// <param name="choose"></param> internal void RemoveChoose ( Choose choose ) { error.VerifyThrow(this.combinedGroupList != null, "Arraylist not initialized!"); this.combinedGroupList.Remove(choose); this.chooseCount--; error.VerifyThrow(this.chooseCount >= 0, "Too many calls to RemoveChoose()."); }
private void SetupMembers() { pg1 = new BuildPropertyGroup(); pg1.SetProperty("foo", "bar"); pg1.SetProperty("abc", "true"); pg1.SetProperty("Unit", "inches"); pg2 = new BuildPropertyGroup(); pg2.SetProperty("foo", "bar"); pg2.SetProperty("abc", "true"); pg3 = new BuildPropertyGroup(); // These Choose objects are only suitable for // holding a place in the GroupingCollection. choose1 = new Choose(); choose2 = new Choose(); choose3 = new Choose(); ig1 = new BuildItemGroup(); ig1.AddNewItem("x", "x1"); ig1.AddNewItem("x", "x2"); ig1.AddNewItem("y", "y1"); ig1.AddNewItem("y", "y2"); ig1.AddNewItem("y", "y3"); ig1.AddNewItem("y", "y4"); ig2 = new BuildItemGroup(); ig2.AddNewItem("jacksonfive", "germaine"); ig2.AddNewItem("jacksonfive", "tito"); ig2.AddNewItem("jacksonfive", "michael"); ig2.AddNewItem("jacksonfive", "latoya"); ig2.AddNewItem("jacksonfive", "janet"); ig3 = new BuildItemGroup(); }
/// <summary> /// Helper method for processing the children of a When. Only parses Choose, /// PropertyGroup, and ItemGroup. All other tags result in an error. /// </summary> /// <remarks> /// </remarks> /// <owner>DavidLe</owner> /// <param name="parentNode"></param> /// <param name="parentProjectForChildren"></param> /// <param name="importedFromAnotherProject"></param> /// <param name="options"></param> /// <param name="nestingDepth">Number of parent <Choose> elements this is nested inside</param> private void ProcessWhenChildren ( XmlElement parentNode, Project parentProjectForChildren, bool importedFromAnotherProject, int nestingDepth ) { // Loop through the child nodes of the <When> element. foreach (XmlNode whenChildNode in parentNode) { switch (whenChildNode.NodeType) { // Handle XML comments under the <When> node (just ignore them). case XmlNodeType.Comment: // fall through case XmlNodeType.Whitespace: // ignore whitespace break; case XmlNodeType.Element: { // Make sure this element doesn't have a custom namespace ProjectXmlUtilities.VerifyThrowProjectValidNamespace((XmlElement)whenChildNode); // The only three types of child nodes that a <When> element can contain // are <PropertyGroup>, <ItemGroup> and <Choose>. switch (whenChildNode.Name) { case XMakeElements.itemGroup: BuildItemGroup newItemGroup = new BuildItemGroup((XmlElement)whenChildNode, importedFromAnotherProject, parentProjectForChildren); this.propertyAndItemLists.InsertAtEnd(newItemGroup); break; // Process the <PropertyGroup> element. case XMakeElements.propertyGroup: BuildPropertyGroup newPropertyGroup = new BuildPropertyGroup(parentProjectForChildren, (XmlElement)whenChildNode, importedFromAnotherProject); newPropertyGroup.EnsureNoReservedProperties(); this.propertyAndItemLists.InsertAtEnd(newPropertyGroup); break; // Process the <Choose> element. case XMakeElements.choose: Choose newChoose = new Choose(parentProjectForChildren, this.PropertyAndItemLists, (XmlElement)whenChildNode, importedFromAnotherProject, nestingDepth); this.propertyAndItemLists.InsertAtEnd(newChoose); break; default: { ProjectXmlUtilities.ThrowProjectInvalidChildElement(whenChildNode); break; } } } break; default: { ProjectXmlUtilities.ThrowProjectInvalidChildElement(whenChildNode); break; } } } }
/// <summary> /// Process each of the direct children beneath the >Project< element. /// These include things like <PropertyGroup>, <ItemGroup>, <Target>, etc. /// This method is simply capturing the data in the form of our own /// internal objects. It is not actually evaluating any of the properties /// or other data. /// </summary> /// <param name="projectElement"></param> /// <param name="projectDirectoryLocation"></param> /// <param name="importedProject"></param> /// <owner>RGoel</owner> private void ProcessProjectChildren ( XmlElement projectElement, string projectDirectoryLocation, bool importedProject ) { // Make sure the <Project> node has been given to us. error.VerifyThrow(projectElement != null, "Need an XML node representing the <project> element."); // Make sure this really is the <Project> node. ProjectXmlUtilities.VerifyThrowElementName(projectElement, XMakeElements.project); // Loop through all the direct children of the <project> element. // This verifies all the XML is legitimate, and creates ordered lists of objects // representing the top-level nodes (itemgroup, choose, etc.) // As this progresses, the Chooses and PropertyGroups are evaluated, so that conditions // on Imports involving properties can be evaluated too, because we need to know whether to // follow the imports. // All this comprises "Pass 1". List<XmlElement> childElements = ProjectXmlUtilities.GetValidChildElements(projectElement); string currentPerThreadProjectDirectory = Project.PerThreadProjectDirectory; try { // Make the correct project directory available. This is needed because it is // used for evaluating "exists" in conditional expressions, for example on <Import> elements. Project.PerThreadProjectDirectory = ProjectDirectory; foreach (XmlElement childElement in childElements) { switch (childElement.Name) { // Process the <ItemDefinitionGroup> element. case XMakeElements.itemDefinitionGroup: itemDefinitionLibrary.Add(childElement); break; // Process the <ItemGroup> element. case XMakeElements.itemGroup: BuildItemGroup newItemGroup = new BuildItemGroup(childElement, importedProject, /*parent project*/ this); this.rawItemGroups.InsertAtEnd(newItemGroup); break; // Process the <PropertyGroup> element. case XMakeElements.propertyGroup: BuildPropertyGroup newPropertyGroup = new BuildPropertyGroup(this, childElement, importedProject); newPropertyGroup.EnsureNoReservedProperties(); this.rawPropertyGroups.InsertAtEnd(newPropertyGroup); // PropertyGroups/Chooses are evaluated immediately during this scan, as they're needed to figure out whether // we include Imports. newPropertyGroup.Evaluate(this.evaluatedProperties, this.conditionedPropertiesTable, ProcessingPass.Pass1); break; // Process the <Choose> element. case XMakeElements.choose: Choose newChoose = new Choose(this, this.rawGroups, childElement, importedProject, 0 /* not nested in another <Choose> */); this.rawGroups.InsertAtEnd(newChoose); // PropertyGroups/Chooses are evaluated immediately during this scan, as they're needed to figure out whether // we include Imports. newChoose.Evaluate(this.evaluatedProperties, false, true, this.conditionedPropertiesTable, ProcessingPass.Pass1); break; // Process the <Target> element. case XMakeElements.target: XmlElement targetElement = childElement; Target newTarget = new Target(targetElement, this, importedProject); // If a target with this name already exists, log a low priority message. if (!ParentEngine.LoggingServices.OnlyLogCriticalEvents) { if (targets.Exists(newTarget.Name)) { ParentEngine.LoggingServices.LogComment(projectBuildEventContext, "OverridingTarget", targets[newTarget.Name].Name, targets[newTarget.Name].ProjectFileOfTargetElement, newTarget.Name, newTarget.ProjectFileOfTargetElement); } } this.targets.AddOverrideTarget(newTarget); if (this.nameOfFirstTarget == null) { this.nameOfFirstTarget = targetElement.GetAttribute(XMakeAttributes.name); } break; // Process the <UsingTask> element. case XMakeElements.usingTask: UsingTask usingTask = new UsingTask(childElement, importedProject); this.usingTasks.Add(usingTask); break; // Process the <ProjectExtensions> element. case XMakeElements.projectExtensions: if (!importedProject) { ProjectErrorUtilities.VerifyThrowInvalidProject(null == this.projectExtensionsNode, childElement, "DuplicateProjectExtensions"); this.projectExtensionsNode = childElement; // No attributes are legal on this element ProjectXmlUtilities.VerifyThrowProjectNoAttributes(childElement); } break; // Process the <Error>, <Warning>, and <Message> elements case XMakeElements.error: case XMakeElements.warning: case XMakeElements.message: ProjectErrorUtilities.VerifyThrowInvalidProject(false, childElement, "ErrorWarningMessageNotSupported", childElement.Name); break; case XMakeElements.importGroup: foreach (XmlElement importGroupChild in childElement.ChildNodes) { switch(importGroupChild.Name) { case XMakeElements.import: ProcessImportElement(importGroupChild, projectDirectoryLocation, importedProject); break; default: ProjectXmlUtilities.ThrowProjectInvalidChildElement(importGroupChild); break; } } break; // Process the <Import> element. case XMakeElements.import: ProcessImportElement(childElement, projectDirectoryLocation, importedProject); break; default: // We've encounted an unknown child element beneath <project>. ProjectXmlUtilities.ThrowProjectInvalidChildElement(childElement); break; } } } finally { // Reset back to the original value Project.PerThreadProjectDirectory = currentPerThreadProjectDirectory; } }
/// <summary> /// Returns an enumerator into the GroupingCollection specified /// at instantiation time. /// </summary> /// <remarks> /// </remarks> /// <owner>DavidLe</owner> /// <returns>IEnumerator</returns> public IEnumerator GetEnumerator( ) { foreach (IItemPropertyGrouping group in this.groupingCollection) { if ((group is BuildItemGroup) && ((this.type == ListType.ItemGroupsTopLevel) || (this.type == ListType.ItemGroupsTopLevelAndChoose) || (this.type == ListType.ItemGroupsAll))) { yield return(group); } else if ((group is BuildPropertyGroup) && ((this.type == ListType.PropertyGroupsTopLevel) || (this.type == ListType.PropertyGroupsTopLevelAndChoose) || (this.type == ListType.PropertyGroupsAll))) { yield return(group); } else if (group is Choose) { if ((this.type == ListType.ChoosesTopLevel) || (this.type == ListType.ItemGroupsTopLevelAndChoose) || (this.type == ListType.PropertyGroupsTopLevelAndChoose)) { yield return(group); } // Recurse into Choose groups to find all item/property groups else if ((this.type == ListType.ItemGroupsAll) || (this.type == ListType.PropertyGroupsAll)) { Choose choose = (Choose)group; foreach (When when in choose.Whens) { if (this.type == ListType.ItemGroupsAll) { foreach (IItemPropertyGrouping nestedGroup in when.PropertyAndItemLists.ItemGroupsAll) { yield return(nestedGroup); } } else if (this.type == ListType.PropertyGroupsAll) { foreach (IItemPropertyGrouping nestedGroup in when.PropertyAndItemLists.PropertyGroupsAll) { yield return(nestedGroup); } } } if (choose.Otherwise != null) { if (this.type == ListType.ItemGroupsAll) { foreach (IItemPropertyGrouping nestedGroup in choose.Otherwise.PropertyAndItemLists.ItemGroupsAll) { yield return(nestedGroup); } } else if (this.type == ListType.PropertyGroupsAll) { foreach (IItemPropertyGrouping nestedGroup in choose.Otherwise.PropertyAndItemLists.PropertyGroupsAll) { yield return(nestedGroup); } } } } } } }