コード例 #1
0
ファイル: LockFileUtils.cs プロジェクト: noahfalk/dnx
        public static LockFileLibrary CreateLockFileLibrary(LockFileLibrary previousLibrary, IPackagePathResolver resolver, IPackage package, string correctedPackageName = null)
        {
            var lockFileLib = new LockFileLibrary();

            // package.Id is read from nuspec and it might be in wrong casing.
            // correctedPackageName should be the package name used by dependency graph and
            // it has the correct casing that runtime needs during dependency resolution.
            lockFileLib.Name = correctedPackageName ?? package.Id;
            lockFileLib.Version = package.Version;
            lockFileLib.Sha512 = File.ReadAllText(resolver.GetHashPath(package.Id, package.Version));

            // If the shas are equal then do nothing
            if (previousLibrary?.Sha512 == lockFileLib.Sha512)
            {
                lockFileLib.Files = previousLibrary.Files;
                lockFileLib.IsServiceable = previousLibrary.IsServiceable;
            }
            else
            {
                lockFileLib.Files = package.GetFiles().Select(p => p.Path).ToList();
                var installPath = resolver.GetInstallPath(package.Id, package.Version);
                foreach (var filePath in lockFileLib.Files)
                {
                    if (!string.Equals(Path.GetExtension(filePath), ".dll", StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }

                    var assemblyPath = Path.Combine(installPath, filePath);
                    try
                    {
                        if (IsAssemblyServiceable(assemblyPath))
                        {
                            lockFileLib.IsServiceable = true;
                            break;
                        }
                    }
                    catch
                    {
                        // Just move on to the next file
                    }
                }
            }

            return lockFileLib;
        }
コード例 #2
0
        public static LockFileLibrary CreateLockFileLibrary(LockFileLibrary previousLibrary, IPackagePathResolver resolver, IPackage package, string correctedPackageName = null)
        {
            var lockFileLib = new LockFileLibrary();

            // package.Id is read from nuspec and it might be in wrong casing.
            // correctedPackageName should be the package name used by dependency graph and
            // it has the correct casing that runtime needs during dependency resolution.
            lockFileLib.Name    = correctedPackageName ?? package.Id;
            lockFileLib.Version = package.Version;
            lockFileLib.Sha512  = File.ReadAllText(resolver.GetHashPath(package.Id, package.Version));

            // If the shas are equal then do nothing
            if (previousLibrary?.Sha512 == lockFileLib.Sha512)
            {
                lockFileLib.Files         = previousLibrary.Files;
                lockFileLib.IsServiceable = previousLibrary.IsServiceable;
            }
            else
            {
                lockFileLib.Files = package.GetFiles().Select(p => p.Path).ToList();
                var installPath = resolver.GetInstallPath(package.Id, package.Version);
                foreach (var filePath in lockFileLib.Files)
                {
                    if (!string.Equals(Path.GetExtension(filePath), ".dll", StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }

                    var assemblyPath = Path.Combine(installPath, filePath);
                    try
                    {
                        if (IsAssemblyServiceable(assemblyPath))
                        {
                            lockFileLib.IsServiceable = true;
                            break;
                        }
                    }
                    catch
                    {
                        // Just move on to the next file
                    }
                }
            }

            return(lockFileLib);
        }
コード例 #3
0
        private string ResolvePackagePath(IPackagePathResolver defaultResolver,
                                          IEnumerable <IPackagePathResolver> cacheResolvers,
                                          IPackage package)
        {
            var    defaultHashPath = defaultResolver.GetHashPath(package.Id, package.Version);
            string expectedHash    = null;

            if (File.Exists(defaultHashPath))
            {
                expectedHash = File.ReadAllText(defaultHashPath);
            }
            else if (_globalSettings != null)
            {
                var library = new Library()
                {
                    Name    = package.Id,
                    Version = package.Version
                };

                _globalSettings.PackageHashes.TryGetValue(library, out expectedHash);
            }

            if (string.IsNullOrEmpty(expectedHash))
            {
                return(defaultResolver.GetInstallPath(package.Id, package.Version));
            }

            foreach (var resolver in cacheResolvers)
            {
                var cacheHashFile = resolver.GetHashPath(package.Id, package.Version);

                // REVIEW: More efficient compare?
                if (File.Exists(cacheHashFile) &&
                    File.ReadAllText(cacheHashFile) == expectedHash)
                {
                    return(resolver.GetInstallPath(package.Id, package.Version));
                }
            }

            return(defaultResolver.GetInstallPath(package.Id, package.Version));
        }
コード例 #4
0
        private static string ResolvePackagePath(IPackagePathResolver defaultResolver,
                                                 IEnumerable <IPackagePathResolver> cacheResolvers,
                                                 IPackage package)
        {
            var defaultHashPath = defaultResolver.GetHashPath(package.Id, package.Version);

            foreach (var resolver in cacheResolvers)
            {
                var cacheHashFile = resolver.GetHashPath(package.Id, package.Version);

                // REVIEW: More efficient compare?
                if (File.Exists(defaultHashPath) &&
                    File.Exists(cacheHashFile) &&
                    File.ReadAllText(defaultHashPath) == File.ReadAllText(cacheHashFile))
                {
                    return(resolver.GetInstallPath(package.Id, package.Version));
                }
            }

            return(defaultResolver.GetInstallPath(package.Id, package.Version));
        }
コード例 #5
0
        private static string ResolvePackagePath(IPackagePathResolver defaultResolver,
                                                 IEnumerable<IPackagePathResolver> cacheResolvers,
                                                 IPackage package)
        {
            var defaultHashPath = defaultResolver.GetHashPath(package.Id, package.Version);

            foreach (var resolver in cacheResolvers)
            {
                var cacheHashFile = resolver.GetHashPath(package.Id, package.Version);

                // REVIEW: More efficient compare?
                if (File.Exists(defaultHashPath) &&
                    File.Exists(cacheHashFile) &&
                    File.ReadAllText(defaultHashPath) == File.ReadAllText(cacheHashFile))
                {
                    return resolver.GetInstallPath(package.Id, package.Version);
                }
            }

            return defaultResolver.GetInstallPath(package.Id, package.Version);
        }