Skip to content

Commit

Permalink
Allow to reference StyleCop.MSBuild targets files - references #516
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Feb 3, 2015
1 parent adc75bb commit 834787b
Show file tree
Hide file tree
Showing 17 changed files with 82 additions and 42 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.27.0-alpha001 - 03.02.2015
* Allow to reference `.props` and `.targets` files - https://github.com/fsprojects/Paket/issues/516

#### 0.26.4 - 02.02.2015
* Create a install function in the api which takes a `paket.dependencies` file as text - https://github.com/fsprojects/Paket/issues/576

Expand Down
10 changes: 10 additions & 0 deletions src/Paket.Core/InstallModel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ type InstallModel =
| _ -> None)
|> Seq.choose id
| None -> Seq.empty

member this.GetTargetsFiles(target : TargetProfile) =
match Seq.tryFind (fun lib -> Seq.exists (fun t -> t = target) lib.Targets) this.LibFolders with
| Some folder -> folder.Files.References
|> Set.map (fun x ->
match x with
| Reference.TargetsFile targetsFile -> Some targetsFile
| _ -> None)
|> Seq.choose id
| None -> Seq.empty

member this.AddLibFolders(libs : seq<string>) : InstallModel =
let libFolders =
Expand Down
64 changes: 36 additions & 28 deletions src/Paket.Core/ProjectFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -267,34 +267,38 @@ type ProjectFile =
|> List.map (fun lib -> PlatformMatching.getCondition lib.Targets,createItemGroup lib.Files.References,createPropertyGroup lib.Files.References)
|> List.sortBy (fun (x,_,_) -> x)

match conditions with
| ["$(TargetFrameworkIdentifier) == 'true'",itemGroup,propertyGroup] -> Seq.empty,itemGroup
| _ ->
let chooseNode = this.CreateNode("Choose")
let chooseNode,additionalPropertyGroup =
match conditions with
| ["$(TargetFrameworkIdentifier) == 'true'",itemGroup,(propertyNames,propertyGroup)] -> itemGroup,if Set.isEmpty propertyNames then None else Some propertyGroup
| _ ->
let chooseNode = this.CreateNode("Choose")

conditions
|> List.map (fun (condition,itemGroup,(propertyNames,propertyGroup)) ->
let whenNode =
this.CreateNode("When")
|> addAttribute "Condition" condition

if not itemGroup.IsEmpty then
whenNode.AppendChild(itemGroup) |> ignore
if not <| Set.isEmpty propertyNames then
whenNode.AppendChild(propertyGroup) |> ignore
whenNode)
|> List.iter(fun node -> chooseNode.AppendChild(node) |> ignore)

let propertyNameNodes =
conditions
|> List.map (fun (_,_,(propertyNames,_)) -> propertyNames)
|> Set.unionMany
|> Seq.map (fun propertyName ->
this.CreateNode("Import")
|> addAttribute "Project" (sprintf "$(%s)" propertyName)
|> addAttribute "Condition" (sprintf "Exists('$(%s)')" propertyName))

propertyNameNodes,chooseNode
|> List.map (fun (condition,itemGroup,(propertyNames,propertyGroup)) ->
let whenNode =
this.CreateNode("When")
|> addAttribute "Condition" condition

if not itemGroup.IsEmpty then
whenNode.AppendChild(itemGroup) |> ignore
if not <| Set.isEmpty propertyNames then
whenNode.AppendChild(propertyGroup) |> ignore
whenNode)
|> List.iter(fun node -> chooseNode.AppendChild(node) |> ignore)

chooseNode,None

let propertyNameNodes =
conditions
|> List.map (fun (_,_,(propertyNames,_)) -> propertyNames)
|> Set.unionMany
|> Seq.map (fun propertyName ->
this.CreateNode("Import")
|> addAttribute "Project" (sprintf "$(%s)" propertyName)
|> addAttribute "Condition" (sprintf "Exists('$(%s)')" propertyName))
|> Seq.toList

propertyNameNodes,chooseNode,additionalPropertyGroup


