Skip to content

Commit

Permalink
Parse license from OData and Nuspec
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Mar 30, 2015
1 parent 1bba3c8 commit 62be8ce
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 5 deletions.
15 changes: 12 additions & 3 deletions src/Paket.Core/NuGetV2.fs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ type NugetPackageCache =
PackageName : string
SourceUrl: string
Unlisted : bool
DownloadUrl : string;
DownloadUrl : string
LicenseUrl : string
CacheVersion: string }

static member CurrentCacheVersion = "1.0"
static member CurrentCacheVersion = "1.1"

let rec private followODataLink getUrlContents url =
async {
Expand Down Expand Up @@ -175,6 +176,11 @@ let parseODataDetails(nugetURL,packageName,version,raw) =
| Some "binary/octet-stream", Some link -> link
| _ -> failwithf "unable to find downloadLink for package %s %O" packageName version

let licenseUrl =
match entry |> getNode "properties" |> optGetNode "LicenseUrl" with
| Some node -> node.InnerText
| _ -> ""

let dependencies =
match entry |> getNode "properties" |> optGetNode "Dependencies" with
| Some node -> node.InnerText
Expand Down Expand Up @@ -203,6 +209,7 @@ let parseODataDetails(nugetURL,packageName,version,raw) =
Dependencies = Requirements.optimizeRestrictions packages
SourceUrl = nugetURL
CacheVersion = NugetPackageCache.CurrentCacheVersion
LicenseUrl = licenseUrl
Unlisted = publishDate = Constants.MagicUnlistingDate }


Expand Down Expand Up @@ -314,6 +321,7 @@ let getDetailsFromLocalFile localNugetPath package (version:SemVerInfo) =
Dependencies = Requirements.optimizeRestrictions nuspec.Dependencies
SourceUrl = localNugetPath
CacheVersion = NugetPackageCache.CurrentCacheVersion
LicenseUrl = nuspec.LicenseUrl
Unlisted = false }
}

Expand Down Expand Up @@ -472,7 +480,7 @@ let GetTargetsFiles(targetFolder) =

targetsFiles

let GetPackageDetails force sources (PackageName package) (version:SemVerInfo) : PackageResolver.PackageDetails=
let GetPackageDetails force sources (PackageName package) (version:SemVerInfo) : PackageResolver.PackageDetails =
let rec tryNext xs =
match xs with
| source :: rest ->
Expand Down Expand Up @@ -501,6 +509,7 @@ let GetPackageDetails force sources (PackageName package) (version:SemVerInfo) :
Source = source
DownloadLink = nugetObject.DownloadUrl
Unlisted = nugetObject.Unlisted
LicenseUrl = nugetObject.LicenseUrl
DirectDependencies =
nugetObject.Dependencies
|> Requirements.optimizeRestrictions
Expand Down
11 changes: 9 additions & 2 deletions src/Paket.Core/Nuspec.fs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ type Nuspec =
{ References : NuspecReferences
Dependencies : (PackageName * VersionRequirement * FrameworkRestrictions) list
OfficialName : string
LicenseUrl : string
FrameworkAssemblyReferences : FrameworkAssemblyReference list }

static member All = { References = NuspecReferences.All; Dependencies = []; FrameworkAssemblyReferences = []; OfficialName = "" }
static member Explicit references = { References = NuspecReferences.Explicit references; Dependencies = []; FrameworkAssemblyReferences = []; OfficialName = "" }
static member All = { References = NuspecReferences.All; Dependencies = []; FrameworkAssemblyReferences = []; OfficialName = ""; LicenseUrl = "" }
static member Explicit references = { References = NuspecReferences.Explicit references; Dependencies = []; FrameworkAssemblyReferences = []; OfficialName = ""; LicenseUrl = "" }
static member Load(fileName : string) =
let fi = FileInfo(fileName)
if not fi.Exists then Nuspec.All
Expand Down Expand Up @@ -76,6 +77,11 @@ type Nuspec =
|> List.map dependency
|> List.append frameworks
|> Requirements.optimizeRestrictions

