public void DuplicatePatterns(string pattern1, string pattern2)
        {
            var matcher = new Matcher();
            matcher.AddInclude(pattern1);
            matcher.AddInclude(pattern2);

            ExecuteAndVerify(matcher, @"src/project",
                "src/project/sub/source2.cs");
        }
        public void IncludeCaseInsensitive(string root, string includePattern, string[] expectedFiles)
        {
            var matcher = new Matcher(StringComparison.OrdinalIgnoreCase);
            matcher.AddInclude(includePattern);

            ExecuteAndVerify(matcher, root, expectedFiles.Select(f => root + "/" + f).ToArray());
        }
        public void FolderExclude()
        {
            var matcher = new Matcher();
            matcher.AddInclude(@"**/*.*");
            matcher.AddExclude(@"obj");
            matcher.AddExclude(@"bin");
            matcher.AddExclude(@".*");

            ExecuteAndVerify(matcher, @"src/project",
                "src/project/source1.cs",
                "src/project/sub/source2.cs",
                "src/project/sub/source3.cs",
                "src/project/sub2/source4.cs",
                "src/project/sub2/source5.cs",
                "src/project/compiler/preprocess/preprocess-source1.cs",
                "src/project/compiler/preprocess/sub/preprocess-source2.cs",
                "src/project/compiler/preprocess/sub/sub/preprocess-source3.cs",
                "src/project/compiler/preprocess/sub/sub/preprocess-source3.txt",
                "src/project/compiler/shared/shared1.cs",
                "src/project/compiler/shared/shared1.txt",
                "src/project/compiler/shared/sub/shared2.cs",
                "src/project/compiler/shared/sub/shared2.txt",
                "src/project/compiler/shared/sub/sub/sharedsub.cs",
                "src/project/compiler/resources/resource.res",
                "src/project/compiler/resources/sub/resource2.res",
                "src/project/compiler/resources/sub/sub/resource3.res",
                "src/project/content1.txt");
        }
        public void DoubleParentsWithRecursiveSearch()
        {
            var matcher = new Matcher();
            matcher.AddInclude(@"..\..\lib\**\*.cs");

            ExecuteAndVerify(matcher, @"src/project",
                "lib/source6.cs",
                "lib/sub3/source7.cs",
                "lib/sub4/source8.cs");
        }
        public static IEnumerable <string> Recurse(string directory, List <string> ignoreGlobs)
        {
            var matcher = new Matcher();

            matcher.AddInclude("**/*");
            matcher.AddExcludePatterns(ignoreGlobs);
            foreach (string file in matcher.GetResultsInFullPath(directory))
            {
                yield return(file);
            }
        }
Exemple #6
0
        private static IEnumerable <FilePatternMatch> GetMatchingFiles(CommandOptions options)
        {
            Matcher matcher = new Matcher(StringComparison.InvariantCulture);

            matcher.AddInclude(options.FileGlobPattern);
            var directoryInfo        = new DirectoryInfo(string.IsNullOrWhiteSpace(options.SourceDirectoryPath) ? Directory.GetCurrentDirectory() : options.SourceDirectoryPath);
            var directoryInfoWrapper = new DirectoryInfoWrapper(directoryInfo);
            var files = matcher.Execute(directoryInfoWrapper).Files;

            return(files);
        }
        public void DoubleParentsWithRecursiveSearch()
        {
            var matcher = new Matcher();

            matcher.AddInclude(@"..\..\lib\**\*.cs");

            ExecuteAndVerify(matcher, @"src/project",
                             "lib/source6.cs",
                             "lib/sub3/source7.cs",
                             "lib/sub4/source8.cs");
        }
        public void SingleFileAndRecursive()
        {
            var matcher = new Matcher();

            matcher.AddInclude("**/*.cs");
            matcher.AddInclude("../project2/source1.cs");
            ExecuteAndVerify(matcher, "src/project",
                             "src/project/source1.cs",
                             "src/project/sub/source2.cs",
                             "src/project/sub/source3.cs",
                             "src/project/sub2/source4.cs",
                             "src/project/sub2/source5.cs",
                             "src/project/compiler/preprocess/preprocess-source1.cs",
                             "src/project/compiler/preprocess/sub/preprocess-source2.cs",
                             "src/project/compiler/preprocess/sub/sub/preprocess-source3.cs",
                             "src/project/compiler/shared/shared1.cs",
                             "src/project/compiler/shared/sub/shared2.cs",
                             "src/project/compiler/shared/sub/sub/sharedsub.cs",
                             "src/project2/source1.cs");
        }
        static void Main(string[] args)
        {
            var matcher = new Matcher();

            matcher.AddInclude("file.txt");

            var matchResult = matcher.Match("file.txt");

            Trace.Assert(matchResult.HasMatches);

            Console.WriteLine("Assertion successful");
        }
        // Internal for unit testing.
        internal PollingWildCardChangeToken(
            DirectoryInfoBase directoryInfo,
            string pattern,
            IClock clock)
        {
            _directoryInfo = directoryInfo;
            Clock          = clock;

            _matcher = new Matcher(StringComparison.OrdinalIgnoreCase);
            _matcher.AddInclude(pattern);
            CalculateChanges();
        }
