Debian Codegraph @

cmd/license.go

raw symbols SCIP
1 package mainscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/cmd`/
2
3 import (
4 "encoding/jsonscip-go gomod github.com/golang/go/src go1.24 `encoding/json`/"
5 "fmtscip-go gomod github.com/golang/go/src go1.24 fmt/"
6 "go/formatscip-go gomod github.com/golang/go/src go1.24 `go/format`/"
7 "osscip-go gomod github.com/golang/go/src go1.24 os/"
8 "stringsscip-go gomod github.com/golang/go/src go1.24 strings/"
9 )
10
11 type LicenseDatascip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/cmd`/LicenseData# struct {
12 Versionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/cmd`/LicenseData#Version. string `json:"licenseListVersion"`
13 Licensesscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/cmd`/LicenseData#Licenses. []Licensescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/cmd`/License# `json:"licenses"`
14 }
15
16 type Licensescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/cmd`/License# struct {
17 Referencescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/cmd`/License#Reference. string `json:"reference"`
18 IsDeprecatedscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/cmd`/License#IsDeprecated. bool `json:"isDeprecatedLicenseId"`
19 DetailsURLscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/cmd`/License#DetailsURL. string `json:"detailsUrl"`
20 ReferenceNumberscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/cmd`/License#ReferenceNumber. int `json:"referenceNumber"`
21 Namescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/cmd`/License#Name. string `json:"name"`
22 LicenseIDscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/cmd`/License#LicenseID. string `json:"licenseId"`
23 SeeAlsoscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/cmd`/License#SeeAlso. []string `json:"seeAlso"`
24 IsOsiApprovedscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/cmd`/License#IsOsiApproved. bool `json:"isOsiApproved"`
25 }
26
27 // extractLicenseIDs reads the official licenses.json file copied from spdx/license-list-data
28 // and writes two files, license_ids.json and deprecated_license_ids.json, containing just
29 // the license IDs and deprecated license IDs, respectively. It returns an error if it
30 // encounters one.
31 func extractLicenseIDsscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/cmd`/extractLicenseIDs().() error {
32 // open file
33 file, err := osscip-go gomod github.com/golang/go/src go1.24 os/.Openscip-go gomod github.com/golang/go/src go1.24 os/Open().("licenses.json")
34 if err != nil {
35 fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Printlnscip-go gomod github.com/golang/go/src go1.24 fmt/Println().(err)
36 return err
37 }
38
39 // read in all licenses marshalled into a slice of license structs
40 var licenseData LicenseDatascip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/cmd`/LicenseData#
41 err = jsonscip-go gomod github.com/golang/go/src go1.24 `encoding/json`/.NewDecoderscip-go gomod github.com/golang/go/src go1.24 `encoding/json`/NewDecoder().(file).Decodescip-go gomod github.com/golang/go/src go1.24 `encoding/json`/Decoder#Decode().(&licenseData)
42 if err != nil {
43 fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Printlnscip-go gomod github.com/golang/go/src go1.24 fmt/Println().(err)
44 return err
45 }
46
47 // create two slices of license IDs, one for deprecated and one for active
48 var activeLicenseIDs []string
49 var deprecatedLicenseIDs []string
50 for _, l := range licenseData.Licensesscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/cmd`/LicenseData#Licenses. {
51 if l.IsDeprecatedscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/cmd`/License#IsDeprecated. {
52 deprecatedLicenseIDs = append(deprecatedLicenseIDs, l.LicenseIDscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/cmd`/License#LicenseID.)
53 } else {
54 activeLicenseIDs = append(activeLicenseIDs, l.LicenseIDscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/cmd`/License#LicenseID.)
55 }
56 }
57
58 // generate the GetLicenses() function in get_licenses.go
59 getLicensesContents := []byte(`package spdxlicenses
60
61 // Code generated by go-spdx cmd/license.go. DO NOT EDIT.
62 // Source: https://github.com/spdx/license-list-data specifies official SPDX license list.
63
64 import "strings"
65
66 // IsActiveLicense does a case-insensitive lookup for the license id in the active licenses map.
67 // It returns true and the case-sensitive ID if found, otherwise false and the original id.
68 func IsActiveLicense(id string) (bool, string) {
69 foundID, ok := licensesMap[strings.ToUpper(id)]
70 if ok {
71 return true, foundID
72 }
73 return false, id
74 }
75
76 // GetLicensesMap returns a map of active license IDs keyed by uppercase ID.
77 func GetLicensesMap() map[string]string {
78 copied := make(map[string]string, len(licensesMap))
79 for k, v := range licensesMap {
80 copied[k] = v
81 }
82 return copied
83 }
84
85 // GetLicenses returns a slice of active license IDs.
86 func GetLicenses() []string {
87 return []string{
88 `)
89 for _, id := range activeLicenseIDs {
90 getLicensesContents = append(getLicensesContents, ` "`+id+`",
91 `...)
92 }
93 getLicensesContents = append(getLicensesContents, ` }
94 }
95
96 `...)
97
98 getLicensesContents = append(getLicensesContents, `var licensesMap = map[string]string{
99 `...)
100 for _, id := range activeLicenseIDs {
101 getLicensesContents = append(getLicensesContents, ` "`+stringsscip-go gomod github.com/golang/go/src go1.24 strings/.ToUpperscip-go gomod github.com/golang/go/src go1.24 strings/ToUpper().(id)+`": "`+id+`",
102 `...)
103 }
104 getLicensesContents = append(getLicensesContents, `}
105 `...)
106
107 getLicensesContents, err = formatscip-go gomod github.com/golang/go/src go1.24 `go/format`/.Sourcescip-go gomod github.com/golang/go/src go1.24 `go/format`/Source().(getLicensesContents)
108 if err != nil {
109 return fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24 fmt/Errorf().("format generated get_licenses.go: %w", err)
110 }
111
112 err = osscip-go gomod github.com/golang/go/src go1.24 os/.WriteFilescip-go gomod github.com/golang/go/src go1.24 os/WriteFile().("../spdxexp/spdxlicenses/get_licenses.go", getLicensesContents, 0600)
113 if err != nil {
114 return err
115 }
116 fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Printlnscip-go gomod github.com/golang/go/src go1.24 fmt/Println().("Writing `../spdxexp/spdxlicenses/get_licenses.go`... COMPLETE")
117
118 // generate the GetDeprecated() function in get_deprecated.go
119 getDeprecatedContents := []byte(`package spdxlicenses
120
121 // Code generated by go-spdx cmd/license.go. DO NOT EDIT.
122 // Source: https://github.com/spdx/license-list-data specifies official SPDX license list.
123
124 import "strings"
125
126 // IsDeprecatedLicense does a case-insensitive lookup for the license id in the deprecated licenses map.
127 // It returns true and the case-sensitive ID if found, otherwise false and the original id.
128 func IsDeprecatedLicense(id string) (bool, string) {
129 foundID, ok := deprecatedMap[strings.ToUpper(id)]
130 if ok {
131 return true, foundID
132 }
133 return false, id
134 }
135
136 // GetDeprecatedMap returns a map of deprecated license IDs keyed by uppercase ID.
137 func GetDeprecatedMap() map[string]string {
138 copied := make(map[string]string, len(deprecatedMap))
139 for k, v := range deprecatedMap {
140 copied[k] = v
141 }
142 return copied
143 }
144
145 // GetDeprecated returns a slice of deprecated license IDs.
146 func GetDeprecated() []string {
147 return []string{
148 `)
149 for _, id := range deprecatedLicenseIDs {
150 getDeprecatedContents = append(getDeprecatedContents, ` "`+id+`",
151 `...)
152 }
153 getDeprecatedContents = append(getDeprecatedContents, ` }
154 }
155
156 `...)
157
158 getDeprecatedContents = append(getDeprecatedContents, `var deprecatedMap = map[string]string{
159 `...)
160 for _, id := range deprecatedLicenseIDs {
161 getDeprecatedContents = append(getDeprecatedContents, ` "`+stringsscip-go gomod github.com/golang/go/src go1.24 strings/.ToUpperscip-go gomod github.com/golang/go/src go1.24 strings/ToUpper().(id)+`": "`+id+`",
162 `...)
163 }
164 getDeprecatedContents = append(getDeprecatedContents, `}
165 `...)
166
167 getDeprecatedContents, err = formatscip-go gomod github.com/golang/go/src go1.24 `go/format`/.Sourcescip-go gomod github.com/golang/go/src go1.24 `go/format`/Source().(getDeprecatedContents)
168 if err != nil {
169 return fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24 fmt/Errorf().("format generated get_deprecated.go: %w", err)
170 }
171
172 err = osscip-go gomod github.com/golang/go/src go1.24 os/.WriteFilescip-go gomod github.com/golang/go/src go1.24 os/WriteFile().("../spdxexp/spdxlicenses/get_deprecated.go", getDeprecatedContents, 0600)
173 if err != nil {
174 return err
175 }
176 fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Printlnscip-go gomod github.com/golang/go/src go1.24 fmt/Println().("Writing `../spdxexp/spdxlicenses/get_deprecated.go`... COMPLETE")
177
178 return nil
179 }