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

Fixes re-ordering problem with files #722

Merged
merged 2 commits into from
Mar 26, 2015
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
19 changes: 15 additions & 4 deletions src/Paket.Core/ProjectFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@ type ProjectFile =
node.ParentNode.RemoveChild(node) |> ignore

member this.UpdateFileItems(fileItems : FileItem list, hard) =
this.DeletePaketNodes("Compile")
this.DeletePaketNodes("Content")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we would never deinstall thing if we don't delete.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Humm, So the InstallProcess.InstallIntoProjects also removes stuff? I guess by virtue of the fact that if it isn't included in that file list then it shouldn't be there? Correct?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the idea was: remove all paket stuff from a fsproj file and add it again. since we can't know if someone remove a package.

let firstItemGroup = this.ProjectNode |> getNodes "ItemGroup" |> Seq.firstOrDefault

Expand All @@ -144,7 +142,6 @@ type ProjectFile =
"Compile", node :?> XmlElement ]
|> dict


for fileItem in fileItems |> List.rev do
let libReferenceNode =
this.CreateNode(fileItem.BuildAction)
Expand All @@ -161,6 +158,7 @@ type ProjectFile =
match node |> getAttribute "Include" with
| Some path when path.StartsWith(Path.GetDirectoryName(fileItem.Include)) -> true
| _ -> false)


if Seq.isEmpty fileItemsInSameDir then
newItemGroups.[fileItem.BuildAction].PrependChild(libReferenceNode) |> ignore
Expand All @@ -177,9 +175,22 @@ type ProjectFile =
then existingNode :?> XmlElement |> addChild (this.CreateNode("Paket","True")) |> ignore
else verbosefn " - custom nodes for %s in %s ==> skipping" fileItem.Include this.FileName
| None ->
let firstNode = fileItemsInSameDir |> Seq.head
let firstNode = fileItemsInSameDir |> Seq.head
firstNode.ParentNode.InsertBefore(libReferenceNode, firstNode) |> ignore

let paketNodes =
this.FindPaketNodes("Compile")
@ this.FindPaketNodes("Content")

//remove uneeded files
for paketNode in paketNodes do
match getAttribute "Include" paketNode with
| Some path ->
if not(fileItems |> List.exists (fun fi -> fi.Include = path))
then paketNode.ParentNode.RemoveChild(paketNode) |> ignore
else ()
| _ -> ()

this.DeleteIfEmpty("PropertyGroup")
this.DeleteIfEmpty("ItemGroup")
this.DeleteIfEmpty("Choose")
Expand Down
2 changes: 1 addition & 1 deletion src/Paket/Paket.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<StartArguments>update</StartArguments>
<StartAction>Project</StartAction>
<StartProgram>paket.exe</StartProgram>
<StartWorkingDirectory>c:\code\Paket09x</StartWorkingDirectory>
<StartWorkingDirectory>D:\Appdev\officeprovider\</StartWorkingDirectory>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand Down
3 changes: 3 additions & 0 deletions tests/Paket.Tests/Paket.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@
<None Include="ProjectFile\TestData\NoCustomFantomasNode.fsprojtest">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="ProjectFile\TestData\MaintainsOrdering.fsprojtest">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<Compile Include="ProjectFile\ConditionSpecs.fs" />
<Compile Include="ProjectFile\FileBuildActionSpecs.fs" />
<Compile Include="ProjectFile\InterProjectDependencySpecs.fs" />
Expand Down
85 changes: 85 additions & 0 deletions tests/Paket.Tests/ProjectFile/OutputSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
open Paket
open NUnit.Framework
open FsUnit
open System.Xml
open System.Xml.Linq

[<Test>]
let ``should detect lib output type for Project1 proj file``() =
Expand Down Expand Up @@ -51,3 +53,86 @@ let ``should detect assembly name for Project3 proj file`` () =
ProjectFile.Load("./ProjectFile/TestData/Project3.fsprojtest").Value.GetAssemblyName()
|> shouldEqual ("Paket.Tests.Win.exe")

[<Test>]
let ``should maintain order when updating project file items`` () =