member this.UpdateReferences(completeModel: Map<NormalizedPackageName,InstallModel>, usedPackages : Map<NormalizedPackageName,PackageInstallSettings>, hard) =
Expand All @@ -314,10 +318,14 @@ type ProjectFile =
this.DeleteCustomModelNodes(kv.Value)
let package = usedPackages.[kv.Key]
this.GenerateXml(kv.Value,package.CopyLocal))
|> Seq.iter (fun (propertyNameNodes,node) ->
if node.ChildNodes.Count > 0 then
|> Seq.iter (fun (propertyNameNodes,node,additionalPropertyGroup) ->
if node.ChildNodes.Count > 0 then
this.ProjectNode.AppendChild node |> ignore

match additionalPropertyGroup with
| Some node -> this.ProjectNode.AppendChild node |> ignore
| None -> ()

propertyNameNodes
|> Seq.iter (this.ProjectNode.AppendChild >> ignore))

Expand Down
20 changes: 18 additions & 2 deletions tests/Paket.Tests/InstallModel/ProcessingSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ let ``should install single client profile lib for everything``() =
let model =
emptymodel.AddReferences([ @"..\Castle.Core\lib\net40-client\Castle.Core.dll" ])

// TODO: not sure it makes sense to include a 4.0 dll into a 3.5 project
// model.GetFiles(SinglePlatform (DotNetFramework FrameworkVersion.V3_5)) |> shouldNotContain @"..\Castle.Core\lib\net40-client\Castle.Core.dll"
model.GetFiles(SinglePlatform (DotNetFramework FrameworkVersion.V4_Client)) |> shouldContain @"..\Castle.Core\lib\net40-client\Castle.Core.dll"
model.GetFiles(SinglePlatform (DotNetFramework FrameworkVersion.V4)) |> shouldContain @"..\Castle.Core\lib\net40-client\Castle.Core.dll"
model.GetFiles(SinglePlatform (DotNetFramework FrameworkVersion.V4_5)) |> shouldContain @"..\Castle.Core\lib\net40-client\Castle.Core.dll"
Expand Down Expand Up @@ -439,3 +437,21 @@ let ``should not install tools``() =
|> Seq.forall (fun folder -> folder.Files.References.IsEmpty)
|> shouldEqual true

[<Test>]
let ``should handle props files``() =
let model =
emptymodel.AddTargetsFiles(
[ @"..\xunit.runner.visualstudio\build\net20\xunit.runner.visualstudio.props"
@"..\xunit.runner.visualstudio\build\portable-net45+aspnetcore50+win+wpa81+wp80+monotouch+monoandroid\xunit.runner.visualstudio.props" ])
.FilterBlackList()

model.GetTargetsFiles(SinglePlatform (DotNetFramework FrameworkVersion.V2)) |> shouldContain @"..\xunit.runner.visualstudio\build\net20\xunit.runner.visualstudio.props"

[<Test>]
let ``should handle Targets files``() =
let model =
emptymodel.AddTargetsFiles(
[ @"..\StyleCop.MSBuild\build\StyleCop.MSBuild.Targets" ])
.FilterBlackList()

model.GetTargetsFiles(SinglePlatform (DotNetFramework FrameworkVersion.V2)) |> shouldContain @"..\StyleCop.MSBuild\build\StyleCop.MSBuild.Targets"
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ let ``should generate Xml for FSharp.Data.SqlClient 1.4.4``() =
[],
Nuspec.Load("Nuspec/FSharp.Data.SqlClient.nuspec"))

let chooseNode = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model,CopyLocal.True) |> snd
let _,chooseNode,_ = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model,CopyLocal.True)
chooseNode.OuterXml
|> normalizeXml
|> shouldEqual (normalizeXml expected)
2 changes: 1 addition & 1 deletion tests/Paket.Tests/InstallModel/Xml/Fantomas.fs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ let ``should generate Xml for Fantomas 1.5``() =
[],
Nuspec.Explicit ["FantomasLib.dll"])

let propertyNodes,chooseNode = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model,CopyLocal.True)
let propertyNodes,chooseNode,additionalNode = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model,CopyLocal.True)
chooseNode.OuterXml
|> normalizeXml
|> shouldEqual (normalizeXml expected)
Expand Down
2 changes: 1 addition & 1 deletion tests/Paket.Tests/InstallModel/Xml/FantomasLib.fs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ let ``should generate Xml for Fantomas 1.5``() =
[],
Nuspec.Explicit ["FantomasLib.dll"])

let chooseNode = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model,CopyLocal.False) |> snd
let _,chooseNode,_ = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model,CopyLocal.False)
chooseNode.OuterXml
|> normalizeXml
|> shouldEqual (normalizeXml expected)
2 changes: 1 addition & 1 deletion tests/Paket.Tests/InstallModel/Xml/Fuchu.fs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ let ``should generate Xml for Fuchu 0.4``() =
[],
Nuspec.All)

let chooseNode = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model,CopyLocal.True) |> snd
let _,chooseNode,_ = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model,CopyLocal.True)
chooseNode.OuterXml
|> normalizeXml
|> shouldEqual (normalizeXml expected)
2 changes: 1 addition & 1 deletion tests/Paket.Tests/InstallModel/Xml/Plossum.fs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ let ``should generate Xml for Plossum``() =
[],
Nuspec.All)

let chooseNode = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model,CopyLocal.True) |> snd
let _,chooseNode,_ = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model,CopyLocal.True)
chooseNode.OuterXml
|> normalizeXml
|> shouldEqual (normalizeXml expected)
2 changes: 1 addition & 1 deletion tests/Paket.Tests/InstallModel/Xml/RxXaml.fs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ let ``should generate Xml for Rx-XAML 2.2.4 with correct framework assembly refe
{ AssemblyName = "System.Windows"; FrameworkRestrictions = [FrameworkRestriction.Exactly(Silverlight "v5.0")] }
{ AssemblyName = "System.Windows"; FrameworkRestrictions = [FrameworkRestriction.Exactly(WindowsPhoneSilverlight "v7.1")] }]})