let licenseUrl =
match doc |> getNode "package" |> optGetNode "metadata" |> optGetNode "licenseUrl" with
| Some link -> link.InnerText
| None -> ""

let references =
doc
Expand Down Expand Up @@ -114,4 +120,5 @@ type Nuspec =
{ References = if references = [] then NuspecReferences.All else NuspecReferences.Explicit references
Dependencies = dependencies
OfficialName = officialName
LicenseUrl = licenseUrl
FrameworkAssemblyReferences = frameworkAssemblyReferences }
1 change: 1 addition & 0 deletions src/Paket.Core/PackageResolver.fs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type PackageDetails =
{ Name : PackageName
Source : PackageSource
DownloadLink : string
LicenseUrl : string
Unlisted : bool
DirectDependencies : DependencySet }

Expand Down
1 change: 1 addition & 0 deletions tests/Paket.Tests/InstallModel/Xml/RxXaml.fs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ let ``should generate Xml for Rx-XAML 2.2.4 with correct framework assembly refe
{ References = NuspecReferences.All
OfficialName = "Reactive Extensions - XAML Support Library"
Dependencies = []
LicenseUrl = ""
FrameworkAssemblyReferences =
[{ AssemblyName = "WindowsBase"; FrameworkRestrictions = [FrameworkRestriction.Exactly(DotNetFramework FrameworkVersion.V4_5)] }
{ AssemblyName = "WindowsBase"; FrameworkRestrictions = [FrameworkRestriction.Exactly(DotNetFramework FrameworkVersion.V4)] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ let ``should generate Xml for System.Net.Http 2.2.8``() =
{ References = NuspecReferences.All
OfficialName = "Microsoft.Net.Http"
Dependencies = []
LicenseUrl = ""
FrameworkAssemblyReferences =
[{ AssemblyName = "System.Net.Http"; FrameworkRestrictions = [FrameworkRestriction.Exactly(DotNetFramework(FrameworkVersion.V4_5))] }
{ AssemblyName = "System.Net.Http.WebRequest"; FrameworkRestrictions = [FrameworkRestriction.Exactly(DotNetFramework(FrameworkVersion.V4_5))] }]})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ let ``should generate Xml for System.Net.Http 2.2.8``() =
{ References = NuspecReferences.All
OfficialName = "Microsoft.Net.Http"
Dependencies = []
LicenseUrl = ""
FrameworkAssemblyReferences =
[{ AssemblyName = "System.Net.Http"; FrameworkRestrictions = [FrameworkRestriction.AtLeast(DotNetFramework(FrameworkVersion.V4_5))] }
{ AssemblyName = "System.Net.Http.WebRequest"; FrameworkRestrictions = [FrameworkRestriction.Exactly(DotNetFramework(FrameworkVersion.V4_5))] }]})
Expand Down
6 changes: 6 additions & 0 deletions tests/Paket.Tests/NuGetOData/ODataSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ let ``can detect explicit dependencies for Fantomas``() =
DownloadUrl = "http://www.nuget.org/api/v2/package/Fantomas/1.6.0"
Dependencies = [PackageName "FSharp.Compiler.Service",DependenciesFileParser.parseVersionRequirement(">= 0.0.73"), []]
Unlisted = false
LicenseUrl = "http://github.com/dungpa/fantomas/blob/master/LICENSE.md"
CacheVersion = NugetPackageCache.CurrentCacheVersion
SourceUrl = fakeUrl }

Expand All @@ -36,6 +37,7 @@ let ``can detect explicit dependencies for Rx-PlaformServices``() =
[PackageName "Rx-Interfaces",DependenciesFileParser.parseVersionRequirement(">= 2.2"), []
PackageName "Rx-Core",DependenciesFileParser.parseVersionRequirement(">= 2.2"), []]
Unlisted = true
LicenseUrl = "http://go.microsoft.com/fwlink/?LinkID=261272"
CacheVersion = NugetPackageCache.CurrentCacheVersion
SourceUrl = fakeUrl }

