public virtual List <IPackage> GetPackagesMatchingDependencies(params PackageDependency[] dependencies) { // Requestoring.Requestor.Global.Verbose = true; var id = dependencies.First().PackageId; var packages = GetPackagesWithId(id); return(packages.Where(pkg => PackageDependency.MatchesAll(pkg, dependencies)).ToList()); }
public virtual List <IPackage> GetPackagesMatchingDependencies(params PackageDependency[] dependencies) { return(Packages.Where(pkg => PackageDependency.MatchesAll(pkg, dependencies)).ToList()); }
static List <RemotePackage> FindDependencies(IDictionary <string, List <PackageDependency> > discoveredDependencies, Package[] packages, params List <RemotePackage>[] listsOfPackages) { var found = new List <RemotePackage>(); var packageIds = packages.Select(p => p.Id); bool throwIfMissing = (discoveredDependencies == null); // if this is null, then we're not recursing // TODO this should be pulled out into its own method that JUST returns a list of PackageDependency for us to find // // get ALL of the dependencies for these packages, grouped by package Id // eg. { "log4net" => ["log4net > 2.0", "log4net < 2.5"] } var allDependencies = new Dictionary <string, List <PackageDependency> >(); foreach (var package in packages) { foreach (var packageDependency in package.Dependencies) { if (packageIds.Contains(packageDependency.PackageId)) { continue; } if (!allDependencies.ContainsKey(packageDependency.PackageId)) { allDependencies[packageDependency.PackageId] = new List <PackageDependency>(); } if (!allDependencies[packageDependency.PackageId].Contains(packageDependency)) { allDependencies[packageDependency.PackageId].Add(packageDependency); } } } // add these packages' dependencies into discoveredDependencies. // we track these to know whether or not we're missing any dependencies for any of the packages found. if (discoveredDependencies == null) { discoveredDependencies = new Dictionary <string, List <PackageDependency> >(); } foreach (var packageDependency in allDependencies) { var dependencyId = packageDependency.Key; var dependencies = packageDependency.Value.ToArray(); if (!discoveredDependencies.ContainsKey(dependencyId)) { discoveredDependencies[dependencyId] = new List <PackageDependency>(); } foreach (var dependency in dependencies) { if (!discoveredDependencies[dependencyId].Contains(dependency)) { discoveredDependencies[dependencyId].Add(dependency); } } } foreach (var packageDependency in allDependencies) { var dependencyId = packageDependency.Key; var dependencies = packageDependency.Value.ToArray(); // go through all sources and get the *latest* version of this dependency (that matches) RemotePackage dependencyPackage = null; foreach (var sourcePackages in listsOfPackages) { var match = sourcePackages.Where(pkg => pkg.Id == dependencyId && PackageDependency.MatchesAll(pkg.Version, dependencies)).OrderBy(pkg => pkg.Version).Reverse().FirstOrDefault(); if (match != null) { if (dependencyPackage == null || dependencyPackage.Version < match.Version) { dependencyPackage = match; } } } if (dependencyPackage != null) { found.Add(dependencyPackage); if (dependencyPackage.Dependencies.Any()) { found.AddRange(Package.FindDependencies(discoveredDependencies, new Package[] { dependencyPackage }, listsOfPackages)); // <--- recurse! } } else { Console.WriteLine("Could not find dependency: {0}", dependencyId); } } // throw a MissingDependencyException if any of the discovered dependencies were not found if (throwIfMissing) { var foundIds = found.Select(pkg => pkg.Id); var missing = new List <PackageDependency>(); foreach (var dependencyPackage in discoveredDependencies) { if (!foundIds.Contains(dependencyPackage.Key)) { missing.AddRange(dependencyPackage.Value); } } if (missing.Count > 0) { throw new MissingDependencyException(missing); } } // TODO instead of just doing a Distinct(), we need to actually inspect the dependencies ... // do not include any of the packages that were passed in as dependencies return(found.Where(pkg => !packageIds.Contains(pkg.Id)).Distinct().ToList()); }