Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/mavnn/Paket
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Oct 30, 2015
2 parents f00a786 + 27f7f2f commit a7e0bb7
Show file tree
Hide file tree
Showing 14 changed files with 174 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@
<Compile Include="AssemblyInfo.fs" />
<Compile Include="TestHelper.fs" />
<Compile Include="InitSpecs.fs" />
<Compile Include="OutdatedSpecs.fs" />
<Compile Include="GroupSpecs.fs" />
<Compile Include="FrameworkRestrictionsSpecs.fs" />
<Compile Include="UpdatePackageSpecs.fs" />
<Compile Include="AddSpecs.fs" />
<Compile Include="OutdatedSpecs.fs" />
<Compile Include="InstallSpecs.fs" />
Expand Down
33 changes: 33 additions & 0 deletions integrationtests/Paket.IntegrationTests/UpdatePackageSpecs.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module Paket.IntegrationTests.UpdatePackageSpecs

open Fake
open System
open NUnit.Framework
open FsUnit
open System
open System.IO
open System.Diagnostics
open Paket
open Paket.Domain

[<Test>]
let ``#1178 update with Mircosoft.* filter``() =
paket "update nuget Microsoft.* --filter" "i001178-update-with-regex" |> ignore
let lockFile = LockFile.LoadFrom(Path.Combine(scenarioTempPath "i001178-update-with-regex","paket.lock"))
lockFile.Groups.[Constants.MainDependencyGroup].Resolution.[PackageName "Castle.Windsor"].Version
|> shouldEqual (SemVer.Parse "2.5.1")
lockFile.Groups.[Constants.MainDependencyGroup].Resolution.[PackageName "NUnit"].Version
|> shouldEqual (SemVer.Parse "2.6.1")
lockFile.Groups.[Constants.MainDependencyGroup].Resolution.[PackageName "Microsoft.AspNet.WebApi.SelfHost"].Version
|> shouldBeGreaterThan (SemVer.Parse "5.0.1")

[<Test>]
let ``#1178 update with [MN].* --filter``() =
paket "update nuget [MN].* --filter" "i001178-update-with-regex" |> ignore
let lockFile = LockFile.LoadFrom(Path.Combine(scenarioTempPath "i001178-update-with-regex","paket.lock"))
lockFile.Groups.[Constants.MainDependencyGroup].Resolution.[PackageName "Castle.Windsor"].Version
|> shouldEqual (SemVer.Parse "2.5.1")
lockFile.Groups.[Constants.MainDependencyGroup].Resolution.[PackageName "NUnit"].Version
|> shouldBeGreaterThan (SemVer.Parse "2.6.1")
lockFile.Groups.[Constants.MainDependencyGroup].Resolution.[PackageName "Microsoft.AspNet.WebApi.SelfHost"].Version
|> shouldBeGreaterThan (SemVer.Parse "5.0.1")
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source https://nuget.org/api/v2

nuget Castle.Windsor
nuget NUnit
nuget Microsoft.AspNet.WebApi.SelfHost
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
NUGET
remote: https://nuget.org/api/v2
specs:
Castle.Core (3.3.3)
Castle.Windsor (2.5.1)
Castle.Core (>= 2.5.1)
Microsoft.AspNet.WebApi.Client (5.2.3)
Microsoft.Net.Http (>= 2.2.22) - framework: portable-wp80+win+net45+wp81+wpa81
Newtonsoft.Json (>= 6.0.4) - framework: portable-wp80+win+net45+wp81+wpa81, >= net45
Microsoft.AspNet.WebApi.Core (5.0.0)
Microsoft.AspNet.WebApi.Client (>= 5.0.0)
Microsoft.AspNet.WebApi.SelfHost (5.0.1)
Microsoft.AspNet.WebApi.Core (>= 5.0.0 < 5.1)
Microsoft.Bcl (1.1.10) - framework: portable-wp80+win+net45+wp81+wpa81
Microsoft.Bcl.Build (>= 1.0.14)
Microsoft.Bcl.Build (1.0.21) - import_targets: false, framework: portable-wp80+win+net45+wp81+wpa81
Microsoft.Net.Http (2.2.29) - framework: portable-wp80+win+net45+wp81+wpa81
Microsoft.Bcl (>= 1.1.10)
Microsoft.Bcl.Build (>= 1.0.14)
Newtonsoft.Json (7.0.1) - framework: portable-wp80+win+net45+wp81+wpa81, >= net45
NUnit (2.6.1)
18 changes: 18 additions & 0 deletions src/Paket.Core/Domain.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Paket.Domain