Expand All @@ -48,6 +50,7 @@ let ``can detect explicit dependencies for EasyNetQ``() =
Dependencies =
[PackageName "RabbitMQ.Client",DependenciesFileParser.parseVersionRequirement(">= 3.4.3"), []]
Unlisted = false
LicenseUrl = "https://github.com/mikehadlow/EasyNetQ/blob/master/licence.txt"
CacheVersion = NugetPackageCache.CurrentCacheVersion
SourceUrl = fakeUrl }

Expand All @@ -59,6 +62,7 @@ let ``can detect explicit dependencies for Fleece``() =
DownloadUrl = "http://www.nuget.org/api/v2/package/Fleece/0.4.0"
Unlisted = false
CacheVersion = NugetPackageCache.CurrentCacheVersion
LicenseUrl = "https://raw.github.com/mausch/Fleece/master/LICENSE"
Dependencies =
[PackageName "FSharpPlus",DependenciesFileParser.parseVersionRequirement(">= 0.0.4"), []
PackageName "ReadOnlyCollectionInterfaces",DependenciesFileParser.parseVersionRequirement("1.0.0"), []
Expand All @@ -74,6 +78,7 @@ let ``can detect explicit dependencies for ReadOnlyCollectionExtensions``() =
DownloadUrl = "http://www.nuget.org/api/v2/package/ReadOnlyCollectionExtensions/1.2.0"
Unlisted = false
CacheVersion = NugetPackageCache.CurrentCacheVersion
LicenseUrl = "https://github.com/mausch/ReadOnlyCollections/blob/master/license.txt"
Dependencies =
[PackageName "LinqBridge",DependenciesFileParser.parseVersionRequirement(">= 1.3.0"),
[FrameworkRestriction.Between(DotNetFramework(FrameworkVersion.V2),DotNetFramework(FrameworkVersion.V3_5))]
Expand All @@ -90,6 +95,7 @@ let ``can detect explicit dependencies for Math.Numerics``() =
{ PackageName = "MathNet.Numerics"
DownloadUrl = "http://www.nuget.org/api/v2/package/MathNet.Numerics/3.3.0"
Unlisted = false
LicenseUrl = "http://numerics.mathdotnet.com/docs/License.html"
CacheVersion = NugetPackageCache.CurrentCacheVersion
Dependencies =
[PackageName "TaskParallelLibrary",DependenciesFileParser.parseVersionRequirement(">= 1.0.2856"),
Expand Down
5 changes: 5 additions & 0 deletions tests/Paket.Tests/Nuspec/NuspecSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ let ``can detect framework assemblies for SqlCLient``() =
[{ AssemblyName = "System.Data"; FrameworkRestrictions = [] }
{ AssemblyName = "System.Xml"; FrameworkRestrictions = [] } ]

[<Test>]
let ``can detect ´license for SqlCLient``() =
Nuspec.Load("Nuspec/FSharp.Data.SqlClient.nuspec").LicenseUrl
|> shouldEqual "http://github.com/fsprojects/FSharp.Data.SqlClient/blob/master/LICENSE.md"

[<Test>]
let ``can detect dependencies for SqlCLient``() =
Nuspec.Load("Nuspec/FSharp.Data.SqlClient.nuspec").Dependencies
Expand Down
1 change: 1 addition & 0 deletions tests/Paket.Tests/TestHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ let PackageDetailsFromGraph (graph : seq<string * string * (string * VersionRequ
{ Name = name
Source = Seq.head sources
DownloadLink = ""
LicenseUrl = ""
Unlisted = false
DirectDependencies = Set.ofList dependencies }

Expand Down

0 comments on commit 62be8ce

Please sign in to comment.