Example #1
0
        public DependencyResolutionResult TryResolveDependencies(IPackageDescriptor packageDescriptor, IEnumerable <IPackageRepository> repositoriesToQuery)
        {
            var packageSelection = new PackageSelectionContext();

            Debug.WriteLine("Resolving descriptor " + packageDescriptor.Dependencies.Select(x => x.ToString()).JoinString(", "));
            for (int i = 0; i < MAX_RETRIES; i++)
            {
                var exclusionList = packageSelection.IncompatiblePackageVersions.Select(x => x.Key);

                var visitor             = new DependencyVisitor(repositoriesToQuery.Packages(), packageSelection, packageDescriptor.Dependencies, packageDescriptor.Overrides);
                var resolutionSucceeded = visitor.VisitDependencies(packageDescriptor.Dependencies);

                if (resolutionSucceeded == false)
                {
                    var newExclusionList = packageSelection.IncompatiblePackageVersions.Select(x => x.Key);
                    if (newExclusionList.Except(exclusionList).Any())
                    {
                        packageSelection = new PackageSelectionContext(packageSelection.IncompatiblePackageVersions);

                        continue;
                    }
                }
                return(Result(packageDescriptor, packageSelection, repositoriesToQuery, visitor.NotFound));
            }
            throw new InvalidOperationException(string.Format("OpenWrap tried {0} times to resolve the tree of dependencies and gave up.", MAX_RETRIES));
        }
Example #2
0
        public DependencyVisitor(IEnumerable <IPackageRepository> repositories,
                                 PackageSelectionContext selectionContext,
                                 IEnumerable <PackageDependency> hints,
                                 IEnumerable <PackageNameOverride> nameOverrides)
        {
            Check.NotNull(selectionContext, "selectionContext");
            Check.NoNullElements(repositories, "repositories");
            Check.NoNullElements(hints, "hints");
            Check.NoNullElements(nameOverrides, "nameOverrides");

            _repositories     = repositories;
            _selectionContext = selectionContext;
            _nameOverrides    = nameOverrides;
            _hints            = hints.ToDictionary(x => x.Name, StringComparer.OrdinalIgnoreCase);
            _notFound         = new List <KeyValuePair <PackageDependency, CallStack> >();
        }
Example #3
0
        DependencyResolutionResult Result(IPackageDescriptor descriptor,
                                          PackageSelectionContext packageSelectionContext,
                                          IEnumerable <IPackageRepository> repositoriesToQuery,
                                          IEnumerable <IGrouping <PackageDependency, CallStack> > notFound)
        {
            var success = (from compatible in packageSelectionContext.CompatiblePackageVersions
                           let id = compatible.Key
                                    let packages = from repo in repositoriesToQuery
                                                   from package in repo.PackagesByName.FindAll(ToDependency(id))
                                                   select package
                                                   select new ResolvedPackage(id, packages.ToList(), compatible.Value.Successful))
                          .ToList();
            var missing = from callStacks in notFound
                          select new ResolvedPackage(new PackageIdentifier(callStacks.Key.Name), Enumerable.Empty <IPackageInfo>(), callStacks.ToList());
            var conflicting = from incompat in packageSelectionContext.IncompatiblePackageVersions.GroupBy(x => x.Key, x => x.Value)
                              select new ResolvedPackage(incompat.Key, Enumerable.Empty <IPackageInfo>(), incompat.SelectMany(x => x.Failed.Concat(x.Successful)));

            return(new DependencyResolutionResult(descriptor, success, conflicting, missing));
        }