let chooseNode = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model,CopyLocal.True) |> snd
let _,chooseNode,_ = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model,CopyLocal.True)
chooseNode.OuterXml
|> normalizeXml
|> shouldEqual (normalizeXml expected)
2 changes: 1 addition & 1 deletion tests/Paket.Tests/InstallModel/Xml/System.Spatial.fs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ let ``should generate Xml for System.Spatial``() =
@"..\System.Spatial\lib\sl4\zh-Hans\System.Spatial.resources.dll"
],[],Nuspec.All)

let chooseNode = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model,CopyLocal.True) |> snd
let _,chooseNode,_ = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model,CopyLocal.True)
chooseNode.OuterXml
|> normalizeXml
|> shouldEqual (normalizeXml expected)
2 changes: 1 addition & 1 deletion tests/Paket.Tests/InstallModel/Xml/SystemNetHttp.fs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ let ``should generate Xml for System.Net.Http 2.2.8``() =
[],
Nuspec.All)

let chooseNode = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model,CopyLocal.True) |> snd
let _,chooseNode,_ = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model,CopyLocal.True)
chooseNode.OuterXml
|> normalizeXml
|> shouldEqual (normalizeXml expected)
2 changes: 1 addition & 1 deletion tests/Paket.Tests/InstallModel/Xml/SystemNetHttpForNet4.fs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ let ``should generate Xml for System.Net.Http 2.2.8``() =
[],
Nuspec.All)

let chooseNode = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model,CopyLocal.True) |> snd
let _,chooseNode,_ = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model,CopyLocal.True)
chooseNode.OuterXml
|> normalizeXml
|> shouldEqual (normalizeXml expected)
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ let ``should generate Xml for System.Net.Http 2.2.8``() =
[{ AssemblyName = "System.Net.Http"; FrameworkRestrictions = [FrameworkRestriction.Exactly(DotNetFramework(FrameworkVersion.V4_5))] }
{ AssemblyName = "System.Net.Http.WebRequest"; FrameworkRestrictions = [FrameworkRestriction.Exactly(DotNetFramework(FrameworkVersion.V4_5))] }]})

let chooseNode = ProjectFile.Load("./ProjectFile/TestData/FrameworkAssemblies.fsprojtest").Value.GenerateXml(model,CopyLocal.True) |> snd
let _,chooseNode,_ = ProjectFile.Load("./ProjectFile/TestData/FrameworkAssemblies.fsprojtest").Value.GenerateXml(model,CopyLocal.True)
chooseNode.OuterXml
|> normalizeXml
|> shouldEqual (normalizeXml expected)
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ let ``should generate Xml for System.Net.Http 2.2.8``() =
[{ AssemblyName = "System.Net.Http"; FrameworkRestrictions = [FrameworkRestriction.AtLeast(DotNetFramework(FrameworkVersion.V4_5))] }
{ AssemblyName = "System.Net.Http.WebRequest"; FrameworkRestrictions = [FrameworkRestriction.Exactly(DotNetFramework(FrameworkVersion.V4_5))] }]})

let chooseNode = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model,CopyLocal.True) |> snd
let _,chooseNode,_ = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model,CopyLocal.True)
chooseNode.OuterXml
|> normalizeXml
|> shouldEqual (normalizeXml expected)
4 changes: 3 additions & 1 deletion tests/Paket.Tests/InstallModel/Xml/xunit.runner.fs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ let ``should generate Xml for xunit.runner.visualstudio 2.0.0``() =
@"..\xunit.runner.visualstudio\build\portable-net45+aspnetcore50+win+wpa81+wp80+monotouch+monoandroid\xunit.runner.visualstudio.props" ],
Nuspec.All)

let propertyNodes,chooseNode = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model,CopyLocal.True)
let propertyNodes,chooseNode,additionalNode = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model,CopyLocal.True)
chooseNode.OuterXml
|> normalizeXml
|> shouldEqual (normalizeXml expected)

additionalNode |> shouldEqual None

propertyNodes |> Seq.length |> shouldEqual 1

(propertyNodes |> Seq.head).OuterXml
Expand Down
1 change: 1 addition & 0 deletions tests/Paket.Tests/Paket.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@
<Compile Include="InstallModel\ProcessingSpecs.fs" />
<Compile Include="InstallModel\Xml\Fantomas.fs" />
<Compile Include="InstallModel\Xml\xunit.runner.fs" />
<Compile Include="InstallModel\Xml\StyleCop.MSBuild.fs" />
<Compile Include="InstallModel\Xml\Plossum.fs" />
<Compile Include="InstallModel\Xml\System.Spatial.fs" />
<Compile Include="InstallModel\Xml\FantomasLib.fs" />
Expand Down

0 comments on commit 834787b

Please sign in to comment.