Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Parse Redirects option from LockFile
  • Loading branch information
forki committed Dec 9, 2014
commit 1f014b766ff71a1210807256c361fe2997fc23a2
2 changes: 1 addition & 1 deletion src/Paket.Core/DependenciesFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ module DependenciesFileParser =
| [| _; projectSpec; fileSpec |] -> getParts projectSpec fileSpec
| _ -> failwithf "invalid http-reference specification:%s %s" Environment.NewLine trimmed

type ParserOption =
type private ParserOption =
| ReferencesMode of bool
| OmitContent of bool
| Redirects of bool
Expand Down
17 changes: 11 additions & 6 deletions src/Paket.Core/LockFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,11 @@ module LockFileParser =
SourceFiles : ResolvedSourceFile list
LastWasPackage : bool
Options: InstallOptions }

type private InstallOptionCase = StrictCase | OmitContentCase

type private ParserOption =
| ReferencesMode of bool
| OmitContent of bool
| Redirects of bool

let private (|Remote|NugetPackage|NugetDependency|SourceFile|RepositoryType|Blank|InstallOption|) (state, line:string) =
match (state.RepositoryType, line.Trim()) with
Expand All @@ -110,8 +113,9 @@ module LockFileParser =
| _, _ when String.IsNullOrWhiteSpace line -> Blank
| _, 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")
| _, String.StartsWith "REFERENCES:" trimmed -> InstallOption(ReferencesMode(trimmed.Trim() = "STRICT"))
| _, String.StartsWith "REDIRECTS:" trimmed -> InstallOption(Redirects(trimmed.Trim() = "ON"))
| _, String.StartsWith "CONTENT:" trimmed -> InstallOption(OmitContent(trimmed.Trim() = "NONE"))
| _, trimmed when line.StartsWith " " ->
let parts = trimmed.Split '('
NugetDependency (parts.[0].Trim(),parts.[1].Replace("(", "").Replace(")", "").Trim())
Expand All @@ -130,8 +134,9 @@ module LockFileParser =
match (state, line) with
| Remote(url) -> { state with RemoteUrl = Some url }
| Blank -> state
| InstallOption (StrictCase,mode) -> { state with Options = {state.Options with Strict = mode} }
| InstallOption (OmitContentCase,omit) -> { state with Options = {state.Options with OmitContent = omit} }
| InstallOption (ReferencesMode(mode)) -> { state with Options = {state.Options with Strict = mode} }
| InstallOption (Redirects(mode)) -> { state with Options = {state.Options with Redirects = mode} }
| InstallOption (OmitContent(omit)) -> { state with Options = {state.Options with OmitContent = omit} }
| RepositoryType repoType -> { state with RepositoryType = Some repoType }
| NugetPackage details ->
match state.RemoteUrl with
Expand Down
16 changes: 16 additions & 0 deletions tests/Paket.Tests/Lockfile/ParserSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,28 @@ let ``should parse strict lock file``() =
let packages = List.rev lockFile.Packages
packages.Length |> shouldEqual 6
lockFile.Options.Strict |> shouldEqual true
lockFile.Options.Redirects |> shouldEqual false

packages.[5].Source |> shouldEqual PackageSources.DefaultNugetSource
packages.[5].Name |> shouldEqual (PackageName "log4net")
packages.[5].Version |> shouldEqual (SemVer.Parse "1.1")
packages.[5].Dependencies |> shouldEqual (Set.ofList [PackageName "log", VersionRequirement.AllReleases, None])

let redirectsLockFile = """REDIRECTS: ON
NUGET
remote: https://nuget.org/api/v2
specs:
Castle.Windsor (2.1)
"""

[<Test>]
let ``should parse redirects lock file``() =
let lockFile = LockFileParser.Parse(toLines redirectsLockFile)
let packages = List.rev lockFile.Packages
packages.Length |> shouldEqual 1
lockFile.Options.Strict |> shouldEqual false
lockFile.Options.Redirects |> shouldEqual true

let dogfood = """NUGET
remote: https://nuget.org/api/v2
specs:
Expand Down