public ExclusionFilter(string _filter) { if (!String.IsNullOrEmpty(_filter)) { globFilter = new GlobFilter(new string[] { _filter }); } }
public ExclusionFilter(List <string> _filter) { if (_filter != null && _filter.Count != 0) { globFilter = new GlobFilter(_filter.ToArray()); } }
private static void FilterAndEnqueue(State state, Settings settings) { Regex[] filters = GlobFilter.ToRegex(settings.Filters); foreach (ClrModule module in state.Runtime.EnumerateModules()) { foreach (ClrType type in module.EnumerateTypeDefToMethodTableMap().Select(map => state.Runtime.GetTypeByMethodTable(map.MethodTable)).Where(type => type is not null)) { foreach (ClrMethod method in type.Methods.Where(method => method.Signature != null)) { if (method.NativeCode > 0) { if (!state.AddressToNameMapping.TryGetValue(method.NativeCode, out _)) { state.AddressToNameMapping.Add(method.NativeCode, method.Signature); } } if (CanBeDisassembled(method)) { foreach (Regex filter in filters) { if (filter.IsMatch(method.Signature)) { state.Todo.Enqueue(new MethodInfo(method, depth: settings.MaxDepth)); // don't allow for recursive disassembling break; } } } } } } }
public void TheFilterIsCaseInsensitive(string pattern, bool expected) { var benchmarkCase = BenchmarkConverter.TypeToBenchmarks(typeof(TypeWithBenchmarks)).BenchmarksCases.Single(); var filter = new GlobFilter(new[] { pattern }); Assert.Equal(expected, filter.Predicate(benchmarkCase)); }
static ContentHashCache() { hashByContentPath = new Hashtable(StringComparer.OrdinalIgnoreCase); var cdn = Config.Get <CDNSettings>(); cdnEnabled = cdn.Enabled == true && !string.IsNullOrEmpty(cdn.Url); cdnHttp = cdn.Url; if (string.IsNullOrEmpty(cdn.HttpsUrl)) { cdnHttps = (cdnHttp ?? "").Replace("http://", "https://"); } else { cdnHttps = cdn.HttpsUrl; } cdnFilter = new GlobFilter(cdn.Include, cdn.Exclude); }
// pluginLoader.close(); // jdk7 is saner internal virtual MetricsFilter GetFilter(string prefix) { // don't create filter instances without out options Org.Apache.Hadoop.Metrics2.Impl.MetricsConfig conf = ((Org.Apache.Hadoop.Metrics2.Impl.MetricsConfig )Subset(prefix)); if (conf.IsEmpty()) { return(null); } MetricsFilter filter = GetPlugin(prefix); if (filter != null) { return(filter); } // glob filter is assumed if pattern is specified but class is not. filter = new GlobFilter(); filter.Init(conf); return(filter); }
public ContentHashCache(IOptions <CDNSettings> cdnSettings, IWebHostEnvironment hostEnvironment, IHttpContextAccessor httpContextAccessor = null) { this.hostEnvironment = hostEnvironment ?? throw new ArgumentNullException(nameof(hostEnvironment)); this.httpContextAccessor = httpContextAccessor; var cdn = cdnSettings.Value; hashByContentPath = new Hashtable(StringComparer.OrdinalIgnoreCase); cdnEnabled = cdn.Enabled == true && !string.IsNullOrEmpty(cdn.Url); cdnHttp = cdn.Url; if (string.IsNullOrEmpty(cdn.HttpsUrl)) { cdnHttps = (cdnHttp ?? "").Replace("http://", "https://", StringComparison.Ordinal); } else { cdnHttps = cdn.HttpsUrl; } cdnFilter = new GlobFilter(cdn.Include, cdn.Exclude); }
public void Run(string csproj) { var process = Process.Start(new ProcessStartInfo { FileName = "dotnet", WorkingDirectory = Path.GetDirectoryName(csproj), CreateNoWindow = true, Arguments = "restore \"" + csproj + "\"" }); process.WaitForExit(); if (process.ExitCode > 0) { Console.Error.WriteLine("Error executing dotnet restore!"); Environment.Exit(process.ExitCode); } var packagesDir = new PackageHelper().DeterminePackagesPath(); var visited = new HashSet <string>(StringComparer.OrdinalIgnoreCase); var queue = new Queue <Tuple <string, string, string> >(); Func <string, bool> skipPackage = id => { if (visited.Contains(id)) { return(true); } foreach (var skip in skipPackages) { if (id.StartsWith(skip, StringComparison.OrdinalIgnoreCase)) { return(true); } } visited.Add(id); return(false); }; var projectDir = Path.GetDirectoryName(csproj); var config = GeneratorConfig.LoadFromFile(Path.Combine(projectDir, "sergen.json")); EnumerateProjectDeps(csproj, (fw, id, ver) => { if (!skipPackage(id) && !string.IsNullOrEmpty(ver)) { queue.Enqueue(new Tuple <string, string, string>(fw, id, ver)); } }); GlobFilter include = null; if (config.Restore?.Include.IsEmptyOrNull() == false) { include = new GlobFilter(config.Restore.Include); } GlobFilter exclude = null; if (config.Restore?.Exclude.IsEmptyOrNull() == false) { exclude = new GlobFilter(config.Restore.Exclude); } while (queue.Count > 0) { var dep = queue.Dequeue(); var id = dep.Item2; var ver = dep.Item3.Trim(); if (ver.EndsWith("-*", StringComparison.Ordinal)) { ver = ver.Substring(0, ver.Length - 2); } else if (ver.StartsWith("[", StringComparison.Ordinal) && ver.EndsWith("]", StringComparison.Ordinal)) { ver = ver.Substring(1, ver.Length - 2).Trim(); } var packageFolder = Path.Combine(Path.Combine(packagesDir, id), ver); if (!Directory.Exists(packageFolder)) { packageFolder = Path.Combine(Path.Combine(packagesDir, id.ToLowerInvariant()), ver); if (!Directory.Exists(packageFolder)) { var myPackagesDir = Path.Combine(packagesDir, "..", "my-packages"); packageFolder = Path.Combine(myPackagesDir, id, ver); if (!Directory.Exists(packageFolder)) { packageFolder = Path.Combine(myPackagesDir, id.ToLowerInvariant(), ver); } } } var nuspecFile = Path.Combine(packageFolder, id + ".nuspec"); if (!File.Exists(nuspecFile)) { nuspecFile = Path.Combine(packageFolder, id.ToLowerInvariant() + ".nuspec"); if (!File.Exists(nuspecFile)) { continue; } } Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("Processing: " + id); Console.ResetColor(); var contentRoot = Path.Combine(packageFolder, "Content/".Replace('/', Path.DirectorySeparatorChar)); if (!Directory.Exists(contentRoot)) { contentRoot = Path.Combine(packageFolder, "content/".Replace('/', Path.DirectorySeparatorChar)); } if (Directory.Exists(contentRoot)) { var targetRoot = Path.GetDirectoryName(csproj); foreach (var file in Directory.GetFiles(contentRoot, "*.*", SearchOption.AllDirectories)) { var extension = Path.GetExtension(file); if (string.Compare(extension, ".transform", StringComparison.OrdinalIgnoreCase) == 0) { continue; } var relative = file.Substring(contentRoot.Length); // toastr! if (relative.StartsWith("content/".Replace('/', Path.DirectorySeparatorChar), StringComparison.Ordinal)) { relative = "Content/".Replace('/', Path.DirectorySeparatorChar) + relative.Substring("content/".Length); } else if (relative.StartsWith("scripts/", StringComparison.Ordinal)) { relative = "Scripts/".Replace('/', Path.DirectorySeparatorChar) + relative.Substring("content/".Length); } else if (relative.StartsWith("Fonts/", StringComparison.Ordinal)) { relative = "fonts/".Replace('/', Path.DirectorySeparatorChar) + relative.Substring("fonts/".Length); } if (relative.StartsWith("scripts/typings/".Replace('/', Path.DirectorySeparatorChar), StringComparison.OrdinalIgnoreCase)) { relative = relative.Substring("scripts/".Length); } else { relative = Path.Combine("wwwroot", relative); } if (include != null && !include.IsMatch(relative)) { continue; } if (exclude != null && exclude.IsMatch(relative)) { continue; } var target = Path.Combine(targetRoot, relative); if (File.Exists(target)) { if (!File.ReadAllBytes(target) .SequenceEqual(File.ReadAllBytes(file))) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Restoring: " + relative); Console.ResetColor(); File.Copy(file, target, true); } } else { if (!Directory.Exists(target)) { Directory.CreateDirectory(Path.GetDirectoryName(target)); } Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Restoring: " + relative); Console.ResetColor(); File.Copy(file, target, false); } } } var nuspecContent = File.ReadAllText(nuspecFile); var nuspec = XElement.Parse(nuspecContent); var meta = nuspec.Elements().Where(x => x.Name?.LocalName == "metadata").FirstOrDefault(); if (meta == null) { continue; } var deps = meta.Elements().Where(x => x.Name?.LocalName == "dependencies").FirstOrDefault();; if (deps == null) { continue; } var fw = dep.Item1; var groups = deps.Elements().Where(x => x.Name?.LocalName == "group"); if (groups.Any()) { foreach (var group in groups) { var target = group.Attribute("targetFramework").Value; if (string.IsNullOrEmpty(target) || string.Compare(target, fw, StringComparison.OrdinalIgnoreCase) == 0 || target.StartsWith(".NETStandard", StringComparison.OrdinalIgnoreCase) || target.StartsWith("netstandard", StringComparison.OrdinalIgnoreCase) || target.StartsWith("netcore", StringComparison.OrdinalIgnoreCase) || target.StartsWith("net", StringComparison.OrdinalIgnoreCase)) { foreach (var dep2 in group.Elements().Where(x => x.Name?.LocalName == "dependency")) { var id2 = dep2.Attribute("id").Value; if (!skipPackage(id2)) { queue.Enqueue(new Tuple <string, string, string>(fw, id2, dep2.Attribute("version").Value)); } } } } } else { foreach (var dep2 in deps.Elements().Where(x => x.Name?.LocalName == "dependency")) { var id2 = dep2.Attribute("id").Value; if (!skipPackage(id2)) { queue.Enqueue(new Tuple <string, string, string>(fw, id2, dep2.Attribute("version").Value)); } } } } }
public void Run(string csproj) { var packagesDir = new PackageHelper().DeterminePackagesPath(); var visited = new HashSet <string>(StringComparer.OrdinalIgnoreCase); Func <string, bool> skipPackage = id => { if (visited.Contains(id)) { return(true); } foreach (var skip in skipPackages) { if (id.StartsWith(skip, StringComparison.OrdinalIgnoreCase)) { return(true); } } visited.Add(id); return(false); }; var projectDir = Path.GetDirectoryName(csproj); var config = GeneratorConfig.LoadFromFile(Path.Combine(projectDir, "sergen.json")); GlobFilter include = null; if (config.Restore?.Include.IsEmptyOrNull() == false) { include = new GlobFilter(config.Restore.Include); } GlobFilter exclude = null; if (config.Restore?.Exclude.IsEmptyOrNull() == false) { exclude = new GlobFilter(config.Restore.Exclude); } var targetRoot = Path.GetDirectoryName(csproj); var restoredFromProjectReference = new HashSet <string>(StringComparer.OrdinalIgnoreCase); void restoreFile(string file, string relative) { relative = PathHelper.ToPath(relative); if (include != null && !include.IsMatch(relative)) { return; } if (exclude != null && exclude.IsMatch(relative)) { return; } if (restoredFromProjectReference.Contains(relative)) { return; } var target = Path.Combine(targetRoot, relative); if (File.Exists(target)) { if (!File.ReadAllBytes(target) .SequenceEqual(File.ReadAllBytes(file))) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Restoring: " + relative); Console.ResetColor(); File.Copy(file, target, true); } } else { if (!Directory.Exists(target)) { Directory.CreateDirectory(Path.GetDirectoryName(target)); } Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Restoring: " + relative); Console.ResetColor(); File.Copy(file, target, false); } } try { foreach (var reference in EnumerateProjectReferences(csproj, new HashSet <string>(StringComparer.OrdinalIgnoreCase))) { var project = new Project(reference); try { foreach (var item in project.AllEvaluatedItems .Where(x => string.Equals(x.ItemType, "TypingsToPackage", StringComparison.OrdinalIgnoreCase) || string.Equals(x.ItemType, "Content", StringComparison.OrdinalIgnoreCase) || string.Equals(x.ItemType, "None", StringComparison.OrdinalIgnoreCase) || string.Equals(x.ItemType, "TypeScriptCompile", StringComparison.OrdinalIgnoreCase)) .Where(x => x.EvaluatedInclude?.EndsWith(".d.ts", StringComparison.OrdinalIgnoreCase) == true)) { var sourceFile = Path.Combine(Path.GetDirectoryName(reference), item.EvaluatedInclude); if (!File.Exists(sourceFile)) { continue; } if (!string.Equals(item.ItemType, "TypingsToPackage", StringComparison.OrdinalIgnoreCase) && item.GetMetadataValue("Pack") != "true") { continue; } var packagePath = item.GetMetadataValue("PackagePath")?.Trim(); if (!string.IsNullOrEmpty(packagePath)) { foreach (var path in packagePath.Split(';', StringSplitOptions.RemoveEmptyEntries)) { if (!PathHelper.ToUrl(path).StartsWith("typings/", StringComparison.OrdinalIgnoreCase)) { continue; } restoreFile(sourceFile, path); restoredFromProjectReference.Add(path); } } } } finally { ProjectCollection.GlobalProjectCollection.UnloadAllProjects(); } } } catch (Exception ex) { Console.Error.WriteLine(ex.Message); } var queue = new Queue <(string ID, string Version)>(); foreach (var x in EnumeratePackageReferences(csproj)) { if (!skipPackage(x.Id) && !string.IsNullOrEmpty(x.Version)) { queue.Enqueue(x); } } ; while (queue.Count > 0) { var dep = queue.Dequeue(); var id = dep.ID; var ver = dep.Version.Trim(); if (ver.EndsWith("-*", StringComparison.Ordinal)) { ver = ver.Substring(0, ver.Length - 2); } else if (ver.StartsWith("[", StringComparison.Ordinal) && ver.EndsWith("]", StringComparison.Ordinal)) { ver = ver.Substring(1, ver.Length - 2).Trim(); } var packageFolder = Path.Combine(Path.Combine(packagesDir, id), ver); if (!Directory.Exists(packageFolder)) { packageFolder = Path.Combine(Path.Combine(packagesDir, id.ToLowerInvariant()), ver); if (!Directory.Exists(packageFolder)) { var myPackagesDir = Path.Combine(packagesDir, "..", "my-packages"); packageFolder = Path.Combine(myPackagesDir, id, ver); if (!Directory.Exists(packageFolder)) { packageFolder = Path.Combine(myPackagesDir, id.ToLowerInvariant(), ver); } } } var nuspecFile = Path.Combine(packageFolder, id + ".nuspec"); if (!File.Exists(nuspecFile)) { nuspecFile = Path.Combine(packageFolder, id.ToLowerInvariant() + ".nuspec"); if (!File.Exists(nuspecFile)) { continue; } } Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("Processing: " + id); Console.ResetColor(); var contentRoot = Path.Combine(packageFolder, "content"); if (!Directory.Exists(contentRoot)) { contentRoot = Path.Combine(packageFolder, "Content"); } if (Directory.Exists(contentRoot)) { foreach (var file in Directory.GetFiles(contentRoot, "*.*", SearchOption.AllDirectories)) { var extension = Path.GetExtension(file); if (string.Compare(extension, ".transform", StringComparison.OrdinalIgnoreCase) == 0) { continue; } var relative = PathHelper.ToUrl(file.Substring(contentRoot.Length + 1)); // normalize paths as Content, Scripts, fonts and typings (these are exact cases expected) if (relative.StartsWith("content/", StringComparison.OrdinalIgnoreCase)) { relative = "Content/" + relative["content/".Length..];
public void Glob_Filter_Works_Properly(string path, bool result) { var filter = new GlobFilter(filters); Assert.Equal(result, filter.IsMatch(path)); }