From 99d2a42c2498541d2ee6a7b7cf02a6642753322c Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Tue, 29 Sep 2015 10:11:13 +0200 Subject: [PATCH] Allow to format PackageRequirements in Nuget syntax --- RELEASE_NOTES.md | 3 + src/Paket.Core/NupkgWriter.fs | 13 +--- src/Paket.Core/VersionRange.fs | 66 ++++++++++++------- src/Paket/Paket.fsproj | 4 +- .../VersionRequirementSpecs.fs | 13 ++++ .../NugetVersionRangeSerializerSpecs.fs | 38 +++++------ 6 files changed, 80 insertions(+), 57 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index bb22ac79f6..b60a90ce90 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,3 +1,6 @@ +#### 2.4.10 - 29.09.2015 +* Įllow to format VersionRequirements in NuGet syntax + #### 2.4.9 - 29.09.2015 * BUGFIX: Fix KeyNotFoundException when project is net4.0-client - https://github.com/fsprojects/Paket/issues/1095 diff --git a/src/Paket.Core/NupkgWriter.fs b/src/Paket.Core/NupkgWriter.fs index cb11aa0c59..3a5b4cb3bd 100644 --- a/src/Paket.Core/NupkgWriter.fs +++ b/src/Paket.Core/NupkgWriter.fs @@ -80,19 +80,10 @@ let nuspecDoc (info:CompleteInfo) = frameworkAssembliesList |> List.iter (buildFrameworkReferencesNode >> d.Add) metadataNode.Add d - let buildDependencyNode (Id, (VersionRequirement(range, prerelease))) = + let buildDependencyNode (Id, requirement:VersionRequirement) = let dep = XElement(ns + "dependency") dep.SetAttributeValue(XName.Get "id", Id) - - let pre = - match prerelease with - | No -> "" - | Concrete [x] -> "-" + x - | _ -> "-prerelease" - - match range.FormatInNuGetSyntax() + pre with - | "0" -> () - | versionStr -> dep.SetAttributeValue(XName.Get "version", versionStr) + dep.SetAttributeValue(XName.Get "version", requirement.FormatInNuGetSyntax()) dep let buildDependenciesNode dependencyList = diff --git a/src/Paket.Core/VersionRange.fs b/src/Paket.Core/VersionRange.fs index c282c2046d..7d017e0d84 100644 --- a/src/Paket.Core/VersionRange.fs +++ b/src/Paket.Core/VersionRange.fs @@ -67,31 +67,6 @@ type VersionRange = from + " " + _to - /// formats a VersionRange in NuGet syntax - member this.FormatInNuGetSyntax() = - match this with - | Minimum(version) -> - match version.Normalize() with - | "0.0.0" -> "" - | x -> x - | GreaterThan(version) -> sprintf "(%s,)" (version.Normalize()) - | Maximum(version) -> sprintf "(,%s]" (version.Normalize()) - | LessThan(version) -> sprintf "(,%s)" (version.Normalize()) - | Specific(version) -> sprintf "[%s]" (version.Normalize()) - | OverrideAll(version) -> sprintf "[%s]" (version.Normalize()) - | Range(fromB, from,_to,_toB) -> - let getMinDelimiter (v:VersionRangeBound) = - match v with - | VersionRangeBound.Including -> "[" - | VersionRangeBound.Excluding -> "(" - - let getMaxDelimiter (v:VersionRangeBound) = - match v with - | VersionRangeBound.Including -> "]" - | VersionRangeBound.Excluding -> ")" - - sprintf "%s%s,%s%s" (getMinDelimiter fromB) (from.Normalize()) (_to.Normalize()) (getMaxDelimiter _toB) - type VersionRequirement = | VersionRequirement of VersionRange * PreReleaseStatus /// Checks wether the given version is in the version range @@ -203,6 +178,47 @@ type VersionRequirement = VersionRequirement(range,!prereleases) + /// Formats a VersionRequirement in NuGet syntax + member this.FormatInNuGetSyntax() = + match this with + | VersionRequirement(range,prerelease) -> + let pre = + match prerelease with + | No -> "" + | Concrete [x] -> "-" + x + | _ -> "-prerelease" + + let normalize (v:SemVerInfo) = v.Normalize() + pre + + let str = + match range with + | Minimum(version) -> + match normalize version with + | "0.0.0" -> "" + | x -> x + | GreaterThan(version) -> sprintf "(%s,)" (normalize version) + | Maximum(version) -> sprintf "(,%s]" (normalize version) + | LessThan(version) -> sprintf "(,%s)" (normalize version) + | Specific(version) -> sprintf "[%s]" (normalize version) + | OverrideAll(version) -> sprintf "[%s]" (normalize version) + | Range(fromB, from,_to,_toB) -> + let getMinDelimiter (v:VersionRangeBound) = + match v with + | VersionRangeBound.Including -> "[" + | VersionRangeBound.Excluding -> "(" + + let getMaxDelimiter (v:VersionRangeBound) = + match v with + | VersionRangeBound.Including -> "]" + | VersionRangeBound.Excluding -> ")" + + sprintf "%s%s,%s%s" (getMinDelimiter fromB) (normalize from) (normalize _to) (getMaxDelimiter _toB) + + + match str with + | "0" -> "" + | versionStr -> versionStr + /// Represents a resolver strategy. [] type ResolverStrategy = diff --git a/src/Paket/Paket.fsproj b/src/Paket/Paket.fsproj index b714687a13..360d6b4250 100644 --- a/src/Paket/Paket.fsproj +++ b/src/Paket/Paket.fsproj @@ -34,11 +34,11 @@ c:\code\Paket09x D:\code\Pakettest D:\code\Paketkopie - update + update nuget Vetserve.Appointments.Interop -v Project paket.exe c:\code\Paketkopie - d:\code\PaketKopie + d:\code\Paketrepro pdbonly diff --git a/tests/Paket.Tests/DependenciesFile/VersionRequirementSpecs.fs b/tests/Paket.Tests/DependenciesFile/VersionRequirementSpecs.fs index 4eccdb95e5..d89165eef3 100644 --- a/tests/Paket.Tests/DependenciesFile/VersionRequirementSpecs.fs +++ b/tests/Paket.Tests/DependenciesFile/VersionRequirementSpecs.fs @@ -26,6 +26,19 @@ let ``can order twiddle-wakka``() = parse "~> 2.2" |> shouldBeSmallerThan (parse "~> 2.3") parse "~> 1.2" |> shouldBeSmallerThan (parse "~> 2.3") +[] +let ``can parse twiddle-wakka with prerelease``() = + let req = DependenciesFileParser.parseVersionRequirement "~> 6.0.0 prerelease" + + req + |> shouldEqual + (VersionRequirement.VersionRequirement( + VersionRange.Range(VersionRangeBound.Including,SemVer.Parse("6.0.0"),SemVer.Parse("6.1.0"),VersionRangeBound.Excluding), + PreReleaseStatus.All)) + + req.FormatInNuGetSyntax() + |> shouldEqual "[6.0.0-prerelease,6.1.0-prerelease)" + [] let ``can order simple at least requirements in package requirement``() = require "A" ResolverStrategy.Max ">= 2.2" |> shouldBeGreaterThan (require "A" ResolverStrategy.Max ">= 2.3") diff --git a/tests/Paket.Tests/NugetVersionRangeSerializerSpecs.fs b/tests/Paket.Tests/NugetVersionRangeSerializerSpecs.fs index a2520fb49e..0831291b8e 100644 --- a/tests/Paket.Tests/NugetVersionRangeSerializerSpecs.fs +++ b/tests/Paket.Tests/NugetVersionRangeSerializerSpecs.fs @@ -8,40 +8,40 @@ open FsUnit let ``can format latest version``() = VersionRequirement.Parse "" |> shouldEqual VersionRequirement.AllReleases -let format(versionRange:VersionRange) = versionRange.FormatInNuGetSyntax() +let format(versionRange:VersionRange) = VersionRequirement(versionRange,PreReleaseStatus.No).FormatInNuGetSyntax() [] let ``can format specific version``() = - VersionRange.Specific(SemVer.Parse "2.2").FormatInNuGetSyntax() |> shouldEqual "[2.2.0]" - VersionRange.Specific(SemVer.Parse "1.2").FormatInNuGetSyntax() |> shouldEqual "[1.2.0]" + VersionRange.Specific(SemVer.Parse "2.2") |> format |> shouldEqual "[2.2.0]" + VersionRange.Specific(SemVer.Parse "1.2") |> format |> shouldEqual "[1.2.0]" [] let ``can format minimum version``() = - VersionRange.Minimum(SemVer.Parse "2.2").FormatInNuGetSyntax() |> shouldEqual "2.2.0" - VersionRange.Minimum(SemVer.Parse "1.2").FormatInNuGetSyntax() |> shouldEqual "1.2.0" - VersionRange.Minimum(SemVer.Parse "7").FormatInNuGetSyntax() |> shouldEqual "7.0.0" - VersionRange.Minimum(SemVer.Parse "0").FormatInNuGetSyntax() |> shouldEqual "" - VersionRange.Minimum(SemVer.Parse "1.0-beta").FormatInNuGetSyntax() |> shouldEqual "1.0.0-beta" + VersionRange.Minimum(SemVer.Parse "2.2") |> format |> shouldEqual "2.2.0" + VersionRange.Minimum(SemVer.Parse "1.2") |> format |> shouldEqual "1.2.0" + VersionRange.Minimum(SemVer.Parse "7") |> format |> shouldEqual "7.0.0" + VersionRange.Minimum(SemVer.Parse "0") |> format |> shouldEqual "" + VersionRange.Minimum(SemVer.Parse "1.0-beta") |> format |> shouldEqual "1.0.0-beta" [] let ``can format greater than version``() = - VersionRange.GreaterThan(SemVer.Parse "2.2").FormatInNuGetSyntax() |> shouldEqual "(2.2.0,)" - VersionRange.GreaterThan(SemVer.Parse "1.2").FormatInNuGetSyntax() |> shouldEqual "(1.2.0,)" + VersionRange.GreaterThan(SemVer.Parse "2.2") |> format |> shouldEqual "(2.2.0,)" + VersionRange.GreaterThan(SemVer.Parse "1.2") |> format |> shouldEqual "(1.2.0,)" [] let ``can format maximum version``() = - VersionRange.Maximum(SemVer.Parse "2.2").FormatInNuGetSyntax() |> shouldEqual "(,2.2.0]" - VersionRange.Maximum(SemVer.Parse "0").FormatInNuGetSyntax() |> shouldEqual "(,0.0.0]" - VersionRange.Maximum(SemVer.Parse "1.2").FormatInNuGetSyntax() |> shouldEqual "(,1.2.0]" + VersionRange.Maximum(SemVer.Parse "2.2") |> format |> shouldEqual "(,2.2.0]" + VersionRange.Maximum(SemVer.Parse "0") |> format |> shouldEqual "(,0.0.0]" + VersionRange.Maximum(SemVer.Parse "1.2") |> format |> shouldEqual "(,1.2.0]" [] let ``can format less than version``() = - VersionRange.LessThan(SemVer.Parse "2.2").FormatInNuGetSyntax() |> shouldEqual "(,2.2.0)" - VersionRange.LessThan(SemVer.Parse "1.2").FormatInNuGetSyntax() |> shouldEqual "(,1.2.0)" + VersionRange.LessThan(SemVer.Parse "2.2") |> format |> shouldEqual "(,2.2.0)" + VersionRange.LessThan(SemVer.Parse "1.2") |> format |> shouldEqual "(,1.2.0)" [] let ``can format range version``() = - VersionRange.Range(VersionRangeBound.Excluding, SemVer.Parse "2.2", SemVer.Parse "3", VersionRangeBound.Excluding).FormatInNuGetSyntax() |> shouldEqual "(2.2.0,3.0.0)" - VersionRange.Range(VersionRangeBound.Excluding, SemVer.Parse "2.2", SemVer.Parse "3", VersionRangeBound.Including).FormatInNuGetSyntax() |> shouldEqual "(2.2.0,3.0.0]" - VersionRange.Range(VersionRangeBound.Including, SemVer.Parse "2.2", SemVer.Parse "3", VersionRangeBound.Excluding).FormatInNuGetSyntax() |> shouldEqual "[2.2.0,3.0.0)" - VersionRange.Range(VersionRangeBound.Including, SemVer.Parse "2.2", SemVer.Parse "3", VersionRangeBound.Including).FormatInNuGetSyntax() |> shouldEqual "[2.2.0,3.0.0]" \ No newline at end of file + VersionRange.Range(VersionRangeBound.Excluding, SemVer.Parse "2.2", SemVer.Parse "3", VersionRangeBound.Excluding) |> format |> shouldEqual "(2.2.0,3.0.0)" + VersionRange.Range(VersionRangeBound.Excluding, SemVer.Parse "2.2", SemVer.Parse "3", VersionRangeBound.Including) |> format |> shouldEqual "(2.2.0,3.0.0]" + VersionRange.Range(VersionRangeBound.Including, SemVer.Parse "2.2", SemVer.Parse "3", VersionRangeBound.Excluding) |> format |> shouldEqual "[2.2.0,3.0.0)" + VersionRange.Range(VersionRangeBound.Including, SemVer.Parse "2.2", SemVer.Parse "3", VersionRangeBound.Including) |> format |> shouldEqual "[2.2.0,3.0.0]" \ No newline at end of file