示例#1
0
        public static Boolean IsSetVariableAllowed(this TaskRestrictions restrictions, String variable)
        {
            ArgUtil.NotNull(variable, nameof(variable));

            var allowedList = restrictions.SettableVariables?.Allowed;

            if (allowedList == null)
            {
                return(true);
            }

            var opts = new Options()
            {
                IgnoreCase = true
            };

            foreach (String pattern in allowedList)
            {
                if (Minimatcher.Check(variable, pattern, opts))
                {
                    return(true);
                }
            }

            return(false);
        }
示例#2
0
        private IReadOnlyCollection <IProject> GetNotExcludedProjects(IReadOnlyCollection <string> exclusionPatterns)
        {
            if (exclusionPatterns == null || exclusionPatterns.Count < 1)
            {
                return(_projects);
            }

            var notExcludedProjects = new List <IProject>();

            foreach (var project in _projects)
            {
                var excluded = false;
                foreach (var excludedProject in exclusionPatterns)
                {
                    if (Minimatcher.Check(project.FilePath, excludedProject, new Options {
                        AllowWindowsPaths = true, NoCase = true
                    }))
                    {
                        _logger.LogDebug($"Ignoring project '{project.FilePath}' as it matches the exclusion pattern {excludedProject}");
                        excluded = true;
                        break;
                    }
                }

                if (excluded)
                {
                    continue;
                }

                notExcludedProjects.Add(project);
            }

            return(notExcludedProjects);
        }
示例#3
0
        private static bool IsSourceFile(JObject obj, string cwd, string fileName)
        {
            IEnumerable <string> files    = obj["files"]?.Values <string>() ?? Enumerable.Empty <string>();
            IEnumerable <string> includes = obj["include"]?.Values <string>() ?? Enumerable.Empty <string>();

            var options = new Options {
                AllowWindowsPaths = true
            };
            string relative = fileName.Substring(cwd.Length).Trim('\\');

            foreach (string file in files)
            {
                bool isMatch = Minimatcher.Check(relative, file, options);
                if (isMatch)
                {
                    return(true);
                }
            }

            foreach (string pattern in includes)
            {
                bool isMatch = Minimatcher.Check(relative, pattern, options);
                if (isMatch)
                {
                    return(true);
                }
            }

            return(false);
        }
示例#4
0
        private bool IsImageOnProbingPath(string file, out Optimization optimization)
        {
            optimization = null;

            foreach (var opti in _config.Optimizations)
            {
                optimization = opti;

                bool isIncluded = opti.Includes.Any(pattern => Minimatcher.Check(file, pattern, _matcherOptions));

                if (!isIncluded)
                {
                    continue;
                }

                bool isExcluded = opti.Excludes.Any(pattern => Minimatcher.Check(file, pattern, _matcherOptions));

                if (isExcluded)
                {
                    continue;
                }

                return(true);
            }

            return(false);
        }
示例#5
0
        public static bool CheckGlobbing(string path, string pattern)
        {
            string p = pattern?.TrimEnd('/');

            if (!string.IsNullOrWhiteSpace(p))
            {
                return(Minimatcher.Check(path, p, _options));
            }

            return(false);
        }
示例#6
0
        public static IEnumerable <string> ExpandFileGlobs(IEnumerable <string> potentialGlobs, IEnumerable <string> libraryFiles)
        {
            var finalSetOfFiles = new HashSet <string>();
            var negatedOptions  = new Minimatch.Options {
                FlipNegate = true
            };

            foreach (string potentialGlob in potentialGlobs)
            {
                // only process globs where we find them, otherwise it can get expensive
                if (potentialGlob.StartsWith("!", StringComparison.Ordinal))
                {
                    // Remove matches from the files list
                    var filesToRemove = finalSetOfFiles.Where(f => Minimatcher.Check(f, potentialGlob, negatedOptions)).ToList();
                    foreach (string file in filesToRemove)
                    {
                        finalSetOfFiles.Remove(file);
                    }
                }
                else if (potentialGlob.IndexOfAny(GlobIndicatorCharacters) >= 0)
                {
                    IEnumerable <string> filterResult = libraryFiles.Where(f => Minimatcher.Check(f, potentialGlob));
                    if (filterResult.Any())
                    {
                        finalSetOfFiles.UnionWith(filterResult);
                    }
                }
                else
                {
                    // not a glob pattern, so just include the file literally
                    finalSetOfFiles.Add(potentialGlob);
                }
            }

            return(finalSetOfFiles);
        }