@@ -34,80 +34,84 @@ let rec private findPackage paths identity logger =
3434 | pkg -> Some( pkg, head)
3535 | [] -> None
3636
37-
38- let getPackageLicense ( projectSpec : PackageSpec ) checkGitHub token checkLicenseContent ( lib : LockFileLibrary ) =
39- let identity = PackageIdentity( lib.Name, lib.Version)
40-
41- let checkLicenseContents ' name url =
42- if checkLicenseContent then checkLicenseContents name url
43- else None
44-
45- let nugetPaths =
46- [| projectSpec.RestoreMetadata.PackagesPath |]
47- |> Seq.append projectSpec.RestoreMetadata.FallbackFolders
48- |> Seq.toList
49-
50- match findPackage nugetPaths identity MemoryLogger.Instance with
51- | None ->
52- { PackageName = lib.Name
53- PackageVersion = lib.Version
54- Type = lib.Type }
55- |> PackageNotFound
56- | Some( pId, path) ->
57- let licenseMetadata =
58- { Type = None
59- Version = None
60- Url = pId.Nuspec.GetLicenseUrl()
61- PackageName = lib.Name
62- PackageVersion = lib.Version }
63- match pId.Nuspec.GetLicenseMetadata() with
64- | null ->
65- let url = pId.Nuspec.GetLicenseUrl()
66- match checkGitHub, knownLicenseCache.TryFind url with
67- | (_, Some cachedLicense) ->
37+ let private buildLicenseFromPackage checkGitHub token checkLicenseContents' ( identity : PackageIdentity ) packagePath
38+ ( pId : LocalPackageInfo ) path =
39+ let licenseMetadata =
40+ { Type = None
41+ Version = None
42+ Url = pId.Nuspec.GetLicenseUrl()
43+ PackageName = identity.Id
44+ PackageVersion = identity.Version }
45+ match pId.Nuspec.GetLicenseMetadata() with
46+ | null ->
47+ let url = pId.Nuspec.GetLicenseUrl()
48+ match checkGitHub, knownLicenseCache.TryFind url with
49+ | (_, Some cachedLicense) ->
50+ { licenseMetadata with
51+ Type = Some cachedLicense.Expression
52+ Version = None }
53+ |> Licensed
54+ | ( true , None) ->
55+ match checkLicenseViaGitHub token url with
56+ | Some cachedLicense ->
6857 { licenseMetadata with
6958 Type = Some cachedLicense.Expression
7059 Version = None }
7160 |> Licensed
72- | ( true , None) ->
73- match checkLicenseViaGitHub token url with
74- | Some cachedLicense ->
75- { licenseMetadata with
76- Type = Some cachedLicense.Expression
77- Version = None }
78- |> Licensed
79- | None ->
80- match checkLicenseContents' lib.Name url with
81- | Some cachedLicense ->
82- { licenseMetadata with
83- Type = Some cachedLicense.Expression
84- Version = None }
85- |> Licensed
86- | None -> licenseMetadata |> LegacyLicensed
87- | ( false , None) ->
88- match checkLicenseContents' lib.Name url with
61+ | None ->
62+ match checkLicenseContents' identity.Id url with
8963 | Some cachedLicense ->
9064 { licenseMetadata with
9165 Type = Some cachedLicense.Expression
9266 Version = None }
9367 |> Licensed
9468 | None -> licenseMetadata |> LegacyLicensed
95- | license when license.Type = LicenseType.File ->
96- match Path.Combine( path, lib.Path, license.License)
97- |> File.ReadAllText
98- |> findMatchingLicense with
99- | Some licenseSpdx ->
69+ | ( false , None) ->
70+ match checkLicenseContents' identity.Id url with
71+ | Some cachedLicense ->
10072 { licenseMetadata with
101- Type = Some licenseSpdx
102- Version = Some license.Version }
103- |> Licensed
104- | None ->
105- { licenseMetadata with
106- Type = Some license.License
107- Version = Some license.Version }
73+ Type = Some cachedLicense.Expression
74+ Version = None }
10875 |> Licensed
109- | license ->
76+ | None -> licenseMetadata |> LegacyLicensed
77+ | license when license.Type = LicenseType.File ->
78+ match Path.Combine( path, packagePath, license.License)
79+ |> File.ReadAllText
80+ |> findMatchingLicense with
81+ | Some licenseSpdx ->
82+ { licenseMetadata with
83+ Type = Some licenseSpdx
84+ Version = Some license.Version }
85+ |> Licensed
86+ | None ->
11087 { licenseMetadata with
11188 Type = Some license.License
11289 Version = Some license.Version }
11390 |> Licensed
91+ | license ->
92+ { licenseMetadata with
93+ Type = Some license.License
94+ Version = Some license.Version }
95+ |> Licensed
96+
97+ let getPackageLicense ( projectSpec : PackageSpec ) checkGitHub token checkLicenseContent packageName packageVersion
98+ packageType =
99+ let identity = PackageIdentity( packageName, packageVersion)
100+
101+ let checkLicenseContents ' name url =
102+ if checkLicenseContent then checkLicenseContents name url else None
103+
104+ let nugetPaths =
105+ [| projectSpec.RestoreMetadata.PackagesPath |]
106+ |> Seq.append projectSpec.RestoreMetadata.FallbackFolders
107+ |> Seq.toList
108+
109+ match findPackage nugetPaths identity MemoryLogger.Instance with
110+ | None ->
111+ { PackageName = identity.Id
112+ PackageVersion = identity.Version
113+ Type = packageType }
114+ |> PackageNotFound
115+ | Some( pId, path) ->
116+ buildLicenseFromPackage checkGitHub token checkLicenseContents' identity
117+ (( sprintf " %s /%A " identity.Id identity.Version) .ToLower()) pId path
0 commit comments