public static string ToFriendlyString(this VersionRange version)
 {
     if (version.Equals(VersionRange.All))
     {
         return("all");
     }
     if (version.Equals(VersionRange.None))
     {
         return("none");
     }
     return(version.PrettyPrint()
            .TrimStart('(')
            .TrimEnd(')'));
 }
예제 #2
0
        public static void AddPackageDependency(PackageDependency dependency, ISet <PackageDependency> set)
        {
            var matchingDependency = set.SingleOrDefault(r => r.Id == dependency.Id);

            if (matchingDependency != null)
            {
                VersionRange newVersionRange = VersionRange.CommonSubSet(new VersionRange[]
                {
                    matchingDependency.VersionRange, dependency.VersionRange
                });
                if (!newVersionRange.Equals(VersionRange.None))
                {
                    set.Remove(matchingDependency);
                    set.Add(new PackageDependency(dependency.Id, newVersionRange, dependency.Include, dependency.Exclude));
                }
                else
                {
                    throw new InvalidOperationException($"Package version constraints for {dependency.Id} return a version range that is empty.");
                }
            }
            else
            {
                set.Add(dependency);
            }
        }
예제 #3
0
 public static void AddLibraryDependency(LibraryDependency dependency, ISet <LibraryDependency> list)
 {
     if (list.Any(r => r.Name == dependency.Name))
     {
         var          matchingDependency = list.Single(r => r.Name == dependency.Name);
         VersionRange newVersionRange    = VersionRange.CommonSubSet(new VersionRange[]
         {
             matchingDependency.LibraryRange.VersionRange, dependency.LibraryRange.VersionRange
         });
         if (!newVersionRange.Equals(VersionRange.None))
         {
             list.Remove(matchingDependency);
             list.Add(new LibraryDependency()
             {
                 LibraryRange   = new LibraryRange(matchingDependency.Name, newVersionRange, LibraryDependencyTarget.All),
                 IncludeType    = dependency.IncludeType & matchingDependency.IncludeType,
                 SuppressParent = dependency.SuppressParent & matchingDependency.SuppressParent
             });
         }
         else
         {
             throw new InvalidOperationException($"Package version constraints for {dependency.Name} return a version range that is empty.");
         }
     }
     else
     {
         list.Add(dependency);
     }
 }
예제 #4
0
        public virtual void TestIsEqual()
        {
            VersionRange range1 = VersionRange.Parse("[1.1.0.1,1.1.0.3)");
            VersionRange range2 = VersionRange.Parse(range1.ToString());

            Assert.IsTrue(range1.Equals(range2));
        }
        public static string SimplePrint(this VersionRange range)
        {
            if (range.Equals(VersionRange.All) || range.Equals(VersionRange.AllStable))
            {
                return("All");
            }

            if (range.Equals(VersionRange.None))
            {
                return("None");
            }

            var minVersion = range.MinVersion;
            var maxVersion = range.MaxVersion;

            if (range.HasUpperBound && maxVersion.IsPrerelease)
            {
                var message = $"Pre release not allowed on upper bound '{range}'.";
                throw new Exception(message);
            }

            if (range.HasLowerBound && minVersion.IsPrerelease && !range.IsMinInclusive)
            {
                var message = $"Pre release not allowed on non-inclusive lower bound '{range}'.";
                throw new Exception(message);
            }

            if (range.HasLowerAndUpperBounds)
            {
                if (minVersion.Minor == 0 &&
                    minVersion.Patch == 0 &&
                    maxVersion.Minor == 0 &&
                    maxVersion.Patch == 0)
                {
                    if (range.IsMinInclusive &&
                        !range.IsMaxInclusive &&
                        minVersion.Major + 1 == maxVersion.Major)
                    {
                        return(minVersion.SimplePrint());
                    }
                }


                // single version
                if (maxVersion.Equals(minVersion) && range.IsMinInclusive && range.IsMaxInclusive)
                {
                    return(minVersion.SimplePrint());
                }

                // TODO:
                //if (minVersion.Equals(maxVersion.p) && range.IsMinInclusive && range.IsMaxInclusive)
                //{
                //    return minVersion.SimplePrint();
                //}
            }

            var builder = StringBuilderCache.Acquire();

            // normal range

            if (range.HasLowerBound)
            {
                if (range.IsMinInclusive)
                {
                    builder.Append(minVersion.SimplePrint());
                }
                else
                {
                    builder.Append(minVersion.NextVersion());
                }
            }
            else
            {
                builder.Append("N");
            }


            if (range.HasUpperBound)
            {
                if (range.IsMaxInclusive)
                {
                    builder.Append(" - ");
                    builder.Append(maxVersion.SimplePrint());
                }
                else
                {
                    var previousVersion2 = maxVersion.PreviousVersion2();
                    if (previousVersion2 > minVersion)
                    {
                        builder.Append(" - ");
                        builder.Append(maxVersion.PreviousVersion());
                    }
                }
            }
            else
            {
                builder.Append(" - ");
                builder.Append("N");
            }

            return(StringBuilderCache.GetStringAndRelease(builder));
        }
