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

Implement --no-install and --redirects for "paket update". #847

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/Paket.Core/AddProcess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ let private add installToProjects addToProjectsF dependenciesFileName package ve

if installAfter then
let sources = dependenciesFile.GetAllPackageSources()
InstallProcess.Install(sources, { SmartInstallOptions.Default with Common = options }, lockFile)
InstallProcess.Install(sources, options, lockFile)

// Add a package with the option to add it to a specified project.
let AddToProject(dependenciesFileName, package, version, options : InstallerOptions, projectName, installAfter) =
Expand Down
12 changes: 6 additions & 6 deletions src/Paket.Core/InstallProcess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ let findAllReferencesFiles root =
|> collect

/// Installs all packages from the lock file.
let InstallIntoProjects(sources, options : SmartInstallOptions, lockFile : LockFile, projects : (ProjectFile * ReferencesFile) list) =
let InstallIntoProjects(sources, options : InstallerOptions, lockFile : LockFile, projects : (ProjectFile * ReferencesFile) list) =
let packagesToInstall =
if options.OnlyReferenced then
projects
Expand All @@ -163,7 +163,7 @@ let InstallIntoProjects(sources, options : SmartInstallOptions, lockFile : LockF
|> Seq.map (fun kv -> kv.Key)

let root = Path.GetDirectoryName lockFile.FileName
let extractedPackages = createModel(root, sources, options.Common.Force, lockFile, Set.ofSeq packagesToInstall)
let extractedPackages = createModel(root, sources, options.Force, lockFile, Set.ofSeq packagesToInstall)

let model =
extractedPackages
Expand Down Expand Up @@ -255,7 +255,7 @@ let InstallIntoProjects(sources, options : SmartInstallOptions, lockFile : LockF
|> Seq.map (fun u -> NormalizedPackageName u.Key,u.Value)
|> Map.ofSeq

project.UpdateReferences(model, usedPackageSettings, options.Common.Hard)
project.UpdateReferences(model, usedPackageSettings, options.Hard)

removeCopiedFiles project

Expand All @@ -282,15 +282,15 @@ let InstallIntoProjects(sources, options : SmartInstallOptions, lockFile : LockF
Include = createRelativePath project.FileName file.FullName
Link = None })

project.UpdateFileItems(gitRemoteItems @ nuGetFileItems, options.Common.Hard)
project.UpdateFileItems(gitRemoteItems @ nuGetFileItems, options.Hard)

project.Save()

if options.Common.Redirects || lockFile.Options.Redirects then
if options.Redirects || lockFile.Options.Redirects then
applyBindingRedirects root extractedPackages

/// Installs all packages from the lock file.
let Install(sources, options : SmartInstallOptions, lockFile : LockFile) =
let Install(sources, options : InstallerOptions, lockFile : LockFile) =
let root = FileInfo(lockFile.FileName).Directory.FullName
let projects = findAllReferencesFiles root |> returnOrFail
InstallIntoProjects(sources, options, lockFile, projects)
2 changes: 1 addition & 1 deletion src/Paket.Core/NugetConvert.fs
Original file line number Diff line number Diff line change
Expand Up @@ -407,4 +407,4 @@ let replaceNugetWithPaket initAutoRestore installAfter result =
if installAfter then
UpdateProcess.Update(
result.PaketEnv.DependenciesFile.FileName,
{ InstallerOptions.Default with Force = true; Hard = true; Redirects = true })
{ UpdaterOptions.Default with Common = { InstallerOptions.Default with Force = true; Hard = true; Redirects = true }})
21 changes: 12 additions & 9 deletions src/Paket.Core/ProcessOptions.fs
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
namespace Paket

// Options for UpdateProcess and InstallProcess.
/// Force - Force the download and reinstallation of all packages
/// Hard - Replace package references within project files even if they are not yet adhering
/// to the Paket's conventions (and hence considered manually managed)
/// Redirects - Create binding redirects for the NuGet packages
/// Force - Force the download and reinstallation of all packages
/// Hard - Replace package references within project files even if they are not yet adhering
/// to the Paket's conventions (and hence considered manually managed)
/// Redirects - Create binding redirects for the NuGet packages
/// OnlyReferenced - Only install packages that are referenced in paket.references files.
type InstallerOptions =
{ Force : bool
Hard : bool
Redirects : bool }
Redirects : bool
OnlyReferenced : bool }

static member Default =
{ Force = false
Hard = false
Redirects = false }
Redirects = false
OnlyReferenced = false }