Exemple #11
0
        static async Task <HashSet <string> > GetFilePathsAsync()
        {
            var config = await ReadConfigAsync();

            var matcher = new Matcher();

            foreach (var val in config.Files)
            {
                matcher.AddInclude(val);
            }
            return(matcher.GetResultsInFullPath(Directory.GetCurrentDirectory()).ToHashSet());
        }
        public void RecursiveSuffixSearch()
        {
            var matcher = new Matcher();

            matcher.AddInclude(@"**.txt");

            ExecuteAndVerify(matcher, @"src/project",
                             "src/project/compiler/preprocess/sub/sub/preprocess-source3.txt",
                             "src/project/compiler/shared/shared1.txt",
                             "src/project/compiler/shared/sub/shared2.txt",
                             "src/project/content1.txt");
        }
Exemple #13
0
        private static void LoadForBiome(Heightmap.Biome biome)
        {
            string biomeName        = Enum.GetName(typeof(Heightmap.Biome), biome).ToLower();
            string pluginConfigPath = Path.Combine(BepInEx.Paths.ConfigPath, TheRuins.PluginName);

            var matcher = new Matcher();

            matcher.AddInclude($"**/{biomeName}/**/*.blueprint");
            matcher.AddInclude($"**/{biomeName}/**/*.vbuild");

            var files = matcher.Execute(new DirectoryInfoWrapper(new DirectoryInfo(pluginConfigPath)));

            var blueprints = new List <Blueprint>();

            foreach (var file in files.Files)
            {
                string blueprintPath = Path.Combine(pluginConfigPath, file.Path);
                blueprints.Add(Blueprint.FromFile(blueprintPath));
            }
            biomeRuins.Add(biome, blueprints);
            Jotunn.Logger.LogInfo($"[TheRuins] Loaded {blueprints.Count} blueprints/vbuilds for {biomeName} biome");
        }
        public static List <string> LoadFiles(string basePath, string pattern)
        {
            var directoryInfo  = new DirectoryInfo(basePath);
            var matchDirectory = new DirectoryInfoWrapper(directoryInfo);

            var matcher = new Matcher();

            matcher.AddInclude(pattern);

            var matchResult = matcher.Execute(matchDirectory);

            return(matchResult.Files.Select(item => item.Path).ToList());
        }
