private static (ITaskItem[] Element, FileMatcher.SearchAction Action, string FileSpec) ExpandWildcards(ITaskItem[] expand) { // Used to detect and log drive enumerating wildcard patterns. string[] files; FileMatcher.SearchAction action = FileMatcher.SearchAction.None; string itemSpec = string.Empty; if (expand == null) { return(null, action, itemSpec); } else { var expanded = new List <ITaskItem>(); foreach (ITaskItem i in expand) { if (FileMatcher.HasWildcards(i.ItemSpec)) { (files, action, _) = FileMatcher.Default.GetFiles(null /* use current directory */, i.ItemSpec); itemSpec = i.ItemSpec; if (action == FileMatcher.SearchAction.FailOnDriveEnumeratingWildcard) { return(expanded.ToArray(), action, itemSpec); } foreach (string file in files) { TaskItem newItem = new TaskItem(i) { ItemSpec = file }; // Compute the RecursiveDir portion. FileMatcher.Result match = FileMatcher.Default.FileMatch(i.ItemSpec, file); if (match.isLegalFileSpec && match.isMatch) { if (!string.IsNullOrEmpty(match.wildcardDirectoryPart)) { newItem.SetMetadata(FileUtilities.ItemSpecModifiers.RecursiveDir, match.wildcardDirectoryPart); } } expanded.Add(newItem); } } else { expanded.Add(i); } } return(expanded.ToArray(), action, itemSpec); } }
/// <summary> /// Expand wildcards in the item list. /// </summary> private static ITaskItem[] ExpandWildcards(ITaskItem[] expand) { if (expand == null) { return(null); } else { var expanded = new List <ITaskItem>(); foreach (ITaskItem i in expand) { if (FileMatcher.HasWildcards(i.ItemSpec)) { string[] files = FileMatcher.Default.GetFiles(null /* use current directory */, i.ItemSpec); foreach (string file in files) { TaskItem newItem = new TaskItem(i) { ItemSpec = file }; // Compute the RecursiveDir portion. FileMatcher.Result match = FileMatcher.Default.FileMatch(i.ItemSpec, file); if (match.isLegalFileSpec && match.isMatch) { if (!string.IsNullOrEmpty(match.wildcardDirectoryPart)) { newItem.SetMetadata(FileUtilities.ItemSpecModifiers.RecursiveDir, match.wildcardDirectoryPart); } } expanded.Add(newItem); } } else { expanded.Add(i); } } return(expanded.ToArray()); } }
/// <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.Default.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))); } }