From c7239bdc744217f39616839f6bb6d3453a6d2307 Mon Sep 17 00:00:00 2001 From: Steve Winslow Date: Sun, 14 Jun 2020 15:45:07 -0400 Subject: Add licensediff and tests for 2.2 Signed-off-by: Steve Winslow --- licensediff/licensediff.go | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'licensediff/licensediff.go') diff --git a/licensediff/licensediff.go b/licensediff/licensediff.go index 9d693b0..4b2f0ac 100644 --- a/licensediff/licensediff.go +++ b/licensediff/licensediff.go @@ -14,9 +14,37 @@ type LicensePair struct { Second string } -// MakePairs essentially just consolidates all files and LicenseConcluded +// MakePairs2_1 essentially just consolidates all files and LicenseConcluded // strings into a single data structure. -func MakePairs(p1 *spdx.Package2_1, p2 *spdx.Package2_1) (map[string]LicensePair, error) { +func MakePairs2_1(p1 *spdx.Package2_1, p2 *spdx.Package2_1) (map[string]LicensePair, error) { + pairs := map[string]LicensePair{} + + // first, go through and add all files/licenses from p1 + for _, f := range p1.Files { + pair := LicensePair{First: f.LicenseConcluded, Second: ""} + pairs[f.FileName] = pair + } + + // now, go through all files/licenses from p2. If already + // present, add as .second; if not, create new pair + for _, f := range p2.Files { + firstLic := "" + existingPair, ok := pairs[f.FileName] + if ok { + // already present; update it + firstLic = existingPair.First + } + // now, update what's there, either way + pair := LicensePair{First: firstLic, Second: f.LicenseConcluded} + pairs[f.FileName] = pair + } + + return pairs, nil +} + +// MakePairs2_2 essentially just consolidates all files and LicenseConcluded +// strings into a single data structure. +func MakePairs2_2(p1 *spdx.Package2_2, p2 *spdx.Package2_2) (map[string]LicensePair, error) { pairs := map[string]LicensePair{} // first, go through and add all files/licenses from p1 -- cgit v1.2.3