예제 #6
0
        public void VersionSpecTest1()
        {
            VersionSpec left      = new VersionRange(1, 2);
            VersionSpec rightpos  = new VersionRange(1, 2);
            VersionSpec rightneg1 = new VersionRange(1, 4);
            VersionSpec rightneg2 = new Revision(1);
            VersionSpec rightnull = null;

            Assert.IsTrue(left.Equals(rightpos));
            Assert.IsFalse(left.Equals(rightneg1));
            Assert.IsFalse(left.Equals(rightneg2));
            Assert.IsFalse(left.Equals(rightnull));

            left      = new HeadRevision();
            rightpos  = new HeadRevision();
            rightneg1 = new HaveRevision();
            rightnull = null;

            Assert.IsTrue(left.Equals(rightpos));
            Assert.IsFalse(left.Equals(rightneg1));
            Assert.IsFalse(left.Equals(rightnull));

            left      = new HaveRevision();
            rightpos  = new HaveRevision();
            rightneg1 = new HeadRevision();
            rightnull = null;

            Assert.IsTrue(left.Equals(rightpos));
            Assert.IsFalse(left.Equals(rightneg1));
            Assert.IsFalse(left.Equals(rightnull));

            left      = new NoneRevision();
            rightpos  = new NoneRevision();
            rightneg1 = new HaveRevision();
            rightnull = null;

            Assert.IsTrue(left.Equals(rightpos));
            Assert.IsFalse(left.Equals(rightneg1));
            Assert.IsFalse(left.Equals(rightnull));

            left      = new Revision(1);
            rightpos  = new Revision(1);
            rightneg1 = new Revision(3);
            rightneg2 = new VersionRange(1, 4);
            rightnull = null;

            Assert.IsTrue(left.Equals(rightpos));
            Assert.IsFalse(left.Equals(rightneg1));
            Assert.IsFalse(left.Equals(rightneg2));
            Assert.IsFalse(left.Equals(rightnull));

            left      = new DateTimeVersion(DateTime.MinValue);
            rightpos  = new DateTimeVersion(DateTime.MinValue);
            rightneg1 = new DateTimeVersion(DateTime.MaxValue);
            rightneg2 = new Revision(3);
            rightnull = null;

            Assert.IsTrue(left.Equals(rightpos));
            Assert.IsFalse(left.Equals(rightneg1));
            Assert.IsFalse(left.Equals(rightneg2));
            Assert.IsFalse(left.Equals(rightnull));

            left      = new LabelNameVersion("label_name");
            rightpos  = new LabelNameVersion("label_name");
            rightneg1 = new LabelNameVersion("wrong_label_name");
            rightneg2 = new Revision(3);
            rightnull = null;

            Assert.IsTrue(left.Equals(rightpos));
            Assert.IsFalse(left.Equals(rightneg1));
            Assert.IsFalse(left.Equals(rightneg2));
            Assert.IsFalse(left.Equals(rightnull));

            left      = new ChangelistIdVersion(44444);
            rightpos  = new ChangelistIdVersion(44444);
            rightneg1 = new ChangelistIdVersion(88888);
            rightneg2 = new Revision(3);
            rightnull = null;

            Assert.IsTrue(left.Equals(rightpos));
            Assert.IsFalse(left.Equals(rightneg1));
            Assert.IsFalse(left.Equals(rightneg2));
            Assert.IsFalse(left.Equals(rightnull));

            left      = new ClientNameVersion("client_name");
            rightpos  = new ClientNameVersion("client_name");
            rightneg1 = new ClientNameVersion("wrong_client_name");
            rightneg2 = new Revision(3);
            rightnull = null;

            Assert.IsTrue(left.Equals(rightpos));
            Assert.IsFalse(left.Equals(rightneg1));
            Assert.IsFalse(left.Equals(rightneg2));
            Assert.IsFalse(left.Equals(rightnull));

            left      = new ActionVersion("#add");
            rightpos  = new ActionVersion("#add");
            rightneg1 = new ActionVersion("#branch");
            rightneg2 = new Revision(3);
            rightnull = null;

            Assert.IsTrue(left.Equals(rightpos));
            Assert.IsFalse(left.Equals(rightneg1));
            Assert.IsFalse(left.Equals(rightneg2));
            Assert.IsFalse(left.Equals(rightnull));
        }