Exemple #15
0
        public static MarkdownProject Load(string searchArea, string namespaceMatch)
        {
            List <MarkdownType> types = new List <MarkdownType>();

            MarkdownProject project = new MarkdownProject();

            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;

            var matcher = new Matcher();

            foreach (var searchPath in searchArea.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
            {
                matcher.AddInclude(searchPath);
            }
            var rootDir = Directory.GetCurrentDirectory();
            var results = matcher.GetResultsInFullPath(rootDir);

            Constants.Logger?.LogInformation($"Found {results.Count()} dlls from {rootDir} using {searchArea}");
            List <string> processedDlls = new List <string>();

            foreach (var dllPath in results)
            {
                var dllName = Path.GetFileName(dllPath);
                Constants.Logger?.LogInformation("Loading Dll: {dllName}", dllPath);

                if (processedDlls.Contains(dllName))
                {
                    Constants.Logger?.LogWarning("Duplicate Dll: {dllName}", dllName);
                    continue;
                }

                try
                {
                    if (File.Exists(dllPath) && Path.GetExtension(dllPath) == ".dll")
                    {
                        LoadDll(dllPath, namespaceMatch);
                        processedDlls.Add(dllName);
                    }
                    else
                    {
                        Constants.Logger?.LogError($"Failed to find {dllPath} dll");
                    }
                }
                catch (Exception e)
                {
                    Constants.Logger?.LogError(e, "Failed to Load {dllName}", dllPath);
                }
            }

            return(project);
        }
        public async ValueTask <IFileReference[]> ListAsync(string path, string searchPattern, bool recursive,
                                                            bool withMetadata)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                path = null;
            }
            else
            {
                if (!path.EndsWith("/"))
                {
                    path = path + "/";
                }
            }

            var prefix        = path;
            var firstWildCard = searchPattern.IndexOf('*');

            if (firstWildCard >= 0)
            {
                prefix       += searchPattern.Substring(0, firstWildCard);
                searchPattern = searchPattern.Substring(firstWildCard);
            }

            var matcher = new Matcher(StringComparison.Ordinal);

            matcher.AddInclude(searchPattern);

            var operationContext = new OperationContext();
            BlobContinuationToken continuationToken = null;
            var results = new List <IListBlobItem>();

            do
            {
                var response = await _container.Value.ListBlobsSegmentedAsync(prefix, recursive,
                                                                              withMetadata?BlobListingDetails.Metadata : BlobListingDetails.None, null, continuationToken,
                                                                              new BlobRequestOptions(), new OperationContext());

                continuationToken = response.ContinuationToken;
                results.AddRange(response.Results);
            } while (continuationToken != null);

            var pathMap = results.OfType <ICloudBlob>()
                          .Select(blob => new AzureFileReference(blob, withMetadata)).ToDictionary(x => x.Path);

            var filteredResults = matcher.Execute(
                new AzureListDirectoryWrapper(path,
                                              pathMap));

            return(filteredResults.Files.Select(x => pathMap[path + x.Path]).ToArray());
        }
        public static Matcher AddIncludePatterns(this Matcher result, string patterns, char separator, string defaultValue)
        {
            if (string.IsNullOrEmpty(patterns))
            {
                result.AddInclude(defaultValue);
            }
            else
            {
                var items = patterns.Split(new char[] { separator }, StringSplitOptions.RemoveEmptyEntries);
                result.AddIncludePatterns(items);
            }

            return(result);
        }
Exemple #18
0
        public static IEnumerable <string> ExpandGlobs(IAsset asset, IWebHostEnvironment env)
        {
            var files = new List <string>();

            foreach (string sourceFile in asset.SourceFiles)
            {
                string outSourceFile;
                var    provider = asset.GetFileProvider(env, sourceFile, out outSourceFile);

                if (provider.GetFileInfo(outSourceFile).Exists)
                {
                    if (!files.Contains(sourceFile))
                    {
                        files.Add(sourceFile);
                    }
                }
                else
                {
                    var    fileInfo = provider.GetFileInfo("/");
                    string root     = fileInfo.PhysicalPath;

                    if (root != null)
                    {
                        var dir     = new DirectoryInfoWrapper(new DirectoryInfo(root));
                        var matcher = new Matcher();
                        matcher.AddInclude(outSourceFile);
                        PatternMatchingResult globbingResult = matcher.Execute(dir);
                        IEnumerable <string>  fileMatches    = globbingResult.Files.Select(f => f.Path.Replace(root, string.Empty));

                        if (!fileMatches.Any())
                        {
                            throw new FileNotFoundException($"No files found matching \"{sourceFile}\" exist in \"{dir.FullName}\"");
                        }

                        files.AddRange(fileMatches.Where(f => !files.Contains(f)));
                    }
                    else
                    {
                        if (!files.Contains(sourceFile))
                        {
                            files.Add(sourceFile);
                        }
                    }
                }
            }

            asset.Items[PhysicalFilesKey] = files;

            return(files);
        }
