From ecb4737e24f1c645c19e938b42568047ce2efd7d Mon Sep 17 00:00:00 2001 From: MvcAttitude Date: Tue, 19 Jan 2016 23:15:57 +0100 Subject: [PATCH 1/4] Fix case sensitivity on package name Paket isn't case sensitive so names can be upper case in paket.lock but lowercase in paket.references --- src/app/FakeLib/PaketHelper.fs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/app/FakeLib/PaketHelper.fs b/src/app/FakeLib/PaketHelper.fs index 43a5cd6c88b..231e03f9a8f 100755 --- a/src/app/FakeLib/PaketHelper.fs +++ b/src/app/FakeLib/PaketHelper.fs @@ -167,10 +167,11 @@ let GetDependenciesForReferencesFile (referencesFile:string) = find <| FileInfo(referencesFile).Directory.FullName let lines = File.ReadAllLines(lockFile) + |> Array.map (fun s -> s.Trim()) let getVersion package = - let line = lines |> Array.find (fun l -> l.StartsWith(" " + package)) - let start = line.Replace(" " + package + " (","") + let line = lines |> Array.find (fun l -> l.StartsWith(package, StringComparison.InvariantCultureIgnoreCase)) + let start = line.Replace(package + " (","") start.Substring(0,start.IndexOf(")")) nugetLines From b39750f85e6a6d8eba059520a05088b922237205 Mon Sep 17 00:00:00 2001 From: klettier Date: Wed, 20 Jan 2016 00:10:13 +0100 Subject: [PATCH 2/4] Refactor to be less imperative --- src/app/FakeLib/PaketHelper.fs | 66 ++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 31 deletions(-) diff --git a/src/app/FakeLib/PaketHelper.fs b/src/app/FakeLib/PaketHelper.fs index 231e03f9a8f..da104c850e1 100755 --- a/src/app/FakeLib/PaketHelper.fs +++ b/src/app/FakeLib/PaketHelper.fs @@ -4,6 +4,7 @@ module Fake.Paket open System open System.IO open System.Xml.Linq +open System.Text.RegularExpressions /// Paket pack parameter type type PaketPackParams = @@ -145,34 +146,37 @@ let Push setParams = /// Returns the dependencies from specified paket.references file let GetDependenciesForReferencesFile (referencesFile:string) = - let isSingleFile (line: string) = line.StartsWith "File:" - let isGroupLine (line: string) = line.StartsWith "group " - let notEmpty (line: string) = not <| String.IsNullOrWhiteSpace line - let parsePackageName (line: string) = - let parts = line.Split(' ') - parts.[0] - - let nugetLines = - File.ReadAllLines(referencesFile) - |> Array.filter notEmpty - |> Array.map (fun s -> s.Trim()) - |> Array.filter (isSingleFile >> not) - |> Array.filter (isGroupLine >> not) - |> Array.map parsePackageName - - let lockFile = - let rec find dir = - let fi = FileInfo(dir "paket.lock") - if fi.Exists then fi.FullName else find fi.Directory.Parent.FullName - find <| FileInfo(referencesFile).Directory.FullName - - let lines = File.ReadAllLines(lockFile) - |> Array.map (fun s -> s.Trim()) - - let getVersion package = - let line = lines |> Array.find (fun l -> l.StartsWith(package, StringComparison.InvariantCultureIgnoreCase)) - let start = line.Replace(package + " (","") - start.Substring(0,start.IndexOf(")")) - - nugetLines - |> Array.map (fun p -> p,getVersion p) + let getReferenceFilePackages = + let isSingleFile (line: string) = line.StartsWith "File:" + let isGroupLine (line: string) = line.StartsWith "group " + let notEmpty (line: string) = not <| String.IsNullOrWhiteSpace line + let parsePackageName (line: string) = + let parts = line.Split(' ') + parts.[0] + File.ReadAllLines + >> Array.filter notEmpty + >> Array.map (fun s -> s.Trim()) + >> Array.filter (isSingleFile >> not) + >> Array.filter (isGroupLine >> not) + >> Array.map parsePackageName + + let getLockFilePackages = + let getPaketLockFile referencesFile = + let rec find dir = + let fi = FileInfo(dir "paket.lock") + if fi.Exists then fi.FullName else find fi.Directory.Parent.FullName + find <| FileInfo(referencesFile).Directory.FullName + + let breakInParts (line : string) = Regex.Match(line,"(.+) \((.+)\)") + + getPaketLockFile + >> File.ReadAllLines + >> Array.map (fun s -> s.Trim()) + >> Array.map breakInParts + >> Array.filter (fun x -> x.Success && x.Groups.Count = 3) + >> Array.map (fun x -> x.Groups.[1].Value, x.Groups.[2].Value) + + let refLines = getReferenceFilePackages referencesFile + + getLockFilePackages referencesFile + |> Array.filter (fun (n, _) -> refLines |> Array.exists (fun pn -> pn.Equals(n, StringComparison.InvariantCultureIgnoreCase))) From 0219e1ee5c398d9e4d7771210100dad68473ad50 Mon Sep 17 00:00:00 2001 From: klettier Date: Wed, 20 Jan 2016 09:39:36 +0100 Subject: [PATCH 3/4] Remove Trim, the spaces were there to find only package lines and to exclude package dependency lines --- src/app/FakeLib/PaketHelper.fs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/app/FakeLib/PaketHelper.fs b/src/app/FakeLib/PaketHelper.fs index da104c850e1..cf6ce81c5f7 100755 --- a/src/app/FakeLib/PaketHelper.fs +++ b/src/app/FakeLib/PaketHelper.fs @@ -167,11 +167,10 @@ let GetDependenciesForReferencesFile (referencesFile:string) = if fi.Exists then fi.FullName else find fi.Directory.Parent.FullName find <| FileInfo(referencesFile).Directory.FullName - let breakInParts (line : string) = Regex.Match(line,"(.+) \((.+)\)") + let breakInParts (line : string) = Regex.Match(line,"^[ ]{4}([^ ].+) \((.+)\)") getPaketLockFile >> File.ReadAllLines - >> Array.map (fun s -> s.Trim()) >> Array.map breakInParts >> Array.filter (fun x -> x.Success && x.Groups.Count = 3) >> Array.map (fun x -> x.Groups.[1].Value, x.Groups.[2].Value) From a574b2749325eaf7a02ff2a2e762db8f0b9bac75 Mon Sep 17 00:00:00 2001 From: klettier Date: Wed, 20 Jan 2016 10:27:22 +0100 Subject: [PATCH 4/4] breakInParts function do the split and format --- src/app/FakeLib/PaketHelper.fs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/app/FakeLib/PaketHelper.fs b/src/app/FakeLib/PaketHelper.fs index cf6ce81c5f7..f8b8b7e1e56 100755 --- a/src/app/FakeLib/PaketHelper.fs +++ b/src/app/FakeLib/PaketHelper.fs @@ -167,13 +167,13 @@ let GetDependenciesForReferencesFile (referencesFile:string) = if fi.Exists then fi.FullName else find fi.Directory.Parent.FullName find <| FileInfo(referencesFile).Directory.FullName - let breakInParts (line : string) = Regex.Match(line,"^[ ]{4}([^ ].+) \((.+)\)") + let breakInParts (line : string) = match Regex.Match(line,"^[ ]{4}([^ ].+) \((.+)\)") with + | m when m.Success && m.Groups.Count = 3 -> Some (m.Groups.[1].Value, m.Groups.[2].Value) + | _ -> None getPaketLockFile >> File.ReadAllLines - >> Array.map breakInParts - >> Array.filter (fun x -> x.Success && x.Groups.Count = 3) - >> Array.map (fun x -> x.Groups.[1].Value, x.Groups.[2].Value) + >> Array.choose breakInParts let refLines = getReferenceFilePackages referencesFile