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 to opt in to BindingRedirects - references #415 #436

Merged
merged 6 commits into from
Dec 9, 2014
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
9 changes: 9 additions & 0 deletions docs/content/dependencies-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,12 @@ This option disables the installation of any content files.

nuget jQuery >= 0 // we don't install jQuery content files
nuget UnionArgParser ~> 0.7

## Redirects option

This option tells paket to create AssemblyBindingRedirects for all referenced libraries.

redirects on
source https://nuget.org/api/v2

nuget UnionArgParser ~> 0.7
4 changes: 3 additions & 1 deletion docs/content/paket-install.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
Ensures that all dependencies in your [`paket.dependencies` file](dependencies-file.html) are present in the `packages` directory and referenced correctly in all projects.

[lang=batchfile]
$ paket install [--force] [--hard]
$ paket install [--force] [--hard] [--redirects]

Options:

`--force`: Forces the download and reinstallation of all packages.

`--hard`: Replaces package references within project files even if they are not yet adhering to Paket's conventions (and hence considered manually managed). See [convert from NuGet](convert-from-nuget.html).

`--redirects`: Creates binding redirects for the NuGet packages.
4 changes: 3 additions & 1 deletion docs/content/paket-update.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
Recomputes the dependency resolution, updates the [`paket.lock` file](lock-file.html) and propagates any resulting package changes into all project files referencing updated packages.

[lang=batchfile]
$ paket update [--force] [--hard]
$ paket update [--force] [--hard] [--redirects]

Options:

`--force`: Forces the download and reinstallation of all packages.

`--hard`: Replaces package references within project files even if they are not yet adhering to to Paket's conventions (and hence considered manually managed). See [convert from NuGet](convert-from-nuget.html).

`--redirects`: Creates binding redirects for the NuGet packages.

## Updating a single package

