aboutsummaryrefslogtreecommitdiff
path: root/licensediff/licensediff.go
diff options
context:
space:
mode:
Diffstat (limited to 'licensediff/licensediff.go')
-rw-r--r--licensediff/licensediff.go32
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