Skip to content

Commit

Permalink
Don't remove custom framework references - fixes #376
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Nov 22, 2014
1 parent 437c840 commit 12b2bac
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 39 deletions.
3 changes: 3 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
12 changes: 12 additions & 0 deletions src/Paket.Core/InstallModel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ->
Expand Down
51 changes: 17 additions & 34 deletions src/Paket.Core/ProjectFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down Expand Up @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -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())

Expand Down
10 changes: 5 additions & 5 deletions tests/Paket.Tests/InstallModel/Xml/ManualNodes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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


Expand All @@ -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

0 comments on commit 12b2bac

Please sign in to comment.