let projFile = ProjectFile.Load("./ProjectFile/TestData/MaintainsOrdering.fsprojtest").Value
let fileItems = [
{ BuildAction = "Compile"; Include = "..\\..\\paket-files\\fsharp\\FSharp.Data\\src\\CommonRuntime\\Pluralizer.fs"; Link = Some("fsharp_data\\Pluralizer.fs") }
{ BuildAction = "Compile"; Include = "..\\..\\paket-files\\fsharp\\FSharp.Data\\src\\CommonRuntime\\NameUtils.fs"; Link = Some("fsharp_data\\NameUtils.fs") }
{ BuildAction = "Compile"; Include = "..\\..\\paket-files\\fsharp\\FSharp.Data\\src\\CommonRuntime\\TextConversions.fs"; Link = Some("fsharp_data\\TextConversions.fs") }
{ BuildAction = "Compile"; Include = "..\\..\\paket-files\\fsharp\\FSharp.Data\\src\\CommonRuntime\\StructuralTypes.fs"; Link = Some("fsharp_data\\StructuralTypes.fs") }
{ BuildAction = "Compile"; Include = "..\\..\\paket-files\\fsharp\\FSharp.Data\\src\\CommonRuntime\\StructuralInference.fs"; Link = Some("fsharp_data\\StructuralInference.fs") }
{ BuildAction = "Compile"; Include = "..\\..\\paket-files\\fsharp\\FSharp.Data\\src\\CommonRuntime\\TextRuntime.fs"; Link = Some("fsharp_data\\TextRuntime.fs") }
{ BuildAction = "Compile"; Include = "DebugProvidedTypes.fs"; Link = None }
{ BuildAction = "Compile"; Include = "ProvidedTypes.fs"; Link = None }
{ BuildAction = "Content"; Include = "ProvidedTypes.fsi"; Link = None }
]
projFile.UpdateFileItems(fileItems, false)

let rec nodes node =
seq {
for node in node |> Seq.cast<XmlNode> do
if node.Name = "Compile" || node.Name = "Content"
then yield Paket.Xml.getAttribute "Include" node
yield! nodes node
}

let actual =
nodes projFile.Document
|> Seq.choose id
|> Seq.toList
let expected =
[
"..\\..\\paket-files\\fsharp\\FSharp.Data\\src\\CommonRuntime\\Pluralizer.fs"
"..\\..\\paket-files\\fsharp\\FSharp.Data\\src\\CommonRuntime\\NameUtils.fs"
"..\\..\\paket-files\\fsharp\\FSharp.Data\\src\\CommonRuntime\\TextConversions.fs"
"..\\..\\paket-files\\fsharp\\FSharp.Data\\src\\CommonRuntime\\StructuralTypes.fs"
"..\\..\\paket-files\\fsharp\\FSharp.Data\\src\\CommonRuntime\\StructuralInference.fs"
"..\\..\\paket-files\\fsharp\\FSharp.Data\\src\\CommonRuntime\\TextRuntime.fs"
"ProvidedTypes.fsi"
"ProvidedTypes.fs"
"DebugProvidedTypes.fs"
"QuotationHelpers.fs"
"CommonTypes.fs"
"ExcelProvider.fs"
"WordProvider.fs"
"ProviderEntryPoint.fs"
]
CollectionAssert.AreEqual(expected, actual)

[<Test>]
let ``should remove missing files that exist in the project`` () =

let projFile = ProjectFile.Load("./ProjectFile/TestData/MaintainsOrdering.fsprojtest").Value
let fileItems = [
{ BuildAction = "Compile"; Include = "DebugProvidedTypes.fs"; Link = None }
{ BuildAction = "Compile"; Include = "ProvidedTypes.fs"; Link = None }
{ BuildAction = "Content"; Include = "ProvidedTypes.fsi"; Link = None }
]
projFile.UpdateFileItems(fileItems, false)

let rec nodes node =
seq {
for node in node |> Seq.cast<XmlNode> do
if node.Name = "Compile" || node.Name = "Content"
then yield Paket.Xml.getAttribute "Include" node
yield! nodes node
}

