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

Fix case sensitivity on package name when search references in Paket.lock #1089

Merged
merged 4 commits into from
Jan 21, 2016
Merged
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
64 changes: 34 additions & 30 deletions src/app/FakeLib/PaketHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -145,33 +146,36 @@ 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)

let getVersion package =
let line = lines |> Array.find (fun l -> l.StartsWith(" " + package))
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) = 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.choose breakInParts

let refLines = getReferenceFilePackages referencesFile

getLockFilePackages referencesFile
|> Array.filter (fun (n, _) -> refLines |> Array.exists (fun pn -> pn.Equals(n, StringComparison.InvariantCultureIgnoreCase)))