Exemple #19
0
        internal IEnumerable <Assembly> GetAssemblies()
        {
            var matcher = new Matcher(StringComparison.InvariantCultureIgnoreCase);

            matcher.AddInclude("./**/*.dll").AddInclude("./**/*.exe");
            var assemblyFiles = _plugInSourceLists.FileProvider.GetDirectoryContents(_path)
                                .Where(f => matcher.Match(f.PhysicalPath).HasMatches);

            if (Filter != null)
            {
                assemblyFiles = assemblyFiles.Where(f => Filter(f.Name));
            }
            return(assemblyFiles.Select(f => _plugInSourceLists.AssemblyLoadContext.LoadFromStream(f.CreateReadStream())));
        }
        /// <summary>
        /// Determines whether this permission rule is a match for the target resource name and claim type.
        /// Uses globbing to match to pattern.
        /// </summary>
        /// <param name="resourceUri">The URI of the target resource.</param>
        /// <param name="accessType">The claim type of the target resource.</param>
        /// <returns>True if a match.</returns>
        public bool IsMatch(Uri resourceUri, string accessType)
        {
            var resourceNameMatcher = new Matcher();

            resourceNameMatcher.AddInclude(this.Resource.Uri.ToString());
            PatternMatchingResult resourceNameMatchResult = resourceNameMatcher.Match(resourceUri.ToString());

            var accessTypeMatcher = new Matcher();

            accessTypeMatcher.AddInclude(this.AccessType);
            PatternMatchingResult accessTypeMatchResult = accessTypeMatcher.Match(accessType);

            return(resourceNameMatchResult.HasMatches && accessTypeMatchResult.HasMatches);
        }
Exemple #21
0
        static async Task Run(string source, string output)
        {
            // Split volume
            var volumePathSplited = DevCore.IO.SplitVolumePath(source);

            Matcher matcher = new Matcher(StringComparison.InvariantCultureIgnoreCase);

            matcher.AddInclude(volumePathSplited.Item2);

            var results = MatcherExtensions.GetResultsInFullPath(matcher, volumePathSplited.Item1 + System.IO.Path.DirectorySeparatorChar);

            Console.WriteLine(string.Empty);
            Console.WriteLineFormatted($@"Volume: {volumePathSplited.Item1}", Color.Green);
            Console.WriteLineFormatted($@"Path: {volumePathSplited.Item2}", Color.Green);
            Console.WriteLineFormatted($@"{results.Count()} files found", Color.Green);
            results.ToList().ForEach(e => Console.WriteLine(e));

            Stopwatch sw = new Stopwatch();

            sw.Start();
            foreach (var item in results)
            {
                using (var cli = new Cli("ffmpeg"))
                {
                    var destiny = Path.ChangeExtension(item, output);
                    var args    = $@"-i ""{item}"" ""{destiny}""";

                    var handler = new BufferHandler(
                        stdOutLine => Console.WriteLine(stdOutLine),
                        stdErrLine => Console.WriteLine(stdErrLine));

                    Console.WriteLine(string.Empty);
                    Console.WriteFormatted($@"Executing: ", Color.Green);
                    Console.WriteLineFormatted($"ffmpeg {args}", Color.White);
                    Console.WriteLine(string.Empty);

                    await cli.ExecuteAsync(args, bufferHandler : handler);
                }
            }
            sw.Stop();

            if (results.Any())
            {
                Console.WriteLine(string.Empty);
                Console.Write($"The process has been executed in: ");
                Console.WriteFormatted($"{sw.Elapsed.TotalSeconds}", Color.Green);
                Console.WriteLine($" seconds.");
            }
        }
Exemple #22
0
        public static string ReadLine()
        {
            var lineStringBuilder = new StringBuilder();

            var dictionary = new Dictionary <ConsoleKey, Func <ConsoleKey, string, bool> >();

            dictionary.Add(ConsoleKey.Enter, (key, currentVal) => true);
            dictionary.Add(ConsoleKey.Tab, (key, currentVal) =>
            {
                var matcher       = new Matcher();
                var parameterList = new List <string>();
                foreach (var parameter in currentVal.Split(' '))
                {
                    if (Regex.IsMatch(parameter, @"(.)+([:]{0,1})([\\])(.)+"))
                    {
                        var result = matcher.AddInclude(parameter).Execute(new DirectoryInfoWrapper(new DirectoryInfo("C:\\")));
                        if (result.HasMatches)
                        {
                            parameterList.Add(result.Files.FirstOrDefault().Path);
                        }
                        parameterList.Add(parameter);
                        continue;
                    }
                    parameterList.Add(parameter);
                }
                lineStringBuilder.Append(string.Join(' ', parameterList));
                return(false);
            });

            var currentKey = Console.ReadKey(true);

            while (true)
            {
                if (dictionary.TryGetValue(currentKey.Key, out var action) &&
                    action.Invoke(currentKey.Key, lineStringBuilder.ToString()))
                {
                    break;
                }
                if (action == null)
                {
                    lineStringBuilder.Append(currentKey.KeyChar);
                    Console.Write(currentKey.KeyChar);
                }

                currentKey = Console.ReadKey(true);
            }

            return(lineStringBuilder.ToString());
        }
