@@ -3,6 +3,7 @@ package main
33import (
44 "encoding/json"
55 "fmt"
6+ "go/format"
67 "os"
78 "strings"
89)
@@ -60,6 +61,27 @@ func extractLicenseIDs() error {
6061// Code generated by go-spdx cmd/license.go. DO NOT EDIT.
6162// Source: https://github.com/spdx/license-list-data specifies official SPDX license list.
6263
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+
6385// GetLicenses returns a slice of active license IDs.
6486func GetLicenses() []string {
6587 return []string{
@@ -80,13 +102,13 @@ func GetLicenses() []string {
80102` ... )
81103 }
82104 getLicensesContents = append (getLicensesContents , `}
83-
84- // GetLicensesMap returns a map of active license IDs keyed by uppercase ID.
85- func GetLicensesMap() map[string]string {
86- return licensesMap
87- }
88105` ... )
89106
107+ getLicensesContents , err = format .Source (getLicensesContents )
108+ if err != nil {
109+ return fmt .Errorf ("format generated get_licenses.go: %w" , err )
110+ }
111+
90112 err = os .WriteFile ("../spdxexp/spdxlicenses/get_licenses.go" , getLicensesContents , 0600 )
91113 if err != nil {
92114 return err
@@ -99,6 +121,27 @@ func GetLicensesMap() map[string]string {
99121// Code generated by go-spdx cmd/license.go. DO NOT EDIT.
100122// Source: https://github.com/spdx/license-list-data specifies official SPDX license list.
101123
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+
102145// GetDeprecated returns a slice of deprecated license IDs.
103146func GetDeprecated() []string {
104147 return []string{
@@ -119,13 +162,13 @@ func GetDeprecated() []string {
119162` ... )
120163 }
121164 getDeprecatedContents = append (getDeprecatedContents , `}
122-
123- // GetDeprecatedMap returns a map of deprecated license IDs keyed by uppercase ID.
124- func GetDeprecatedMap() map[string]string {
125- return deprecatedMap
126- }
127165` ... )
128166
167+ getDeprecatedContents , err = format .Source (getDeprecatedContents )
168+ if err != nil {
169+ return fmt .Errorf ("format generated get_deprecated.go: %w" , err )
170+ }
171+
129172 err = os .WriteFile ("../spdxexp/spdxlicenses/get_deprecated.go" , getDeprecatedContents , 0600 )
130173 if err != nil {
131174 return err
0 commit comments