public static void CopyWithIgnores(DirectoryInfo source, DirectoryInfo target, IgnoreList ignores) { if (source is null) { throw new ArgumentNullException(nameof(source)); } if (target is null) { throw new ArgumentNullException(nameof(target)); } if (ignores is null) { throw new ArgumentNullException(nameof(ignores)); } foreach (var dir in source.GetDirectories().Where(d => !ignores.IsIgnored(d))) { CopyWithIgnores(dir, target.CreateSubdirectory(dir.Name), ignores); } foreach (var file in source.GetFiles().Where(f => !ignores.IsIgnored(f))) { file.CopyTo(Path.Combine(target.FullName, file.Name)); } }
public void Respect_Rule_Overrides() { var list = new IgnoreList(new string[] { "*.txt", "!sub1/*.txt", "sub1/README2.txt" }); Assert.IsTrue(list.IsIgnored("README1.txt", true)); Assert.IsFalse(list.IsIgnored("sub1/README1.txt", true)); Assert.IsTrue(list.IsIgnored("sub1/README2.txt", true)); }
public void Add_Rules_From_File() { var ignoreList = new IgnoreList(new string[] { "README.txt" }); ignoreList.AddRules(_basePath + @"\loadfromfile.gitignore"); Assert.IsTrue(ignoreList.IsIgnored("README.txt", true)); Assert.IsFalse(ignoreList.IsIgnored("test.jpg", true)); Assert.IsTrue(ignoreList.IsIgnored("test.cs", true)); }
public void Ignore_After_Dynamic_Remove() { var ignoreList = new IgnoreList(new List <string> { "README1.txt", "README2.txt", "README3.txt", "README4.txt" }); ignoreList.RemoveRule("README2.txt"); Assert.IsTrue(ignoreList.IsIgnored("README1.txt", true)); Assert.IsFalse(ignoreList.IsIgnored("README2.txt", true)); Assert.IsTrue(ignoreList.IsIgnored("README3.txt", true)); Assert.IsTrue(ignoreList.IsIgnored("README4.txt", true)); }
public static void CopyWithIgnores(DirectoryInfo source, DirectoryInfo target, IgnoreList ignores) { foreach (DirectoryInfo dir in source.GetDirectories().Where(d => !ignores.IsIgnored(d))) { CopyWithIgnores(dir, target.CreateSubdirectory(dir.Name), ignores); } foreach (FileInfo file in source.GetFiles().Where(f => !ignores.IsIgnored(f))) { file.CopyTo(Path.Combine(target.FullName, file.Name)); } }
public void File_Rule_Line_Numbers_ToString() { var log = new IgnoreLog(); var list = new IgnoreList(new string[] { "*.cs" }); list.AddRules(_basePath + "/multiplematch.gitignore"); var paths = new List <string> { "test/test1.cs", "test/test2.cs" }; paths.ForEach(path => list.IsIgnored(path, true, log)); const string expectedResult = @"test/test1.cs IGNORED by *.cs INCLUDED by !test/*.cs (line 3) IGNORED by test/test*.cs (line 4) test/test2.cs IGNORED by *.cs INCLUDED by !test/*.cs (line 3) IGNORED by test/test*.cs (line 4) INCLUDED by !test/test2.cs (line 6)"; Assert.IsTrue(log.ToString() == expectedResult); }
public void Log_ToString() { var log = new IgnoreLog(); var list = new IgnoreList(new string[] { "one/", "two/", "!one/two/" }); var paths = new List <string> { "one", "one/two", "two" }; paths.ForEach(path => list.IsIgnored(path, true, log)); const string expectedResult = @"one IGNORED by one/ one/two IGNORED by one/ IGNORED by two/ INCLUDED by !one/two/ two IGNORED by two/"; Assert.IsTrue(log.ToString() == expectedResult); }
protected virtual void OnMethod(RunnerEventArgs e) { OnEvent(AnalyzeMethod, e); foreach (IMethodRule rule in method_rules) { defectCountBeforeCheck = Defects.Count; // stop if we reach the user defined defect limit if (defectCountBeforeCheck >= DefectsLimit) { break; } // ignore if the visibility does not match user selection ApplicabilityScope scope = rule.ApplicabilityScope; if ((scope != ApplicabilityScope.All) && !VisibilityCheck(scope, e.CurrentMethod.IsVisible())) { continue; } // ignore the rule on some user defined methods if (IgnoreList.IsIgnored(rule, e.CurrentMethod)) { continue; } currentRule = rule; rule.CheckMethod(e.CurrentMethod); } }
public void Ignore_After_Dynamic_Add() { var list = new IgnoreList(new List <string> { "README1.txt" }); list.AddRule("README2.txt"); list.AddRules(new List <string> { "README3.txt", "README4.txt" }); Assert.IsTrue(list.IsIgnored("README1.txt", true)); Assert.IsTrue(list.IsIgnored("README2.txt", true)); Assert.IsTrue(list.IsIgnored("README3.txt", true)); Assert.IsTrue(list.IsIgnored("README4.txt", true)); }
public void DirectoryInfo_Match() { var directory = new DirectoryInfo(_basePath + @"\test"); var list = new IgnoreList(new string[] { "test" }); Assert.IsTrue(list.IsIgnored(directory)); }
public void FileInfo_Match() { var directory = new DirectoryInfo(_basePath); var file = directory.GetFiles("*.txt")[0]; var list = new IgnoreList(new string[] { "test.txt" }); Assert.IsTrue(list.IsIgnored(file)); }
private bool Filter(Severity severity, Confidence confidence, IMetadataTokenProvider location) { if (!SeverityBitmask.Get(severity) || !ConfidenceBitmask.Get(confidence)) { return(false); } // for Assembly | Type | Methods we can ignore before executing the rule // but for others (e.g. Parameters, Fields...) we can only ignore the results return(!IgnoreList.IsIgnored(currentRule, location)); }
public void DirectoryInfo_Match_Log() { var directory = new DirectoryInfo(_basePath + "/test"); var list = new IgnoreList(new string[] { "test" }); var log = new IgnoreLog(); Assert.IsTrue(list.IsIgnored(directory, log)); Assert.IsTrue(log.Count == 1); Assert.IsTrue(log[directory.FullName].Count == 1); Assert.IsTrue(log[directory.FullName][0] == "IGNORED by test"); }
public void Ignored_Directory_Ignores_All_Children() { var list = new IgnoreList(new string[] { "ignored/", "!ignored/one/two/" }); Assert.IsTrue(list.IsIgnored("ignored/test.txt", false)); Assert.IsTrue(list.IsIgnored("ignored/one/test.txt", false)); Assert.IsTrue(list.IsIgnored("ignored/two/three.txt", false)); Assert.IsTrue(list.IsIgnored("ignored/one/two/test.txt", false)); Assert.IsTrue(list.IsIgnored("ignored/one/two/three/test.txt", false)); Assert.IsFalse(list.IsIgnored("notignored/test.txt", false)); Assert.IsFalse(list.IsIgnored("notignored/one/test.txt", false)); Assert.IsFalse(list.IsIgnored("notignored/one/two/test.txt", false)); }
public void Add_Rule_Flags_Respected() { var directory = new DirectoryInfo(_basePath + @"\TEST"); var list1 = new IgnoreList(new string[] { "x" }); var list2 = new IgnoreList(new string[] { "x" }); list1.AddRule("test"); list2.AddRule("test", MatchFlags.CASEFOLD); Assert.IsFalse(list1.IsIgnored(directory)); Assert.IsTrue(list2.IsIgnored(directory)); }
public void Constructor_Flags_Respected() { var directory = new DirectoryInfo(_basePath + @"\TEST"); // Case sensitive list, should not match var list1 = new IgnoreList(new string[] { "test" }); // Case insensitive, should match var list2 = new IgnoreList(new string[] { "test" }, MatchFlags.CASEFOLD); Assert.IsFalse(list1.IsIgnored(directory)); Assert.IsTrue(list2.IsIgnored(directory)); }
public void FileInfo_Match_Log() { var directory = new DirectoryInfo(_basePath); var file = directory.GetFiles("*.txt")[0]; var list = new IgnoreList(new string[] { "test.txt" }); var log = new IgnoreLog(); Assert.IsTrue(list.IsIgnored(file, log)); Assert.IsTrue(log.Count == 1); Assert.IsTrue(log[file.FullName].Count == 1); Assert.IsTrue(log[file.FullName][0] == "IGNORED by test.txt"); }
public void Log_Matched_Rules() { var ignoreList = new IgnoreList(new string[] { "*.txt", "*.cs", "!sub1/*.txt", "sub1/README2.txt" }); var log = new IgnoreLog(); ignoreList.IsIgnored("sub1/README2.txt", true, log); Assert.IsTrue(log.Count == 1); Assert.IsTrue(log["sub1/README2.txt"].Count == 3); Assert.IsTrue(log["sub1/README2.txt"][0] == "IGNORED by *.txt"); Assert.IsTrue(log["sub1/README2.txt"][1] == "INCLUDED by !sub1/*.txt"); Assert.IsTrue(log["sub1/README2.txt"][2] == "IGNORED by sub1/README2.txt"); }
/// <summary> /// Returns a collection of files contained in the specified directory and recursively in sub-directories. /// If the directory has a ".pakfilter" file, it will be used to filter which files to find. /// The .pakfilter file contains a list of filtering rules with the same syntax as the .gitignore file in Git. However, /// contrary to the .gitignore file which is a blacklist, the .pakfilter file is a whitelist. /// </summary> /// <param name="dir">The directory to find files in</param> /// <returns>An array of absolute file paths</returns> public static IReadOnlyCollection <string> Find(string dir) { var files = Directory.GetFiles(dir, "*", SearchOption.AllDirectories); if (!HasFilterFile(dir)) { return(files); } var ignoreList = new IgnoreList(Path.Combine(dir, FilterFileName)); return(files.Where(file => ignoreList.IsIgnored(file, false)).ToList()); }
private static async Task <ComponentTree> BuildTreeFrom( ProjectSettings settings, string path, IgnoreList ignoreList) { var directory = new DirectoryInfo(settings.GetRootedPath(path)); var componentTree = await GetTreeAt(directory, settings); var children = (await directory .GetDirectories() .Where(x => !ignoreList.IsIgnored(new DirectoryInfo(settings.GetRelativePath(x.FullName)))) .Select(childDirectory => BuildTreeFrom(settings, childDirectory.FullName, ignoreList)) .WhenAll()) .ToImmutableList(); return(ComponentTree.WithChildren(componentTree, children)); }
public virtual void Report(Defect defect) { if (defect == null) { throw new ArgumentNullException("defect"); } if (!Filter(defect.Severity, defect.Confidence, defect.Location)) { return; } if (IgnoreList.IsIgnored(defect.Rule, defect.Target)) { return; } defect_list.Add(defect); }
private RuleResult PreCheck(IMetadataTokenProvider obj) { if (obj == null) { throw new ArgumentNullException("obj", "Cannot check a null object"); } Reset(); AssemblyDefinition assembly = obj.GetAssembly(); if (!Assemblies.Contains(assembly)) { Assemblies.Clear(); Assemblies.Add(assembly); Engines.Build(Assemblies); } CurrentTarget = obj; return(IgnoreList.IsIgnored(CurrentRule, obj) ? RuleResult.DoesNotApply : RuleResult.Success); }
// protected since a higher-level (e.g. GUI) runner might want to override // them to update it's user interface protected virtual void OnAssembly(RunnerEventArgs e) { OnEvent(AnalyzeAssembly, e); foreach (IAssemblyRule rule in assembly_rules) { defectCountBeforeCheck = Defects.Count; // stop if we reach the user defined defect limit if (defectCountBeforeCheck >= DefectsLimit) { break; } // ignore the rule on some user defined assemblies if (IgnoreList.IsIgnored(rule, e.CurrentAssembly)) { continue; } currentRule = rule; rule.CheckAssembly(e.CurrentAssembly); } }
public bool IsIgnored(string path) => !_isInitialized || _ignoreList.IsIgnored(path, PathHelper.IsDirectoryPath(path));
public static void OnScriptError(ScriptCore.ScriptProxy proxy, Exception exception) { try { using (TestSpan span = new TestSpan(TimeSpanLogger.Bin, "OnScriptError", DebuggingLevel)) { bool fullReset = true; bool record = !IgnoreList.IsIgnored(exception, out fullReset); IScriptLogic target = null; if (proxy != null) { target = proxy.Target; } StringBuilder noticeText = new StringBuilder(); StringBuilder logText = new StringBuilder(); SimUpdate update = target as SimUpdate; if (update != null) { target = update.mSim; } else { AutonomyManager autonomy = target as AutonomyManager; if (autonomy != null) { target = SearchForAutonomy(exception.StackTrace); } else { Services services = target as Services; if (services != null) { target = SearchForAssignedSim(exception.StackTrace); } } } SimDescription targetSim = SearchForSim(exception.StackTrace); if (targetSim != null) { new FixInvisibleTask(targetSim).AddToSimulator(); } IGameObject obj = null; if (targetSim != null) { obj = ScriptCoreLogger.Convert(targetSim, noticeText, logText); } else { obj = ScriptCoreLogger.Convert(target, noticeText, logText); if (obj == null) { obj = target as IGameObject; } } ObjectGuid id = ObjectGuid.InvalidObjectGuid; bool moonDial = false; if (obj != null) { id = obj.ObjectId; moonDial = obj.GetType() == typeof(Sims3.Gameplay.Objects.Decorations.MoonDial); if (moonDial) { record = false; } } if (record) { ScriptCoreLogger.Append(noticeText, logText, id, ObjectGuid.InvalidObjectGuid, exception, sAlreadyCaught); } /* do not use else if here */ if ((proxy != null) && (proxy.Target is RoleManagerTask)) { new CheckRoleManagerTask().Perform(proxy.Target as RoleManagerTask, true); } Sim simObj = obj as Sim; if (simObj != null) { try { if (simObj.Household == null) { fullReset = true; } if ((!fullReset) && (proxy != null)) { proxy.OnReset(); } } catch (Exception e) { Common.Exception(proxy.Target, null, "PartialReset", e); fullReset = true; } if (fullReset) { if (update != null) { try { Simulator.DestroyObject(update.Proxy.ObjectId); } catch { } } new ResetSimTask(simObj); return; } } else if (proxy != null && !moonDial) { proxy.OnReset(); } } } catch (Exception e) { Exception(proxy.Target, e); } }
public void Handle_Non_Relative_Path() { var list = new IgnoreList(new string[] { "ignored/" }); Assert.IsTrue(list.IsIgnored("/ignored/test/test.txt", false)); }