Skip to content

Commit

Permalink
Put fixed packages to the end - references #814
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed May 6, 2015
1 parent 058ac97 commit 97c9db3
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 27 deletions.
3 changes: 3 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#### 1.3.23 - 06.05.2015
* BUGFIX: Put fixed packages to the end - https://github.com/fsprojects/Paket/issues/814

#### 1.3.22 - 06.05.2015
* BUGFIX: Fix `paket add` if package is already there - https://github.com/fsprojects/Paket/issues/814

Expand Down
58 changes: 31 additions & 27 deletions src/Paket.Core/DependenciesFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,8 @@ type DependenciesFile(fileName,options,sources,packages : PackageRequirement lis
{ ResolvedPackages = PackageResolver.Resolve(getVersionF, getPackageDetailsF, options.Settings.FrameworkRestrictions, remoteDependencies @ packages)
ResolvedSourceFiles = remoteFiles }

member __.AddAdditionalPackage(packageName:PackageName,versionRequirement,resolverStrategy,settings) =
member __.AddAdditionalPackage(packageName:PackageName,versionRequirement,resolverStrategy,settings,?toTheEnd) =
let toTheEnd = defaultArg toTheEnd false
let packageString = DependenciesFileSerializer.packageString packageName versionRequirement resolverStrategy settings

// Try to find alphabetical matching position to insert the package
Expand All @@ -342,34 +343,37 @@ type DependenciesFile(fileName,options,sources,packages : PackageRequirement lis
let newLines =
let list = new System.Collections.Generic.List<_>()
list.AddRange textRepresentation
match tryFindPackageLine packageName with
| Some pos -> list.[pos] <- packageString
| None ->
match smaller with
| [] ->
match packages with
| [] ->
if remoteFiles <> [] then
list.Insert(0,"")
if toTheEnd then
list.Add(packageString)
else
match tryFindPackageLine packageName with
| Some pos -> list.[pos] <- packageString
| None ->
match smaller with
| [] ->
match packages with
| [] ->
if remoteFiles <> [] then
list.Insert(0,"")

match sources with
| [] ->
list.Insert(0,packageString)
list.Insert(0,"")
list.Insert(0,DependenciesFileSerializer.sourceString Constants.DefaultNugetStream)
| _ ->
list.Add("")
list.Add(packageString)
| p::_ ->
match sources with
| [] ->
list.Insert(0,packageString)
list.Insert(0,"")
list.Insert(0,DependenciesFileSerializer.sourceString Constants.DefaultNugetStream)
| _ ->
list.Add("")
list.Add(packageString)
| p::_ ->
match tryFindPackageLine p.Name with
| None -> list.Add packageString
| Some pos -> list.Insert(pos,packageString)
| _ ->
let p = Seq.last smaller

match tryFindPackageLine p.Name with
| None -> list.Add packageString
| Some pos -> list.Insert(pos,packageString)
| _ ->
let p = Seq.last smaller

match tryFindPackageLine p.Name with
| None -> list.Add packageString
| Some pos -> list.Insert(pos + 1,packageString)
| Some pos -> list.Insert(pos + 1,packageString)

list |> Seq.toArray

Expand All @@ -393,7 +397,7 @@ type DependenciesFile(fileName,options,sources,packages : PackageRequirement lis
| _ -> vr.VersionRequirement
| None -> vr.ResolverStrategy,vr.VersionRequirement

this.AddAdditionalPackage(packageName,versionRequirement,resolverStrategy,settings)
this.AddAdditionalPackage(packageName,versionRequirement,resolverStrategy,settings,true)

member this.AddFixedPackage(packageName:PackageName,version:string) =
this.AddFixedPackage(packageName,version,InstallSettings.Default)
Expand Down
28 changes: 28 additions & 0 deletions tests/Paket.Tests/DependenciesFile/AddPackageSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -304,3 +304,31 @@ nuget log4net 1.2.10"""
cfg.ToString()
|> shouldEqual (normalizeLineEndings expected)

[<Test>]
let ``should pin Microsoft.AspNet.WebApi.Client package in correct position``() =
let config = """source http://internalfeed/NugetWebFeed/nuget
nuget Microsoft.AspNet.WebApi.Core 5.2.3
nuget Microsoft.AspNet.WebApi.WebHost 5.2.3
nuget log4net
source https://nuget.org/api/v2
nuget Microsoft.AspNet.WebApi
nuget log4net 1.2.10"""

let cfg = DependenciesFile.FromCode(config).AddFixedPackage(PackageName "Microsoft.AspNet.WebApi.Client","5.2.3")

let expected = """source http://internalfeed/NugetWebFeed/nuget
nuget Microsoft.AspNet.WebApi.Core 5.2.3
nuget Microsoft.AspNet.WebApi.WebHost 5.2.3
nuget log4net
source https://nuget.org/api/v2
nuget Microsoft.AspNet.WebApi
nuget log4net 1.2.10
nuget Microsoft.AspNet.WebApi.Client 5.2.3"""

cfg.ToString()
|> shouldEqual (normalizeLineEndings expected)

0 comments on commit 97c9db3

Please sign in to comment.