open System.IO
open System.Text.RegularExpressions

/// Represents a NuGet package name
[<System.Diagnostics.DebuggerDisplay("{Item}")>]
Expand Down Expand Up @@ -32,6 +33,23 @@ type PackageName =
/// Function to convert a string into a NuGet package name
let PackageName(name:string) = PackageName.PackageName(name.Trim(),name.ToLowerInvariant().Trim())

// Represents a filter of normalized package names
[<System.Diagnostics.DebuggerDisplay("{Item}")>]
type PackageFilter =
| PackageFilter of string
member this.regex =
match this with
| PackageFilter f ->
Regex("^" + f + "$",
RegexOptions.Compiled
||| RegexOptions.CultureInvariant
||| RegexOptions.IgnoreCase)
member this.Match (packageName : PackageName) =
this.regex.IsMatch (packageName.GetCompareString())
override this.ToString() =
match this with
| PackageFilter filter -> filter

/// Represents a normalized group name
[<System.Diagnostics.DebuggerDisplay("{Item}")>]
[<CustomEquality;CustomComparison>]
Expand Down
12 changes: 6 additions & 6 deletions src/Paket.Core/PackageResolver.fs
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ type Resolved = {
ResolvedSourceFiles : ModuleResolver.ResolvedSourceFile list }

type UpdateMode =
| UpdatePackage of GroupName * PackageName
| UpdateGroup of GroupName
| UpdateFiltered of GroupName * PackageFilter
| Install
| UpdateAll

Expand All @@ -197,9 +197,9 @@ let Resolve(groupName:GroupName, sources, getVersionsF, getPackageDetailsF, stra
tracefn "Resolving packages for group %O:" groupName
let lastConflictReported = ref DateTime.Now

let startWithPackage =
let packageFilter =
match updateMode with
| UpdatePackage(_,p) -> Some p
| UpdateFiltered (_, f) -> Some f
| _ -> None

let rootSettings =
Expand Down Expand Up @@ -263,7 +263,7 @@ let Resolve(groupName:GroupName, sources, getVersionsF, getPackageDetailsF, stra
match conflictHistory.TryGetValue d.Name with
| true,c -> -c
| _ -> 0
if PackageRequirement.Compare(d,!currentMin,startWithPackage,boost,!currentBoost) = -1 then
if PackageRequirement.Compare(d,!currentMin,packageFilter,boost,!currentBoost) = -1 then
currentMin := d
currentBoost := boost
!currentMin
Expand Down Expand Up @@ -319,8 +319,8 @@ let Resolve(groupName:GroupName, sources, getVersionsF, getPackageDetailsF, stra
match currentRequirement.Parent.IsRootRequirement(), Set.count currentRequirements with
| true, 1 -> ResolverStrategy.Max
| _ -> combined
| UpdatePackage (g, p) ->
match groupName = g && currentRequirement.Name = p with
| UpdateFiltered (g, f) ->
match groupName = g && f.Match currentRequirement.Name with
| true -> ResolverStrategy.Max
| false -> combined

Expand Down
14 changes: 14 additions & 0 deletions src/Paket.Core/PublicAPI.fs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,20 @@ type Dependencies(dependenciesFileName: string) =
Common = InstallerOptions.CreateLegacyOptions(force, hard, withBindingRedirects, createNewBindingFiles, semVerUpdateMode)
NoInstall = installAfter |> not }))

/// Update a filtered set of packages
member this.UpdateFilteredPackages(groupName: string option, package: string, version: string option, force: bool, hard: bool, withBindingRedirects: bool, createNewBindingFiles:bool, installAfter: bool, semVerUpdateMode): unit =
let groupName =
match groupName with
| None -> Constants.MainDependencyGroup
| Some name -> GroupName name