let actual =
nodes projFile.Document
|> Seq.choose id
|> Seq.toList
let expected =
[
"ProvidedTypes.fsi"
"ProvidedTypes.fs"
"DebugProvidedTypes.fs"
"QuotationHelpers.fs"
"CommonTypes.fs"
"ExcelProvider.fs"
"WordProvider.fs"
"ProviderEntryPoint.fs"
]
CollectionAssert.AreEqual(expected, actual)
125 changes: 125 additions & 0 deletions tests/Paket.Tests/ProjectFile/TestData/MaintainsOrdering.fsprojtest
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>b8134fc6-3f15-4f95-baac-e5b2c7856060</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>OfficeProvider</RootNamespace>
<AssemblyName>OfficeProvider</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFSharpCoreVersion>4.3.1.0</TargetFSharpCoreVersion>
<Name>OfficeProvider</Name>
<TargetFrameworkProfile />
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<Tailcalls>false</Tailcalls>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<WarningLevel>3</WarningLevel>
<DocumentationFile>bin\Debug\OfficeProvider.XML</DocumentationFile>
<StartArguments>D:\Appdev\officeprovider\tests\test.sln</StartArguments>
<StartAction>Program</StartAction>
<StartProgram>devenv.exe</StartProgram>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<Tailcalls>true</Tailcalls>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<WarningLevel>3</WarningLevel>
<DocumentationFile>bin\Release\OfficeProvider.XML</DocumentationFile>
</PropertyGroup>
<PropertyGroup>
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">11</MinimumVisualStudioVersion>
</PropertyGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '11.0'">
<PropertyGroup Condition="Exists('$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets')">
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets')">
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets</FSharpTargetsPath>
</PropertyGroup>
</Otherwise>
</Choose>
<Import Project="$(FSharpTargetsPath)" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
<Import Project="..\..\.paket\paket.targets" />
<ItemGroup>
<Compile Include="..\..\paket-files\fsharp\FSharp.Data\src\CommonRuntime\Pluralizer.fs">
<Paket>True</Paket>
<Link>fsharp_data/Pluralizer.fs</Link>
</Compile>
<Compile Include="..\..\paket-files\fsharp\FSharp.Data\src\CommonRuntime\NameUtils.fs">
<Paket>True</Paket>
<Link>fsharp_data/NameUtils.fs</Link>
</Compile>
<Compile Include="..\..\paket-files\fsharp\FSharp.Data\src\CommonRuntime\TextConversions.fs">
<Paket>True</Paket>
<Link>fsharp_data/TextConversions.fs</Link>
</Compile>
<Compile Include="..\..\paket-files\fsharp\FSharp.Data\src\CommonRuntime\StructuralTypes.fs">
<Paket>True</Paket>
<Link>fsharp_data/StructuralTypes.fs</Link>
</Compile>
<Compile Include="..\..\paket-files\fsharp\FSharp.Data\src\CommonRuntime\StructuralInference.fs">
<Paket>True</Paket>
<Link>fsharp_data/StructuralInference.fs</Link>
</Compile>
<Compile Include="..\..\paket-files\fsharp\FSharp.Data\src\CommonRuntime\TextRuntime.fs">
<Paket>True</Paket>
<Link>fsharp_data/TextRuntime.fs</Link>
</Compile>
<Content Include="ProvidedTypes.fsi">
<Paket>True</Paket>
</Content>
<Compile Include="ProvidedTypes.fs">
<Paket>True</Paket>
</Compile>
<Compile Include="DebugProvidedTypes.fs">
<Paket>True</Paket>
</Compile>
<Compile Include="QuotationHelpers.fs" />
<Compile Include="CommonTypes.fs" />
<Compile Include="ExcelProvider.fs" />
<Compile Include="WordProvider.fs" />
<Compile Include="ProviderEntryPoint.fs" />
<None Include="Script.fsx" />
<None Include="paket.references" />
</ItemGroup>
<ItemGroup>
<Reference Include="mscorlib" />
<Reference Include="FSharp.Core, Version=$(TargetFSharpCoreVersion), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Numerics" />
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Reference Include="DocumentFormat.OpenXml">
<HintPath>..\..\packages\DocumentFormat.OpenXml\lib\DocumentFormat.OpenXml.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</Project>