Ejemplo n.º 1
0
 public void InsertAfterChild (ProjectElement child, ProjectElement reference)
 {
         if (reference == null) {
                 PrependChild (child);
         } else {
                 child.Parent = this;
                 children.AddAfter (reference.LinkedListNode, child.LinkedListNode);
         }
 }
 public void AppendChild (ProjectElement child)
 {
         children.Add (child);
         child.Parent = this;
         if (Count != 1) {
                 child.PreviousSibling = children[Count - 2];
                 children[Count - 2].NextSibling = child;
         }
 }
Ejemplo n.º 3
0
 internal static PropertyStorageLocations GetLocationFromCondition(MSBuild.Construction.ProjectElement element)
 {
     while (element != null)
     {
         if (!string.IsNullOrEmpty(element.Condition))
         {
             return(GetLocationFromCondition(element.Condition));
         }
         element = element.Parent;
     }
     return(PropertyStorageLocations.Base);
 }
 public void InsertAfterChild (ProjectElement child, ProjectElement reference)
 {
         if (reference == null) {
                 PrependChild (child);
         } else {
                 child.Parent = this;
                 var referenceIndex = children.IndexOf (reference);
                 children.Insert (referenceIndex + 1, child);
                 child.PreviousSibling = reference;
                 reference.NextSibling = child;
                 
                 if (referenceIndex + 2 < Count) {
                         child.NextSibling = children[referenceIndex + 2];
                         children[referenceIndex + 2].PreviousSibling = child;
                 }
         }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Overridden to verify that the potential parent and siblings
 /// are acceptable. Throws InvalidOperationException if they are not.
 /// </summary>
 internal override void VerifyThrowInvalidOperationAcceptableLocation(ProjectElementContainer parent, ProjectElement previousSibling, ProjectElement nextSibling)
 {
     ErrorUtilities.VerifyThrowInvalidOperation(parent is ProjectChooseElement, "OM_CannotAcceptParent");
     ErrorUtilities.VerifyThrowInvalidOperation(!(nextSibling is ProjectWhenElement) && !(previousSibling is ProjectOtherwiseElement) && !(nextSibling is ProjectOtherwiseElement), "OM_NoOtherwiseBeforeWhenOrOtherwise");
 }
Ejemplo n.º 6
0
 public void RemoveChild (ProjectElement child)
 {
         child.Parent = null;
         children.Remove (child.LinkedListNode);
 }
 public void PrependChild (ProjectElement child)
 {
         children.Insert (0, child);
         child.Parent = this;
         if (Count != 1) {
                 child.NextSibling = children[1];
                 children[1].PreviousSibling = child;
         }
 }
Ejemplo n.º 8
0
 internal override void VerifyThrowInvalidOperationAcceptableLocation(ProjectElementContainer parent, ProjectElement previousSibling, ProjectElement nextSibling)
 {
     ErrorUtilities.VerifyThrowInvalidOperation(parent is ProjectRootElement, "OM_CannotAcceptParent");
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Sets the parent of this element if it is a valid parent,
        /// otherwise throws.
        /// </summary>
        internal override void VerifyThrowInvalidOperationAcceptableLocation(ProjectElementContainer parent, ProjectElement previousSibling, ProjectElement nextSibling)
        {
            ErrorUtilities.VerifyThrowInvalidOperation(parent is ProjectRootElement || parent is ProjectWhenElement || parent is ProjectOtherwiseElement, "OM_CannotAcceptParent");

            int nestingDepth = 0;
            ProjectElementContainer immediateParent = parent;

            while (parent != null)
            {
                parent = parent.Parent;

                nestingDepth++;

                // This should really be an OM error, with no error number. But it's so obscure, it's not worth a new string.
                ProjectErrorUtilities.VerifyThrowInvalidProject(nestingDepth <= ProjectParser.MaximumChooseNesting, immediateParent.Location, "ChooseOverflow", ProjectParser.MaximumChooseNesting);
            }
        }
 /// <summary>
 /// Overridden to verify that the potential parent and siblings
 /// are acceptable. Throws InvalidOperationException if they are not.
 /// </summary>
 internal override void VerifyThrowInvalidOperationAcceptableLocation(ProjectElementContainer parent, ProjectElement previousSibling, ProjectElement nextSibling)
 {
     VerifyCorrectParent(parent);
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Overridden to verify that the potential parent and siblings
 /// are acceptable. Throws InvalidOperationException if they are not.
 /// </summary>
 internal override void VerifyThrowInvalidOperationAcceptableLocation(ProjectElementContainer parent, ProjectElement previousSibling, ProjectElement nextSibling)
 {
     ErrorUtilities.VerifyThrowInvalidOperation(parent.Parent is ProjectTargetElement || (Include.Length > 0 || Update.Length > 0 || Remove.Length > 0), "OM_ItemsOutsideTargetMustHaveIncludeOrUpdateOrRemove");
     ErrorUtilities.VerifyThrowInvalidOperation(parent.Parent is ProjectRootElement || parent.Parent is ProjectTargetElement || parent.Parent is ProjectWhenElement || parent.Parent is ProjectOtherwiseElement, "OM_CannotAcceptParent");
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Overridden to verify that the potential parent and siblings
 /// are acceptable. Throws InvalidOperationException if they are not.
 /// </summary>
 internal override void VerifyThrowInvalidOperationAcceptableLocation(ProjectElementContainer parent, ProjectElement previousSibling, ProjectElement nextSibling)
 {
     ErrorUtilities.VerifyThrowInvalidOperation(parent is ProjectRootElement || parent is ProjectImportGroupElement, "OM_CannotAcceptParent");
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Sets the parent of this element if it is a valid parent,
        /// otherwise throws.
        /// </summary>
        internal override void VerifyThrowInvalidOperationAcceptableLocation(ProjectElementContainer parent, ProjectElement previousSibling, ProjectElement nextSibling)
        {
            ErrorUtilities.VerifyThrowInvalidOperation(parent is ProjectRootElement || parent is ProjectWhenElement || parent is ProjectOtherwiseElement, "OM_CannotAcceptParent");

            int nestingDepth = 0;
            ProjectElementContainer immediateParent = parent;

            while (parent != null)
            {
                parent = parent.Parent;

                nestingDepth++;

                // This should really be an OM error, with no error number. But it's so obscure, it's not worth a new string.
                ProjectErrorUtilities.VerifyThrowInvalidProject(nestingDepth <= ProjectParser.MaximumChooseNesting, immediateParent.Location, "ChooseOverflow", ProjectParser.MaximumChooseNesting);
            }
        }
Ejemplo n.º 14
0
 public void RemoveChild(ProjectElement child)
 {
 }
Ejemplo n.º 15
0
 private static string CheckNextSibling(ProjectElement nextSibling, int iMaxSiblings)
 {
     if (iMaxSiblings > 0)
     {
         Microsoft.Build.Construction.ProjectPropertyElement ppe_sibling = (Microsoft.Build.Construction.ProjectPropertyElement)nextSibling;
         if (ppe_sibling.Name.ToLower().Equals("outputpath"))
         {
             return ppe_sibling.Value;
         }
         else
         {
             if (ppe_sibling.NextSibling!=null)
             {
                 return CheckNextSibling(ppe_sibling.NextSibling, iMaxSiblings - 1);
             }
             else
             {
                 return null;
             }
         }
     }
     else
     {
         return null;
     }
 }
Ejemplo n.º 16
0
        /// <summary>
        /// Adds a ProjectElement to the Xml tree
        /// </summary>
        /// <param name="child">A child to add to the Xml tree, which has already been added to the ProjectElement tree</param>
        /// <remarks>
        /// The MSBuild construction APIs keep a tree of ProjectElements and a parallel Xml tree which consists of
        /// objects from System.Xml.  This is a helper method which adds an XmlElement or Xml attribute to the Xml
        /// tree after the corresponding ProjectElement has been added to the construction API tree, and fixes up
        /// whitespace as necessary.
        /// </remarks>
        internal void AddToXml(ProjectElement child)
        {
            if (child.ExpressedAsAttribute)
            {
                // todo children represented as attributes need to be placed in order too
                //  Assume that the name of the child has already been validated to conform with rules in XmlUtilities.VerifyThrowArgumentValidElementName

                //  Make sure we're not trying to add multiple attributes with the same name
                ProjectErrorUtilities.VerifyThrowInvalidProject(!XmlElement.HasAttribute(child.XmlElement.Name),
                                                                XmlElement.Location, "InvalidChildElementDueToDuplication", child.XmlElement.Name, ElementName);

                SetElementAsAttributeValue(child);
            }
            else
            {
                //  We want to add the XmlElement to the same position in the child list as the corresponding ProjectElement.
                //  Depending on whether the child ProjectElement has a PreviousSibling or a NextSibling, we may need to
                //  use the InsertAfter, InsertBefore, or AppendChild methods to add it in the right place.
                //
                //  Also, if PreserveWhitespace is true, then the elements we add won't automatically get indented, so
                //  we try to match the surrounding formatting.

                // Siblings, in either direction in the linked list, may be represented either as attributes or as elements.
                // Therefore, we need to traverse both directions to find the first sibling of the same type as the one being added.
                // If none is found, then the node being added is inserted as the only node of its kind

                ProjectElement             referenceSibling;
                Predicate <ProjectElement> siblingIsSameAsChild = _ => _.ExpressedAsAttribute == false;

                if (TrySearchLeftSiblings(child.PreviousSibling, siblingIsSameAsChild, out referenceSibling))
                {
                    //  Add after previous sibling
                    XmlElement.InsertAfter(child.XmlElement, referenceSibling.XmlElement);
                    if (XmlDocument.PreserveWhitespace)
                    {
                        //  Try to match the surrounding formatting by checking the whitespace that precedes the node we inserted
                        //  after, and inserting the same whitespace between the previous node and the one we added
                        if (referenceSibling.XmlElement.PreviousSibling != null &&
                            referenceSibling.XmlElement.PreviousSibling.NodeType == XmlNodeType.Whitespace)
                        {
                            var newWhitespaceNode = XmlDocument.CreateWhitespace(referenceSibling.XmlElement.PreviousSibling.Value);
                            XmlElement.InsertAfter(newWhitespaceNode, referenceSibling.XmlElement);
                        }
                    }
                }
                else if (TrySearchRightSiblings(child.NextSibling, siblingIsSameAsChild, out referenceSibling))
                {
                    //  Add as first child
                    XmlElement.InsertBefore(child.XmlElement, referenceSibling.XmlElement);

                    if (XmlDocument.PreserveWhitespace)
                    {
                        //  Try to match the surrounding formatting by checking the whitespace that precedes where we inserted
                        //  the new node, and inserting the same whitespace between the node we added and the one after it.
                        if (child.XmlElement.PreviousSibling != null &&
                            child.XmlElement.PreviousSibling.NodeType == XmlNodeType.Whitespace)
                        {
                            var newWhitespaceNode = XmlDocument.CreateWhitespace(child.XmlElement.PreviousSibling.Value);
                            XmlElement.InsertBefore(newWhitespaceNode, referenceSibling.XmlElement);
                        }
                    }
                }
                else
                {
                    //  Add as only child
                    XmlElement.AppendChild(child.XmlElement);

                    if (XmlDocument.PreserveWhitespace)
                    {
                        //  Try to match the surrounding formatting and add one indentation level
                        if (XmlElement.FirstChild.NodeType == XmlNodeType.Whitespace)
                        {
                            //  This container had a whitespace node, which should generally be a newline and the indent
                            //  before the closing tag.  So we add the default indentation to it so the child will now be indented
                            //  further, and then create a new whitespace node after the child so the closing tag will be on
                            //  a new line with the same indentation.
                            //  If the whitespace we end up copying isn't actually (newline + indentation) like we expect, then it
                            //  should still be OK to copy it, as we'll still be trying to match the surrounding formatting.
                            string whitespace = XmlElement.FirstChild.Value;
                            XmlElement.FirstChild.Value = whitespace + DEFAULT_INDENT;
                            var newWhitespaceNode = XmlDocument.CreateWhitespace(whitespace);
                            XmlElement.InsertAfter(newWhitespaceNode, child.XmlElement);
                        }
                        else if (XmlElement.PreviousSibling != null &&
                                 XmlElement.PreviousSibling.NodeType == XmlNodeType.Whitespace)
                        {
                            //  This container didn't have any whitespace in it.  This probably means it didn't have separate open
                            //  and close tags.  So add a whitespace node before the new child with additional indentation over the
                            //  container's indentation, and add a whitespace node with the same level of indentation as the container
                            //  after the new child so the closing tag will be indented properly.
                            string parentWhitespace       = XmlElement.PreviousSibling.Value;
                            var    indentedWhitespaceNode = XmlDocument.CreateWhitespace(parentWhitespace + DEFAULT_INDENT);
                            XmlElement.InsertBefore(indentedWhitespaceNode, child.XmlElement);
                            var unindentedWhitespaceNode = XmlDocument.CreateWhitespace(parentWhitespace);
                            XmlElement.InsertAfter(unindentedWhitespaceNode, child.XmlElement);
                        }
                    }
                }
            }
        }
Ejemplo n.º 17
0
 public void InsertBeforeChild (ProjectElement child, ProjectElement reference)
 {
         if (reference == null) {
                 AppendChild (child);
         } else {
                 child.Parent = this;
                 children.AddBefore (reference.LinkedListNode, child.LinkedListNode);
         }
 }
Ejemplo n.º 18
0
 public void AppendChild (ProjectElement child)
 {
         children.AddLast (child.LinkedListNode);
         child.Parent = this;
 }
Ejemplo n.º 19
0
 /// <summary>
 /// Overridden to verify that the potential parent and siblings
 /// are acceptable. Throws InvalidOperationException if they are not.
 /// </summary>
 internal abstract void VerifyThrowInvalidOperationAcceptableLocation(ProjectElementContainer proposedParent, ProjectElement previousSibling, ProjectElement nextSibling);
Ejemplo n.º 20
0
        /// <summary>
        /// Adds a ProjectElement to the Xml tree
        /// </summary>
        /// <param name="child">A child to add to the Xml tree, which has already been added to the ProjectElement tree</param>
        /// <remarks>
        /// The MSBuild construction APIs keep a tree of ProjectElements and a parallel Xml tree which consists of
        /// objects from System.Xml.  This is a helper method which adds an XmlElement or Xml attribute to the Xml
        /// tree after the corresponding ProjectElement has been added to the construction API tree, and fixes up
        /// whitespace as necessary.
        /// </remarks>
        internal void AddToXml(ProjectElement child)
        {
            if (child.ExpressedAsAttribute)
            {
                // todo children represented as attributes need to be placed in order too
                //  Assume that the name of the child has already been validated to conform with rules in XmlUtilities.VerifyThrowArgumentValidElementName

                //  Make sure we're not trying to add multiple attributes with the same name
                ProjectErrorUtilities.VerifyThrowInvalidProject(!XmlElement.HasAttribute(child.XmlElement.Name),
                                                                XmlElement.Location, "InvalidChildElementDueToDuplication", child.XmlElement.Name, ElementName);

                SetElementAsAttributeValue(child);
            }
            else
            {
                //  We want to add the XmlElement to the same position in the child list as the corresponding ProjectElement.
                //  Depending on whether the child ProjectElement has a PreviousSibling or a NextSibling, we may need to
                //  use the InsertAfter, InsertBefore, or AppendChild methods to add it in the right place.
                //
                //  Also, if PreserveWhitespace is true, then the elements we add won't automatically get indented, so
                //  we try to match the surrounding formatting.

                // Siblings, in either direction in the linked list, may be represented either as attributes or as elements.
                // Therefore, we need to traverse both directions to find the first sibling of the same type as the one being added.
                // If none is found, then the node being added is inserted as the only node of its kind

                ProjectElement             referenceSibling;
                Predicate <ProjectElement> siblingIsExplicitElement = _ => _.ExpressedAsAttribute == false;

                if (TrySearchLeftSiblings(child.PreviousSibling, siblingIsExplicitElement, out referenceSibling))
                {
                    //  Add after previous sibling
                    XmlElement.InsertAfter(child.XmlElement, referenceSibling.XmlElement);
                    if (XmlDocument.PreserveWhitespace)
                    {
                        //  Try to match the surrounding formatting by checking the whitespace that precedes the node we inserted
                        //  after, and inserting the same whitespace between the previous node and the one we added
                        if (referenceSibling.XmlElement.PreviousSibling != null &&
                            referenceSibling.XmlElement.PreviousSibling.NodeType == XmlNodeType.Whitespace)
                        {
                            var newWhitespaceNode = XmlDocument.CreateWhitespace(referenceSibling.XmlElement.PreviousSibling.Value);
                            XmlElement.InsertAfter(newWhitespaceNode, referenceSibling.XmlElement);
                        }
                    }
                }
                else if (TrySearchRightSiblings(child.NextSibling, siblingIsExplicitElement, out referenceSibling))
                {
                    //  Add as first child
                    XmlElement.InsertBefore(child.XmlElement, referenceSibling.XmlElement);

                    if (XmlDocument.PreserveWhitespace)
                    {
                        //  Try to match the surrounding formatting by checking the whitespace that precedes where we inserted
                        //  the new node, and inserting the same whitespace between the node we added and the one after it.
                        if (child.XmlElement.PreviousSibling != null &&
                            child.XmlElement.PreviousSibling.NodeType == XmlNodeType.Whitespace)
                        {
                            var newWhitespaceNode = XmlDocument.CreateWhitespace(child.XmlElement.PreviousSibling.Value);
                            XmlElement.InsertBefore(newWhitespaceNode, referenceSibling.XmlElement);
                        }
                    }
                }
                else
                {
                    //  Add as only child
                    XmlElement.AppendChild(child.XmlElement);

                    if (XmlDocument.PreserveWhitespace)
                    {
                        //  If the empty parent has whitespace in it, delete it
                        if (XmlElement.FirstChild.NodeType == XmlNodeType.Whitespace)
                        {
                            XmlElement.RemoveChild(XmlElement.FirstChild);
                        }

                        var parentIndentation = GetElementIndentation(XmlElement);

                        var leadingWhitespaceNode  = XmlDocument.CreateWhitespace(Environment.NewLine + parentIndentation + DEFAULT_INDENT);
                        var trailingWhiteSpaceNode = XmlDocument.CreateWhitespace(Environment.NewLine + parentIndentation);

                        XmlElement.InsertBefore(leadingWhitespaceNode, child.XmlElement);
                        XmlElement.InsertAfter(trailingWhiteSpaceNode, child.XmlElement);
                    }
                }
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Parse a ProjectTargetElement
        /// </summary>
        private ProjectTargetElement ParseProjectTargetElement(XmlElementWithLocation element)
        {
            ProjectXmlUtilities.VerifyThrowProjectAttributes(element, s_validAttributesOnTarget);
            ProjectXmlUtilities.VerifyThrowProjectRequiredAttribute(element, XMakeAttributes.name);

            string targetName = ProjectXmlUtilities.GetAttributeValue(element, XMakeAttributes.name);

            // Orcas compat: all target names are automatically unescaped
            targetName = EscapingUtilities.UnescapeAll(targetName);

            int indexOfSpecialCharacter = targetName.IndexOfAny(XMakeElements.illegalTargetNameCharacters);

            if (indexOfSpecialCharacter >= 0)
            {
                ProjectErrorUtilities.ThrowInvalidProject(element.GetAttributeLocation(XMakeAttributes.name), "NameInvalid", targetName, targetName[indexOfSpecialCharacter]);
            }

            ProjectTargetElement  target  = new ProjectTargetElement(element, _project, _project);
            ProjectOnErrorElement onError = null;

            foreach (XmlElementWithLocation childElement in ProjectXmlUtilities.GetVerifyThrowProjectChildElements(element))
            {
                ProjectElement child = null;

                switch (childElement.Name)
                {
                case XMakeElements.propertyGroup:
                    if (onError != null)
                    {
                        ProjectErrorUtilities.ThrowInvalidProject(onError.Location, "NodeMustBeLastUnderElement", XMakeElements.onError, XMakeElements.target, childElement.Name);
                    }

                    child = ParseProjectPropertyGroupElement(childElement, target);
                    break;

                case XMakeElements.itemGroup:
                    if (onError != null)
                    {
                        ProjectErrorUtilities.ThrowInvalidProject(onError.Location, "NodeMustBeLastUnderElement", XMakeElements.onError, XMakeElements.target, childElement.Name);
                    }

                    child = ParseProjectItemGroupElement(childElement, target);
                    break;

                case XMakeElements.onError:
                    onError = ParseProjectOnErrorElement(childElement, target);
                    child   = onError;
                    break;

                case XMakeElements.itemDefinitionGroup:
                    ProjectErrorUtilities.ThrowInvalidProject(childElement.Location, "ItemDefinitionGroupNotLegalInsideTarget", childElement.Name);
                    break;

                default:
                    if (onError != null)
                    {
                        ProjectErrorUtilities.ThrowInvalidProject(onError.Location, "NodeMustBeLastUnderElement", XMakeElements.onError, XMakeElements.target, childElement.Name);
                    }

                    child = ParseProjectTaskElement(childElement, target);
                    break;
                }

                target.AppendParentedChildNoChecks(child);
            }

            return(target);
        }
Ejemplo n.º 22
0
 private static bool TrySearchRightSiblings(ProjectElement initialElement, Predicate <ProjectElement> siblingIsAcceptable, out ProjectElement referenceSibling)
 {
     return(TrySearchSiblings(initialElement, siblingIsAcceptable, s => s.NextSibling, out referenceSibling));
 }
Ejemplo n.º 23
0
 /// <summary>
 /// Overridden to verify that the potential parent and siblings
 /// are acceptable. Throws InvalidOperationException if they are not.
 /// </summary>
 internal override void VerifyThrowInvalidOperationAcceptableLocation(ProjectElementContainer parent, ProjectElement previousSibling, ProjectElement nextSibling)
 {
     ErrorUtilities.VerifyThrowInvalidOperation(parent is ProjectChooseElement, "OM_CannotAcceptParent");
     ErrorUtilities.VerifyThrowInvalidOperation(!(previousSibling is ProjectOtherwiseElement), "OM_NoOtherwiseBeforeWhenOrOtherwise");
 }
Ejemplo n.º 24
0
 public void RemoveChild(ProjectElement child)
 {
     child.Parent = null;
     children.Remove(child.LinkedListNode);
 }
 /// <summary>
 /// Overridden to verify that the potential parent and siblings
 /// are acceptable. Throws InvalidOperationException if they are not.
 /// </summary>
 internal override void VerifyThrowInvalidOperationAcceptableLocation(ProjectElementContainer parent, ProjectElement previousSibling, ProjectElement nextSibling)
 {
     VerifyCorrectParent(parent);
 }
Ejemplo n.º 26
0
 public void AppendChild(ProjectElement child)
 {
     children.AddLast(child.LinkedListNode);
     child.Parent = this;
 }
Ejemplo n.º 27
0
 public void RemoveChild (ProjectElement child)
 {
         child.Parent = null;
         children.Remove(child);
         if (child.NextSibling != null)
                 child.NextSibling.PreviousSibling = child.PreviousSibling;
         if (child.PreviousSibling != null)
                 child.PreviousSibling.NextSibling = child.NextSibling;
 }
Ejemplo n.º 28
0
 /// <summary>
 /// Overridden to verify that the potential parent and siblings
 /// are acceptable. Throws InvalidOperationException if they are not.
 /// </summary>
 internal abstract void VerifyThrowInvalidOperationAcceptableLocation(ProjectElementContainer proposedParent, ProjectElement previousSibling, ProjectElement nextSibling);
Ejemplo n.º 29
0
        /// <inheritdoc />
        public override void CopyFrom(ProjectElement element)
        {
            base.CopyFrom(element);

            // clear out caching fields.
            _definitelyAreNoChildrenWithWildcards = false;
        }
Ejemplo n.º 30
0
 /// <summary>
 /// Dummy required implementation
 /// </summary>
 internal override void VerifyThrowInvalidOperationAcceptableLocation(ProjectElementContainer parent, ProjectElement previousSibling, ProjectElement nextSibling)
 {
     ErrorUtilities.ThrowInternalErrorUnreachable();
 }
 public void InsertBeforeChild (ProjectElement child, ProjectElement reference)
 {
         if (reference == null) {
                 AppendChild (child);
         } else {
                 child.Parent = this;
                 var referenceIndex = children.IndexOf (reference);
                 children.Insert (referenceIndex, child);
                 child.NextSibling = reference;
                 reference.PreviousSibling = child;
                 
                 if (referenceIndex > 0) {
                         child.PreviousSibling = children[referenceIndex - 1];
                         children[referenceIndex - 1].NextSibling = child;
                 }
         }
 }
Ejemplo n.º 32
0
        /// <inheritdoc />
        public override void CopyFrom(ProjectElement element)
        {
            base.CopyFrom(element);

            // clear cached fields
            _include = null;
            _exclude = null;
            _remove = null;
            _includeHasWildcards = null;
        }
 public void RemoveChild (ProjectElement child)
 {
 }
Ejemplo n.º 34
0
 /// <summary>
 /// Overridden to verify that the potential parent and siblings
 /// are acceptable. Throws InvalidOperationException if they are not.
 /// </summary>
 internal override void VerifyThrowInvalidOperationAcceptableLocation(ProjectElementContainer parent, ProjectElement previousSibling, ProjectElement nextSibling)
 {
     ErrorUtilities.VerifyThrowInvalidOperation(parent.Parent is ProjectTargetElement || (Include.Length > 0 || Update.Length > 0 || Remove.Length > 0), "OM_ItemsOutsideTargetMustHaveIncludeOrUpdateOrRemove");
     ErrorUtilities.VerifyThrowInvalidOperation(parent.Parent is ProjectRootElement || parent.Parent is ProjectTargetElement || parent.Parent is ProjectWhenElement || parent.Parent is ProjectOtherwiseElement, "OM_CannotAcceptParent");
 }
Ejemplo n.º 35
0
        /// <inheritdoc/>
        public override void CopyFrom(ProjectElement element)
        {
            ErrorUtilities.VerifyThrowArgumentNull(element, "element");
            ErrorUtilities.VerifyThrowArgument(this.GetType().IsEquivalentTo(element.GetType()), "element");

            if (this == element)
            {
                return;
            }

            this.Label = element.Label;

            var other = (ProjectExtensionsElement)element;
            this.Content = other.Content;

            this.MarkDirty("CopyFrom", null);
        }
Ejemplo n.º 36
0
        /// <summary>
        /// Parse the child of a ProjectRootElement
        /// </summary>
        private void ParseProjectRootElementChildren(XmlElementWithLocation element)
        {
            foreach (XmlElementWithLocation childElement in ProjectXmlUtilities.GetVerifyThrowProjectChildElements(element))
            {
                ProjectElement child = null;

                switch (childElement.Name)
                {
                case XMakeElements.propertyGroup:
                    child = ParseProjectPropertyGroupElement(childElement, _project);
                    break;

                case XMakeElements.itemGroup:
                    child = ParseProjectItemGroupElement(childElement, _project);
                    break;

                case XMakeElements.importGroup:
                    child = ParseProjectImportGroupElement(childElement, _project);
                    break;

                case XMakeElements.import:
                    child = ParseProjectImportElement(childElement, _project);
                    break;

                case XMakeElements.usingTask:
                    child = ParseProjectUsingTaskElement(childElement);
                    break;

                case XMakeElements.target:
                    child = ParseProjectTargetElement(childElement);
                    break;

                case XMakeElements.itemDefinitionGroup:
                    child = ParseProjectItemDefinitionGroupElement(childElement);
                    break;

                case XMakeElements.choose:
                    child = ParseProjectChooseElement(childElement, _project, 0 /* nesting depth */);
                    break;

                case XMakeElements.projectExtensions:
                    child = ParseProjectExtensionsElement(childElement);
                    break;

                case XMakeElements.sdk:
                    child = ParseProjectSdkElement(childElement);
                    break;

                // Obsolete
                case XMakeElements.error:
                case XMakeElements.warning:
                case XMakeElements.message:
                    ProjectErrorUtilities.ThrowInvalidProject(childElement.Location, "ErrorWarningMessageNotSupported", childElement.Name);
                    break;

                default:
                    ProjectXmlUtilities.ThrowProjectInvalidChildElement(childElement.Name, childElement.ParentNode.Name, childElement.Location);
                    break;
                }

                _project.AppendParentedChildNoChecks(child);
            }
        }
Ejemplo n.º 37
0
        /// <summary>
        /// Applies properties from the specified type to this instance.
        /// </summary>
        /// <param name="element">The element to act as a template to copy from.</param>
        public virtual void CopyFrom(ProjectElement element)
        {
            ErrorUtilities.VerifyThrowArgumentNull(element, "element");
            ErrorUtilities.VerifyThrowArgument(this.GetType().IsEquivalentTo(element.GetType()), "element");

            if (this == element)
            {
                return;
            }

            // Remove all the current attributes and textual content.
            this.XmlElement.RemoveAllAttributes();
            if (this.XmlElement.ChildNodes.Count == 1 && this.XmlElement.FirstChild.NodeType == XmlNodeType.Text)
            {
                this.XmlElement.RemoveChild(this.XmlElement.FirstChild);
            }

            // Ensure the element name itself matches.
            this.ReplaceElement(XmlUtilities.RenameXmlElement(this.XmlElement, element.XmlElement.Name, XmlElement.NamespaceURI));

            // Copy over the attributes from the template element.
            foreach (XmlAttribute attribute in element.XmlElement.Attributes)
            {
                this.XmlElement.SetAttribute(attribute.LocalName, attribute.NamespaceURI, attribute.Value);
            }

            // If this element has pure text content, copy that over.
            if (element.XmlElement.ChildNodes.Count == 1 && element.XmlElement.FirstChild.NodeType == XmlNodeType.Text)
            {
                this.XmlElement.AppendChild(this.XmlElement.OwnerDocument.CreateTextNode(element.XmlElement.FirstChild.Value));
            }

            this._expressedAsAttribute = element._expressedAsAttribute;

            this.MarkDirty("CopyFrom", null);
        }
Ejemplo n.º 38
0
        /// <summary>
        /// Parse a ProjectUsingTaskElement
        /// </summary>
        private ProjectUsingTaskElement ParseProjectUsingTaskElement(XmlElementWithLocation element)
        {
            ProjectXmlUtilities.VerifyThrowProjectAttributes(element, s_validAttributesOnUsingTask);
            ProjectErrorUtilities.VerifyThrowInvalidProject(element.GetAttribute(XMakeAttributes.taskName).Length > 0, element.Location, "ProjectTaskNameEmpty");

            string assemblyName = element.GetAttribute(XMakeAttributes.assemblyName);
            string assemblyFile = element.GetAttribute(XMakeAttributes.assemblyFile);

            ProjectErrorUtilities.VerifyThrowInvalidProject
            (
                ((assemblyName.Length > 0) ^ (assemblyFile.Length > 0)),
                element.Location,
                "UsingTaskAssemblySpecification",
                XMakeElements.usingTask,
                XMakeAttributes.assemblyName,
                XMakeAttributes.assemblyFile
            );

            ProjectXmlUtilities.VerifyThrowProjectAttributeEitherMissingOrNotEmpty(element, XMakeAttributes.assemblyName);
            ProjectXmlUtilities.VerifyThrowProjectAttributeEitherMissingOrNotEmpty(element, XMakeAttributes.assemblyFile);

            ProjectUsingTaskElement usingTask = new ProjectUsingTaskElement(element, _project, _project);

            bool foundTaskElement    = false;
            bool foundParameterGroup = false;

            foreach (XmlElementWithLocation childElement in ProjectXmlUtilities.GetVerifyThrowProjectChildElements(element))
            {
                ProjectElement child            = null;
                string         childElementName = childElement.Name;
                switch (childElementName)
                {
                case XMakeElements.usingTaskParameterGroup:
                    if (foundParameterGroup)
                    {
                        ProjectXmlUtilities.ThrowProjectInvalidChildElementDueToDuplicate(childElement);
                    }

                    child = ParseUsingTaskParameterGroupElement(childElement, usingTask);
                    foundParameterGroup = true;
                    break;

                case XMakeElements.usingTaskBody:
                    if (foundTaskElement)
                    {
                        ProjectXmlUtilities.ThrowProjectInvalidChildElementDueToDuplicate(childElement);
                    }

                    child            = ParseUsingTaskBodyElement(childElement, usingTask);
                    foundTaskElement = true;
                    break;

                default:
                    ProjectXmlUtilities.ThrowProjectInvalidChildElement(childElement.Name, element.Name, element.Location);
                    break;
                }

                usingTask.AppendParentedChildNoChecks(child);
            }

            return(usingTask);
        }
Ejemplo n.º 39
0
 /// <summary>
 /// Dummy required implementation
 /// </summary>
 internal override void VerifyThrowInvalidOperationAcceptableLocation(ProjectElementContainer parent, ProjectElement previousSibling, ProjectElement nextSibling)
 {
     ErrorUtilities.ThrowInternalErrorUnreachable();
 }
Ejemplo n.º 40
0
        /// <inheritdoc />
        public override void CopyFrom(ProjectElement element)
        {
            base.CopyFrom(element);

            // Clear caching fields
            _name = null;
        }