Пример #1
0
        public DependencyChain <EvaluatedPackage> Apply(DependencyChain <LicensedPackage> chain)
        {
            var root         = Apply(chain.Package);
            var dependencies = Apply(chain.Dependencies);

            return(new DependencyChain <EvaluatedPackage>(root, dependencies));
        }
Пример #2
0
        /// <summary>
        /// Recursively try to find licenses for all packages in a dependency
        /// chain.
        /// </summary>
        public async Task <DependencyChain <LicensedPackage> > GetLicensesAsync(DependencyChain <AnalyzedPackage> chain)
        {
            var rootLicense = await GetLicenseAsync(chain.Package);

            string path = string.Format(this.licensePathFormatStr, chain.Package.Id, chain.Package.Version);

            DiskCache.Cache(path, new ResolvedLicense(rootLicense.License, rootLicense.State, rootLicense.Messages));

            var dependencyLicensesTasks = chain.Dependencies.Select(GetLicensesAsync).ToArray();

            Task.WaitAll(dependencyLicensesTasks);
            var dependencyLicenses = dependencyLicensesTasks.Select(x => x.Result).ToList();

            return(new DependencyChain <LicensedPackage>(rootLicense, dependencyLicenses));
        }
Пример #3
0
        /// <summary>
        /// Pretty-print the given dependency chain.
        /// </summary>
        public static string Print(DependencyChain <EvaluatedPackage> package, int level = 0)
        {
            string indent = new string(' ', level);

            string packageInfo = $"{package.Package.Id} {package.Package.Version}";
            string result      = $"{indent}- {packageInfo}";
            int    pad         = Math.Max(0, 70 - result.Length);

            result += package.Package.License.PadLeft(pad, ' ');
            pad     = Math.Max(0, 90 - result.Length);
            result += package.Package.Result.ToString().PadLeft(pad, ' ');

            StringBuilder sb = new StringBuilder($"{result}{Environment.NewLine}");

            foreach (var d in package.Dependencies)
            {
                sb.Append(indent).Append(Print(d, level + 1));
            }

            return(sb.ToString());
        }
Пример #4
0
 public int GetHashCode(DependencyChain <TPackage> obj)
 {
     return(obj.Package.Id.GetHashCode() ^ obj.Package.Version.GetHashCode());
 }
Пример #5
0
 public bool Equals(DependencyChain <TPackage> x, DependencyChain <TPackage> y)
 {
     return(x.Package.Id.Equals(y.Package.Id) && x.Package.Version.Equals(y.Package.Version));
 }
Пример #6
0
        private static ICollection <DependencyChain <EvaluatedPackage> > GetDependencies(DependencyChain <EvaluatedPackage> p)
        {
            List <DependencyChain <EvaluatedPackage> > result = new List <DependencyChain <EvaluatedPackage> >();

            result.Add(new DependencyChain <EvaluatedPackage>(p.Package, DependencyChain <EvaluatedPackage> .EmptyList));
            result.AddRange(p.Dependencies.SelectMany(GetDependencies));
            return(result);
        }