diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 27e0f6381d..093ed82bec 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,3 +1,6 @@ +#### 0.2.0-alpha010 - 16.09.2014 +* Support cleaner syntax in paket.dependencies - https://github.com/fsprojects/Paket/pull/95 + #### 0.2.0-alpha009 - 16.09.2014 * Support content files from nuget - https://github.com/fsprojects/Paket/pull/84 diff --git a/src/Paket/DependenciesFile.fs b/src/Paket/DependenciesFile.fs index cf8a5253ee..e45cc0e4a1 100644 --- a/src/Paket/DependenciesFile.fs +++ b/src/Paket/DependenciesFile.fs @@ -7,10 +7,12 @@ open Paket /// [omit] module DependenciesFileParser = + let private basicOperators = ["~>";">=";"="] + let private operators = basicOperators @ (basicOperators |> List.map (fun o -> "!" + o)) + let parseVersionRange (text : string) : VersionRange = - let splitVersion (text:string) = - let tokens = ["~>";">=";"=" ] - match tokens |> List.tryFind(text.StartsWith) with + let splitVersion (text:string) = + match basicOperators |> List.tryFind(text.StartsWith) with | Some token -> token, text.Replace(token + " ", "") | None -> "=", text @@ -37,11 +39,16 @@ module DependenciesFileParser = let private (|Remote|Package|Blank|ReferencesMode|SourceFile|) (line:string) = match line.Trim() with | _ when String.IsNullOrWhiteSpace line -> Blank - | trimmed when trimmed.StartsWith "source" -> - let fst = trimmed.IndexOf("\"") - let snd = trimmed.IndexOf("\"",fst+1) - Remote (trimmed.Substring(fst,snd-fst).Replace("\"","")) - | trimmed when trimmed.StartsWith "nuget" -> Package(trimmed.Replace("nuget","").Trim()) + | trimmed when trimmed.StartsWith "source" -> + let parts = trimmed.Split ' ' + Remote (parts.[1].Replace("\"","")) + | trimmed when trimmed.StartsWith "nuget" -> + let parts = trimmed.Replace("nuget","").Trim().Replace("\"", "").Split ' ' |> Seq.toList + match parts with + | name :: operator :: version :: _ + when List.exists ((=) operator) operators -> Package(name,operator + " " + version) + | name :: version :: _ -> Package(name,version) + | _ -> failwithf "could not retrieve nuget package from %s" trimmed | trimmed when trimmed.StartsWith "references" -> ReferencesMode(trimmed.Replace("references","").Trim() = "strict") | trimmed when trimmed.StartsWith "github" -> let parts = trimmed.Replace("\"", "").Split ' ' @@ -64,14 +71,10 @@ module DependenciesFileParser = | Remote newSource -> lineNo, referencesMode, (PackageSource.Parse(newSource.TrimEnd([|'/'|])) :: sources), packages, sourceFiles | Blank -> lineNo, referencesMode, sources, packages, sourceFiles | ReferencesMode mode -> lineNo, mode, sources, packages, sourceFiles - | Package details -> - let parts = details.Split('"') - if parts.Length < 4 || String.IsNullOrWhiteSpace parts.[1] || String.IsNullOrWhiteSpace parts.[3] then - failwith "missing \"" - let version = parts.[3] + | Package(name,version) -> lineNo, referencesMode, sources, { Sources = sources - Name = parts.[1] + Name = name ResolverStrategy = if version.StartsWith "!" then ResolverStrategy.Min else ResolverStrategy.Max VersionRange = parseVersionRange(version.Trim '!') } :: packages, sourceFiles | SourceFile((owner,project, commit), path) -> diff --git a/tests/Paket.Tests/DependenciesFile/ParserSpecs.fs b/tests/Paket.Tests/DependenciesFile/ParserSpecs.fs index 9097ab937c..0231b93d3c 100644 --- a/tests/Paket.Tests/DependenciesFile/ParserSpecs.fs +++ b/tests/Paket.Tests/DependenciesFile/ParserSpecs.fs @@ -74,38 +74,6 @@ let ``should read config with multiple sources``() = (cfg.Packages |> List.find (fun p -> p.Name = "MinPackage")).Sources |> shouldEqual [Nuget "http://nuget.org/api/v3"; Nuget "http://nuget.org/api/v2"] (cfg.Packages |> List.find (fun p -> p.Name = "FAKE")).Sources |> shouldEqual [Nuget "http://nuget.org/api/v2"] -let config5 = """source "http://nuget.org/api/v2" - -nuget "RavenDB.Client" ">= 0" -nuget RavenDB.Server" ">= 0" // missing " -""" - -[] -let ``should report errors if pacakge misses "``() = - try - DependenciesFile.FromCode config5 |> ignore - failwith "No message given" - with - | exn -> - exn.Message.Contains("paket.dependencies") |> shouldEqual true - exn.Message.Contains("line 4") |> shouldEqual true - exn.Message.Contains("missing \"") |> shouldEqual true - -let config6 = """source "http://nuget.org/api/v2" -nuget "Fody" "1.25.0" -nuget "Obsolete.Fody" 3.1.0.0" // missing " -""" - -[] -let ``should report errors if version misses "``() = - try - DependenciesFile.FromCode config6 |> ignore - failwith "No message given" - with - | exn -> - exn.Message.Contains("paket.dependencies") |> shouldEqual true - exn.Message.Contains("line 3") |> shouldEqual true - exn.Message.Contains("missing \"") |> shouldEqual true let config7 = """nuget "Fody" "> 0" """ @@ -120,7 +88,7 @@ let ``should report errors if nuget is single``() = exn.Message.Contains("paket.dependencies") |> shouldEqual true exn.Message.Contains("line 1") |> shouldEqual true exn.Message.Contains("could not parse version range") |> shouldEqual true - exn.Message.Contains("> 0") |> shouldEqual true + exn.Message.Contains(">") |> shouldEqual true [] let ``should read source file from config``() = @@ -151,3 +119,41 @@ let ``should read strict config``() = cfg.Strict |> shouldEqual true (cfg.Packages |> List.find (fun p -> p.Name = "FAKE")).Sources |> shouldEqual [Nuget "http://nuget.org/api/v2"] + + +let configWithoutQuotes = """ +source http://nuget.org/api/v2 + +nuget Castle.Windsor-log4net ~> 3.2 +nuget Rx-Main ~> 2.0 +nuget FAKE = 1.1 +nuget SignalR = 3.3.2 +""" + +[] +let ``should read config without "``() = + let cfg = DependenciesFile.FromCode configWithoutQuotes + cfg.Strict |> shouldEqual false + cfg.DirectDependencies.Count |> shouldEqual 4 + + cfg.DirectDependencies.["Rx-Main"] |> shouldEqual (VersionRange.Between("2.0", "3.0")) + cfg.DirectDependencies.["Castle.Windsor-log4net"] |> shouldEqual (VersionRange.Between("3.2", "4.0")) + cfg.DirectDependencies.["FAKE"] |> shouldEqual (VersionRange.Exactly "1.1") + cfg.DirectDependencies.["SignalR"] |> shouldEqual (VersionRange.Exactly "3.3.2") + + +[] +let ``should read github source file from config without quotes``() = + let config = """github fsharp/FAKE src/app/FAKE/Cli.fs + github fsharp/FAKE:bla123zxc src/app/FAKE/FileWithCommit.fs """ + let dependencies = DependenciesFile.FromCode config + dependencies.RemoteFiles + |> shouldEqual + [ { Owner = "fsharp" + Project = "FAKE" + Name = "src/app/FAKE/Cli.fs" + Commit = None } + { Owner = "fsharp" + Project = "FAKE" + Name = "src/app/FAKE/FileWithCommit.fs" + Commit = Some "bla123zxc" } ] \ No newline at end of file