Skip to content

Commit

Permalink
Check if a feed supports a protocol and never retry if not - references
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Sep 29, 2015
1 parent 2e70c1a commit 5150eb1
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 51 deletions.
21 changes: 5 additions & 16 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
#### 2.4.11 - 29.09.2015
#### 2.5.0-alpha001 - 29.09.2015
* Remove all Paket entries from projects which have no paket.references - https://github.com/fsprojects/Paket/issues/1097

#### 2.4.10 - 29.09.2015
* Allow to format VersionRequirements in NuGet syntax

#### 2.4.9 - 29.09.2015
* BUGFIX: Fix KeyNotFoundException when project is net4.0-client - https://github.com/fsprojects/Paket/issues/1095

#### 2.4.8 - 28.09.2015
* Put prerelease requirement into NuSpec during paket pack - https://github.com/fsprojects/Paket/issues/1088

#### 2.4.7 - 28.09.2015
* Skip asking for versions if only a specific version is requested

#### 2.4.6 - 28.09.2015
* Only fixup dates in zip archive under Mono - https://github.com/fsprojects/Paket/pull/1094
* BUGFIX: Put prerelease requirement into NuSpec during paket pack - https://github.com/fsprojects/Paket/issues/1088
* BUGFIX: Inconsistent framework exclusion in paket.dependencies - https://github.com/fsprojects/Paket/issues/1093

#### 2.4.1 - 28.09.2015
* BUGFIX: Commands add/remove stripped link:false from file references - https://github.com/fsprojects/Paket/issues/1089
* COSMETICS: Only fixup dates in zip archive under Mono - https://github.com/fsprojects/Paket/pull/1094
* PERFORMANCE: Skip asking for versions if only a specific version is requested
* PERFORMANCE: Check if a feed supports a protocol and never retry if not - https://github.com/fsprojects/Paket/issues/1085

#### 2.4.0 - 28.09.2015
* BUGFIX: Paket does not touch config files when the list of binding redirects to add is empty - https://github.com/fsprojects/Paket/pull/1092
Expand Down
90 changes: 58 additions & 32 deletions src/Paket.Core/NuGetV2.fs
Original file line number Diff line number Diff line change
Expand Up @@ -66,62 +66,88 @@ let getAllVersionsFromNugetODataWithFilter (getUrlContents, nugetURL, package) =
verbosefn "getAllVersionsFromNugetODataWithFilter from url '%s'" url
followODataLink getUrlContents url

let protocolCache = System.Collections.Generic.HashSet<_>()

/// Gets versions of the given package via OData via /FindPackagesById()?id='packageId'.
let getAllVersionsFromNugetOData (getUrlContents, nugetURL, package) =
let getAllVersionsFromNugetOData (getUrlContents, nugetURL, auth, package) =
async {
// we cannot cache this
try
let url = sprintf "%s/FindPackagesById()?id='%s'" nugetURL package
verbosefn "getAllVersionsFromNugetOData from url '%s'" url
return! followODataLink getUrlContents url
with _ -> return! getAllVersionsFromNugetODataWithFilter (getUrlContents, nugetURL, package)
let probingCode = "NuGetV2-FindPackagesById"
if protocolCache.Contains((nugetURL,auth,probingCode)) then
return! getAllVersionsFromNugetODataWithFilter (getUrlContents, nugetURL, package)
else
try
let url = sprintf "%s/FindPackagesById()?id='%s'" nugetURL package
verbosefn "getAllVersionsFromNugetOData from url '%s'" url
return! followODataLink getUrlContents url
with _ ->
protocolCache.Add((nugetURL,auth,probingCode)) |> ignore
return! getAllVersionsFromNugetODataWithFilter (getUrlContents, nugetURL, package)
}

