Skip to content

Commit

Permalink
Merge pull request #363 from mexx/fix-359
Browse files Browse the repository at this point in the history
correct handling of package dependencies containing nuget
  • Loading branch information
forki committed Nov 16, 2014
2 parents 43fefe8 + 8384736 commit 3378e41
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
16 changes: 8 additions & 8 deletions src/Paket.Core/DependenciesFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
8 changes: 4 additions & 4 deletions src/Paket.Core/LockFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
6 changes: 6 additions & 0 deletions src/Paket.Core/Utils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 10 additions & 1 deletion tests/Paket.Tests/DependenciesFile/ParserSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
cfg.DirectDependencies.["Nancy.Owin"].Range |> shouldEqual (VersionRange.Specific (SemVer.Parse "0.22.2"))

[<Test>]
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"))

0 comments on commit 3378e41

Please sign in to comment.