public bool Matches(string path, [NotNullWhen(true)] out string?transformed) { if (FilePattern.Matches(filePatterns, path, out var suffix)) { transformed = FileUtils.ConvertToUnix(name) + suffix; return(true); } transformed = null; return(false); }
// ------------------------------------------------------------------- private string[] VerifyRequiredFiles(ITargetAssignment assignment, ISubmittableItem[] items) { Dictionary <string, bool> requiredFiles = new Dictionary <string, bool>(); string[] patterns = assignment.AllRequiredFiles; foreach (string pattern in patterns) { requiredFiles.Add(pattern, false); } foreach (ISubmittableItem item in new DepthFirstTraversal <ISubmittableItem>(items, delegate(ISubmittableItem i) { return(i.Children); })) { if (item.Kind == SubmittableItemKind.File) { foreach (string reqPattern in patterns) { FilePattern pattern = new FilePattern(reqPattern); if (pattern.Matches(item.Filename)) { requiredFiles[reqPattern] = true; } } } } List <string> missingFiles = new List <string>(); foreach (string requiredFile in requiredFiles.Keys) { if (requiredFiles[requiredFile] == false) { missingFiles.Add(requiredFile); } } if (missingFiles.Count == 0) { return(null); } else { return(missingFiles.ToArray()); } }
public void TestMatching() { var fp1 = new FilePattern(@"C:\agent\root\abc//"); var fp2 = new FilePattern(@"C:\agent\root\def//ghi"); var patterns = new[] { fp1, fp2 }; var success = FilePattern.Matches(patterns, @"C:\agent\root\abc\file.cs", out var s); Assert.True(success); Assert.Equal("/file.cs", s); success = FilePattern.Matches(patterns, @"C:\agent\root\def\ghi\file.cs", out s); Assert.True(success); Assert.Equal("/ghi/file.cs", s); success = FilePattern.Matches(patterns, @"C:\agent\root\def\file.cs", out _); Assert.False(success); }
public virtual bool IsFileExcluded(string projectRelativePath) { bool localExclude = false; bool localInclude = false; // Check to see if the file is excluded locally. string[] excludes = ExcludedFiles; foreach (string exclude in excludes) { FilePattern pattern = new FilePattern(exclude); if (pattern.Matches(projectRelativePath)) { localExclude = true; break; } } // Check to see if the file is explicitly included // locally. string[] includes = IncludedFiles; foreach (string include in includes) { FilePattern pattern = new FilePattern(include); if (pattern.Matches(projectRelativePath)) { localInclude = true; break; } } if (localInclude && localExclude) { if (ambiguityResolution == AmbiguityResolution.Exclude) return true; else return false; } else if (localExclude) { return true; } else if (localInclude) { return false; } // If no explicit mention of the file was found, // try going up the assignment tree. if (parent != null) return parent.IsFileExcluded(projectRelativePath); else { if (includes.Length == 0) return false; else return true; } }
// ------------------------------------------------------------------- private string[] VerifyRequiredFiles(ITargetAssignment assignment, ISubmittableItem[] items) { Dictionary<string, bool> requiredFiles = new Dictionary<string, bool>(); string[] patterns = assignment.AllRequiredFiles; foreach(string pattern in patterns) requiredFiles.Add(pattern, false); foreach (ISubmittableItem item in new DepthFirstTraversal<ISubmittableItem>(items, delegate(ISubmittableItem i) { return i.Children; })) { if (item.Kind == SubmittableItemKind.File) { foreach (string reqPattern in patterns) { FilePattern pattern = new FilePattern(reqPattern); if(pattern.Matches(item.Filename)) { requiredFiles[reqPattern] = true; } } } } List<string> missingFiles = new List<string>(); foreach (string requiredFile in requiredFiles.Keys) { if (requiredFiles[requiredFile] == false) { missingFiles.Add(requiredFile); } } if (missingFiles.Count == 0) { return null; } else { return missingFiles.ToArray(); } }