aboutsummaryrefslogtreecommitdiff
path: root/tvsaver/saver2v2
diff options
context:
space:
mode:
authorSteve Winslow <steve@swinslow.net>2020-11-08 16:06:08 -0500
committerSteve Winslow <steve@swinslow.net>2020-11-08 16:06:08 -0500
commite40b5386299d68156151222ad5b092dcc6f2a04d (patch)
treefeefa3cd2fcee2aa75d9fc56d9884e42881b2764 /tvsaver/saver2v2
parenta47f1698a1fdd2360c661440e8925e84cc971263 (diff)
downloadspdx-tools-e40b5386299d68156151222ad5b092dcc6f2a04d.tar.gz
Fix saving for expanded external document refs
Signed-off-by: Steve Winslow <steve@swinslow.net>
Diffstat (limited to 'tvsaver/saver2v2')
-rw-r--r--tvsaver/saver2v2/save_creation_info.go13
-rw-r--r--tvsaver/saver2v2/save_creation_info_test.go16
2 files changed, 24 insertions, 5 deletions
diff --git a/tvsaver/saver2v2/save_creation_info.go b/tvsaver/saver2v2/save_creation_info.go
index af9b977..1492fb4 100644
--- a/tvsaver/saver2v2/save_creation_info.go
+++ b/tvsaver/saver2v2/save_creation_info.go
@@ -5,6 +5,7 @@ package saver2v2
import (
"fmt"
"io"
+ "sort"
"github.com/spdx/tools-golang/spdx"
)
@@ -25,8 +26,16 @@ func renderCreationInfo2_2(ci *spdx.CreationInfo2_2, w io.Writer) error {
if ci.DocumentNamespace != "" {
fmt.Fprintf(w, "DocumentNamespace: %s\n", ci.DocumentNamespace)
}
- for _, s := range ci.ExternalDocumentReferences {
- fmt.Fprintf(w, "ExternalDocumentRef: %s\n", s)
+ // print EDRs in order sorted by identifier
+ edrIDs := []string{}
+ for docRefID := range ci.ExternalDocumentReferences {
+ edrIDs = append(edrIDs, docRefID)
+ }
+ sort.Strings(edrIDs)
+ for _, edrID := range edrIDs {
+ edr := ci.ExternalDocumentReferences[edrID]
+ fmt.Fprintf(w, "ExternalDocumentRef: DocumentRef-%s %s %s:%s\n",
+ edr.DocumentRefID, edr.URI, edr.Alg, edr.Checksum)
}
if ci.LicenseListVersion != "" {
fmt.Fprintf(w, "LicenseListVersion: %s\n", ci.LicenseListVersion)
diff --git a/tvsaver/saver2v2/save_creation_info_test.go b/tvsaver/saver2v2/save_creation_info_test.go
index 3e23c0b..404abfe 100644
--- a/tvsaver/saver2v2/save_creation_info_test.go
+++ b/tvsaver/saver2v2/save_creation_info_test.go
@@ -17,9 +17,19 @@ func TestSaver2_2CISavesText(t *testing.T) {
SPDXIdentifier: spdx.ElementID("DOCUMENT"),
DocumentName: "spdx-go-0.0.1.abcdef",
DocumentNamespace: "https://github.com/swinslow/spdx-docs/spdx-go/spdx-go-0.0.1.abcdef.whatever",
- ExternalDocumentReferences: []string{
- "DocumentRef-spdx-go-0.0.1a https://github.com/swinslow/spdx-docs/spdx-go/spdx-go-0.0.1a.cdefab.whatever SHA1:0123456701234567012345670123456701234567",
- "DocumentRef-time-1.2.3 https://github.com/swinslow/spdx-docs/time/time-1.2.3.cdefab.whatever SHA1:0123456701234567012345670123456701234568",
+ ExternalDocumentReferences: map[string]spdx.ExternalDocumentRef2_2{
+ "spdx-go-0.0.1a": spdx.ExternalDocumentRef2_2{
+ DocumentRefID: "spdx-go-0.0.1a",
+ URI: "https://github.com/swinslow/spdx-docs/spdx-go/spdx-go-0.0.1a.cdefab.whatever",
+ Alg: "SHA1",
+ Checksum: "0123456701234567012345670123456701234567",
+ },
+ "time-1.2.3": spdx.ExternalDocumentRef2_2{
+ DocumentRefID: "time-1.2.3",
+ URI: "https://github.com/swinslow/spdx-docs/time/time-1.2.3.cdefab.whatever",
+ Alg: "SHA1",
+ Checksum: "0123456701234567012345670123456701234568",
+ },
},
LicenseListVersion: "3.9",
CreatorPersons: []string{