/// <summary> /// Processes the "include" list and the "exclude" list for an item element, and returns /// the resultant virtual group of items. Ignores any condition on the item. /// </summary> /// <param name="baseDirectory">Where relative paths should be evaluated from</param> /// <param name="originalItem">The "mother" item that's being expanded</param> /// <param name="expander">Expander to evaluated items and properties</param> /// <param name="expandMetadata">Whether metadata expressions should be expanded, or left as literals</param> internal static BuildItemGroup ExpandItemIntoItems ( string baseDirectory, BuildItem originalItem, Expander expander, bool expandMetadata ) { ErrorUtilities.VerifyThrow(originalItem != null, "Can't add a null item to project."); ErrorUtilities.VerifyThrow(expander != null, "expander can't be null."); // Take the entire string specified in the "Include" attribute, and split // it up by semi-colons. Then loop over the individual pieces. // Expand only with properties first, so that expressions like Include="@(foo)" will transfer the metadata of the "foo" items as well, not just their item specs. List <string> itemIncludePieces = (new Expander(expander, ExpanderOptions.ExpandProperties).ExpandAllIntoStringListLeaveEscaped(originalItem.Include, originalItem.IncludeAttribute)); BuildItemGroup itemsToInclude = new BuildItemGroup(); for (int i = 0; i < itemIncludePieces.Count; i++) { BuildItemGroup itemizedGroup = expander.ExpandSingleItemListExpressionIntoItemsLeaveEscaped(itemIncludePieces[i], originalItem.IncludeAttribute); if (itemizedGroup == null) { // The expression did not represent a single @(...) item list reference. if (expandMetadata) { // We're inside a target: metadata expressions like %(foo) are legal, so expand them now itemIncludePieces[i] = expander.ExpandMetadataLeaveEscaped(itemIncludePieces[i]); } // Now it's a string constant, possibly with wildcards. // Take each individual path or file expression, and expand any // wildcards. Then loop through each file returned. if (itemIncludePieces[i].Length > 0) { string[] includeFileList = EngineFileUtilities.GetFileListEscaped(baseDirectory, itemIncludePieces[i]); for (int j = 0; j < includeFileList.Length; j++) { BuildItem newItem = itemsToInclude.AddNewItem(originalItem.Name, originalItem.Include); newItem.SetEvaluatedItemSpecEscaped(itemIncludePieces[i]); // comes from XML include --- "arbitrarily escaped" newItem.SetFinalItemSpecEscaped(includeFileList[j]); // comes from file system matcher -- "canonically escaped" } } } else { itemsToInclude.ImportItems(itemizedGroup); } } List <BuildItem> matchingItems = FindItemsMatchingSpecification(itemsToInclude, originalItem.Exclude, originalItem.ExcludeAttribute, expander, baseDirectory); if (matchingItems != null) { foreach (BuildItem item in matchingItems) { itemsToInclude.RemoveItem(item); } } return(itemsToInclude); }
/// <summary> /// Attempts to extract the items in the given item vector expression. Item vectors embedded in strings, /// and item vectors with separator specifications are considered invalid, because it is not clear /// if those item vectors are meant to be lists or strings -- if the latter, the ExpandEmbeddedItemVectors() /// method should be used instead. /// </summary> /// <param name="itemVectorExpression"></param> /// <param name="parentNode"></param> /// <param name="readOnlyLookup"></param> /// <param name="itemVectorMatch"></param> /// <returns>a virtual BuildItemGroup containing the items resulting from the expression, or null if the expression was invalid.</returns> /// <owner>SumedhK;RGoel</owner> internal static BuildItemGroup ItemizeItemVector ( string itemVectorExpression, XmlNode parentNode, ReadOnlyLookup readOnlyLookup, out Match itemVectorMatch ) { itemVectorMatch = null; BuildItemGroup items = null; itemVectorMatch = GetItemVectorMatches(itemVectorExpression); if (itemVectorMatch != null && itemVectorMatch.Success) { // The method above reports a match if there are any // valid @(itemlist) references in the given expression. // If the passed-in expression contains exactly one item list reference, // with nothing else concatenated to the beginning or end, then proceed // with itemizing it, otherwise error. ProjectErrorUtilities.VerifyThrowInvalidProject(itemVectorMatch.Value == itemVectorExpression, parentNode, "EmbeddedItemVectorCannotBeItemized", itemVectorExpression); ItemExpander itemExpander = new ItemExpander(parentNode, readOnlyLookup); // If the reference contains a separator, we need to flatten the list into a scalar and then create // an item group with a single item. This is necessary for VSWhidbey 525917 - basically we need this // to be able to convert item lists with user specified separators into properties. if (itemVectorMatch.Groups["SEPARATOR_SPECIFICATION"].Length > 0) { string expandedItemVector = itemExpander.ExpandItemVector(itemVectorMatch); string itemType = itemVectorMatch.Groups["TYPE"].Value; items = new BuildItemGroup(); if (expandedItemVector.Length > 0) { items.AddNewItem(itemType, expandedItemVector); } } else { items = itemExpander.ItemizeItemVector(itemVectorMatch); } ErrorUtilities.VerifyThrow(items != null, "ItemizeItemVector shouldn't give us null."); } return(items); }