Exemple #1
0
        public void IsMatch_When_MatchingWithDoubleAndSingleStarAndInputUsesBackslash_Then_ResultShouldBeAsExpected(string input, bool expectedResult)
        {
            var regex = GlobRegex.Create(@"c:/a/**/*.txt");

            var result = regex.IsMatch(input);

            result.Should().Be(expectedResult);
        }
Exemple #2
0
        public void IsMatch_When_MatchingWithNoWildcards_Then_ResultShouldBeAsExpected(string input, bool expectedResult)
        {
            var regex = GlobRegex.Create(@"c:\a\file.txt");

            var result = regex.IsMatch(input);

            result.Should().Be(expectedResult);
        }
Exemple #3
0
        public async Task UpdatePackagesInProjectsAsync(UpdateVerb updateVerb)
        {
            var rootDirectory = updateVerb.RootDirectory ?? this.fileSystem.Directory.GetCurrentDirectory();

            this.packageUpdaterFacadeReporter.StartingPackageUpdate(rootDirectory);
            var changedProjects = new List <MsBuildProject>();
            var stopwatch       = Stopwatch.StartNew();

            try
            {
                var globalGlobRegex = string.IsNullOrEmpty(updateVerb.VersionPattern)
                    ? null
                    : GlobRegex.Create(updateVerb.VersionPattern);
                foreach (var project in this.msBuildProjectFileSearcher.GetProjects(rootDirectory, updateVerb.Projects).ToList())
                {
                    this.packageUpdaterFacadeReporter.UpdatingProject(project);

                    var msBuildProject = await this.msBuildProjectPackagesParser.GetPackages(project, updateVerb.PackageIds);

                    var packageUpdates = await this.packageVersionSelector.GetPackageVersions(msBuildProject.PossiblePackageUpdates, globalGlobRegex, rootDirectory, updateVerb.AllowPrerelease, updateVerb.Source);

                    var result = this.packageVersionUpdater.TryUpdateAsync(msBuildProject, packageUpdates);
                    if (result)
                    {
                        changedProjects.Add(result.Value);
                    }
                }

                foreach (var changedProject in changedProjects)
                {
                    await this.fileSystem.File.WriteAllTextAsync(changedProject.Path, changedProject.ProjectContent);
                }

                if (changedProjects.Count > 0 && !updateVerb.SkipRestore)
                {
                    await this.packageRestorer.RestoreAsync(rootDirectory, updateVerb.Verbose);
                }
            }
            catch (Exception e)
            {
                this.packageUpdaterFacadeReporter.Exception(e);
                return;
            }

            this.packageUpdaterFacadeReporter.CompletedPackageUpdate(changedProjects, updateVerb.SkipRestore, stopwatch.Elapsed);
        }
Exemple #4
0
        public Task <int> PruneAsync(AllVerb allVerb)
        {
            var stopwatch = Stopwatch.StartNew();
            var source    = this.nuGetSourceProvider.GetDefaultSource(allVerb.Source);

            this.purgerReporter.StartPruning(source, allVerb.PackageIds);
            var numberDirectoriesPruned = 0;

            try
            {
                if (!UriUtility.TryCreateSourceUri(source, UriKind.Absolute).IsFile)
                {
                    throw new InvalidOperationException("Prune only works with local sources");
                }

                foreach (var packageId in allVerb.PackageIds)
                {
                    var globRegex   = GlobRegex.Create(packageId);
                    var directories = this.fileSystem.Directory.GetDirectories(source)
                                      .Where(x => globRegex.IsMatch(Path.GetFileName(x)));
                    foreach (var directory in directories)
                    {
                        this.fileSystem.Directory.Delete(directory, true);
                        this.purgerReporter.Deleted(directory);
                        numberDirectoriesPruned++;
                    }
                }

                this.purgerReporter.CompletedPruning(true, numberDirectoriesPruned, stopwatch.Elapsed);
            }
            catch (OperationCanceledException)
            {
                this.purgerReporter.CompletedPruning(false, numberDirectoriesPruned, stopwatch.Elapsed);
                return(Task.FromResult(-3));
            }
            catch (Exception e)
            {
                this.purgerReporter.Exception(e);
                return(Task.FromResult(-1));
            }

            return(Task.FromResult(0));
        }
        public IEnumerable <string> GetProjects(string rootDirectory, IReadOnlyList <string> projects)
        {
            var projectRegexes = projects.Count == 0 ? new[] { new Regex(MatchAllRegex) } : projects.Select(x => GlobRegex.Create(x, false)).ToArray();

            return(this.directory.EnumerateFiles(rootDirectory, AllFilesSearchPattern, SearchOption.AllDirectories)
                   .Where(x => SearchPatterns.Any(x.EndsWith) && projectRegexes.Any(regex => regex.IsMatch(x))));
        }