Skip to content

Commit

Permalink
Merge pull request #460 from fsprojects/install
Browse files Browse the repository at this point in the history
Don't add Nuget package twice to ReferencesFile - fixes #454
  • Loading branch information
forki committed Dec 20, 2014
2 parents 536c421 + fb7d164 commit d9dbf4d
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 90 deletions.
17 changes: 4 additions & 13 deletions src/Paket.Core/AddProcess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,12 @@ let Add(dependenciesFileName, package, version, force, hard, interactive, instal
LockFile.LoadFrom(lockFileName.FullName)

if interactive then
let (PackageName package) = package
let (PackageName packageName) = package
for project in ProjectFile.FindAllProjects(Path.GetDirectoryName lockFile.FileName) do
if Utils.askYesNo(sprintf " Install to %s?" project.Name) then
let proj = FileInfo(project.FileName)
match ProjectFile.FindReferencesFile proj with
| None ->
let newFileName =
let fi = FileInfo(Path.Combine(proj.Directory.FullName,Constants.ReferencesFile))
if fi.Exists then
Path.Combine(proj.Directory.FullName,proj.Name + "." + Constants.ReferencesFile)
else
fi.FullName

File.WriteAllLines(newFileName,[package])
| Some fileName -> File.AppendAllLines(fileName,["";package])
ProjectFile.FindOrCreateReferencesFile(FileInfo(project.FileName))
.AddNuGetReference(package)
.Save()

if installAfter then
let sources = dependenciesFile.GetAllPackageSources()
Expand Down
134 changes: 66 additions & 68 deletions src/Paket.Core/Paket.Core.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,74 +66,6 @@
</Target>
-->
<Import Project="$(SolutionDir)\.paket\paket.targets" />
<ItemGroup>
<Compile Include="..\..\paket-files\nessos\Streams\src\Streams.Core\Streams.fs">
<Paket>True</Paket>
<Link>Streams.fs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<Content Include="..\..\packages\FSharp.Core\lib\net40\FSharp.Core.optdata">
<Link>FSharp.Core.optdata</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="..\..\packages\FSharp.Core\lib\net40\FSharp.Core.sigdata">
<Link>FSharp.Core.sigdata</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Compile Include="Async.fs" />
<Compile Include="Domain.fs" />
<Compile Include="SemVer.fs" />
<Compile Include="VersionRange.fs" />
<Compile Include="Constants.fs" />
<Compile Include="Logging.fs" />
<Compile Include="Xml.fs" />
<Compile Include="Utils.fs" />
<Compile Include="ConfigFile.fs" />
<Compile Include="PackageSources.fs" />
<Compile Include="FrameworkHandling.fs" />
<Compile Include="PlatformMatching.fs" />
<Compile Include="Requirements.fs" />
<Compile Include="ModuleResolver.fs" />
<Compile Include="RemoteDownload.fs" />
<Compile Include="PackageResolver.fs" />
<Compile Include="Nuspec.fs" />
<Compile Include="InstallModel.fs" />
<Compile Include="ProjectFile.fs" />
<Compile Include="SolutionFile.fs" />
<Compile Include="NuGetV3.fs" />
<Compile Include="NuGetV2.fs" />
<Compile Include="DependenciesFile.fs" />
<Compile Include="ReferencesFile.fs" />
<Compile Include="DependencyModel.fs" />
<Compile Include="LockFile.fs" />
<Compile Include="RestoreProcess.fs" />
<Compile Include="BindingRedirects.fs" />
<Compile Include="InstallProcess.fs" />
<Compile Include="UpdateProcess.fs" />
<Compile Include="RemoveProcess.fs" />
<Compile Include="AddProcess.fs" />
<Compile Include="Simplifier.fs" />
<Compile Include="VSIntegration.fs" />
<Compile Include="NugetConvert.fs" />
<Compile Include="FindOutdated.fs" />
<Compile Include="FindReferences.fs" />
<Compile Include="PublicAPI.fs" />
<None Include="paket.references" />
<Compile Include="AssemblyInfo.fs" />
<Compile Include="CustomAssemblyInfo.fs" />
</ItemGroup>
<ItemGroup>
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Data.Linq" />
<Reference Include="System.Numerics" />
<Reference Include="System.Security" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<Import Project="Paket.Core.paket.targets" Condition="Exists('Paket.Core.paket.targets')" />
<Choose>
<When Condition="($(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v2.0' Or $(TargetFrameworkVersion) == 'v3.0' Or $(TargetFrameworkVersion) == 'v3.5' Or $(TargetFrameworkVersion) == 'v4.0' Or $(TargetFrameworkVersion) == 'v4.5' Or $(TargetFrameworkVersion) == 'v4.5.1' Or $(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.5.3')) Or ($(TargetFrameworkIdentifier) == 'MonoAndroid') Or ($(TargetFrameworkIdentifier) == 'MonoTouch')">
Expand Down Expand Up @@ -276,4 +208,70 @@
</ItemGroup>
</When>
</Choose>
<ItemGroup>
<Compile Include="..\..\paket-files\nessos\Streams\src\Streams.Core\Streams.fs">
<Paket>True</Paket>
<Link>Streams.fs</Link>
</Compile>
<Content Include="..\..\packages\FSharp.Core\lib\net40\FSharp.Core.optdata">
<Link>FSharp.Core.optdata</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="..\..\packages\FSharp.Core\lib\net40\FSharp.Core.sigdata">
<Link>FSharp.Core.sigdata</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Compile Include="Async.fs" />
<Compile Include="Domain.fs" />
<Compile Include="SemVer.fs" />
<Compile Include="VersionRange.fs" />
<Compile Include="Constants.fs" />
<Compile Include="Logging.fs" />
<Compile Include="Xml.fs" />
<Compile Include="Utils.fs" />
<Compile Include="ConfigFile.fs" />
<Compile Include="PackageSources.fs" />
<Compile Include="FrameworkHandling.fs" />
<Compile Include="PlatformMatching.fs" />
<Compile Include="Requirements.fs" />
<Compile Include="ModuleResolver.fs" />
<Compile Include="RemoteDownload.fs" />
<Compile Include="PackageResolver.fs" />
<Compile Include="Nuspec.fs" />
<Compile Include="InstallModel.fs" />
<Compile Include="ReferencesFile.fs" />
<Compile Include="ProjectFile.fs" />
<Compile Include="SolutionFile.fs" />
<Compile Include="NuGetV3.fs" />
<Compile Include="NuGetV2.fs" />
<Compile Include="DependenciesFile.fs" />
<Compile Include="DependencyModel.fs" />
<Compile Include="LockFile.fs" />
<Compile Include="RestoreProcess.fs" />
<Compile Include="BindingRedirects.fs" />
<Compile Include="InstallProcess.fs" />
<Compile Include="UpdateProcess.fs" />
<Compile Include="RemoveProcess.fs" />
<Compile Include="AddProcess.fs" />
<Compile Include="Simplifier.fs" />
<Compile Include="VSIntegration.fs" />
<Compile Include="NugetConvert.fs" />
<Compile Include="FindOutdated.fs" />
<Compile Include="FindReferences.fs" />
<Compile Include="PublicAPI.fs" />
<None Include="paket.references" />
<Compile Include="AssemblyInfo.fs" />
<Compile Include="CustomAssemblyInfo.fs" />
</ItemGroup>
<ItemGroup>
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Data.Linq" />
<Reference Include="System.Numerics" />
<Reference Include="System.Security" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
</ItemGroup>
</Project>
13 changes: 13 additions & 0 deletions src/Paket.Core/ProjectFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ type ProjectFile =

findInDir projectFile.Directory

static member FindOrCreateReferencesFile (projectFile : FileInfo) =
match ProjectFile.FindReferencesFile projectFile with
| None ->
let newFileName =
let fi = FileInfo(Path.Combine(projectFile.Directory.FullName,Constants.ReferencesFile))
if fi.Exists then
Path.Combine(projectFile.Directory.FullName,projectFile.Name + "." + Constants.ReferencesFile)
else
fi.FullName

ReferencesFile.New newFileName
| Some fileName -> ReferencesFile.FromFile fileName

member this.CreateNode(name) =
this.Document.CreateElement(name, Constants.ProjectDefaultNameSpace)

Expand Down
21 changes: 15 additions & 6 deletions src/Paket.Core/ReferencesFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@ type RemoteFileReference =

type ReferencesFile =
{ FileName: string
NugetPackages: list<PackageName>
RemoteFiles: list<RemoteFileReference> }
NugetPackages: PackageName list
RemoteFiles: RemoteFileReference list }

