aboutsummaryrefslogtreecommitdiff
path: root/tvsaver/saver2v1/save_document.go
diff options
context:
space:
mode:
authorRishabhBhatnagar <bhatnagarrishabh4@gmail.com>2020-01-09 20:39:55 +0530
committerRishabhBhatnagar <bhatnagarrishabh4@gmail.com>2020-01-09 21:04:37 +0530
commitcd59ee66408a908f7ef94548814514f6bc9fc906 (patch)
tree550b146d4de0cc00a4784147f7d8f2a7bc93cffe /tvsaver/saver2v1/save_document.go
parentf4fef41a45620391fca6481f4700b89de170ab88 (diff)
downloadspdx-tools-cd59ee66408a908f7ef94548814514f6bc9fc906.tar.gz
Create Go Module
- Unpack directory v0 to move all the content to the root directory. - ./v0/* converted to ./* - all the test cases were fixed to remove one directory less indexing for test files - add go.mod - go version 1.13 is used to have a relatively stable versioning system Signed-off-by: RishabhBhatnagar <bhatnagarrishabh4@gmail.com>
Diffstat (limited to 'tvsaver/saver2v1/save_document.go')
-rw-r--r--tvsaver/saver2v1/save_document.go65
1 files changed, 65 insertions, 0 deletions
diff --git a/tvsaver/saver2v1/save_document.go b/tvsaver/saver2v1/save_document.go
new file mode 100644
index 0000000..97891f5
--- /dev/null
+++ b/tvsaver/saver2v1/save_document.go
@@ -0,0 +1,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
+}