/// Gets all versions no. of the given package.
let getAllVersionsFromNuGet2(auth,nugetURL,package) =
// we cannot cache this
async {
let url = sprintf "%s/package-versions/%s?includePrerelease=true" nugetURL package
verbosefn "getAllVersionsFromNuGet2 from url '%s'" url
let! raw = safeGetFromUrl(auth, url, acceptJson)
let probingCode = "NuGetV2-package-versions"
let getUrlContents url acceptJson = getFromUrl(auth, url, acceptJson)
match raw with
| None -> let! result = getAllVersionsFromNugetOData(getUrlContents, nugetURL, package)
return result
| Some data ->
try
if protocolCache.Contains((nugetURL,auth,probingCode)) then
let! result = getAllVersionsFromNugetOData(getUrlContents, nugetURL, auth, package)
return result
else
let url = sprintf "%s/package-versions/%s?includePrerelease=true" nugetURL package
verbosefn "getAllVersionsFromNuGet2 from url '%s'" url
let! raw = safeGetFromUrl(auth, url, acceptJson)
match raw with
| None ->
protocolCache.Add((nugetURL,auth,probingCode)) |> ignore
let! result = getAllVersionsFromNugetOData(getUrlContents, nugetURL, auth, package)
return result
| Some data ->
try
let result = JsonConvert.DeserializeObject<string []>(data) |> Array.toSeq
return result
with _ -> verbosefn "exn when deserialising data '%s'" data
let! result = getAllVersionsFromNugetOData(getUrlContents, nugetURL, package)
return result
with exn ->
return! failwithf "Could not get data from %s for package %s.%s Message: %s" nugetURL package
Environment.NewLine exn.Message
try
let result = JsonConvert.DeserializeObject<string []>(data) |> Array.toSeq
return result
with _ ->
verbosefn "exn when deserialising data '%s'" data
protocolCache.Add((nugetURL,auth,probingCode)) |> ignore
let! result = getAllVersionsFromNugetOData(getUrlContents, nugetURL, auth, package)
return result
with exn ->
return! failwithf "Could not get data from %s for package %s.%s Message: %s" nugetURL package
Environment.NewLine exn.Message
}


let getAllVersions(auth, nugetURL, package) =
let tryNuGetV3() = async {
let tryNuGetV3() = async {
try
let! data = NuGetV3.findVersionsForPackage(auth, nugetURL, package, true, 100000)

return data
with
| exn -> return None }
| exn ->
return None }

let tryNuGet() = async {
let! data = tryNuGetV3()

match data with
| None ->
let probingCode = "NuGetV3"
if protocolCache.Contains((nugetURL,auth,probingCode)) then
let! result = getAllVersionsFromNuGet2(auth,nugetURL,package)
return result
| Some data when Array.isEmpty data ->
let! result = getAllVersionsFromNuGet2(auth,nugetURL,package)
return result
| Some data -> return (Array.toSeq data) }
else
let! data = tryNuGetV3()

match data with
| None ->
protocolCache.Add((nugetURL,auth,probingCode)) |> ignore
let! result = getAllVersionsFromNuGet2(auth,nugetURL,package)
return result
| Some data when Array.isEmpty data ->
protocolCache.Add((nugetURL,auth,probingCode)) |> ignore
let! result = getAllVersionsFromNuGet2(auth,nugetURL,package)
return result
| Some data ->
return (Array.toSeq data) }

async {
try
Expand Down
4 changes: 2 additions & 2 deletions src/Paket/Paket.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
<StartWorkingDirectory>c:\code\Paket09x</StartWorkingDirectory>
<StartWorkingDirectory>D:\code\Pakettest</StartWorkingDirectory>
<StartWorkingDirectory>D:\code\Paketkopie</StartWorkingDirectory>
<StartArguments>install</StartArguments>
<StartArguments>update</StartArguments>
<StartAction>Project</StartAction>
<StartProgram>paket.exe</StartProgram>
<StartWorkingDirectory>c:\code\Paketkopie</StartWorkingDirectory>
<StartWorkingDirectory>d:\code\PaketKopie</StartWorkingDirectory>
<StartWorkingDirectory>d:\code\PaketRepro</StartWorkingDirectory>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand Down
2 changes: 1 addition & 1 deletion tests/Paket.Tests/NuGetOData/ODataSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ let ``can calculate v3 path``() =
let ``can read all versions from single page with multiple entries``() =
let getUrlContentsStub _ _ = async { return File.ReadAllText "NuGetOData/NUnit.xml" }

let versions = getAllVersionsFromNugetOData(getUrlContentsStub, fakeUrl, "NUnit")
let versions = getAllVersionsFromNugetOData(getUrlContentsStub, fakeUrl, None, "NUnit")
|> Async.RunSynchronously

versions |> shouldContain "3.0.0-alpha-2"
Expand Down

0 comments on commit 5150eb1

Please sign in to comment.