Exemple #23
0
 public ExcludedFilesHelper(string[] excludes, ILogger logger)
 {
     if (excludes != null && excludes.Length > 0)
     {
         _matcher = new Matcher();
         foreach (var excludeRule in excludes)
         {
             if (excludeRule is null)
             {
                 continue;
             }
             _matcher.AddInclude(Path.IsPathRooted(excludeRule) ? excludeRule.Substring(Path.GetPathRoot(excludeRule).Length) : excludeRule);
         }
     }
 }
Exemple #24
0
        internal static PatternMatchingResult FindMatchingFiles(string directoryPath, string pattern)
        {
            // Check the user can access the folder
            // This will return false if the path does not exist or you do not have read permissions.
            if (!Directory.Exists(directoryPath))
            {
                throw new Exception($"Directory does not exist or you do not have read access. Tried to access directory '{directoryPath}'");
            }

            var matcher = new Matcher();

            matcher.AddInclude(pattern);
            var results = matcher.Execute(new DirectoryInfoWrapper(new DirectoryInfo(directoryPath)));

            return(results);
        }
        public bool TryGetAssetFromRoute(string route, out IAsset asset)
        {
            asset = null;

            // Bail if this is an absolute path
            if (string.IsNullOrEmpty(route) || route.StartsWith("//") || route.Contains("://"))
            {
                return(false);
            }

            string cleanRoute = NormalizeRoute(route);

            // First check direct matches
            foreach (IAsset existing in Assets)
            {
                if (existing.Route.Equals(cleanRoute, StringComparison.OrdinalIgnoreCase))
                {
                    asset = existing;
                    return(true);
                }
            }

            // Then check globbing matches
            if (route != "/")
            {
                foreach (IAsset existing in Assets)
                {
                    var matcher = new Matcher();
                    matcher.AddInclude(existing.Route);

                    if (matcher.Match(cleanRoute.TrimStart('/')).HasMatches)
                    {
                        asset = new Asset(cleanRoute, existing.ContentType, this, new[] { cleanRoute });

                        foreach (IProcessor processor in existing.Processors)
                        {
                            asset.Processors.Add(processor);
                        }

                        _assets.Add(asset);
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemple #26
0
        public virtual PatternMatchingResult Execute(DirectoryInfoBase directoryInfo)
        {
            var files = new List <FilePatternMatch>();

            foreach (var includePattern in _includePatterns)
            {
                var matcher = new Matcher();
                matcher.AddInclude(includePattern);
                matcher.AddExcludePatterns(_excludePatterns);
                var result = matcher.Execute(directoryInfo);
                if (result.Files.Any())
                {
                    files.AddRange(result.Files);
                }
            }
            return(new PatternMatchingResult(files));
        }
        public static PageTreeItem <IFileInfo> LoadFiles(this IPageDirectoryLoader pageDirectoryLoader,
                                                         IFileProvider fileProvider,
                                                         string pageGlob,
                                                         string indexGlob)
        {
            var pageMatcher = new Matcher(StringComparison.OrdinalIgnoreCase);

            pageMatcher.AddInclude(pageGlob);
            var indexMatcher = new Matcher(StringComparison.OrdinalIgnoreCase);

            indexMatcher.AddInclude(indexGlob);
            return(pageDirectoryLoader.LoadFiles(fileProvider, new PageDirectoryLoaderOptions
            {
                NormalPageMatcher = pageMatcher,
                IndexPageMatcher = indexMatcher
            }));
        }
Exemple #28
0
        public static string[] Glob([NotNull] string directory, [NotNull] string pattern)
        {
            if (directory is null)
            {
                throw new ArgumentNullException(nameof(directory));
            }
            if (pattern is null)
            {
                throw new ArgumentNullException(nameof(pattern));
            }

            var folder  = new DirectoryInfo(directory);
            var matcher = new Matcher();

            matcher.AddInclude(pattern);
            return(Glob(folder, matcher));
        }
Exemple #29
0
        public bool Build()
        {
            var projectFilesFinder = new Matcher();

            // Resolve all the project names
            var projectFilesToBuild = new List <string>();

            foreach (var pattern in _buildOptions.ProjectPatterns)
            {
                if (pattern.Contains("*"))
                {
                    // Requires globbing
                    projectFilesFinder.AddInclude(NormalizeGlobbingPattern(pattern));
                }
                else
                {
                    projectFilesToBuild.Add(pattern);
                }
            }

            var rootDirectory       = Directory.GetCurrentDirectory();
            var patternSearchFolder = new DirectoryInfoWrapper(new DirectoryInfo(rootDirectory));
            var globbingProjects    = projectFilesFinder.Execute(patternSearchFolder).Files.Select(file =>
                                                                                                   Path.Combine(rootDirectory, file));

            projectFilesToBuild.AddRange(globbingProjects);

            var sw = Stopwatch.StartNew();

            _cacheContextAccessor = new CacheContextAccessor();
            _cache = new Cache(_cacheContextAccessor);

            var globalSucess = true;

            foreach (var project in projectFilesToBuild)
            {
                var buildSuccess = BuildInternal(project);
                globalSucess &= buildSuccess;
            }

            _buildOptions.Reports.Information.WriteLine($"Total build time elapsed: { sw.Elapsed }");
            _buildOptions.Reports.Information.WriteLine($"Total projects built: { projectFilesToBuild.Count }");

            return(globalSucess);
        }
        public IEnumerable <string> GetChangedFiles(string commitId, string glob = null)
        {
            Matcher m = new Matcher(StringComparison.InvariantCultureIgnoreCase);

            m.AddInclude(glob);

            var mergeCommit = _repository.Lookup <Commit>(commitId);

            foreach (var entry in mergeCommit.Tree)
            {
                var matchingResult = m.Match(entry.Path);

                if (matchingResult.HasMatches)
                {
                    yield return(entry.Path);
                }
            }
        }
Exemple #31
0
        Matcher GetMatcher()
        {
            var matcher = new Matcher(StringComparison.CurrentCultureIgnoreCase);

            if (Includes != null && Includes.Length != 0)
            {
                matcher.AddIncludePatterns(Includes);
            }
            else
            {
                matcher.AddInclude("**/*");
            }
            if (Excludes != null && Excludes.Length != 0)
            {
                matcher.AddExcludePatterns(Excludes);
            }
            return(matcher);
        }
        public IEnumerable <string> GetFiles(string includePattern, string targetDirectory)
        {
            var matcher = new Matcher();

            matcher.AddInclude(includePattern);

            if (_omniSharpOptions.FileOptions.SystemExcludeSearchPatterns != null && _omniSharpOptions.FileOptions.SystemExcludeSearchPatterns.Any())
            {
                matcher.AddExcludePatterns(_omniSharpOptions.FileOptions.SystemExcludeSearchPatterns);
            }

            if (_omniSharpOptions.FileOptions.ExcludeSearchPatterns != null && _omniSharpOptions.FileOptions.ExcludeSearchPatterns.Any())
            {
                matcher.AddExcludePatterns(_omniSharpOptions.FileOptions.ExcludeSearchPatterns);
            }

            return(matcher.GetResultsInFullPath(targetDirectory));
        }
Exemple #33
0
        [Fact] // https://github.com/dotnet/runtime/issues/44767
        public void VerifyAbsolutePaths_HasMatches()
        {
            var fileMatcher = new Matcher();

            fileMatcher.AddInclude("**/*");

            if (PlatformDetection.IsWindows)
            {
                // Windows-like absolute paths are not supported on Unix.
                string fakeWindowsPath = "C:\\This\\is\\a\\nested\\windows-like\\path\\somefile.cs";
                Assert.True(fileMatcher.Match(Path.GetPathRoot(fakeWindowsPath), fakeWindowsPath).HasMatches);
            }

            // Unix-like absolute paths are treated as relative paths on Windows.
            string fakeUnixPath = "/This/is/a/nested/unix-like/path/somefile.cs";

            Assert.True(fileMatcher.Match(Path.GetPathRoot(fakeUnixPath), fakeUnixPath).HasMatches);
        }
Exemple #34
0
        public static int Main(string[] args)
        {
            var workDir = args.Length > 0 ? args[0] : ".";
            var outputFileNameWithPath = workDir == "." ? OutputFileName : Path.Combine(workDir, OutputFileName);

            var matcher = new Matcher();

            matcher.AddInclude(@"**\*.cs");
            matcher.AddExclude(OutputFileName);

            var inputFiles = matcher.GetResultsInFullPath(workDir).ToArray();

            Console.WriteLine("Rewriting async methods");
            var asyncCode = new Rewriter().RewriteAndMerge(inputFiles);

            File.WriteAllText(outputFileNameWithPath, asyncCode);
            return(0);
        }
Exemple #35
0
 public void SingleFileAndRecursive()
 {
     var matcher = new Matcher();
     matcher.AddInclude("**/*.cs");
     matcher.AddInclude("../project2/source1.cs");
     ExecuteAndVerify(matcher, "src/project",
         "src/project/source1.cs",
         "src/project/sub/source2.cs",
         "src/project/sub/source3.cs",
         "src/project/sub2/source4.cs",
         "src/project/sub2/source5.cs",
         "src/project/compiler/preprocess/preprocess-source1.cs",
         "src/project/compiler/preprocess/sub/preprocess-source2.cs",
         "src/project/compiler/preprocess/sub/sub/preprocess-source3.cs",
         "src/project/compiler/shared/shared1.cs",
         "src/project/compiler/shared/sub/shared2.cs",
         "src/project/compiler/shared/sub/sub/sharedsub.cs",
         "src/project2/source1.cs");
 }
Exemple #36
0
        public void ExcludeCaseSensitive(string root, string excludePattern, string[] expectedFiles)
        {
            var matcher = new Matcher(StringComparison.Ordinal);
            matcher.AddInclude("**/*.*");
            matcher.AddExclude(excludePattern);

            ExecuteAndVerify(matcher, root, expectedFiles.Select(f => root + "/" + f).ToArray());
        }
        public void MultipleSubDirsAfterFirstWildcardMatch_HasCorrectStem()
        {
            var matcher = new Matcher();
            matcher.AddInclude("compiler/**/*.cs");

            var directoryPath = Path.Combine(_context.RootPath, "src/project");
            var results = matcher.Execute(new DirectoryInfoWrapper(new DirectoryInfo(directoryPath)));

            var actual = results.Files.Select(match => match.Stem);
            var expected = new string[] {
                "preprocess/preprocess-source1.cs",
                "preprocess/sub/preprocess-source2.cs",
                "preprocess/sub/sub/preprocess-source3.cs",
                "shared/shared1.cs",
                "shared/sub/shared2.cs",
                "shared/sub/sub/sharedsub.cs"
            };

            Assert.Equal(
                expected.OrderBy(e => e),
                actual.OrderBy(e => e),
                StringComparer.OrdinalIgnoreCase);
        }
Exemple #38
0
        public void OneLevelParentAndRecursiveSearch()
        {
            var matcher = new Matcher();
            matcher.AddInclude(@"../project2/**/*.cs");

            ExecuteAndVerify(matcher, @"src/project",
                "src/project2/source1.cs",
                "src/project2/sub/source2.cs",
                "src/project2/sub/source3.cs",
                "src/project2/sub2/source4.cs",
                "src/project2/sub2/source5.cs",
                "src/project2/compiler/preprocess/preprocess-source1.cs",
                "src/project2/compiler/preprocess/sub/preprocess-source2.cs",
                "src/project2/compiler/preprocess/sub/sub/preprocess-source3.cs",
                "src/project2/compiler/shared/shared1.cs",
                "src/project2/compiler/shared/sub/shared2.cs",
                "src/project2/compiler/shared/sub/sub/sharedsub.cs");
        }
Exemple #39
0
        public void RecursiveAndDoubleParentsWithRecursiveSearch()
        {
            var matcher = new Matcher();
            matcher.AddInclude("**/*.cs")
                   .AddInclude(@"../../lib/**/*.cs");

            ExecuteAndVerify(matcher, @"src/project",
                "src/project/source1.cs",
                "src/project/sub/source2.cs",
                "src/project/sub/source3.cs",
                "src/project/sub2/source4.cs",
                "src/project/sub2/source5.cs",
                "src/project/compiler/preprocess/preprocess-source1.cs",
                "src/project/compiler/preprocess/sub/preprocess-source2.cs",
                "src/project/compiler/preprocess/sub/sub/preprocess-source3.cs",
                "src/project/compiler/shared/shared1.cs",
                "src/project/compiler/shared/sub/shared2.cs",
                "src/project/compiler/shared/sub/sub/sharedsub.cs",
                "lib/source6.cs",
                "lib/sub3/source7.cs",
                "lib/sub4/source8.cs");
        }
Exemple #40
0
        public void RecursiveSuffixSearch()
        {
            var matcher = new Matcher();
            matcher.AddInclude(@"**.txt");

            ExecuteAndVerify(matcher, @"src/project",
                "src/project/compiler/preprocess/sub/sub/preprocess-source3.txt",
                "src/project/compiler/shared/shared1.txt",
                "src/project/compiler/shared/sub/shared2.txt",
                "src/project/content1.txt");
        }
Exemple #41
0
 public void SingleFile(string pattern, string expect)
 {
     var matcher = new Matcher();
     matcher.AddInclude(pattern);
     ExecuteAndVerify(matcher, "src/project", expect);
 }
        public void StemCorrectWithDifferentWildCards()
        {
            var matcher = new Matcher();
            matcher.AddInclude("sub/*.cs");
            matcher.AddInclude("**/*.cs");

            var directoryPath = Path.Combine(_context.RootPath, "src/project");
            var results = matcher.Execute(new DirectoryInfoWrapper(new DirectoryInfo(directoryPath)));

            var actual = results.Files.Select(match => match.Stem);
            var expected = new string[] {
                "source1.cs",
                "source2.cs",
                "source3.cs",
                "sub2/source4.cs",
                "sub2/source5.cs",
                "compiler/preprocess/preprocess-source1.cs",
                "compiler/preprocess/sub/preprocess-source2.cs",
                "compiler/preprocess/sub/sub/preprocess-source3.cs",
                "compiler/shared/shared1.cs",
                "compiler/shared/sub/shared2.cs",
                "compiler/shared/sub/sub/sharedsub.cs"
            };

            Assert.Equal(
                expected.OrderBy(e => e),
                actual.OrderBy(e => e),
                StringComparer.OrdinalIgnoreCase);
        }
Exemple #43
0
 public void FolderInclude()
 {
     var matcher = new Matcher();
     matcher.AddInclude(@"compiler/");
     ExecuteAndVerify(matcher, @"src/project",
         "src/project/compiler/preprocess/preprocess-source1.cs",
         "src/project/compiler/preprocess/sub/preprocess-source2.cs",
         "src/project/compiler/preprocess/sub/sub/preprocess-source3.cs",
         "src/project/compiler/preprocess/sub/sub/preprocess-source3.txt",
         "src/project/compiler/shared/shared1.cs",
         "src/project/compiler/shared/shared1.txt",
         "src/project/compiler/shared/sub/shared2.cs",
         "src/project/compiler/shared/sub/shared2.txt",
         "src/project/compiler/shared/sub/sub/sharedsub.cs",
         "src/project/compiler/resources/resource.res",
         "src/project/compiler/resources/sub/resource2.res",
         "src/project/compiler/resources/sub/sub/resource3.res");
 }
Exemple #44
0
        public void WildcardAndDoubleParentsSearch()
        {
            var matcher = new Matcher();
            matcher.AddInclude(@"..\..\lib\*.cs");
            matcher.AddInclude(@"*.cs");

            ExecuteAndVerify(matcher, @"src/project",
                "src/project/source1.cs",
                "lib/source6.cs");
        }