Ejemplo n.º 1
0
 public static IPackageInfo Find(this ILookup<string, IPackageInfo> packages, PackageDependency dependency)
 {
     if (!packages.Contains(dependency.Name))
         return null;
     return (from package in packages[dependency.Name]
             where package.Version != null && dependency.IsFulfilledBy(package.Version)
             orderby package.Version descending
             select package).FirstOrDefault();
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Applies the override, if it's relevant to the dependency, to produce a modified dependency.
 /// </summary>
 public PackageDependency Apply(PackageDependency dependency)
 {
     if (dependency.Name == OldPackage)
     {
         // TODO: Should we create a new PackageDependency instance instead?
         // Might be a good idea to make these objects immutable...
         dependency.Name = NewPackage;
     }
     return dependency;
 }
Ejemplo n.º 3
0
        public static IEnumerable<IPackageInfo> FindAll(this ILookup<string, IPackageInfo> packages, PackageDependency dependency)
        {
            if (!packages.Contains(dependency.Name))
                return Enumerable.Empty<IPackageInfo>();

            return (from package in packages[dependency.Name]
                    where package.Version != null && dependency.IsFulfilledBy(package.Version)
                    orderby package.Version descending
                    select package).ToList();
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Applies the override, if it's relevant to the dependency, to produce a modified dependency.
 /// </summary>
 public PackageDependency Apply(PackageDependency dependency)
 {
     if (dependency.Name.EqualsNoCase(OldPackage))
     {
         // TODO: Should we create a new PackageDependency instance instead?
         // Might be a good idea to make these objects immutable...
        return new PackageDependencyBuilder(dependency).Name(NewPackage);
     }
     return dependency;
 }
Ejemplo n.º 5
0
 KeyValuePair<PackageIdentifier, IPackageInfo>? NextAvailablePackageVersion(IEnumerable<PackageIdentifier> seen, PackageDependency dependency)
 {
     return (from packageById in from repo in _repositories
                                 from package in repo.FindAll(dependency)
                                 where _selectionContext.IsIgnored(package.Identifier) == false
                                 group package by package.Identifier
             where seen.Contains(packageById.Key) == false && packageById.Count() > 0
             orderby packageById.Key.Version descending
             select new KeyValuePair<PackageIdentifier, IPackageInfo>?(
                     new KeyValuePair<PackageIdentifier, IPackageInfo>(
                             packageById.Key,
                             packageById.First())))
             .FirstOrDefault();
 }
Ejemplo n.º 6
0
        public static IPackageInfo Find(this ILookup<string, IPackageInfo> packages, PackageDependency dependency)
        {
            if (!packages.Contains(dependency.Name))
                return null;

            var allMatchingPackages = from package in packages[dependency.Name]
                                      where package.Version != null && dependency.IsFulfilledBy(package.Version)
                                      orderby package.Version descending
                                      select package;

            // only remove nuked versions if it's not an exact match
            var bestMatching = allMatchingPackages.FirstOrDefault();

            if (bestMatching != null)
            {
                if (dependency.IsExactlyFulfilledBy(bestMatching.Version))
                    return bestMatching;
            }

            // remove any nuked versions before returning the best match
            return (from package in allMatchingPackages
                    where !package.Nuked
                    select package).FirstOrDefault();
        }
Ejemplo n.º 7
0
 PackageDependency ApplyPackageNameOverride(PackageDependency originalDependency)
 {
     return _nameOverrides.Aggregate(originalDependency, (modifiedDependency, wrapOverride) => wrapOverride.Apply(modifiedDependency));
 }
Ejemplo n.º 8
0
 PackageDependency ApplyPackageHintOverride(PackageDependency originalDependency)
 {
     return _hints.ContainsKey(originalDependency.Name) ? _hints[originalDependency.Name] : originalDependency;
 }
Ejemplo n.º 9
0
        bool VisitPackageVersions(PackageDependency dependency)
        {
            KeyValuePair<PackageIdentifier, IPackageInfo>? packageVersion;
            var seen = new List<PackageIdentifier>();
            while ((packageVersion = NextAvailablePackageVersion(seen, dependency)) != null)
            {
                seen.Add(packageVersion.Value.Key);
                _selectionContext.Trying(packageVersion.Value.Key);
                PushStack(packageVersion.Value.Key);

                IPackageInfo package = packageVersion.Value.Value;
                if (package != null && VisitDependencies(package.Dependencies))
                {
                    _selectionContext.PackageSucceeds(packageVersion.Value.Key, CurrentCallStack);
                    PopStack();
                    WriteDebug("VisitPackage version Succeeded");
                    return true;
                }
                _selectionContext.PackageHasChildrenConflicting(packageVersion.Value.Key);
                PopStack();
                WriteDebug("VisitPackage version failed");
            }
            WriteDebug("VisitPackage failed");
            if (seen.Empty())
            {
                _notFound.Add(new KeyValuePair<PackageDependency, CallStack>(dependency, CurrentCallStack));
            }
            return false;
        }
Ejemplo n.º 10
0
        bool VisitDependency(PackageDependency dependency)
        {
            try
            {
                dependency = ApplyPackageHintOverride(ApplyPackageNameOverride(dependency));
                PushStack(dependency);

                var existing = _selectionContext.SelectedPackageByName(dependency.Name);
                if (existing != null && existing.IsCompatibleWith(dependency))
                {
                    WriteDebug("VisitDependencies existing version compatible");
                    PushStack(existing);
                    _selectionContext.ExistingPackageCompatible(existing, CurrentCallStack);
                    PopStack();
                    return true;
                }
                if (existing != null)
                {
                    _selectionContext.Trying(existing);
                    _selectionContext.PackageConflicts(existing, CurrentCallStack);

                    WriteDebug("VisitDependencies existing version failed");
                    return false;
                }

                if (!VisitPackageVersions(dependency))
                {

                    WriteDebug("VisitDependencies failed");
                    return false;
                }
                return true;
            }
            finally
            {
                PopStack();
            }
        }
Ejemplo n.º 11
0
 public PackageDependencyBuilder(PackageDependency dep)
 {
     _name = dep.Name;
     _tags = new List<string>(dep.Tags);
     _versions = new List<VersionVertex>(dep.VersionVertices);
 }
Ejemplo n.º 12
0
 public IEnumerable<IPackageInfo> FindAll(PackageDependency dependency)
 {
     return PackagesByName.FindAll(dependency);
 }
Ejemplo n.º 13
0
 static PackageDependency CreateDependency(XmlNode xmlNode)
 {
     var dep = new PackageDependency
     {
         Name = (xmlNode.Attributes["id"] ?? xmlNode.Attributes["id", NuSpecSchema]).Value
     };
     var version = xmlNode.Attributes["version"] ?? xmlNode.Attributes["version", NuSpecSchema];
     var minversion = xmlNode.Attributes["minversion"] ?? xmlNode.Attributes["minversion", NuSpecSchema];
     var maxversion = xmlNode.Attributes["maxversion"] ?? xmlNode.Attributes["maxversion", NuSpecSchema];
     if (version != null)
         dep.VersionVertices.Add(new ExactVersionVertex(version.Value.ToVersion()));
     if (minversion != null)
         dep.VersionVertices.Add(new GreaterThenOrEqualVersionVertex(minversion.Value.ToVersion()));
     if (maxversion != null)
         dep.VersionVertices.Add(new LessThanVersionVertex(maxversion.Value.ToVersion()));
     return dep;
 }
Ejemplo n.º 14
0
 public DependencyNotFoundInRepositories(PackageDependency dependency, IEnumerable<IPackageRepository> repositories)
 {
     Dependency = dependency;
     Repositories = repositories;
 }
Ejemplo n.º 15
0
 public PackageDependency(PackageDependency copy)
 {
     VersionVertices = new List<VersionVertex>(copy.VersionVertices);
     Tags = new List<string>(copy.Tags);
     Name = copy.Name;
 }
Ejemplo n.º 16
0
        IEnumerable<ICommandOutput> ValidateInputs()
        {
            _dependency = FindDependencyByName();
            if (_dependency == null)
            {
                yield return new Error("Dependency not found: " + Name);
                yield break;
            }

            var gotVersion = Version != null;
            var gotMinVersion = MinVersion != null;
            var gotMaxVersion = MaxVersion != null;
            var numberOfVersionInputTypes = (new[] { gotVersion, (gotMinVersion || gotMaxVersion), AnyVersion }).Count(v => v);

            if (numberOfVersionInputTypes > 1)
            {
                yield return new Error("Arguments for 'version', 'version boundaries' and 'anyVersion' cannot be combined.");
                yield break;
            }

            if (gotVersion && Version.ToVersion() == null)
            {
                yield return new Error("Could not parse version: " + Version);
                yield break;
            }

            if (gotMinVersion && MinVersion.ToVersion() == null)
            {
                yield return new Error("Could not parse minversion: " + MinVersion);
                yield break;
            }

            if (gotMaxVersion && MaxVersion.ToVersion() == null)
            {
                yield return new Error("Could not parse maxversion: " + MaxVersion);
                yield break;
            }
        }
Ejemplo n.º 17
0
 PackageDependency UpdatedDependency(PackageDependency dependency)
 {
     var builder = new PackageDependencyBuilder(dependency);
     if (_content.HasValue)
     {
         builder = builder.Content(_content.Value);
     }
     if (_anchored.HasValue)
     {
         builder = builder.Anchored(_anchored.Value);
     }
     if (SomeVersionInputGiven)
     {
         builder = builder.SetVersionVertices(Enumerable.Empty<VersionVertex>());
     }
     if (AnyVersion)
     {
         builder = builder.VersionVertex(new AnyVersionVertex());
     }
     if (Version != null)
     {
         builder = builder.VersionVertex(new ExactVersionVertex(Version.ToVersion()));
     }
     if (MinVersion != null)
     {
         builder = builder.VersionVertex(new GreaterThenOrEqualVersionVertex(MinVersion.ToVersion()));
     }
     if (MaxVersion != null)
     {
         builder = builder.VersionVertex(new LessThanVersionVertex(MaxVersion.ToVersion()));
     }
     return builder;
 }
Ejemplo n.º 18
0
 void UpdatedDependency(PackageDependency dependency)
 {
     if (_content.HasValue)
     {
         dependency.ContentOnly = _content.Value;
     }
     if (_anchored.HasValue)
     {
         dependency.Anchored = _anchored.Value;
     }
     if (SomeVersionInputGiven)
     {
         dependency.VersionVertices.Clear();
     }
     if (AnyVersion)
     {
         dependency.VersionVertices.Add(new AnyVersionVertex());
     }
     if (Version != null)
     {
         dependency.VersionVertices.Add(new ExactVersionVertex(Version.ToVersion()));
     }
     if (MinVersion != null)
     {
         dependency.VersionVertices.Add(new GreaterThenOrEqualVersionVertex(MinVersion.ToVersion()));
     }
     if (MaxVersion != null)
     {
         dependency.VersionVertices.Add(new LessThanVersionVertex(MaxVersion.ToVersion()));
     }
 }
Ejemplo n.º 19
0
 public IPackageInfo Find(PackageDependency dependency)
 {
     return PackagesByName.Find(dependency);
 }
Ejemplo n.º 20
0
 public ParentedDependency(PackageDependency dependency, ParentedDependency parent)
 {
     Dependency = dependency;
     Parent = parent;
 }
 public void sonic_is_changed_to_super_sonic()
 {
     var sonic = new PackageDependency { Name = "sonic" };
     PackageNameOverride.Apply(sonic);
     sonic.Name.ShouldBe("super-sonic");
 }
Ejemplo n.º 22
0
 void PushStack(PackageDependency dependency)
 {
     _currentNode.Push(new DependencyNode(dependency));
     WriteDebug("D:" + dependency);
 }
 public void tails_is_still_tails()
 {
     var tails = new PackageDependency { Name = "tails" };
     PackageNameOverride.Apply(tails);
     tails.Name.ShouldBe("tails");
 }
Ejemplo n.º 24
0
 public DependencyNode(PackageDependency dependency)
 {
     Dependency = dependency;
 }