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
|
// Package saver2v1 contains functions to render and write a tag-value
// formatted version of an in-memory SPDX document and its sections
// (version 2.1).
// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
package saver2v1
import (
"fmt"
"io"
"github.com/spdx/tools-golang/spdx"
)
// RenderDocument2_1 is the main entry point to take an SPDX in-memory
// Document (version 2.1), and render it to the received io.Writer.
// It is only exported in order to be available to the tvsaver package,
// and typically does not need to be called by client code.
func RenderDocument2_1(doc *spdx.Document2_1, w io.Writer) error {
if doc.CreationInfo == nil {
return fmt.Errorf("Document had nil CreationInfo section")
}
renderCreationInfo2_1(doc.CreationInfo, w)
for _, pkg := range doc.Packages {
if pkg.IsUnpackaged == true {
fmt.Fprintf(w, "##### Unpackaged files\n\n")
} else {
fmt.Fprintf(w, "##### Package: %s\n\n", pkg.PackageName)
}
renderPackage2_1(pkg, w)
}
if len(doc.OtherLicenses) > 0 {
fmt.Fprintf(w, "##### Other Licenses\n\n")
for _, ol := range doc.OtherLicenses {
renderOtherLicense2_1(ol, w)
}
}
if len(doc.Relationships) > 0 {
fmt.Fprintf(w, "##### Relationships\n\n")
for _, rln := range doc.Relationships {
renderRelationship2_1(rln, w)
}
fmt.Fprintf(w, "\n")
}
if len(doc.Annotations) > 0 {
fmt.Fprintf(w, "##### Annotations\n\n")
for _, ann := range doc.Annotations {
renderAnnotation2_1(ann, w)
fmt.Fprintf(w, "\n")
}
}
if len(doc.Reviews) > 0 {
fmt.Fprintf(w, "##### Reviews\n\n")
for _, rev := range doc.Reviews {
renderReview2_1(rev, w)
}
}
return nil
}
|