@@ -3,7 +3,6 @@ package main
3
3
import (
4
4
"encoding/json"
5
5
"fmt"
6
- "io/ioutil"
7
6
"os"
8
7
)
9
8
@@ -43,61 +42,54 @@ func extractLicenseIDs() error {
43
42
return err
44
43
}
45
44
46
- // create two slices of license IDs, one for deprecated and one for not deprecated
45
+ // create two slices of license IDs, one for deprecated and one for active
46
+ var activeLicenseIDs []string
47
47
var deprecatedLicenseIDs []string
48
- var nonDeprecatedLicenseIDs []string
49
48
for _ , l := range licenseData .Licenses {
50
49
if l .IsDeprecated {
51
50
deprecatedLicenseIDs = append (deprecatedLicenseIDs , l .LicenseID )
52
51
} else {
53
- nonDeprecatedLicenseIDs = append (nonDeprecatedLicenseIDs , l .LicenseID )
52
+ activeLicenseIDs = append (activeLicenseIDs , l .LicenseID )
54
53
}
55
54
}
56
55
57
- // save deprecated license IDs followed by a comma with one per line in file deprecated_license_ids.txt
58
- deprecatedLicenseIDsTxt := []byte {}
59
- for _ , id := range deprecatedLicenseIDs {
60
- deprecatedLicenseIDsTxt = append (deprecatedLicenseIDsTxt , []byte (" \" " )... )
61
- deprecatedLicenseIDsTxt = append (deprecatedLicenseIDsTxt , []byte (id )... )
62
- deprecatedLicenseIDsTxt = append (deprecatedLicenseIDsTxt , []byte ("\" ," )... )
63
- deprecatedLicenseIDsTxt = append (deprecatedLicenseIDsTxt , []byte ("\n " )... )
64
- }
65
- err = ioutil .WriteFile ("deprecated_license_ids.txt" , deprecatedLicenseIDsTxt , 0600 )
66
- if err != nil {
67
- return err
68
- }
56
+ // generate the GetLicenses() function in get_licenses.go
57
+ getLicensesContents := []byte (`package spdxlicenses
69
58
70
- // save deprecated license IDs to json array in file deprecated_license_ids.json
71
- deprecatedLicenseIDsJSON , err := json .Marshal (deprecatedLicenseIDs )
72
- if err != nil {
73
- return err
74
- }
75
- err = ioutil .WriteFile ("deprecated_license_ids.json" , deprecatedLicenseIDsJSON , 0600 )
76
- if err != nil {
77
- return err
59
+ func GetLicenses() []string {
60
+ return []string{
61
+ ` )
62
+ for _ , id := range activeLicenseIDs {
63
+ getLicensesContents = append (getLicensesContents , ` "` + id + `",
64
+ ` ... )
78
65
}
66
+ getLicensesContents = append (getLicensesContents , ` }
67
+ }
68
+ ` ... )
79
69
80
- // save non-deprecated license IDs followed by a comma with one per line in file license_ids.txt
81
- nonDeprecatedLicenseIDsTxt := []byte {}
82
- for _ , id := range nonDeprecatedLicenseIDs {
83
- nonDeprecatedLicenseIDsTxt = append (nonDeprecatedLicenseIDsTxt , []byte (" \" " )... )
84
- nonDeprecatedLicenseIDsTxt = append (nonDeprecatedLicenseIDsTxt , []byte (id )... )
85
- nonDeprecatedLicenseIDsTxt = append (nonDeprecatedLicenseIDsTxt , []byte ("\" ," )... )
86
- nonDeprecatedLicenseIDsTxt = append (nonDeprecatedLicenseIDsTxt , []byte ("\n " )... )
87
- }
88
- err = ioutil .WriteFile ("license_ids.txt" , nonDeprecatedLicenseIDsTxt , 0600 )
70
+ err = os .WriteFile ("../spdxexp/spdxlicenses/get_licenses.go" , getLicensesContents , 0600 )
89
71
if err != nil {
90
72
return err
91
73
}
92
74
93
- // save non-deprecated license IDs to json array in file license_ids.json
94
- nonDeprecatedLicenseIDsJSON , err := json .Marshal (nonDeprecatedLicenseIDs )
95
- if err != nil {
96
- return err
75
+ // generate the GetDeprecated() function in get_deprecated.go
76
+ getDeprecatedContents := []byte (`package spdxlicenses
77
+
78
+ func GetDeprecated() []string {
79
+ return []string{
80
+ ` )
81
+ for _ , id := range deprecatedLicenseIDs {
82
+ getDeprecatedContents = append (getDeprecatedContents , ` "` + id + `",
83
+ ` ... )
97
84
}
98
- err = ioutil .WriteFile ("license_ids.json" , nonDeprecatedLicenseIDsJSON , 0600 )
85
+ getDeprecatedContents = append (getDeprecatedContents , ` }
86
+ }
87
+ ` ... )
88
+
89
+ err = os .WriteFile ("../spdxexp/spdxlicenses/get_deprecated.go" , getDeprecatedContents , 0600 )
99
90
if err != nil {
100
91
return err
101
92
}
93
+
102
94
return nil
103
95
}
0 commit comments