1// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later 2 3package saver2v1 4 5import ( 6 "fmt" 7 "io" 8 "sort" 9 10 "github.com/spdx/tools-golang/spdx/common" 11 "github.com/spdx/tools-golang/spdx/v2_1" 12) 13 14func renderFile2_1(f *v2_1.File, w io.Writer) error { 15 if f.FileName != "" { 16 fmt.Fprintf(w, "FileName: %s\n", f.FileName) 17 } 18 if f.FileSPDXIdentifier != "" { 19 fmt.Fprintf(w, "SPDXID: %s\n", common.RenderElementID(f.FileSPDXIdentifier)) 20 } 21 for _, s := range f.FileTypes { 22 fmt.Fprintf(w, "FileType: %s\n", s) 23 } 24 25 for _, checksum := range f.Checksums { 26 fmt.Fprintf(w, "FileChecksum: %s: %s\n", checksum.Algorithm, checksum.Value) 27 } 28 if f.LicenseConcluded != "" { 29 fmt.Fprintf(w, "LicenseConcluded: %s\n", f.LicenseConcluded) 30 } 31 for _, s := range f.LicenseInfoInFiles { 32 fmt.Fprintf(w, "LicenseInfoInFile: %s\n", s) 33 } 34 if f.LicenseComments != "" { 35 fmt.Fprintf(w, "LicenseComments: %s\n", textify(f.LicenseComments)) 36 } 37 if f.FileCopyrightText != "" { 38 fmt.Fprintf(w, "FileCopyrightText: %s\n", textify(f.FileCopyrightText)) 39 } 40 for _, aop := range f.ArtifactOfProjects { 41 fmt.Fprintf(w, "ArtifactOfProjectName: %s\n", aop.Name) 42 if aop.HomePage != "" { 43 fmt.Fprintf(w, "ArtifactOfProjectHomePage: %s\n", aop.HomePage) 44 } 45 if aop.URI != "" { 46 fmt.Fprintf(w, "ArtifactOfProjectURI: %s\n", aop.URI) 47 } 48 } 49 if f.FileComment != "" { 50 fmt.Fprintf(w, "FileComment: %s\n", textify(f.FileComment)) 51 } 52 if f.FileNotice != "" { 53 fmt.Fprintf(w, "FileNotice: %s\n", textify(f.FileNotice)) 54 } 55 for _, s := range f.FileContributors { 56 fmt.Fprintf(w, "FileContributor: %s\n", s) 57 } 58 for _, s := range f.FileDependencies { 59 fmt.Fprintf(w, "FileDependency: %s\n", s) 60 } 61 62 fmt.Fprintf(w, "\n") 63 64 // also render any snippets for this file 65 // get slice of Snippet identifiers so we can sort them 66 snippetKeys := []string{} 67 for k := range f.Snippets { 68 snippetKeys = append(snippetKeys, string(k)) 69 } 70 sort.Strings(snippetKeys) 71 for _, sID := range snippetKeys { 72 s := f.Snippets[common.ElementID(sID)] 73 renderSnippet2_1(s, w) 74 } 75 76 return nil 77} 78