static member createLegacyOptions(force, hard, redirects) =
{ InstallerOptions.Default with
Force = force
Hard = hard
Redirects = redirects }

type SmartInstallOptions =
type UpdaterOptions =
{ Common : InstallerOptions
OnlyReferenced : bool }
NoInstall : bool }

static member Default =
{ Common = InstallerOptions.Default
OnlyReferenced = false }
NoInstall = false }
32 changes: 22 additions & 10 deletions src/Paket.Core/PublicAPI.fs
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,14 @@ type Dependencies(dependenciesFileName: string) =

/// Installs all dependencies.
member this.Install(force: bool, hard: bool, withBindingRedirects: bool, onlyReferenced: bool): unit =
this.Install({ SmartInstallOptions.Default with
Common = { SmartInstallOptions.Default.Common with Force = force; Hard = hard; Redirects = withBindingRedirects }
OnlyReferenced = onlyReferenced })
this.Install({ InstallerOptions.createLegacyOptions(force, hard, withBindingRedirects) with OnlyReferenced = onlyReferenced })

/// Installs all dependencies.
member private this.Install(options: SmartInstallOptions): unit =
member private this.Install(options: InstallerOptions): unit =
Utils.RunInLockedAccessMode(
this.RootPath,
fun () -> UpdateProcess.SmartInstall(dependenciesFileName, None, options))
fun () -> UpdateProcess.SmartInstall(dependenciesFileName, None,
{ UpdaterOptions.Default with Common = options }))

/// Creates a paket.dependencies file with the given text in the current directory and installs it.
static member Install(dependencies, ?path: string, ?force, ?hard, ?withBindingRedirects) =
Expand All @@ -168,21 +167,34 @@ type Dependencies(dependenciesFileName: string) =
hard = defaultArg hard false,
withBindingRedirects = defaultArg withBindingRedirects false)

/// Updates all dependencies.
member this.Update(force: bool, hard: bool): unit = this.Update(force, hard, false)

/// Updates all dependencies.
member this.Update(force: bool,hard: bool,withBindingRedirects:bool): unit =
Utils.RunInLockedAccessMode(
this.RootPath,
fun () -> UpdateProcess.Update(dependenciesFileName, InstallerOptions.createLegacyOptions(force, hard, withBindingRedirects)))
this.Update(force, hard, withBindingRedirects, true)

/// Updates all dependencies.
member this.Update(force: bool, hard: bool): unit = this.Update(force, hard, false)
member this.Update(force: bool, hard: bool, withBindingRedirects: bool, installAfter: bool): unit =
Utils.RunInLockedAccessMode(
this.RootPath,
fun () -> UpdateProcess.Update(dependenciesFileName,
{ UpdaterOptions.Default with
Common = InstallerOptions.createLegacyOptions(force, hard, withBindingRedirects)
NoInstall = installAfter |> not }))

/// Updates the given package.
member this.UpdatePackage(package: string, version: string option, force: bool, hard: bool): unit =
this.UpdatePackage(package, version, force, hard, false, true)

/// Updates the given package.
member this.UpdatePackage(package: string, version: string option, force: bool, hard: bool, withBindingRedirects: bool, installAfter: bool): unit =
Utils.RunInLockedAccessMode(
this.RootPath,
fun () -> UpdateProcess.UpdatePackage(dependenciesFileName, PackageName package, version,
InstallerOptions.createLegacyOptions(force, hard, false)))
{ UpdaterOptions.Default with
Common = InstallerOptions.createLegacyOptions(force, hard, withBindingRedirects)
NoInstall = installAfter |> not }))

