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

Allow filtered updates of packages matching a regex #1178

Merged
merged 7 commits into from
Oct 30, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
5 changes: 5 additions & 0 deletions src/Paket.Core/PackageResolver.fs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ type Resolved = {
type UpdateMode =
| UpdatePackage of GroupName * PackageName
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we remove that case and express it as UpdateFiltered of GroupName * PackageFilter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As in, escape .s and treat it as a filter? I think it would work. Hope your regression tests are good up to date though! :D

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Give me a few minutes and I'll see if all the tests pass.

| UpdateGroup of GroupName
| UpdateFiltered of GroupName * PackageFilter
| Install
| UpdateAll

Expand Down Expand Up @@ -323,6 +324,10 @@ let Resolve(groupName:GroupName, sources, getVersionsF, getPackageDetailsF, stra
match groupName = g && currentRequirement.Name = p with
| true -> ResolverStrategy.Max
| false -> combined
| UpdateFiltered (g, f) ->
match groupName = g && f.Match currentRequirement.Name with
| true -> ResolverStrategy.Max
| false -> combined

// we didn't select a version yet so all versions are possible
let isInRange mapF ver =
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
28 changes: 28 additions & 0 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 @@ -202,6 +215,21 @@ let UpdatePackage(dependenciesFileName, groupName, packageName : PackageName, ne

SmartInstall(dependenciesFile, UpdatePackage(groupName,packageName), 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) =
let dependenciesFile = DependenciesFile.ReadFromFile(dependenciesFileName)
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