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

Support for only using nuget v3 api #1205

Merged
merged 6 commits into from
Nov 11, 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
8 changes: 4 additions & 4 deletions src/Paket.Bootstrapper/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
[assembly: AssemblyTitleAttribute("Paket.Bootstrapper")]
[assembly: AssemblyProductAttribute("Paket")]
[assembly: AssemblyDescriptionAttribute("A package dependency manager for .NET with support for NuGet packages and GitHub repositories.")]
[assembly: AssemblyVersionAttribute("2.23.0")]
[assembly: AssemblyFileVersionAttribute("2.23.0")]
[assembly: AssemblyInformationalVersionAttribute("2.23.0")]
[assembly: AssemblyVersionAttribute("2.12.3")]
[assembly: AssemblyFileVersionAttribute("2.12.3")]
[assembly: AssemblyInformationalVersionAttribute("2.12.3")]
namespace System {
internal static class AssemblyVersionInformation {
internal const string Version = "2.23.0";
internal const string Version = "2.12.3";
}
}
8 changes: 4 additions & 4 deletions src/Paket.Core/AssemblyInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ open System.Reflection
[<assembly: AssemblyProductAttribute("Paket")>]
[<assembly: AssemblyCompanyAttribute("Paket team")>]
[<assembly: AssemblyDescriptionAttribute("A package dependency manager for .NET with support for NuGet packages and GitHub repositories.")>]
[<assembly: AssemblyVersionAttribute("2.23.0")>]
[<assembly: AssemblyFileVersionAttribute("2.23.0")>]
[<assembly: AssemblyInformationalVersionAttribute("2.23.0")>]
[<assembly: AssemblyVersionAttribute("2.12.3")>]
[<assembly: AssemblyFileVersionAttribute("2.12.3")>]
[<assembly: AssemblyInformationalVersionAttribute("2.12.3")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] Version = "2.23.0"
let [<Literal>] Version = "2.12.3"
3 changes: 3 additions & 0 deletions src/Paket.Core/Constants.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ let GitHubUrl = "https://github.com"
[<Literal>]
let DefaultNugetStream = "https://nuget.org/api/v2"

[<Literal>]
let DefaultNugetV3Stream = "http://api.nuget.org/v3/index.json"

[<Literal>]
let GitHubReleasesUrl = "https://api.github.com/repos/fsprojects/Paket/releases"

Expand Down
1 change: 1 addition & 0 deletions src/Paket.Core/LockFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ module LockFileSerializer =
let package = kv.Value
match package.Source with
| Nuget source -> source.Url,source.Authentication,package
| NugetV3 source -> source.Url,source.Authentication,package
| LocalNuget path -> path,None,package
)
|> Seq.groupBy (fun (a,b,_) -> a,b)
Expand Down
33 changes: 18 additions & 15 deletions src/Paket.Core/NuGetV2.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,13 @@ open Paket.Logging
open System.Text

open Paket.Domain
open Paket.NuGet
open Paket.Utils
open Paket.Xml
open Paket.PackageSources
open Paket.Requirements
open FSharp.Polyfill

type NugetPackageCache =
{ Dependencies : (PackageName * VersionRequirement * FrameworkRestrictions) list
PackageName : string
SourceUrl: string
Unlisted : bool
DownloadUrl : string
LicenseUrl : string
CacheVersion: string }

static member CurrentCacheVersion = "2.0"

