Skip to content

Commit

Permalink
Package names in Dependencies file are no longer case-sensitive - fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Sep 17, 2014
1 parent c0336bd commit 07dea24
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 20 deletions.
3 changes: 3 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#### 0.2.0-alpha012 - 17.09.2014
* Package names in Dependencies file are no longer case-sensitive - https://github.com/fsprojects/Paket/pull/108

#### 0.2.0-alpha011 - 17.09.2014
* Always pin the Github version of a referenced file in the lockfile - https://github.com/fsprojects/Paket/pull/110

Expand Down
2 changes: 1 addition & 1 deletion paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ NUGET
RazorEngine (3.3.0)
FSharp.Compiler.Service (0.0.59)
Microsoft.AspNet.Razor (2.0.30506.0)
Newtonsoft.Json (6.0.5)
NUnit (2.6.3)
NUnit.Runners (2.6.3)
Newtonsoft.Json (6.0.5)
RazorEngine (3.3.0)
Microsoft.AspNet.Razor (>= 2.0.30506.0)
SourceLink.Fake (0.3.4)
Expand Down
9 changes: 5 additions & 4 deletions src/Paket/BasicTypes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,11 @@ type Dependency =
| FromPackage d -> d.Referenced

/// Represents package details
type PackageDetails = {
Source: PackageSource
DownloadLink: string
DirectDependencies : UnresolvedPackage list }
type PackageDetails =
{ Name : string
Source : PackageSource
DownloadLink : string
DirectDependencies : UnresolvedPackage list }

/// Interface for discovery APIs.
type IDiscovery =
Expand Down
34 changes: 25 additions & 9 deletions src/Paket/Nuget.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ open Newtonsoft.Json
open Ionic.Zip
open System.Xml
open System.Collections.Generic
open System.Text.RegularExpressions

let private loadNuGetOData raw =
let doc = XmlDocument()
Expand Down Expand Up @@ -68,9 +69,9 @@ let getAllVersions (nugetURL, package) =
/// Gets versions of the given package from local Nuget feed.
let getAllVersionsFromLocalPath (localNugetPath, package) =
async {
return Directory.EnumerateFiles(localNugetPath)
|> Seq.choose (fun f ->
let _match = Text.RegularExpressions.Regex(sprintf @"%s\.(\d.*)\.nupkg" package).Match(f)
return Directory.EnumerateFiles(localNugetPath,"*.nupkg",SearchOption.AllDirectories)
|> Seq.choose (fun fileName ->
let _match = Regex(sprintf @"%s\.(\d.*)\.nupkg" package, RegexOptions.IgnoreCase).Match(fileName)
if _match.Groups.Count > 1 then Some _match.Groups.[1].Value else None)
}

Expand Down Expand Up @@ -125,6 +126,14 @@ let getDetailsFromNugetViaOData nugetURL package sources resolverStrategy versio
}
|> Seq.head

let officialName =
seq {
for node in doc.SelectNodes("//ns:entry/ns:title", manager) do
yield node.InnerText
}
|> Seq.head


let downloadLink =
seq {
for node in doc.SelectNodes("//ns:entry/ns:content", manager) do
Expand All @@ -151,7 +160,7 @@ let getDetailsFromNugetViaOData nugetURL package sources resolverStrategy versio
ResolverStrategy = resolverStrategy })
|> Array.toList

return downloadLink,packages
return officialName,downloadLink,packages
}

/// The NuGet cache folder.
Expand All @@ -164,7 +173,7 @@ let private loadFromCacheOrOData force fileName nugetURL package sources resolve
if not force && File.Exists fileName then
try
let json = File.ReadAllText(fileName)
return false,JsonConvert.DeserializeObject<string * UnresolvedPackage list>(json)
return false,JsonConvert.DeserializeObject<string * string * UnresolvedPackage list>(json)

This comment has been minimized.

Copy link
@theimowski

theimowski Sep 17, 2014

Member

this change results in an JsonConvert exception, if the file created with earlier version of Paket exists in cache - #108

This comment has been minimized.

Copy link
@forki

forki via email Sep 17, 2014

