Debian Codegraph @

cmd/exceptions.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 ExceptionDatascip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/cmd`/ExceptionData# struct {
12 Versionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/cmd`/ExceptionData#Version. string `json:"licenseListVersion"`
13 Exceptionsscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/cmd`/ExceptionData#Exceptions. []Exceptionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/cmd`/Exception# `json:"exceptions"`
14 }
15
16 type Exceptionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/cmd`/Exception# struct {
17 Referencescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/cmd`/Exception#Reference. string `json:"reference"`
18 IsDeprecatedscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/cmd`/Exception#IsDeprecated. bool `json:"isDeprecatedLicenseId"`
19 DetailsURLscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/cmd`/Exception#DetailsURL. string `json:"detailsUrl"`
20 ReferenceNumberscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/cmd`/Exception#ReferenceNumber. int `json:"referenceNumber"`
21 Namescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/cmd`/Exception#Name. string `json:"name"`
22 LicenseIDscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/cmd`/Exception#LicenseID. string `json:"licenseExceptionId"`
23 SeeAlsoscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/cmd`/Exception#SeeAlso. []string `json:"seeAlso"`
24 IsOsiApprovedscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/cmd`/Exception#IsOsiApproved. bool `json:"isOsiApproved"`
25 }
26
27 // extractExceptionLicenseIDs read official exception licenses file copied from spdx/license-list-data
28 // and write file exception_license_ids.json containing just the non-deprecated exception license IDs.
29 // NOTE: For now, this function ignores the deprecated exception licenses.
30 func extractExceptionLicenseIDsscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/cmd`/extractExceptionLicenseIDs().() error {
31 // open file
32 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().("exceptions.json")
33 if err != nil {
34 fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Printlnscip-go gomod github.com/golang/go/src go1.24 fmt/Println().(err)
35 return err
36 }
37
38 // read in all licenses marshalled into a slice of exception structs
39 var exceptionData ExceptionDatascip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/cmd`/ExceptionData#
40 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().(&exceptionData)
41 if err != nil {
42 return err
43 }
44
45 // create slice of exception license IDs that are not deprecated
46 var exceptionLicenseIDs []string
47 for _, e := range exceptionData.Exceptionsscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/cmd`/ExceptionData#Exceptions. {
48 if !e.IsDeprecatedscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/cmd`/Exception#IsDeprecated. {
49 exceptionLicenseIDs = append(exceptionLicenseIDs, e.LicenseIDscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/cmd`/Exception#LicenseID.)
50 }
51 }
52
53 // generate the GetExceptions() function in get_exceptions.go
54 getExceptionsContents := []byte(`package spdxlicenses
55
56 // Code generated by go-spdx cmd/exceptions.go. DO NOT EDIT.
57 // Source: https://github.com/spdx/license-list-data specifies official SPDX license list.
58
59 import "strings"
60
61 // IsException does a case-insensitive lookup for the exception id in the exceptions map.
62 // It returns true and the case-sensitive ID if found, otherwise false and the original id.
63 func IsException(id string) (bool, string) {
64 foundID, ok := exceptionsMap[strings.ToUpper(id)]
65 if ok {
66 return true, foundID
67 }
68 return false, id
69 }
70
71 // GetExceptionsMap returns a map of exception license IDs keyed by uppercase ID.
72 func GetExceptionsMap() map[string]string {
73 copied := make(map[string]string, len(exceptionsMap))
74 for k, v := range exceptionsMap {
75 copied[k] = v
76 }
77 return copied
78 }
79
80 // GetExceptions returns a slice of exception license IDs.
81 func GetExceptions() []string {
82 return []string{
83 `)
84 for _, id := range exceptionLicenseIDs {
85 getExceptionsContents = append(getExceptionsContents, ` "`+id+`",
86 `...)
87 }
88 getExceptionsContents = append(getExceptionsContents, ` }
89 }
90
91 `...)
92
93 getExceptionsContents = append(getExceptionsContents, `var exceptionsMap = map[string]string{
94 `...)
95 for _, id := range exceptionLicenseIDs {
96 getExceptionsContents = append(getExceptionsContents, ` "`+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+`",
97 `...)
98 }
99 getExceptionsContents = append(getExceptionsContents, `}
100 `...)
101
102 getExceptionsContents, 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().(getExceptionsContents)
103 if err != nil {
104 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_exceptions.go: %w", err)
105 }
106
107 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_exceptions.go", getExceptionsContents, 0600)
108 if err != nil {
109 return err
110 }
111 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_exceptions.go`... COMPLETE")
112
113 return nil
114 }