From ec34b46dd06a52938b45ef5c193a6126eaafe9bc Mon Sep 17 00:00:00 2001 From: Matthias Dittrich Date: Sat, 2 Sep 2017 17:48:12 +0200 Subject: [PATCH] cleanup --- src/Paket.Core/Dependencies/NuGetV3.fs | 61 ++++++++++---------------- 1 file changed, 23 insertions(+), 38 deletions(-) diff --git a/src/Paket.Core/Dependencies/NuGetV3.fs b/src/Paket.Core/Dependencies/NuGetV3.fs index 3f9a7666bc..fe4d6cb049 100644 --- a/src/Paket.Core/Dependencies/NuGetV3.fs +++ b/src/Paket.Core/Dependencies/NuGetV3.fs @@ -17,17 +17,17 @@ open Paket.Logging open Paket.PlatformMatching -type NugetV3SourceResourceJSON = +type NugetV3SourceResourceJSON = { [] Type : string [] ID : string } -type NugetV3SourceRootJSON = +type NugetV3SourceRootJSON = { [] Resources : NugetV3SourceResourceJSON [] } -//type NugetV3Source = +//type NugetV3Source = // { Url : string // Authentication : NugetSourceAuthentication option } @@ -96,17 +96,17 @@ let getNuGetV3Resource (source : NugetV3Source) (resourceType : NugetV3ResourceT } /// [omit] -type JSONResource = +type JSONResource = { Type : string; ID: string } /// [omit] -type JSONVersionData = - { Data : string [] +type JSONVersionData = + { Data : string [] Versions : string [] } /// [omit] -type JSONRootData = +type JSONRootData = { Resources : JSONResource [] } /// [omit] @@ -116,7 +116,7 @@ let private searchDict = new System.Collections.Concurrent.ConcurrentDictionary< let private allVersionsDict = new System.Collections.Concurrent.ConcurrentDictionary<_,System.Threading.Tasks.Task<_>>() /// Calculates the NuGet v3 URL from a NuGet v2 URL. -let calculateNuGet3Path(nugetUrl:string) = +let calculateNuGet3Path(nugetUrl:string) = match nugetUrl.TrimEnd([|'/'|]) with | "http://nuget.org/api/v2" -> Some "http://api.nuget.org/v3/index.json" | "https://nuget.org/api/v2" -> Some "https://api.nuget.org/v3/index.json" @@ -130,7 +130,7 @@ let calculateNuGet3Path(nugetUrl:string) = | _ -> None /// Calculates the NuGet v3 URL from a NuGet v2 URL. -let calculateNuGet2Path(nugetUrl:string) = +let calculateNuGet2Path(nugetUrl:string) = match nugetUrl.TrimEnd([|'/'|]) with | "http://api.nuget.org/v3/index.json" -> Some "http://nuget.org/api/v2" | "https://api.nuget.org/v3/index.json" -> Some "https://nuget.org/api/v2" @@ -144,24 +144,24 @@ let calculateNuGet2Path(nugetUrl:string) = /// [omit] -let getSearchAPI(auth,nugetUrl) = +let getSearchAPI(auth,nugetUrl) = searchDict.GetOrAdd(nugetUrl, fun nugetUrl -> async { match calculateNuGet3Path nugetUrl with | None -> return None - | Some v3Path -> + | Some v3Path -> let source = { Url = v3Path; Authentication = auth } let! v3res = getNuGetV3Resource source AutoComplete |> Async.Catch - return + return match v3res with | Choice1Of2 s -> Some s - | Choice2Of2 ex -> + | Choice2Of2 ex -> if verbose then traceWarnfn "getSearchAPI: %s" (ex.ToString()) None } |> Async.StartAsTask) /// [omit] -let getAllVersionsAPI(auth,nugetUrl) = +let getAllVersionsAPI(auth,nugetUrl) = allVersionsDict.GetOrAdd(nugetUrl, fun nugetUrl -> async { match calculateNuGet3Path nugetUrl with @@ -172,7 +172,7 @@ let getAllVersionsAPI(auth,nugetUrl) = return match v3res with | Choice1Of2 s -> Some s - | Choice2Of2 ex -> + | Choice2Of2 ex -> if verbose then traceWarnfn "getAllVersionsAPI: %s" (ex.ToString()) None } |> Async.StartAsTask) @@ -240,13 +240,13 @@ let extractPackages(response:string) = let private getPackages(auth, nugetURL, packageNamePrefix, maxResults) = async { let! apiRes = getSearchAPI(auth,nugetURL) |> Async.AwaitTask match apiRes with - | Some url -> + | Some url -> let query = sprintf "%s?q=%s&take=%d" url packageNamePrefix maxResults let! response = safeGetFromUrl(auth |> Option.map toCredentials,query,acceptJson) match SafeWebResult.asResult response with | Result.Ok text -> return Result.Ok (extractPackages text) | Result.Error err -> return Result.Error err - | None -> + | None -> if verbose then tracefn "Could not calculate search api from %s" nugetURL return Result.Ok [||] } @@ -258,28 +258,23 @@ let FindPackages(auth, nugetURL, packageNamePrefix, maxResults) = } -type CatalogDependency = +type CatalogDependency = { [] - Id : string - + Id : string [] Range : string } -type CatalogDependencyGroup = +type CatalogDependencyGroup = { [] TargetFramework : string - [] Dependencies : CatalogDependency [] } -type Catalog = +type Catalog = { [] LicenseUrl : string - [] Listed : System.Nullable - [] Version : string - [] DependencyGroups : CatalogDependencyGroup [] } @@ -290,8 +285,7 @@ type PackageIndexPackage = [] DownloadLink: string [] - PackageDetails: Catalog - } + PackageDetails: Catalog } type PackageIndexPage = { [] @@ -307,7 +301,7 @@ type PackageIndexPage = [] Upper: string } -type PackageIndex = +type PackageIndex = { [] Id: string [] @@ -376,15 +370,6 @@ let getRelevantPage (source:NugetV3Source) (index:PackageIndex) (version:SemVerI return None | _ :: _ -> return failwithf "Mulitple pages of V3 index '%s' match with version '%O'" index.Id version - - //let! rawData = safeGetFromUrl (auth, url, acceptJson) - //return - // match rawData with - // | NotFound -> - // raise <| System.Exception(sprintf "could not get catalog data (404) from '%s'" url) - // | UnknownError err -> - // raise <| System.Exception(sprintf "could not get catalog data from %s" url, err.SourceException) - // | SuccessResponse x -> JsonConvert.DeserializeObject(x) } let getPackageDetails (source:NugetV3Source) (packageName:PackageName) (version:SemVerInfo) : Async =