Skip to content

Commit

Permalink
Fixes lock file restrictions parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
mrinaldi committed Oct 16, 2015
1 parent c6f6af2 commit 49f9296
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/Paket.Core/LockFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,16 @@ module LockFileParser =
let Parse(lockFileLines) =
let remove textToRemove (source:string) = source.Replace(textToRemove, "")
let removeBrackets = remove "(" >> remove ")"
let parsePackage (s : string) =
let parts = s.Split([|" - "|],StringSplitOptions.None)
let optionsString =
if parts.Length < 2 then "" else
if parts.[1] <> "" && parts.[1].Contains(":") |> not then
("framework: " + parts.[1]) // TODO: This is for backwards-compat and should be removed later
else
parts.[1]
parts.[0],InstallSettings.Parse(optionsString)

([{ GroupName = Constants.MainDependencyGroup; RepositoryType = None; RemoteUrl = None; Packages = []; SourceFiles = []; Options = InstallOptions.Default; LastWasPackage = false }], lockFileLines)
||> Seq.fold(fun state line ->
match state with
Expand All @@ -234,15 +244,9 @@ module LockFileParser =
| NugetPackage details ->
match currentGroup.RemoteUrl with
| Some remote ->
let parts = details.Split([|" - "|],StringSplitOptions.None)
let parts' = parts.[0].Split ' '
let package,settings = parsePackage details
let parts' = package.Split ' '
let version = parts'.[1] |> removeBrackets
let optionsString =
if parts.Length < 2 then "" else
if parts.[1] <> "" && parts.[1].Contains(":") |> not then
("framework: " + parts.[1]) // TODO: This is for backwards-compat and should be removed later
else
parts.[1]

{ currentGroup with
LastWasPackage = true
Expand All @@ -251,19 +255,17 @@ module LockFileParser =
Name = PackageName parts'.[0]
Dependencies = Set.empty
Unlisted = false
Settings = InstallSettings.Parse(optionsString)
Settings = settings
Version = SemVer.Parse version } :: currentGroup.Packages }::otherGroups
| None -> failwith "no source has been specified."
| NugetDependency (name, v) ->
let parts = v.Split([|" - "|],StringSplitOptions.None)
let version = parts.[0]
let restrictions = if parts.Length <= 1 then [] else parseRestrictions parts.[1]
let version,settings = parsePackage v
if currentGroup.LastWasPackage then
match currentGroup.Packages with
| currentPackage :: otherPackages ->
{ currentGroup with
Packages = { currentPackage with
Dependencies = Set.add (PackageName name, DependenciesFileParser.parseVersionRequirement version, restrictions) currentPackage.Dependencies
Dependencies = Set.add (PackageName name, DependenciesFileParser.parseVersionRequirement version, settings.FrameworkRestrictions) currentPackage.Dependencies
} :: otherPackages } ::otherGroups
| [] -> failwithf "cannot set a dependency to %s %s - no package has been specified." name v
else
Expand Down
28 changes: 28 additions & 0 deletions tests/Paket.Tests/Lockfile/ParserSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,26 @@ let ``should parse framework restricted lock file``() =
let packages = List.rev lockFile.Packages
packages.Length |> shouldEqual 7

packages.[0].Dependencies |> Set.toList |> List.map (fun (_, _, r) -> r)
|> List.item 2
|> shouldEqual ([FrameworkRestriction.AtLeast(FrameworkIdentifier.DotNetFramework(FrameworkVersion.V4_Client))])

packages.[3].Source |> shouldEqual PackageSources.DefaultNugetSource
packages.[3].Name |> shouldEqual (PackageName "LinqBridge")
packages.[3].Version |> shouldEqual (SemVer.Parse "1.3.0")
packages.[3].Settings.FrameworkRestrictions |> shouldEqual ([FrameworkRestriction.Between(FrameworkIdentifier.DotNetFramework(FrameworkVersion.V2),FrameworkIdentifier.DotNetFramework(FrameworkVersion.V3_5))])
packages.[3].Settings.ImportTargets |> shouldEqual None

let dependencies4 =
packages.[4].Dependencies |> Set.toList |> List.map (fun (_, _, r) -> r)

dependencies4.Head
|> shouldEqual ([FrameworkRestriction.Between(FrameworkIdentifier.DotNetFramework(FrameworkVersion.V2), FrameworkIdentifier.DotNetFramework(FrameworkVersion.V3_5))])
dependencies4.Tail.Head
|> shouldEqual ([FrameworkRestriction.Exactly(FrameworkIdentifier.DotNetFramework(FrameworkVersion.V2))
FrameworkRestriction.Exactly(FrameworkIdentifier.DotNetFramework(FrameworkVersion.V3_5))
FrameworkRestriction.AtLeast(FrameworkIdentifier.DotNetFramework(FrameworkVersion.V4_Client))])

packages.[5].Source |> shouldEqual PackageSources.DefaultNugetSource
packages.[5].Name |> shouldEqual (PackageName "ReadOnlyCollectionInterfaces")
packages.[5].Version |> shouldEqual (SemVer.Parse "1.0.0")
Expand Down Expand Up @@ -312,6 +326,10 @@ let ``should parse framework restricted lock file in new syntax``() =
let packages = List.rev lockFile.Packages
packages.Length |> shouldEqual 7

packages.[0].Dependencies |> Set.toList |> List.map (fun (_, _, r) -> r)
|> List.item 2
|> shouldEqual ([FrameworkRestriction.AtLeast(FrameworkIdentifier.DotNetFramework(FrameworkVersion.V4_Client))])

packages.[3].Source |> shouldEqual PackageSources.DefaultNugetSource
packages.[3].Name |> shouldEqual (PackageName "LinqBridge")
packages.[3].Version |> shouldEqual (SemVer.Parse "1.3.0")
Expand All @@ -321,6 +339,16 @@ let ``should parse framework restricted lock file in new syntax``() =
packages.[3].Settings.IncludeVersionInPath |> shouldEqual (Some true)
packages.[3].Settings.OmitContent |> shouldEqual (Some ContentCopySettings.Omit)

let dependencies4 =
packages.[4].Dependencies |> Set.toList |> List.map (fun (_, _, r) -> r)

dependencies4.Head
|> shouldEqual ([FrameworkRestriction.Between(FrameworkIdentifier.DotNetFramework(FrameworkVersion.V2), FrameworkIdentifier.DotNetFramework(FrameworkVersion.V3_5))])
dependencies4.Tail.Head
|> shouldEqual ([FrameworkRestriction.Exactly(FrameworkIdentifier.DotNetFramework(FrameworkVersion.V2))
FrameworkRestriction.Exactly(FrameworkIdentifier.DotNetFramework(FrameworkVersion.V3_5))
FrameworkRestriction.AtLeast(FrameworkIdentifier.DotNetFramework(FrameworkVersion.V4_Client))])

packages.[5].Source |> shouldEqual PackageSources.DefaultNugetSource
packages.[5].Name |> shouldEqual (PackageName "ReadOnlyCollectionInterfaces")
packages.[5].Version |> shouldEqual (SemVer.Parse "1.0.0")
Expand Down

0 comments on commit 49f9296

Please sign in to comment.