From 12b2bacf7fab8e7c1146b545a34fc03f99dd92c4 Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Sat, 22 Nov 2014 12:30:20 +0100 Subject: [PATCH] Don't remove custom framework references - fixes #376 --- RELEASE_NOTES.md | 3 ++ src/Paket.Core/InstallModel.fs | 12 +++++ src/Paket.Core/ProjectFile.fs | 51 +++++++------------ .../InstallModel/Xml/ManualNodes.fs | 10 ++-- 4 files changed, 37 insertions(+), 39 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 01aac7f725..f6799fe8b9 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,3 +1,6 @@ +#### 0.16.0-alpha001 - 22.11.2014 +* Don't remove custom framework references - https://github.com/fsprojects/Paket/issues/376 + #### 0.15.6 - 21.11.2014 * BUGFIX: Path to dependencies file is now relative after `convert-from-nuget` - https://github.com/fsprojects/Paket/pull/379 diff --git a/src/Paket.Core/InstallModel.fs b/src/Paket.Core/InstallModel.fs index 91567eee6b..659b7e4a19 100644 --- a/src/Paket.Core/InstallModel.fs +++ b/src/Paket.Core/InstallModel.fs @@ -145,6 +145,12 @@ type InstallModel = member this.MapGroupFrameworks(mapF) = this.MapGroups(fun _ group -> { group with Frameworks = Map.map mapF group.Frameworks }) + member this.MapFallbacks(mapF) = + let fallbackMapped = + this.MapGroups(fun _ group -> { group with Fallbacks = mapF group.Fallbacks }) + { fallbackMapped with DefaultFallback = mapF fallbackMapped.DefaultFallback } + + member this.AddReference(framework : FrameworkIdentifier, lib : string, references) : InstallModel = let install = match references with @@ -260,6 +266,12 @@ type InstallModel = let files = kv.Value if files.References <> fallbacks.References then frameworks else Map.remove kv.Key frameworks) group.Frameworks }) + + member this.FilterReferences(references) = + let inline mapF (files:InstallFiles) = {files with References = files.References |> Set.filter (fun reference -> Set.contains reference.ReferenceName references |> not) } + this + .MapGroupFrameworks(fun _ files -> mapF files) + .MapFallbacks(mapF) member this.DeleteEmptyGroupIfDefaultFallback() = this.MapGroups(fun _ group -> diff --git a/src/Paket.Core/ProjectFile.fs b/src/Paket.Core/ProjectFile.fs index 728c114c33..8cbcf83dbb 100644 --- a/src/Paket.Core/ProjectFile.fs +++ b/src/Paket.Core/ProjectFile.fs @@ -33,15 +33,14 @@ type ProjectFile = member this.Name = FileInfo(this.FileName).Name - member this.CustomReferenceNodes = lazy( + member this.GetCustomReferenceNodes() = [for node in this.Document |> getDescendants "Reference" do let isPaket = ref false for child in node.ChildNodes do if child.Name = "Paket" then isPaket := true if not !isPaket then - yield node] - ) + yield node] /// Finds all project files static member FindAllProjects(folder) = @@ -156,14 +155,14 @@ type ProjectFile = this.DeleteIfEmpty("ItemGroup") - member this.GetCustomNodes(model:InstallModel) = + member this.GetCustomModelNodes(model:InstallModel) = let libs = model.GetReferenceNames.Force() - this.CustomReferenceNodes.Force() + this.GetCustomReferenceNodes() |> List.filter (fun node -> Set.contains (node.Attributes.["Include"].InnerText.Split(',').[0]) libs) - member this.DeleteCustomNodes(model:InstallModel) = - let nodesToDelete = this.GetCustomNodes(model) + member this.DeleteCustomModelNodes(model:InstallModel) = + let nodesToDelete = this.GetCustomModelNodes(model) if nodesToDelete <> [] then let (PackageName name) = model.PackageName @@ -172,21 +171,6 @@ type ProjectFile = for node in nodesToDelete do node.ParentNode.RemoveChild(node) |> ignore - member this.DeleteFrameworkAssemblies(model:InstallModel) = - let nodesToDelete = List<_>() - - let libs = model.GetFrameworkAssemblies.Force() - for node in this.Document |> getDescendants "Reference" do - if Set.contains (node.Attributes.["Include"].InnerText.Split(',').[0]) libs then - nodesToDelete.Add node - - if nodesToDelete |> Seq.isEmpty |> not then - let (PackageName name) = model.PackageName - verbosefn " - Deleting custom projects nodes for %s" name - - for node in nodesToDelete do - node.ParentNode.RemoveChild(node) |> ignore - member this.GenerateXml(model:InstallModel) = let createItemGroup references = let itemGroup = this.CreateNode("ItemGroup") @@ -264,22 +248,21 @@ type ProjectFile = ["ItemGroup";"When";"Otherwise";"Choose";"When";"Choose"] |> List.iter this.DeleteIfEmpty - - for kv in usedPackages do - let installModel = completeModel.[NormalizedPackageName kv.Key] - this.DeleteFrameworkAssemblies(installModel) - if hard then - this.DeleteCustomNodes(installModel) + if hard then + for kv in usedPackages do + let installModel = completeModel.[NormalizedPackageName kv.Key] + this.DeleteCustomModelNodes(installModel) + + let references = + this.GetCustomReferenceNodes() + |> List.map (fun node -> node.Attributes.["Include"].InnerText.Split(',').[0]) + |> Set.ofList let merged = usedPackages - |> Seq.fold (fun (model:InstallModel) kv -> - let installModel = completeModel.[NormalizedPackageName kv.Key] - if this.GetCustomNodes(installModel) <> [] then - traceWarnfn " - custom nodes for %s ==> skipping" ((|PackageName|) kv.Key) - model - else model.MergeWith(installModel)) + |> Seq.fold (fun (model:InstallModel) kv -> model.MergeWith( completeModel.[NormalizedPackageName kv.Key])) (InstallModel.EmptyModel(PackageName "",SemVer.Parse "0")) + |> fun x -> x.FilterReferences(references) let chooseNode = this.GenerateXml(merged.FilterFallbacks()) diff --git a/tests/Paket.Tests/InstallModel/Xml/ManualNodes.fs b/tests/Paket.Tests/InstallModel/Xml/ManualNodes.fs index 94fcbb32ef..0f179d97e3 100644 --- a/tests/Paket.Tests/InstallModel/Xml/ManualNodes.fs +++ b/tests/Paket.Tests/InstallModel/Xml/ManualNodes.fs @@ -14,7 +14,7 @@ let ``should find custom nodes in doc``() = @"..\Fantomas\lib\Fantomas.exe" ], Nuspec.Explicit ["FantomasLib.dll"]) - ProjectFile.Load("./ProjectFile/TestData/CustomFantomasNode.fsprojtest").Value.GetCustomNodes(model).IsEmpty + ProjectFile.Load("./ProjectFile/TestData/CustomFantomasNode.fsprojtest").Value.GetCustomModelNodes(model).IsEmpty |> shouldEqual false @@ -27,7 +27,7 @@ let ``should not find custom nodes if there are none``() = @"..\Fantomas\lib\Fantomas.exe" ], Nuspec.Explicit ["FantomasLib.dll"]) - ProjectFile.Load("./ProjectFile/TestData/NoCustomFantomasNode.fsprojtest").Value.GetCustomNodes(model).IsEmpty + ProjectFile.Load("./ProjectFile/TestData/NoCustomFantomasNode.fsprojtest").Value.GetCustomModelNodes(model).IsEmpty |> shouldEqual true @@ -42,10 +42,10 @@ let ``should delete custom nodes if there are some``() = let project = ProjectFile.Load("./ProjectFile/TestData/CustomFantomasNode.fsprojtest").Value - project.GetCustomNodes(model).IsEmpty + project.GetCustomModelNodes(model).IsEmpty |> shouldEqual false - project.DeleteCustomNodes(model) + project.DeleteCustomModelNodes(model) - project.GetCustomNodes(model).IsEmpty + project.GetCustomModelNodes(model).IsEmpty |> shouldEqual true \ No newline at end of file