Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes lock file restrictions parsing #1144

Merged
merged 1 commit into from
Oct 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be removed by now?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. Please remove the comment. I guess we better keep it forever

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