/// Restores all dependencies.
member this.Restore(): unit = this.Restore(false,[])
Expand Down
7 changes: 2 additions & 5 deletions src/Paket.Core/RemoveProcess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,14 @@ let private remove removeFromProjects dependenciesFileName (package: PackageName
let lockFile =
if stillInstalled then oldLockFile else
let exisitingDependenciesFile = DependenciesFile.ReadFromFile dependenciesFileName
let dependenciesFile =
exisitingDependenciesFile
.Remove(package)

let dependenciesFile = exisitingDependenciesFile.Remove(package)
dependenciesFile.Save()

UpdateProcess.SelectiveUpdate(dependenciesFile,None,force)

if installAfter then
let sources = DependenciesFile.ReadFromFile(dependenciesFileName).GetAllPackageSources()
InstallProcess.Install(sources, { SmartInstallOptions.Default with Common = { InstallerOptions.Default with Force = force; Hard = hard; Redirects = false }}, lockFile )
InstallProcess.Install(sources, InstallerOptions.createLegacyOptions(force, hard, false), lockFile )

// remove a package with the option to remove it from a specified project
let RemoveFromProject(dependenciesFileName, package:PackageName, force, hard, projectName, installAfter) =
Expand Down
20 changes: 9 additions & 11 deletions src/Paket.Core/UpdateProcess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -67,33 +67,31 @@ let SelectiveUpdate(dependenciesFile : DependenciesFile, exclude, force) =
LockFile.Create(lockFileName.FullName, dependenciesFile.Options, resolution.ResolvedPackages, resolution.ResolvedSourceFiles)

/// Smart install command
let SmartInstall(dependenciesFileName, exclude, options : SmartInstallOptions) =
let SmartInstall(dependenciesFileName, exclude, options : UpdaterOptions) =
let root = Path.GetDirectoryName dependenciesFileName
let projects = InstallProcess.findAllReferencesFiles root |> returnOrFail
let dependenciesFile = DependenciesFile.ReadFromFile(dependenciesFileName)

let lockFile = SelectiveUpdate(dependenciesFile,exclude,options.Common.Force)

InstallProcess.InstallIntoProjects(
dependenciesFile.GetAllPackageSources(),
options,
lockFile,
projects)
if not options.NoInstall then
InstallProcess.InstallIntoProjects(
dependenciesFile.GetAllPackageSources(),
options.Common, lockFile, projects)

/// Update a single package command
let UpdatePackage(dependenciesFileName, packageName : PackageName, newVersion, options : InstallerOptions) =
let UpdatePackage(dependenciesFileName, packageName : PackageName, newVersion, options : UpdaterOptions) =
match newVersion with
| Some v ->
DependenciesFile.ReadFromFile(dependenciesFileName)
.UpdatePackageVersion(packageName, v)
.Save()
| None -> tracefn "Updating %s in %s" (packageName.ToString()) dependenciesFileName

SmartInstall(dependenciesFileName, Some(NormalizedPackageName packageName),
{ SmartInstallOptions.Default with Common = options })
SmartInstall(dependenciesFileName, Some(NormalizedPackageName packageName), options)

/// Update command
let Update(dependenciesFileName, options : InstallerOptions) =
let Update(dependenciesFileName, options : UpdaterOptions) =
let lockFileName = DependenciesFile.FindLockfile dependenciesFileName
if lockFileName.Exists then lockFileName.Delete()
SmartInstall(dependenciesFileName, None, { SmartInstallOptions.Default with Common = options })
SmartInstall(dependenciesFileName, None, options)
2 changes: 2 additions & 0 deletions src/Paket/Commands.fs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ type UpdateArgs =
| [<AltCommandLine("-f")>] Force
| Hard
| Redirects
| No_Install
with
interface IArgParserTemplate with
member this.Usage =
Expand All @@ -202,6 +203,7 @@ with
| Force -> "Forces the download and reinstallation of all packages."
| Hard -> "Replaces package references within project files even if they are not yet adhering to the Paket's conventions (and hence considered manually managed)."
| Redirects -> "Creates binding redirects for the NuGet packages."
| No_Install -> "Skips paket install --hard process afterward generation of paket.lock file."

type FindPackagesArgs =
| [<CustomCommandLine("searchtext")>] SearchText of string
Expand Down
7 changes: 4 additions & 3 deletions src/Paket/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,14 @@ let simplify (results : ArgParseResults<_>) =
let update (results : ArgParseResults<_>) =
let hard = results.Contains <@ UpdateArgs.Hard @>
let force = results.Contains <@ UpdateArgs.Force @>
let noInstall = results.Contains <@ UpdateArgs.No_Install @>
let withBindingRedirects = results.Contains <@ UpdateArgs.Redirects @>
match results.TryGetResult <@ UpdateArgs.Nuget @> with
| Some packageName ->
let version = results.TryGetResult <@ UpdateArgs.Version @>
Dependencies.Locate().UpdatePackage(packageName, version, force, hard)
Dependencies.Locate().UpdatePackage(packageName, version, force, hard, withBindingRedirects, noInstall |> not)
| _ ->
let withBindingRedirects = results.Contains <@ UpdateArgs.Redirects @>
Dependencies.Locate().Update(force, hard, withBindingRedirects)
Dependencies.Locate().Update(force, hard, withBindingRedirects, noInstall |> not)

let pack (results : ArgParseResults<_>) =
let outputPath = results.GetResult <@ PackArgs.Output @>
Expand Down