From d6abb44acc0ac8a748ece47f4acab405e90bbb34 Mon Sep 17 00:00:00 2001 From: cr7pt0gr4ph7 Date: Thu, 28 May 2015 18:12:06 +0200 Subject: [PATCH] Implement --no-install and --redirects for "paket update". This commit also contains the following changes: - Merge SmallInstallOptions into InstallerOptions. - Add UpdaterOptions. --- src/Paket.Core/AddProcess.fs | 2 +- src/Paket.Core/InstallProcess.fs | 12 ++++++------ src/Paket.Core/NugetConvert.fs | 2 +- src/Paket.Core/ProcessOptions.fs | 21 ++++++++++++--------- src/Paket.Core/PublicAPI.fs | 32 ++++++++++++++++++++++---------- src/Paket.Core/RemoveProcess.fs | 7 ++----- src/Paket.Core/UpdateProcess.fs | 20 +++++++++----------- src/Paket/Commands.fs | 2 ++ src/Paket/Program.fs | 7 ++++--- 9 files changed, 59 insertions(+), 46 deletions(-) diff --git a/src/Paket.Core/AddProcess.fs b/src/Paket.Core/AddProcess.fs index 6ba01c8d6d..9e2b75493c 100644 --- a/src/Paket.Core/AddProcess.fs +++ b/src/Paket.Core/AddProcess.fs @@ -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) = diff --git a/src/Paket.Core/InstallProcess.fs b/src/Paket.Core/InstallProcess.fs index d026390e37..d0ccb365e7 100644 --- a/src/Paket.Core/InstallProcess.fs +++ b/src/Paket.Core/InstallProcess.fs @@ -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 @@ -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 @@ -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 @@ -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) diff --git a/src/Paket.Core/NugetConvert.fs b/src/Paket.Core/NugetConvert.fs index db037b13df..f3119cb1f8 100644 --- a/src/Paket.Core/NugetConvert.fs +++ b/src/Paket.Core/NugetConvert.fs @@ -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 }}) diff --git a/src/Paket.Core/ProcessOptions.fs b/src/Paket.Core/ProcessOptions.fs index 73e2c215e8..b200b1f746 100644 --- a/src/Paket.Core/ProcessOptions.fs +++ b/src/Paket.Core/ProcessOptions.fs @@ -1,19 +1,22 @@ 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 @@ -21,10 +24,10 @@ type InstallerOptions = Hard = hard Redirects = redirects } -type SmartInstallOptions = +type UpdaterOptions = { Common : InstallerOptions - OnlyReferenced : bool } + NoInstall : bool } static member Default = { Common = InstallerOptions.Default - OnlyReferenced = false } + NoInstall = false } diff --git a/src/Paket.Core/PublicAPI.fs b/src/Paket.Core/PublicAPI.fs index 9643d01095..78e43c7514 100644 --- a/src/Paket.Core/PublicAPI.fs +++ b/src/Paket.Core/PublicAPI.fs @@ -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) = @@ -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,[]) diff --git a/src/Paket.Core/RemoveProcess.fs b/src/Paket.Core/RemoveProcess.fs index 39d185bc7f..3e6fdfebce 100644 --- a/src/Paket.Core/RemoveProcess.fs +++ b/src/Paket.Core/RemoveProcess.fs @@ -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) = diff --git a/src/Paket.Core/UpdateProcess.fs b/src/Paket.Core/UpdateProcess.fs index 4d4857af4e..bc8bf4ad3d 100644 --- a/src/Paket.Core/UpdateProcess.fs +++ b/src/Paket.Core/UpdateProcess.fs @@ -67,21 +67,20 @@ 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) @@ -89,11 +88,10 @@ let UpdatePackage(dependenciesFileName, packageName : PackageName, newVersion, o .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) diff --git a/src/Paket/Commands.fs b/src/Paket/Commands.fs index 90380de896..527abf470c 100644 --- a/src/Paket/Commands.fs +++ b/src/Paket/Commands.fs @@ -193,6 +193,7 @@ type UpdateArgs = | [] Force | Hard | Redirects + | No_Install with interface IArgParserTemplate with member this.Usage = @@ -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 = | [] SearchText of string diff --git a/src/Paket/Program.fs b/src/Paket/Program.fs index 75c2d6375e..561682aac1 100644 --- a/src/Paket/Program.fs +++ b/src/Paket/Program.fs @@ -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 @>