Skip to content

Commit fefc4eb

Browse files
committed
turning a field into an optional one
1 parent 43d8ff3 commit fefc4eb

File tree

2 files changed

+66
-45
lines changed

2 files changed

+66
-45
lines changed

src/DotNetDelice.Licensing/Spdx.fs

Lines changed: 56 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,56 @@
1-
module Spdx
2-
3-
open FSharp.Data
4-
open System.IO
5-
6-
[<Literal>]
7-
let private URL = "https://spdx.org/licenses/licenses.json"
8-
9-
type Spdx = JsonProvider<"""{ "licenses": [{
10-
"reference": "./MIT.html",
11-
"isDeprecatedLicenseId": false,
12-
"isFsfLibre": true,
13-
"detailsUrl": "http://spdx.org/licenses/MIT.json",
14-
"referenceNumber": "201",
15-
"name": "MIT License",
16-
"licenseId": "MIT",
17-
"seeAlso": [
18-
"https://opensource.org/licenses/MIT"
19-
],
20-
"isOsiApproved": true
21-
}] }""">
22-
23-
let private download() = Spdx.AsyncLoad URL
24-
let private getFileLocation() = Path.Combine(System.Environment.CurrentDirectory, "licenses.json")
25-
26-
let getSpdx refreshFile =
27-
async {
28-
if refreshFile then
29-
if File.Exists(getFileLocation()) then File.Delete <| getFileLocation()
30-
let! contents = download()
31-
File.WriteAllText(getFileLocation(), contents.ToString())
32-
return contents
33-
else if not (File.Exists(getFileLocation())) then
34-
let! contents = download()
35-
File.WriteAllText(getFileLocation(), contents.ToString())
36-
return contents
37-
else
38-
let contents = File.ReadAllText <| getFileLocation()
39-
return Spdx.Parse contents
40-
}
1+
module Spdx
2+
3+
open FSharp.Data
4+
open System.IO
5+
6+
[<Literal>]
7+
let private URL =
8+
"https://spdx.org/licenses/licenses.json"
9+
10+
type Spdx =
11+
JsonProvider<"""{ "licenses": [{
12+
"reference": "./MIT.html",
13+
"isDeprecatedLicenseId": false,
14+
"isFsfLibre": true,
15+
"detailsUrl": "http://spdx.org/licenses/MIT.json",
16+
"referenceNumber": "201",
17+
"name": "MIT License",
18+
"licenseId": "MIT",
19+
"seeAlso": [
20+
"https://opensource.org/licenses/MIT"
21+
],
22+
"isOsiApproved": true
23+
},
24+
{
25+
"reference": "./MIT.html",
26+
"isDeprecatedLicenseId": false,
27+
"detailsUrl": "http://spdx.org/licenses/MIT.json",
28+
"referenceNumber": "201",
29+
"name": "MIT License",
30+
"licenseId": "MIT",
31+
"seeAlso": [
32+
"https://opensource.org/licenses/MIT"
33+
],
34+
"isOsiApproved": true
35+
}] }""">
36+
37+
let private download () = Spdx.AsyncLoad URL
38+
39+
let private getFileLocation () =
40+
Path.Combine(System.Environment.CurrentDirectory, "licenses.json")
41+
42+
let getSpdx refreshFile =
43+
async {
44+
if refreshFile then
45+
if File.Exists(getFileLocation ()) then File.Delete <| getFileLocation ()
46+
let! contents = download ()
47+
File.WriteAllText(getFileLocation (), contents.ToString())
48+
return contents
49+
else if not (File.Exists(getFileLocation ())) then
50+
let! contents = download ()
51+
File.WriteAllText(getFileLocation (), contents.ToString())
52+
return contents
53+
else
54+
let contents = File.ReadAllText <| getFileLocation ()
55+
return Spdx.Parse contents
56+
}

src/DotNetDelice/Output.fs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ type PrintableLicense =
2626
let private licensesCodeGen legacyLicensed =
2727
legacyLicensed
2828
|> Seq.groupBy (fun l -> l.Url)
29-
|> Seq.iter
30-
(fun (url, pkgs) ->
29+
|> Seq.iter (fun (url, pkgs) ->
3130
printfn "(\"%s\", { Expression = \"\"; Packages = Map.ofList[%s]})" url.Value
3231
(pkgs
3332
|> Seq.map (fun p -> sprintf "(\"%s\", [\"%A\"])" p.Name p.Version)
@@ -36,8 +35,14 @@ let private licensesCodeGen legacyLicensed =
3635
let getSpdxInfo licenseId =
3736
async {
3837
let! spdx = getSpdx false
39-
match spdx.Licenses |> Array.tryFind (fun l -> l.LicenseId = licenseId) with
40-
| Some spdxInfo -> return (spdxInfo.IsOsiApproved, spdxInfo.IsFsfLibre, spdxInfo.IsDeprecatedLicenseId)
38+
match spdx.Licenses
39+
|> Array.tryFind (fun l -> l.LicenseId = licenseId) with
40+
| Some spdxInfo ->
41+
return (spdxInfo.IsOsiApproved,
42+
(match spdxInfo.IsFsfLibre with
43+
| Some b -> b
44+
| None -> false),
45+
spdxInfo.IsDeprecatedLicenseId)
4146
| None -> return (false, false, false)
4247
}
4348
|> Async.RunSynchronously
@@ -78,4 +83,4 @@ let getProjectBreakdown licenses =
7883
| _ -> None)
7984
|> Seq.sortBy (fun l -> l.PackageName)
8085

81-
(unlicensed, projectReferences, licensed, legacyLicensed)
86+
(unlicensed, projectReferences, licensed, legacyLicensed)

0 commit comments

Comments
 (0)