public void GetMatchedFiles_ContainsGlobMatchingZeroFiles_EmptyList()
        {
            string[] libraryFiles = new[]
            {
                "file.js",
            };
            string[] fileSpec = new[]
            {
                "*.css",
            };

            IEnumerable <string> result = FileGlobbingUtility.ExpandFileGlobs(fileSpec, libraryFiles);

            CollectionAssert.AreEqual(Array.Empty <string>(), result.ToList());
        }
        public void GetMatchedFiles_NoGlobsSpecifiedAndNoMatches_ReturnsInputList()
        {
            string[] libraryFiles = new[]
            {
                "folder/file.css",
            };
            string[] fileSpec = new[]
            {
                "file.css",
            };

            IEnumerable <string> result = FileGlobbingUtility.ExpandFileGlobs(fileSpec, libraryFiles);

            CollectionAssert.AreEqual(fileSpec, result.ToList());
        }
        public void GetMatchedFiles_ContainsGlobMatchingMultipleFiles_ReturnsAllMatches()
        {
            string[] libraryFiles = new[]
            {
                "a.css",
                "b.css",
            };
            string[] fileSpec = new[]
            {
                "*.css",
            };

            IEnumerable <string> result = FileGlobbingUtility.ExpandFileGlobs(fileSpec, libraryFiles);

            CollectionAssert.AreEqual(libraryFiles, result.ToList());
        }
        public void GetMatchedFiles_ContainsGlobsUsingGlobStar_ReturnsMatches()
        {
            string[] libraryFiles = new[] {
                "notMatch/foo/file.css",
                "match/foo/a.css",
                "match/bar/baz/b.css",
            };
            string[] fileSpec = new[] {
                "match/**/*.css",
            };

            IEnumerable <string> result = FileGlobbingUtility.ExpandFileGlobs(fileSpec, libraryFiles);

            string[] expected = new[] {
                "match/foo/a.css",
                "match/bar/baz/b.css",
            };
            CollectionAssert.AreEqual(expected, result.ToList());
        }
        public void GetMatchedFiles_ContainsGlobsWithExclusion_ProcessedInOrderSeen()
        {
            string[] libraryFiles = new[] {
                "match/foo/a.css",
                "match/bar/baz/b.css",
                "other/foo/b.css",
            };
            string[] fileSpec = new[] {
                "match/**/*.css",
                "!**/b.css",
                "other/**/*.css"
            };

            IEnumerable <string> result = FileGlobbingUtility.ExpandFileGlobs(fileSpec, libraryFiles);

            string[] expected = new[] {
                "match/foo/a.css",
                "other/foo/b.css",
            };
            CollectionAssert.AreEqual(expected, result.ToList());
        }
예제 #6
0
        /// <inheritdoc />
        public virtual async Task <ILibraryOperationResult> UpdateStateAsync(ILibraryInstallationState desiredState, CancellationToken cancellationToken)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                return(LibraryOperationResult.FromCancelled(desiredState));
            }

            string libraryId = LibraryNamingScheme.GetLibraryId(desiredState.Name, desiredState.Version);

            try
            {
                ILibraryCatalog catalog = GetCatalog();
                ILibrary        library = await catalog.GetLibraryAsync(desiredState.Name, desiredState.Version, cancellationToken).ConfigureAwait(false);

                if (library == null)
                {
                    return(new LibraryOperationResult(desiredState, PredefinedErrors.UnableToResolveSource(desiredState.Name, desiredState.ProviderId)));
                }

                if (desiredState.Files != null && desiredState.Files.Count > 0)
                {
                    // expand any potential file patterns
                    IEnumerable <string> updatedFiles = FileGlobbingUtility.ExpandFileGlobs(desiredState.Files, library.Files.Keys);
                    var processedState = new LibraryInstallationState
                    {
                        Name                      = desiredState.Name,
                        Version                   = desiredState.Version,
                        ProviderId                = desiredState.ProviderId,
                        DestinationPath           = desiredState.DestinationPath,
                        IsUsingDefaultDestination = desiredState.IsUsingDefaultDestination,
                        IsUsingDefaultProvider    = desiredState.IsUsingDefaultProvider,
                        Files                     = updatedFiles.ToList(),
                    };

                    return(CheckForInvalidFiles(processedState, libraryId, library));
                }

                desiredState = new LibraryInstallationState
                {
                    ProviderId                = Id,
                    Name                      = desiredState.Name,
                    Version                   = desiredState.Version,
                    DestinationPath           = desiredState.DestinationPath,
                    Files                     = library.Files.Keys.ToList(),
                    IsUsingDefaultDestination = desiredState.IsUsingDefaultDestination,
                    IsUsingDefaultProvider    = desiredState.IsUsingDefaultProvider
                };
            }
            catch (InvalidLibraryException)
            {
                return(new LibraryOperationResult(desiredState, PredefinedErrors.UnableToResolveSource(libraryId, desiredState.ProviderId)));
            }
            catch (UnauthorizedAccessException)
            {
                return(new LibraryOperationResult(desiredState, PredefinedErrors.PathOutsideWorkingDirectory()));
            }
            catch (Exception ex)
            {
                HostInteraction.Logger.Log(ex.ToString(), LogLevel.Error);
                return(new LibraryOperationResult(desiredState, PredefinedErrors.UnknownException()));
            }

            return(LibraryOperationResult.FromSuccess(desiredState));
        }