diff options
author | Steve Winslow <steve@swinslow.net> | 2020-06-14 15:45:07 -0400 |
---|---|---|
committer | Steve Winslow <steve@swinslow.net> | 2020-06-14 15:45:07 -0400 |
commit | c7239bdc744217f39616839f6bb6d3453a6d2307 (patch) | |
tree | 4bd59cdc6dd536f1a36514439c828dca36f78a7e /licensediff/licensediff.go | |
parent | dfaf5f3e3ed8a977d4ba1783ec6b95afa3faa150 (diff) | |
download | spdx-tools-c7239bdc744217f39616839f6bb6d3453a6d2307.tar.gz |
Add licensediff and tests for 2.2
Signed-off-by: Steve Winslow <steve@swinslow.net>
Diffstat (limited to 'licensediff/licensediff.go')
-rw-r--r-- | licensediff/licensediff.go | 32 |
1 files changed, 30 insertions, 2 deletions
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 |