Utils.RunInLockedAccessMode(
this.RootPath,
fun () -> UpdateProcess.UpdateFilteredPackages(dependenciesFileName, groupName, PackageName package, version,
{ UpdaterOptions.Default with
Common = InstallerOptions.CreateLegacyOptions(force, hard, withBindingRedirects, createNewBindingFiles, semVerUpdateMode)
NoInstall = installAfter |> not }))

/// Updates the given package.
member this.UpdatePackage(groupName, package: string, version: string option, force: bool, hard: bool, semVerUpdateMode): unit =
this.UpdatePackage(groupName, package, version, force, hard, false, false, true, semVerUpdateMode)
Expand Down
6 changes: 3 additions & 3 deletions src/Paket.Core/Requirements.fs
Original file line number Diff line number Diff line change
Expand Up @@ -433,15 +433,15 @@ type PackageRequirement =

member this.Depth = this.Graph.Length

static member Compare(x,y,startWithPackage:PackageName option,boostX,boostY) =
static member Compare(x,y,startWithPackage:PackageFilter option,boostX,boostY) =
if x = y then 0 else
seq {
yield compare
(not x.VersionRequirement.Range.IsGlobalOverride,x.Depth)
(not y.VersionRequirement.Range.IsGlobalOverride,y.Depth)
yield match startWithPackage with
| Some name when name = x.Name -> -1
| Some name when name = y.Name -> 1
| Some filter when filter.Match x.Name -> -1
| Some filter when filter.Match y.Name -> 1
| _ -> 0
yield -compare x.ResolverStrategy y.ResolverStrategy
yield compare boostX boostY
Expand Down
42 changes: 31 additions & 11 deletions src/Paket.Core/UpdateProcess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@ let selectiveUpdate force getSha1 getSortedVersionsF getPackageDetailsF (lockFil
dependenciesFile.Groups
|> Map.filter (fun k _ -> k = groupName)

changes,groups
| UpdateFiltered (groupName, filter) ->
let changes =
lockFile.GetGroupedResolution()
|> Seq.map (fun k -> k.Key)
|> Seq.filter (fun (g,_) -> g = groupName)
|> Seq.filter (fun (_, p) -> filter.Match p)
|> Set.ofSeq

let groups =
dependenciesFile.Groups
|> Map.filter (fun k _ -> k = groupName)

changes,groups
| Install ->
let nuGetChanges = DependencyChangeDetection.findNuGetChangesInDependenciesFile(dependenciesFile,lockFile)
Expand Down Expand Up @@ -116,16 +129,6 @@ let selectiveUpdate force getSha1 getSortedVersionsF getPackageDetailsF (lockFil
|> Map.filter hasChanges

nuGetChanges,groups
| UpdatePackage(groupName,packageName) ->
let changes =
lockFile.GetAllNormalizedDependenciesOf(groupName,packageName)
|> Set.ofSeq

let groups =
dependenciesFile.Groups
|> Map.filter (fun key _ -> key = groupName)

changes,groups

let preferredVersions =
DependencyChangeDetection.GetPreferredNuGetVersions lockFile
Expand Down Expand Up @@ -200,7 +203,24 @@ let UpdatePackage(dependenciesFileName, groupName, packageName : PackageName, ne
tracefn "Updating %O in %s group %O" packageName dependenciesFileName groupName
dependenciesFile

SmartInstall(dependenciesFile, UpdatePackage(groupName,packageName), options)
let filter = PackageFilter (packageName.ToString().Replace(".", "\\."))

SmartInstall(dependenciesFile, UpdateFiltered(groupName,filter), options)

/// Update a filtered list of packages
let UpdateFilteredPackages(dependenciesFileName, groupName, packageName : PackageName, newVersion, options : UpdaterOptions) =
let dependenciesFile = DependenciesFile.ReadFromFile(dependenciesFileName)

let filter = PackageFilter <| packageName.ToString()

let dependenciesFile =
match newVersion with
| Some v -> dependenciesFile.UpdatePackageVersion(groupName,packageName, v)
| None ->
tracefn "Updating %O in %s group %O" packageName dependenciesFileName groupName
dependenciesFile

SmartInstall(dependenciesFile, UpdateFiltered(groupName, filter), options)

/// Update a single group command
let UpdateGroup(dependenciesFileName, groupName, options : UpdaterOptions) =
Expand Down
2 changes: 2 additions & 0 deletions src/Paket/Commands.fs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ type UpdateArgs =
| Keep_Major
| Keep_Minor
| Keep_Patch
| Filter
with
interface IArgParserTemplate with
member this.Usage =
Expand All @@ -236,6 +237,7 @@ with
| Keep_Major -> "Allows only updates that are not changing the major version of the NuGet packages."
| Keep_Minor -> "Allows only updates that are not changing the minor version of the NuGet packages."
| Keep_Patch -> "Allows only updates that are not changing the patch version of the NuGet packages."
| Filter -> "Treat the nuget parameter as a regex to filter packages rather than an exact match."

type FindPackagesArgs =
| [<CustomCommandLine("searchtext")>] SearchText of string
Expand Down
6 changes: 5 additions & 1 deletion src/Paket/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,15 @@ let update (results : ParseResults<_>) =
if results.Contains <@ UpdateArgs.Keep_Minor @> then SemVerUpdateMode.KeepMinor else
if results.Contains <@ UpdateArgs.Keep_Major @> then SemVerUpdateMode.KeepMajor else
SemVerUpdateMode.NoRestriction
let filter = results.Contains <@ UpdateArgs.Filter @>

match results.TryGetResult <@ UpdateArgs.Nuget @> with
| Some packageName ->
let version = results.TryGetResult <@ UpdateArgs.Version @>
Dependencies.Locate().UpdatePackage(group, packageName, version, force, hard, withBindingRedirects, createNewBindingFiles, noInstall |> not, semVerUpdateMode)
if filter then
Dependencies.Locate().UpdateFilteredPackages(group, packageName, version, force, hard, withBindingRedirects, createNewBindingFiles, noInstall |> not, semVerUpdateMode)
else
Dependencies.Locate().UpdatePackage(group, packageName, version, force, hard, withBindingRedirects, createNewBindingFiles, noInstall |> not, semVerUpdateMode)
| _ ->
match group with
| Some groupName ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ let ``should update to lastest when updating all``() =
let ``should respect overrides when updating single package``() =
let resolved =
DependenciesFile.FromCode(config6)
|> resolve graph2 (UpdateMode.UpdatePackage(Constants.MainDependencyGroup, PackageName "Castle.Windsor-NLog"))
|> resolve graph2 (UpdateMode.UpdateFiltered(Constants.MainDependencyGroup, PackageFilter "Castle\\.Windsor-NLog"))
getVersion resolved.[PackageName "Castle.Windsor-NLog"] |> shouldEqual "3.3.0"
getVersion resolved.[PackageName "Castle.Core-NLog"] |> shouldEqual "3.3.1"
getVersion resolved.[PackageName "Castle.Core"] |> shouldEqual "3.3.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ let ``should favor strategy override when updating all``() =
let ``should respect overrides when updating single package``() =
let resolved =
DependenciesFile.FromCode(config6)
|> resolve graph2 (UpdateMode.UpdatePackage(Constants.MainDependencyGroup, PackageName "Castle.Windsor-NLog"))
|> resolve graph2 (UpdateMode.UpdateFiltered(Constants.MainDependencyGroup, PackageFilter "Castle\\.Windsor-NLog"))
getVersion resolved.[PackageName "Castle.Windsor-NLog"] |> shouldEqual "3.3.0"
getVersion resolved.[PackageName "Castle.Core-NLog"] |> shouldEqual "3.3.0"
getVersion resolved.[PackageName "Castle.Core"] |> shouldEqual "3.3.1"
Expand Down
Loading

0 comments on commit a7e0bb7

Please sign in to comment.