Ejemplo n.º 1
0
        [InlineData("package", "assembly", false)] // different
        public void LibraryIdentity_Equals_LibraryType(string typeA, string typeB, bool expected)
        {
            // Arrange
            var version   = new NuGetVersion("1.0.0");
            var identityA = new LibraryIdentity("packageA", version, LibraryType.Parse(typeA));
            var identityB = new LibraryIdentity("packageA", version, LibraryType.Parse(typeB));

            // Act
            var actual = identityA.Equals(identityB);

            // Assert
            Assert.Equal(expected, actual);
        }
Ejemplo n.º 2
0
        public bool TryGetLibrary(LockFileTargetLibrary targetLibrary, out LockFileLibrary library)
        {
            var libraryType = LibraryType.Parse(targetLibrary.Type);

            if (libraryType == LibraryType.Package)
            {
                library = GetPackage(targetLibrary.Name, targetLibrary.Version);
            }
            else
            {
                library = GetProject(targetLibrary.Name);
            }

            return(library != null);
        }
Ejemplo n.º 3
0
        public LockFileLookup(LockFile lockFile)
        {
            _packages = new Dictionary <KeyValuePair <string, NuGetVersion>, LockFileLibrary>(PackageCacheKeyComparer.Instance);
            _projects = new Dictionary <string, LockFileLibrary>(StringComparer.OrdinalIgnoreCase);

            foreach (var library in lockFile.Libraries)
            {
                var libraryType = LibraryType.Parse(library.Type);

                if (libraryType == LibraryType.Package)
                {
                    _packages[new KeyValuePair <string, NuGetVersion>(library.Name, library.Version)] = library;
                }
                if (libraryType == LibraryType.Project)
                {
                    _projects[library.Name] = library;
                }
            }
        }
        public LockFileLookup(LockFile lockFile)
        {
            _packages = new Dictionary <Tuple <string, NuGetVersion>, LockFileLibrary>();
            _projects = new Dictionary <string, LockFileLibrary>();

            foreach (var library in lockFile.Libraries)
            {
                var libraryType = LibraryType.Parse(library.Type);

                if (libraryType == LibraryType.Package)
                {
                    _packages[Tuple.Create(library.Name, library.Version)] = library;
                }
                if (libraryType == LibraryType.Project)
                {
                    _projects[library.Name] = library;
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Get ordered dependencies from the lock file
        /// </summary>
        /// <param name="lockFile"></param>
        /// <returns></returns>
        public static IReadOnlyList <LibraryIdentity> GetOrderedLockFileDependencies(LockFile lockFile)
        {
            var results = new List <LibraryIdentity>();

            var dependencies = new HashSet <PackageDependencyInfo>(PackageIdentity.Comparer);
            var typeMappings = new Dictionary <PackageDependencyInfo, LibraryIdentity>(PackageIdentity.Comparer);

            foreach (var target in lockFile.Targets)
            {
                foreach (var targetLibrary in target.Libraries)
                {
                    var identity   = new PackageIdentity(targetLibrary.Name, targetLibrary.Version);
                    var dependency = new PackageDependencyInfo(identity, targetLibrary.Dependencies);
                    dependencies.Add(dependency);

                    if (!typeMappings.ContainsKey(dependency))
                    {
                        var libraryIdentity = new LibraryIdentity(
                            targetLibrary.Name,
                            targetLibrary.Version,
                            LibraryType.Parse(targetLibrary.Type));

                        typeMappings.Add(dependency, libraryIdentity);
                    }
                }
            }

            // Sort dependencies
            var sortedDependencies = TopologicalSortUtility.SortPackagesByDependencyOrder(dependencies);

            foreach (var dependency in sortedDependencies)
            {
                // Convert back
                // PackageDependencyInfo -> LibraryIdentity
                results.Add(typeMappings[dependency]);
            }

            return(results);
        }