static member DefaultLink = Constants.PaketFilesFolderName

static member New(fileName) =
{ FileName = fileName
NugetPackages = []
RemoteFiles = [] }

static member FromLines(lines : string[]) =
let isSingleFile (line: string) = line.StartsWith "File:"
let notEmpty (line: string) = not <| String.IsNullOrWhiteSpace line
Expand All @@ -41,10 +46,14 @@ type ReferencesFile =
let lines = File.ReadAllLines(fileName)
{ ReferencesFile.FromLines lines with FileName = fileName }

member this.AddNuGetReference(reference : PackageName) =
let (PackageName referenceName) = reference
tracefn "Adding %s to %s" referenceName (this.FileName)
{ this with NugetPackages = this.NugetPackages @ [reference] }
member this.AddNuGetReference(packageName : PackageName) =
let (PackageName referenceName) = packageName
let normalized = NormalizedPackageName packageName
if this.NugetPackages |> Seq.exists (fun p -> NormalizedPackageName p = normalized) then
this
else
tracefn "Adding %s to %s" referenceName (this.FileName)
{ this with NugetPackages = this.NugetPackages @ [packageName] }

member this.Save() =
File.WriteAllText(this.FileName, this.ToString())
Expand Down
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>install --hard</StartArguments>
<StartArguments>add nuget NUNIT --interactive</StartArguments>
<StartAction>Project</StartAction>
<StartProgram>paket.exe</StartProgram>
<StartWorkingDirectory>
</StartWorkingDirectory>
<StartWorkingDirectory>d:\code\PaketTest3</StartWorkingDirectory>
<StartWorkingDirectory>c:\code\PaketKopie</StartWorkingDirectory>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand Down
30 changes: 29 additions & 1 deletion tests/Paket.Tests/ReferencesFile/ReferencesFileSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,32 @@ let ``should parse lines with trailing whitspace correctly``() =
let refFile = ReferencesFile.FromLines(toLines refFileWithTrailingWhitespace)
refFile.NugetPackages.Length |> shouldEqual 2
refFile.NugetPackages.Head |> shouldEqual (PackageName "Castle.Windsor")
refFile.NugetPackages.Tail.Head |> shouldEqual (PackageName "Newtonsoft.Json")
refFile.NugetPackages.Tail.Head |> shouldEqual (PackageName "Newtonsoft.Json")

[<Test>]
let ``should add nuget package``() =
let empty = ReferencesFile.New("file.txt")
empty.NugetPackages.Length |> shouldEqual 0
empty.RemoteFiles.Length |> shouldEqual 0
empty.FileName |> shouldEqual "file.txt"

let refFile = empty.AddNuGetReference(PackageName "NUnit")
refFile.NugetPackages.Length |> shouldEqual 1
refFile.NugetPackages.Head |> shouldEqual (PackageName "NUnit")

let refFile' = refFile.AddNuGetReference(PackageName "xUnit")
refFile'.NugetPackages.Length |> shouldEqual 2
refFile'.NugetPackages.Head |> shouldEqual (PackageName "NUnit")
refFile'.NugetPackages.Tail.Head |> shouldEqual (PackageName "xUnit")


[<Test>]
let ``should not add nuget package twice``() =
let refFile =
ReferencesFile.New("file.txt")
.AddNuGetReference(PackageName "NUnit")
.AddNuGetReference(PackageName "NUnit")
.AddNuGetReference(PackageName "NUnit")

refFile.NugetPackages.Length |> shouldEqual 1
refFile.NugetPackages.Head |> shouldEqual (PackageName "NUnit")

0 comments on commit d9dbf4d

Please sign in to comment.