/
save_files.go
70 lines (63 loc) · 1.8 KB
/
save_files.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
package saver2v2
import (
"github.com/spdx/tools-golang/spdx"
)
func renderFiles2_2(doc *spdx.Document2_2, jsondocument map[string]interface{}) ([]interface{}, error) {
var files []interface{}
for k, v := range doc.UnpackagedFiles {
file := make(map[string]interface{})
file["SPDXID"] = spdx.RenderElementID(k)
ann, _ := renderAnnotations2_2(doc.Annotations, spdx.MakeDocElementID("", string(v.FileSPDXIdentifier)))
if ann != nil {
file["annotations"] = ann
}
if v.FileContributor != nil {
file["fileContributors"] = v.FileContributor
}
if v.FileComment != "" {
file["comment"] = v.FileComment
}
// save package checksums
if v.FileChecksums != nil {
var checksums []interface{}
for _, value := range v.FileChecksums {
checksum := make(map[string]interface{})
checksum["algorithm"] = string(value.Algorithm)
checksum["checksumValue"] = value.Value
checksums = append(checksums, checksum)
}
file["checksums"] = checksums
}
if v.FileCopyrightText != "" {
file["copyrightText"] = v.FileCopyrightText
}
if v.FileName != "" {
file["fileName"] = v.FileName
}
if v.FileType != nil {
file["fileTypes"] = v.FileType
}
if v.LicenseComments != "" {
file["licenseComments"] = v.LicenseComments
}
if v.LicenseConcluded != "" {
file["licenseConcluded"] = v.LicenseConcluded
}
if v.LicenseInfoInFile != nil {
file["licenseInfoInFiles"] = v.LicenseInfoInFile
}
if v.FileNotice != "" {
file["noticeText"] = v.FileNotice
}
if v.FileDependencies != nil {
file["fileDependencies"] = v.FileDependencies
}
if v.FileAttributionTexts != nil {
file["attributionTexts"] = v.FileAttributionTexts
}
files = append(files, file)
}
jsondocument["files"] = files
return files, nil
}