From 8384736bacc6a5cdd577351fb14ff1d174591791 Mon Sep 17 00:00:00 2001 From: Max Malook Date: Sat, 15 Nov 2014 22:26:12 +0100 Subject: [PATCH] correct handling of package dependencies containing nuget --- src/Paket.Core/DependenciesFile.fs | 16 ++++++++-------- src/Paket.Core/LockFile.fs | 8 ++++---- src/Paket.Core/Utils.fs | 6 ++++++ .../Paket.Tests/DependenciesFile/ParserSpecs.fs | 11 ++++++++++- 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/Paket.Core/DependenciesFile.fs b/src/Paket.Core/DependenciesFile.fs index db24a748f8..9d488c7b96 100644 --- a/src/Paket.Core/DependenciesFile.fs +++ b/src/Paket.Core/DependenciesFile.fs @@ -126,9 +126,9 @@ module DependenciesFileParser = let private (|Remote|Package|Blank|ReferencesMode|OmitContent|SourceFile|) (line:string) = match line.Trim() with | _ when String.IsNullOrWhiteSpace line -> Blank - | trimmed when trimmed.StartsWith "source" -> Remote(PackageSource.Parse(trimmed)) - | trimmed when trimmed.StartsWith "nuget" -> - let parts = trimmed.Replace("nuget","").Trim().Replace("\"", "").Split([|' '|],StringSplitOptions.RemoveEmptyEntries) |> Seq.toList + | String.StartsWith "source" _ as trimmed -> Remote(PackageSource.Parse(trimmed)) + | String.StartsWith "nuget" trimmed -> + let parts = trimmed.Trim().Replace("\"", "").Split([|' '|],StringSplitOptions.RemoveEmptyEntries) |> Seq.toList let isVersion(text:string) = match Int32.TryParse(text.[0].ToString()) with @@ -145,13 +145,13 @@ module DependenciesFileParser = | name :: rest -> Package(name,">= 0 " + String.Join(" ",rest)) | name :: [] -> Package(name,">= 0") | _ -> failwithf "could not retrieve nuget package from %s" trimmed - | trimmed when trimmed.StartsWith "references" -> ReferencesMode(trimmed.Replace("references","").Trim() = "strict") - | trimmed when trimmed.StartsWith "content" -> OmitContent(trimmed.Replace("content","").Trim() = "none") - | trimmed when trimmed.StartsWith "gist" -> + | String.StartsWith "references" trimmed -> ReferencesMode(trimmed.Trim() = "strict") + | String.StartsWith "content" trimmed -> OmitContent(trimmed.Trim() = "none") + | String.StartsWith "gist" _ as trimmed -> SourceFile(``parse git source`` trimmed SingleSourceFileOrigin.GistLink "gist") - | trimmed when trimmed.StartsWith "github" -> + | String.StartsWith "github" _ as trimmed -> SourceFile(``parse git source`` trimmed SingleSourceFileOrigin.GitHubLink "github") - | trimmed when trimmed.StartsWith "http" -> + | String.StartsWith "http" _ as trimmed -> SourceFile(``parse http source`` trimmed) | _ -> Blank diff --git a/src/Paket.Core/LockFile.fs b/src/Paket.Core/LockFile.fs index 15bddf5243..0485f40e56 100644 --- a/src/Paket.Core/LockFile.fs +++ b/src/Paket.Core/LockFile.fs @@ -103,10 +103,10 @@ module LockFileParser = | _, "NUGET" -> RepositoryType "NUGET" | _, "GITHUB" -> RepositoryType "GITHUB" | _, _ when String.IsNullOrWhiteSpace line -> Blank - | _, trimmed when trimmed.StartsWith "remote:" -> Remote(trimmed.Substring(trimmed.IndexOf(": ") + 2).Split(' ').[0]) - | _, trimmed when trimmed.StartsWith "specs:" -> Blank - | _, trimmed when trimmed.StartsWith "REFERENCES:" -> InstallOption(StrictCase,trimmed.Replace("REFERENCES:","").Trim() = "STRICT") - | _, trimmed when trimmed.StartsWith "CONTENT:" -> InstallOption(OmitContentCase,trimmed.Replace("CONTENT:","").Trim() = "NONE") + | _, String.StartsWith "remote:" trimmed -> Remote(trimmed.Trim().Split(' ').[0]) + | _, String.StartsWith "specs:" _ -> Blank + | _, String.StartsWith "REFERENCES:" trimmed -> InstallOption(StrictCase,trimmed.Trim() = "STRICT") + | _, String.StartsWith "CONTENT:" trimmed -> InstallOption(OmitContentCase,trimmed.Trim() = "NONE") | _, trimmed when line.StartsWith " " -> let parts = trimmed.Split '(' NugetDependency (parts.[0].Trim(),parts.[1].Replace("(", "").Replace(")", "").Trim()) diff --git a/src/Paket.Core/Utils.fs b/src/Paket.Core/Utils.fs index 7ddcbec63d..0eebfa656b 100644 --- a/src/Paket.Core/Utils.fs +++ b/src/Paket.Core/Utils.fs @@ -170,3 +170,9 @@ let FindAllFiles(folder, pattern) = DirectoryInfo(folder).EnumerateFiles(pattern /// [omit] module Seq = let firstOrDefault seq = Seq.tryFind (fun _ -> true) seq + +module String = + let (|StartsWith|_|) prefix (input: string) = + if input.StartsWith prefix then + Some (input.Substring(prefix.Length)) + else None diff --git a/tests/Paket.Tests/DependenciesFile/ParserSpecs.fs b/tests/Paket.Tests/DependenciesFile/ParserSpecs.fs index e59930d693..ad4643aafc 100644 --- a/tests/Paket.Tests/DependenciesFile/ParserSpecs.fs +++ b/tests/Paket.Tests/DependenciesFile/ParserSpecs.fs @@ -390,4 +390,13 @@ nuget Nancy.Owin 0.22.2 let ``should read config with local source``() = let cfg = DependenciesFile.FromCode(configWithLocalSource) - cfg.DirectDependencies.["Nancy.Owin"].Range |> shouldEqual (VersionRange.Specific (SemVer.Parse "0.22.2")) \ No newline at end of file + cfg.DirectDependencies.["Nancy.Owin"].Range |> shouldEqual (VersionRange.Specific (SemVer.Parse "0.22.2")) + +[] +let ``should read config with package name containing nuget``() = + let config = """ + nuget nuget.Core 0.1 + """ + let cfg = DependenciesFile.FromCode(config) + + cfg.DirectDependencies.["nuget.Core"].Range |> shouldEqual (VersionRange.Specific (SemVer.Parse "0.1"))