diff options
author | Steve Winslow <steve@swinslow.net> | 2020-04-25 15:22:49 -0400 |
---|---|---|
committer | Steve Winslow <steve@swinslow.net> | 2020-04-25 15:22:49 -0400 |
commit | 4a8bcf1883c3547f2efb6af5a2f002293117c45b (patch) | |
tree | 4d4b20ff7fd9d9c6b66e3728e0398faf5207bd96 /spdx | |
parent | b68821f66a8d47c441e3da9ab059205e7e30b3f4 (diff) | |
download | spdx-tools-4a8bcf1883c3547f2efb6af5a2f002293117c45b.tar.gz |
Change to element IDs and maps
Signed-off-by: Steve Winslow <steve@swinslow.net>
Diffstat (limited to 'spdx')
-rw-r--r-- | spdx/annotation.go | 2 | ||||
-rw-r--r-- | spdx/creation_info.go | 2 | ||||
-rw-r--r-- | spdx/document.go | 2 | ||||
-rw-r--r-- | spdx/file.go | 5 | ||||
-rw-r--r-- | spdx/identifier.go | 26 | ||||
-rw-r--r-- | spdx/package.go | 4 | ||||
-rw-r--r-- | spdx/relationship.go | 4 | ||||
-rw-r--r-- | spdx/snippet.go | 4 |
8 files changed, 38 insertions, 11 deletions
diff --git a/spdx/annotation.go b/spdx/annotation.go index 0846d62..9687a28 100644 --- a/spdx/annotation.go +++ b/spdx/annotation.go @@ -21,7 +21,7 @@ type Annotation2_1 struct { // 8.4: SPDX Identifier Reference // Cardinality: conditional (mandatory, one) if there is an Annotation - AnnotationSPDXIdentifier string + AnnotationSPDXIdentifier DocElementID // 8.5: Annotation Comment // Cardinality: conditional (mandatory, one) if there is an Annotation diff --git a/spdx/creation_info.go b/spdx/creation_info.go index 1d4355c..f606364 100644 --- a/spdx/creation_info.go +++ b/spdx/creation_info.go @@ -16,7 +16,7 @@ type CreationInfo2_1 struct { // 2.3: SPDX Identifier; should be "SPDXRef-DOCUMENT" // Cardinality: mandatory, one - SPDXIdentifier string + SPDXIdentifier ElementID // 2.4: Document Name // Cardinality: mandatory, one diff --git a/spdx/document.go b/spdx/document.go index 9f0c919..d2e9e13 100644 --- a/spdx/document.go +++ b/spdx/document.go @@ -7,7 +7,7 @@ package spdx // See https://spdx.org/sites/cpstandard/files/pages/files/spdxversion2.1.pdf type Document2_1 struct { CreationInfo *CreationInfo2_1 - Packages []*Package2_1 + Packages map[ElementID]*Package2_1 OtherLicenses []*OtherLicense2_1 Relationships []*Relationship2_1 Annotations []*Annotation2_1 diff --git a/spdx/file.go b/spdx/file.go index 3732107..91e40d1 100644 --- a/spdx/file.go +++ b/spdx/file.go @@ -11,7 +11,7 @@ type File2_1 struct { // 4.2: File SPDX Identifier: "SPDXRef-[idstring]" // Cardinality: mandatory, one - FileSPDXIdentifier string + FileSPDXIdentifier ElementID // 4.3: File Type // Cardinality: optional, multiple @@ -62,7 +62,8 @@ type File2_1 struct { FileDependencies []string // Snippets contained in this File - Snippets []*Snippet2_1 + // Note that Snippets could be defined in a different Document! + Snippets map[DocElementID]*Snippet2_1 } // ArtifactOfProject2_1 is a DEPRECATED collection of data regarding diff --git a/spdx/identifier.go b/spdx/identifier.go new file mode 100644 index 0000000..d61d9c9 --- /dev/null +++ b/spdx/identifier.go @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + +package spdx + +// ElementID represents the identifier string portion of an SPDX element +// identifier. DocElementID should be used for any attributes which can +// contain identifiers defined in a different SPDX document. +// ElementIDs should NOT contain the mandatory 'SPDXRef-' portion. +type ElementID string + +// DocElementID represents an SPDX element identifier that could be defined +// in a different SPDX document, and therefore could have a "DocumentRef-" +// portion, such as Relationships and Annotations. +// ElementID is used for attributes in which a "DocumentRef-" portion cannot +// appear, such as a Package or File definition (since it is necessarily +// being defined in the present document). +// DocumentRefID will be the empty string for elements defined in the +// present document. +// DocElementIDs should NOT contain the mandatory 'DocumentRef-' or +// 'SPDXRef-' portions. +type DocElementID struct { + DocumentRefID string + ElementRefID ElementID +} + +// TODO: add equivalents for LicenseRef- identifiers diff --git a/spdx/package.go b/spdx/package.go index d49922f..989e2de 100644 --- a/spdx/package.go +++ b/spdx/package.go @@ -16,7 +16,7 @@ type Package2_1 struct { // 3.2: Package SPDX Identifier: "SPDXRef-[idstring]" // Cardinality: mandatory, one - PackageSPDXIdentifier string + PackageSPDXIdentifier ElementID // 3.3: Package Version // Cardinality: optional, one @@ -115,7 +115,7 @@ type Package2_1 struct { // contained within PackageExternalReference2_1 struct, if present // Files contained in this Package - Files []*File2_1 + Files map[ElementID]*File2_1 } // PackageExternalReference2_1 is an External Reference to additional info diff --git a/spdx/relationship.go b/spdx/relationship.go index bc87967..ef524a3 100644 --- a/spdx/relationship.go +++ b/spdx/relationship.go @@ -11,8 +11,8 @@ type Relationship2_1 struct { // one mandatory for SPDX Document with multiple packages // RefA and RefB are first and second item // Relationship is type from 7.1.1 - RefA string - RefB string + RefA DocElementID + RefB DocElementID Relationship string // 7.2: Relationship Comment diff --git a/spdx/snippet.go b/spdx/snippet.go index 14b3b25..89680c5 100644 --- a/spdx/snippet.go +++ b/spdx/snippet.go @@ -7,11 +7,11 @@ type Snippet2_1 struct { // 5.1: Snippet SPDX Identifier: "SPDXRef-[idstring]" // Cardinality: mandatory, one - SnippetSPDXIdentifier string + SnippetSPDXIdentifier ElementID // 5.2: Snippet from File SPDX Identifier // Cardinality: mandatory, one - SnippetFromFileSPDXIdentifier string + SnippetFromFileSPDXIdentifier DocElementID // 5.3: Snippet Byte Range: [start byte]:[end byte] // Cardinality: mandatory, one |