Author Member

This comment has been minimized.

Copy link
@theimowski

theimowski Sep 17, 2014

Member

my bad, didn't notice the try catch + I was debugging with "break on CLR exceptions thrown" setting and thought the app crashed

This comment has been minimized.

Copy link
@forki

forki via email Sep 17, 2014

Author Member

This comment has been minimized.

Copy link
@theimowski

theimowski Sep 17, 2014

Member

Probably it did, but cannot tell for sure as I instantly removed all jsons from NuGet cache

This comment has been minimized.

Copy link
@forki

forki via email Sep 17, 2014

Author Member
with _ ->
let! details = getDetailsFromNugetViaOData nugetURL package sources resolverStrategy version
return true,details
Expand Down Expand Up @@ -225,9 +234,15 @@ let getDetailsFromLocalFile path package sources resolverStrategy version =
ResolverStrategy = resolverStrategy })
|> Seq.toList

let officialName =
xmlDoc.SelectNodes(sprintf "/%s:package/%s:metadata/%s:id" pfx pfx pfx, ns)
|> Seq.cast<XmlNode>
|> Seq.head
|> fun node -> node.InnerText

File.Delete(nuspec.FullName)

return package,dependencies
return officialName,package,dependencies
}

/// Downloads the given package to the NuGet Cache folder
Expand All @@ -240,7 +255,7 @@ let DownloadPackage(url, name, sources, version, force) =
return targetFileName
else
// discover the link on the fly
let! (link, _) = getDetailsFromNuget force url name sources ResolverStrategy.Max version
let! (_,link, _) = getDetailsFromNuget force url name sources ResolverStrategy.Max version
use client = new WebClient()
tracefn "Downloading %s %s to %s" name version targetFileName
// TODO: Set credentials
Expand Down Expand Up @@ -321,9 +336,10 @@ let NugetDiscovery =
return! tryNext []
}

let! source,(link,packages) = tryNext sources
let! source,(name,link,packages) = tryNext sources
return
{ Source = source
{ Name = name
Source = source
DownloadLink = link
DirectDependencies =
packages |> List.map (fun package -> {package with Sources = source :: (List.filter ((<>) source) sources) })}
Expand Down
11 changes: 6 additions & 5 deletions src/Paket/PackageResolver.fs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ let private shrink (s1 : Shrinked, s2 : Shrinked) =
| _ -> Shrinked.Conflict(version1, version2)
| _ -> s1

let private addDependency package dependencies newDependency =
let private addDependency (packageName:string) dependencies newDependency =
let name = packageName.ToLower()
let newDependency = Shrinked.Ok newDependency
match Map.tryFind package dependencies with
| Some oldDependency -> Map.add package (shrink(oldDependency,newDependency)) dependencies
| None -> Map.add package newDependency dependencies
match Map.tryFind name dependencies with
| Some oldDependency -> Map.add name (shrink(oldDependency,newDependency)) dependencies
| None -> Map.add name newDependency dependencies

/// Resolves all direct and indirect dependencies
let Resolve(force, discovery : IDiscovery, rootDependencies:UnresolvedPackage seq) =
Expand Down Expand Up @@ -102,7 +103,7 @@ let Resolve(force, discovery : IDiscovery, rootDependencies:UnresolvedPackage se
|> Async.RunSynchronously

let resolvedPackage:ResolvedPackage =
{ Name = resolvedName
{ Name = packageDetails.Name
Version = resolvedVersion
DirectDependencies =
packageDetails.DirectDependencies
Expand Down
2 changes: 1 addition & 1 deletion tests/Paket.Tests/TestHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let DictionaryDiscovery(graph : seq<string * string * (string * VersionRange) li
VersionRange = v
ResolverStrategy = resolverStrategy
Sources = sources })
return { Source = Seq.head sources; DownloadLink = ""; DirectDependencies = dependencies }
return { Name = package; Source = Seq.head sources; DownloadLink = ""; DirectDependencies = dependencies }
}

member __.GetVersions(sources, package) =
Expand Down

0 comments on commit 07dea24

Please sign in to comment.