Skip to content

Commit

Permalink
Refactor to use functions in the ReferencesFile for add/remove - fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Jan 14, 2015
1 parent ec6435b commit 784f464
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 15 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.22.12 - 14.01.2015
* BUGFIX: `paket add` offered to add dependencies even when they are already added - https://github.com/fsprojects/Paket/issues/550

#### 0.22.11 - 14.01.2015
* BUGFIX: Detect `Net20-client` - https://github.com/fsprojects/Paket/issues/547

Expand Down
4 changes: 2 additions & 2 deletions src/Paket.Core/ProjectFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ type ProjectFile =
match ProjectFile.FindReferencesFile proj with
| None -> false
| Some fileName ->
let lines = File.ReadAllLines(fileName)
lines |> Seq.exists (fun l -> l.ToLower() = package.ToString().ToLower())
let referencesFile = ReferencesFile.FromFile fileName
referencesFile.NugetPackages |> Seq.exists (fun p -> NormalizedPackageName p = package)

member this.CreateNode(name, text) =
let node = this.CreateNode(name)
Expand Down
9 changes: 9 additions & 0 deletions src/Paket.Core/ReferencesFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ type ReferencesFile =
tracefn "Adding %s to %s" referenceName (this.FileName)
{ this with NugetPackages = this.NugetPackages @ [packageName] }

member this.RemoveNuGetReference(packageName : PackageName) =
let (PackageName referenceName) = packageName
let normalized = NormalizedPackageName packageName
if this.NugetPackages |> Seq.exists (fun p -> NormalizedPackageName p = normalized) |> not then
this
else
tracefn "Removing %s from %s" referenceName (this.FileName)
{ this with NugetPackages = this.NugetPackages |> List.filter (fun p -> NormalizedPackageName p <> normalized) }

member this.Save() =
File.WriteAllText(this.FileName, this.ToString())
tracefn "References file saved to %s" this.FileName
Expand Down
19 changes: 7 additions & 12 deletions src/Paket.Core/RemoveProcess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,13 @@ let Remove(dependenciesFileName, package:PackageName, force, hard, interactive,
let (PackageName name) = package
let root = Path.GetDirectoryName dependenciesFileName
let allProjects = ProjectFile.FindAllProjects root
for project in allProjects do
let proj = FileInfo(project.FileName)
match ProjectFile.FindReferencesFile proj with
| None -> ()
| Some fileName ->
let lines = File.ReadAllLines(fileName)
let installed = lines |> Seq.exists (fun l -> l.ToLower() = name.ToLower())
if installed then
if (not interactive) || Utils.askYesNo(sprintf " Remove from %s?" project.Name) then
let newLines = lines |> Seq.filter (fun l -> l.ToLower() <> name.ToLower())
File.WriteAllLines(fileName,newLines)

for project in allProjects do
if project.HasPackageInstalled(NormalizedPackageName package) then
if (not interactive) || Utils.askYesNo(sprintf " Remove from %s?" project.Name) then
ProjectFile.FindOrCreateReferencesFile(FileInfo(project.FileName))
.RemoveNuGetReference(package)
.Save()

// check we have it removed from all paket.references files
let stillInstalled =
allProjects
Expand Down
2 changes: 1 addition & 1 deletion src/Paket/Paket.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<DocumentationFile>
</DocumentationFile>
<StartArguments>update -f</StartArguments>
<StartArguments>add nuget NUnit -i</StartArguments>
<StartArguments>remove nuget nunit -i</StartArguments>

This comment has been minimized.

Copy link
@theimowski

theimowski Jan 15, 2015

Member

How come there are two entries for StartArguments? same for WorkingDir 5 lines below

This comment has been minimized.

Copy link
@forki

forki Jan 15, 2015

Author Member

this is a issue with merge of XML files.
Pelase fix by deleting duplicates

<StartAction>Project</StartAction>
<StartProgram>paket.exe</StartProgram>
<StartWorkingDirectory>
Expand Down

0 comments on commit 784f464

Please sign in to comment.