It's also possible to update only a single package and to keep all other dependencies fixed:
Expand Down
2 changes: 1 addition & 1 deletion src/Paket.Core/AddProcess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ let Add(dependenciesFileName, package, version, force, hard, interactive, instal

if installAfter then
let sources = dependenciesFile.GetAllPackageSources()
InstallProcess.Install(sources, force, hard, lockFile)
InstallProcess.Install(sources, force, hard, false, lockFile)

if changed then
dependenciesFile.Save()
20 changes: 14 additions & 6 deletions src/Paket.Core/DependenciesFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ open Paket.PackageSources
/// [omit]
type InstallOptions =
{ Strict : bool
Redirects : bool
OmitContent : bool }

static member Default = { Strict = false; OmitContent = false}
static member Default = { Strict = false; OmitContent = false; Redirects = false}

/// [omit]
module DependenciesFileParser =
Expand Down Expand Up @@ -128,7 +129,12 @@ module DependenciesFileParser =
| [| _; projectSpec; fileSpec |] -> getParts projectSpec fileSpec
| _ -> failwithf "invalid http-reference specification:%s %s" Environment.NewLine trimmed

let private (|Remote|Package|Blank|ReferencesMode|OmitContent|SourceFile|) (line:string) =
type private ParserOption =
| ReferencesMode of bool
| OmitContent of bool
| Redirects of bool

let private (|Remote|Package|Blank|ParserOptions|SourceFile|) (line:string) =
match line.Trim() with
| _ when String.IsNullOrWhiteSpace line -> Blank
| String.StartsWith "source" _ as trimmed -> Remote(PackageSource.Parse(trimmed))
Expand All @@ -150,8 +156,9 @@ module DependenciesFileParser =
| name :: rest -> Package(name,">= 0 " + String.Join(" ",rest))
| name :: [] -> Package(name,">= 0")
| _ -> failwithf "could not retrieve nuget package from %s" trimmed
| String.StartsWith "references" trimmed -> ReferencesMode(trimmed.Trim() = "strict")
| String.StartsWith "content" trimmed -> OmitContent(trimmed.Trim() = "none")
| String.StartsWith "references" trimmed -> ParserOptions(ParserOption.ReferencesMode(trimmed.Trim() = "strict"))
| String.StartsWith "redirects" trimmed -> ParserOptions(ParserOption.Redirects(trimmed.Trim() = "on"))
| String.StartsWith "content" trimmed -> ParserOptions(ParserOption.OmitContent(trimmed.Trim() = "none"))
| String.StartsWith "gist" _ as trimmed ->
SourceFile(``parse git source`` trimmed SingleSourceFileOrigin.GistLink "gist")
| String.StartsWith "github" _ as trimmed ->
Expand All @@ -168,8 +175,9 @@ module DependenciesFileParser =
match line with
| Remote(newSource) -> lineNo, options, sources @ [newSource], packages, sourceFiles
| Blank -> lineNo, options, sources, packages, sourceFiles
| ReferencesMode mode -> lineNo, { options with Strict = mode }, sources, packages, sourceFiles
| OmitContent omit -> lineNo, { options with OmitContent = omit }, sources, packages, sourceFiles
| ParserOptions(ParserOption.ReferencesMode mode) -> lineNo, { options with Strict = mode }, sources, packages, sourceFiles
| ParserOptions(ParserOption.Redirects mode) -> lineNo, { options with Redirects = mode }, sources, packages, sourceFiles
| ParserOptions(ParserOption.OmitContent omit) -> lineNo, { options with OmitContent = omit }, sources, packages, sourceFiles
| Package(name,version) ->
lineNo, options, sources,
{ Sources = sources
Expand Down
5 changes: 3 additions & 2 deletions src/Paket.Core/InstallProcess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ let private applyBindingRedirects root extractedPackages =
|> applyBindingRedirectsToFolder root

/// Installs the given all packages from the lock file.
let Install(sources,force, hard, lockFile:LockFile) =
let Install(sources,force, hard, withBindingRedirects, lockFile:LockFile) =
let root = FileInfo(lockFile.FileName).Directory.FullName
let extractedPackages = createModel(root,sources,force, lockFile)

Expand Down Expand Up @@ -185,4 +185,5 @@ let Install(sources,force, hard, lockFile:LockFile) =

project.Save()

applyBindingRedirects root extractedPackages
if withBindingRedirects || lockFile.Options.Redirects then
applyBindingRedirects root extractedPackages
18 changes: 12 additions & 6 deletions src/Paket.Core/LockFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module LockFileSerializer =
let hasReported = ref false
[ if options.Strict then yield "REFERENCES: STRICT"
if options.OmitContent then yield "CONTENT: NONE"
if options.Redirects then yield "REDIRECTS: ON"
for (source, _), packages in sources do
if not !hasReported then
yield "NUGET"
Expand Down Expand Up @@ -97,8 +98,11 @@ module LockFileParser =
SourceFiles : ResolvedSourceFile list
LastWasPackage : bool
Options: InstallOptions }

type private InstallOptionCase = StrictCase | OmitContentCase

type private ParserOption =
| ReferencesMode of bool
| OmitContent of bool
| Redirects of bool

let private (|Remote|NugetPackage|NugetDependency|SourceFile|RepositoryType|Blank|InstallOption|) (state, line:string) =
match (state.RepositoryType, line.Trim()) with
Expand All @@ -109,8 +113,9 @@ module LockFileParser =
| _, _ when String.IsNullOrWhiteSpace line -> Blank
| _, String.StartsWith "remote:" trimmed -> Remote(trimmed.Trim().Split(' ').[0])
| _, String.StartsWith "specs:" _ -> Blank
| _, String.StartsWith "REFERENCES:" trimmed -> InstallOption(StrictCase,trimmed.Trim() = "STRICT")
| _, String.StartsWith "CONTENT:" trimmed -> InstallOption(OmitContentCase,trimmed.Trim() = "NONE")
| _, String.StartsWith "REFERENCES:" trimmed -> InstallOption(ReferencesMode(trimmed.Trim() = "STRICT"))
| _, String.StartsWith "REDIRECTS:" trimmed -> InstallOption(Redirects(trimmed.Trim() = "ON"))
| _, String.StartsWith "CONTENT:" trimmed -> InstallOption(OmitContent(trimmed.Trim() = "NONE"))
| _, trimmed when line.StartsWith " " ->
let parts = trimmed.Split '('
NugetDependency (parts.[0].Trim(),parts.[1].Replace("(", "").Replace(")", "").Trim())
Expand All @@ -129,8 +134,9 @@ module LockFileParser =
match (state, line) with
| Remote(url) -> { state with RemoteUrl = Some url }
| Blank -> state
| InstallOption (StrictCase,mode) -> { state with Options = {state.Options with Strict = mode} }
| InstallOption (OmitContentCase,omit) -> { state with Options = {state.Options with OmitContent = omit} }
| InstallOption (ReferencesMode(mode)) -> { state with Options = {state.Options with Strict = mode} }
| InstallOption (Redirects(mode)) -> { state with Options = {state.Options with Redirects = mode} }
| InstallOption (OmitContent(omit)) -> { state with Options = {state.Options with OmitContent = omit} }
| RepositoryType repoType -> { state with RepositoryType = Some repoType }
| NugetPackage details ->
match state.RemoteUrl with
Expand Down
2 changes: 1 addition & 1 deletion src/Paket.Core/NugetConvert.fs
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,4 @@ let ConvertFromNuget(dependenciesFileName, force, installAfter, initAutoRestore,
VSIntegration.InitAutoRestore dependenciesFileName

if installAfter then
UpdateProcess.Update(dependenciesFileName,true,false,true)
UpdateProcess.Update(dependenciesFileName,true,false,true,true)
10 changes: 8 additions & 2 deletions src/Paket.Core/PublicAPI.fs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,16 @@ type Dependencies(dependenciesFileName: string) =
AddProcess.Add(dependenciesFileName, PackageName package, version, force, hard, interactive, installAfter)

/// Installs all dependencies.
member this.Install(force: bool,hard: bool): unit = UpdateProcess.Update(dependenciesFileName,false,force,hard)
member this.Install(force: bool,hard: bool,withBindingRedirects:bool): unit = UpdateProcess.Update(dependenciesFileName,false,force,hard,withBindingRedirects)

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

/// Updates all dependencies.
member this.Update(force: bool,hard: bool,withBindingRedirects:bool): unit = UpdateProcess.Update(dependenciesFileName,true,force,hard,withBindingRedirects)

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

/// Updates the given package.
member this.UpdatePackage(package: string,version: string option,force: bool,hard: bool): unit =
Expand Down
2 changes: 1 addition & 1 deletion src/Paket.Core/RemoveProcess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ let Remove(dependenciesFileName, package:PackageName, force, hard, interactive,

if installAfter then
let sources = DependenciesFile.ReadFromFile(dependenciesFileName).GetAllPackageSources()
InstallProcess.Install(sources, force, hard, lockFile)
InstallProcess.Install(sources, force, hard, false, lockFile)
8 changes: 4 additions & 4 deletions src/Paket.Core/UpdateProcess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ open Paket.PackageResolver
open System.Collections.Generic

/// Update command
let Update(dependenciesFileName, forceResolution, force, hard) =
let Update(dependenciesFileName, forceResolution, force, hard, withBindingRedirects) =
let lockFileName = DependenciesFile.FindLockfile dependenciesFileName

let sources, lockFile =
Expand All @@ -21,7 +21,7 @@ let Update(dependenciesFileName, forceResolution, force, hard) =
let sources = dependenciesFile.GetAllPackageSources()
sources, LockFile.LoadFrom(lockFileName.FullName)

InstallProcess.Install(sources, force, hard, lockFile)
InstallProcess.Install(sources, force, hard, withBindingRedirects, lockFile)

let private fixOldDependencies failOnMissingPackage (dependenciesFile:DependenciesFile) (package:PackageName) (oldLockFile:LockFile) =
let allDependencies =
Expand Down Expand Up @@ -62,7 +62,7 @@ let updateWithModifiedDependenciesFile(failOnMissingPackage,dependenciesFile:Dep
/// Update a single package command
let UpdatePackage(dependenciesFileName, packageName : PackageName, newVersion, force, hard) =
let lockFileName = DependenciesFile.FindLockfile dependenciesFileName
if not lockFileName.Exists then Update(dependenciesFileName, true, force, hard) else
if not lockFileName.Exists then Update(dependenciesFileName, true, force, hard, false) else

let sources, lockFile =
let dependenciesFile =
Expand All @@ -76,4 +76,4 @@ let UpdatePackage(dependenciesFileName, packageName : PackageName, newVersion, f

fixOldDependencies true dependenciesFile packageName
|> update lockFileName.FullName force
InstallProcess.Install(sources, force, hard, lockFile)
InstallProcess.Install(sources, force, hard, false, lockFile)
4 changes: 2 additions & 2 deletions src/Paket/Paket.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
<WarningLevel>3</WarningLevel>
<DocumentationFile>
</DocumentationFile>
<StartArguments>update -f</StartArguments>
<StartArguments>remove nuget cs-script --interactive</StartArguments>
<StartAction>Project</StartAction>
<StartProgram>paket.exe</StartProgram>
<StartWorkingDirectory>
</StartWorkingDirectory>
<StartWorkingDirectory>d:\code\PaketTest</StartWorkingDirectory>
<StartWorkingDirectory>d:\code\paket-dependencies</StartWorkingDirectory>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand Down
6 changes: 4 additions & 2 deletions src/Paket/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type CLIArguments =
| [<First>][<NoAppSettings>][<Rest>][<CustomCommandLine("find-refs")>] FindRefs of string
| [<AltCommandLine("-v")>] Verbose
| [<AltCommandLine("-i")>] Interactive
| Redirects
| [<AltCommandLine("-f")>] Force
| Hard
| [<CustomCommandLine("nuget")>] Nuget of string
Expand Down Expand Up @@ -117,6 +118,7 @@ try
let noInstall = results.Contains <@ CLIArguments.No_Install @>
let noAutoRestore = results.Contains <@ CLIArguments.No_Auto_Restore @>
let includePrereleases = results.Contains <@ CLIArguments.Include_Prereleases @>
let withBindingRedirects = results.Contains <@ CLIArguments.Redirects @>

match command with
| Command.Init -> Dependencies.Create() |> ignore
Expand All @@ -131,7 +133,7 @@ try
| Command.Remove ->
let packageName = results.GetResult <@ CLIArguments.Nuget @>
Dependencies.Locate().Remove(packageName,force,hard,interactive,noInstall |> not)
| Command.Install -> Dependencies.Locate().Install(force,hard)
| Command.Install -> Dependencies.Locate().Install(force,hard,withBindingRedirects)
| Command.Restore ->
let files = results.GetResults <@ CLIArguments.References_Files @>
Dependencies.Locate().Restore(force,files)
Expand All @@ -140,7 +142,7 @@ try
| Some packageName ->
let version = results.TryGetResult <@ CLIArguments.Version @>
Dependencies.Locate().UpdatePackage(packageName, version, force, hard)
| _ -> Dependencies.Locate().Update(force,hard)
| _ -> Dependencies.Locate().Update(force,hard,withBindingRedirects)
| Command.Outdated ->
let strict = results.Contains <@ CLIArguments.Ignore_Constraints @> |> not
Dependencies.Locate().ShowOutdated(strict,includePrereleases)
Expand Down
31 changes: 31 additions & 0 deletions tests/Paket.Tests/DependenciesFile/ParserSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,37 @@ nuget "FAKE" "~> 3.0"
let ``should read strict config``() =
let cfg = DependenciesFile.FromCode(strictConfig)
cfg.Options.Strict |> shouldEqual true
cfg.Options.Redirects |> shouldEqual false

(cfg.Packages |> List.find (fun p -> p.Name = PackageName "FAKE")).Sources |> shouldEqual [PackageSource.NugetSource "http://nuget.org/api/v2"]

let redirectsConfig = """
redirects on
source "http://nuget.org/api/v2" // first source

nuget "FAKE" "~> 3.0"
"""

[<Test>]
let ``should read config with redirects``() =
let cfg = DependenciesFile.FromCode(redirectsConfig)
cfg.Options.Strict |> shouldEqual false
cfg.Options.Redirects |> shouldEqual true

(cfg.Packages |> List.find (fun p -> p.Name = PackageName "FAKE")).Sources |> shouldEqual [PackageSource.NugetSource "http://nuget.org/api/v2"]

let noRedirectsConfig = """
redirects off
source "http://nuget.org/api/v2" // first source

nuget "FAKE" "~> 3.0"
"""

[<Test>]
let ``should read config with no redirects``() =
let cfg = DependenciesFile.FromCode(noRedirectsConfig)
cfg.Options.Strict |> shouldEqual false
cfg.Options.Redirects |> shouldEqual false

(cfg.Packages |> List.find (fun p -> p.Name = PackageName "FAKE")).Sources |> shouldEqual [PackageSource.NugetSource "http://nuget.org/api/v2"]

Expand Down
30 changes: 0 additions & 30 deletions tests/Paket.Tests/Lockfile/GenerateContentNoneOptionSpecs.fs

This file was deleted.

30 changes: 0 additions & 30 deletions tests/Paket.Tests/Lockfile/GenerateStrictModeSpecs.fs

This file was deleted.

Loading