Skip to content

Commit

Permalink
Allow to add references section to paket.template file - closes #721
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Mar 27, 2015
1 parent 8c90659 commit f31cf82
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 1 deletion.
3 changes: 3 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#### 0.36.0 - 27.03.2015
* Allow to add references section to paket.template file - https://github.com/fsprojects/Paket/issues/721

#### 0.35.13 - 27.03.2015
* Allow to compute libraries for specific framework - https://github.com/fsprojects/Paket/issues/723

Expand Down
12 changes: 12 additions & 0 deletions src/Paket.Core/NupkgWriter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ let nuspecDoc (info:CompleteInfo) =
let d = XElement(ns + "dependencies")
dependencyList |> List.iter (buildDependencyNode >> d.Add)
metadataNode.Add d

let buildReferenceNode (fileName) =
let dep = XElement(ns + "reference")
dep.SetAttributeValue(XName.Get "file", fileName)
dep

let buildReferencesNode referenceList =
if referenceList = [] then () else
let d = XElement(ns + "references")
referenceList |> List.iter (buildReferenceNode >> d.Add)
metadataNode.Add d

!! "id" core.Id
match core.Version with
Expand All @@ -102,6 +113,7 @@ let nuspecDoc (info:CompleteInfo) =
if optional.DevelopmentDependency then
!! "developmentDependency" "true"

optional.References |> buildReferencesNode
optional.Dependencies |> buildDependenciesNode
XDocument(declaration, box root)

Expand Down
9 changes: 9 additions & 0 deletions src/Paket.Core/TemplateFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ type internal OptionalPackagingInfo =
Tags : string list
DevelopmentDependency : bool
Dependencies : (string * VersionRequirement) list
References : string list
Files : (string * string) list }
static member Epmty : OptionalPackagingInfo =
{ Title = None
Expand All @@ -133,6 +134,7 @@ type internal OptionalPackagingInfo =
Tags = []
DevelopmentDependency = false
Dependencies = []
References = []
Files = [] }

type internal CompleteInfo = CompleteCoreInfo * OptionalPackagingInfo
Expand Down Expand Up @@ -223,6 +225,12 @@ module internal TemplateFile =
splitted.[0],target))
|> Option.map List.ofSeq
|> fun x -> defaultArg x []

let private getReferences (map : Map<string, string>) =
Map.tryFind "references" map
|> Option.map (fun d -> d.Split '\n')
|> Option.map List.ofSeq
|> fun x -> defaultArg x []

let private getOptionalInfo (map : Map<string, string>) =
let get (n : string) = Map.tryFind (n.ToLowerInvariant()) map
Expand Down Expand Up @@ -275,6 +283,7 @@ module internal TemplateFile =
Tags = tags
DevelopmentDependency = developmentDependency
Dependencies = getDependencies map
References = getReferences map
Files = getFiles map }

let Parse(file,contentStream : Stream) =
Expand Down
7 changes: 6 additions & 1 deletion tests/Paket.Tests/NuspecWriterSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ open NUnit.Framework
open TestHelpers

[<Test>]
let ``should serialize cor info``() =
let ``should serialize core info``() =
let result = """<package xmlns="http://schemas.microsoft.com/packaging/2011/10/nuspec.xsd">
<metadata>
<id>Paket.Tests</id>
Expand Down Expand Up @@ -114,6 +114,10 @@ second line</releaseNotes>
<language>en-US</language>
<tags>aa bb</tags>
<developmentDependency>true</developmentDependency>
<references>
<reference file="file1.dll" />
<reference file="file2.dll" />
</references>
</metadata>
</package>"""

Expand All @@ -135,6 +139,7 @@ second line</releaseNotes>
IconUrl = Some "http://www.somewhere.com/Icon"
Copyright = Some "Paket owners 2015"
RequireLicenseAcceptance = true
References = ["file1.dll";"file2.dll"]
Tags = ["aa"; "bb"]
DevelopmentDependency = true }

Expand Down
27 changes: 27 additions & 0 deletions tests/Paket.Tests/TemplateFileParsing.fs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,33 @@ files
to' |> shouldEqual "lib"
| _ -> Assert.Fail()

[<Test>]
let ``Detect references correctly``() =
let text = """type file
id My.Thing
authors Bob McBob
description
A longer description
on two lines.
references
somefile
someOtherFile.dll
version
1.0
"""
let sut =
TemplateFile.Parse("file1.template", strToStream text)
|> returnOrFail
|> function
| CompleteInfo (_, opt)
| ProjectInfo (_, opt) -> opt

match sut.References with
| reference1::reference2::[] ->
reference1 |> shouldEqual "somefile"
reference2 |> shouldEqual "someOtherFile.dll"
| _ -> Assert.Fail()

[<Test>]
let ``Detect multiple files correctly``() =
let text = """type file
Expand Down

0 comments on commit f31cf82

Please sign in to comment.