/// <summary> /// Extract the value for "RecursiveDir", if any, from the Include. /// If there is none, returns an empty string. /// </summary> /// <remarks> /// Inputs to and outputs of this function are all escaped. /// </remarks> private static string GetRecursiveDirValue(string evaluatedIncludeBeforeWildcardExpansionEscaped, string evaluatedIncludeEscaped) { // If there were no wildcards, the two strings will be the same, and there is no recursivedir part. if (String.Equals(evaluatedIncludeBeforeWildcardExpansionEscaped, evaluatedIncludeEscaped, StringComparison.OrdinalIgnoreCase)) { return(String.Empty); } // we're going to the file system, so unescape the include value here: string evaluatedIncludeBeforeWildcardExpansion = EscapingUtilities.UnescapeAll(evaluatedIncludeBeforeWildcardExpansionEscaped); string evaluatedInclude = EscapingUtilities.UnescapeAll(evaluatedIncludeEscaped); FileMatcher.Result match = FileMatcher.FileMatch(evaluatedIncludeBeforeWildcardExpansion, evaluatedInclude); if (match.isLegalFileSpec && match.isMatch) { return(EscapingUtilities.Escape(match.wildcardDirectoryPart)); } return(String.Empty); }
/// <summary> /// Expand wildcards in the item list. /// </summary> /// <param name="expand"></param> /// <returns></returns> private static ITaskItem[] ExpandWildcards(ITaskItem[] expand) { if (expand == null) { return(null); } else { ArrayList expanded = new ArrayList(); foreach (ITaskItem i in expand) { if (FileMatcher.HasWildcards(i.ItemSpec)) { string[] files = FileMatcher.GetFiles(null /* use current directory */, i.ItemSpec); foreach (string file in files) { TaskItem newItem = new TaskItem((ITaskItem)i); newItem.ItemSpec = file; // Compute the RecursiveDir portion. FileMatcher.Result match = FileMatcher.FileMatch(i.ItemSpec, file); if (match.isLegalFileSpec && match.isMatch) { if (match.wildcardDirectoryPart != null && match.wildcardDirectoryPart.Length > 0) { newItem.SetMetadata(FileUtilities.ItemSpecModifiers.RecursiveDir, match.wildcardDirectoryPart); } } expanded.Add(newItem); } } else { expanded.Add(i); } } return((ITaskItem[])expanded.ToArray(typeof(ITaskItem))); } }