let rec private followODataLink auth url =
async {
let! raw = getFromUrl(auth, url, acceptXml)
Expand Down Expand Up @@ -245,7 +235,7 @@ let CacheFolder =

let inline normalizeUrl(url:string) = url.Replace("https","http").Replace("www.","")

let private loadFromCacheOrOData force fileName (auth,nugetURL) package version =
let private loadFromCacheOrODataOrV3 force fileName (auth,nugetURL) package version =
async {
if not force && File.Exists fileName then
try
Expand Down Expand Up @@ -287,7 +277,7 @@ let getDetailsFromNuGet force auth nugetURL (packageName:PackageName) (version:S
if not force && errorFile.Exists then
failwithf "Error file for %O exists at %s" packageName errorFile.FullName

let! (invalidCache,details) = loadFromCacheOrOData force cacheFile.FullName (auth,nugetURL) packageName version
let! (invalidCache,details) = loadFromCacheOrODataOrV3 force cacheFile.FullName (auth,nugetURL) packageName version

verbosefn "loaded details for '%O@%O' from url '%s'" packageName version nugetURL

Expand Down Expand Up @@ -494,7 +484,7 @@ let DownloadLicense(root,force,packageName:PackageName,version:SemVerInfo,licens
}

/// Downloads the given package to the NuGet Cache folder
let DownloadPackage(root, auth, url, groupName, packageName:PackageName, version:SemVerInfo, includeVersionInPath, force) =
let DownloadPackage(root, auth, (source : PackageSource), groupName, packageName:PackageName, version:SemVerInfo, includeVersionInPath, force) =
async {
let targetFileName = Path.Combine(CacheFolder, packageName.ToString() + "." + version.Normalize() + ".nupkg")
let targetFile = FileInfo targetFileName
Expand All @@ -503,7 +493,14 @@ let DownloadPackage(root, auth, url, groupName, packageName:PackageName, version
verbosefn "%O %O already downloaded." packageName version
else
// discover the link on the fly
let! nugetPackage = getDetailsFromNuGet force auth url packageName version
let url, nugetPackage =
match source with
| Nuget source ->
source.Url, (getDetailsFromNuGet force auth source.Url packageName version)
| NugetV3 source ->
source.Url, (NuGetV3.GetPackageDetails source packageName version)
| _ -> failwith "shouldnt be here"
let! nugetPackage = nugetPackage
try
tracefn "Downloading %O %O" packageName version
verbosefn " to %s" targetFileName
Expand Down Expand Up @@ -603,6 +600,10 @@ let GetPackageDetails root force sources packageName (version:SemVerInfo) : Pack
packageName
version
return Some(source,result)
| NugetV3 nugetSource ->
let! result =
NuGetV3.GetPackageDetails nugetSource packageName version
return Some(source,result)
| LocalNuget path ->
let! result = getDetailsFromLocalFile root path packageName version
return Some(source,result)
Expand Down Expand Up @@ -666,6 +667,8 @@ let GetVersions root (sources, packageName:PackageName) =
getVersionsCached "ODataWithFilter" tryGetAllVersionsFromNugetODataWithFilter (auth, source.Url, packageName) ]

v2Feeds @ v3Feeds
| NugetV3 source ->
[ tryNuGetV3 (source.BasicAuthentication, source.AutoCompleteUrl, packageName) ]
| LocalNuget path -> [ getAllVersionsFromLocalPath (path, packageName, root) ])
|> Seq.toArray
|> Array.map Async.Choice
Expand Down
101 changes: 101 additions & 0 deletions src/Paket.Core/NuGetV3.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ module Paket.NuGetV3
open Newtonsoft.Json
open System.Collections.Generic

open Paket.Domain
open Paket.Utils
open Paket.Xml
open Paket.PackageSources
open Paket.Requirements

/// [omit]
type JSONResource =
{ Type : string;
Expand Down Expand Up @@ -34,6 +40,7 @@ let calculateNuGet3Path(nugetUrl:string) =
| "http://www.nuget.org/api/v2" -> Some "http://api.nuget.org/v3/index.json"
| "https://www.nuget.org/api/v2" -> Some "https://api.nuget.org/v3/index.json"
| url when url.EndsWith("api/v2") && url.Contains("myget.org") -> Some (url.Replace("api/v2","api/v3/index.json"))
| url when url.EndsWith("api/v3/index.json") -> Some url
| _ -> None

/// [omit]
Expand Down Expand Up @@ -105,3 +112,97 @@ let FindPackages(auth, nugetURL, packageNamePrefix, maxResults) =
async {
return! getPackages(auth, nugetURL, packageNamePrefix, maxResults)
}

type Registration =
{ [<JsonProperty("catalogEntry")>]
CatalogEntry : string

[<JsonProperty("packageContent")>]
PackageContent : string }

type CatalogDependency =
{ [<JsonProperty("id")>]
Id : string

[<JsonProperty("range")>]
Range : string }
type CatalogDependencyGroup =
{ [<JsonProperty("targetFramework")>]
TargetFramework : string option

[<JsonProperty("dependencies")>]
Dependencies : CatalogDependency [] }
type Catalog =
{ [<JsonProperty("licenseUrl")>]
LicenseUrl : string

[<JsonProperty("listed")>]
Listed : bool

[<JsonProperty("dependencyGroups")>]
DependencyGroups : CatalogDependencyGroup [] }

let getRegistration (source : NugetV3Source) (packageName:PackageName) (version:SemVerInfo) =
async {
let url = sprintf "%s%s/%s.json" source.RegistrationUrl (packageName.ToString().ToLower()) version.AsString
let! rawData = safeGetFromUrl (source.BasicAuthentication, url, acceptJson)
return
match rawData with
| None -> failwithf "could not get registration data from %s" url
| Some x -> JsonConvert.DeserializeObject<Registration>(x)
}

let getCatalog url auth =
async {
let! rawData = safeGetFromUrl (auth, url, acceptJson)
return
match rawData with
| None -> failwithf "could not get catalog data from %s" url
| Some x -> JsonConvert.DeserializeObject<Catalog>(x)
}

/// Uses the NuGet v3 registration endpoint to retrieve package details .
let GetPackageDetails (source : NugetV3Source) (packageName:PackageName) (version:SemVerInfo) : Async<NuGet.NugetPackageCache> =
async {
let! registrationData = getRegistration source packageName version
let! catalogData = getCatalog registrationData.CatalogEntry source.BasicAuthentication

let dependencies =
catalogData.DependencyGroups
|> Seq.map(fun group ->
group.Dependencies
|> Seq.map(fun dep -> dep, group.TargetFramework))
|> Seq.concat
|> Seq.map(fun (dep, targetFramework) ->
let targetFramework =
match targetFramework with
| None -> []
| Some x ->
match FrameworkDetection.Extract x with
| Some x -> [ FrameworkRestriction.Exactly x ]
| None -> []
(PackageName dep.Id), (VersionRequirement.Parse dep.Range), targetFramework)
|> Seq.toList

return
{ Dependencies = [] //this needs to be implemented Requirements.optimizeDependencies dependencies
PackageName = packageName.ToString()
SourceUrl = source.Url
Unlisted = not catalogData.Listed
DownloadUrl = registrationData.PackageContent
LicenseUrl = catalogData.LicenseUrl
CacheVersion = NuGet.NugetPackageCache.CurrentCacheVersion }

}
(*
get from https://api.nuget.org/v3/registration1/fsharp.orm/1.0.0.json

will provide:
* catalogEntry, a link to the catalog page
* packageContent, a link to the nupkg file

use catalogEntry to download the catalog, like https://api.nuget.org/v3/catalog0/data/2015.11.03.22.34.24/fsharp.orm.1.0.0.json
use dependencyGroups to get the dependencies for the package
use licenseUrl
use listed
*)
16 changes: 16 additions & 0 deletions src/Paket.Core/Nuget.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/// Contains NuGet support.
module Paket.NuGet

open Paket.Domain
open Paket.Requirements

type NugetPackageCache =
{ Dependencies : (PackageName * VersionRequirement * FrameworkRestrictions) list
PackageName : string
SourceUrl: string
Unlisted : bool
DownloadUrl : string
LicenseUrl : string
CacheVersion: string }

static member CurrentCacheVersion = "2.0"
Loading